From: Chris S. <san...@us...> - 2005-06-16 04:11:47
|
Update of /cvsroot/stack/stack-1-0/scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13332/scripts Modified Files: Tag: frontend_dev stackDatabase.php Log Message: Index: stackDatabase.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackDatabase.php,v retrieving revision 1.16.2.3 retrieving revision 1.16.2.4 diff -C2 -d -r1.16.2.3 -r1.16.2.4 *** stackDatabase.php 15 Jun 2005 20:33:14 -0000 1.16.2.3 --- stackDatabase.php 16 Jun 2005 04:11:38 -0000 1.16.2.4 *************** *** 109,130 **** global $_PHP_SELF; - // Sort out how we are going to filter questions. - $filter_kw = ''; - $filter_name = ''; if ('try' == $action) { ! $filter_kw = 'demo'; ! $filter_name = ''; ! } else { ! if (is_array($filter)) { ! if (array_key_exists('kw',$filter)) { ! $filter_kw = trim($filter['kw']); ! } ! if (array_key_exists('name',$filter)) { ! $filter_name = trim($filter['name']); ! } ! } } ! // Build the query to the database. $query = 'SELECT --- 109,126 ---- global $_PHP_SELF; + // Sort out how we are going to filter questions. + if ('' === $filter) { + $filter['kw'] = ''; + $filter['name'] = ''; + } if ('try' == $action) { ! $filter['kw'] = 'demo'; ! $filter['name'] = ''; } ! ! $filter_name = $filter['name']; ! $filter_kw = $filter['kw']; ! // Build the query to the database. $query = 'SELECT *************** *** 167,181 **** // Decide how to filter questions ! $dispQ = TRUE; ! if ('' != $filter_kw) { ! if ('' != $filter_name) { ! $dispQ = max(strpos($qkeywords,$filter_kw),strpos($qname,$filter_name)); ! } else { ! $dispQ = strpos($qkeywords,$filter_kw); ! } ! } else if ('' != $filter_name) { ! $dispQ = strpos($qname,$filter_name); ! } ! if (FALSE !== $dispQ) { --- 163,167 ---- // Decide how to filter questions ! $dispQ = stack_db_question_filter($qname,$qkeywords,$filter_name,$filter_kw); if (FALSE !== $dispQ) { *************** *** 242,245 **** --- 228,239 ---- { // List all the questions in the database + // Sort out how we are going to filter questions. + if ('' === $filter) { + $filter['kw'] = ''; + $filter['name'] = ''; + } + $filter_name = $filter['name']; + $filter_kw = $filter['kw']; + $query = 'SELECT questionID, questionName, questionKeywords *************** *** 251,255 **** echo '<table><thead><tr>'; ! echo "<tr><th>Add</th><th>Question no.</th><th>Name</th> <th>Key words</th></tr>\n"; echo "\n</thead><tbody>\n"; --- 245,249 ---- echo '<table><thead><tr>'; ! echo "<tr><th>Add</th><th>Question no.</th><th>Name</th> <th>Keyword</th></tr>\n"; echo "\n</thead><tbody>\n"; *************** *** 257,265 **** $row = mysql_fetch_row($result); $qkw = stripslashes($row[2]); ! $dispQ = TRUE; ! if ('' != $filter) { ! $dispQ = strpos($qkw,$filter); ! } if (FALSE !== $dispQ) { --- 251,257 ---- $row = mysql_fetch_row($result); + $name = stripslashes($row[1]); $qkw = stripslashes($row[2]); ! $dispQ = stack_db_question_filter($name,$qkw,$filter_name,$filter_kw); if (FALSE !== $dispQ) { *************** *** 267,278 **** $qname = ''; ! if ('' != $row[1]) { ! $qname = stripslashes($row[1]); ! $qname = "<a href=\"javascript:EditPopup('$qID');\">{$qname}</a>"; } echo "<tr><td><input type=\"checkbox\" name=\"questionsToAdd[$qID][add]\" value=\"ticked\" /></td>\n"; ! echo "<td>$qID</td><td>$qname</td><td>$qkw</td> </tr>\n"; } // End preg_match to display each line. --- 259,269 ---- $qname = ''; ! if ('' != $name) { ! $name = "<a href=\"javascript:EditPopup('$qID');\">{$name}</a>"; } echo "<tr><td><input type=\"checkbox\" name=\"questionsToAdd[$qID][add]\" value=\"ticked\" /></td>\n"; ! echo "<td>$qID</td><td>$name</td><td>$qkw</td> </tr>\n"; } // End preg_match to display each line. *************** *** 288,291 **** --- 279,310 ---- } + + /** + * Decides whether to display a question based upon the name, keywords and filter. + * + * @param $name string Question name. + * @param $kw string Question keywords. + * @param $filter_name string Filter to be applied to the name. + * @param $filter_kw string Filter to be applied to the name. + * @return $dispQ boolean + */ + function stack_db_question_filter($name,$kw,$filter_name,$filter_kw) { + + $dispQ = TRUE; + + if ('' != $filter_kw) { + if ('' != $filter_name) { + $dispQ = max(strpos($kw,$filter_kw),strpos($name,$filter_name)); + } else { + $dispQ = strpos($kw,$filter_kw); + } + } else if ('' != $filter_name) { + $dispQ = strpos($name,$filter_name); + } + + return($dispQ); + } + + /** * Add or edit a question in the database. |