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