--- loncom/interface/lonsearchcourse.pm 2011/01/17 20:43:09 1.2 +++ loncom/interface/lonsearchcourse.pm 2024/02/11 23:03:13 1.12 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Search Course # -# $Id: lonsearchcourse.pm,v 1.2 2011/01/17 20:43:09 www Exp $ +# $Id: lonsearchcourse.pm,v 1.12 2024/02/11 23:03:13 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -41,7 +41,7 @@ use Apache::lonlocal; use LONCAPA::lonmetadata(); use HTML::Entities(); use Apache::lonnavmaps; -use Apache::londocs(); +use Apache::lonnavdisplay(); use Apache::lonindexer(); use LONCAPA; @@ -54,47 +54,32 @@ my $totalfound; sub menu { my $scrout=''; if ($env{'request.course.id'}) { - my %lt=&Apache::lonlocal::texthash('srch' => 'Search', - 'header' => 'Course Search', - 'note' => 'Enter terms or phrases, then press "Search" below', + my %lt=&Apache::lonlocal::texthash( + 'srch' => 'Search', + 'note' => 'Search terms', + 'options' => 'Options', 'use' => 'use related words', 'full' =>'fulltext search (time consuming)', 'disc' => 'search discussion postings (resources and discussion boards)', ); $scrout.=(< -
-
-

$lt{'header'}

-

-$lt{'note'}. -

- - - - - -
ENDCOURSESEARCH - $scrout.=' '. - &Apache::lonhtmlcommon::textbox('courseexp', - $env{'form.courseexp'},40); - my $crscheckbox = - &Apache::lonhtmlcommon::checkbox('crsfulltext', - $env{'form.crsfulltext'}); - my $relcheckbox = - &Apache::lonhtmlcommon::checkbox('crsrelated', - $env{'form.crsrelated'}); - my $discheckbox = - &Apache::lonhtmlcommon::checkbox('crsdiscuss', - $env{'form.crsrelated'}); + $scrout.=&Apache::lonhtmlcommon::start_pick_box(). + &Apache::lonhtmlcommon::row_title($lt{'note'}). + &Apache::lonhtmlcommon::textbox('courseexp', + $env{'form.courseexp'},40). + &Apache::lonhtmlcommon::row_closure(). + &Apache::lonhtmlcommon::row_title($lt{'options'}). + '
\n". + '
\n". + '
\n". + &Apache::lonhtmlcommon::end_pick_box(); $scrout.=(<

-
ENDENDCOURSE } @@ -138,6 +123,11 @@ sub course_search { my $discuss=$env{'form.crsdiscuss'}; my @allwords=($search_string,@New_Words); $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( '
'. @@ -148,15 +138,22 @@ sub course_search { my $c=$r->connection; if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db", &GDBM_READER(),0640)) { - foreach (sort(keys(%hash))) { - if ($c->aborted()) { last; } - if (($_=~/^src\_(.+)$/)) { - if ($hash{'randomout_'.$1} & !$env{'request.role.adv'}) { - next; + foreach my $key (sort(keys(%hash))) { + last if ($c->aborted()); + if ($key =~ /^src\_(.+)$/) { + my $rid = $1; + 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); - &checkonthis($r,$1,$hash{$_},0,&Apache::lonnet::gettitle($symb), - $fulltext,$symb,@allwords); + &checkonthis($r,$1,$hash{$key},0,&Apache::lonnet::gettitle($symb), + $fulltext,$symb,$target,@allwords); } } untie(%hash); @@ -228,7 +225,7 @@ sub course_search { } $url .= &escape($resource->symb()); my $title = $resource->compTitle(); - $r->print('
'. + $r->print('
'. ($title?$title:$url).'  - '. $disctype.'
'); $totaldiscussions++; @@ -243,15 +240,12 @@ sub course_search { $r->print('
'.&mt('An error occurred retrieving information about resources in the course.').'
'.&mt('It is recommended that you [_1]re-initialize the course[_2] and then try your search again.','','').'
'); } } - -# =================================================== Done going through course - $r->print(&Apache::loncommon::end_page()); } # =============================== This pulls up a resource and its dependencies sub checkonthis { - my ($r,$id,$url,$level,$title,$fulltext,$symb,@allwords)=@_; + my ($r,$id,$url,$level,$title,$fulltext,$symb,$target,@allwords)=@_; $alreadyseen{$id}=1; if (&Apache::loncommon::connection_aborted($r)) { return; } $r->rflush(); @@ -279,12 +273,20 @@ sub checkonthis { } my $href=$url; if ($hash{'encrypted_'.$id} && !$env{'request.role.adv'}) { - $href=&Apache::lonenc::encrypted($href) - .'?symb='.&Apache::lonenc::encrypted($symb); + $href=&Apache::lonenc::encrypted($href); + if ($url =~ /\.sequence$/) { + $href .= '?navmap=1'; + } else { + $href .= '?symb='.&Apache::lonenc::encrypted($symb); + } } else { - $href.='?symb='.&escape($symb); + if ($href =~ /\.sequence$/) { + $href .= '?navmap=1'; + } else { + $href .= '?symb='.&escape($symb); + } } - $r->print(''.($title?$title:$url). + $r->print(''.($title?$title:$url). '
'); $totalfound++; } elsif ($fulltext) { @@ -294,18 +296,18 @@ sub checkonthis { # Check also the dependencies of this one my $dependencies= &Apache::lonnet::metadata($url,'dependencies'); - foreach (split(/\,/,$dependencies)) { - if (($_=~/^\/res\//) && (!$alreadyseen{$id})) { - &checkonthis($r,$id,$_,$level+1,'',$fulltext,undef,@allwords); + foreach my $url (split(/\,/,$dependencies)) { + if (($url =~ /^\/res\//) && (!$alreadyseen{$id})) { + &checkonthis($r,$id,$url,$level+1,'',$fulltext,undef,$target,@allwords); } } } sub checkwords { my ($result,$applies,@allwords) = @_; - foreach (@allwords) { - if ($_=~/\w/) { - if ($result=~/$_/si) { + foreach my $word (@allwords) { + if ($word =~ /\w/) { + if ($result =~ /$word/si) { $applies++; } } @@ -329,6 +331,14 @@ sub handler { &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['phase']); $r->print(&Apache::loncommon::start_page("$crstype Search")); &Apache::lonhtmlcommon::clear_breadcrumbs(); + 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"}); @@ -338,13 +348,30 @@ sub handler { text => 'Search Results'}); } $r->print(&Apache::lonhtmlcommon::breadcrumbs("$crstype Search")); - &Apache::londocs::startContentScreen($r,'coursesearch'); - if ($env{'form.phase'} eq 'results') { - &course_search($r); + &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 { - $r->print(&menu()); + $r->print(&menu()); } - &Apache::londocs::endContentScreen($r); + &Apache::lonnavdisplay::endContentScreen($r); $r->print(&Apache::loncommon::end_page()); return OK; }