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