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