Annotation of loncom/interface/lonsearchcat.pm, revision 1.189
1.98 harris41 1: # The LearningOnline Network with CAPA
1.108 harris41 2: # Search Catalog
3: #
1.189 ! www 4: # $Id: lonsearchcat.pm,v 1.188 2003/09/29 15:28:40 www 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.121 matthew 28: ###############################################################################
29: ###############################################################################
30:
31: =pod
32:
33: =head1 NAME
34:
1.140 matthew 35: lonsearchcat - LONCAPA Search Interface
1.121 matthew 36:
37: =head1 SYNOPSIS
38:
39: Search interface to LON-CAPAs digital library
40:
41: =head1 DESCRIPTION
42:
43: This module enables searching for a distributed browseable catalog.
1.104 harris41 44:
1.121 matthew 45: This is part of the LearningOnline Network with CAPA project
46: described at http://www.lon-capa.org.
47:
48: lonsearchcat presents the user with an interface to search the LON-CAPA
49: digital library. lonsearchcat also initiates the execution of a search
50: by sending the search parameters to LON-CAPA servers. The progress of
51: search (on a server basis) is displayed to the user in a seperate window.
52:
53: =head1 Internals
54:
55: =over 4
56:
57: =cut
58:
59: ###############################################################################
1.98 harris41 60: ###############################################################################
1.121 matthew 61:
1.128 harris41 62: ###############################################################################
1.98 harris41 63: ## ##
64: ## ORGANIZATION OF THIS PERL MODULE ##
65: ## ##
1.105 harris41 66: ## 1. Modules used by this module ##
1.128 harris41 67: ## 2. Variables used throughout the module ##
68: ## 3. handler subroutine called via Apache and mod_perl ##
69: ## 4. Other subroutines ##
1.98 harris41 70: ## ##
71: ###############################################################################
72:
1.1 www 73: package Apache::lonsearchcat;
74:
1.98 harris41 75: # ------------------------------------------------- modules used by this module
1.1 www 76: use strict;
1.167 www 77: use Apache::Constants qw(:common :http);
1.6 harris41 78: use Apache::lonnet();
79: use Apache::File();
1.7 harris41 80: use CGI qw(:standard);
1.41 harris41 81: use Text::Query;
1.101 harris41 82: use GDBM_File;
1.112 harris41 83: use Apache::loncommon();
1.144 matthew 84: use Apache::lonmysql();
1.186 www 85: use Apache::lonlocal;
1.1 www 86:
1.90 harris41 87: # ---------------------------------------- variables used throughout the module
88:
1.121 matthew 89: ######################################################################
90: ######################################################################
91:
92: =pod
93:
94: =item Global variables
95:
96: =over 4
97:
98: =item $importbutton
99:
1.134 matthew 100: button to take the select results and go to group sorting
1.121 matthew 101:
1.142 matthew 102: =item %groupsearch_db
1.121 matthew 103:
1.142 matthew 104: Database hash used to save values for the groupsearch RAT interface.
1.121 matthew 105:
106: =item $diropendb
107:
108: The full path to the (temporary) search database file. This is set and
109: used in &handler() and is also used in &output_results().
110:
1.139 matthew 111: =item %Views
112:
113: Hash which associates an output view description with the function
114: that produces it. Adding a new view type should be as easy as
115: adding a line to the definition of this hash and making sure the function
116: takes the proper parameters.
117:
1.155 matthew 118: =item $bodytag
119:
120: LON-CAPA standard body tag, gotten from &Apache::lonnet::bodytag.
121: No title, no table, just a <body> tag.
122:
1.121 matthew 123: =back
124:
125: =cut
126:
127: ######################################################################
128: ######################################################################
129:
1.98 harris41 130: # -- dynamically rendered interface components
131: my $importbutton; # button to take the selected results and go to group sorting
132:
133: # -- miscellaneous variables
1.142 matthew 134: my %groupsearch_db; # database hash
1.127 matthew 135: my $diropendb = ""; # db file
1.139 matthew 136: # View Description Function Pointer
137: my %Views = ("Detailed Citation View" => \&detailed_citation_view,
138: "Summary View" => \&summary_view,
139: "Fielded Format" => \&fielded_format_view,
1.150 matthew 140: "XML/SGML" => \&xml_sgml_view,
141: "Compact View" => \&compact_view);
1.145 matthew 142: my %persistent_db;
143: my $hidden_fields;
1.155 matthew 144: my $bodytag;
145:
1.169 www 146: #
147: # For course search
148: #
1.167 www 149: my %alreadyseen;
150: my $hashtied;
151: my %hash;
1.169 www 152: my $totalfound;
1.167 www 153:
1.121 matthew 154: ######################################################################
155: ######################################################################
156:
157: =pod
158:
159: =item &handler() - main handler invoked by httpd child
160:
1.124 matthew 161: =item Variables
162:
163: =over 4
164:
165: =item $hidden
166:
167: holds 'hidden' html forms
168:
169: =item $scrout
170:
171: string that holds portions of the screen output
172:
173: =back
174:
1.121 matthew 175: =cut
1.101 harris41 176:
1.121 matthew 177: ######################################################################
178: ######################################################################
1.98 harris41 179: sub handler {
180: my $r = shift;
1.145 matthew 181: #
1.157 www 182:
183: my $loaderror=&Apache::lonnet::overloaderror($r);
184: if ($loaderror) { return $loaderror; }
185:
1.145 matthew 186: my $closebutton; # button that closes the search window
187: # This button is different for the RAT compared to
188: # normal invocation.
189: #
1.186 www 190: &Apache::loncommon::content_type($r,'text/html');
1.98 harris41 191: $r->send_http_header;
192: return OK if $r->header_only;
1.156 matthew 193: ##
194: ## Prevent caching of the search interface window. Hopefully this means
195: ## we will get the launch=1 passed in a little more.
196: &Apache::loncommon::no_cache($r);
1.145 matthew 197: ##
198: ## Pick up form fields passed in the links.
199: ##
200: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.146 matthew 201: ['catalogmode','launch','acts','mode','form','element','pause',
1.158 matthew 202: 'phase','persistent_db_id','table','start','show',
203: 'cleargroupsort']);
1.146 matthew 204: ##
205: ## The following is a trick - we wait a few seconds if asked to so
206: ## the daemon running the search can get ahead of the daemon
207: ## printing the results. We only need (theoretically) to do
208: ## this once, so the pause indicator is deleted
209: ##
210: if (exists($ENV{'form.pause'})) {
1.181 matthew 211: sleep(1);
1.146 matthew 212: delete($ENV{'form.pause'});
213: }
1.143 matthew 214: ##
215: ## Initialize global variables
216: ##
1.121 matthew 217: my $domain = $r->dir_config('lonDefDomain');
1.177 albertel 218: $diropendb= "/home/httpd/perl/tmp/$ENV{'user.domain'}_$ENV{'user.name'}_searchcat.db";
1.145 matthew 219: #
220: # set the name of the persistent database
1.146 matthew 221: # $ENV{'form.persistent_db_id'} can only have digits in it.
1.145 matthew 222: if (! exists($ENV{'form.persistent_db_id'}) ||
1.147 matthew 223: ($ENV{'form.persistent_db_id'} =~ /\D/) ||
224: ($ENV{'form.launch'} eq '1')) {
1.145 matthew 225: $ENV{'form.persistent_db_id'} = time;
226: }
1.155 matthew 227: $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1);
1.146 matthew 228: my $persistent_db_file = "/home/httpd/perl/tmp/".
1.145 matthew 229: &Apache::lonnet::escape($domain).
230: '_'.&Apache::lonnet::escape($ENV{'user.name'}).
231: '_'.$ENV{'form.persistent_db_id'}.'_persistent_search.db';
1.146 matthew 232: ##
1.152 matthew 233: if (! &get_persistent_form_data($persistent_db_file)) {
1.150 matthew 234: if ($ENV{'form.phase'} =~ /(run_search|results)/) {
235: &Apache::lonnet::logthis("lonsearchcat:Unable to recover data ".
236: "from $persistent_db_file");
237: $r->print(<<END);
238: <html>
239: <head><title>LON-CAPA Search Error</title></head>
1.155 matthew 240: $bodytag
1.150 matthew 241: We were unable to retrieve data describing your search. This is a serious
242: error and has been logged. Please alert your LON-CAPA administrator.
243: </body>
244: </html>
245: END
246: return OK;
247: }
1.147 matthew 248: }
1.124 matthew 249: ##
1.143 matthew 250: ## Clear out old values from groupsearch database
1.124 matthew 251: ##
1.146 matthew 252: untie %groupsearch_db if (tied(%groupsearch_db));
1.158 matthew 253: if (($ENV{'form.cleargroupsort'} eq '1') ||
254: (($ENV{'form.launch'} eq '1') &&
255: ($ENV{'form.catalogmode'} eq 'groupsearch'))) {
1.148 matthew 256: if (tie(%groupsearch_db,'GDBM_File',$diropendb,&GDBM_WRCREAT(),0640)) {
1.101 harris41 257: &start_fresh_session();
1.142 matthew 258: untie %groupsearch_db;
1.158 matthew 259: delete($ENV{'form.cleargroupsort'});
1.122 matthew 260: } else {
1.155 matthew 261: # This is a stupid error to give to the user.
262: # It really tells them nothing.
263: $r->print('<html><head></head>'.$bodytag.
264: 'Unable to tie hash to db file</body></html>');
1.101 harris41 265: return OK;
266: }
267: }
1.124 matthew 268: ##
1.150 matthew 269: ## Configure hidden fields
1.124 matthew 270: ##
1.145 matthew 271: $hidden_fields = '<input type="hidden" name="persistent_db_id" value="'.
1.150 matthew 272: $ENV{'form.persistent_db_id'}.'" />'."\n";
273: if (exists($ENV{'form.catalogmode'})) {
274: $hidden_fields .= '<input type="hidden" name="catalogmode" value="'.
275: $ENV{'form.catalogmode'}.'" />'."\n";
276: }
277: if (exists($ENV{'form.form'})) {
278: $hidden_fields .= '<input type="hidden" name="form" value="'.
279: $ENV{'form.form'}.'" />'."\n";
280: }
281: if (exists($ENV{'form.element'})) {
282: $hidden_fields .= '<input type="hidden" name="element" value="'.
283: $ENV{'form.element'}.'" />'."\n";
284: }
285: if (exists($ENV{'form.mode'})) {
286: $hidden_fields .= '<input type="hidden" name="mode" value="'.
287: $ENV{'form.mode'}.'" />'."\n";
288: }
289: ##
290: ## Configure dynamic components of interface
1.146 matthew 291: ##
1.98 harris41 292: if ($ENV{'form.catalogmode'} eq 'interactive') {
1.150 matthew 293: $closebutton="<input type='button' name='close' value='CLOSE' ";
294: if ($ENV{'form.phase'} =~ /(results|run_search)/) {
295: $closebutton .="onClick='parent.close()'";
296: } else {
297: $closebutton .="onClick='self.close()'";
298: }
299: $closebutton .=">\n";
1.124 matthew 300: } elsif ($ENV{'form.catalogmode'} eq 'groupsearch') {
1.150 matthew 301: $closebutton="<input type='button' name='close' value='CLOSE' ";
302: if ($ENV{'form.phase'} =~ /(results|run_search)/) {
303: $closebutton .="onClick='parent.close()'";
304: } else {
305: $closebutton .="onClick='self.close()'";
306: }
307: $closebutton .= ">";
1.98 harris41 308: $importbutton=<<END;
309: <input type='button' name='import' value='IMPORT'
310: onClick='javascript:select_group()'>
311: END
1.146 matthew 312: } else {
313: $closebutton = '';
314: $importbutton = '';
1.98 harris41 315: }
1.124 matthew 316: ##
1.146 matthew 317: ## Sanity checks on form elements
1.124 matthew 318: ##
1.146 matthew 319: if (!defined($ENV{'form.viewselect'})) {
1.150 matthew 320: if (($ENV{'form.catalogmode'} eq 'groupsearch') ||
321: ($ENV{'form.catalogmode'} eq 'interactive')) {
322: $ENV{'form.viewselect'} ="Compact View";
323: } else {
324: $ENV{'form.viewselect'} ="Detailed Citation View";
325: }
1.146 matthew 326: }
1.149 matthew 327: $ENV{'form.phase'} = 'disp_basic' if (! exists($ENV{'form.phase'}));
1.151 matthew 328: $ENV{'form.show'} = 20 if (! exists($ENV{'form.show'}));
1.146 matthew 329: ##
330: ## Switch on the phase
331: ##
332: if ($ENV{'form.phase'} eq 'disp_basic') {
333: &print_basic_search_form($r,$closebutton);
334: } elsif ($ENV{'form.phase'} eq 'disp_adv') {
335: &print_advanced_search_form($r,$closebutton);
336: } elsif ($ENV{'form.phase'} eq 'results') {
337: &display_results($r,$importbutton,$closebutton);
1.151 matthew 338: } elsif ($ENV{'form.phase'} =~ /^(sort|run_search)$/) {
1.146 matthew 339: my ($query,$customquery,$customshow,$libraries,$pretty_string) =
340: &get_persistent_data($persistent_db_file,
341: ['query','customquery','customshow',
342: 'libraries','pretty_string']);
1.151 matthew 343: if ($ENV{'form.phase'} eq 'sort') {
344: &print_sort_form($r,$pretty_string);
345: } elsif ($ENV{'form.phase'} eq 'run_search') {
346: &run_search($r,$query,$customquery,$customshow,
347: $libraries,$pretty_string);
348: }
1.167 www 349: } elsif ($ENV{'form.phase'} eq 'course_search') {
350: &course_search($r);
1.146 matthew 351: } elsif(($ENV{'form.phase'} eq 'basic_search') ||
352: ($ENV{'form.phase'} eq 'adv_search')) {
1.151 matthew 353: $ENV{'form.searchmode'} = 'basic';
354: if ($ENV{'form.phase'} eq 'adv_search') {
355: $ENV{'form.searchmode'} = 'advanced';
356: }
1.146 matthew 357: # Set up table
358: if (! defined(&create_results_table())) {
1.147 matthew 359: $r->print(<<END);
360: <html><head><title>Search Error</title></head>
1.155 matthew 361: $bodytag
1.147 matthew 362: Unable to create table in which to store search results.
363: The search has been aborted.
364: </body>
365: </html>
366: END
367: return OK;
1.146 matthew 368: }
1.147 matthew 369: delete($ENV{'form.launch'});
1.146 matthew 370: if (! &make_form_data_persistent($r,$persistent_db_file)) {
1.147 matthew 371: $r->print(<<END);
372: <html><head><title>Search Error</title></head>
1.155 matthew 373: $bodytag
1.147 matthew 374: Unable to properly store search information. The search has been aborted.
375: </body>
376: </html>
377: END
378: return OK;
1.146 matthew 379: }
1.145 matthew 380: #
1.139 matthew 381: # We are running a search
1.134 matthew 382: my ($query,$customquery,$customshow,$libraries) =
383: (undef,undef,undef,undef);
1.143 matthew 384: my $pretty_string;
1.146 matthew 385: if ($ENV{'form.phase'} eq 'basic_search') {
1.180 matthew 386: ($query,$pretty_string,$libraries) =
387: &parse_basic_search($r,$closebutton);
1.146 matthew 388: } else { # Advanced search
1.143 matthew 389: ($query,$customquery,$customshow,$libraries,$pretty_string)
1.145 matthew 390: = &parse_advanced_search($r,$closebutton);
1.134 matthew 391: return OK if (! defined($query));
392: }
1.152 matthew 393: &make_persistent({ query => $query,
1.146 matthew 394: customquery => $customquery,
395: customshow => $customshow,
396: libraries => $libraries,
397: pretty_string => $pretty_string },
398: $persistent_db_file);
1.145 matthew 399: ##
1.146 matthew 400: ## Print out the frames interface
1.145 matthew 401: ##
1.146 matthew 402: &print_frames_interface($r);
1.124 matthew 403: }
404: return OK;
405: }
1.98 harris41 406:
1.124 matthew 407: ######################################################################
408: ######################################################################
409:
1.167 www 410: sub course_search {
411: my $r=shift;
412: my $bodytag=&Apache::loncommon::bodytag('Course Search');
413: my $pretty_search_string = '<b>'.$ENV{'form.courseexp'}.'</b>';
414: my $search_string = $ENV{'form.courseexp'};
415: my @New_Words;
416: if ($ENV{'form.crsrelated'}) {
417: ($search_string,@New_Words) = &related_version($ENV{'form.courseexp'});
418: if (@New_Words) {
419: $pretty_search_string .= " with related words: <b>@New_Words</b>.";
420: } else {
421: $pretty_search_string .= " with no related words.";
422: }
423: }
424: my $fulltext=$ENV{'form.crsfulltext'};
425: my @allwords=($search_string,@New_Words);
1.169 www 426: $totalfound=0;
1.167 www 427: $r->print('<html><head><title>LON-CAPA Course Search</title></head>'.
428: $bodytag.$pretty_search_string);
429: $r->rflush();
430: # ======================================================= Go through the course
431: $hashtied=0;
432: undef %alreadyseen;
433: %alreadyseen=();
1.169 www 434: my $c=$r->connection;
1.167 www 435: &tiehash();
436: foreach (keys %hash) {
1.169 www 437: if ($c->aborted()) { last; }
1.167 www 438: if (($_=~/^src\_(.+)$/) && (!$alreadyseen{$hash{$_}})) {
1.168 www 439: &checkonthis($r,$hash{$_},0,$hash{'title_'.$1},$fulltext,@allwords);
1.167 www 440: }
441: }
442: &untiehash();
1.169 www 443: unless ($totalfound) {
1.187 www 444: $r->print('<p>'.&mt('No resources found').'.</p>');
1.169 www 445: }
1.167 www 446: # =================================================== Done going through course
447: $r->print('</body></html>');
448: }
449:
450: # ---------------------------------------------------------------- tie the hash
451:
452: sub tiehash {
453: $hashtied=0;
454: if ($ENV{'request.course.fn'}) {
455: if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
456: &GDBM_READER(),0640)) {
457: $hashtied=1;
458: }
459: }
460: }
461:
462: sub untiehash {
463: if ($hashtied) { untie %hash; }
464: $hashtied=0;
465: }
466:
467: # =============================== This pulls up a resource and its dependencies
468:
469: sub checkonthis {
1.168 www 470: my ($r,$url,$level,$title,$fulltext,@allwords)=@_;
1.167 www 471: $alreadyseen{$url}=1;
472: $r->rflush();
473: my $result=&Apache::lonnet::metadata($url,'title').' '.
474: &Apache::lonnet::metadata($url,'subject').' '.
475: &Apache::lonnet::metadata($url,'abstract').' '.
476: &Apache::lonnet::metadata($url,'keywords');
477: if (($url) && ($fulltext)) {
1.168 www 478: $result.=&Apache::lonnet::ssi_body($url);
1.167 www 479: }
480: $result=~s/\s+/ /gs;
481: my $applies=0;
482: foreach (@allwords) {
483: if ($_=~/\w/) {
484: if ($result=~/$_/si) {
485: $applies++;
486: }
487: }
488: }
489: # Does this resource apply?
490: if ($applies) {
491: $r->print('<br />');
492: for (my $i=0;$i<=$level*5;$i++) {
493: $r->print(' ');
494: }
495: $r->print('<a href="'.$url.'" target="cat">'.
1.169 www 496: ($title?$title:$url).'</a><br />');
497: $totalfound++;
498: } elsif ($fulltext) {
499: $r->print(' .');
1.167 www 500: }
1.169 www 501: $r->rflush();
1.167 www 502: # Check also the dependencies of this one
503: my $dependencies=
504: &Apache::lonnet::metadata($url,'dependencies');
505: foreach (split(/\,/,$dependencies)) {
506: if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {
1.168 www 507: &checkonthis($r,$_,$level+1,'',$fulltext,@allwords);
1.167 www 508: }
509: }
510: }
511:
512: ######################################################################
513: ######################################################################
514:
1.124 matthew 515: =pod
516:
1.146 matthew 517: =item &print_basic_search_form()
1.124 matthew 518:
519: Returns a scalar which holds html for the basic search form.
520:
521: =cut
522:
523: ######################################################################
524: ######################################################################
1.3 harris41 525:
1.146 matthew 526: sub print_basic_search_form{
527: my ($r,$closebutton) = @_;
1.167 www 528: my $bodytag=&Apache::loncommon::bodytag('Search');
1.124 matthew 529: my $scrout=<<"ENDDOCUMENT";
530: <html>
531: <head>
532: <title>The LearningOnline Network with CAPA</title>
533: <script type="text/javascript">
534: function openhelp(val) {
535: openhelpwin=open('/adm/help/searchcat.html','helpscreen',
536: 'scrollbars=1,width=600,height=300');
537: openhelpwin.focus();
1.6 harris41 538: }
1.124 matthew 539: </script>
540: </head>
1.154 www 541: $bodytag
1.167 www 542: ENDDOCUMENT
543: if (&Apache::lonnet::allowed('bre',$ENV{'request.role.domain'})) {
544: $scrout.=(<<ENDDOCUMENT);
545: <h1>Catalog Search</h1>
1.124 matthew 546: <form method="post" action="/adm/searchcat">
1.146 matthew 547: <input type="hidden" name="phase" value="basic_search" />
1.145 matthew 548: $hidden_fields
1.124 matthew 549: <p>
1.131 matthew 550: Enter terms or phrases separated by AND, OR, or NOT
1.129 matthew 551: then press SEARCH below.
1.124 matthew 552: </p>
553: <p>
554: <table>
555: <tr><td>
556: ENDDOCUMENT
557: $scrout.=' '.&simpletextfield('basicexp',$ENV{'form.basicexp'},40).
558: ' ';
1.180 matthew 559: my $relatedcheckbox = &simplecheckbox('related',$ENV{'form.related'});
560: my $domain = $r->dir_config('lonDefDomain');
1.184 matthew 561: my $domaincheckbox = &simplecheckbox('domains',$domain);
1.187 www 562: my $srch=&mt('Search');
563: my $header=&mt('Advanced Search');
1.139 matthew 564: $scrout.=<<END;
1.160 www 565: </td><td><a
566: href="/adm/searchcat?phase=disp_adv&catalogmode=$ENV{'form.catalogmode'}&launch=$ENV{'form.launch'}"
1.187 www 567: >$header</a></td></tr>
1.180 matthew 568: <tr><td>$relatedcheckbox use related words</td>
569: <td>$domaincheckbox only search domain <b>$domain</b></td></tr>
1.141 matthew 570: </table>
1.124 matthew 571: </p>
572: <p>
1.187 www 573: <input type="submit" name="basicsubmit" value='$srch' />
1.124 matthew 574: $closebutton
1.139 matthew 575: END
1.187 www 576: $scrout.=&selectbox('View','viewselect',
1.139 matthew 577: $ENV{'form.viewselect'},
578: undef,undef,undef,
579: sort(keys(%Views)));
1.188 www 580: $scrout.=&selectbox('Per Page','show',
1.151 matthew 581: $ENV{'form.show'},
582: undef,undef,undef,
583: (10,20,50,100));
1.139 matthew 584: $scrout.=<<ENDDOCUMENT;
1.124 matthew 585: </p>
586: </form>
1.167 www 587: ENDDOCUMENT
1.180 matthew 588: }
589: if ($ENV{'request.course.id'}) {
1.187 www 590: my %lt=&Apache::lonlocal::texthash(
591: 'srch' => 'Search',
592: 'header' => 'Course Search',
593: 'note' => 'Enter terms or phrases, then press "Search" below',
594: );
1.180 matthew 595: $scrout.=(<<ENDCOURSESEARCH);
596: <hr />
1.187 www 597: <h1>$lt{'header'}</h1>
1.167 www 598: <form method="post" action="/adm/searchcat">
599: <input type="hidden" name="phase" value="course_search" />
600: $hidden_fields
601: <p>
1.187 www 602: $lt{'note'}.
1.167 www 603: </p>
604: <p>
605: <table>
606: <tr><td>
607: ENDCOURSESEARCH
1.180 matthew 608: $scrout.=' '.
609: &simpletextfield('courseexp',$ENV{'form.courseexp'},40);
610: my $crscheckbox =
611: &simplecheckbox('crsfulltext',$ENV{'form.crsfulltext'});
612: my $relcheckbox =
613: &simplecheckbox('crsrelated',$ENV{'form.crsrelated'});
614: $scrout.=(<<ENDENDCOURSE);
1.167 www 615: </td></tr>
616: <tr><td>$relcheckbox use related words</td><td></td></tr>
617: <tr><td>$crscheckbox fulltext search (time consuming)</td><td></td></tr>
618: </table><p>
1.187 www 619: <input type="submit" name="coursesubmit" value='$lt{'srch'}' />
1.167 www 620: </p>
621: ENDENDCOURSE
1.180 matthew 622: }
1.167 www 623: $scrout.=(<<ENDDOCUMENT);
1.124 matthew 624: </body>
625: </html>
626: ENDDOCUMENT
1.146 matthew 627: $r->print($scrout);
628: return;
1.124 matthew 629: }
630: ######################################################################
631: ######################################################################
632:
633: =pod
634:
635: =item &advanced_search_form()
636:
637: Returns a scalar which holds html for the advanced search form.
638:
639: =cut
640:
641: ######################################################################
642: ######################################################################
643:
1.146 matthew 644: sub print_advanced_search_form{
645: my ($r,$closebutton) = @_;
1.129 matthew 646: my $advanced_buttons = <<"END";
647: <p>
648: <input type="submit" name="advancedsubmit" value='SEARCH' />
649: <input type="reset" name="reset" value='RESET' />
650: $closebutton
651: <input type="button" value="HELP" onClick="openhelp()" />
652: </p>
653: END
1.139 matthew 654: if (!defined($ENV{'form.viewselect'})) {
655: $ENV{'form.viewselect'} ="Detailed Citation View";
656: }
1.154 www 657: my $bodytag=&Apache::loncommon::bodytag('Advanced Catalog Search');
1.124 matthew 658: my $scrout=<<"ENDHEADER";
659: <html>
660: <head>
661: <title>The LearningOnline Network with CAPA</title>
662: <script type="text/javascript">
663: function openhelp(val) {
664: openhelpwin=open('/adm/help/searchcat.html','helpscreen',
665: 'scrollbars=1,width=600,height=300');
666: openhelpwin.focus();
1.18 harris41 667: }
1.124 matthew 668: </script>
669: </head>
1.154 www 670: $bodytag
1.131 matthew 671: Enter terms or phrases separated by search operators
1.129 matthew 672: such as AND, OR, or NOT.<br />
1.130 matthew 673: <form method="post" action="/adm/searchcat">
1.129 matthew 674: $advanced_buttons
1.145 matthew 675: $hidden_fields
1.146 matthew 676: <input type="hidden" name="phase" value="adv_search" />
1.129 matthew 677: <table>
1.130 matthew 678: <tr><td><font color="#800000" face="helvetica"><b>VIEW:</b></font></td>
679: <td>
1.124 matthew 680: ENDHEADER
1.139 matthew 681: $scrout.=&selectbox(undef,'viewselect',
682: $ENV{'form.viewselect'},
683: undef,undef,undef,
684: sort(keys(%Views)));
1.151 matthew 685: $scrout.=' ';
686: $scrout.=&selectbox(undef,'show',
687: $ENV{'form.show'},
688: undef,undef,undef,
689: (10,20,50,100));
690: $scrout.=' '.
1.187 www 691: '<font color="#800000" face="helvetica">'.&mt('Per Page').'</font>';
692: $scrout.="</td><td>".&mt('Related').'<br />'.&mt('Words')."</td></tr>\n";
1.142 matthew 693: $scrout.=&searchphrasefield_with_related('title', 'title' ,
694: $ENV{'form.title'});
1.135 matthew 695: $scrout.=&searchphrasefield('author', 'author' ,$ENV{'form.author'});
1.142 matthew 696: $scrout.=&searchphrasefield_with_related('subject', 'subject' ,
697: $ENV{'form.subject'});
698: $scrout.=&searchphrasefield_with_related('keywords','keywords',
699: $ENV{'form.keywords'});
1.135 matthew 700: $scrout.=&searchphrasefield('URL', 'url' ,$ENV{'form.url'});
1.142 matthew 701: $scrout.=&searchphrasefield_with_related('notes', 'notes' ,
702: $ENV{'form.notes'});
703: $scrout.=&searchphrasefield_with_related('abstract','abstract',
704: $ENV{'form.abstract'});
1.129 matthew 705: # Hack - an empty table row.
1.142 matthew 706: $scrout.="<tr><td> </td><td> </td><td> </td></tr>\n";
1.161 matthew 707: $scrout.=&searchphrasefield('file<br />extension','extension',
708: $ENV{'form.extension'});
1.142 matthew 709: $scrout.="<tr><td> </td><td> </td><td> </td></tr>\n";
1.129 matthew 710: $scrout.=&searchphrasefield('publisher<br />owner','owner',
711: $ENV{'form.owner'});
712: $scrout.="</table>\n";
1.161 matthew 713: $ENV{'form.category'}='any' if (! defined($ENV{'form.category'}));
1.132 matthew 714: $scrout.=&selectbox('File Category','category',
1.131 matthew 715: $ENV{'form.category'},
716: 'any','Any category',
717: undef,
718: (&Apache::loncommon::filecategories()));
1.11 harris41 719: $ENV{'form.language'}='any' unless length($ENV{'form.language'});
1.133 matthew 720: #----------------------------------------------------------------
1.132 matthew 721: # Allow restriction to multiple domains.
722: # I make the crazy assumption that there will never be a domain 'any'.
723: #
1.133 matthew 724: $ENV{'form.domains'} = 'any' if (! exists($ENV{'form.domains'}));
725: my @allowed_domains = (ref($ENV{'form.domains'}) ? @{$ENV{'form.domains'}}
726: : ($ENV{'form.domains'}) );
727: my %domain_hash = ();
728: foreach (@allowed_domains) {
729: $domain_hash{$_}++;
730: }
1.132 matthew 731: my @domains =&Apache::loncommon::get_domains();
732: # adjust the size of the select box
733: my $size = 4;
1.165 albertel 734: $size = (scalar @domains < ($size - 1) ? scalar @domains + 1 : $size);
1.145 matthew 735: $scrout.="\n".'<font color="#800000" face="helvetica"><b>'.
1.174 albertel 736: 'DOMAINS TO BE SEARCHED</b></font><br />'.
1.145 matthew 737: '<select name="domains" size="'.$size.'" multiple>'."\n".
738: '<option name="any" value="any" '.
739: ($domain_hash{'any'}? 'selected ' :'').
1.133 matthew 740: '>all domains</option>'."\n";
1.145 matthew 741: foreach my $dom (sort @domains) {
742: $scrout.="<option name=\"$dom\" ".
743: ($domain_hash{$dom} ? 'selected ' :'').">$dom</option>\n";
1.132 matthew 744: }
1.145 matthew 745: $scrout.="</select>\n";
1.133 matthew 746: #----------------------------------------------------------------
1.3 harris41 747: $scrout.=&selectbox('Limit by language','language',
1.111 harris41 748: $ENV{'form.language'},'any','Any Language',
1.166 albertel 749: \&Apache::loncommon::languagedescription,
1.111 harris41 750: (&Apache::loncommon::languageids),
751: );
1.8 harris41 752: # ------------------------------------------------ Compute date selection boxes
753: $scrout.=<<CREATIONDATESTART;
1.3 harris41 754: <p>
755: <font color="#800000" face="helvetica"><b>LIMIT BY CREATION DATE RANGE:</b>
756: </font>
1.98 harris41 757: <br />
1.8 harris41 758: between:
759: CREATIONDATESTART
1.11 harris41 760: $scrout.=&dateboxes('creationdatestart',1,1,1976,
761: $ENV{'form.creationdatestart_month'},
762: $ENV{'form.creationdatestart_day'},
763: $ENV{'form.creationdatestart_year'},
764: );
1.124 matthew 765: $scrout.="and:\n";
1.11 harris41 766: $scrout.=&dateboxes('creationdateend',12,31,2051,
767: $ENV{'form.creationdateend_month'},
768: $ENV{'form.creationdateend_day'},
769: $ENV{'form.creationdateend_year'},
770: );
1.8 harris41 771: $scrout.="</p>";
772: $scrout.=<<LASTREVISIONDATESTART;
773: <p>
774: <font color="#800000" face="helvetica"><b>LIMIT BY LAST REVISION DATE RANGE:
775: </b></font>
1.98 harris41 776: <br />between:
1.8 harris41 777: LASTREVISIONDATESTART
1.11 harris41 778: $scrout.=&dateboxes('lastrevisiondatestart',1,1,1976,
779: $ENV{'form.lastrevisiondatestart_month'},
780: $ENV{'form.lastrevisiondatestart_day'},
781: $ENV{'form.lastrevisiondatestart_year'},
782: );
1.8 harris41 783: $scrout.=<<LASTREVISIONDATEEND;
784: and:
785: LASTREVISIONDATEEND
1.11 harris41 786: $scrout.=&dateboxes('lastrevisiondateend',12,31,2051,
787: $ENV{'form.lastrevisiondateend_month'},
788: $ENV{'form.lastrevisiondateend_day'},
789: $ENV{'form.lastrevisiondateend_year'},
790: );
1.8 harris41 791: $scrout.='</p>';
1.11 harris41 792: $ENV{'form.copyright'}='any' unless length($ENV{'form.copyright'});
1.8 harris41 793: $scrout.=&selectbox('Limit by copyright/distribution','copyright',
1.111 harris41 794: $ENV{'form.copyright'},
795: 'any','Any copyright/distribution',
1.166 albertel 796: \&Apache::loncommon::copyrightdescription,
1.111 harris41 797: (&Apache::loncommon::copyrightids),
798: );
1.14 harris41 799: # ------------------------------------------- Compute customized metadata field
1.152 matthew 800: # $scrout.=<<CUSTOMMETADATA;
801: #<p>
802: #<font color="#800000" face="helvetica"><b>LIMIT BY SPECIAL METADATA FIELDS:</b>
803: #</font>
804: #For resource-specific metadata, enter in an expression in the form of
805: #<i>key</i>=<i>value</i> separated by operators such as AND, OR or NOT.<br />
806: #<b>Example:</b> grandmother=75 OR grandfather=85
807: #<br />
808: #CUSTOMMETADATA
809: # $scrout.=&simpletextfield('custommetadata',$ENV{'form.custommetadata'});
810: # $scrout.=<<CUSTOMSHOW;
811: #<p>
812: #<font color="#800000" face="helvetica"><b>SHOW SPECIAL METADATA FIELDS:</b>
813: #</font>
814: #Enter in a space-separated list of special metadata fields to show
815: #in a fielded listing for each record result.
816: #<br />
817: #CUSTOMSHOW
818: # $scrout.=&simpletextfield('customshow',$ENV{'form.customshow'});
1.124 matthew 819: $scrout.=<<ENDDOCUMENT;
1.129 matthew 820: $advanced_buttons
1.8 harris41 821: </form>
822: </body>
823: </html>
824: ENDDOCUMENT
1.146 matthew 825: $r->print($scrout);
826: return;
1.124 matthew 827: }
1.8 harris41 828:
1.121 matthew 829: ######################################################################
830: ######################################################################
831:
832: =pod
833:
1.146 matthew 834: =item &get_persistent_form_data
1.145 matthew 835:
1.146 matthew 836: Inputs: filename of database
837:
838: Outputs: returns undef on database errors.
839:
840: This function is the reverse of &make_persistent() for form data.
1.145 matthew 841: Retrieve persistent data from %persistent_db. Retrieved items will have their
1.146 matthew 842: values unescaped. If a form value already exists in $ENV, it will not be
843: overwritten. Form values that are array references may have values appended
844: to them.
1.145 matthew 845:
846: =cut
847:
848: ######################################################################
849: ######################################################################
1.146 matthew 850: sub get_persistent_form_data {
851: my $filename = shift;
1.147 matthew 852: return 0 if (! -e $filename);
1.146 matthew 853: return undef if (! tie(%persistent_db,'GDBM_File',$filename,
1.148 matthew 854: &GDBM_READER(),0640));
1.146 matthew 855: #
856: # These make sure we do not get array references printed out as 'values'.
1.161 matthew 857: my %arrays_allowed = ('form.domains'=>1);
1.146 matthew 858: #
859: # Loop through the keys, looking for 'form.'
860: foreach my $name (keys(%persistent_db)) {
861: next if ($name !~ /^form./);
1.182 matthew 862: # Kludgification begins!
863: if ($name eq 'form.domains' &&
864: $ENV{'form.searchmode'} eq 'basic' &&
865: $ENV{'form.phase'} ne 'disp_basic') {
866: next;
867: }
868: # End kludge (hopefully)
1.152 matthew 869: next if (exists($ENV{$name}));
1.146 matthew 870: my @values = map {
871: &Apache::lonnet::unescape($_);
872: } split(',',$persistent_db{$name});
873: next if (@values <1);
1.152 matthew 874: if ($arrays_allowed{$name}) {
875: $ENV{$name} = [@values];
1.146 matthew 876: } else {
1.152 matthew 877: $ENV{$name} = $values[0] if ($values[0]);
1.146 matthew 878: }
879: }
880: untie (%persistent_db);
881: return 1;
882: }
1.181 matthew 883:
1.146 matthew 884: ######################################################################
885: ######################################################################
886:
887: =pod
888:
889: =item &get_persistent_data
890:
891: Inputs: filename of database, ref to array of values to recover.
892:
893: Outputs: array of values. Returns undef on error.
894:
895: This function is the reverse of &make_persistent();
896: Retrieve persistent data from %persistent_db. Retrieved items will have their
897: values unescaped. If the item contains commas (before unescaping), the
898: returned value will be an array pointer.
899:
900: =cut
901:
902: ######################################################################
903: ######################################################################
904: sub get_persistent_data {
905: my $filename = shift;
906: my @Vars = @{shift()};
907: my @Values; # Return array
908: return undef if (! -e $filename);
909: return undef if (! tie(%persistent_db,'GDBM_File',$filename,
1.148 matthew 910: &GDBM_READER(),0640));
1.146 matthew 911: foreach my $name (@Vars) {
912: if (! exists($persistent_db{$name})) {
913: push @Values, undef;
914: next;
915: }
916: my @values = map {
917: &Apache::lonnet::unescape($_);
918: } split(',',$persistent_db{$name});
1.152 matthew 919: if (@values <= 1) {
1.146 matthew 920: push @Values,$values[0];
1.145 matthew 921: } else {
1.146 matthew 922: push @Values,\@values;
1.145 matthew 923: }
924: }
1.146 matthew 925: untie (%persistent_db);
926: return @Values;
1.145 matthew 927: }
928:
929: ######################################################################
930: ######################################################################
931:
932: =pod
933:
1.121 matthew 934: =item &make_persistent()
935:
1.146 matthew 936: Inputs: Hash of values to save, filename of persistent database.
937:
938: Store variables away to the %persistent_db.
1.145 matthew 939: Values will be escaped. Values that are array pointers will have their
940: elements escaped and concatenated in a comma seperated string.
1.122 matthew 941:
1.121 matthew 942: =cut
943:
944: ######################################################################
945: ######################################################################
1.98 harris41 946: sub make_persistent {
1.133 matthew 947: my %save = %{shift()};
1.146 matthew 948: my $filename = shift;
949: return undef if (! tie(%persistent_db,'GDBM_File',
1.148 matthew 950: $filename,&GDBM_WRCREAT(),0640));
1.146 matthew 951: foreach my $name (keys(%save)) {
1.145 matthew 952: my @values = (ref($save{$name}) ? @{$save{$name}} : ($save{$name}));
953: # We handle array references, but not recursively.
954: my $store = join(',', map { &Apache::lonnet::escape($_); } @values );
955: $persistent_db{$name} = $store;
1.109 harris41 956: }
1.146 matthew 957: untie(%persistent_db);
958: return 1;
959: }
960:
961: ######################################################################
962: ######################################################################
963:
964: =pod
965:
966: =item &make_form_data_persistent()
967:
968: Inputs: filename of persistent database.
969:
970: Store most form variables away to the %persistent_db.
971: Values will be escaped. Values that are array pointers will have their
972: elements escaped and concatenated in a comma seperated string.
973:
974: =cut
975:
976: ######################################################################
977: ######################################################################
978: sub make_form_data_persistent {
979: my $r = shift;
980: my $filename = shift;
981: my %save;
982: foreach (keys(%ENV)) {
1.150 matthew 983: next if (!/^form/ || /submit/);
1.146 matthew 984: $save{$_} = $ENV{$_};
985: }
1.152 matthew 986: return &make_persistent(\%save,$filename);
1.98 harris41 987: }
988:
1.122 matthew 989: ######################################################################
1.142 matthew 990: # HTML form building functions #
1.122 matthew 991: ######################################################################
992:
993: =pod
994:
995: =item HTML form building functions
996:
997: =over 4
998:
1.142 matthew 999: =cut
1000:
1001: ###############################################
1002: ###############################################
1003:
1004: =pod
1005:
1.122 matthew 1006: =item &simpletextfield()
1007:
1008: Inputs: $name,$value,$size
1009:
1010: Returns a text input field with the given name, value, and size.
1011: If size is not specified, a value of 20 is used.
1012:
1.142 matthew 1013: =cut
1014:
1015: ###############################################
1016: ###############################################
1017:
1018: sub simpletextfield {
1019: my ($name,$value,$size)=@_;
1020: $size = 20 if (! defined($size));
1021: return '<input type="text" name="'.$name.
1022: '" size="'.$size.'" value="'.$value.'" />';
1023: }
1024:
1025: ###############################################
1026: ###############################################
1027:
1028: =pod
1029:
1.122 matthew 1030: =item &simplecheckbox()
1031:
1032: Inputs: $name,$value
1033:
1034: Returns a simple check box with the given $name.
1035: If $value eq 'on' the box is checked.
1036:
1.142 matthew 1037: =cut
1038:
1039: ###############################################
1040: ###############################################
1.122 matthew 1041:
1.180 matthew 1042: sub simplecheckbox{
1043: my ($name,$value,$checked)=@_;
1044: $checked="checked" if ($value eq 'on');
1045: return '<input type="checkbox" name="'.$name.'" value="'.$value.'" '.
1046: $checked.' />';
1.142 matthew 1047: }
1.122 matthew 1048:
1.142 matthew 1049: ###############################################
1050: ###############################################
1.122 matthew 1051:
1.142 matthew 1052: =pod
1.122 matthew 1053:
1.142 matthew 1054: =item &fieldtitle()
1.126 matthew 1055:
1.142 matthew 1056: Input: $title
1.122 matthew 1057:
1.142 matthew 1058: Returns a scalar with html which will display $title as a search
1059: field heading.
1.129 matthew 1060:
1.142 matthew 1061: =cut
1.129 matthew 1062:
1.142 matthew 1063: ###############################################
1064: ###############################################
1.129 matthew 1065:
1.142 matthew 1066: sub fieldtitle {
1.187 www 1067: my $title = uc(&mt(shift()));
1.142 matthew 1068: return '<font color="#800000" face="helvetica"><b>'.$title.
1069: ': </b></font>';
1070: }
1.129 matthew 1071:
1.142 matthew 1072: ###############################################
1073: ###############################################
1.129 matthew 1074:
1.142 matthew 1075: =pod
1.129 matthew 1076:
1.142 matthew 1077: =item &searchphrasefield()
1.129 matthew 1078:
1.142 matthew 1079: Inputs: $title,$name,$value
1.129 matthew 1080:
1.142 matthew 1081: Returns html for a title line and an input field for entering search terms.
1082: The entry field (which is where the $name and $value are used) is a 50 column
1083: simpletextfield. The html returned is for a row in a three column table.
1.129 matthew 1084:
1.142 matthew 1085: =cut
1.129 matthew 1086:
1.142 matthew 1087: ###############################################
1088: ###############################################
1089:
1090: sub searchphrasefield {
1091: my ($title,$name,$value)=@_;
1092: return '<tr><td>'.&fieldtitle($title).'</td><td>'.
1093: &simpletextfield($name,$value,50)."</td><td> </td></tr>\n";
1094: }
1.129 matthew 1095:
1.142 matthew 1096: ###############################################
1097: ###############################################
1.129 matthew 1098:
1.142 matthew 1099: =pod
1.129 matthew 1100:
1.142 matthew 1101: =item &searchphrasefield_with_related()
1.129 matthew 1102:
1.142 matthew 1103: Inputs: $title,$name,$value
1.129 matthew 1104:
1.142 matthew 1105: Returns html for a title line and an input field for entering search terms
1106: and a check box for 'related words'. The entry field (which is where the
1107: $name and $value are used) is a 50 column simpletextfield. The name of
1108: the related words checkbox is "$name_related".
1.129 matthew 1109:
1.142 matthew 1110: =cut
1.129 matthew 1111:
1.142 matthew 1112: ###############################################
1113: ###############################################
1114:
1115: sub searchphrasefield_with_related {
1116: my ($title,$name,$value)=@_;
1117: return '<tr><td>'.&fieldtitle($title).'</td><td>'.
1118: &simpletextfield($name,$value,50).'</td><td align="center"> '.
1119: &simplecheckbox($name.'_related',$ENV{'form.'.$name.'_related'}).
1120: " </td></tr>\n";
1121: }
1.126 matthew 1122:
1.142 matthew 1123: ###############################################
1124: ###############################################
1.122 matthew 1125:
1.142 matthew 1126: =pod
1.122 matthew 1127:
1.142 matthew 1128: =item &dateboxes()
1.8 harris41 1129:
1.142 matthew 1130: Returns html selection form elements for the specification of
1131: the day, month, and year.
1.11 harris41 1132:
1.142 matthew 1133: =cut
1.11 harris41 1134:
1.142 matthew 1135: ###############################################
1136: ###############################################
1.3 harris41 1137:
1.8 harris41 1138: sub dateboxes {
1.11 harris41 1139: my ($name,$defaultmonth,$defaultday,$defaultyear,
1140: $currentmonth,$currentday,$currentyear)=@_;
1141: ($defaultmonth,$defaultday,$defaultyear)=('','','');
1.117 matthew 1142: #
1143: # Day
1144: my $day=<<END;
1145: <select name="${name}_day">
1146: <option value='$defaultday'> </option>
1147: END
1148: for (my $i = 1; $i<=31; $i++) {
1149: $day.="<option value=\"$i\">$i</option>\n";
1150: }
1151: $day.="</select>\n";
1152: $day=~s/(\"$currentday\")/$1 SELECTED/ if length($currentday);
1153: #
1154: # Month
1.11 harris41 1155: my $month=<<END;
1.8 harris41 1156: <select name="${name}_month">
1.11 harris41 1157: <option value='$defaultmonth'> </option>
1158: END
1.117 matthew 1159: my $i = 1;
1160: foreach (qw/January February March April May June
1161: July August September October November December /){
1.187 www 1162: $month .="<option value=\"$i\">".&mt($_)."</option>\n";
1.117 matthew 1163: $i++;
1164: }
1165: $month.="</select>\n";
1.11 harris41 1166: $month=~s/(\"$currentmonth\")/$1 SELECTED/ if length($currentmonth);
1.117 matthew 1167: #
1168: # Year (obviously)
1.11 harris41 1169: my $year=<<END;
1.8 harris41 1170: <select name="${name}_year">
1.11 harris41 1171: <option value='$defaultyear'> </option>
1.3 harris41 1172: END
1.117 matthew 1173: my $maxyear = 2051;
1174: for (my $i = 1976; $i<=$maxyear; $i++) {
1175: $year.="<option value=\"$i\">$i</option>\n";
1176: }
1177: $year.="</select>\n";
1.11 harris41 1178: $year=~s/(\"$currentyear\")/$1 SELECTED/ if length($currentyear);
1179: return "$month$day$year";
1.3 harris41 1180: }
1181:
1.142 matthew 1182: ###############################################
1183: ###############################################
1184:
1185: =pod
1186:
1187: =item &selectbox()
1188:
1189: Returns a scalar containing an html <select> form.
1190:
1191: Inputs:
1192:
1193: =over 4
1194:
1195: =item $title
1196:
1197: Printed above the select box, in uppercase. If undefined, only a select
1198: box will be returned, with no additional html.
1199:
1200: =item $name
1201:
1202: The name element of the <select> tag.
1203:
1204: =item $default
1205:
1206: The default value of the form. Can be $anyvalue, or in @idlist.
1207:
1208: =item $anyvalue
1209:
1210: The <option value="..."> used to indicate a default of
1211: none of the values. Can be undef.
1212:
1213: =item $anytag
1214:
1215: The text associate with $anyvalue above.
1216:
1217: =item $functionref
1218:
1219: Each element in @idlist will be passed as a parameter
1220: to the function referenced here. The return value of the function should
1221: be a scalar description of the items. If this value is undefined the
1222: description of each item in @idlist will be the item name.
1223:
1224: =item @idlist
1225:
1226: The items to be selected from. One of these or $anyvalue will be the
1227: value returned by the form element, $ENV{form.$name}.
1228:
1229: =back
1230:
1231: =cut
1232:
1233: ###############################################
1234:
1.3 harris41 1235: sub selectbox {
1.129 matthew 1236: my ($title,$name,$default,$anyvalue,$anytag,$functionref,@idlist)=@_;
1237: if (! defined($functionref)) { $functionref = sub { $_[0]}; }
1.139 matthew 1238: my $selout='';
1.186 www 1239: $title=&mt($title);
1.139 matthew 1240: if (defined($title)) {
1241: my $uctitle=uc($title);
1242: $selout="\n".'<p><font color="#800000" face="helvetica">'.
1243: '<b>'.$uctitle.': </b></font>';
1244: }
1245: $selout .= '<select name="'.$name.'">';
1246: unshift @idlist,$anyvalue if (defined($anyvalue));
1247: foreach (@idlist) {
1.122 matthew 1248: $selout.='<option value="'.$_.'"';
1.129 matthew 1249: if ($_ eq $default and !/^any$/) {
1.187 www 1250: $selout.=' selected >'.&mt(&{$functionref}($_)).'</option>';
1.111 harris41 1251: }
1.129 matthew 1252: elsif ($_ eq $default and /^$anyvalue$/) {
1.187 www 1253: $selout.=' selected >'.&mt($anytag).'</option>';
1.111 harris41 1254: }
1.187 www 1255: else {$selout.='>'.&mt(&{$functionref}($_)).'</option>';}
1.109 harris41 1256: }
1.139 matthew 1257: return $selout.'</select>'.(defined($title)?'</p>':' ');
1.6 harris41 1258: }
1259:
1.122 matthew 1260: ######################################################################
1.142 matthew 1261: # End of HTML form building functions #
1262: ######################################################################
1263:
1264: =pod
1265:
1266: =back
1267:
1268: =cut
1269:
1270:
1271: ######################################################################
1.122 matthew 1272: ######################################################################
1273:
1274: =pod
1275:
1.134 matthew 1276: =item &parse_advanced_search()
1277:
1278: Parse advanced search form and return the following:
1279:
1280: =over 4
1281:
1282: =item $query Scalar containing an SQL query.
1.126 matthew 1283:
1.134 matthew 1284: =item $customquery Scalar containing a custom query.
1285:
1286: =item $customshow Scalar containing commands to show custom metadata.
1287:
1288: =item $libraries_to_query Reference to array of domains to search.
1289:
1290: =back
1.122 matthew 1291:
1292: =cut
1293:
1294: ######################################################################
1295: ######################################################################
1.134 matthew 1296: sub parse_advanced_search {
1.145 matthew 1297: my ($r,$closebutton)=@_;
1.32 harris41 1298: my $fillflag=0;
1.143 matthew 1299: my $pretty_search_string = "<br />\n";
1.64 harris41 1300: # Clean up fields for safety
1301: for my $field ('title','author','subject','keywords','url','version',
1302: 'creationdatestart_month','creationdatestart_day',
1303: 'creationdatestart_year','creationdateend_month',
1304: 'creationdateend_day','creationdateend_year',
1305: 'lastrevisiondatestart_month','lastrevisiondatestart_day',
1306: 'lastrevisiondatestart_year','lastrevisiondateend_month',
1307: 'lastrevisiondateend_day','lastrevisiondateend_year',
1.161 matthew 1308: 'notes','abstract','extension','language','owner',
1.131 matthew 1309: 'custommetadata','customshow','category') {
1.101 harris41 1310: $ENV{"form.$field"}=~s/[^\w\/\s\(\)\=\-\"\']//g;
1.64 harris41 1311: }
1.117 matthew 1312: foreach ('mode','form','element') {
1313: # is this required? Hmmm.
1314: next unless (exists($ENV{"form.$_"}));
1315: $ENV{"form.$_"}=&Apache::lonnet::unescape($ENV{"form.$_"});
1316: $ENV{"form.$_"}=~s/[^\w\/\s\(\)\=\-\"\']//g;
1317: }
1.131 matthew 1318: # Preprocess the category form element.
1.161 matthew 1319: $ENV{'form.category'} = 'any' if (! defined($ENV{'form.category'}) ||
1320: ref($ENV{'form.category'}));
1321: #
1.90 harris41 1322: # Check to see if enough information was filled in
1.32 harris41 1323: for my $field ('title','author','subject','keywords','url','version',
1.161 matthew 1324: 'notes','abstract','category','extension','language',
1325: 'owner','custommetadata') {
1.40 harris41 1326: if (&filled($ENV{"form.$field"})) {
1.32 harris41 1327: $fillflag++;
1328: }
1329: }
1330: unless ($fillflag) {
1.151 matthew 1331: &output_blank_field_error($r,$closebutton,'phase=disp_adv');
1.134 matthew 1332: return ;
1.32 harris41 1333: }
1.90 harris41 1334: # Turn the form input into a SQL-based query
1.39 harris41 1335: my $query='';
1.45 harris41 1336: my @queries;
1.143 matthew 1337: my $font = '<font color="#800000" face="helvetica">';
1.90 harris41 1338: # Evaluate logical expression AND/OR/NOT phrase fields.
1.58 harris41 1339: foreach my $field ('title','author','subject','notes','abstract','url',
1.161 matthew 1340: 'keywords','version','owner') {
1.44 harris41 1341: if ($ENV{'form.'.$field}) {
1.142 matthew 1342: my $searchphrase = $ENV{'form.'.$field};
1.143 matthew 1343: $pretty_search_string .= $font."$field</font> contains <b>".
1344: $searchphrase."</b>";
1.142 matthew 1345: if ($ENV{'form.'.$field.'_related'}) {
1.143 matthew 1346: my @New_Words;
1347: ($searchphrase,@New_Words) = &related_version($searchphrase);
1348: if (@New_Words) {
1349: $pretty_search_string .= " with related words: ".
1350: "<b>@New_Words</b>.";
1351: } else {
1352: $pretty_search_string .= " with no related words.";
1353: }
1.142 matthew 1354: }
1.143 matthew 1355: $pretty_search_string .= "<br />\n";
1.142 matthew 1356: push @queries,&build_SQL_query($field,$searchphrase);
1.131 matthew 1357: }
1.44 harris41 1358: }
1.161 matthew 1359: #
1360: # Make the 'mime' from 'form.category' and 'form.extension'
1361: #
1362: my $searchphrase;
1363: if (exists($ENV{'form.category'}) &&
1364: $ENV{'form.category'} !~ /^\s*$/ &&
1365: $ENV{'form.category'} ne 'any') {
1366: my @extensions = &Apache::loncommon::filecategorytypes
1367: ($ENV{'form.category'});
1368: if (scalar(@extensions) > 0) {
1369: $searchphrase = join(' OR ',@extensions);
1370: }
1371: }
1372: if (exists($ENV{'form.extension'}) && $ENV{'form.extension'} !~ /^\s*$/) {
1373: $searchphrase .= ' OR ' if (defined($searchphrase));
1374: my @extensions = split(/,/,$ENV{'form.extension'});
1375: $searchphrase .= join(' OR ',@extensions);
1376: }
1377: if (defined($searchphrase)) {
1378: push @queries,&build_SQL_query('mime',$searchphrase);
1379: $pretty_search_string .=$font.'mime</font> contains <b>'.
1380: $searchphrase.'</b><br />';
1.135 matthew 1381: }
1.161 matthew 1382: #####
1.90 harris41 1383: # Evaluate option lists
1.58 harris41 1384: if ($ENV{'form.language'} and $ENV{'form.language'} ne 'any') {
1.90 harris41 1385: push @queries,"(language like \"$ENV{'form.language'}\")";
1.143 matthew 1386: $pretty_search_string.=$font."language</font>= ".
1387: &Apache::loncommon::languagedescription($ENV{'form.language'}).
1388: "<br />\n";
1.58 harris41 1389: }
1390: if ($ENV{'form.copyright'} and $ENV{'form.copyright'} ne 'any') {
1.90 harris41 1391: push @queries,"(copyright like \"$ENV{'form.copyright'}\")";
1.143 matthew 1392: $pretty_search_string.=$font."copyright</font> = ".
1393: &Apache::loncommon::copyrightdescription($ENV{'form.copyright'}).
1394: "<br \>\n";
1.58 harris41 1395: }
1.143 matthew 1396: #
1.90 harris41 1397: # Evaluate date windows
1.60 harris41 1398: my $datequery=&build_date_queries(
1399: $ENV{'form.creationdatestart_month'},
1400: $ENV{'form.creationdatestart_day'},
1401: $ENV{'form.creationdatestart_year'},
1402: $ENV{'form.creationdateend_month'},
1403: $ENV{'form.creationdateend_day'},
1404: $ENV{'form.creationdateend_year'},
1405: $ENV{'form.lastrevisiondatestart_month'},
1406: $ENV{'form.lastrevisiondatestart_day'},
1407: $ENV{'form.lastrevisiondatestart_year'},
1408: $ENV{'form.lastrevisiondateend_month'},
1409: $ENV{'form.lastrevisiondateend_day'},
1410: $ENV{'form.lastrevisiondateend_year'},
1411: );
1.90 harris41 1412: # Test to see if date windows are legitimate
1.61 harris41 1413: if ($datequery=~/^Incorrect/) {
1.145 matthew 1414: &output_date_error($r,$datequery,$closebutton);
1.134 matthew 1415: return ;
1.143 matthew 1416: } elsif ($datequery) {
1417: # Here is where you would set up pretty_search_string to output
1418: # date query information.
1.60 harris41 1419: push @queries,$datequery;
1420: }
1.90 harris41 1421: # Process form information for custom metadata querying
1.134 matthew 1422: my $customquery=undef;
1.152 matthew 1423: # if ($ENV{'form.custommetadata'}) {
1424: # $pretty_search_string .=$font."Custom Metadata Search</font>: <b>".
1425: # $ENV{'form.custommetadata'}."</b><br />\n";
1426: # $customquery=&build_custommetadata_query('custommetadata',
1427: # $ENV{'form.custommetadata'});
1428: # }
1.134 matthew 1429: my $customshow=undef;
1.152 matthew 1430: # if ($ENV{'form.customshow'}) {
1431: # $pretty_search_string .=$font."Custom Metadata Display</font>: <b>".
1432: # $ENV{'form.customshow'}."</b><br />\n";
1433: # $customshow=$ENV{'form.customshow'};
1434: # $customshow=~s/[^\w\s]//g;
1435: # my @fields=split(/\s+/,$customshow);
1436: # $customshow=join(" ",@fields);
1437: # }
1.133 matthew 1438: ## ---------------------------------------------------------------
1.132 matthew 1439: ## Deal with restrictions to given domains
1440: ##
1.180 matthew 1441: my ($libraries_to_query,$pretty_domains_string) =
1442: &parse_domain_restrictions();
1443: $pretty_search_string .= $pretty_domains_string."<br />\n";
1444: #
1445: if (@queries) {
1446: $query=join(" AND ",@queries);
1447: $query="select * from metadata where $query";
1448: } elsif ($customquery) {
1449: $query = '';
1450: }
1451: return ($query,$customquery,$customshow,$libraries_to_query,
1452: $pretty_search_string);
1453: }
1454:
1455: sub parse_domain_restrictions {
1.132 matthew 1456: my $libraries_to_query = undef;
1457: # $ENV{'form.domains'} can be either a scalar or an array reference.
1458: # We need an array.
1.180 matthew 1459: if (! exists($ENV{'form.domains'})) {
1460: return (undef,'');
1461: }
1462: my @allowed_domains;
1463: if (ref($ENV{'form.domains'})) {
1464: @allowed_domains = @{$ENV{'form.domains'}};
1465: } else {
1466: @allowed_domains = ($ENV{'form.domains'});
1467: }
1.132 matthew 1468: my %domain_hash = ();
1.143 matthew 1469: my $pretty_domains_string;
1.132 matthew 1470: foreach (@allowed_domains) {
1471: $domain_hash{$_}++;
1472: }
1.143 matthew 1473: if ($domain_hash{'any'}) {
1.152 matthew 1474: $pretty_domains_string = "In all LON-CAPA domains.";
1.143 matthew 1475: } else {
1476: if (@allowed_domains > 1) {
1.152 matthew 1477: $pretty_domains_string = "In LON-CAPA domains:";
1.143 matthew 1478: } else {
1.152 matthew 1479: $pretty_domains_string = "In LON-CAPA domain ";
1.143 matthew 1480: }
1481: foreach (sort @allowed_domains) {
1.152 matthew 1482: $pretty_domains_string .= "<b>".$_."</b> ";
1.132 matthew 1483: }
1.143 matthew 1484: foreach (keys(%Apache::lonnet::libserv)) {
1485: if (exists($domain_hash{$Apache::lonnet::hostdom{$_}})) {
1486: push @$libraries_to_query,$_;
1487: }
1.132 matthew 1488: }
1489: }
1.180 matthew 1490: return ($libraries_to_query,$pretty_domains_string);
1.18 harris41 1491: }
1492:
1.122 matthew 1493: ######################################################################
1494: ######################################################################
1495:
1496: =pod
1497:
1.134 matthew 1498: =item &parse_basic_search()
1.122 matthew 1499:
1.134 matthew 1500: Parse the basic search form and return a scalar containing an sql query.
1.126 matthew 1501:
1.122 matthew 1502: =cut
1503:
1504: ######################################################################
1505: ######################################################################
1.134 matthew 1506: sub parse_basic_search {
1.145 matthew 1507: my ($r,$closebutton)=@_;
1.64 harris41 1508: # Clean up fields for safety
1509: for my $field ('basicexp') {
1510: $ENV{"form.$field"}=~s/[^\w\s\(\)\-]//g;
1511: }
1.117 matthew 1512: foreach ('mode','form','element') {
1513: # is this required? Hmmm.
1514: next unless (exists($ENV{"form.$_"}));
1515: $ENV{"form.$_"}=&Apache::lonnet::unescape($ENV{"form.$_"});
1516: $ENV{"form.$_"}=~s/[^\w\/\s\(\)\=\-\"\']//g;
1517: }
1.180 matthew 1518: my ($libraries_to_query,$pretty_domains_string) =
1519: &parse_domain_restrictions();
1.90 harris41 1520: # Check to see if enough is filled in
1.26 harris41 1521: unless (&filled($ENV{'form.basicexp'})) {
1.151 matthew 1522: &output_blank_field_error($r,$closebutton,'phase=disp_basic');
1.24 harris41 1523: return OK;
1524: }
1.143 matthew 1525: my $pretty_search_string = '<b>'.$ENV{'form.basicexp'}.'</b>';
1.142 matthew 1526: my $search_string = $ENV{'form.basicexp'};
1.141 matthew 1527: if ($ENV{'form.related'}) {
1.143 matthew 1528: my @New_Words;
1529: ($search_string,@New_Words) = &related_version($ENV{'form.basicexp'});
1530: if (@New_Words) {
1531: $pretty_search_string .= " with related words: <b>@New_Words</b>.";
1532: } else {
1533: $pretty_search_string .= " with no related words.";
1534: }
1.141 matthew 1535: }
1.90 harris41 1536: # Build SQL query string based on form page
1.39 harris41 1537: my $query='';
1.178 matthew 1538: my $concatarg=join(',',
1.124 matthew 1539: ('title', 'author', 'subject', 'notes', 'abstract',
1540: 'keywords'));
1.95 harris41 1541: $concatarg='title' if $ENV{'form.titleonly'};
1.178 matthew 1542: $query=&build_SQL_query('concat_ws(" ",'.$concatarg.')',$search_string);
1.180 matthew 1543: if (defined($pretty_domains_string) && $pretty_domains_string ne '') {
1544: $pretty_search_string .= ' '.$pretty_domains_string;
1545: }
1.143 matthew 1546: $pretty_search_string .= "<br />\n";
1.183 matthew 1547: my $final_query = 'SELECT * FROM metadata WHERE '.$query;
1548: # &Apache::lonnet::logthis($final_query);
1549: return ($final_query,$pretty_search_string,
1.180 matthew 1550: $libraries_to_query);
1.22 harris41 1551: }
1552:
1.122 matthew 1553:
1554: ######################################################################
1555: ######################################################################
1556:
1557: =pod
1558:
1.142 matthew 1559: =item &related_version
1560:
1561: Modifies an input string to include related words. Words in the string
1562: are replaced with parenthesized lists of 'OR'd words. For example
1563: "torque" is replaced with "(torque OR word1 OR word2 OR ...)".
1564:
1565: Note: Using this twice on a string is probably silly.
1566:
1567: =cut
1568:
1569: ######################################################################
1570: ######################################################################
1571: sub related_version {
1572: my $search_string = shift;
1573: my $result = $search_string;
1.143 matthew 1574: my %New_Words = ();
1.142 matthew 1575: while ($search_string =~ /(\w+)/cg) {
1576: my $word = $1;
1577: next if (lc($word) =~ /\b(or|and|not)\b/);
1578: my @Words = &Apache::loncommon::get_related_words($word);
1.143 matthew 1579: @Words = ($#Words>4? @Words[0..4] : @Words);
1580: foreach (@Words) { $New_Words{$_}++;}
1581: my $replacement = join " OR ", ($word,@Words);
1.142 matthew 1582: $result =~ s/(\b)$word(\b)/$1($replacement)$2/g;
1583: }
1.143 matthew 1584: return $result,sort(keys(%New_Words));
1.142 matthew 1585: }
1586:
1587: ######################################################################
1588: ######################################################################
1589:
1590: =pod
1591:
1.122 matthew 1592: =item &build_SQL_query()
1593:
1.126 matthew 1594: Builds a SQL query string from a logical expression with AND/OR keywords
1595: using Text::Query and &recursive_SQL_query_builder()
1596:
1.122 matthew 1597: =cut
1598:
1599: ######################################################################
1600: ######################################################################
1.98 harris41 1601: sub build_SQL_query {
1602: my ($field_name,$logic_statement)=@_;
1603: my $q=new Text::Query('abc',
1604: -parse => 'Text::Query::ParseAdvanced',
1605: -build => 'Text::Query::Build');
1606: $q->prepare($logic_statement);
1607: my $matchexp=${$q}{'matchexp'}; chomp $matchexp;
1608: my $sql_query=&recursive_SQL_query_build($field_name,$matchexp);
1609: return $sql_query;
1610: }
1611:
1.122 matthew 1612: ######################################################################
1613: ######################################################################
1614:
1615: =pod
1616:
1617: =item &build_custommetadata_query()
1618:
1.126 matthew 1619: Constructs a custom metadata query using a rather heinous regular
1620: expression.
1621:
1.122 matthew 1622: =cut
1623:
1624: ######################################################################
1625: ######################################################################
1.98 harris41 1626: sub build_custommetadata_query {
1627: my ($field_name,$logic_statement)=@_;
1628: my $q=new Text::Query('abc',
1629: -parse => 'Text::Query::ParseAdvanced',
1630: -build => 'Text::Query::BuildAdvancedString');
1631: $q->prepare($logic_statement);
1632: my $matchexp=${$q}{'-parse'}{'-build'}{'matchstring'};
1633: # quick fix to change literal into xml tag-matching
1634: # will eventually have to write a separate builder module
1.122 matthew 1635: # wordone=wordtwo becomes\<wordone\>[^\<] *wordtwo[^\<]*\<\/wordone\>
1636: $matchexp =~ s/(\w+)\\=([\w\\\+]+)?# wordone=wordtwo is changed to
1637: /\\<$1\\>?# \<wordone\>
1638: \[\^\\<\]?# [^\<]
1639: \*$2\[\^\\<\]?# *wordtwo[^\<]
1640: \*\\<\\\/$1\\>?# *\<\/wordone\>
1641: /g;
1.98 harris41 1642: return $matchexp;
1643: }
1644:
1.122 matthew 1645: ######################################################################
1646: ######################################################################
1647:
1648: =pod
1649:
1650: =item &recursive_SQL_query_build()
1651:
1.126 matthew 1652: Recursively constructs an SQL query. Takes as input $dkey and $pattern.
1653:
1.122 matthew 1654: =cut
1655:
1656: ######################################################################
1657: ######################################################################
1.98 harris41 1658: sub recursive_SQL_query_build {
1659: my ($dkey,$pattern)=@_;
1660: my @matches=($pattern=~/(\[[^\]|\[]*\])/g);
1661: return $pattern unless @matches;
1662: foreach my $match (@matches) {
1.173 matthew 1663: $match=~/\[ (\w+)\s(.*) \]/;
1664: my ($key,$value)=($1,$2);
1665: my $replacement='';
1666: if ($key eq 'literal') {
1.178 matthew 1667: $replacement="($dkey LIKE \"\%$value\%\")";
1668: } elsif (lc($key) eq 'not') {
1669: $value=~s/LIKE/NOT LIKE/;
1.173 matthew 1670: # $replacement="($dkey not like $value)";
1671: $replacement="$value";
1672: } elsif ($key eq 'and') {
1673: $value=~/(.*[\"|\)]) ([|\(|\^].*)/;
1674: $replacement="($1 AND $2)";
1675: } elsif ($key eq 'or') {
1676: $value=~/(.*[\"|\)]) ([|\(|\^].*)/;
1677: $replacement="($1 OR $2)";
1.98 harris41 1678: }
1679: substr($pattern,
1.173 matthew 1680: index($pattern,$match),
1681: length($match),
1682: $replacement);
1.98 harris41 1683: }
1684: &recursive_SQL_query_build($dkey,$pattern);
1685: }
1.22 harris41 1686:
1.122 matthew 1687: ######################################################################
1688: ######################################################################
1689:
1690: =pod
1691:
1692: =item &build_date_queries()
1693:
1.126 matthew 1694: Builds a SQL logic query to check time/date entries.
1695: Also reports errors (check for /^Incorrect/).
1696:
1.122 matthew 1697: =cut
1698:
1699: ######################################################################
1700: ######################################################################
1.98 harris41 1701: sub build_date_queries {
1702: my ($cmonth1,$cday1,$cyear1,$cmonth2,$cday2,$cyear2,
1703: $lmonth1,$lday1,$lyear1,$lmonth2,$lday2,$lyear2)=@_;
1704: my @queries;
1705: if ($cmonth1 or $cday1 or $cyear1 or $cmonth2 or $cday2 or $cyear2) {
1706: unless ($cmonth1 and $cday1 and $cyear1 and
1707: $cmonth2 and $cday2 and $cyear2) {
1708: return "Incorrect entry for the creation date. You must specify ".
1709: "a starting month, day, and year and an ending month, ".
1710: "day, and year.";
1711: }
1712: my $cnumeric1=sprintf("%d%2d%2d",$cyear1,$cmonth1,$cday1);
1713: $cnumeric1+=0;
1714: my $cnumeric2=sprintf("%d%2d%2d",$cyear2,$cmonth2,$cday2);
1715: $cnumeric2+=0;
1716: if ($cnumeric1>$cnumeric2) {
1717: return "Incorrect entry for the creation date. The starting ".
1718: "date must occur before the ending date.";
1719: }
1720: my $cquery="(creationdate BETWEEN '$cyear1-$cmonth1-$cday1' AND '".
1721: "$cyear2-$cmonth2-$cday2 23:59:59')";
1722: push @queries,$cquery;
1723: }
1724: if ($lmonth1 or $lday1 or $lyear1 or $lmonth2 or $lday2 or $lyear2) {
1725: unless ($lmonth1 and $lday1 and $lyear1 and
1726: $lmonth2 and $lday2 and $lyear2) {
1727: return "Incorrect entry for the last revision date. You must ".
1728: "specify a starting month, day, and year and an ending ".
1729: "month, day, and year.";
1730: }
1731: my $lnumeric1=sprintf("%d%2d%2d",$lyear1,$lmonth1,$lday1);
1732: $lnumeric1+=0;
1733: my $lnumeric2=sprintf("%d%2d%2d",$lyear2,$lmonth2,$lday2);
1734: $lnumeric2+=0;
1735: if ($lnumeric1>$lnumeric2) {
1736: return "Incorrect entry for the last revision date. The ".
1737: "starting date must occur before the ending date.";
1738: }
1739: my $lquery="(lastrevisiondate BETWEEN '$lyear1-$lmonth1-$lday1' AND '".
1740: "$lyear2-$lmonth2-$lday2 23:59:59')";
1741: push @queries,$lquery;
1742: }
1743: if (@queries) {
1744: return join(" AND ",@queries);
1745: }
1746: return '';
1.18 harris41 1747: }
1.6 harris41 1748:
1.122 matthew 1749: ######################################################################
1750: ######################################################################
1751:
1.144 matthew 1752: =pod
1753:
1754: =item ©right_check()
1755:
1756: =cut
1757:
1758: ######################################################################
1759: ######################################################################
1760: sub copyright_check {
1761: my $Metadata = shift;
1762: # Check copyright tags and skip results the user cannot use
1763: my (undef,undef,$resdom,$resname) = split('/',
1764: $Metadata->{'url'});
1765: # Check for priv
1766: if (($Metadata->{'copyright'} eq 'priv') &&
1767: (($ENV{'user.name'} ne $resname) &&
1768: ($ENV{'user.domain'} ne $resdom))) {
1769: return 0;
1770: }
1771: # Check for domain
1772: if (($Metadata->{'copyright'} eq 'domain') &&
1773: ($ENV{'user.domain'} ne $resdom)) {
1774: return 0;
1775: }
1776: return 1;
1777: }
1778:
1.151 matthew 1779:
1780: ######################################################################
1781: ######################################################################
1782:
1783: =pod
1784:
1785: =item &ensure_db_and_table
1786:
1787: Ensure we can get lonmysql to connect to the database and the table we
1788: need exists.
1789:
1790: Inputs: $r, table id
1791:
1792: Returns: undef on error, 1 if the table exists.
1793:
1794: =cut
1795:
1796: ######################################################################
1797: ######################################################################
1798: sub ensure_db_and_table {
1799: my ($r,$table) = @_;
1800: ##
1801: ## Sanity check the table id.
1802: ##
1803: if (! defined($table) || $table eq '' || $table =~ /\D/ ) {
1804: $r->print("Unable to retrieve search results. ".
1805: "Unable to determine the table results were stored in. ".
1806: "</body></html>");
1807: return undef;
1808: }
1809: ##
1810: ## Make sure we can connect and the table exists.
1811: ##
1812: my $connection_result = &Apache::lonmysql::connect_to_db();
1813: if (!defined($connection_result)) {
1814: $r->print("Unable to connect to the MySQL database where your results".
1815: " are stored. </body></html>");
1816: &Apache::lonnet::logthis("lonsearchcat: unable to get lonmysql to".
1817: " connect to database.");
1818: &Apache::lonnet::logthis(&Apache::lonmysql::get_error());
1819: return undef;
1820: }
1821: my $table_check = &Apache::lonmysql::check_table($table);
1822: if (! defined($table_check)) {
1823: $r->print("A MySQL error has occurred.</form></body></html>");
1824: &Apache::lonnet::logthis("lonmysql was unable to determine the status".
1825: " of table ".$table);
1826: return undef;
1827: } elsif (! $table_check) {
1828: $r->print("The table of results could not be found.");
1829: &Apache::lonnet::logthis("The user requested a table, ".$table.
1830: ", that could not be found.");
1831: return undef;
1832: }
1833: return 1;
1834: }
1835:
1836: ######################################################################
1837: ######################################################################
1838:
1839: =pod
1840:
1841: =item &print_sort_form
1842:
1843: =cut
1844:
1845: ######################################################################
1846: ######################################################################
1847: sub print_sort_form {
1848: my ($r,$pretty_query_string) = @_;
1849: ##
1.187 www 1850: my %SortableFields=&Apache::lonlocal::texthash(
1851: id => 'Default',
1.151 matthew 1852: title => 'Title',
1853: author => 'Author',
1854: subject => 'Subject',
1855: url => 'URL',
1856: version => 'Version Number',
1857: mime => 'Mime type',
1858: lang => 'Language',
1859: owner => 'Owner/Publisher',
1860: copyright => 'Copyright',
1861: hostname => 'Host',
1862: creationdate => 'Creation Date',
1.187 www 1863: lastrevisiondate => 'Revision Date'
1.151 matthew 1864: );
1865: ##
1866: my $table = $ENV{'form.table'};
1867: return if (! &ensure_db_and_table($r,$table));
1868: ##
1869: ## Get the number of results
1870: ##
1871: my $total_results = &Apache::lonmysql::number_of_rows($table);
1872: if (! defined($total_results)) {
1873: $r->print("A MySQL error has occurred.</form></body></html>");
1874: &Apache::lonnet::logthis("lonmysql was unable to determine the number".
1875: " of rows in table ".$table);
1876: &Apache::lonnet::logthis(&Apache::lonmysql::get_error());
1877: return;
1878: }
1879: my $result;
1880: $result.=<<END;
1881: <html>
1882: <head>
1883: <script>
1884: function change_sort() {
1885: var newloc = "/adm/searchcat?phase=results";
1886: newloc += "&persistent_db_id=$ENV{'form.persistent_db_id'}";
1887: newloc += "&sortby=";
1888: newloc += document.forms.statusform.elements.sortby.value;
1889: parent.resultsframe.location= newloc;
1890: }
1891: </script>
1892: <title>Results</title>
1893: </head>
1.155 matthew 1894: $bodytag
1.151 matthew 1895: <form name="statusform" action="" method="post">
1.153 matthew 1896: <input type="hidden" name="Queue" value="" />
1.151 matthew 1897: END
1898:
1899: #<h2>Sort Results</h2>
1900: #Sort by: <select size="1" name="sortby" onchange="javascript:change_sort();">
1901: # $ENV{'form.sortby'} = 'id' if (! defined($ENV{'form.sortby'}));
1902: # foreach (keys(%SortableFields)) {
1903: # $result.="<option name=\"$_\"";
1904: # if ($_ eq $ENV{'form.sortby'}) {
1905: # $result.=" selected ";
1906: # }
1907: # $result.=" >$SortableFields{$_}</option>\n";
1908: # }
1909: # $result.="</select>\n";
1910: my $revise = &revise_button();
1911: $result.=<<END;
1912: <p>
1913: There are $total_results matches to your query. $revise
1914: </p><p>
1915: Search:$pretty_query_string
1916: </p>
1917: </form>
1918: </body>
1919: </html>
1920: END
1921: $r->print($result);
1922: return;
1923: }
1924:
1.144 matthew 1925: #####################################################################
1926: #####################################################################
1927:
1928: =pod
1929:
1930: =item MySQL Table Description
1931:
1932: MySQL table creation requires a precise description of the data to be
1933: stored. The use of the correct types to hold data is vital to efficient
1934: storage and quick retrieval of records. The columns must be described in
1935: the following format:
1936:
1937: =cut
1938:
1.170 matthew 1939: #####################################################################
1940: #####################################################################
1941:
1942: my @Datatypes =
1943: ( { name => 'id',
1944: type => 'MEDIUMINT',
1945: restrictions => 'UNSIGNED NOT NULL',
1946: primary_key => 'yes',
1947: auto_inc => 'yes' },
1948: { name => 'title', type=>'TEXT'},
1949: { name => 'author', type=>'TEXT'},
1950: { name => 'subject', type=>'TEXT'},
1951: { name => 'url', type=>'TEXT', restrictions => 'NOT NULL' },
1952: { name => 'keywords', type=>'TEXT'},
1953: { name => 'version', type=>'TEXT'},
1954: { name => 'notes', type=>'TEXT'},
1955: { name => 'abstract', type=>'TEXT'},
1956: { name => 'mime', type=>'TEXT'},
1957: { name => 'lang', type=>'TEXT'},
1958: { name => 'owner', type=>'TEXT'},
1959: { name => 'copyright', type=>'TEXT'},
1960: { name => 'hostname', type=>'TEXT'},
1.144 matthew 1961: #--------------------------------------------------
1.170 matthew 1962: { name => 'creationdate', type=>'DATETIME'},
1963: { name => 'lastrevisiondate', type=>'DATETIME'},
1.144 matthew 1964: #--------------------------------------------------
1965: );
1966:
1.147 matthew 1967: my @Fullindicies =
1.151 matthew 1968: qw/title/;
1969: # qw/title author subject abstract mime language owner copyright/;
1.147 matthew 1970:
1.144 matthew 1971: ######################################################################
1972: ######################################################################
1973:
1974: =pod
1975:
1.146 matthew 1976: =item &create_results_table()
1977:
1978: Creates the table of search results by calling lonmysql. Stores the
1979: table id in $ENV{'form.table'}
1980:
1981: Inputs: none.
1982:
1983: Returns: the identifier of the table on success, undef on error.
1984:
1985: =cut
1986:
1987: ######################################################################
1988: ######################################################################
1989: sub create_results_table {
1990: my $table = &Apache::lonmysql::create_table
1.170 matthew 1991: ( { columns => \@Datatypes,
1.172 matthew 1992: FULLTEXT => [{'columns' => \@Fullindicies},],
1.146 matthew 1993: } );
1994: if (defined($table)) {
1995: $ENV{'form.table'} = $table;
1996: return $table;
1997: }
1998: return undef; # Error...
1999: }
1.148 matthew 2000:
1.146 matthew 2001: ######################################################################
2002: ######################################################################
2003:
2004: =pod
2005:
1.150 matthew 2006: =item Search Status update functions
1.144 matthew 2007:
1.150 matthew 2008: Each of the following functions changes the values of one of the
2009: input fields used to display the search status to the user. The names
2010: should be explanatory.
1.144 matthew 2011:
1.150 matthew 2012: Inputs: Apache request handler ($r), text to display.
1.148 matthew 2013:
1.150 matthew 2014: Returns: Nothing.
1.148 matthew 2015:
2016: =over 4
2017:
2018: =item &update_count_status()
2019:
1.150 matthew 2020: =item &update_status()
1.148 matthew 2021:
1.150 matthew 2022: =item &update_seconds()
1.148 matthew 2023:
2024: =back
2025:
2026: =cut
2027:
2028: ######################################################################
2029: ######################################################################
2030: sub update_count_status {
2031: my ($r,$text) = @_;
2032: $text =~ s/\'/\\\'/g;
2033: $r->print
2034: ("<script>document.statusform.count.value = ' $text'</script>\n");
2035: $r->rflush();
2036: }
2037:
1.150 matthew 2038: sub update_status {
1.148 matthew 2039: my ($r,$text) = @_;
2040: $text =~ s/\'/\\\'/g;
2041: $r->print
1.150 matthew 2042: ("<script>document.statusform.status.value = ' $text'</script>\n");
1.148 matthew 2043: $r->rflush();
2044: }
2045:
1.150 matthew 2046: sub update_seconds {
1.148 matthew 2047: my ($r,$text) = @_;
2048: $text =~ s/\'/\\\'/g;
2049: $r->print
1.150 matthew 2050: ("<script>document.statusform.seconds.value = ' $text'</script>\n");
1.148 matthew 2051: $r->rflush();
2052: }
2053:
2054: ######################################################################
2055: ######################################################################
2056:
2057: =pod
2058:
1.151 matthew 2059: =item &revise_button
2060:
2061: Inputs: None
2062:
2063: Returns: html string for a 'revise search' button.
2064:
2065: =cut
2066:
2067: ######################################################################
2068: ######################################################################
2069: sub revise_button {
2070: my $revise_phase = 'disp_basic';
2071: $revise_phase = 'disp_adv' if ($ENV{'form.searchmode'} eq 'advanced');
2072: my $newloc = '/adm/searchcat'.
2073: '?persistent_db_id='.$ENV{'form.persistent_db_id'}.
1.158 matthew 2074: '&cleargroupsort=1'.
1.151 matthew 2075: '&phase='.$revise_phase;
2076: my $result = qq{<input type="button" value="Revise search" name="revise"} .
2077: qq{ onClick="parent.location='$newloc';" /> };
2078: return $result;
2079: }
2080:
2081: ######################################################################
2082: ######################################################################
2083:
2084: =pod
2085:
1.144 matthew 2086: =item &run_search
2087:
2088: =cut
2089:
2090: ######################################################################
2091: ######################################################################
2092: sub run_search {
1.146 matthew 2093: my ($r,$query,$customquery,$customshow,$serverlist,$pretty_string) = @_;
1.150 matthew 2094: my $connection = $r->connection;
1.144 matthew 2095: #
1.145 matthew 2096: # Timing variables
2097: #
2098: my $starttime = time;
1.151 matthew 2099: my $max_time = 30; # seconds for the search to complete
1.145 matthew 2100: #
1.146 matthew 2101: # Print run_search header
2102: #
1.151 matthew 2103: $r->print(<<END);
2104: <html>
2105: <head><title>Search Status</title></head>
1.155 matthew 2106: $bodytag
1.151 matthew 2107: <form name="statusform" action="" method="post">
2108: <input type="hidden" name="Queue" value="" />
2109: END
2110: # Check to see if $pretty_string has more than one carriage return.
2111: # Assume \n s are following <br /> s and truncate the value.
2112: # (there is probably a better way)...
1.152 matthew 2113: my @Lines = split /<br \/>/,$pretty_string;
2114: if (@Lines > 2) {
2115: $pretty_string = join '<br \>',(@Lines[0..2],'....<br />');
1.151 matthew 2116: }
1.187 www 2117: $r->print(&mt("Search").": ".$pretty_string);
1.146 matthew 2118: $r->rflush();
2119: #
1.145 matthew 2120: # Determine the servers we need to contact.
2121: #
1.144 matthew 2122: my @Servers_to_contact;
2123: if (defined($serverlist)) {
1.152 matthew 2124: if (ref($serverlist) eq 'ARRAY') {
2125: @Servers_to_contact = @$serverlist;
2126: } else {
2127: @Servers_to_contact = ($serverlist);
2128: }
1.144 matthew 2129: } else {
2130: @Servers_to_contact = sort(keys(%Apache::lonnet::libserv));
2131: }
2132: my %Server_status;
1.146 matthew 2133: my $table =$ENV{'form.table'};
1.150 matthew 2134: if (! defined($table) || $table eq '' || $table =~ /\D/ ) {
1.147 matthew 2135: $r->print("Unable to determine table id to store search results in.".
1.148 matthew 2136: "The search has been aborted.</body></html>");
1.147 matthew 2137: return;
2138: }
2139: my $table_status = &Apache::lonmysql::check_table($table);
2140: if (! defined($table_status)) {
2141: $r->print("Unable to determine status of table.</body></html>");
2142: &Apache::lonnet::logthis("Bogus table id of $table for ".
2143: "$ENV{'user.name'} @ $ENV{'user.domain'}");
2144: &Apache::lonnet::logthis("lonmysql error = ".
1.144 matthew 2145: &Apache::lonmysql::get_error());
1.147 matthew 2146: return;
2147: }
2148: if (! $table_status) {
2149: $r->print("The table id,$table, we tried to use is invalid.".
1.148 matthew 2150: "The search has been aborted.</body></html>");
1.144 matthew 2151: return;
2152: }
1.145 matthew 2153: ##
1.146 matthew 2154: ## Prepare for the big loop.
2155: ##
1.144 matthew 2156: my $hitcountsum;
2157: my $server;
2158: my $status;
1.151 matthew 2159: my $revise = &revise_button();
1.148 matthew 2160: $r->print(<<END);
2161: <table>
1.151 matthew 2162: <tr><th>Status</th><th>Total Matches</th><th>Time Remaining</th><th></th></tr>
1.148 matthew 2163: <tr>
1.150 matthew 2164: <td><input type="text" name="status" value="" size="30" /></td>
2165: <td><input type="text" name="count" value="" size="10" /></td>
2166: <td><input type="text" name="seconds" value="" size="8" /></td>
1.151 matthew 2167: <td>$revise</td>
1.148 matthew 2168: </tr>
2169: </table>
2170: </form>
2171: END
2172: $r->rflush();
1.150 matthew 2173: my $time_remaining = $max_time - (time - $starttime) ;
2174: my $last_time = $time_remaining;
2175: &update_seconds($r,$time_remaining);
1.178 matthew 2176: &update_status($r,'contacting '.$Servers_to_contact[0]);
1.159 matthew 2177: while (($time_remaining > 0) &&
1.144 matthew 2178: ((@Servers_to_contact) || keys(%Server_status))) {
2179: # Send out a search request if it needs to be done.
2180: if (@Servers_to_contact) {
2181: # Contact one server
2182: my $server = shift(@Servers_to_contact);
1.189 ! www 2183: &update_status($r,&mt('contacting').' '.$server);
1.144 matthew 2184: my $reply=&Apache::lonnet::metadata_query($query,$customquery,
2185: $customshow,[$server]);
2186: ($server) = keys(%$reply);
2187: $Server_status{$server} = $reply->{$server};
2188: } else {
1.150 matthew 2189: # wait a sec. to give time for files to be written
2190: # This sleep statement is here instead of outside the else
2191: # block because we do not want to pause if we have servers
2192: # left to contact.
1.183 matthew 2193: if (scalar (keys(%Server_status))) {
2194: &update_status($r,
1.189 ! www 2195: &mt('waiting on').' '.(join(' ',keys(%Server_status))));
1.183 matthew 2196: }
1.150 matthew 2197: sleep(1);
1.144 matthew 2198: }
1.159 matthew 2199: #
2200: #
2201: # Loop through the servers we have contacted but do not
2202: # have results from yet, looking for results.
1.144 matthew 2203: while (my ($server,$status) = each(%Server_status)) {
1.150 matthew 2204: last if ($connection->aborted());
1.144 matthew 2205: if ($status eq 'con_lost') {
2206: delete ($Server_status{$server});
2207: next;
2208: }
2209: $status=~/^([\.\w]+)$/;
2210: my $datafile=$r->dir_config('lonDaemons').'/tmp/'.$1;
2211: if (-e $datafile && ! -e "$datafile.end") {
1.189 ! www 2212: &update_status($r,&mt('Receiving results from').' '.$server);
1.144 matthew 2213: next;
2214: }
1.150 matthew 2215: last if ($connection->aborted());
1.144 matthew 2216: if (-e "$datafile.end") {
1.189 ! www 2217: &update_status($r,&mt('Reading results from').' '.$server);
1.144 matthew 2218: if (-z "$datafile") {
2219: delete($Server_status{$server});
2220: next;
2221: }
2222: my $fh;
2223: if (!($fh=Apache::File->new($datafile))) {
1.146 matthew 2224: $r->print("Unable to open search results file for ".
1.145 matthew 2225: "server $server. Omitting from search");
1.150 matthew 2226: delete($Server_status{$server});
2227: next;
1.144 matthew 2228: }
2229: # Read in the whole file.
2230: while (my $result = <$fh>) {
1.150 matthew 2231: last if ($connection->aborted());
1.144 matthew 2232: # handle custom fields? Someday we will!
2233: chomp($result);
2234: next unless $result;
2235: # Parse the result.
2236: my %Fields = &parse_raw_result($result,$server);
2237: $Fields{'hostname'} = $server;
2238: next if (! ©right_check(\%Fields));
2239: # Store the result in the mysql database
2240: my $result = &Apache::lonmysql::store_row($table,\%Fields);
2241: if (! defined($result)) {
1.146 matthew 2242: $r->print(&Apache::lonmysql::get_error());
1.144 matthew 2243: }
1.146 matthew 2244: # $r->print(&Apache::lonmysql::get_debug());
1.144 matthew 2245: $hitcountsum ++;
1.150 matthew 2246: $time_remaining = $max_time - (time - $starttime) ;
2247: if ($last_time - $time_remaining > 0) {
2248: &update_seconds($r,$time_remaining);
2249: $last_time = $time_remaining;
2250: }
2251: if ($hitcountsum % 50 == 0) {
2252: &update_count_status($r,$hitcountsum);
2253: }
1.144 matthew 2254: } # End of foreach (@results)
2255: $fh->close();
2256: # $server is only deleted if the results file has been
2257: # found and (successfully) opened. This may be a bad idea.
2258: delete($Server_status{$server});
2259: }
1.150 matthew 2260: last if ($connection->aborted());
1.148 matthew 2261: &update_count_status($r,$hitcountsum);
1.144 matthew 2262: }
1.150 matthew 2263: last if ($connection->aborted());
1.144 matthew 2264: # Finished looping through the servers
1.159 matthew 2265: $starttime = time if (@Servers_to_contact);
1.150 matthew 2266: $time_remaining = $max_time - (time - $starttime) ;
2267: if ($last_time - $time_remaining > 0) {
2268: $last_time = $time_remaining;
2269: &update_seconds($r,$time_remaining);
2270: }
1.144 matthew 2271: }
1.189 ! www 2272: &update_status($r,&mt('Search Complete').$server);
1.151 matthew 2273: &update_seconds($r,0);
1.144 matthew 2274: &Apache::lonmysql::disconnect_from_db();
2275: # We have run out of time or run out of servers to talk to and
2276: # results to get.
1.146 matthew 2277: $r->print("</body></html>");
1.153 matthew 2278: if ($ENV{'form.catalogmode'} ne 'groupsearch') {
2279: $r->print("<script>".
2280: "window.location='/adm/searchcat?".
2281: "phase=sort&".
2282: "persistent_db_id=$ENV{'form.persistent_db_id'}';".
2283: "</script>");
2284: }
1.144 matthew 2285: return;
2286: }
2287:
2288: ######################################################################
2289: ######################################################################
2290: =pod
2291:
1.146 matthew 2292: =item &prev_next_buttons
1.144 matthew 2293:
2294: =cut
2295:
2296: ######################################################################
2297: ######################################################################
1.146 matthew 2298: sub prev_next_buttons {
1.145 matthew 2299: my ($current_min,$show,$total,$parms) = @_;
2300: return '' if ($show eq 'all'); # No links if you get them all at once.
2301: my $links;
2302: ##
2303: ## Prev
2304: my $prev_min = $current_min - $show;
1.151 matthew 2305: $prev_min = 1 if $prev_min < 1;
1.145 matthew 2306: if ($prev_min < $current_min) {
2307: $links .= qq{
1.146 matthew 2308: <a href="/adm/searchcat?$parms&start=$prev_min&show=$show">prev</a>
1.145 matthew 2309: };
1.146 matthew 2310: } else {
2311: $links .= 'prev';
1.145 matthew 2312: }
2313: ##
2314: ## Pages.... Someday.
2315: ##
1.146 matthew 2316: $links .= qq{
2317: <a href="/adm/searchcat?$parms&start=$current_min&$show=$show">reload</a>
2318: };
1.145 matthew 2319: ##
2320: ## Next
2321: my $next_min = $current_min + $show;
1.146 matthew 2322: $next_min = $current_min if ($next_min > $total);
1.145 matthew 2323: if ($next_min != $current_min) {
1.146 matthew 2324: $links .= qq{
2325: <a href="/adm/searchcat?$parms&start=$next_min&show=$show">next</a>
1.145 matthew 2326: };
1.146 matthew 2327: } else {
2328: $links .= ' next';
1.144 matthew 2329: }
1.145 matthew 2330: return $links;
1.144 matthew 2331: }
2332: ######################################################################
2333: ######################################################################
2334:
2335: =pod
2336:
2337: =item &display_results
2338:
2339: =cut
2340:
2341: ######################################################################
2342: ######################################################################
2343: sub display_results {
1.150 matthew 2344: my ($r,$importbutton,$closebutton) = @_;
2345: my $connection = $r->connection;
2346: $r->print(&search_results_header($importbutton,$closebutton));
1.144 matthew 2347: ##
2348: ## Set viewing function
2349: ##
2350: my $viewfunction = $Views{$ENV{'form.viewselect'}};
2351: if (!defined($viewfunction)) {
2352: $r->print("Internal Error - Bad view selected.\n");
2353: $r->rflush();
2354: return;
2355: }
2356: ##
1.158 matthew 2357: ## $checkbox_num is a count of the number of checkboxes output on the
2358: ## page this is used only during catalogmode=groupsearch.
2359: my $checkbox_num = 0;
2360: ##
1.144 matthew 2361: ## Get the catalog controls setup
2362: ##
1.146 matthew 2363: my $action = "/adm/searchcat?phase=results";
2364: ##
1.147 matthew 2365: ## Deal with groupsearch
1.146 matthew 2366: ##
2367: if ($ENV{'form.catalogmode'} eq 'groupsearch') {
2368: if (! tie(%groupsearch_db,'GDBM_File',$diropendb,
1.148 matthew 2369: &GDBM_WRCREAT(),0640)) {
1.150 matthew 2370: $r->print('Unable to store import results.</form></body></html>');
1.146 matthew 2371: $r->rflush();
2372: return;
2373: }
1.144 matthew 2374: }
1.145 matthew 2375: ##
2376: ## Prepare the table for querying
2377: ##
1.144 matthew 2378: my $table = $ENV{'form.table'};
1.151 matthew 2379: return if (! &ensure_db_and_table($r,$table));
1.145 matthew 2380: ##
2381: ## Get the number of results
2382: ##
2383: my $total_results = &Apache::lonmysql::number_of_rows($table);
2384: if (! defined($total_results)) {
1.150 matthew 2385: $r->print("A MySQL error has occurred.</form></body></html>");
1.145 matthew 2386: &Apache::lonnet::logthis("lonmysql was unable to determine the number".
2387: " of rows in table ".$table);
2388: &Apache::lonnet::logthis(&Apache::lonmysql::get_error());
2389: return;
2390: }
2391: ##
2392: ## Determine how many results we need to get
2393: ##
1.151 matthew 2394: $ENV{'form.start'} = 1 if (! exists($ENV{'form.start'}));
2395: $ENV{'form.show'} = 'all' if (! exists($ENV{'form.show'}));
1.146 matthew 2396: my $min = $ENV{'form.start'};
1.145 matthew 2397: my $max;
2398: if ($ENV{'form.show'} eq 'all') {
2399: $max = $total_results ;
2400: } else {
1.151 matthew 2401: $max = $min + $ENV{'form.show'} - 1;
1.146 matthew 2402: $max = $total_results if ($max > $total_results);
1.145 matthew 2403: }
2404: ##
2405: ## Output links (if necessary) for 'prev' and 'next' pages.
2406: ##
1.146 matthew 2407: $r->print
1.148 matthew 2408: ('<center>'.
1.146 matthew 2409: &prev_next_buttons($min,$ENV{'form.show'},$total_results,
2410: "table=".$ENV{'form.table'}.
2411: "&phase=results".
2412: "&persistent_db_id=".$ENV{'form.persistent_db_id'})
1.148 matthew 2413: ."</center>\n"
1.146 matthew 2414: );
1.150 matthew 2415: if ($total_results == 0) {
1.181 matthew 2416: $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="1">'.
1.187 www 2417: '<h3>'.&mt('There are currently no results').'.</h3>'.
1.150 matthew 2418: "</form></body></html>");
2419: return;
2420: } else {
2421: $r->print
2422: ("<center>Results $min to $max out of $total_results</center>\n");
2423: }
1.145 matthew 2424: ##
2425: ## Get results from MySQL table
2426: ##
2427: my @Results = &Apache::lonmysql::get_rows($table,
1.151 matthew 2428: 'id>='.$min.' AND id<='.$max);
1.145 matthew 2429: ##
2430: ## Loop through the results and output them.
2431: ##
1.144 matthew 2432: foreach my $row (@Results) {
1.150 matthew 2433: if ($connection->aborted()) {
1.162 www 2434: &cleanup();
1.150 matthew 2435: return;
2436: }
1.144 matthew 2437: my %Fields = %{&parse_row(@$row)};
1.145 matthew 2438: my $output="<p>\n";
1.158 matthew 2439: my $prefix=&catalogmode_output($Fields{'title'},$Fields{'url'},
2440: $Fields{'id'},$checkbox_num++);
1.144 matthew 2441: # Render the result into html
1.150 matthew 2442: $output.= &$viewfunction($prefix,%Fields);
1.145 matthew 2443: # Print them out as they come in.
1.144 matthew 2444: $r->print($output);
2445: $r->rflush();
2446: }
2447: if (@Results < 1) {
1.187 www 2448: $r->print(&mt("There were no results matching your query"));
1.147 matthew 2449: } else {
2450: $r->print
1.148 matthew 2451: ('<center>'.
1.147 matthew 2452: &prev_next_buttons($min,$ENV{'form.show'},$total_results,
2453: "table=".$ENV{'form.table'}.
2454: "&phase=results".
2455: "&persistent_db_id=".
2456: $ENV{'form.persistent_db_id'})
1.148 matthew 2457: ."</center>\n"
1.147 matthew 2458: );
1.144 matthew 2459: }
1.150 matthew 2460: $r->print("</form></body></html>");
1.144 matthew 2461: $r->rflush();
1.150 matthew 2462: untie %groupsearch_db if (tied(%groupsearch_db));
1.144 matthew 2463: return;
2464: }
2465:
2466: ######################################################################
2467: ######################################################################
2468:
2469: =pod
2470:
1.158 matthew 2471: =item &catalogmode_output($title,$url,$fnum,$checkbox_num)
1.145 matthew 2472:
2473: Returns html needed for the various catalog modes. Gets inputs from
1.158 matthew 2474: $ENV{'form.catalogmode'}. Stores data in %groupsearch_db.
1.145 matthew 2475:
2476: =cut
2477:
2478: ######################################################################
2479: ######################################################################
2480: sub catalogmode_output {
2481: my $output = '';
1.158 matthew 2482: my ($title,$url,$fnum,$checkbox_num) = @_;
1.145 matthew 2483: if ($ENV{'form.catalogmode'} eq 'interactive') {
1.150 matthew 2484: $title=~ s/\'/\\\'/g;
1.145 matthew 2485: if ($ENV{'form.catalogmode'} eq 'interactive') {
2486: $output.=<<END
2487: <font size='-1'><INPUT TYPE="button" NAME="returnvalues" VALUE="SELECT"
2488: onClick="javascript:select_data('$title','$url')">
2489: </font>
2490: END
2491: }
1.150 matthew 2492: } elsif ($ENV{'form.catalogmode'} eq 'groupsearch') {
1.145 matthew 2493: $groupsearch_db{"pre_${fnum}_link"}=$url;
2494: $groupsearch_db{"pre_${fnum}_title"}=$title;
2495: $output.=<<END;
2496: <font size='-1'>
2497: <input type="checkbox" name="returnvalues" value="SELECT"
1.158 matthew 2498: onClick="javascript:queue($checkbox_num,$fnum)" />
1.145 matthew 2499: </font>
2500: END
2501: }
2502: return $output;
2503: }
2504: ######################################################################
2505: ######################################################################
2506:
2507: =pod
2508:
1.144 matthew 2509: =item &parse_row
2510:
2511: Parse a row returned from the database.
2512:
2513: =cut
2514:
2515: ######################################################################
2516: ######################################################################
2517: sub parse_row {
2518: my @Row = @_;
2519: my %Fields;
2520: for (my $i=0;$i<=$#Row;$i++) {
1.170 matthew 2521: $Fields{$Datatypes[$i]->{'name'}}=&Apache::lonnet::unescape($Row[$i]);
1.144 matthew 2522: }
2523: $Fields{'language'} =
2524: &Apache::loncommon::languagedescription($Fields{'lang'});
2525: $Fields{'copyrighttag'} =
2526: &Apache::loncommon::copyrightdescription($Fields{'copyright'});
2527: $Fields{'mimetag'} =
2528: &Apache::loncommon::filedescription($Fields{'mime'});
2529: return \%Fields;
2530: }
1.126 matthew 2531:
2532: ###########################################################
2533: ###########################################################
2534:
2535: =pod
2536:
2537: =item &parse_raw_result()
2538:
2539: Takes a line from the file of results and parse it. Returns a hash
2540: with keys for the following fields:
2541: 'title', 'author', 'subject', 'url', 'keywords', 'version', 'notes',
2542: 'abstract', 'mime', 'lang', 'owner', 'copyright', 'creationdate',
2543: 'lastrevisiondate'.
2544:
2545: In addition, the following tags are set by calling the appropriate
2546: lonnet function: 'language', 'cprtag', 'mimetag'.
2547:
2548: The 'title' field is set to "Untitled" if the title field is blank.
2549:
2550: 'abstract' and 'keywords' are truncated to 200 characters.
2551:
2552: =cut
2553:
2554: ###########################################################
2555: ###########################################################
2556: sub parse_raw_result {
2557: my ($result,$hostname) = @_;
2558: # Check for a comma - if it is there then we do not need to unescape the
2559: # string. There seems to be some kind of problem with some items in
2560: # the database - the entire string gets sent out unescaped...?
2561: unless ($result =~ /,/) {
2562: $result = &Apache::lonnet::unescape($result);
2563: }
2564: my @fields=map {
2565: &Apache::lonnet::unescape($_);
2566: } (split(/\,/,$result));
2567: my ($title,$author,$subject,$url,$keywords,$version,
2568: $notes,$abstract,$mime,$lang,
2569: $creationdate,$lastrevisiondate,$owner,$copyright)=@fields;
2570: my %Fields =
2571: ( title => &Apache::lonnet::unescape($title),
2572: author => &Apache::lonnet::unescape($author),
2573: subject => &Apache::lonnet::unescape($subject),
2574: url => &Apache::lonnet::unescape($url),
2575: keywords => &Apache::lonnet::unescape($keywords),
2576: version => &Apache::lonnet::unescape($version),
2577: notes => &Apache::lonnet::unescape($notes),
2578: abstract => &Apache::lonnet::unescape($abstract),
2579: mime => &Apache::lonnet::unescape($mime),
2580: lang => &Apache::lonnet::unescape($lang),
2581: owner => &Apache::lonnet::unescape($owner),
2582: copyright => &Apache::lonnet::unescape($copyright),
2583: creationdate => &Apache::lonnet::unescape($creationdate),
2584: lastrevisiondate => &Apache::lonnet::unescape($lastrevisiondate)
2585: );
2586: $Fields{'language'} =
2587: &Apache::loncommon::languagedescription($Fields{'lang'});
2588: $Fields{'copyrighttag'} =
2589: &Apache::loncommon::copyrightdescription($Fields{'copyright'});
2590: $Fields{'mimetag'} =
2591: &Apache::loncommon::filedescription($Fields{'mime'});
1.134 matthew 2592: if ($Fields{'author'}=~/^(\s*|error)$/) {
2593: $Fields{'author'}="Unknown Author";
2594: }
1.126 matthew 2595: # Put spaces in the keyword list, if needed.
2596: $Fields{'keywords'}=~ s/,([A-z])/, $1/g;
2597: if ($Fields{'title'}=~ /^\s*$/ ) {
2598: $Fields{'title'}='Untitled';
2599: }
2600: unless ($ENV{'user.adv'}) {
1.144 matthew 2601: # What is this anyway?
1.126 matthew 2602: $Fields{'keywords'} = '- not displayed -';
2603: $Fields{'notes'} = '- not displayed -';
2604: $Fields{'abstract'} = '- not displayed -';
2605: $Fields{'subject'} = '- not displayed -';
2606: }
2607: if (length($Fields{'abstract'})>200) {
2608: $Fields{'abstract'} =
2609: substr($Fields{'abstract'},0,200).'...';
2610: }
2611: if (length($Fields{'keywords'})>200) {
2612: $Fields{'keywords'} =
2613: substr($Fields{'keywords'},0,200).'...';
2614: }
2615: return %Fields;
2616: }
2617:
2618: ###########################################################
2619: ###########################################################
2620:
2621: =pod
2622:
2623: =item &handle_custom_fields()
2624:
2625: =cut
2626:
2627: ###########################################################
2628: ###########################################################
2629: sub handle_custom_fields {
2630: my @results = @{shift()};
2631: my $customshow='';
2632: my $extrashow='';
2633: my @customfields;
2634: if ($ENV{'form.customshow'}) {
2635: $customshow=$ENV{'form.customshow'};
2636: $customshow=~s/[^\w\s]//g;
2637: my @fields=map {
2638: "<font color=\"#008000\">$_:</font><!-- $_ -->";
2639: } split(/\s+/,$customshow);
2640: @customfields=split(/\s+/,$customshow);
2641: if ($customshow) {
2642: $extrashow="<ul><li>".join("</li><li>",@fields)."</li></ul>\n";
2643: }
2644: }
2645: my $customdata='';
2646: my %customhash;
2647: foreach my $result (@results) {
2648: if ($result=~/^(custom\=.*)$/) { # grab all custom metadata
2649: my $tmp=$result;
2650: $tmp=~s/^custom\=//;
2651: my ($k,$v)=map {&Apache::lonnet::unescape($_);
2652: } split(/\,/,$tmp);
2653: $customhash{$k}=$v;
2654: }
2655: }
2656: return ($extrashow,\@customfields,\%customhash);
1.41 harris41 2657: }
2658:
1.122 matthew 2659: ######################################################################
2660: ######################################################################
2661:
1.125 matthew 2662: =pod
2663:
2664: =item &search_results_header
2665:
1.130 matthew 2666: Output the proper html headers and javascript code to deal with different
2667: calling modes.
2668:
2669: Takes most inputs directly from %ENV, except $mode.
2670:
2671: =over 4
2672:
2673: =item $mode is either (at this writing) 'Basic' or 'Advanced'
2674:
2675: =back
1.126 matthew 2676:
1.130 matthew 2677: The following environment variables are checked:
1.126 matthew 2678:
2679: =over 4
2680:
2681: =item 'form.catalogmode'
2682:
2683: Checked for 'interactive' and 'groupsearch'.
2684:
2685: =item 'form.mode'
2686:
2687: Checked for existance & 'edit' mode.
2688:
2689: =item 'form.form'
2690:
2691: =item 'form.element'
2692:
2693: =back
2694:
1.125 matthew 2695: =cut
2696:
2697: ######################################################################
2698: ######################################################################
2699: sub search_results_header {
1.150 matthew 2700: my ($importbutton,$closebutton) = @_;
1.125 matthew 2701: my $result = '';
2702: # output beginning of search page
2703: # conditional output of script functions dependent on the mode in
2704: # which the search was invoked
2705: if ($ENV{'form.catalogmode'} eq 'interactive'){
2706: if (! exists($ENV{'form.mode'}) || $ENV{'form.mode'} ne 'edit') {
2707: $result.=<<SCRIPT;
2708: <script type="text/javascript">
2709: function select_data(title,url) {
2710: changeTitle(title);
2711: changeURL(url);
1.150 matthew 2712: parent.close();
1.125 matthew 2713: }
2714: function changeTitle(val) {
1.153 matthew 2715: if (parent.opener.inf.document.forms.resinfo.elements.t) {
2716: parent.opener.inf.document.forms.resinfo.elements.t.value=val;
1.125 matthew 2717: }
2718: }
2719: function changeURL(val) {
1.153 matthew 2720: if (parent.opener.inf.document.forms.resinfo.elements.u) {
2721: parent.opener.inf.document.forms.resinfo.elements.u.value=val;
1.125 matthew 2722: }
2723: }
2724: </script>
2725: SCRIPT
2726: } elsif ($ENV{'form.mode'} eq 'edit') {
2727: my $form = $ENV{'form.form'};
2728: my $element = $ENV{'form.element'};
2729: $result.=<<SCRIPT;
2730: <script type="text/javascript">
2731: function select_data(title,url) {
2732: changeURL(url);
1.150 matthew 2733: parent.close();
1.125 matthew 2734: }
2735: function changeTitle(val) {
2736: }
2737: function changeURL(val) {
1.150 matthew 2738: if (parent.targetwin.document) {
2739: parent.targetwin.document.forms["$form"].elements["$element"].value=val;
1.125 matthew 2740: } else {
2741: var url = 'forms[\"$form\"].elements[\"$element\"].value';
2742: alert("Unable to transfer data to "+url);
2743: }
2744: }
2745: </script>
2746: SCRIPT
2747: }
2748: }
2749: $result.=<<SCRIPT if $ENV{'form.catalogmode'} eq 'groupsearch';
2750: <script type="text/javascript">
1.158 matthew 2751: function queue(checkbox_num,val) {
1.185 matthew 2752: if (document.forms.results.returnvalues.length != "undefined" &&
2753: typeof(document.forms.results.returnvalues.length) == "number") {
2754: if (document.forms.results.returnvalues[checkbox_num].checked) {
2755: parent.statusframe.document.forms.statusform.elements.Queue.value +='1a'+val+'b';
2756: } else {
2757: parent.statusframe.document.forms.statusform.elements.Queue.value +='0a'+val+'b';
2758: }
1.150 matthew 2759: } else {
1.185 matthew 2760: if (document.forms.results.returnvalues.checked) {
2761: parent.statusframe.document.forms.statusform.elements.Queue.value +='1a'+val+'b';
2762: } else {
2763: parent.statusframe.document.forms.statusform.elements.Queue.value +='0a'+val+'b';
2764: }
1.150 matthew 2765: }
1.125 matthew 2766: }
2767: function select_group() {
1.150 matthew 2768: parent.window.location=
1.125 matthew 2769: "/adm/groupsort?mode=$ENV{'form.mode'}&catalogmode=groupsearch&acts="+
1.150 matthew 2770: parent.statusframe.document.forms.statusform.elements.Queue.value;
1.125 matthew 2771: }
2772: </script>
2773: SCRIPT
1.130 matthew 2774: $result.=<<END;
2775: </head>
1.155 matthew 2776: $bodytag
1.150 matthew 2777: <form name="results" method="post" action="" >
2778: <input type="hidden" name="Queue" value="" />
2779: $importbutton
1.130 matthew 2780: END
1.125 matthew 2781: return $result;
2782: }
2783:
2784: ######################################################################
2785: ######################################################################
1.146 matthew 2786: sub search_status_header {
2787: return <<ENDSTATUS;
2788: <html><head><title>Search Status</title></head>
1.155 matthew 2789: $bodytag
1.146 matthew 2790: <h3>Search Status</h3>
2791: Sending search request to LON-CAPA servers.<br />
2792: ENDSTATUS
2793: }
2794:
1.150 matthew 2795: sub results_link {
2796: my $basic_link = "/adm/searchcat?"."&table=".$ENV{'form.table'}.
2797: "&persistent_db_id=".$ENV{'form.persistent_db_id'};
2798: my $results_link = $basic_link."&phase=results".
1.151 matthew 2799: "&pause=1"."&start=1";
1.150 matthew 2800: return $results_link;
2801: }
2802:
1.146 matthew 2803: ######################################################################
2804: ######################################################################
2805: sub print_frames_interface {
2806: my $r = shift;
2807: my $basic_link = "/adm/searchcat?"."&table=".$ENV{'form.table'}.
2808: "&persistent_db_id=".$ENV{'form.persistent_db_id'};
2809: my $run_search_link = $basic_link."&phase=run_search";
1.150 matthew 2810: my $results_link = &results_link();
1.146 matthew 2811: my $result = <<"ENDFRAMES";
2812: <html>
2813: <head>
1.150 matthew 2814: <script>
2815: var targetwin = opener;
1.158 matthew 2816: var queue = '';
1.150 matthew 2817: </script>
1.146 matthew 2818: <title>LON-CAPA Digital Library Search Results</title>
2819: </head>
1.176 www 2820: <frameset rows="150,*">
1.146 matthew 2821: <frame name="statusframe" src="$run_search_link">
2822: <frame name="resultsframe" src="$results_link">
2823: </frameset>
2824: </html>
2825: ENDFRAMES
2826:
2827: $r->print($result);
2828: return;
2829: }
2830:
2831: ######################################################################
2832: ######################################################################
1.125 matthew 2833:
1.122 matthew 2834: =pod
2835:
2836: =item Metadata Viewing Functions
2837:
2838: Output is a HTML-ified string.
2839: Input arguments are title, author, subject, url, keywords, version,
2840: notes, short abstract, mime, language, creation date,
1.126 matthew 2841: last revision date, owner, copyright, hostname, and
1.122 matthew 2842: extra custom metadata to show.
2843:
2844: =over 4
2845:
2846: =item &detailed_citation_view()
2847:
2848: =cut
2849:
2850: ######################################################################
2851: ######################################################################
1.50 harris41 2852: sub detailed_citation_view {
1.150 matthew 2853: my ($prefix,%values) = @_;
1.50 harris41 2854: my $result=<<END;
1.150 matthew 2855: <b>$prefix<a href="http://$ENV{'HTTP_HOST'}$values{'url'}"
2856: target='search_preview'>$values{'title'}</a></b>
1.56 harris41 2857: <p>
1.130 matthew 2858: <b>$values{'author'}</b>, <i>$values{'owner'}</i><br />
2859:
2860: <b>Subject: </b> $values{'subject'}<br />
2861: <b>Keyword(s): </b> $values{'keywords'}<br />
2862: <b>Notes: </b> $values{'notes'}<br />
2863: <b>MIME Type: </b> $values{'mimetag'}<br />
2864: <b>Language: </b> $values{'language'}<br />
2865: <b>Copyright/Distribution:</b> $values{'cprtag'}<br />
1.78 harris41 2866: </p>
1.126 matthew 2867: $values{'extrashow'}
1.78 harris41 2868: <p>
1.126 matthew 2869: $values{'shortabstract'}
1.50 harris41 2870: </p>
1.150 matthew 2871: <hr align='left' width='200' noshade />
1.50 harris41 2872: END
2873: return $result;
2874: }
2875:
1.122 matthew 2876: ######################################################################
2877: ######################################################################
2878:
2879: =pod
2880:
2881: =item &summary_view()
2882:
2883: =cut
2884: ######################################################################
2885: ######################################################################
1.50 harris41 2886: sub summary_view {
1.150 matthew 2887: my ($prefix,%values) = @_;
1.50 harris41 2888: my $result=<<END;
1.150 matthew 2889: $prefix<a href="http://$ENV{'HTTP_HOST'}$values{'url'}"
1.126 matthew 2890: target='search_preview'>$values{'author'}</a><br />
2891: $values{'title'}<br />
2892: $values{'owner'} -- $values{'lastrevisiondate'}<br />
2893: $values{'copyrighttag'}<br />
2894: $values{'extrashow'}
1.50 harris41 2895: </p>
1.150 matthew 2896: <hr align='left' width='200' noshade />
1.50 harris41 2897: END
2898: return $result;
2899: }
2900:
1.122 matthew 2901: ######################################################################
2902: ######################################################################
2903:
2904: =pod
2905:
1.150 matthew 2906: =item &compact_view()
2907:
2908: =cut
2909:
2910: ######################################################################
2911: ######################################################################
2912: sub compact_view {
2913: my ($prefix,%values) = @_;
2914: my $result=<<END;
2915: $prefix <a href="http://$ENV{'HTTP_HOST'}$values{'url'}" target='search_preview'>
2916: $values{'title'}</a>
2917: <b>$values{'author'}</b><br />
2918: END
2919: return $result;
2920: }
2921:
2922:
2923: ######################################################################
2924: ######################################################################
2925:
2926: =pod
2927:
1.122 matthew 2928: =item &fielded_format_view()
2929:
2930: =cut
2931:
2932: ######################################################################
2933: ######################################################################
1.50 harris41 2934: sub fielded_format_view {
1.150 matthew 2935: my ($prefix,%values) = @_;
1.50 harris41 2936: my $result=<<END;
1.150 matthew 2937: $prefix
1.126 matthew 2938: <b>URL: </b> <a href="http://$ENV{'HTTP_HOST'}$values{'url'}"
2939: target='search_preview'>$values{'url'}</a>
1.56 harris41 2940: <br />
1.126 matthew 2941: <b>Title:</b> $values{'title'}<br />
2942: <b>Author(s):</b> $values{'author'}<br />
2943: <b>Subject:</b> $values{'subject'}<br />
2944: <b>Keyword(s):</b> $values{'keywords'}<br />
2945: <b>Notes:</b> $values{'notes'}<br />
2946: <b>MIME Type:</b> $values{'mimetag'}<br />
2947: <b>Language:</b> $values{'language'}<br />
2948: <b>Creation Date:</b> $values{'creationdate'}<br />
2949: <b>Last Revision Date:</b> $values{'lastrevisiondate'}<br />
2950: <b>Publisher/Owner:</b> $values{'owner'}<br />
2951: <b>Copyright/Distribution:</b> $values{'copyrighttag'}<br />
2952: <b>Repository Location:</b> $values{'hostname'}<br />
2953: <b>Abstract:</b> $values{'shortabstract'}<br />
2954: $values{'extrashow'}
1.50 harris41 2955: </p>
1.150 matthew 2956: <hr align='left' width='200' noshade />
1.50 harris41 2957: END
2958: return $result;
2959: }
2960:
1.122 matthew 2961: ######################################################################
2962: ######################################################################
2963:
2964: =pod
2965:
2966: =item &xml_sgml_view()
2967:
2968: =back
2969:
2970: =cut
2971:
2972: ######################################################################
2973: ######################################################################
1.50 harris41 2974: sub xml_sgml_view {
1.150 matthew 2975: my ($prefix,%values) = @_;
1.50 harris41 2976: my $result=<<END;
1.150 matthew 2977: $prefix
1.56 harris41 2978: <pre>
2979: <LonCapaResource>
1.126 matthew 2980: <url>$values{'url'}</url>
2981: <title>$values{'title'}</title>
2982: <author>$values{'author'}</author>
2983: <subject>$values{'subject'}</subject>
2984: <keywords>$values{'keywords'}</keywords>
2985: <notes>$values{'notes'}</notes>
1.56 harris41 2986: <mimeInfo>
1.126 matthew 2987: <mime>$values{'mime'}</mime>
2988: <mimetag>$values{'mimetag'}</mimetag>
1.56 harris41 2989: </mimeInfo>
2990: <languageInfo>
1.126 matthew 2991: <language>$values{'lang'}</language>
2992: <languagetag>$values{'language'}</languagetag>
1.56 harris41 2993: </languageInfo>
1.126 matthew 2994: <creationdate>$values{'creationdate'}</creationdate>
2995: <lastrevisiondate>$values{'lastrevisiondate'}</lastrevisiondate>
2996: <owner>$values{'owner'}</owner>
1.56 harris41 2997: <copyrightInfo>
1.126 matthew 2998: <copyright>$values{'copyright'}</copyright>
2999: <copyrighttag>$values{'copyrighttag'}</copyrighttag>
1.56 harris41 3000: </copyrightInfo>
1.126 matthew 3001: <repositoryLocation>$values{'hostname'}</repositoryLocation>
3002: <shortabstract>$values{'shortabstract'}</shortabstract>
1.57 harris41 3003: </LonCapaResource>
1.56 harris41 3004: </pre>
1.126 matthew 3005: $values{'extrashow'}
1.150 matthew 3006: <hr align='left' width='200' noshade />
1.50 harris41 3007: END
3008: return $result;
1.60 harris41 3009: }
3010:
1.122 matthew 3011: ######################################################################
3012: ######################################################################
3013:
3014: =pod
3015:
3016: =item &filled() see if field is filled.
3017:
3018: =cut
3019:
3020: ######################################################################
3021: ######################################################################
1.98 harris41 3022: sub filled {
3023: my ($field)=@_;
3024: if ($field=~/\S/ && $field ne 'any') {
3025: return 1;
1.61 harris41 3026: }
1.98 harris41 3027: else {
3028: return 0;
1.61 harris41 3029: }
1.60 harris41 3030: }
3031:
1.122 matthew 3032: ######################################################################
3033: ######################################################################
3034:
3035: =pod
3036:
3037: =item &output_blank_field_error()
3038:
1.151 matthew 3039: Output a complete page that indicates the user has not filled in enough
3040: information to do a search.
3041:
3042: Inputs: $r (Apache request handle), $closebutton, $parms.
3043:
3044: Returns: nothing
3045:
3046: $parms is extra information to include in the 'Revise search request' link.
3047:
1.122 matthew 3048: =cut
3049:
3050: ######################################################################
3051: ######################################################################
1.98 harris41 3052: sub output_blank_field_error {
1.151 matthew 3053: my ($r,$closebutton,$parms)=@_;
1.98 harris41 3054: # make query information persistent to allow for subsequent revision
3055: $r->print(<<BEGINNING);
3056: <html>
3057: <head>
3058: <title>The LearningOnline Network with CAPA</title>
3059: BEGINNING
3060: $r->print(<<RESULTS);
3061: </head>
1.155 matthew 3062: $bodytag
1.98 harris41 3063: <img align='right' src='/adm/lonIcons/lonlogos.gif' />
3064: <h1>Search Catalog</h1>
3065: <form method="post" action="/adm/searchcat">
1.145 matthew 3066: $hidden_fields
1.151 matthew 3067: <a href="/adm/searchcat?$parms&persistent_db_id=$ENV{'form.persistent_db_id'}"
1.146 matthew 3068: >Revise search request</a>
1.98 harris41 3069: $closebutton
3070: <hr />
1.151 matthew 3071: <h3>Unactionable search query.</h3>
1.98 harris41 3072: <p>
1.151 matthew 3073: You did not fill in enough information for the search to be started.
3074: You need to fill in relevant fields on the search page in order
3075: for a query to be processed.
1.98 harris41 3076: </p>
3077: </body>
3078: </html>
3079: RESULTS
3080: }
3081:
1.122 matthew 3082: ######################################################################
3083: ######################################################################
3084:
3085: =pod
3086:
3087: =item &output_date_error()
3088:
3089: Output a full html page with an error message.
3090:
1.145 matthew 3091: Inputs:
3092:
3093: $r, the request pointer.
3094: $message, the error message for the user.
3095: $closebutton, the specialized close button needed for groupsearch.
3096:
1.122 matthew 3097: =cut
3098:
3099: ######################################################################
3100: ######################################################################
1.60 harris41 3101: sub output_date_error {
1.145 matthew 3102: my ($r,$message,$closebutton)=@_;
1.60 harris41 3103: # make query information persistent to allow for subsequent revision
1.122 matthew 3104: $r->print(<<RESULTS);
1.60 harris41 3105: <html>
3106: <head>
3107: <title>The LearningOnline Network with CAPA</title>
3108: </head>
1.155 matthew 3109: $bodytag
1.98 harris41 3110: <img align='right' src='/adm/lonIcons/lonlogos.gif' />
1.60 harris41 3111: <h1>Search Catalog</h1>
3112: <form method="post" action="/adm/searchcat">
1.145 matthew 3113: $hidden_fields
1.60 harris41 3114: <input type='button' value='Revise search request'
1.98 harris41 3115: onClick='this.form.submit();' />
1.60 harris41 3116: $closebutton
1.98 harris41 3117: <hr />
1.151 matthew 3118: <h3>Error</h3>
1.60 harris41 3119: <p>
3120: $message
3121: </p>
3122: </body>
3123: </html>
3124: RESULTS
1.101 harris41 3125: }
3126:
1.122 matthew 3127: ######################################################################
3128: ######################################################################
3129:
3130: =pod
3131:
3132: =item &start_fresh_session()
3133:
1.142 matthew 3134: Cleans the global %groupsearch_db by removing all fields which begin with
1.122 matthew 3135: 'pre_' or 'store'.
3136:
3137: =cut
3138:
3139: ######################################################################
3140: ######################################################################
1.101 harris41 3141: sub start_fresh_session {
1.142 matthew 3142: delete $groupsearch_db{'mode_catalog'};
3143: foreach (keys %groupsearch_db) {
1.101 harris41 3144: if ($_ =~ /^pre_/) {
1.142 matthew 3145: delete $groupsearch_db{$_};
1.101 harris41 3146: }
3147: if ($_ =~ /^store/) {
1.142 matthew 3148: delete $groupsearch_db{$_};
1.101 harris41 3149: }
1.109 harris41 3150: }
1.3 harris41 3151: }
1.1 www 3152:
3153: 1;
1.162 www 3154:
3155: sub cleanup {
1.163 www 3156: if (tied(%groupsearch_db)) {
3157: &Apache::lonnet::logthis('Cleanup searchcat: groupsearch_db');
3158: unless (untie(%groupsearch_db)) {
3159: &Apache::lonnet::logthis('Failed cleanup searchcat: groupsearch_db');
3160: }
3161: }
1.167 www 3162: &untiehash();
1.162 www 3163: &Apache::lonmysql::disconnect_from_db();
3164: }
1.98 harris41 3165:
1.1 www 3166: __END__
1.105 harris41 3167:
1.121 matthew 3168: =pod
1.105 harris41 3169:
1.121 matthew 3170: =back
1.105 harris41 3171:
3172: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>