Annotation of loncom/interface/lonsearchcat.pm, revision 1.50
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;
596:
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;
618: $compiledresult.=<<END;
1.6 harris41 619: <p>
1.8 harris41 620: END
1.18 harris41 621: $compiledresult.=<<END if $ENV{'form.catalogmode'} eq 'interactive';
1.8 harris41 622: <font size='-1'><INPUT TYPE="button" NAME="returnvalues" VALUE="SELECT"
1.10 harris41 623: onClick="javascript:select_data('$title','$url')">
1.8 harris41 624: </font>
625: <br>
626: END
1.50 ! harris41 627:
! 628: if ($ENV{'form.viewselect'} eq 'Detailed Citation View') {
! 629: $compiledresult.=&detailed_citation_view(@fields);
! 630: }
! 631: elsif ($ENV{'form.viewselect'} eq 'Summary View') {
! 632: $compiledresult.=&summary_view(@fields);
! 633: }
! 634: elsif ($ENV{'form.viewselect'} eq 'Fielded Format') {
! 635: $compiledresult.=&fielded_format_view(@fields);
! 636: }
! 637: elsif ($ENV{'form.viewselect'} eq 'XML/SGML') {
! 638: $compiledresult.=&xml_sgml_view(@fields);
! 639: }
! 640:
1.18 harris41 641: }
1.6 harris41 642:
1.18 harris41 643: unless ($compiledresult) {
644: $compiledresult="There were no results that matched your query";
645: }
1.6 harris41 646:
1.18 harris41 647: # make query information persistent to allow for subsequent revision
648: my $persistent='';
649: map {
650: if (/^form\./ && !/submit/) {
651: my $name=$_;
652: my $key=$name;
653: $name=~s/^form\.//;
654: $persistent.=<<END;
1.9 harris41 655: <INPUT TYPE='hidden' NAME='$name' VALUE='$ENV{$key}'>
656: END
1.18 harris41 657: }
658: } (keys %ENV);
1.9 harris41 659:
1.18 harris41 660: $r->print(<<BEGINNING);
1.6 harris41 661: <html>
662: <head>
663: <title>The LearningOnline Network with CAPA</title>
1.8 harris41 664: BEGINNING
1.18 harris41 665: $r->print(<<SCRIPT) if $ENV{'form.catalogmode'} eq 'interactive';
1.8 harris41 666: <script>
667: function select_data(title,url) {
668: changeTitle(title);
669: changeURL(url);
670: }
671: function changeTitle(val) {
672: if (opener.inf.document.forms.resinfo.elements.t) {
673: opener.inf.document.forms.resinfo.elements.t.value=val;
674: }
675: }
676: function changeURL(val) {
677: if (opener.inf.document.forms.resinfo.elements.u) {
678: opener.inf.document.forms.resinfo.elements.u.value=val;
679: }
680: }
681: </script>
682: SCRIPT
1.18 harris41 683: $r->print(<<RESULTS);
1.6 harris41 684: </head>
685: <body bgcolor="#ffffff">
686: <img align=right src=/adm/lonIcons/lonlogos.gif>
687: <h1>Search Catalog</h1>
688: <form method="post" action="/adm/searchcat">
1.9 harris41 689: <input type='button' value='Revise search request'
690: onClick='this.form.submit();'>
1.46 harris41 691: $closebutton
1.9 harris41 692: $persistent
1.6 harris41 693: <hr>
694: <h3>Search Query</h3>
1.43 harris41 695: RESULTS
696: if ($mode eq 'Basic') {
697: $r->print(<<RESULTS);
1.6 harris41 698: <p>
1.19 harris41 699: <b>Basic search:</b> $ENV{'form.basicexp'}
1.6 harris41 700: </p>
1.43 harris41 701: RESULTS
1.44 harris41 702: }
1.43 harris41 703: elsif ($mode eq 'Advanced') {
704: $r->print(<<RESULTS);
705: <p>
706: <b>Advanced search</b>
1.44 harris41 707: $query
1.43 harris41 708: </p>
709: RESULTS
710: }
1.44 harris41 711: $r->print(<<RESULTS);
1.6 harris41 712: <h3>Search Results</h3>
713: $compiledresult
714: </body>
715: </html>
716: RESULTS
1.18 harris41 717: }
1.41 harris41 718: }
719:
720: # ------------------------------------------------------------- build_SQL_query
721: sub build_SQL_query {
1.43 harris41 722: my ($field_name,$logic_statement)=@_;
723: my $q=new Text::Query('abc',
724: -parse => 'Text::Query::ParseAdvanced',
725: -build => 'Text::Query::Build');
1.44 harris41 726: $q->prepare($logic_statement);
1.43 harris41 727: my $matchexp=${$q}{'matchexp'}; chomp $matchexp;
728: my $sql_query=&recursive_SQL_query_build($field_name,$matchexp);
1.44 harris41 729: return $sql_query;
1.43 harris41 730: }
1.41 harris41 731:
1.43 harris41 732: # - Recursively parse a reverse notation expression into a SQL query expression
733: sub recursive_SQL_query_build {
734: my ($dkey,$pattern)=@_;
735: my @matches=($pattern=~/(\[[^\]|\[]*\])/g);
736: return $pattern unless @matches;
737: foreach my $match (@matches) {
738: $match=~/\[ (\w+)\s(.*) \]/;
1.44 harris41 739: my ($key,$value)=($1,$2);
1.43 harris41 740: my $replacement='';
741: if ($key eq 'literal') {
742: $replacement="($dkey like \"\%$value\%\")";
743: }
744: elsif ($key eq 'and') {
745: $value=~/(.*[\"|\)]) ([|\(|\^].*)/;
746: $replacement="($1 AND $2)";
747: }
748: elsif ($key eq 'or') {
749: $value=~/(.*[\"|\)]) ([|\(|\^].*)/;
750: $replacement="($1 OR $2)";
751: }
752: substr($pattern,
753: index($pattern,$match),
754: length($match),
755: $replacement
756: );
757: }
758: &recursive_SQL_query_build($dkey,$pattern);
1.50 ! harris41 759: }
! 760:
! 761: # ------------------------------------------------------ Detailed Citation View
! 762: sub detailed_citation_view {
! 763: my ($title,$author,$subject,$url,$keywords,$version,
! 764: $notes,$abstract,$mime,$lang,
! 765: $creationdate,$lastrevisiondate,$owner,$copyright)=@_;
! 766: my $result=<<END;
! 767: <b>URL: </b> <A HREF="http://$ENV{'HTTP_HOST'}$url" TARGET='search_preview'>$url</A>
! 768: <br>
! 769: <b>Title:</b> $title<br>
! 770: <b>Author(s):</b> $author<br>
! 771: <b>Subject:</b> $subject<br>
! 772: <b>Keyword(s):</b> $keywords<br>
! 773: <b>Notes:</b> $notes<br>
! 774: <b>Abstract:</b> $shortabstract<br>
! 775: <b>MIME Type:</b> $mimetag{$mime}<br>
! 776: <b>Language:</b> $language{$lang}<br>
! 777: <b>Creation Date:</b> $creationdate<br>
! 778: <b>Last Revision Date:</b> $lastrevisiondate<br>
! 779: <b>Publisher/Owner:</b> $owner<br>
! 780: <b>Copyright/Distribution:</b> $copyright<br>
! 781: <b>Repository Location:</b> $hostname
! 782: </p>
! 783: END
! 784: return $result;
! 785: }
! 786:
! 787: # ---------------------------------------------------------------- Summary View
! 788: sub summary_view {
! 789: my ($title,$author,$subject,$url,$keywords,$version,
! 790: $notes,$abstract,$mime,$lang,
! 791: $creationdate,$lastrevisiondate,$owner,$copyright)=@_;
! 792: my $result=<<END;
! 793: <b>URL: </b> <A HREF="http://$ENV{'HTTP_HOST'}$url" TARGET='search_preview'>$url</A>
! 794: <br>
! 795: <b>Title:</b> $title<br>
! 796: <b>Author(s):</b> $author<br>
! 797: <b>Subject:</b> $subject<br>
! 798: <b>Keyword(s):</b> $keywords<br>
! 799: <b>Notes:</b> $notes<br>
! 800: <b>Abstract:</b> $shortabstract<br>
! 801: <b>MIME Type:</b> $mimetag{$mime}<br>
! 802: <b>Language:</b> $language{$lang}<br>
! 803: <b>Creation Date:</b> $creationdate<br>
! 804: <b>Last Revision Date:</b> $lastrevisiondate<br>
! 805: <b>Publisher/Owner:</b> $owner<br>
! 806: <b>Copyright/Distribution:</b> $copyright<br>
! 807: <b>Repository Location:</b> $hostname
! 808: </p>
! 809: END
! 810: return $result;
! 811: }
! 812:
! 813: # -------------------------------------------------------------- Fielded Format
! 814: sub fielded_format_view {
! 815: my ($title,$author,$subject,$url,$keywords,$version,
! 816: $notes,$abstract,$mime,$lang,
! 817: $creationdate,$lastrevisiondate,$owner,$copyright)=@_;
! 818: my $result=<<END;
! 819: <b>URL: </b> <A HREF="http://$ENV{'HTTP_HOST'}$url" TARGET='search_preview'>$url</A>
! 820: <br>
! 821: <b>Title:</b> $title<br>
! 822: <b>Author(s):</b> $author<br>
! 823: <b>Subject:</b> $subject<br>
! 824: <b>Keyword(s):</b> $keywords<br>
! 825: <b>Notes:</b> $notes<br>
! 826: <b>Abstract:</b> $shortabstract<br>
! 827: <b>MIME Type:</b> $mimetag{$mime}<br>
! 828: <b>Language:</b> $language{$lang}<br>
! 829: <b>Creation Date:</b> $creationdate<br>
! 830: <b>Last Revision Date:</b> $lastrevisiondate<br>
! 831: <b>Publisher/Owner:</b> $owner<br>
! 832: <b>Copyright/Distribution:</b> $copyright<br>
! 833: <b>Repository Location:</b> $hostname
! 834: </p>
! 835: END
! 836: return $result;
! 837: }
! 838:
! 839: # -------------------------------------------------------------------- XML/SGML
! 840: sub xml_sgml_view {
! 841: my ($title,$author,$subject,$url,$keywords,$version,
! 842: $notes,$abstract,$mime,$lang,
! 843: $creationdate,$lastrevisiondate,$owner,$copyright)=@_;
! 844: my $result=<<END;
! 845: <b>URL: </b> <A HREF="http://$ENV{'HTTP_HOST'}$url" TARGET='search_preview'>$url</A>
! 846: <br>
! 847: <b>Title:</b> $title<br>
! 848: <b>Author(s):</b> $author<br>
! 849: <b>Subject:</b> $subject<br>
! 850: <b>Keyword(s):</b> $keywords<br>
! 851: <b>Notes:</b> $notes<br>
! 852: <b>Abstract:</b> $shortabstract<br>
! 853: <b>MIME Type:</b> $mimetag{$mime}<br>
! 854: <b>Language:</b> $language{$lang}<br>
! 855: <b>Creation Date:</b> $creationdate<br>
! 856: <b>Last Revision Date:</b> $lastrevisiondate<br>
! 857: <b>Publisher/Owner:</b> $owner<br>
! 858: <b>Copyright/Distribution:</b> $copyright<br>
! 859: <b>Repository Location:</b> $hostname
! 860: </p>
! 861: END
! 862: return $result;
1.3 harris41 863: }
1.1 www 864:
865: 1;
866: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>