Annotation of loncom/interface/lonsearchcat.pm, revision 1.53
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
6: # Scott Harrison: 03/20/2001
1.1 www 7: #
1.41 harris41 8: # Functions
9: #
10: # handler(server reference) : interacts with the Apache server layer
11: # (for /adm/searchcat URLs)
12: # simpletextfield(name,value) : returns HTML formatted string for simple text
13: # field
14: # simplecheckbox(name,value) : returns HTML formatted string for simple
15: # checkbox
16: # searchphrasefield(title,name,value) : returns HTML formatted string for
17: # a search expression phrase field
18: # dateboxes(name, defaultmonth, defaultday, defaultyear) : returns HTML
19: # formatted string
20: # for a calendar date
21: # selectbox(title,name,value,%HASH=options) : returns HTML formatted string for
22: # a selection box field
1.42 harris41 23: # advancedsearch(server reference, environment reference) : perform a complex
24: # multi-field logical query
1.41 harris41 25: # filled(field) : determines whether a given field has been filled
1.42 harris41 26: # basicsearch(server reference, environment reference) : perform a simple
27: # single-field logical query
28: # output_blank_field_error(server reference) : outputs a message saying that
29: # more fields need to be filled in
30: # output_results(output mode,
31: # server reference,
32: # environment reference,
33: # reply list reference) : outputs results from search
1.43 harris41 34: # build_SQL_query(field name, logic) : builds a SQL query string from a
35: # logical expression with AND/OR keywords
36: # recursive_SQL_query_build(field name, reverse notation expression) :
37: # builds a SQL query string from a reverse notation expression
38: # logical expression with AND/OR keywords
1.41 harris41 39:
1.1 www 40: package Apache::lonsearchcat;
41:
42: use strict;
43: use Apache::Constants qw(:common);
1.6 harris41 44: use Apache::lonnet();
45: use Apache::File();
1.7 harris41 46: use CGI qw(:standard);
1.41 harris41 47: use Text::Query;
1.1 www 48:
1.3 harris41 49: my %language;
50: my $scrout;
51: my %metadatafields;
52: my %cprtag;
53: my %mimetag;
1.46 harris41 54: my $closebutton;
55: my $viewselect=<<END;
56: <select name='view'>
1.50 harris41 57: <option value='Detailed Citation View'>Detailed Citation View</option>
58: <option value='Summary View'>Summary View</option>
59: <option value='Fielded Format'>Fielded Format</option>
60: <option value='XML/SGML'>XML/SGML</option>
1.46 harris41 61: </select>
62: END
1.3 harris41 63:
1.1 www 64: sub handler {
65: my $r = shift;
1.7 harris41 66:
67: # -------------------------------------- see if called from an interactive mode
68: map {
69: my ($name, $value) = split(/=/,$_);
70: $value =~ tr/+/ /;
71: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
72: if ($name eq 'catalogmode') {
73: $ENV{'form.'.$name}=$value;
74: }
75: } (split(/&/,$ENV{'QUERY_STRING'}));
76:
1.1 www 77: $r->content_type('text/html');
78: $r->send_http_header;
79: return OK if $r->header_only;
80:
1.3 harris41 81: %metadatafields=();
82:
1.8 harris41 83: my $hidden='';
84: $hidden=<<END if $ENV{'form.catalogmode'} eq 'interactive';
85: <input type='hidden' name='catalogmode' value='interactive'>
86: END
87:
1.47 harris41 88: $closebutton=<<END if $ENV{'form.catalogmode'} eq 'interactive';
1.46 harris41 89: <input type="button" name="close" value="CLOSE" onClick="self.close()">
90: END
91:
1.3 harris41 92: # ------------------------------------------------ First, check out environment
93: $metadatafields{'owner'}=$ENV{'user.name'}.'@'.$ENV{'user.domain'};
94:
1.8 harris41 95: # --------------------------------- Compute various listings of metadata values
1.3 harris41 96:
97: %language=();
98: $language{'any'}='Any language';
99: {
100: my $fh=Apache::File->new($r->dir_config('lonTabDir').'/language.tab');
101: map {
102: $_=~/(\w+)\s+([\w\s\-]+)/;
103: $language{$1}=$2;
104: } <$fh>;
105: }
106:
107: %cprtag=();
108: $cprtag{'any'}='Any copyright/distribution';
109: {
110: my $fh=Apache::File->new($r->dir_config('lonIncludes').'/copyright.tab');
111: map {
112: $_=~/(\w+)\s+([\w\s\-]+)/;
113: $cprtag{$1}=$2;
114: } <$fh>;
115: }
116:
117: %mimetag=();
118: $mimetag{'any'}='Any type';
119: {
120: my $fh=Apache::File->new($r->dir_config('lonTabDir').'/filetypes.tab');
121: map {
122: $_=~/(\w+)\s+(\w+)\s+([\w\s\-]+)/;
123: $mimetag{$1}=".$1 $3";
124: } <$fh>;
125: }
126:
1.6 harris41 127: if ($ENV{'form.basicsubmit'} eq 'SEARCH') {
1.19 harris41 128: return &basicsearch($r,\%ENV);
1.6 harris41 129: }
1.18 harris41 130: elsif ($ENV{'form.advancedsubmit'} eq 'SEARCH') {
131: return &advancedsearch($r,\%ENV);
132: }
1.6 harris41 133:
1.8 harris41 134: $scrout=''; # building a part of screen output
1.3 harris41 135: $scrout.=&searchphrasefield('Limit by title','title',
1.11 harris41 136: $ENV{'form.title'});
1.3 harris41 137:
138: $scrout.=&searchphrasefield('Limit by author','author',
1.11 harris41 139: $ENV{'form.author'});
1.3 harris41 140:
141: $scrout.=&searchphrasefield('Limit by subject','subject',
1.11 harris41 142: $ENV{'form.subject'});
143:
144: $scrout.=&searchphrasefield('Limit by keywords','keywords',
145: $ENV{'form.keywords'});
146:
147: $scrout.=&searchphrasefield('Limit by URL','url',
148: $ENV{'form.url'});
149:
150: $scrout.=&searchphrasefield('Limit by version','version',
151: $ENV{'form.version'});
1.3 harris41 152:
153: $scrout.=&searchphrasefield('Limit by notes','notes',
1.11 harris41 154: $ENV{'form.notes'});
1.3 harris41 155:
156: $scrout.=&searchphrasefield('Limit by abstract','abstract',
1.11 harris41 157: $ENV{'form.abstract'});
1.3 harris41 158:
1.11 harris41 159: $ENV{'form.mime'}='notxxx' unless length($ENV{'form.mime'});
1.3 harris41 160: $scrout.=&selectbox('Limit by MIME type','mime',
1.11 harris41 161: $ENV{'form.mime'},%mimetag);
162:
163: $ENV{'form.language'}='any' unless length($ENV{'form.language'});
1.3 harris41 164:
165: $scrout.=&selectbox('Limit by language','language',
1.11 harris41 166: $ENV{'form.language'},%language);
1.3 harris41 167:
1.8 harris41 168:
169: # ------------------------------------------------ Compute date selection boxes
170: $scrout.=<<CREATIONDATESTART;
1.3 harris41 171: <p>
172: <font color="#800000" face="helvetica"><b>LIMIT BY CREATION DATE RANGE:</b>
173: </font>
174: <br>
1.8 harris41 175: between:
176: CREATIONDATESTART
1.11 harris41 177: $scrout.=&dateboxes('creationdatestart',1,1,1976,
178: $ENV{'form.creationdatestart_month'},
179: $ENV{'form.creationdatestart_day'},
180: $ENV{'form.creationdatestart_year'},
181: );
1.8 harris41 182: $scrout.=<<CREATIONDATEEND;
183: and:
184: CREATIONDATEEND
1.11 harris41 185: $scrout.=&dateboxes('creationdateend',12,31,2051,
186: $ENV{'form.creationdateend_month'},
187: $ENV{'form.creationdateend_day'},
188: $ENV{'form.creationdateend_year'},
189: );
1.8 harris41 190: $scrout.="</p>";
191:
192: $scrout.=<<LASTREVISIONDATESTART;
193: <p>
194: <font color="#800000" face="helvetica"><b>LIMIT BY LAST REVISION DATE RANGE:
195: </b></font>
196: <br>between:
197: LASTREVISIONDATESTART
1.11 harris41 198: $scrout.=&dateboxes('lastrevisiondatestart',1,1,1976,
199: $ENV{'form.lastrevisiondatestart_month'},
200: $ENV{'form.lastrevisiondatestart_day'},
201: $ENV{'form.lastrevisiondatestart_year'},
202: );
1.8 harris41 203: $scrout.=<<LASTREVISIONDATEEND;
204: and:
205: LASTREVISIONDATEEND
1.11 harris41 206: $scrout.=&dateboxes('lastrevisiondateend',12,31,2051,
207: $ENV{'form.lastrevisiondateend_month'},
208: $ENV{'form.lastrevisiondateend_day'},
209: $ENV{'form.lastrevisiondateend_year'},
210: );
1.8 harris41 211: $scrout.='</p>';
212:
213: $scrout.=&searchphrasefield('Limit by publisher/owner','owner',
1.11 harris41 214: $ENV{'form.owner'});
215: # $metadatafields{'owner'});
1.8 harris41 216:
1.11 harris41 217: $ENV{'form.copyright'}='any' unless length($ENV{'form.copyright'});
1.8 harris41 218: $scrout.=&selectbox('Limit by copyright/distribution','copyright',
1.11 harris41 219: $ENV{'form.copyright'},%cprtag);
1.8 harris41 220:
1.14 harris41 221: # ------------------------------------------- Compute customized metadata field
222: $scrout.=<<CUSTOMMETADATA;
223: <p>
224: <font color="#800000" face="helvetica"><b>LIMIT BY OTHER METADATA FIELDS:</b>
225: </font>
226: For author-specific metadata, enter in an expression in the form of
227: <i>key</i>=<i>value</i> separated by operators such as AND or OR.<br>
228: <b>Example:</b> grandmother=75 OR grandfather=85
229: <br>
230: CUSTOMMETADATA
231: $scrout.=&simpletextfield('custommetadata',$ENV{'form.custommetadata'});
1.15 harris41 232: $scrout.=' <i>initial users of this system do not need to worry about this option</i>';
1.14 harris41 233:
1.8 harris41 234: # ---------------------------------------------------------------- Print screen
235: $r->print(<<ENDDOCUMENT);
236: <html>
237: <head>
238: <title>The LearningOnline Network with CAPA</title>
239: </head>
240: <body bgcolor="#FFFFFF">
241: <img align=right src=/adm/lonIcons/lonlogos.gif>
242: <h1>Search Catalog</h1>
243: <form method="post" action="/adm/searchcat">
244: $hidden
245: <hr>
246: <h3>Basic Search</h3>
247: <p>
248: Enter terms or phrases separated by search operators
249: such as AND or OR then press SEARCH below. Terms should be specific
250: to the title, author, subject, notes, or abstract information associated
251: with a resource.
252: <br>
1.11 harris41 253: ENDDOCUMENT
254: $r->print(&simpletextfield('basicexp',$ENV{'form.basicexp'}));
255: $r->print(' ');
256: $r->print(&simplecheckbox('titleonly',$ENV{'form.titleonly'}));
257: $r->print('<font color="#800000">Title only</font> ');
258: $r->print(&simplecheckbox('allversions',$ENV{'form.allversions'}));
259: $r->print(<<ENDDOCUMENT);
260: <font color="#800000">Search historic archives</font>
1.8 harris41 261: <br>
262: <input type="submit" name="basicsubmit" value="SEARCH">
263: <input type="reset" name="reset" value="RESET">
1.46 harris41 264: $closebutton
265: $viewselect
1.8 harris41 266: </p>
267: <hr>
268: <h3>Advanced Search</h3>
269: $scrout
270: <p>
271: <input type="submit" name="advancedsubmit" value="SEARCH">
272: <input type="reset" name="reset" value="RESET">
1.46 harris41 273: $closebutton
274: $viewselect
1.3 harris41 275: </p>
1.8 harris41 276: </form>
277: </body>
278: </html>
279: ENDDOCUMENT
280: return OK;
281: }
282:
283: # --------------------------------------------------------- Various form fields
284:
1.11 harris41 285: sub simpletextfield {
286: my ($name,$value)=@_;
287: return '<input type=text name="'.$name.'" size=20 value="'.$value.'">';
288: }
289:
290: sub simplecheckbox {
291: my ($name,$value)=@_;
292: my $checked='';
293: $checked="CHECKED" if $value eq 'on';
294: return '<input type=checkbox name="'.$name.'" '. $checked . '>';
295: }
296:
1.8 harris41 297: sub searchphrasefield {
298: my ($title,$name,$value)=@_;
299: my $instruction=<<END;
300: Enter terms or phrases separated by search operators such
301: as AND or OR.
302: END
303: my $uctitle=uc($title);
304: return "\n<p><font color=\"#800000\" face=\"helvetica\"><b>$uctitle:</b>".
305: "</FONT> $instruction<br>".
306: '<input type=text name="'.$name.'" size=80 value="'.$value.'">';
307: }
1.3 harris41 308:
1.8 harris41 309: sub dateboxes {
1.11 harris41 310: my ($name,$defaultmonth,$defaultday,$defaultyear,
311: $currentmonth,$currentday,$currentyear)=@_;
312: ($defaultmonth,$defaultday,$defaultyear)=('','','');
313: my $month=<<END;
1.8 harris41 314: <select name="${name}_month">
1.11 harris41 315: <option value='$defaultmonth'> </option>
316: <option value="1">January</option>
317: <option value="2">February</option>
318: <option value="3">March</option>
319: <option value="4">April</option>
320: <option value="5">May</option>
321: <option value="6">June</option>
322: <option value="7">July</option>
323: <option value="8">August</option>
324: <option value="9">September</option>
1.3 harris41 325: <option value="10">October</option>
326: <option value="11">November</option>
327: <option value="12">December</option>
328: </select>
1.11 harris41 329: END
330: $month=~s/(\"$currentmonth\")/$1 SELECTED/ if length($currentmonth);
331: my $day=<<END;
1.8 harris41 332: <select name="${name}_day">
1.11 harris41 333: <option value='$defaultday'> </option>
334: <option value="1">1</option>
335: <option value="2">2</option>
336: <option value="3">3</option>
337: <option value="4">4</option>
338: <option value="5">5</option>
339: <option value="6">6</option>
340: <option value="7">7</option>
341: <option value="8">8</option>
342: <option value="9">9</option>
343: <option value="10">10</option>
344: <option value="11">11</option>
345: <option value="12">12</option>
346: <option value="13">13</option>
347: <option value="14">14</option>
348: <option value="15">15</option>
349: <option value="16">16</option>
350: <option value="17">17</option>
351: <option value="18">18</option>
352: <option value="19">19</option>
353: <option value="20">20</option>
354: <option value="21">21</option>
355: <option value="22">22</option>
356: <option value="23">23</option>
357: <option value="24">24</option>
358: <option value="25">25</option>
359: <option value="26">26</option>
360: <option value="27">27</option>
361: <option value="28">28</option>
362: <option value="29">29</option>
363: <option value="30">30</option>
364: <option value="31">31</option>
1.3 harris41 365: </select>
1.11 harris41 366: END
367: $day=~s/(\"$currentday\")/$1 SELECTED/ if length($currentday);
368: my $year=<<END;
1.8 harris41 369: <select name="${name}_year">
1.11 harris41 370: <option value='$defaultyear'> </option>
371: <option value="1976">1976</option>
372: <option value="1977">1977</option>
373: <option value="1978">1978</option>
374: <option value="1979">1979</option>
375: <option value="1980">1980</option>
376: <option value="1981">1981</option>
377: <option value="1982">1982</option>
378: <option value="1983">1983</option>
379: <option value="1984">1984</option>
380: <option value="1985">1985</option>
381: <option value="1986">1986</option>
382: <option value="1987">1987</option>
383: <option value="1988">1988</option>
384: <option value="1989">1989</option>
385: <option value="1990">1990</option>
386: <option value="1991">1991</option>
387: <option value="1992">1992</option>
388: <option value="1993">1993</option>
389: <option value="1994">1994</option>
390: <option value="1995">1995</option>
391: <option value="1996">1996</option>
392: <option value="1997">1997</option>
393: <option value="1998">1998</option>
394: <option value="1999">1999</option>
395: <option value="2000">2000</option>
396: <option value="2001">2001</option>
397: <option value="2002">2002</option>
398: <option value="2003">2003</option>
399: <option value="2004">2004</option>
400: <option value="2005">2005</option>
401: <option value="2006">2006</option>
402: <option value="2007">2007</option>
403: <option value="2008">2008</option>
404: <option value="2009">2009</option>
405: <option value="2010">2010</option>
406: <option value="2011">2011</option>
407: <option value="2012">2012</option>
408: <option value="2013">2013</option>
409: <option value="2014">2014</option>
410: <option value="2015">2015</option>
411: <option value="2016">2016</option>
412: <option value="2017">2017</option>
413: <option value="2018">2018</option>
414: <option value="2019">2019</option>
415: <option value="2020">2020</option>
416: <option value="2021">2021</option>
417: <option value="2022">2022</option>
418: <option value="2023">2023</option>
419: <option value="2024">2024</option>
420: <option value="2025">2025</option>
421: <option value="2026">2026</option>
422: <option value="2027">2027</option>
423: <option value="2028">2028</option>
424: <option value="2029">2029</option>
425: <option value="2030">2030</option>
426: <option value="2031">2031</option>
427: <option value="2032">2032</option>
428: <option value="2033">2033</option>
429: <option value="2034">2034</option>
430: <option value="2035">2035</option>
431: <option value="2036">2036</option>
432: <option value="2037">2037</option>
433: <option value="2038">2038</option>
434: <option value="2039">2039</option>
435: <option value="2040">2040</option>
436: <option value="2041">2041</option>
437: <option value="2042">2042</option>
438: <option value="2043">2043</option>
439: <option value="2044">2044</option>
440: <option value="2045">2045</option>
441: <option value="2046">2046</option>
442: <option value="2047">2047</option>
443: <option value="2048">2048</option>
444: <option value="2049">2049</option>
445: <option value="2050">2050</option>
446: <option value="2051">2051</option>
1.3 harris41 447: </select>
448: END
1.11 harris41 449: $year=~s/(\"$currentyear\")/$1 SELECTED/ if length($currentyear);
450: return "$month$day$year";
1.3 harris41 451: }
452:
453: sub selectbox {
454: my ($title,$name,$value,%options)=@_;
455: my $uctitle=uc($title);
456: my $selout="\n<p><font color=\"#800000\" face=\"helvetica\"><b>$uctitle:".
457: "</b></font><br>".'<select name="'.$name.'">';
458: map {
459: $selout.='<option value="'.$_.'"';
460: if ($_ eq $value) { $selout.=' selected'; }
461: $selout.='>'.$options{$_}.'</option>';
462: } sort keys %options;
463: return $selout.'</select>';
1.6 harris41 464: }
465:
1.45 harris41 466: # ----------------------------------------------- Performing an advanced search
1.18 harris41 467: sub advancedsearch {
468: my ($r,$envhash)=@_;
469: my %ENV=%{$envhash};
470:
1.32 harris41 471: my $fillflag=0;
472: for my $field ('title','author','subject','keywords','url','version',
473: 'notes','abstract','mime','language','owner',
474: 'custommetadata') {
1.40 harris41 475: if (&filled($ENV{"form.$field"})) {
1.32 harris41 476: $fillflag++;
477: }
478: }
479:
480: unless ($fillflag) {
481: &output_blank_field_error($r);
482: return OK;
483: }
1.39 harris41 484:
485: my $query='';
1.44 harris41 486:
1.45 harris41 487: my @queries;
1.44 harris41 488: # Go through logical expression AND/OR/NOT phrase fields.
489: foreach my $field ('title','author','subject','notes','abstract') {
490: if ($ENV{'form.'.$field}) {
1.45 harris41 491: push @queries,&build_SQL_query($field,$ENV{'form.'.$field});
1.44 harris41 492: }
493: }
1.45 harris41 494: if (@queries) {
1.49 harris41 495: $query=join(" and ",@queries);
1.46 harris41 496: $query="select * from metadata where $query";
1.45 harris41 497: my $reply=&Apache::lonnet::metadata_query($query);
498: &output_results('Advanced',$r,$envhash,$query,$reply);
499: }
500: else {
501: &output_results('Advanced',$r,$envhash,$query);
502: }
1.24 harris41 503: return OK;
1.18 harris41 504: }
505:
1.26 harris41 506: # ---------------------------------------------------- see if a field is filled
507: sub filled {
1.31 harris41 508: my ($field)=@_;
509: if ($field=~/\S/) {
1.28 harris41 510: return 1;
511: }
512: else {
513: return 0;
514: }
1.26 harris41 515: }
516:
1.6 harris41 517: # --------------------------------------------------- Performing a basic search
518: sub basicsearch {
1.19 harris41 519: my ($r,$envhash)=@_;
520: my %ENV=%{$envhash};
1.6 harris41 521:
1.26 harris41 522: unless (&filled($ENV{'form.basicexp'})) {
1.24 harris41 523: &output_blank_field_error($r);
524: return OK;
525: }
1.22 harris41 526:
1.39 harris41 527: my $query='';
1.33 harris41 528: my $concatarg=join('," ",',
529: ('title', 'author', 'subject', 'notes', 'abstract'));
530:
531: $query="select * from metadata where concat($concatarg) like '\%$ENV{'form.basicexp'}\%'";
1.13 harris41 532: my $reply=&Apache::lonnet::metadata_query($query);
1.44 harris41 533: &output_results('Basic',$r,$envhash,$query,$reply);
1.18 harris41 534: return OK;
1.22 harris41 535: }
536:
1.44 harris41 537: # ---------------- Message to output when there are not enough fields filled in
1.22 harris41 538: sub output_blank_field_error {
539: my ($r)=@_;
540: # make query information persistent to allow for subsequent revision
541: my $persistent='';
542: map {
543: if (/^form\./ && !/submit/) {
544: my $name=$_;
545: my $key=$name;
546: $name=~s/^form\.//;
547: $persistent.=<<END;
548: <INPUT TYPE='hidden' NAME='$name' VALUE='$ENV{$key}'>
549: END
550: }
551: } (keys %ENV);
552:
553: $r->print(<<BEGINNING);
554: <html>
555: <head>
556: <title>The LearningOnline Network with CAPA</title>
557: BEGINNING
558: $r->print(<<RESULTS);
559: </head>
560: <body bgcolor="#ffffff">
561: <img align=right src=/adm/lonIcons/lonlogos.gif>
562: <h1>Search Catalog</h1>
563: <form method="post" action="/adm/searchcat">
564: $persistent
565: <input type='button' value='Revise search request'
566: onClick='this.form.submit();'>
1.46 harris41 567: $closebutton
1.22 harris41 568: <hr>
569: <h3>Helpful Message</h3>
570: <p>
571: Incorrect search query due to blank entry fields.
572: You need to fill in the relevant
573: fields on the search page in order for a query to be
574: processed.
575: </p>
576: </body>
577: </html>
578: RESULTS
1.18 harris41 579: }
1.6 harris41 580:
1.18 harris41 581: # ----------------------------- format and output results based on a reply list
582: sub output_results {
1.44 harris41 583: my ($mode,$r,$envhash,$query,@replylist)=@_;
1.19 harris41 584: my %ENV=%{$envhash};
1.44 harris41 585: my $compiledresult='';
586:
1.18 harris41 587: foreach my $reply (@replylist) {
588:
589: my @results;
590:
591: my $replyfile='';
592: $reply=~/^([\.\w]+)$/; # must do since 'use strict' checks for tainting
593: $replyfile=$r->dir_config('lonDaemons').'/tmp/'.$1;
594: $reply=~/(.*?)\_/;
595: my $hostname=$1;
1.52 harris41 596: sleep 3; # temporary fix, need to check for completion and status
1.18 harris41 597: {
598: while (1) {
599: last if -e $replyfile;
600: sleep 1;
601: }
602: # QUESTION: how should I handle this error condition..
603: # I'm sure there is syntax elsewhere I can use..
604: my $fh=Apache::File->new($replyfile) or
605: ($r->print('file cannot be opened') and return OK);
606: @results=<$fh>;
1.6 harris41 607: }
608:
1.18 harris41 609: foreach my $result (@results) {
1.50 harris41 610: my @fields=map
611: {&Apache::lonnet::unescape($_)}
612: (split(/\,/,$result));
1.18 harris41 613: my ($title,$author,$subject,$url,$keywords,$version,
614: $notes,$abstract,$mime,$lang,
1.50 harris41 615: $creationdate,$lastrevisiondate,$owner,$copyright)=@fields;
1.18 harris41 616: my $shortabstract=$abstract;
617: $shortabstract=substr($abstract,0,200) if length($abstract)>200;
1.51 harris41 618: $fields[7]=$shortabstract;
1.18 harris41 619: $compiledresult.=<<END;
1.53 ! harris41 620: <p>($title)
1.8 harris41 621: END
1.18 harris41 622: $compiledresult.=<<END if $ENV{'form.catalogmode'} eq 'interactive';
1.8 harris41 623: <font size='-1'><INPUT TYPE="button" NAME="returnvalues" VALUE="SELECT"
1.10 harris41 624: onClick="javascript:select_data('$title','$url')">
1.8 harris41 625: </font>
626: <br>
627: END
1.51 harris41 628: my $httphost=$ENV{'HTTP_HOST'};
1.53 ! harris41 629:
1.50 harris41 630: if ($ENV{'form.viewselect'} eq 'Detailed Citation View') {
1.51 harris41 631: $compiledresult.=&detailed_citation_view(@fields,
632: $hostname,$httphost);
1.50 harris41 633: }
634: elsif ($ENV{'form.viewselect'} eq 'Summary View') {
1.51 harris41 635: $compiledresult.=&summary_view(@fields,$hostname,$httphost);
1.50 harris41 636: }
637: elsif ($ENV{'form.viewselect'} eq 'Fielded Format') {
1.51 harris41 638: $compiledresult.=&fielded_format_view(@fields,$hostname,
639: $httphost);
1.50 harris41 640: }
641: elsif ($ENV{'form.viewselect'} eq 'XML/SGML') {
1.51 harris41 642: $compiledresult.=&xml_sgml_view(@fields,$hostname,$httphost);
1.50 harris41 643: }
644:
1.18 harris41 645: }
1.6 harris41 646:
1.18 harris41 647: unless ($compiledresult) {
648: $compiledresult="There were no results that matched your query";
649: }
1.6 harris41 650:
1.18 harris41 651: # make query information persistent to allow for subsequent revision
652: my $persistent='';
653: map {
654: if (/^form\./ && !/submit/) {
655: my $name=$_;
656: my $key=$name;
657: $name=~s/^form\.//;
658: $persistent.=<<END;
1.9 harris41 659: <INPUT TYPE='hidden' NAME='$name' VALUE='$ENV{$key}'>
660: END
1.18 harris41 661: }
662: } (keys %ENV);
1.9 harris41 663:
1.18 harris41 664: $r->print(<<BEGINNING);
1.6 harris41 665: <html>
666: <head>
667: <title>The LearningOnline Network with CAPA</title>
1.8 harris41 668: BEGINNING
1.18 harris41 669: $r->print(<<SCRIPT) if $ENV{'form.catalogmode'} eq 'interactive';
1.8 harris41 670: <script>
671: function select_data(title,url) {
672: changeTitle(title);
673: changeURL(url);
674: }
675: function changeTitle(val) {
676: if (opener.inf.document.forms.resinfo.elements.t) {
677: opener.inf.document.forms.resinfo.elements.t.value=val;
678: }
679: }
680: function changeURL(val) {
681: if (opener.inf.document.forms.resinfo.elements.u) {
682: opener.inf.document.forms.resinfo.elements.u.value=val;
683: }
684: }
685: </script>
686: SCRIPT
1.18 harris41 687: $r->print(<<RESULTS);
1.6 harris41 688: </head>
689: <body bgcolor="#ffffff">
690: <img align=right src=/adm/lonIcons/lonlogos.gif>
691: <h1>Search Catalog</h1>
692: <form method="post" action="/adm/searchcat">
1.9 harris41 693: <input type='button' value='Revise search request'
694: onClick='this.form.submit();'>
1.46 harris41 695: $closebutton
1.9 harris41 696: $persistent
1.6 harris41 697: <hr>
698: <h3>Search Query</h3>
1.43 harris41 699: RESULTS
700: if ($mode eq 'Basic') {
701: $r->print(<<RESULTS);
1.6 harris41 702: <p>
1.19 harris41 703: <b>Basic search:</b> $ENV{'form.basicexp'}
1.6 harris41 704: </p>
1.43 harris41 705: RESULTS
1.44 harris41 706: }
1.43 harris41 707: elsif ($mode eq 'Advanced') {
708: $r->print(<<RESULTS);
709: <p>
710: <b>Advanced search</b>
1.44 harris41 711: $query
1.43 harris41 712: </p>
713: RESULTS
714: }
1.44 harris41 715: $r->print(<<RESULTS);
1.6 harris41 716: <h3>Search Results</h3>
717: $compiledresult
718: </body>
719: </html>
720: RESULTS
1.18 harris41 721: }
1.41 harris41 722: }
723:
724: # ------------------------------------------------------------- build_SQL_query
725: sub build_SQL_query {
1.43 harris41 726: my ($field_name,$logic_statement)=@_;
727: my $q=new Text::Query('abc',
728: -parse => 'Text::Query::ParseAdvanced',
729: -build => 'Text::Query::Build');
1.44 harris41 730: $q->prepare($logic_statement);
1.43 harris41 731: my $matchexp=${$q}{'matchexp'}; chomp $matchexp;
732: my $sql_query=&recursive_SQL_query_build($field_name,$matchexp);
1.44 harris41 733: return $sql_query;
1.43 harris41 734: }
1.41 harris41 735:
1.43 harris41 736: # - Recursively parse a reverse notation expression into a SQL query expression
737: sub recursive_SQL_query_build {
738: my ($dkey,$pattern)=@_;
739: my @matches=($pattern=~/(\[[^\]|\[]*\])/g);
740: return $pattern unless @matches;
741: foreach my $match (@matches) {
742: $match=~/\[ (\w+)\s(.*) \]/;
1.44 harris41 743: my ($key,$value)=($1,$2);
1.43 harris41 744: my $replacement='';
745: if ($key eq 'literal') {
746: $replacement="($dkey like \"\%$value\%\")";
747: }
748: elsif ($key eq 'and') {
749: $value=~/(.*[\"|\)]) ([|\(|\^].*)/;
750: $replacement="($1 AND $2)";
751: }
752: elsif ($key eq 'or') {
753: $value=~/(.*[\"|\)]) ([|\(|\^].*)/;
754: $replacement="($1 OR $2)";
755: }
756: substr($pattern,
757: index($pattern,$match),
758: length($match),
759: $replacement
760: );
761: }
762: &recursive_SQL_query_build($dkey,$pattern);
1.50 harris41 763: }
764:
765: # ------------------------------------------------------ Detailed Citation View
766: sub detailed_citation_view {
767: my ($title,$author,$subject,$url,$keywords,$version,
1.51 harris41 768: $notes,$shortabstract,$mime,$lang,
769: $creationdate,$lastrevisiondate,$owner,$copyright,
770: $hostname,$httphost)=@_;
1.50 harris41 771: my $result=<<END;
1.51 harris41 772: DETAILED
773: <b>URL: </b> <A HREF="http://$httphost$url" TARGET='search_preview'>$url</A>
1.50 harris41 774: <br>
775: <b>Title:</b> $title<br>
776: <b>Author(s):</b> $author<br>
777: <b>Subject:</b> $subject<br>
778: <b>Keyword(s):</b> $keywords<br>
779: <b>Notes:</b> $notes<br>
780: <b>Abstract:</b> $shortabstract<br>
781: <b>MIME Type:</b> $mimetag{$mime}<br>
782: <b>Language:</b> $language{$lang}<br>
783: <b>Creation Date:</b> $creationdate<br>
784: <b>Last Revision Date:</b> $lastrevisiondate<br>
785: <b>Publisher/Owner:</b> $owner<br>
786: <b>Copyright/Distribution:</b> $copyright<br>
787: <b>Repository Location:</b> $hostname
788: </p>
789: END
790: return $result;
791: }
792:
793: # ---------------------------------------------------------------- Summary View
794: sub summary_view {
795: my ($title,$author,$subject,$url,$keywords,$version,
1.51 harris41 796: $notes,$shortabstract,$mime,$lang,
797: $creationdate,$lastrevisiondate,$owner,$copyright,
798: $hostname,$httphost)=@_;
1.50 harris41 799: my $result=<<END;
1.51 harris41 800: SUMMARY
801: <b>URL: </b> <A HREF="http://$httphost$url" TARGET='search_preview'>$url</A>
1.50 harris41 802: <br>
803: <b>Title:</b> $title<br>
804: <b>Author(s):</b> $author<br>
805: <b>Subject:</b> $subject<br>
806: <b>Keyword(s):</b> $keywords<br>
807: <b>Notes:</b> $notes<br>
808: <b>Abstract:</b> $shortabstract<br>
809: <b>MIME Type:</b> $mimetag{$mime}<br>
810: <b>Language:</b> $language{$lang}<br>
811: <b>Creation Date:</b> $creationdate<br>
812: <b>Last Revision Date:</b> $lastrevisiondate<br>
813: <b>Publisher/Owner:</b> $owner<br>
814: <b>Copyright/Distribution:</b> $copyright<br>
815: <b>Repository Location:</b> $hostname
816: </p>
817: END
818: return $result;
819: }
820:
821: # -------------------------------------------------------------- Fielded Format
822: sub fielded_format_view {
823: my ($title,$author,$subject,$url,$keywords,$version,
1.51 harris41 824: $notes,$shortabstract,$mime,$lang,
825: $creationdate,$lastrevisiondate,$owner,$copyright,
826: $hostname,$httphost)=@_;
1.50 harris41 827: my $result=<<END;
1.51 harris41 828: FIELDED
829: <b>URL: </b> <A HREF="http://$httphost$url" TARGET='search_preview'>$url</A>
1.50 harris41 830: <br>
831: <b>Title:</b> $title<br>
832: <b>Author(s):</b> $author<br>
833: <b>Subject:</b> $subject<br>
834: <b>Keyword(s):</b> $keywords<br>
835: <b>Notes:</b> $notes<br>
836: <b>Abstract:</b> $shortabstract<br>
837: <b>MIME Type:</b> $mimetag{$mime}<br>
838: <b>Language:</b> $language{$lang}<br>
839: <b>Creation Date:</b> $creationdate<br>
840: <b>Last Revision Date:</b> $lastrevisiondate<br>
841: <b>Publisher/Owner:</b> $owner<br>
842: <b>Copyright/Distribution:</b> $copyright<br>
843: <b>Repository Location:</b> $hostname
844: </p>
845: END
846: return $result;
847: }
848:
849: # -------------------------------------------------------------------- XML/SGML
850: sub xml_sgml_view {
851: my ($title,$author,$subject,$url,$keywords,$version,
1.51 harris41 852: $notes,$shortabstract,$mime,$lang,
853: $creationdate,$lastrevisiondate,$owner,$copyright,
854: $hostname,$httphost)=@_;
1.50 harris41 855: my $result=<<END;
1.51 harris41 856: XML/SGML
857: <b>URL: </b> <A HREF="http://$httphost$url" TARGET='search_preview'>$url</A>
1.50 harris41 858: <br>
859: <b>Title:</b> $title<br>
860: <b>Author(s):</b> $author<br>
861: <b>Subject:</b> $subject<br>
862: <b>Keyword(s):</b> $keywords<br>
863: <b>Notes:</b> $notes<br>
864: <b>Abstract:</b> $shortabstract<br>
865: <b>MIME Type:</b> $mimetag{$mime}<br>
866: <b>Language:</b> $language{$lang}<br>
867: <b>Creation Date:</b> $creationdate<br>
868: <b>Last Revision Date:</b> $lastrevisiondate<br>
869: <b>Publisher/Owner:</b> $owner<br>
870: <b>Copyright/Distribution:</b> $copyright<br>
871: <b>Repository Location:</b> $hostname
872: </p>
873: END
874: return $result;
1.3 harris41 875: }
1.1 www 876:
877: 1;
878: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>