--- loncom/interface/lonsearchcat.pm 2008/05/28 22:22:27 1.295 +++ loncom/interface/lonsearchcat.pm 2011/01/17 20:18:02 1.327 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Search Catalog # -# $Id: lonsearchcat.pm,v 1.295 2008/05/28 22:22:27 www Exp $ +# $Id: lonsearchcat.pm,v 1.327 2011/01/17 20:18:02 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -118,8 +118,6 @@ sub handler { # This is set and used in &handler() and is also used in # &output_results(). - my $loaderror=&Apache::lonnet::overloaderror($r); - if ($loaderror) { return $loaderror; } # my $closebutton; # button that closes the search window # This button is different for the RAT compared to @@ -175,25 +173,16 @@ sub handler { if (&Apache::lonnet::allowed('bre',$env{'request.role.domain'})) { push(@allowed_searches,'res'); } - if (exists($env{'request.course.id'}) && $env{'request.course.id'} ne '') { - push(@allowed_searches,'course'); - } my $crumb_text = 'Portfolio Search'; - if (@allowed_searches == 3) { - $crumb_text = 'Course, Portfolio and Catalog Search'; - } elsif (@allowed_searches ==2) { - if (grep(/^res$/,@allowed_searches)) { - $crumb_text = 'Portfolio and Catalog Search'; - } elsif (grep(/^course$/,@allowed_searches)) { - $crumb_text = 'Portfolio and Course Search'; - } + if (@allowed_searches ==2) { + $crumb_text = 'Portfolio and Catalog Search'; } &Apache::lonhtmlcommon::add_breadcrumb ({href=>'/adm/searchcat?'. &Apache::loncommon::inhibit_menu_check(). - '&catalogmode='.$env{'form.catalogmode'}. - '&launch='.$env{'form.launch'}. - '&mode='.$env{'form.mode'}, + '&catalogmode='.$env{'form.catalogmode'}. + '&launch='.$env{'form.launch'}. + '&mode='.$env{'form.mode'}, text=>"$crumb_text", target=>'_top', bug=>'Searching',}); @@ -266,24 +255,25 @@ sub handler { ## Configure dynamic components of interface ## if ($env{'form.catalogmode'} eq 'interactive') { - $closebutton=" + END } else { $closebutton = ''; @@ -302,8 +292,6 @@ END if ($env{'form.phase'} eq 'adv_search' || $env{'form.phase'} eq 'disp_adv') { $env{'form.searchmode'} = 'advanced'; - } elsif ($env{'form.phase'} eq 'course_search') { - $env{'form.searchmode'} = 'course_search'; } # if ($env{'form.searchmode'} eq 'advanced') { @@ -313,22 +301,13 @@ END } &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'}, + '&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?'.&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',}); - } + } ## ## Switch on the phase ## @@ -350,8 +329,6 @@ END &run_search($r,$query,$customquery,$customshow, $libraries,$pretty_string,$env{'form.area'}); } - } elsif ($env{'form.phase'} eq 'course_search') { - &course_search($r); } elsif(($env{'form.phase'} eq 'basic_search') || ($env{'form.phase'} eq 'adv_search')) { # @@ -447,226 +424,6 @@ sub hidden_field { } ###################################################################### -###################################################################### -## -## Course Search -## -###################################################################### -###################################################################### -{ # Scope the course search to avoid global variables -# -# Variables For course search -my %alreadyseen; -my %hash; -my $totalfound; - -sub make_symb { - my ($id)=@_; - my ($mapid,$resid)=split(/\./,$id); - my $map=$hash{'map_id_'.$mapid}; - my $res=$hash{'src_'.$id}; - my $symb=&Apache::lonnet::encode_symb($map,$resid,$res); - return $symb; -} - -sub course_search { - my $r=shift; - my $pretty_search_string = ''.$env{'form.courseexp'}.''; - my $search_string = $env{'form.courseexp'}; - my @New_Words; - undef(%alreadyseen); - if ($env{'form.crsrelated'}) { - ($search_string,@New_Words) = &related_version($env{'form.courseexp'}); - if (@New_Words) { - $pretty_search_string .= ' '.&mt("with related words").": @New_Words."; - } else { - $pretty_search_string .= ' '.&mt('with no related words')."."; - } - } - my $fulltext=$env{'form.crsfulltext'}; - my $discuss=$env{'form.crsdiscuss'}; - my @allwords=($search_string,@New_Words); - $totalfound=0; - $r->print(&Apache::loncommon::start_page('Course Search'). - '
'.&mt('No matches found in resources').'.
'); - } - -# Check discussions if requested - if ($discuss) { - my $totaldiscussions = 0; - $r->print(''.&mt('No matches found in postings').'.
'); - } - } - -# =================================================== Done going through course - $r->print(&Apache::loncommon::end_page()); -} - -# =============================== This pulls up a resource and its dependencies - -sub checkonthis { - my ($r,$id,$url,$level,$title,$fulltext,$symb,@allwords)=@_; - $alreadyseen{$id}=1; - if (&Apache::loncommon::connection_aborted($r)) { return; } - $r->rflush(); - - my $result=$title.' '; - if ($env{'request.role.adv'} || !$hash{'encrypted_'.$id}) { - $result.=&Apache::lonnet::metadata($url,'title').' '. - &Apache::lonnet::metadata($url,'subject').' '. - &Apache::lonnet::metadata($url,'abstract').' '. - &Apache::lonnet::metadata($url,'keywords'); - } - my ($extension)=($url=~/\.(\w+)$/); - if (&Apache::loncommon::fileembstyle($extension) eq 'ssi' && - ($url) && ($fulltext)) { - $result.=&Apache::lonnet::ssi_body($url.'?symb='.&escape($symb)); - } - $result=~s/\s+/ /gs; - my $applies = 0; - $applies = &checkwords($result,$applies,@allwords); -# Does this resource apply? - if ($applies) { - $r->print('-$lt{'note'}. -
--
-ENDCOURSESEARCH
- $scrout.=' '.
- &Apache::lonhtmlcommon::textbox('courseexp',
- $env{'form.courseexp'},40);
- my $crscheckbox =
- &Apache::lonhtmlcommon::checkbox('crsfulltext',
- $env{'form.crsfulltext'});
- my $relcheckbox =
- &Apache::lonhtmlcommon::checkbox('crsrelated',
- $env{'form.crsrelated'});
- my $discheckbox =
- &Apache::lonhtmlcommon::checkbox('crsdiscuss',
- $env{'form.crsrelated'});
- $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; @@ -1157,17 +906,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; } @@ -1393,7 +1145,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. @@ -1638,7 +1390,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).')'; } @@ -1675,7 +1427,7 @@ sub parse_domain_restrictions { foreach (sort @allowed_domains) { $pretty_domains_string .= "".$_." "; } - my %servers = &Apache::lonnet::get_servers(\@allowed_domains, + my %servers = &Apache::lonnet::get_unique_servers(\@allowed_domains, 'library'); $libraries_to_query = [keys(%servers)]; } @@ -1701,7 +1453,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. @@ -1740,7 +1492,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); } @@ -2118,7 +1870,7 @@ sub copyright_check { } # Check for custom rights if ($Metadata->{'copyright'} eq 'custom') { - return &Apache::lonnet::customacccess('bre',$Metadata->{'url'}); + return &Apache::lonnet::customaccess('bre',$Metadata->{'url'}); } return 1; } @@ -2147,9 +1899,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 saved 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;
}
##
@@ -2231,6 +1987,7 @@ sub print_sort_form {
}
my $js =<
$pretty_string =~ s:^\s*
::i;
@@ -2500,7 +2271,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();
@@ -2514,7 +2285,7 @@ END
@Servers_to_contact = ($serverlist);
}
} else {
- my %all_library_servers = &Apache::lonnet::all_library();
+ my %all_library_servers = &Apache::lonnet::unique_library();
@Servers_to_contact = sort(keys(%all_library_servers));
}
my %Server_status;
@@ -2555,18 +2326,22 @@ END
my $server;
my $status;
my $revise = &revise_button();
- $r->print(<
-Status Total Matches Time Remaining
-
-
-
-END
+ $r->print('');
$r->rflush();
&reset_timing();
&update_seconds($r);
@@ -2671,7 +2446,7 @@ END
last if ($connection->aborted());
&update_seconds($r);
}
- &update_status($r,&mt('Search Complete [_1]',$server));
+ &update_status($r,&mt('Search Complete on Server [_1]',$server));
&update_seconds($r);
#
&Apache::lonmysql::disconnect_from_db(); # This is unneccessary
@@ -2681,11 +2456,11 @@ END
# loaded from /adm/searchcat
$r->print(&Apache::loncommon::end_page());
# if ($env{'form.catalogmode'} ne 'import') {
- $r->print("");
+ $r->print(<
+SCRIPT
# }
return;
}
@@ -2708,15 +2483,15 @@ sub prev_next_buttons {
return '' if ($show eq 'all'); # No links if you get them all at once.
#
# Create buttons
- my $buttons = '';
- $buttons .= ' 'x3;
- $buttons .= ''
+ .''
+ .' '
+ .''
+ .' '
+ .''
+ .'
-
-
- $revise
-
' + .&mt('Internal Error - Bad view selected.') + .'
'."\n"); $r->rflush(); return; } @@ -2758,7 +2535,10 @@ sub display_results { if ($env{'form.catalogmode'} eq 'import') { if (! tie(%groupsearch_db,'GDBM_File',$diropendb, &GDBM_WRCREAT(),0640)) { - $r->print('Unable to save import results.'. + $r->print(''. + &mt('Unable to save import results.'). + '
'. + ''. &Apache::loncommon::end_page()); $r->rflush(); return; @@ -2772,7 +2552,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); @@ -2877,37 +2660,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 - (''.
- ' | '. - &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'; } @@ -2952,21 +2739,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'}.','.
' '.$values{'owner'}.'
';
@@ -3444,7 +3332,7 @@ sub detailed_citation_view {
$result .= ''.&mt($field->{'translate'}).'';
foreach my $item (split(',',$values{$field->{'name'}})){
$item = &Apache::lonnet::clutter($item);
- $result .= &display_url($item,[2,0,1]);
+ $result .= '
'.&display_url($item,1).'
';
}
} elsif (exists($field->{'format'}) && $field->{'format'} ne ''){
$result.= &mt($field->{'translate'},
@@ -3452,7 +3340,7 @@ sub detailed_citation_view {
$values{$field->{'name'}}))."
\n";
} else {
if ($field->{'special'} eq 'url link') {
- $result .= &display_url($jumpurl,[3,0,1]);
+ $result .= '
'.&display_url($jumpurl,1).'
';
} else {
$result.= &mt($field->{'translate'},
$values{$field->{'name'}});
@@ -3467,17 +3355,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 @@ -3791,23 +3694,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 @@ -3838,16 +3750,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