Annotation of loncom/interface/lonsearchcat.pm, revision 1.105
1.98 harris41 1: # The LearningOnline Network with CAPA
2: #
1.1 www 3: # Search Catalog
4: #
1.97 harris41 5: # YEAR=2001
1.104 harris41 6: # 3/8, 3/12, 3/13, 3/14, 3/15, 3/19 Scott Harrison
7: # 3/20, 3/21, 3/22, 3/26, 3/27, 4/2, 8/15, 8/24, 8/25 Scott Harrison
8: # 10/12,10/14,10/15,10/16,11/28 Scott Harrison
9: #
1.105 ! harris41 10: # $Id: lonsearchcat.pm,v 1.104 2001/11/28 14:02:31 harris41 Exp $
1.104 harris41 11: ###
12:
1.98 harris41 13: ###############################################################################
14: ## ##
15: ## ORGANIZATION OF THIS PERL MODULE ##
16: ## ##
1.105 ! harris41 17: ## 1. Modules used by this module ##
! 18: ## 2. Choices for different output views (detailed, summary, xml, etc) ##
! 19: ## 3. BEGIN block (to be run once after compilation) ##
! 20: ## 4. Handling routine called via Apache and mod_perl ##
! 21: ## 5. Other subroutines ##
1.98 harris41 22: ## ##
23: ###############################################################################
24:
1.1 www 25: package Apache::lonsearchcat;
26:
1.98 harris41 27: # ------------------------------------------------- modules used by this module
1.1 www 28: use strict;
29: use Apache::Constants qw(:common);
1.6 harris41 30: use Apache::lonnet();
31: use Apache::File();
1.7 harris41 32: use CGI qw(:standard);
1.41 harris41 33: use Text::Query;
1.101 harris41 34: use GDBM_File;
1.1 www 35:
1.90 harris41 36: # ---------------------------------------- variables used throughout the module
37:
1.98 harris41 38: # -- information holders
39: my %language; # holds contents of language.tab
40: my %cprtag; # holds contents of copyright.tab
41: my %mimetag; # holds contents of filetypes.tab
42: my %hostdomains; # matches host name to host domain
43: my %hostips; # matches host name to host ip
44: my %hitcount; # stores number of hits per host
45:
46: # -- dynamically rendered interface components
47: my $closebutton; # button that closes the search window
48: my $importbutton; # button to take the selected results and go to group sorting
49:
50: # -- miscellaneous variables
51: my $scrout; # string that holds portions of the screen output
52: my $yourself; # allows for quickly limiting to oneself
1.101 harris41 53: my %hash;
1.98 harris41 54:
55: # ------------------------------------------ choices for different output views
56: # Detailed Citation View ---> sub detailed_citation_view
1.90 harris41 57: # Summary View ---> sub summary_view
58: # Fielded Format ---> sub fielded_format_view
59: # XML/SGML ---> sub xml_sgml_view
1.55 harris41 60: my $basicviewselect=<<END;
61: <select name='basicviewselect'>
62: <option value='Detailed Citation View'>Detailed Citation View</option>
63: <option value='Summary View'>Summary View</option>
64: <option value='Fielded Format'>Fielded Format</option>
65: <option value='XML/SGML'>XML/SGML</option>
66: </select>
67: END
68: my $advancedviewselect=<<END;
69: <select name='advancedviewselect'>
1.50 harris41 70: <option value='Detailed Citation View'>Detailed Citation View</option>
71: <option value='Summary View'>Summary View</option>
72: <option value='Fielded Format'>Fielded Format</option>
73: <option value='XML/SGML'>XML/SGML</option>
1.46 harris41 74: </select>
75: END
1.3 harris41 76:
1.98 harris41 77: # ----------------------------------------------------------------------- BEGIN
78: sub BEGIN {
1.8 harris41 79: # --------------------------------- Compute various listings of metadata values
1.3 harris41 80: $language{'any'}='Any language';
81: {
1.98 harris41 82: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
83: '/language.tab');
1.3 harris41 84: map {
1.57 harris41 85: $_=~/(\w+)\s+([\w\s\-]+)/; chomp;
1.3 harris41 86: $language{$1}=$2;
87: } <$fh>;
88: }
89: $cprtag{'any'}='Any copyright/distribution';
90: {
1.98 harris41 91: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonIncludes'}.
92: '/copyright.tab');
1.3 harris41 93: map {
1.57 harris41 94: $_=~/(\w+)\s+([\w\s\-]+)/; chomp;
1.3 harris41 95: $cprtag{$1}=$2;
96: } <$fh>;
97: }
98: $mimetag{'any'}='Any type';
99: {
1.98 harris41 100: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
101: '/filetypes.tab');
1.3 harris41 102: map {
1.57 harris41 103: $_=~/(\w+)\s+(\w+)\s+([\w\s\-]+)/; chomp;
1.3 harris41 104: $mimetag{$1}=".$1 $3";
105: } <$fh>;
106: }
1.98 harris41 107: {
108: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
109: '/hosts.tab');
110: map {
111: $_=~/(\w+?)\:(\w+?)\:(\w+?)\:(.*)/; chomp;
112: if ($3 eq 'library') {
113: $hostdomains{$1}=$2;
114: $hostips{$1}=$4;
115: }
116: } <$fh>;
117: }
118: }
119:
1.101 harris41 120: my $diropendb = "";
121: my $domain = "";
122:
1.98 harris41 123: # ----------------------------- Handling routine called via Apache and mod_perl
124: sub handler {
125: my $r = shift;
1.103 harris41 126: untie %hash;
1.98 harris41 127: &get_unprocessed_cgi();
128:
129: $r->content_type('text/html');
130: $r->send_http_header;
131: return OK if $r->header_only;
132:
1.101 harris41 133: $domain = $r->dir_config('lonDefDomain');
134:
1.104 harris41 135: $diropendb= "/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_searchcat.db";
1.101 harris41 136:
137: if ($ENV{'form.launch'} eq '1') {
138: if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) {
139: &start_fresh_session();
140: untie %hash;
141: }
142: else {
143: $r->print('<html><head></head><body>Unable to tie hash to db '.
144: 'file</body></html>');
145: return OK;
146: }
147: }
148:
1.98 harris41 149: # ----------------------------------- configure dynamic components of interface
150: my $hidden='';
151: if ($ENV{'form.catalogmode'} eq 'interactive') {
152: $hidden="<input type='hidden' name='catalogmode' value='interactive'>".
153: "\n";
154: $closebutton="<input type='button' name='close' value='CLOSE' ".
155: "onClick='self.close()'>"."\n";
156: }
157: elsif ($ENV{'form.catalogmode'} eq 'groupsearch') {
158: $hidden=<<END;
159: <input type='hidden' name='catalogmode' value='groupsearch'>
160: END
161: $closebutton=<<END;
162: <input type='button' name='close' value='CLOSE' onClick='self.close()'>
163: END
164: $importbutton=<<END;
165: <input type='button' name='import' value='IMPORT'
166: onClick='javascript:select_group()'>
167: END
168: }
169:
170: # ------------------------------------------------------ Determine current user
171: $yourself=$ENV{'user.name'}.'@'.$ENV{'user.domain'};
172:
173: # --- Now, depending on the interface actions, do one of three things here:
174: # --- 1. a basic search
175: # --- 2. an advanced search
176: # --- 3. output a search interface
1.3 harris41 177:
1.90 harris41 178: # ----------------------------------- See if a search invocation should be done
1.6 harris41 179: if ($ENV{'form.basicsubmit'} eq 'SEARCH') {
1.101 harris41 180: untie %hash; return &basicsearch($r,\%ENV);
1.6 harris41 181: }
1.18 harris41 182: elsif ($ENV{'form.advancedsubmit'} eq 'SEARCH') {
1.101 harris41 183: untie %hash; return &advancedsearch($r,\%ENV);
1.18 harris41 184: }
1.6 harris41 185:
1.90 harris41 186: # ----------------------------- Else, begin building search interface to output
1.8 harris41 187: $scrout=''; # building a part of screen output
1.3 harris41 188: $scrout.=&searchphrasefield('Limit by title','title',
1.11 harris41 189: $ENV{'form.title'});
1.3 harris41 190:
191: $scrout.=&searchphrasefield('Limit by author','author',
1.11 harris41 192: $ENV{'form.author'});
1.3 harris41 193:
194: $scrout.=&searchphrasefield('Limit by subject','subject',
1.11 harris41 195: $ENV{'form.subject'});
196:
197: $scrout.=&searchphrasefield('Limit by keywords','keywords',
198: $ENV{'form.keywords'});
199:
200: $scrout.=&searchphrasefield('Limit by URL','url',
201: $ENV{'form.url'});
202:
1.96 harris41 203: # $scrout.=&searchphrasefield('Limit by version','version',
204: # $ENV{'form.version'});
1.3 harris41 205:
206: $scrout.=&searchphrasefield('Limit by notes','notes',
1.11 harris41 207: $ENV{'form.notes'});
1.3 harris41 208:
209: $scrout.=&searchphrasefield('Limit by abstract','abstract',
1.11 harris41 210: $ENV{'form.abstract'});
1.3 harris41 211:
1.11 harris41 212: $ENV{'form.mime'}='notxxx' unless length($ENV{'form.mime'});
1.3 harris41 213: $scrout.=&selectbox('Limit by MIME type','mime',
1.11 harris41 214: $ENV{'form.mime'},%mimetag);
215:
216: $ENV{'form.language'}='any' unless length($ENV{'form.language'});
1.3 harris41 217:
218: $scrout.=&selectbox('Limit by language','language',
1.11 harris41 219: $ENV{'form.language'},%language);
1.3 harris41 220:
1.8 harris41 221:
222: # ------------------------------------------------ Compute date selection boxes
223: $scrout.=<<CREATIONDATESTART;
1.3 harris41 224: <p>
225: <font color="#800000" face="helvetica"><b>LIMIT BY CREATION DATE RANGE:</b>
226: </font>
1.98 harris41 227: <br />
1.8 harris41 228: between:
229: CREATIONDATESTART
1.11 harris41 230: $scrout.=&dateboxes('creationdatestart',1,1,1976,
231: $ENV{'form.creationdatestart_month'},
232: $ENV{'form.creationdatestart_day'},
233: $ENV{'form.creationdatestart_year'},
234: );
1.8 harris41 235: $scrout.=<<CREATIONDATEEND;
236: and:
237: CREATIONDATEEND
1.11 harris41 238: $scrout.=&dateboxes('creationdateend',12,31,2051,
239: $ENV{'form.creationdateend_month'},
240: $ENV{'form.creationdateend_day'},
241: $ENV{'form.creationdateend_year'},
242: );
1.8 harris41 243: $scrout.="</p>";
244:
245: $scrout.=<<LASTREVISIONDATESTART;
246: <p>
247: <font color="#800000" face="helvetica"><b>LIMIT BY LAST REVISION DATE RANGE:
248: </b></font>
1.98 harris41 249: <br />between:
1.8 harris41 250: LASTREVISIONDATESTART
1.11 harris41 251: $scrout.=&dateboxes('lastrevisiondatestart',1,1,1976,
252: $ENV{'form.lastrevisiondatestart_month'},
253: $ENV{'form.lastrevisiondatestart_day'},
254: $ENV{'form.lastrevisiondatestart_year'},
255: );
1.8 harris41 256: $scrout.=<<LASTREVISIONDATEEND;
257: and:
258: LASTREVISIONDATEEND
1.11 harris41 259: $scrout.=&dateboxes('lastrevisiondateend',12,31,2051,
260: $ENV{'form.lastrevisiondateend_month'},
261: $ENV{'form.lastrevisiondateend_day'},
262: $ENV{'form.lastrevisiondateend_year'},
263: );
1.8 harris41 264: $scrout.='</p>';
265:
266: $scrout.=&searchphrasefield('Limit by publisher/owner','owner',
1.11 harris41 267: $ENV{'form.owner'});
1.8 harris41 268:
1.11 harris41 269: $ENV{'form.copyright'}='any' unless length($ENV{'form.copyright'});
1.8 harris41 270: $scrout.=&selectbox('Limit by copyright/distribution','copyright',
1.11 harris41 271: $ENV{'form.copyright'},%cprtag);
1.8 harris41 272:
1.14 harris41 273: # ------------------------------------------- Compute customized metadata field
274: $scrout.=<<CUSTOMMETADATA;
275: <p>
1.77 harris41 276: <font color="#800000" face="helvetica"><b>LIMIT BY SPECIAL METADATA FIELDS:</b>
1.14 harris41 277: </font>
1.77 harris41 278: For resource-specific metadata, enter in an expression in the form of
1.100 harris41 279: <i>key</i>=<i>value</i> separated by operators such as AND, OR or NOT.<br />
1.14 harris41 280: <b>Example:</b> grandmother=75 OR grandfather=85
1.98 harris41 281: <br />
1.14 harris41 282: CUSTOMMETADATA
283: $scrout.=&simpletextfield('custommetadata',$ENV{'form.custommetadata'});
1.15 harris41 284: $scrout.=' <i>initial users of this system do not need to worry about this option</i>';
1.14 harris41 285:
1.77 harris41 286: $scrout.=<<CUSTOMSHOW;
287: <p>
288: <font color="#800000" face="helvetica"><b>SHOW SPECIAL METADATA FIELDS:</b>
289: </font>
290: Enter in a space-separated list of special metadata fields to show
291: in a fielded listing for each record result.
1.98 harris41 292: <br />
1.77 harris41 293: CUSTOMSHOW
294: $scrout.=&simpletextfield('customshow',$ENV{'form.customshow'});
295: $scrout.=' <i>initial users of this system do not need to worry about this option</i>';
296:
1.8 harris41 297: # ---------------------------------------------------------------- Print screen
298: $r->print(<<ENDDOCUMENT);
299: <html>
300: <head>
301: <title>The LearningOnline Network with CAPA</title>
1.100 harris41 302: <script type="text/javascript">
303: function openhelp(val) {
304: openhelpwin=open('/adm/help/searchcat.html','helpscreen',
305: 'scrollbars=1,width=400,height=300');
306: openhelpwin.focus();
307: }
308: </script>
1.8 harris41 309: </head>
310: <body bgcolor="#FFFFFF">
1.98 harris41 311: <img align='right' src='/adm/lonIcons/lonlogos.gif' />
1.8 harris41 312: <h1>Search Catalog</h1>
313: <form method="post" action="/adm/searchcat">
314: $hidden
1.98 harris41 315: <hr />
1.8 harris41 316: <h3>Basic Search</h3>
317: <p>
318: Enter terms or phrases separated by search operators
1.100 harris41 319: such as AND, OR, or NOT then press SEARCH below. Terms should be specific
1.8 harris41 320: to the title, author, subject, notes, or abstract information associated
321: with a resource.
1.98 harris41 322: <br />
1.11 harris41 323: ENDDOCUMENT
324: $r->print(&simpletextfield('basicexp',$ENV{'form.basicexp'}));
325: $r->print(' ');
326: $r->print(&simplecheckbox('titleonly',$ENV{'form.titleonly'}));
327: $r->print('<font color="#800000">Title only</font> ');
1.96 harris41 328: # $r->print(&simplecheckbox('allversions',$ENV{'form.allversions'}));
329: # <font color="#800000">Search historic archives</font>
1.11 harris41 330: $r->print(<<ENDDOCUMENT);
1.98 harris41 331: <br />
1.68 harris41 332: <input type="submit" name="basicsubmit" value='SEARCH' />
333: <input type="reset" name="reset" value='RESET' />
1.46 harris41 334: $closebutton
1.55 harris41 335: $basicviewselect
1.100 harris41 336: <input type="button" value="HELP" onClick="openhelp()" />
1.8 harris41 337: </p>
1.98 harris41 338: <hr />
1.8 harris41 339: <h3>Advanced Search</h3>
340: $scrout
341: <p>
1.68 harris41 342: <input type="submit" name="advancedsubmit" value='SEARCH' />
343: <input type="reset" name="reset" value='RESET' />
1.46 harris41 344: $closebutton
1.55 harris41 345: $advancedviewselect
1.100 harris41 346: <input type="button" value="HELP" onClick="openhelp()" />
1.3 harris41 347: </p>
1.8 harris41 348: </form>
349: </body>
350: </html>
351: ENDDOCUMENT
352: return OK;
353: }
354:
1.98 harris41 355: # ----------- grab unprocessed CGI variables that may have been appended to URL
356: sub get_unprocessed_cgi {
357: map {
358: my ($name, $value) = split(/=/,$_);
359: $value =~ tr/+/ /;
360: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.101 harris41 361: if ($name eq 'catalogmode' or $name eq 'launch' or $name eq 'acts') {
1.98 harris41 362: $ENV{'form.'.$name}=$value;
363: }
364: } (split(/&/,$ENV{'QUERY_STRING'}));
365: }
366:
367: # ------------------------------------------------------------- make persistent
368: sub make_persistent {
369: my $persistent='';
370:
371: map {
372: if (/^form\./ && !/submit/) {
373: my $name=$_;
374: my $key=$name;
375: $ENV{$key}=~s/\'//g; # do not mess with html field syntax
376: $name=~s/^form\.//;
377: $persistent.=<<END;
378: <input type='hidden' name='$name' value='$ENV{$key}' />
379: END
380: }
381: } (keys %ENV);
382: return $persistent;
383: }
384:
1.8 harris41 385: # --------------------------------------------------------- Various form fields
386:
1.11 harris41 387: sub simpletextfield {
388: my ($name,$value)=@_;
1.68 harris41 389: return '<input type=text name=\''.$name.
390: '\' size=20 value=\''.$value.'\' />';
1.11 harris41 391: }
392:
393: sub simplecheckbox {
394: my ($name,$value)=@_;
395: my $checked='';
396: $checked="CHECKED" if $value eq 'on';
1.68 harris41 397: return '<input type=checkbox name=\''.$name.'\' '. $checked . '>';
1.11 harris41 398: }
399:
1.8 harris41 400: sub searchphrasefield {
401: my ($title,$name,$value)=@_;
402: my $instruction=<<END;
403: Enter terms or phrases separated by search operators such
1.100 harris41 404: as AND, OR, or NOT.
1.8 harris41 405: END
406: my $uctitle=uc($title);
407: return "\n<p><font color=\"#800000\" face=\"helvetica\"><b>$uctitle:</b>".
1.98 harris41 408: "</FONT> $instruction<br />".
1.68 harris41 409: '<input type=text name="'.$name.'" size=80 value=\''.$value.'\'>';
1.8 harris41 410: }
1.3 harris41 411:
1.8 harris41 412: sub dateboxes {
1.11 harris41 413: my ($name,$defaultmonth,$defaultday,$defaultyear,
414: $currentmonth,$currentday,$currentyear)=@_;
415: ($defaultmonth,$defaultday,$defaultyear)=('','','');
416: my $month=<<END;
1.8 harris41 417: <select name="${name}_month">
1.11 harris41 418: <option value='$defaultmonth'> </option>
419: <option value="1">January</option>
420: <option value="2">February</option>
421: <option value="3">March</option>
422: <option value="4">April</option>
423: <option value="5">May</option>
424: <option value="6">June</option>
425: <option value="7">July</option>
426: <option value="8">August</option>
427: <option value="9">September</option>
1.3 harris41 428: <option value="10">October</option>
429: <option value="11">November</option>
430: <option value="12">December</option>
431: </select>
1.11 harris41 432: END
433: $month=~s/(\"$currentmonth\")/$1 SELECTED/ if length($currentmonth);
434: my $day=<<END;
1.8 harris41 435: <select name="${name}_day">
1.11 harris41 436: <option value='$defaultday'> </option>
437: <option value="1">1</option>
438: <option value="2">2</option>
439: <option value="3">3</option>
440: <option value="4">4</option>
441: <option value="5">5</option>
442: <option value="6">6</option>
443: <option value="7">7</option>
444: <option value="8">8</option>
445: <option value="9">9</option>
446: <option value="10">10</option>
447: <option value="11">11</option>
448: <option value="12">12</option>
449: <option value="13">13</option>
450: <option value="14">14</option>
451: <option value="15">15</option>
452: <option value="16">16</option>
453: <option value="17">17</option>
454: <option value="18">18</option>
455: <option value="19">19</option>
456: <option value="20">20</option>
457: <option value="21">21</option>
458: <option value="22">22</option>
459: <option value="23">23</option>
460: <option value="24">24</option>
461: <option value="25">25</option>
462: <option value="26">26</option>
463: <option value="27">27</option>
464: <option value="28">28</option>
465: <option value="29">29</option>
466: <option value="30">30</option>
467: <option value="31">31</option>
1.3 harris41 468: </select>
1.11 harris41 469: END
470: $day=~s/(\"$currentday\")/$1 SELECTED/ if length($currentday);
471: my $year=<<END;
1.8 harris41 472: <select name="${name}_year">
1.11 harris41 473: <option value='$defaultyear'> </option>
474: <option value="1976">1976</option>
475: <option value="1977">1977</option>
476: <option value="1978">1978</option>
477: <option value="1979">1979</option>
478: <option value="1980">1980</option>
479: <option value="1981">1981</option>
480: <option value="1982">1982</option>
481: <option value="1983">1983</option>
482: <option value="1984">1984</option>
483: <option value="1985">1985</option>
484: <option value="1986">1986</option>
485: <option value="1987">1987</option>
486: <option value="1988">1988</option>
487: <option value="1989">1989</option>
488: <option value="1990">1990</option>
489: <option value="1991">1991</option>
490: <option value="1992">1992</option>
491: <option value="1993">1993</option>
492: <option value="1994">1994</option>
493: <option value="1995">1995</option>
494: <option value="1996">1996</option>
495: <option value="1997">1997</option>
496: <option value="1998">1998</option>
497: <option value="1999">1999</option>
498: <option value="2000">2000</option>
499: <option value="2001">2001</option>
500: <option value="2002">2002</option>
501: <option value="2003">2003</option>
502: <option value="2004">2004</option>
503: <option value="2005">2005</option>
504: <option value="2006">2006</option>
505: <option value="2007">2007</option>
506: <option value="2008">2008</option>
507: <option value="2009">2009</option>
508: <option value="2010">2010</option>
509: <option value="2011">2011</option>
510: <option value="2012">2012</option>
511: <option value="2013">2013</option>
512: <option value="2014">2014</option>
513: <option value="2015">2015</option>
514: <option value="2016">2016</option>
515: <option value="2017">2017</option>
516: <option value="2018">2018</option>
517: <option value="2019">2019</option>
518: <option value="2020">2020</option>
519: <option value="2021">2021</option>
520: <option value="2022">2022</option>
521: <option value="2023">2023</option>
522: <option value="2024">2024</option>
523: <option value="2025">2025</option>
524: <option value="2026">2026</option>
525: <option value="2027">2027</option>
526: <option value="2028">2028</option>
527: <option value="2029">2029</option>
528: <option value="2030">2030</option>
529: <option value="2031">2031</option>
530: <option value="2032">2032</option>
531: <option value="2033">2033</option>
532: <option value="2034">2034</option>
533: <option value="2035">2035</option>
534: <option value="2036">2036</option>
535: <option value="2037">2037</option>
536: <option value="2038">2038</option>
537: <option value="2039">2039</option>
538: <option value="2040">2040</option>
539: <option value="2041">2041</option>
540: <option value="2042">2042</option>
541: <option value="2043">2043</option>
542: <option value="2044">2044</option>
543: <option value="2045">2045</option>
544: <option value="2046">2046</option>
545: <option value="2047">2047</option>
546: <option value="2048">2048</option>
547: <option value="2049">2049</option>
548: <option value="2050">2050</option>
549: <option value="2051">2051</option>
1.3 harris41 550: </select>
551: END
1.11 harris41 552: $year=~s/(\"$currentyear\")/$1 SELECTED/ if length($currentyear);
553: return "$month$day$year";
1.3 harris41 554: }
555:
556: sub selectbox {
557: my ($title,$name,$value,%options)=@_;
558: my $uctitle=uc($title);
559: my $selout="\n<p><font color=\"#800000\" face=\"helvetica\"><b>$uctitle:".
1.98 harris41 560: "</b></font><br />".'<select name="'.$name.'">';
1.3 harris41 561: map {
1.68 harris41 562: $selout.='<option value=\''.$_.'\'';
1.3 harris41 563: if ($_ eq $value) { $selout.=' selected'; }
564: $selout.='>'.$options{$_}.'</option>';
565: } sort keys %options;
566: return $selout.'</select>';
1.6 harris41 567: }
568:
1.45 harris41 569: # ----------------------------------------------- Performing an advanced search
1.18 harris41 570: sub advancedsearch {
571: my ($r,$envhash)=@_;
572: my %ENV=%{$envhash};
573:
1.32 harris41 574: my $fillflag=0;
1.64 harris41 575: # Clean up fields for safety
576: for my $field ('title','author','subject','keywords','url','version',
577: 'creationdatestart_month','creationdatestart_day',
578: 'creationdatestart_year','creationdateend_month',
579: 'creationdateend_day','creationdateend_year',
580: 'lastrevisiondatestart_month','lastrevisiondatestart_day',
581: 'lastrevisiondatestart_year','lastrevisiondateend_month',
582: 'lastrevisiondateend_day','lastrevisiondateend_year',
583: 'notes','abstract','mime','language','owner',
1.77 harris41 584: 'custommetadata','customshow') {
1.101 harris41 585: $ENV{"form.$field"}=~s/[^\w\/\s\(\)\=\-\"\']//g;
1.64 harris41 586: }
1.90 harris41 587:
588: # Check to see if enough information was filled in
1.32 harris41 589: for my $field ('title','author','subject','keywords','url','version',
590: 'notes','abstract','mime','language','owner',
591: 'custommetadata') {
1.40 harris41 592: if (&filled($ENV{"form.$field"})) {
1.32 harris41 593: $fillflag++;
594: }
595: }
596: unless ($fillflag) {
597: &output_blank_field_error($r);
598: return OK;
599: }
1.39 harris41 600:
1.90 harris41 601:
602: # Turn the form input into a SQL-based query
1.39 harris41 603: my $query='';
1.44 harris41 604:
1.45 harris41 605: my @queries;
1.90 harris41 606: # Evaluate logical expression AND/OR/NOT phrase fields.
1.58 harris41 607: foreach my $field ('title','author','subject','notes','abstract','url',
608: 'keywords','version','owner') {
1.44 harris41 609: if ($ENV{'form.'.$field}) {
1.45 harris41 610: push @queries,&build_SQL_query($field,$ENV{'form.'.$field});
1.44 harris41 611: }
612: }
1.90 harris41 613: # Evaluate option lists
1.58 harris41 614: if ($ENV{'form.language'} and $ENV{'form.language'} ne 'any') {
1.90 harris41 615: push @queries,"(language like \"$ENV{'form.language'}\")";
1.58 harris41 616: }
617: if ($ENV{'form.mime'} and $ENV{'form.mime'} ne 'any') {
1.90 harris41 618: push @queries,"(mime like \"$ENV{'form.mime'}\")";
1.58 harris41 619: }
620: if ($ENV{'form.copyright'} and $ENV{'form.copyright'} ne 'any') {
1.90 harris41 621: push @queries,"(copyright like \"$ENV{'form.copyright'}\")";
1.58 harris41 622: }
1.90 harris41 623: # Evaluate date windows
1.60 harris41 624: my $datequery=&build_date_queries(
625: $ENV{'form.creationdatestart_month'},
626: $ENV{'form.creationdatestart_day'},
627: $ENV{'form.creationdatestart_year'},
628: $ENV{'form.creationdateend_month'},
629: $ENV{'form.creationdateend_day'},
630: $ENV{'form.creationdateend_year'},
631: $ENV{'form.lastrevisiondatestart_month'},
632: $ENV{'form.lastrevisiondatestart_day'},
633: $ENV{'form.lastrevisiondatestart_year'},
634: $ENV{'form.lastrevisiondateend_month'},
635: $ENV{'form.lastrevisiondateend_day'},
636: $ENV{'form.lastrevisiondateend_year'},
637: );
1.90 harris41 638: # Test to see if date windows are legitimate
1.61 harris41 639: if ($datequery=~/^Incorrect/) {
640: &output_date_error($r,$datequery);
641: return OK;
642: }
643: elsif ($datequery) {
1.60 harris41 644: push @queries,$datequery;
645: }
1.90 harris41 646:
647: # Process form information for custom metadata querying
1.76 harris41 648: my $customquery='';
1.64 harris41 649: if ($ENV{'form.custommetadata'}) {
650: $customquery=&build_custommetadata_query('custommetadata',
651: $ENV{'form.custommetadata'});
652: }
1.83 harris41 653: my $customshow='';
654: if ($ENV{'form.customshow'}) {
655: $customshow=$ENV{'form.customshow'};
656: $customshow=~s/[^\w\s]//g;
657: my @fields=split(/\s+/,$customshow);
658: $customshow=join(" ",@fields);
659: }
1.90 harris41 660: # Send query statements over the network to be processed by either the SQL
661: # database or a recursive scheme of 'grep'-like actions (for custom
662: # metadata).
1.45 harris41 663: if (@queries) {
1.58 harris41 664: $query=join(" AND ",@queries);
1.46 harris41 665: $query="select * from metadata where $query";
1.90 harris41 666: my $reply; # reply hash reference
1.83 harris41 667: unless ($customquery or $customshow) {
1.76 harris41 668: $reply=&Apache::lonnet::metadata_query($query);
669: }
670: else {
1.83 harris41 671: $reply=&Apache::lonnet::metadata_query($query,
672: $customquery,$customshow);
1.76 harris41 673: }
1.64 harris41 674: &output_results('Advanced',$r,$envhash,$customquery,$reply);
1.45 harris41 675: }
1.86 harris41 676: elsif ($customquery) {
1.90 harris41 677: my $reply; # reply hash reference
1.86 harris41 678: $reply=&Apache::lonnet::metadata_query('',
679: $customquery,$customshow);
680: &output_results('Advanced',$r,$envhash,$customquery,$reply);
1.45 harris41 681: }
1.92 harris41 682: # should not get to this point
683: return 'Error. Should not have gone to this point.';
1.18 harris41 684: }
685:
1.6 harris41 686: # --------------------------------------------------- Performing a basic search
687: sub basicsearch {
1.19 harris41 688: my ($r,$envhash)=@_;
689: my %ENV=%{$envhash};
1.64 harris41 690: # Clean up fields for safety
691: for my $field ('basicexp') {
692: $ENV{"form.$field"}=~s/[^\w\s\(\)\-]//g;
693: }
694:
1.90 harris41 695: # Check to see if enough is filled in
1.26 harris41 696: unless (&filled($ENV{'form.basicexp'})) {
1.24 harris41 697: &output_blank_field_error($r);
698: return OK;
699: }
1.22 harris41 700:
1.90 harris41 701: # Build SQL query string based on form page
1.39 harris41 702: my $query='';
1.33 harris41 703: my $concatarg=join('," ",',
704: ('title', 'author', 'subject', 'notes', 'abstract'));
1.95 harris41 705: $concatarg='title' if $ENV{'form.titleonly'};
1.94 harris41 706:
707: $query=&build_SQL_query('concat('.$concatarg.')',$ENV{'form.'.'basicexp'});
708:
1.90 harris41 709: # Get reply (either a hash reference to filehandles or bad connection)
1.94 harris41 710: my $reply=&Apache::lonnet::metadata_query('select * from metadata where '.$query);
1.90 harris41 711:
712: # Output search results
1.98 harris41 713:
1.44 harris41 714: &output_results('Basic',$r,$envhash,$query,$reply);
1.90 harris41 715:
1.18 harris41 716: return OK;
1.22 harris41 717: }
718:
1.98 harris41 719: # ------------------------------------------------------------- build_SQL_query
720: sub build_SQL_query {
721: my ($field_name,$logic_statement)=@_;
722: my $q=new Text::Query('abc',
723: -parse => 'Text::Query::ParseAdvanced',
724: -build => 'Text::Query::Build');
725: $q->prepare($logic_statement);
726: my $matchexp=${$q}{'matchexp'}; chomp $matchexp;
727: my $sql_query=&recursive_SQL_query_build($field_name,$matchexp);
728: return $sql_query;
729: }
730:
731: # ------------------------------------------------- build custom metadata query
732: sub build_custommetadata_query {
733: my ($field_name,$logic_statement)=@_;
734: my $q=new Text::Query('abc',
735: -parse => 'Text::Query::ParseAdvanced',
736: -build => 'Text::Query::BuildAdvancedString');
737: $q->prepare($logic_statement);
738: my $matchexp=${$q}{'-parse'}{'-build'}{'matchstring'};
739: # quick fix to change literal into xml tag-matching
740: # will eventually have to write a separate builder module
741: my $oldmatchexp=$matchexp;
742: $matchexp=~s/(\w+)\\\=([\w\\\+]+)/\\\<$1\\\>\[\^\\\<\]\*$2\[\^\\\<\]\*\\\<\\\/$1\\\>/g;
743: return $matchexp;
744: }
745:
746: # - Recursively parse a reverse notation expression into a SQL query expression
747: sub recursive_SQL_query_build {
748: my ($dkey,$pattern)=@_;
749: my @matches=($pattern=~/(\[[^\]|\[]*\])/g);
750: return $pattern unless @matches;
751: foreach my $match (@matches) {
752: $match=~/\[ (\w+)\s(.*) \]/;
753: my ($key,$value)=($1,$2);
754: my $replacement='';
755: if ($key eq 'literal') {
756: $replacement="($dkey like \"\%$value\%\")";
757: }
758: elsif ($key eq 'not') {
759: $value=~s/like/not like/;
760: # $replacement="($dkey not like $value)";
761: $replacement="$value";
762: }
763: elsif ($key eq 'and') {
764: $value=~/(.*[\"|\)]) ([|\(|\^].*)/;
765: $replacement="($1 AND $2)";
766: }
767: elsif ($key eq 'or') {
768: $value=~/(.*[\"|\)]) ([|\(|\^].*)/;
769: $replacement="($1 OR $2)";
770: }
771: substr($pattern,
772: index($pattern,$match),
773: length($match),
774: $replacement
775: );
776: }
777: &recursive_SQL_query_build($dkey,$pattern);
778: }
1.22 harris41 779:
1.98 harris41 780: # ------------------------------------------------------------ Build date query
781: sub build_date_queries {
782: my ($cmonth1,$cday1,$cyear1,$cmonth2,$cday2,$cyear2,
783: $lmonth1,$lday1,$lyear1,$lmonth2,$lday2,$lyear2)=@_;
784: my @queries;
785: if ($cmonth1 or $cday1 or $cyear1 or $cmonth2 or $cday2 or $cyear2) {
786: unless ($cmonth1 and $cday1 and $cyear1 and
787: $cmonth2 and $cday2 and $cyear2) {
788: return "Incorrect entry for the creation date. You must specify ".
789: "a starting month, day, and year and an ending month, ".
790: "day, and year.";
791: }
792: my $cnumeric1=sprintf("%d%2d%2d",$cyear1,$cmonth1,$cday1);
793: $cnumeric1+=0;
794: my $cnumeric2=sprintf("%d%2d%2d",$cyear2,$cmonth2,$cday2);
795: $cnumeric2+=0;
796: if ($cnumeric1>$cnumeric2) {
797: return "Incorrect entry for the creation date. The starting ".
798: "date must occur before the ending date.";
799: }
800: my $cquery="(creationdate BETWEEN '$cyear1-$cmonth1-$cday1' AND '".
801: "$cyear2-$cmonth2-$cday2 23:59:59')";
802: push @queries,$cquery;
803: }
804: if ($lmonth1 or $lday1 or $lyear1 or $lmonth2 or $lday2 or $lyear2) {
805: unless ($lmonth1 and $lday1 and $lyear1 and
806: $lmonth2 and $lday2 and $lyear2) {
807: return "Incorrect entry for the last revision date. You must ".
808: "specify a starting month, day, and year and an ending ".
809: "month, day, and year.";
810: }
811: my $lnumeric1=sprintf("%d%2d%2d",$lyear1,$lmonth1,$lday1);
812: $lnumeric1+=0;
813: my $lnumeric2=sprintf("%d%2d%2d",$lyear2,$lmonth2,$lday2);
814: $lnumeric2+=0;
815: if ($lnumeric1>$lnumeric2) {
816: return "Incorrect entry for the last revision date. The ".
817: "starting date must occur before the ending date.";
818: }
819: my $lquery="(lastrevisiondate BETWEEN '$lyear1-$lmonth1-$lday1' AND '".
820: "$lyear2-$lmonth2-$lday2 23:59:59')";
821: push @queries,$lquery;
822: }
823: if (@queries) {
824: return join(" AND ",@queries);
825: }
826: return '';
1.18 harris41 827: }
1.6 harris41 828:
1.18 harris41 829: # ----------------------------- format and output results based on a reply list
1.98 harris41 830: # There are two windows that this function writes to. The main search
831: # window ("srch") has a listing of the results. A secondary window ("popwin")
832: # gives the status of the network search (time elapsed, number of machines
833: # contacted, etc.)
1.18 harris41 834: sub output_results {
1.101 harris41 835: my $fnum; # search result counter
1.92 harris41 836: my ($mode,$r,$envhash,$query,$replyref)=@_;
1.19 harris41 837: my %ENV=%{$envhash};
1.92 harris41 838: my %rhash=%{$replyref};
1.44 harris41 839: my $compiledresult='';
1.102 harris41 840: my $timeremain=300;
1.98 harris41 841: my $elapsetime=0;
1.93 harris41 842: my $resultflag=0;
843: my $tflag=1;
844:
845: # make query information persistent to allow for subsequent revision
846: my $persistent=&make_persistent();
847:
848: # output beginning of search page
1.92 harris41 849: $r->print(<<BEGINNING);
850: <html>
851: <head>
852: <title>The LearningOnline Network with CAPA</title>
853: BEGINNING
1.98 harris41 854:
855: # conditional output of script functions dependent on the mode in
856: # which the search was invoked
1.92 harris41 857: $r->print(<<SCRIPT) if $ENV{'form.catalogmode'} eq 'interactive';
1.100 harris41 858: <script type="text/javascript">
1.92 harris41 859: function select_data(title,url) {
860: changeTitle(title);
861: changeURL(url);
1.97 harris41 862: self.close();
1.92 harris41 863: }
864: function changeTitle(val) {
865: if (opener.inf.document.forms.resinfo.elements.t) {
866: opener.inf.document.forms.resinfo.elements.t.value=val;
867: }
868: }
869: function changeURL(val) {
870: if (opener.inf.document.forms.resinfo.elements.u) {
871: opener.inf.document.forms.resinfo.elements.u.value=val;
872: }
873: }
874: </script>
875: SCRIPT
1.98 harris41 876: $r->print(<<SCRIPT) if $ENV{'form.catalogmode'} eq 'groupsearch';
1.100 harris41 877: <script type="text/javascript">
1.98 harris41 878: function select_data(title,url) {
1.101 harris41 879: // alert('DEBUG: Should be storing '+title+' and '+url);
1.98 harris41 880: }
881: function queue(val) {
1.101 harris41 882: if (eval("document.forms.results.returnvalues["+val+"].checked")) {
1.98 harris41 883: document.forms.results.acts.value+='1a'+val+'b';
884: }
885: else {
886: document.forms.results.acts.value+='0a'+val+'b';
887: }
888: }
889: function select_group() {
1.101 harris41 890: window.location="/adm/groupsort?catalogmode=groupsearch&acts="+
891: document.forms.results.acts.value;
1.98 harris41 892: }
893: </script>
894: SCRIPT
1.100 harris41 895: $r->print(<<SCRIPT);
896: <script type="text/javascript">
1.98 harris41 897: function displayinfo(val) {
898: popwin.document.forms.popremain.sdetails.value=val;
899: }
1.100 harris41 900: function openhelp(val) {
901: openhelpwin=open('/adm/help/searchcat.html','helpscreen',
902: 'scrollbars=1,width=400,height=300');
903: openhelpwin.focus();
904: }
1.102 harris41 905: function abortsearch(val) {
906: openhelpwin=open('/adm/help/searchcat.html','helpscreen',
907: 'scrollbars=1,width=400,height=300');
908: openhelpwin.focus();
909: }
1.98 harris41 910: </script>
911: SCRIPT
912: $r->rflush();
913:
914: # begin showing the cataloged results
1.92 harris41 915: $r->print(<<CATALOGBEGIN);
916: </head>
917: <body bgcolor="#ffffff">
918: <img align=right src=/adm/lonIcons/lonlogos.gif>
919: <h1>Search Catalog</h1>
920: CATALOGBEGIN
1.98 harris41 921: $r->print(<<CATALOGCONTROLS);
922: <form name='results' method="post" action="/adm/searchcat">
923: <input type='hidden' name='acts' value='' />
1.93 harris41 924: <input type='button' value='Revise search request'
1.98 harris41 925: onClick='this.form.submit();' />
926: $importbutton
1.93 harris41 927: $closebutton
928: $persistent
1.98 harris41 929: <hr />
1.93 harris41 930: <h3>Search Query</h3>
1.98 harris41 931: CATALOGCONTROLS
1.93 harris41 932: if ($mode eq 'Basic') {
933: $r->print(<<RESULTS);
934: <p>
935: <b>Basic search:</b> $ENV{'form.basicexp'}
936: </p>
937: RESULTS
938: }
939: elsif ($mode eq 'Advanced') {
940: $r->print(<<RESULTS);
941: <p>
942: <b>Advanced search</b>
943: $query
944: </p>
945: RESULTS
946: }
947: $r->print('<h3>Search Results</h3>');
1.92 harris41 948: $r->rflush();
1.98 harris41 949: my $servernum=(keys %rhash)+0;
950:
951: # define server grid (shows status of multiple machines)
952: my $hcinit;
953: my $grid="'<br />'+";
954: $grid.="\n";
955: my $sn=1;
956: for my $sk (sort keys %rhash) {
957: # '<a href="
958: $grid.="'<a href=\"";
959: # javascript:displayinfo('+
960: $grid.="javascript:opener.displayinfo('+";
961: # "'"+'key
962: $grid.="\"'\"+'";
1.99 harris41 963: $grid.=$sk;
1.98 harris41 964: my $hc;
965: if ($rhash{$sk} eq 'con_lost') {
966: $hc="!!!BAD CONNECTION, CONTACT SYSTEM ADMINISTRATOR!!!";
967: }
968: else {
969: $hc="'+\"'\"+\"+hc['$sk']+\"+\"'\"+'";
1.99 harris41 970: $hcinit.="hc[\"$sk\"]=\"not yet connected...\";";
1.98 harris41 971: }
972: $grid.=" hitcount=".$hc;
1.99 harris41 973: $grid.=" domain=".$hostdomains{$sk};
1.98 harris41 974: $grid.=" IP=".$hostips{$sk};
975: # '+"'"+'">'+
976: $grid.="'+\"'\"+')\">'+";
977: $grid.="\n";
978: $grid.="'<img border=\"0\" name=\"img".$sn."\"".
1.99 harris41 979: " src=\"/adm/lonIcons/srvnull.gif\" alt=\"".$sk."\" /></a>'+\n";
1.98 harris41 980: $grid.="'<br />'+\n" unless $sn%10;
981: $sn++;
982: }
1.92 harris41 983: $r->print(<<ENDPOP);
1.100 harris41 984: <script type="text/javascript">
1.98 harris41 985: popwin=open('','popwin','scrollbars=1,width=400,height=200');
986: popwin.focus();
987: popwin.document.writeln('<'+'html>');
988: popwin.document.writeln('<'+'head>');
989: popwin.document.writeln('<'+'script>');
990: popwin.document.writeln('hc=new Array();$hcinit');
991: popwin.document.writeln('<'+'/script>');
992: popwin.document.writeln('<'+'/head>'+
993: '<'+'body bgcolor="#FFFFFF">'+
1.100 harris41 994: '<'+'image name="whirly" align="right" src="/adm/lonIcons/'+
1.99 harris41 995: 'lonanim.gif" '+
996: 'alt="animated logo" />'+
1.98 harris41 997: '<'+'h3>Search Results Progress<'+'/h3>'+
998: '<'+'form name="popremain">'+
999: '<'+'tt>'+
1.99 harris41 1000: '<'+'br clear="all"/><i>PLEASE BE PATIENT</i>'+
1.98 harris41 1001: '<'+'br />SCANNING $servernum SERVERS'+
1002: '<'+'br clear="all" />Number of record hits found '+
1003: '<'+'input type="text" size="10" name="numhits"'+
1004: ' value="0" />'+
1005: '<'+'br clear="all" />Time elapsed '+
1006: '<'+'input type="text" size="10" name="elapsetime"'+
1007: ' value="0" />'+
1008: '<'+'br />'+
1009: 'SERVER GRID (click on any cell for details)'+
1010: $grid
1011: '<'+'br />'+
1012: 'Server details '+
1013: '<'+'input type="text" size="25" name="sdetails"'+
1014: ' value="" />'+
1015: '<'+'br />'+
1016: ' <'+'input type="button" name="button"'+
1.100 harris41 1017: ' value="abort search and view current results" '+
1.102 harris41 1018: ' onClick="javascript:opener.abortsearch()" />'+
1.98 harris41 1019: ' <'+'input type="button" name="button"'+
1.100 harris41 1020: ' value="help" onClick="javascript:opener.openhelp()" />'+
1.98 harris41 1021: '<'+'/tt>'+
1022: '<'+'/form>'+
1023: '<'+'/body><'+'/html>');
1.92 harris41 1024: popwin.document.close();
1025: </script>
1026: ENDPOP
1027: $r->rflush();
1.44 harris41 1028:
1.93 harris41 1029: my $servercount=0;
1.98 harris41 1030: my $hitcountsum=0;
1.102 harris41 1031: my $bloop=$servernum;
1032: my %orkey;
1033: BLOOP: while(1) {
1034: my $sn=0;
1035: last BLOOP unless $bloop;
1036: RLOOP: foreach my $rkey (sort keys %rhash) {
1.98 harris41 1037: $sn++;
1.102 harris41 1038: next RLOOP if $orkey{$rkey};
1.93 harris41 1039: $servercount++;
1040: $tflag=1;
1041: $compiledresult='';
1042: my $hostname=$rkey;
1.92 harris41 1043: my $reply=$rhash{$rkey};
1.18 harris41 1044: my @results;
1.92 harris41 1045:
1.18 harris41 1046: my $replyfile='';
1.93 harris41 1047:
1048: if ($reply eq 'con_lost') {
1.100 harris41 1049: $r->print('<script type="text/javascript">popwin.document.img'.
1050: $sn.'.'.
1.99 harris41 1051: 'src="/adm/lonIcons/srvbad.gif";</script>'.
1052: "\n");
1053: $r->rflush();
1.102 harris41 1054: $bloop--;
1055: $orkey{$rkey}=1;
1.93 harris41 1056: }
1057: else {
1058: $reply=~/^([\.\w]+)$/; # must do since 'use strict' checks for tainting
1059: $replyfile=$r->dir_config('lonDaemons').'/tmp/'.$1;
1060: $reply=~/(.*?)\_/;
1061: {
1.98 harris41 1062: my $temp=0;
1063: WLOOP: while (1) {
1064: if (-e $replyfile && $tflag) {
1.100 harris41 1065: $r->print('<script type="text/javascript">'.
1066: 'popwin.document.img'.$sn.'.'.
1.99 harris41 1067: 'src="/adm/lonIcons/srvhalf.gif";</script>'.
1.98 harris41 1068: "\n");
1069: $r->rflush();
1.100 harris41 1070: $r->print('<script type="text/javascript">'.
1071: 'popwin.hc["'.$rkey.'"]='.
1.99 harris41 1072: '"still transferring..."'.';</script>'.
1.98 harris41 1073: "\n");
1074: $r->rflush();
1075: $tflag=0;
1076: }
1.102 harris41 1077: last WLOOP if $temp>1;
1.98 harris41 1078: if (-e "$replyfile.end") {
1.102 harris41 1079: $bloop--;
1080: $orkey{$rkey}=1;
1.98 harris41 1081: if (-s $replyfile) {
1.100 harris41 1082: $r->print('<script type="text/javascript">'.
1083: 'popwin.document.img'.$sn.'.'.
1084: 'src="/adm/lonIcons/srvgood.gif";'.
1085: '</script>'."\n");
1.98 harris41 1086: $r->rflush();
1087: my $fh=Apache::File->new($replyfile) or
1088: ($r->print('ERROR: file '.
1089: $replyfile.' cannot be opened') and
1090: return OK);
1091: @results=<$fh> if $fh;
1092: $hitcount{$rkey}=@results+0;
1.100 harris41 1093: $r->print('<script type="text/javascript">'.
1094: 'popwin.hc["'.$rkey.'"]='.
1.98 harris41 1095: $hitcount{$rkey}.';</script>'.
1096: "\n");
1097: $r->rflush();
1098: $hitcountsum+=$hitcount{$rkey};
1.100 harris41 1099: $r->print('<script type="text/javascript">'.
1100: 'popwin.document.forms.popremain.'.
1.98 harris41 1101: 'numhits.value='.$hitcountsum.
1102: ';</script>'.
1103: "\n");
1104: $r->rflush();
1105: }
1.99 harris41 1106: else {
1.100 harris41 1107: $r->print('<script type="text/javascript">'.
1108: 'popwin.document.img'.$sn.'.'.
1109: 'src="/adm/lonIcons/srvempty.gif";'.
1110: '</script>'.
1111: "\n");
1.99 harris41 1112: $r->rflush();
1.100 harris41 1113: $r->print('<script type="text/javascript">'.
1114: 'popwin.hc["'.$rkey.'"]=0'.
1.99 harris41 1115: ';</script>'.
1116: "\n");
1117: $r->rflush();
1118: }
1.98 harris41 1119: last WLOOP;
1120: }
1121: last WLOOP unless $timeremain;
1122: sleep 1;
1123: $timeremain--;
1124: $elapsetime++;
1.100 harris41 1125: $r->print('<script type="text/javascript">'.
1126: 'popwin.document.popremain.elapsetime.'.
1.98 harris41 1127: 'value="'.$elapsetime.'";</script>'."\n");
1128: $r->rflush();
1129: $temp++;
1130: }
1.93 harris41 1131: }
1.100 harris41 1132: $r->print('<script type="text/javascript">'.
1133: 'popwin.document.whirly.'.
1134: 'src="'.'/adm/lonIcons/lonanimend.gif'.
1135: '";</script>'."\n");
1136: $r->rflush();
1.6 harris41 1137: }
1.77 harris41 1138: my $customshow='';
1139: my $extrashow='';
1.87 harris41 1140: my @customfields;
1.77 harris41 1141: if ($ENV{'form.customshow'}) {
1142: $customshow=$ENV{'form.customshow'};
1143: $customshow=~s/[^\w\s]//g;
1.87 harris41 1144: my @fields=map {"<font color=\"#008000\">$_:</font><!-- $_ -->"}
1.93 harris41 1145: split(/\s+/,$customshow);
1.88 harris41 1146: @customfields=split(/\s+/,$customshow);
1.81 harris41 1147: if ($customshow) {
1148: $extrashow="<ul><li>".join("</li><li>",@fields)."</li></ul>\n";
1149: }
1.77 harris41 1150: }
1.79 harris41 1151: my $customdata='';
1.87 harris41 1152: my %customhash;
1.79 harris41 1153: foreach my $result (@results) {
1.82 harris41 1154: if ($result=~/^(custom\=.*)$/) { # grab all custom metadata
1.87 harris41 1155: my $tmp=$result;
1156: $tmp=~s/^custom\=//;
1157: my ($k,$v)=map {&Apache::lonnet::unescape($_);
1158: } split(/\,/,$tmp);
1159: $customhash{$k}=$v;
1.82 harris41 1160: }
1.79 harris41 1161: }
1.101 harris41 1162: if (keys %hash) {
1163: untie %hash;
1164: }
1165: if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) {
1166: if ($ENV{'form.launch'} eq '1') {
1167: &start_fresh_session();
1168: }
1169: foreach my $result (@results) {
1170: next if $result=~/^custom\=/;
1171: chomp $result;
1172: next unless $result;
1173: my @fields=map
1174: {&Apache::lonnet::unescape($_)}
1175: (split(/\,/,$result));
1176: my ($title,$author,$subject,$url,$keywords,$version,
1177: $notes,$abstract,$mime,$lang,
1178: $creationdate,$lastrevisiondate,$owner,$copyright)=@fields;
1.102 harris41 1179:
1180: unless ($ENV{'user.adv'}) {
1181: $keywords='<i>- not displayed -</i>';
1182: $fields[4]=$keywords;
1183: $notes='<i>- not displayed -</i>';
1184: $fields[6]=$notes;
1185: $abstract='<i>- not displayed -</i>';
1186: $fields[7]=$abstract;
1187: $subject='<i>- not displayed -</i>';
1188: $fields[2]=$subject;
1189: }
1190:
1.101 harris41 1191: my $shortabstract=$abstract;
1.102 harris41 1192: $shortabstract=substr($abstract,0,200).'...' if length($abstract)>200;
1.101 harris41 1193: $fields[7]=$shortabstract;
1.102 harris41 1194: my $shortkeywords=$keywords;
1195: $shortkeywords=substr($keywords,0,200).'...' if length($keywords)>200;
1196: $fields[4]=$shortkeywords;
1197:
1.101 harris41 1198: my $extrashow2=$extrashow;
1199: if ($extrashow) {
1200: foreach my $field (@customfields) {
1201: my $value='';
1202: if ($customhash{$url}=~/\<${field}[^\>]*\>(.*?)\<\/${field}[^\>]*\>/s) {
1203: $value=$1;
1204: }
1205: $extrashow2=~s/\<\!\-\- $field \-\-\>/ $value/g;
1206: }
1207: }
1.93 harris41 1208:
1.101 harris41 1209: $compiledresult.=<<END if $compiledresult or $servercount!=$servernum;
1.89 harris41 1210: <hr align='left' width='200' noshade />
1211: END
1.101 harris41 1212: $compiledresult.=<<END;
1.56 harris41 1213: <p>
1.8 harris41 1214: END
1.101 harris41 1215: $compiledresult.=<<END if $ENV{'form.catalogmode'} eq 'interactive';
1.8 harris41 1216: <font size='-1'><INPUT TYPE="button" NAME="returnvalues" VALUE="SELECT"
1.10 harris41 1217: onClick="javascript:select_data('$title','$url')">
1.8 harris41 1218: </font>
1.98 harris41 1219: <br />
1220: END
1.101 harris41 1221: if ($ENV{'form.catalogmode'} eq 'groupsearch') {
1222: $fnum+=0;
1223: $hash{"pre_${fnum}_link"}=$url;
1224: $hash{"pre_${fnum}_title"}=$title;
1225: $compiledresult.=<<END;
1.98 harris41 1226: <font size='-1'><input type="checkbox" name="returnvalues" value="SELECT"
1227: onClick="javascript:queue($fnum)" />
1228: </font>
1229: <br />
1.8 harris41 1230: END
1.101 harris41 1231: # <input type="hidden" name="title$fnum" value="$title" />
1232: # <input type="hidden" name="url$fnum" value="$url" />
1233: $fnum++;
1234: }
1235: my $httphost=$ENV{'HTTP_HOST'};
1236:
1237: my $viewselect;
1238: if ($mode eq 'Basic') {
1239: $viewselect=$ENV{'form.basicviewselect'};
1240: }
1241: elsif ($mode eq 'Advanced') {
1242: $viewselect=$ENV{'form.advancedviewselect'};
1243: }
1.55 harris41 1244:
1.101 harris41 1245: if ($viewselect eq 'Detailed Citation View') {
1246: $compiledresult.=&detailed_citation_view(@fields,
1.93 harris41 1247: $hostname,$httphost,
1248: $extrashow2);
1.101 harris41 1249: }
1250: elsif ($viewselect eq 'Summary View') {
1251: $compiledresult.=&summary_view(@fields,$hostname,$httphost,
1.93 harris41 1252: $extrashow2);
1.101 harris41 1253: }
1254: elsif ($viewselect eq 'Fielded Format') {
1255: $compiledresult.=&fielded_format_view(@fields,$hostname,
1.93 harris41 1256: $httphost,$extrashow2);
1.101 harris41 1257: }
1258: elsif ($viewselect eq 'XML/SGML') {
1259: $compiledresult.=&xml_sgml_view(@fields,$hostname,$httphost,
1.93 harris41 1260: $extrashow2);
1.101 harris41 1261: }
1.93 harris41 1262:
1.101 harris41 1263: }
1264:
1265: untie %hash;
1.18 harris41 1266: }
1.101 harris41 1267: else {
1268: $r->print('<html><head></head><body>Unable to tie hash to db '.
1269: 'file</body></html>');
1270: }
1.93 harris41 1271: if ($compiledresult) {
1272: $resultflag=1;
1.18 harris41 1273: }
1.6 harris41 1274:
1.43 harris41 1275: $r->print(<<RESULTS);
1.93 harris41 1276: $compiledresult
1.43 harris41 1277: RESULTS
1.93 harris41 1278: my $percent=sprintf('%3.0f',($servercount/$servernum*100));
1.44 harris41 1279: }
1.102 harris41 1280: }
1.93 harris41 1281: unless ($resultflag) {
1282: $r->print("\nThere were no results that matched your query\n");
1.43 harris41 1283: }
1.100 harris41 1284: # $r->print('<script type="text/javascript">'.'popwin.close()</script>'."\n"); $r->rflush();
1.93 harris41 1285: $r->print(<<RESULTS);
1.6 harris41 1286: </body>
1287: </html>
1288: RESULTS
1.41 harris41 1289: }
1290:
1.50 harris41 1291: # ------------------------------------------------------ Detailed Citation View
1292: sub detailed_citation_view {
1293: my ($title,$author,$subject,$url,$keywords,$version,
1.51 harris41 1294: $notes,$shortabstract,$mime,$lang,
1295: $creationdate,$lastrevisiondate,$owner,$copyright,
1.77 harris41 1296: $hostname,$httphost,$extrashow)=@_;
1.50 harris41 1297: my $result=<<END;
1.56 harris41 1298: <i>$owner</i>, last revised $lastrevisiondate
1299: <h3><A HREF="http://$httphost$url" TARGET='search_preview'>$title</A></h3>
1300: <h3>$author</h3>
1301: </p>
1302: <p>
1.98 harris41 1303: <b>Subject:</b> $subject<br />
1304: <b>Keyword(s):</b> $keywords<br />
1305: <b>Notes:</b> $notes<br />
1306: <b>MIME Type:</b> $mimetag{$mime}<br />
1307: <b>Language:</b> $language{$lang}<br />
1308: <b>Copyright/Distribution:</b> $cprtag{$copyright}<br />
1.78 harris41 1309: </p>
1.77 harris41 1310: $extrashow
1.78 harris41 1311: <p>
1.56 harris41 1312: $shortabstract
1.50 harris41 1313: </p>
1314: END
1315: return $result;
1316: }
1317:
1318: # ---------------------------------------------------------------- Summary View
1319: sub summary_view {
1320: my ($title,$author,$subject,$url,$keywords,$version,
1.51 harris41 1321: $notes,$shortabstract,$mime,$lang,
1322: $creationdate,$lastrevisiondate,$owner,$copyright,
1.77 harris41 1323: $hostname,$httphost,$extrashow)=@_;
1.50 harris41 1324: my $result=<<END;
1.56 harris41 1325: <a href="http://$httphost$url" TARGET='search_preview'>$author</a><br />
1326: $title<br />
1327: $owner -- $lastrevisiondate<br />
1328: $cprtag{$copyright}<br />
1.77 harris41 1329: $extrashow
1.50 harris41 1330: </p>
1331: END
1332: return $result;
1333: }
1334:
1335: # -------------------------------------------------------------- Fielded Format
1336: sub fielded_format_view {
1337: my ($title,$author,$subject,$url,$keywords,$version,
1.51 harris41 1338: $notes,$shortabstract,$mime,$lang,
1339: $creationdate,$lastrevisiondate,$owner,$copyright,
1.77 harris41 1340: $hostname,$httphost,$extrashow)=@_;
1.50 harris41 1341: my $result=<<END;
1.51 harris41 1342: <b>URL: </b> <A HREF="http://$httphost$url" TARGET='search_preview'>$url</A>
1.56 harris41 1343: <br />
1344: <b>Title:</b> $title<br />
1345: <b>Author(s):</b> $author<br />
1346: <b>Subject:</b> $subject<br />
1347: <b>Keyword(s):</b> $keywords<br />
1348: <b>Notes:</b> $notes<br />
1349: <b>MIME Type:</b> $mimetag{$mime}<br />
1350: <b>Language:</b> $language{$lang}<br />
1351: <b>Creation Date:</b> $creationdate<br />
1352: <b>Last Revision Date:</b> $lastrevisiondate<br />
1353: <b>Publisher/Owner:</b> $owner<br />
1354: <b>Copyright/Distribution:</b> $cprtag{$copyright}<br />
1355: <b>Repository Location:</b> $hostname<br />
1356: <b>Abstract:</b> $shortabstract<br />
1.77 harris41 1357: $extrashow
1.50 harris41 1358: </p>
1359: END
1360: return $result;
1361: }
1362:
1363: # -------------------------------------------------------------------- XML/SGML
1364: sub xml_sgml_view {
1365: my ($title,$author,$subject,$url,$keywords,$version,
1.51 harris41 1366: $notes,$shortabstract,$mime,$lang,
1367: $creationdate,$lastrevisiondate,$owner,$copyright,
1.77 harris41 1368: $hostname,$httphost,$extrashow)=@_;
1.50 harris41 1369: my $result=<<END;
1.56 harris41 1370: <pre>
1371: <LonCapaResource>
1.57 harris41 1372: <url>$url</url>
1.56 harris41 1373: <title>$title</title>
1374: <author>$author</author>
1375: <subject>$subject</subject>
1376: <keywords>$keywords</keywords>
1377: <notes>$notes</notes>
1378: <mimeInfo>
1379: <mime>$mime</mime>
1380: <mimetag>$mimetag{$mime}</mimetag>
1381: </mimeInfo>
1382: <languageInfo>
1383: <language>$lang</language>
1384: <languagetag>$language{$lang}</languagetag>
1385: </languageInfo>
1386: <creationdate>$creationdate</creationdate>
1387: <lastrevisiondate>$lastrevisiondate</lastrevisiondate>
1388: <owner>$owner</owner>
1389: <copyrightInfo>
1390: <copyright>$copyright</copyright>
1391: <copyrighttag>$cprtag{$copyright}</copyrighttag>
1392: </copyrightInfo>
1393: <repositoryLocation>$hostname</repositoryLocation>
1394: <shortabstract>$shortabstract</shortabstract>
1.57 harris41 1395: </LonCapaResource>
1.56 harris41 1396: </pre>
1.77 harris41 1397: $extrashow
1.50 harris41 1398: END
1399: return $result;
1.60 harris41 1400: }
1401:
1.98 harris41 1402: # ---------------------------------------------------- see if a field is filled
1403: sub filled {
1404: my ($field)=@_;
1405: if ($field=~/\S/ && $field ne 'any') {
1406: return 1;
1.61 harris41 1407: }
1.98 harris41 1408: else {
1409: return 0;
1.61 harris41 1410: }
1.60 harris41 1411: }
1412:
1.98 harris41 1413: # ---------------- Message to output when there are not enough fields filled in
1414: sub output_blank_field_error {
1415: my ($r)=@_;
1416: # make query information persistent to allow for subsequent revision
1417: my $persistent=&make_persistent();
1418:
1419: $r->print(<<BEGINNING);
1420: <html>
1421: <head>
1422: <title>The LearningOnline Network with CAPA</title>
1423: BEGINNING
1424: $r->print(<<RESULTS);
1425: </head>
1426: <body bgcolor="#ffffff">
1427: <img align='right' src='/adm/lonIcons/lonlogos.gif' />
1428: <h1>Search Catalog</h1>
1429: <form method="post" action="/adm/searchcat">
1430: $persistent
1431: <input type='button' value='Revise search request'
1432: onClick='this.form.submit();' />
1433: $closebutton
1434: <hr />
1435: <h3>Helpful Message</h3>
1436: <p>
1437: Incorrect search query due to blank entry fields.
1438: You need to fill in the relevant
1439: fields on the search page in order for a query to be
1440: processed.
1441: </p>
1442: </body>
1443: </html>
1444: RESULTS
1445: }
1446:
1447: # ----------------------------------------------------------- Output date error
1.60 harris41 1448: sub output_date_error {
1449: my ($r,$message)=@_;
1450: # make query information persistent to allow for subsequent revision
1.65 harris41 1451: my $persistent=&make_persistent();
1.60 harris41 1452:
1453: $r->print(<<BEGINNING);
1454: <html>
1455: <head>
1456: <title>The LearningOnline Network with CAPA</title>
1457: BEGINNING
1458: $r->print(<<RESULTS);
1459: </head>
1460: <body bgcolor="#ffffff">
1.98 harris41 1461: <img align='right' src='/adm/lonIcons/lonlogos.gif' />
1.60 harris41 1462: <h1>Search Catalog</h1>
1463: <form method="post" action="/adm/searchcat">
1464: $persistent
1465: <input type='button' value='Revise search request'
1.98 harris41 1466: onClick='this.form.submit();' />
1.60 harris41 1467: $closebutton
1.98 harris41 1468: <hr />
1.60 harris41 1469: <h3>Helpful Message</h3>
1470: <p>
1471: $message
1472: </p>
1473: </body>
1474: </html>
1475: RESULTS
1.101 harris41 1476: }
1477:
1.104 harris41 1478: # --------- settings whenever the user causes the search window to be launched
1.101 harris41 1479: sub start_fresh_session {
1480: delete $hash{'mode_catalog'};
1481: map {
1482: if ($_ =~ /^pre_/) {
1483: delete $hash{$_};
1484: }
1485: if ($_ =~ /^store/) {
1486: delete $hash{$_};
1487: }
1488: } keys %hash;
1.3 harris41 1489: }
1.1 www 1490:
1491: 1;
1.98 harris41 1492:
1.1 www 1493: __END__
1.105 ! harris41 1494:
! 1495: =head1 NAME
! 1496:
! 1497: Apache::lonsearchcat - mod_perl module for handling a searchable catalog
! 1498:
! 1499: =head1 SYNOPSIS
! 1500:
! 1501: Invoked by /etc/httpd/conf/srm.conf:
! 1502:
! 1503: <Location /adm/searchcat>
! 1504: PerlAccessHandler Apache::lonacc
! 1505: SetHandler perl-script
! 1506: PerlHandler Apache::lonsearchcat
! 1507: ErrorDocument 403 /adm/login
! 1508: ErrorDocument 500 /adm/errorhandler
! 1509: </Location>
! 1510:
! 1511: =head1 INTRODUCTION
! 1512:
! 1513: This module enables searching for a distributed browseable catalog.
! 1514:
! 1515: This is part of the LearningOnline Network with CAPA project
! 1516: described at http://www.lon-capa.org.
! 1517:
! 1518: =head1 BEGIN SUBROUTINE
! 1519:
! 1520: This routine is only run once after compilation.
! 1521:
! 1522: =over 4
! 1523:
! 1524: =item *
! 1525:
! 1526: Initializes %language hash table.
! 1527:
! 1528: =item *
! 1529:
! 1530: Initializes %cprtag hash table (for copyright.tab).
! 1531:
! 1532: =item *
! 1533:
! 1534: Initializes %mimetag hash table (for filetypes.tab).
! 1535:
! 1536: =item *
! 1537:
! 1538: Initializes %hostdomains and hostips hash table (for hosts.tab).
! 1539:
! 1540: =back
! 1541:
! 1542: =head1 HANDLER SUBROUTINE
! 1543:
! 1544: This routine is called by Apache and mod_perl.
! 1545:
! 1546: =over 4
! 1547:
! 1548: =item *
! 1549:
! 1550: configure dynamic components of interface
! 1551:
! 1552: =item *
! 1553:
! 1554: determine current user
! 1555:
! 1556: =item *
! 1557:
! 1558: see if a search invocation should be done
! 1559:
! 1560: =item *
! 1561:
! 1562: else, begin building search interface to output
! 1563:
! 1564: =item *
! 1565:
! 1566: compute date selection boxes
! 1567:
! 1568: =item *
! 1569:
! 1570: compute customized metadata field
! 1571:
! 1572: =item *
! 1573:
! 1574: print screen
! 1575:
! 1576: =back
! 1577:
! 1578: =head1 OTHER SUBROUTINES
! 1579:
! 1580: =over 4
! 1581:
! 1582: =item *
! 1583:
! 1584: get_unprocessed_cgi() : reads in critical name/value pairs that may have not
! 1585: been processed and passed into %ENV by the web server
! 1586:
! 1587: =item *
! 1588:
! 1589: make_persistent() : makes a set of hidden HTML fields to make
! 1590: SQL search interface information to be persistent
! 1591:
! 1592: =back
! 1593:
! 1594: WEB INTERFACE COMPONENT FUNCTIONS
! 1595:
! 1596: =over 4
! 1597:
! 1598: =item *
! 1599:
! 1600: simpletextfield(name,value) : returns HTML formatted string for simple text
! 1601: field
! 1602:
! 1603: =item *
! 1604:
! 1605: simplecheckbox(name,value) : returns HTML formatted string for simple
! 1606: checkbox
! 1607:
! 1608: =item *
! 1609:
! 1610: searchphrasefield(title,name,value) : returns HTML formatted string for
! 1611: a search expression phrase field
! 1612:
! 1613: =item *
! 1614:
! 1615: dateboxes(name, defaultmonth, defaultday, defaultyear) : returns HTML
! 1616: formatted string for a calendar date
! 1617:
! 1618: =item *
! 1619:
! 1620: selectbox(title,name,value,%HASH=options) : returns HTML formatted string for
! 1621: a selection box field
! 1622:
! 1623: =back
! 1624:
! 1625: SEARCH FUNCTIONS
! 1626:
! 1627: =over 4
! 1628:
! 1629: =item *
! 1630:
! 1631: advancedsearch(server reference, environment reference) : perform a complex
! 1632: multi-field logical query
! 1633:
! 1634: =item *
! 1635:
! 1636: basicsearch(server reference, environment reference) : perform a simple
! 1637: single-field logical query
! 1638:
! 1639: =item *
! 1640:
! 1641: build_SQL_query(field name, logic) : builds a SQL query string from a
! 1642: logical expression with AND/OR keywords
! 1643:
! 1644: =item *
! 1645:
! 1646: build_custommetadata_query(field_name, logic_statement) : builds a perl
! 1647: regular expression from a logical expression with AND/OR keywords
! 1648:
! 1649: =item *
! 1650:
! 1651: recursive_SQL_query_build(field name, reverse notation expression) :
! 1652: builds a SQL query string from a reverse notation expression
! 1653: logical expression with AND/OR keywords
! 1654:
! 1655: =item *
! 1656:
! 1657: build_date_queries(cmonth1, cday1, cyear1, cmonth2, cday2, cyear2,
! 1658: lmonth1, lday1, lyear1, lmonth2, lday2, lyear2) :
! 1659: Builds a SQL logic query to check time/date entries.
! 1660:
! 1661: =back
! 1662:
! 1663: OUTPUTTING RESULTS FUNCTION
! 1664:
! 1665: =over 4
! 1666:
! 1667: =item *
! 1668:
! 1669: output_results(output mode, server reference, environment reference,
! 1670: reply list reference) : outputs results from search
! 1671:
! 1672: =back
! 1673:
! 1674: DIFFERENT WAYS TO VIEW METADATA RECORDS
! 1675:
! 1676: =over 4
! 1677:
! 1678: =item *
! 1679:
! 1680: detailed_citation_view(ORDERED METADATA LIST FOR A RESULT OBJECT INSTANCE) :
! 1681: see metadata viewing notes below
! 1682:
! 1683: =item *
! 1684:
! 1685: summary_view(ORDERED METADATA LIST FOR A RESULT OBJECT INSTANCE) :
! 1686: see metadata viewing notes below
! 1687:
! 1688: =item *
! 1689:
! 1690: fielded_format_view(ORDERED METADATA LIST FOR A RESULT OBJECT INSTANCE) :
! 1691: see metadata viewing notes below
! 1692:
! 1693: =item *
! 1694:
! 1695: xml_sgml_view(ORDERED METADATA LIST FOR A RESULT OBJECT INSTANCE) :
! 1696: see metadata viewing notes below
! 1697:
! 1698: =back
! 1699:
! 1700: _____________________________________________________________________
! 1701: | * Metadata viewing notes |
! 1702: | Output is a HTML-ified string. |
! 1703: | Input arguments are title, author, subject, url, keywords, version, |
! 1704: | notes, short abstract, mime, language, creation date, |
! 1705: | last revision date, owner, copyright, hostname, httphost, and |
! 1706: | extra custom metadata to show. |
! 1707: ---------------------------------------------------------------------
! 1708:
! 1709: TEST CONDITIONAL FUNCTIONS
! 1710:
! 1711: =over 4
! 1712:
! 1713: =item *
! 1714:
! 1715: filled(field) : determines whether a given field has been filled
! 1716:
! 1717: =back
! 1718:
! 1719: ERROR FUNCTIONS
! 1720:
! 1721: =over 4
! 1722:
! 1723: =item *
! 1724:
! 1725: output_blank_field_error(server reference) : outputs a message saying that
! 1726: more fields need to be filled in
! 1727:
! 1728: =item *
! 1729:
! 1730: output_date_error(server reference, error message) : outputs
! 1731: an error message specific to bad date format.
! 1732:
! 1733: =back
! 1734:
! 1735: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>