--- loncom/interface/lonsearchcat.pm 2006/09/26 15:24:18 1.276
+++ loncom/interface/lonsearchcat.pm 2009/07/02 17:05:31 1.309
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Search Catalog
#
-# $Id: lonsearchcat.pm,v 1.276 2006/09/26 15:24:18 raeburn Exp $
+# $Id: lonsearchcat.pm,v 1.309 2009/07/02 17:05:31 bisitz Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -78,7 +78,6 @@ use HTML::Entities();
use Parse::RecDescent;
use Apache::lonnavmaps;
use Apache::lonindexer();
-use lib '/home/httpd/lib/perl/';
use LONCAPA;
######################################################################
@@ -139,7 +138,7 @@ sub handler {
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
['catalogmode','launch','acts','mode','form','element','pause',
'phase','persistent_db_id','table','start','show',
- 'cleargroupsort','titleelement','area']);
+ 'cleargroupsort','titleelement','area','inhibitmenu']);
##
## The following is a trick - we wait a few seconds if asked to so
## the daemon running the search can get ahead of the daemon
@@ -171,25 +170,33 @@ sub handler {
'_'.$env{'form.persistent_db_id'}.'_persistent_search.db';
##
&Apache::lonhtmlcommon::clear_breadcrumbs();
+
+ my @allowed_searches = ('portfolio');
+ if (&Apache::lonnet::allowed('bre',$env{'request.role.domain'})) {
+ push(@allowed_searches,'res');
+ }
if (exists($env{'request.course.id'}) && $env{'request.course.id'} ne '') {
- &Apache::lonhtmlcommon::add_breadcrumb
- ({href=>'/adm/searchcat?'.
- 'catalogmode='.$env{'form.catalogmode'}.
- '&launch='.$env{'form.launch'}.
- '&mode='.$env{'form.mode'},
- text=>"Course and Catalog Search",
- target=>'_top',
- bug=>'Searching',});
- } else {
- &Apache::lonhtmlcommon::add_breadcrumb
- ({href=>'/adm/searchcat?'.
- 'catalogmode='.$env{'form.catalogmode'}.
- '&launch='.$env{'form.launch'}.
- '&mode='.$env{'form.mode'},
- text=>"Catalog Search",
+ push(@allowed_searches,'course');
+ }
+ my $crumb_text = 'Portfolio Search';
+ if (@allowed_searches == 3) {
+ $crumb_text = 'Course, Portfolio and Catalog Search';
+ } elsif (@allowed_searches ==2) {
+ if (grep(/^res$/,@allowed_searches)) {
+ $crumb_text = 'Portfolio and Catalog Search';
+ } elsif (grep(/^course$/,@allowed_searches)) {
+ $crumb_text = 'Portfolio and Course Search';
+ }
+ }
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>'/adm/searchcat?'.
+ &Apache::loncommon::inhibit_menu_check().
+ '&catalogmode='.$env{'form.catalogmode'}.
+ '&launch='.$env{'form.launch'}.
+ '&mode='.$env{'form.mode'},
+ text=>"$crumb_text",
target=>'_top',
bug=>'Searching',});
- }
#
if ($env{'form.phase'} !~ m/(basic|adv|course)_search/) {
if (! &get_persistent_form_data($persistent_db_file)) {
@@ -252,11 +259,14 @@ sub handler {
if (exists($env{'form.area'})) {
$hidden_fields .= &hidden_field('area');
}
+ if (exists($env{'form.inhibitmenu'})) {
+ $hidden_fields .= &hidden_field('inhibitmenu');
+ }
##
## Configure dynamic components of interface
##
if ($env{'form.catalogmode'} eq 'interactive') {
- $closebutton="
END
} else {
@@ -297,19 +308,25 @@ END
}
#
if ($env{'form.searchmode'} eq 'advanced') {
+ my $srchtype = 'Catalog';
+ if ($env{'form.area'} eq 'portfolio') {
+ $srchtype = 'Portfolio';
+ }
&Apache::lonhtmlcommon::add_breadcrumb
- ({href=>'/adm/searchcat?phase=disp_adv&'.
- 'catalogmode='.$env{'form.catalogmode'}.
- '&launch='.$env{'form.launch'}.
- '&mode='.$env{'form.mode'},
- text=>"Advanced Search",
+ ({href=>'/adm/searchcat?'.&Apache::loncommon::inhibit_menu_check().
+ '&phase=disp_adv'.
+ '&catalogmode='.$env{'form.catalogmode'}.
+ '&launch='.$env{'form.launch'}.
+ '&mode='.$env{'form.mode'},
+ text=>"Advanced $srchtype Search",
bug=>'Searching',});
} elsif ($env{'form.searchmode'} eq 'course search') {
&Apache::lonhtmlcommon::add_breadcrumb
- ({href=>'/adm/searchcat?phase=disp_adv&'.
+ ({href=>'/adm/searchcat?'.&Apache::loncommon::inhibit_menu_check().
+ '&phase=disp_adv'.
'catalogmode='.$env{'form.catalogmode'}.
- '&launch='.$env{'form.launch'}.
- '&mode='.$env{'form.mode'},
+ '&launch='.$env{'form.launch'}.
+ '&mode='.$env{'form.mode'},
text=>"Course Search",
bug=>'Searching',});
}
@@ -369,7 +386,7 @@ END
$errorstring);
my $msg =
- 'Unable to create table in which to store search results. '.
+ 'Unable to create table in which to save search results. '.
'The search has been aborted.';
&Apache::loncommon::simple_error_page($r,'Search Error',
$msg);
@@ -378,7 +395,7 @@ END
delete($env{'form.launch'});
if (! &make_form_data_persistent($r,$persistent_db_file)) {
my $msg=
- 'Unable to properly store search information. '.
+ 'Unable to properly save search information. '.
'The search has been aborted.';
&Apache::loncommon::simple_error_page($r,'Search Error',
$msg);
@@ -502,72 +519,77 @@ sub course_search {
my $totaldiscussions = 0;
$r->print('
'.&mt('Discussion postings').':
');
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($navmap)) {
+ 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/$LONCAPA::domain_re/$LONCAPA::username_re)/(\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;
+ 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);
}
- $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##;
+ 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('discussion board');
+ } else {
+ $url = '/res/'.$url;
}
- $disctype = &mt('bulletin board');
- } else {
- $url = '/res/'.$url;
- }
- if ($url =~ /\?/) {
- $url .= '&symb=';
+ if ($url =~ /\?/) {
+ $url .= '&symb=';
+ } else {
+ $url .= '?symb=';
+ }
+ $url .= &escape($resource->symb());
+ my $title = $resource->compTitle();
+ $r->print('
'.
+ ($title?$title:$url).' - '.
+ $disctype.'
');
+ $totaldiscussions++;
} else {
- $url .= '?symb=';
+ $r->print(' .');
}
- $url .= &escape($resource->symb());
- my $title = $resource->compTitle();
- $r->print('
'.
- ($title?$title:$url).' - '.$disctype.'
');
- $totaldiscussions++;
- } else {
- $r->print(' .');
}
- }
- unless ($totaldiscussions) {
- $r->print('
'.&mt('No matches found in postings').'.
'); + unless ($totaldiscussions) { + $r->print(''.&mt('No matches found in postings').'.
'); + } + } else { + $r->print('' + .&mt('There are [_1] matches to your query.',$total_results) + .' '.$revise.'
' + .''.&mt('Search: ').$pretty_query_string + .'
'; $r->print($result.&Apache::loncommon::end_page()); return; } @@ -2386,13 +2449,14 @@ Returns: html string for a 'revise searc ###################################################################### ###################################################################### sub revise_button { + my $revisetext = &mt('Revise search'); my $revise_phase = 'disp_basic'; $revise_phase = 'disp_adv' if ($env{'form.searchmode'} eq 'advanced'); my $newloc = '/adm/searchcat'. '?persistent_db_id='.$env{'form.persistent_db_id'}. - '&cleargroupsort=1'. - '&phase='.$revise_phase; - my $result = qq{ }; return $result; } @@ -2422,16 +2486,13 @@ sub run_search { # # Print run_search header # - my $start_page = &Apache::loncommon::start_page('Search Status',undef, - {'no_title' => 1}); + my $start_page = &Apache::loncommon::start_page('Search Status',undef); my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Searching','Searching', $env{'form.catalogmode'} ne 'import'); $r->print(<'.
- ' | '. &prev_next_buttons($min,$env{'form.show'},$total_results). ' | '.
@@ -2905,8 +2969,8 @@ sub display_results {
(' \n";
$result .= ''.$values{'author'}.','.
@@ -3385,11 +3450,8 @@ sub detailed_citation_view {
if (exists($field->{'type'}) && $field->{'type'} eq 'list') {
$result .= ''.&mt($field->{'translate'}).'';
foreach my $item (split(',',$values{$field->{'name'}})){
- $result .=
- &Apache::lonhtmlcommon::crumbs(&Apache::lonnet::clutter($item),
- 'preview',
- '',
- (($env{'form.catalogmode'} eq 'import')?'parent.statusframe.document.forms.statusform':''),2,0,1);
+ $item = &Apache::lonnet::clutter($item);
+ $result .= &display_url($item,[2,0,1]);
}
} elsif (exists($field->{'format'}) && $field->{'format'} ne ''){
$result.= &mt($field->{'translate'},
@@ -3397,15 +3459,7 @@ sub detailed_citation_view {
$values{$field->{'name'}}))." '.$values{'shortabstract'}.' '; } - $result .= ''."\n"; + $result .= ' '."\n"; return $result; } @@ -3461,24 +3515,18 @@ sub summary_view { $result .= ' '.$tmp.' '; } my $jumpurl=$values{'url'}; - my $link; - if ($jumpurl=~m|^/ext/|) { - $jumpurl=~s|^/ext/|http://|; - $link=' '.$jumpurl.''; - } else { - $link=&Apache::lonhtmlcommon::crumbs($jumpurl, - 'preview', - '', - (($env{'form.catalogmode'} eq 'import')?'parent.statusframe.document.forms.statusform':''),2,0,1); - } + $jumpurl=~s|^/ext/|http://|; + my $link = &display_url($jumpurl,[2,0,1]); + $result.=< +$link $values{'author'}, $values{'owner'} -- $values{'lastrevisiondate'} $values{'copyrighttag'} $values{'extrashow'} - + END return $result; } @@ -3506,30 +3554,42 @@ sub summary_preview { sub compact_view { my ($prefix,%values) = @_; my $jumpurl=$values{'url'}; - my $link; - if ($jumpurl=~m|^/ext/|) { - $jumpurl=~s|^/ext/|http://|; - $link=''.$jumpurl.''; - } else { - $link=&Apache::lonhtmlcommon::crumbs($jumpurl, - 'preview', - '', - (($env{'form.catalogmode'} eq 'import')?'parent.statusframe.document.forms.statusform':''),1,1,1).' '; - } + $jumpurl=~s|^/ext/|http://|; + + my $link = &display_url($jumpurl,[1,1,1]); + my $result = - $prefix.''; + $prefix.''; if (exists($env{'form.sortfield'}) && $env{'form.sortfield'} !~ /^(default|author|url|title)$/) { my $tmp = $values{$env{'form.sortfield'}}; if (! defined($tmp)) { $tmp = 'undefined'; } $result .= ' '.$tmp.' '; } - $result.=' '. - $values{'title'}.''.(' 'x2).$link. - ''.$values{'author'}.' ('.$values{'domain'}.') '; + $jumpurl = &HTML::Entities::encode($jumpurl,'<>&"'); + $result.=' '. + ''. + &HTML::Entities::encode($values{'title'},'<>&"').' '. + $link.' '.$values{'author'}.' ('.$values{'domain'}.') '; return $result; } +sub display_url { + my ($url,$crumb_args) = @_; + my $link; + if ($url=~m|^/ext/|) { + $url=~s|^/ext/|http://|; + $link=''.$url.''; + } elsif ($url=~m{^(http://|/uploaded/)}) { + $link=''.$url.''; + } else { + $link=&Apache::lonhtmlcommon::crumbs($url, + 'preview', + '', + (($env{'form.catalogmode'} eq 'import')?'parent.statusframe.document.forms.statusform':''),@{$crumb_args}).' '; + } + return $link; +} ###################################################################### ###################################################################### @@ -3553,7 +3613,7 @@ sub fielded_format_view { $prefix
'."\n"; + $result .= ' '."\n"; return $result; } @@ -3650,7 +3710,7 @@ $prefix $xml $values{'extrashow'} - + END return $result; } @@ -3710,7 +3770,7 @@ $closebutton $errorstring $end_page ENDPAGE @@ -3754,7 +3814,7 @@ $closebutton $errormsg $end_page ENDPAGE |