';
+}
+
######################################################################
-=pod
+=pod
+=over 4
+
=item &print_basic_search_form()
Prints the form for the basic search. Sorry the name is so cryptic.
@@ -438,19 +517,31 @@ Prints the form for the basic search. S
######################################################################
sub print_basic_search_form {
my ($r,$closebutton,$hidden_fields) = @_;
+ my %lt = &Apache::lonlocal::texthash (
+ res => 'Content Library Search',
+ portfolio => 'Portfolio Search',
+ );
my $result = ($env{'form.catalogmode'} ne 'import');
+ my $area;
my $bread_crumb =
&Apache::lonhtmlcommon::breadcrumbs('Searching','Search_Basic',
$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'})) {
- $scrout .= &setup_basic_search($r,'res',$hidden_fields,$closebutton);
- $scrout .= ' ';
- }
+ my $scrout = &Apache::loncommon::start_page('Content Library').$bread_crumb.
+ '
'."\n".
+ &start_search_tabs();
+ if (&Apache::lonnet::allowed('bre',$env{'request.role.domain'}) eq 'F') {
+ if ($env{'form.area'} eq 'portfolio') {
# Search form for accessible portfolio files
- $scrout.= &setup_basic_search($r,'portfolio',$hidden_fields,$closebutton);
- $scrout .= &Apache::loncommon::end_page();
+ $scrout .= &setup_basic_search($r,'portfolio',$hidden_fields,$closebutton);
+ } else {
+# Search form for resource space
+ $scrout .= &setup_basic_search($r,'res',$hidden_fields,$closebutton);
+ }
+ } else {
+# Search form for accessible portfolio files
+ $scrout .= &setup_basic_search($r,'portfolio',$hidden_fields,$closebutton);
+ }
+ $scrout .= &end_search_tabs().&Apache::loncommon::end_page();
$r->print($scrout);
return;
}
@@ -459,7 +550,7 @@ sub setup_basic_search {
my ($r,$area,$hidden_fields,$closebutton) = @_;
# Define interface components
my %lt = &Apache::lonlocal::texthash (
- res => 'LON-CAPA Catalog Search',
+ res => 'Content Library Search',
portfolio => 'Portfolio Search',
);
my ($userelatedwords,$onlysearchdomain,$inclext,$adv_search_link,$scrout);
@@ -473,14 +564,31 @@ sub setup_basic_search {
.&mt('use related words')
.'';
+ my $anydom = 1;
+ if ($area eq 'res') {
+ unless (&Apache::lonnet::allowed('bre','/res/') eq 'F') {
+ $anydom = 0;
+ }
+ }
+ my $singledom;
+ my ($disabled,$checked);
+ if ($anydom) {
+ $singledom = $r->dir_config('lonDefDomain');
+ if ($env{'form.domains'} eq $singledom) {
+ $checked = 1;
+ }
+ } else {
+ $singledom = $env{'user.domain'};
+ $disabled = ' disabled="disabled"';
+ $checked = 1;
+ }
$onlysearchdomain = '';
$adv_search_link = '';
}
#
- $scrout .= '
'.$/;
-# if ($env{'request.course.id'}) {
- $scrout .= '
'.$lt{$area}.'
';
-# } else {
- # No need to tell them they are searching
-# $scrout.= (' 'x2);
-# }
- $scrout.='
'
.&mt('Unable to retrieve search results. '
.'Unable to determine the table results were saved in.')
+ .'
'
+ . '
'.&mt('Internal info:').'
'
+ .'
'.$table.'
'
.&Apache::loncommon::end_page()
);
return undef;
@@ -1914,9 +2129,12 @@ sub ensure_db_and_table {
##
my $connection_result = &Apache::lonmysql::connect_to_db();
if (!defined($connection_result)) {
- $r->print("Unable to connect to the MySQL database where your results".
- " are saved.".
- &Apache::loncommon::end_page());
+ $r->print(
+ '
'
+ .&mt('Unable to connect to the MySQL database where your results are saved.')
+ .'
'
+ .&Apache::loncommon::end_page()
+ );
&Apache::lonnet::logthis("lonsearchcat: unable to get lonmysql to".
" connect to database.");
&Apache::lonnet::logthis(&Apache::lonmysql::get_error());
@@ -1924,13 +2142,20 @@ sub ensure_db_and_table {
}
my $table_check = &Apache::lonmysql::check_table($table);
if (! defined($table_check)) {
- $r->print("A MySQL error has occurred.".
- &Apache::loncommon::end_page());
+ $r->print(
+ '
'
+ .&mt('A MySQL error has occurred.')
+ .'
'
+ .&Apache::loncommon::end_page());
&Apache::lonnet::logthis("lonmysql was unable to determine the status".
" of table ".$table);
return undef;
} elsif (! $table_check) {
- $r->print("The table of results could not be found.");
+ $r->print(
+ '
'
+ .&mt('The table of results could not be found.')
+ .'
'
+ );
&Apache::lonnet::logthis("The user requested a table, ".$table.
", that could not be found.");
return undef;
@@ -1953,7 +2178,7 @@ a link to change the search query.
######################################################################
######################################################################
sub print_sort_form {
- my ($r,$pretty_query_string) = @_;
+ my ($r,$pretty_query_string,$target) = @_;
##
my %SortableFields=&Apache::lonlocal::texthash(
@@ -1986,29 +2211,20 @@ sub print_sort_form {
&Apache::lonnet::logthis(&Apache::lonmysql::get_error());
return;
}
- my $js =<
-// $target};
}
-// ]]>
-
-END
-
- my $start_page = &Apache::loncommon::start_page('Results',$js);
+ my $start_page = &Apache::loncommon::start_page('Results',undef,$args);
my $breadcrumbs=
&Apache::lonhtmlcommon::breadcrumbs('Searching','Searching',
- $env{'form.catalogmode'} ne 'import');
-
+ $env{'form.catalogmode'} ne 'import',
+ '','','','','','',$target);
my $result = <
+
'.&Apache::loncommon::end_page());
return;
}
@@ -2164,8 +2380,22 @@ SCRIPT
$r->rflush();
}
+sub reload_result_frame {
+ my ($r) = @_;
+ my $newloc = '/adm/searchcat?phase=results&persistent_db_id='.
+ $env{'form.persistent_db_id'}.'&area='.$env{'form.area'}.
+ '&catalogmode='.$env{'form.catalogmode'};
+ $r->print(<
+SCRIPT
+
+ $r->rflush();
+}
+
{
- my $max_time = 300; # seconds for the search to complete
+ my $max_time = 60; # seconds for the search to complete
my $start_time = 0;
my $last_time = 0;
@@ -2224,7 +2454,9 @@ sub revise_button {
my $newloc = '/adm/searchcat'.
'?persistent_db_id='.$env{'form.persistent_db_id'}.
'&cleargroupsort=1'.
- '&phase='.$revise_phase;
+ '&phase='.$revise_phase.
+ '&area='.$env{'form.area'}.
+ '&catalogmode='.$env{'form.catalogmode'};
my $result = qq{ };
return $result;
@@ -2246,7 +2478,7 @@ results into MySQL.
######################################################################
sub run_search {
my ($r,$query,$customquery,$customshow,$serverlist,
- $pretty_string,$area) = @_;
+ $pretty_string,$area,$domainsref,$target) = @_;
my $tabletype = 'metadata';
if ($area eq 'portfolio') {
$tabletype = 'portfolio_search';
@@ -2255,13 +2487,19 @@ sub run_search {
#
# Print run_search header
#
- my $start_page = &Apache::loncommon::start_page('Search Status',undef);
+ my $args;
+ if ($target eq '_parent') {
+ $args = {'links_target' => $target};
+ }
+ my $start_page = &Apache::loncommon::start_page('Search Status',undef,$args);
my $breadcrumbs =
&Apache::lonhtmlcommon::breadcrumbs('Searching','Searching',
- $env{'form.catalogmode'} ne 'import');
+ $env{'form.catalogmode'} ne 'import',
+ '','','','','','',$target);
$r->print(<
END
# Remove leading and trailing
$pretty_string =~ s:^\s* ::i;
@@ -2278,16 +2516,37 @@ END
$r->rflush();
#
# Determine the servers we need to contact.
- my @Servers_to_contact;
+ my (@Servers_to_contact,%domains_by_server);
if (defined($serverlist)) {
if (ref($serverlist) eq 'ARRAY') {
@Servers_to_contact = @$serverlist;
} else {
@Servers_to_contact = ($serverlist);
}
+ if (ref($domainsref) eq 'HASH') {
+ foreach my $server (@Servers_to_contact) {
+ $domains_by_server{$server} = $domainsref->{$server};
+ }
+ }
} else {
- my %all_library_servers = &Apache::lonnet::unique_library();
+ my %library_servers = &Apache::lonnet::unique_library();
+ my (%all_library_servers, %older_library_servers);
+ foreach my $key (keys(%library_servers)) {
+ if (&Apache::lonnet::get_server_loncaparev('',$key) =~ /^\'?(\d+)\.(\d+)/) {
+ my $major = $1;
+ my $minor = $2;
+ if (($major < 2) || (($major == 2) && ($minor < 11))) {
+ map { $older_library_servers{$_} = 1; }
+ &Apache::lonnet::machine_ids($library_servers{$key});
+ }
+ }
+ }
+ %all_library_servers = (%library_servers,%older_library_servers);
@Servers_to_contact = sort(keys(%all_library_servers));
+ foreach my $server (@Servers_to_contact) {
+ $domains_by_server{$server} =
+ join(',',sort(&Apache::lonnet::machine_domains($all_library_servers{$server})));
+ }
}
my %Server_status;
#
@@ -2323,6 +2582,8 @@ END
##
## Prepare for the big loop.
my $hitcountsum;
+ my $oldhitcountsum;
+ my $displaycount;
my %matches;
my $server;
my $status;
@@ -2357,7 +2618,7 @@ END
my $server = shift(@Servers_to_contact);
&update_status($r,&mt('contacting [_1]',$server));
my $reply=&Apache::lonnet::metadata_query($query,$customquery,
- $customshow,[$server]);
+ $customshow,[$server],\%domains_by_server);
($server) = keys(%$reply);
$Server_status{$server} = $reply->{$server};
} else {
@@ -2369,7 +2630,7 @@ END
&update_status($r,
&mt('waiting on [_1]',join(' ',keys(%Server_status))));
}
- sleep(1);
+ sleep(0.1);
}
#
# Loop through the servers we have contacted but do not
@@ -2383,7 +2644,10 @@ END
next;
}
$status=~s|/||g;
- my $datafile=$r->dir_config('lonDaemons').'/tmp/'.$status;
+
+
+
+ my $datafile=LONCAPA::tempdir().$status;
if (-e $datafile && ! -e "$datafile.end") {
&update_status($r,&mt('Receiving results from [_1]',$server));
next;
@@ -2419,8 +2683,8 @@ END
if ($area eq 'portfolio') {
next if (defined($matches{$Fields{'url'}}));
- # Skip if inaccessible
- next if (!&Apache::lonnet::portfolio_access($Fields{'url'}));
+ # Skip unless access control set to public or passphrase-protected
+ next unless (($Fields{'scope'} eq 'public') || ($Fields{'scope'} eq 'guest'));
$matches{$Fields{'url'}} = 1;
}
#
@@ -2442,7 +2706,15 @@ END
delete($Server_status{$server});
}
last if ($connection->aborted());
- &update_count_status($r,$hitcountsum);
+ if ($oldhitcountsum < $hitcountsum) {
+ &update_count_status($r,$hitcountsum);
+ if (($hitcountsum <= $env{'form.show'}) ||
+ (!$displaycount && $hitcountsum)) {
+ reload_result_frame($r);
+ $displaycount = $hitcountsum;
+ }
+ $oldhitcountsum = $hitcountsum;
+ }
}
last if ($connection->aborted());
&update_seconds($r);
@@ -2455,11 +2727,11 @@ END
# We have run out of time or run out of servers to talk to and
# results to get, so let the client know the top frame needs to be
# loaded from /adm/searchcat
- $r->print(&Apache::loncommon::end_page());
+ $r->print('
'.&Apache::loncommon::end_page());
# if ($env{'form.catalogmode'} ne 'import') {
$r->print(<
SCRIPT
# }
@@ -2519,7 +2791,8 @@ sub display_results {
if (!defined($viewfunction)) {
$r->print('
'
.&mt('Internal Error - Bad view selected.')
- .'
'."\n");
+ .''."\n"
+ .''.&Apache::loncommon::end_page());
$r->rflush();
return;
}
@@ -2530,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
@@ -2556,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);
@@ -2661,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
@@ -2685,16 +2966,15 @@ sub display_results {
);
if ($total_results == 0) {
- $r->print(''.
- '