Diff for /loncom/interface/lonsearchcat.pm between versions 1.51 and 1.89

version 1.51, 2001/03/21 02:18:14 version 1.89, 2001/03/27 21:41:06
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 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>
   END
   my $advancedviewselect=<<END;
   <select name='advancedviewselect'>
 <option value='Detailed Citation View'>Detailed Citation View</option>  <option value='Detailed Citation View'>Detailed Citation View</option>
 <option value='Summary View'>Summary View</option>  <option value='Summary View'>Summary View</option>
 <option value='Fielded Format'>Fielded Format</option>  <option value='Fielded Format'>Fielded Format</option>
Line 86  sub handler { Line 94  sub handler {
 END  END
   
     $closebutton=<<END if $ENV{'form.catalogmode'} eq 'interactive';      $closebutton=<<END if $ENV{'form.catalogmode'} eq 'interactive';
 <input type="button" name="close" value="CLOSE" onClick="self.close()">  <input type="button" name="close" value='CLOSE' onClick="self.close()">
 END  END
   
 # ------------------------------------------------ First, check out environment  # ------------------------------------------------ First, check out environment
Line 99  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 109  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 119  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 221  LASTREVISIONDATEEND Line 229  LASTREVISIONDATEEND
 # ------------------------------------------- Compute customized metadata field  # ------------------------------------------- Compute customized metadata field
     $scrout.=<<CUSTOMMETADATA;      $scrout.=<<CUSTOMMETADATA;
 <p>  <p>
 <font color="#800000" face="helvetica"><b>LIMIT BY OTHER METADATA FIELDS:</b>  <font color="#800000" face="helvetica"><b>LIMIT BY SPECIAL METADATA FIELDS:</b>
 </font>  </font>
 For author-specific metadata, enter in an expression in the form of   For resource-specific metadata, enter in an expression in the form of 
 <i>key</i>=<i>value</i> separated by operators such as AND or OR.<br>  <i>key</i>=<i>value</i> separated by operators such as AND or OR.<br>
 <b>Example:</b> grandmother=75 OR grandfather=85  <b>Example:</b> grandmother=75 OR grandfather=85
 <br>  <br>
Line 231  CUSTOMMETADATA Line 239  CUSTOMMETADATA
 $scrout.=&simpletextfield('custommetadata',$ENV{'form.custommetadata'});  $scrout.=&simpletextfield('custommetadata',$ENV{'form.custommetadata'});
 $scrout.=' <i>initial users of this system do not need to worry about this option</i>';  $scrout.=' <i>initial users of this system do not need to worry about this option</i>';
   
       $scrout.=<<CUSTOMSHOW;
   <p>
   <font color="#800000" face="helvetica"><b>SHOW SPECIAL METADATA FIELDS:</b>
   </font>
   Enter in a space-separated list of special metadata fields to show
   in a fielded listing for each record result.
   <br>
   CUSTOMSHOW
   $scrout.=&simpletextfield('customshow',$ENV{'form.customshow'});
   $scrout.=' <i>initial users of this system do not need to worry about this option</i>';
   
 # ---------------------------------------------------------------- Print screen  # ---------------------------------------------------------------- Print screen
     $r->print(<<ENDDOCUMENT);      $r->print(<<ENDDOCUMENT);
 <html>  <html>
Line 259  ENDDOCUMENT Line 278  ENDDOCUMENT
     $r->print(<<ENDDOCUMENT);      $r->print(<<ENDDOCUMENT);
 <font color="#800000">Search historic archives</font>  <font color="#800000">Search historic archives</font>
 <br>  <br>
 <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>
 $scrout  $scrout
 <p>  <p>
 <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 284  ENDDOCUMENT Line 303  ENDDOCUMENT
   
 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.'\' />';
 }  }
   
 sub simplecheckbox {  sub simplecheckbox {
     my ($name,$value)=@_;      my ($name,$value)=@_;
     my $checked='';      my $checked='';
     $checked="CHECKED" if $value eq 'on';      $checked="CHECKED" if $value eq 'on';
     return '<input type=checkbox name="'.$name.'" '. $checked . '>';      return '<input type=checkbox name=\''.$name.'\' '. $checked . '>';
 }  }
   
 sub searchphrasefield {  sub searchphrasefield {
Line 303  END Line 323  END
     my $uctitle=uc($title);      my $uctitle=uc($title);
     return "\n<p><font color=\"#800000\" face=\"helvetica\"><b>$uctitle:</b>".      return "\n<p><font color=\"#800000\" face=\"helvetica\"><b>$uctitle:</b>".
    "</FONT> $instruction<br>".     "</FONT> $instruction<br>".
            '<input type=text name="'.$name.'" size=80 value="'.$value.'">';             '<input type=text name="'.$name.'" size=80 value=\''.$value.'\'>';
 }  }
   
 sub dateboxes {  sub dateboxes {
Line 456  sub selectbox { Line 476  sub selectbox {
     my $selout="\n<p><font color=\"#800000\" face=\"helvetica\"><b>$uctitle:".      my $selout="\n<p><font color=\"#800000\" face=\"helvetica\"><b>$uctitle:".
  "</b></font><br>".'<select name="'.$name.'">';   "</b></font><br>".'<select name="'.$name.'">';
     map {      map {
         $selout.='<option value="'.$_.'"';          $selout.='<option value=\''.$_.'\'';
         if ($_ eq $value) { $selout.=' selected'; }          if ($_ eq $value) { $selout.=' selected'; }
         $selout.='>'.$options{$_}.'</option>';          $selout.='>'.$options{$_}.'</option>';
     } sort keys %options;      } sort keys %options;
Line 469  sub advancedsearch { Line 489  sub advancedsearch {
     my %ENV=%{$envhash};      my %ENV=%{$envhash};
   
     my $fillflag=0;      my $fillflag=0;
       # Clean up fields for safety
       for my $field ('title','author','subject','keywords','url','version',
      'creationdatestart_month','creationdatestart_day',
      'creationdatestart_year','creationdateend_month',
      'creationdateend_day','creationdateend_year',
      'lastrevisiondatestart_month','lastrevisiondatestart_day',
      'lastrevisiondatestart_year','lastrevisiondateend_month',
      'lastrevisiondateend_day','lastrevisiondateend_year',
      'notes','abstract','mime','language','owner',
      'custommetadata','customshow') {
    $ENV{"form.$field"}=~s/[^\w\s\(\)\=\-\"\']//g;
       }
     for my $field ('title','author','subject','keywords','url','version',      for my $field ('title','author','subject','keywords','url','version',
    'notes','abstract','mime','language','owner',     'notes','abstract','mime','language','owner',
    'custommetadata') {     'custommetadata') {
Line 486  sub advancedsearch { Line 518  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;
       }
       my $customquery='';
       if ($ENV{'form.custommetadata'}) {
    $customquery=&build_custommetadata_query('custommetadata',
         $ENV{'form.custommetadata'});
       }
       my $customshow='';
       if ($ENV{'form.customshow'}) {
    $customshow=$ENV{'form.customshow'};
    $customshow=~s/[^\w\s]//g;
    my @fields=split(/\s+/,$customshow);
    $customshow=join(" ",@fields);
       }
     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='';
  &output_results('Advanced',$r,$envhash,$query,$reply);   unless ($customquery or $customshow) {
       $reply=&Apache::lonnet::metadata_query($query);
    }
    else {
       $reply=&Apache::lonnet::metadata_query($query,
      $customquery,$customshow);
    }
    &output_results('Advanced',$r,$envhash,$customquery,$reply);
     }      }
     else {      elsif ($customquery) {
  &output_results('Advanced',$r,$envhash,$query);   my $reply='';
    $reply=&Apache::lonnet::metadata_query('',
          $customquery,$customshow);
    &output_results('Advanced',$r,$envhash,$customquery,$reply);
     }      }
       $r->print(' '); # just in case.. hrrmm..
     return OK;      return OK;
 }  }
   
Line 519  sub basicsearch { Line 606  sub basicsearch {
     my ($r,$envhash)=@_;      my ($r,$envhash)=@_;
     my %ENV=%{$envhash};      my %ENV=%{$envhash};
   
       # Clean up fields for safety
       for my $field ('basicexp') {
    $ENV{"form.$field"}=~s/[^\w\s\(\)\-]//g;
       }
   
     unless (&filled($ENV{'form.basicexp'})) {      unless (&filled($ENV{'form.basicexp'})) {
  &output_blank_field_error($r);   &output_blank_field_error($r);
  return OK;   return OK;
Line 538  sub basicsearch { Line 630  sub basicsearch {
 sub output_blank_field_error {  sub output_blank_field_error {
     my ($r)=@_;      my ($r)=@_;
     # make query information persistent to allow for subsequent revision      # make query information persistent to allow for subsequent revision
     my $persistent='';      my $persistent=&make_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);      $r->print(<<BEGINNING);
 <html>  <html>
Line 593  sub output_results { Line 675  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 606  sub output_results { Line 688  sub output_results {
     @results=<$fh>;      @results=<$fh>;
  }   }
   
    my $customshow='';
    my $extrashow='';
    my @customfields;
    if ($ENV{'form.customshow'}) {
       $customshow=$ENV{'form.customshow'};
       $customshow=~s/[^\w\s]//g;
       my @fields=map {"<font color=\"#008000\">$_:</font><!-- $_ -->"} 
                      split(/\s+/,$customshow);
       @customfields=split(/\s+/,$customshow);
       if ($customshow) {
    $extrashow="<ul><li>".join("</li><li>",@fields)."</li></ul>\n";
       }
    }
    my $customdata='';
    my %customhash;
  foreach my $result (@results) {   foreach my $result (@results) {
       if ($result=~/^(custom\=.*)$/) { # grab all custom metadata
    my $tmp=$result;
    $tmp=~s/^custom\=//;
    my ($k,$v)=map {&Apache::lonnet::unescape($_);
       } split(/\,/,$tmp);
    $customhash{$k}=$v;
       }
    }
    foreach my $result (@results) {
       next if $result=~/^custom\=/;
       chomp $result;
       next unless $result;
     my @fields=map      my @fields=map
                    {&Apache::lonnet::unescape($_)}                     {&Apache::lonnet::unescape($_)}
                    (split(/\,/,$result));                     (split(/\,/,$result));
Line 616  sub output_results { Line 725  sub output_results {
     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;      $fields[7]=$shortabstract;
       my $extrashow2=$extrashow;
       if ($extrashow) {
    foreach my $field (@customfields) {
       my $value='';
       if ($customhash{$url}=~/\<${field}[^\>]*\>(.*?)\<\/${field}[^\>]*\>/s) {
            $value=$1;
       }
       $extrashow2=~s/\<\!\-\- $field \-\-\>/ $value/g;
    }
       }
   
       $compiledresult.=<<END if $compiledresult;
   <hr align='left' width='200' noshade />
   END
     $compiledresult.=<<END;      $compiledresult.=<<END;
 <p>  <p>
 END  END
Line 626  onClick="javascript:select_data('$title' Line 749  onClick="javascript:select_data('$title'
 <br>  <br>
 END  END
             my $httphost=$ENV{'HTTP_HOST'};              my $httphost=$ENV{'HTTP_HOST'};
             if ($ENV{'form.viewselect'} eq 'Detailed Citation View') {  
       my $viewselect;
       if ($mode eq 'Basic') {
    $viewselect=$ENV{'form.basicviewselect'};
       }
       elsif ($mode eq 'Advanced') {
    $viewselect=$ENV{'form.advancedviewselect'};
       }
   
               if ($viewselect eq 'Detailed Citation View') {
  $compiledresult.=&detailed_citation_view(@fields,   $compiledresult.=&detailed_citation_view(@fields,
  $hostname,$httphost);   $hostname,$httphost,
    $extrashow2);
     }      }
             elsif ($ENV{'form.viewselect'} eq 'Summary View') {              elsif ($viewselect eq 'Summary View') {
  $compiledresult.=&summary_view(@fields,$hostname,$httphost);   $compiledresult.=&summary_view(@fields,$hostname,$httphost,
          $extrashow2);
     }      }
             elsif ($ENV{'form.viewselect'} eq 'Fielded Format') {              elsif ($viewselect eq 'Fielded Format') {
  $compiledresult.=&fielded_format_view(@fields,$hostname,   $compiledresult.=&fielded_format_view(@fields,$hostname,
       $httphost);        $httphost,$extrashow2);
     }      }
             elsif ($ENV{'form.viewselect'} eq 'XML/SGML') {              elsif ($viewselect eq 'XML/SGML') {
  $compiledresult.=&xml_sgml_view(@fields,$hostname,$httphost);   $compiledresult.=&xml_sgml_view(@fields,$hostname,$httphost,
    $extrashow2);
     }      }
   
         }          }
Line 648  END Line 783  END
  }   }
   
  # make query information persistent to allow for subsequent revision   # make query information persistent to allow for subsequent revision
  my $persistent='';   my $persistent=&make_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);   $r->print(<<BEGINNING);
 <html>  <html>
Line 689  SCRIPT Line 814  SCRIPT
 <img align=right src=/adm/lonIcons/lonlogos.gif>  <img align=right src=/adm/lonIcons/lonlogos.gif>
 <h1>Search Catalog</h1>  <h1>Search Catalog</h1>
 <form method="post" action="/adm/searchcat">  <form method="post" action="/adm/searchcat">
   $customdata
 <input type='button' value='Revise search request'  <input type='button' value='Revise search request'
 onClick='this.form.submit();'>  onClick='this.form.submit();'>
 $closebutton  $closebutton
Line 732  sub build_SQL_query { Line 858  sub build_SQL_query {
     return $sql_query;      return $sql_query;
 }  }
   
   # ------------------------------------------------- build custom metadata query
   sub build_custommetadata_query {
       my ($field_name,$logic_statement)=@_;
       my $q=new Text::Query('abc',
     -parse => 'Text::Query::ParseAdvanced',
     -build => 'Text::Query::BuildAdvancedString');
       $q->prepare($logic_statement);
       my $matchexp=${$q}{'-parse'}{'-build'}{'matchstring'};
       # quick fix to change literal into xml tag-matching
       # will eventually have to write a separate builder module
       my $oldmatchexp=$matchexp;
       $matchexp=~s/(\w+)\\\=([\w\\\+]+)/\\\<$1\\\>\[\^\\\<\]\*$2\[\^\\\<\]\*\\\<\\\/$1\\\>/g;
       return $matchexp;
   }
   
 # - Recursively parse a reverse notation expression into a SQL query expression  # - Recursively parse a reverse notation expression into a SQL query expression
 sub recursive_SQL_query_build {  sub recursive_SQL_query_build {
     my ($dkey,$pattern)=@_;      my ($dkey,$pattern)=@_;
Line 766  sub detailed_citation_view { Line 907  sub detailed_citation_view {
     my ($title,$author,$subject,$url,$keywords,$version,      my ($title,$author,$subject,$url,$keywords,$version,
  $notes,$shortabstract,$mime,$lang,   $notes,$shortabstract,$mime,$lang,
  $creationdate,$lastrevisiondate,$owner,$copyright,   $creationdate,$lastrevisiondate,$owner,$copyright,
  $hostname,$httphost)=@_;   $hostname,$httphost,$extrashow)=@_;
     my $result=<<END;      my $result=<<END;
 DETAILED  <i>$owner</i>, last revised $lastrevisiondate
 <b>URL: </b> <A HREF="http://$httphost$url" TARGET='search_preview'>$url</A>  <h3><A HREF="http://$httphost$url" TARGET='search_preview'>$title</A></h3>
 <br>  <h3>$author</h3>
 <b>Title:</b> $title<br>  </p>
 <b>Author(s):</b> $author<br>  <p>
 <b>Subject:</b> $subject<br>  <b>Subject:</b> $subject<br>
 <b>Keyword(s):</b> $keywords<br>  <b>Keyword(s):</b> $keywords<br>
 <b>Notes:</b> $notes<br>  <b>Notes:</b> $notes<br>
 <b>Abstract:</b> $shortabstract<br>  
 <b>MIME Type:</b> $mimetag{$mime}<br>  <b>MIME Type:</b> $mimetag{$mime}<br>
 <b>Language:</b> $language{$lang}<br>  <b>Language:</b> $language{$lang}<br>
 <b>Creation Date:</b> $creationdate<br>  <b>Copyright/Distribution:</b> $cprtag{$copyright}<br>
 <b>Last Revision Date:</b> $lastrevisiondate<br>  </p>
 <b>Publisher/Owner:</b> $owner<br>  $extrashow
 <b>Copyright/Distribution:</b> $copyright<br>  <p>
 <b>Repository Location:</b> $hostname  $shortabstract
 </p>  </p>
 END  END
     return $result;      return $result;
Line 794  sub summary_view { Line 934  sub summary_view {
     my ($title,$author,$subject,$url,$keywords,$version,      my ($title,$author,$subject,$url,$keywords,$version,
  $notes,$shortabstract,$mime,$lang,   $notes,$shortabstract,$mime,$lang,
  $creationdate,$lastrevisiondate,$owner,$copyright,   $creationdate,$lastrevisiondate,$owner,$copyright,
  $hostname,$httphost)=@_;   $hostname,$httphost,$extrashow)=@_;
     my $result=<<END;      my $result=<<END;
 SUMMARY  <a href="http://$httphost$url" TARGET='search_preview'>$author</a><br />
 <b>URL: </b> <A HREF="http://$httphost$url" TARGET='search_preview'>$url</A>  $title<br />
 <br>  $owner -- $lastrevisiondate<br />
 <b>Title:</b> $title<br>  $cprtag{$copyright}<br />
 <b>Author(s):</b> $author<br>  $extrashow
 <b>Subject:</b> $subject<br>  
 <b>Keyword(s):</b> $keywords<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>  </p>
 END  END
     return $result;      return $result;
Line 822  sub fielded_format_view { Line 951  sub fielded_format_view {
     my ($title,$author,$subject,$url,$keywords,$version,      my ($title,$author,$subject,$url,$keywords,$version,
  $notes,$shortabstract,$mime,$lang,   $notes,$shortabstract,$mime,$lang,
  $creationdate,$lastrevisiondate,$owner,$copyright,   $creationdate,$lastrevisiondate,$owner,$copyright,
  $hostname,$httphost)=@_;   $hostname,$httphost,$extrashow)=@_;
     my $result=<<END;      my $result=<<END;
 FIELDED  
 <b>URL: </b> <A HREF="http://$httphost$url" TARGET='search_preview'>$url</A>  <b>URL: </b> <A HREF="http://$httphost$url" TARGET='search_preview'>$url</A>
 <br>  <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 />
 <b>Keyword(s):</b> $keywords<br>  <b>Keyword(s):</b> $keywords<br />
 <b>Notes:</b> $notes<br>  <b>Notes:</b> $notes<br />
 <b>Abstract:</b> $shortabstract<br>  <b>MIME Type:</b> $mimetag{$mime}<br />
 <b>MIME Type:</b> $mimetag{$mime}<br>  <b>Language:</b> $language{$lang}<br />
 <b>Language:</b> $language{$lang}<br>  <b>Creation Date:</b> $creationdate<br />
 <b>Creation Date:</b> $creationdate<br>  <b>Last Revision Date:</b> $lastrevisiondate<br />
 <b>Last Revision Date:</b> $lastrevisiondate<br>  <b>Publisher/Owner:</b> $owner<br />
 <b>Publisher/Owner:</b> $owner<br>  <b>Copyright/Distribution:</b> $cprtag{$copyright}<br />
 <b>Copyright/Distribution:</b> $copyright<br>  <b>Repository Location:</b> $hostname<br />
 <b>Repository Location:</b> $hostname  <b>Abstract:</b> $shortabstract<br />
   $extrashow
 </p>  </p>
 END  END
     return $result;      return $result;
Line 850  sub xml_sgml_view { Line 979  sub xml_sgml_view {
     my ($title,$author,$subject,$url,$keywords,$version,      my ($title,$author,$subject,$url,$keywords,$version,
  $notes,$shortabstract,$mime,$lang,   $notes,$shortabstract,$mime,$lang,
  $creationdate,$lastrevisiondate,$owner,$copyright,   $creationdate,$lastrevisiondate,$owner,$copyright,
  $hostname,$httphost)=@_;   $hostname,$httphost,$extrashow)=@_;
     my $result=<<END;      my $result=<<END;
 XML/SGML  <pre>
 <b>URL: </b> <A HREF="http://$httphost$url" TARGET='search_preview'>$url</A>  &lt;LonCapaResource&gt;
 <br>  &lt;url&gt;$url&lt;/url&gt;
 <b>Title:</b> $title<br>  &lt;title&gt;$title&lt;/title&gt;
 <b>Author(s):</b> $author<br>  &lt;author&gt;$author&lt;/author&gt;
 <b>Subject:</b> $subject<br>  &lt;subject&gt;$subject&lt;/subject&gt;
 <b>Keyword(s):</b> $keywords<br>  &lt;keywords&gt;$keywords&lt;/keywords&gt;
 <b>Notes:</b> $notes<br>  &lt;notes&gt;$notes&lt;/notes&gt;
 <b>Abstract:</b> $shortabstract<br>  &lt;mimeInfo&gt;
 <b>MIME Type:</b> $mimetag{$mime}<br>  &lt;mime&gt;$mime&lt;/mime&gt;
 <b>Language:</b> $language{$lang}<br>  &lt;mimetag&gt;$mimetag{$mime}&lt;/mimetag&gt;
 <b>Creation Date:</b> $creationdate<br>  &lt;/mimeInfo&gt;
 <b>Last Revision Date:</b> $lastrevisiondate<br>  &lt;languageInfo&gt;
 <b>Publisher/Owner:</b> $owner<br>  &lt;language&gt;$lang&lt;/language&gt;
 <b>Copyright/Distribution:</b> $copyright<br>  &lt;languagetag&gt;$language{$lang}&lt;/languagetag&gt;
 <b>Repository Location:</b> $hostname  &lt;/languageInfo&gt;
 </p>  &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>
   $extrashow
 END  END
     return $result;      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=sprintf("%d%2d%2d",$cyear1,$cmonth1,$cday1);
    $cnumeric1+=0;
    my $cnumeric2=sprintf("%d%2d%2d",$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=sprintf("%d%2d%2d",$lyear1,$lmonth1,$lday1);
    $lnumeric1+=0;
    my $lnumeric2=sprintf("%d%2d%2d",$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=&make_persistent();
   
       $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
   }
   
   sub make_persistent {
       my $persistent='';
       
       map {
    if (/^form\./ && !/submit/) {
       my $name=$_;
       my $key=$name;
       $ENV{$key}=~s/\'//g; # do not mess with html field syntax
       $name=~s/^form\.//;
       $persistent.=<<END;
   <input type='hidden' name='$name' value='$ENV{$key}' />
   END
           }
       } (keys %ENV);
       return $persistent;
   }
 1;  1;
 __END__  __END__

Removed from v.1.51  
changed lines
  Added in v.1.89


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