--- loncom/interface/lonsearchcat.pm 2006/05/12 16:45:41 1.264
+++ loncom/interface/lonsearchcat.pm 2009/07/03 08:18:48 1.311
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Search Catalog
#
-# $Id: lonsearchcat.pm,v 1.264 2006/05/12 16:45:41 albertel Exp $
+# $Id: lonsearchcat.pm,v 1.311 2009/07/03 08:18:48 bisitz Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -78,6 +78,7 @@ use HTML::Entities();
use Parse::RecDescent;
use Apache::lonnavmaps;
use Apache::lonindexer();
+use LONCAPA;
######################################################################
######################################################################
@@ -137,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
@@ -153,7 +154,7 @@ sub handler {
##
my $domain = $r->dir_config('lonDefDomain');
$diropendb= "/home/httpd/perl/tmp/".
- "$env{'user.domain'}_$env{'user.name'}_searchcat.db";
+ "$env{'user.domain'}_$env{'user.name'}_sel_res.db";
#
# set the name of the persistent database
# $env{'form.persistent_db_id'} can only have digits in it.
@@ -164,30 +165,38 @@ sub handler {
}
my $persistent_db_file = "/home/httpd/perl/tmp/".
- &Apache::lonnet::escape($domain).
- '_'.&Apache::lonnet::escape($env{'user.name'}).
+ &escape($domain).
+ '_'.&escape($env{'user.name'}).
'_'.$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)) {
@@ -213,7 +222,7 @@ sub handler {
untie %groupsearch_db if (tied(%groupsearch_db));
if (($env{'form.cleargroupsort'} eq '1') ||
(($env{'form.launch'} eq '1') &&
- ($env{'form.catalogmode'} eq 'groupsearch'))) {
+ ($env{'form.catalogmode'} eq 'import'))) {
if (tie(%groupsearch_db,'GDBM_File',$diropendb,&GDBM_WRCREAT(),0640)) {
&start_fresh_session();
untie %groupsearch_db;
@@ -247,27 +256,34 @@ 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 {
@@ -292,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',});
}
@@ -316,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,
@@ -326,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);
@@ -356,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);
@@ -372,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);
@@ -465,7 +488,20 @@ sub course_search {
my $discuss=$env{'form.crsdiscuss'};
my @allwords=($search_string,@New_Words);
$totalfound=0;
- $r->print(&Apache::loncommon::start_page('Course Search').
+
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>'/adm/searchcat?'.&Apache::loncommon::inhibit_menu_check().
+ '&phase=disp_adv'.
+ 'catalogmode='.$env{'form.catalogmode'}.
+ '&launch='.$env{'form.launch'}.
+ '&mode='.$env{'form.mode'},
+ text=>"Course Search",
+ bug=>'Searching',});
+ $r->print(&Apache::loncommon::start_page('Course Search'));
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('Searching','Searching',
+ $env{'form.catalogmode'} ne 'import'));
+
+ $r->print(
'
'.
$pretty_search_string.'
'.
''.&mt('Course content').': ');
@@ -496,72 +532,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 .= &Apache::lonnet::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('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.','','').'
');
}
}
@@ -587,7 +628,7 @@ sub checkonthis {
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.=&Apache::lonnet::ssi_body($url.'?symb='.&escape($symb));
}
$result=~s/\s+/ /gs;
my $applies = 0;
@@ -603,7 +644,7 @@ sub checkonthis {
$href=&Apache::lonenc::encrypted($href)
.'?symb='.&Apache::lonenc::encrypted($symb);
} else {
- $href.='?symb='.&Apache::lonnet::escape($symb);
+ $href.='?symb='.&escape($symb);
}
$r->print(''.($title?$title:$url).
' ');
@@ -658,80 +699,25 @@ Prints the form for the basic search. S
######################################################################
sub print_basic_search_form {
my ($r,$closebutton,$hidden_fields) = @_;
- my $result = ($env{'form.catalogmode'} ne 'groupsearch');
+ my $result = ($env{'form.catalogmode'} ne 'import');
my $bread_crumb =
&Apache::lonhtmlcommon::breadcrumbs('Searching','Search_Basic',
- $env{'form.catalogmode'} ne 'groupsearch');
- my $scrout = &Apache::loncommon::start_page('Search').$bread_crumb;
+ $env{'form.catalogmode'} ne 'import');
+ my $scrout = &Apache::loncommon::start_page('Content Library').$bread_crumb;
+# Search form for resource space
if (&Apache::lonnet::allowed('bre',$env{'request.role.domain'})) {
- # Define interface components
- my $userelatedwords= '';
- my $onlysearchdomain='';
- my $inclext= '';
- my $adv_search_link =
- ''.&mt('Advanced Search').'';
- #
- $scrout.='';
+ $scrout .= &setup_basic_search($r,'res',$hidden_fields,$closebutton);
+ $scrout .= ' ';
}
+# Search form for accessible portfolio files
+ $scrout.= &setup_basic_search($r,'portfolio',$hidden_fields,$closebutton);
if ($env{'request.course.id'}) {
my %lt=&Apache::lonlocal::texthash('srch' => 'Search',
'header' => 'Course Search',
'note' => 'Enter terms or phrases, then press "Search" below',
'use' => 'use related words',
'full' =>'fulltext search (time consuming)',
- 'disc' => 'search discussion postings (resources and bulletin boards)',
+ 'disc' => 'search discussion postings (resources and discussion boards)',
);
$scrout.=(<
@@ -775,6 +761,75 @@ ENDENDCOURSE
$r->print($scrout);
return;
}
+
+sub setup_basic_search {
+ my ($r,$area,$hidden_fields,$closebutton) = @_;
+ # Define interface components
+ my %lt = &Apache::lonlocal::texthash (
+ res => 'LON-CAPA Catalog Search',
+ portfolio => 'Portfolio Search',
+ );
+ my ($userelatedwords,$onlysearchdomain,$inclext,$adv_search_link,$scrout);
+ $userelatedwords = '';
+ $onlysearchdomain = '';
+ $adv_search_link = ''.&mt('Advanced Search').'';
+ #
+ $scrout.='';
+ return $scrout;
+}
+
######################################################################
######################################################################
@@ -792,7 +847,7 @@ sub print_advanced_search_form{
my ($r,$closebutton,$hidden_fields) = @_;
my $bread_crumb =
&Apache::lonhtmlcommon::breadcrumbs('Searching','Search_Advanced',
- $env{'form.catalogmode'} ne 'groupsearch');
+ $env{'form.catalogmode'} ne 'import');
my %lt=&Apache::lonlocal::texthash('srch' => 'Search',
'reset' => 'Reset',
'help' => 'Help');
@@ -801,7 +856,22 @@ sub print_advanced_search_form{
$closebutton
END
- my $scrout= &Apache::loncommon::start_page('Advanced Catalog Search');
+ my $srchtype = 'Catalog';
+ my $jscript;
+ if ($env{'form.area'} eq 'portfolio') {
+ $srchtype = 'Portfolio';
+ $jscript = '';
+ }
+ my $scrout= &Apache::loncommon::start_page("Advanced $srchtype Search",
+ $jscript);
$scrout .= <<"ENDHEADER";
$bread_crumb
';
$r->print($result.&Apache::loncommon::end_page());
return;
}
@@ -2170,7 +2327,7 @@ my @Fullindicies;
Creates the table of search results by calling lonmysql. Stores the
table id in $env{'form.table'}
-Inputs: none.
+Inputs: search area - either res or portfolio
Returns: the identifier of the table on success, undef on error.
@@ -2179,8 +2336,9 @@ Returns: the identifier of the table on
######################################################################
######################################################################
sub set_up_table_structure {
+ my ($tabletype) = @_;
my ($datatypes,$fullindicies) =
- &LONCAPA::lonmetadata::describe_metadata_storage();
+ &LONCAPA::lonmetadata::describe_metadata_storage($tabletype);
# Copy the table description before modifying it...
@Datatypes = @{$datatypes};
unshift(@Datatypes,{name => 'id',
@@ -2193,7 +2351,12 @@ sub set_up_table_structure {
}
sub create_results_table {
- &set_up_table_structure();
+ my ($area) = @_;
+ if ($area eq 'portfolio') {
+ &set_up_table_structure('portfolio_search');
+ } else {
+ &set_up_table_structure('metadata');
+ }
my $table = &Apache::lonmysql::create_table
( { columns => \@Datatypes,
FULLTEXT => [{'columns' => \@Fullindicies},],
@@ -2299,13 +2462,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;
}
@@ -2325,22 +2489,23 @@ results into MySQL.
######################################################################
######################################################################
sub run_search {
- my ($r,$query,$customquery,$customshow,$serverlist,$pretty_string) = @_;
-
+ my ($r,$query,$customquery,$customshow,$serverlist,
+ $pretty_string,$area) = @_;
+ my $tabletype = 'metadata';
+ if ($area eq 'portfolio') {
+ $tabletype = 'portfolio_search';
+ }
my $connection = $r->connection;
#
# Print run_search header
#
- my $start_page = &Apache::loncommon::start_page('Search Status',undef,
- {'only_body' => 1});
+ my $start_page = &Apache::loncommon::start_page('Search Status',undef);
my $breadcrumbs =
&Apache::lonhtmlcommon::breadcrumbs('Searching','Searching',
- $env{'form.catalogmode'} ne 'groupsearch');
+ $env{'form.catalogmode'} ne 'import');
$r->print(<
-
END
# Remove leading and trailing
$pretty_string =~ s:^\s* ::i;
@@ -2351,7 +2516,7 @@ END
pop(@Lines);
}
if (@Lines > 2) {
- $pretty_string = join ' ',(@Lines[0..2],'.... ');
+ $pretty_string = join ' ',(@Lines[0..2],'... ');
}
$r->print(&mt("Search: [_1]",$pretty_string));
$r->rflush();
@@ -2365,14 +2530,15 @@ END
@Servers_to_contact = ($serverlist);
}
} else {
- @Servers_to_contact = sort(keys(%Apache::lonnet::libserv));
+ my %all_library_servers = &Apache::lonnet::all_library();
+ @Servers_to_contact = sort(keys(%all_library_servers));
}
my %Server_status;
#
# Check on the mysql table we will use to store results.
my $table =$env{'form.table'};
if (! defined($table) || $table eq '' || $table =~ /\D/ ) {
- $r->print("Unable to determine table id to store search results in.".
+ $r->print("Unable to determine table id to save search results in.".
"The search has been aborted.".
&Apache::loncommon::end_page());
return;
@@ -2401,21 +2567,26 @@ END
##
## Prepare for the big loop.
my $hitcountsum;
+ my %matches;
my $server;
my $status;
my $revise = &revise_button();
- $r->print(<
-
END
foreach my $field ('title','author','domain','subject','keywords','notes',
'mimetag','language','creationdate','lastrevisiondate',
@@ -3448,7 +3649,7 @@ END
}
$result .= "