Diff for /loncom/interface/lonsearchcourse.pm between versions 1.1 and 1.12

version 1.1, 2011/01/17 20:18:02 version 1.12, 2024/02/11 23:03:13
Line 41  use Apache::lonlocal; Line 41  use Apache::lonlocal;
 use LONCAPA::lonmetadata();  use LONCAPA::lonmetadata();
 use HTML::Entities();  use HTML::Entities();
 use Apache::lonnavmaps;  use Apache::lonnavmaps;
 use Apache::londocs();  use Apache::lonnavdisplay();
 use Apache::lonindexer();  use Apache::lonindexer();
 use LONCAPA;  use LONCAPA;
   
Line 54  my $totalfound; Line 54  my $totalfound;
 sub menu {  sub menu {
     my $scrout='';      my $scrout='';
     if ($env{'request.course.id'}) {      if ($env{'request.course.id'}) {
         my %lt=&Apache::lonlocal::texthash('srch' => 'Search',          my %lt=&Apache::lonlocal::texthash(
                                            'header' => 'Course Search',           'srch' => 'Search',
          'note' => 'Enter terms or phrases, then press "Search" below',           'note' => 'Search terms',
            'options' => 'Options',
          'use' => 'use related words',           'use' => 'use related words',
          'full' =>'fulltext search (time consuming)',           'full' =>'fulltext search (time consuming)',
          'disc' => 'search discussion postings (resources and discussion boards)',           'disc' => 'search discussion postings (resources and discussion boards)',
                                            );                                             );
         $scrout.=(<<ENDCOURSESEARCH);          $scrout.=(<<ENDCOURSESEARCH);
 <form name="loncapa_search" method="post" action="/adm/searchcourse">  <form name="loncapa_search" method="post" action="/adm/searchcourse">
 <center>  
 <hr />  
 <h1>$lt{'header'}</h1>      
 <input type="hidden" name="phase" value="results" />  <input type="hidden" name="phase" value="results" />
 <p>  
 $lt{'note'}.  
 </p>  
 <table>  
 <tr><td>  
 ENDCOURSESEARCH  ENDCOURSESEARCH
         $scrout.='&nbsp;'.         $scrout.=&Apache::lonhtmlcommon::start_pick_box().
             &Apache::lonhtmlcommon::textbox('courseexp',                  &Apache::lonhtmlcommon::row_title($lt{'note'}).
                                   $env{'form.courseexp'},40);                  &Apache::lonhtmlcommon::textbox('courseexp',
         my $crscheckbox =                                    $env{'form.courseexp'},40).
             &Apache::lonhtmlcommon::checkbox('crsfulltext',                  &Apache::lonhtmlcommon::row_closure().
                                    $env{'form.crsfulltext'});                  &Apache::lonhtmlcommon::row_title($lt{'options'}).
         my $relcheckbox =                  '<label>'.&Apache::lonhtmlcommon::checkbox('crsfulltext',$env{'form.crsfulltext'}).$lt{'full'}."</label><br />\n".
             &Apache::lonhtmlcommon::checkbox('crsrelated',                  '<label>'.&Apache::lonhtmlcommon::checkbox('crsrelated',$env{'form.crsrelated'}).$lt{'use'}."</label><br />\n".
                                    $env{'form.crsrelated'});                  '<label>'.&Apache::lonhtmlcommon::checkbox('crsdiscuss',$env{'form.crsdiscuss'}).$lt{'disc'}."</label><br />\n".
         my $discheckbox =                  &Apache::lonhtmlcommon::end_pick_box();
             &Apache::lonhtmlcommon::checkbox('crsdiscuss',  
                                    $env{'form.crsrelated'});  
         $scrout.=(<<ENDENDCOURSE);          $scrout.=(<<ENDENDCOURSE);
 </td></tr>  
 <tr><td><label>$relcheckbox $lt{'use'}</label></td><td></td></tr>  
 <tr><td><label>$crscheckbox $lt{'full'}</label></td><td></td></tr>  
 <tr><td><label>$discheckbox $lt{'disc'}</label></td><td></td></tr>  
 </table>  
 <p>  <p>
 <input type="submit" name="coursesubmit" value='$lt{'srch'}' />  <input type="submit" name="coursesubmit" value='$lt{'srch'}' />
 </p>  </p>
 </center>  
 </form>  </form>
 ENDENDCOURSE  ENDENDCOURSE
     }      }
Line 138  sub course_search { Line 123  sub course_search {
     my $discuss=$env{'form.crsdiscuss'};      my $discuss=$env{'form.crsdiscuss'};
     my @allwords=($search_string,@New_Words);      my @allwords=($search_string,@New_Words);
     $totalfound=0;      $totalfound=0;
       my $target = 'cat';
       if ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
           (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
           $target = '_self';
       }
   
     $r->print(      $r->print(
               '<hr /><center><font size="+2" face="arial">'.                '<hr /><center><font size="+2" face="arial">'.
Line 148  sub course_search { Line 138  sub course_search {
     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 my $key (sort(keys(%hash))) {
             if ($c->aborted()) { last; }              last if ($c->aborted());
             if (($_=~/^src\_(.+)$/)) {              if ($key =~ /^src\_(.+)$/) {
                 if ($hash{'randomout_'.$1} & !$env{'request.role.adv'}) {                  my $rid = $1;
                     next;                  unless ($env{'request.role.adv'}) {
                       next if ($hash{'randomout_'.$rid} || $hash{'deeplinkout_'.$rid});
                       if (!$env{'request.deeplink.login'} && $hash{'deeplinkonly_'.$rid}) {
                           my ($value) = map { &unescape($_); } split(/:/,$hash{'deeplinkonly_'.$rid});
                           my ($state,$others,$listed) = split(/,/,$value);
                           next if (($state eq 'only') &&
                                    (($listed eq 'absent') || ($listed eq 'grades')));
                       }
                 }                  }
                 my $symb=&make_symb($1);                  my $symb=&make_symb($1);
                 &checkonthis($r,$1,$hash{$_},0,&Apache::lonnet::gettitle($symb),                  &checkonthis($r,$1,$hash{$key},0,&Apache::lonnet::gettitle($symb),
                              $fulltext,$symb,@allwords);                               $fulltext,$symb,$target,@allwords);
             }              }
         }          }
         untie(%hash);          untie(%hash);
Line 228  sub course_search { Line 225  sub course_search {
                     }                      }
                     $url .= &escape($resource->symb());                      $url .= &escape($resource->symb());
                     my $title = $resource->compTitle();                      my $title = $resource->compTitle();
                     $r->print('<br /><a href="'.$url.'" target="cat">'.                      $r->print('<br /><a href="'.$url.'" target="'.$target.'">'.
                          ($title?$title:$url).'</a>&nbsp;&nbsp;-&nbsp;'.                           ($title?$title:$url).'</a>&nbsp;&nbsp;-&nbsp;'.
                          $disctype.'<br />');                           $disctype.'<br />');
                     $totaldiscussions++;                      $totaldiscussions++;
Line 243  sub course_search { Line 240  sub course_search {
             $r->print('<div class="LC_error">'.&mt('An error occurred retrieving information about resources in the course.').'<br />'.&mt('It is recommended that you [_1]re-initialize the course[_2] and then try your search again.','<a href="/adm/roles">','</a>').'</div>');              $r->print('<div class="LC_error">'.&mt('An error occurred retrieving information about resources in the course.').'<br />'.&mt('It is recommended that you [_1]re-initialize the course[_2] and then try your search again.','<a href="/adm/roles">','</a>').'</div>');
         }          }
     }      }
   
 # =================================================== Done going through course  
     $r->print(&Apache::loncommon::end_page());  
 }  }
   
 # =============================== 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,$id,$url,$level,$title,$fulltext,$symb,$target,@allwords)=@_;
     $alreadyseen{$id}=1;      $alreadyseen{$id}=1;
     if (&Apache::loncommon::connection_aborted($r)) { return; }      if (&Apache::loncommon::connection_aborted($r)) { return; }
     $r->rflush();      $r->rflush();
Line 279  sub checkonthis { Line 273  sub checkonthis {
        }         }
        my $href=$url;         my $href=$url;
        if ($hash{'encrypted_'.$id} && !$env{'request.role.adv'}) {         if ($hash{'encrypted_'.$id} && !$env{'request.role.adv'}) {
            $href=&Apache::lonenc::encrypted($href)             $href=&Apache::lonenc::encrypted($href);
                .'?symb='.&Apache::lonenc::encrypted($symb);             if ($url =~ /\.sequence$/) {
                  $href .= '?navmap=1';
              } else {
                  $href .= '?symb='.&Apache::lonenc::encrypted($symb);
              }
        } else {         } else {
            $href.='?symb='.&escape($symb);             if ($href =~ /\.sequence$/) {
                  $href .= '?navmap=1';
              } else {
                  $href .= '?symb='.&escape($symb);
              }
        }         }
        $r->print('<a href="'.$href.'" target="cat">'.($title?$title:$url).         $r->print('<a href="'.$href.'" target="'.$target.'">'.($title?$title:$url).
                  '</a><br />');                   '</a><br />');
        $totalfound++;         $totalfound++;
     } elsif ($fulltext) {      } elsif ($fulltext) {
Line 294  sub checkonthis { Line 296  sub checkonthis {
 # Check also the dependencies of this one  # Check also the dependencies of this one
     my $dependencies=      my $dependencies=
                 &Apache::lonnet::metadata($url,'dependencies');                  &Apache::lonnet::metadata($url,'dependencies');
     foreach (split(/\,/,$dependencies)) {      foreach my $url (split(/\,/,$dependencies)) {
        if (($_=~/^\/res\//) && (!$alreadyseen{$id})) {         if (($url =~ /^\/res\//) && (!$alreadyseen{$id})) {
           &checkonthis($r,$id,$_,$level+1,'',$fulltext,undef,@allwords);            &checkonthis($r,$id,$url,$level+1,'',$fulltext,undef,$target,@allwords);
        }         }
     }      }
 }  }
   
 sub checkwords {  sub checkwords {
     my ($result,$applies,@allwords) = @_;      my ($result,$applies,@allwords) = @_;
     foreach (@allwords) {      foreach my $word (@allwords) {
         if ($_=~/\w/) {          if ($word =~ /\w/) {
             if ($result=~/$_/si) {              if ($result =~ /$word/si) {
                 $applies++;                  $applies++;
             }              }
         }          }
Line 327  sub handler { Line 329  sub handler {
   
     my $crstype = &Apache::loncommon::course_type();      my $crstype = &Apache::loncommon::course_type();
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['phase']);      &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['phase']);
     &Apache::lonhtmlcommon::clear_breadcrumbs();  
     $r->print(&Apache::loncommon::start_page("$crstype Search"));      $r->print(&Apache::loncommon::start_page("$crstype Search"));
     $r->print(&Apache::lonhtmlcommon::breadcrumbs("$crstype Search"));      &Apache::lonhtmlcommon::clear_breadcrumbs();
     &Apache::londocs::startContentScreen($r,'coursesearch');      if ($env{'request.course.id'} eq '') {
           $r->print(&Apache::lonhtmlcommon::breadcrumbs("$crstype Search"));
           $r->print(&Apache::loncommon::end_page());
           my $requrl = $r->uri;
           $env{'user.error.msg'} = "$requrl:bre:0:0:Course not initialized";
           $env{'user.reinit'} = 1;
           return HTTP_NOT_ACCEPTABLE;
       }
       &Apache::lonhtmlcommon::add_breadcrumb(
               {   href => '/adm/searchcourse',
                   text => "$crstype Search"});
     if ($env{'form.phase'} eq 'results') {      if ($env{'form.phase'} eq 'results') {
        &course_search($r);         &Apache::lonhtmlcommon::add_breadcrumb(
               {   href => '/adm/searchcourse?phase=results',
                   text => 'Search Results'});
       }
       $r->print(&Apache::lonhtmlcommon::breadcrumbs("$crstype Search"));
       &Apache::lonnavdisplay::startContentScreen($r,'coursesearch');
       my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
       my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
       my $clientip = &Apache::lonnet::get_requestor_ip($r);
       my ($blocked,$blocktext) =
           &Apache::loncommon::blocking_status('search',$clientip,$cnum,$cdom);
       if ($blocked) {
           my $checkrole = "cm./$cdom/$cnum";
           if ($env{'request.course.sec'} ne '') {
               $checkrole .= "/$env{'request.course.sec'}";
           }
           if ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
               ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
               undef($blocked);
           }
       }
       if ($blocked) {
           $r->print($blocktext);
       } elsif ($env{'form.phase'} eq 'results') {
           &course_search($r);
     } else {      } else {
        $r->print(&menu());          $r->print(&menu());
     }      }
     &Apache::londocs::endContentScreen($r);      &Apache::lonnavdisplay::endContentScreen($r);
     $r->print(&Apache::loncommon::end_page());      $r->print(&Apache::loncommon::end_page());
     return OK;      return OK;
 }  }

Removed from v.1.1  
changed lines
  Added in v.1.12


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