--- loncom/interface/lonsearchcat.pm 2001/03/08 13:32:04 1.2
+++ loncom/interface/lonsearchcat.pm 2001/03/12 17:28:32 1.7
@@ -7,58 +7,804 @@ package Apache::lonsearchcat;
use strict;
use Apache::Constants qw(:common);
+use Apache::lonnet();
+use Apache::File();
+use CGI qw(:standard);
+
+my %language;
+my $scrout;
+my %metadatafields;
+my %cprtag;
+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=();
+
+# ------------------------------------------------ First, check out environment
+ $metadatafields{'owner'}=$ENV{'user.name'}.'@'.$ENV{'user.domain'};
+
+
+ %language=();
+ $language{'any'}='Any language';
+ {
+ my $fh=Apache::File->new($r->dir_config('lonTabDir').'/language.tab');
+ map {
+ $_=~/(\w+)\s+([\w\s\-]+)/;
+ $language{$1}=$2;
+ } <$fh>;
+ }
+
+ %cprtag=();
+ $cprtag{'any'}='Any copyright/distribution';
+ {
+ my $fh=Apache::File->new($r->dir_config('lonIncludes').'/copyright.tab');
+ map {
+ $_=~/(\w+)\s+([\w\s\-]+)/;
+ $cprtag{$1}=$2;
+ } <$fh>;
+ }
+
+ %mimetag=();
+ $mimetag{'any'}='Any type';
+ {
+ my $fh=Apache::File->new($r->dir_config('lonTabDir').'/filetypes.tab');
+ map {
+ $_=~/(\w+)\s+(\w+)\s+([\w\s\-]+)/;
+ $mimetag{$1}=".$1 $3";
+ } <$fh>;
+ }
+
+ if ($ENV{'form.basicsubmit'} eq 'SEARCH') {
+ return &basicsearch($r,$ENV{'form.basicexp'});
+ }
+
+ $scrout="";
+ $scrout.=&searchphrasefield('Limit by title','title',
+ '');
+
+ $scrout.=&searchphrasefield('Limit by author','author',
+ '');
+
+ $scrout.=&searchphrasefield('Limit by subject','subject',
+ '');
+
+ $scrout.=&searchphrasefield('Limit by notes','notes',
+ '');
+
+ $scrout.=&searchphrasefield('Limit by abstract','abstract',
+ '');
+
+ $scrout.=&selectbox('Limit by MIME type','mime',
+ 'notxxx',%mimetag);
+
+ $scrout.=&selectbox('Limit by language','language',
+ 'any',%language);
+
+ $scrout.=<
+between:
+
+
+and:
+
+
+
$title: $uctitle:".
+ "
".
+ '';
+}
+
+sub searchphrasefield {
+ my ($title,$name,$value)=@_;
+ my $instruction=<
".
+ '';
+}
+
+sub selectbox {
+ my ($title,$name,$value,%options)=@_;
+ my $uctitle=uc($title);
+ my $selout="\n
".'';
+}
+
+# --------------------------------------------------- Performing a basic search
+sub basicsearch {
+ my ($r,$expression)=@_;
+
+ my $query=$expression;
+# $query="select * from metadata where concat(title,':\@:',author) like '\%Sci\%'";
+ $query="select * from metadata where concat(title,\" \",author) like '\%$expression\%'";
+# my $reply=&Apache::lonnet::reply("querysend:DESCRIBE metadata","msul3");
+ my $reply=&Apache::lonnet::reply("querysend:$query",'msul3');
+# my $reply=&Apache::lonnet::reply('querysend:select * from metadata','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;
+
+ {
+ while (1) {
+ last if -e $replyfile;
+ sleep 1;
+ }
+ # QUESTION: how should I handle this error condition..
+ # I'm sure there is syntax elsewhere I can use..
+ my $fh=Apache::File->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=<
+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
+
+
Search Catalog
+