Annotation of loncom/interface/lonsearchcat.pm, revision 1.130
1.98 harris41 1: # The LearningOnline Network with CAPA
1.108 harris41 2: # Search Catalog
3: #
1.130 ! matthew 4: # $Id: lonsearchcat.pm,v 1.129 2002/06/25 15:08:59 matthew Exp $
1.108 harris41 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.
1.98 harris41 14: #
1.108 harris41 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/
1.1 www 27: #
1.97 harris41 28: # YEAR=2001
1.104 harris41 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
1.113 harris41 31: # 10/12,10/14,10/15,10/16,11/28,11/29,12/10,12/12,12/16 Scott Harrison
1.115 harris41 32: # YEAR=2002
33: # 1/17 Scott Harrison
1.121 matthew 34: # 6/17 Matthew Hall
1.104 harris41 35: #
1.121 matthew 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.
1.104 harris41 52:
1.121 matthew 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: ###############################################################################
1.98 harris41 68: ###############################################################################
1.121 matthew 69:
1.128 harris41 70: ###############################################################################
1.98 harris41 71: ## ##
72: ## ORGANIZATION OF THIS PERL MODULE ##
73: ## ##
1.105 harris41 74: ## 1. Modules used by this module ##
1.128 harris41 75: ## 2. Variables used throughout the module ##
76: ## 3. handler subroutine called via Apache and mod_perl ##
77: ## 4. Other subroutines ##
1.98 harris41 78: ## ##
79: ###############################################################################
80:
1.1 www 81: package Apache::lonsearchcat;
82:
1.98 harris41 83: # ------------------------------------------------- modules used by this module
1.1 www 84: use strict;
85: use Apache::Constants qw(:common);
1.6 harris41 86: use Apache::lonnet();
87: use Apache::File();
1.7 harris41 88: use CGI qw(:standard);
1.41 harris41 89: use Text::Query;
1.101 harris41 90: use GDBM_File;
1.112 harris41 91: use Apache::loncommon();
1.1 www 92:
1.90 harris41 93: # ---------------------------------------- variables used throughout the module
94:
1.121 matthew 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:
1.98 harris41 128: # -- dynamically rendered interface components
1.121 matthew 129: my $closebutton; # button that closes the search window
1.98 harris41 130: my $importbutton; # button to take the selected results and go to group sorting
131:
132: # -- miscellaneous variables
1.121 matthew 133: my %hash; # database hash
1.127 matthew 134: my $diropendb = ""; # db file
1.98 harris41 135:
1.121 matthew 136: ######################################################################
137: ######################################################################
138:
139: =pod
140:
141: =item &handler() - main handler invoked by httpd child
142:
1.124 matthew 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:
1.121 matthew 157: =cut
1.101 harris41 158:
1.121 matthew 159: ######################################################################
160: ######################################################################
1.98 harris41 161: sub handler {
162: my $r = shift;
1.103 harris41 163: untie %hash;
1.98 harris41 164:
165: $r->content_type('text/html');
166: $r->send_http_header;
167: return OK if $r->header_only;
168:
1.121 matthew 169: my $domain = $r->dir_config('lonDefDomain');
1.122 matthew 170: $diropendb= "/home/httpd/perl/tmp/".&Apache::lonnet::escape($domain).
171: "\_".&Apache::lonnet::escape($ENV{'user.name'})."_searchcat.db";
1.101 harris41 172:
1.116 matthew 173: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.124 matthew 174: ['catalogmode','launch','acts','mode','form','element',
175: 'reqinterface']);
176: ##
177: ## Clear out old values from database
178: ##
1.101 harris41 179: if ($ENV{'form.launch'} eq '1') {
180: if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) {
181: &start_fresh_session();
182: untie %hash;
1.122 matthew 183: } else {
1.101 harris41 184: $r->print('<html><head></head><body>Unable to tie hash to db '.
185: 'file</body></html>');
186: return OK;
187: }
188: }
1.124 matthew 189: ##
190: ## Produce some output, so people know it is working
191: ##
1.119 www 192: $r->print("\n");
193: $r->rflush;
1.124 matthew 194: ##
195: ## Configure dynamic components of interface
196: ##
197: my $hidden; # Holds 'hidden' html forms
1.98 harris41 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";
1.124 matthew 203: } elsif ($ENV{'form.catalogmode'} eq 'groupsearch') {
1.98 harris41 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: }
1.117 matthew 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
1.124 matthew 221: ##
222: ## What are we doing?
223: ##
224: if ($ENV{'form.basicsubmit'} eq 'SEARCH') {
225: # Perform basic search and give results
1.130 ! matthew 226: return &basicsearch($r,$hidden);
1.124 matthew 227: } elsif ($ENV{'form.advancedsubmit'} eq 'SEARCH') {
228: # Perform advanced search and give results
1.130 ! matthew 229: return &advancedsearch($r,$hidden);
1.124 matthew 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: }
1.98 harris41 240:
1.124 matthew 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: ######################################################################
1.3 harris41 254:
1.124 matthew 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();
1.6 harris41 266: }
1.124 matthew 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>
1.129 matthew 276: Enter terms or quoted phrases separated by AND, OR, or NOT
277: then press SEARCH below.
1.124 matthew 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
1.130 ! matthew 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>
1.124 matthew 299: </select>
1.130 ! matthew 300: <!-- end of view selection -->
1.124 matthew 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) = @_;
1.129 matthew 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
1.124 matthew 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();
1.18 harris41 342: }
1.124 matthew 343: </script>
344: </head>
345: <body bgcolor="#FFFFFF">
346: <img align='right' src='/adm/lonIcons/lonlogos.gif' />
1.129 matthew 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 />
1.130 ! matthew 351: <form method="post" action="/adm/searchcat">
1.129 matthew 352: $advanced_buttons
1.124 matthew 353: $hidden
1.129 matthew 354: <table>
1.130 ! matthew 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>
1.124 matthew 366: ENDHEADER
1.129 matthew 367: $scrout.=&searchphrasefield('title','title',
1.11 harris41 368: $ENV{'form.title'});
1.129 matthew 369: $scrout.=&searchphrasefield('author','author',
1.11 harris41 370: $ENV{'form.author'});
1.129 matthew 371: $scrout.=&searchphrasefield('subject','subject',
1.11 harris41 372: $ENV{'form.subject'});
1.129 matthew 373: $scrout.=&searchphrasefield('keywords','keywords',
1.11 harris41 374: $ENV{'form.keywords'});
1.129 matthew 375: $scrout.=&searchphrasefield('URL','url',
1.11 harris41 376: $ENV{'form.url'});
1.96 harris41 377: # $scrout.=&searchphrasefield('Limit by version','version',
378: # $ENV{'form.version'});
1.129 matthew 379: $scrout.=&searchphrasefield('notes','notes',
1.11 harris41 380: $ENV{'form.notes'});
1.129 matthew 381: $scrout.=&searchphrasefield('abstract','abstract',
1.11 harris41 382: $ENV{'form.abstract'});
1.129 matthew 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));
1.11 harris41 397: $ENV{'form.language'}='any' unless length($ENV{'form.language'});
1.3 harris41 398: $scrout.=&selectbox('Limit by language','language',
1.111 harris41 399: $ENV{'form.language'},'any','Any Language',
400: \&{Apache::loncommon::languagedescription},
401: (&Apache::loncommon::languageids),
402: );
1.8 harris41 403: # ------------------------------------------------ Compute date selection boxes
404: $scrout.=<<CREATIONDATESTART;
1.3 harris41 405: <p>
406: <font color="#800000" face="helvetica"><b>LIMIT BY CREATION DATE RANGE:</b>
407: </font>
1.98 harris41 408: <br />
1.8 harris41 409: between:
410: CREATIONDATESTART
1.11 harris41 411: $scrout.=&dateboxes('creationdatestart',1,1,1976,
412: $ENV{'form.creationdatestart_month'},
413: $ENV{'form.creationdatestart_day'},
414: $ENV{'form.creationdatestart_year'},
415: );
1.124 matthew 416: $scrout.="and:\n";
1.11 harris41 417: $scrout.=&dateboxes('creationdateend',12,31,2051,
418: $ENV{'form.creationdateend_month'},
419: $ENV{'form.creationdateend_day'},
420: $ENV{'form.creationdateend_year'},
421: );
1.8 harris41 422: $scrout.="</p>";
423: $scrout.=<<LASTREVISIONDATESTART;
424: <p>
425: <font color="#800000" face="helvetica"><b>LIMIT BY LAST REVISION DATE RANGE:
426: </b></font>
1.98 harris41 427: <br />between:
1.8 harris41 428: LASTREVISIONDATESTART
1.11 harris41 429: $scrout.=&dateboxes('lastrevisiondatestart',1,1,1976,
430: $ENV{'form.lastrevisiondatestart_month'},
431: $ENV{'form.lastrevisiondatestart_day'},
432: $ENV{'form.lastrevisiondatestart_year'},
433: );
1.8 harris41 434: $scrout.=<<LASTREVISIONDATEEND;
435: and:
436: LASTREVISIONDATEEND
1.11 harris41 437: $scrout.=&dateboxes('lastrevisiondateend',12,31,2051,
438: $ENV{'form.lastrevisiondateend_month'},
439: $ENV{'form.lastrevisiondateend_day'},
440: $ENV{'form.lastrevisiondateend_year'},
441: );
1.8 harris41 442: $scrout.='</p>';
1.11 harris41 443: $ENV{'form.copyright'}='any' unless length($ENV{'form.copyright'});
1.8 harris41 444: $scrout.=&selectbox('Limit by copyright/distribution','copyright',
1.111 harris41 445: $ENV{'form.copyright'},
446: 'any','Any copyright/distribution',
447: \&{Apache::loncommon::copyrightdescription},
448: (&Apache::loncommon::copyrightids),
449: );
1.14 harris41 450: # ------------------------------------------- Compute customized metadata field
451: $scrout.=<<CUSTOMMETADATA;
452: <p>
1.77 harris41 453: <font color="#800000" face="helvetica"><b>LIMIT BY SPECIAL METADATA FIELDS:</b>
1.14 harris41 454: </font>
1.77 harris41 455: For resource-specific metadata, enter in an expression in the form of
1.100 harris41 456: <i>key</i>=<i>value</i> separated by operators such as AND, OR or NOT.<br />
1.14 harris41 457: <b>Example:</b> grandmother=75 OR grandfather=85
1.98 harris41 458: <br />
1.14 harris41 459: CUSTOMMETADATA
1.124 matthew 460: $scrout.=&simpletextfield('custommetadata',$ENV{'form.custommetadata'});
1.77 harris41 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.
1.98 harris41 467: <br />
1.77 harris41 468: CUSTOMSHOW
1.124 matthew 469: $scrout.=&simpletextfield('customshow',$ENV{'form.customshow'});
470: $scrout.=<<ENDDOCUMENT;
1.129 matthew 471: $advanced_buttons
1.8 harris41 472: </form>
473: </body>
474: </html>
475: ENDDOCUMENT
1.124 matthew 476: return $scrout;
477: }
1.8 harris41 478:
1.121 matthew 479: ######################################################################
480: ######################################################################
481:
482: =pod
483:
484: =item &make_persistent()
485:
486: Returns a scalar which holds the current ENV{'form.*'} values in
1.126 matthew 487: a 'hidden' html input tag. This allows search interface information
488: to be somewhat persistent.
1.122 matthew 489:
1.121 matthew 490: =cut
491:
492: ######################################################################
493: ######################################################################
494:
1.98 harris41 495: sub make_persistent {
496: my $persistent='';
1.109 harris41 497: foreach (keys %ENV) {
1.98 harris41 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;
1.125 matthew 504: <input type="hidden" name="$name" value="$ENV{$key}" />
1.98 harris41 505: END
506: }
1.109 harris41 507: }
1.98 harris41 508: return $persistent;
509: }
510:
1.122 matthew 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:
1.126 matthew 546: Returns html selection form elements for the specification of
547: the day, month, and year.
548:
1.122 matthew 549: =item &selectbox()
550:
1.129 matthew 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
1.126 matthew 591:
1.122 matthew 592: =back
593:
594: =cut
595:
596: ######################################################################
597: ######################################################################
1.8 harris41 598:
1.11 harris41 599: sub simpletextfield {
1.122 matthew 600: my ($name,$value,$size)=@_;
601: $size = 20 if (! defined($size));
602: return '<input type="text" name="'.$name.
603: '" size="'.$size.'" value="'.$value.'" />';
1.11 harris41 604: }
605:
606: sub simplecheckbox {
607: my ($name,$value)=@_;
608: my $checked='';
1.129 matthew 609: $checked="checked" if $value eq 'on';
1.122 matthew 610: return '<input type="checkbox" name="'.$name.'" '. $checked . ' />';
1.11 harris41 611: }
612:
1.8 harris41 613: sub searchphrasefield {
614: my ($title,$name,$value)=@_;
615: my $uctitle=uc($title);
1.129 matthew 616: return '<tr><td><font color="#800000" face="helvetica">'.
617: '<b>'.$uctitle.': </b></font></td><td>'.
618: &simpletextfield($name,$value,50)."</td></tr>\n";
1.8 harris41 619: }
1.3 harris41 620:
1.8 harris41 621: sub dateboxes {
1.11 harris41 622: my ($name,$defaultmonth,$defaultday,$defaultyear,
623: $currentmonth,$currentday,$currentyear)=@_;
624: ($defaultmonth,$defaultday,$defaultyear)=('','','');
1.117 matthew 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
1.11 harris41 638: my $month=<<END;
1.8 harris41 639: <select name="${name}_month">
1.11 harris41 640: <option value='$defaultmonth'> </option>
641: END
1.117 matthew 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";
1.11 harris41 649: $month=~s/(\"$currentmonth\")/$1 SELECTED/ if length($currentmonth);
1.117 matthew 650: #
651: # Year (obviously)
1.11 harris41 652: my $year=<<END;
1.8 harris41 653: <select name="${name}_year">
1.11 harris41 654: <option value='$defaultyear'> </option>
1.3 harris41 655: END
1.117 matthew 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";
1.11 harris41 661: $year=~s/(\"$currentyear\")/$1 SELECTED/ if length($currentyear);
662: return "$month$day$year";
1.3 harris41 663: }
664:
665: sub selectbox {
1.129 matthew 666: my ($title,$name,$default,$anyvalue,$anytag,$functionref,@idlist)=@_;
667: if (! defined($functionref)) { $functionref = sub { $_[0]}; }
1.3 harris41 668: my $uctitle=uc($title);
1.122 matthew 669: my $selout="\n".'<p><font color="#800000" face="helvetica">'.
670: '<b>'.$uctitle.':</b></font><br /><select name="'.$name.'">';
1.111 harris41 671: foreach ($anyvalue,@idlist) {
1.122 matthew 672: $selout.='<option value="'.$_.'"';
1.129 matthew 673: if ($_ eq $default and !/^any$/) {
1.122 matthew 674: $selout.=' selected >'.&{$functionref}($_).'</option>';
1.111 harris41 675: }
1.129 matthew 676: elsif ($_ eq $default and /^$anyvalue$/) {
1.122 matthew 677: $selout.=' selected >'.$anytag.'</option>';
1.111 harris41 678: }
679: else {$selout.='>'.&{$functionref}($_).'</option>';}
1.109 harris41 680: }
1.129 matthew 681: return $selout.'</select></p>';
1.6 harris41 682: }
683:
1.122 matthew 684: ######################################################################
685: ######################################################################
686:
687: =pod
688:
1.126 matthew 689: =item &advancedsearch()
690:
691: Parse advanced search results.
1.122 matthew 692:
693: =cut
694:
695: ######################################################################
696: ######################################################################
1.18 harris41 697: sub advancedsearch {
1.130 ! matthew 698: my ($r,$hidden)=@_;
1.32 harris41 699: my $fillflag=0;
1.64 harris41 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',
1.77 harris41 709: 'custommetadata','customshow') {
1.101 harris41 710: $ENV{"form.$field"}=~s/[^\w\/\s\(\)\=\-\"\']//g;
1.64 harris41 711: }
1.117 matthew 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: }
1.90 harris41 718: # Check to see if enough information was filled in
1.32 harris41 719: for my $field ('title','author','subject','keywords','url','version',
720: 'notes','abstract','mime','language','owner',
721: 'custommetadata') {
1.40 harris41 722: if (&filled($ENV{"form.$field"})) {
1.32 harris41 723: $fillflag++;
724: }
725: }
726: unless ($fillflag) {
727: &output_blank_field_error($r);
728: return OK;
729: }
1.90 harris41 730: # Turn the form input into a SQL-based query
1.39 harris41 731: my $query='';
1.45 harris41 732: my @queries;
1.90 harris41 733: # Evaluate logical expression AND/OR/NOT phrase fields.
1.58 harris41 734: foreach my $field ('title','author','subject','notes','abstract','url',
1.129 matthew 735: 'keywords','version','owner','mime') {
1.44 harris41 736: if ($ENV{'form.'.$field}) {
1.45 harris41 737: push @queries,&build_SQL_query($field,$ENV{'form.'.$field});
1.44 harris41 738: }
739: }
1.90 harris41 740: # Evaluate option lists
1.58 harris41 741: if ($ENV{'form.language'} and $ENV{'form.language'} ne 'any') {
1.90 harris41 742: push @queries,"(language like \"$ENV{'form.language'}\")";
1.58 harris41 743: }
1.129 matthew 744: # if ($ENV{'form.mime'} and $ENV{'form.mime'} ne 'any') {
745: # push @queries,"(mime like \"$ENV{'form.mime'}\")";
746: # }
1.58 harris41 747: if ($ENV{'form.copyright'} and $ENV{'form.copyright'} ne 'any') {
1.90 harris41 748: push @queries,"(copyright like \"$ENV{'form.copyright'}\")";
1.58 harris41 749: }
1.90 harris41 750: # Evaluate date windows
1.60 harris41 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: );
1.90 harris41 765: # Test to see if date windows are legitimate
1.61 harris41 766: if ($datequery=~/^Incorrect/) {
767: &output_date_error($r,$datequery);
768: return OK;
769: }
770: elsif ($datequery) {
1.60 harris41 771: push @queries,$datequery;
772: }
1.90 harris41 773: # Process form information for custom metadata querying
1.76 harris41 774: my $customquery='';
1.64 harris41 775: if ($ENV{'form.custommetadata'}) {
776: $customquery=&build_custommetadata_query('custommetadata',
777: $ENV{'form.custommetadata'});
778: }
1.83 harris41 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: }
1.90 harris41 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).
1.45 harris41 789: if (@queries) {
1.58 harris41 790: $query=join(" AND ",@queries);
1.46 harris41 791: $query="select * from metadata where $query";
1.90 harris41 792: my $reply; # reply hash reference
1.83 harris41 793: unless ($customquery or $customshow) {
1.76 harris41 794: $reply=&Apache::lonnet::metadata_query($query);
795: }
796: else {
1.83 harris41 797: $reply=&Apache::lonnet::metadata_query($query,
798: $customquery,$customshow);
1.76 harris41 799: }
1.130 ! matthew 800: &output_results('Advanced',$r,$customquery,$reply,$hidden);
1.126 matthew 801: return OK;
802: } elsif ($customquery) {
1.90 harris41 803: my $reply; # reply hash reference
1.86 harris41 804: $reply=&Apache::lonnet::metadata_query('',
805: $customquery,$customshow);
1.130 ! matthew 806: &output_results('Advanced',$r,$customquery,$reply,$hidden);
1.126 matthew 807: return OK;
1.45 harris41 808: }
1.92 harris41 809: # should not get to this point
810: return 'Error. Should not have gone to this point.';
1.18 harris41 811: }
812:
1.122 matthew 813: ######################################################################
814: ######################################################################
815:
816: =pod
817:
818: =item &basicsearch()
819:
1.126 matthew 820: Parse basic search form.
821:
1.122 matthew 822: =cut
823:
824: ######################################################################
825: ######################################################################
1.6 harris41 826: sub basicsearch {
1.130 ! matthew 827: my ($r,$hidden)=@_;
1.64 harris41 828: # Clean up fields for safety
829: for my $field ('basicexp') {
830: $ENV{"form.$field"}=~s/[^\w\s\(\)\-]//g;
831: }
1.117 matthew 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: }
1.64 harris41 838:
1.90 harris41 839: # Check to see if enough is filled in
1.26 harris41 840: unless (&filled($ENV{'form.basicexp'})) {
1.24 harris41 841: &output_blank_field_error($r);
842: return OK;
843: }
1.22 harris41 844:
1.90 harris41 845: # Build SQL query string based on form page
1.39 harris41 846: my $query='';
1.33 harris41 847: my $concatarg=join('," ",',
1.124 matthew 848: ('title', 'author', 'subject', 'notes', 'abstract',
849: 'keywords'));
1.95 harris41 850: $concatarg='title' if $ENV{'form.titleonly'};
1.94 harris41 851:
852: $query=&build_SQL_query('concat('.$concatarg.')',$ENV{'form.'.'basicexp'});
853:
1.90 harris41 854: # Get reply (either a hash reference to filehandles or bad connection)
1.126 matthew 855: # &Apache::lonnet::logthis("metadata query started:".time);
1.94 harris41 856: my $reply=&Apache::lonnet::metadata_query('select * from metadata where '.$query);
1.126 matthew 857: # &Apache::lonnet::logthis("metadata query finished:".time);
1.90 harris41 858: # Output search results
1.98 harris41 859:
1.130 ! matthew 860: &output_results('Basic',$r,$query,$reply,$hidden);
1.90 harris41 861:
1.18 harris41 862: return OK;
1.22 harris41 863: }
864:
1.122 matthew 865:
866: ######################################################################
867: ######################################################################
868:
869: =pod
870:
871: =item &build_SQL_query()
872:
1.126 matthew 873: Builds a SQL query string from a logical expression with AND/OR keywords
874: using Text::Query and &recursive_SQL_query_builder()
875:
1.122 matthew 876: =cut
877:
878: ######################################################################
879: ######################################################################
1.98 harris41 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:
1.122 matthew 891: ######################################################################
892: ######################################################################
893:
894: =pod
895:
896: =item &build_custommetadata_query()
897:
1.126 matthew 898: Constructs a custom metadata query using a rather heinous regular
899: expression.
900:
1.122 matthew 901: =cut
902:
903: ######################################################################
904: ######################################################################
1.98 harris41 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
1.122 matthew 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;
1.98 harris41 921: return $matchexp;
922: }
923:
1.122 matthew 924: ######################################################################
925: ######################################################################
926:
927: =pod
928:
929: =item &recursive_SQL_query_build()
930:
1.126 matthew 931: Recursively constructs an SQL query. Takes as input $dkey and $pattern.
932:
1.122 matthew 933: =cut
934:
935: ######################################################################
936: ######################################################################
1.98 harris41 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: }
1.22 harris41 969:
1.122 matthew 970: ######################################################################
971: ######################################################################
972:
973: =pod
974:
975: =item &build_date_queries()
976:
1.126 matthew 977: Builds a SQL logic query to check time/date entries.
978: Also reports errors (check for /^Incorrect/).
979:
1.122 matthew 980: =cut
981:
982: ######################################################################
983: ######################################################################
1.98 harris41 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 '';
1.18 harris41 1030: }
1.6 harris41 1031:
1.122 matthew 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: ######################################################################
1.18 harris41 1049: sub output_results {
1.126 matthew 1050: # &Apache::lonnet::logthis("output_results:".time);
1.101 harris41 1051: my $fnum; # search result counter
1.130 ! matthew 1052: my ($mode,$r,$query,$replyref,$hidden)=@_;
1.92 harris41 1053: my %rhash=%{$replyref};
1.44 harris41 1054: my $compiledresult='';
1.125 matthew 1055: my $timeremain=300; # (seconds)
1.98 harris41 1056: my $elapsetime=0;
1.93 harris41 1057: my $resultflag=0;
1058: my $tflag=1;
1.130 ! matthew 1059: my $viewselect=$ENV{'form.viewselect'};
1.125 matthew 1060: #
1.93 harris41 1061: # make query information persistent to allow for subsequent revision
1062: my $persistent=&make_persistent();
1.130 ! matthew 1063: # spit out the results header
! 1064: $r->print(&search_results_header($mode));
1.98 harris41 1065: $r->rflush();
1066: # begin showing the cataloged results
1.129 matthew 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">
1.118 www 1075: $hidden
1.98 harris41 1076: <input type='hidden' name='acts' value='' />
1.93 harris41 1077: <input type='button' value='Revise search request'
1.98 harris41 1078: onClick='this.form.submit();' />
1079: $importbutton
1.93 harris41 1080: $closebutton
1081: $persistent
1.98 harris41 1082: <hr />
1083: CATALOGCONTROLS
1.125 matthew 1084: #
1085: # make the pop-up window for status
1086: #
1087: $r->print(&make_popwin(%rhash));
1.92 harris41 1088: $r->rflush();
1.125 matthew 1089: ##
1090: ## Prepare for the main loop below
1091: ##
1.93 harris41 1092: my $servercount=0;
1.98 harris41 1093: my $hitcountsum=0;
1.125 matthew 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) {
1.126 matthew 1105: # &Apache::lonnet::logthis("Server $rkey:".time);
1.93 harris41 1106: $servercount++;
1107: $compiledresult='';
1.92 harris41 1108: my $reply=$rhash{$rkey};
1.18 harris41 1109: my @results;
1.93 harris41 1110: if ($reply eq 'con_lost') {
1.125 matthew 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;
1.93 harris41 1118: $reply=~/(.*?)\_/;
1.126 matthew 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;
1.127 matthew 1139: my $hits =@results;
1.126 matthew 1140: &popwin_js($r,'popwin.hc["'.$rkey.'"]='.
1.127 matthew 1141: $hits.';');
1142: $hitcountsum+=$hits;
1.126 matthew 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;");
1.93 harris41 1157: }
1.117 matthew 1158: &popwin_js($r,'popwin.document.whirly.'.
1159: 'src="/adm/lonIcons/lonanimend.gif";');
1.125 matthew 1160: } # end of if ($reply eq 'con_lost') else statement
1.126 matthew 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 {
1.101 harris41 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;
1.126 matthew 1179: %Fields = &parse_raw_result($result,$rkey);
1180: $Fields{'extrashow'}=$extrashow;
1.101 harris41 1181: if ($extrashow) {
1182: foreach my $field (@customfields) {
1183: my $value='';
1.126 matthew 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');
1.8 harris41 1193: <font size='-1'><INPUT TYPE="button" NAME="returnvalues" VALUE="SELECT"
1.126 matthew 1194: onClick="javascript:select_data('$titleesc','$Fields{'url'}')">
1.8 harris41 1195: </font>
1.98 harris41 1196: <br />
1197: END
1.115 harris41 1198: }
1.101 harris41 1199: if ($ENV{'form.catalogmode'} eq 'groupsearch') {
1200: $fnum+=0;
1.126 matthew 1201: $hash{"pre_${fnum}_link"}=$Fields{'url'};
1202: $hash{"pre_${fnum}_title"}=$Fields{'title'};
1.101 harris41 1203: $compiledresult.=<<END;
1.118 www 1204: <font size='-1'>
1205: <input type="checkbox" name="returnvalues" value="SELECT"
1.98 harris41 1206: onClick="javascript:queue($fnum)" />
1207: </font>
1208: <br />
1.8 harris41 1209: END
1.101 harris41 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') {
1.126 matthew 1215: $compiledresult.=&detailed_citation_view
1216: (%Fields, hostname => $rkey );
1.101 harris41 1217: }
1218: elsif ($viewselect eq 'Summary View') {
1.126 matthew 1219: $compiledresult.=&summary_view
1220: (%Fields, hostname => $rkey );
1.101 harris41 1221: }
1222: elsif ($viewselect eq 'Fielded Format') {
1.126 matthew 1223: $compiledresult.=&fielded_format_view
1224: (%Fields, hostname => $rkey );
1.101 harris41 1225: }
1226: elsif ($viewselect eq 'XML/SGML') {
1.126 matthew 1227: $compiledresult.=&xml_sgml_view
1228: (%Fields, hostname => $rkey );
1.101 harris41 1229: }
1.130 ! matthew 1230: if ($compiledresult or $servercount!=$servernum) {
! 1231: $compiledresult.="<hr align='left' width='200' noshade />";
! 1232: }
1.101 harris41 1233: }
1234: untie %hash;
1.18 harris41 1235: }
1.93 harris41 1236: if ($compiledresult) {
1237: $resultflag=1;
1.126 matthew 1238: $r->print($compiledresult);
1.18 harris41 1239: }
1.93 harris41 1240: my $percent=sprintf('%3.0f',($servercount/$servernum*100));
1.126 matthew 1241: } # End of foreach loop over servers remaining
1242: } # End of big loop - while($serversleft && $timeremain)
1.93 harris41 1243: unless ($resultflag) {
1244: $r->print("\nThere were no results that matched your query\n");
1.43 harris41 1245: }
1.100 harris41 1246: # $r->print('<script type="text/javascript">'.'popwin.close()</script>'."\n"); $r->rflush();
1.126 matthew 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);
1.41 harris41 1372: }
1373:
1.122 matthew 1374: ######################################################################
1375: ######################################################################
1376:
1.125 matthew 1377: =pod
1378:
1379: =item &search_results_header
1380:
1.130 ! matthew 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
1.126 matthew 1391:
1.130 ! matthew 1392: The following environment variables are checked:
1.126 matthew 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:
1.125 matthew 1410: =cut
1411:
1412: ######################################################################
1413: ######################################################################
1414: sub search_results_header {
1.130 ! matthew 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: }
1.125 matthew 1423: my $result = '';
1424: # output beginning of search page
1425: $result.=<<BEGINNING;
1426: <html>
1427: <head>
1.130 ! matthew 1428: <title>$title</title>
1.125 matthew 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
1.130 ! matthew 1511: $result.=<<END;
! 1512: </head>
! 1513: <body bgcolor="#ffffff">
! 1514: <img align=right src=/adm/lonIcons/lonlogos.gif>
! 1515: <h1>$title</h1>
! 1516: END
1.125 matthew 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;
1.127 matthew 1558: $grid.=" domain=".$Apache::lonnet::hostdom{$sk};
1559: $grid.=" IP=".$Apache::lonnet::hostip{$sk};
1.125 matthew 1560: # '+"'"+'">'+
1561: $grid.="'+\"'\"+')\">'+";
1562: $grid.="\n";
1.127 matthew 1563: $grid.="'<img border=\"0\" name=\"img_".$Apache::lonnet::hostdom{$sk}.
1564: '_'.$sk."\" src=\"/adm/lonIcons/srvnull.gif\" alt=\"".$sk.
1565: "\" /></a>'+\n";
1.125 matthew 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:
1.122 matthew 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,
1.126 matthew 1626: last revision date, owner, copyright, hostname, and
1.122 matthew 1627: extra custom metadata to show.
1628:
1629: =over 4
1630:
1631: =item &detailed_citation_view()
1632:
1633: =cut
1634:
1635: ######################################################################
1636: ######################################################################
1.50 harris41 1637: sub detailed_citation_view {
1.126 matthew 1638: my %values = @_;
1.50 harris41 1639: my $result=<<END;
1.126 matthew 1640: <h3><a href="http://$ENV{'HTTP_HOST'}$values{'url'}"
1641: target='search_preview'>$values{'title'}</a></h3>
1.56 harris41 1642: <p>
1.130 ! matthew 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 />
1.78 harris41 1651: </p>
1.126 matthew 1652: $values{'extrashow'}
1.78 harris41 1653: <p>
1.126 matthew 1654: $values{'shortabstract'}
1.50 harris41 1655: </p>
1656: END
1657: return $result;
1658: }
1659:
1.122 matthew 1660: ######################################################################
1661: ######################################################################
1662:
1663: =pod
1664:
1665: =item &summary_view()
1666:
1667: =cut
1668:
1669: ######################################################################
1670: ######################################################################
1.50 harris41 1671: sub summary_view {
1.126 matthew 1672: my %values = @_;
1.50 harris41 1673: my $result=<<END;
1.126 matthew 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'}
1.50 harris41 1680: </p>
1681: END
1682: return $result;
1683: }
1684:
1.122 matthew 1685: ######################################################################
1686: ######################################################################
1687:
1688: =pod
1689:
1690: =item &fielded_format_view()
1691:
1692: =cut
1693:
1694: ######################################################################
1695: ######################################################################
1.50 harris41 1696: sub fielded_format_view {
1.126 matthew 1697: my %values = @_;
1.50 harris41 1698: my $result=<<END;
1.126 matthew 1699: <b>URL: </b> <a href="http://$ENV{'HTTP_HOST'}$values{'url'}"
1700: target='search_preview'>$values{'url'}</a>
1.56 harris41 1701: <br />
1.126 matthew 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'}
1.50 harris41 1716: </p>
1717: END
1718: return $result;
1719: }
1720:
1.122 matthew 1721: ######################################################################
1722: ######################################################################
1723:
1724: =pod
1725:
1726: =item &xml_sgml_view()
1727:
1728: =back
1729:
1730: =cut
1731:
1732: ######################################################################
1733: ######################################################################
1.50 harris41 1734: sub xml_sgml_view {
1.126 matthew 1735: my %values = @_;
1.50 harris41 1736: my $result=<<END;
1.56 harris41 1737: <pre>
1738: <LonCapaResource>
1.126 matthew 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>
1.56 harris41 1745: <mimeInfo>
1.126 matthew 1746: <mime>$values{'mime'}</mime>
1747: <mimetag>$values{'mimetag'}</mimetag>
1.56 harris41 1748: </mimeInfo>
1749: <languageInfo>
1.126 matthew 1750: <language>$values{'lang'}</language>
1751: <languagetag>$values{'language'}</languagetag>
1.56 harris41 1752: </languageInfo>
1.126 matthew 1753: <creationdate>$values{'creationdate'}</creationdate>
1754: <lastrevisiondate>$values{'lastrevisiondate'}</lastrevisiondate>
1755: <owner>$values{'owner'}</owner>
1.56 harris41 1756: <copyrightInfo>
1.126 matthew 1757: <copyright>$values{'copyright'}</copyright>
1758: <copyrighttag>$values{'copyrighttag'}</copyrighttag>
1.56 harris41 1759: </copyrightInfo>
1.126 matthew 1760: <repositoryLocation>$values{'hostname'}</repositoryLocation>
1761: <shortabstract>$values{'shortabstract'}</shortabstract>
1.57 harris41 1762: </LonCapaResource>
1.56 harris41 1763: </pre>
1.126 matthew 1764: $values{'extrashow'}
1.50 harris41 1765: END
1766: return $result;
1.60 harris41 1767: }
1768:
1.122 matthew 1769: ######################################################################
1770: ######################################################################
1771:
1772: =pod
1773:
1774: =item &filled() see if field is filled.
1775:
1776: =cut
1777:
1778: ######################################################################
1779: ######################################################################
1.98 harris41 1780: sub filled {
1781: my ($field)=@_;
1782: if ($field=~/\S/ && $field ne 'any') {
1783: return 1;
1.61 harris41 1784: }
1.98 harris41 1785: else {
1786: return 0;
1.61 harris41 1787: }
1.60 harris41 1788: }
1789:
1.122 matthew 1790: ######################################################################
1791: ######################################################################
1792:
1793: =pod
1794:
1795: =item &output_blank_field_error()
1796:
1797: =cut
1798:
1799: ######################################################################
1800: ######################################################################
1.98 harris41 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:
1.122 matthew 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: ######################################################################
1.60 harris41 1847: sub output_date_error {
1848: my ($r,$message)=@_;
1849: # make query information persistent to allow for subsequent revision
1.65 harris41 1850: my $persistent=&make_persistent();
1.60 harris41 1851:
1.122 matthew 1852: $r->print(<<RESULTS);
1.60 harris41 1853: <html>
1854: <head>
1855: <title>The LearningOnline Network with CAPA</title>
1856: </head>
1857: <body bgcolor="#ffffff">
1.98 harris41 1858: <img align='right' src='/adm/lonIcons/lonlogos.gif' />
1.60 harris41 1859: <h1>Search Catalog</h1>
1860: <form method="post" action="/adm/searchcat">
1861: $persistent
1862: <input type='button' value='Revise search request'
1.98 harris41 1863: onClick='this.form.submit();' />
1.60 harris41 1864: $closebutton
1.98 harris41 1865: <hr />
1.60 harris41 1866: <h3>Helpful Message</h3>
1867: <p>
1868: $message
1869: </p>
1870: </body>
1871: </html>
1872: RESULTS
1.101 harris41 1873: }
1874:
1.122 matthew 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: ######################################################################
1.101 harris41 1889: sub start_fresh_session {
1890: delete $hash{'mode_catalog'};
1.109 harris41 1891: foreach (keys %hash) {
1.101 harris41 1892: if ($_ =~ /^pre_/) {
1893: delete $hash{$_};
1894: }
1895: if ($_ =~ /^store/) {
1896: delete $hash{$_};
1897: }
1.109 harris41 1898: }
1.3 harris41 1899: }
1.117 matthew 1900:
1.122 matthew 1901: ######################################################################
1902: ######################################################################
1903:
1904: =pod
1905:
1906: =item &popwin_js() send javascript to popwin
1907:
1908: =cut
1909:
1910: ######################################################################
1911: ######################################################################
1.117 matthew 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:
1.122 matthew 1926: ######################################################################
1927: ######################################################################
1928:
1929: =pod
1930:
1931: =item &popwin_imgupdate()
1932:
1.125 matthew 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:
1.122 matthew 1936: =cut
1937:
1938: ######################################################################
1939: ######################################################################
1.117 matthew 1940: sub popwin_imgupdate {
1.125 matthew 1941: my ($r,$server,$icon) = @_;
1.127 matthew 1942: &popwin_js($r,'popwin.document.img_'.$Apache::lonnet::hostdom{$server}.
1943: '_'.$server.'.'.'src="/adm/lonIcons/'.$icon.'";');
1.117 matthew 1944: }
1.1 www 1945:
1946: 1;
1.98 harris41 1947:
1.1 www 1948: __END__
1.105 harris41 1949:
1.121 matthew 1950: =pod
1.105 harris41 1951:
1.121 matthew 1952: =back
1.105 harris41 1953:
1954: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>