# The LearningOnline Network # Search Catalog # # 03/08/2001 Scott Harrison # 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.=< LIMIT BY CREATION DATE RANGE:
between: and:

CREATIONDATEEND $scrout.=< LIMIT BY LAST REVISION DATE RANGE:
between: and:

LASTREVISIONDATEEND $scrout.=&searchphrasefield('Limit by publisher/owner','owner', $metadatafields{'owner'}); $scrout.=&selectbox('Limit by copyright/distribution','copyright', 'any',%cprtag); # ---------------------------------------------------------------- Print screen $r->print(< The LearningOnline Network with CAPA

Search Catalog


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

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 selectbox { my ($title,$name,$value,%options)=@_; my $uctitle=uc($title); my $selout="\n

$uctitle:". "
".''; } # --------------------------------------------------- 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=< 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

Search Catalog


Search Query

$expression

Search Results

$compiledresult RESULTS return OK; } 1; __END__