Diff for /loncom/interface/lonsearchcat.pm between versions 1.166 and 1.167

version 1.166, 2003/02/10 21:25:43 version 1.167, 2003/03/08 01:43:12
Line 74  package Apache::lonsearchcat; Line 74  package Apache::lonsearchcat;
   
 # ------------------------------------------------- modules used by this module  # ------------------------------------------------- modules used by this module
 use strict;  use strict;
 use Apache::Constants qw(:common);  use Apache::Constants qw(:common :http);
 use Apache::lonnet();  use Apache::lonnet();
 use Apache::File();  use Apache::File();
 use CGI qw(:standard);  use CGI qw(:standard);
Line 142  my %persistent_db; Line 142  my %persistent_db;
 my $hidden_fields;  my $hidden_fields;
 my $bodytag;  my $bodytag;
   
   my %alreadyseen;
   my $hashtied;
   my %hash;
    
 ######################################################################  ######################################################################
 ######################################################################  ######################################################################
   
Line 338  END Line 342  END
             &run_search($r,$query,$customquery,$customshow,              &run_search($r,$query,$customquery,$customshow,
                         $libraries,$pretty_string);                          $libraries,$pretty_string);
         }          }
       } elsif ($ENV{'form.phase'} eq 'course_search') {
           &course_search($r);
     } elsif(($ENV{'form.phase'} eq 'basic_search') ||      } elsif(($ENV{'form.phase'} eq 'basic_search') ||
             ($ENV{'form.phase'} eq 'adv_search')) {              ($ENV{'form.phase'} eq 'adv_search')) {
         $ENV{'form.searchmode'} = 'basic';          $ENV{'form.searchmode'} = 'basic';
Line 396  END Line 402  END
 ######################################################################  ######################################################################
 ######################################################################  ######################################################################
   
   sub course_search {
       my $r=shift;
       my $bodytag=&Apache::loncommon::bodytag('Course Search');
       my $pretty_search_string = '<b>'.$ENV{'form.courseexp'}.'</b>';
       my $search_string = $ENV{'form.courseexp'};
       my @New_Words;
       if ($ENV{'form.crsrelated'}) {
           ($search_string,@New_Words) = &related_version($ENV{'form.courseexp'});
           if (@New_Words) {
               $pretty_search_string .= " with related words: <b>@New_Words</b>.";
           } else {
               $pretty_search_string .= " with no related words.";
           }
       }
       my $fulltext=$ENV{'form.crsfulltext'};
       my @allwords=($search_string,@New_Words);
       $r->print('<html><head><title>LON-CAPA Course Search</title></head>'.
         $bodytag.$pretty_search_string);
       $r->rflush();
   # ======================================================= Go through the course
      $hashtied=0;
      undef %alreadyseen;
      %alreadyseen=();
      &tiehash();
      foreach (keys %hash) {
          if (($_=~/^src\_(.+)$/) && (!$alreadyseen{$hash{$_}})) {
              &checkonthis($r,$hash{$_},0,$hash{'title_'.$1},@allwords,$fulltext);
          }
      }
      &untiehash();
   # =================================================== Done going through course
       $r->print('</body></html>');
   }
   
   # ---------------------------------------------------------------- tie the hash
   
   sub tiehash {
       $hashtied=0;
       if ($ENV{'request.course.fn'}) {
           if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
               &GDBM_READER(),0640)) {
                   $hashtied=1;
           }
       }    
   }
   
   sub untiehash {
       if ($hashtied) { untie %hash; }
       $hashtied=0;
   }
   
   # =============================== This pulls up a resource and its dependencies
   
   sub checkonthis {
       my ($r,$url,$level,$title,@allwords,$fulltext)=@_;
       $alreadyseen{$url}=1;
       $r->rflush();
       my $result=&Apache::lonnet::metadata($url,'title').' '.
                  &Apache::lonnet::metadata($url,'subject').' '.
                  &Apache::lonnet::metadata($url,'abstract').' '.
                  &Apache::lonnet::metadata($url,'keywords');
       if (($url) && ($fulltext)) {
    $result.=&Apache::lonnet::ssibody($url);
       }
       $result=~s/\s+/ /gs;
       my $applies=0;
       foreach (@allwords) {
           if ($_=~/\w/) {
      if ($result=~/$_/si) {
         $applies++;
              }
          }
       }
   # Does this resource apply?
       if ($applies) {
          $r->print('<br />');
          for (my $i=0;$i<=$level*5;$i++) {
              $r->print('&nbsp;');
          }
          $r->print('<a href="'.$url.'" target="cat">'.
    ($title?$title:$url).'</a>');
          $r->rflush();
       }
   # Check also the dependencies of this one
       my $dependencies=
                   &Apache::lonnet::metadata($url,'dependencies');
       foreach (split(/\,/,$dependencies)) {
          if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {
             &checkonthis($r,$_,$level+1,'',@allwords,$fulltext);
          }
       }
   }
   
   ######################################################################
   ######################################################################
   
 =pod   =pod 
   
 =item &print_basic_search_form()   =item &print_basic_search_form() 
Line 409  Returns a scalar which holds html for th Line 511  Returns a scalar which holds html for th
   
 sub print_basic_search_form{  sub print_basic_search_form{
     my ($r,$closebutton) = @_;      my ($r,$closebutton) = @_;
     my $bodytag=&Apache::loncommon::bodytag('Catalog Search');      my $bodytag=&Apache::loncommon::bodytag('Search');
     my $scrout=<<"ENDDOCUMENT";      my $scrout=<<"ENDDOCUMENT";
 <html>  <html>
 <head>  <head>
Line 423  sub print_basic_search_form{ Line 525  sub print_basic_search_form{
 </script>  </script>
 </head>  </head>
 $bodytag  $bodytag
   ENDDOCUMENT
   if (&Apache::lonnet::allowed('bre',$ENV{'request.role.domain'})) {
       $scrout.=(<<ENDDOCUMENT);
   <h1>Catalog Search</h1>
 <form method="post" action="/adm/searchcat">  <form method="post" action="/adm/searchcat">
 <input type="hidden" name="phase" value="basic_search" />  <input type="hidden" name="phase" value="basic_search" />
 $hidden_fields  $hidden_fields
Line 460  END Line 566  END
 per page.  per page.
 </p>  </p>
 </form>  </form>
   ENDDOCUMENT
       if ($ENV{'request.course.id'}) { $scrout.='<hr />'; }
   }
   if ($ENV{'request.course.id'}) {
       $scrout.=(<<ENDCOURSESEARCH);
   <h1>Course Search</h1>    
   <form method="post" action="/adm/searchcat">
   <input type="hidden" name="phase" value="course_search" />
   $hidden_fields
   <p>
   Enter terms or phrases, then press SEARCH below.
   </p>
   <p>
   <table>
   <tr><td>
   ENDCOURSESEARCH
       $scrout.='&nbsp;'.&simpletextfield('courseexp',$ENV{'form.courseexp'},40);
       my $crscheckbox = &simplecheckbox('crsfulltext',$ENV{'form.crsfulltext'});
       my $relcheckbox = &simplecheckbox('crsrelated',$ENV{'form.crsrelated'});
   $scrout.=(<<ENDENDCOURSE);
   </td></tr>
   <tr><td>$relcheckbox use related words</td><td></td></tr>
   <tr><td>$crscheckbox fulltext search (time consuming)</td><td></td></tr>
   </table><p>
   &nbsp;<input type="submit" name="coursesubmit" value='SEARCH' />
   </p>
   ENDENDCOURSE
   }
       $scrout.=(<<ENDDOCUMENT);
 </body>  </body>
 </html>  </html>
 ENDDOCUMENT  ENDDOCUMENT
Line 2968  sub cleanup { Line 3103  sub cleanup {
   &Apache::lonnet::logthis('Failed cleanup searchcat: groupsearch_db');    &Apache::lonnet::logthis('Failed cleanup searchcat: groupsearch_db');
         }          }
     }      }
       &untiehash();
     &Apache::lonmysql::disconnect_from_db();      &Apache::lonmysql::disconnect_from_db();
 }  }
   

Removed from v.1.166  
changed lines
  Added in v.1.167


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