--- loncom/interface/lonsearchcat.pm 2014/01/14 18:54:56 1.341
+++ loncom/interface/lonsearchcat.pm 2025/03/19 15:44:44 1.364
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Search Catalog
#
-# $Id: lonsearchcat.pm,v 1.341 2014/01/14 18:54:56 bisitz Exp $
+# $Id: lonsearchcat.pm,v 1.364 2025/03/19 15:44:44 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -78,6 +78,7 @@ use Apache::lonnavmaps;
use Apache::lonindexer();
use Apache::lonwishlist();
use LONCAPA;
+use Time::HiRes qw(sleep);
######################################################################
######################################################################
@@ -143,7 +144,7 @@ sub handler {
## this once, so the pause indicator is deleted
##
if (exists($env{'form.pause'})) {
- sleep(1);
+ sleep(0.1);
delete($env{'form.pause'});
}
##
@@ -169,22 +170,46 @@ sub handler {
##
&Apache::lonhtmlcommon::clear_breadcrumbs();
- my @allowed_searches = ('portfolio');
- if (&Apache::lonnet::allowed('bre',$env{'request.role.domain'})) {
+ my $crumb_text;
+ my @allowed_searches;
+ if ($env{'form.catalogmode'} eq 'import') {
+ $env{'form.area'} = 'res';
+ $crumb_text = 'Content Library Search';
+ } else {
+ push(@allowed_searches,'portfolio');
+ }
+ if (&Apache::lonnet::allowed('bre',$env{'request.role.domain'}) eq 'F') {
push(@allowed_searches,'res');
- }
- my $crumb_text = 'Portfolio Search';
+ } else {
+ unless ($env{'form.catalogmode'} eq 'import') {
+ $env{'form.area'} = 'portfolio';
+ $crumb_text = 'Portfolio Search';
+ }
+ }
if (@allowed_searches ==2) {
- $crumb_text = 'Portfolio and Catalog Search';
+ unless (($env{'form.area'} eq 'portfolio') || ($env{'form.area'} eq 'res')) {
+ delete($env{'form.area'});
+ }
+ $crumb_text = 'Portfolio and Content Library Search';
+ }
+ my $target = '_top';
+ if ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
+ (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
+ if ($env{'form.phase'} =~ /^(sort|run_search)$/) {
+ $target = '_parent';
+ } else {
+ $target = '_self';
+ }
}
&Apache::lonhtmlcommon::add_breadcrumb
({href=>'/adm/searchcat?'.
&Apache::loncommon::inhibit_menu_check().
'&catalogmode='.$env{'form.catalogmode'}.
'&launch='.$env{'form.launch'}.
- '&mode='.$env{'form.mode'},
+ '&mode='.$env{'form.mode'}.
+ '&area='.$env{'form.area'},
text=>"$crumb_text",
- target=>'_top',
+ target=>$target,
bug=>'Searching',});
#
if ($env{'form.phase'} !~ m/(basic|adv|course)_search/) {
@@ -193,7 +218,7 @@ sub handler {
&Apache::lonnet::logthis('lonsearchcat:'.
'Unable to recover data from '.
$persistent_db_file);
- my $msg =
+ my $msg =
&mt('We were unable to retrieve data describing your search.').
' '.&mt('This is a serious error and has been logged.').
'
'.
@@ -298,7 +323,7 @@ END
}
#
if ($env{'form.searchmode'} eq 'advanced') {
- my $srchtype = 'Catalog';
+ my $srchtype = 'Content Library';
if ($env{'form.area'} eq 'portfolio') {
$srchtype = 'Portfolio';
}
@@ -307,10 +332,23 @@ END
'&phase=disp_adv'.
'&catalogmode='.$env{'form.catalogmode'}.
'&launch='.$env{'form.launch'}.
- '&mode='.$env{'form.mode'},
+ '&mode='.$env{'form.mode'}.
+ '&area='.$env{'form.area'},
text=>"Advanced $srchtype Search",
bug=>'Searching',});
- }
+ } elsif (($env{'form.phase'} eq 'results') ||
+ ($env{'form.phase'} =~ /^(sort|run_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'}.
+ '&area='.$env{'form.area'}.
+ '&searchmode='.$env{'form.searchmode'},
+ text=>"Search Results",
+ bug=>'Searching',});
+ }
##
## Switch on the phase
##
@@ -327,10 +365,10 @@ END
['query','customquery','customshow',
'libraries','pretty_string','domains']);
if ($env{'form.phase'} eq 'sort') {
- &print_sort_form($r,$pretty_string);
+ &print_sort_form($r,$pretty_string,$target);
} elsif ($env{'form.phase'} eq 'run_search') {
&run_search($r,$query,$customquery,$customshow,
- $libraries,$pretty_string,$env{'form.area'},$domainsref);
+ $libraries,$pretty_string,$env{'form.area'},$domainsref,$target);
}
} elsif(($env{'form.phase'} eq 'basic_search') ||
($env{'form.phase'} eq 'adv_search')) {
@@ -389,7 +427,7 @@ END
}
}
return OK;
-}
+}
#
# The mechanism used to store values away and retrieve them does not
@@ -427,6 +465,42 @@ sub hidden_field {
return ''.$/;
}
+sub start_search_tabs {
+ my $area;
+ my %lt = &Apache::lonlocal::texthash (
+ res => 'Content Library Search',
+ portfolio => 'Portfolio Search',
+ );
+ my $output = '
'.
- &Apache::lonhtmlcommon::textbox('basicexp',
- $env{'form.basicexp'},50).
- ' '. - ''.&searchhelp().''.' | '.
- ''.
- ''.(' 'x3).$adv_search_link.''.' '. - ''.(' 'x1).$userelatedwords.''.' '. - ''.(' 'x1).$onlysearchdomain.''.' '. - ''.(' 'x1).$inclext.''.' '. - ' | '.
- '
' + $scrout .= '
' .&viewoptions() .'
' .'' @@ -538,9 +632,9 @@ sub setup_basic_search { .'value="'.&mt('Search').'" />' .' ' .$closebutton - .'
'; + .'' .&mt('Internal Error - Bad view selected.') - .'
'."\n"); + .''."\n" + .''.&Apache::loncommon::end_page()); $r->rflush(); return; } @@ -2620,20 +2803,27 @@ sub display_results { ## ## Get the catalog controls setup ## - my $action = "/adm/searchcat?phase=results"; + my $action = '/adm/searchcat?phase=results&area='.$env{'form.area'}. + '&catalogmode='.$env{'form.catalogmode'}; ## ## Deal with import by opening the import db file. if ($env{'form.catalogmode'} eq 'import') { if (! tie(%groupsearch_db,'GDBM_File',$diropendb, &GDBM_WRCREAT(),0640)) { + # NOTE: this can happen when a previous request to searchcat?phase=results gets interrupted + # (%groupsearch_db is not untied) $r->print(''. &mt('Unable to save import results.'). '
'. - ''. + ''. &Apache::loncommon::end_page()); $r->rflush(); return; } + # untie %groupsearch_db if the connection gets aborted before the end + $r->register_cleanup(sub { + untie %groupsearch_db if (tied(%groupsearch_db)); + }); } ## ## Prepare the table for querying @@ -2646,7 +2836,7 @@ sub display_results { $r->print(''. &mt('A MySQL error has occurred.'). '
'. - ''. + ''. &Apache::loncommon::end_page()); &Apache::lonnet::logthis("lonmysql was unable to determine the number". " of rows in table ".$table); @@ -2751,17 +2941,18 @@ sub display_results { $env{'form.sortorder'}='asc'; } } - my $sortform = '' - .&mt('Sort by:').' ' + my $sortform = '' + .&mt('Sort by:').' ' .&Apache::loncommon::select_form($env{'form.sortfield'}, - 'sortfield', - \%sort_fields) + 'sortfield', + \%sort_fields,'','','', + 'LC_sortby') .' ' .&Apache::loncommon::select_form($env{'form.sortorder'}, - 'sortorder', - {asc =>&mt('Ascending'), - desc=>&mt('Descending') - }) + 'sortorder', + {asc =>&mt('Ascending'), + desc=>&mt('Descending') + },'','','','LC_sortby') .''; ## ## Display links for 'prev' and 'next' pages (if necessary) and Display Options @@ -2775,16 +2966,15 @@ sub display_results { ); if ($total_results == 0) { - $r->print(''. - ''.&mt('There are currently no results.').'
'. - "". + $r->print('