END
- my $scrout= &Apache::loncommon::start_page('Advanced Catalog Search');
- $scrout .= <<"ENDHEADER";
-$bread_crumb
-';
+
$scrout .= &Apache::loncommon::end_page();
$r->print($scrout);
return;
@@ -1074,17 +909,20 @@ sub viewoptions {
if (! defined($env{'form.viewselect'})) {
$env{'form.viewselect'}='detailed';
}
- $scrout.=&Apache::lonmeta::selectbox('viewselect',
- $env{'form.viewselect'},
- \&viewoptiontext,
- sort(keys(%Views)));
- $scrout.= ' ';
+ $scrout .= ''
+ .&mt('Type:').' '
+ .&Apache::lonmeta::selectbox('viewselect',
+ $env{'form.viewselect'},
+ \&viewoptiontext,
+ sort(keys(%Views)))
+ .'';
my $countselect = &Apache::lonmeta::selectbox('show',
$env{'form.show'},
undef,
(10,20,50,100,1000,10000));
- $scrout .= (' 'x2).&mt('[_1] Records per Page',$countselect).
- ''.$/;
+ $scrout .= ' '
+ .&mt('Records per Page:').' '.$countselect
+ .''.$/;
return $scrout;
}
@@ -1175,8 +1013,9 @@ Outputs: array of values. Returns undef
This function is the reverse of &make_persistent();
Retrieve persistent data from %persistent_db. Retrieved items will have their
-values unescaped. If the item contains commas (before unescaping), the
-returned value will be an array pointer.
+values unescaped. If the item is 'domains; then the returned
+value will be a hash pointer. Otherwise, if the item contains
+commas (before unescaping), the returned value will be an array pointer.
=cut
@@ -1194,13 +1033,25 @@ sub get_persistent_data {
push @Values, undef;
next;
}
- my @values = map {
- &unescape($_);
- } split(',',$persistent_db{$name});
- if (@values <= 1) {
- push @Values,$values[0];
+ if ($name eq 'domains') {
+ my %valueshash;
+ my @items= map { &unescape($_); } split(',',$persistent_db{$name});
+ foreach my $item (@items) {
+ if ($item =~ /=/) {
+ my ($key,$val) = map { &unescape($_); } split(/=/,$item);
+ $valueshash{$key} = $val;
+ }
+ }
+ push(@Values,\%valueshash);
} else {
- push @Values,\@values;
+ my @values = map {
+ &unescape($_);
+ } split(',',$persistent_db{$name});
+ if (@values <= 1) {
+ push @Values,$values[0];
+ } else {
+ push @Values,\@values;
+ }
}
}
untie (%persistent_db);
@@ -1218,7 +1069,9 @@ Inputs: Hash of values to save, filename
Store variables away to the %persistent_db.
Values will be escaped. Values that are array pointers will have their
-elements escaped and concatenated in a comma separated string.
+elements escaped and concatenated in a comma separated string. Values
+that are hash pointers will have their keys and values escaped and
+concatenated in a comma separated string.
=cut
@@ -1230,8 +1083,17 @@ sub make_persistent {
return undef if (! tie(%persistent_db,'GDBM_File',
$filename,&GDBM_WRCREAT(),0640));
foreach my $name (keys(%save)) {
- my @values = (ref($save{$name}) ? @{$save{$name}} : ($save{$name}));
- # We handle array references, but not recursively.
+ my @values=();
+ if (ref($save{$name}) eq 'ARRAY') {
+ @values = @{$save{$name}};
+ } elsif (ref($save{$name}) eq 'HASH') {
+ foreach my $key (%{$save{$name}}) {
+ push(@values,&escape($key).'='.&escape($save{$name}{$key}));
+ }
+ } else {
+ @values = $save{$name};
+ }
+ # We handle array and hash references, but not recursively.
my $store = join(',', map { &escape($_); } @values );
$persistent_db{$name} = $store;
}
@@ -1310,7 +1172,7 @@ sub parse_advanced_search {
'lastrevisiondatestart_month','lastrevisiondatestart_day',
'lastrevisiondatestart_year','lastrevisiondateend_month',
'lastrevisiondateend_day','lastrevisiondateend_year') {
- $env{'form.'.$field}=~s/[^\w\/\s\(\)\=\-\"\']//g;
+ $env{'form.'.$field}=~s/[^\w\/\s\(\)\=\-\"\'.\*]//g;
}
foreach ('mode','form','element') {
# is this required? Hmmm.
@@ -1343,6 +1205,17 @@ sub parse_advanced_search {
$fillflag++;
}
}
+ if ($env{'form.area'} eq 'portfolio') {
+ # Added metadata fields
+ for (my $i=0; $i<$env{'form.numaddedfields'} ; $i++) {
+ my $field = $env{'form.addedfield_'.$i};
+ $field =~ s/^\s*(\S*)\s*$/$1/;
+ $field =~ s/\W/_/g;
+ if ($field ne '') {
+ $fillflag++;
+ }
+ }
+ }
if (! $fillflag) {
&output_blank_field_error($r,$closebutton,
'phase=disp_adv',$hidden_fields);
@@ -1429,29 +1302,56 @@ sub parse_advanced_search {
&Apache::loncommon::copyrightdescription($env{'form.copyright'}).
" \n";
}
- #
- # Statistics
- foreach my $field (@StatsFields,@EvalFields) {
- my ($min,$max);
- if (exists($env{'form.'.$field.'_min'}) &&
- $env{'form.'.$field.'_min'} ne '') {
- $min = $env{'form.'.$field.'_min'};
- }
- if (exists($env{'form.'.$field.'_max'}) &&
- $env{'form.'.$field.'_max'} ne '') {
- $max = $env{'form.'.$field.'_max'};
- }
- next if (! defined($max) && ! defined($min));
- if (defined($min) && defined($max)) {
- ($min,$max) = sort {$a <=>$b} ($min,$max);
- }
- if (defined($min) && $min =~ /^(\d+\.\d+|\d+|\.\d+)$/) {
- push(@queries,'('.$field.'>'.$min.')');
- $pretty_search_string.=$font.$field.'>'.$min.' ';
- }
- if (defined($max) && $max =~ /^(\d+\.\d+|\d+|\.\d+)$/) {
- push(@queries,'('.$field.'<'.$max.')');
- $pretty_search_string.=$font.$field.'<'.$max.' ';
+ if ($env{'form.area'} eq 'portfolio') {
+ #
+ # Added metadata fields
+ for (my $i=0; $i<$env{'form.numaddedfields'} ; $i++) {
+ my $field = $env{'form.addedfield_'.$i};
+ $field =~ s/^\s*(\S*)\s*$/$1/;
+ $field =~ s/\W/_/g;
+ $field =~ tr/A-Z/a-z/;
+ if ($field ne '') {
+ my $value = $env{'form.addedvalues_'.$i};
+ if ($value ne '') {
+ $value =~ s/'/''/g; #' stupid emacs
+ my ($error,$query) =
+ &process_phrase_input($value,0,'pf.value');
+ if (!defined($error)) {
+ push(@queries,"pf.field = '$field' AND $query");
+ $pretty_search_string .=
+ $font.$field.': '.
+ $env{'form.addedvalues_'.$i}.' ';
+ }
+ } else {
+ push(@queries,"pf.field = '$field' AND pf.value IS NULL");
+ }
+ }
+ }
+ } else {
+ #
+ # Statistics
+ foreach my $field (@StatsFields,@EvalFields) {
+ my ($min,$max);
+ if (exists($env{'form.'.$field.'_min'}) &&
+ $env{'form.'.$field.'_min'} ne '') {
+ $min = $env{'form.'.$field.'_min'};
+ }
+ if (exists($env{'form.'.$field.'_max'}) &&
+ $env{'form.'.$field.'_max'} ne '') {
+ $max = $env{'form.'.$field.'_max'};
+ }
+ next if (! defined($max) && ! defined($min));
+ if (defined($min) && defined($max)) {
+ ($min,$max) = sort {$a <=>$b} ($min,$max);
+ }
+ if (defined($min) && $min =~ /^(\d+\.\d+|\d+|\.\d+)$/) {
+ push(@queries,'('.$field.'>'.$min.')');
+ $pretty_search_string.=$font.$field.'>'.$min.' ';
+ }
+ if (defined($max) && $max =~ /^(\d+\.\d+|\d+|\.\d+)$/) {
+ push(@queries,'('.$field.'<'.$max.')');
+ $pretty_search_string.=$font.$field.'<'.$max.' ';
+ }
}
}
#
@@ -1510,23 +1410,29 @@ sub parse_advanced_search {
##
## Deal with restrictions to given domains
##
- my ($libraries_to_query,$pretty_domains_string) = &parse_domain_restrictions();
+ my ($libraries_to_query,$pretty_domains_string,$domains_to_query) =
+ &parse_domain_restrictions();
if ($pretty_domains_string) {
$pretty_search_string .= $pretty_domains_string." \n";
}
#
if (@queries) {
- $query="SELECT * FROM metadata WHERE (".join(") AND (",@queries).')';
+ if ($env{'form.area'} eq 'portfolio') {
+ $query ="SELECT pm.*,pa.keynum,pa.scope FROM portfolio_metadata pm, portfolio_access pa, portfolio_addedfields pf WHERE (pm.url = pa.url AND pf.url = pm.url AND (pa.start < UTC_TIMESTAMP() AND (pa.end IS NULL OR pa.end > UTC_TIMESTAMP())) AND (".join(') AND (',@queries).'))';
+ } else {
+ $query="SELECT * FROM metadata WHERE (".join(") AND (",@queries).')';
+ }
} elsif ($customquery) {
$query = '';
}
#&Apache::lonnet::logthis('advanced query = '.$/.$query);
return ($query,$customquery,$customshow,$libraries_to_query,
- $pretty_search_string);
+ $pretty_search_string,$domains_to_query);
}
sub parse_domain_restrictions {
my $libraries_to_query = undef;
+ my $domains_to_query = undef;
# $env{'form.domains'} can be either a scalar or an array reference.
# We need an array.
if (! exists($env{'form.domains'}) || $env{'form.domains'} eq '') {
@@ -1540,24 +1446,42 @@ sub parse_domain_restrictions {
$domain_hash{$_}++;
}
if ($domain_hash{'any'}) {
- $pretty_domains_string = "In all LON-CAPA domains.";
+ $pretty_domains_string = &mt("in all LON-CAPA domains.");
} else {
if (@allowed_domains > 1) {
- $pretty_domains_string = "In LON-CAPA domains:";
+ $pretty_domains_string = &mt("in LON-CAPA domains:");
} else {
- $pretty_domains_string = "In LON-CAPA domain ";
+ $pretty_domains_string = &mt("in LON-CAPA domain ");
}
foreach (sort @allowed_domains) {
$pretty_domains_string .= "".$_." ";
}
- foreach (keys(%Apache::lonnet::libserv)) {
- if (exists($domain_hash{$Apache::lonnet::hostdom{$_}})) {
- push @$libraries_to_query,$_;
+ my %library_servers = &Apache::lonnet::get_unique_servers(\@allowed_domains,
+ 'library');
+ my (%older_library_servers,%okdoms,%domains_for_id);
+ map { $okdoms{$_} = 1; } @allowed_domains;
+ 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});
+ } else {
+ my %possdoms;
+ map { $possdoms{$_}=1 if ($okdoms{$_}); }
+ &Apache::lonnet::machine_domains($library_servers{$key});
+ $domains_for_id{$key} = join(',',sort(keys(%possdoms)));
+ }
}
}
+ my %servers = (%library_servers,%older_library_servers);
+ $libraries_to_query = [keys(%servers)];
+ $domains_to_query = \%domains_for_id;
}
return ($libraries_to_query,
- $pretty_domains_string);
+ $pretty_domains_string,
+ $domains_to_query);
}
######################################################################
@@ -1578,7 +1502,7 @@ sub parse_basic_search {
#
# Clean up fields for safety
for my $field ('basicexp') {
- $env{"form.$field"}=~s/[^\w\s\'\"\!\(\)\-]//g;
+ $env{"form.$field"}=~s/[^\w\s\'\"\!\(\)\-\*]//g;
}
foreach ('mode','form','element') {
# is this required? Hmmm.
@@ -1586,7 +1510,8 @@ sub parse_basic_search {
$env{"form.$_"}=&unescape($env{"form.$_"});
$env{"form.$_"}=~s/[^\w\/\s\(\)\=\-\"\']//g;
}
- my ($libraries_to_query,$pretty_domains_string) = &parse_domain_restrictions();
+ my ($libraries_to_query,$pretty_domains_string,$domains_to_query) =
+ &parse_domain_restrictions();
#
# Check to see if enough of a query is filled in
my $search_string = $env{'form.basicexp'};
@@ -1596,10 +1521,13 @@ sub parse_basic_search {
}
my $pretty_search_string=$search_string;
my @Queries;
- my $searchfield = 'concat_ws(" ",'.join(',',
- ('title','author','subject',
- 'notes','abstract','keywords')
- ).')';
+ my @fields = ('title','author','subject','notes','abstract','keywords');
+ my $searchfield;
+ if ($env{'form.area'} eq 'portfolio') {
+ $searchfield = 'concat_ws(" ",pm.'.join(',pm.',@fields).')';
+ } else {
+ $searchfield = 'concat_ws(" ",'.join(',',@fields).')';
+ }
my ($error,$SQLQuery) = &process_phrase_input($search_string,
$env{'form.related'},
$searchfield);
@@ -1612,16 +1540,24 @@ sub parse_basic_search {
#foreach my $q (@Queries) {
# &Apache::lonnet::logthis(' '.$q);
#}
- my $final_query = 'SELECT * FROM metadata WHERE '.join(" AND ",@Queries);
+ my $final_query;
+ if ($env{'form.area'} eq 'portfolio') {
+ $final_query = 'SELECT pm.*,pa.keynum,pa.scope FROM portfolio_metadata pm, portfolio_access pa WHERE (pm.url = pa.url AND (pa.start < UTC_TIMESTAMP() AND (pa.end IS NULL OR pa.end > UTC_TIMESTAMP())) AND '.join(" AND ",@Queries).')';
+ } else {
+ $final_query = 'SELECT * FROM metadata WHERE '.join(" AND ",@Queries);
+ }
#
+ if ($env{'form.related'}) {
+ $pretty_search_string.=' '.&mt('(including related words)');
+ }
if (defined($pretty_domains_string) && $pretty_domains_string ne '') {
$pretty_search_string .= ' '.$pretty_domains_string;
}
$pretty_search_string .= " \n";
$pretty_search_string =~ s:^ and ::;
- #&Apache::lonnet::logthis('simple search final query = '.$/.$final_query);
+ &Apache::lonnet::logthis('simple search final query = '.$/.$final_query);
return ($final_query,$pretty_search_string,
- $libraries_to_query);
+ $libraries_to_query,$domains_to_query);
}
@@ -1722,7 +1658,7 @@ sub process_phrase_input {
$item[1];
}
term:
- /[\w\Q:!@#$%^&*()+_=|{}<>,.;\\\/?\E]+/ {
+ /[\w\Q:!@#$%^&*()+_=|{}<>,.;\\\/?\E\-]+/ {
$item[1];
}
ENDGRAMMAR
@@ -1893,14 +1829,14 @@ sub build_date_queries {
if ((defined($cafter) && ! defined($cbefore)) ||
(defined($cbefore) && ! defined($cafter))) {
# This is bad, so let them know
- $error = &mt('Incorrect entry for the creation date. '.
+ $error = &mt('Incorrect entry for the creation date. '.
'You must specify both the beginning and ending dates.');
}
if (! defined($error) &&
((defined($mafter) && ! defined($mbefore)) ||
(defined($mbefore) && ! defined($mafter)))) {
# This is also bad, so let them know
- $error = &mt('Incorrect entry for the last revision date. '.
+ $error = &mt('Incorrect entry for the last revision date. '.
'You must specify both the beginning and ending dates.');
}
if (! defined($error)) {
@@ -1982,6 +1918,10 @@ sub copyright_check {
($env{'user.domain'} ne $resdom)) {
return 0;
}
+ # Check for custom rights
+ if ($Metadata->{'copyright'} eq 'custom') {
+ return &Apache::lonnet::customaccess('bre',$Metadata->{'url'});
+ }
return 1;
}
@@ -2009,9 +1949,15 @@ sub ensure_db_and_table {
## Sanity check the table id.
##
if (! defined($table) || $table eq '' || $table =~ /\D/ ) {
- $r->print("Unable to retrieve search results. ".
- "Unable to determine the table results were stored in. ".
- &Apache::loncommon::end_page());
+ $r->print(&Apache::loncommon::start_page('Error')
+ .'
'
+ .&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;
}
##
@@ -2019,9 +1965,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 stored.".
- &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());
@@ -2029,13 +1978,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;
@@ -2093,6 +2049,7 @@ sub print_sort_form {
}
my $js =<
+//
END
- my $start_page = &Apache::loncommon::start_page('Results',$js,
- {'no_title' => 1});
+ my $start_page = &Apache::loncommon::start_page('Results',$js);
my $breadcrumbs=
&Apache::lonhtmlcommon::breadcrumbs('Searching','Searching',
$env{'form.catalogmode'} ne 'import');
@@ -2129,14 +2086,11 @@ END
# }
# $result.="\n";
my $revise = &revise_button();
- $result.=<
-There are $total_results matches to your query. $revise
-
-Search:$pretty_query_string
-
-
-END
+ $result.='
'
+ .&mt('Total of [quant,_1,match,matches] to your query.',$total_results)
+ .' '.$revise.'
'
+ .'
'.&mt('Search: ').$pretty_query_string
+ .'
';
$r->print($result.&Apache::loncommon::end_page());
return;
}
@@ -2173,7 +2127,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.
@@ -2182,8 +2136,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',
@@ -2196,7 +2151,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},],
@@ -2240,16 +2200,28 @@ Returns: Nothing.
sub update_count_status {
my ($r,$text) = @_;
$text =~ s/\'/\\\'/g;
- $r->print
- ("\n");
+ $r->print(<
+SCRIPT
+
$r->rflush();
}
sub update_status {
my ($r,$text) = @_;
$text =~ s/\'/\\\'/g;
- $r->print
- ("\n");
+ $r->print(<
+SCRIPT
+
$r->rflush();
}
@@ -2276,9 +2248,14 @@ sub update_seconds {
my ($r) = @_;
my $time = &time_left();
if (($last_time-$time) > 0) {
- $r->print("\n");
+ $r->print(<
+SCRIPT
+
$r->rflush();
}
$last_time = $time;
@@ -2302,14 +2279,15 @@ 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{ };
+ '&cleargroupsort=1'.
+ '&phase='.$revise_phase;
+ my $result = qq{ };
return $result;
}
@@ -2328,22 +2306,23 @@ results into MySQL.
######################################################################
######################################################################
sub run_search {
- my ($r,$query,$customquery,$customshow,$serverlist,$pretty_string) = @_;
-
+ my ($r,$query,$customquery,$customshow,$serverlist,
+ $pretty_string,$area,$domainsref) = @_;
+ 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,
- {'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(<
-
END
# Remove leading and trailing
$pretty_string =~ s:^\s* ::i;
@@ -2354,28 +2333,52 @@ 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();
#
# 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 {
- @Servers_to_contact = sort(keys(%Apache::lonnet::libserv));
+ 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) {
+ my %possdoms;
+ map { $possdoms{$_}=1; } &Apache::lonnet::machine_domains($all_library_servers{$server});
+ $domains_by_server{$server} =
+ join(',',sort(&Apache::lonnet::machine_domains($all_library_servers{$server})));
+ }
}
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;
@@ -2404,21 +2407,26 @@ END
##
## Prepare for the big loop.
my $hitcountsum;
+ my %matches;
my $server;
my $status;
my $revise = &revise_button();
- $r->print(<
-
'
+ .&mt('Internal Error - Bad view selected.')
+ .'
'."\n");
$r->rflush();
return;
}
@@ -2606,7 +2623,10 @@ sub display_results {
if ($env{'form.catalogmode'} eq 'import') {
if (! tie(%groupsearch_db,'GDBM_File',$diropendb,
&GDBM_WRCREAT(),0640)) {
- $r->print('Unable to store import results.'.
+ $r->print('
'.
+ &mt('Unable to save import results.').
+ '
'.
+ ''.
&Apache::loncommon::end_page());
$r->rflush();
return;
@@ -2620,7 +2640,10 @@ sub display_results {
## Get the number of results
my $total_results = &Apache::lonmysql::number_of_rows($table);
if (! defined($total_results)) {
- $r->print("A MySQL error has occurred.".
+ $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);
@@ -2651,7 +2674,8 @@ sub display_results {
$r->print(&hidden_field('table').
&hidden_field('phase').
&hidden_field('persistent_db_id').
- &hidden_field('start')
+ &hidden_field('start').
+ &hidden_field('area')
);
#
# Build sorting selector
@@ -2672,6 +2696,16 @@ sub display_results {
{key =>'lowestgradelevel'},
{key =>'highestgradelevel'},
{key =>'standards',desc=>'Standards'},
+ );
+ if ($area eq 'portfolio') {
+ push(@fields,
+ (
+ {key => 'scope'},
+ {key => 'keynum'},
+ ));
+ } else {
+ push(@fields,
+ (
{key =>'count',desc=>'Number of accesses'},
{key =>'stdno',desc=>'Students Attempting'},
{key =>'avetries',desc=>'Average Number of Tries'},
@@ -2682,7 +2716,8 @@ sub display_results {
{key =>'correct',desc=>'Evaluation: Material is Correct'},
{key =>'helpful',desc=>'Evaluation: Material is Helpful'},
{key =>'depth',desc=>'Evaluation: Material has Depth'},
- );
+ ));
+ }
my %fieldnames = &Apache::lonmeta::fieldnames();
my @field_order;
foreach my $field_data (@fields) {
@@ -2699,7 +2734,13 @@ sub display_results {
my %sort_fields = map {$_->{'key'},$_->{'desc'}} @fields;
$sort_fields{'select_form_order'} = \@field_order;
$env{'form.sortorder'} = 'desc' if (! exists($env{'form.sortorder'}));
- $env{'form.sortfield'} = 'count' if (! exists($env{'form.sortfield'}));
+ if (! exists($env{'form.sortfield'})) {
+ if ($area eq 'portfolio') {
+ $env{'form.sortfield'} = 'owner';
+ } else {
+ $env{'form.sortfield'} = 'count';
+ }
+ }
if (! exists($env{'form.sortorder'})) {
if ($env{'form.sortfield'}=~/^(count|stdno|disc|clear|technical|correct|helpful)$/) {
$env{'form.sortorder'}='desc';
@@ -2707,37 +2748,40 @@ sub display_results {
$env{'form.sortorder'}='asc';
}
}
- my $sortform = &mt('Sort by [_1] [_2]',
- &Apache::loncommon::select_form($env{'form.sortfield'},
+ my $sortform = ''
+ .&mt('Sort by:').' '
+ .&Apache::loncommon::select_form($env{'form.sortfield'},
'sortfield',
- %sort_fields),
- &Apache::loncommon::select_form($env{'form.sortorder'},
+ \%sort_fields)
+ .' '
+ .&Apache::loncommon::select_form($env{'form.sortorder'},
'sortorder',
- (asc =>&mt('Ascending'),
+ {asc =>&mt('Ascending'),
desc=>&mt('Descending')
- ))
- );
+ })
+ .'';
##
- ## Output links (if necessary) for 'prev' and 'next' pages.
- $r->print
- ('
'.
mt('Results [_1] to [_2] out of [_3]',
$min,$max,$total_results).
- "\n");
+ "
\n");
}
##
## Get results from MySQL table
@@ -2763,13 +2807,18 @@ 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';
+ }
+ $r->print(&Apache::loncommon::start_data_table());
foreach my $row (@Results) {
if ($connection->aborted()) {
&cleanup();
return;
}
- my %Fields = %{&parse_row(@$row)};
- my $output="
\n";
+ my %Fields = %{&parse_row($tabletype,@$row)};
+ my $output;
if (! defined($Fields{'title'}) || $Fields{'title'} eq '') {
$Fields{'title'} = 'Untitled';
}
@@ -2778,21 +2827,27 @@ sub display_results {
# Render the result into html
$output.= &$viewfunction($prefix,%Fields);
# Print them out as they come in.
- $r->print($output);
+ $r->print(&Apache::loncommon::start_data_table_row()
+ .'
'
+ .$output
+ .'
'
+ .&Apache::loncommon::end_data_table_row()
+ );
$r->rflush();
}
+ $r->print(&Apache::loncommon::end_data_table());
if (@Results < 1) {
- $r->print(&mt("There were no results matching your query"));
+ $r->print('
'
+ .&mt('There were no results matching your query.')
+ .'
$end_page
ENDPAGE
@@ -3607,23 +3706,32 @@ $parms is extra information to include i
######################################################################
sub output_blank_field_error {
my ($r,$closebutton,$parms,$hidden_fields)=@_;
- my $errormsg = &mt('You did not fill in enough information for the search to be started. You need to fill in relevant fields on the search page in order for a query to be processed.');
+ my $errormsg = &mt('You did not fill in enough information for the search to be started. You need to fill in relevant fields on the search page in order for a query to be processed.');
my $revise = &mt('Revise Search Request');
- my $heading = &mt('Unactionable Search Queary');
+ my $heading = &mt('Unactionable Search Query');
my $start_page = &Apache::loncommon::start_page('Search');
my $end_page = &Apache::loncommon::end_page();
+ if ($closebutton) {
+ $closebutton = '
$end_page
ENDPAGE
@@ -3654,16 +3762,18 @@ sub output_date_error {
# make query information persistent to allow for subsequent revision
my $start_page = &Apache::loncommon::start_page('Search');
my $end_page = &Apache::loncommon::end_page();
+ my $heading = &mt('Error');
$r->print(<
$hidden_fields
+onclick='this.form.submit();' />
$closebutton
+
-