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.

310 lines
13 KiB

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