Diff for /loncom/interface/lonsearchcat.pm between versions 1.49 and 1.61

version 1.49, 2001/03/21 01:19:37 version 1.61, 2001/03/21 12:40:37
Line 52  my %metadatafields; Line 52  my %metadatafields;
 my %cprtag;  my %cprtag;
 my %mimetag;  my %mimetag;
 my $closebutton;  my $closebutton;
 my $viewselect=<<END;  my $basicviewselect=<<END;
 <select name='view'>  <select name='basicviewselect'>
 <option value='Detailed View'>Detailed View</option>  <option value='Detailed Citation View'>Detailed Citation View</option>
 <option value='Brief View'>Brief View</option>  <option value='Summary View'>Summary View</option>
   <option value='Fielded Format'>Fielded Format</option>
   <option value='XML/SGML'>XML/SGML</option>
   </select>
   END
   my $advancedviewselect=<<END;
   <select name='advancedviewselect'>
   <option value='Detailed Citation View'>Detailed Citation View</option>
   <option value='Summary View'>Summary View</option>
   <option value='Fielded Format'>Fielded Format</option>
   <option value='XML/SGML'>XML/SGML</option>
 </select>  </select>
 END  END
   
Line 97  END Line 107  END
     {      {
  my $fh=Apache::File->new($r->dir_config('lonTabDir').'/language.tab');   my $fh=Apache::File->new($r->dir_config('lonTabDir').'/language.tab');
  map {   map {
     $_=~/(\w+)\s+([\w\s\-]+)/;      $_=~/(\w+)\s+([\w\s\-]+)/; chomp;
     $language{$1}=$2;      $language{$1}=$2;
  } <$fh>;   } <$fh>;
     }      }
Line 107  END Line 117  END
     {      {
  my $fh=Apache::File->new($r->dir_config('lonIncludes').'/copyright.tab');   my $fh=Apache::File->new($r->dir_config('lonIncludes').'/copyright.tab');
  map {   map {
     $_=~/(\w+)\s+([\w\s\-]+)/;      $_=~/(\w+)\s+([\w\s\-]+)/; chomp;
     $cprtag{$1}=$2;      $cprtag{$1}=$2;
  } <$fh>;   } <$fh>;
     }      }
Line 117  END Line 127  END
     {      {
  my $fh=Apache::File->new($r->dir_config('lonTabDir').'/filetypes.tab');   my $fh=Apache::File->new($r->dir_config('lonTabDir').'/filetypes.tab');
  map {   map {
     $_=~/(\w+)\s+(\w+)\s+([\w\s\-]+)/;      $_=~/(\w+)\s+(\w+)\s+([\w\s\-]+)/; chomp;
     $mimetag{$1}=".$1 $3";      $mimetag{$1}=".$1 $3";
  } <$fh>;   } <$fh>;
     }      }
Line 260  ENDDOCUMENT Line 270  ENDDOCUMENT
 <input type="submit" name="basicsubmit" value="SEARCH">  <input type="submit" name="basicsubmit" value="SEARCH">
 <input type="reset" name="reset" value="RESET">  <input type="reset" name="reset" value="RESET">
 $closebutton  $closebutton
 $viewselect  $basicviewselect
 </p>  </p>
 <hr>  <hr>
 <h3>Advanced Search</h3>  <h3>Advanced Search</h3>
Line 269  $scrout Line 279  $scrout
 <input type="submit" name="advancedsubmit" value="SEARCH">  <input type="submit" name="advancedsubmit" value="SEARCH">
 <input type="reset" name="reset" value="RESET">  <input type="reset" name="reset" value="RESET">
 $closebutton  $closebutton
 $viewselect  $advancedviewselect
 </p>  </p>
 </form>  </form>
 </body>  </body>
Line 484  sub advancedsearch { Line 494  sub advancedsearch {
   
     my @queries;      my @queries;
     # Go through logical expression AND/OR/NOT phrase fields.      # Go through logical expression AND/OR/NOT phrase fields.
     foreach my $field ('title','author','subject','notes','abstract') {  
       foreach my $field ('title','author','subject','notes','abstract','url',
          'keywords','version','owner') {
  if ($ENV{'form.'.$field}) {   if ($ENV{'form.'.$field}) {
     push @queries,&build_SQL_query($field,$ENV{'form.'.$field});      push @queries,&build_SQL_query($field,$ENV{'form.'.$field});
  }   }
     }      }
       if ($ENV{'form.language'} and $ENV{'form.language'} ne 'any') {
    push @queries,"(language like \"\%$ENV{'form.language'}\%\")";
       }
       if ($ENV{'form.mime'} and $ENV{'form.mime'} ne 'any') {
    push @queries,"(mime like \"\%$ENV{'form.mime'}\%\")";
       }
       if ($ENV{'form.copyright'} and $ENV{'form.copyright'} ne 'any') {
    push @queries,"(copyright like \"\%$ENV{'form.copyright'}\%\")";
       }
       my $datequery=&build_date_queries(
    $ENV{'form.creationdatestart_month'},
    $ENV{'form.creationdatestart_day'},
    $ENV{'form.creationdatestart_year'},
    $ENV{'form.creationdateend_month'},
    $ENV{'form.creationdateend_day'},
    $ENV{'form.creationdateend_year'},
    $ENV{'form.lastrevisiondatestart_month'},
    $ENV{'form.lastrevisiondatestart_day'},
    $ENV{'form.lastrevisiondatestart_year'},
    $ENV{'form.lastrevisiondateend_month'},
    $ENV{'form.lastrevisiondateend_day'},
    $ENV{'form.lastrevisiondateend_year'},
    );
       if ($datequery=~/^Incorrect/) {
    &output_date_error($r,$datequery);
    return OK;
       }
       elsif ($datequery) {
    push @queries,$datequery;
       }
     if (@queries) {      if (@queries) {
  $query=join(" and ",@queries);   $query=join(" AND ",@queries);
  $query="select * from metadata where $query";   $query="select * from metadata where $query";
  my $reply=&Apache::lonnet::metadata_query($query);   my $reply=&Apache::lonnet::metadata_query($query);
  &output_results('Advanced',$r,$envhash,$query,$reply);   &output_results('Advanced',$r,$envhash,$query,$reply);
Line 591  sub output_results { Line 633  sub output_results {
  $replyfile=$r->dir_config('lonDaemons').'/tmp/'.$1;   $replyfile=$r->dir_config('lonDaemons').'/tmp/'.$1;
  $reply=~/(.*?)\_/;   $reply=~/(.*?)\_/;
  my $hostname=$1;   my $hostname=$1;
    sleep 3; # temporary fix, need to check for completion and status
  {   {
     while (1) {      while (1) {
  last if -e $replyfile;   last if -e $replyfile;
Line 605  sub output_results { Line 647  sub output_results {
  }   }
   
  foreach my $result (@results) {   foreach my $result (@results) {
       my @fields=map
                      {&Apache::lonnet::unescape($_)}
                      (split(/\,/,$result));
     my ($title,$author,$subject,$url,$keywords,$version,      my ($title,$author,$subject,$url,$keywords,$version,
  $notes,$abstract,$mime,$lang,   $notes,$abstract,$mime,$lang,
  $creationdate,$lastrevisiondate,$owner,$copyright   $creationdate,$lastrevisiondate,$owner,$copyright)=@fields;
  )=map {&Apache::lonnet::unescape($_)} (split(/\,/,$result));  
     my $shortabstract=$abstract;      my $shortabstract=$abstract;
     $shortabstract=substr($abstract,0,200) if length($abstract)>200;      $shortabstract=substr($abstract,0,200) if length($abstract)>200;
       $fields[7]=$shortabstract;
     $compiledresult.=<<END;      $compiledresult.=<<END;
 <p>  <p>
 END  END
Line 620  onClick="javascript:select_data('$title' Line 665  onClick="javascript:select_data('$title'
 </font>  </font>
 <br>  <br>
 END  END
             $compiledresult.=<<END;              my $httphost=$ENV{'HTTP_HOST'};
 <b>URL: </b> <A HREF="http://$ENV{'HTTP_HOST'}$url" TARGET='search_preview'>$url</A>  
 <br>      my $viewselect;
 <b>Title:</b> $title<br>      if ($mode eq 'Basic') {
 <b>Author(s):</b> $author<br>   $viewselect=$ENV{'form.basicviewselect'};
 <b>Subject:</b> $subject<br>      }
 <b>Keyword(s):</b> $keywords<br>      elsif ($mode eq 'Advanced') {
 <b>Notes:</b> $notes<br>   $viewselect=$ENV{'form.advancedviewselect'};
 <b>Abstract:</b> $shortabstract<br>      }
 <b>MIME Type:</b> $mimetag{$mime}<br>  
 <b>Language:</b> $language{$lang}<br>              if ($viewselect eq 'Detailed Citation View') {
 <b>Creation Date:</b> $creationdate<br>   $compiledresult.=&detailed_citation_view(@fields,
 <b>Last Revision Date:</b> $lastrevisiondate<br>   $hostname,$httphost);
 <b>Publisher/Owner:</b> $owner<br>      }
 <b>Copyright/Distribution:</b> $copyright<br>              elsif ($viewselect eq 'Summary View') {
 <b>Repository Location:</b> $hostname   $compiledresult.=&summary_view(@fields,$hostname,$httphost);
 </p>      }
 END              elsif ($viewselect eq 'Fielded Format') {
    $compiledresult.=&fielded_format_view(@fields,$hostname,
         $httphost);
       }
               elsif ($viewselect eq 'XML/SGML') {
    $compiledresult.=&xml_sgml_view(@fields,$hostname,$httphost);
       }
   
         }          }
   
  unless ($compiledresult) {   unless ($compiledresult) {
Line 758  sub recursive_SQL_query_build { Line 810  sub recursive_SQL_query_build {
     &recursive_SQL_query_build($dkey,$pattern);      &recursive_SQL_query_build($dkey,$pattern);
 }  }
   
   # ------------------------------------------------------ Detailed Citation View
   sub detailed_citation_view {
       my ($title,$author,$subject,$url,$keywords,$version,
    $notes,$shortabstract,$mime,$lang,
    $creationdate,$lastrevisiondate,$owner,$copyright,
    $hostname,$httphost)=@_;
       my $result=<<END;
   <i>$owner</i>, last revised $lastrevisiondate
   <h3><A HREF="http://$httphost$url" TARGET='search_preview'>$title</A></h3>
   <h3>$author</h3>
   </p>
   <p>
   <b>Subject:</b> $subject<br>
   <b>Keyword(s):</b> $keywords<br>
   <b>Notes:</b> $notes<br>
   <b>MIME Type:</b> $mimetag{$mime}<br>
   <b>Language:</b> $language{$lang}<br>
   <b>Copyright/Distribution:</b> $cprtag{$copyright}<br>
   $shortabstract
   </p>
   END
       return $result;
   }
   
   # ---------------------------------------------------------------- Summary View
   sub summary_view {
       my ($title,$author,$subject,$url,$keywords,$version,
    $notes,$shortabstract,$mime,$lang,
    $creationdate,$lastrevisiondate,$owner,$copyright,
    $hostname,$httphost)=@_;
       my $result=<<END;
   <a href="http://$httphost$url" TARGET='search_preview'>$author</a><br />
   $title<br />
   $owner -- $lastrevisiondate<br />
   $cprtag{$copyright}<br />
   </p>
   END
       return $result;
   }
   
   # -------------------------------------------------------------- Fielded Format
   sub fielded_format_view {
       my ($title,$author,$subject,$url,$keywords,$version,
    $notes,$shortabstract,$mime,$lang,
    $creationdate,$lastrevisiondate,$owner,$copyright,
    $hostname,$httphost)=@_;
       my $result=<<END;
   <b>URL: </b> <A HREF="http://$httphost$url" TARGET='search_preview'>$url</A>
   <br />
   <b>Title:</b> $title<br />
   <b>Author(s):</b> $author<br />
   <b>Subject:</b> $subject<br />
   <b>Keyword(s):</b> $keywords<br />
   <b>Notes:</b> $notes<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> $cprtag{$copyright}<br />
   <b>Repository Location:</b> $hostname<br />
   <b>Abstract:</b> $shortabstract<br />
   </p>
   END
       return $result;
   }
   
   # -------------------------------------------------------------------- XML/SGML
   sub xml_sgml_view {
       my ($title,$author,$subject,$url,$keywords,$version,
    $notes,$shortabstract,$mime,$lang,
    $creationdate,$lastrevisiondate,$owner,$copyright,
    $hostname,$httphost)=@_;
       my $result=<<END;
   <pre>
   &lt;LonCapaResource&gt;
   &lt;url&gt;$url&lt;/url&gt;
   &lt;title&gt;$title&lt;/title&gt;
   &lt;author&gt;$author&lt;/author&gt;
   &lt;subject&gt;$subject&lt;/subject&gt;
   &lt;keywords&gt;$keywords&lt;/keywords&gt;
   &lt;notes&gt;$notes&lt;/notes&gt;
   &lt;mimeInfo&gt;
   &lt;mime&gt;$mime&lt;/mime&gt;
   &lt;mimetag&gt;$mimetag{$mime}&lt;/mimetag&gt;
   &lt;/mimeInfo&gt;
   &lt;languageInfo&gt;
   &lt;language&gt;$lang&lt;/language&gt;
   &lt;languagetag&gt;$language{$lang}&lt;/languagetag&gt;
   &lt;/languageInfo&gt;
   &lt;creationdate&gt;$creationdate&lt;/creationdate&gt;
   &lt;lastrevisiondate&gt;$lastrevisiondate&lt;/lastrevisiondate&gt;
   &lt;owner&gt;$owner&lt;/owner&gt;
   &lt;copyrightInfo&gt;
   &lt;copyright&gt;$copyright&lt;/copyright&gt;
   &lt;copyrighttag&gt;$cprtag{$copyright}&lt;/copyrighttag&gt;
   &lt;/copyrightInfo&gt;
   &lt;repositoryLocation&gt;$hostname&lt;/repositoryLocation&gt;
   &lt;shortabstract&gt;$shortabstract&lt;/shortabstract&gt;
   &lt;/LonCapaResource&gt;
   </pre>
   END
       return $result;
   }
   
   sub build_date_queries {
       my ($cmonth1,$cday1,$cyear1,$cmonth2,$cday2,$cyear2,
    $lmonth1,$lday1,$lyear1,$lmonth2,$lday2,$lyear2)=@_;
       my @queries;
       if ($cmonth1 or $cday1 or $cyear1 or $cmonth2 or $cday2 or $cyear2) {
    unless ($cmonth1 and $cday1 and $cyear1 and
    $cmonth2 and $cday2 and $cyear2) {
       return "Incorrect entry for the creation date.  You must specify ".
      "a starting month, day, and year and an ending month, ".
      "day, and year.";
    }
    my $cnumeric1="$cyear1$cmonth1$cday1";
    $cnumeric1+=0;
    my $cnumeric2="$cyear2$cmonth2$cday2";
    $cnumeric2+=0;
    if ($cnumeric1>$cnumeric2) {
       return "Incorrect entry for the creation date.  The starting ".
      "date must occur before the ending date.";
    }
    my $cquery="(creationdate BETWEEN '$cyear1-$cmonth1-$cday1' AND '".
              "$cyear2-$cmonth2-$cday2 23:59:59')";
    push @queries,$cquery;
       }
       if ($lmonth1 or $lday1 or $lyear1 or $lmonth2 or $lday2 or $lyear2) {
    unless ($lmonth1 and $lday1 and $lyear1 and
    $lmonth2 and $lday2 and $lyear2) {
       return "Incorrect entry for the last revision date.  You must ".
      "specify a starting month, day, and year and an ending ".
      "month, day, and year.";
    my $lnumeric1="$lyear1$lmonth1$lday1";
    $lnumeric1+=0;
    my $lnumeric2="$lyear2$lmonth2$lday2";
    $lnumeric2+=0;
    if ($lnumeric1>$lnumeric2) {
       return "Incorrect entry for the last revision date.  The ".
      "starting date must occur before the ending date.";
    }
    my $lquery="(lastrevisiondate BETWEEN '$lyear1-$lmonth1-$lday1' AND '".
              "$lyear2-$lmonth2-$lday2 23:59:59')";
    push @queries,$lquery;
       }
       if (@queries) {
    return join(" AND ",@queries);
       }
       return '';
   }
   
   sub output_date_error {
       my ($r,$message)=@_;
       # 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);
   
       $r->print(<<BEGINNING);
   <html>
   <head>
   <title>The LearningOnline Network with CAPA</title>
   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();'>
   $closebutton
   <hr>
   <h3>Helpful Message</h3>
   <p>
   $message
   </p>
   </body>
   </html>
   RESULTS
   }
   
 1;  1;
 __END__  __END__

Removed from v.1.49  
changed lines
  Added in v.1.61


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