Diff for /loncom/interface/lonsearchcat.pm between versions 1.5 and 1.6

version 1.5, 2001/03/08 16:55:43 version 1.6, 2001/03/08 20:54:53
Line 7  package Apache::lonsearchcat; Line 7  package Apache::lonsearchcat;
   
 use strict;  use strict;
 use Apache::Constants qw(:common);  use Apache::Constants qw(:common);
   use Apache::lonnet();
   use Apache::File();
   
 my %language;  my %language;
 my $scrout;  my $scrout;
Line 56  sub handler { Line 58  sub handler {
  } <$fh>;   } <$fh>;
     }      }
   
       if ($ENV{'form.basicsubmit'} eq 'SEARCH') {
    return &basicsearch($r,$ENV{'form.basicexp'});
       }
   
     $scrout="";      $scrout="";
     $scrout.=&searchphrasefield('Limit by title','title',      $scrout.=&searchphrasefield('Limit by title','title',
  '');   '');
Line 681  sub selectbox { Line 687  sub selectbox {
     return $selout.'</select>';      return $selout.'</select>';
 }  }
   
   # --------------------------------------------------- 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=<<END;
   <p>
   <b>Title:</b> $title<br>
   <b>Author(s):</b> $author<br>
   <b>Subject:</b> $subject<br>
   <b>Keyword(s):</b> <i>not available yet</i><br>
   <b>Notes:</b> $notes<br>
   <b>Abstract:</b> $shortabstract<br>
   <b>MIME Type:</b> $mimetag{$mime}<br>
   <b>Language:</b> $language{$lang}<br>
   <b>Creation Date:</b> $creationdate<br>
   <b>Last Revision Date:</b> $lastrevisiondate<br>
   <b>Publisher/Owner:</b> $owner<br>
   <b>Copyright/Distribution:</b> $copyright<br>
   <b>Repository Location:</b> $hostname
   </p>
   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(<<RESULTS);
   <html>
   <head>
   <title>The LearningOnline Network with CAPA</title>
   </head>
   <body bgcolor="#ffffff">
   <img align=right src=/adm/lonIcons/lonlogos.gif>
   <h1>Search Catalog</h1>
   <form method="post" action="/adm/searchcat">
   <hr>
   <h3>Search Query</h3>
   <p>
   $expression
   </p>
   <h3>Search Results</h3>
   $compiledresult
   </body>
   </html>
   RESULTS
   
       return OK;
   }
   
 1;  1;
 __END__  __END__

Removed from v.1.5  
changed lines
  Added in v.1.6


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>