1: # The LearningOnline Network with CAPA
2: #
3: # Search Catalog
4: #
5: # YEAR=2001
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: #
10: # $Id: lonsearchcat.pm,v 1.105 2001/11/28 16:47:25 harris41 Exp $
11: ###
12:
13: ###############################################################################
14: ## ##
15: ## ORGANIZATION OF THIS PERL MODULE ##
16: ## ##
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 ##
22: ## ##
23: ###############################################################################
24:
25: package Apache::lonsearchcat;
26:
27: # ------------------------------------------------- modules used by this module
28: use strict;
29: use Apache::Constants qw(:common);
30: use Apache::lonnet();
31: use Apache::File();
32: use CGI qw(:standard);
33: use Text::Query;
34: use GDBM_File;
35:
36: # ---------------------------------------- variables used throughout the module
37:
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
53: my %hash;
54:
55: # ------------------------------------------ choices for different output views
56: # Detailed Citation View ---> sub detailed_citation_view
57: # Summary View ---> sub summary_view
58: # Fielded Format ---> sub fielded_format_view
59: # XML/SGML ---> sub xml_sgml_view
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'>
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>
74: </select>
75: END
76:
77: # ----------------------------------------------------------------------- BEGIN
78: sub BEGIN {
79: # --------------------------------- Compute various listings of metadata values
80: $language{'any'}='Any language';
81: {
82: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
83: '/language.tab');
84: map {
85: $_=~/(\w+)\s+([\w\s\-]+)/; chomp;
86: $language{$1}=$2;
87: } <$fh>;
88: }
89: $cprtag{'any'}='Any copyright/distribution';
90: {
91: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonIncludes'}.
92: '/copyright.tab');
93: map {
94: $_=~/(\w+)\s+([\w\s\-]+)/; chomp;
95: $cprtag{$1}=$2;
96: } <$fh>;
97: }
98: $mimetag{'any'}='Any type';
99: {
100: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
101: '/filetypes.tab');
102: map {
103: $_=~/(\w+)\s+(\w+)\s+([\w\s\-]+)/; chomp;
104: $mimetag{$1}=".$1 $3";
105: } <$fh>;
106: }
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:
120: my $diropendb = "";
121: my $domain = "";
122:
123: # ----------------------------- Handling routine called via Apache and mod_perl
124: sub handler {
125: my $r = shift;
126: untie %hash;
127: &get_unprocessed_cgi();
128:
129: $r->content_type('text/html');
130: $r->send_http_header;
131: return OK if $r->header_only;
132:
133: $domain = $r->dir_config('lonDefDomain');
134:
135: $diropendb= "/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_searchcat.db";
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:
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
177:
178: # ----------------------------------- See if a search invocation should be done
179: if ($ENV{'form.basicsubmit'} eq 'SEARCH') {
180: untie %hash; return &basicsearch($r,\%ENV);
181: }
182: elsif ($ENV{'form.advancedsubmit'} eq 'SEARCH') {
183: untie %hash; return &advancedsearch($r,\%ENV);
184: }
185:
186: # ----------------------------- Else, begin building search interface to output
187: $scrout=''; # building a part of screen output
188: $scrout.=&searchphrasefield('Limit by title','title',
189: $ENV{'form.title'});
190:
191: $scrout.=&searchphrasefield('Limit by author','author',
192: $ENV{'form.author'});
193:
194: $scrout.=&searchphrasefield('Limit by subject','subject',
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:
203: # $scrout.=&searchphrasefield('Limit by version','version',
204: # $ENV{'form.version'});
205:
206: $scrout.=&searchphrasefield('Limit by notes','notes',
207: $ENV{'form.notes'});
208:
209: $scrout.=&searchphrasefield('Limit by abstract','abstract',
210: $ENV{'form.abstract'});
211:
212: $ENV{'form.mime'}='notxxx' unless length($ENV{'form.mime'});
213: $scrout.=&selectbox('Limit by MIME type','mime',
214: $ENV{'form.mime'},%mimetag);
215:
216: $ENV{'form.language'}='any' unless length($ENV{'form.language'});
217:
218: $scrout.=&selectbox('Limit by language','language',
219: $ENV{'form.language'},%language);
220:
221:
222: # ------------------------------------------------ Compute date selection boxes
223: $scrout.=<<CREATIONDATESTART;
224: <p>
225: <font color="#800000" face="helvetica"><b>LIMIT BY CREATION DATE RANGE:</b>
226: </font>
227: <br />
228: between:
229: CREATIONDATESTART
230: $scrout.=&dateboxes('creationdatestart',1,1,1976,
231: $ENV{'form.creationdatestart_month'},
232: $ENV{'form.creationdatestart_day'},
233: $ENV{'form.creationdatestart_year'},
234: );
235: $scrout.=<<CREATIONDATEEND;
236: and:
237: CREATIONDATEEND
238: $scrout.=&dateboxes('creationdateend',12,31,2051,
239: $ENV{'form.creationdateend_month'},
240: $ENV{'form.creationdateend_day'},
241: $ENV{'form.creationdateend_year'},
242: );
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>
249: <br />between:
250: LASTREVISIONDATESTART
251: $scrout.=&dateboxes('lastrevisiondatestart',1,1,1976,
252: $ENV{'form.lastrevisiondatestart_month'},
253: $ENV{'form.lastrevisiondatestart_day'},
254: $ENV{'form.lastrevisiondatestart_year'},
255: );
256: $scrout.=<<LASTREVISIONDATEEND;
257: and:
258: LASTREVISIONDATEEND
259: $scrout.=&dateboxes('lastrevisiondateend',12,31,2051,
260: $ENV{'form.lastrevisiondateend_month'},
261: $ENV{'form.lastrevisiondateend_day'},
262: $ENV{'form.lastrevisiondateend_year'},
263: );
264: $scrout.='</p>';
265:
266: $scrout.=&searchphrasefield('Limit by publisher/owner','owner',
267: $ENV{'form.owner'});
268:
269: $ENV{'form.copyright'}='any' unless length($ENV{'form.copyright'});
270: $scrout.=&selectbox('Limit by copyright/distribution','copyright',
271: $ENV{'form.copyright'},%cprtag);
272:
273: # ------------------------------------------- Compute customized metadata field
274: $scrout.=<<CUSTOMMETADATA;
275: <p>
276: <font color="#800000" face="helvetica"><b>LIMIT BY SPECIAL METADATA FIELDS:</b>
277: </font>
278: For resource-specific metadata, enter in an expression in the form of
279: <i>key</i>=<i>value</i> separated by operators such as AND, OR or NOT.<br />
280: <b>Example:</b> grandmother=75 OR grandfather=85
281: <br />
282: CUSTOMMETADATA
283: $scrout.=&simpletextfield('custommetadata',$ENV{'form.custommetadata'});
284: $scrout.=' <i>initial users of this system do not need to worry about this option</i>';
285:
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.
292: <br />
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:
297: # ---------------------------------------------------------------- Print screen
298: $r->print(<<ENDDOCUMENT);
299: <html>
300: <head>
301: <title>The LearningOnline Network with CAPA</title>
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>
309: </head>
310: <body bgcolor="#FFFFFF">
311: <img align='right' src='/adm/lonIcons/lonlogos.gif' />
312: <h1>Search Catalog</h1>
313: <form method="post" action="/adm/searchcat">
314: $hidden
315: <hr />
316: <h3>Basic Search</h3>
317: <p>
318: Enter terms or phrases separated by search operators
319: such as AND, OR, or NOT then press SEARCH below. Terms should be specific
320: to the title, author, subject, notes, or abstract information associated
321: with a resource.
322: <br />
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> ');
328: # $r->print(&simplecheckbox('allversions',$ENV{'form.allversions'}));
329: # <font color="#800000">Search historic archives</font>
330: $r->print(<<ENDDOCUMENT);
331: <br />
332: <input type="submit" name="basicsubmit" value='SEARCH' />
333: <input type="reset" name="reset" value='RESET' />
334: $closebutton
335: $basicviewselect
336: <input type="button" value="HELP" onClick="openhelp()" />
337: </p>
338: <hr />
339: <h3>Advanced Search</h3>
340: $scrout
341: <p>
342: <input type="submit" name="advancedsubmit" value='SEARCH' />
343: <input type="reset" name="reset" value='RESET' />
344: $closebutton
345: $advancedviewselect
346: <input type="button" value="HELP" onClick="openhelp()" />
347: </p>
348: </form>
349: </body>
350: </html>
351: ENDDOCUMENT
352: return OK;
353: }
354:
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;
361: if ($name eq 'catalogmode' or $name eq 'launch' or $name eq 'acts') {
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:
385: # --------------------------------------------------------- Various form fields
386:
387: sub simpletextfield {
388: my ($name,$value)=@_;
389: return '<input type=text name=\''.$name.
390: '\' size=20 value=\''.$value.'\' />';
391: }
392:
393: sub simplecheckbox {
394: my ($name,$value)=@_;
395: my $checked='';
396: $checked="CHECKED" if $value eq 'on';
397: return '<input type=checkbox name=\''.$name.'\' '. $checked . '>';
398: }
399:
400: sub searchphrasefield {
401: my ($title,$name,$value)=@_;
402: my $instruction=<<END;
403: Enter terms or phrases separated by search operators such
404: as AND, OR, or NOT.
405: END
406: my $uctitle=uc($title);
407: return "\n<p><font color=\"#800000\" face=\"helvetica\"><b>$uctitle:</b>".
408: "</FONT> $instruction<br />".
409: '<input type=text name="'.$name.'" size=80 value=\''.$value.'\'>';
410: }
411:
412: sub dateboxes {
413: my ($name,$defaultmonth,$defaultday,$defaultyear,
414: $currentmonth,$currentday,$currentyear)=@_;
415: ($defaultmonth,$defaultday,$defaultyear)=('','','');
416: my $month=<<END;
417: <select name="${name}_month">
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>
428: <option value="10">October</option>
429: <option value="11">November</option>
430: <option value="12">December</option>
431: </select>
432: END
433: $month=~s/(\"$currentmonth\")/$1 SELECTED/ if length($currentmonth);
434: my $day=<<END;
435: <select name="${name}_day">
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>
468: </select>
469: END
470: $day=~s/(\"$currentday\")/$1 SELECTED/ if length($currentday);
471: my $year=<<END;
472: <select name="${name}_year">
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>
550: </select>
551: END
552: $year=~s/(\"$currentyear\")/$1 SELECTED/ if length($currentyear);
553: return "$month$day$year";
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:".
560: "</b></font><br />".'<select name="'.$name.'">';
561: map {
562: $selout.='<option value=\''.$_.'\'';
563: if ($_ eq $value) { $selout.=' selected'; }
564: $selout.='>'.$options{$_}.'</option>';
565: } sort keys %options;
566: return $selout.'</select>';
567: }
568:
569: # ----------------------------------------------- Performing an advanced search
570: sub advancedsearch {
571: my ($r,$envhash)=@_;
572: my %ENV=%{$envhash};
573:
574: my $fillflag=0;
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',
584: 'custommetadata','customshow') {
585: $ENV{"form.$field"}=~s/[^\w\/\s\(\)\=\-\"\']//g;
586: }
587:
588: # Check to see if enough information was filled in
589: for my $field ('title','author','subject','keywords','url','version',
590: 'notes','abstract','mime','language','owner',
591: 'custommetadata') {
592: if (&filled($ENV{"form.$field"})) {
593: $fillflag++;
594: }
595: }
596: unless ($fillflag) {
597: &output_blank_field_error($r);
598: return OK;
599: }
600:
601:
602: # Turn the form input into a SQL-based query
603: my $query='';
604:
605: my @queries;
606: # Evaluate logical expression AND/OR/NOT phrase fields.
607: foreach my $field ('title','author','subject','notes','abstract','url',
608: 'keywords','version','owner') {
609: if ($ENV{'form.'.$field}) {
610: push @queries,&build_SQL_query($field,$ENV{'form.'.$field});
611: }
612: }
613: # Evaluate option lists
614: if ($ENV{'form.language'} and $ENV{'form.language'} ne 'any') {
615: push @queries,"(language like \"$ENV{'form.language'}\")";
616: }
617: if ($ENV{'form.mime'} and $ENV{'form.mime'} ne 'any') {
618: push @queries,"(mime like \"$ENV{'form.mime'}\")";
619: }
620: if ($ENV{'form.copyright'} and $ENV{'form.copyright'} ne 'any') {
621: push @queries,"(copyright like \"$ENV{'form.copyright'}\")";
622: }
623: # Evaluate date windows
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: );
638: # Test to see if date windows are legitimate
639: if ($datequery=~/^Incorrect/) {
640: &output_date_error($r,$datequery);
641: return OK;
642: }
643: elsif ($datequery) {
644: push @queries,$datequery;
645: }
646:
647: # Process form information for custom metadata querying
648: my $customquery='';
649: if ($ENV{'form.custommetadata'}) {
650: $customquery=&build_custommetadata_query('custommetadata',
651: $ENV{'form.custommetadata'});
652: }
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: }
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).
663: if (@queries) {
664: $query=join(" AND ",@queries);
665: $query="select * from metadata where $query";
666: my $reply; # reply hash reference
667: unless ($customquery or $customshow) {
668: $reply=&Apache::lonnet::metadata_query($query);
669: }
670: else {
671: $reply=&Apache::lonnet::metadata_query($query,
672: $customquery,$customshow);
673: }
674: &output_results('Advanced',$r,$envhash,$customquery,$reply);
675: }
676: elsif ($customquery) {
677: my $reply; # reply hash reference
678: $reply=&Apache::lonnet::metadata_query('',
679: $customquery,$customshow);
680: &output_results('Advanced',$r,$envhash,$customquery,$reply);
681: }
682: # should not get to this point
683: return 'Error. Should not have gone to this point.';
684: }
685:
686: # --------------------------------------------------- Performing a basic search
687: sub basicsearch {
688: my ($r,$envhash)=@_;
689: my %ENV=%{$envhash};
690: # Clean up fields for safety
691: for my $field ('basicexp') {
692: $ENV{"form.$field"}=~s/[^\w\s\(\)\-]//g;
693: }
694:
695: # Check to see if enough is filled in
696: unless (&filled($ENV{'form.basicexp'})) {
697: &output_blank_field_error($r);
698: return OK;
699: }
700:
701: # Build SQL query string based on form page
702: my $query='';
703: my $concatarg=join('," ",',
704: ('title', 'author', 'subject', 'notes', 'abstract'));
705: $concatarg='title' if $ENV{'form.titleonly'};
706:
707: $query=&build_SQL_query('concat('.$concatarg.')',$ENV{'form.'.'basicexp'});
708:
709: # Get reply (either a hash reference to filehandles or bad connection)
710: my $reply=&Apache::lonnet::metadata_query('select * from metadata where '.$query);
711:
712: # Output search results
713:
714: &output_results('Basic',$r,$envhash,$query,$reply);
715:
716: return OK;
717: }
718:
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: }
779:
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 '';
827: }
828:
829: # ----------------------------- format and output results based on a reply list
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.)
834: sub output_results {
835: my $fnum; # search result counter
836: my ($mode,$r,$envhash,$query,$replyref)=@_;
837: my %ENV=%{$envhash};
838: my %rhash=%{$replyref};
839: my $compiledresult='';
840: my $timeremain=300;
841: my $elapsetime=0;
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
849: $r->print(<<BEGINNING);
850: <html>
851: <head>
852: <title>The LearningOnline Network with CAPA</title>
853: BEGINNING
854:
855: # conditional output of script functions dependent on the mode in
856: # which the search was invoked
857: $r->print(<<SCRIPT) if $ENV{'form.catalogmode'} eq 'interactive';
858: <script type="text/javascript">
859: function select_data(title,url) {
860: changeTitle(title);
861: changeURL(url);
862: self.close();
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
876: $r->print(<<SCRIPT) if $ENV{'form.catalogmode'} eq 'groupsearch';
877: <script type="text/javascript">
878: function select_data(title,url) {
879: // alert('DEBUG: Should be storing '+title+' and '+url);
880: }
881: function queue(val) {
882: if (eval("document.forms.results.returnvalues["+val+"].checked")) {
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() {
890: window.location="/adm/groupsort?catalogmode=groupsearch&acts="+
891: document.forms.results.acts.value;
892: }
893: </script>
894: SCRIPT
895: $r->print(<<SCRIPT);
896: <script type="text/javascript">
897: function displayinfo(val) {
898: popwin.document.forms.popremain.sdetails.value=val;
899: }
900: function openhelp(val) {
901: openhelpwin=open('/adm/help/searchcat.html','helpscreen',
902: 'scrollbars=1,width=400,height=300');
903: openhelpwin.focus();
904: }
905: function abortsearch(val) {
906: openhelpwin=open('/adm/help/searchcat.html','helpscreen',
907: 'scrollbars=1,width=400,height=300');
908: openhelpwin.focus();
909: }
910: </script>
911: SCRIPT
912: $r->rflush();
913:
914: # begin showing the cataloged results
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
921: $r->print(<<CATALOGCONTROLS);
922: <form name='results' method="post" action="/adm/searchcat">
923: <input type='hidden' name='acts' value='' />
924: <input type='button' value='Revise search request'
925: onClick='this.form.submit();' />
926: $importbutton
927: $closebutton
928: $persistent
929: <hr />
930: <h3>Search Query</h3>
931: CATALOGCONTROLS
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>');
948: $r->rflush();
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.="\"'\"+'";
963: $grid.=$sk;
964: my $hc;
965: if ($rhash{$sk} eq 'con_lost') {
966: $hc="!!!BAD CONNECTION, CONTACT SYSTEM ADMINISTRATOR!!!";
967: }
968: else {
969: $hc="'+\"'\"+\"+hc['$sk']+\"+\"'\"+'";
970: $hcinit.="hc[\"$sk\"]=\"not yet connected...\";";
971: }
972: $grid.=" hitcount=".$hc;
973: $grid.=" domain=".$hostdomains{$sk};
974: $grid.=" IP=".$hostips{$sk};
975: # '+"'"+'">'+
976: $grid.="'+\"'\"+')\">'+";
977: $grid.="\n";
978: $grid.="'<img border=\"0\" name=\"img".$sn."\"".
979: " src=\"/adm/lonIcons/srvnull.gif\" alt=\"".$sk."\" /></a>'+\n";
980: $grid.="'<br />'+\n" unless $sn%10;
981: $sn++;
982: }
983: $r->print(<<ENDPOP);
984: <script type="text/javascript">
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">'+
994: '<'+'image name="whirly" align="right" src="/adm/lonIcons/'+
995: 'lonanim.gif" '+
996: 'alt="animated logo" />'+
997: '<'+'h3>Search Results Progress<'+'/h3>'+
998: '<'+'form name="popremain">'+
999: '<'+'tt>'+
1000: '<'+'br clear="all"/><i>PLEASE BE PATIENT</i>'+
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"'+
1017: ' value="abort search and view current results" '+
1018: ' onClick="javascript:opener.abortsearch()" />'+
1019: ' <'+'input type="button" name="button"'+
1020: ' value="help" onClick="javascript:opener.openhelp()" />'+
1021: '<'+'/tt>'+
1022: '<'+'/form>'+
1023: '<'+'/body><'+'/html>');
1024: popwin.document.close();
1025: </script>
1026: ENDPOP
1027: $r->rflush();
1028:
1029: my $servercount=0;
1030: my $hitcountsum=0;
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) {
1037: $sn++;
1038: next RLOOP if $orkey{$rkey};
1039: $servercount++;
1040: $tflag=1;
1041: $compiledresult='';
1042: my $hostname=$rkey;
1043: my $reply=$rhash{$rkey};
1044: my @results;
1045:
1046: my $replyfile='';
1047:
1048: if ($reply eq 'con_lost') {
1049: $r->print('<script type="text/javascript">popwin.document.img'.
1050: $sn.'.'.
1051: 'src="/adm/lonIcons/srvbad.gif";</script>'.
1052: "\n");
1053: $r->rflush();
1054: $bloop--;
1055: $orkey{$rkey}=1;
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: {
1062: my $temp=0;
1063: WLOOP: while (1) {
1064: if (-e $replyfile && $tflag) {
1065: $r->print('<script type="text/javascript">'.
1066: 'popwin.document.img'.$sn.'.'.
1067: 'src="/adm/lonIcons/srvhalf.gif";</script>'.
1068: "\n");
1069: $r->rflush();
1070: $r->print('<script type="text/javascript">'.
1071: 'popwin.hc["'.$rkey.'"]='.
1072: '"still transferring..."'.';</script>'.
1073: "\n");
1074: $r->rflush();
1075: $tflag=0;
1076: }
1077: last WLOOP if $temp>1;
1078: if (-e "$replyfile.end") {
1079: $bloop--;
1080: $orkey{$rkey}=1;
1081: if (-s $replyfile) {
1082: $r->print('<script type="text/javascript">'.
1083: 'popwin.document.img'.$sn.'.'.
1084: 'src="/adm/lonIcons/srvgood.gif";'.
1085: '</script>'."\n");
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;
1093: $r->print('<script type="text/javascript">'.
1094: 'popwin.hc["'.$rkey.'"]='.
1095: $hitcount{$rkey}.';</script>'.
1096: "\n");
1097: $r->rflush();
1098: $hitcountsum+=$hitcount{$rkey};
1099: $r->print('<script type="text/javascript">'.
1100: 'popwin.document.forms.popremain.'.
1101: 'numhits.value='.$hitcountsum.
1102: ';</script>'.
1103: "\n");
1104: $r->rflush();
1105: }
1106: else {
1107: $r->print('<script type="text/javascript">'.
1108: 'popwin.document.img'.$sn.'.'.
1109: 'src="/adm/lonIcons/srvempty.gif";'.
1110: '</script>'.
1111: "\n");
1112: $r->rflush();
1113: $r->print('<script type="text/javascript">'.
1114: 'popwin.hc["'.$rkey.'"]=0'.
1115: ';</script>'.
1116: "\n");
1117: $r->rflush();
1118: }
1119: last WLOOP;
1120: }
1121: last WLOOP unless $timeremain;
1122: sleep 1;
1123: $timeremain--;
1124: $elapsetime++;
1125: $r->print('<script type="text/javascript">'.
1126: 'popwin.document.popremain.elapsetime.'.
1127: 'value="'.$elapsetime.'";</script>'."\n");
1128: $r->rflush();
1129: $temp++;
1130: }
1131: }
1132: $r->print('<script type="text/javascript">'.
1133: 'popwin.document.whirly.'.
1134: 'src="'.'/adm/lonIcons/lonanimend.gif'.
1135: '";</script>'."\n");
1136: $r->rflush();
1137: }
1138: my $customshow='';
1139: my $extrashow='';
1140: my @customfields;
1141: if ($ENV{'form.customshow'}) {
1142: $customshow=$ENV{'form.customshow'};
1143: $customshow=~s/[^\w\s]//g;
1144: my @fields=map {"<font color=\"#008000\">$_:</font><!-- $_ -->"}
1145: split(/\s+/,$customshow);
1146: @customfields=split(/\s+/,$customshow);
1147: if ($customshow) {
1148: $extrashow="<ul><li>".join("</li><li>",@fields)."</li></ul>\n";
1149: }
1150: }
1151: my $customdata='';
1152: my %customhash;
1153: foreach my $result (@results) {
1154: if ($result=~/^(custom\=.*)$/) { # grab all custom metadata
1155: my $tmp=$result;
1156: $tmp=~s/^custom\=//;
1157: my ($k,$v)=map {&Apache::lonnet::unescape($_);
1158: } split(/\,/,$tmp);
1159: $customhash{$k}=$v;
1160: }
1161: }
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;
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:
1191: my $shortabstract=$abstract;
1192: $shortabstract=substr($abstract,0,200).'...' if length($abstract)>200;
1193: $fields[7]=$shortabstract;
1194: my $shortkeywords=$keywords;
1195: $shortkeywords=substr($keywords,0,200).'...' if length($keywords)>200;
1196: $fields[4]=$shortkeywords;
1197:
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: }
1208:
1209: $compiledresult.=<<END if $compiledresult or $servercount!=$servernum;
1210: <hr align='left' width='200' noshade />
1211: END
1212: $compiledresult.=<<END;
1213: <p>
1214: END
1215: $compiledresult.=<<END if $ENV{'form.catalogmode'} eq 'interactive';
1216: <font size='-1'><INPUT TYPE="button" NAME="returnvalues" VALUE="SELECT"
1217: onClick="javascript:select_data('$title','$url')">
1218: </font>
1219: <br />
1220: END
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;
1226: <font size='-1'><input type="checkbox" name="returnvalues" value="SELECT"
1227: onClick="javascript:queue($fnum)" />
1228: </font>
1229: <br />
1230: END
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: }
1244:
1245: if ($viewselect eq 'Detailed Citation View') {
1246: $compiledresult.=&detailed_citation_view(@fields,
1247: $hostname,$httphost,
1248: $extrashow2);
1249: }
1250: elsif ($viewselect eq 'Summary View') {
1251: $compiledresult.=&summary_view(@fields,$hostname,$httphost,
1252: $extrashow2);
1253: }
1254: elsif ($viewselect eq 'Fielded Format') {
1255: $compiledresult.=&fielded_format_view(@fields,$hostname,
1256: $httphost,$extrashow2);
1257: }
1258: elsif ($viewselect eq 'XML/SGML') {
1259: $compiledresult.=&xml_sgml_view(@fields,$hostname,$httphost,
1260: $extrashow2);
1261: }
1262:
1263: }
1264:
1265: untie %hash;
1266: }
1267: else {
1268: $r->print('<html><head></head><body>Unable to tie hash to db '.
1269: 'file</body></html>');
1270: }
1271: if ($compiledresult) {
1272: $resultflag=1;
1273: }
1274:
1275: $r->print(<<RESULTS);
1276: $compiledresult
1277: RESULTS
1278: my $percent=sprintf('%3.0f',($servercount/$servernum*100));
1279: }
1280: }
1281: unless ($resultflag) {
1282: $r->print("\nThere were no results that matched your query\n");
1283: }
1284: # $r->print('<script type="text/javascript">'.'popwin.close()</script>'."\n"); $r->rflush();
1285: $r->print(<<RESULTS);
1286: </body>
1287: </html>
1288: RESULTS
1289: }
1290:
1291: # ------------------------------------------------------ Detailed Citation View
1292: sub detailed_citation_view {
1293: my ($title,$author,$subject,$url,$keywords,$version,
1294: $notes,$shortabstract,$mime,$lang,
1295: $creationdate,$lastrevisiondate,$owner,$copyright,
1296: $hostname,$httphost,$extrashow)=@_;
1297: my $result=<<END;
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>
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 />
1309: </p>
1310: $extrashow
1311: <p>
1312: $shortabstract
1313: </p>
1314: END
1315: return $result;
1316: }
1317:
1318: # ---------------------------------------------------------------- Summary View
1319: sub summary_view {
1320: my ($title,$author,$subject,$url,$keywords,$version,
1321: $notes,$shortabstract,$mime,$lang,
1322: $creationdate,$lastrevisiondate,$owner,$copyright,
1323: $hostname,$httphost,$extrashow)=@_;
1324: my $result=<<END;
1325: <a href="http://$httphost$url" TARGET='search_preview'>$author</a><br />
1326: $title<br />
1327: $owner -- $lastrevisiondate<br />
1328: $cprtag{$copyright}<br />
1329: $extrashow
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,
1338: $notes,$shortabstract,$mime,$lang,
1339: $creationdate,$lastrevisiondate,$owner,$copyright,
1340: $hostname,$httphost,$extrashow)=@_;
1341: my $result=<<END;
1342: <b>URL: </b> <A HREF="http://$httphost$url" TARGET='search_preview'>$url</A>
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 />
1357: $extrashow
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,
1366: $notes,$shortabstract,$mime,$lang,
1367: $creationdate,$lastrevisiondate,$owner,$copyright,
1368: $hostname,$httphost,$extrashow)=@_;
1369: my $result=<<END;
1370: <pre>
1371: <LonCapaResource>
1372: <url>$url</url>
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>
1395: </LonCapaResource>
1396: </pre>
1397: $extrashow
1398: END
1399: return $result;
1400: }
1401:
1402: # ---------------------------------------------------- see if a field is filled
1403: sub filled {
1404: my ($field)=@_;
1405: if ($field=~/\S/ && $field ne 'any') {
1406: return 1;
1407: }
1408: else {
1409: return 0;
1410: }
1411: }
1412:
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
1448: sub output_date_error {
1449: my ($r,$message)=@_;
1450: # make query information persistent to allow for subsequent revision
1451: my $persistent=&make_persistent();
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">
1461: <img align='right' src='/adm/lonIcons/lonlogos.gif' />
1462: <h1>Search Catalog</h1>
1463: <form method="post" action="/adm/searchcat">
1464: $persistent
1465: <input type='button' value='Revise search request'
1466: onClick='this.form.submit();' />
1467: $closebutton
1468: <hr />
1469: <h3>Helpful Message</h3>
1470: <p>
1471: $message
1472: </p>
1473: </body>
1474: </html>
1475: RESULTS
1476: }
1477:
1478: # --------- settings whenever the user causes the search window to be launched
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;
1489: }
1490:
1491: 1;
1492:
1493: __END__
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>