You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

308 lines
13 KiB

  1. <?php
  2. // Project: Web Reference Database (refbase) <http://www.refbase.net>
  3. // Copyright: Matthias Steffens <mailto:refbase@extracts.de> and the file's
  4. // original author(s).
  5. //
  6. // This code is distributed in the hope that it will be useful,
  7. // but WITHOUT ANY WARRANTY. Please see the GNU General Public
  8. // License for more details.
  9. //
  10. // File: ./simple_search.php
  11. // Repository: $HeadURL: file:///svn/p/refbase/code/branches/bleeding-edge/simple_search.php $
  12. // Author(s): Matthias Steffens <mailto:refbase@extracts.de>
  13. //
  14. // Created: 29-Jul-02, 16:39
  15. // Modified: $Date: 2012-02-27 20:25:30 +0000 (Mon, 27 Feb 2012) $
  16. // $Author: msteffens $
  17. // $Revision: 1337 $
  18. // Search form providing access to the main fields of the database.
  19. // It offers some output options (like how many records to display per page)
  20. // and let's you specify the output sort order (up to three levels deep).
  21. // Incorporate some include files:
  22. include 'initialize/db.inc.php'; // 'db.inc.php' is included to hide username and password
  23. include 'includes/header.inc.php'; // include header
  24. include 'includes/footer.inc.php'; // include footer
  25. include 'includes/include.inc.php'; // include common functions
  26. include 'initialize/ini.inc.php'; // include common variables
  27. // --------------------------------------------------------------------
  28. // START A SESSION:
  29. // call the 'start_session()' function (from 'include.inc.php') which will also read out available session variables:
  30. start_session(true);
  31. // --------------------------------------------------------------------
  32. // Initialize preferred display language:
  33. // (note that 'locales.inc.php' has to be included *after* the call to the 'start_session()' function)
  34. include 'includes/locales.inc.php'; // include the locales
  35. // --------------------------------------------------------------------
  36. // (1) Open the database connection and use the literature database:
  37. connectToMySQLDatabase(); // function 'connectToMySQLDatabase()' is defined in 'include.inc.php'
  38. // If there's no stored message available:
  39. if (!isset($_SESSION['HeaderString']))
  40. $HeaderString = $loc["SearchMain"].":"; // Provide the default message
  41. else
  42. {
  43. $HeaderString = $_SESSION['HeaderString']; // extract 'HeaderString' session variable (only necessary if register globals is OFF!)
  44. // Note: though we clear the session variable, the current message is still available to this script via '$HeaderString':
  45. deleteSessionVariable("HeaderString"); // function 'deleteSessionVariable()' is defined in 'include.inc.php'
  46. }
  47. // Extract the view type requested by the user (either 'Mobile', 'Print', 'Web' or ''):
  48. // ('' will produce the default 'Web' output style)
  49. if (isset($_REQUEST['viewType']))
  50. $viewType = $_REQUEST['viewType'];
  51. else
  52. $viewType = "";
  53. // Get the default number of records per page preferred by the current user:
  54. $showRows = $_SESSION['userRecordsPerPage'];
  55. // Get the user's preference for displaying auto-completions:
  56. $showAutoCompletions = $_SESSION['userAutoCompletions'];
  57. // Show the login status:
  58. showLogin(); // (function 'showLogin()' is defined in 'include.inc.php')
  59. // (2a) Display header:
  60. // call the 'displayHTMLhead()' and 'showPageHeader()' functions (which are defined in 'header.inc.php'):
  61. displayHTMLhead(encodeHTML($officialDatabaseName) . " -- " . $loc["SimpleSearch"], "index,follow", "Search the " . encodeHTML($officialDatabaseName), "", false, "", $viewType, array());
  62. showPageHeader($HeaderString);
  63. // Define variables holding common drop-down elements, i.e. build properly formatted <option> tag elements:
  64. $dropDownConditionals1Array = array("contains" => $loc["contains"],
  65. "does not contain" => $loc["contains not"],
  66. "is equal to" => $loc["equal to"],
  67. "is not equal to" => $loc["equal to not"],
  68. "starts with" => $loc["starts with"],
  69. "ends with" => $loc["ends with"]);
  70. $dropDownItems1 = buildSelectMenuOptions($dropDownConditionals1Array, "//", "\t\t\t", true); // function 'buildSelectMenuOptions()' is defined in 'include.inc.php'
  71. $dropDownConditionals2Array = array("is greater than" => $loc["is greater than"],
  72. "is less than" => $loc["is less than"],
  73. "is within range" => $loc["is within range"],
  74. "is within list" => $loc["is within list"]);
  75. $dropDownItems2 = buildSelectMenuOptions($dropDownConditionals2Array, "//", "\t\t\t", true); // function 'buildSelectMenuOptions()' is defined in 'include.inc.php'
  76. // TODO: if possible, we should use function 'mapFieldNames()' here
  77. $dropDownFieldNameArray = array("author" => $loc["DropDownFieldName_Author"],
  78. "title" => $loc["DropDownFieldName_Title"],
  79. "year" => $loc["DropDownFieldName_Year"],
  80. "publication" => $loc["DropDownFieldName_Publication"],
  81. "volume_numeric" => $loc["DropDownFieldName_Volume"], // 'volume_numeric' is used instead of 'volume' in the sort dropdown menus
  82. "pages" => $loc["DropDownFieldName_Pages"]);
  83. $dropDownItems3 = buildSelectMenuOptions($dropDownFieldNameArray, "//", "\t\t\t", true); // function 'buildSelectMenuOptions()' is defined in 'include.inc.php'
  84. // Build HTML elements that allow for search suggestions for text entered by the user:
  85. if (isset($_SESSION['userAutoCompletions']) AND ($_SESSION['userAutoCompletions'] == "yes"))
  86. {
  87. $authorSuggestElements = buildSuggestElements("authorName", "authorSuggestions", "authorSuggestProgress", "col-author-"); // function 'buildSuggestElements()' is defined in 'include.inc.php'
  88. $titleSuggestElements = buildSuggestElements("titleName", "titleSuggestions", "titleSuggestProgress", "col-title-");
  89. $yearSuggestElements = buildSuggestElements("yearNo", "yearSuggestions", "yearSuggestProgress", "col-year-");
  90. $publicationSuggestElements = buildSuggestElements("publicationName2", "publicationSuggestions", "publicationSuggestProgress", "col-publication-");
  91. $volumeSuggestElements = buildSuggestElements("volumeNo", "volumeSuggestions", "volumeSuggestProgress", "col-volume-");
  92. $pagesSuggestElements = buildSuggestElements("pagesNo", "pagesSuggestions", "pagesSuggestProgress", "col-pages-");
  93. }
  94. else
  95. {
  96. $authorSuggestElements = "";
  97. $titleSuggestElements = "";
  98. $yearSuggestElements = "";
  99. $publicationSuggestElements = "";
  100. $volumeSuggestElements = "";
  101. $pagesSuggestElements = "";
  102. }
  103. // (2b) Start <form> and <table> holding the form elements:
  104. ?>
  105. <form action="search.php" method="GET" name="simpleSearch">
  106. <input type="hidden" name="formType" value="simpleSearch">
  107. <input type="hidden" name="showQuery" value="0">
  108. <table align="center" border="0" cellpadding="0" cellspacing="10" width="95%" summary="This table holds the search form">
  109. <tr>
  110. <th align="left"><?php echo $loc["Show"]; ?></th>
  111. <th align="left"><?php echo $loc["Field"]; ?></th>
  112. <th align="left"><?php echo $loc["That..."]; ?></th>
  113. <th align="left"><?php echo $loc["Searchstring"]; ?></th>
  114. </tr>
  115. <tr>
  116. <td width="20" valign="middle"><input type="checkbox" id="showAuthor" name="showAuthor" value="1" checked></td>
  117. <td width="40"><b><?php echo $loc["Author"]; ?>:</b></td>
  118. <td width="125">
  119. <select id="authorSelector" name="authorSelector"><?php echo $dropDownItems1; ?>
  120. </select>
  121. </td>
  122. <td>
  123. <input type="text" id="authorName" name="authorName" size="42"><?php echo $authorSuggestElements; ?>
  124. </td>
  125. </tr>
  126. <tr>
  127. <td valign="middle"><input type="checkbox" id="showTitle" name="showTitle" value="1" checked></td>
  128. <td><b><?php echo $loc["Title"]; ?>:</b></td>
  129. <td>
  130. <select id="titleSelector" name="titleSelector"><?php echo $dropDownItems1; ?>
  131. </select>
  132. </td>
  133. <td>
  134. <input type="text" id="titleName" name="titleName" size="42"><?php echo $titleSuggestElements; ?>
  135. </td>
  136. </tr>
  137. <tr>
  138. <td valign="middle"><input type="checkbox" id="showYear" name="showYear" value="1" checked></td>
  139. <td><b><?php echo $loc["Year"]; ?>:</b></td>
  140. <td>
  141. <select id="yearSelector" name="yearSelector"><?php echo $dropDownItems1 . $dropDownItems2; ?>
  142. </select>
  143. </td>
  144. <td>
  145. <input type="text" id="yearNo" name="yearNo" size="42"><?php echo $yearSuggestElements; ?>
  146. </td>
  147. </tr>
  148. <tr>
  149. <td valign="middle"><input type="checkbox" id="showPublication" name="showPublication" value="1" checked></td>
  150. <td><b><?php echo $loc["Publication"]; ?>:</b></td>
  151. <td>
  152. <input type="hidden" id="publicationRadioB" name="publicationRadio" value="0">
  153. <select id="publicationSelector2" name="publicationSelector2"><?php echo $dropDownItems1; ?>
  154. </select>
  155. </td>
  156. <td>
  157. <input type="text" id="publicationName2" name="publicationName2" size="42"><?php echo $publicationSuggestElements; ?>
  158. </td>
  159. </tr>
  160. <tr>
  161. <td valign="middle"><input type="checkbox" id="showVolume" name="showVolume" value="1" checked></td>
  162. <td><b><?php echo $loc["Volume"]; ?>:</b></td>
  163. <td>
  164. <select id="volumeSelector" name="volumeSelector"><?php echo $dropDownItems1 . $dropDownItems2; ?>
  165. </select>
  166. </td>
  167. <td>
  168. <input type="text" id="volumeNo" name="volumeNo" size="42"><?php echo $volumeSuggestElements; ?>
  169. </td>
  170. </tr>
  171. <tr>
  172. <td valign="middle"><input type="checkbox" id="showPages" name="showPages" value="1" checked></td>
  173. <td><b><?php echo $loc["Pages"]; ?>:</b></td>
  174. <td>
  175. <select id="pagesSelector" name="pagesSelector"><?php echo $dropDownItems1; ?>
  176. </select>
  177. </td>
  178. <td>
  179. <input type="text" id="pagesNo" name="pagesNo" size="42"><?php echo $pagesSuggestElements; ?>
  180. </td>
  181. </tr>
  182. <tr>
  183. <td>&nbsp;</td>
  184. <td>&nbsp;</td>
  185. <td>&nbsp;</td>
  186. <td>&nbsp;</td>
  187. </tr>
  188. <tr>
  189. <td>&nbsp;</td>
  190. <td valign="top"><b><?php echo $loc["DisplayOptions"]; ?>:</b></td>
  191. <td valign="middle"><input type="checkbox" id="showLinks" name="showLinks" value="1" checked>&nbsp;&nbsp;&nbsp;<?php echo $loc["ShowLinks"]; ?></td>
  192. <td valign="middle"><?php echo $loc["ShowRecordsPerPage_Prefix"]; ?>&nbsp;&nbsp;&nbsp;<input type="text" id="showRows" name="showRows" value="<?php echo $showRows; ?>" size="4" title="<?php echo $loc["DescriptionShowRecordsPerPage"]; ?>">&nbsp;&nbsp;&nbsp;<?php echo $loc["ShowRecordsPerPage_Suffix"]; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="<?php echo $loc["ButtonTitle_Search"]; ?>"></td>
  193. </tr>
  194. <tr>
  195. <td>&nbsp;</td>
  196. <td>&nbsp;</td>
  197. <td>&nbsp;</td>
  198. <td>&nbsp;</td>
  199. </tr>
  200. <tr>
  201. <td>&nbsp;</td>
  202. <td>1.&nbsp;<?php echo $loc["sort by"]; ?>:</td>
  203. <td>
  204. <select id="sortSelector1" name="sortSelector1"><?php
  205. $sortSelector1DropDownItems = preg_replace("/<option([^>]*)>" . $loc["DropDownFieldName_Author"] . "/", "<option\\1 selected>" . $loc["DropDownFieldName_Author"], $dropDownItems3); // select the 'author' menu entry ...
  206. echo $sortSelector1DropDownItems;
  207. ?>
  208. </select>
  209. </td>
  210. <td>
  211. <input type="radio" id="sortRadio1A" name="sortRadio1" value="0" checked>&nbsp;&nbsp;&nbsp;<?php echo $loc["ascending"]; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  212. <input type="radio" id="sortRadio1B" name="sortRadio1" value="1">&nbsp;&nbsp;&nbsp;<?php echo $loc["descending"]; ?>
  213. </td>
  214. </tr>
  215. <tr>
  216. <td>&nbsp;</td>
  217. <td>2.&nbsp;<?php echo $loc["sort by"]; ?>:</td>
  218. <td>
  219. <select id="sortSelector2" name="sortSelector2"><?php
  220. $sortSelector2DropDownItems = preg_replace("/<option([^>]*)>" . $loc["DropDownFieldName_Year"] . "/", "<option\\1 selected>" . $loc["DropDownFieldName_Year"], $dropDownItems3); // select the 'year' menu entry ...
  221. echo $sortSelector2DropDownItems;
  222. ?>
  223. </select>
  224. </td>
  225. <td>
  226. <input type="radio" id="sortRadio2A" name="sortRadio2" value="0">&nbsp;&nbsp;&nbsp;<?php echo $loc["ascending"]; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  227. <input type="radio" id="sortRadio2B" name="sortRadio2" value="1" checked>&nbsp;&nbsp;&nbsp;<?php echo $loc["descending"]; ?>
  228. </td>
  229. </tr>
  230. <tr>
  231. <td>&nbsp;</td>
  232. <td>3.&nbsp;<?php echo $loc["sort by"]; ?>:</td>
  233. <td>
  234. <select id="sortSelector3" name="sortSelector3"><?php
  235. $sortSelector3DropDownItems = preg_replace("/<option([^>]*)>" . $loc["DropDownFieldName_Publication"] . "/", "<option\\1 selected>" . $loc["DropDownFieldName_Publication"], $dropDownItems3); // select the 'publication' menu entry ...
  236. echo $sortSelector3DropDownItems;
  237. ?>
  238. </select>
  239. </td>
  240. <td>
  241. <input type="radio" id="sortRadio3A" name="sortRadio3" value="0" checked>&nbsp;&nbsp;&nbsp;<?php echo $loc["ascending"]; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  242. <input type="radio" id="sortRadio3B" name="sortRadio3" value="1">&nbsp;&nbsp;&nbsp;<?php echo $loc["descending"]; ?>
  243. </td>
  244. </tr>
  245. </table>
  246. </form><?php
  247. // (5) Close the database connection:
  248. disconnectFromMySQLDatabase(); // function 'disconnectFromMySQLDatabase()' is defined in 'include.inc.php'
  249. // --------------------------------------------------------------------
  250. // DISPLAY THE HTML FOOTER:
  251. // call the 'showPageFooter()' and 'displayHTMLfoot()' functions (which are defined in 'footer.inc.php')
  252. showPageFooter($HeaderString);
  253. displayHTMLfoot();
  254. // --------------------------------------------------------------------
  255. ?>