Diff for /loncom/interface/lonsearchcat.pm between versions 1.16 and 1.41

version 1.16, 2001/03/15 17:55:59 version 1.41, 2001/03/19 16:45:38
Line 3 Line 3
 #  #
 # 03/08/2001 Scott Harrison  # 03/08/2001 Scott Harrison
 #  #
   # Functions
   #
   # handler(server reference) : interacts with the Apache server layer
   #                             (for /adm/searchcat URLs)
   # simpletextfield(name,value) : returns HTML formatted string for simple text
   #                               field
   # simplecheckbox(name,value) : returns HTML formatted string for simple
   #                              checkbox
   # searchphrasefield(title,name,value) : returns HTML formatted string for
   #                                       a search expression phrase field
   # dateboxes(name, defaultmonth, defaultday, defaultyear) : returns HTML
   #                                                          formatted string
   #                                                          for a calendar date
   # selectbox(title,name,value,%HASH=options) : returns HTML formatted string for
   #                                             a selection box field
   # advancedsearch() : 
   # filled(field) : determines whether a given field has been filled
   # basicsearch() : 
   # output_blank_field_error() : outputs a message saying that more fields need
   #                              to be filled in
   # output_results() : outputs results from search
   # build_SQL_query() : builds a SQL query string from a logical expression
   #                     with AND/OR keywords
   
 package Apache::lonsearchcat;  package Apache::lonsearchcat;
   
 use strict;  use strict;
Line 10  use Apache::Constants qw(:common); Line 34  use Apache::Constants qw(:common);
 use Apache::lonnet();  use Apache::lonnet();
 use Apache::File();  use Apache::File();
 use CGI qw(:standard);  use CGI qw(:standard);
   use Text::Query;
   
 my %language;  my %language;
 my $scrout;  my $scrout;
Line 77  END Line 102  END
     }      }
   
     if ($ENV{'form.basicsubmit'} eq 'SEARCH') {      if ($ENV{'form.basicsubmit'} eq 'SEARCH') {
  return &basicsearch($r,$ENV{'form.basicexp'});   return &basicsearch($r,\%ENV);
       }
       elsif ($ENV{'form.advancedsubmit'} eq 'SEARCH') {
    return &advancedsearch($r,\%ENV);
     }      }
   
     $scrout=''; # building a part of screen output      $scrout=''; # building a part of screen output
Line 229  ENDDOCUMENT Line 257  ENDDOCUMENT
   
 # --------------------------------------------------------- Various form fields  # --------------------------------------------------------- Various form fields
   
 sub textfield {  
     my ($title,$name,$value)=@_;  
     return "\n<p><b>$title:</b><br>".  
            '<input type=text name="'.$name.'" size=80 value="'.$value.'">';  
 }  
   
 sub simpletextfield {  sub simpletextfield {
     my ($name,$value)=@_;      my ($name,$value)=@_;
     return '<input type=text name="'.$name.'" size=20 value="'.$value.'">';      return '<input type=text name="'.$name.'" size=20 value="'.$value.'">';
Line 416  sub selectbox { Line 438  sub selectbox {
     return $selout.'</select>';      return $selout.'</select>';
 }  }
   
   # ------------------------------------------------ Performing a advanced search
   sub advancedsearch {
       my ($r,$envhash)=@_;
       my %ENV=%{$envhash};
   
       my $fillflag=0;
       for my $field ('title','author','subject','keywords','url','version',
      'notes','abstract','mime','language','owner',
      'custommetadata') {
    if (&filled($ENV{"form.$field"})) {
       $fillflag++;
    }
       }
   
       unless ($fillflag) {
    &output_blank_field_error($r);
    return OK;
       }
   
       my $query='';
   #    my $concatarg=join(',"    ",',
   #       ('title', 'author', 'subject', 'notes', 'abstract'));
   
       $query="select * from metadata where concat(title) like '\%$ENV{'form.title'}\%'";
       my $reply=&Apache::lonnet::metadata_query($query);
   
       &output_results($r,$envhash,$reply);
       return OK;
   }
   
   # ---------------------------------------------------- see if a field is filled
   sub filled {
       my ($field)=@_;
       if ($field=~/\S/) {
    return 1;
       }
       else {
    return 0;
       }
   }
   
 # --------------------------------------------------- Performing a basic search  # --------------------------------------------------- Performing a basic search
 sub basicsearch {  sub basicsearch {
     my ($r,$expression)=@_;      my ($r,$envhash)=@_;
       my %ENV=%{$envhash};
   
     my $query=$expression;      unless (&filled($ENV{'form.basicexp'})) {
     $query="select * from metadata where concat(title,\"    \",author) like '\%$expression\%'";   &output_blank_field_error($r);
 #    my $reply=&Apache::lonnet::reply("querysend:$query",'msul3');   return OK;
       }
   
       my $query='';
       my $concatarg=join(',"    ",',
          ('title', 'author', 'subject', 'notes', 'abstract'));
   
       $query="select * from metadata where concat($concatarg) like '\%$ENV{'form.basicexp'}\%'";
     my $reply=&Apache::lonnet::metadata_query($query);      my $reply=&Apache::lonnet::metadata_query($query);
       &output_results($r,$envhash,$reply);
       return OK;
   }
   
     my @results;  sub output_blank_field_error {
       my ($r)=@_;
       # make query information persistent to allow for subsequent revision
       my $persistent='';
       map {
    if (/^form\./ && !/submit/) {
       my $name=$_;
       my $key=$name;
       $name=~s/^form\.//;
       $persistent.=<<END;
   <INPUT TYPE='hidden' NAME='$name' VALUE='$ENV{$key}'>
   END
           }
       } (keys %ENV);
   
     my $replyfile='';      $r->print(<<BEGINNING);
     $reply=~/^([\.\w]+)$/; # must do since 'use strict' checks for tainting  <html>
     $replyfile=$r->dir_config('lonDaemons').'/tmp/'.$1;  <head>
     $reply=~/(.*?)\_/;  <title>The LearningOnline Network with CAPA</title>
     my $hostname=$1;  BEGINNING
       $r->print(<<RESULTS);
   </head>
   <body bgcolor="#ffffff">
   <img align=right src=/adm/lonIcons/lonlogos.gif>
   <h1>Search Catalog</h1>
   <form method="post" action="/adm/searchcat">
   $persistent
   <input type='button' value='Revise search request'
   onClick='this.form.submit();'>
   <input type='button' value='CLOSE'
   onClick='self.close();'>
   <hr>
   <h3>Helpful Message</h3>
   <p>
   Incorrect search query due to blank entry fields.
   You need to fill in the relevant
   fields on the search page in order for a query to be
   processed.
   </p>
   </body>
   </html>
   RESULTS
   }
   
     {  # ----------------------------- format and output results based on a reply list
  while (1) {  sub output_results {
     last if -e $replyfile;      my ($r,$envhash,@replylist)=@_;
     sleep 1;      my %ENV=%{$envhash};
       foreach my $reply (@replylist) {
   
    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>;
  }   }
  # QUESTION: how should I handle this error condition..  
  # I'm sure there is syntax elsewhere I can use..   my $compiledresult='';
  my $fh=Apache::File->new($replyfile) or  
        ($r->print('file cannot be opened') and return OK);   foreach my $result (@results) {
        @results=<$fh>;      my ($title,$author,$subject,$url,$keywords,$version,
     }   $notes,$abstract,$mime,$lang,
    $creationdate,$lastrevisiondate,$owner,$copyright
     my $compiledresult='';   )=map {&Apache::lonnet::unescape($_)} (split(/\,/,$result));
       my $shortabstract=$abstract;
     foreach my $result (@results) {      $shortabstract=substr($abstract,0,200) if length($abstract)>200;
  my ($title,$author,$subject,$url,$keywords,$version,      $compiledresult.=<<END;
     $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>  <p>
 END  END
  $compiledresult.=<<END if $ENV{'form.catalogmode'} eq 'interactive';              $compiledresult.=<<END if $ENV{'form.catalogmode'} eq 'interactive';
 <font size='-1'><INPUT TYPE="button" NAME="returnvalues" VALUE="SELECT"  <font size='-1'><INPUT TYPE="button" NAME="returnvalues" VALUE="SELECT"
 onClick="javascript:select_data('$title','$url')">  onClick="javascript:select_data('$title','$url')">
 </font>  </font>
 <br>  <br>
 END  END
         $compiledresult.=<<END;              $compiledresult.=<<END;
 <b>URL: </b> <A HREF='http://spock.lite.msu.edu/res/msu/shh1/poobah1.html' TARGET='search_preview'>$url</A><br>  <b>URL: </b> <A HREF="http://$ENV{'HTTP_HOST'}$url" TARGET='search_preview'>$url</A>
   <br>
 <b>Title:</b> $title<br>  <b>Title:</b> $title<br>
 <b>Author(s):</b> $author<br>  <b>Author(s):</b> $author<br>
 <b>Subject:</b> $subject<br>  <b>Subject:</b> $subject<br>
Line 480  END Line 605  END
 <b>Repository Location:</b> $hostname  <b>Repository Location:</b> $hostname
 </p>  </p>
 END  END
 }          }
   
     unless ($compiledresult) {   unless ($compiledresult) {
  $compiledresult="There were no results that matched your query";      $compiledresult="There were no results that matched your query";
     }   }
   
     # make query information persistent to allow for subsequent revision   # make query information persistent to allow for subsequent revision
     my $persistent='';   my $persistent='';
     map {   map {
  if (/^form\./ && !/submit/) {      if (/^form\./ && !/submit/) {
     my $name=$_;   my $name=$_;
     my $key=$name;   my $key=$name;
     $name=~s/^form\.//;   $name=~s/^form\.//;
     $persistent.=<<END;   $persistent.=<<END;
 <INPUT TYPE='hidden' NAME='$name' VALUE='$ENV{$key}'>  <INPUT TYPE='hidden' NAME='$name' VALUE='$ENV{$key}'>
 END  END
         }              }
     } (keys %ENV);   } (keys %ENV);
   
     $r->print(<<BEGINNING);   $r->print(<<BEGINNING);
 <html>  <html>
 <head>  <head>
 <title>The LearningOnline Network with CAPA</title>  <title>The LearningOnline Network with CAPA</title>
 BEGINNING  BEGINNING
     $r->print(<<SCRIPT) if $ENV{'form.catalogmode'} eq 'interactive';          $r->print(<<SCRIPT) if $ENV{'form.catalogmode'} eq 'interactive';
 <script>  <script>
     function select_data(title,url) {      function select_data(title,url) {
  changeTitle(title);   changeTitle(title);
Line 522  BEGINNING Line 647  BEGINNING
     }      }
 </script>  </script>
 SCRIPT  SCRIPT
     $r->print(<<RESULTS);          $r->print(<<RESULTS);
 </head>  </head>
 <body bgcolor="#ffffff">  <body bgcolor="#ffffff">
 <img align=right src=/adm/lonIcons/lonlogos.gif>  <img align=right src=/adm/lonIcons/lonlogos.gif>
Line 536  $persistent Line 661  $persistent
 <hr>  <hr>
 <h3>Search Query</h3>  <h3>Search Query</h3>
 <p>  <p>
 <b>Basic search:</b> $expression  <b>Basic search:</b> $ENV{'form.basicexp'}
 </p>  </p>
 <h3>Search Results</h3>  <h3>Search Results</h3>
 $compiledresult  $compiledresult
 </body>  </body>
 </html>  </html>
 RESULTS  RESULTS
       }
   }
   
   # ------------------------------------------------------------- build_SQL_query
   sub build_SQL_query {
   
     return OK;  
 }  }
   
 1;  1;

Removed from v.1.16  
changed lines
  Added in v.1.41


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