Annotation of loncom/interface/lonsearchcat.pm, revision 1.129
1.98 harris41 1: # The LearningOnline Network with CAPA
1.108 harris41 2: # Search Catalog
3: #
1.129 ! matthew 4: # $Id: lonsearchcat.pm,v 1.128 2002/06/24 16:45:22 harris41 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
226: return &basicsearch($r,\%ENV,$hidden);
227: } elsif ($ENV{'form.advancedsubmit'} eq 'SEARCH') {
228: # Perform advanced search and give results
229: return &advancedsearch($r,\%ENV,$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: }
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
293: <!-- basic view selection -->
294: <select name='basicviewselect'>
295: <option value='Detailed Citation View' selected="true">
296: Detailed Citation View</option>
297: <option value='Summary View'>Summary View</option>
298: <option value='Fielded Format'>Fielded Format</option>
299: <option value='XML/SGML'>XML/SGML</option>
300: </select>
301: <!-- end of basic view selection -->
302: <input type="button" value="HELP" onClick="openhelp()" />
303: </p>
304: </form>
305: </body>
306: </html>
307: ENDDOCUMENT
308: return $scrout;
309: }
310: ######################################################################
311: ######################################################################
312:
313: =pod
314:
315: =item &advanced_search_form()
316:
317: Returns a scalar which holds html for the advanced search form.
318:
319: =cut
320:
321: ######################################################################
322: ######################################################################
323:
324: sub advanced_search_form{
325: my ($closebutton,$hidden) = @_;
1.129 ! matthew 326: my $advanced_buttons = <<"END";
! 327: <p>
! 328: <input type="submit" name="advancedsubmit" value='SEARCH' />
! 329: <input type="reset" name="reset" value='RESET' />
! 330: $closebutton
! 331: <!-- advance view select -->
! 332: <select name='advancedviewselect'>
! 333: <option value='Detailed Citation View' selected="true">
! 334: Detailed Citation View</option>
! 335: <option value='Summary View'>Summary View</option>
! 336: <option value='Fielded Format'>Fielded Format</option>
! 337: <option value='XML/SGML'>XML/SGML</option>
! 338: </select>
! 339: <!-- end of advanced view select -->
! 340: <input type="button" value="HELP" onClick="openhelp()" />
! 341: </p>
! 342: END
1.124 matthew 343: my $scrout=<<"ENDHEADER";
344: <html>
345: <head>
346: <title>The LearningOnline Network with CAPA</title>
347: <script type="text/javascript">
348: function openhelp(val) {
349: openhelpwin=open('/adm/help/searchcat.html','helpscreen',
350: 'scrollbars=1,width=600,height=300');
351: openhelpwin.focus();
1.18 harris41 352: }
1.124 matthew 353: </script>
354: </head>
355: <body bgcolor="#FFFFFF">
356: <img align='right' src='/adm/lonIcons/lonlogos.gif' />
1.129 ! matthew 357: <h1>Advanced Catalog Search</h1>
! 358: <hr />
! 359: Enter terms or quoted phrases separated by search operators
! 360: such as AND, OR, or NOT.<br />
! 361: $advanced_buttons
1.124 matthew 362: $hidden
1.129 ! matthew 363: <table>
1.124 matthew 364: ENDHEADER
1.129 ! matthew 365: $scrout.=&searchphrasefield('title','title',
1.11 harris41 366: $ENV{'form.title'});
1.129 ! matthew 367: $scrout.=&searchphrasefield('author','author',
1.11 harris41 368: $ENV{'form.author'});
1.129 ! matthew 369: $scrout.=&searchphrasefield('subject','subject',
1.11 harris41 370: $ENV{'form.subject'});
1.129 ! matthew 371: $scrout.=&searchphrasefield('keywords','keywords',
1.11 harris41 372: $ENV{'form.keywords'});
1.129 ! matthew 373: $scrout.=&searchphrasefield('URL','url',
1.11 harris41 374: $ENV{'form.url'});
1.96 harris41 375: # $scrout.=&searchphrasefield('Limit by version','version',
376: # $ENV{'form.version'});
1.129 ! matthew 377: $scrout.=&searchphrasefield('notes','notes',
1.11 harris41 378: $ENV{'form.notes'});
1.129 ! matthew 379: $scrout.=&searchphrasefield('abstract','abstract',
1.11 harris41 380: $ENV{'form.abstract'});
1.129 ! matthew 381: # Hack - an empty table row.
! 382: $scrout.="<tr><td> </td><td> </td></tr>\n";
! 383: $scrout.=&searchphrasefield('file<br />extension','mime',
! 384: $ENV{'form.mime'});
! 385: $scrout.="<tr><td> </td><td> </td></tr>\n";
! 386: $scrout.=&searchphrasefield('publisher<br />owner','owner',
! 387: $ENV{'form.owner'});
! 388: $scrout.="</table>\n";
! 389: # $ENV{'form.mime'}='any' unless length($ENV{'form.mime'});
! 390: # $scrout.=&selectbox('Limit by MIME type','mime',
! 391: # $ENV{'form.mime'},
! 392: # 'any','Any type',
! 393: # \&{Apache::loncommon::filedescriptionex},
! 394: # (&Apache::loncommon::fileextensions));
1.11 harris41 395: $ENV{'form.language'}='any' unless length($ENV{'form.language'});
1.3 harris41 396: $scrout.=&selectbox('Limit by language','language',
1.111 harris41 397: $ENV{'form.language'},'any','Any Language',
398: \&{Apache::loncommon::languagedescription},
399: (&Apache::loncommon::languageids),
400: );
1.8 harris41 401: # ------------------------------------------------ Compute date selection boxes
402: $scrout.=<<CREATIONDATESTART;
1.3 harris41 403: <p>
404: <font color="#800000" face="helvetica"><b>LIMIT BY CREATION DATE RANGE:</b>
405: </font>
1.98 harris41 406: <br />
1.8 harris41 407: between:
408: CREATIONDATESTART
1.11 harris41 409: $scrout.=&dateboxes('creationdatestart',1,1,1976,
410: $ENV{'form.creationdatestart_month'},
411: $ENV{'form.creationdatestart_day'},
412: $ENV{'form.creationdatestart_year'},
413: );
1.124 matthew 414: $scrout.="and:\n";
1.11 harris41 415: $scrout.=&dateboxes('creationdateend',12,31,2051,
416: $ENV{'form.creationdateend_month'},
417: $ENV{'form.creationdateend_day'},
418: $ENV{'form.creationdateend_year'},
419: );
1.8 harris41 420: $scrout.="</p>";
421: $scrout.=<<LASTREVISIONDATESTART;
422: <p>
423: <font color="#800000" face="helvetica"><b>LIMIT BY LAST REVISION DATE RANGE:
424: </b></font>
1.98 harris41 425: <br />between:
1.8 harris41 426: LASTREVISIONDATESTART
1.11 harris41 427: $scrout.=&dateboxes('lastrevisiondatestart',1,1,1976,
428: $ENV{'form.lastrevisiondatestart_month'},
429: $ENV{'form.lastrevisiondatestart_day'},
430: $ENV{'form.lastrevisiondatestart_year'},
431: );
1.8 harris41 432: $scrout.=<<LASTREVISIONDATEEND;
433: and:
434: LASTREVISIONDATEEND
1.11 harris41 435: $scrout.=&dateboxes('lastrevisiondateend',12,31,2051,
436: $ENV{'form.lastrevisiondateend_month'},
437: $ENV{'form.lastrevisiondateend_day'},
438: $ENV{'form.lastrevisiondateend_year'},
439: );
1.8 harris41 440: $scrout.='</p>';
1.11 harris41 441: $ENV{'form.copyright'}='any' unless length($ENV{'form.copyright'});
1.8 harris41 442: $scrout.=&selectbox('Limit by copyright/distribution','copyright',
1.111 harris41 443: $ENV{'form.copyright'},
444: 'any','Any copyright/distribution',
445: \&{Apache::loncommon::copyrightdescription},
446: (&Apache::loncommon::copyrightids),
447: );
1.14 harris41 448: # ------------------------------------------- Compute customized metadata field
449: $scrout.=<<CUSTOMMETADATA;
450: <p>
1.77 harris41 451: <font color="#800000" face="helvetica"><b>LIMIT BY SPECIAL METADATA FIELDS:</b>
1.14 harris41 452: </font>
1.77 harris41 453: For resource-specific metadata, enter in an expression in the form of
1.100 harris41 454: <i>key</i>=<i>value</i> separated by operators such as AND, OR or NOT.<br />
1.14 harris41 455: <b>Example:</b> grandmother=75 OR grandfather=85
1.98 harris41 456: <br />
1.14 harris41 457: CUSTOMMETADATA
1.124 matthew 458: $scrout.=&simpletextfield('custommetadata',$ENV{'form.custommetadata'});
1.77 harris41 459: $scrout.=<<CUSTOMSHOW;
460: <p>
461: <font color="#800000" face="helvetica"><b>SHOW SPECIAL METADATA FIELDS:</b>
462: </font>
463: Enter in a space-separated list of special metadata fields to show
464: in a fielded listing for each record result.
1.98 harris41 465: <br />
1.77 harris41 466: CUSTOMSHOW
1.124 matthew 467: $scrout.=&simpletextfield('customshow',$ENV{'form.customshow'});
468: $scrout.=<<ENDDOCUMENT;
1.129 ! matthew 469: $advanced_buttons
1.8 harris41 470: </form>
471: </body>
472: </html>
473: ENDDOCUMENT
1.124 matthew 474: return $scrout;
475: }
1.8 harris41 476:
1.121 matthew 477: ######################################################################
478: ######################################################################
479:
480: =pod
481:
482: =item &make_persistent()
483:
484: Returns a scalar which holds the current ENV{'form.*'} values in
1.126 matthew 485: a 'hidden' html input tag. This allows search interface information
486: to be somewhat persistent.
1.122 matthew 487:
1.121 matthew 488: =cut
489:
490: ######################################################################
491: ######################################################################
492:
1.98 harris41 493: sub make_persistent {
494: my $persistent='';
1.109 harris41 495: foreach (keys %ENV) {
1.98 harris41 496: if (/^form\./ && !/submit/) {
497: my $name=$_;
498: my $key=$name;
499: $ENV{$key}=~s/\'//g; # do not mess with html field syntax
500: $name=~s/^form\.//;
501: $persistent.=<<END;
1.125 matthew 502: <input type="hidden" name="$name" value="$ENV{$key}" />
1.98 harris41 503: END
504: }
1.109 harris41 505: }
1.98 harris41 506: return $persistent;
507: }
508:
1.122 matthew 509:
510: ######################################################################
511: ######################################################################
512:
513: =pod
514:
515: =item HTML form building functions
516:
517: =over 4
518:
519: =item &simpletextfield()
520:
521: Inputs: $name,$value,$size
522:
523: Returns a text input field with the given name, value, and size.
524: If size is not specified, a value of 20 is used.
525:
526: =item &simplecheckbox()
527:
528: Inputs: $name,$value
529:
530: Returns a simple check box with the given $name.
531: If $value eq 'on' the box is checked.
532:
533: =item &searchphrasefield()
534:
535: Inputs: $title,$name,$value
536:
537: Returns html for a title line and an input field for entering search terms.
538: the instructions "Enter terms or phrases separated by search operators such
539: as AND, OR, or NOT." are given following the title. The entry field (which
540: is where the $name and $value are used) is an 80 column simpletextfield.
541:
542: =item &dateboxes()
543:
1.126 matthew 544: Returns html selection form elements for the specification of
545: the day, month, and year.
546:
1.122 matthew 547: =item &selectbox()
548:
1.129 ! matthew 549: Returns a scalar containing an html <select> form.
! 550:
! 551: Inputs:
! 552:
! 553: =over 4
! 554:
! 555: =item $title
! 556:
! 557: Printed above the select box, in uppercase.
! 558:
! 559: =item $name
! 560:
! 561: The name element of the <select> tag.
! 562:
! 563: =item $default
! 564:
! 565: The default value of the form. Can be $anyvalue or in @idlist.
! 566:
! 567: =item $anyvalue
! 568:
! 569: The <option value="..."> used to indicate a default of
! 570: none of the values.
! 571:
! 572: =item $anytag
! 573:
! 574: The text associate with $anyvalue above.
! 575:
! 576: =item $functionref
! 577:
! 578: Each element in @idlist will be passed as a parameter
! 579: to the function referenced here. The return value of the function should
! 580: be a scalar description of the items. If this value is undefined the
! 581: description of each item in @idlist will be the item name.
! 582:
! 583: =item @idlist
! 584:
! 585: The items to be selected from. One of these or $anyvalue will be the
! 586: value returned by the form element, $ENV{form.$name}.
! 587:
! 588: =back
1.126 matthew 589:
1.122 matthew 590: =back
591:
592: =cut
593:
594: ######################################################################
595: ######################################################################
1.8 harris41 596:
1.11 harris41 597: sub simpletextfield {
1.122 matthew 598: my ($name,$value,$size)=@_;
599: $size = 20 if (! defined($size));
600: return '<input type="text" name="'.$name.
601: '" size="'.$size.'" value="'.$value.'" />';
1.11 harris41 602: }
603:
604: sub simplecheckbox {
605: my ($name,$value)=@_;
606: my $checked='';
1.129 ! matthew 607: $checked="checked" if $value eq 'on';
1.122 matthew 608: return '<input type="checkbox" name="'.$name.'" '. $checked . ' />';
1.11 harris41 609: }
610:
1.8 harris41 611: sub searchphrasefield {
612: my ($title,$name,$value)=@_;
613: my $uctitle=uc($title);
1.129 ! matthew 614: return '<tr><td><font color="#800000" face="helvetica">'.
! 615: '<b>'.$uctitle.': </b></font></td><td>'.
! 616: &simpletextfield($name,$value,50)."</td></tr>\n";
1.8 harris41 617: }
1.3 harris41 618:
1.8 harris41 619: sub dateboxes {
1.11 harris41 620: my ($name,$defaultmonth,$defaultday,$defaultyear,
621: $currentmonth,$currentday,$currentyear)=@_;
622: ($defaultmonth,$defaultday,$defaultyear)=('','','');
1.117 matthew 623: #
624: # Day
625: my $day=<<END;
626: <select name="${name}_day">
627: <option value='$defaultday'> </option>
628: END
629: for (my $i = 1; $i<=31; $i++) {
630: $day.="<option value=\"$i\">$i</option>\n";
631: }
632: $day.="</select>\n";
633: $day=~s/(\"$currentday\")/$1 SELECTED/ if length($currentday);
634: #
635: # Month
1.11 harris41 636: my $month=<<END;
1.8 harris41 637: <select name="${name}_month">
1.11 harris41 638: <option value='$defaultmonth'> </option>
639: END
1.117 matthew 640: my $i = 1;
641: foreach (qw/January February March April May June
642: July August September October November December /){
643: $month .="<option value=\"$i\">$_</option>\n";
644: $i++;
645: }
646: $month.="</select>\n";
1.11 harris41 647: $month=~s/(\"$currentmonth\")/$1 SELECTED/ if length($currentmonth);
1.117 matthew 648: #
649: # Year (obviously)
1.11 harris41 650: my $year=<<END;
1.8 harris41 651: <select name="${name}_year">
1.11 harris41 652: <option value='$defaultyear'> </option>
1.3 harris41 653: END
1.117 matthew 654: my $maxyear = 2051;
655: for (my $i = 1976; $i<=$maxyear; $i++) {
656: $year.="<option value=\"$i\">$i</option>\n";
657: }
658: $year.="</select>\n";
1.11 harris41 659: $year=~s/(\"$currentyear\")/$1 SELECTED/ if length($currentyear);
660: return "$month$day$year";
1.3 harris41 661: }
662:
663: sub selectbox {
1.129 ! matthew 664: my ($title,$name,$default,$anyvalue,$anytag,$functionref,@idlist)=@_;
! 665: if (! defined($functionref)) { $functionref = sub { $_[0]}; }
1.3 harris41 666: my $uctitle=uc($title);
1.122 matthew 667: my $selout="\n".'<p><font color="#800000" face="helvetica">'.
668: '<b>'.$uctitle.':</b></font><br /><select name="'.$name.'">';
1.111 harris41 669: foreach ($anyvalue,@idlist) {
1.122 matthew 670: $selout.='<option value="'.$_.'"';
1.129 ! matthew 671: if ($_ eq $default and !/^any$/) {
1.122 matthew 672: $selout.=' selected >'.&{$functionref}($_).'</option>';
1.111 harris41 673: }
1.129 ! matthew 674: elsif ($_ eq $default and /^$anyvalue$/) {
1.122 matthew 675: $selout.=' selected >'.$anytag.'</option>';
1.111 harris41 676: }
677: else {$selout.='>'.&{$functionref}($_).'</option>';}
1.109 harris41 678: }
1.129 ! matthew 679: return $selout.'</select></p>';
1.6 harris41 680: }
681:
1.122 matthew 682: ######################################################################
683: ######################################################################
684:
685: =pod
686:
1.126 matthew 687: =item &advancedsearch()
688:
689: Parse advanced search results.
1.122 matthew 690:
691: =cut
692:
693: ######################################################################
694: ######################################################################
1.18 harris41 695: sub advancedsearch {
1.124 matthew 696: my ($r,$envhash,$hidden)=@_;
1.18 harris41 697: my %ENV=%{$envhash};
1.32 harris41 698: my $fillflag=0;
1.64 harris41 699: # Clean up fields for safety
700: for my $field ('title','author','subject','keywords','url','version',
701: 'creationdatestart_month','creationdatestart_day',
702: 'creationdatestart_year','creationdateend_month',
703: 'creationdateend_day','creationdateend_year',
704: 'lastrevisiondatestart_month','lastrevisiondatestart_day',
705: 'lastrevisiondatestart_year','lastrevisiondateend_month',
706: 'lastrevisiondateend_day','lastrevisiondateend_year',
707: 'notes','abstract','mime','language','owner',
1.77 harris41 708: 'custommetadata','customshow') {
1.101 harris41 709: $ENV{"form.$field"}=~s/[^\w\/\s\(\)\=\-\"\']//g;
1.64 harris41 710: }
1.117 matthew 711: foreach ('mode','form','element') {
712: # is this required? Hmmm.
713: next unless (exists($ENV{"form.$_"}));
714: $ENV{"form.$_"}=&Apache::lonnet::unescape($ENV{"form.$_"});
715: $ENV{"form.$_"}=~s/[^\w\/\s\(\)\=\-\"\']//g;
716: }
1.90 harris41 717: # Check to see if enough information was filled in
1.32 harris41 718: for my $field ('title','author','subject','keywords','url','version',
719: 'notes','abstract','mime','language','owner',
720: 'custommetadata') {
1.40 harris41 721: if (&filled($ENV{"form.$field"})) {
1.32 harris41 722: $fillflag++;
723: }
724: }
725: unless ($fillflag) {
726: &output_blank_field_error($r);
727: return OK;
728: }
1.90 harris41 729: # Turn the form input into a SQL-based query
1.39 harris41 730: my $query='';
1.45 harris41 731: my @queries;
1.90 harris41 732: # Evaluate logical expression AND/OR/NOT phrase fields.
1.58 harris41 733: foreach my $field ('title','author','subject','notes','abstract','url',
1.129 ! matthew 734: 'keywords','version','owner','mime') {
1.44 harris41 735: if ($ENV{'form.'.$field}) {
1.45 harris41 736: push @queries,&build_SQL_query($field,$ENV{'form.'.$field});
1.44 harris41 737: }
738: }
1.90 harris41 739: # Evaluate option lists
1.58 harris41 740: if ($ENV{'form.language'} and $ENV{'form.language'} ne 'any') {
1.90 harris41 741: push @queries,"(language like \"$ENV{'form.language'}\")";
1.58 harris41 742: }
1.129 ! matthew 743: # if ($ENV{'form.mime'} and $ENV{'form.mime'} ne 'any') {
! 744: # push @queries,"(mime like \"$ENV{'form.mime'}\")";
! 745: # }
1.58 harris41 746: if ($ENV{'form.copyright'} and $ENV{'form.copyright'} ne 'any') {
1.90 harris41 747: push @queries,"(copyright like \"$ENV{'form.copyright'}\")";
1.58 harris41 748: }
1.90 harris41 749: # Evaluate date windows
1.60 harris41 750: my $datequery=&build_date_queries(
751: $ENV{'form.creationdatestart_month'},
752: $ENV{'form.creationdatestart_day'},
753: $ENV{'form.creationdatestart_year'},
754: $ENV{'form.creationdateend_month'},
755: $ENV{'form.creationdateend_day'},
756: $ENV{'form.creationdateend_year'},
757: $ENV{'form.lastrevisiondatestart_month'},
758: $ENV{'form.lastrevisiondatestart_day'},
759: $ENV{'form.lastrevisiondatestart_year'},
760: $ENV{'form.lastrevisiondateend_month'},
761: $ENV{'form.lastrevisiondateend_day'},
762: $ENV{'form.lastrevisiondateend_year'},
763: );
1.90 harris41 764: # Test to see if date windows are legitimate
1.61 harris41 765: if ($datequery=~/^Incorrect/) {
766: &output_date_error($r,$datequery);
767: return OK;
768: }
769: elsif ($datequery) {
1.60 harris41 770: push @queries,$datequery;
771: }
1.90 harris41 772: # Process form information for custom metadata querying
1.76 harris41 773: my $customquery='';
1.64 harris41 774: if ($ENV{'form.custommetadata'}) {
775: $customquery=&build_custommetadata_query('custommetadata',
776: $ENV{'form.custommetadata'});
777: }
1.83 harris41 778: my $customshow='';
779: if ($ENV{'form.customshow'}) {
780: $customshow=$ENV{'form.customshow'};
781: $customshow=~s/[^\w\s]//g;
782: my @fields=split(/\s+/,$customshow);
783: $customshow=join(" ",@fields);
784: }
1.90 harris41 785: # Send query statements over the network to be processed by either the SQL
786: # database or a recursive scheme of 'grep'-like actions (for custom
787: # metadata).
1.45 harris41 788: if (@queries) {
1.58 harris41 789: $query=join(" AND ",@queries);
1.46 harris41 790: $query="select * from metadata where $query";
1.90 harris41 791: my $reply; # reply hash reference
1.83 harris41 792: unless ($customquery or $customshow) {
1.76 harris41 793: $reply=&Apache::lonnet::metadata_query($query);
794: }
795: else {
1.83 harris41 796: $reply=&Apache::lonnet::metadata_query($query,
797: $customquery,$customshow);
1.76 harris41 798: }
1.124 matthew 799: &output_results('Advanced',$r,$envhash,$customquery,$reply,$hidden);
1.126 matthew 800: return OK;
801: } elsif ($customquery) {
1.90 harris41 802: my $reply; # reply hash reference
1.86 harris41 803: $reply=&Apache::lonnet::metadata_query('',
804: $customquery,$customshow);
1.124 matthew 805: &output_results('Advanced',$r,$envhash,$customquery,$reply,$hidden);
1.126 matthew 806: return OK;
1.45 harris41 807: }
1.92 harris41 808: # should not get to this point
809: return 'Error. Should not have gone to this point.';
1.18 harris41 810: }
811:
1.122 matthew 812: ######################################################################
813: ######################################################################
814:
815: =pod
816:
817: =item &basicsearch()
818:
1.126 matthew 819: Parse basic search form.
820:
1.122 matthew 821: =cut
822:
823: ######################################################################
824: ######################################################################
1.6 harris41 825: sub basicsearch {
1.124 matthew 826: my ($r,$envhash,$hidden)=@_;
1.19 harris41 827: my %ENV=%{$envhash};
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.124 matthew 860: &output_results('Basic',$r,$envhash,$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.124 matthew 1052: my ($mode,$r,$envhash,$query,$replyref,$hidden)=@_;
1.19 harris41 1053: my %ENV=%{$envhash};
1.92 harris41 1054: my %rhash=%{$replyref};
1.44 harris41 1055: my $compiledresult='';
1.125 matthew 1056: my $timeremain=300; # (seconds)
1.98 harris41 1057: my $elapsetime=0;
1.93 harris41 1058: my $resultflag=0;
1059: my $tflag=1;
1.125 matthew 1060: #
1.93 harris41 1061: # make query information persistent to allow for subsequent revision
1062: my $persistent=&make_persistent();
1.125 matthew 1063: # spit out the generic header
1064: $r->print(&search_results_header());
1.98 harris41 1065: $r->rflush();
1066: # begin showing the cataloged results
1.92 harris41 1067: $r->print(<<CATALOGBEGIN);
1068: </head>
1069: <body bgcolor="#ffffff">
1070: <img align=right src=/adm/lonIcons/lonlogos.gif>
1071: <h1>Search Catalog</h1>
1072: CATALOGBEGIN
1.129 ! matthew 1073: my $action = "/adm/searchcat";
! 1074: if ($mode eq 'Basic') {
! 1075: $action .= "?reqinterface=basic";
! 1076: } elsif ($mode eq 'Advanced') {
! 1077: $action .= "?reqinterface=advanced";
! 1078: }
! 1079: $r->print(<<CATALOGCONTROLS);
! 1080: <form name='results' method="post" action="$action">
1.118 www 1081: $hidden
1.98 harris41 1082: <input type='hidden' name='acts' value='' />
1.93 harris41 1083: <input type='button' value='Revise search request'
1.98 harris41 1084: onClick='this.form.submit();' />
1085: $importbutton
1.93 harris41 1086: $closebutton
1087: $persistent
1.98 harris41 1088: <hr />
1.93 harris41 1089: <h3>Search Query</h3>
1.98 harris41 1090: CATALOGCONTROLS
1.125 matthew 1091: #
1092: # Remind them what they searched for
1093: #
1.93 harris41 1094: if ($mode eq 'Basic') {
1.125 matthew 1095: $r->print('<p><b>Basic search:</b> '.$ENV{'form.basicexp'}.'</p>');
1096: } elsif ($mode eq 'Advanced') {
1097: $r->print('<p><b>Advanced search</b> '.$query.'</p>');
1.93 harris41 1098: }
1099: $r->print('<h3>Search Results</h3>');
1.92 harris41 1100: $r->rflush();
1.125 matthew 1101: #
1102: # make the pop-up window for status
1103: #
1104: $r->print(&make_popwin(%rhash));
1.92 harris41 1105: $r->rflush();
1.125 matthew 1106: ##
1107: ## Prepare for the main loop below
1108: ##
1.93 harris41 1109: my $servercount=0;
1.98 harris41 1110: my $hitcountsum=0;
1.125 matthew 1111: my $servernum=(keys %rhash);
1112: my $serversleft=$servernum;
1113: ##
1114: ## Run until we run out of time or we run out of servers
1115: ##
1116: while($serversleft && $timeremain) {
1117: ##
1118: ## %rhash has servers deleted from it as results come in
1119: ## (within the foreach loop below).
1120: ##
1121: foreach my $rkey (sort keys %rhash) {
1.126 matthew 1122: # &Apache::lonnet::logthis("Server $rkey:".time);
1.93 harris41 1123: $servercount++;
1124: $compiledresult='';
1.92 harris41 1125: my $reply=$rhash{$rkey};
1.18 harris41 1126: my @results;
1.93 harris41 1127: if ($reply eq 'con_lost') {
1.125 matthew 1128: &popwin_imgupdate($r,$rkey,"srvbad.gif");
1129: $serversleft--;
1130: delete $rhash{$rkey};
1131: } else {
1132: # must do since 'use strict' checks for tainting
1133: $reply=~/^([\.\w]+)$/;
1134: my $replyfile=$r->dir_config('lonDaemons').'/tmp/'.$1;
1.93 harris41 1135: $reply=~/(.*?)\_/;
1.126 matthew 1136: for (my $counter=0;$counter<2;$counter++) {
1137: if (-e $replyfile && ! -e "$replyfile.end") {
1138: &popwin_imgupdate($r,$rkey,"srvhalf.gif");
1139: &popwin_js($r,'popwin.hc["'.$rkey.'"]='.
1140: '"still transferring..."'.';');
1141: }
1142: # Are we finished transferring data?
1143: if (-e "$replyfile.end") {
1144: $serversleft--;
1145: delete $rhash{$rkey};
1146: if (-s $replyfile) {
1147: &popwin_imgupdate($r,$rkey,"srvgood.gif");
1148: my $fh;
1149: unless ($fh=Apache::File->new($replyfile)){
1150: # Is it really appropriate to die on this error?
1151: $r->print('ERROR: file '.
1152: $replyfile.' cannot be opened');
1153: return OK;
1154: }
1155: @results=<$fh> if $fh;
1.127 matthew 1156: my $hits =@results;
1.126 matthew 1157: &popwin_js($r,'popwin.hc["'.$rkey.'"]='.
1.127 matthew 1158: $hits.';');
1159: $hitcountsum+=$hits;
1.126 matthew 1160: &popwin_js($r,'popwin.document.forms.popremain.'.
1161: 'numhits.value='.$hitcountsum.';');
1162: } else {
1163: &popwin_imgupdate($r,$rkey,"srvempty.gif");
1164: &popwin_js($r,'popwin.hc["'.$rkey.'"]=0;');
1165: }
1166: last;
1167: } # end of if ( -e "$replyfile.end")
1168: last unless $timeremain;
1169: sleep 1; # wait for daemons to write files?
1170: $timeremain--;
1171: $elapsetime++;
1172: &popwin_js($r,"popwin.document.popremain.".
1173: "elapsetime.value=$elapsetime;");
1.93 harris41 1174: }
1.117 matthew 1175: &popwin_js($r,'popwin.document.whirly.'.
1176: 'src="/adm/lonIcons/lonanimend.gif";');
1.125 matthew 1177: } # end of if ($reply eq 'con_lost') else statement
1.126 matthew 1178: my %Fields = undef; # Holds the data to be sent to the various
1179: # *_view routines.
1180: my ($extrashow,$customfields,$customhash) = &handle_custom_fields(\@results);
1181: my @customfields = @$customfields;
1182: my %customhash = %$customhash;
1183: untie %hash if (keys %hash);
1184: #
1185: if (! tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) {
1186: $r->print('<html><head></head><body>Unable to tie hash to db '.
1187: 'file</body></html>');
1188: } else {
1.101 harris41 1189: if ($ENV{'form.launch'} eq '1') {
1190: &start_fresh_session();
1191: }
1192: foreach my $result (@results) {
1193: next if $result=~/^custom\=/;
1194: chomp $result;
1195: next unless $result;
1.126 matthew 1196: %Fields = &parse_raw_result($result,$rkey);
1197: $Fields{'extrashow'}=$extrashow;
1.101 harris41 1198: if ($extrashow) {
1199: foreach my $field (@customfields) {
1200: my $value='';
1.126 matthew 1201: $value = $1 if ($customhash{$Fields{'url'}}=~/\<{$field}[^\>]*\>(.*?)\<\/{$field}[^\>]*\>/s);
1202: $Fields{'extrashow'}=~s/\<\!\-\- $field \-\-\>/ $value/g;
1203: }
1204: }
1205: if ($compiledresult or $servercount!=$servernum) {
1206: $compiledresult.="<hr align='left' width='200' noshade />";
1.101 harris41 1207: }
1.126 matthew 1208: $compiledresult.="\n<p>\n";
1209: if ($ENV{'form.catalogmode'} eq 'interactive') {
1210: my $titleesc=$Fields{'title'};
1211: $titleesc=~s/\'/\\'/; # '
1212: $compiledresult.=<<END if ($ENV{'form.catalogmode'} eq 'interactive');
1.8 harris41 1213: <font size='-1'><INPUT TYPE="button" NAME="returnvalues" VALUE="SELECT"
1.126 matthew 1214: onClick="javascript:select_data('$titleesc','$Fields{'url'}')">
1.8 harris41 1215: </font>
1.98 harris41 1216: <br />
1217: END
1.115 harris41 1218: }
1.101 harris41 1219: if ($ENV{'form.catalogmode'} eq 'groupsearch') {
1220: $fnum+=0;
1.126 matthew 1221: $hash{"pre_${fnum}_link"}=$Fields{'url'};
1222: $hash{"pre_${fnum}_title"}=$Fields{'title'};
1.101 harris41 1223: $compiledresult.=<<END;
1.118 www 1224: <font size='-1'>
1225: <input type="checkbox" name="returnvalues" value="SELECT"
1.98 harris41 1226: onClick="javascript:queue($fnum)" />
1227: </font>
1228: <br />
1.8 harris41 1229: END
1.101 harris41 1230: # <input type="hidden" name="title$fnum" value="$title" />
1231: # <input type="hidden" name="url$fnum" value="$url" />
1232: $fnum++;
1233: }
1234: my $viewselect;
1235: if ($mode eq 'Basic') {
1236: $viewselect=$ENV{'form.basicviewselect'};
1237: }
1238: elsif ($mode eq 'Advanced') {
1239: $viewselect=$ENV{'form.advancedviewselect'};
1240: }
1241: if ($viewselect eq 'Detailed Citation View') {
1.126 matthew 1242: $compiledresult.=&detailed_citation_view
1243: (%Fields, hostname => $rkey );
1.101 harris41 1244: }
1245: elsif ($viewselect eq 'Summary View') {
1.126 matthew 1246: $compiledresult.=&summary_view
1247: (%Fields, hostname => $rkey );
1.101 harris41 1248: }
1249: elsif ($viewselect eq 'Fielded Format') {
1.126 matthew 1250: $compiledresult.=&fielded_format_view
1251: (%Fields, hostname => $rkey );
1.101 harris41 1252: }
1253: elsif ($viewselect eq 'XML/SGML') {
1.126 matthew 1254: $compiledresult.=&xml_sgml_view
1255: (%Fields, hostname => $rkey );
1.101 harris41 1256: }
1257: }
1258: untie %hash;
1.18 harris41 1259: }
1.93 harris41 1260: if ($compiledresult) {
1261: $resultflag=1;
1.126 matthew 1262: $r->print($compiledresult);
1.18 harris41 1263: }
1.93 harris41 1264: my $percent=sprintf('%3.0f',($servercount/$servernum*100));
1.126 matthew 1265: } # End of foreach loop over servers remaining
1266: } # End of big loop - while($serversleft && $timeremain)
1.93 harris41 1267: unless ($resultflag) {
1268: $r->print("\nThere were no results that matched your query\n");
1.43 harris41 1269: }
1.100 harris41 1270: # $r->print('<script type="text/javascript">'.'popwin.close()</script>'."\n"); $r->rflush();
1.126 matthew 1271: $r->print("</body>\n</html>\n");
1272: return;
1273: }
1274:
1275: ###########################################################
1276: ###########################################################
1277:
1278: =pod
1279:
1280: =item &parse_raw_result()
1281:
1282: Takes a line from the file of results and parse it. Returns a hash
1283: with keys for the following fields:
1284: 'title', 'author', 'subject', 'url', 'keywords', 'version', 'notes',
1285: 'abstract', 'mime', 'lang', 'owner', 'copyright', 'creationdate',
1286: 'lastrevisiondate'.
1287:
1288: In addition, the following tags are set by calling the appropriate
1289: lonnet function: 'language', 'cprtag', 'mimetag'.
1290:
1291: The 'title' field is set to "Untitled" if the title field is blank.
1292:
1293: 'abstract' and 'keywords' are truncated to 200 characters.
1294:
1295: =cut
1296:
1297: ###########################################################
1298: ###########################################################
1299: sub parse_raw_result {
1300: my ($result,$hostname) = @_;
1301: # Check for a comma - if it is there then we do not need to unescape the
1302: # string. There seems to be some kind of problem with some items in
1303: # the database - the entire string gets sent out unescaped...?
1304: unless ($result =~ /,/) {
1305: $result = &Apache::lonnet::unescape($result);
1306: }
1307: my @fields=map {
1308: &Apache::lonnet::unescape($_);
1309: } (split(/\,/,$result));
1310: my ($title,$author,$subject,$url,$keywords,$version,
1311: $notes,$abstract,$mime,$lang,
1312: $creationdate,$lastrevisiondate,$owner,$copyright)=@fields;
1313: my %Fields =
1314: ( title => &Apache::lonnet::unescape($title),
1315: author => &Apache::lonnet::unescape($author),
1316: subject => &Apache::lonnet::unescape($subject),
1317: url => &Apache::lonnet::unescape($url),
1318: keywords => &Apache::lonnet::unescape($keywords),
1319: version => &Apache::lonnet::unescape($version),
1320: notes => &Apache::lonnet::unescape($notes),
1321: abstract => &Apache::lonnet::unescape($abstract),
1322: mime => &Apache::lonnet::unescape($mime),
1323: lang => &Apache::lonnet::unescape($lang),
1324: owner => &Apache::lonnet::unescape($owner),
1325: copyright => &Apache::lonnet::unescape($copyright),
1326: creationdate => &Apache::lonnet::unescape($creationdate),
1327: lastrevisiondate => &Apache::lonnet::unescape($lastrevisiondate)
1328: );
1329: $Fields{'language'} =
1330: &Apache::loncommon::languagedescription($Fields{'lang'});
1331: $Fields{'copyrighttag'} =
1332: &Apache::loncommon::copyrightdescription($Fields{'copyright'});
1333: $Fields{'mimetag'} =
1334: &Apache::loncommon::filedescription($Fields{'mime'});
1335: # Put spaces in the keyword list, if needed.
1336: $Fields{'keywords'}=~ s/,([A-z])/, $1/g;
1337: if ($Fields{'title'}=~ /^\s*$/ ) {
1338: $Fields{'title'}='Untitled';
1339: }
1340: unless ($ENV{'user.adv'}) {
1341: $Fields{'keywords'} = '- not displayed -';
1342: $Fields{'notes'} = '- not displayed -';
1343: $Fields{'abstract'} = '- not displayed -';
1344: $Fields{'subject'} = '- not displayed -';
1345: }
1346: if (length($Fields{'abstract'})>200) {
1347: $Fields{'abstract'} =
1348: substr($Fields{'abstract'},0,200).'...';
1349: }
1350: if (length($Fields{'keywords'})>200) {
1351: $Fields{'keywords'} =
1352: substr($Fields{'keywords'},0,200).'...';
1353: }
1354: return %Fields;
1355: }
1356:
1357: ###########################################################
1358: ###########################################################
1359:
1360: =pod
1361:
1362: =item &handle_custom_fields()
1363:
1364: =cut
1365:
1366: ###########################################################
1367: ###########################################################
1368: sub handle_custom_fields {
1369: my @results = @{shift()};
1370: my $customshow='';
1371: my $extrashow='';
1372: my @customfields;
1373: if ($ENV{'form.customshow'}) {
1374: $customshow=$ENV{'form.customshow'};
1375: $customshow=~s/[^\w\s]//g;
1376: my @fields=map {
1377: "<font color=\"#008000\">$_:</font><!-- $_ -->";
1378: } split(/\s+/,$customshow);
1379: @customfields=split(/\s+/,$customshow);
1380: if ($customshow) {
1381: $extrashow="<ul><li>".join("</li><li>",@fields)."</li></ul>\n";
1382: }
1383: }
1384: my $customdata='';
1385: my %customhash;
1386: foreach my $result (@results) {
1387: if ($result=~/^(custom\=.*)$/) { # grab all custom metadata
1388: my $tmp=$result;
1389: $tmp=~s/^custom\=//;
1390: my ($k,$v)=map {&Apache::lonnet::unescape($_);
1391: } split(/\,/,$tmp);
1392: $customhash{$k}=$v;
1393: }
1394: }
1395: return ($extrashow,\@customfields,\%customhash);
1.41 harris41 1396: }
1397:
1.122 matthew 1398: ######################################################################
1399: ######################################################################
1400:
1.125 matthew 1401: =pod
1402:
1403: =item &search_results_header
1404:
1.126 matthew 1405: Output the proper javascript code to deal with different calling modes.
1406:
1407: Takes inputs directly from from %ENV. The following environment variables
1408: are checked:
1409:
1410: =over 4
1411:
1412: =item 'form.catalogmode'
1413:
1414: Checked for 'interactive' and 'groupsearch'.
1415:
1416: =item 'form.mode'
1417:
1418: Checked for existance & 'edit' mode.
1419:
1420: =item 'form.form'
1421:
1422: =item 'form.element'
1423:
1424: =back
1425:
1.125 matthew 1426: =cut
1427:
1428: ######################################################################
1429: ######################################################################
1430: sub search_results_header {
1431: my $result = '';
1432: # output beginning of search page
1433: $result.=<<BEGINNING;
1434: <html>
1435: <head>
1436: <title>The LearningOnline Network with CAPA</title>
1437: BEGINNING
1438: # conditional output of script functions dependent on the mode in
1439: # which the search was invoked
1440: if ($ENV{'form.catalogmode'} eq 'interactive'){
1441: if (! exists($ENV{'form.mode'}) || $ENV{'form.mode'} ne 'edit') {
1442: $result.=<<SCRIPT;
1443: <script type="text/javascript">
1444: function select_data(title,url) {
1445: changeTitle(title);
1446: changeURL(url);
1447: self.close();
1448: }
1449: function changeTitle(val) {
1450: if (opener.inf.document.forms.resinfo.elements.t) {
1451: opener.inf.document.forms.resinfo.elements.t.value=val;
1452: }
1453: }
1454: function changeURL(val) {
1455: if (opener.inf.document.forms.resinfo.elements.u) {
1456: opener.inf.document.forms.resinfo.elements.u.value=val;
1457: }
1458: }
1459: </script>
1460: SCRIPT
1461: } elsif ($ENV{'form.mode'} eq 'edit') {
1462: my $form = $ENV{'form.form'};
1463: my $element = $ENV{'form.element'};
1464: $result.=<<SCRIPT;
1465: <script type="text/javascript">
1466: function select_data(title,url) {
1467: changeURL(url);
1468: self.close();
1469: }
1470: function changeTitle(val) {
1471: }
1472: function changeURL(val) {
1473: if (window.opener.document) {
1474: window.opener.document.forms["$form"].elements["$element"].value=val;
1475: } else {
1476: var url = 'forms[\"$form\"].elements[\"$element\"].value';
1477: alert("Unable to transfer data to "+url);
1478: }
1479: }
1480: </script>
1481: SCRIPT
1482: }
1483: }
1484: $result.=<<SCRIPT if $ENV{'form.catalogmode'} eq 'groupsearch';
1485: <script type="text/javascript">
1486: function select_data(title,url) {
1487: // alert('DEBUG: Should be storing '+title+' and '+url);
1488: }
1489: function queue(val) {
1490: if (eval("document.forms.results.returnvalues["+val+"].checked")) {
1491: document.forms.results.acts.value+='1a'+val+'b';
1492: }
1493: else {
1494: document.forms.results.acts.value+='0a'+val+'b';
1495: }
1496: }
1497: function select_group() {
1498: window.location=
1499: "/adm/groupsort?mode=$ENV{'form.mode'}&catalogmode=groupsearch&acts="+
1500: document.forms.results.acts.value;
1501: }
1502: </script>
1503: SCRIPT
1504: $result.=<<SCRIPT;
1505: <script type="text/javascript">
1506: function displayinfo(val) {
1507: popwin.document.forms.popremain.sdetails.value=val;
1508: }
1509: function openhelp(val) {
1510: openhelpwin=open('/adm/help/searchcat.html','helpscreen',
1511: 'scrollbars=1,width=400,height=300');
1512: openhelpwin.focus();
1513: }
1514: function abortsearch(val) {
1515: popwin.close();
1516: }
1517: </script>
1518: SCRIPT
1519: return $result;
1520: }
1521:
1522: ######################################################################
1523: ######################################################################
1524:
1525: =pod
1526:
1527: =item &make_popwin()
1528:
1529: Returns html with javascript in it to open up the status window.
1530:
1531: =cut
1532:
1533: ######################################################################
1534: ######################################################################
1535: sub make_popwin {
1536: my %rhash = @_;
1537: my $servernum=(keys %rhash);
1538: my $hcinit;
1539: my $grid="'<br />'+\n";
1540: # $sn is the server number, used ONLY to make sure we have
1541: # rows of 10 each. No longer used to index images.
1542: my $sn=1;
1543: foreach my $sk (sort keys %rhash) {
1544: # '<a href="
1545: $grid.="'<a href=\"";
1546: # javascript:displayinfo('+
1547: $grid.="javascript:opener.displayinfo('+";
1548: # "'"+'key
1549: $grid.="\"'\"+'";
1550: $grid.=$sk;
1551: my $hc;
1552: if ($rhash{$sk} eq 'con_lost') {
1553: $hc="BAD CONNECTION, CONTACT SYSTEM ADMINISTRATOR ";
1554: }
1555: else {
1556: $hc="'+\"'\"+\"+hc['$sk']+\"+\"'\"+'";
1557: $hcinit.="hc[\"$sk\"]=\"not yet connected...\";";
1558: }
1559: $grid.=" hitcount=".$hc;
1.127 matthew 1560: $grid.=" domain=".$Apache::lonnet::hostdom{$sk};
1561: $grid.=" IP=".$Apache::lonnet::hostip{$sk};
1.125 matthew 1562: # '+"'"+'">'+
1563: $grid.="'+\"'\"+')\">'+";
1564: $grid.="\n";
1.127 matthew 1565: $grid.="'<img border=\"0\" name=\"img_".$Apache::lonnet::hostdom{$sk}.
1566: '_'.$sk."\" src=\"/adm/lonIcons/srvnull.gif\" alt=\"".$sk.
1567: "\" /></a>'+\n";
1.125 matthew 1568: $grid.="'<br />'+\n" unless $sn%10;
1569: $sn++;
1570: }
1571: my $result.=<<ENDPOP;
1572: <script type="text/javascript">
1573: popwin=open('','popwin','scrollbars=1,width=400,height=220');
1574: popwin.focus();
1575: popwin.document.writeln('<'+'html>');
1576: popwin.document.writeln('<'+'head>');
1577: popwin.document.writeln('<'+'script>');
1578: popwin.document.writeln('hc=new Array();$hcinit');
1579: popwin.document.writeln('<'+'/script>');
1580: popwin.document.writeln('<'+'/head>'+
1581: '<'+'body bgcolor="#FFFFFF">'+
1582: '<'+'image name="whirly" align="right" src="/adm/lonIcons/'+
1583: 'lonanim.gif" '+
1584: 'alt="animated logo" />'+
1585: '<'+'h3>Search Results Progress<'+'/h3>'+
1586: '<'+'form name="popremain">'+
1587: '<'+'tt>'+
1588: '<'+'br clear="all"/><i>PLEASE BE PATIENT</i>'+
1589: '<'+'br />SCANNING $servernum SERVERS'+
1590: '<'+'br clear="all" />Number of record hits found '+
1591: '<'+'input type="text" size="10" name="numhits"'+
1592: ' value="0" />'+
1593: '<'+'br clear="all" />Time elapsed '+
1594: '<'+'input type="text" size="10" name="elapsetime"'+
1595: ' value="0" />'+
1596: '<'+'br />'+
1597: 'SERVER GRID (click on any cell for details)'+
1598: $grid
1599: '<'+'br />'+
1600: 'Server details '+
1601: '<'+'input type="text" size="35" name="sdetails"'+
1602: ' value="" />'+
1603: '<'+'br />'+
1604: ' <'+'input type="button" name="button"'+
1605: ' value="close this window" '+
1606: ' onClick="javascript:opener.abortsearch()" />'+
1607: ' <'+'input type="button" name="button"'+
1608: ' value="help" onClick="javascript:opener.openhelp()" />'+
1609: '<'+'/tt>'+
1610: '<'+'/form>'+
1611: '<'+'/body><'+'/html>');
1612: popwin.document.close();
1613: </script>
1614: ENDPOP
1615: return $result;
1616: }
1617:
1618: ######################################################################
1619: ######################################################################
1620:
1.122 matthew 1621: =pod
1622:
1623: =item Metadata Viewing Functions
1624:
1625: Output is a HTML-ified string.
1626: Input arguments are title, author, subject, url, keywords, version,
1627: notes, short abstract, mime, language, creation date,
1.126 matthew 1628: last revision date, owner, copyright, hostname, and
1.122 matthew 1629: extra custom metadata to show.
1630:
1631: =over 4
1632:
1633: =item &detailed_citation_view()
1634:
1635: =cut
1636:
1637: ######################################################################
1638: ######################################################################
1.50 harris41 1639: sub detailed_citation_view {
1.126 matthew 1640: my %values = @_;
1.50 harris41 1641: my $result=<<END;
1.126 matthew 1642: <i>$values{'owner'}</i>, last revised $values{'lastrevisiondate'}
1643: <h3><a href="http://$ENV{'HTTP_HOST'}$values{'url'}"
1644: target='search_preview'>$values{'title'}</a></h3>
1645: <h3>$values{'author'}</h3>
1.56 harris41 1646: </p>
1647: <p>
1.126 matthew 1648: <b>Subject:</b> $values{'subject'}<br />
1649: <b>Keyword(s):</b> $values{'keywords'}<br />
1650: <b>Notes:</b> $values{'notes'}<br />
1.111 harris41 1651: <b>MIME Type:</b>
1652: END
1.126 matthew 1653: $result.=&Apache::loncommon::filedescription($values{'mime'});
1.111 harris41 1654: $result.=<<END;
1655: <br />
1656: <b>Language:</b>
1657: END
1.126 matthew 1658: $result.=&Apache::loncommon::languagedescription($values{'lang'});
1.111 harris41 1659: $result.=<<END;
1660: <br />
1661: <b>Copyright/Distribution:</b>
1662: END
1.126 matthew 1663: $result.=&Apache::loncommon::copyrightdescription($values{'copyright'});
1.111 harris41 1664: $result.=<<END;
1665: <br />
1.78 harris41 1666: </p>
1.126 matthew 1667: $values{'extrashow'}
1.78 harris41 1668: <p>
1.126 matthew 1669: $values{'shortabstract'}
1.50 harris41 1670: </p>
1671: END
1672: return $result;
1673: }
1674:
1.122 matthew 1675: ######################################################################
1676: ######################################################################
1677:
1678: =pod
1679:
1680: =item &summary_view()
1681:
1682: =cut
1683:
1684: ######################################################################
1685: ######################################################################
1.50 harris41 1686: sub summary_view {
1.126 matthew 1687: my %values = @_;
1.50 harris41 1688: my $result=<<END;
1.126 matthew 1689: <a href="http://$ENV{'HTTP_HOST'}$values{'url'}"
1690: target='search_preview'>$values{'author'}</a><br />
1691: $values{'title'}<br />
1692: $values{'owner'} -- $values{'lastrevisiondate'}<br />
1693: $values{'copyrighttag'}<br />
1694: $values{'extrashow'}
1.50 harris41 1695: </p>
1696: END
1697: return $result;
1698: }
1699:
1.122 matthew 1700: ######################################################################
1701: ######################################################################
1702:
1703: =pod
1704:
1705: =item &fielded_format_view()
1706:
1707: =cut
1708:
1709: ######################################################################
1710: ######################################################################
1.50 harris41 1711: sub fielded_format_view {
1.126 matthew 1712: my %values = @_;
1.50 harris41 1713: my $result=<<END;
1.126 matthew 1714: <b>URL: </b> <a href="http://$ENV{'HTTP_HOST'}$values{'url'}"
1715: target='search_preview'>$values{'url'}</a>
1.56 harris41 1716: <br />
1.126 matthew 1717: <b>Title:</b> $values{'title'}<br />
1718: <b>Author(s):</b> $values{'author'}<br />
1719: <b>Subject:</b> $values{'subject'}<br />
1720: <b>Keyword(s):</b> $values{'keywords'}<br />
1721: <b>Notes:</b> $values{'notes'}<br />
1722: <b>MIME Type:</b> $values{'mimetag'}<br />
1723: <b>Language:</b> $values{'language'}<br />
1724: <b>Creation Date:</b> $values{'creationdate'}<br />
1725: <b>Last Revision Date:</b> $values{'lastrevisiondate'}<br />
1726: <b>Publisher/Owner:</b> $values{'owner'}<br />
1727: <b>Copyright/Distribution:</b> $values{'copyrighttag'}<br />
1728: <b>Repository Location:</b> $values{'hostname'}<br />
1729: <b>Abstract:</b> $values{'shortabstract'}<br />
1730: $values{'extrashow'}
1.50 harris41 1731: </p>
1732: END
1733: return $result;
1734: }
1735:
1.122 matthew 1736: ######################################################################
1737: ######################################################################
1738:
1739: =pod
1740:
1741: =item &xml_sgml_view()
1742:
1743: =back
1744:
1745: =cut
1746:
1747: ######################################################################
1748: ######################################################################
1.50 harris41 1749: sub xml_sgml_view {
1.126 matthew 1750: my %values = @_;
1.50 harris41 1751: my $result=<<END;
1.56 harris41 1752: <pre>
1753: <LonCapaResource>
1.126 matthew 1754: <url>$values{'url'}</url>
1755: <title>$values{'title'}</title>
1756: <author>$values{'author'}</author>
1757: <subject>$values{'subject'}</subject>
1758: <keywords>$values{'keywords'}</keywords>
1759: <notes>$values{'notes'}</notes>
1.56 harris41 1760: <mimeInfo>
1.126 matthew 1761: <mime>$values{'mime'}</mime>
1762: <mimetag>$values{'mimetag'}</mimetag>
1.56 harris41 1763: </mimeInfo>
1764: <languageInfo>
1.126 matthew 1765: <language>$values{'lang'}</language>
1766: <languagetag>$values{'language'}</languagetag>
1.56 harris41 1767: </languageInfo>
1.126 matthew 1768: <creationdate>$values{'creationdate'}</creationdate>
1769: <lastrevisiondate>$values{'lastrevisiondate'}</lastrevisiondate>
1770: <owner>$values{'owner'}</owner>
1.56 harris41 1771: <copyrightInfo>
1.126 matthew 1772: <copyright>$values{'copyright'}</copyright>
1773: <copyrighttag>$values{'copyrighttag'}</copyrighttag>
1.56 harris41 1774: </copyrightInfo>
1.126 matthew 1775: <repositoryLocation>$values{'hostname'}</repositoryLocation>
1776: <shortabstract>$values{'shortabstract'}</shortabstract>
1.57 harris41 1777: </LonCapaResource>
1.56 harris41 1778: </pre>
1.126 matthew 1779: $values{'extrashow'}
1.50 harris41 1780: END
1781: return $result;
1.60 harris41 1782: }
1783:
1.122 matthew 1784: ######################################################################
1785: ######################################################################
1786:
1787: =pod
1788:
1789: =item &filled() see if field is filled.
1790:
1791: =cut
1792:
1793: ######################################################################
1794: ######################################################################
1.98 harris41 1795: sub filled {
1796: my ($field)=@_;
1797: if ($field=~/\S/ && $field ne 'any') {
1798: return 1;
1.61 harris41 1799: }
1.98 harris41 1800: else {
1801: return 0;
1.61 harris41 1802: }
1.60 harris41 1803: }
1804:
1.122 matthew 1805: ######################################################################
1806: ######################################################################
1807:
1808: =pod
1809:
1810: =item &output_blank_field_error()
1811:
1812: =cut
1813:
1814: ######################################################################
1815: ######################################################################
1.98 harris41 1816: sub output_blank_field_error {
1817: my ($r)=@_;
1818: # make query information persistent to allow for subsequent revision
1819: my $persistent=&make_persistent();
1820:
1821: $r->print(<<BEGINNING);
1822: <html>
1823: <head>
1824: <title>The LearningOnline Network with CAPA</title>
1825: BEGINNING
1826: $r->print(<<RESULTS);
1827: </head>
1828: <body bgcolor="#ffffff">
1829: <img align='right' src='/adm/lonIcons/lonlogos.gif' />
1830: <h1>Search Catalog</h1>
1831: <form method="post" action="/adm/searchcat">
1832: $persistent
1833: <input type='button' value='Revise search request'
1834: onClick='this.form.submit();' />
1835: $closebutton
1836: <hr />
1837: <h3>Helpful Message</h3>
1838: <p>
1839: Incorrect search query due to blank entry fields.
1840: You need to fill in the relevant
1841: fields on the search page in order for a query to be
1842: processed.
1843: </p>
1844: </body>
1845: </html>
1846: RESULTS
1847: }
1848:
1.122 matthew 1849: ######################################################################
1850: ######################################################################
1851:
1852: =pod
1853:
1854: =item &output_date_error()
1855:
1856: Output a full html page with an error message.
1857:
1858: =cut
1859:
1860: ######################################################################
1861: ######################################################################
1.60 harris41 1862: sub output_date_error {
1863: my ($r,$message)=@_;
1864: # make query information persistent to allow for subsequent revision
1.65 harris41 1865: my $persistent=&make_persistent();
1.60 harris41 1866:
1.122 matthew 1867: $r->print(<<RESULTS);
1.60 harris41 1868: <html>
1869: <head>
1870: <title>The LearningOnline Network with CAPA</title>
1871: </head>
1872: <body bgcolor="#ffffff">
1.98 harris41 1873: <img align='right' src='/adm/lonIcons/lonlogos.gif' />
1.60 harris41 1874: <h1>Search Catalog</h1>
1875: <form method="post" action="/adm/searchcat">
1876: $persistent
1877: <input type='button' value='Revise search request'
1.98 harris41 1878: onClick='this.form.submit();' />
1.60 harris41 1879: $closebutton
1.98 harris41 1880: <hr />
1.60 harris41 1881: <h3>Helpful Message</h3>
1882: <p>
1883: $message
1884: </p>
1885: </body>
1886: </html>
1887: RESULTS
1.101 harris41 1888: }
1889:
1.122 matthew 1890: ######################################################################
1891: ######################################################################
1892:
1893: =pod
1894:
1895: =item &start_fresh_session()
1896:
1897: Cleans the global %hash by removing all fields which begin with
1898: 'pre_' or 'store'.
1899:
1900: =cut
1901:
1902: ######################################################################
1903: ######################################################################
1.101 harris41 1904: sub start_fresh_session {
1905: delete $hash{'mode_catalog'};
1.109 harris41 1906: foreach (keys %hash) {
1.101 harris41 1907: if ($_ =~ /^pre_/) {
1908: delete $hash{$_};
1909: }
1910: if ($_ =~ /^store/) {
1911: delete $hash{$_};
1912: }
1.109 harris41 1913: }
1.3 harris41 1914: }
1.117 matthew 1915:
1.122 matthew 1916: ######################################################################
1917: ######################################################################
1918:
1919: =pod
1920:
1921: =item &popwin_js() send javascript to popwin
1922:
1923: =cut
1924:
1925: ######################################################################
1926: ######################################################################
1.117 matthew 1927: sub popwin_js {
1928: # Print javascript out to popwin, but make sure we dont generate
1929: # any javascript errors in doing so.
1930: my ($r,$text) = @_;
1931: $r->print(<<"END");
1932: <script type="text/javascript">
1933: if (! popwin.closed) {
1934: $text
1935: }
1936: </script>
1937: END
1938: $r->rflush();
1939: }
1940:
1.122 matthew 1941: ######################################################################
1942: ######################################################################
1943:
1944: =pod
1945:
1946: =item &popwin_imgupdate()
1947:
1.125 matthew 1948: Send a given image (and its location) out to the browser. Takes as
1949: input $r, loncapa server id, and an icon URL.
1950:
1.122 matthew 1951: =cut
1952:
1953: ######################################################################
1954: ######################################################################
1.117 matthew 1955: sub popwin_imgupdate {
1.125 matthew 1956: my ($r,$server,$icon) = @_;
1.127 matthew 1957: &popwin_js($r,'popwin.document.img_'.$Apache::lonnet::hostdom{$server}.
1958: '_'.$server.'.'.'src="/adm/lonIcons/'.$icon.'";');
1.117 matthew 1959: }
1.1 www 1960:
1961: 1;
1.98 harris41 1962:
1.1 www 1963: __END__
1.105 harris41 1964:
1.121 matthew 1965: =pod
1.105 harris41 1966:
1.121 matthew 1967: =back
1.105 harris41 1968:
1969: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>