source: trunk/gsdl/macros/query.dm@ 4175

Last change on this file since 4175 was 4175, checked in by kjdon, 21 years ago

changed the form searching stuff so that it doesn't use the escape function - this was causing trouble under windows for non latin characters. instead, have changed the format function to escape out any reserved characters (%, &, + etc) just in case these are entered in the box. haven't done all teh 'unsafe' characters, may need to do these too??

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 17.9 KB
Line 
1package query
2
3
4#######################################################################
5# Macros whose values are set from within the server at runtime. These
6# are here only for reference and to set default values if required.
7#######################################################################
8
9_quotedquery_ {}
10_freqmsg_ {}
11_resultline_ {}
12_thisfirst_ {}
13_thislast_ {}
14_nextfirst_ {}
15_nextlast_ {}
16_prevfirst_ {}
17_prevlast_ {}
18_searchhistorylist_ {}
19#_histvalue0_ to _histvalue19_
20_advformlist_ {}
21_regformlist_ {}
22_fqfselection_ {}
23
24
25#######################################################################
26# icons
27#######################################################################
28
29_iconthispage_ {<img src="_httpiconhsearch_" alt="_texticonthispage_" title="_texticonthispage_" width="_widthhsearch_" height="_heighthsearch_">}
30_iconthispage_ [v=1] {<h2>_texticonthispage_</h2>}
31
32_iconqueryresultsbar_ {<img src="_httpiconqryresb_" width="_widthqryresb_" height="_heightqryresb_" alt="_texticonqueryresultsbar_" title="_texticonqueryresultsbar_">}
33_iconqueryresultsbar_[v=1] {_texticonqueryresultsbar_}
34
35_iconsearchhistorybar_ {<img src="_httpiconsrchhistb_" width="_widthsrchhistb_" height="_heightsrchhistb_" alt="_texticonsearchhistorybar_" title="_texticonsearchhistorybar_">}
36_iconsearchhistorybar_[v=1] {_texticonsearchhistorybar_}
37
38# _iconnext_ and _iconprev_ are overridden in this package as we
39# don't want alt text here
40_iconnext_{<img src="_httpiconmore_" width=_widthmore_ height=_heightmore_ border=0 align=top>}
41_iconnext_ [v=1] {}
42_iconprev_{<img src="_httpiconless_" width=_widthless_ height=_heightless_ border=0 align=top>}
43_iconprev_ [v=1] {}
44
45# the small squares for search history
46## " " ## handmade ## mstds ##
47_httpiconmstdsqrof_ {_httpimg_/mstdsof.gif}
48_httpiconmstdsqron_ {_httpimg_/mstdson.gif}
49_widthmstdsqrx_ {13}
50_heightmstdsqrx_ {13}
51
52#######################################################################
53# images
54#######################################################################
55
56_imagethispage_ {_iconthispage_}
57
58#the buttons for the search history entries
59# takes one arg - the entry number (0-num entries)
60_imagehistbutton_ {<a href="_httpquery_" onMouseover="roll('histbutton_1_',1);" onMouseOut="roll('histbutton_1_',0);" onClick="inputQuery(histvalue_1_); return false;"><img name="histbutton_1_" src="_httpiconmstdsqrof_" onLoad="gbutton(this,'_httpiconmstdsqron_');" border=0 alt="_textusequery_" title="_textusequery_"></a>}
61
62
63#######################################################################
64# scripts (and some macros for the scripts)
65#######################################################################
66
67_pagescriptextra_ {_If_("_cgiargct_" eq "1" && "_cgiargqt_" eq "1",_formpagescriptextra_,_dummypagescriptextra_)
68_If_("_cgiarghd_" ne "0",_historypagescriptextra_) }
69
70_dummypagescriptextra_{
71function initialize() \{
72\}
73}
74_formpagescriptextra_ {
75// query scripts generated by \_query:pagescriptextra\_
76
77_standardfunctions_
78_formfunctions_
79_searchfunctions_
80
81function getsearchargs () \{
82
83 var args="";
84 args = "&fqa=0&fqv="+argfqv+"&fqf="+argfqf;
85 _If_(_cgiargb_,args += "&fqk="+argfqk+"&fqs="+argfqs+"&fqc="+argfqc;)
86
87 return args;
88\}
89
90
91
92function getqueryargs () \{
93 return "&fqa=1"+"&q="+argq+"&fqv="+argfqv+"&fqf="+argfqf+
94 "&fqk="+argfqk+"&fqs="+argfqs+"&fqc="+argfqc ;
95\}
96
97}
98
99_historypagescriptextra_{
100
101var histvalue0='_histvalue0_';
102var histvalue1='_histvalue1_';
103var histvalue2='_histvalue2_';
104var histvalue3='_histvalue3_';
105var histvalue4='_histvalue4_';
106var histvalue5='_histvalue5_';
107var histvalue6='_histvalue6_';
108var histvalue7='_histvalue7_';
109var histvalue8='_histvalue8_';
110var histvalue9='_histvalue9_';
111var histvalue10='_histvalue10_';
112var histvalue11='_histvalue11_';
113var histvalue12='_histvalue12_';
114var histvalue13='_histvalue13_';
115var histvalue14='_histvalue14_';
116var histvalue15='_histvalue15_';
117var histvalue16='_histvalue16_';
118var histvalue17='_histvalue17_';
119var histvalue18='_histvalue18_';
120var histvalue19='_histvalue19_';
121
122function inputQuery(value) \{
123 if ("_cgiargqt_" == "0") \{ // text search
124 document.QueryForm.q.value += " "+value;
125 \}
126 else \{
127 if ("_cgiargb_" == "1") \{ // advanced query
128 document.QueryForm.q.value += " "+value;
129 updateq();
130 \}
131 else \{ // simple form search
132 // do something here, what??
133 \}
134 \}
135\}
136
137}
138
139_standardfunctions_{
140
141 function getstdargs() \{
142
143 stdarg = "";
144 _If_(_cgiargh_,_getharg_)
145 _If_(_gselection_,_getgarg_)
146 _If_(_cgiargj_,_getjarg_)
147
148 value = document.QueryForm.t.options[document.QueryForm.t.selectedIndex].value;
149 if (value != "_cgiargt_") stdarg += "&t="+value;
150
151 stdarg += "&r=1&hs=1";
152 return stdarg;
153 \}
154
155}
156
157#some macros to go with getstdargs()
158_getharg_{
159 value = document.QueryForm.h.options[document.QueryForm.h.selectedIndex].value;
160 if (value != "_cgiargh_") stdarg += "&h="+value;
161}
162
163_getgarg_{
164 value = document.QueryForm.g.options[document.QueryForm.g.selectedIndex].value;
165 if (value != "_cgiargg_") stdarg += "&g="+value;
166}
167
168_getjarg_{
169 value = document.QueryForm.j.options[document.QueryForm.j.selectedIndex].value;
170 if (value != "_cgiargj_") stdarg += "&j="+value;
171}
172
173
174_formfunctions_{
175
176argfqf="_cgiargfqf_";
177argfqv="_cgiargfqv_";
178argfqk="_cgiargfqk_";
179argfqs="_cgiargfqs_";
180argfqc="_cgiargfqc_";
181argq = "";
182
183function initialize () \{
184
185 if (document.QueryForm.fqf != null) \{initfqf();\}
186 initfqv();
187 if ( "_cgiargb_" == "1") \{
188 initfqs();
189 initfqk();
190 initfqc();
191 initq();
192 \}
193
194\}
195
196// fqf - the field selection box
197function initfqf() \{
198 var i;
199 fqf = argfqf.split(",");
200 for (i=0; i<fqf.length; i++) \{
201 for (j=0;j<document.QueryForm.fqf[i].options.length;j++) \{
202 if (fqf[i] != "" && fqf[i]== document.QueryForm.fqf[i].options[j].value) \{
203 document.QueryForm.fqf[i].options[j].selected = true;
204 break;
205 \}
206 \}
207 \}
208 if (fqf.length < document.QueryForm.fqf.length) \{ // initialize remaining ones
209 var v=1; // the option with a null value is either at place 1 or 2
210 if (document.QueryForm.fqf[0].options[v].value !="") v++;
211 for (i=fqf.length;i<document.QueryForm.fqf.length;i++) \{
212 var z=i;
213 while (z >= document.QueryForm.fqf[i].options.length-1) \{
214 z = z-(document.QueryForm.fqf[i].options.length-1);
215 \}
216 if (z>=v)z++; // skip over the void value
217
218 document.QueryForm.fqf[i].options[z].selected = true;
219
220 \}
221 \}
222 updatefqf();
223
224\}
225
226function updatefqf() \{
227
228 var i;
229 argfqf = "";
230 var j = document.QueryForm.fqf[0].selectedIndex;
231 argfqf += document.QueryForm.fqf[0].options[j].value;
232 for (i=1; i<document.QueryForm.fqf.length;i++) \{
233 j = document.QueryForm.fqf[i].selectedIndex;
234 argfqf += "," + document.QueryForm.fqf[i].options[j].value;
235 \}
236
237\}
238
239
240function clearfqf() \{
241 var i;
242 for (i=0;i<document.QueryForm.fqf.length;i++) \{
243 var z = i;
244 if (i >= document.QueryForm.fqf[i].options.length) z = z-document.QueryForm.fqf[i].options.length;
245 document.QueryForm.fqf[i].options[z].selected = true;
246 \}
247 updatefqf();
248\}
249
250// fqc - the boolean operator selection box
251function initfqc() \{
252 var i,j;
253 fqc = argfqc.split(",");
254 if (_cgiargfqn_ == 2) \{ // there will only be one fqc element
255 for (j=0;j<document.QueryForm.fqc.options.length;j++) \{
256 if (fqc[0] == document.QueryForm.fqc.options[j].value) \{
257 document.QueryForm.fqc.options[j].selected = true;
258 break;
259 \}
260 \}
261 \}
262 else \{
263 for (i=0; i<fqc.length;i++) \{
264 for (j=0;j<document.QueryForm.fqc[i].options.length;j++) \{
265 if (fqc[i] == document.QueryForm.fqc[i].options[j].value) \{
266 document.QueryForm.fqc[i].options[j].selected = true;
267 break;
268 \}
269 \}
270 \}
271 \}
272 updatefqc();
273
274\}
275
276function updatefqc() \{
277
278 var i,j;
279 argfqc = "";
280 if (_cgiargfqn_ == 2) \{
281 j = document.QueryForm.fqc.selectedIndex;
282 argfqc += document.QueryForm.fqc.options[j].value;
283 \}
284 else \{
285 j = document.QueryForm.fqc[0].selectedIndex;
286 argfqc += document.QueryForm.fqc[0].options[j].value;
287 for (i=1;i<document.QueryForm.fqc.length;i++) \{
288 j = document.QueryForm.fqc[i].selectedIndex;
289 argfqc += "," + document.QueryForm.fqc[i].options[j].value;
290 \}
291 \}
292
293\}
294
295
296function clearfqc() \{
297
298 var i;
299 if (_cgiargfqn_ == 2) \{
300 document.QueryForm.fqc.options[0].selected = true;
301 \}
302 else \{
303 for (i=0; i<document.QueryForm.fqc.length; i++) \{
304 document.QueryForm.fqc[i].options[0].selected = true;
305 \}
306 \}
307 updatefqc();
308\}
309
310// fqv - the query word/phrase text box
311function initfqv() \{
312
313 var i;
314 fqv= argfqv.split(",");
315 for (i=0; i<fqv.length; i++) \{
316 document.QueryForm.fqv[i].value = fqv[i];
317 \}
318 updatefqv();
319
320
321\}
322
323 //argfqv += escape(format(document.QueryForm.fqv[0].value));
324
325function updatefqv() \{
326
327 var i;
328 argfqv="";
329 argfqv += format(document.QueryForm.fqv[0].value);
330 for (i=1; i<document.QueryForm.fqv.length;i++) \{
331 argfqv += ",";
332 argfqv += format(document.QueryForm.fqv[i].value);
333 \}
334\}
335
336function clearfqv() \{
337 var i;
338 for (i=0; i< document.QueryForm.fqv.length;i++) \{
339 document.QueryForm.fqv[i].value = "";
340 \}
341 updatefqv();
342\}
343
344// fqs - the stemming checkboxes
345function initfqs() \{
346
347 var i;
348 fqs = argfqs.split(",");
349 for (i=0; i<fqs.length; i++) \{
350 if (fqs[i]=="1") \{
351 document.QueryForm.fqs[i].checked = true;
352 \}
353 \}
354 updatefqs();
355
356\}
357
358function updatefqs() \{
359 argfqs="";
360 if (document.QueryForm.fqs[0].checked) \{
361 argfqs += "1";
362 \}
363 else \{
364 argfqs += "0";
365 \}
366 var i;
367 for (i=1; i<document.QueryForm.fqs.length; i++) \{
368 if (document.QueryForm.fqs[i].checked) \{
369 argfqs += ",1";
370 \}
371 else \{
372 argfqs += ",0";
373 \}
374 \}
375\}
376
377
378function clearfqs() \{
379 var i;
380 for (i=0; i<document.QueryForm.fqs.length; i++) \{
381 document.QueryForm.fqs[i].checked = false;
382 \}
383 updatefqs();
384\}
385
386// kqk - the casefolding checkboxes
387function initfqk() \{
388 var i;
389 fqk = argfqk.split(",");
390 for (i=0; i<fqk.length; i++) \{
391 if (fqk[i]=="1") \{
392 document.QueryForm.fqk[i].checked = true;
393 \}
394 \}
395 updatefqk();
396
397\}
398
399
400function updatefqk() \{
401 argfqk="";
402 if (document.QueryForm.fqk[0].checked) \{
403 argfqk += "1";
404 \}
405 else \{
406 argfqk += "0";
407 \}
408 var i;
409 for (i=1; i<document.QueryForm.fqk.length; i++) \{
410 if (document.QueryForm.fqk[i].checked) \{
411 argfqk += ",1";
412 \}
413 else \{
414 argfqk += ",0";
415 \}
416 \}
417\}
418
419function clearfqk() \{
420 var i;
421 for (i=0; i<document.QueryForm.fqk.length; i++) \{
422 document.QueryForm.fqk[i].checked = false;
423 \}
424 updatefqk();
425\}
426
427// q - the advanced query box
428function initq() \{
429 updateq();
430\}
431
432//argq += escape(document.QueryForm.q.value);
433
434function updateq() \{
435 argq = "";
436 argq += format(document.QueryForm.q.value);
437\}
438
439function clearq() \{
440 document.QueryForm.q.value="";
441\}
442
443
444// convert commas and spaces to plus
445// also convert other illegal characters to %xx codes
446function format(string) \{
447 var str = "" + string;
448 var out = "", flag = 0;
449 var ch = "";
450 var j;
451 for (j = 0; j < str.length; j++) \{
452 ch=str.charAt(j);
453 if (ch == " "|| ch == ",") \{
454 if ( flag == 0) \{
455 out += "+";
456 flag=1;
457 \}
458 continue;
459 \}
460 if (ch == ";" || ch == ":" || ch == "/" || ch == "?" ||
461 ch == "@" || ch == "&" || ch == "=" || ch == "#") \{
462 out += escape(ch);
463 flag=0;
464 continue;
465 \}
466 out += str.charAt(j);
467 flag=0;
468 \}
469 return out;
470\}
471
472}
473
474#_httpquery_ has a=q&e=compressedargs
475#if adv form, need to set k=0 and s=0
476_advformargs_{_If_(_cgiargb_,&k=0&s=0)}
477
478_searchfunctions_ {
479
480function beginSearch() \{
481window.location="_httpquery_"+getstdargs()+"_advformargs_"+getsearchargs();
482\}
483
484function runQuery() \{
485window.location="_httpquery_"+getstdargs()+"_advformargs_"+getqueryargs();
486\}
487
488function clearForm() \{
489 clearfqf();
490 clearfqv();
491
492 if ("_cgiargb_" == "1") \{
493 clearfqk();
494 clearfqs();
495 clearfqc();
496 \}
497
498\}
499
500}
501
502#######################################################################
503# headers
504# these are overridden so we can put an onLoad event handler
505# in the <body> tag of this page - for mgpp, form search pages
506#######################################################################
507
508#copied from prefs
509
510_header_ {_cgihead_
511_htmlhead_(background="_httpiconchalk_" onLoad="initialize();")_startspacer__pagebanner_
512}
513
514# this declaration ends up being the same as style=restrict, never mind
515_header_[v=1] {_cgihead_
516_htmlhead_(onLoad="initialize();")_pagebanner_
517}
518
519#######################################################################
520# page content
521#######################################################################
522
523
524_pagetitle_ {_If_(_cgiargq_,_textquerytitle_,_textnoquerytitle_)}
525
526
527_content_ {
528<center>
529_navigationbar_
530</center>
531<center>
532_If_(_cgiargct_,_selectqueryform_,_queryform_)
533</center>
534_If_(_searchhistorylist_,<center>_iconsearchhistorybar_</center><br>
535<center>
536_searchhistorylist_
537</center>)
538_If_(_cgiargq_,<center>_iconqueryresultsbar_</center><br>
539<small>
540_freqmsg_
541_textpostprocess_</small><br>
542_resultline_
543,<center>_iconblankbar_</center>)<br>
544}
545
546_selectqueryform_{_If_(_cgiargqt_,_fieldqueryform_,_queryform_)}
547
548_queryform_ {
549<!-- query form (\_query:queryform\_) -->
550<form name=QueryForm method=get action="_gwcgi_">
551
552<input type=hidden name="a" value="q">
553<input type=hidden name="r" value="1">
554<input type=hidden name="hs" value="1">
555<input type=hidden name="e" value="_decodedcompressedoptions_">
556_queryformcontent_
557
558</form>
559<!-- end of query form -->
560}
561
562_queryformcontent_{_basicqueryform_}
563
564_basicqueryform_ {<table><tr><td>
565<nobr>_textselect_</nobr>
566</td></tr>
567<tr><td>
568_If_(_cgiargqb_,_largequerybox_,_smallquerybox_)
569</td></tr></table>
570}
571
572_datesearch_
573{<table><tr><td>
574 <center>
575_textstartdate_
576<input type="text" name="ds" value = "_cgiargds_"size="4" maxlength="4">
577<select name="dsbc" value="_cgiargdsbc_" size="1">
578 <option value = "0"_If_(_cgiargdsbc_,, selected)>_textad_
579 <option value = "1"_If_(_cgiargdsbc_, selected)>_textbc_
580</select>
581_textenddate_
582<input type="text" name="de" value = "_cgiargde_" size="4" maxlength="4">
583<select name="debc" size="1">
584 <option value = "0" _If_(_cgiargdebc_,, selected)>_textad_
585 <option value = "1" _If_(_cgiargdebc_, selected)>_textbc_
586</select>
587</center>
588</tr></td>
589<tr><td>
590_textexplaineras_
591</tr></td>
592</table>
593</center>
594}
595
596_smallquerybox_ {<tr><td><nobr><input type="text" name="q" value="_cgiargq_" size="50">
597<input type="submit" value="_textbeginsearch_"></nobr>}
598
599_largequerybox_ {
600<tr><td><textarea name="q" cols=63 rows=10>
601_cgiargq_
602</textarea></td></tr>
603<tr align=right><td><table>
604<tr><td><input type="submit" value="_textbeginsearch_"></td>
605</tr></table></td></tr>}
606
607
608_fieldqueryform_ {
609<!-- field query form (\_query:fieldqueryform\_) -->
610<form name=QueryForm method=get action="_gwcgi_">
611<table><tr><td>
612<nobr>
613_textformselect_
614</nobr>
615</td></tr>
616_If_(_cgiargb_,_advancedforms_,_simpleforms_)
617</table>
618_If_(_cgiargb_,<center>_iconblankbar_</center><br>
619<center>_advancedformextra_</center>)
620</form>
621<!-- end of query form -->
622}
623
624_advancedforms_{
625<tr><td><center> <table border=0 cellspacing=0 cellpadding=0 width="90%">
626<tr><th></th><th align=left>_textwordphrase_</th><th colspan=2><nobr>_textfoldstem_</nobr></th><th align=center>&nbsp;&nbsp;_textinfield_</th></tr>
627_advformlist_
628<tr><td colspan=2><input type=button value="_textclearform_" onClick="clearForm();"></td>
629<td colspan=3><table>
630<tr><td><input type=button value="_textbeginsearch_" onClick="beginSearch();"></td>
631</tr></table></td></tr>
632</table></td></tr>
633}
634
635_advancedformextra_{
636<table>
637<tr><td>_textadvquery_</td></tr>
638<tr><td><textarea name=q cols=57 rows=3 onChange="updateq();">_cgiargq_</textarea></td>
639<td valign=bottom>
640<input type="button" value="_textrunquery_" onClick="runQuery();"></td></tr>
641</table>
642}
643
644_simpleforms_{
645<tr><td><center> <table border=0 cellspacing=0 cellpadding=0 width="90%">
646<tr><th align=left>_textwordphrase_</th><th align=left>&nbsp;&nbsp;_textinfield_</th></tr>
647_regformlist_
648<tr><td><input type=button value="_textclearform_" onClick="clearForm();"></td>
649<td><table>
650<tr><td><input type=button value="_textbeginsearch_" onClick="beginSearch();"></td>
651</tr>
652</table></td></tr>
653</table></td></tr>}
654
655_regformelement_{
656<td><input type=text size=39 name="fqv" onChange="updatefqv();"></td>
657<td>_fqfselection_</td>}
658
659#has no and/or/not selection box
660_firstadvformelement_{
661<td></td><td><input type=text size=31 name="fqv" onChange="updatefqv();"></td>
662<td align=center><input type=checkbox name="fqk" onClick="updatefqk();""></td>
663<td align-center><input type=checkbox name="fqs" onClick="updatefqs();"></td>
664<td align=right>_fqfselection_</td>}
665
666_advformelement_{
667<td>_fqcselection_</td>
668<td><input type=text size=31 name="fqv" onChange="updatefqv();"></td>
669<td align=center><input type=checkbox name="fqk" onClick="updatefqk();"></td>
670<td align-center><input type=checkbox name="fqs" onClick="updatefqs();"></td>
671<td align=right>_fqfselection_</td>}
672
673_fqcselection_ {
674<select name="fqc" onChange="updatefqc();">
675<option value="and">_textand_
676<option value="or">_textor_
677<option value="not">_textandnot_
678</select>}
679
680_textselect_ {_If_(_cgiargb_,_textadvancedsearch_,_textsimplesearch_)}
681_textformselect_ {_If_(_cgiargb_,_textformadvancedsearch_,_textformsimplesearch_)}
682
683_ZZ_{_textallfields_}
684
685# we want to put the links to previous/next pages of results
686# in the footer
687_pagefooterextra_ {
688<center>
689<table cellspacing=0 cellpadding=0 width=_pagewidth_>
690<tr>
691<td align=left>_If_(_prevfirst_,<a href="_httpquery_&r=_prevfirst_">_iconprev__textmatches__prevfirst_ - _prevlast_</a>)</td>
692<td align=right>_If_(_nextfirst_,<a href="_httpquery_&r=_nextfirst_">_textmatches__nextfirst_ - _nextlast__iconnext_</a>)</td>
693</tr></table>
694</center>
695}
696
697_querytypeselection_ {
698<select name="t">
699<option value="1"_If_(_cgiargt_, selected)>_textsome_
700<option value="0"_If_(_cgiargt_,, selected)>_textall_
701</select>
702}
703
704_formquerytypeselection_ {
705<select name="t">
706<option value="1"_If_(_cgiargt_, selected)>_textformsome_
707<option value="0"_If_(_cgiargt_,, selected)>_textformall_
708</select>
709}
710
711
Note: See TracBrowser for help on using the repository browser.