function searchSuggestions($cqlQuery, $query) { global $recordSchema; global $loginUserID; global $tableRefs, $tableUserData; // defined in 'db.inc.php' global $connection; global $client; // Extract the first field & search pattern from the 'WHERE' clause: // (these will be used to retrieve search suggestions) $origSearchSuggestionsField = preg_replace("/^[ ()]*(\\w+).*/i", "\\1", $query); $searchSuggestionsPattern = preg_replace("/.*? (?:RLIKE|[=<>]+) \"?(.+?)\"?(?=( *\\) *?)*( +(AND|OR)\\b|\$)).*/i", "\\1", $query); // see NOTE above if (preg_match("/^main_fields\$/i", $origSearchSuggestionsField)) { // fetch search suggestions for all of the user's "main fields" $searchSuggestionsFieldsArray = preg_split("/ *, */", $_SESSION['userMainFields']); } else { $searchSuggestionsFieldsArray = array($origSearchSuggestionsField); } // we only need to fetch search suggestions for one field $outputDataArray = array(); // make sure that the buffer variable is empty // Retrieve matching search suggestions for each field given in '$searchSuggestionsFieldsArray': foreach ($searchSuggestionsFieldsArray as $searchSuggestionsField) { if (preg_match("/^main_fields\$/i", $origSearchSuggestionsField)) { $searchSuggestionsQuery = preg_replace("/\\bmain_fields\\b/i", $searchSuggestionsField, $query); } else { $searchSuggestionsQuery = $query; } // Check whether we need to split field values for this field: if (preg_match("/^(author|keywords|abstract|address|corporate_author|place|editor|language|summary_language|series_editor|area|expedition|notes|location|call_number|created_by|modified_by|user_keys|user_notes|user_groups|related)\$/i", $searchSuggestionsField)) { $splitValues = true; } else { $splitValues = false; } // Define split patterns for this field: if (preg_match("/^(author|corporate_author|editor|series_editor)\$/i", $searchSuggestionsField)) { $splitPattern = " *[;()/]+ *"; } elseif (preg_match("/^abstract\$/i", $searchSuggestionsField)) { $splitPattern = "\\s*[,.()/?!]+\\s+|\\s+[,.()/?!]\\s*|\\s+-\\s+"; } elseif (preg_match("/^(place|notes|location|user_notes|user_groups|related)\$/i", $searchSuggestionsField)) { $splitPattern = " *[;]+ *"; } elseif (preg_match("/^(call_number)\$/i", $searchSuggestionsField)) { $splitPattern = " *[;@]+ *"; } else { $splitPattern = " *[,;()/]+ *"; } // Produce the list of search suggestions for this field: // (function 'selectDistinct()' is defined in 'include.inc.php') $searchSuggestionsArray = selectDistinct($connection, $tableRefs, "serial", $tableUserData, "record_id", "user_id", $loginUserID, $searchSuggestionsField, "", "", "", "", "serial", "\".+\" AND {$searchSuggestionsQuery}", $splitValues, $splitPattern, "ARRAY", $searchSuggestionsPattern, false); if (!empty($searchSuggestionsArray)) { // Prefix each item with an index name and relation: // // NOTE: When the user selects a search suggestion in Firefox's search box, Firefox replaces the // user-entered data in the browser's search field with the chosen search suggestion. This // removes any CQL index and relation that was entered by the user (e.g. "keywords any ...") // and 'cql.serverChoice' will be searched instead. Since this would lead to unexpected (or // zero) results, we prefix all search suggestions with the index name and the '=' relation. // // TODO: This will need to be revised if 'cql.serverChoice' is mapped to the user's preferred list // of "main fields". Even better would be if browsers would support alternate query URLs for // each suggestion in the completion list. if (preg_match("/^json\$/i", $recordSchema) and preg_match("/^sug/i", $client)) { // e.g. "sug-refbase_suggest-1.0" $searchSuggestionsArray = preg_replace('/^/', "{$searchSuggestionsField} = ", $searchSuggestionsArray); } $outputDataArray = array_merge($outputDataArray, $searchSuggestionsArray); // append this field's search suggestions to the array of found search suggestions } } if (!empty($outputDataArray)) { if (preg_match("/^main_fields\$/i", $origSearchSuggestionsField)) { // Remove duplicate values from array: $outputDataArray = array_unique($outputDataArray); // Sort in ascending order: sort($outputDataArray); } if (preg_match("/^json\$/i", $recordSchema)) { $outputData = '"' . implode('", "', $outputDataArray) . '"'; } else { // unordered HTML list $outputData = "<li>" . implode("</li><li>", $outputDataArray) . "</li>"; } } else { $outputData = ""; } if (preg_match("/^json\$/i", $recordSchema)) { // return JSON-formatted search suggestions: return '["' . $cqlQuery . '", [' . $outputData . ']]'; } else { // return HTML-formatted search suggestions: return "<ul>" . $outputData . "</ul>"; } // e.g.: <ul><li>firefox</li><li>first choice</li><li>mozilla firefox</li></ul> }
// No, just show as an option print "\n\t<option value=\"{$result}\">{$result}"; } print "</option>"; } print "\n</select>"; } // end of function // Connect to the server if (!($connection = @mysql_connect(DB_HOST, DB_USER, DB_PW))) { showerror(); } if (!mysql_select_db(DB_NAME, $connection)) { showerror(); } print "\nRegion: "; // Produce the select list // Parameters: // 1: Database connection // 2. Table that contains values // 3. Attribute that contains values // 4. <SELECT> element name // 5. Optional <OPTION SELECTED> selectDistinct($connection, "region", "region_name", "regionName", "All"); ?> <br> <input type="submit" value="Show Wines"> </form> </body> </html>
// Parameters: // 1: Database connection // 2. Table that contains values // 3. The field name of the table's primary key // 4. Table name of the user data table // 5. The field name within the user data table that corresponds to the field in 3. // 6. The field name of the user ID field within the user data table // 7. The user ID of the currently logged in user (which must be provided as a session variable) // 8. Attribute that contains values // 9. <SELECT> element name // 10. An additional non-database value (display string) // 11. String that gets submitted instead of the display string given in 10. // 12. Optional <OPTION SELECTED> // 13. Restrict query to field... (keep empty if no restriction wanted) // 14. ...where field contents are... // 15. Split field contents into substrings? (yes = true, no = false) // 16. POSIX-PATTERN to split field contents into substrings (in order to obtain actual values) echo selectDistinct($connection, $tableRefs, "serial", $tableUserData, "record_id", "user_id", $loginUserID, "series_title", "seriesTitleName", $loc["All"], "All", $loc["All"], "", "", false, ""); echo "\n\t</td>" . "\n</tr>"; echo "\n<tr>" . "\n\t<td> </td>" . "\n\t<td align=\"right\">or:</td>\n\t<td align=\"center\"><input type=\"radio\" name=\"seriesTitleRadio\" value=\"0\"></td>" . "\n\t<td>\n\t\t<select name=\"seriesTitleSelector2\">\n\t\t\t<option>contains</option>\n\t\t\t<option>does not contain</option>\n\t\t\t<option>is equal to</option>\n\t\t\t<option>is not equal to</option>\n\t\t\t<option>starts with</option>\n\t\t\t<option>ends with</option>\n\t\t</select>\n\t</td>" . "\n\t<td><input type=\"text\" name=\"seriesTitleName2\" size=\"42\"></td>" . "\n</tr>"; // (4) Complete the form: echo "\n<tr>" . "\n\t<td valign=\"middle\"><input type=\"checkbox\" name=\"showVolume\" value=\"1\"></td>" . "\n\t<td><b>Volume:</b></td>\n\t<td> </td>" . "\n\t<td>\n\t\t<select name=\"volumeSelector\">\n\t\t\t<option>contains</option>\n\t\t\t<option>does not contain</option>\n\t\t\t<option>is equal to</option>\n\t\t\t<option>is not equal to</option>\n\t\t\t<option>starts with</option>\n\t\t\t<option>ends with</option>\n\t\t\t<option>is greater than</option>\n\t\t\t<option>is less than</option>\n\t\t\t<option>is within range</option>\n\t\t\t<option>is within list</option>\n\t\t</select>\n\t</td>" . "\n\t<td><input type=\"text\" name=\"volumeNo\" size=\"42\"></td>" . "\n</tr>" . "\n<tr>" . "\n\t<td valign=\"middle\"><input type=\"checkbox\" name=\"showPages\" value=\"1\" checked></td>" . "\n\t<td><b>Pages:</b></td>\n\t<td> </td>" . "\n\t<td>\n\t\t<select name=\"pagesSelector\">\n\t\t\t<option>contains</option>\n\t\t\t<option>does not contain</option>\n\t\t\t<option>is equal to</option>\n\t\t\t<option>is not equal to</option>\n\t\t\t<option>starts with</option>\n\t\t\t<option>ends with</option>\n\t\t</select>\n\t</td>" . "\n\t<td><input type=\"text\" name=\"pagesNo\" size=\"42\"></td>" . "\n</tr>" . "\n<tr>" . "\n\t<td width=\"20\" valign=\"middle\"><input type=\"checkbox\" name=\"showPublisher\" value=\"1\"></td>" . "\n\t<td width=\"40\"><b>Publisher:</b></td>\n\t<td width=\"10\"> </td>" . "\n\t<td width=\"130\">\n\t\t<select name=\"publisherSelector\">\n\t\t\t<option>contains</option>\n\t\t\t<option>does not contain</option>\n\t\t\t<option>is equal to</option>\n\t\t\t<option>is not equal to</option>\n\t\t\t<option>starts with</option>\n\t\t\t<option>ends with</option>\n\t\t</select>\n\t</td>" . "\n\t<td><input type=\"text\" name=\"publisherName\" size=\"42\"></td>" . "\n</tr>" . "\n<tr>" . "\n\t<td width=\"20\" valign=\"middle\"><input type=\"checkbox\" name=\"showPlace\" value=\"1\"></td>" . "\n\t<td width=\"40\"><b>Place:</b></td>\n\t<td width=\"10\"> </td>" . "\n\t<td width=\"130\">\n\t\t<select name=\"placeSelector\">\n\t\t\t<option>contains</option>\n\t\t\t<option>does not contain</option>\n\t\t\t<option>is equal to</option>\n\t\t\t<option>is not equal to</option>\n\t\t\t<option>starts with</option>\n\t\t\t<option>ends with</option>\n\t\t</select>\n\t</td>" . "\n\t<td><input type=\"text\" name=\"placeName\" size=\"42\"></td>" . "\n</tr>" . "\n<tr>" . "\n\t<td width=\"20\" valign=\"middle\"><input type=\"checkbox\" name=\"showCallNumber\" value=\"1\" checked></td>" . "\n\t<td width=\"40\"><b>Signature:</b></td>\n\t<td width=\"10\"> </td>" . "\n\t<td width=\"130\">\n\t\t<select name=\"callNumberSelector\">\n\t\t\t<option>contains</option>\n\t\t\t<option>does not contain</option>\n\t\t\t<option>is equal to</option>\n\t\t\t<option>is not equal to</option>\n\t\t\t<option>starts with</option>\n\t\t\t<option>ends with</option>\n\t\t</select>\n\t</td>" . "\n\t<td><input type=\"text\" name=\"callNumberName\" size=\"42\"></td>" . "\n</tr>" . "\n<tr>" . "\n\t<td width=\"20\" valign=\"middle\"><input type=\"checkbox\" name=\"showKeywords\" value=\"1\"></td>" . "\n\t<td width=\"40\"><b>Keywords:</b></td>\n\t<td width=\"10\"> </td>" . "\n\t<td width=\"130\">\n\t\t<select name=\"keywordsSelector\">\n\t\t\t<option>contains</option>\n\t\t\t<option>does not contain</option>\n\t\t\t<option>is equal to</option>\n\t\t\t<option>is not equal to</option>\n\t\t\t<option>starts with</option>\n\t\t\t<option>ends with</option>\n\t\t</select>\n\t</td>" . "\n\t<td><input type=\"text\" name=\"keywordsName\" size=\"42\"></td>" . "\n</tr>" . "\n<tr>" . "\n\t<td width=\"20\" valign=\"middle\"><input type=\"checkbox\" name=\"showNotes\" value=\"1\"></td>" . "\n\t<td width=\"40\"><b>Notes:</b></td>\n\t<td width=\"10\"> </td>" . "\n\t<td width=\"130\">\n\t\t<select name=\"notesSelector\">\n\t\t\t<option>contains</option>\n\t\t\t<option>does not contain</option>\n\t\t\t<option>is equal to</option>\n\t\t\t<option>is not equal to</option>\n\t\t\t<option>starts with</option>\n\t\t\t<option>ends with</option>\n\t\t</select>\n\t</td>" . "\n\t<td><input type=\"text\" name=\"notesName\" size=\"42\"></td>" . "\n</tr>" . "\n<tr>\n\t<td> </td>\n\t<td> </td>\n\t<td> </td>\n\t<td> </td>\n\t<td> </td>" . "\n</tr>" . "\n<tr>" . "\n\t<td> </td>" . "\n\t<td valign=\"top\"><b>Display Options:</b></td>\n\t<td> </td>" . "\n\t<td valign=\"middle\"><input type=\"checkbox\" name=\"showLinks\" value=\"1\" checked> Display Links</td>" . "\n\t<td valign=\"middle\">Show <input type=\"text\" name=\"showRows\" value=\"" . $showRows . "\" size=\"4\" title=\"" . $loc["DescriptionShowRecordsPerPage"] . "\"> records per page" . " <input type=\"submit\" value=\"Search\"></td>" . "\n</tr>" . "\n<tr>" . "\n\t<td> </td>\n\t<td> </td>\n\t<td> </td>\n\t<td> </td>\n\t<td> </td>" . "\n</tr>" . "\n<tr>" . "\n\t<td> </td>\n\t<td>1st sort by:</td>\n\t<td> </td>" . "\n\t<td>\n\t\t<select name=\"sortSelector1\">\n\t\t\t<option selected>author</option>\n\t\t\t<option>title</option>\n\t\t\t<option>year</option>\n\t\t\t<option>editor</option>\n\t\t\t<option>series_title</option>\n\t\t\t<option>series_volume</option>\n\t\t\t<option>pages</option>\n\t\t\t<option>publisher</option>\n\t\t\t<option>place</option>\n\t\t\t<option>call_number</option>\n\t\t\t<option>keywords</option>\n\t\t\t<option>notes</option>\n\t\t</select>\n\t</td>" . "\n\t<td>\n\t\t<input type=\"radio\" name=\"sortRadio1\" value=\"0\" checked> ascending " . "\n\t\t<input type=\"radio\" name=\"sortRadio1\" value=\"1\"> descending\n\t</td>" . "\n</tr>" . "\n<tr>" . "\n\t<td> </td>\n\t<td>2nd sort by:</td>\n\t<td> </td>" . "\n\t<td>\n\t\t<select name=\"sortSelector2\">\n\t\t\t<option>author</option>\n\t\t\t<option>title</option>\n\t\t\t<option selected>year</option>\n\t\t\t<option>editor</option>\n\t\t\t<option>series_title</option>\n\t\t\t<option>series_volume</option>\n\t\t\t<option>pages</option>\n\t\t\t<option>publisher</option>\n\t\t\t<option>place</option>\n\t\t\t<option>call_number</option>\n\t\t\t<option>keywords</option>\n\t\t\t<option>notes</option>\n\t\t</select>\n\t</td>" . "\n\t<td>\n\t\t<input type=\"radio\" name=\"sortRadio2\" value=\"0\"> ascending " . "\n\t\t<input type=\"radio\" name=\"sortRadio2\" value=\"1\" checked> descending\n\t</td>" . "\n</tr>" . "\n<tr>" . "\n\t<td> </td>\n\t<td>3rd sort by:</td>\n\t<td> </td>" . "\n\t<td>\n\t\t<select name=\"sortSelector3\">\n\t\t\t<option>author</option>\n\t\t\t<option selected>title</option>\n\t\t\t<option>year</option>\n\t\t\t<option>editor</option>\n\t\t\t<option>series_title</option>\n\t\t\t<option>series_volume</option>\n\t\t\t<option>pages</option>\n\t\t\t<option>publisher</option>\n\t\t\t<option>place</option>\n\t\t\t<option>call_number</option>\n\t\t\t<option>keywords</option>\n\t\t\t<option>notes</option>\n\t\t</select>\n\t</td>" . "\n\t<td>\n\t\t<input type=\"radio\" name=\"sortRadio3\" value=\"0\" checked> ascending " . "\n\t\t<input type=\"radio\" name=\"sortRadio3\" value=\"1\"> descending\n\t</td>" . "\n</tr>" . "\n</table>" . "\n</form>"; // (5) Close the database connection: disconnectFromMySQLDatabase(); // function 'disconnectFromMySQLDatabase()' is defined in 'include.inc.php' // -------------------------------------------------------------------- // DISPLAY THE HTML FOOTER: // call the 'showPageFooter()' and 'displayHTMLfoot()' functions (which are defined in 'footer.inc.php') showPageFooter($HeaderString); displayHTMLfoot(); // --------------------------------------------------------------------
// 2. Table that contains values // 3. The field name of the table's primary key // 4. Table name of the user data table // 5. The field name within the user data table that corresponds to the field in 3. // 6. The field name of the user ID field within the user data table // 7. The user ID of the currently logged in user (which must be provided as a session variable) // 8. Attribute that contains values // 9. <SELECT> element name // 10. An additional non-database value (display string) // 11. String that gets submitted instead of the display string given in 10. // 12. Optional <OPTION SELECTED> // 13. Restrict query to field... (keep empty if no restriction wanted) // 14. ...where field contents are... // 15. Split field contents into substrings? (yes = true, no = false) // 16. POSIX-PATTERN to split field contents into substrings (in order to obtain actual values) echo selectDistinct($connection, $tableRefs, "serial", $tableUserData, "record_id", "user_id", $loginUserID, "user_groups", "userGroupsName", $loc["All"], "All", $loc["All"], "", "", true, " *[,;()] *"); ?> </td> </tr> <tr> <td> </td> <td align="right"><?php echo $loc["or"]; ?> :</td> <td align="center"><input type="radio" name="userGroupsRadio" value="0"></td> <td> <select name="userGroupsSelector2"><?php echo $dropDownItems1; ?>