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