--- loncom/interface/lonsearchcat.pm 2006/06/08 16:58:56 1.268
+++ loncom/interface/lonsearchcat.pm 2009/05/04 16:45:57 1.306
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Search Catalog
#
-# $Id: lonsearchcat.pm,v 1.268 2006/06/08 16:58:56 www Exp $
+# $Id: lonsearchcat.pm,v 1.306 2009/05/04 16:45:57 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']);
+ '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)) {
@@ -249,11 +256,17 @@ sub handler {
if (exists($env{'form.mode'})) {
$hidden_fields .= &hidden_field('mode');
}
+ 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 {
@@ -294,16 +308,22 @@ 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'}.
+ ({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 Search",
+ 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'},
@@ -318,7 +338,8 @@ END
} elsif ($env{'form.phase'} eq 'disp_adv') {
&print_advanced_search_form($r,$closebutton,$hidden_fields);
} elsif ($env{'form.phase'} eq 'results') {
- &display_results($r,$importbutton,$closebutton,$diropendb);
+ &display_results($r,$importbutton,$closebutton,$diropendb,
+ $env{'form.area'});
} elsif ($env{'form.phase'} =~ /^(sort|run_search)$/) {
my ($query,$customquery,$customshow,$libraries,$pretty_string) =
&get_persistent_data($persistent_db_file,
@@ -328,7 +349,7 @@ END
&print_sort_form($r,$pretty_string);
} elsif ($env{'form.phase'} eq 'run_search') {
&run_search($r,$query,$customquery,$customshow,
- $libraries,$pretty_string);
+ $libraries,$pretty_string,$env{'form.area'});
}
} elsif ($env{'form.phase'} eq 'course_search') {
&course_search($r);
@@ -358,14 +379,14 @@ END
$persistent_db_file);
#
# Set up table
- if (! defined(&create_results_table())) {
+ if (! defined(&create_results_table($env{'form.area'}))) {
my $errorstring=&Apache::lonmysql::get_error();
&Apache::lonnet::logthis('lonsearchcat.pm: Unable to create '.
'needed table. lonmysql error:'.
$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);
@@ -374,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);
@@ -498,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(''."\n". + &Apache::loncommon::start_data_table()); + $r->print(&Apache::loncommon::start_data_table_header_row() + .' | '.&mt('Status').' | ' + .''.&mt('Total Matches').' | ' + .''.&mt('Time Remaining').' | ' + .&Apache::loncommon::end_data_table_header_row() + .&Apache::loncommon::start_data_table_row() + .'' + .' | ' + .' | ' + .&Apache::loncommon::end_data_table_row() + .&Apache::loncommon::end_data_table() + .' | '.$revise.' |
---|
'.
- ' | '. &prev_next_buttons($min,$env{'form.show'},$total_results). ' | '.
@@ -2763,12 +2942,16 @@ sub display_results {
my @Results = &Apache::lonmysql::get_rows($table,$sort_command);
##
## Loop through the results and output them.
+ my $tabletype = 'metadata';
+ if ($area eq 'portfolio') {
+ $tabletype = 'portfolio_search';
+ }
foreach my $row (@Results) {
if ($connection->aborted()) {
&cleanup();
return;
}
- my %Fields = %{&parse_row(@$row)};
+ my %Fields = %{&parse_row($tabletype,@$row)};
my $output=" \n";
if (! defined($Fields{'title'}) || $Fields{'title'} eq '') {
$Fields{'title'} = 'Untitled';
@@ -2821,8 +3004,8 @@ sub catalogmode_output {
$title=~ s/\'/\\\'/g;
if ($env{'form.catalogmode'} eq 'interactive') {
$output.=< \n";
$result .= ''.$values{'author'}.','.
' '.$values{'owner'}.' |