Diff for /loncom/interface/lonsearchcat.pm between versions 1.151 and 1.152

version 1.151, 2002/08/04 18:28:01 version 1.152, 2002/08/07 12:37:16
Line 206  sub handler { Line 206  sub handler {
             '_'.&Apache::lonnet::escape($ENV{'user.name'}).              '_'.&Apache::lonnet::escape($ENV{'user.name'}).
                 '_'.$ENV{'form.persistent_db_id'}.'_persistent_search.db';                  '_'.$ENV{'form.persistent_db_id'}.'_persistent_search.db';
     ##      ##
     if (! &get_persistent_form_data($r,$persistent_db_file)) {      if (! &get_persistent_form_data($persistent_db_file)) {
         if ($ENV{'form.phase'} =~ /(run_search|results)/) {          if ($ENV{'form.phase'} =~ /(run_search|results)/) {
             &Apache::lonnet::logthis("lonsearchcat:Unable to recover data ".              &Apache::lonnet::logthis("lonsearchcat:Unable to recover data ".
                                      "from $persistent_db_file");                                       "from $persistent_db_file");
Line 360  END Line 360  END
                 = &parse_advanced_search($r,$closebutton);                  = &parse_advanced_search($r,$closebutton);
             return OK if (! defined($query));              return OK if (! defined($query));
         }          }
         &make_persistent($r,          &make_persistent({ query => $query,
                          { query => $query,  
                            customquery => $customquery,                             customquery => $customquery,
                            customshow => $customshow,                             customshow => $customshow,
                            libraries => $libraries,                             libraries => $libraries,
Line 620  LASTREVISIONDATEEND Line 619  LASTREVISIONDATEEND
  (&Apache::loncommon::copyrightids),   (&Apache::loncommon::copyrightids),
  );   );
 # ------------------------------------------- Compute customized metadata field  # ------------------------------------------- Compute customized metadata field
     $scrout.=<<CUSTOMMETADATA;  #    $scrout.=<<CUSTOMMETADATA;
 <p>  #<p>
 <font color="#800000" face="helvetica"><b>LIMIT BY SPECIAL METADATA FIELDS:</b>  #<font color="#800000" face="helvetica"><b>LIMIT BY SPECIAL METADATA FIELDS:</b>
 </font>  #</font>
 For resource-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 NOT.<br />  #<i>key</i>=<i>value</i> separated by operators such as AND, OR or NOT.<br />
 <b>Example:</b> grandmother=75 OR grandfather=85  #<b>Example:</b> grandmother=75 OR grandfather=85
 <br />  #<br />
 CUSTOMMETADATA  #CUSTOMMETADATA
     $scrout.=&simpletextfield('custommetadata',$ENV{'form.custommetadata'});  #    $scrout.=&simpletextfield('custommetadata',$ENV{'form.custommetadata'});
     $scrout.=<<CUSTOMSHOW;  #    $scrout.=<<CUSTOMSHOW;
 <p>  #<p>
 <font color="#800000" face="helvetica"><b>SHOW SPECIAL METADATA FIELDS:</b>  #<font color="#800000" face="helvetica"><b>SHOW SPECIAL METADATA FIELDS:</b>
 </font>  #</font>
 Enter in a space-separated list of special metadata fields to show  #Enter in a space-separated list of special metadata fields to show
 in a fielded listing for each record result.  #in a fielded listing for each record result.
 <br />  #<br />
 CUSTOMSHOW  #CUSTOMSHOW
     $scrout.=&simpletextfield('customshow',$ENV{'form.customshow'});  #    $scrout.=&simpletextfield('customshow',$ENV{'form.customshow'});
     $scrout.=<<ENDDOCUMENT;      $scrout.=<<ENDDOCUMENT;
 $advanced_buttons  $advanced_buttons
 </form>  </form>
Line 671  to them. Line 670  to them.
 ######################################################################  ######################################################################
 ######################################################################  ######################################################################
 sub get_persistent_form_data {  sub get_persistent_form_data {
     my $r = shift;  
     my $filename = shift;      my $filename = shift;
     return 0 if (! -e $filename);      return 0 if (! -e $filename);
     return undef if (! tie(%persistent_db,'GDBM_File',$filename,      return undef if (! tie(%persistent_db,'GDBM_File',$filename,
Line 683  sub get_persistent_form_data { Line 681  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./);
           next if (exists($ENV{$name}));
         my @values = map {           my @values = map { 
             &Apache::lonnet::unescape($_);              &Apache::lonnet::unescape($_);
         } split(',',$persistent_db{$name});          } split(',',$persistent_db{$name});
         next if (@values <1);          next if (@values <1);
         if (exists($ENV{$name})) {          if ($arrays_allowed{$name}) {
             if (ref($ENV{$name}) eq 'ARRAY') {              $ENV{$name} = [@values];
                 # If it is an array, tack @values on the end of it.  
                 $ENV{$name} = [@$ENV{$name},@values];  
             } elsif (! ref($ENV{$name}) && $arrays_allowed{$name}) {  
                 # if arrays are allowed, turn it into one and add @values  
                 $ENV{$name} = [$ENV{$name},@values];  
             } # otherwise, assume the value in $ENV{$name} is better than ours.  
         } else {          } else {
             if ($arrays_allowed{$name}) {              $ENV{$name} = $values[0] if ($values[0]);
                 $ENV{$name} = [@values];  
             } else {  
                 $ENV{$name} = $values[0] if ($values[0]);  
             }  
         }          }
     }      }
     untie (%persistent_db);      untie (%persistent_db);
Line 741  sub get_persistent_data { Line 730  sub get_persistent_data {
         my @values = map {           my @values = map { 
             &Apache::lonnet::unescape($_);              &Apache::lonnet::unescape($_);
         } split(',',$persistent_db{$name});          } split(',',$persistent_db{$name});
         if (@values == 1) {          if (@values <= 1) {
             push @Values,$values[0];              push @Values,$values[0];
         } else {          } else {
             push @Values,\@values;              push @Values,\@values;
Line 769  elements escaped and concatenated in a c Line 758  elements escaped and concatenated in a c
 ######################################################################  ######################################################################
 ######################################################################  ######################################################################
 sub make_persistent {  sub make_persistent {
     my $r = shift;  
     my %save = %{shift()};      my %save = %{shift()};
     my $filename = shift;      my $filename = shift;
     return undef if (! tie(%persistent_db,'GDBM_File',      return undef if (! tie(%persistent_db,'GDBM_File',
                            $filename,&GDBM_WRCREAT(),0640));                             $filename,&GDBM_WRCREAT(),0640));
     foreach my $name (keys(%save)) {      foreach my $name (keys(%save)) {
         next if (! exists($save{$name}));  
         next if (! defined($save{$name}) || $save{$name} eq '');  
         my @values = (ref($save{$name}) ? @{$save{$name}} : ($save{$name}));          my @values = (ref($save{$name}) ? @{$save{$name}} : ($save{$name}));
         # We handle array references, but not recursively.          # We handle array references, but not recursively.
         my $store = join(',', map { &Apache::lonnet::escape($_); } @values );          my $store = join(',', map { &Apache::lonnet::escape($_); } @values );
Line 811  sub make_form_data_persistent { Line 797  sub make_form_data_persistent {
         next if (!/^form/ || /submit/);          next if (!/^form/ || /submit/);
         $save{$_} = $ENV{$_};          $save{$_} = $ENV{$_};
     }      }
     return &make_persistent($r,\%save,$filename);      return &make_persistent(\%save,$filename);
 }  }
   
 ######################################################################  ######################################################################
Line 1230  sub parse_advanced_search { Line 1216  sub parse_advanced_search {
     }      }
     # Process form information for custom metadata querying      # Process form information for custom metadata querying
     my $customquery=undef;      my $customquery=undef;
     if ($ENV{'form.custommetadata'}) {  #    if ($ENV{'form.custommetadata'}) {
         $pretty_search_string .=$font."Custom Metadata Search</font>: <b>".  #        $pretty_search_string .=$font."Custom Metadata Search</font>: <b>".
             $ENV{'form.custommetadata'}."</b><br />\n";  #            $ENV{'form.custommetadata'}."</b><br />\n";
  $customquery=&build_custommetadata_query('custommetadata',  # $customquery=&build_custommetadata_query('custommetadata',
       $ENV{'form.custommetadata'});  #      $ENV{'form.custommetadata'});
     }  #    }
     my $customshow=undef;      my $customshow=undef;
     if ($ENV{'form.customshow'}) {  #    if ($ENV{'form.customshow'}) {
         $pretty_search_string .=$font."Custom Metadata Display</font>: <b>".  #        $pretty_search_string .=$font."Custom Metadata Display</font>: <b>".
             $ENV{'form.customshow'}."</b><br />\n";  #            $ENV{'form.customshow'}."</b><br />\n";
  $customshow=$ENV{'form.customshow'};  # $customshow=$ENV{'form.customshow'};
  $customshow=~s/[^\w\s]//g;  # $customshow=~s/[^\w\s]//g;
  my @fields=split(/\s+/,$customshow);  # my @fields=split(/\s+/,$customshow);
  $customshow=join(" ",@fields);  # $customshow=join(" ",@fields);
     }  #    }
     ## ---------------------------------------------------------------      ## ---------------------------------------------------------------
     ## Deal with restrictions to given domains      ## Deal with restrictions to given domains
     ##       ## 
Line 1259  sub parse_advanced_search { Line 1245  sub parse_advanced_search {
         $domain_hash{$_}++;          $domain_hash{$_}++;
     }      }
     if ($domain_hash{'any'}) {      if ($domain_hash{'any'}) {
         $pretty_domains_string = "Searching all domains.";          $pretty_domains_string = "In all LON-CAPA domains.";
     } else {      } else {
         if (@allowed_domains > 1) {          if (@allowed_domains > 1) {
             $pretty_domains_string = "Searching domains:";              $pretty_domains_string = "In LON-CAPA domains:";
         } else {          } else {
             $pretty_domains_string = "Searching domain ";              $pretty_domains_string = "In LON-CAPA domain ";
         }          }
         foreach (sort @allowed_domains) {          foreach (sort @allowed_domains) {
             $pretty_domains_string .= "<b>$_</b> ";              $pretty_domains_string .= "<b>".$_."</b> ";
         }          }
         foreach (keys(%Apache::lonnet::libserv)) {          foreach (keys(%Apache::lonnet::libserv)) {
             if (exists($domain_hash{$Apache::lonnet::hostdom{$_}})) {              if (exists($domain_hash{$Apache::lonnet::hostdom{$_}})) {
Line 1909  END Line 1895  END
     # Check to see if $pretty_string has more than one carriage return.      # Check to see if $pretty_string has more than one carriage return.
     # Assume \n s are following <br /> s and truncate the value.      # Assume \n s are following <br /> s and truncate the value.
     # (there is probably a better way)...      # (there is probably a better way)...
     my @Lines = split /\n/,$pretty_string;      my @Lines = split /<br \/>/,$pretty_string;
     if (@Lines > 1) {      if (@Lines > 2) {
         $pretty_string = join /\n/,(@Lines[0..1],'....<br />');          $pretty_string = join '<br \>',(@Lines[0..2],'....<br />');
     }      }
     $r->print("Search: ".$pretty_string);      $r->print("Search: ".$pretty_string);
     $r->rflush();      $r->rflush();
Line 1920  END Line 1906  END
     #      #
     my @Servers_to_contact;      my @Servers_to_contact;
     if (defined($serverlist)) {      if (defined($serverlist)) {
         @Servers_to_contact = @$serverlist;          if (ref($serverlist) eq 'ARRAY') {
               @Servers_to_contact = @$serverlist;
           } else {
               @Servers_to_contact = ($serverlist);
           }
     } else {      } else {
         @Servers_to_contact = sort(keys(%Apache::lonnet::libserv));          @Servers_to_contact = sort(keys(%Apache::lonnet::libserv));
     }      }

Removed from v.1.151  
changed lines
  Added in v.1.152


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