Skip to content

Latest commit

 

History

History
373 lines (301 loc) · 10 KB

listandsearch.php

File metadata and controls

373 lines (301 loc) · 10 KB
 
Jun 11, 2004
Jun 11, 2004
1
2
<?php
Jun 11, 2004
Jun 11, 2004
3
require_once 'operations.php';
Jun 12, 2004
Jun 12, 2004
4
5
6
7
8
9
require_once 'database.php';
require_once 'common.php';
$queryfuncs = array();
Jun 14, 2004
Jun 14, 2004
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function render_extension_list($wantname, $query)
{
$count = db_num_rows($query);
if (($wantname) and ($count > 1))
write_error('(Unexpected number of results from database!)');
print("<ul>\n");
while ( ($row = db_fetch_array($query)) != false )
{
$url = get_alext_url($row['extname']);
print(" <li><a href='$url'>${row['extname']}</a>\n");
} // while
print("</ul>\n<p>Total results: $count\n");
} // render_extension_list
Jun 14, 2004
Jun 14, 2004
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function render_token_list($wantname, $query)
{
$count = db_num_rows($query);
if (($wantname) and ($count > 1))
write_error('(Unexpected number of results from database!)');
print("<ul>\n");
while ( ($row = db_fetch_array($query)) != false )
{
$url = get_alext_url($row['extname']);
$hex = sprintf("0x%X", $row['tokenval']); // !!! FIXME: faster way to do this?
print(" <li>${row['tokenname']} ($hex)");
print(" from <a href='$url'>${row['extname']}</a>\n");
} // while
print("</ul>\n<p>Total results: $count\n");
} // render_token_list
Jun 14, 2004
Jun 14, 2004
42
Jun 12, 2004
Jun 12, 2004
43
44
45
$queryfuncs['extension'] = 'find_extension';
function find_extension($wantname)
{
Jun 14, 2004
Jun 14, 2004
46
47
48
49
50
51
$flags = is_authorized_vendor() ?
$sql = 'select extname from alextreg_extensions' .
' where (1==1)';
if (!is_authorized_vendor())
$sql .= ' and (flags & $extflags_public)';
Jun 12, 2004
Jun 12, 2004
52
53
54
55
if ($wantname)
{
$sqlwantname = db_escape_string($wantname);
Jun 14, 2004
Jun 14, 2004
56
$sql .= " and (extname='$sqlwantname')";
Jun 12, 2004
Jun 12, 2004
57
58
59
60
61
62
} // if
$query = do_dbquery($sql);
if ($query == false)
return; // error output is handled in database.php ...
else
Jun 14, 2004
Jun 14, 2004
63
render_extension_list($wantname, $query);
Jun 12, 2004
Jun 12, 2004
64
65
66
67
68
69
70
db_free_result($query);
} // find_extension
function find_token($additionalsql, $wantname)
{
Jun 12, 2004
Jun 12, 2004
71
72
$sql = 'select tok.tokenname as tokenname,' .
' tok.tokenval as tokenval,' .
Jun 13, 2004
Jun 13, 2004
73
' ext.extname as extname' .
Jun 12, 2004
Jun 12, 2004
74
75
' from alextreg_tokens as tok' .
' left outer join alextreg_extensions as ext' .
Jun 14, 2004
Jun 14, 2004
76
' on tok.extid=ext.id where (1==1)' .
Jun 12, 2004
Jun 12, 2004
77
78
$additionalsql;
Jun 14, 2004
Jun 14, 2004
79
80
81
if (!is_authorized_vendor())
$sql .= ' and (ext.flags & $extflags_public)';
Jun 12, 2004
Jun 12, 2004
82
83
84
85
$query = do_dbquery($sql);
if ($query == false)
return; // error output is handled in database.php ...
else
Jun 14, 2004
Jun 14, 2004
86
render_token_list($wantname, $query);
Jun 12, 2004
Jun 12, 2004
87
88
89
90
91
92
93
94
95
96
97
98
db_free_result($query);
} // find_token
$queryfuncs['tokenname'] = 'find_tokenname';
function find_tokenname($wantname)
{
$additionalsql = '';
if ($wantname)
{
$sqlwantname = db_escape_string($wantname);
Jun 14, 2004
Jun 14, 2004
99
$additionalsql .= " and (tok.tokenname='$sqlwantname')";
Jun 12, 2004
Jun 12, 2004
100
101
102
103
104
105
} // if
find_token($additionalsql, $wantname);
} // find_tokenname
Jun 12, 2004
Jun 12, 2004
106
$queryfuncs['tokenvalue'] = 'find_tokenvalue';
Jun 12, 2004
Jun 12, 2004
107
108
109
110
111
112
function find_tokenvalue($wantname)
{
$additionalsql = '';
if ($wantname)
{
$sqlwantname = db_escape_string($wantname);
Jun 12, 2004
Jun 12, 2004
113
$additionalsql .= " where tok.tokenval='$sqlwantname'";
Jun 12, 2004
Jun 12, 2004
114
115
116
} // if
find_token($additionalsql, $wantname);
Jun 13, 2004
Jun 13, 2004
117
} // find_tokenvalue
Jun 12, 2004
Jun 12, 2004
118
119
120
121
122
$queryfuncs['entrypoint'] = 'find_entrypoint';
function find_entrypoint($wantname)
{
Jun 13, 2004
Jun 13, 2004
123
124
125
126
$sql = 'select ent.entrypointname as entrypointname,' .
' ext.extname as extname' .
' from alextreg_entrypoints as ent' .
' left outer join alextreg_extensions as ext' .
Jun 14, 2004
Jun 14, 2004
127
128
129
130
' on ent.extid=ext.id where (1==1)';
if (!is_authorized_vendor())
$sql .= ' and (ext.flags & $extflags_public)';
Jun 13, 2004
Jun 13, 2004
131
132
133
134
if ($wantname)
{
$sqlwantname = db_escape_string($wantname);
Jun 14, 2004
Jun 14, 2004
135
$sql .= " and (ent.entrypointname='$sqlwantname')";
Jun 13, 2004
Jun 13, 2004
136
137
138
139
140
141
142
143
144
145
146
147
148
149
} // if
$query = do_dbquery($sql);
if ($query == false)
return; // error output is handled in database.php ...
else
{
$count = db_num_rows($query);
if (($wantname) and ($count > 1))
write_error('(Unexpected number of results from database!)');
print("<ul>\n");
while ( ($row = db_fetch_array($query)) != false )
{
Jun 14, 2004
Jun 14, 2004
150
$url = get_alext_url($row['extname']);
Jun 13, 2004
Jun 13, 2004
151
152
153
154
155
156
157
print(" <li>${row['entrypointname']} ");
print(" from <a href='$url'>${row['extname']}</a>\n");
} // while
print("</ul>\n<p>Total results: $count\n");
} // else
db_free_result($query);
Jun 12, 2004
Jun 12, 2004
158
159
160
161
162
163
} // find_entrypoint
$queryfuncs['anything'] = 'find_anything';
function find_anything($wantname)
{
Jun 13, 2004
Jun 13, 2004
164
165
166
167
find_extension($wantname);
find_tokenname($wantname);
find_tokenvalue($wantname);
find_entrypoint($wantname);
Jun 12, 2004
Jun 12, 2004
168
169
} // find_anything
Jun 11, 2004
Jun 11, 2004
170
Jun 12, 2004
Jun 12, 2004
171
function do_find($wanttype, $wantname = NULL)
Jun 11, 2004
Jun 11, 2004
172
{
Jun 12, 2004
Jun 12, 2004
173
174
global $queryfuncs;
Jun 12, 2004
Jun 12, 2004
175
176
177
178
179
180
181
182
$queryfunc = $queryfuncs[$wanttype];
if (!isset($queryfunc))
{
write_error('Invalid search type.');
return;
} // if
$queryfunc($wantname);
Jun 13, 2004
Jun 13, 2004
183
184
echo "\n<hr>\n";
Jun 12, 2004
Jun 12, 2004
185
186
187
188
189
190
} // do_find
$operations['op_findone'] = 'op_findone';
function op_findone()
{
Jun 11, 2004
Jun 11, 2004
191
192
$wanttype = $_REQUEST['wanttype'];
$wantname = $_REQUEST['wantname'];
Jun 12, 2004
Jun 12, 2004
193
write_debug("called op_findone($wanttype, $wantname)");
Jun 12, 2004
Jun 12, 2004
194
Jun 12, 2004
Jun 12, 2004
195
196
197
198
199
200
if ( (empty($wantname)) or (empty($wanttype)) )
{
write_error('Please fill out all fields.');
return;
} // if
Jun 12, 2004
Jun 12, 2004
201
do_find($wanttype, $wantname);
Jun 12, 2004
Jun 12, 2004
202
} // op_findone
Jun 11, 2004
Jun 11, 2004
203
204
Jun 14, 2004
Jun 14, 2004
205
206
207
208
209
210
211
212
213
214
215
function show_one_extension($extrow)
{
$extname = $extrow['extname'];
$extid = $extrow['id'];
$wikiurl = get_alext_wiki_url($extname);
echo "<p>$extname (<a href='${wikiurl}'>docs</a>)\n";
echo "<p>Tokens:\n<ul>\n";
$sql = 'select * from alextreg_tokens as tok' .
' left outer join alextreg_extensions as ext' .
' on tok.extid=ext.id';
Jun 14, 2004
Jun 14, 2004
216
217
218
219
if (!is_authorized_vendor())
$sql .= ' where (ext.flags & $extflags_public)';
Jun 14, 2004
Jun 14, 2004
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
$query = do_dbquery($sql);
if ($query == false)
return; // uh...?
else if ($query == 0)
echo " <li> (no new tokens.)\n";
else
{
while ( ($row = db_fetch_array($query)) != false )
{
$hex = sprintf("0x%X", $row['tokenval']); // !!! FIXME: faster way to do this?
echo " <li> ${row['tokenname']} ($hex):";
echo " added ${row['entrydate']},";
echo " last modified ${row['lastedit']}\n";
} // while
} // else
Jun 14, 2004
Jun 14, 2004
235
db_free_result($query);
Jun 14, 2004
Jun 14, 2004
236
237
238
239
240
241
242
243
244
245
246
if (is_authorized_vendor())
{
echo " <li>\n<form>\n";
echo "Add a new token named <input type='text' name='wantname'>\n";
echo "<input type='hidden' name='extid' value='$extid'>\n";
echo "<input type='hidden' name='operation' value='op_addtoken'>\n";
echo "<input type='submit' name='form_submit' value='Go!'>\n";
echo "</form>\n";
} // if
Jun 14, 2004
Jun 14, 2004
247
248
249
250
251
252
253
echo "</ul>\n";
echo "<p>Entry points:\n<ul>\n";
$sql = 'select * from alextreg_entrypoints as ent' .
' left outer join alextreg_extensions as ext' .
' on ent.extid=ext.id';
Jun 14, 2004
Jun 14, 2004
254
255
256
if (!is_authorized_vendor())
$sql .= ' where (ext.flags & $extflags_public)';
Jun 14, 2004
Jun 14, 2004
257
258
259
260
261
262
263
264
265
266
267
268
269
270
$query = do_dbquery($sql);
if ($query == false)
return; // uh...?
else if ($query == 0)
echo " <li> (no new entry points.)\n";
else
{
while ( ($row = db_fetch_array($query)) != false )
{
echo " <li> ${row['entrypointname']}:";
echo " added ${row['entrydate']},";
echo " last modified ${row['lastedit']}\n";
} // while
} // else
Jun 14, 2004
Jun 14, 2004
271
db_free_result($query);
Jun 14, 2004
Jun 14, 2004
272
273
274
275
276
277
278
279
280
281
282
if (is_authorized_vendor())
{
echo " <li>\n<form>\n";
echo "Add a new entry point named <input type='text' name='wantname'>\n";
echo "<input type='hidden' name='extid' value='$extid'>\n";
echo "<input type='hidden' name='operation' value='op_addentrypoint'>\n";
echo "<input type='submit' name='form_submit' value='Go!'>\n";
echo "</form>\n";
} // if
Jun 14, 2004
Jun 14, 2004
283
284
285
286
287
288
echo "</ul>\n";
echo "<hr>\n";
} // show_one_extension
Jun 11, 2004
Jun 11, 2004
289
290
291
$operations['op_findall'] = 'op_findall';
function op_findall()
{
Jun 11, 2004
Jun 11, 2004
292
$wanttype = $_REQUEST['wanttype'];
Jun 12, 2004
Jun 12, 2004
293
write_debug("called op_findall($wanttype)");
Jun 12, 2004
Jun 12, 2004
294
do_find($wanttype);
Jun 12, 2004
Jun 12, 2004
295
} // op_findall
Jun 11, 2004
Jun 11, 2004
296
297
Jun 14, 2004
Jun 14, 2004
298
299
300
301
302
303
304
305
306
307
$operations['op_showext'] = 'op_showext';
function op_showext()
{
$extname = $_REQUEST['extname'];
if (empty($extname))
{
write_error('No extension specified.');
return;
} // if
Jun 14, 2004
Jun 14, 2004
308
$sqlextname = db_escape_string($extname);
Jun 14, 2004
Jun 14, 2004
309
$sql = "select * from alextreg_extensions" .
Jun 14, 2004
Jun 14, 2004
310
" where extname='$sqlextname'";
Jun 14, 2004
Jun 14, 2004
311
Jun 14, 2004
Jun 14, 2004
312
313
314
if (!is_authorized_vendor())
$sql .= ' and (flags & $extflags_public)';
Jun 14, 2004
Jun 14, 2004
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
$query = do_dbquery($sql);
if ($query == false)
return; // error output is handled in database.php ...
else if (db_num_rows($query) == 0)
write_error('No such extension.');
else
{
// just in case there's more than one for some reason...
while ( ($row = db_fetch_array($query)) != false )
show_one_extension($row);
} // else
db_free_result($query);
} // op_showext
Jun 11, 2004
Jun 11, 2004
330
Jun 11, 2004
Jun 11, 2004
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
function render_search_ui()
{
print <<<EOF
<p>
Where do you want to go today?
<p>
<form method="post" action="${_SERVER['PHP_SELF']}">
I want
<select name="wanttype" size="1">
<option selected value="extension">an extension</option>
<option value="tokenname">a token name</option>
<option value="tokenvalue">a token value</option>
<option value="entrypoint">an entry point</option>
<option value="anything">anything</option>
</select>
named <input type="text" name="wantname" value="">.
<input type="hidden" name="operation" value="op_findone">
<input type="submit" name="form_submit" value="Go!">
<input type="reset" value="Clear">
</form>
<p>
...or...
<p>
<form method="post" action="${_SERVER['PHP_SELF']}">
I want a list of all known
<select name="wanttype" size="1">
Jun 12, 2004
Jun 12, 2004
361
362
363
<option selected value="extension">extensions</option>
<option value="tokenname">tokens</option>
<option value="entrypoint">entry points</option>
Jun 11, 2004
Jun 11, 2004
364
365
366
367
368
369
370
371
372
</select>.
<input type="hidden" name="operation" value="op_findall">
<input type="submit" name="form_submit" value="Go!">
</form>
EOF;
} // render_search_ui
Jun 12, 2004
Jun 12, 2004
373
?>