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