--- loncom/interface/lonsearchcat.pm 2007/03/12 22:05:30 1.283 +++ loncom/interface/lonsearchcat.pm 2008/12/12 17:46:25 1.302 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Search Catalog # -# $Id: lonsearchcat.pm,v 1.283 2007/03/12 22:05:30 banghart Exp $ +# $Id: lonsearchcat.pm,v 1.302 2008/12/12 17:46:25 raeburn 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,7 +190,8 @@ sub handler { } &Apache::lonhtmlcommon::add_breadcrumb ({href=>'/adm/searchcat?'. - 'catalogmode='.$env{'form.catalogmode'}. + &Apache::loncommon::inhibit_menu_check(). + '&catalogmode='.$env{'form.catalogmode'}. '&launch='.$env{'form.launch'}. '&mode='.$env{'form.mode'}, text=>"$crumb_text", @@ -258,11 +259,14 @@ 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 { @@ -308,15 +313,17 @@ END $srchtype = 'Portfolio'; } &Apache::lonhtmlcommon::add_breadcrumb - ({href=>'/adm/searchcat?phase=disp_adv&'. - 'catalogmode='.$env{'form.catalogmode'}. + ({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'}, @@ -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); @@ -753,14 +760,10 @@ sub setup_basic_search { $r->dir_config('lonDefDomain')), $r->dir_config('lonDefDomain')). ''; - if ($area eq 'res') { - $inclext= ''; - } $adv_search_link = ''.&searchhelp().''.''. ''. - ''.(' 'x3).$adv_search_link.''.'
'. - ''.(' 'x1).$userelatedwords.''.'
'. - ''.(' 'x1).$onlysearchdomain.''.'
'. - ''.(' 'x1).$inclext.''.'
'. + ''.(' 'x3).$adv_search_link.''.'
'. + ''.(' 'x1).$userelatedwords.''.'
'. + ''.(' 'x1).$onlysearchdomain.''.'
'. + ''.(' 'x1).$inclext.''.'
'. '
'. ''.$/; # @@ -861,7 +864,7 @@ ENDHEADER ''; my %fields=&Apache::lonmeta::fieldnames(); # - $scrout .= '

'.&mt('Standard [_1] Metadata',$srchtype).'

'; + $scrout .= '

'.&mt("Standard $srchtype Metadata").'

'; $scrout .= "\n"; $scrout .= '\n"; @@ -892,7 +895,7 @@ ENDHEADER $env{'form.'.$field.'_related'}, 50); if ($related_word_search{$field}) { - $scrout .= 'related words'; + $scrout .= &mt('related words'); } else { $scrout .= ''.$/; # # Misc metadata @@ -990,7 +988,7 @@ ENDHEADER description=>'Network-wide number of accesses (hits)',}, { name=>'stdno', description=> - 'Total number of students who have worked on this problem',}, + 'Statistics calculated for number of students',}, { name => 'avetries', description=>'Average number of tries till solved',}, { name => 'difficulty', @@ -1037,6 +1035,7 @@ ENDHEADER # Creation/Modification date limits $scrout .= '

'.&mt('Creation and Modification dates').'

'; $scrout .= "\n
 '. (' 'x2).&searchhelp()."
 '; } @@ -919,11 +922,6 @@ ENDHEADER &Apache::loncommon::domain_select('domains', $env{'form.domains'},1). '
' - } $scrout .= '
\n"; + $scrout .= "\n"; my $cafter = &Apache::lonhtmlcommon::date_setter('advsearch', # formname 'creationdate1', # fieldname @@ -1055,10 +1054,10 @@ ENDHEADER '', # state 1, # no_hh_mm_ss ); - $scrout .= &mt(''. - ''. - ''. - '',$cafter,$cbefore); + $scrout .= '' + .'' + .'' + .''; my $lafter = &Apache::lonhtmlcommon::date_setter('advsearch', 'revisiondate1', @@ -1077,10 +1076,10 @@ ENDHEADER '', # state 1, # no_hh_mm_ss ); - $scrout .= &mt(''. - ''. - ''. - '',$lafter,$lbefore); + $scrout .= '' + .'' + .'' + .''; $scrout.="
 ".&mt('Month[_1]Day[_2]Year',' 'x14,' 'x6)."
Created between[_1]
and [_2]
'.&mt('Created between').''.$cafter.'
'.&mt('and').''.$cbefore.'
Last modified between [_1]
and[_2]
'.&mt('Last modified between').''.$lafter.'
'.&mt('and').''.$lbefore.'
\n"; $scrout.=<'.$/; + $scrout .= (' 'x2) + .&mt('[_1] Records per Page',$countselect) + .''.$/; return $scrout; } @@ -1395,7 +1395,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. @@ -1640,7 +1640,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).')'; } @@ -1703,7 +1703,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. @@ -1742,7 +1742,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); } @@ -1858,7 +1858,7 @@ sub process_phrase_input { $item[1]; } term: - /[\w\Q:!@#$%^&*()+_=|{}<>,.;\\\/?\E]+/ { + /[\w\Q:!@#$%^&*()+_=|{}<>,.;\\\/?\E\-]+/ { $item[1]; } ENDGRAMMAR @@ -2118,6 +2118,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; } @@ -2146,7 +2150,7 @@ sub ensure_db_and_table { ## if (! defined($table) || $table eq '' || $table =~ /\D/ ) { $r->print("Unable to retrieve search results. ". - "Unable to determine the table results were stored in. ". + "Unable to determine the table results were saved in. ". &Apache::loncommon::end_page()); return undef; } @@ -2156,7 +2160,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."); @@ -2265,14 +2269,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; } @@ -2444,13 +2445,14 @@ 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{ }; return $result; } @@ -2488,8 +2490,6 @@ sub run_search { $r->print(< - END # Remove leading and trailing
$pretty_string =~ s:^\s*
::i; @@ -2500,7 +2500,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(); @@ -2522,7 +2522,7 @@ END # 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; @@ -2555,18 +2555,22 @@ END my $server; my $status; my $revise = &revise_button(); - $r->print(< -StatusTotal MatchesTime Remaining - - - - -$revise - - - -END + $r->print('
'."\n". + ''."\n". + '' + .'' + .'' + .&Apache::loncommon::end_data_table_header_row() + .&Apache::loncommon::start_data_table_row() + .'' + .'' + .'' + .&Apache::loncommon::end_data_table_row() + .&Apache::loncommon::end_data_table() + .'
'."\n". + &Apache::loncommon::start_data_table()); + $r->print(&Apache::loncommon::start_data_table_header_row() + .''.&mt('Status').''.&mt('Total Matches').''.&mt('Time Remaining').' '.$revise.'
'); $r->rflush(); &reset_timing(); &update_seconds($r); @@ -2638,8 +2642,6 @@ END my %Fields = &parse_raw_result($result,$server,$tabletype); $Fields{'hostname'} = $server; # - # Skip if external and we did not want that - next if ((! $env{'form.inclext'}) && ($Fields{'url'}=~/^\/ext\//)); # Skip based on copyright next if (! ©right_check(\%Fields)); @@ -2760,7 +2762,7 @@ 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('Unable to save import results.'. &Apache::loncommon::end_page()); $r->rflush(); return; @@ -2893,7 +2895,7 @@ sub display_results { ## Output links (if necessary) for 'prev' and 'next' pages. $r->print ('
'. - ''.$sortform.''. + ''.$sortform.''. ''. &prev_next_buttons($min,$env{'form.show'},$total_results). ''. @@ -2997,8 +2999,8 @@ sub catalogmode_output { $title=~ s/\'/\\\'/g; if ($env{'form.catalogmode'} eq 'interactive') { $output.=< + END } @@ -3007,7 +3009,7 @@ END $groupsearch_db{"pre_${fnum}_title"}=$title; $output.=< - END @@ -3234,6 +3236,7 @@ function changeURL(val) { SCRIPT } } + my $inhibit_menu = "&".&Apache::loncommon::inhibit_menu_check(); $js.=< @@ -3377,7 +3380,7 @@ sub detailed_citation_view { $jumpurl=~s|^/ext/|http://|; $result .= ''.$prefix. ''.' '. - ''.$values{'title'}."\n"; $result .= "

\n"; $result .= ''.$values{'author'}.','. @@ -3444,11 +3447,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'}, @@ -3456,15 +3456,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'}}); @@ -3520,19 +3512,13 @@ sub summary_view { $result .= ' '.$tmp.' '; } my $jumpurl=$values{'url'}; - my $link; - if ($jumpurl=~m|^/ext/|) { - $jumpurl=~s|^/ext/|http://|; - $link='
'.$jumpurl.''; - } else { - $link=&Apache::lonhtmlcommon::crumbs($jumpurl, - 'preview', - '', - (($env{'form.catalogmode'} eq 'import')?'parent.statusframe.document.forms.statusform':''),2,0,1); - } + $jumpurl=~s|^/ext/|http://|; + my $link = &display_url($jumpurl,[2,0,1]); + $result.=<$values{'title'}$link +$values{'title'}
+$link
$values{'author'}, $values{'owner'} -- $values{'lastrevisiondate'}
$values{'copyrighttag'}
$values{'extrashow'} @@ -3565,16 +3551,10 @@ sub summary_preview { sub compact_view { my ($prefix,%values) = @_; my $jumpurl=$values{'url'}; - my $link; - if ($jumpurl=~m|^/ext/|) { - $jumpurl=~s|^/ext/|http://|; - $link=''.$jumpurl.''; - } else { - $link=&Apache::lonhtmlcommon::crumbs($jumpurl, - 'preview', - '', - (($env{'form.catalogmode'} eq 'import')?'parent.statusframe.document.forms.statusform':''),1,1,1).' '; - } + $jumpurl=~s|^/ext/|http://|; + + my $link = &display_url($jumpurl,[1,1,1]); + my $result = $prefix.''; if (exists($env{'form.sortfield'}) && @@ -3583,12 +3563,30 @@ sub compact_view { if (! defined($tmp)) { $tmp = 'undefined'; } $result .= ' '.$tmp.' '; } - $result.=' '. - $values{'title'}.''.(' 'x2).$link. - ''.$values{'author'}.' ('.$values{'domain'}.')
'; + $jumpurl = &HTML::Entities::encode($jumpurl,'<>&"'); + $result.=' '. + ''. + &HTML::Entities::encode($values{'title'},'<>&"').' '. + $link.' '.$values{'author'}.' ('.$values{'domain'}.')
'; return $result; } +sub display_url { + my ($url,$crumb_args) = @_; + my $link; + if ($url=~m|^/ext/|) { + $url=~s|^/ext/|http://|; + $link=''.$url.''; + } elsif ($url=~m{^(http://|/uploaded/)}) { + $link=''.$url.''; + } else { + $link=&Apache::lonhtmlcommon::crumbs($url, + 'preview', + '', + (($env{'form.catalogmode'} eq 'import')?'parent.statusframe.document.forms.statusform':''),@{$crumb_args}).' '; + } + return $link; +} ###################################################################### ###################################################################### @@ -3612,7 +3610,7 @@ sub fielded_format_view { $prefix

URL:
-
$values{'url'}
END foreach my $field ('title','author','domain','subject','keywords','notes',