Skip to content

Latest commit

 

History

History
454 lines (370 loc) · 13.7 KB

listandsearch.php

File metadata and controls

454 lines (370 loc) · 13.7 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
function render_extension_list($wantname, $query)
{
$count = db_num_rows($query);
if (($wantname) and ($count > 1))
write_error('(Unexpected number of results from database!)');
Jun 22, 2004
Jun 22, 2004
16
print("Extensions:\n<ul>\n");
Jun 14, 2004
Jun 14, 2004
17
18
19
20
21
22
23
24
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
function render_token_list($wantname, $query)
{
$count = db_num_rows($query);
if (($wantname) and ($count > 1))
write_error('(Unexpected number of results from database!)');
Jun 22, 2004
Jun 22, 2004
31
print("Tokens:\n<ul>\n");
Jun 14, 2004
Jun 14, 2004
32
33
34
35
36
37
38
39
40
41
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 15, 2004
Jun 15, 2004
43
44
45
46
47
48
function render_entrypoint_list($wantname, $query)
{
$count = db_num_rows($query);
if (($wantname) and ($count > 1))
write_error('(Unexpected number of results from database!)');
Jun 22, 2004
Jun 22, 2004
49
print("Entry points:\n<ul>\n");
Jun 15, 2004
Jun 15, 2004
50
51
52
53
54
55
56
57
58
59
while ( ($row = db_fetch_array($query)) != false )
{
$url = get_alext_url($row['extname']);
print(" <li>${row['entrypointname']} ");
print(" from <a href='$url'>${row['extname']}</a>\n");
} // while
print("</ul>\n<p>Total results: $count\n");
} // render_entrypoint_list
Jun 12, 2004
Jun 12, 2004
60
61
62
$queryfuncs['extension'] = 'find_extension';
function find_extension($wantname)
{
Jun 14, 2004
Jun 14, 2004
63
$sql = 'select extname from alextreg_extensions' .
Jun 15, 2004
Jun 15, 2004
64
' where (1=1)';
Jun 14, 2004
Jun 14, 2004
65
66
if (!is_authorized_vendor())
Jun 22, 2004
Jun 22, 2004
67
$sql .= " and (public=1)";
Jun 12, 2004
Jun 12, 2004
68
69
70
71
if ($wantname)
{
$sqlwantname = db_escape_string($wantname);
Jun 14, 2004
Jun 14, 2004
72
$sql .= " and (extname='$sqlwantname')";
Jun 12, 2004
Jun 12, 2004
73
74
75
76
77
78
} // if
$query = do_dbquery($sql);
if ($query == false)
return; // error output is handled in database.php ...
else
Jun 14, 2004
Jun 14, 2004
79
render_extension_list($wantname, $query);
Jun 12, 2004
Jun 12, 2004
80
81
82
83
84
85
86
db_free_result($query);
} // find_extension
function find_token($additionalsql, $wantname)
{
Jun 12, 2004
Jun 12, 2004
87
88
$sql = 'select tok.tokenname as tokenname,' .
' tok.tokenval as tokenval,' .
Jun 13, 2004
Jun 13, 2004
89
' ext.extname as extname' .
Jun 12, 2004
Jun 12, 2004
90
91
' from alextreg_tokens as tok' .
' left outer join alextreg_extensions as ext' .
Jun 15, 2004
Jun 15, 2004
92
' on tok.extid=ext.id where (1=1)' .
Jun 12, 2004
Jun 12, 2004
93
94
$additionalsql;
Jun 14, 2004
Jun 14, 2004
95
if (!is_authorized_vendor())
Jun 22, 2004
Jun 22, 2004
96
$sql .= " and (ext.public=1)";
Jun 14, 2004
Jun 14, 2004
97
Jun 12, 2004
Jun 12, 2004
98
99
100
101
$query = do_dbquery($sql);
if ($query == false)
return; // error output is handled in database.php ...
else
Jun 14, 2004
Jun 14, 2004
102
render_token_list($wantname, $query);
Jun 12, 2004
Jun 12, 2004
103
104
105
106
107
108
109
110
111
112
113
114
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
115
$additionalsql .= " and (tok.tokenname='$sqlwantname')";
Jun 12, 2004
Jun 12, 2004
116
117
118
119
120
121
} // if
find_token($additionalsql, $wantname);
} // find_tokenname
Jun 12, 2004
Jun 12, 2004
122
$queryfuncs['tokenvalue'] = 'find_tokenvalue';
Jun 12, 2004
Jun 12, 2004
123
124
125
126
127
function find_tokenvalue($wantname)
{
$additionalsql = '';
if ($wantname)
{
Jun 15, 2004
Jun 15, 2004
128
129
if (!is_numeric($wantname))
return;
Jun 15, 2004
Jun 15, 2004
130
$sqlwantname = db_escape_string($wantname);
Jun 15, 2004
Jun 15, 2004
131
$additionalsql .= " and (tok.tokenval=$sqlwantname)";
Jun 12, 2004
Jun 12, 2004
132
133
134
} // if
find_token($additionalsql, $wantname);
Jun 13, 2004
Jun 13, 2004
135
} // find_tokenvalue
Jun 12, 2004
Jun 12, 2004
136
137
138
139
140
$queryfuncs['entrypoint'] = 'find_entrypoint';
function find_entrypoint($wantname)
{
Jun 13, 2004
Jun 13, 2004
141
142
143
144
$sql = 'select ent.entrypointname as entrypointname,' .
' ext.extname as extname' .
' from alextreg_entrypoints as ent' .
' left outer join alextreg_extensions as ext' .
Jun 15, 2004
Jun 15, 2004
145
' on ent.extid=ext.id where (1=1)';
Jun 14, 2004
Jun 14, 2004
146
147
if (!is_authorized_vendor())
Jun 22, 2004
Jun 22, 2004
148
$sql .= " and (ext.public=1)";
Jun 13, 2004
Jun 13, 2004
149
150
151
152
if ($wantname)
{
$sqlwantname = db_escape_string($wantname);
Jun 14, 2004
Jun 14, 2004
153
$sql .= " and (ent.entrypointname='$sqlwantname')";
Jun 13, 2004
Jun 13, 2004
154
155
156
157
158
159
} // if
$query = do_dbquery($sql);
if ($query == false)
return; // error output is handled in database.php ...
else
Jun 15, 2004
Jun 15, 2004
160
render_entrypoint_list($wantname, $query);
Jun 13, 2004
Jun 13, 2004
161
162
db_free_result($query);
Jun 12, 2004
Jun 12, 2004
163
164
165
166
167
168
} // find_entrypoint
$queryfuncs['anything'] = 'find_anything';
function find_anything($wantname)
{
Jun 13, 2004
Jun 13, 2004
169
170
171
172
find_extension($wantname);
find_tokenname($wantname);
find_tokenvalue($wantname);
find_entrypoint($wantname);
Jun 12, 2004
Jun 12, 2004
173
174
} // find_anything
Jun 11, 2004
Jun 11, 2004
175
Jun 12, 2004
Jun 12, 2004
176
function do_find($wanttype, $wantname = NULL)
Jun 11, 2004
Jun 11, 2004
177
{
Jun 12, 2004
Jun 12, 2004
178
179
global $queryfuncs;
Jun 12, 2004
Jun 12, 2004
180
181
182
183
184
185
186
187
$queryfunc = $queryfuncs[$wanttype];
if (!isset($queryfunc))
{
write_error('Invalid search type.');
return;
} // if
$queryfunc($wantname);
Jun 13, 2004
Jun 13, 2004
188
189
echo "\n<hr>\n";
Jun 12, 2004
Jun 12, 2004
190
191
192
193
194
195
} // do_find
$operations['op_findone'] = 'op_findone';
function op_findone()
{
Jun 22, 2004
Jun 22, 2004
196
197
if (!get_input_string('wanttype', 'Database field type', $wanttype)) return;
if (!get_input_string('wantname', 'Database field name', $wantname)) return;
Jun 12, 2004
Jun 12, 2004
198
write_debug("called op_findone($wanttype, $wantname)");
Jun 12, 2004
Jun 12, 2004
199
do_find($wanttype, $wantname);
Jun 12, 2004
Jun 12, 2004
200
} // op_findone
Jun 11, 2004
Jun 11, 2004
201
202
Jun 14, 2004
Jun 14, 2004
203
204
function show_one_extension($extrow)
{
Jun 22, 2004
Jun 22, 2004
205
206
$is_vendor = is_authorized_vendor();
Jun 14, 2004
Jun 14, 2004
207
208
$extname = $extrow['extname'];
$extid = $extrow['id'];
Jun 22, 2004
Jun 22, 2004
209
$public = $extrow['public'];
Jun 14, 2004
Jun 14, 2004
210
$wikiurl = get_alext_wiki_url($extname);
Jun 15, 2004
Jun 15, 2004
211
$htmlextname = htmlentities($extname, ENT_QUOTES);
Jun 22, 2004
Jun 22, 2004
212
213
214
215
if ((!$public) and (!$is_vendor)) // sanity check.
return;
Jun 15, 2004
Jun 15, 2004
216
echo "<p>$htmlextname (<a href='${wikiurl}'>docs</a>)\n";
Jun 22, 2004
Jun 22, 2004
217
Jun 22, 2004
Jun 22, 2004
218
$tab = '&nbsp;&nbsp;&nbsp;&nbsp;';
Jun 22, 2004
Jun 22, 2004
219
echo "<p><font size='-1'>\n";
Jun 22, 2004
Jun 22, 2004
220
221
echo "${tab}Registered on ${extrow['entrydate']} by ${extrow['author']}<br>\n";
echo "${tab}Last edited on ${extrow['lastedit']} by ${extrow['lasteditauthor']}<br>\n";
Jun 22, 2004
Jun 22, 2004
222
223
echo "</font>\n";
Jun 22, 2004
Jun 22, 2004
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
// get the tokens, move it to an array of db rows...
$tokens = array();
$sql = "select * from alextreg_tokens where (extid=$extid)";
if (!$is_vendor)
$sql .= ' and (ext.public=1)';
$query = do_dbquery($sql);
if ($query == false)
return; // uh...?
while ( ($row = db_fetch_array($query)) != false )
$tokens[] = $row;
db_free_result($query);
$entrypoints = array();
$sql = "select * from alextreg_entrypoints where (extid=$extid)";
if (!$is_vendor)
$sql .= ' and (ext.public=1)';
$query = do_dbquery($sql);
if ($query == false)
return; // uh...?
while ( ($row = db_fetch_array($query)) != false )
$entrypoints[] = $row;
db_free_result($query);
Jun 22, 2004
Jun 22, 2004
249
250
if ($is_vendor)
{
Jun 22, 2004
Jun 22, 2004
251
echo "<p>\n";
Jun 22, 2004
Jun 22, 2004
252
echo "<table border='1'><tr><td><b>Vendor:</b></td></tr><tr><td>\n";
Jun 22, 2004
Jun 22, 2004
253
Jun 22, 2004
Jun 22, 2004
254
$toggle = (($public) ? 'n' : 'y');
Jun 22, 2004
Jun 22, 2004
255
$is = ($public) ? 'is' : 'is not';
Jun 22, 2004
Jun 22, 2004
256
echo "<form>\n";
Jun 22, 2004
Jun 22, 2004
257
258
echo "This extension $is publically visible.\n";
echo "<input type='hidden' name='extid' value='$extid'>\n";
Jun 22, 2004
Jun 22, 2004
259
echo "<input type='hidden' name='extname' value='$htmlextname'>\n";
Jun 22, 2004
Jun 22, 2004
260
261
262
echo "<input type='hidden' name='newval' value='$toggle'>\n";
echo "<input type='hidden' name='operation' value='op_showhideext'>\n";
echo "<input type='submit' name='form_submit' value='Toggle'>\n";
Jun 22, 2004
Jun 22, 2004
263
echo "</form>\n";
Jun 22, 2004
Jun 22, 2004
264
Jun 22, 2004
Jun 22, 2004
265
echo "<form>\n";
Jun 22, 2004
Jun 22, 2004
266
267
268
269
270
271
echo "Add a new token named <input type='text' name='tokname'>\n";
echo "with the value <input type='text' name='tokval'>.\n";
echo "<input type='hidden' name='extid' value='$extid'>\n";
echo "<input type='hidden' name='extname' value='$htmlextname'>\n";
echo "<input type='hidden' name='operation' value='op_addtoken'>\n";
echo "<input type='submit' name='form_submit' value='Go!'>\n";
Jun 22, 2004
Jun 22, 2004
272
echo "</form>\n";
Jun 22, 2004
Jun 22, 2004
273
Jun 22, 2004
Jun 22, 2004
274
echo "<form>\n";
Jun 22, 2004
Jun 22, 2004
275
276
277
278
279
echo "Add a new entry point named <input type='text' name='entrypointname'>\n";
echo "<input type='hidden' name='extid' value='$extid'>\n";
echo "<input type='hidden' name='extname' value='$htmlextname'>\n";
echo "<input type='hidden' name='operation' value='op_addentrypoint'>\n";
echo "<input type='submit' name='form_submit' value='Go!'>\n";
Jun 22, 2004
Jun 22, 2004
280
echo "</form>\n";
Jun 22, 2004
Jun 22, 2004
281
Jun 22, 2004
Jun 22, 2004
282
echo "<form>\n";
Jun 22, 2004
Jun 22, 2004
283
284
echo "I'd like to rename this extension to\n";
echo "<input type='text' name='newval' value=''>.\n";
Jun 22, 2004
Jun 22, 2004
285
286
echo "<input type='hidden' name='extid' value='$extid'>\n";
echo "<input type='hidden' name='extname' value='$htmlextname'>\n";
Jun 22, 2004
Jun 22, 2004
287
echo "<input type='hidden' name='operation' value='op_renameext'>\n";
Jun 22, 2004
Jun 22, 2004
288
289
290
echo "<input type='submit' name='form_submit' value='Go!'>\n";
echo "</form>\n";
Jun 22, 2004
Jun 22, 2004
291
echo "<form>\n";
Jun 22, 2004
Jun 22, 2004
292
echo "I'd like to delete this extension.\n";
Jun 22, 2004
Jun 22, 2004
293
294
echo "<input type='hidden' name='extid' value='$extid'>\n";
echo "<input type='hidden' name='extname' value='$htmlextname'>\n";
Jun 22, 2004
Jun 22, 2004
295
echo "<input type='hidden' name='operation' value='op_delext'>\n";
Jun 22, 2004
Jun 22, 2004
296
297
298
echo "<input type='submit' name='form_submit' value='Go!'>\n";
echo "</form>\n";
Jun 23, 2004
Jun 23, 2004
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
if (count($tokens))
{
echo "<form>\n";
echo "I want to delete the token named\n";
echo "<select name='tokname' size='1'>\n";
echo " <option value=''>...</option>\n";
foreach ($tokens as $row)
echo " <option value='${row['id']}'>${row['tokenname']}</option>\n";
echo "</select>\n";
echo "<input type='hidden' name='extid' value='$extid'>\n";
echo "<input type='hidden' name='extname' value='$htmlextname'>\n";
echo "<input type='hidden' name='operation' value='op_deltok'>\n";
echo "<input type='submit' name='form_submit' value='Go!'>\n";
echo "</form>\n";
} // if
if (count($entrypoints))
{
echo "<form>\n";
echo "I want to delete the entry point named\n";
echo "<select name='entname' size='1'>\n";
echo " <option value=''>...</option>\n";
foreach ($tokens as $row)
echo " <option value='${row['entrypointname']}'>${row['entrypointname']}</option>\n";
echo "</select>\n";
echo "<input type='hidden' name='extid' value='$extid'>\n";
echo "<input type='hidden' name='extname' value='$htmlextname'>\n";
echo "<input type='hidden' name='operation' value='op_delent'>\n";
echo "<input type='submit' name='form_submit' value='Go!'>\n";
echo "</form>\n";
} // if
Jun 22, 2004
Jun 22, 2004
331
echo "</td></tr></table>\n";
Jun 22, 2004
Jun 22, 2004
332
333
} // if
Jun 14, 2004
Jun 14, 2004
334
335
echo "<p>Tokens:\n<ul>\n";
Jun 22, 2004
Jun 22, 2004
336
if (count($tokens) == 0)
Jun 15, 2004
Jun 15, 2004
337
echo " <li> (no tokens.)\n";
Jun 14, 2004
Jun 14, 2004
338
339
else
{
Jun 22, 2004
Jun 22, 2004
340
foreach ($tokens as $row)
Jun 14, 2004
Jun 14, 2004
341
342
{
$hex = sprintf("0x%X", $row['tokenval']); // !!! FIXME: faster way to do this?
Jun 15, 2004
Jun 15, 2004
343
344
345
346
echo " <li> ${row['tokenname']} ($hex)";
//echo " added ${row['entrydate']},";
//echo " last modified ${row['lastedit']}";
echo "\n";
Jun 23, 2004
Jun 23, 2004
347
} // foreach
Jun 14, 2004
Jun 14, 2004
348
349
350
351
} // else
echo "</ul>\n";
echo "<p>Entry points:\n<ul>\n";
Jun 22, 2004
Jun 22, 2004
352
if (count($entrypoints) == 0)
Jun 15, 2004
Jun 15, 2004
353
echo " <li> (no entry points.)\n";
Jun 14, 2004
Jun 14, 2004
354
355
else
{
Jun 22, 2004
Jun 22, 2004
356
foreach ($entrypoints as $row)
Jun 14, 2004
Jun 14, 2004
357
{
Jun 15, 2004
Jun 15, 2004
358
359
360
361
echo " <li> ${row['entrypointname']}";
//echo " added ${row['entrydate']},";
//echo " last modified ${row['lastedit']}";
echo "\n";
Jun 23, 2004
Jun 23, 2004
362
} // foreach
Jun 14, 2004
Jun 14, 2004
363
} // else
Jun 14, 2004
Jun 14, 2004
364
Jun 14, 2004
Jun 14, 2004
365
366
367
368
369
370
echo "</ul>\n";
echo "<hr>\n";
} // show_one_extension
Jun 11, 2004
Jun 11, 2004
371
372
373
$operations['op_findall'] = 'op_findall';
function op_findall()
{
Jun 22, 2004
Jun 22, 2004
374
if (!get_input_string('wanttype', 'Database field type', $wanttype)) return;
Jun 12, 2004
Jun 12, 2004
375
write_debug("called op_findall($wanttype)");
Jun 12, 2004
Jun 12, 2004
376
do_find($wanttype);
Jun 12, 2004
Jun 12, 2004
377
} // op_findall
Jun 11, 2004
Jun 11, 2004
378
379
Jun 15, 2004
Jun 15, 2004
380
function do_showext($extname)
Jun 14, 2004
Jun 14, 2004
381
{
Jun 14, 2004
Jun 14, 2004
382
$sqlextname = db_escape_string($extname);
Jun 14, 2004
Jun 14, 2004
383
$sql = "select * from alextreg_extensions" .
Jun 14, 2004
Jun 14, 2004
384
" where extname='$sqlextname'";
Jun 14, 2004
Jun 14, 2004
385
Jun 14, 2004
Jun 14, 2004
386
if (!is_authorized_vendor())
Jun 22, 2004
Jun 22, 2004
387
$sql .= " and (public=1)";
Jun 14, 2004
Jun 14, 2004
388
Jun 14, 2004
Jun 14, 2004
389
390
391
392
393
394
395
396
397
398
399
400
401
$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);
Jun 15, 2004
Jun 15, 2004
402
403
404
405
406
407
} // do_showext
$operations['op_showext'] = 'op_showext';
function op_showext()
{
Jun 22, 2004
Jun 22, 2004
408
if (!get_input_string('extname', 'extension name', $extname)) return;
Jun 15, 2004
Jun 15, 2004
409
do_showext($extname);
Jun 14, 2004
Jun 14, 2004
410
411
} // op_showext
Jun 11, 2004
Jun 11, 2004
412
Jun 11, 2004
Jun 11, 2004
413
414
415
416
417
418
419
function render_search_ui()
{
print <<<EOF
<p>
Where do you want to go today?
Jun 22, 2004
Jun 22, 2004
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
<p>
<form method="post" action="${_SERVER['PHP_SELF']}">
I want a list of all known
<select name="wanttype" size="1">
<option selected value="extension">extensions</option>
<option value="tokenname">tokens</option>
<option value="entrypoint">entry points</option>
</select>.
<input type="hidden" name="operation" value="op_findall">
<input type="submit" name="form_submit" value="Go!">
</form>
<p>
...or...
Jun 11, 2004
Jun 11, 2004
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
<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!">
</form>
EOF;
} // render_search_ui
Jun 12, 2004
Jun 12, 2004
454
?>