File:
[LON-CAPA] /
loncom /
interface /
lonsearchcat.pm
Revision
1.130:
download - view:
text,
annotated -
select for diffs
Wed Jun 26 16:04:13 2002 UTC (22 years, 2 months ago) by
matthew
Branches:
MAIN
CVS tags:
HEAD
Removed the passing of %ENV to subroutines basicsearch, advancedsearch,
and output_results.
&basic_search_form
Changed view selection html.
&advanced_search_form
Changed view selection html.
Added <form> tag, allowing the advanced search interface to work.
View selection element can only appear once in the page, otherwise the
value passed back to the function is an array, which is just a can
of worms.
&output_results
Changed page headers to be more concise.
Changed view selection code to conform to new methods used in the search
forms.
Moved the short horizontal line to appear after results, not before.
&search_results_header
More POD added.
Now takes the search mode as a parameter, so the headers and title output
can be a little more customized.
&detailed_citation_view
Minor cosmetic changes.
1: # The LearningOnline Network with CAPA
2: # Search Catalog
3: #
4: # $Id: lonsearchcat.pm,v 1.130 2002/06/26 16:04:13 matthew Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: # YEAR=2001
29: # 3/8, 3/12, 3/13, 3/14, 3/15, 3/19 Scott Harrison
30: # 3/20, 3/21, 3/22, 3/26, 3/27, 4/2, 8/15, 8/24, 8/25 Scott Harrison
31: # 10/12,10/14,10/15,10/16,11/28,11/29,12/10,12/12,12/16 Scott Harrison
32: # YEAR=2002
33: # 1/17 Scott Harrison
34: # 6/17 Matthew Hall
35: #
36: ###############################################################################
37: ###############################################################################
38:
39: =pod
40:
41: =head1 NAME
42:
43: lonsearchcat
44:
45: =head1 SYNOPSIS
46:
47: Search interface to LON-CAPAs digital library
48:
49: =head1 DESCRIPTION
50:
51: This module enables searching for a distributed browseable catalog.
52:
53: This is part of the LearningOnline Network with CAPA project
54: described at http://www.lon-capa.org.
55:
56: lonsearchcat presents the user with an interface to search the LON-CAPA
57: digital library. lonsearchcat also initiates the execution of a search
58: by sending the search parameters to LON-CAPA servers. The progress of
59: search (on a server basis) is displayed to the user in a seperate window.
60:
61: =head1 Internals
62:
63: =over 4
64:
65: =cut
66:
67: ###############################################################################
68: ###############################################################################
69:
70: ###############################################################################
71: ## ##
72: ## ORGANIZATION OF THIS PERL MODULE ##
73: ## ##
74: ## 1. Modules used by this module ##
75: ## 2. Variables used throughout the module ##
76: ## 3. handler subroutine called via Apache and mod_perl ##
77: ## 4. Other subroutines ##
78: ## ##
79: ###############################################################################
80:
81: package Apache::lonsearchcat;
82:
83: # ------------------------------------------------- modules used by this module
84: use strict;
85: use Apache::Constants qw(:common);
86: use Apache::lonnet();
87: use Apache::File();
88: use CGI qw(:standard);
89: use Text::Query;
90: use GDBM_File;
91: use Apache::loncommon();
92:
93: # ---------------------------------------- variables used throughout the module
94:
95: ######################################################################
96: ######################################################################
97:
98: =pod
99:
100: =item Global variables
101:
102: =over 4
103:
104: =item $closebutton
105:
106: button that closes the search window
107:
108: =item $importbutton
109:
110: button to take the selecte results and go to group sorting
111:
112: =item %hash
113:
114: The ubiquitous database hash
115:
116: =item $diropendb
117:
118: The full path to the (temporary) search database file. This is set and
119: used in &handler() and is also used in &output_results().
120:
121: =back
122:
123: =cut
124:
125: ######################################################################
126: ######################################################################
127:
128: # -- dynamically rendered interface components
129: my $closebutton; # button that closes the search window
130: my $importbutton; # button to take the selected results and go to group sorting
131:
132: # -- miscellaneous variables
133: my %hash; # database hash
134: my $diropendb = ""; # db file
135:
136: ######################################################################
137: ######################################################################
138:
139: =pod
140:
141: =item &handler() - main handler invoked by httpd child
142:
143: =item Variables
144:
145: =over 4
146:
147: =item $hidden
148:
149: holds 'hidden' html forms
150:
151: =item $scrout
152:
153: string that holds portions of the screen output
154:
155: =back
156:
157: =cut
158:
159: ######################################################################
160: ######################################################################
161: sub handler {
162: my $r = shift;
163: untie %hash;
164:
165: $r->content_type('text/html');
166: $r->send_http_header;
167: return OK if $r->header_only;
168:
169: my $domain = $r->dir_config('lonDefDomain');
170: $diropendb= "/home/httpd/perl/tmp/".&Apache::lonnet::escape($domain).
171: "\_".&Apache::lonnet::escape($ENV{'user.name'})."_searchcat.db";
172:
173: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
174: ['catalogmode','launch','acts','mode','form','element',
175: 'reqinterface']);
176: ##
177: ## Clear out old values from database
178: ##
179: if ($ENV{'form.launch'} eq '1') {
180: if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) {
181: &start_fresh_session();
182: untie %hash;
183: } else {
184: $r->print('<html><head></head><body>Unable to tie hash to db '.
185: 'file</body></html>');
186: return OK;
187: }
188: }
189: ##
190: ## Produce some output, so people know it is working
191: ##
192: $r->print("\n");
193: $r->rflush;
194: ##
195: ## Configure dynamic components of interface
196: ##
197: my $hidden; # Holds 'hidden' html forms
198: if ($ENV{'form.catalogmode'} eq 'interactive') {
199: $hidden="<input type='hidden' name='catalogmode' value='interactive'>".
200: "\n";
201: $closebutton="<input type='button' name='close' value='CLOSE' ".
202: "onClick='self.close()'>"."\n";
203: } elsif ($ENV{'form.catalogmode'} eq 'groupsearch') {
204: $hidden=<<END;
205: <input type='hidden' name='catalogmode' value='groupsearch'>
206: END
207: $closebutton=<<END;
208: <input type='button' name='close' value='CLOSE' onClick='self.close()'>
209: END
210: $importbutton=<<END;
211: <input type='button' name='import' value='IMPORT'
212: onClick='javascript:select_group()'>
213: END
214: }
215: $hidden .= <<END;
216: <input type='hidden' name='mode' value='$ENV{'form.mode'}'>
217: <input type='hidden' name='form' value='$ENV{'form.form'}'>
218: <input type='hidden' name='element' value='$ENV{'form.element'}'>
219: <input type='hidden' name='date' value='2'>
220: END
221: ##
222: ## What are we doing?
223: ##
224: if ($ENV{'form.basicsubmit'} eq 'SEARCH') {
225: # Perform basic search and give results
226: return &basicsearch($r,$hidden);
227: } elsif ($ENV{'form.advancedsubmit'} eq 'SEARCH') {
228: # Perform advanced search and give results
229: return &advancedsearch($r,$hidden);
230: } elsif ($ENV{'form.reqinterface'} eq 'advanced') {
231: # Output the advanced interface
232: $r->print(&advanced_search_form($closebutton,$hidden));
233: return OK;
234: } else {
235: # Output normal search interface
236: $r->print(&basic_search_form($closebutton,$hidden));
237: }
238: return OK;
239: }
240:
241: ######################################################################
242: ######################################################################
243:
244: =pod
245:
246: =item &basic_search_form()
247:
248: Returns a scalar which holds html for the basic search form.
249:
250: =cut
251:
252: ######################################################################
253: ######################################################################
254:
255: sub basic_search_form{
256: my ($closebutton,$hidden) = @_;
257: my $scrout=<<"ENDDOCUMENT";
258: <html>
259: <head>
260: <title>The LearningOnline Network with CAPA</title>
261: <script type="text/javascript">
262: function openhelp(val) {
263: openhelpwin=open('/adm/help/searchcat.html','helpscreen',
264: 'scrollbars=1,width=600,height=300');
265: openhelpwin.focus();
266: }
267: </script>
268: </head>
269: <body bgcolor="#FFFFFF">
270: <img align='right' src='/adm/lonIcons/lonlogos.gif' />
271: <h1>Search Catalog</h1>
272: <form method="post" action="/adm/searchcat">
273: $hidden
274: <h3>Basic Search</h3>
275: <p>
276: Enter terms or quoted phrases separated by AND, OR, or NOT
277: then press SEARCH below.
278: </p>
279: <p>
280: <table>
281: <tr><td>
282: ENDDOCUMENT
283: $scrout.=' '.&simpletextfield('basicexp',$ENV{'form.basicexp'},40).
284: ' ';
285: # $scrout.=&simplecheckbox('allversions',$ENV{'form.allversions'});
286: # $scrout.='<font color="#800000">Search historic archives</font>';
287: $scrout.=<<ENDDOCUMENT;
288: </td><td><a href="/adm/searchcat?reqinterface=advanced">Advanced Search</a></td></tr></table>
289: </p>
290: <p>
291: <input type="submit" name="basicsubmit" value='SEARCH' />
292: $closebutton
293: <!-- view selection -->
294: <select name="viewselect">
295: <option value="Detailed Citation View" selected="true" >Detailed Citation View</option>
296: <option value="Summary View" >Summary View</option>
297: <option value="Fielded Format">Fielded Format</option>
298: <option value="XML/SGML" >XML/SGML</option>
299: </select>
300: <!-- end of view selection -->
301: <input type="button" value="HELP" onClick="openhelp()" />
302: </p>
303: </form>
304: </body>
305: </html>
306: ENDDOCUMENT
307: return $scrout;
308: }
309: ######################################################################
310: ######################################################################
311:
312: =pod
313:
314: =item &advanced_search_form()
315:
316: Returns a scalar which holds html for the advanced search form.
317:
318: =cut
319:
320: ######################################################################
321: ######################################################################
322:
323: sub advanced_search_form{
324: my ($closebutton,$hidden) = @_;
325: my $advanced_buttons = <<"END";
326: <p>
327: <input type="submit" name="advancedsubmit" value='SEARCH' />
328: <input type="reset" name="reset" value='RESET' />
329: $closebutton
330: <input type="button" value="HELP" onClick="openhelp()" />
331: </p>
332: END
333: my $scrout=<<"ENDHEADER";
334: <html>
335: <head>
336: <title>The LearningOnline Network with CAPA</title>
337: <script type="text/javascript">
338: function openhelp(val) {
339: openhelpwin=open('/adm/help/searchcat.html','helpscreen',
340: 'scrollbars=1,width=600,height=300');
341: openhelpwin.focus();
342: }
343: </script>
344: </head>
345: <body bgcolor="#FFFFFF">
346: <img align='right' src='/adm/lonIcons/lonlogos.gif' />
347: <h1>Advanced Catalog Search</h1>
348: <hr />
349: Enter terms or quoted phrases separated by search operators
350: such as AND, OR, or NOT.<br />
351: <form method="post" action="/adm/searchcat">
352: $advanced_buttons
353: $hidden
354: <table>
355: <tr><td><font color="#800000" face="helvetica"><b>VIEW:</b></font></td>
356: <td>
357: <!-- view selection -->
358: <select name="viewselect" size ="1">
359: <option value="Detailed Citation View" selected="true">Detailed Citation View</option>
360: <option value="Summary View">Summary View</option>
361: <option value="Fielded Format">Fielded Format</option>
362: <option value="XML/SGML">XML/SGML</option>
363: </select>
364: <!-- end of view selection -->
365: </td></tr>
366: ENDHEADER
367: $scrout.=&searchphrasefield('title','title',
368: $ENV{'form.title'});
369: $scrout.=&searchphrasefield('author','author',
370: $ENV{'form.author'});
371: $scrout.=&searchphrasefield('subject','subject',
372: $ENV{'form.subject'});
373: $scrout.=&searchphrasefield('keywords','keywords',
374: $ENV{'form.keywords'});
375: $scrout.=&searchphrasefield('URL','url',
376: $ENV{'form.url'});
377: # $scrout.=&searchphrasefield('Limit by version','version',
378: # $ENV{'form.version'});
379: $scrout.=&searchphrasefield('notes','notes',
380: $ENV{'form.notes'});
381: $scrout.=&searchphrasefield('abstract','abstract',
382: $ENV{'form.abstract'});
383: # Hack - an empty table row.
384: $scrout.="<tr><td> </td><td> </td></tr>\n";
385: $scrout.=&searchphrasefield('file<br />extension','mime',
386: $ENV{'form.mime'});
387: $scrout.="<tr><td> </td><td> </td></tr>\n";
388: $scrout.=&searchphrasefield('publisher<br />owner','owner',
389: $ENV{'form.owner'});
390: $scrout.="</table>\n";
391: # $ENV{'form.mime'}='any' unless length($ENV{'form.mime'});
392: # $scrout.=&selectbox('Limit by MIME type','mime',
393: # $ENV{'form.mime'},
394: # 'any','Any type',
395: # \&{Apache::loncommon::filedescriptionex},
396: # (&Apache::loncommon::fileextensions));
397: $ENV{'form.language'}='any' unless length($ENV{'form.language'});
398: $scrout.=&selectbox('Limit by language','language',
399: $ENV{'form.language'},'any','Any Language',
400: \&{Apache::loncommon::languagedescription},
401: (&Apache::loncommon::languageids),
402: );
403: # ------------------------------------------------ Compute date selection boxes
404: $scrout.=<<CREATIONDATESTART;
405: <p>
406: <font color="#800000" face="helvetica"><b>LIMIT BY CREATION DATE RANGE:</b>
407: </font>
408: <br />
409: between:
410: CREATIONDATESTART
411: $scrout.=&dateboxes('creationdatestart',1,1,1976,
412: $ENV{'form.creationdatestart_month'},
413: $ENV{'form.creationdatestart_day'},
414: $ENV{'form.creationdatestart_year'},
415: );
416: $scrout.="and:\n";
417: $scrout.=&dateboxes('creationdateend',12,31,2051,
418: $ENV{'form.creationdateend_month'},
419: $ENV{'form.creationdateend_day'},
420: $ENV{'form.creationdateend_year'},
421: );
422: $scrout.="</p>";
423: $scrout.=<<LASTREVISIONDATESTART;
424: <p>
425: <font color="#800000" face="helvetica"><b>LIMIT BY LAST REVISION DATE RANGE:
426: </b></font>
427: <br />between:
428: LASTREVISIONDATESTART
429: $scrout.=&dateboxes('lastrevisiondatestart',1,1,1976,
430: $ENV{'form.lastrevisiondatestart_month'},
431: $ENV{'form.lastrevisiondatestart_day'},
432: $ENV{'form.lastrevisiondatestart_year'},
433: );
434: $scrout.=<<LASTREVISIONDATEEND;
435: and:
436: LASTREVISIONDATEEND
437: $scrout.=&dateboxes('lastrevisiondateend',12,31,2051,
438: $ENV{'form.lastrevisiondateend_month'},
439: $ENV{'form.lastrevisiondateend_day'},
440: $ENV{'form.lastrevisiondateend_year'},
441: );
442: $scrout.='</p>';
443: $ENV{'form.copyright'}='any' unless length($ENV{'form.copyright'});
444: $scrout.=&selectbox('Limit by copyright/distribution','copyright',
445: $ENV{'form.copyright'},
446: 'any','Any copyright/distribution',
447: \&{Apache::loncommon::copyrightdescription},
448: (&Apache::loncommon::copyrightids),
449: );
450: # ------------------------------------------- Compute customized metadata field
451: $scrout.=<<CUSTOMMETADATA;
452: <p>
453: <font color="#800000" face="helvetica"><b>LIMIT BY SPECIAL METADATA FIELDS:</b>
454: </font>
455: For resource-specific metadata, enter in an expression in the form of
456: <i>key</i>=<i>value</i> separated by operators such as AND, OR or NOT.<br />
457: <b>Example:</b> grandmother=75 OR grandfather=85
458: <br />
459: CUSTOMMETADATA
460: $scrout.=&simpletextfield('custommetadata',$ENV{'form.custommetadata'});
461: $scrout.=<<CUSTOMSHOW;
462: <p>
463: <font color="#800000" face="helvetica"><b>SHOW SPECIAL METADATA FIELDS:</b>
464: </font>
465: Enter in a space-separated list of special metadata fields to show
466: in a fielded listing for each record result.
467: <br />
468: CUSTOMSHOW
469: $scrout.=&simpletextfield('customshow',$ENV{'form.customshow'});
470: $scrout.=<<ENDDOCUMENT;
471: $advanced_buttons
472: </form>
473: </body>
474: </html>
475: ENDDOCUMENT
476: return $scrout;
477: }
478:
479: ######################################################################
480: ######################################################################
481:
482: =pod
483:
484: =item &make_persistent()
485:
486: Returns a scalar which holds the current ENV{'form.*'} values in
487: a 'hidden' html input tag. This allows search interface information
488: to be somewhat persistent.
489:
490: =cut
491:
492: ######################################################################
493: ######################################################################
494:
495: sub make_persistent {
496: my $persistent='';
497: foreach (keys %ENV) {
498: if (/^form\./ && !/submit/) {
499: my $name=$_;
500: my $key=$name;
501: $ENV{$key}=~s/\'//g; # do not mess with html field syntax
502: $name=~s/^form\.//;
503: $persistent.=<<END;
504: <input type="hidden" name="$name" value="$ENV{$key}" />
505: END
506: }
507: }
508: return $persistent;
509: }
510:
511:
512: ######################################################################
513: ######################################################################
514:
515: =pod
516:
517: =item HTML form building functions
518:
519: =over 4
520:
521: =item &simpletextfield()
522:
523: Inputs: $name,$value,$size
524:
525: Returns a text input field with the given name, value, and size.
526: If size is not specified, a value of 20 is used.
527:
528: =item &simplecheckbox()
529:
530: Inputs: $name,$value
531:
532: Returns a simple check box with the given $name.
533: If $value eq 'on' the box is checked.
534:
535: =item &searchphrasefield()
536:
537: Inputs: $title,$name,$value
538:
539: Returns html for a title line and an input field for entering search terms.
540: the instructions "Enter terms or phrases separated by search operators such
541: as AND, OR, or NOT." are given following the title. The entry field (which
542: is where the $name and $value are used) is an 80 column simpletextfield.
543:
544: =item &dateboxes()
545:
546: Returns html selection form elements for the specification of
547: the day, month, and year.
548:
549: =item &selectbox()
550:
551: Returns a scalar containing an html <select> form.
552:
553: Inputs:
554:
555: =over 4
556:
557: =item $title
558:
559: Printed above the select box, in uppercase.
560:
561: =item $name
562:
563: The name element of the <select> tag.
564:
565: =item $default
566:
567: The default value of the form. Can be $anyvalue or in @idlist.
568:
569: =item $anyvalue
570:
571: The <option value="..."> used to indicate a default of
572: none of the values.
573:
574: =item $anytag
575:
576: The text associate with $anyvalue above.
577:
578: =item $functionref
579:
580: Each element in @idlist will be passed as a parameter
581: to the function referenced here. The return value of the function should
582: be a scalar description of the items. If this value is undefined the
583: description of each item in @idlist will be the item name.
584:
585: =item @idlist
586:
587: The items to be selected from. One of these or $anyvalue will be the
588: value returned by the form element, $ENV{form.$name}.
589:
590: =back
591:
592: =back
593:
594: =cut
595:
596: ######################################################################
597: ######################################################################
598:
599: sub simpletextfield {
600: my ($name,$value,$size)=@_;
601: $size = 20 if (! defined($size));
602: return '<input type="text" name="'.$name.
603: '" size="'.$size.'" value="'.$value.'" />';
604: }
605:
606: sub simplecheckbox {
607: my ($name,$value)=@_;
608: my $checked='';
609: $checked="checked" if $value eq 'on';
610: return '<input type="checkbox" name="'.$name.'" '. $checked . ' />';
611: }
612:
613: sub searchphrasefield {
614: my ($title,$name,$value)=@_;
615: my $uctitle=uc($title);
616: return '<tr><td><font color="#800000" face="helvetica">'.
617: '<b>'.$uctitle.': </b></font></td><td>'.
618: &simpletextfield($name,$value,50)."</td></tr>\n";
619: }
620:
621: sub dateboxes {
622: my ($name,$defaultmonth,$defaultday,$defaultyear,
623: $currentmonth,$currentday,$currentyear)=@_;
624: ($defaultmonth,$defaultday,$defaultyear)=('','','');
625: #
626: # Day
627: my $day=<<END;
628: <select name="${name}_day">
629: <option value='$defaultday'> </option>
630: END
631: for (my $i = 1; $i<=31; $i++) {
632: $day.="<option value=\"$i\">$i</option>\n";
633: }
634: $day.="</select>\n";
635: $day=~s/(\"$currentday\")/$1 SELECTED/ if length($currentday);
636: #
637: # Month
638: my $month=<<END;
639: <select name="${name}_month">
640: <option value='$defaultmonth'> </option>
641: END
642: my $i = 1;
643: foreach (qw/January February March April May June
644: July August September October November December /){
645: $month .="<option value=\"$i\">$_</option>\n";
646: $i++;
647: }
648: $month.="</select>\n";
649: $month=~s/(\"$currentmonth\")/$1 SELECTED/ if length($currentmonth);
650: #
651: # Year (obviously)
652: my $year=<<END;
653: <select name="${name}_year">
654: <option value='$defaultyear'> </option>
655: END
656: my $maxyear = 2051;
657: for (my $i = 1976; $i<=$maxyear; $i++) {
658: $year.="<option value=\"$i\">$i</option>\n";
659: }
660: $year.="</select>\n";
661: $year=~s/(\"$currentyear\")/$1 SELECTED/ if length($currentyear);
662: return "$month$day$year";
663: }
664:
665: sub selectbox {
666: my ($title,$name,$default,$anyvalue,$anytag,$functionref,@idlist)=@_;
667: if (! defined($functionref)) { $functionref = sub { $_[0]}; }
668: my $uctitle=uc($title);
669: my $selout="\n".'<p><font color="#800000" face="helvetica">'.
670: '<b>'.$uctitle.':</b></font><br /><select name="'.$name.'">';
671: foreach ($anyvalue,@idlist) {
672: $selout.='<option value="'.$_.'"';
673: if ($_ eq $default and !/^any$/) {
674: $selout.=' selected >'.&{$functionref}($_).'</option>';
675: }
676: elsif ($_ eq $default and /^$anyvalue$/) {
677: $selout.=' selected >'.$anytag.'</option>';
678: }
679: else {$selout.='>'.&{$functionref}($_).'</option>';}
680: }
681: return $selout.'</select></p>';
682: }
683:
684: ######################################################################
685: ######################################################################
686:
687: =pod
688:
689: =item &advancedsearch()
690:
691: Parse advanced search results.
692:
693: =cut
694:
695: ######################################################################
696: ######################################################################
697: sub advancedsearch {
698: my ($r,$hidden)=@_;
699: my $fillflag=0;
700: # Clean up fields for safety
701: for my $field ('title','author','subject','keywords','url','version',
702: 'creationdatestart_month','creationdatestart_day',
703: 'creationdatestart_year','creationdateend_month',
704: 'creationdateend_day','creationdateend_year',
705: 'lastrevisiondatestart_month','lastrevisiondatestart_day',
706: 'lastrevisiondatestart_year','lastrevisiondateend_month',
707: 'lastrevisiondateend_day','lastrevisiondateend_year',
708: 'notes','abstract','mime','language','owner',
709: 'custommetadata','customshow') {
710: $ENV{"form.$field"}=~s/[^\w\/\s\(\)\=\-\"\']//g;
711: }
712: foreach ('mode','form','element') {
713: # is this required? Hmmm.
714: next unless (exists($ENV{"form.$_"}));
715: $ENV{"form.$_"}=&Apache::lonnet::unescape($ENV{"form.$_"});
716: $ENV{"form.$_"}=~s/[^\w\/\s\(\)\=\-\"\']//g;
717: }
718: # Check to see if enough information was filled in
719: for my $field ('title','author','subject','keywords','url','version',
720: 'notes','abstract','mime','language','owner',
721: 'custommetadata') {
722: if (&filled($ENV{"form.$field"})) {
723: $fillflag++;
724: }
725: }
726: unless ($fillflag) {
727: &output_blank_field_error($r);
728: return OK;
729: }
730: # Turn the form input into a SQL-based query
731: my $query='';
732: my @queries;
733: # Evaluate logical expression AND/OR/NOT phrase fields.
734: foreach my $field ('title','author','subject','notes','abstract','url',
735: 'keywords','version','owner','mime') {
736: if ($ENV{'form.'.$field}) {
737: push @queries,&build_SQL_query($field,$ENV{'form.'.$field});
738: }
739: }
740: # Evaluate option lists
741: if ($ENV{'form.language'} and $ENV{'form.language'} ne 'any') {
742: push @queries,"(language like \"$ENV{'form.language'}\")";
743: }
744: # if ($ENV{'form.mime'} and $ENV{'form.mime'} ne 'any') {
745: # push @queries,"(mime like \"$ENV{'form.mime'}\")";
746: # }
747: if ($ENV{'form.copyright'} and $ENV{'form.copyright'} ne 'any') {
748: push @queries,"(copyright like \"$ENV{'form.copyright'}\")";
749: }
750: # Evaluate date windows
751: my $datequery=&build_date_queries(
752: $ENV{'form.creationdatestart_month'},
753: $ENV{'form.creationdatestart_day'},
754: $ENV{'form.creationdatestart_year'},
755: $ENV{'form.creationdateend_month'},
756: $ENV{'form.creationdateend_day'},
757: $ENV{'form.creationdateend_year'},
758: $ENV{'form.lastrevisiondatestart_month'},
759: $ENV{'form.lastrevisiondatestart_day'},
760: $ENV{'form.lastrevisiondatestart_year'},
761: $ENV{'form.lastrevisiondateend_month'},
762: $ENV{'form.lastrevisiondateend_day'},
763: $ENV{'form.lastrevisiondateend_year'},
764: );
765: # Test to see if date windows are legitimate
766: if ($datequery=~/^Incorrect/) {
767: &output_date_error($r,$datequery);
768: return OK;
769: }
770: elsif ($datequery) {
771: push @queries,$datequery;
772: }
773: # Process form information for custom metadata querying
774: my $customquery='';
775: if ($ENV{'form.custommetadata'}) {
776: $customquery=&build_custommetadata_query('custommetadata',
777: $ENV{'form.custommetadata'});
778: }
779: my $customshow='';
780: if ($ENV{'form.customshow'}) {
781: $customshow=$ENV{'form.customshow'};
782: $customshow=~s/[^\w\s]//g;
783: my @fields=split(/\s+/,$customshow);
784: $customshow=join(" ",@fields);
785: }
786: # Send query statements over the network to be processed by either the SQL
787: # database or a recursive scheme of 'grep'-like actions (for custom
788: # metadata).
789: if (@queries) {
790: $query=join(" AND ",@queries);
791: $query="select * from metadata where $query";
792: my $reply; # reply hash reference
793: unless ($customquery or $customshow) {
794: $reply=&Apache::lonnet::metadata_query($query);
795: }
796: else {
797: $reply=&Apache::lonnet::metadata_query($query,
798: $customquery,$customshow);
799: }
800: &output_results('Advanced',$r,$customquery,$reply,$hidden);
801: return OK;
802: } elsif ($customquery) {
803: my $reply; # reply hash reference
804: $reply=&Apache::lonnet::metadata_query('',
805: $customquery,$customshow);
806: &output_results('Advanced',$r,$customquery,$reply,$hidden);
807: return OK;
808: }
809: # should not get to this point
810: return 'Error. Should not have gone to this point.';
811: }
812:
813: ######################################################################
814: ######################################################################
815:
816: =pod
817:
818: =item &basicsearch()
819:
820: Parse basic search form.
821:
822: =cut
823:
824: ######################################################################
825: ######################################################################
826: sub basicsearch {
827: my ($r,$hidden)=@_;
828: # Clean up fields for safety
829: for my $field ('basicexp') {
830: $ENV{"form.$field"}=~s/[^\w\s\(\)\-]//g;
831: }
832: foreach ('mode','form','element') {
833: # is this required? Hmmm.
834: next unless (exists($ENV{"form.$_"}));
835: $ENV{"form.$_"}=&Apache::lonnet::unescape($ENV{"form.$_"});
836: $ENV{"form.$_"}=~s/[^\w\/\s\(\)\=\-\"\']//g;
837: }
838:
839: # Check to see if enough is filled in
840: unless (&filled($ENV{'form.basicexp'})) {
841: &output_blank_field_error($r);
842: return OK;
843: }
844:
845: # Build SQL query string based on form page
846: my $query='';
847: my $concatarg=join('," ",',
848: ('title', 'author', 'subject', 'notes', 'abstract',
849: 'keywords'));
850: $concatarg='title' if $ENV{'form.titleonly'};
851:
852: $query=&build_SQL_query('concat('.$concatarg.')',$ENV{'form.'.'basicexp'});
853:
854: # Get reply (either a hash reference to filehandles or bad connection)
855: # &Apache::lonnet::logthis("metadata query started:".time);
856: my $reply=&Apache::lonnet::metadata_query('select * from metadata where '.$query);
857: # &Apache::lonnet::logthis("metadata query finished:".time);
858: # Output search results
859:
860: &output_results('Basic',$r,$query,$reply,$hidden);
861:
862: return OK;
863: }
864:
865:
866: ######################################################################
867: ######################################################################
868:
869: =pod
870:
871: =item &build_SQL_query()
872:
873: Builds a SQL query string from a logical expression with AND/OR keywords
874: using Text::Query and &recursive_SQL_query_builder()
875:
876: =cut
877:
878: ######################################################################
879: ######################################################################
880: sub build_SQL_query {
881: my ($field_name,$logic_statement)=@_;
882: my $q=new Text::Query('abc',
883: -parse => 'Text::Query::ParseAdvanced',
884: -build => 'Text::Query::Build');
885: $q->prepare($logic_statement);
886: my $matchexp=${$q}{'matchexp'}; chomp $matchexp;
887: my $sql_query=&recursive_SQL_query_build($field_name,$matchexp);
888: return $sql_query;
889: }
890:
891: ######################################################################
892: ######################################################################
893:
894: =pod
895:
896: =item &build_custommetadata_query()
897:
898: Constructs a custom metadata query using a rather heinous regular
899: expression.
900:
901: =cut
902:
903: ######################################################################
904: ######################################################################
905: sub build_custommetadata_query {
906: my ($field_name,$logic_statement)=@_;
907: my $q=new Text::Query('abc',
908: -parse => 'Text::Query::ParseAdvanced',
909: -build => 'Text::Query::BuildAdvancedString');
910: $q->prepare($logic_statement);
911: my $matchexp=${$q}{'-parse'}{'-build'}{'matchstring'};
912: # quick fix to change literal into xml tag-matching
913: # will eventually have to write a separate builder module
914: # wordone=wordtwo becomes\<wordone\>[^\<] *wordtwo[^\<]*\<\/wordone\>
915: $matchexp =~ s/(\w+)\\=([\w\\\+]+)?# wordone=wordtwo is changed to
916: /\\<$1\\>?# \<wordone\>
917: \[\^\\<\]?# [^\<]
918: \*$2\[\^\\<\]?# *wordtwo[^\<]
919: \*\\<\\\/$1\\>?# *\<\/wordone\>
920: /g;
921: return $matchexp;
922: }
923:
924: ######################################################################
925: ######################################################################
926:
927: =pod
928:
929: =item &recursive_SQL_query_build()
930:
931: Recursively constructs an SQL query. Takes as input $dkey and $pattern.
932:
933: =cut
934:
935: ######################################################################
936: ######################################################################
937: sub recursive_SQL_query_build {
938: my ($dkey,$pattern)=@_;
939: my @matches=($pattern=~/(\[[^\]|\[]*\])/g);
940: return $pattern unless @matches;
941: foreach my $match (@matches) {
942: $match=~/\[ (\w+)\s(.*) \]/;
943: my ($key,$value)=($1,$2);
944: my $replacement='';
945: if ($key eq 'literal') {
946: $replacement="($dkey like \"\%$value\%\")";
947: }
948: elsif ($key eq 'not') {
949: $value=~s/like/not like/;
950: # $replacement="($dkey not like $value)";
951: $replacement="$value";
952: }
953: elsif ($key eq 'and') {
954: $value=~/(.*[\"|\)]) ([|\(|\^].*)/;
955: $replacement="($1 AND $2)";
956: }
957: elsif ($key eq 'or') {
958: $value=~/(.*[\"|\)]) ([|\(|\^].*)/;
959: $replacement="($1 OR $2)";
960: }
961: substr($pattern,
962: index($pattern,$match),
963: length($match),
964: $replacement
965: );
966: }
967: &recursive_SQL_query_build($dkey,$pattern);
968: }
969:
970: ######################################################################
971: ######################################################################
972:
973: =pod
974:
975: =item &build_date_queries()
976:
977: Builds a SQL logic query to check time/date entries.
978: Also reports errors (check for /^Incorrect/).
979:
980: =cut
981:
982: ######################################################################
983: ######################################################################
984: sub build_date_queries {
985: my ($cmonth1,$cday1,$cyear1,$cmonth2,$cday2,$cyear2,
986: $lmonth1,$lday1,$lyear1,$lmonth2,$lday2,$lyear2)=@_;
987: my @queries;
988: if ($cmonth1 or $cday1 or $cyear1 or $cmonth2 or $cday2 or $cyear2) {
989: unless ($cmonth1 and $cday1 and $cyear1 and
990: $cmonth2 and $cday2 and $cyear2) {
991: return "Incorrect entry for the creation date. You must specify ".
992: "a starting month, day, and year and an ending month, ".
993: "day, and year.";
994: }
995: my $cnumeric1=sprintf("%d%2d%2d",$cyear1,$cmonth1,$cday1);
996: $cnumeric1+=0;
997: my $cnumeric2=sprintf("%d%2d%2d",$cyear2,$cmonth2,$cday2);
998: $cnumeric2+=0;
999: if ($cnumeric1>$cnumeric2) {
1000: return "Incorrect entry for the creation date. The starting ".
1001: "date must occur before the ending date.";
1002: }
1003: my $cquery="(creationdate BETWEEN '$cyear1-$cmonth1-$cday1' AND '".
1004: "$cyear2-$cmonth2-$cday2 23:59:59')";
1005: push @queries,$cquery;
1006: }
1007: if ($lmonth1 or $lday1 or $lyear1 or $lmonth2 or $lday2 or $lyear2) {
1008: unless ($lmonth1 and $lday1 and $lyear1 and
1009: $lmonth2 and $lday2 and $lyear2) {
1010: return "Incorrect entry for the last revision date. You must ".
1011: "specify a starting month, day, and year and an ending ".
1012: "month, day, and year.";
1013: }
1014: my $lnumeric1=sprintf("%d%2d%2d",$lyear1,$lmonth1,$lday1);
1015: $lnumeric1+=0;
1016: my $lnumeric2=sprintf("%d%2d%2d",$lyear2,$lmonth2,$lday2);
1017: $lnumeric2+=0;
1018: if ($lnumeric1>$lnumeric2) {
1019: return "Incorrect entry for the last revision date. The ".
1020: "starting date must occur before the ending date.";
1021: }
1022: my $lquery="(lastrevisiondate BETWEEN '$lyear1-$lmonth1-$lday1' AND '".
1023: "$lyear2-$lmonth2-$lday2 23:59:59')";
1024: push @queries,$lquery;
1025: }
1026: if (@queries) {
1027: return join(" AND ",@queries);
1028: }
1029: return '';
1030: }
1031:
1032: ######################################################################
1033: ######################################################################
1034:
1035: =pod
1036:
1037: =item &output_results()
1038:
1039: Format and output results based on a reply list.
1040: There are two windows that this function writes to. The main search
1041: window ("srch") has a listing of the results. A secondary window ("popwin")
1042: gives the status of the network search (time elapsed, number of machines
1043: contacted, etc.)
1044:
1045: =cut
1046:
1047: ######################################################################
1048: ######################################################################
1049: sub output_results {
1050: # &Apache::lonnet::logthis("output_results:".time);
1051: my $fnum; # search result counter
1052: my ($mode,$r,$query,$replyref,$hidden)=@_;
1053: my %rhash=%{$replyref};
1054: my $compiledresult='';
1055: my $timeremain=300; # (seconds)
1056: my $elapsetime=0;
1057: my $resultflag=0;
1058: my $tflag=1;
1059: my $viewselect=$ENV{'form.viewselect'};
1060: #
1061: # make query information persistent to allow for subsequent revision
1062: my $persistent=&make_persistent();
1063: # spit out the results header
1064: $r->print(&search_results_header($mode));
1065: $r->rflush();
1066: # begin showing the cataloged results
1067: my $action = "/adm/searchcat";
1068: if ($mode eq 'Basic') {
1069: $action .= "?reqinterface=basic";
1070: } elsif ($mode eq 'Advanced') {
1071: $action .= "?reqinterface=advanced";
1072: }
1073: $r->print(<<CATALOGCONTROLS);
1074: <form name='results' method="post" action="$action">
1075: $hidden
1076: <input type='hidden' name='acts' value='' />
1077: <input type='button' value='Revise search request'
1078: onClick='this.form.submit();' />
1079: $importbutton
1080: $closebutton
1081: $persistent
1082: <hr />
1083: CATALOGCONTROLS
1084: #
1085: # make the pop-up window for status
1086: #
1087: $r->print(&make_popwin(%rhash));
1088: $r->rflush();
1089: ##
1090: ## Prepare for the main loop below
1091: ##
1092: my $servercount=0;
1093: my $hitcountsum=0;
1094: my $servernum=(keys %rhash);
1095: my $serversleft=$servernum;
1096: ##
1097: ## Run until we run out of time or we run out of servers
1098: ##
1099: while($serversleft && $timeremain) {
1100: ##
1101: ## %rhash has servers deleted from it as results come in
1102: ## (within the foreach loop below).
1103: ##
1104: foreach my $rkey (sort keys %rhash) {
1105: # &Apache::lonnet::logthis("Server $rkey:".time);
1106: $servercount++;
1107: $compiledresult='';
1108: my $reply=$rhash{$rkey};
1109: my @results;
1110: if ($reply eq 'con_lost') {
1111: &popwin_imgupdate($r,$rkey,"srvbad.gif");
1112: $serversleft--;
1113: delete $rhash{$rkey};
1114: } else {
1115: # must do since 'use strict' checks for tainting
1116: $reply=~/^([\.\w]+)$/;
1117: my $replyfile=$r->dir_config('lonDaemons').'/tmp/'.$1;
1118: $reply=~/(.*?)\_/;
1119: for (my $counter=0;$counter<2;$counter++) {
1120: if (-e $replyfile && ! -e "$replyfile.end") {
1121: &popwin_imgupdate($r,$rkey,"srvhalf.gif");
1122: &popwin_js($r,'popwin.hc["'.$rkey.'"]='.
1123: '"still transferring..."'.';');
1124: }
1125: # Are we finished transferring data?
1126: if (-e "$replyfile.end") {
1127: $serversleft--;
1128: delete $rhash{$rkey};
1129: if (-s $replyfile) {
1130: &popwin_imgupdate($r,$rkey,"srvgood.gif");
1131: my $fh;
1132: unless ($fh=Apache::File->new($replyfile)){
1133: # Is it really appropriate to die on this error?
1134: $r->print('ERROR: file '.
1135: $replyfile.' cannot be opened');
1136: return OK;
1137: }
1138: @results=<$fh> if $fh;
1139: my $hits =@results;
1140: &popwin_js($r,'popwin.hc["'.$rkey.'"]='.
1141: $hits.';');
1142: $hitcountsum+=$hits;
1143: &popwin_js($r,'popwin.document.forms.popremain.'.
1144: 'numhits.value='.$hitcountsum.';');
1145: } else {
1146: &popwin_imgupdate($r,$rkey,"srvempty.gif");
1147: &popwin_js($r,'popwin.hc["'.$rkey.'"]=0;');
1148: }
1149: last;
1150: } # end of if ( -e "$replyfile.end")
1151: last unless $timeremain;
1152: sleep 1; # wait for daemons to write files?
1153: $timeremain--;
1154: $elapsetime++;
1155: &popwin_js($r,"popwin.document.popremain.".
1156: "elapsetime.value=$elapsetime;");
1157: }
1158: &popwin_js($r,'popwin.document.whirly.'.
1159: 'src="/adm/lonIcons/lonanimend.gif";');
1160: } # end of if ($reply eq 'con_lost') else statement
1161: my %Fields = undef; # Holds the data to be sent to the various
1162: # *_view routines.
1163: my ($extrashow,$customfields,$customhash) = &handle_custom_fields(\@results);
1164: my @customfields = @$customfields;
1165: my %customhash = %$customhash;
1166: untie %hash if (keys %hash);
1167: #
1168: if (! tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) {
1169: $r->print('<html><head></head><body>Unable to tie hash to db '.
1170: 'file</body></html>');
1171: } else {
1172: if ($ENV{'form.launch'} eq '1') {
1173: &start_fresh_session();
1174: }
1175: foreach my $result (@results) {
1176: next if $result=~/^custom\=/;
1177: chomp $result;
1178: next unless $result;
1179: %Fields = &parse_raw_result($result,$rkey);
1180: $Fields{'extrashow'}=$extrashow;
1181: if ($extrashow) {
1182: foreach my $field (@customfields) {
1183: my $value='';
1184: $value = $1 if ($customhash{$Fields{'url'}}=~/\<{$field}[^\>]*\>(.*?)\<\/{$field}[^\>]*\>/s);
1185: $Fields{'extrashow'}=~s/\<\!\-\- $field \-\-\>/ $value/g;
1186: }
1187: }
1188: $compiledresult.="\n<p>\n";
1189: if ($ENV{'form.catalogmode'} eq 'interactive') {
1190: my $titleesc=$Fields{'title'};
1191: $titleesc=~s/\'/\\'/; # '
1192: $compiledresult.=<<END if ($ENV{'form.catalogmode'} eq 'interactive');
1193: <font size='-1'><INPUT TYPE="button" NAME="returnvalues" VALUE="SELECT"
1194: onClick="javascript:select_data('$titleesc','$Fields{'url'}')">
1195: </font>
1196: <br />
1197: END
1198: }
1199: if ($ENV{'form.catalogmode'} eq 'groupsearch') {
1200: $fnum+=0;
1201: $hash{"pre_${fnum}_link"}=$Fields{'url'};
1202: $hash{"pre_${fnum}_title"}=$Fields{'title'};
1203: $compiledresult.=<<END;
1204: <font size='-1'>
1205: <input type="checkbox" name="returnvalues" value="SELECT"
1206: onClick="javascript:queue($fnum)" />
1207: </font>
1208: <br />
1209: END
1210: # <input type="hidden" name="title$fnum" value="$title" />
1211: # <input type="hidden" name="url$fnum" value="$url" />
1212: $fnum++;
1213: }
1214: if ($viewselect eq 'Detailed Citation View') {
1215: $compiledresult.=&detailed_citation_view
1216: (%Fields, hostname => $rkey );
1217: }
1218: elsif ($viewselect eq 'Summary View') {
1219: $compiledresult.=&summary_view
1220: (%Fields, hostname => $rkey );
1221: }
1222: elsif ($viewselect eq 'Fielded Format') {
1223: $compiledresult.=&fielded_format_view
1224: (%Fields, hostname => $rkey );
1225: }
1226: elsif ($viewselect eq 'XML/SGML') {
1227: $compiledresult.=&xml_sgml_view
1228: (%Fields, hostname => $rkey );
1229: }
1230: if ($compiledresult or $servercount!=$servernum) {
1231: $compiledresult.="<hr align='left' width='200' noshade />";
1232: }
1233: }
1234: untie %hash;
1235: }
1236: if ($compiledresult) {
1237: $resultflag=1;
1238: $r->print($compiledresult);
1239: }
1240: my $percent=sprintf('%3.0f',($servercount/$servernum*100));
1241: } # End of foreach loop over servers remaining
1242: } # End of big loop - while($serversleft && $timeremain)
1243: unless ($resultflag) {
1244: $r->print("\nThere were no results that matched your query\n");
1245: }
1246: # $r->print('<script type="text/javascript">'.'popwin.close()</script>'."\n"); $r->rflush();
1247: $r->print("</body>\n</html>\n");
1248: return;
1249: }
1250:
1251: ###########################################################
1252: ###########################################################
1253:
1254: =pod
1255:
1256: =item &parse_raw_result()
1257:
1258: Takes a line from the file of results and parse it. Returns a hash
1259: with keys for the following fields:
1260: 'title', 'author', 'subject', 'url', 'keywords', 'version', 'notes',
1261: 'abstract', 'mime', 'lang', 'owner', 'copyright', 'creationdate',
1262: 'lastrevisiondate'.
1263:
1264: In addition, the following tags are set by calling the appropriate
1265: lonnet function: 'language', 'cprtag', 'mimetag'.
1266:
1267: The 'title' field is set to "Untitled" if the title field is blank.
1268:
1269: 'abstract' and 'keywords' are truncated to 200 characters.
1270:
1271: =cut
1272:
1273: ###########################################################
1274: ###########################################################
1275: sub parse_raw_result {
1276: my ($result,$hostname) = @_;
1277: # Check for a comma - if it is there then we do not need to unescape the
1278: # string. There seems to be some kind of problem with some items in
1279: # the database - the entire string gets sent out unescaped...?
1280: unless ($result =~ /,/) {
1281: $result = &Apache::lonnet::unescape($result);
1282: }
1283: my @fields=map {
1284: &Apache::lonnet::unescape($_);
1285: } (split(/\,/,$result));
1286: my ($title,$author,$subject,$url,$keywords,$version,
1287: $notes,$abstract,$mime,$lang,
1288: $creationdate,$lastrevisiondate,$owner,$copyright)=@fields;
1289: my %Fields =
1290: ( title => &Apache::lonnet::unescape($title),
1291: author => &Apache::lonnet::unescape($author),
1292: subject => &Apache::lonnet::unescape($subject),
1293: url => &Apache::lonnet::unescape($url),
1294: keywords => &Apache::lonnet::unescape($keywords),
1295: version => &Apache::lonnet::unescape($version),
1296: notes => &Apache::lonnet::unescape($notes),
1297: abstract => &Apache::lonnet::unescape($abstract),
1298: mime => &Apache::lonnet::unescape($mime),
1299: lang => &Apache::lonnet::unescape($lang),
1300: owner => &Apache::lonnet::unescape($owner),
1301: copyright => &Apache::lonnet::unescape($copyright),
1302: creationdate => &Apache::lonnet::unescape($creationdate),
1303: lastrevisiondate => &Apache::lonnet::unescape($lastrevisiondate)
1304: );
1305: $Fields{'language'} =
1306: &Apache::loncommon::languagedescription($Fields{'lang'});
1307: $Fields{'copyrighttag'} =
1308: &Apache::loncommon::copyrightdescription($Fields{'copyright'});
1309: $Fields{'mimetag'} =
1310: &Apache::loncommon::filedescription($Fields{'mime'});
1311: # Put spaces in the keyword list, if needed.
1312: $Fields{'keywords'}=~ s/,([A-z])/, $1/g;
1313: if ($Fields{'title'}=~ /^\s*$/ ) {
1314: $Fields{'title'}='Untitled';
1315: }
1316: unless ($ENV{'user.adv'}) {
1317: $Fields{'keywords'} = '- not displayed -';
1318: $Fields{'notes'} = '- not displayed -';
1319: $Fields{'abstract'} = '- not displayed -';
1320: $Fields{'subject'} = '- not displayed -';
1321: }
1322: if (length($Fields{'abstract'})>200) {
1323: $Fields{'abstract'} =
1324: substr($Fields{'abstract'},0,200).'...';
1325: }
1326: if (length($Fields{'keywords'})>200) {
1327: $Fields{'keywords'} =
1328: substr($Fields{'keywords'},0,200).'...';
1329: }
1330: return %Fields;
1331: }
1332:
1333: ###########################################################
1334: ###########################################################
1335:
1336: =pod
1337:
1338: =item &handle_custom_fields()
1339:
1340: =cut
1341:
1342: ###########################################################
1343: ###########################################################
1344: sub handle_custom_fields {
1345: my @results = @{shift()};
1346: my $customshow='';
1347: my $extrashow='';
1348: my @customfields;
1349: if ($ENV{'form.customshow'}) {
1350: $customshow=$ENV{'form.customshow'};
1351: $customshow=~s/[^\w\s]//g;
1352: my @fields=map {
1353: "<font color=\"#008000\">$_:</font><!-- $_ -->";
1354: } split(/\s+/,$customshow);
1355: @customfields=split(/\s+/,$customshow);
1356: if ($customshow) {
1357: $extrashow="<ul><li>".join("</li><li>",@fields)."</li></ul>\n";
1358: }
1359: }
1360: my $customdata='';
1361: my %customhash;
1362: foreach my $result (@results) {
1363: if ($result=~/^(custom\=.*)$/) { # grab all custom metadata
1364: my $tmp=$result;
1365: $tmp=~s/^custom\=//;
1366: my ($k,$v)=map {&Apache::lonnet::unescape($_);
1367: } split(/\,/,$tmp);
1368: $customhash{$k}=$v;
1369: }
1370: }
1371: return ($extrashow,\@customfields,\%customhash);
1372: }
1373:
1374: ######################################################################
1375: ######################################################################
1376:
1377: =pod
1378:
1379: =item &search_results_header
1380:
1381: Output the proper html headers and javascript code to deal with different
1382: calling modes.
1383:
1384: Takes most inputs directly from %ENV, except $mode.
1385:
1386: =over 4
1387:
1388: =item $mode is either (at this writing) 'Basic' or 'Advanced'
1389:
1390: =back
1391:
1392: The following environment variables are checked:
1393:
1394: =over 4
1395:
1396: =item 'form.catalogmode'
1397:
1398: Checked for 'interactive' and 'groupsearch'.
1399:
1400: =item 'form.mode'
1401:
1402: Checked for existance & 'edit' mode.
1403:
1404: =item 'form.form'
1405:
1406: =item 'form.element'
1407:
1408: =back
1409:
1410: =cut
1411:
1412: ######################################################################
1413: ######################################################################
1414: sub search_results_header {
1415: my ($mode) = @_;
1416: $mode = lc($mode);
1417: my $title;
1418: if ($mode eq 'advanced') {
1419: $title = "Advanced Search Results";
1420: } elsif ($mode eq 'basic') {
1421: $title = "Basic Search Results";
1422: }
1423: my $result = '';
1424: # output beginning of search page
1425: $result.=<<BEGINNING;
1426: <html>
1427: <head>
1428: <title>$title</title>
1429: BEGINNING
1430: # conditional output of script functions dependent on the mode in
1431: # which the search was invoked
1432: if ($ENV{'form.catalogmode'} eq 'interactive'){
1433: if (! exists($ENV{'form.mode'}) || $ENV{'form.mode'} ne 'edit') {
1434: $result.=<<SCRIPT;
1435: <script type="text/javascript">
1436: function select_data(title,url) {
1437: changeTitle(title);
1438: changeURL(url);
1439: self.close();
1440: }
1441: function changeTitle(val) {
1442: if (opener.inf.document.forms.resinfo.elements.t) {
1443: opener.inf.document.forms.resinfo.elements.t.value=val;
1444: }
1445: }
1446: function changeURL(val) {
1447: if (opener.inf.document.forms.resinfo.elements.u) {
1448: opener.inf.document.forms.resinfo.elements.u.value=val;
1449: }
1450: }
1451: </script>
1452: SCRIPT
1453: } elsif ($ENV{'form.mode'} eq 'edit') {
1454: my $form = $ENV{'form.form'};
1455: my $element = $ENV{'form.element'};
1456: $result.=<<SCRIPT;
1457: <script type="text/javascript">
1458: function select_data(title,url) {
1459: changeURL(url);
1460: self.close();
1461: }
1462: function changeTitle(val) {
1463: }
1464: function changeURL(val) {
1465: if (window.opener.document) {
1466: window.opener.document.forms["$form"].elements["$element"].value=val;
1467: } else {
1468: var url = 'forms[\"$form\"].elements[\"$element\"].value';
1469: alert("Unable to transfer data to "+url);
1470: }
1471: }
1472: </script>
1473: SCRIPT
1474: }
1475: }
1476: $result.=<<SCRIPT if $ENV{'form.catalogmode'} eq 'groupsearch';
1477: <script type="text/javascript">
1478: function select_data(title,url) {
1479: // alert('DEBUG: Should be storing '+title+' and '+url);
1480: }
1481: function queue(val) {
1482: if (eval("document.forms.results.returnvalues["+val+"].checked")) {
1483: document.forms.results.acts.value+='1a'+val+'b';
1484: }
1485: else {
1486: document.forms.results.acts.value+='0a'+val+'b';
1487: }
1488: }
1489: function select_group() {
1490: window.location=
1491: "/adm/groupsort?mode=$ENV{'form.mode'}&catalogmode=groupsearch&acts="+
1492: document.forms.results.acts.value;
1493: }
1494: </script>
1495: SCRIPT
1496: $result.=<<SCRIPT;
1497: <script type="text/javascript">
1498: function displayinfo(val) {
1499: popwin.document.forms.popremain.sdetails.value=val;
1500: }
1501: function openhelp(val) {
1502: openhelpwin=open('/adm/help/searchcat.html','helpscreen',
1503: 'scrollbars=1,width=400,height=300');
1504: openhelpwin.focus();
1505: }
1506: function abortsearch(val) {
1507: popwin.close();
1508: }
1509: </script>
1510: SCRIPT
1511: $result.=<<END;
1512: </head>
1513: <body bgcolor="#ffffff">
1514: <img align=right src=/adm/lonIcons/lonlogos.gif>
1515: <h1>$title</h1>
1516: END
1517: return $result;
1518: }
1519:
1520: ######################################################################
1521: ######################################################################
1522:
1523: =pod
1524:
1525: =item &make_popwin()
1526:
1527: Returns html with javascript in it to open up the status window.
1528:
1529: =cut
1530:
1531: ######################################################################
1532: ######################################################################
1533: sub make_popwin {
1534: my %rhash = @_;
1535: my $servernum=(keys %rhash);
1536: my $hcinit;
1537: my $grid="'<br />'+\n";
1538: # $sn is the server number, used ONLY to make sure we have
1539: # rows of 10 each. No longer used to index images.
1540: my $sn=1;
1541: foreach my $sk (sort keys %rhash) {
1542: # '<a href="
1543: $grid.="'<a href=\"";
1544: # javascript:displayinfo('+
1545: $grid.="javascript:opener.displayinfo('+";
1546: # "'"+'key
1547: $grid.="\"'\"+'";
1548: $grid.=$sk;
1549: my $hc;
1550: if ($rhash{$sk} eq 'con_lost') {
1551: $hc="BAD CONNECTION, CONTACT SYSTEM ADMINISTRATOR ";
1552: }
1553: else {
1554: $hc="'+\"'\"+\"+hc['$sk']+\"+\"'\"+'";
1555: $hcinit.="hc[\"$sk\"]=\"not yet connected...\";";
1556: }
1557: $grid.=" hitcount=".$hc;
1558: $grid.=" domain=".$Apache::lonnet::hostdom{$sk};
1559: $grid.=" IP=".$Apache::lonnet::hostip{$sk};
1560: # '+"'"+'">'+
1561: $grid.="'+\"'\"+')\">'+";
1562: $grid.="\n";
1563: $grid.="'<img border=\"0\" name=\"img_".$Apache::lonnet::hostdom{$sk}.
1564: '_'.$sk."\" src=\"/adm/lonIcons/srvnull.gif\" alt=\"".$sk.
1565: "\" /></a>'+\n";
1566: $grid.="'<br />'+\n" unless $sn%10;
1567: $sn++;
1568: }
1569: my $result.=<<ENDPOP;
1570: <script type="text/javascript">
1571: popwin=open('','popwin','scrollbars=1,width=400,height=220');
1572: popwin.focus();
1573: popwin.document.writeln('<'+'html>');
1574: popwin.document.writeln('<'+'head>');
1575: popwin.document.writeln('<'+'script>');
1576: popwin.document.writeln('hc=new Array();$hcinit');
1577: popwin.document.writeln('<'+'/script>');
1578: popwin.document.writeln('<'+'/head>'+
1579: '<'+'body bgcolor="#FFFFFF">'+
1580: '<'+'image name="whirly" align="right" src="/adm/lonIcons/'+
1581: 'lonanim.gif" '+
1582: 'alt="animated logo" />'+
1583: '<'+'h3>Search Results Progress<'+'/h3>'+
1584: '<'+'form name="popremain">'+
1585: '<'+'tt>'+
1586: '<'+'br clear="all"/><i>PLEASE BE PATIENT</i>'+
1587: '<'+'br />SCANNING $servernum SERVERS'+
1588: '<'+'br clear="all" />Number of record hits found '+
1589: '<'+'input type="text" size="10" name="numhits"'+
1590: ' value="0" />'+
1591: '<'+'br clear="all" />Time elapsed '+
1592: '<'+'input type="text" size="10" name="elapsetime"'+
1593: ' value="0" />'+
1594: '<'+'br />'+
1595: 'SERVER GRID (click on any cell for details)'+
1596: $grid
1597: '<'+'br />'+
1598: 'Server details '+
1599: '<'+'input type="text" size="35" name="sdetails"'+
1600: ' value="" />'+
1601: '<'+'br />'+
1602: ' <'+'input type="button" name="button"'+
1603: ' value="close this window" '+
1604: ' onClick="javascript:opener.abortsearch()" />'+
1605: ' <'+'input type="button" name="button"'+
1606: ' value="help" onClick="javascript:opener.openhelp()" />'+
1607: '<'+'/tt>'+
1608: '<'+'/form>'+
1609: '<'+'/body><'+'/html>');
1610: popwin.document.close();
1611: </script>
1612: ENDPOP
1613: return $result;
1614: }
1615:
1616: ######################################################################
1617: ######################################################################
1618:
1619: =pod
1620:
1621: =item Metadata Viewing Functions
1622:
1623: Output is a HTML-ified string.
1624: Input arguments are title, author, subject, url, keywords, version,
1625: notes, short abstract, mime, language, creation date,
1626: last revision date, owner, copyright, hostname, and
1627: extra custom metadata to show.
1628:
1629: =over 4
1630:
1631: =item &detailed_citation_view()
1632:
1633: =cut
1634:
1635: ######################################################################
1636: ######################################################################
1637: sub detailed_citation_view {
1638: my %values = @_;
1639: my $result=<<END;
1640: <h3><a href="http://$ENV{'HTTP_HOST'}$values{'url'}"
1641: target='search_preview'>$values{'title'}</a></h3>
1642: <p>
1643: <b>$values{'author'}</b>, <i>$values{'owner'}</i><br />
1644:
1645: <b>Subject: </b> $values{'subject'}<br />
1646: <b>Keyword(s): </b> $values{'keywords'}<br />
1647: <b>Notes: </b> $values{'notes'}<br />
1648: <b>MIME Type: </b> $values{'mimetag'}<br />
1649: <b>Language: </b> $values{'language'}<br />
1650: <b>Copyright/Distribution:</b> $values{'cprtag'}<br />
1651: </p>
1652: $values{'extrashow'}
1653: <p>
1654: $values{'shortabstract'}
1655: </p>
1656: END
1657: return $result;
1658: }
1659:
1660: ######################################################################
1661: ######################################################################
1662:
1663: =pod
1664:
1665: =item &summary_view()
1666:
1667: =cut
1668:
1669: ######################################################################
1670: ######################################################################
1671: sub summary_view {
1672: my %values = @_;
1673: my $result=<<END;
1674: <a href="http://$ENV{'HTTP_HOST'}$values{'url'}"
1675: target='search_preview'>$values{'author'}</a><br />
1676: $values{'title'}<br />
1677: $values{'owner'} -- $values{'lastrevisiondate'}<br />
1678: $values{'copyrighttag'}<br />
1679: $values{'extrashow'}
1680: </p>
1681: END
1682: return $result;
1683: }
1684:
1685: ######################################################################
1686: ######################################################################
1687:
1688: =pod
1689:
1690: =item &fielded_format_view()
1691:
1692: =cut
1693:
1694: ######################################################################
1695: ######################################################################
1696: sub fielded_format_view {
1697: my %values = @_;
1698: my $result=<<END;
1699: <b>URL: </b> <a href="http://$ENV{'HTTP_HOST'}$values{'url'}"
1700: target='search_preview'>$values{'url'}</a>
1701: <br />
1702: <b>Title:</b> $values{'title'}<br />
1703: <b>Author(s):</b> $values{'author'}<br />
1704: <b>Subject:</b> $values{'subject'}<br />
1705: <b>Keyword(s):</b> $values{'keywords'}<br />
1706: <b>Notes:</b> $values{'notes'}<br />
1707: <b>MIME Type:</b> $values{'mimetag'}<br />
1708: <b>Language:</b> $values{'language'}<br />
1709: <b>Creation Date:</b> $values{'creationdate'}<br />
1710: <b>Last Revision Date:</b> $values{'lastrevisiondate'}<br />
1711: <b>Publisher/Owner:</b> $values{'owner'}<br />
1712: <b>Copyright/Distribution:</b> $values{'copyrighttag'}<br />
1713: <b>Repository Location:</b> $values{'hostname'}<br />
1714: <b>Abstract:</b> $values{'shortabstract'}<br />
1715: $values{'extrashow'}
1716: </p>
1717: END
1718: return $result;
1719: }
1720:
1721: ######################################################################
1722: ######################################################################
1723:
1724: =pod
1725:
1726: =item &xml_sgml_view()
1727:
1728: =back
1729:
1730: =cut
1731:
1732: ######################################################################
1733: ######################################################################
1734: sub xml_sgml_view {
1735: my %values = @_;
1736: my $result=<<END;
1737: <pre>
1738: <LonCapaResource>
1739: <url>$values{'url'}</url>
1740: <title>$values{'title'}</title>
1741: <author>$values{'author'}</author>
1742: <subject>$values{'subject'}</subject>
1743: <keywords>$values{'keywords'}</keywords>
1744: <notes>$values{'notes'}</notes>
1745: <mimeInfo>
1746: <mime>$values{'mime'}</mime>
1747: <mimetag>$values{'mimetag'}</mimetag>
1748: </mimeInfo>
1749: <languageInfo>
1750: <language>$values{'lang'}</language>
1751: <languagetag>$values{'language'}</languagetag>
1752: </languageInfo>
1753: <creationdate>$values{'creationdate'}</creationdate>
1754: <lastrevisiondate>$values{'lastrevisiondate'}</lastrevisiondate>
1755: <owner>$values{'owner'}</owner>
1756: <copyrightInfo>
1757: <copyright>$values{'copyright'}</copyright>
1758: <copyrighttag>$values{'copyrighttag'}</copyrighttag>
1759: </copyrightInfo>
1760: <repositoryLocation>$values{'hostname'}</repositoryLocation>
1761: <shortabstract>$values{'shortabstract'}</shortabstract>
1762: </LonCapaResource>
1763: </pre>
1764: $values{'extrashow'}
1765: END
1766: return $result;
1767: }
1768:
1769: ######################################################################
1770: ######################################################################
1771:
1772: =pod
1773:
1774: =item &filled() see if field is filled.
1775:
1776: =cut
1777:
1778: ######################################################################
1779: ######################################################################
1780: sub filled {
1781: my ($field)=@_;
1782: if ($field=~/\S/ && $field ne 'any') {
1783: return 1;
1784: }
1785: else {
1786: return 0;
1787: }
1788: }
1789:
1790: ######################################################################
1791: ######################################################################
1792:
1793: =pod
1794:
1795: =item &output_blank_field_error()
1796:
1797: =cut
1798:
1799: ######################################################################
1800: ######################################################################
1801: sub output_blank_field_error {
1802: my ($r)=@_;
1803: # make query information persistent to allow for subsequent revision
1804: my $persistent=&make_persistent();
1805:
1806: $r->print(<<BEGINNING);
1807: <html>
1808: <head>
1809: <title>The LearningOnline Network with CAPA</title>
1810: BEGINNING
1811: $r->print(<<RESULTS);
1812: </head>
1813: <body bgcolor="#ffffff">
1814: <img align='right' src='/adm/lonIcons/lonlogos.gif' />
1815: <h1>Search Catalog</h1>
1816: <form method="post" action="/adm/searchcat">
1817: $persistent
1818: <input type='button' value='Revise search request'
1819: onClick='this.form.submit();' />
1820: $closebutton
1821: <hr />
1822: <h3>Helpful Message</h3>
1823: <p>
1824: Incorrect search query due to blank entry fields.
1825: You need to fill in the relevant
1826: fields on the search page in order for a query to be
1827: processed.
1828: </p>
1829: </body>
1830: </html>
1831: RESULTS
1832: }
1833:
1834: ######################################################################
1835: ######################################################################
1836:
1837: =pod
1838:
1839: =item &output_date_error()
1840:
1841: Output a full html page with an error message.
1842:
1843: =cut
1844:
1845: ######################################################################
1846: ######################################################################
1847: sub output_date_error {
1848: my ($r,$message)=@_;
1849: # make query information persistent to allow for subsequent revision
1850: my $persistent=&make_persistent();
1851:
1852: $r->print(<<RESULTS);
1853: <html>
1854: <head>
1855: <title>The LearningOnline Network with CAPA</title>
1856: </head>
1857: <body bgcolor="#ffffff">
1858: <img align='right' src='/adm/lonIcons/lonlogos.gif' />
1859: <h1>Search Catalog</h1>
1860: <form method="post" action="/adm/searchcat">
1861: $persistent
1862: <input type='button' value='Revise search request'
1863: onClick='this.form.submit();' />
1864: $closebutton
1865: <hr />
1866: <h3>Helpful Message</h3>
1867: <p>
1868: $message
1869: </p>
1870: </body>
1871: </html>
1872: RESULTS
1873: }
1874:
1875: ######################################################################
1876: ######################################################################
1877:
1878: =pod
1879:
1880: =item &start_fresh_session()
1881:
1882: Cleans the global %hash by removing all fields which begin with
1883: 'pre_' or 'store'.
1884:
1885: =cut
1886:
1887: ######################################################################
1888: ######################################################################
1889: sub start_fresh_session {
1890: delete $hash{'mode_catalog'};
1891: foreach (keys %hash) {
1892: if ($_ =~ /^pre_/) {
1893: delete $hash{$_};
1894: }
1895: if ($_ =~ /^store/) {
1896: delete $hash{$_};
1897: }
1898: }
1899: }
1900:
1901: ######################################################################
1902: ######################################################################
1903:
1904: =pod
1905:
1906: =item &popwin_js() send javascript to popwin
1907:
1908: =cut
1909:
1910: ######################################################################
1911: ######################################################################
1912: sub popwin_js {
1913: # Print javascript out to popwin, but make sure we dont generate
1914: # any javascript errors in doing so.
1915: my ($r,$text) = @_;
1916: $r->print(<<"END");
1917: <script type="text/javascript">
1918: if (! popwin.closed) {
1919: $text
1920: }
1921: </script>
1922: END
1923: $r->rflush();
1924: }
1925:
1926: ######################################################################
1927: ######################################################################
1928:
1929: =pod
1930:
1931: =item &popwin_imgupdate()
1932:
1933: Send a given image (and its location) out to the browser. Takes as
1934: input $r, loncapa server id, and an icon URL.
1935:
1936: =cut
1937:
1938: ######################################################################
1939: ######################################################################
1940: sub popwin_imgupdate {
1941: my ($r,$server,$icon) = @_;
1942: &popwin_js($r,'popwin.document.img_'.$Apache::lonnet::hostdom{$server}.
1943: '_'.$server.'.'.'src="/adm/lonIcons/'.$icon.'";');
1944: }
1945:
1946: 1;
1947:
1948: __END__
1949:
1950: =pod
1951:
1952: =back
1953:
1954: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>