Annotation of loncom/interface/lonsearchcat.pm, revision 1.12
1.1 www 1: # The LearningOnline Network
2: # Search Catalog
3: #
1.2 harris41 4: # 03/08/2001 Scott Harrison
1.1 www 5: #
6: package Apache::lonsearchcat;
7:
8: use strict;
9: use Apache::Constants qw(:common);
1.6 harris41 10: use Apache::lonnet();
11: use Apache::File();
1.7 harris41 12: use CGI qw(:standard);
1.1 www 13:
1.3 harris41 14: my %language;
15: my $scrout;
16: my %metadatafields;
17: my %cprtag;
18: my %mimetag;
19:
1.1 www 20: sub handler {
21: my $r = shift;
1.7 harris41 22:
23: # -------------------------------------- see if called from an interactive mode
24: map {
25: my ($name, $value) = split(/=/,$_);
26: $value =~ tr/+/ /;
27: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
28: if ($name eq 'catalogmode') {
29: $ENV{'form.'.$name}=$value;
30: }
31: } (split(/&/,$ENV{'QUERY_STRING'}));
32:
1.1 www 33: $r->content_type('text/html');
34: $r->send_http_header;
35: return OK if $r->header_only;
36:
1.3 harris41 37: %metadatafields=();
38:
1.8 harris41 39: my $hidden='';
40: $hidden=<<END if $ENV{'form.catalogmode'} eq 'interactive';
41: <input type='hidden' name='catalogmode' value='interactive'>
42: END
43:
1.3 harris41 44: # ------------------------------------------------ First, check out environment
45: $metadatafields{'owner'}=$ENV{'user.name'}.'@'.$ENV{'user.domain'};
46:
1.8 harris41 47: # --------------------------------- Compute various listings of metadata values
1.3 harris41 48:
49: %language=();
50: $language{'any'}='Any language';
51: {
52: my $fh=Apache::File->new($r->dir_config('lonTabDir').'/language.tab');
53: map {
54: $_=~/(\w+)\s+([\w\s\-]+)/;
55: $language{$1}=$2;
56: } <$fh>;
57: }
58:
59: %cprtag=();
60: $cprtag{'any'}='Any copyright/distribution';
61: {
62: my $fh=Apache::File->new($r->dir_config('lonIncludes').'/copyright.tab');
63: map {
64: $_=~/(\w+)\s+([\w\s\-]+)/;
65: $cprtag{$1}=$2;
66: } <$fh>;
67: }
68:
69: %mimetag=();
70: $mimetag{'any'}='Any type';
71: {
72: my $fh=Apache::File->new($r->dir_config('lonTabDir').'/filetypes.tab');
73: map {
74: $_=~/(\w+)\s+(\w+)\s+([\w\s\-]+)/;
75: $mimetag{$1}=".$1 $3";
76: } <$fh>;
77: }
78:
1.6 harris41 79: if ($ENV{'form.basicsubmit'} eq 'SEARCH') {
80: return &basicsearch($r,$ENV{'form.basicexp'});
81: }
82:
1.8 harris41 83: $scrout=''; # building a part of screen output
1.3 harris41 84: $scrout.=&searchphrasefield('Limit by title','title',
1.11 harris41 85: $ENV{'form.title'});
1.3 harris41 86:
87: $scrout.=&searchphrasefield('Limit by author','author',
1.11 harris41 88: $ENV{'form.author'});
1.3 harris41 89:
90: $scrout.=&searchphrasefield('Limit by subject','subject',
1.11 harris41 91: $ENV{'form.subject'});
92:
93: $scrout.=&searchphrasefield('Limit by keywords','keywords',
94: $ENV{'form.keywords'});
95:
96: $scrout.=&searchphrasefield('Limit by URL','url',
97: $ENV{'form.url'});
98:
99: $scrout.=&searchphrasefield('Limit by version','version',
100: $ENV{'form.version'});
1.3 harris41 101:
102: $scrout.=&searchphrasefield('Limit by notes','notes',
1.11 harris41 103: $ENV{'form.notes'});
1.3 harris41 104:
105: $scrout.=&searchphrasefield('Limit by abstract','abstract',
1.11 harris41 106: $ENV{'form.abstract'});
1.3 harris41 107:
1.11 harris41 108: $ENV{'form.mime'}='notxxx' unless length($ENV{'form.mime'});
1.3 harris41 109: $scrout.=&selectbox('Limit by MIME type','mime',
1.11 harris41 110: $ENV{'form.mime'},%mimetag);
111:
112: $ENV{'form.language'}='any' unless length($ENV{'form.language'});
1.3 harris41 113:
114: $scrout.=&selectbox('Limit by language','language',
1.11 harris41 115: $ENV{'form.language'},%language);
1.3 harris41 116:
1.8 harris41 117:
118: # ------------------------------------------------ Compute date selection boxes
119: $scrout.=<<CREATIONDATESTART;
1.3 harris41 120: <p>
121: <font color="#800000" face="helvetica"><b>LIMIT BY CREATION DATE RANGE:</b>
122: </font>
123: <br>
1.8 harris41 124: between:
125: CREATIONDATESTART
1.11 harris41 126: $scrout.=&dateboxes('creationdatestart',1,1,1976,
127: $ENV{'form.creationdatestart_month'},
128: $ENV{'form.creationdatestart_day'},
129: $ENV{'form.creationdatestart_year'},
130: );
1.8 harris41 131: $scrout.=<<CREATIONDATEEND;
132: and:
133: CREATIONDATEEND
1.11 harris41 134: $scrout.=&dateboxes('creationdateend',12,31,2051,
135: $ENV{'form.creationdateend_month'},
136: $ENV{'form.creationdateend_day'},
137: $ENV{'form.creationdateend_year'},
138: );
1.8 harris41 139: $scrout.="</p>";
140:
141: $scrout.=<<LASTREVISIONDATESTART;
142: <p>
143: <font color="#800000" face="helvetica"><b>LIMIT BY LAST REVISION DATE RANGE:
144: </b></font>
145: <br>between:
146: LASTREVISIONDATESTART
1.11 harris41 147: $scrout.=&dateboxes('lastrevisiondatestart',1,1,1976,
148: $ENV{'form.lastrevisiondatestart_month'},
149: $ENV{'form.lastrevisiondatestart_day'},
150: $ENV{'form.lastrevisiondatestart_year'},
151: );
1.8 harris41 152: $scrout.=<<LASTREVISIONDATEEND;
153: and:
154: LASTREVISIONDATEEND
1.11 harris41 155: $scrout.=&dateboxes('lastrevisiondateend',12,31,2051,
156: $ENV{'form.lastrevisiondateend_month'},
157: $ENV{'form.lastrevisiondateend_day'},
158: $ENV{'form.lastrevisiondateend_year'},
159: );
1.8 harris41 160: $scrout.='</p>';
161:
162: $scrout.=&searchphrasefield('Limit by publisher/owner','owner',
1.11 harris41 163: $ENV{'form.owner'});
164: # $metadatafields{'owner'});
1.8 harris41 165:
1.11 harris41 166: $ENV{'form.copyright'}='any' unless length($ENV{'form.copyright'});
1.8 harris41 167: $scrout.=&selectbox('Limit by copyright/distribution','copyright',
1.11 harris41 168: $ENV{'form.copyright'},%cprtag);
1.8 harris41 169:
170: # ---------------------------------------------------------------- Print screen
171: $r->print(<<ENDDOCUMENT);
172: <html>
173: <head>
174: <title>The LearningOnline Network with CAPA</title>
175: </head>
176: <body bgcolor="#FFFFFF">
177: <img align=right src=/adm/lonIcons/lonlogos.gif>
178: <h1>Search Catalog</h1>
179: <form method="post" action="/adm/searchcat">
180: $hidden
181: <hr>
182: <h3>Basic Search</h3>
183: <p>
184: Enter terms or phrases separated by search operators
185: such as AND or OR then press SEARCH below. Terms should be specific
186: to the title, author, subject, notes, or abstract information associated
187: with a resource.
188: <br>
1.11 harris41 189: ENDDOCUMENT
190: $r->print(&simpletextfield('basicexp',$ENV{'form.basicexp'}));
191: $r->print(' ');
192: $r->print(&simplecheckbox('titleonly',$ENV{'form.titleonly'}));
193: $r->print('<font color="#800000">Title only</font> ');
194: $r->print(&simplecheckbox('allversions',$ENV{'form.allversions'}));
195: $r->print(<<ENDDOCUMENT);
196: <font color="#800000">Search historic archives</font>
1.8 harris41 197: <br>
198: <input type="submit" name="basicsubmit" value="SEARCH">
199: <input type="reset" name="reset" value="RESET">
200: <input type="button" name="close" value="CLOSE" onClick="self.close()">
201: </p>
202: <hr>
203: <h3>Advanced Search</h3>
204: $scrout
205: <p>
206: <input type="submit" name="advancedsubmit" value="SEARCH">
207: <input type="reset" name="reset" value="RESET">
208: <input type="button" name="close" value="CLOSE" onClick="self.close()">
1.3 harris41 209: </p>
1.8 harris41 210: </form>
211: </body>
212: </html>
213: ENDDOCUMENT
214: return OK;
215: }
216:
217: # --------------------------------------------------------- Various form fields
218:
219: sub textfield {
220: my ($title,$name,$value)=@_;
221: return "\n<p><b>$title:</b><br>".
222: '<input type=text name="'.$name.'" size=80 value="'.$value.'">';
223: }
224:
1.11 harris41 225: sub simpletextfield {
226: my ($name,$value)=@_;
227: return '<input type=text name="'.$name.'" size=20 value="'.$value.'">';
228: }
229:
230: sub simplecheckbox {
231: my ($name,$value)=@_;
232: my $checked='';
233: $checked="CHECKED" if $value eq 'on';
234: return '<input type=checkbox name="'.$name.'" '. $checked . '>';
235: }
236:
1.8 harris41 237: sub searchphrasefield {
238: my ($title,$name,$value)=@_;
239: my $instruction=<<END;
240: Enter terms or phrases separated by search operators such
241: as AND or OR.
242: END
243: my $uctitle=uc($title);
244: return "\n<p><font color=\"#800000\" face=\"helvetica\"><b>$uctitle:</b>".
245: "</FONT> $instruction<br>".
246: '<input type=text name="'.$name.'" size=80 value="'.$value.'">';
247: }
1.3 harris41 248:
1.8 harris41 249: sub dateboxes {
1.11 harris41 250: my ($name,$defaultmonth,$defaultday,$defaultyear,
251: $currentmonth,$currentday,$currentyear)=@_;
252: ($defaultmonth,$defaultday,$defaultyear)=('','','');
253: my $month=<<END;
1.8 harris41 254: <select name="${name}_month">
1.11 harris41 255: <option value='$defaultmonth'> </option>
256: <option value="1">January</option>
257: <option value="2">February</option>
258: <option value="3">March</option>
259: <option value="4">April</option>
260: <option value="5">May</option>
261: <option value="6">June</option>
262: <option value="7">July</option>
263: <option value="8">August</option>
264: <option value="9">September</option>
1.3 harris41 265: <option value="10">October</option>
266: <option value="11">November</option>
267: <option value="12">December</option>
268: </select>
1.11 harris41 269: END
270: $month=~s/(\"$currentmonth\")/$1 SELECTED/ if length($currentmonth);
271: my $day=<<END;
1.8 harris41 272: <select name="${name}_day">
1.11 harris41 273: <option value='$defaultday'> </option>
274: <option value="1">1</option>
275: <option value="2">2</option>
276: <option value="3">3</option>
277: <option value="4">4</option>
278: <option value="5">5</option>
279: <option value="6">6</option>
280: <option value="7">7</option>
281: <option value="8">8</option>
282: <option value="9">9</option>
283: <option value="10">10</option>
284: <option value="11">11</option>
285: <option value="12">12</option>
286: <option value="13">13</option>
287: <option value="14">14</option>
288: <option value="15">15</option>
289: <option value="16">16</option>
290: <option value="17">17</option>
291: <option value="18">18</option>
292: <option value="19">19</option>
293: <option value="20">20</option>
294: <option value="21">21</option>
295: <option value="22">22</option>
296: <option value="23">23</option>
297: <option value="24">24</option>
298: <option value="25">25</option>
299: <option value="26">26</option>
300: <option value="27">27</option>
301: <option value="28">28</option>
302: <option value="29">29</option>
303: <option value="30">30</option>
304: <option value="31">31</option>
1.3 harris41 305: </select>
1.11 harris41 306: END
307: $day=~s/(\"$currentday\")/$1 SELECTED/ if length($currentday);
308: my $year=<<END;
1.8 harris41 309: <select name="${name}_year">
1.11 harris41 310: <option value='$defaultyear'> </option>
311: <option value="1976">1976</option>
312: <option value="1977">1977</option>
313: <option value="1978">1978</option>
314: <option value="1979">1979</option>
315: <option value="1980">1980</option>
316: <option value="1981">1981</option>
317: <option value="1982">1982</option>
318: <option value="1983">1983</option>
319: <option value="1984">1984</option>
320: <option value="1985">1985</option>
321: <option value="1986">1986</option>
322: <option value="1987">1987</option>
323: <option value="1988">1988</option>
324: <option value="1989">1989</option>
325: <option value="1990">1990</option>
326: <option value="1991">1991</option>
327: <option value="1992">1992</option>
328: <option value="1993">1993</option>
329: <option value="1994">1994</option>
330: <option value="1995">1995</option>
331: <option value="1996">1996</option>
332: <option value="1997">1997</option>
333: <option value="1998">1998</option>
334: <option value="1999">1999</option>
335: <option value="2000">2000</option>
336: <option value="2001">2001</option>
337: <option value="2002">2002</option>
338: <option value="2003">2003</option>
339: <option value="2004">2004</option>
340: <option value="2005">2005</option>
341: <option value="2006">2006</option>
342: <option value="2007">2007</option>
343: <option value="2008">2008</option>
344: <option value="2009">2009</option>
345: <option value="2010">2010</option>
346: <option value="2011">2011</option>
347: <option value="2012">2012</option>
348: <option value="2013">2013</option>
349: <option value="2014">2014</option>
350: <option value="2015">2015</option>
351: <option value="2016">2016</option>
352: <option value="2017">2017</option>
353: <option value="2018">2018</option>
354: <option value="2019">2019</option>
355: <option value="2020">2020</option>
356: <option value="2021">2021</option>
357: <option value="2022">2022</option>
358: <option value="2023">2023</option>
359: <option value="2024">2024</option>
360: <option value="2025">2025</option>
361: <option value="2026">2026</option>
362: <option value="2027">2027</option>
363: <option value="2028">2028</option>
364: <option value="2029">2029</option>
365: <option value="2030">2030</option>
366: <option value="2031">2031</option>
367: <option value="2032">2032</option>
368: <option value="2033">2033</option>
369: <option value="2034">2034</option>
370: <option value="2035">2035</option>
371: <option value="2036">2036</option>
372: <option value="2037">2037</option>
373: <option value="2038">2038</option>
374: <option value="2039">2039</option>
375: <option value="2040">2040</option>
376: <option value="2041">2041</option>
377: <option value="2042">2042</option>
378: <option value="2043">2043</option>
379: <option value="2044">2044</option>
380: <option value="2045">2045</option>
381: <option value="2046">2046</option>
382: <option value="2047">2047</option>
383: <option value="2048">2048</option>
384: <option value="2049">2049</option>
385: <option value="2050">2050</option>
386: <option value="2051">2051</option>
1.3 harris41 387: </select>
388: END
1.11 harris41 389: $year=~s/(\"$currentyear\")/$1 SELECTED/ if length($currentyear);
390: return "$month$day$year";
1.3 harris41 391: }
392:
393: sub selectbox {
394: my ($title,$name,$value,%options)=@_;
395: my $uctitle=uc($title);
396: my $selout="\n<p><font color=\"#800000\" face=\"helvetica\"><b>$uctitle:".
397: "</b></font><br>".'<select name="'.$name.'">';
398: map {
399: $selout.='<option value="'.$_.'"';
400: if ($_ eq $value) { $selout.=' selected'; }
401: $selout.='>'.$options{$_}.'</option>';
402: } sort keys %options;
403: return $selout.'</select>';
1.6 harris41 404: }
405:
406: # --------------------------------------------------- Performing a basic search
407: sub basicsearch {
408: my ($r,$expression)=@_;
409:
410: my $query=$expression;
411: $query="select * from metadata where concat(title,\" \",author) like '\%$expression\%'";
1.12 ! harris41 412: # my $reply=&Apache::lonnet::reply("querysend:$query",'msul3');
! 413: my $reply=&Apache::lonnet::metadata_query("querysend:$query",'msul3');
1.6 harris41 414:
415: my @results;
416:
417: my $replyfile='';
418: $reply=~/^([\.\w]+)$/; # must do since 'use strict' checks for tainting
419: $replyfile=$r->dir_config('lonDaemons').'/tmp/'.$1;
420: $reply=~/(.*?)\_/;
421: my $hostname=$1;
422:
423: {
424: while (1) {
425: last if -e $replyfile;
426: sleep 1;
427: }
428: # QUESTION: how should I handle this error condition..
429: # I'm sure there is syntax elsewhere I can use..
430: my $fh=Apache::File->new($replyfile) or
431: ($r->print('file cannot be opened') and return OK);
432: @results=<$fh>;
433: }
434:
435: my $compiledresult='';
436:
437: foreach my $result (@results) {
1.9 harris41 438: my ($title,$author,$subject,$url,$keywords,$version,
439: $notes,$abstract,$mime,$lang,
1.6 harris41 440: $creationdate,$lastrevisiondate,$owner,$copyright
441: )=map {&Apache::lonnet::unescape($_)} (split(/\,/,$result));
442: my $shortabstract=$abstract;
443: $shortabstract=substr($abstract,0,200) if length($abstract)>200;
1.8 harris41 444: $compiledresult.=<<END;
1.6 harris41 445: <p>
1.8 harris41 446: END
447: $compiledresult.=<<END if $ENV{'form.catalogmode'} eq 'interactive';
448: <font size='-1'><INPUT TYPE="button" NAME="returnvalues" VALUE="SELECT"
1.10 harris41 449: onClick="javascript:select_data('$title','$url')">
1.8 harris41 450: </font>
451: <br>
452: END
453: $compiledresult.=<<END;
1.9 harris41 454: <b>URL: </b> $url<br>
1.6 harris41 455: <b>Title:</b> $title<br>
456: <b>Author(s):</b> $author<br>
457: <b>Subject:</b> $subject<br>
1.9 harris41 458: <b>Keyword(s):</b> $keywords<br>
1.6 harris41 459: <b>Notes:</b> $notes<br>
460: <b>Abstract:</b> $shortabstract<br>
461: <b>MIME Type:</b> $mimetag{$mime}<br>
462: <b>Language:</b> $language{$lang}<br>
463: <b>Creation Date:</b> $creationdate<br>
464: <b>Last Revision Date:</b> $lastrevisiondate<br>
465: <b>Publisher/Owner:</b> $owner<br>
466: <b>Copyright/Distribution:</b> $copyright<br>
467: <b>Repository Location:</b> $hostname
468: </p>
469: END
470: }
471:
472: unless ($compiledresult) {
473: $compiledresult="There were no results that matched your query";
474: }
475:
1.9 harris41 476: # make query information persistent to allow for subsequent revision
477: my $persistent='';
478: map {
479: if (/^form\./ && !/submit/) {
480: my $name=$_;
481: my $key=$name;
482: $name=~s/^form\.//;
483: $persistent.=<<END;
484: <INPUT TYPE='hidden' NAME='$name' VALUE='$ENV{$key}'>
485: END
486: }
487: } (keys %ENV);
488:
1.8 harris41 489: $r->print(<<BEGINNING);
1.6 harris41 490: <html>
491: <head>
492: <title>The LearningOnline Network with CAPA</title>
1.8 harris41 493: BEGINNING
494: $r->print(<<SCRIPT) if $ENV{'form.catalogmode'} eq 'interactive';
495: <script>
496: function select_data(title,url) {
497: changeTitle(title);
498: changeURL(url);
499: }
500: function changeTitle(val) {
501: if (opener.inf.document.forms.resinfo.elements.t) {
502: opener.inf.document.forms.resinfo.elements.t.value=val;
503: }
504: }
505: function changeURL(val) {
506: if (opener.inf.document.forms.resinfo.elements.u) {
507: opener.inf.document.forms.resinfo.elements.u.value=val;
508: }
509: }
510: </script>
511: SCRIPT
512: $r->print(<<RESULTS);
1.6 harris41 513: </head>
514: <body bgcolor="#ffffff">
515: <img align=right src=/adm/lonIcons/lonlogos.gif>
516: <h1>Search Catalog</h1>
517: <form method="post" action="/adm/searchcat">
1.9 harris41 518: <input type='button' value='Revise search request'
519: onClick='this.form.submit();'>
1.11 harris41 520: <input type='button' value='CLOSE'
521: onClick='self.close();'>
1.9 harris41 522: $persistent
1.6 harris41 523: <hr>
524: <h3>Search Query</h3>
525: <p>
1.8 harris41 526: <b>Basic search:</b> $expression
1.6 harris41 527: </p>
528: <h3>Search Results</h3>
529: $compiledresult
530: </body>
531: </html>
532: RESULTS
533:
534: return OK;
1.3 harris41 535: }
1.1 www 536:
537: 1;
538: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>