Annotation of loncom/interface/lonsearchcat.pm, revision 1.96
1.1 www 1: # The LearningOnline Network
2: # Search Catalog
3: #
1.2 harris41 4: # 03/08/2001 Scott Harrison
1.42 harris41 5: # Scott Harrison: 03/12/2001, 03/13/2001, 03/14/2001, 03/15/2001, 03/19/2001
1.91 harris41 6: # Scott Harrison: 03/20/2001, 03/21/2001, 03/22/2001, 03/26/2001, 03/27/2001
7: # Scott Harrison: 04/02/2001
1.1 www 8: #
1.41 harris41 9: # Functions
10: #
11: # handler(server reference) : interacts with the Apache server layer
12: # (for /adm/searchcat URLs)
13: # simpletextfield(name,value) : returns HTML formatted string for simple text
14: # field
15: # simplecheckbox(name,value) : returns HTML formatted string for simple
16: # checkbox
17: # searchphrasefield(title,name,value) : returns HTML formatted string for
18: # a search expression phrase field
19: # dateboxes(name, defaultmonth, defaultday, defaultyear) : returns HTML
20: # formatted string
21: # for a calendar date
22: # selectbox(title,name,value,%HASH=options) : returns HTML formatted string for
23: # a selection box field
1.42 harris41 24: # advancedsearch(server reference, environment reference) : perform a complex
25: # multi-field logical query
1.41 harris41 26: # filled(field) : determines whether a given field has been filled
1.42 harris41 27: # basicsearch(server reference, environment reference) : perform a simple
28: # single-field logical query
29: # output_blank_field_error(server reference) : outputs a message saying that
30: # more fields need to be filled in
31: # output_results(output mode,
32: # server reference,
33: # environment reference,
34: # reply list reference) : outputs results from search
1.43 harris41 35: # build_SQL_query(field name, logic) : builds a SQL query string from a
36: # logical expression with AND/OR keywords
37: # recursive_SQL_query_build(field name, reverse notation expression) :
38: # builds a SQL query string from a reverse notation expression
39: # logical expression with AND/OR keywords
1.90 harris41 40: # build_custommetadata_query(field_name, logic_statement) : builds a perl
41: # regular expression from a logical expression with AND/OR
42: # keywords
43: # detailed_citation_view, summary_view, fielded_format_view, xml_sgml_view:
44: # four different ways to view metadata records. Outputs a HTML-ified string.
45: # Input arguments are title, author, subject, url, keywords, version, notes,
46: # short abstract, mime, language, creation date, last revision date, owner,
47: # copyright, hostname, httphost, and extra custom metadata to show.
48: # build_date_queries(cmonth1, cday1, cyear1, cmonth2, cday2, cyear2,
49: # lmonth1, lday1, lyear1, lmonth2, lday2, lyear2) :
50: # Builds a SQL logic query to check time/date entries.
51: # output_date_error(server reference, error message) : outputs
52: # an error message specific to bad date format.
53: # make_persistent() : makes a set of hidden HTML fields to make
54: # SQL search interface information to be persistent
1.41 harris41 55:
1.1 www 56: package Apache::lonsearchcat;
57:
58: use strict;
59: use Apache::Constants qw(:common);
1.6 harris41 60: use Apache::lonnet();
61: use Apache::File();
1.7 harris41 62: use CGI qw(:standard);
1.41 harris41 63: use Text::Query;
1.1 www 64:
1.90 harris41 65: # ---------------------------------------- variables used throughout the module
1.3 harris41 66: my %language;
67: my $scrout;
68: my %metadatafields;
69: my %cprtag;
70: my %mimetag;
1.46 harris41 71: my $closebutton;
1.90 harris41 72:
73: # ------ form selection elements that allow for choosing different output views
74: # Detailed Citation View ---> sub detailed_citationview
75: # Summary View ---> sub summary_view
76: # Fielded Format ---> sub fielded_format_view
77: # XML/SGML ---> sub xml_sgml_view
1.55 harris41 78: my $basicviewselect=<<END;
79: <select name='basicviewselect'>
80: <option value='Detailed Citation View'>Detailed Citation View</option>
81: <option value='Summary View'>Summary View</option>
82: <option value='Fielded Format'>Fielded Format</option>
83: <option value='XML/SGML'>XML/SGML</option>
84: </select>
85: END
86: my $advancedviewselect=<<END;
87: <select name='advancedviewselect'>
1.50 harris41 88: <option value='Detailed Citation View'>Detailed Citation View</option>
89: <option value='Summary View'>Summary View</option>
90: <option value='Fielded Format'>Fielded Format</option>
91: <option value='XML/SGML'>XML/SGML</option>
1.46 harris41 92: </select>
93: END
1.3 harris41 94:
1.90 harris41 95: # ----------------------------- Handling routine called via Apache and mod_perl
1.1 www 96: sub handler {
97: my $r = shift;
1.7 harris41 98:
99: # -------------------------------------- see if called from an interactive mode
100: map {
101: my ($name, $value) = split(/=/,$_);
102: $value =~ tr/+/ /;
103: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
104: if ($name eq 'catalogmode') {
105: $ENV{'form.'.$name}=$value;
106: }
107: } (split(/&/,$ENV{'QUERY_STRING'}));
108:
1.1 www 109: $r->content_type('text/html');
110: $r->send_http_header;
111: return OK if $r->header_only;
112:
1.3 harris41 113: %metadatafields=();
114:
1.8 harris41 115: my $hidden='';
1.90 harris41 116: if ($ENV{'form.catalogmode'} eq 'interactive') {
117: $hidden=<<END;
1.8 harris41 118: <input type='hidden' name='catalogmode' value='interactive'>
119: END
1.90 harris41 120: $closebutton=<<END;
1.68 harris41 121: <input type="button" name="close" value='CLOSE' onClick="self.close()">
1.46 harris41 122: END
1.90 harris41 123: }
1.46 harris41 124:
1.3 harris41 125: # ------------------------------------------------ First, check out environment
126: $metadatafields{'owner'}=$ENV{'user.name'}.'@'.$ENV{'user.domain'};
127:
1.8 harris41 128: # --------------------------------- Compute various listings of metadata values
1.3 harris41 129:
130: %language=();
131: $language{'any'}='Any language';
132: {
133: my $fh=Apache::File->new($r->dir_config('lonTabDir').'/language.tab');
134: map {
1.57 harris41 135: $_=~/(\w+)\s+([\w\s\-]+)/; chomp;
1.3 harris41 136: $language{$1}=$2;
137: } <$fh>;
138: }
139:
140: %cprtag=();
141: $cprtag{'any'}='Any copyright/distribution';
142: {
143: my $fh=Apache::File->new($r->dir_config('lonIncludes').'/copyright.tab');
144: map {
1.57 harris41 145: $_=~/(\w+)\s+([\w\s\-]+)/; chomp;
1.3 harris41 146: $cprtag{$1}=$2;
147: } <$fh>;
148: }
149:
150: %mimetag=();
151: $mimetag{'any'}='Any type';
152: {
153: my $fh=Apache::File->new($r->dir_config('lonTabDir').'/filetypes.tab');
154: map {
1.57 harris41 155: $_=~/(\w+)\s+(\w+)\s+([\w\s\-]+)/; chomp;
1.3 harris41 156: $mimetag{$1}=".$1 $3";
157: } <$fh>;
158: }
159:
1.90 harris41 160: # ----------------------------------- See if a search invocation should be done
1.6 harris41 161: if ($ENV{'form.basicsubmit'} eq 'SEARCH') {
1.19 harris41 162: return &basicsearch($r,\%ENV);
1.6 harris41 163: }
1.18 harris41 164: elsif ($ENV{'form.advancedsubmit'} eq 'SEARCH') {
165: return &advancedsearch($r,\%ENV);
166: }
1.6 harris41 167:
1.90 harris41 168: # ----------------------------- Else, begin building search interface to output
1.8 harris41 169: $scrout=''; # building a part of screen output
1.3 harris41 170: $scrout.=&searchphrasefield('Limit by title','title',
1.11 harris41 171: $ENV{'form.title'});
1.3 harris41 172:
173: $scrout.=&searchphrasefield('Limit by author','author',
1.11 harris41 174: $ENV{'form.author'});
1.3 harris41 175:
176: $scrout.=&searchphrasefield('Limit by subject','subject',
1.11 harris41 177: $ENV{'form.subject'});
178:
179: $scrout.=&searchphrasefield('Limit by keywords','keywords',
180: $ENV{'form.keywords'});
181:
182: $scrout.=&searchphrasefield('Limit by URL','url',
183: $ENV{'form.url'});
184:
1.96 ! harris41 185: # $scrout.=&searchphrasefield('Limit by version','version',
! 186: # $ENV{'form.version'});
1.3 harris41 187:
188: $scrout.=&searchphrasefield('Limit by notes','notes',
1.11 harris41 189: $ENV{'form.notes'});
1.3 harris41 190:
191: $scrout.=&searchphrasefield('Limit by abstract','abstract',
1.11 harris41 192: $ENV{'form.abstract'});
1.3 harris41 193:
1.11 harris41 194: $ENV{'form.mime'}='notxxx' unless length($ENV{'form.mime'});
1.3 harris41 195: $scrout.=&selectbox('Limit by MIME type','mime',
1.11 harris41 196: $ENV{'form.mime'},%mimetag);
197:
198: $ENV{'form.language'}='any' unless length($ENV{'form.language'});
1.3 harris41 199:
200: $scrout.=&selectbox('Limit by language','language',
1.11 harris41 201: $ENV{'form.language'},%language);
1.3 harris41 202:
1.8 harris41 203:
204: # ------------------------------------------------ Compute date selection boxes
205: $scrout.=<<CREATIONDATESTART;
1.3 harris41 206: <p>
207: <font color="#800000" face="helvetica"><b>LIMIT BY CREATION DATE RANGE:</b>
208: </font>
209: <br>
1.8 harris41 210: between:
211: CREATIONDATESTART
1.11 harris41 212: $scrout.=&dateboxes('creationdatestart',1,1,1976,
213: $ENV{'form.creationdatestart_month'},
214: $ENV{'form.creationdatestart_day'},
215: $ENV{'form.creationdatestart_year'},
216: );
1.8 harris41 217: $scrout.=<<CREATIONDATEEND;
218: and:
219: CREATIONDATEEND
1.11 harris41 220: $scrout.=&dateboxes('creationdateend',12,31,2051,
221: $ENV{'form.creationdateend_month'},
222: $ENV{'form.creationdateend_day'},
223: $ENV{'form.creationdateend_year'},
224: );
1.8 harris41 225: $scrout.="</p>";
226:
227: $scrout.=<<LASTREVISIONDATESTART;
228: <p>
229: <font color="#800000" face="helvetica"><b>LIMIT BY LAST REVISION DATE RANGE:
230: </b></font>
231: <br>between:
232: LASTREVISIONDATESTART
1.11 harris41 233: $scrout.=&dateboxes('lastrevisiondatestart',1,1,1976,
234: $ENV{'form.lastrevisiondatestart_month'},
235: $ENV{'form.lastrevisiondatestart_day'},
236: $ENV{'form.lastrevisiondatestart_year'},
237: );
1.8 harris41 238: $scrout.=<<LASTREVISIONDATEEND;
239: and:
240: LASTREVISIONDATEEND
1.11 harris41 241: $scrout.=&dateboxes('lastrevisiondateend',12,31,2051,
242: $ENV{'form.lastrevisiondateend_month'},
243: $ENV{'form.lastrevisiondateend_day'},
244: $ENV{'form.lastrevisiondateend_year'},
245: );
1.8 harris41 246: $scrout.='</p>';
247:
248: $scrout.=&searchphrasefield('Limit by publisher/owner','owner',
1.11 harris41 249: $ENV{'form.owner'});
250: # $metadatafields{'owner'});
1.8 harris41 251:
1.11 harris41 252: $ENV{'form.copyright'}='any' unless length($ENV{'form.copyright'});
1.8 harris41 253: $scrout.=&selectbox('Limit by copyright/distribution','copyright',
1.11 harris41 254: $ENV{'form.copyright'},%cprtag);
1.8 harris41 255:
1.14 harris41 256: # ------------------------------------------- Compute customized metadata field
257: $scrout.=<<CUSTOMMETADATA;
258: <p>
1.77 harris41 259: <font color="#800000" face="helvetica"><b>LIMIT BY SPECIAL METADATA FIELDS:</b>
1.14 harris41 260: </font>
1.77 harris41 261: For resource-specific metadata, enter in an expression in the form of
1.14 harris41 262: <i>key</i>=<i>value</i> separated by operators such as AND or OR.<br>
263: <b>Example:</b> grandmother=75 OR grandfather=85
264: <br>
265: CUSTOMMETADATA
266: $scrout.=&simpletextfield('custommetadata',$ENV{'form.custommetadata'});
1.15 harris41 267: $scrout.=' <i>initial users of this system do not need to worry about this option</i>';
1.14 harris41 268:
1.77 harris41 269: $scrout.=<<CUSTOMSHOW;
270: <p>
271: <font color="#800000" face="helvetica"><b>SHOW SPECIAL METADATA FIELDS:</b>
272: </font>
273: Enter in a space-separated list of special metadata fields to show
274: in a fielded listing for each record result.
275: <br>
276: CUSTOMSHOW
277: $scrout.=&simpletextfield('customshow',$ENV{'form.customshow'});
278: $scrout.=' <i>initial users of this system do not need to worry about this option</i>';
279:
1.8 harris41 280: # ---------------------------------------------------------------- Print screen
281: $r->print(<<ENDDOCUMENT);
282: <html>
283: <head>
284: <title>The LearningOnline Network with CAPA</title>
285: </head>
286: <body bgcolor="#FFFFFF">
287: <img align=right src=/adm/lonIcons/lonlogos.gif>
288: <h1>Search Catalog</h1>
289: <form method="post" action="/adm/searchcat">
290: $hidden
291: <hr>
292: <h3>Basic Search</h3>
293: <p>
294: Enter terms or phrases separated by search operators
295: such as AND or OR then press SEARCH below. Terms should be specific
296: to the title, author, subject, notes, or abstract information associated
297: with a resource.
298: <br>
1.11 harris41 299: ENDDOCUMENT
300: $r->print(&simpletextfield('basicexp',$ENV{'form.basicexp'}));
301: $r->print(' ');
302: $r->print(&simplecheckbox('titleonly',$ENV{'form.titleonly'}));
303: $r->print('<font color="#800000">Title only</font> ');
1.96 ! harris41 304: # $r->print(&simplecheckbox('allversions',$ENV{'form.allversions'}));
! 305: # <font color="#800000">Search historic archives</font>
1.11 harris41 306: $r->print(<<ENDDOCUMENT);
1.8 harris41 307: <br>
1.68 harris41 308: <input type="submit" name="basicsubmit" value='SEARCH' />
309: <input type="reset" name="reset" value='RESET' />
1.46 harris41 310: $closebutton
1.55 harris41 311: $basicviewselect
1.8 harris41 312: </p>
313: <hr>
314: <h3>Advanced Search</h3>
315: $scrout
316: <p>
1.68 harris41 317: <input type="submit" name="advancedsubmit" value='SEARCH' />
318: <input type="reset" name="reset" value='RESET' />
1.46 harris41 319: $closebutton
1.55 harris41 320: $advancedviewselect
1.3 harris41 321: </p>
1.8 harris41 322: </form>
323: </body>
324: </html>
325: ENDDOCUMENT
326: return OK;
327: }
328:
329: # --------------------------------------------------------- Various form fields
330:
1.11 harris41 331: sub simpletextfield {
332: my ($name,$value)=@_;
1.68 harris41 333: return '<input type=text name=\''.$name.
334: '\' size=20 value=\''.$value.'\' />';
1.11 harris41 335: }
336:
337: sub simplecheckbox {
338: my ($name,$value)=@_;
339: my $checked='';
340: $checked="CHECKED" if $value eq 'on';
1.68 harris41 341: return '<input type=checkbox name=\''.$name.'\' '. $checked . '>';
1.11 harris41 342: }
343:
1.8 harris41 344: sub searchphrasefield {
345: my ($title,$name,$value)=@_;
346: my $instruction=<<END;
347: Enter terms or phrases separated by search operators such
348: as AND or OR.
349: END
350: my $uctitle=uc($title);
351: return "\n<p><font color=\"#800000\" face=\"helvetica\"><b>$uctitle:</b>".
352: "</FONT> $instruction<br>".
1.68 harris41 353: '<input type=text name="'.$name.'" size=80 value=\''.$value.'\'>';
1.8 harris41 354: }
1.3 harris41 355:
1.8 harris41 356: sub dateboxes {
1.11 harris41 357: my ($name,$defaultmonth,$defaultday,$defaultyear,
358: $currentmonth,$currentday,$currentyear)=@_;
359: ($defaultmonth,$defaultday,$defaultyear)=('','','');
360: my $month=<<END;
1.8 harris41 361: <select name="${name}_month">
1.11 harris41 362: <option value='$defaultmonth'> </option>
363: <option value="1">January</option>
364: <option value="2">February</option>
365: <option value="3">March</option>
366: <option value="4">April</option>
367: <option value="5">May</option>
368: <option value="6">June</option>
369: <option value="7">July</option>
370: <option value="8">August</option>
371: <option value="9">September</option>
1.3 harris41 372: <option value="10">October</option>
373: <option value="11">November</option>
374: <option value="12">December</option>
375: </select>
1.11 harris41 376: END
377: $month=~s/(\"$currentmonth\")/$1 SELECTED/ if length($currentmonth);
378: my $day=<<END;
1.8 harris41 379: <select name="${name}_day">
1.11 harris41 380: <option value='$defaultday'> </option>
381: <option value="1">1</option>
382: <option value="2">2</option>
383: <option value="3">3</option>
384: <option value="4">4</option>
385: <option value="5">5</option>
386: <option value="6">6</option>
387: <option value="7">7</option>
388: <option value="8">8</option>
389: <option value="9">9</option>
390: <option value="10">10</option>
391: <option value="11">11</option>
392: <option value="12">12</option>
393: <option value="13">13</option>
394: <option value="14">14</option>
395: <option value="15">15</option>
396: <option value="16">16</option>
397: <option value="17">17</option>
398: <option value="18">18</option>
399: <option value="19">19</option>
400: <option value="20">20</option>
401: <option value="21">21</option>
402: <option value="22">22</option>
403: <option value="23">23</option>
404: <option value="24">24</option>
405: <option value="25">25</option>
406: <option value="26">26</option>
407: <option value="27">27</option>
408: <option value="28">28</option>
409: <option value="29">29</option>
410: <option value="30">30</option>
411: <option value="31">31</option>
1.3 harris41 412: </select>
1.11 harris41 413: END
414: $day=~s/(\"$currentday\")/$1 SELECTED/ if length($currentday);
415: my $year=<<END;
1.8 harris41 416: <select name="${name}_year">
1.11 harris41 417: <option value='$defaultyear'> </option>
418: <option value="1976">1976</option>
419: <option value="1977">1977</option>
420: <option value="1978">1978</option>
421: <option value="1979">1979</option>
422: <option value="1980">1980</option>
423: <option value="1981">1981</option>
424: <option value="1982">1982</option>
425: <option value="1983">1983</option>
426: <option value="1984">1984</option>
427: <option value="1985">1985</option>
428: <option value="1986">1986</option>
429: <option value="1987">1987</option>
430: <option value="1988">1988</option>
431: <option value="1989">1989</option>
432: <option value="1990">1990</option>
433: <option value="1991">1991</option>
434: <option value="1992">1992</option>
435: <option value="1993">1993</option>
436: <option value="1994">1994</option>
437: <option value="1995">1995</option>
438: <option value="1996">1996</option>
439: <option value="1997">1997</option>
440: <option value="1998">1998</option>
441: <option value="1999">1999</option>
442: <option value="2000">2000</option>
443: <option value="2001">2001</option>
444: <option value="2002">2002</option>
445: <option value="2003">2003</option>
446: <option value="2004">2004</option>
447: <option value="2005">2005</option>
448: <option value="2006">2006</option>
449: <option value="2007">2007</option>
450: <option value="2008">2008</option>
451: <option value="2009">2009</option>
452: <option value="2010">2010</option>
453: <option value="2011">2011</option>
454: <option value="2012">2012</option>
455: <option value="2013">2013</option>
456: <option value="2014">2014</option>
457: <option value="2015">2015</option>
458: <option value="2016">2016</option>
459: <option value="2017">2017</option>
460: <option value="2018">2018</option>
461: <option value="2019">2019</option>
462: <option value="2020">2020</option>
463: <option value="2021">2021</option>
464: <option value="2022">2022</option>
465: <option value="2023">2023</option>
466: <option value="2024">2024</option>
467: <option value="2025">2025</option>
468: <option value="2026">2026</option>
469: <option value="2027">2027</option>
470: <option value="2028">2028</option>
471: <option value="2029">2029</option>
472: <option value="2030">2030</option>
473: <option value="2031">2031</option>
474: <option value="2032">2032</option>
475: <option value="2033">2033</option>
476: <option value="2034">2034</option>
477: <option value="2035">2035</option>
478: <option value="2036">2036</option>
479: <option value="2037">2037</option>
480: <option value="2038">2038</option>
481: <option value="2039">2039</option>
482: <option value="2040">2040</option>
483: <option value="2041">2041</option>
484: <option value="2042">2042</option>
485: <option value="2043">2043</option>
486: <option value="2044">2044</option>
487: <option value="2045">2045</option>
488: <option value="2046">2046</option>
489: <option value="2047">2047</option>
490: <option value="2048">2048</option>
491: <option value="2049">2049</option>
492: <option value="2050">2050</option>
493: <option value="2051">2051</option>
1.3 harris41 494: </select>
495: END
1.11 harris41 496: $year=~s/(\"$currentyear\")/$1 SELECTED/ if length($currentyear);
497: return "$month$day$year";
1.3 harris41 498: }
499:
500: sub selectbox {
501: my ($title,$name,$value,%options)=@_;
502: my $uctitle=uc($title);
503: my $selout="\n<p><font color=\"#800000\" face=\"helvetica\"><b>$uctitle:".
504: "</b></font><br>".'<select name="'.$name.'">';
505: map {
1.68 harris41 506: $selout.='<option value=\''.$_.'\'';
1.3 harris41 507: if ($_ eq $value) { $selout.=' selected'; }
508: $selout.='>'.$options{$_}.'</option>';
509: } sort keys %options;
510: return $selout.'</select>';
1.6 harris41 511: }
512:
1.45 harris41 513: # ----------------------------------------------- Performing an advanced search
1.18 harris41 514: sub advancedsearch {
515: my ($r,$envhash)=@_;
516: my %ENV=%{$envhash};
517:
1.32 harris41 518: my $fillflag=0;
1.64 harris41 519: # Clean up fields for safety
520: for my $field ('title','author','subject','keywords','url','version',
521: 'creationdatestart_month','creationdatestart_day',
522: 'creationdatestart_year','creationdateend_month',
523: 'creationdateend_day','creationdateend_year',
524: 'lastrevisiondatestart_month','lastrevisiondatestart_day',
525: 'lastrevisiondatestart_year','lastrevisiondateend_month',
526: 'lastrevisiondateend_day','lastrevisiondateend_year',
527: 'notes','abstract','mime','language','owner',
1.77 harris41 528: 'custommetadata','customshow') {
1.68 harris41 529: $ENV{"form.$field"}=~s/[^\w\s\(\)\=\-\"\']//g;
1.64 harris41 530: }
1.90 harris41 531:
532: # Check to see if enough information was filled in
1.32 harris41 533: for my $field ('title','author','subject','keywords','url','version',
534: 'notes','abstract','mime','language','owner',
535: 'custommetadata') {
1.40 harris41 536: if (&filled($ENV{"form.$field"})) {
1.32 harris41 537: $fillflag++;
538: }
539: }
540: unless ($fillflag) {
541: &output_blank_field_error($r);
542: return OK;
543: }
1.39 harris41 544:
1.90 harris41 545:
546: # Turn the form input into a SQL-based query
1.39 harris41 547: my $query='';
1.44 harris41 548:
1.45 harris41 549: my @queries;
1.90 harris41 550: # Evaluate logical expression AND/OR/NOT phrase fields.
1.58 harris41 551: foreach my $field ('title','author','subject','notes','abstract','url',
552: 'keywords','version','owner') {
1.44 harris41 553: if ($ENV{'form.'.$field}) {
1.45 harris41 554: push @queries,&build_SQL_query($field,$ENV{'form.'.$field});
1.44 harris41 555: }
556: }
1.90 harris41 557: # Evaluate option lists
1.58 harris41 558: if ($ENV{'form.language'} and $ENV{'form.language'} ne 'any') {
1.90 harris41 559: push @queries,"(language like \"$ENV{'form.language'}\")";
1.58 harris41 560: }
561: if ($ENV{'form.mime'} and $ENV{'form.mime'} ne 'any') {
1.90 harris41 562: push @queries,"(mime like \"$ENV{'form.mime'}\")";
1.58 harris41 563: }
564: if ($ENV{'form.copyright'} and $ENV{'form.copyright'} ne 'any') {
1.90 harris41 565: push @queries,"(copyright like \"$ENV{'form.copyright'}\")";
1.58 harris41 566: }
1.90 harris41 567: # Evaluate date windows
1.60 harris41 568: my $datequery=&build_date_queries(
569: $ENV{'form.creationdatestart_month'},
570: $ENV{'form.creationdatestart_day'},
571: $ENV{'form.creationdatestart_year'},
572: $ENV{'form.creationdateend_month'},
573: $ENV{'form.creationdateend_day'},
574: $ENV{'form.creationdateend_year'},
575: $ENV{'form.lastrevisiondatestart_month'},
576: $ENV{'form.lastrevisiondatestart_day'},
577: $ENV{'form.lastrevisiondatestart_year'},
578: $ENV{'form.lastrevisiondateend_month'},
579: $ENV{'form.lastrevisiondateend_day'},
580: $ENV{'form.lastrevisiondateend_year'},
581: );
1.90 harris41 582: # Test to see if date windows are legitimate
1.61 harris41 583: if ($datequery=~/^Incorrect/) {
584: &output_date_error($r,$datequery);
585: return OK;
586: }
587: elsif ($datequery) {
1.60 harris41 588: push @queries,$datequery;
589: }
1.90 harris41 590:
591: # Process form information for custom metadata querying
1.76 harris41 592: my $customquery='';
1.64 harris41 593: if ($ENV{'form.custommetadata'}) {
594: $customquery=&build_custommetadata_query('custommetadata',
595: $ENV{'form.custommetadata'});
596: }
1.83 harris41 597: my $customshow='';
598: if ($ENV{'form.customshow'}) {
599: $customshow=$ENV{'form.customshow'};
600: $customshow=~s/[^\w\s]//g;
601: my @fields=split(/\s+/,$customshow);
602: $customshow=join(" ",@fields);
603: }
1.90 harris41 604: # Send query statements over the network to be processed by either the SQL
605: # database or a recursive scheme of 'grep'-like actions (for custom
606: # metadata).
1.45 harris41 607: if (@queries) {
1.58 harris41 608: $query=join(" AND ",@queries);
1.46 harris41 609: $query="select * from metadata where $query";
1.90 harris41 610: my $reply; # reply hash reference
1.83 harris41 611: unless ($customquery or $customshow) {
1.76 harris41 612: $reply=&Apache::lonnet::metadata_query($query);
613: }
614: else {
1.83 harris41 615: $reply=&Apache::lonnet::metadata_query($query,
616: $customquery,$customshow);
1.76 harris41 617: }
1.64 harris41 618: &output_results('Advanced',$r,$envhash,$customquery,$reply);
1.45 harris41 619: }
1.86 harris41 620: elsif ($customquery) {
1.90 harris41 621: my $reply; # reply hash reference
1.86 harris41 622: $reply=&Apache::lonnet::metadata_query('',
623: $customquery,$customshow);
624: &output_results('Advanced',$r,$envhash,$customquery,$reply);
1.45 harris41 625: }
1.92 harris41 626: # should not get to this point
627: return 'Error. Should not have gone to this point.';
1.18 harris41 628: }
629:
1.26 harris41 630: # ---------------------------------------------------- see if a field is filled
631: sub filled {
1.31 harris41 632: my ($field)=@_;
1.92 harris41 633: if ($field=~/\S/ && $field ne 'any') {
1.28 harris41 634: return 1;
635: }
636: else {
637: return 0;
638: }
1.26 harris41 639: }
640:
1.6 harris41 641: # --------------------------------------------------- Performing a basic search
642: sub basicsearch {
1.19 harris41 643: my ($r,$envhash)=@_;
644: my %ENV=%{$envhash};
1.6 harris41 645:
1.64 harris41 646: # Clean up fields for safety
647: for my $field ('basicexp') {
648: $ENV{"form.$field"}=~s/[^\w\s\(\)\-]//g;
649: }
650:
1.90 harris41 651: # Check to see if enough is filled in
1.26 harris41 652: unless (&filled($ENV{'form.basicexp'})) {
1.24 harris41 653: &output_blank_field_error($r);
654: return OK;
655: }
1.22 harris41 656:
1.90 harris41 657: # Build SQL query string based on form page
1.39 harris41 658: my $query='';
1.33 harris41 659: my $concatarg=join('," ",',
660: ('title', 'author', 'subject', 'notes', 'abstract'));
1.95 harris41 661: $concatarg='title' if $ENV{'form.titleonly'};
1.94 harris41 662:
663: $query=&build_SQL_query('concat('.$concatarg.')',$ENV{'form.'.'basicexp'});
664:
1.33 harris41 665:
1.90 harris41 666: # Get reply (either a hash reference to filehandles or bad connection)
1.94 harris41 667: my $reply=&Apache::lonnet::metadata_query('select * from metadata where '.$query);
1.90 harris41 668:
669: # Output search results
1.44 harris41 670: &output_results('Basic',$r,$envhash,$query,$reply);
1.90 harris41 671:
1.18 harris41 672: return OK;
1.22 harris41 673: }
674:
1.44 harris41 675: # ---------------- Message to output when there are not enough fields filled in
1.22 harris41 676: sub output_blank_field_error {
677: my ($r)=@_;
678: # make query information persistent to allow for subsequent revision
1.65 harris41 679: my $persistent=&make_persistent();
1.22 harris41 680:
681: $r->print(<<BEGINNING);
682: <html>
683: <head>
684: <title>The LearningOnline Network with CAPA</title>
685: BEGINNING
686: $r->print(<<RESULTS);
687: </head>
688: <body bgcolor="#ffffff">
689: <img align=right src=/adm/lonIcons/lonlogos.gif>
690: <h1>Search Catalog</h1>
691: <form method="post" action="/adm/searchcat">
692: $persistent
693: <input type='button' value='Revise search request'
694: onClick='this.form.submit();'>
1.46 harris41 695: $closebutton
1.22 harris41 696: <hr>
697: <h3>Helpful Message</h3>
698: <p>
699: Incorrect search query due to blank entry fields.
700: You need to fill in the relevant
701: fields on the search page in order for a query to be
702: processed.
703: </p>
704: </body>
705: </html>
706: RESULTS
1.18 harris41 707: }
1.6 harris41 708:
1.18 harris41 709: # ----------------------------- format and output results based on a reply list
710: sub output_results {
1.92 harris41 711: my ($mode,$r,$envhash,$query,$replyref)=@_;
1.19 harris41 712: my %ENV=%{$envhash};
1.92 harris41 713: my %rhash=%{$replyref};
1.44 harris41 714: my $compiledresult='';
1.92 harris41 715: my $timeremain=30;
1.93 harris41 716: my $resultflag=0;
717: my $tflag=1;
718:
719: # make query information persistent to allow for subsequent revision
720: my $persistent=&make_persistent();
721:
722: # output beginning of search page
1.92 harris41 723: $r->print(<<BEGINNING);
724: <html>
725: <head>
726: <title>The LearningOnline Network with CAPA</title>
727: BEGINNING
728: $r->print(<<SCRIPT) if $ENV{'form.catalogmode'} eq 'interactive';
729: <script>
730: function select_data(title,url) {
731: changeTitle(title);
732: changeURL(url);
733: }
734: function changeTitle(val) {
735: if (opener.inf.document.forms.resinfo.elements.t) {
736: opener.inf.document.forms.resinfo.elements.t.value=val;
737: }
738: }
739: function changeURL(val) {
740: if (opener.inf.document.forms.resinfo.elements.u) {
741: opener.inf.document.forms.resinfo.elements.u.value=val;
742: }
743: }
744: </script>
745: SCRIPT
746: $r->print(<<CATALOGBEGIN);
747: </head>
748: <body bgcolor="#ffffff">
749: <img align=right src=/adm/lonIcons/lonlogos.gif>
750: <h1>Search Catalog</h1>
751: CATALOGBEGIN
1.93 harris41 752: $r->print(<<RESULTS);
753: <form method="post" action="/adm/searchcat">
754: <input type='button' value='Revise search request'
755: onClick='this.form.submit();'>
756: $closebutton
757: $persistent
758: <hr>
759: <h3>Search Query</h3>
760: RESULTS
761: if ($mode eq 'Basic') {
762: $r->print(<<RESULTS);
763: <p>
764: <b>Basic search:</b> $ENV{'form.basicexp'}
765: </p>
766: RESULTS
767: }
768: elsif ($mode eq 'Advanced') {
769: $r->print(<<RESULTS);
770: <p>
771: <b>Advanced search</b>
772: $query
773: </p>
774: RESULTS
775: }
776: $r->print('<h3>Search Results</h3>');
1.92 harris41 777: $r->rflush();
778: $r->print(<<ENDPOP);
779: <script>
780: popwin=open('','popwin','width=400,height=200');
781: popwin.document.writeln('<html><body bgcolor="#FFFFFF">'+
782: '<h3>Search Results Progress</h3>'+
783: '<form name=popremain>'+
784: '<br />Server space <input type=text size=25 name=space value="">'+
785: '<br />Status <input type=text size=25 name=status value="">'+
786: '<br />Maximum remaining time <input type=text size=25 name=timeout value="30">'+
787: '</form>'+
788: '</body></html>');
789: popwin.document.close();
790: </script>
791: ENDPOP
792: $r->rflush();
1.44 harris41 793:
1.92 harris41 794: my $servernum=(keys %rhash)+0;
795: $r->print('<script>popwin.document.popremain.space.value="'.
1.93 harris41 796: $servernum.', 0%, count=0/'.$servernum.'";</script>');
1.92 harris41 797: $r->rflush();
1.93 harris41 798: my $servercount=0;
1.92 harris41 799: foreach my $rkey (keys %rhash) {
1.93 harris41 800: $servercount++;
801: $tflag=1;
802: $compiledresult='';
803: my $hostname=$rkey;
1.92 harris41 804: $r->print('<script>popwin.document.popremain.status.value="'.
805: $rkey.', trying contact";</script>');
806: $r->rflush();
807: my $reply=$rhash{$rkey};
1.18 harris41 808: my @results;
1.92 harris41 809:
1.18 harris41 810: my $replyfile='';
1.93 harris41 811:
812: if ($reply eq 'con_lost') {
813: my $percent=sprintf('%3.0f',($servercount/$servernum*100));
814: $r->print('<script>popwin.document.popremain.space.value="'.
815: $servernum.', '.$percent.'%, count='.$servercount.
816: '/'.$servernum.'";</script>');
817: }
818: else {
819: $reply=~/^([\.\w]+)$/; # must do since 'use strict' checks for tainting
820: $replyfile=$r->dir_config('lonDaemons').'/tmp/'.$1;
821: $reply=~/(.*?)\_/;
822: {
823: while (1) {
824: if (-e $replyfile && $tflag) {
825: $r->print('<script>popwin.document.popremain.status.'.
826: 'value="'.$rkey.', transmitting";</script>');
827: $r->rflush();
828: $tflag=0;
829: }
830: last if -e "$replyfile.end";
831: last unless $timeremain;
832: sleep 1;
833: $timeremain--;
834: $r->print('<script>popwin.document.popremain.timeout.value="'.
835: $timeremain.'";</script>');
836: $r->rflush();
837: }
838: # QUESTION: how should I handle this error condition..
839: # I'm sure there is syntax elsewhere I can use..
840: my $fh=Apache::File->new($replyfile) or
841: ($r->print('ERROR: file cannot be opened') and return OK);
842: @results=<$fh>;
843: }
1.6 harris41 844: }
1.77 harris41 845: my $customshow='';
846: my $extrashow='';
1.87 harris41 847: my @customfields;
1.77 harris41 848: if ($ENV{'form.customshow'}) {
849: $customshow=$ENV{'form.customshow'};
850: $customshow=~s/[^\w\s]//g;
1.87 harris41 851: my @fields=map {"<font color=\"#008000\">$_:</font><!-- $_ -->"}
1.93 harris41 852: split(/\s+/,$customshow);
1.88 harris41 853: @customfields=split(/\s+/,$customshow);
1.81 harris41 854: if ($customshow) {
855: $extrashow="<ul><li>".join("</li><li>",@fields)."</li></ul>\n";
856: }
1.77 harris41 857: }
1.79 harris41 858: my $customdata='';
1.87 harris41 859: my %customhash;
1.79 harris41 860: foreach my $result (@results) {
1.82 harris41 861: if ($result=~/^(custom\=.*)$/) { # grab all custom metadata
1.87 harris41 862: my $tmp=$result;
863: $tmp=~s/^custom\=//;
864: my ($k,$v)=map {&Apache::lonnet::unescape($_);
865: } split(/\,/,$tmp);
866: $customhash{$k}=$v;
1.82 harris41 867: }
1.79 harris41 868: }
1.18 harris41 869: foreach my $result (@results) {
1.82 harris41 870: next if $result=~/^custom\=/;
871: chomp $result;
1.85 harris41 872: next unless $result;
1.50 harris41 873: my @fields=map
1.93 harris41 874: {&Apache::lonnet::unescape($_)}
875: (split(/\,/,$result));
1.18 harris41 876: my ($title,$author,$subject,$url,$keywords,$version,
877: $notes,$abstract,$mime,$lang,
1.50 harris41 878: $creationdate,$lastrevisiondate,$owner,$copyright)=@fields;
1.18 harris41 879: my $shortabstract=$abstract;
880: $shortabstract=substr($abstract,0,200) if length($abstract)>200;
1.51 harris41 881: $fields[7]=$shortabstract;
1.87 harris41 882: my $extrashow2=$extrashow;
883: if ($extrashow) {
884: foreach my $field (@customfields) {
885: my $value='';
886: if ($customhash{$url}=~/\<${field}[^\>]*\>(.*?)\<\/${field}[^\>]*\>/s) {
1.93 harris41 887: $value=$1;
1.87 harris41 888: }
1.93 harris41 889: $extrashow2=~s/\<\!\-\- $field \-\-\>/ $value/g;
890: }
891: }
892:
893: $compiledresult.=<<END if $compiledresult;
1.89 harris41 894: <hr align='left' width='200' noshade />
895: END
1.93 harris41 896: $compiledresult.=<<END;
1.56 harris41 897: <p>
1.8 harris41 898: END
1.93 harris41 899: $compiledresult.=<<END if $ENV{'form.catalogmode'} eq 'interactive';
1.8 harris41 900: <font size='-1'><INPUT TYPE="button" NAME="returnvalues" VALUE="SELECT"
1.10 harris41 901: onClick="javascript:select_data('$title','$url')">
1.8 harris41 902: </font>
903: <br>
904: END
1.51 harris41 905: my $httphost=$ENV{'HTTP_HOST'};
1.53 harris41 906:
1.93 harris41 907: my $viewselect;
908: if ($mode eq 'Basic') {
1.55 harris41 909: $viewselect=$ENV{'form.basicviewselect'};
910: }
1.93 harris41 911: elsif ($mode eq 'Advanced') {
912: $viewselect=$ENV{'form.advancedviewselect'};
913: }
1.55 harris41 914:
915: if ($viewselect eq 'Detailed Citation View') {
1.93 harris41 916: $compiledresult.=&detailed_citation_view(@fields,
917: $hostname,$httphost,
918: $extrashow2);
1.50 harris41 919: }
1.55 harris41 920: elsif ($viewselect eq 'Summary View') {
1.77 harris41 921: $compiledresult.=&summary_view(@fields,$hostname,$httphost,
1.93 harris41 922: $extrashow2);
1.50 harris41 923: }
1.55 harris41 924: elsif ($viewselect eq 'Fielded Format') {
1.51 harris41 925: $compiledresult.=&fielded_format_view(@fields,$hostname,
1.93 harris41 926: $httphost,$extrashow2);
1.50 harris41 927: }
1.55 harris41 928: elsif ($viewselect eq 'XML/SGML') {
1.77 harris41 929: $compiledresult.=&xml_sgml_view(@fields,$hostname,$httphost,
1.93 harris41 930: $extrashow2);
1.50 harris41 931: }
1.93 harris41 932:
1.18 harris41 933: }
1.6 harris41 934:
1.93 harris41 935: if ($compiledresult) {
936: $resultflag=1;
1.18 harris41 937: }
1.6 harris41 938:
1.43 harris41 939: $r->print(<<RESULTS);
1.93 harris41 940: $compiledresult
1.43 harris41 941: RESULTS
1.93 harris41 942: my $percent=sprintf('%3.0f',($servercount/$servernum*100));
943: $r->print('<script>popwin.document.popremain.space.value="'.
944: $servernum.', '.$percent.'%, count='.$servercount.
945: '/'.$servernum.'";</script>');
1.44 harris41 946: }
1.93 harris41 947: unless ($resultflag) {
948: $r->print("\nThere were no results that matched your query\n");
1.43 harris41 949: }
1.93 harris41 950: $r->print('<script>popwin.close()</script>'); $r->rflush();
951: $r->print(<<RESULTS);
1.6 harris41 952: </body>
953: </html>
954: RESULTS
1.41 harris41 955: }
956:
957: # ------------------------------------------------------------- build_SQL_query
958: sub build_SQL_query {
1.43 harris41 959: my ($field_name,$logic_statement)=@_;
960: my $q=new Text::Query('abc',
961: -parse => 'Text::Query::ParseAdvanced',
962: -build => 'Text::Query::Build');
1.44 harris41 963: $q->prepare($logic_statement);
1.43 harris41 964: my $matchexp=${$q}{'matchexp'}; chomp $matchexp;
965: my $sql_query=&recursive_SQL_query_build($field_name,$matchexp);
1.44 harris41 966: return $sql_query;
1.43 harris41 967: }
1.41 harris41 968:
1.64 harris41 969: # ------------------------------------------------- build custom metadata query
970: sub build_custommetadata_query {
971: my ($field_name,$logic_statement)=@_;
972: my $q=new Text::Query('abc',
973: -parse => 'Text::Query::ParseAdvanced',
974: -build => 'Text::Query::BuildAdvancedString');
975: $q->prepare($logic_statement);
976: my $matchexp=${$q}{'-parse'}{'-build'}{'matchstring'};
1.69 harris41 977: # quick fix to change literal into xml tag-matching
1.75 harris41 978: # will eventually have to write a separate builder module
1.72 harris41 979: my $oldmatchexp=$matchexp;
1.88 harris41 980: $matchexp=~s/(\w+)\\\=([\w\\\+]+)/\\\<$1\\\>\[\^\\\<\]\*$2\[\^\\\<\]\*\\\<\\\/$1\\\>/g;
1.76 harris41 981: return $matchexp;
1.64 harris41 982: }
983:
1.43 harris41 984: # - Recursively parse a reverse notation expression into a SQL query expression
985: sub recursive_SQL_query_build {
986: my ($dkey,$pattern)=@_;
987: my @matches=($pattern=~/(\[[^\]|\[]*\])/g);
988: return $pattern unless @matches;
989: foreach my $match (@matches) {
990: $match=~/\[ (\w+)\s(.*) \]/;
1.44 harris41 991: my ($key,$value)=($1,$2);
1.43 harris41 992: my $replacement='';
993: if ($key eq 'literal') {
994: $replacement="($dkey like \"\%$value\%\")";
1.94 harris41 995: }
996: elsif ($key eq 'not') {
997: $value=~s/like/not like/;
998: # $replacement="($dkey not like $value)";
999: $replacement="$value";
1.43 harris41 1000: }
1001: elsif ($key eq 'and') {
1002: $value=~/(.*[\"|\)]) ([|\(|\^].*)/;
1003: $replacement="($1 AND $2)";
1004: }
1005: elsif ($key eq 'or') {
1006: $value=~/(.*[\"|\)]) ([|\(|\^].*)/;
1007: $replacement="($1 OR $2)";
1008: }
1009: substr($pattern,
1010: index($pattern,$match),
1011: length($match),
1012: $replacement
1013: );
1014: }
1015: &recursive_SQL_query_build($dkey,$pattern);
1.50 harris41 1016: }
1017:
1018: # ------------------------------------------------------ Detailed Citation View
1019: sub detailed_citation_view {
1020: my ($title,$author,$subject,$url,$keywords,$version,
1.51 harris41 1021: $notes,$shortabstract,$mime,$lang,
1022: $creationdate,$lastrevisiondate,$owner,$copyright,
1.77 harris41 1023: $hostname,$httphost,$extrashow)=@_;
1.50 harris41 1024: my $result=<<END;
1.56 harris41 1025: <i>$owner</i>, last revised $lastrevisiondate
1026: <h3><A HREF="http://$httphost$url" TARGET='search_preview'>$title</A></h3>
1027: <h3>$author</h3>
1028: </p>
1029: <p>
1.50 harris41 1030: <b>Subject:</b> $subject<br>
1031: <b>Keyword(s):</b> $keywords<br>
1032: <b>Notes:</b> $notes<br>
1033: <b>MIME Type:</b> $mimetag{$mime}<br>
1034: <b>Language:</b> $language{$lang}<br>
1.56 harris41 1035: <b>Copyright/Distribution:</b> $cprtag{$copyright}<br>
1.78 harris41 1036: </p>
1.77 harris41 1037: $extrashow
1.78 harris41 1038: <p>
1.56 harris41 1039: $shortabstract
1.50 harris41 1040: </p>
1041: END
1042: return $result;
1043: }
1044:
1045: # ---------------------------------------------------------------- Summary View
1046: sub summary_view {
1047: my ($title,$author,$subject,$url,$keywords,$version,
1.51 harris41 1048: $notes,$shortabstract,$mime,$lang,
1049: $creationdate,$lastrevisiondate,$owner,$copyright,
1.77 harris41 1050: $hostname,$httphost,$extrashow)=@_;
1.50 harris41 1051: my $result=<<END;
1.56 harris41 1052: <a href="http://$httphost$url" TARGET='search_preview'>$author</a><br />
1053: $title<br />
1054: $owner -- $lastrevisiondate<br />
1055: $cprtag{$copyright}<br />
1.77 harris41 1056: $extrashow
1.50 harris41 1057: </p>
1058: END
1059: return $result;
1060: }
1061:
1062: # -------------------------------------------------------------- Fielded Format
1063: sub fielded_format_view {
1064: my ($title,$author,$subject,$url,$keywords,$version,
1.51 harris41 1065: $notes,$shortabstract,$mime,$lang,
1066: $creationdate,$lastrevisiondate,$owner,$copyright,
1.77 harris41 1067: $hostname,$httphost,$extrashow)=@_;
1.50 harris41 1068: my $result=<<END;
1.51 harris41 1069: <b>URL: </b> <A HREF="http://$httphost$url" TARGET='search_preview'>$url</A>
1.56 harris41 1070: <br />
1071: <b>Title:</b> $title<br />
1072: <b>Author(s):</b> $author<br />
1073: <b>Subject:</b> $subject<br />
1074: <b>Keyword(s):</b> $keywords<br />
1075: <b>Notes:</b> $notes<br />
1076: <b>MIME Type:</b> $mimetag{$mime}<br />
1077: <b>Language:</b> $language{$lang}<br />
1078: <b>Creation Date:</b> $creationdate<br />
1079: <b>Last Revision Date:</b> $lastrevisiondate<br />
1080: <b>Publisher/Owner:</b> $owner<br />
1081: <b>Copyright/Distribution:</b> $cprtag{$copyright}<br />
1082: <b>Repository Location:</b> $hostname<br />
1083: <b>Abstract:</b> $shortabstract<br />
1.77 harris41 1084: $extrashow
1.50 harris41 1085: </p>
1086: END
1087: return $result;
1088: }
1089:
1090: # -------------------------------------------------------------------- XML/SGML
1091: sub xml_sgml_view {
1092: my ($title,$author,$subject,$url,$keywords,$version,
1.51 harris41 1093: $notes,$shortabstract,$mime,$lang,
1094: $creationdate,$lastrevisiondate,$owner,$copyright,
1.77 harris41 1095: $hostname,$httphost,$extrashow)=@_;
1.50 harris41 1096: my $result=<<END;
1.56 harris41 1097: <pre>
1098: <LonCapaResource>
1.57 harris41 1099: <url>$url</url>
1.56 harris41 1100: <title>$title</title>
1101: <author>$author</author>
1102: <subject>$subject</subject>
1103: <keywords>$keywords</keywords>
1104: <notes>$notes</notes>
1105: <mimeInfo>
1106: <mime>$mime</mime>
1107: <mimetag>$mimetag{$mime}</mimetag>
1108: </mimeInfo>
1109: <languageInfo>
1110: <language>$lang</language>
1111: <languagetag>$language{$lang}</languagetag>
1112: </languageInfo>
1113: <creationdate>$creationdate</creationdate>
1114: <lastrevisiondate>$lastrevisiondate</lastrevisiondate>
1115: <owner>$owner</owner>
1116: <copyrightInfo>
1117: <copyright>$copyright</copyright>
1118: <copyrighttag>$cprtag{$copyright}</copyrighttag>
1119: </copyrightInfo>
1120: <repositoryLocation>$hostname</repositoryLocation>
1121: <shortabstract>$shortabstract</shortabstract>
1.57 harris41 1122: </LonCapaResource>
1.56 harris41 1123: </pre>
1.77 harris41 1124: $extrashow
1.50 harris41 1125: END
1126: return $result;
1.60 harris41 1127: }
1128:
1129: sub build_date_queries {
1130: my ($cmonth1,$cday1,$cyear1,$cmonth2,$cday2,$cyear2,
1131: $lmonth1,$lday1,$lyear1,$lmonth2,$lday2,$lyear2)=@_;
1.61 harris41 1132: my @queries;
1133: if ($cmonth1 or $cday1 or $cyear1 or $cmonth2 or $cday2 or $cyear2) {
1134: unless ($cmonth1 and $cday1 and $cyear1 and
1135: $cmonth2 and $cday2 and $cyear2) {
1136: return "Incorrect entry for the creation date. You must specify ".
1137: "a starting month, day, and year and an ending month, ".
1138: "day, and year.";
1139: }
1.63 harris41 1140: my $cnumeric1=sprintf("%d%2d%2d",$cyear1,$cmonth1,$cday1);
1.61 harris41 1141: $cnumeric1+=0;
1.63 harris41 1142: my $cnumeric2=sprintf("%d%2d%2d",$cyear2,$cmonth2,$cday2);
1.61 harris41 1143: $cnumeric2+=0;
1144: if ($cnumeric1>$cnumeric2) {
1145: return "Incorrect entry for the creation date. The starting ".
1146: "date must occur before the ending date.";
1147: }
1148: my $cquery="(creationdate BETWEEN '$cyear1-$cmonth1-$cday1' AND '".
1149: "$cyear2-$cmonth2-$cday2 23:59:59')";
1150: push @queries,$cquery;
1151: }
1152: if ($lmonth1 or $lday1 or $lyear1 or $lmonth2 or $lday2 or $lyear2) {
1153: unless ($lmonth1 and $lday1 and $lyear1 and
1154: $lmonth2 and $lday2 and $lyear2) {
1155: return "Incorrect entry for the last revision date. You must ".
1156: "specify a starting month, day, and year and an ending ".
1157: "month, day, and year.";
1.62 harris41 1158: }
1.63 harris41 1159: my $lnumeric1=sprintf("%d%2d%2d",$lyear1,$lmonth1,$lday1);
1.61 harris41 1160: $lnumeric1+=0;
1.63 harris41 1161: my $lnumeric2=sprintf("%d%2d%2d",$lyear2,$lmonth2,$lday2);
1.61 harris41 1162: $lnumeric2+=0;
1163: if ($lnumeric1>$lnumeric2) {
1164: return "Incorrect entry for the last revision date. The ".
1165: "starting date must occur before the ending date.";
1166: }
1167: my $lquery="(lastrevisiondate BETWEEN '$lyear1-$lmonth1-$lday1' AND '".
1168: "$lyear2-$lmonth2-$lday2 23:59:59')";
1169: push @queries,$lquery;
1170: }
1171: if (@queries) {
1172: return join(" AND ",@queries);
1173: }
1174: return '';
1.60 harris41 1175: }
1176:
1177: sub output_date_error {
1178: my ($r,$message)=@_;
1179: # make query information persistent to allow for subsequent revision
1.65 harris41 1180: my $persistent=&make_persistent();
1.60 harris41 1181:
1182: $r->print(<<BEGINNING);
1183: <html>
1184: <head>
1185: <title>The LearningOnline Network with CAPA</title>
1186: BEGINNING
1187: $r->print(<<RESULTS);
1188: </head>
1189: <body bgcolor="#ffffff">
1190: <img align=right src=/adm/lonIcons/lonlogos.gif>
1191: <h1>Search Catalog</h1>
1192: <form method="post" action="/adm/searchcat">
1193: $persistent
1194: <input type='button' value='Revise search request'
1195: onClick='this.form.submit();'>
1196: $closebutton
1197: <hr>
1198: <h3>Helpful Message</h3>
1199: <p>
1200: $message
1201: </p>
1202: </body>
1203: </html>
1204: RESULTS
1.3 harris41 1205: }
1.1 www 1206:
1.64 harris41 1207: sub make_persistent {
1.65 harris41 1208: my $persistent='';
1.66 harris41 1209:
1.65 harris41 1210: map {
1211: if (/^form\./ && !/submit/) {
1212: my $name=$_;
1213: my $key=$name;
1.69 harris41 1214: $ENV{$key}=~s/\'//g; # do not mess with html field syntax
1.65 harris41 1215: $name=~s/^form\.//;
1216: $persistent.=<<END;
1.68 harris41 1217: <input type='hidden' name='$name' value='$ENV{$key}' />
1.65 harris41 1218: END
1219: }
1220: } (keys %ENV);
1221: return $persistent;
1.64 harris41 1222: }
1.1 www 1223: 1;
1224: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>