--- loncom/interface/lonsearchcat.pm 2001/03/08 16:45:22 1.3 +++ loncom/interface/lonsearchcat.pm 2001/03/13 15:36:15 1.8 @@ -7,6 +7,9 @@ package Apache::lonsearchcat; use strict; use Apache::Constants qw(:common); +use Apache::lonnet(); +use Apache::File(); +use CGI qw(:standard); my %language; my $scrout; @@ -16,15 +19,32 @@ my %mimetag; sub handler { my $r = shift; + +# -------------------------------------- see if called from an interactive mode + map { + my ($name, $value) = split(/=/,$_); + $value =~ tr/+/ /; + $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; + if ($name eq 'catalogmode') { + $ENV{'form.'.$name}=$value; + } + } (split(/&/,$ENV{'QUERY_STRING'})); + $r->content_type('text/html'); $r->send_http_header; return OK if $r->header_only; %metadatafields=(); + my $hidden=''; + $hidden=< +END + # ------------------------------------------------ First, check out environment $metadatafields{'owner'}=$ENV{'user.name'}.'@'.$ENV{'user.domain'}; +# --------------------------------- Compute various listings of metadata values %language=(); $language{'any'}='Any language'; @@ -56,7 +76,11 @@ sub handler { } <$fh>; } - $scrout=""; + if ($ENV{'form.basicsubmit'} eq 'SEARCH') { + return &basicsearch($r,$ENV{'form.basicexp'}); + } + + $scrout=''; # building a part of screen output $scrout.=&searchphrasefield('Limit by title','title', ''); @@ -78,276 +102,108 @@ sub handler { $scrout.=&selectbox('Limit by language','language', 'any',%language); - $scrout.=< LIMIT BY CREATION DATE RANGE:
-between: - - -and: - - -

+between: +CREATIONDATESTART + $scrout.=&dateboxes('creationdatestart'); + $scrout.=< LIMIT BY LAST REVISION DATE RANGE: -
between: + +Title only +
+ + + +

+
+

Advanced Search

+$scrout +

+ + + +

+ + + +ENDDOCUMENT + return OK; +} + +# --------------------------------------------------------- Various form fields + +sub textfield { + my ($title,$name,$value)=@_; + return "\n

$title:
". + ''; +} + +sub searchphrasefield { + my ($title,$name,$value)=@_; + my $instruction=<$uctitle:". + " $instruction
". + ''; +} + +sub dateboxes { + my ($name)=@_; + return< + @@ -361,8 +217,8 @@ CREATIONDATEEND - + @@ -395,7 +251,7 @@ CREATIONDATEEND - @@ -474,210 +330,133 @@ CREATIONDATEEND -and: - - -

-LASTREVISIONDATEEND +END +} - $scrout.=&searchphrasefield('Limit by publisher/owner','owner', - $metadatafields{'owner'}); +sub selectbox { + my ($title,$name,$value,%options)=@_; + my $uctitle=uc($title); + my $selout="\n

$uctitle:". + "
".''; +} - $scrout.=&selectbox('Limit by copyright/distribution','copyright', - 'any',%cprtag); +# --------------------------------------------------- Performing a basic search +sub basicsearch { + my ($r,$expression)=@_; + + my $query=$expression; + $query="select * from metadata where concat(title,\" \",author) like '\%$expression\%'"; + my $reply=&Apache::lonnet::reply("querysend:$query",'msul3'); + + my @results; + + my $replyfile=''; + $reply=~/^([\.\w]+)$/; # must do since 'use strict' checks for tainting + $replyfile=$r->dir_config('lonDaemons').'/tmp/'.$1; + $reply=~/(.*?)\_/; + my $hostname=$1; -# ---------------------------------------------------------------- Print screen - $r->print(<new($replyfile) or + ($r->print('file cannot be opened') and return OK); + @results=<$fh>; + } + + my $compiledresult=''; + + foreach my $result (@results) { + my ($title,$author,$subject,$notes,$abstract,$mime,$lang, + $creationdate,$lastrevisiondate,$owner,$copyright + )=map {&Apache::lonnet::unescape($_)} (split(/\,/,$result)); + my $shortabstract=$abstract; + $shortabstract=substr($abstract,0,200) if length($abstract)>200; + $compiledresult.=< +END + $compiledresult.=< + +
+END + $compiledresult.=<Title: $title
+Author(s): $author
+Subject: $subject
+Keyword(s): not available yet
+Notes: $notes
+Abstract: $shortabstract
+MIME Type: $mimetag{$mime}
+Language: $language{$lang}
+Creation Date: $creationdate
+Last Revision Date: $lastrevisiondate
+Publisher/Owner: $owner
+Copyright/Distribution: $copyright
+Repository Location: $hostname +

+END +} + + unless ($compiledresult) { + $compiledresult="There were no results that matched your query"; + } + +# Question... allow to ask question from this page, or click to +# search again? + $r->print(< The LearningOnline Network with CAPA +BEGINNING + $r->print(< + function select_data(title,url) { + changeTitle(title); + changeURL(url); + } + function changeTitle(val) { + if (opener.inf.document.forms.resinfo.elements.t) { + opener.inf.document.forms.resinfo.elements.t.value=val; + } + } + function changeURL(val) { + if (opener.inf.document.forms.resinfo.elements.u) { + opener.inf.document.forms.resinfo.elements.u.value=val; + } + } + +SCRIPT + $r->print(< - + +

Search Catalog

+Revise search request
-

Basic Search

-

-Enter terms or phrases separated by search operators -such as AND or OR then press SEARCH below. Terms should be specific -to the title, author, subject, notes, or abstract information associated -with a resource. -
- - -Title only -
- -

-
-

Advanced Search

-$scrout +

Search Query

- +Basic search: $expression

-
+

Search Results

+$compiledresult -ENDDOCUMENT - return OK; -} +RESULTS -# --------------------------------------------------------- Various form fields - -sub textfield { - my ($title,$name,$value)=@_; - return "\n

$title:
". - ''; -} - -sub searchphrasefield { - my ($title,$name,$value)=@_; - my $instruction=<$uctitle:". - ": $instruction
". - ''; -} - -sub selectbox { - my ($title,$name,$value,%options)=@_; - my $uctitle=uc($title); - my $selout="\n

$uctitle:". - "
".''; + return OK; } 1;