Diff for /loncom/interface/lonsearchcat.pm between versions 1.175 and 1.186

version 1.175, 2003/05/30 20:54:28 version 1.186, 2003/09/22 00:48:32
Line 82  use Text::Query; Line 82  use Text::Query;
 use GDBM_File;  use GDBM_File;
 use Apache::loncommon();  use Apache::loncommon();
 use Apache::lonmysql();  use Apache::lonmysql();
 use Apache::lonmenu();  use Apache::lonlocal;
   
 # ---------------------------------------- variables used throughout the module  # ---------------------------------------- variables used throughout the module
   
Line 187  sub handler { Line 187  sub handler {
                       # This button is different for the RAT compared to                        # This button is different for the RAT compared to
                       # normal invocation.                        # normal invocation.
     #      #
     $r->content_type('text/html');      &Apache::loncommon::content_type($r,'text/html');
     $r->send_http_header;      $r->send_http_header;
     return OK if $r->header_only;      return OK if $r->header_only;
     ##      ##
Line 208  sub handler { Line 208  sub handler {
     ##     this once, so the pause indicator is deleted      ##     this once, so the pause indicator is deleted
     ##      ##
     if (exists($ENV{'form.pause'})) {      if (exists($ENV{'form.pause'})) {
         sleep(3);          sleep(1);
         delete($ENV{'form.pause'});          delete($ENV{'form.pause'});
     }      }
     ##      ##
     ## Initialize global variables      ## Initialize global variables
     ##      ##
     my $domain  = $r->dir_config('lonDefDomain');      my $domain  = $r->dir_config('lonDefDomain');
     $diropendb= "/home/httpd/perl/tmp/".&Apache::lonnet::escape($domain).      $diropendb= "/home/httpd/perl/tmp/$ENV{'user.domain'}_$ENV{'user.name'}_searchcat.db";
             "\_".&Apache::lonnet::escape($ENV{'user.name'})."_searchcat.db";  
     #      #
     # set the name of the persistent database      # set the name of the persistent database
     #          $ENV{'form.persistent_db_id'} can only have digits in it.      #          $ENV{'form.persistent_db_id'} can only have digits in it.
Line 384  END Line 383  END
             (undef,undef,undef,undef);              (undef,undef,undef,undef);
         my $pretty_string;          my $pretty_string;
         if ($ENV{'form.phase'} eq 'basic_search') {          if ($ENV{'form.phase'} eq 'basic_search') {
             ($query,$pretty_string) = &parse_basic_search($r,$closebutton);              ($query,$pretty_string,$libraries) = 
                   &parse_basic_search($r,$closebutton);
         } else {                      # Advanced search          } else {                      # Advanced search
             ($query,$customquery,$customshow,$libraries,$pretty_string)               ($query,$customquery,$customshow,$libraries,$pretty_string) 
                 = &parse_advanced_search($r,$closebutton);                  = &parse_advanced_search($r,$closebutton);
Line 556  then press SEARCH below. Line 556  then press SEARCH below.
 ENDDOCUMENT  ENDDOCUMENT
     $scrout.=' '.&simpletextfield('basicexp',$ENV{'form.basicexp'},40).      $scrout.=' '.&simpletextfield('basicexp',$ENV{'form.basicexp'},40).
         ' ';          ' ';
     my $checkbox = &simplecheckbox('related',$ENV{'form.related'});      my $relatedcheckbox = &simplecheckbox('related',$ENV{'form.related'});
       my $domain = $r->dir_config('lonDefDomain');
       my $domaincheckbox = &simplecheckbox('domains',$domain);
     $scrout.=<<END;      $scrout.=<<END;
 </td><td><a  </td><td><a
 href="/adm/searchcat?phase=disp_adv&catalogmode=$ENV{'form.catalogmode'}&launch=$ENV{'form.launch'}"  href="/adm/searchcat?phase=disp_adv&catalogmode=$ENV{'form.catalogmode'}&launch=$ENV{'form.launch'}"
 >Advanced Search</a></td></tr>  >Advanced Search</a></td></tr>
 <tr><td>$checkbox use related words</td><td></td></tr>  <tr><td>$relatedcheckbox use related words</td>
       <td>$domaincheckbox only search domain <b>$domain</b></td></tr>
 </table>  </table>
 </p>  </p>
 <p>  <p>
Line 581  per page. Line 584  per page.
 </p>  </p>
 </form>  </form>
 ENDDOCUMENT  ENDDOCUMENT
     if ($ENV{'request.course.id'}) { $scrout.='<hr />'; }      }
 }      if ($ENV{'request.course.id'}) {
 if ($ENV{'request.course.id'}) {          $scrout.=(<<ENDCOURSESEARCH);
     $scrout.=(<<ENDCOURSESEARCH);  <hr />
 <h1>Course Search</h1>      <h1>Course Search</h1>    
 <form method="post" action="/adm/searchcat">  <form method="post" action="/adm/searchcat">
 <input type="hidden" name="phase" value="course_search" />  <input type="hidden" name="phase" value="course_search" />
Line 596  Enter terms or phrases, then press SEARC Line 599  Enter terms or phrases, then press SEARC
 <table>  <table>
 <tr><td>  <tr><td>
 ENDCOURSESEARCH  ENDCOURSESEARCH
     $scrout.='&nbsp;'.&simpletextfield('courseexp',$ENV{'form.courseexp'},40);          $scrout.='&nbsp;'.
     my $crscheckbox = &simplecheckbox('crsfulltext',$ENV{'form.crsfulltext'});              &simpletextfield('courseexp',$ENV{'form.courseexp'},40);
     my $relcheckbox = &simplecheckbox('crsrelated',$ENV{'form.crsrelated'});          my $crscheckbox = 
 $scrout.=(<<ENDENDCOURSE);              &simplecheckbox('crsfulltext',$ENV{'form.crsfulltext'});
           my $relcheckbox = 
               &simplecheckbox('crsrelated',$ENV{'form.crsrelated'});
           $scrout.=(<<ENDENDCOURSE);
 </td></tr>  </td></tr>
 <tr><td>$relcheckbox use related words</td><td></td></tr>  <tr><td>$relcheckbox use related words</td><td></td></tr>
 <tr><td>$crscheckbox fulltext search (time consuming)</td><td></td></tr>  <tr><td>$crscheckbox fulltext search (time consuming)</td><td></td></tr>
Line 607  $scrout.=(<<ENDENDCOURSE); Line 613  $scrout.=(<<ENDENDCOURSE);
 &nbsp;<input type="submit" name="coursesubmit" value='SEARCH' />  &nbsp;<input type="submit" name="coursesubmit" value='SEARCH' />
 </p>  </p>
 ENDENDCOURSE  ENDENDCOURSE
 }      }
     $scrout.=(<<ENDDOCUMENT);      $scrout.=(<<ENDDOCUMENT);
 </body>  </body>
 </html>  </html>
Line 847  sub get_persistent_form_data { Line 853  sub get_persistent_form_data {
     # Loop through the keys, looking for 'form.'      # Loop through the keys, looking for 'form.'
     foreach my $name (keys(%persistent_db)) {      foreach my $name (keys(%persistent_db)) {
         next if ($name !~ /^form./);          next if ($name !~ /^form./);
           # Kludgification begins!
           if ($name eq 'form.domains' && 
               $ENV{'form.searchmode'} eq 'basic' &&
               $ENV{'form.phase'} ne 'disp_basic') {
               next;
           }
           # End kludge (hopefully)
         next if (exists($ENV{$name}));          next if (exists($ENV{$name}));
         my @values = map {           my @values = map { 
             &Apache::lonnet::unescape($_);              &Apache::lonnet::unescape($_);
Line 861  sub get_persistent_form_data { Line 874  sub get_persistent_form_data {
     untie (%persistent_db);      untie (%persistent_db);
     return 1;      return 1;
 }  }
   
 ######################################################################  ######################################################################
 ######################################################################  ######################################################################
   
Line 1019  If $value eq 'on' the box is checked. Line 1033  If $value eq 'on' the box is checked.
 ###############################################  ###############################################
 ###############################################  ###############################################
   
 sub simplecheckbox {  sub simplecheckbox{
     my ($name,$value)=@_;      my ($name,$value,$checked)=@_;
     my $checked='';      $checked="checked" if ($value eq 'on');
     $checked="checked" if $value eq 'on';      return '<input type="checkbox" name="'.$name.'" value="'.$value.'" '.
     return '<input type="checkbox" name="'.$name.'" '. $checked . ' />';          $checked.' />';
 }  }
   
 ###############################################  ###############################################
Line 1216  sub selectbox { Line 1230  sub selectbox {
     my ($title,$name,$default,$anyvalue,$anytag,$functionref,@idlist)=@_;      my ($title,$name,$default,$anyvalue,$anytag,$functionref,@idlist)=@_;
     if (! defined($functionref)) { $functionref = sub { $_[0]}; }      if (! defined($functionref)) { $functionref = sub { $_[0]}; }
     my $selout='';      my $selout='';
       $title=&mt($title);
     if (defined($title)) {      if (defined($title)) {
         my $uctitle=uc($title);          my $uctitle=uc($title);
         $selout="\n".'<p><font color="#800000" face="helvetica">'.          $selout="\n".'<p><font color="#800000" face="helvetica">'.
Line 1417  sub parse_advanced_search { Line 1432  sub parse_advanced_search {
     ## ---------------------------------------------------------------      ## ---------------------------------------------------------------
     ## Deal with restrictions to given domains      ## Deal with restrictions to given domains
     ##       ## 
       my ($libraries_to_query,$pretty_domains_string) = 
           &parse_domain_restrictions();
       $pretty_search_string .= $pretty_domains_string."<br />\n";
       #
       if (@queries) {
    $query=join(" AND ",@queries);
    $query="select * from metadata where $query";
       } elsif ($customquery) {
           $query = '';
       }
       return ($query,$customquery,$customshow,$libraries_to_query,
               $pretty_search_string);
   }
   
   sub parse_domain_restrictions {
     my $libraries_to_query = undef;      my $libraries_to_query = undef;
     # $ENV{'form.domains'} can be either a scalar or an array reference.      # $ENV{'form.domains'} can be either a scalar or an array reference.
     # We need an array.      # We need an array.
     my @allowed_domains = (ref($ENV{'form.domains'}) ? @{$ENV{'form.domains'}}       if (! exists($ENV{'form.domains'})) {
                            :  ($ENV{'form.domains'}) );          return (undef,'');
       }
       my @allowed_domains;
       if (ref($ENV{'form.domains'})) {
           @allowed_domains =  @{$ENV{'form.domains'}};
       } else {
           @allowed_domains = ($ENV{'form.domains'});
       }
     my %domain_hash = ();      my %domain_hash = ();
     my $pretty_domains_string;      my $pretty_domains_string;
     foreach (@allowed_domains) {      foreach (@allowed_domains) {
Line 1444  sub parse_advanced_search { Line 1481  sub parse_advanced_search {
             }              }
         }          }
     }      }
     $pretty_search_string .= $pretty_domains_string."<br />\n";      return ($libraries_to_query,$pretty_domains_string);
     #  
     if (@queries) {  
  $query=join(" AND ",@queries);  
  $query="select * from metadata where $query";  
     } elsif ($customquery) {  
         $query = '';  
     }  
     return ($query,$customquery,$customshow,$libraries_to_query,  
             $pretty_search_string);  
 }  }
   
 ######################################################################  ######################################################################
Line 1481  sub parse_basic_search { Line 1509  sub parse_basic_search {
  $ENV{"form.$_"}=&Apache::lonnet::unescape($ENV{"form.$_"});   $ENV{"form.$_"}=&Apache::lonnet::unescape($ENV{"form.$_"});
  $ENV{"form.$_"}=~s/[^\w\/\s\(\)\=\-\"\']//g;   $ENV{"form.$_"}=~s/[^\w\/\s\(\)\=\-\"\']//g;
     }      }
       my ($libraries_to_query,$pretty_domains_string) = 
           &parse_domain_restrictions();
     # Check to see if enough is filled in      # Check to see if enough is filled in
     unless (&filled($ENV{'form.basicexp'})) {      unless (&filled($ENV{'form.basicexp'})) {
  &output_blank_field_error($r,$closebutton,'phase=disp_basic');   &output_blank_field_error($r,$closebutton,'phase=disp_basic');
Line 1500  sub parse_basic_search { Line 1529  sub parse_basic_search {
     }      }
     # Build SQL query string based on form page      # Build SQL query string based on form page
     my $query='';      my $query='';
     my $concatarg=join(',"    ",',      my $concatarg=join(',',
        ('title', 'author', 'subject', 'notes', 'abstract',         ('title', 'author', 'subject', 'notes', 'abstract',
                         'keywords'));                          'keywords'));
     $concatarg='title' if $ENV{'form.titleonly'};      $concatarg='title' if $ENV{'form.titleonly'};
     $query=&build_SQL_query('concat('.$concatarg.')',$search_string);      $query=&build_SQL_query('concat_ws(" ",'.$concatarg.')',$search_string);
       if (defined($pretty_domains_string) && $pretty_domains_string ne '') {
           $pretty_search_string .= ' '.$pretty_domains_string;
       }
     $pretty_search_string .= "<br />\n";      $pretty_search_string .= "<br />\n";
     return 'select * from metadata where '.$query,$pretty_search_string;      my $final_query = 'SELECT * FROM metadata WHERE '.$query;
   #    &Apache::lonnet::logthis($final_query);
       return ($final_query,$pretty_search_string,
               $libraries_to_query);
 }  }
   
   
Line 1623  sub recursive_SQL_query_build { Line 1658  sub recursive_SQL_query_build {
         my ($key,$value)=($1,$2);          my ($key,$value)=($1,$2);
         my $replacement='';          my $replacement='';
         if ($key eq 'literal') {          if ($key eq 'literal') {
             $replacement="($dkey like \"\%$value\%\")";              $replacement="($dkey LIKE \"\%$value\%\")";
         } elsif ($key eq 'not') {          } elsif (lc($key) eq 'not') {
             $value=~s/like/not like/;              $value=~s/LIKE/NOT LIKE/;
 #          $replacement="($dkey not like $value)";  #          $replacement="($dkey not like $value)";
             $replacement="$value";              $replacement="$value";
         } elsif ($key eq 'and') {          } elsif ($key eq 'and') {
Line 2132  END Line 2167  END
     my $time_remaining = $max_time - (time - $starttime) ;      my $time_remaining = $max_time - (time - $starttime) ;
     my $last_time = $time_remaining;      my $last_time = $time_remaining;
     &update_seconds($r,$time_remaining);      &update_seconds($r,$time_remaining);
       &update_status($r,'contacting '.$Servers_to_contact[0]);
     while (($time_remaining > 0) &&      while (($time_remaining > 0) &&
            ((@Servers_to_contact) || keys(%Server_status))) {             ((@Servers_to_contact) || keys(%Server_status))) {
         # Send out a search request if it needs to be done.          # Send out a search request if it needs to be done.
         if (@Servers_to_contact) {          if (@Servers_to_contact) {
             # Contact one server              # Contact one server
             my $server = shift(@Servers_to_contact);              my $server = shift(@Servers_to_contact);
               &update_status($r,'contacting '.$server);
             my $reply=&Apache::lonnet::metadata_query($query,$customquery,              my $reply=&Apache::lonnet::metadata_query($query,$customquery,
                                                       $customshow,[$server]);                                                        $customshow,[$server]);
             ($server) = keys(%$reply);              ($server) = keys(%$reply);
             $Server_status{$server} = $reply->{$server};              $Server_status{$server} = $reply->{$server};
             &update_status($r,'contacting '.$server);  
         } else {          } else {
             # wait a sec. to give time for files to be written              # wait a sec. to give time for files to be written
             # This sleep statement is here instead of outside the else               # This sleep statement is here instead of outside the else 
             # block because we do not want to pause if we have servers              # block because we do not want to pause if we have servers
             # left to contact.                # left to contact.  
               if (scalar (keys(%Server_status))) {
                   &update_status($r,
                                  'waiting on '.(join(' ',keys(%Server_status))));
               }
             sleep(1)              sleep(1)
         }          }
         #          #
         if (scalar (keys(%Server_status))) {  
             &update_status($r,'waiting on '.(join(' ',keys(%Server_status))));  
         }  
         #          #
         # Loop through the servers we have contacted but do not          # Loop through the servers we have contacted but do not
         # have results from yet, looking for results.          # have results from yet, looking for results.
Line 2370  sub display_results { Line 2407  sub display_results {
          ."</center>\n"           ."</center>\n"
          );           );
     if ($total_results == 0) {      if ($total_results == 0) {
         $r->print("There are currently no results.\n".          $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="1">'.
                     '<h3>There are currently no results.</h3>'.
                   "</form></body></html>");                    "</form></body></html>");
         return;          return;
     } else {      } else {
Line 2705  SCRIPT Line 2743  SCRIPT
     $result.=<<SCRIPT if $ENV{'form.catalogmode'} eq 'groupsearch';      $result.=<<SCRIPT if $ENV{'form.catalogmode'} eq 'groupsearch';
 <script type="text/javascript">  <script type="text/javascript">
     function queue(checkbox_num,val) {      function queue(checkbox_num,val) {
         if (document.forms.results.returnvalues[checkbox_num].checked) {          if (document.forms.results.returnvalues.length != "undefined" &&
             parent.statusframe.document.forms.statusform.elements.Queue.value +='1a'+val+'b';              typeof(document.forms.results.returnvalues.length) == "number") {
               if (document.forms.results.returnvalues[checkbox_num].checked) {
                   parent.statusframe.document.forms.statusform.elements.Queue.value +='1a'+val+'b';
               } else {
                   parent.statusframe.document.forms.statusform.elements.Queue.value +='0a'+val+'b';
               }
         } else {          } else {
             parent.statusframe.document.forms.statusform.elements.Queue.value +='0a'+val+'b';              if (document.forms.results.returnvalues.checked) {
                   parent.statusframe.document.forms.statusform.elements.Queue.value +='1a'+val+'b';
               } else {
                   parent.statusframe.document.forms.statusform.elements.Queue.value +='0a'+val+'b';
               }
         }          }
     }      }
     function select_group() {      function select_group() {
Line 2755  sub print_frames_interface { Line 2802  sub print_frames_interface {
         "&persistent_db_id=".$ENV{'form.persistent_db_id'};          "&persistent_db_id=".$ENV{'form.persistent_db_id'};
     my $run_search_link = $basic_link."&phase=run_search";      my $run_search_link = $basic_link."&phase=run_search";
     my $results_link = &results_link();      my $results_link = &results_link();
     my $loadevents=&Apache::lonmenu::loadevents();  
     my $unloadevents=&Apache::lonmenu::unloadevents();  
     my $addscript=&Apache::lonmenu::registerurl();  
     my $result = <<"ENDFRAMES";      my $result = <<"ENDFRAMES";
 <html>  <html>
 <head>  <head>
Line 2765  sub print_frames_interface { Line 2809  sub print_frames_interface {
 var targetwin = opener;  var targetwin = opener;
 var queue = '';  var queue = '';
 </script>  </script>
 $addscript  
 <title>LON-CAPA Digital Library Search Results</title>  <title>LON-CAPA Digital Library Search Results</title>
 </head>  </head>
 <frameset rows="150,*" onLoad="$loadevents" onUnload="$unloadevents">  <frameset rows="150,*">
     <frame name="statusframe"  src="$run_search_link">      <frame name="statusframe"  src="$run_search_link">
     <frame name="resultsframe" src="$results_link">      <frame name="resultsframe" src="$results_link">
 </frameset>  </frameset>

Removed from v.1.175  
changed lines
  Added in v.1.186


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