Diff for /loncom/interface/lonsearchcat.pm between versions 1.230.2.3 and 1.231

version 1.230.2.3, 2005/02/02 22:03:27 version 1.231, 2004/07/19 16:38:07
Line 76  use Apache::lonlocal; Line 76  use Apache::lonlocal;
 use LONCAPA::lonmetadata();  use LONCAPA::lonmetadata();
 use HTML::Entities();  use HTML::Entities();
 use Parse::RecDescent;  use Parse::RecDescent;
   use Apache::lonnavmaps;
   
 ######################################################################  ######################################################################
 ######################################################################  ######################################################################
Line 448  my %alreadyseen; Line 449  my %alreadyseen;
 my %hash;  my %hash;
 my $totalfound;  my $totalfound;
   
 sub make_symb {  
     my ($id)=@_;  
     my ($mapid,$resid)=split(/\./,$id);  
     my $map=$hash{'map_id_'.$mapid};  
     my $res=$hash{'src_'.$id};  
     my $symb=&Apache::lonnet::encode_symb($map,$resid,$res);  
     return $symb;  
 }  
   
 sub course_search {  sub course_search {
     my $r=shift;      my $r=shift;
     my $bodytag=&Apache::loncommon::bodytag('Course Search');      my $bodytag=&Apache::loncommon::bodytag('Course Search');
     my $pretty_search_string = '<b>'.$ENV{'form.courseexp'}.'</b>';      my $pretty_search_string = '<b>'.$ENV{'form.courseexp'}.'</b>';
     my $search_string = $ENV{'form.courseexp'};      my $search_string = $ENV{'form.courseexp'};
     my @New_Words;      my @New_Words;
     undef(%alreadyseen);  
     if ($ENV{'form.crsrelated'}) {      if ($ENV{'form.crsrelated'}) {
         ($search_string,@New_Words) = &related_version($ENV{'form.courseexp'});          ($search_string,@New_Words) = &related_version($ENV{'form.courseexp'});
         if (@New_Words) {          if (@New_Words) {
Line 473  sub course_search { Line 464  sub course_search {
         }          }
     }      }
     my $fulltext=$ENV{'form.crsfulltext'};      my $fulltext=$ENV{'form.crsfulltext'};
       my $discuss=$ENV{'form.crsdiscuss'};
     my @allwords=($search_string,@New_Words);      my @allwords=($search_string,@New_Words);
     $totalfound=0;      $totalfound=0;
     $r->print('<html><head><title>LON-CAPA Course Search</title></head>'.      $r->print('<html><head><title>LON-CAPA Course Search</title></head>'.
       $bodytag.'<hr /><center><font size="+2" face="arial">'.$pretty_search_string.'</font></center><hr />');        $bodytag.'<hr /><center><font size="+2" face="arial">'.$pretty_search_string.'</font></center><hr /><b>'.&mt('Course content').':</b><br />');
     $r->rflush();      $r->rflush();
 # ======================================================= Go through the course  # ======================================================= Go through the course
       undef %alreadyseen;
       %alreadyseen=();
     my $c=$r->connection;      my $c=$r->connection;
     if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",      if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
             &GDBM_READER(),0640)) {              &GDBM_READER(),0640)) {
         foreach (sort(keys(%hash))) {          foreach (keys %hash) {
             if ($c->aborted()) { last; }              if ($c->aborted()) { last; }
             if (($_=~/^src\_(.+)$/)) {              if (($_=~/^src\_(.+)$/) && (!$alreadyseen{$hash{$_}})) {
  if ($hash{'randomout_'.$1} & !$ENV{'request.role.adv'}) {                  &checkonthis($r,$hash{$_},0,$hash{'title_'.$1},$fulltext,
     next;                                @allwords);
  }  
  my $symb=&make_symb($1);  
                 &checkonthis($r,$1,$hash{$_},0,&Apache::lonnet::gettitle($symb),  
      $fulltext,$symb,@allwords);  
             }              }
         }          }
         untie(%hash);          untie(%hash);
     }      }
     unless ($totalfound) {      unless ($totalfound) {
  $r->print('<p>'.&mt('No resources found').'.</p>');   $r->print('<p>'.&mt('No matches found in resources').'.</p>');
     }      }
   
   # Check discussions if requested
       if ($discuss) {
           my $totaldiscussions = 0;
           $r->print('<br /><br /><b>'.&mt('Discussion postings').':</b><br />'); 
           my $navmap = Apache::lonnavmaps::navmap->new();
           my @allres=$navmap->retrieveResources();
           my %discussiontime = &Apache::lonnet::dump('discussiontimes',
                                  $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                                  $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
           foreach my $resource (@allres) {
               my $result = '';
               my $applies = 0;
               my $symb = $resource->symb();
               my $ressymb = $symb;
               if ($symb =~ m#(___adm/\w+/\w+)/(\d+)/bulletinboard$#) {
                   $ressymb = 'bulletin___'.$2.$1.'/'.$2.'/bulletinboard';
                   unless ($ressymb =~ m#bulletin___\d+___adm/wrapper#) {
                       $ressymb=~s#(bulletin___\d+___)#$1adm/wrapper/#;
                   }
               }
               if (defined($discussiontime{$ressymb})) { 
                   my %contrib = &Apache::lonnet::restore($ressymb,$ENV{'request.course.id'},
                        $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                        $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                   if ($contrib{'version'}) {
                       for (my $id=1;$id<=$contrib{'version'};$id++) {
                           unless (($contrib{'hidden'}=~/\.$id\./) || ($contrib{'deleted'}=~/\.$id\./)) { 
                               if ($contrib{$id.':subject'}) {
                                   $result .= $contrib{$id.':subject'};
                               }
                               if ($contrib{$id.':message'}) {
                                   $result .= $contrib{$id.':message'};
                               }
                               if ($contrib{$id,':attachmenturl'}) {
                                   if ($contrib{$id,':attachmenturl'} =~ m-/([^/]+)$-) {
                                       $result .= $1;
                                   }
                               }
                               $applies = &checkwords($result,$applies,@allwords);
                           }
                       }
                   }
               }
   # Does this discussion apply?
               if ($applies) {
                   my ($map,$ind,$url)=&Apache::lonnet::decode_symb($ressymb);
                   my $disctype = &mt('resource');
                   if ($url =~ m#/bulletinboard$#) {
                       if ($url =~m#^adm/wrapper/adm/.*/bulletinboard$#) {
                           $url =~s#^adm/wrapper##;
                       }
                       $disctype = &mt('bulletin board');
                   } else {
                       $url = '/res/'.$url;
                   }
                   if ($url =~ /\?/) {
                       $url .= '&symb=';
                   } else {
                       $url .= '?symb=';
                   }
                   $url .= &Apache::lonnet::escape($resource->symb());
                   my $title = $resource->compTitle();
                   $r->print('<br /><a href="'.$url.'" target="cat">'.
                        ($title?$title:$url).'</a>&nbsp;&nbsp;-&nbsp;'.$disctype.'<br />');
                   $totaldiscussions++;
               } else {
                   $r->print(' .');
               }
           }
           unless ($totaldiscussions) {
               $r->print('<p>'.&mt('No matches found in postings').'.</p>');
           }
       }
    
 # =================================================== Done going through course  # =================================================== Done going through course
     $r->print('</body></html>');      $r->print('</body></html>');
 }  }
Line 505  sub course_search { Line 570  sub course_search {
 # =============================== This pulls up a resource and its dependencies  # =============================== This pulls up a resource and its dependencies
   
 sub checkonthis {  sub checkonthis {
     my ($r,$id,$url,$level,$title,$fulltext,$symb,@allwords)=@_;      my ($r,$url,$level,$title,$fulltext,@allwords)=@_;
     $alreadyseen{$id}=1;      $alreadyseen{$url}=1;
     if (&Apache::loncommon::connection_aborted($r)) { return; }  
     $r->rflush();      $r->rflush();
           my $result=&Apache::lonnet::metadata($url,'title').' '.
     my $result=$title.' ';                 &Apache::lonnet::metadata($url,'subject').' '.
     if ($ENV{'request.role.adv'} || !$hash{'encrypted_'.$id}) {                 &Apache::lonnet::metadata($url,'abstract').' '.
  $result.=&Apache::lonnet::metadata($url,'title').' '.                 &Apache::lonnet::metadata($url,'keywords');
     &Apache::lonnet::metadata($url,'subject').' '.      if (($url) && ($fulltext)) {
     &Apache::lonnet::metadata($url,'abstract').' '.   $result.=&Apache::lonnet::ssi_body($url);
     &Apache::lonnet::metadata($url,'keywords');  
     }  
     my ($extension)=($url=~/\.(\w+)$/);  
     if (&Apache::loncommon::fileembstyle($extension) eq 'ssi' &&  
  ($url) && ($fulltext)) {  
  $result.=&Apache::lonnet::ssi_body($url.'?symb='.&Apache::lonnet::escape($symb));  
     }      }
     $result=~s/\s+/ /gs;      $result=~s/\s+/ /gs;
     my $applies=0;      my $applies = 0;
     foreach (@allwords) {      $applies = &checkwords($result,$applies,@allwords);
         if ($_=~/\w/) {  
    if ($result=~/$_/si) {  
       $applies++;  
            }  
        }  
     }  
 # Does this resource apply?  # Does this resource apply?
     if ($applies) {      if ($applies) {
        $r->print('<br />');         $r->print('<br />');
        for (my $i=0;$i<=$level*5;$i++) {         for (my $i=0;$i<=$level*5;$i++) {
            $r->print('&nbsp;');             $r->print('&nbsp;');
        }         }
        my $href=$url;         $r->print('<a href="'.$url.'" target="cat">'.
        if ($hash{'encrypted_'.$id} && !$ENV{'request.role.adv'}) {   ($title?$title:$url).'</a><br />');
    $href=&Apache::lonenc::encrypted($href)  
        .'?symb='.&Apache::lonenc::encrypted($symb);  
        } else {  
    $href.='?symb='.&Apache::lonnet::escape($symb);  
        }  
        $r->print('<a href="'.$href.'" target="cat">'.($title?$title:$url).  
  '</a><br />');  
        $totalfound++;         $totalfound++;
     } elsif ($fulltext) {      } elsif ($fulltext) {
        $r->print(' .');         $r->print(' .');
Line 555  sub checkonthis { Line 600  sub checkonthis {
     my $dependencies=      my $dependencies=
                 &Apache::lonnet::metadata($url,'dependencies');                  &Apache::lonnet::metadata($url,'dependencies');
     foreach (split(/\,/,$dependencies)) {      foreach (split(/\,/,$dependencies)) {
        if (($_=~/^\/res\//) && (!$alreadyseen{$id})) {          if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {
           &checkonthis($r,$id,$_,$level+1,'',$fulltext,undef,@allwords);            &checkonthis($r,$_,$level+1,'',$fulltext,@allwords);
        }         }
     }      }
 }  }
   
   sub checkwords {
       my ($result,$applies,@allwords) = @_;
       foreach (@allwords) {
           if ($_=~/\w/) {
               if ($result=~/$_/si) {
                   $applies++;
               }
           }
       }
       return $applies;
   }
   
 sub untiehash {  sub untiehash {
     if (tied(%hash)) {      if (tied(%hash)) {
         untie(%hash);          untie(%hash);
Line 664  sub print_basic_search_form { Line 721  sub print_basic_search_form {
                                            'header' => 'Course Search',                                             'header' => 'Course Search',
  'note' => 'Enter terms or phrases, then press "Search" below',   'note' => 'Enter terms or phrases, then press "Search" below',
  'use' => 'use related words',   'use' => 'use related words',
  'full' =>'fulltext search (time consuming)'   'full' =>'fulltext search (time consuming)',
            'disc' => 'search discussion postings (resources and bulletin boards)',
    );     );
         $scrout.=(<<ENDCOURSESEARCH);          $scrout.=(<<ENDCOURSESEARCH);
 <form name="loncapa_search" method="post" action="/adm/searchcat">  <form name="loncapa_search" method="post" action="/adm/searchcat">
Line 689  ENDCOURSESEARCH Line 747  ENDCOURSESEARCH
         my $relcheckbox =           my $relcheckbox = 
             &Apache::lonhtmlcommon::checkbox('crsrelated',              &Apache::lonhtmlcommon::checkbox('crsrelated',
    $ENV{'form.crsrelated'});     $ENV{'form.crsrelated'});
           my $discheckbox = 
               &Apache::lonhtmlcommon::checkbox('crsdiscuss',
                                      $ENV{'form.crsrelated'});
         $scrout.=(<<ENDENDCOURSE);          $scrout.=(<<ENDENDCOURSE);
 </td></tr>  </td></tr>
 <tr><td>$relcheckbox $lt{'use'}</td><td></td></tr>  <tr><td>$relcheckbox $lt{'use'}</td><td></td></tr>
 <tr><td>$crscheckbox $lt{'full'}</td><td></td></tr>  <tr><td>$crscheckbox $lt{'full'}</td><td></td></tr>
   <tr><td>$discheckbox $lt{'disc'}</td><td></td></tr>
 </table><p>  </table><p>
 &nbsp;<input type="submit" name="coursesubmit" value='$lt{'srch'}' />  &nbsp;<input type="submit" name="coursesubmit" value='$lt{'srch'}' />
 </p>  </p>

Removed from v.1.230.2.3  
changed lines
  Added in v.1.231


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