'.'';
return $scrout;
}
@@ -817,25 +562,52 @@ sub print_advanced_search_form{
'reset' => 'Reset',
'help' => 'Help');
my $advanced_buttons=<<"END";
+
$closebutton
+
END
- my $scrout= &Apache::loncommon::start_page('Advanced Catalog Search');
- $scrout .= <<"ENDHEADER";
-$bread_crumb
-';
+
$scrout .= &Apache::loncommon::end_page();
$r->print($scrout);
return;
@@ -1130,17 +908,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;
}
@@ -1366,7 +1147,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.
@@ -1399,6 +1180,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);
@@ -1489,9 +1281,25 @@ sub parse_advanced_search {
#
# Added metadata fields
for (my $i=0; $i<$env{'form.numaddedfields'} ; $i++) {
- if (($env{'form.addedfield_'.$i} ne '') &&
- ($env{'form.addedvalue_'.$i} ne '')) {
- my $stuff = 1; #FIXME
+ 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 {
@@ -1583,7 +1391,11 @@ sub parse_advanced_search {
}
#
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 = '';
}
@@ -1617,11 +1429,9 @@ sub parse_domain_restrictions {
foreach (sort @allowed_domains) {
$pretty_domains_string .= "".$_." ";
}
- foreach (keys(%Apache::lonnet::libserv)) {
- if (exists($domain_hash{$Apache::lonnet::hostdom{$_}})) {
- push @$libraries_to_query,$_;
- }
- }
+ my %servers = &Apache::lonnet::get_unique_servers(\@allowed_domains,
+ 'library');
+ $libraries_to_query = [keys(%servers)];
}
return ($libraries_to_query,
$pretty_domains_string);
@@ -1645,7 +1455,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.
@@ -1684,7 +1494,7 @@ sub parse_basic_search {
#}
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 < NOW() AND (pa.end IS NULL OR pa.end > NOW())) AND '.join(" AND ",@Queries).')';
+ $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);
}
@@ -1800,7 +1610,7 @@ sub process_phrase_input {
$item[1];
}
term:
- /[\w\Q:!@#$%^&*()+_=|{}<>,.;\\\/?\E]+/ {
+ /[\w\Q:!@#$%^&*()+_=|{}<>,.;\\\/?\E\-]+/ {
$item[1];
}
ENDGRAMMAR
@@ -1971,14 +1781,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)) {
@@ -2060,6 +1870,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;
}
@@ -2087,9 +1901,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;
}
##
@@ -2097,9 +1917,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());
@@ -2107,13 +1930,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;
@@ -2171,6 +2001,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');
@@ -2207,14 +2038,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('There are [_1] matches to your query.',$total_results)
+ .' '.$revise.'
'
+ .'
'.&mt('Search: ').$pretty_query_string
+ .'
';
$r->print($result.&Apache::loncommon::end_page());
return;
}
@@ -2324,16 +2152,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();
}
@@ -2360,9 +2200,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;
@@ -2386,14 +2231,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;
}
@@ -2422,16 +2268,13 @@ sub run_search {
#
# 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;
@@ -2442,7 +2285,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();
@@ -2456,14 +2299,15 @@ END
@Servers_to_contact = ($serverlist);
}
} else {
- @Servers_to_contact = sort(keys(%Apache::lonnet::libserv));
+ my %all_library_servers = &Apache::lonnet::unique_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;
@@ -2496,18 +2340,22 @@ END
my $server;
my $status;
my $revise = &revise_button();
- $r->print(<
-
'
+ .&mt('Internal Error - Bad view selected.')
+ .'
'."\n");
$r->rflush();
return;
}
@@ -2701,7 +2552,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;
@@ -2715,7 +2569,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);
@@ -2820,37 +2677,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
@@ -2880,13 +2740,14 @@ sub display_results {
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($tabletype,@$row)};
- my $output="
\n";
+ my $output;
if (! defined($Fields{'title'}) || $Fields{'title'} eq '') {
$Fields{'title'} = 'Untitled';
}
@@ -2895,21 +2756,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
@@ -3738,23 +3635,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
@@ -3785,16 +3691,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
+
-