File:
[LON-CAPA] /
loncom /
interface /
lonsearchcat.pm
Revision
1.102:
download - view:
text,
annotated -
select for diffs
Wed Oct 17 03:31:34 2001 UTC (22 years, 10 months ago) by
harris41
Branches:
MAIN
CVS tags:
HEAD
masking of metadata info based on user.adv works
also improved time-server cycling... will now
last for 5 minutes.. abort button doesn't yet
work, but plan to have mini-handler for this
soon that produces a semaphore-type file which
is monitored by the status looping
1: # The LearningOnline Network with CAPA
2: #
3: # Search Catalog
4: #
5: # YEAR=2001
6: # 03/08/2001 Scott Harrison
7: # Scott Harrison: 03/12/2001, 03/13/2001, 03/14/2001, 03/15/2001, 03/19/2001
8: # Scott Harrison: 03/20/2001, 03/21/2001, 03/22/2001, 03/26/2001, 03/27/2001
9: # Scott Harrison: 04/02/2001, 08/15/2001, 08/24/2001, 08/25/2001
10: # 10/12,10/14,10/15,10/16 Scott Harrison
11: ###############################################################################
12: ## ##
13: ## ORGANIZATION OF THIS PERL MODULE ##
14: ## ##
15: ## 1. Description of functions ##
16: ## 2. Modules used by this module ##
17: ## 3. Choices for different output views (detailed, summary, xml, etc) ##
18: ## 4. BEGIN block (to be run once after compilation) ##
19: ## 5. Handling routine called via Apache and mod_perl ##
20: ## 6. Other subroutines ##
21: ## ##
22: ###############################################################################
23:
24: # ---------------------------------------------------- Description of functions
25: #
26: #
27: # === WEB HANDLER FUNCTIONS
28: # BEGIN() : run once after compilation to initialize values
29: # handler(server reference) : interacts with the Apache server layer
30: # (for /adm/searchcat URLs)
31: # get_unprocessed_cgi() : reads in critical name/value pairs that may have not
32: # been processed and passed into %ENV by the web server
33: # make_persistent() : makes a set of hidden HTML fields to make
34: # SQL search interface information to be persistent
35: #
36: #
37: # === WEB INTERFACE COMPONENT FUNCTIONS
38: # simpletextfield(name,value) : returns HTML formatted string for simple text
39: # field
40: # simplecheckbox(name,value) : returns HTML formatted string for simple
41: # checkbox
42: # searchphrasefield(title,name,value) : returns HTML formatted string for
43: # a search expression phrase field
44: # dateboxes(name, defaultmonth, defaultday, defaultyear) : returns HTML
45: # formatted string
46: # for a calendar date
47: # selectbox(title,name,value,%HASH=options) : returns HTML formatted string for
48: # a selection box field
49: #
50: #
51: # === SEARCH FUNCTIONS
52: # advancedsearch(server reference, environment reference) : perform a complex
53: # multi-field logical query
54: # basicsearch(server reference, environment reference) : perform a simple
55: # single-field logical query
56: # build_SQL_query(field name, logic) : builds a SQL query string from a
57: # logical expression with AND/OR keywords
58: # build_custommetadata_query(field_name, logic_statement) : builds a perl
59: # regular expression from a logical expression with AND/OR
60: # keywords
61: # recursive_SQL_query_build(field name, reverse notation expression) :
62: # builds a SQL query string from a reverse notation expression
63: # logical expression with AND/OR keywords
64: # build_date_queries(cmonth1, cday1, cyear1, cmonth2, cday2, cyear2,
65: # lmonth1, lday1, lyear1, lmonth2, lday2, lyear2) :
66: # Builds a SQL logic query to check time/date entries.
67: #
68: #
69: # === OUTPUTTING RESULTS FUNCTION
70: # output_results(output mode,
71: # server reference,
72: # environment reference,
73: # reply list reference) : outputs results from search
74: #
75: #
76: # === DIFFERENT WAYS TO VIEW METADATA RECORDS
77: # detailed_citation_view(ORDERED METADATA LIST FOR A RESULT OBJECT INSTANCE) :
78: # see metadata viewing notes below
79: # summary_view(ORDERED METADATA LIST FOR A RESULT OBJECT INSTANCE) :
80: # see metadata viewing notes below
81: # fielded_format_view(ORDERED METADATA LIST FOR A RESULT OBJECT INSTANCE) :
82: # see metadata viewing notes below
83: # xml_sgml_view(ORDERED METADATA LIST FOR A RESULT OBJECT INSTANCE) :
84: # see metadata viewing notes below
85: # ___________________________________________________________________________
86: # | * Metadata viewing notes |
87: # | Output is a HTML-ified string. |
88: # | Input arguments are title, author, subject, url, keywords, version, notes,|
89: # | short abstract, mime, language, creation date, last revision date, owner, |
90: # | copyright, hostname, httphost, and extra custom metadata to show. |
91: # ---------------------------------------------------------------------------
92: #
93: #
94: # === TEST CONDITIONAL FUNCTIONS
95: # filled(field) : determines whether a given field has been filled
96: #
97: #
98: # === ERROR FUNCTIONS
99: # output_blank_field_error(server reference) : outputs a message saying that
100: # more fields need to be filled in
101: # output_date_error(server reference, error message) : outputs
102: # an error message specific to bad date format.
103:
104: package Apache::lonsearchcat;
105:
106: # ------------------------------------------------- modules used by this module
107: use strict;
108: use Apache::Constants qw(:common);
109: use Apache::lonnet();
110: use Apache::File();
111: use CGI qw(:standard);
112: use Text::Query;
113: use GDBM_File;
114:
115: # ---------------------------------------- variables used throughout the module
116:
117: # -- information holders
118: my %language; # holds contents of language.tab
119: my %cprtag; # holds contents of copyright.tab
120: my %mimetag; # holds contents of filetypes.tab
121: my %hostdomains; # matches host name to host domain
122: my %hostips; # matches host name to host ip
123: my %hitcount; # stores number of hits per host
124:
125: # -- dynamically rendered interface components
126: my $closebutton; # button that closes the search window
127: my $importbutton; # button to take the selected results and go to group sorting
128:
129: # -- miscellaneous variables
130: my $scrout; # string that holds portions of the screen output
131: my $yourself; # allows for quickly limiting to oneself
132: my %hash;
133:
134: # ------------------------------------------ choices for different output views
135: # Detailed Citation View ---> sub detailed_citation_view
136: # Summary View ---> sub summary_view
137: # Fielded Format ---> sub fielded_format_view
138: # XML/SGML ---> sub xml_sgml_view
139: my $basicviewselect=<<END;
140: <select name='basicviewselect'>
141: <option value='Detailed Citation View'>Detailed Citation View</option>
142: <option value='Summary View'>Summary View</option>
143: <option value='Fielded Format'>Fielded Format</option>
144: <option value='XML/SGML'>XML/SGML</option>
145: </select>
146: END
147: my $advancedviewselect=<<END;
148: <select name='advancedviewselect'>
149: <option value='Detailed Citation View'>Detailed Citation View</option>
150: <option value='Summary View'>Summary View</option>
151: <option value='Fielded Format'>Fielded Format</option>
152: <option value='XML/SGML'>XML/SGML</option>
153: </select>
154: END
155:
156: # ----------------------------------------------------------------------- BEGIN
157: sub BEGIN {
158: # --------------------------------- Compute various listings of metadata values
159: $language{'any'}='Any language';
160: {
161: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
162: '/language.tab');
163: map {
164: $_=~/(\w+)\s+([\w\s\-]+)/; chomp;
165: $language{$1}=$2;
166: } <$fh>;
167: }
168: $cprtag{'any'}='Any copyright/distribution';
169: {
170: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonIncludes'}.
171: '/copyright.tab');
172: map {
173: $_=~/(\w+)\s+([\w\s\-]+)/; chomp;
174: $cprtag{$1}=$2;
175: } <$fh>;
176: }
177: $mimetag{'any'}='Any type';
178: {
179: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
180: '/filetypes.tab');
181: map {
182: $_=~/(\w+)\s+(\w+)\s+([\w\s\-]+)/; chomp;
183: $mimetag{$1}=".$1 $3";
184: } <$fh>;
185: }
186: {
187: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
188: '/hosts.tab');
189: map {
190: $_=~/(\w+?)\:(\w+?)\:(\w+?)\:(.*)/; chomp;
191: if ($3 eq 'library') {
192: $hostdomains{$1}=$2;
193: $hostips{$1}=$4;
194: }
195: } <$fh>;
196: }
197: }
198:
199: my $diropendb = "";
200: my $domain = "";
201:
202: # ----------------------------- Handling routine called via Apache and mod_perl
203: sub handler {
204: my $r = shift;
205:
206: &get_unprocessed_cgi();
207:
208: $r->content_type('text/html');
209: $r->send_http_header;
210: return OK if $r->header_only;
211:
212: $domain = $r->dir_config('lonDefDomain');
213:
214: $diropendb = "/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_indexer.db";
215:
216: if ($ENV{'form.launch'} eq '1') {
217: if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) {
218: &start_fresh_session();
219: untie %hash;
220: }
221: else {
222: $r->print('<html><head></head><body>Unable to tie hash to db '.
223: 'file</body></html>');
224: return OK;
225: }
226: }
227:
228: # ----------------------------------- configure dynamic components of interface
229: my $hidden='';
230: if ($ENV{'form.catalogmode'} eq 'interactive') {
231: $hidden="<input type='hidden' name='catalogmode' value='interactive'>".
232: "\n";
233: $closebutton="<input type='button' name='close' value='CLOSE' ".
234: "onClick='self.close()'>"."\n";
235: }
236: elsif ($ENV{'form.catalogmode'} eq 'groupsearch') {
237: $hidden=<<END;
238: <input type='hidden' name='catalogmode' value='groupsearch'>
239: END
240: $closebutton=<<END;
241: <input type='button' name='close' value='CLOSE' onClick='self.close()'>
242: END
243: $importbutton=<<END;
244: <input type='button' name='import' value='IMPORT'
245: onClick='javascript:select_group()'>
246: END
247: }
248:
249: # ------------------------------------------------------ Determine current user
250: $yourself=$ENV{'user.name'}.'@'.$ENV{'user.domain'};
251:
252: # --- Now, depending on the interface actions, do one of three things here:
253: # --- 1. a basic search
254: # --- 2. an advanced search
255: # --- 3. output a search interface
256:
257: # ----------------------------------- See if a search invocation should be done
258: if ($ENV{'form.basicsubmit'} eq 'SEARCH') {
259: untie %hash; return &basicsearch($r,\%ENV);
260: }
261: elsif ($ENV{'form.advancedsubmit'} eq 'SEARCH') {
262: untie %hash; return &advancedsearch($r,\%ENV);
263: }
264:
265: # ----------------------------- Else, begin building search interface to output
266: $scrout=''; # building a part of screen output
267: $scrout.=&searchphrasefield('Limit by title','title',
268: $ENV{'form.title'});
269:
270: $scrout.=&searchphrasefield('Limit by author','author',
271: $ENV{'form.author'});
272:
273: $scrout.=&searchphrasefield('Limit by subject','subject',
274: $ENV{'form.subject'});
275:
276: $scrout.=&searchphrasefield('Limit by keywords','keywords',
277: $ENV{'form.keywords'});
278:
279: $scrout.=&searchphrasefield('Limit by URL','url',
280: $ENV{'form.url'});
281:
282: # $scrout.=&searchphrasefield('Limit by version','version',
283: # $ENV{'form.version'});
284:
285: $scrout.=&searchphrasefield('Limit by notes','notes',
286: $ENV{'form.notes'});
287:
288: $scrout.=&searchphrasefield('Limit by abstract','abstract',
289: $ENV{'form.abstract'});
290:
291: $ENV{'form.mime'}='notxxx' unless length($ENV{'form.mime'});
292: $scrout.=&selectbox('Limit by MIME type','mime',
293: $ENV{'form.mime'},%mimetag);
294:
295: $ENV{'form.language'}='any' unless length($ENV{'form.language'});
296:
297: $scrout.=&selectbox('Limit by language','language',
298: $ENV{'form.language'},%language);
299:
300:
301: # ------------------------------------------------ Compute date selection boxes
302: $scrout.=<<CREATIONDATESTART;
303: <p>
304: <font color="#800000" face="helvetica"><b>LIMIT BY CREATION DATE RANGE:</b>
305: </font>
306: <br />
307: between:
308: CREATIONDATESTART
309: $scrout.=&dateboxes('creationdatestart',1,1,1976,
310: $ENV{'form.creationdatestart_month'},
311: $ENV{'form.creationdatestart_day'},
312: $ENV{'form.creationdatestart_year'},
313: );
314: $scrout.=<<CREATIONDATEEND;
315: and:
316: CREATIONDATEEND
317: $scrout.=&dateboxes('creationdateend',12,31,2051,
318: $ENV{'form.creationdateend_month'},
319: $ENV{'form.creationdateend_day'},
320: $ENV{'form.creationdateend_year'},
321: );
322: $scrout.="</p>";
323:
324: $scrout.=<<LASTREVISIONDATESTART;
325: <p>
326: <font color="#800000" face="helvetica"><b>LIMIT BY LAST REVISION DATE RANGE:
327: </b></font>
328: <br />between:
329: LASTREVISIONDATESTART
330: $scrout.=&dateboxes('lastrevisiondatestart',1,1,1976,
331: $ENV{'form.lastrevisiondatestart_month'},
332: $ENV{'form.lastrevisiondatestart_day'},
333: $ENV{'form.lastrevisiondatestart_year'},
334: );
335: $scrout.=<<LASTREVISIONDATEEND;
336: and:
337: LASTREVISIONDATEEND
338: $scrout.=&dateboxes('lastrevisiondateend',12,31,2051,
339: $ENV{'form.lastrevisiondateend_month'},
340: $ENV{'form.lastrevisiondateend_day'},
341: $ENV{'form.lastrevisiondateend_year'},
342: );
343: $scrout.='</p>';
344:
345: $scrout.=&searchphrasefield('Limit by publisher/owner','owner',
346: $ENV{'form.owner'});
347:
348: $ENV{'form.copyright'}='any' unless length($ENV{'form.copyright'});
349: $scrout.=&selectbox('Limit by copyright/distribution','copyright',
350: $ENV{'form.copyright'},%cprtag);
351:
352: # ------------------------------------------- Compute customized metadata field
353: $scrout.=<<CUSTOMMETADATA;
354: <p>
355: <font color="#800000" face="helvetica"><b>LIMIT BY SPECIAL METADATA FIELDS:</b>
356: </font>
357: For resource-specific metadata, enter in an expression in the form of
358: <i>key</i>=<i>value</i> separated by operators such as AND, OR or NOT.<br />
359: <b>Example:</b> grandmother=75 OR grandfather=85
360: <br />
361: CUSTOMMETADATA
362: $scrout.=&simpletextfield('custommetadata',$ENV{'form.custommetadata'});
363: $scrout.=' <i>initial users of this system do not need to worry about this option</i>';
364:
365: $scrout.=<<CUSTOMSHOW;
366: <p>
367: <font color="#800000" face="helvetica"><b>SHOW SPECIAL METADATA FIELDS:</b>
368: </font>
369: Enter in a space-separated list of special metadata fields to show
370: in a fielded listing for each record result.
371: <br />
372: CUSTOMSHOW
373: $scrout.=&simpletextfield('customshow',$ENV{'form.customshow'});
374: $scrout.=' <i>initial users of this system do not need to worry about this option</i>';
375:
376: # ---------------------------------------------------------------- Print screen
377: $r->print(<<ENDDOCUMENT);
378: <html>
379: <head>
380: <title>The LearningOnline Network with CAPA</title>
381: <script type="text/javascript">
382: function openhelp(val) {
383: openhelpwin=open('/adm/help/searchcat.html','helpscreen',
384: 'scrollbars=1,width=400,height=300');
385: openhelpwin.focus();
386: }
387: </script>
388: </head>
389: <body bgcolor="#FFFFFF">
390: <img align='right' src='/adm/lonIcons/lonlogos.gif' />
391: <h1>Search Catalog</h1>
392: <form method="post" action="/adm/searchcat">
393: $hidden
394: <hr />
395: <h3>Basic Search</h3>
396: <p>
397: Enter terms or phrases separated by search operators
398: such as AND, OR, or NOT then press SEARCH below. Terms should be specific
399: to the title, author, subject, notes, or abstract information associated
400: with a resource.
401: <br />
402: ENDDOCUMENT
403: $r->print(&simpletextfield('basicexp',$ENV{'form.basicexp'}));
404: $r->print(' ');
405: $r->print(&simplecheckbox('titleonly',$ENV{'form.titleonly'}));
406: $r->print('<font color="#800000">Title only</font> ');
407: # $r->print(&simplecheckbox('allversions',$ENV{'form.allversions'}));
408: # <font color="#800000">Search historic archives</font>
409: $r->print(<<ENDDOCUMENT);
410: <br />
411: <input type="submit" name="basicsubmit" value='SEARCH' />
412: <input type="reset" name="reset" value='RESET' />
413: $closebutton
414: $basicviewselect
415: <input type="button" value="HELP" onClick="openhelp()" />
416: </p>
417: <hr />
418: <h3>Advanced Search</h3>
419: $scrout
420: <p>
421: <input type="submit" name="advancedsubmit" value='SEARCH' />
422: <input type="reset" name="reset" value='RESET' />
423: $closebutton
424: $advancedviewselect
425: <input type="button" value="HELP" onClick="openhelp()" />
426: </p>
427: </form>
428: </body>
429: </html>
430: ENDDOCUMENT
431: return OK;
432: }
433:
434: # ----------- grab unprocessed CGI variables that may have been appended to URL
435: sub get_unprocessed_cgi {
436: map {
437: my ($name, $value) = split(/=/,$_);
438: $value =~ tr/+/ /;
439: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
440: if ($name eq 'catalogmode' or $name eq 'launch' or $name eq 'acts') {
441: $ENV{'form.'.$name}=$value;
442: }
443: } (split(/&/,$ENV{'QUERY_STRING'}));
444: }
445:
446: # ------------------------------------------------------------- make persistent
447: sub make_persistent {
448: my $persistent='';
449:
450: map {
451: if (/^form\./ && !/submit/) {
452: my $name=$_;
453: my $key=$name;
454: $ENV{$key}=~s/\'//g; # do not mess with html field syntax
455: $name=~s/^form\.//;
456: $persistent.=<<END;
457: <input type='hidden' name='$name' value='$ENV{$key}' />
458: END
459: }
460: } (keys %ENV);
461: return $persistent;
462: }
463:
464: # --------------------------------------------------------- Various form fields
465:
466: sub simpletextfield {
467: my ($name,$value)=@_;
468: return '<input type=text name=\''.$name.
469: '\' size=20 value=\''.$value.'\' />';
470: }
471:
472: sub simplecheckbox {
473: my ($name,$value)=@_;
474: my $checked='';
475: $checked="CHECKED" if $value eq 'on';
476: return '<input type=checkbox name=\''.$name.'\' '. $checked . '>';
477: }
478:
479: sub searchphrasefield {
480: my ($title,$name,$value)=@_;
481: my $instruction=<<END;
482: Enter terms or phrases separated by search operators such
483: as AND, OR, or NOT.
484: END
485: my $uctitle=uc($title);
486: return "\n<p><font color=\"#800000\" face=\"helvetica\"><b>$uctitle:</b>".
487: "</FONT> $instruction<br />".
488: '<input type=text name="'.$name.'" size=80 value=\''.$value.'\'>';
489: }
490:
491: sub dateboxes {
492: my ($name,$defaultmonth,$defaultday,$defaultyear,
493: $currentmonth,$currentday,$currentyear)=@_;
494: ($defaultmonth,$defaultday,$defaultyear)=('','','');
495: my $month=<<END;
496: <select name="${name}_month">
497: <option value='$defaultmonth'> </option>
498: <option value="1">January</option>
499: <option value="2">February</option>
500: <option value="3">March</option>
501: <option value="4">April</option>
502: <option value="5">May</option>
503: <option value="6">June</option>
504: <option value="7">July</option>
505: <option value="8">August</option>
506: <option value="9">September</option>
507: <option value="10">October</option>
508: <option value="11">November</option>
509: <option value="12">December</option>
510: </select>
511: END
512: $month=~s/(\"$currentmonth\")/$1 SELECTED/ if length($currentmonth);
513: my $day=<<END;
514: <select name="${name}_day">
515: <option value='$defaultday'> </option>
516: <option value="1">1</option>
517: <option value="2">2</option>
518: <option value="3">3</option>
519: <option value="4">4</option>
520: <option value="5">5</option>
521: <option value="6">6</option>
522: <option value="7">7</option>
523: <option value="8">8</option>
524: <option value="9">9</option>
525: <option value="10">10</option>
526: <option value="11">11</option>
527: <option value="12">12</option>
528: <option value="13">13</option>
529: <option value="14">14</option>
530: <option value="15">15</option>
531: <option value="16">16</option>
532: <option value="17">17</option>
533: <option value="18">18</option>
534: <option value="19">19</option>
535: <option value="20">20</option>
536: <option value="21">21</option>
537: <option value="22">22</option>
538: <option value="23">23</option>
539: <option value="24">24</option>
540: <option value="25">25</option>
541: <option value="26">26</option>
542: <option value="27">27</option>
543: <option value="28">28</option>
544: <option value="29">29</option>
545: <option value="30">30</option>
546: <option value="31">31</option>
547: </select>
548: END
549: $day=~s/(\"$currentday\")/$1 SELECTED/ if length($currentday);
550: my $year=<<END;
551: <select name="${name}_year">
552: <option value='$defaultyear'> </option>
553: <option value="1976">1976</option>
554: <option value="1977">1977</option>
555: <option value="1978">1978</option>
556: <option value="1979">1979</option>
557: <option value="1980">1980</option>
558: <option value="1981">1981</option>
559: <option value="1982">1982</option>
560: <option value="1983">1983</option>
561: <option value="1984">1984</option>
562: <option value="1985">1985</option>
563: <option value="1986">1986</option>
564: <option value="1987">1987</option>
565: <option value="1988">1988</option>
566: <option value="1989">1989</option>
567: <option value="1990">1990</option>
568: <option value="1991">1991</option>
569: <option value="1992">1992</option>
570: <option value="1993">1993</option>
571: <option value="1994">1994</option>
572: <option value="1995">1995</option>
573: <option value="1996">1996</option>
574: <option value="1997">1997</option>
575: <option value="1998">1998</option>
576: <option value="1999">1999</option>
577: <option value="2000">2000</option>
578: <option value="2001">2001</option>
579: <option value="2002">2002</option>
580: <option value="2003">2003</option>
581: <option value="2004">2004</option>
582: <option value="2005">2005</option>
583: <option value="2006">2006</option>
584: <option value="2007">2007</option>
585: <option value="2008">2008</option>
586: <option value="2009">2009</option>
587: <option value="2010">2010</option>
588: <option value="2011">2011</option>
589: <option value="2012">2012</option>
590: <option value="2013">2013</option>
591: <option value="2014">2014</option>
592: <option value="2015">2015</option>
593: <option value="2016">2016</option>
594: <option value="2017">2017</option>
595: <option value="2018">2018</option>
596: <option value="2019">2019</option>
597: <option value="2020">2020</option>
598: <option value="2021">2021</option>
599: <option value="2022">2022</option>
600: <option value="2023">2023</option>
601: <option value="2024">2024</option>
602: <option value="2025">2025</option>
603: <option value="2026">2026</option>
604: <option value="2027">2027</option>
605: <option value="2028">2028</option>
606: <option value="2029">2029</option>
607: <option value="2030">2030</option>
608: <option value="2031">2031</option>
609: <option value="2032">2032</option>
610: <option value="2033">2033</option>
611: <option value="2034">2034</option>
612: <option value="2035">2035</option>
613: <option value="2036">2036</option>
614: <option value="2037">2037</option>
615: <option value="2038">2038</option>
616: <option value="2039">2039</option>
617: <option value="2040">2040</option>
618: <option value="2041">2041</option>
619: <option value="2042">2042</option>
620: <option value="2043">2043</option>
621: <option value="2044">2044</option>
622: <option value="2045">2045</option>
623: <option value="2046">2046</option>
624: <option value="2047">2047</option>
625: <option value="2048">2048</option>
626: <option value="2049">2049</option>
627: <option value="2050">2050</option>
628: <option value="2051">2051</option>
629: </select>
630: END
631: $year=~s/(\"$currentyear\")/$1 SELECTED/ if length($currentyear);
632: return "$month$day$year";
633: }
634:
635: sub selectbox {
636: my ($title,$name,$value,%options)=@_;
637: my $uctitle=uc($title);
638: my $selout="\n<p><font color=\"#800000\" face=\"helvetica\"><b>$uctitle:".
639: "</b></font><br />".'<select name="'.$name.'">';
640: map {
641: $selout.='<option value=\''.$_.'\'';
642: if ($_ eq $value) { $selout.=' selected'; }
643: $selout.='>'.$options{$_}.'</option>';
644: } sort keys %options;
645: return $selout.'</select>';
646: }
647:
648: # ----------------------------------------------- Performing an advanced search
649: sub advancedsearch {
650: my ($r,$envhash)=@_;
651: my %ENV=%{$envhash};
652:
653: my $fillflag=0;
654: # Clean up fields for safety
655: for my $field ('title','author','subject','keywords','url','version',
656: 'creationdatestart_month','creationdatestart_day',
657: 'creationdatestart_year','creationdateend_month',
658: 'creationdateend_day','creationdateend_year',
659: 'lastrevisiondatestart_month','lastrevisiondatestart_day',
660: 'lastrevisiondatestart_year','lastrevisiondateend_month',
661: 'lastrevisiondateend_day','lastrevisiondateend_year',
662: 'notes','abstract','mime','language','owner',
663: 'custommetadata','customshow') {
664: $ENV{"form.$field"}=~s/[^\w\/\s\(\)\=\-\"\']//g;
665: }
666:
667: # Check to see if enough information was filled in
668: for my $field ('title','author','subject','keywords','url','version',
669: 'notes','abstract','mime','language','owner',
670: 'custommetadata') {
671: if (&filled($ENV{"form.$field"})) {
672: $fillflag++;
673: }
674: }
675: unless ($fillflag) {
676: &output_blank_field_error($r);
677: return OK;
678: }
679:
680:
681: # Turn the form input into a SQL-based query
682: my $query='';
683:
684: my @queries;
685: # Evaluate logical expression AND/OR/NOT phrase fields.
686: foreach my $field ('title','author','subject','notes','abstract','url',
687: 'keywords','version','owner') {
688: if ($ENV{'form.'.$field}) {
689: push @queries,&build_SQL_query($field,$ENV{'form.'.$field});
690: }
691: }
692: # Evaluate option lists
693: if ($ENV{'form.language'} and $ENV{'form.language'} ne 'any') {
694: push @queries,"(language like \"$ENV{'form.language'}\")";
695: }
696: if ($ENV{'form.mime'} and $ENV{'form.mime'} ne 'any') {
697: push @queries,"(mime like \"$ENV{'form.mime'}\")";
698: }
699: if ($ENV{'form.copyright'} and $ENV{'form.copyright'} ne 'any') {
700: push @queries,"(copyright like \"$ENV{'form.copyright'}\")";
701: }
702: # Evaluate date windows
703: my $datequery=&build_date_queries(
704: $ENV{'form.creationdatestart_month'},
705: $ENV{'form.creationdatestart_day'},
706: $ENV{'form.creationdatestart_year'},
707: $ENV{'form.creationdateend_month'},
708: $ENV{'form.creationdateend_day'},
709: $ENV{'form.creationdateend_year'},
710: $ENV{'form.lastrevisiondatestart_month'},
711: $ENV{'form.lastrevisiondatestart_day'},
712: $ENV{'form.lastrevisiondatestart_year'},
713: $ENV{'form.lastrevisiondateend_month'},
714: $ENV{'form.lastrevisiondateend_day'},
715: $ENV{'form.lastrevisiondateend_year'},
716: );
717: # Test to see if date windows are legitimate
718: if ($datequery=~/^Incorrect/) {
719: &output_date_error($r,$datequery);
720: return OK;
721: }
722: elsif ($datequery) {
723: push @queries,$datequery;
724: }
725:
726: # Process form information for custom metadata querying
727: my $customquery='';
728: if ($ENV{'form.custommetadata'}) {
729: $customquery=&build_custommetadata_query('custommetadata',
730: $ENV{'form.custommetadata'});
731: }
732: my $customshow='';
733: if ($ENV{'form.customshow'}) {
734: $customshow=$ENV{'form.customshow'};
735: $customshow=~s/[^\w\s]//g;
736: my @fields=split(/\s+/,$customshow);
737: $customshow=join(" ",@fields);
738: }
739: # Send query statements over the network to be processed by either the SQL
740: # database or a recursive scheme of 'grep'-like actions (for custom
741: # metadata).
742: if (@queries) {
743: $query=join(" AND ",@queries);
744: $query="select * from metadata where $query";
745: my $reply; # reply hash reference
746: unless ($customquery or $customshow) {
747: $reply=&Apache::lonnet::metadata_query($query);
748: }
749: else {
750: $reply=&Apache::lonnet::metadata_query($query,
751: $customquery,$customshow);
752: }
753: &output_results('Advanced',$r,$envhash,$customquery,$reply);
754: }
755: elsif ($customquery) {
756: my $reply; # reply hash reference
757: $reply=&Apache::lonnet::metadata_query('',
758: $customquery,$customshow);
759: &output_results('Advanced',$r,$envhash,$customquery,$reply);
760: }
761: # should not get to this point
762: return 'Error. Should not have gone to this point.';
763: }
764:
765: # --------------------------------------------------- Performing a basic search
766: sub basicsearch {
767: my ($r,$envhash)=@_;
768: my %ENV=%{$envhash};
769: # Clean up fields for safety
770: for my $field ('basicexp') {
771: $ENV{"form.$field"}=~s/[^\w\s\(\)\-]//g;
772: }
773:
774: # Check to see if enough is filled in
775: unless (&filled($ENV{'form.basicexp'})) {
776: &output_blank_field_error($r);
777: return OK;
778: }
779:
780: # Build SQL query string based on form page
781: my $query='';
782: my $concatarg=join('," ",',
783: ('title', 'author', 'subject', 'notes', 'abstract'));
784: $concatarg='title' if $ENV{'form.titleonly'};
785:
786: $query=&build_SQL_query('concat('.$concatarg.')',$ENV{'form.'.'basicexp'});
787:
788: # Get reply (either a hash reference to filehandles or bad connection)
789: my $reply=&Apache::lonnet::metadata_query('select * from metadata where '.$query);
790:
791: # Output search results
792:
793: &output_results('Basic',$r,$envhash,$query,$reply);
794:
795: return OK;
796: }
797:
798: # ------------------------------------------------------------- build_SQL_query
799: sub build_SQL_query {
800: my ($field_name,$logic_statement)=@_;
801: my $q=new Text::Query('abc',
802: -parse => 'Text::Query::ParseAdvanced',
803: -build => 'Text::Query::Build');
804: $q->prepare($logic_statement);
805: my $matchexp=${$q}{'matchexp'}; chomp $matchexp;
806: my $sql_query=&recursive_SQL_query_build($field_name,$matchexp);
807: return $sql_query;
808: }
809:
810: # ------------------------------------------------- build custom metadata query
811: sub build_custommetadata_query {
812: my ($field_name,$logic_statement)=@_;
813: my $q=new Text::Query('abc',
814: -parse => 'Text::Query::ParseAdvanced',
815: -build => 'Text::Query::BuildAdvancedString');
816: $q->prepare($logic_statement);
817: my $matchexp=${$q}{'-parse'}{'-build'}{'matchstring'};
818: # quick fix to change literal into xml tag-matching
819: # will eventually have to write a separate builder module
820: my $oldmatchexp=$matchexp;
821: $matchexp=~s/(\w+)\\\=([\w\\\+]+)/\\\<$1\\\>\[\^\\\<\]\*$2\[\^\\\<\]\*\\\<\\\/$1\\\>/g;
822: return $matchexp;
823: }
824:
825: # - Recursively parse a reverse notation expression into a SQL query expression
826: sub recursive_SQL_query_build {
827: my ($dkey,$pattern)=@_;
828: my @matches=($pattern=~/(\[[^\]|\[]*\])/g);
829: return $pattern unless @matches;
830: foreach my $match (@matches) {
831: $match=~/\[ (\w+)\s(.*) \]/;
832: my ($key,$value)=($1,$2);
833: my $replacement='';
834: if ($key eq 'literal') {
835: $replacement="($dkey like \"\%$value\%\")";
836: }
837: elsif ($key eq 'not') {
838: $value=~s/like/not like/;
839: # $replacement="($dkey not like $value)";
840: $replacement="$value";
841: }
842: elsif ($key eq 'and') {
843: $value=~/(.*[\"|\)]) ([|\(|\^].*)/;
844: $replacement="($1 AND $2)";
845: }
846: elsif ($key eq 'or') {
847: $value=~/(.*[\"|\)]) ([|\(|\^].*)/;
848: $replacement="($1 OR $2)";
849: }
850: substr($pattern,
851: index($pattern,$match),
852: length($match),
853: $replacement
854: );
855: }
856: &recursive_SQL_query_build($dkey,$pattern);
857: }
858:
859: # ------------------------------------------------------------ Build date query
860: sub build_date_queries {
861: my ($cmonth1,$cday1,$cyear1,$cmonth2,$cday2,$cyear2,
862: $lmonth1,$lday1,$lyear1,$lmonth2,$lday2,$lyear2)=@_;
863: my @queries;
864: if ($cmonth1 or $cday1 or $cyear1 or $cmonth2 or $cday2 or $cyear2) {
865: unless ($cmonth1 and $cday1 and $cyear1 and
866: $cmonth2 and $cday2 and $cyear2) {
867: return "Incorrect entry for the creation date. You must specify ".
868: "a starting month, day, and year and an ending month, ".
869: "day, and year.";
870: }
871: my $cnumeric1=sprintf("%d%2d%2d",$cyear1,$cmonth1,$cday1);
872: $cnumeric1+=0;
873: my $cnumeric2=sprintf("%d%2d%2d",$cyear2,$cmonth2,$cday2);
874: $cnumeric2+=0;
875: if ($cnumeric1>$cnumeric2) {
876: return "Incorrect entry for the creation date. The starting ".
877: "date must occur before the ending date.";
878: }
879: my $cquery="(creationdate BETWEEN '$cyear1-$cmonth1-$cday1' AND '".
880: "$cyear2-$cmonth2-$cday2 23:59:59')";
881: push @queries,$cquery;
882: }
883: if ($lmonth1 or $lday1 or $lyear1 or $lmonth2 or $lday2 or $lyear2) {
884: unless ($lmonth1 and $lday1 and $lyear1 and
885: $lmonth2 and $lday2 and $lyear2) {
886: return "Incorrect entry for the last revision date. You must ".
887: "specify a starting month, day, and year and an ending ".
888: "month, day, and year.";
889: }
890: my $lnumeric1=sprintf("%d%2d%2d",$lyear1,$lmonth1,$lday1);
891: $lnumeric1+=0;
892: my $lnumeric2=sprintf("%d%2d%2d",$lyear2,$lmonth2,$lday2);
893: $lnumeric2+=0;
894: if ($lnumeric1>$lnumeric2) {
895: return "Incorrect entry for the last revision date. The ".
896: "starting date must occur before the ending date.";
897: }
898: my $lquery="(lastrevisiondate BETWEEN '$lyear1-$lmonth1-$lday1' AND '".
899: "$lyear2-$lmonth2-$lday2 23:59:59')";
900: push @queries,$lquery;
901: }
902: if (@queries) {
903: return join(" AND ",@queries);
904: }
905: return '';
906: }
907:
908: # ----------------------------- format and output results based on a reply list
909: # There are two windows that this function writes to. The main search
910: # window ("srch") has a listing of the results. A secondary window ("popwin")
911: # gives the status of the network search (time elapsed, number of machines
912: # contacted, etc.)
913: sub output_results {
914: my $fnum; # search result counter
915: my ($mode,$r,$envhash,$query,$replyref)=@_;
916: my %ENV=%{$envhash};
917: my %rhash=%{$replyref};
918: my $compiledresult='';
919: my $timeremain=300;
920: my $elapsetime=0;
921: my $resultflag=0;
922: my $tflag=1;
923:
924: # make query information persistent to allow for subsequent revision
925: my $persistent=&make_persistent();
926:
927: # output beginning of search page
928: $r->print(<<BEGINNING);
929: <html>
930: <head>
931: <title>The LearningOnline Network with CAPA</title>
932: BEGINNING
933:
934: # conditional output of script functions dependent on the mode in
935: # which the search was invoked
936: $r->print(<<SCRIPT) if $ENV{'form.catalogmode'} eq 'interactive';
937: <script type="text/javascript">
938: function select_data(title,url) {
939: changeTitle(title);
940: changeURL(url);
941: self.close();
942: }
943: function changeTitle(val) {
944: if (opener.inf.document.forms.resinfo.elements.t) {
945: opener.inf.document.forms.resinfo.elements.t.value=val;
946: }
947: }
948: function changeURL(val) {
949: if (opener.inf.document.forms.resinfo.elements.u) {
950: opener.inf.document.forms.resinfo.elements.u.value=val;
951: }
952: }
953: </script>
954: SCRIPT
955: $r->print(<<SCRIPT) if $ENV{'form.catalogmode'} eq 'groupsearch';
956: <script type="text/javascript">
957: function select_data(title,url) {
958: // alert('DEBUG: Should be storing '+title+' and '+url);
959: }
960: function queue(val) {
961: if (eval("document.forms.results.returnvalues["+val+"].checked")) {
962: document.forms.results.acts.value+='1a'+val+'b';
963: }
964: else {
965: document.forms.results.acts.value+='0a'+val+'b';
966: }
967: }
968: function select_group() {
969: window.location="/adm/groupsort?catalogmode=groupsearch&acts="+
970: document.forms.results.acts.value;
971: }
972: </script>
973: SCRIPT
974: $r->print(<<SCRIPT);
975: <script type="text/javascript">
976: function displayinfo(val) {
977: popwin.document.forms.popremain.sdetails.value=val;
978: }
979: function openhelp(val) {
980: openhelpwin=open('/adm/help/searchcat.html','helpscreen',
981: 'scrollbars=1,width=400,height=300');
982: openhelpwin.focus();
983: }
984: function abortsearch(val) {
985: openhelpwin=open('/adm/help/searchcat.html','helpscreen',
986: 'scrollbars=1,width=400,height=300');
987: openhelpwin.focus();
988: }
989: </script>
990: SCRIPT
991: $r->rflush();
992:
993: # begin showing the cataloged results
994: $r->print(<<CATALOGBEGIN);
995: </head>
996: <body bgcolor="#ffffff">
997: <img align=right src=/adm/lonIcons/lonlogos.gif>
998: <h1>Search Catalog</h1>
999: CATALOGBEGIN
1000: $r->print(<<CATALOGCONTROLS);
1001: <form name='results' method="post" action="/adm/searchcat">
1002: <input type='hidden' name='acts' value='' />
1003: <input type='button' value='Revise search request'
1004: onClick='this.form.submit();' />
1005: $importbutton
1006: $closebutton
1007: $persistent
1008: <hr />
1009: <h3>Search Query</h3>
1010: CATALOGCONTROLS
1011: if ($mode eq 'Basic') {
1012: $r->print(<<RESULTS);
1013: <p>
1014: <b>Basic search:</b> $ENV{'form.basicexp'}
1015: </p>
1016: RESULTS
1017: }
1018: elsif ($mode eq 'Advanced') {
1019: $r->print(<<RESULTS);
1020: <p>
1021: <b>Advanced search</b>
1022: $query
1023: </p>
1024: RESULTS
1025: }
1026: $r->print('<h3>Search Results</h3>');
1027: $r->rflush();
1028: my $servernum=(keys %rhash)+0;
1029:
1030: # define server grid (shows status of multiple machines)
1031: my $hcinit;
1032: my $grid="'<br />'+";
1033: $grid.="\n";
1034: my $sn=1;
1035: for my $sk (sort keys %rhash) {
1036: # '<a href="
1037: $grid.="'<a href=\"";
1038: # javascript:displayinfo('+
1039: $grid.="javascript:opener.displayinfo('+";
1040: # "'"+'key
1041: $grid.="\"'\"+'";
1042: $grid.=$sk;
1043: my $hc;
1044: if ($rhash{$sk} eq 'con_lost') {
1045: $hc="!!!BAD CONNECTION, CONTACT SYSTEM ADMINISTRATOR!!!";
1046: }
1047: else {
1048: $hc="'+\"'\"+\"+hc['$sk']+\"+\"'\"+'";
1049: $hcinit.="hc[\"$sk\"]=\"not yet connected...\";";
1050: }
1051: $grid.=" hitcount=".$hc;
1052: $grid.=" domain=".$hostdomains{$sk};
1053: $grid.=" IP=".$hostips{$sk};
1054: # '+"'"+'">'+
1055: $grid.="'+\"'\"+')\">'+";
1056: $grid.="\n";
1057: $grid.="'<img border=\"0\" name=\"img".$sn."\"".
1058: " src=\"/adm/lonIcons/srvnull.gif\" alt=\"".$sk."\" /></a>'+\n";
1059: $grid.="'<br />'+\n" unless $sn%10;
1060: $sn++;
1061: }
1062: $r->print(<<ENDPOP);
1063: <script type="text/javascript">
1064: popwin=open('','popwin','scrollbars=1,width=400,height=200');
1065: popwin.focus();
1066: popwin.document.writeln('<'+'html>');
1067: popwin.document.writeln('<'+'head>');
1068: popwin.document.writeln('<'+'script>');
1069: popwin.document.writeln('hc=new Array();$hcinit');
1070: popwin.document.writeln('<'+'/script>');
1071: popwin.document.writeln('<'+'/head>'+
1072: '<'+'body bgcolor="#FFFFFF">'+
1073: '<'+'image name="whirly" align="right" src="/adm/lonIcons/'+
1074: 'lonanim.gif" '+
1075: 'alt="animated logo" />'+
1076: '<'+'h3>Search Results Progress<'+'/h3>'+
1077: '<'+'form name="popremain">'+
1078: '<'+'tt>'+
1079: '<'+'br clear="all"/><i>PLEASE BE PATIENT</i>'+
1080: '<'+'br />SCANNING $servernum SERVERS'+
1081: '<'+'br clear="all" />Number of record hits found '+
1082: '<'+'input type="text" size="10" name="numhits"'+
1083: ' value="0" />'+
1084: '<'+'br clear="all" />Time elapsed '+
1085: '<'+'input type="text" size="10" name="elapsetime"'+
1086: ' value="0" />'+
1087: '<'+'br />'+
1088: 'SERVER GRID (click on any cell for details)'+
1089: $grid
1090: '<'+'br />'+
1091: 'Server details '+
1092: '<'+'input type="text" size="25" name="sdetails"'+
1093: ' value="" />'+
1094: '<'+'br />'+
1095: ' <'+'input type="button" name="button"'+
1096: ' value="abort search and view current results" '+
1097: ' onClick="javascript:opener.abortsearch()" />'+
1098: ' <'+'input type="button" name="button"'+
1099: ' value="help" onClick="javascript:opener.openhelp()" />'+
1100: '<'+'/tt>'+
1101: '<'+'/form>'+
1102: '<'+'/body><'+'/html>');
1103: popwin.document.close();
1104: </script>
1105: ENDPOP
1106: $r->rflush();
1107:
1108: my $servercount=0;
1109: my $hitcountsum=0;
1110: my $bloop=$servernum;
1111: my %orkey;
1112: BLOOP: while(1) {
1113: my $sn=0;
1114: last BLOOP unless $bloop;
1115: RLOOP: foreach my $rkey (sort keys %rhash) {
1116: $sn++;
1117: next RLOOP if $orkey{$rkey};
1118: $servercount++;
1119: $tflag=1;
1120: $compiledresult='';
1121: my $hostname=$rkey;
1122: my $reply=$rhash{$rkey};
1123: my @results;
1124:
1125: my $replyfile='';
1126:
1127: if ($reply eq 'con_lost') {
1128: $r->print('<script type="text/javascript">popwin.document.img'.
1129: $sn.'.'.
1130: 'src="/adm/lonIcons/srvbad.gif";</script>'.
1131: "\n");
1132: $r->rflush();
1133: $bloop--;
1134: $orkey{$rkey}=1;
1135: }
1136: else {
1137: $reply=~/^([\.\w]+)$/; # must do since 'use strict' checks for tainting
1138: $replyfile=$r->dir_config('lonDaemons').'/tmp/'.$1;
1139: $reply=~/(.*?)\_/;
1140: {
1141: my $temp=0;
1142: WLOOP: while (1) {
1143: if (-e $replyfile && $tflag) {
1144: $r->print('<script type="text/javascript">'.
1145: 'popwin.document.img'.$sn.'.'.
1146: 'src="/adm/lonIcons/srvhalf.gif";</script>'.
1147: "\n");
1148: $r->rflush();
1149: $r->print('<script type="text/javascript">'.
1150: 'popwin.hc["'.$rkey.'"]='.
1151: '"still transferring..."'.';</script>'.
1152: "\n");
1153: $r->rflush();
1154: $tflag=0;
1155: }
1156: last WLOOP if $temp>1;
1157: if (-e "$replyfile.end") {
1158: $bloop--;
1159: $orkey{$rkey}=1;
1160: if (-s $replyfile) {
1161: $r->print('<script type="text/javascript">'.
1162: 'popwin.document.img'.$sn.'.'.
1163: 'src="/adm/lonIcons/srvgood.gif";'.
1164: '</script>'."\n");
1165: $r->rflush();
1166: my $fh=Apache::File->new($replyfile) or
1167: ($r->print('ERROR: file '.
1168: $replyfile.' cannot be opened') and
1169: return OK);
1170: @results=<$fh> if $fh;
1171: $hitcount{$rkey}=@results+0;
1172: $r->print('<script type="text/javascript">'.
1173: 'popwin.hc["'.$rkey.'"]='.
1174: $hitcount{$rkey}.';</script>'.
1175: "\n");
1176: $r->rflush();
1177: $hitcountsum+=$hitcount{$rkey};
1178: $r->print('<script type="text/javascript">'.
1179: 'popwin.document.forms.popremain.'.
1180: 'numhits.value='.$hitcountsum.
1181: ';</script>'.
1182: "\n");
1183: $r->rflush();
1184: }
1185: else {
1186: $r->print('<script type="text/javascript">'.
1187: 'popwin.document.img'.$sn.'.'.
1188: 'src="/adm/lonIcons/srvempty.gif";'.
1189: '</script>'.
1190: "\n");
1191: $r->rflush();
1192: $r->print('<script type="text/javascript">'.
1193: 'popwin.hc["'.$rkey.'"]=0'.
1194: ';</script>'.
1195: "\n");
1196: $r->rflush();
1197: }
1198: last WLOOP;
1199: }
1200: last WLOOP unless $timeremain;
1201: sleep 1;
1202: $timeremain--;
1203: $elapsetime++;
1204: $r->print('<script type="text/javascript">'.
1205: 'popwin.document.popremain.elapsetime.'.
1206: 'value="'.$elapsetime.'";</script>'."\n");
1207: $r->rflush();
1208: $temp++;
1209: }
1210: }
1211: $r->print('<script type="text/javascript">'.
1212: 'popwin.document.whirly.'.
1213: 'src="'.'/adm/lonIcons/lonanimend.gif'.
1214: '";</script>'."\n");
1215: $r->rflush();
1216: }
1217: my $customshow='';
1218: my $extrashow='';
1219: my @customfields;
1220: if ($ENV{'form.customshow'}) {
1221: $customshow=$ENV{'form.customshow'};
1222: $customshow=~s/[^\w\s]//g;
1223: my @fields=map {"<font color=\"#008000\">$_:</font><!-- $_ -->"}
1224: split(/\s+/,$customshow);
1225: @customfields=split(/\s+/,$customshow);
1226: if ($customshow) {
1227: $extrashow="<ul><li>".join("</li><li>",@fields)."</li></ul>\n";
1228: }
1229: }
1230: my $customdata='';
1231: my %customhash;
1232: foreach my $result (@results) {
1233: if ($result=~/^(custom\=.*)$/) { # grab all custom metadata
1234: my $tmp=$result;
1235: $tmp=~s/^custom\=//;
1236: my ($k,$v)=map {&Apache::lonnet::unescape($_);
1237: } split(/\,/,$tmp);
1238: $customhash{$k}=$v;
1239: }
1240: }
1241: if (keys %hash) {
1242: untie %hash;
1243: }
1244: if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) {
1245: if ($ENV{'form.launch'} eq '1') {
1246: &start_fresh_session();
1247: }
1248: foreach my $result (@results) {
1249: next if $result=~/^custom\=/;
1250: chomp $result;
1251: next unless $result;
1252: my @fields=map
1253: {&Apache::lonnet::unescape($_)}
1254: (split(/\,/,$result));
1255: my ($title,$author,$subject,$url,$keywords,$version,
1256: $notes,$abstract,$mime,$lang,
1257: $creationdate,$lastrevisiondate,$owner,$copyright)=@fields;
1258:
1259: unless ($ENV{'user.adv'}) {
1260: $keywords='<i>- not displayed -</i>';
1261: $fields[4]=$keywords;
1262: $notes='<i>- not displayed -</i>';
1263: $fields[6]=$notes;
1264: $abstract='<i>- not displayed -</i>';
1265: $fields[7]=$abstract;
1266: $subject='<i>- not displayed -</i>';
1267: $fields[2]=$subject;
1268: }
1269:
1270: my $shortabstract=$abstract;
1271: $shortabstract=substr($abstract,0,200).'...' if length($abstract)>200;
1272: $fields[7]=$shortabstract;
1273: my $shortkeywords=$keywords;
1274: $shortkeywords=substr($keywords,0,200).'...' if length($keywords)>200;
1275: $fields[4]=$shortkeywords;
1276:
1277: my $extrashow2=$extrashow;
1278: if ($extrashow) {
1279: foreach my $field (@customfields) {
1280: my $value='';
1281: if ($customhash{$url}=~/\<${field}[^\>]*\>(.*?)\<\/${field}[^\>]*\>/s) {
1282: $value=$1;
1283: }
1284: $extrashow2=~s/\<\!\-\- $field \-\-\>/ $value/g;
1285: }
1286: }
1287:
1288: $compiledresult.=<<END if $compiledresult or $servercount!=$servernum;
1289: <hr align='left' width='200' noshade />
1290: END
1291: $compiledresult.=<<END;
1292: <p>
1293: END
1294: $compiledresult.=<<END if $ENV{'form.catalogmode'} eq 'interactive';
1295: <font size='-1'><INPUT TYPE="button" NAME="returnvalues" VALUE="SELECT"
1296: onClick="javascript:select_data('$title','$url')">
1297: </font>
1298: <br />
1299: END
1300: if ($ENV{'form.catalogmode'} eq 'groupsearch') {
1301: $fnum+=0;
1302: $hash{"pre_${fnum}_link"}=$url;
1303: $hash{"pre_${fnum}_title"}=$title;
1304: $compiledresult.=<<END;
1305: <font size='-1'><input type="checkbox" name="returnvalues" value="SELECT"
1306: onClick="javascript:queue($fnum)" />
1307: </font>
1308: <br />
1309: END
1310: # <input type="hidden" name="title$fnum" value="$title" />
1311: # <input type="hidden" name="url$fnum" value="$url" />
1312: $fnum++;
1313: }
1314: my $httphost=$ENV{'HTTP_HOST'};
1315:
1316: my $viewselect;
1317: if ($mode eq 'Basic') {
1318: $viewselect=$ENV{'form.basicviewselect'};
1319: }
1320: elsif ($mode eq 'Advanced') {
1321: $viewselect=$ENV{'form.advancedviewselect'};
1322: }
1323:
1324: if ($viewselect eq 'Detailed Citation View') {
1325: $compiledresult.=&detailed_citation_view(@fields,
1326: $hostname,$httphost,
1327: $extrashow2);
1328: }
1329: elsif ($viewselect eq 'Summary View') {
1330: $compiledresult.=&summary_view(@fields,$hostname,$httphost,
1331: $extrashow2);
1332: }
1333: elsif ($viewselect eq 'Fielded Format') {
1334: $compiledresult.=&fielded_format_view(@fields,$hostname,
1335: $httphost,$extrashow2);
1336: }
1337: elsif ($viewselect eq 'XML/SGML') {
1338: $compiledresult.=&xml_sgml_view(@fields,$hostname,$httphost,
1339: $extrashow2);
1340: }
1341:
1342: }
1343:
1344: untie %hash;
1345: }
1346: else {
1347: $r->print('<html><head></head><body>Unable to tie hash to db '.
1348: 'file</body></html>');
1349: }
1350: if ($compiledresult) {
1351: $resultflag=1;
1352: }
1353:
1354: $r->print(<<RESULTS);
1355: $compiledresult
1356: RESULTS
1357: my $percent=sprintf('%3.0f',($servercount/$servernum*100));
1358: }
1359: }
1360: unless ($resultflag) {
1361: $r->print("\nThere were no results that matched your query\n");
1362: }
1363: # $r->print('<script type="text/javascript">'.'popwin.close()</script>'."\n"); $r->rflush();
1364: $r->print(<<RESULTS);
1365: </body>
1366: </html>
1367: RESULTS
1368: }
1369:
1370: # ------------------------------------------------------ Detailed Citation View
1371: sub detailed_citation_view {
1372: my ($title,$author,$subject,$url,$keywords,$version,
1373: $notes,$shortabstract,$mime,$lang,
1374: $creationdate,$lastrevisiondate,$owner,$copyright,
1375: $hostname,$httphost,$extrashow)=@_;
1376: my $result=<<END;
1377: <i>$owner</i>, last revised $lastrevisiondate
1378: <h3><A HREF="http://$httphost$url" TARGET='search_preview'>$title</A></h3>
1379: <h3>$author</h3>
1380: </p>
1381: <p>
1382: <b>Subject:</b> $subject<br />
1383: <b>Keyword(s):</b> $keywords<br />
1384: <b>Notes:</b> $notes<br />
1385: <b>MIME Type:</b> $mimetag{$mime}<br />
1386: <b>Language:</b> $language{$lang}<br />
1387: <b>Copyright/Distribution:</b> $cprtag{$copyright}<br />
1388: </p>
1389: $extrashow
1390: <p>
1391: $shortabstract
1392: </p>
1393: END
1394: return $result;
1395: }
1396:
1397: # ---------------------------------------------------------------- Summary View
1398: sub summary_view {
1399: my ($title,$author,$subject,$url,$keywords,$version,
1400: $notes,$shortabstract,$mime,$lang,
1401: $creationdate,$lastrevisiondate,$owner,$copyright,
1402: $hostname,$httphost,$extrashow)=@_;
1403: my $result=<<END;
1404: <a href="http://$httphost$url" TARGET='search_preview'>$author</a><br />
1405: $title<br />
1406: $owner -- $lastrevisiondate<br />
1407: $cprtag{$copyright}<br />
1408: $extrashow
1409: </p>
1410: END
1411: return $result;
1412: }
1413:
1414: # -------------------------------------------------------------- Fielded Format
1415: sub fielded_format_view {
1416: my ($title,$author,$subject,$url,$keywords,$version,
1417: $notes,$shortabstract,$mime,$lang,
1418: $creationdate,$lastrevisiondate,$owner,$copyright,
1419: $hostname,$httphost,$extrashow)=@_;
1420: my $result=<<END;
1421: <b>URL: </b> <A HREF="http://$httphost$url" TARGET='search_preview'>$url</A>
1422: <br />
1423: <b>Title:</b> $title<br />
1424: <b>Author(s):</b> $author<br />
1425: <b>Subject:</b> $subject<br />
1426: <b>Keyword(s):</b> $keywords<br />
1427: <b>Notes:</b> $notes<br />
1428: <b>MIME Type:</b> $mimetag{$mime}<br />
1429: <b>Language:</b> $language{$lang}<br />
1430: <b>Creation Date:</b> $creationdate<br />
1431: <b>Last Revision Date:</b> $lastrevisiondate<br />
1432: <b>Publisher/Owner:</b> $owner<br />
1433: <b>Copyright/Distribution:</b> $cprtag{$copyright}<br />
1434: <b>Repository Location:</b> $hostname<br />
1435: <b>Abstract:</b> $shortabstract<br />
1436: $extrashow
1437: </p>
1438: END
1439: return $result;
1440: }
1441:
1442: # -------------------------------------------------------------------- XML/SGML
1443: sub xml_sgml_view {
1444: my ($title,$author,$subject,$url,$keywords,$version,
1445: $notes,$shortabstract,$mime,$lang,
1446: $creationdate,$lastrevisiondate,$owner,$copyright,
1447: $hostname,$httphost,$extrashow)=@_;
1448: my $result=<<END;
1449: <pre>
1450: <LonCapaResource>
1451: <url>$url</url>
1452: <title>$title</title>
1453: <author>$author</author>
1454: <subject>$subject</subject>
1455: <keywords>$keywords</keywords>
1456: <notes>$notes</notes>
1457: <mimeInfo>
1458: <mime>$mime</mime>
1459: <mimetag>$mimetag{$mime}</mimetag>
1460: </mimeInfo>
1461: <languageInfo>
1462: <language>$lang</language>
1463: <languagetag>$language{$lang}</languagetag>
1464: </languageInfo>
1465: <creationdate>$creationdate</creationdate>
1466: <lastrevisiondate>$lastrevisiondate</lastrevisiondate>
1467: <owner>$owner</owner>
1468: <copyrightInfo>
1469: <copyright>$copyright</copyright>
1470: <copyrighttag>$cprtag{$copyright}</copyrighttag>
1471: </copyrightInfo>
1472: <repositoryLocation>$hostname</repositoryLocation>
1473: <shortabstract>$shortabstract</shortabstract>
1474: </LonCapaResource>
1475: </pre>
1476: $extrashow
1477: END
1478: return $result;
1479: }
1480:
1481: # ---------------------------------------------------- see if a field is filled
1482: sub filled {
1483: my ($field)=@_;
1484: if ($field=~/\S/ && $field ne 'any') {
1485: return 1;
1486: }
1487: else {
1488: return 0;
1489: }
1490: }
1491:
1492: # ---------------- Message to output when there are not enough fields filled in
1493: sub output_blank_field_error {
1494: my ($r)=@_;
1495: # make query information persistent to allow for subsequent revision
1496: my $persistent=&make_persistent();
1497:
1498: $r->print(<<BEGINNING);
1499: <html>
1500: <head>
1501: <title>The LearningOnline Network with CAPA</title>
1502: BEGINNING
1503: $r->print(<<RESULTS);
1504: </head>
1505: <body bgcolor="#ffffff">
1506: <img align='right' src='/adm/lonIcons/lonlogos.gif' />
1507: <h1>Search Catalog</h1>
1508: <form method="post" action="/adm/searchcat">
1509: $persistent
1510: <input type='button' value='Revise search request'
1511: onClick='this.form.submit();' />
1512: $closebutton
1513: <hr />
1514: <h3>Helpful Message</h3>
1515: <p>
1516: Incorrect search query due to blank entry fields.
1517: You need to fill in the relevant
1518: fields on the search page in order for a query to be
1519: processed.
1520: </p>
1521: </body>
1522: </html>
1523: RESULTS
1524: }
1525:
1526: # ----------------------------------------------------------- Output date error
1527: sub output_date_error {
1528: my ($r,$message)=@_;
1529: # make query information persistent to allow for subsequent revision
1530: my $persistent=&make_persistent();
1531:
1532: $r->print(<<BEGINNING);
1533: <html>
1534: <head>
1535: <title>The LearningOnline Network with CAPA</title>
1536: BEGINNING
1537: $r->print(<<RESULTS);
1538: </head>
1539: <body bgcolor="#ffffff">
1540: <img align='right' src='/adm/lonIcons/lonlogos.gif' />
1541: <h1>Search Catalog</h1>
1542: <form method="post" action="/adm/searchcat">
1543: $persistent
1544: <input type='button' value='Revise search request'
1545: onClick='this.form.submit();' />
1546: $closebutton
1547: <hr />
1548: <h3>Helpful Message</h3>
1549: <p>
1550: $message
1551: </p>
1552: </body>
1553: </html>
1554: RESULTS
1555: }
1556:
1557: # --------- settings whenever the user causes the indexer window to be launched
1558: sub start_fresh_session {
1559: delete $hash{'mode_catalog'};
1560: map {
1561: if ($_ =~ /^pre_/) {
1562: delete $hash{$_};
1563: }
1564: if ($_ =~ /^store/) {
1565: delete $hash{$_};
1566: }
1567: } keys %hash;
1568: }
1569:
1570: 1;
1571:
1572: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>