--- loncom/interface/lonsearchcat.pm 2007/03/12 17:06:15 1.281 +++ loncom/interface/lonsearchcat.pm 2009/10/06 10:31:41 1.315 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Search Catalog # -# $Id: lonsearchcat.pm,v 1.281 2007/03/12 17:06:15 albertel Exp $ +# $Id: lonsearchcat.pm,v 1.315 2009/10/06 10:31:41 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -138,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','area']); + '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 @@ -190,9 +190,10 @@ sub handler { } &Apache::lonhtmlcommon::add_breadcrumb ({href=>'/adm/searchcat?'. - 'catalogmode='.$env{'form.catalogmode'}. - '&launch='.$env{'form.launch'}. - '&mode='.$env{'form.mode'}, + &Apache::loncommon::inhibit_menu_check(). + '&catalogmode='.$env{'form.catalogmode'}. + '&launch='.$env{'form.launch'}. + '&mode='.$env{'form.mode'}, text=>"$crumb_text", target=>'_top', bug=>'Searching',}); @@ -258,28 +259,32 @@ sub handler { 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 { $closebutton = ''; @@ -308,18 +313,20 @@ END $srchtype = 'Portfolio'; } &Apache::lonhtmlcommon::add_breadcrumb - ({href=>'/adm/searchcat?phase=disp_adv&'. - 'catalogmode='.$env{'form.catalogmode'}. - '&launch='.$env{'form.launch'}. - '&mode='.$env{'form.mode'}, + ({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',}); } @@ -379,7 +386,7 @@ END $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); @@ -388,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); @@ -481,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( '
'.&mt('No matches found in resources').'.
'); + $r->print(''.&mt('No matches found in resources.').'
'); } # Check discussions if requested @@ -512,72 +532,77 @@ sub course_search { my $totaldiscussions = 0; $r->print(''.&mt('No matches found in postings').'.
'); + unless ($totaldiscussions) { + $r->print(''.&mt('No matches found in postings.').'
'); + } + } else { + $r->print('$lt{'note'}.
-
ENDCOURSESEARCH @@ -725,8 +749,9 @@ ENDCOURSESEARCH | |
- + +
+
@@ -750,19 +775,19 @@ sub setup_basic_search { ''; $onlysearchdomain = ''; - if ($area eq 'res') { - $inclext= ''; - } $adv_search_link = ''.&mt('Advanced Search').''; # $scrout.=''; } # - $scrout .= '' + .&viewoptions() + .'
' + .'' + .'' + .' ' + .$closebutton + .'
'; + # + $scrout .= '$closebutton +
END 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 -'; + $scrout .= &Apache::loncommon::end_page(); $r->print($scrout); return; @@ -1155,17 +1202,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; } @@ -1391,7 +1441,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. @@ -1636,7 +1686,7 @@ sub parse_advanced_search { # if (@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 < NOW() AND (pa.end IS NULL OR pa.end > NOW())) AND (".join(') AND (',@queries).'))'; + $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).')'; } @@ -1699,7 +1749,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. @@ -1738,7 +1788,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); } @@ -1854,7 +1904,7 @@ sub process_phrase_input { $item[1]; } term: - /[\w\Q:!@#$%^&*()+_=|{}<>,.;\\\/?\E]+/ { + /[\w\Q:!@#$%^&*()+_=|{}<>,.;\\\/?\E\-]+/ { $item[1]; } ENDGRAMMAR @@ -2114,6 +2164,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; } @@ -2141,9 +2195,13 @@ 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(&mt('Error')) +. 'table: |'.$table.'|
' # SB + .''
+ .&mt('Unable to retrieve search results. '
+ .'Unable to determine the table results were saved in.')
+ .&Apache::loncommon::end_page()
+ );
return undef;
}
##
@@ -2152,7 +2210,7 @@ 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.".
+ " are saved.".
&Apache::loncommon::end_page());
&Apache::lonnet::logthis("lonsearchcat: unable to get lonmysql to".
" connect to database.");
@@ -2225,18 +2283,19 @@ sub print_sort_form {
}
my $js =<
-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; } @@ -2378,16 +2434,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(); } @@ -2414,9 +2482,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; @@ -2440,14 +2513,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; } @@ -2476,16 +2550,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(<' + .&mt('Internal Error - Bad view selected.') + .'
'."\n"); $r->rflush(); return; } @@ -2756,7 +2831,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; @@ -2770,7 +2848,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); @@ -2875,37 +2956,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'), desc=>&mt('Descending') )) - ); + .''; ## - ## Output links (if necessary) for 'prev' and 'next' pages. - $r->print - (''.
- ' | '. - &prev_next_buttons($min,$env{'form.show'},$total_results). - ' | '. - &viewoptions().' |
'.&mt('There are currently no results.').'
'. "". &Apache::loncommon::end_page()); return; } else { - $r->print('\n"; + my $output; if (! defined($Fields{'title'}) || $Fields{'title'} eq '') { $Fields{'title'} = 'Untitled'; } @@ -2950,21 +3035,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() + .'
' + .&mt('There were no results matching your query.') + .'
'); } else { - $r->print - ('\n";
$result .= ''.$values{'author'}.','.
@@ -3440,11 +3540,8 @@ sub detailed_citation_view {
if (exists($field->{'type'}) && $field->{'type'} eq 'list') {
$result .= ''.&mt($field->{'translate'}).'';
foreach my $item (split(',',$values{$field->{'name'}})){
- $result .=
- &Apache::lonhtmlcommon::crumbs(&Apache::lonnet::clutter($item),
- 'preview',
- '',
- (($env{'form.catalogmode'} eq 'import')?'parent.statusframe.document.forms.statusform':''),2,0,1);
+ $item = &Apache::lonnet::clutter($item);
+ $result .= &display_url($item,[2,0,1]);
}
} elsif (exists($field->{'format'}) && $field->{'format'} ne ''){
$result.= &mt($field->{'translate'},
@@ -3452,15 +3549,7 @@ sub detailed_citation_view {
$values{$field->{'name'}}))."
\n";
} else {
if ($field->{'special'} eq 'url link') {
- if ($jumpurl=~/^http\:\/\//) {
- $result.=''.$jumpurl.'';
- } else {
- $result .=
- &Apache::lonhtmlcommon::crumbs($jumpurl,
- 'preview',
- '',
- (($env{'form.catalogmode'} eq 'import')?'parent.statusframe.document.forms.statusform':''),3,0,1);
- }
+ $result .= &display_url($jumpurl,[3,0,1]);
} else {
$result.= &mt($field->{'translate'},
$values{$field->{'name'}});
@@ -3475,17 +3564,14 @@ sub detailed_citation_view {
if (exists($values{'shortabstract'}) && $values{'shortabstract'} ne '') {
$result .= '
'.$values{'shortabstract'}.'
'; } - $result .= ''. - &detailed_citation_view($prefix,%values). + return &detailed_citation_view($prefix,%values). ' | '. - &Apache::lonindexer::showpreview($values{'url'}). - ' |
'. - &summary_view($prefix,%values). + return &summary_view($prefix,%values). ' | '. - &Apache::lonindexer::showpreview($values{'url'}). - ' |
+
$errorstring
$end_page ENDPAGE @@ -3793,23 +3882,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 = ''.$closebutton.'
+
$errormsg
$end_page ENDPAGE @@ -3840,16 +3938,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(<+
$message
$end_page