Diff for /loncom/interface/lonsearchcat.pm between versions 1.92 and 1.97

version 1.92, 2001/04/02 16:57:38 version 1.97, 2001/08/16 02:20:01
Line 1 Line 1
 # The LearningOnline Network  # The LearningOnline Network
 # Search Catalog  # Search Catalog
 #  #
   # YEAR=2001
 # 03/08/2001 Scott Harrison  # 03/08/2001 Scott Harrison
 # Scott Harrison: 03/12/2001, 03/13/2001, 03/14/2001, 03/15/2001, 03/19/2001  # Scott Harrison: 03/12/2001, 03/13/2001, 03/14/2001, 03/15/2001, 03/19/2001
 # Scott Harrison: 03/20/2001, 03/21/2001, 03/22/2001, 03/26/2001, 03/27/2001  # Scott Harrison: 03/20/2001, 03/21/2001, 03/22/2001, 03/26/2001, 03/27/2001
 # Scott Harrison: 04/02/2001  # Scott Harrison: 04/02/2001, 08/15/2001
 #  #
 # Functions  # Functions
 #  #
Line 182  END Line 183  END
     $scrout.=&searchphrasefield('Limit by URL','url',      $scrout.=&searchphrasefield('Limit by URL','url',
  $ENV{'form.url'});   $ENV{'form.url'});
   
     $scrout.=&searchphrasefield('Limit by version','version',  #    $scrout.=&searchphrasefield('Limit by version','version',
  $ENV{'form.version'});  # $ENV{'form.version'});
   
     $scrout.=&searchphrasefield('Limit by notes','notes',      $scrout.=&searchphrasefield('Limit by notes','notes',
  $ENV{'form.notes'});   $ENV{'form.notes'});
Line 301  ENDDOCUMENT Line 302  ENDDOCUMENT
     $r->print(' ');      $r->print(' ');
     $r->print(&simplecheckbox('titleonly',$ENV{'form.titleonly'}));      $r->print(&simplecheckbox('titleonly',$ENV{'form.titleonly'}));
     $r->print('<font color="#800000">Title only</font> ');      $r->print('<font color="#800000">Title only</font> ');
     $r->print(&simplecheckbox('allversions',$ENV{'form.allversions'}));  #    $r->print(&simplecheckbox('allversions',$ENV{'form.allversions'}));
   # <font color="#800000">Search historic archives</font>
     $r->print(<<ENDDOCUMENT);      $r->print(<<ENDDOCUMENT);
 <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' />
Line 658  sub basicsearch { Line 659  sub basicsearch {
     my $query='';      my $query='';
     my $concatarg=join(',"    ",',      my $concatarg=join(',"    ",',
        ('title', 'author', 'subject', 'notes', 'abstract'));         ('title', 'author', 'subject', 'notes', 'abstract'));
     $query='select * from metadata where concat(' . $concatarg . ') like %' .      $concatarg='title' if $ENV{'form.titleonly'};
    $ENV{'form.basicexp'} . '%';  
       $query=&build_SQL_query('concat('.$concatarg.')',$ENV{'form.'.'basicexp'});
   
   
     # Get reply (either a hash reference to filehandles or bad connection)      # Get reply (either a hash reference to filehandles or bad connection)
     my $reply=&Apache::lonnet::metadata_query($query);      my $reply=&Apache::lonnet::metadata_query('select * from metadata where '.$query);
   
     # Output search results      # Output search results
     &output_results('Basic',$r,$envhash,$query,$reply);      &output_results('Basic',$r,$envhash,$query,$reply);
Line 711  sub output_results { Line 714  sub output_results {
     my %rhash=%{$replyref};      my %rhash=%{$replyref};
     my $compiledresult='';      my $compiledresult='';
     my $timeremain=30;      my $timeremain=30;
       my $resultflag=0;
       my $tflag=1;
   
       # make query information persistent to allow for subsequent revision
       my $persistent=&make_persistent();
   
       # output beginning of search page
  $r->print(<<BEGINNING);   $r->print(<<BEGINNING);
 <html>  <html>
 <head>  <head>
Line 721  BEGINNING Line 731  BEGINNING
     function select_data(title,url) {      function select_data(title,url) {
  changeTitle(title);   changeTitle(title);
  changeURL(url);   changeURL(url);
    self.close();
     }      }
     function changeTitle(val) {      function changeTitle(val) {
  if (opener.inf.document.forms.resinfo.elements.t) {   if (opener.inf.document.forms.resinfo.elements.t) {
Line 740  SCRIPT Line 751  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>
 CATALOGBEGIN  CATALOGBEGIN
           $r->print(<<RESULTS);
   <form method="post" action="/adm/searchcat">
   <input type='button' value='Revise search request'
   onClick='this.form.submit();'>
   $closebutton
   $persistent
   <hr>
   <h3>Search Query</h3>
   RESULTS
       if ($mode eq 'Basic') {
    $r->print(<<RESULTS);
   <p>
   <b>Basic search:</b> $ENV{'form.basicexp'}
   </p>
   RESULTS
       }
       elsif ($mode eq 'Advanced') {
    $r->print(<<RESULTS);
   <p>
   <b>Advanced search</b>
   $query
   </p>
   RESULTS
       }
       $r->print('<h3>Search Results</h3>');
     $r->rflush();      $r->rflush();
     $r->print(<<ENDPOP);      $r->print(<<ENDPOP);
 <script>  <script>
Line 759  ENDPOP Line 795  ENDPOP
   
     my $servernum=(keys %rhash)+0;      my $servernum=(keys %rhash)+0;
     $r->print('<script>popwin.document.popremain.space.value="'.      $r->print('<script>popwin.document.popremain.space.value="'.
       $servernum.', 0%, count=0/1";</script>');        $servernum.', 0%, count=0/'.$servernum.'";</script>');
     $r->rflush();       $r->rflush(); 
       my $servercount=0;
     foreach my $rkey (keys %rhash) {      foreach my $rkey (keys %rhash) {
    $servercount++;
    $tflag=1;
    $compiledresult='';
    my $hostname=$rkey;
  $r->print('<script>popwin.document.popremain.status.value="'.   $r->print('<script>popwin.document.popremain.status.value="'.
   $rkey.', trying contact";</script>');    $rkey.', trying contact";</script>');
  $r->rflush();   $r->rflush();
Line 769  ENDPOP Line 810  ENDPOP
  my @results;   my @results;
   
  my $replyfile='';   my $replyfile='';
  $reply=~/^([\.\w]+)$/; # must do since 'use strict' checks for tainting  
  $replyfile=$r->dir_config('lonDaemons').'/tmp/'.$1;   if ($reply eq 'con_lost') {
  $reply=~/(.*?)\_/;      my $percent=sprintf('%3.0f',($servercount/$servernum*100));
  my $hostname=$1;      $r->print('<script>popwin.document.popremain.space.value="'.
  {        $servernum.', '.$percent.'%, count='.$servercount.
     while (1) {        '/'.$servernum.'";</script>');
  $r->print('<script>popwin.document.popremain.status.value="'.   }
   $rkey.', contacted";</script>') if -e $replyfile;   else {
  $r->rflush();      $reply=~/^([\.\w]+)$/; # must do since 'use strict' checks for tainting
  last if -e "$replyfile.end";      $replyfile=$r->dir_config('lonDaemons').'/tmp/'.$1;
  last unless $timeremain;      $reply=~/(.*?)\_/;
  sleep 1;      {
  $timeremain--;   while (1) {
  $r->print('<script>popwin.document.popremain.timeout.value="'.      if (-e $replyfile && $tflag) {
   $timeremain.'";</script>');   $r->print('<script>popwin.document.popremain.status.'.
  $r->rflush();    'value="'.$rkey.', transmitting";</script>');
    $r->rflush();
    $tflag=0;
        }
       last if -e "$replyfile.end";
       last unless $timeremain;
       sleep 1;
       $timeremain--;
       $r->print('<script>popwin.document.popremain.timeout.value="'.
         $timeremain.'";</script>');
       $r->rflush();
    }
    # 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('ERROR: 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 $fh=Apache::File->new($replyfile) or  
  ($r->print('file cannot be opened') and return OK);  
     @results=<$fh>;  
  }   }
   
  my $customshow='';   my $customshow='';
  my $extrashow='';   my $extrashow='';
  my @customfields;   my @customfields;
Line 800  ENDPOP Line 851  ENDPOP
     $customshow=$ENV{'form.customshow'};      $customshow=$ENV{'form.customshow'};
     $customshow=~s/[^\w\s]//g;      $customshow=~s/[^\w\s]//g;
     my @fields=map {"<font color=\"#008000\">$_:</font><!-- $_ -->"}       my @fields=map {"<font color=\"#008000\">$_:</font><!-- $_ -->"} 
                    split(/\s+/,$customshow);      split(/\s+/,$customshow);
     @customfields=split(/\s+/,$customshow);      @customfields=split(/\s+/,$customshow);
     if ($customshow) {      if ($customshow) {
  $extrashow="<ul><li>".join("</li><li>",@fields)."</li></ul>\n";   $extrashow="<ul><li>".join("</li><li>",@fields)."</li></ul>\n";
Line 822  ENDPOP Line 873  ENDPOP
     chomp $result;      chomp $result;
     next unless $result;      next unless $result;
     my @fields=map      my @fields=map
                    {&Apache::lonnet::unescape($_)}      {&Apache::lonnet::unescape($_)}
                    (split(/\,/,$result));      (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)=@fields;   $creationdate,$lastrevisiondate,$owner,$copyright)=@fields;
Line 835  ENDPOP Line 886  ENDPOP
  foreach my $field (@customfields) {   foreach my $field (@customfields) {
     my $value='';      my $value='';
     if ($customhash{$url}=~/\<${field}[^\>]*\>(.*?)\<\/${field}[^\>]*\>/s) {      if ($customhash{$url}=~/\<${field}[^\>]*\>(.*?)\<\/${field}[^\>]*\>/s) {
          $value=$1;          $value=$1;
     }      }
     $extrashow2=~s/\<\!\-\- $field \-\-\>/ $value/g;              $extrashow2=~s/\<\!\-\- $field \-\-\>/ $value/g;
  }          }
     }              }
   
     $compiledresult.=<<END if $compiledresult;              $compiledresult.=<<END if $compiledresult;
 <hr align='left' width='200' noshade />  <hr align='left' width='200' noshade />
 END  END
     $compiledresult.=<<END;              $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>
Line 855  onClick="javascript:select_data('$title' Line 906  onClick="javascript:select_data('$title'
 END  END
             my $httphost=$ENV{'HTTP_HOST'};              my $httphost=$ENV{'HTTP_HOST'};
   
     my $viewselect;              my $viewselect;
     if ($mode eq 'Basic') {              if ($mode eq 'Basic') {
  $viewselect=$ENV{'form.basicviewselect'};   $viewselect=$ENV{'form.basicviewselect'};
     }      }
     elsif ($mode eq 'Advanced') {              elsif ($mode eq 'Advanced') {
  $viewselect=$ENV{'form.advancedviewselect'};          $viewselect=$ENV{'form.advancedviewselect'};
     }              }
   
             if ($viewselect eq 'Detailed Citation View') {              if ($viewselect eq 'Detailed Citation View') {
  $compiledresult.=&detailed_citation_view(@fields,          $compiledresult.=&detailed_citation_view(@fields,
  $hostname,$httphost,   $hostname,$httphost,
  $extrashow2);   $extrashow2);
     }      }
             elsif ($viewselect eq 'Summary View') {              elsif ($viewselect eq 'Summary View') {
  $compiledresult.=&summary_view(@fields,$hostname,$httphost,   $compiledresult.=&summary_view(@fields,$hostname,$httphost,
        $extrashow2);         $extrashow2);
     }      }
             elsif ($viewselect eq 'Fielded Format') {              elsif ($viewselect eq 'Fielded Format') {
  $compiledresult.=&fielded_format_view(@fields,$hostname,   $compiledresult.=&fielded_format_view(@fields,$hostname,
       $httphost,$extrashow2);        $httphost,$extrashow2);
     }      }
             elsif ($viewselect eq 'XML/SGML') {              elsif ($viewselect eq 'XML/SGML') {
  $compiledresult.=&xml_sgml_view(@fields,$hostname,$httphost,   $compiledresult.=&xml_sgml_view(@fields,$hostname,$httphost,
  $extrashow2);   $extrashow2);
     }      }
       
         }          }
   
  unless ($compiledresult) {   if ($compiledresult) {
     $compiledresult="There were no results that matched your query";      $resultflag=1;
  }   }
   
  # make query information persistent to allow for subsequent revision  
  my $persistent=&make_persistent();  
   
         $r->print(<<RESULTS);  
 <form method="post" action="/adm/searchcat">  
 $customdata  
 <input type='button' value='Revise search request'  
 onClick='this.form.submit();'>  
 $closebutton  
 $persistent  
 <hr>  
 <h3>Search Query</h3>  
 RESULTS  
     if ($mode eq 'Basic') {  
  $r->print(<<RESULTS);   $r->print(<<RESULTS);
 <p>  $compiledresult
 <b>Basic search:</b> $ENV{'form.basicexp'}  
 </p>  
 RESULTS  RESULTS
           my $percent=sprintf('%3.0f',($servercount/$servernum*100));
    $r->print('<script>popwin.document.popremain.space.value="'.
             $servernum.', '.$percent.'%, count='.$servercount.
     '/'.$servernum.'";</script>');
     }      }
     elsif ($mode eq 'Advanced') {      unless ($resultflag) {
  $r->print(<<RESULTS);          $r->print("\nThere were no results that matched your query\n");
 <p>  
 <b>Advanced search</b>  
 $query  
 </p>  
 RESULTS  
     }      }
  $r->print(<<RESULTS);      $r->print('<script>popwin.close()</script>'); $r->rflush(); 
 <h3>Search Results</h3>      $r->print(<<RESULTS);
 $compiledresult  
 </body>  </body>
 </html>  </html>
 RESULTS  RESULTS
     }  
     $r->print('<script>popwin.close()</script>'); $r->rflush();   
 }  }
   
 # ------------------------------------------------------------- build_SQL_query  # ------------------------------------------------------------- build_SQL_query
Line 964  sub recursive_SQL_query_build { Line 995  sub recursive_SQL_query_build {
  if ($key eq 'literal') {   if ($key eq 'literal') {
     $replacement="($dkey like \"\%$value\%\")";      $replacement="($dkey like \"\%$value\%\")";
  }   }
    elsif ($key eq 'not') {
       $value=~s/like/not like/;
   #    $replacement="($dkey not like $value)";
       $replacement="$value";
    }
  elsif ($key eq 'and') {   elsif ($key eq 'and') {
     $value=~/(.*[\"|\)]) ([|\(|\^].*)/;      $value=~/(.*[\"|\)]) ([|\(|\^].*)/;
     $replacement="($1 AND $2)";      $replacement="($1 AND $2)";

Removed from v.1.92  
changed lines
  Added in v.1.97


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