--- loncom/interface/lonsearchcat.pm 2005/11/26 02:42:45 1.247 +++ loncom/interface/lonsearchcat.pm 2006/03/21 21:07:31 1.259 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Search Catalog # -# $Id: lonsearchcat.pm,v 1.247 2005/11/26 02:42:45 www Exp $ +# $Id: lonsearchcat.pm,v 1.259 2006/03/21 21:07:31 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -77,6 +77,7 @@ use LONCAPA::lonmetadata(); use HTML::Entities(); use Parse::RecDescent; use Apache::lonnavmaps; +use Apache::lonindexer(); ###################################################################### ###################################################################### @@ -93,7 +94,9 @@ my %persistent_db; # gdbm hash which h # The different view modes and associated functions my %Views = ("detailed" => \&detailed_citation_view, + "detailedpreview" => \&detailed_citation_preview, "summary" => \&summary_view, + "summarypreview" => \&summary_preview, "fielded" => \&fielded_format_view, "xml" => \&xml_sgml_view, "compact" => \&compact_view); @@ -113,9 +116,6 @@ sub handler { my $diropendb; # The full path to the (temporary) search database file. # This is set and used in &handler() and is also used in # &output_results(). - my $bodytag; # LON-CAPA standard body tag, gotten from - # &Apache::lonnet::bodytag. - # No title, no table, just a tag. my $loaderror=&Apache::lonnet::overloaderror($r); if ($loaderror) { return $loaderror; } @@ -162,7 +162,7 @@ sub handler { ($env{'form.launch'} eq '1')) { $env{'form.persistent_db_id'} = time; } - $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1); + my $persistent_db_file = "/home/httpd/perl/tmp/". &Apache::lonnet::escape($domain). '_'.&Apache::lonnet::escape($env{'user.name'}). @@ -195,18 +195,12 @@ sub handler { &Apache::lonnet::logthis('lonsearchcat:'. 'Unable to recover data from '. $persistent_db_file); - my $html=&Apache::lonxml::xmlbegin(); - $r->print(< -LON-CAPA Search Error -$bodytag -We were unable to retrieve data describing your search. This is a serious -error and has been logged. Please alert your LON-CAPA administrator. - - -END - return OK; + my $msg = + 'We were unable to retrieve data describing your search. '. + 'This is a serious error and has been logged. '. + 'Please alert your LON-CAPA administrator.'; + return &Apache::loncommon::simple_error_page($r,'Search Error', + $msg); } } } else { @@ -226,10 +220,9 @@ END } else { # This is a stupid error to give to the user. # It really tells them nothing. - my $html=&Apache::lonxml::xmlbegin(); - $r->print($html.''.$bodytag. - 'Unable to tie hash to db file'); - return OK; + my $msg = 'Unable to tie hash to db file.'; + return &Apache::loncommon::simple_error_page($r,'Search Error', + $msg); } } ## @@ -283,12 +276,7 @@ END ## Sanity checks on form elements ## if (!defined($env{'form.viewselect'})) { - if (($env{'form.catalogmode'} eq 'groupsearch') || - ($env{'form.catalogmode'} eq 'interactive')) { - $env{'form.viewselect'} ="Compact View"; - } else { - $env{'form.viewselect'} ="Detailed Citation View"; - } + $env{'form.viewselect'} ="summary"; } $env{'form.phase'} = 'disp_basic' if (! exists($env{'form.phase'})); $env{'form.show'} = 20 if (! exists($env{'form.show'})); @@ -371,33 +359,21 @@ END &Apache::lonnet::logthis('lonsearchcat.pm: Unable to create '. 'needed table. lonmysql error:'. $errorstring); - my $html=&Apache::lonxml::xmlbegin(); - $r->print(< -Search Error -$bodytag -Unable to create table in which to store search results. -The search has been aborted. - - -END - return OK; + + my $msg = + 'Unable to create table in which to store search results. '. + 'The search has been aborted.'; + return &Apache::loncommon::simple_error_page($r,'Search Error', + $msg); } delete($env{'form.launch'}); if (! &make_form_data_persistent($r,$persistent_db_file)) { - my $html=&Apache::lonxml::xmlbegin(); - $r->print(< -Search Error -$bodytag -Unable to properly store search information. The search has been aborted. - - -END - return OK; - } + my $msg= + 'Unable to properly store search information. '. + 'The search has been aborted.'; + return &Apache::loncommon::simple_error_page($r,'Search Error', + $msg); + } ## ## Print out the frames interface ## @@ -469,7 +445,6 @@ sub make_symb { sub course_search { my $r=shift; - my $bodytag=&Apache::loncommon::bodytag('Course Search'); my $pretty_search_string = ''.$env{'form.courseexp'}.''; my $search_string = $env{'form.courseexp'}; my @New_Words; @@ -486,9 +461,10 @@ sub course_search { my $discuss=$env{'form.crsdiscuss'}; my @allwords=($search_string,@New_Words); $totalfound=0; - my $html=&Apache::lonxml::xmlbegin(); - $r->print($html.'LON-CAPA Course Search'. - $bodytag.'
'.$pretty_search_string.'

'.&mt('Course content').':
'); + $r->print(&Apache::loncommon::start_page('Course Search'). + '
'. + $pretty_search_string.'
'. + '
'.&mt('Course content').':
'); $r->rflush(); # ======================================================= Go through the course my $c=$r->connection; @@ -586,7 +562,7 @@ sub course_search { } # =================================================== Done going through course - $r->print(''); + $r->print(&Apache::loncommon::end_page()); } # =============================== This pulls up a resource and its dependencies @@ -662,16 +638,6 @@ sub untiehash { } # End of course search scoping -sub search_html_header { - my $html=&Apache::lonxml::xmlbegin(); - my $Str = < -The LearningOnline Network with CAPA - -ENDHEADER - return $Str; -} ###################################################################### ###################################################################### @@ -689,11 +655,11 @@ Prints the form for the basic search. S sub print_basic_search_form { my ($r,$closebutton,$hidden_fields) = @_; my $result = ($env{'form.catalogmode'} ne 'groupsearch'); - my $bodytag=&Apache::loncommon::bodytag('Search'). + my $bread_crumb = &Apache::lonhtmlcommon::breadcrumbs(undef,'Searching','Search_Basic', undef,undef, $env{'form.catalogmode'} ne 'groupsearch'); - my $scrout = &search_html_header().$bodytag; + my $scrout = &Apache::loncommon::start_page('Search').$bread_crumb; if (&Apache::lonnet::allowed('bre',$env{'request.role.domain'})) { # Define interface components my $userelatedwords= ''; + my $inclext= ''; my $adv_search_link = ''. @@ -799,10 +770,7 @@ ENDCOURSESEARCH ENDENDCOURSE } - $scrout.=(< - -ENDDOCUMENT + $scrout .= &Apache::loncommon::end_page(); $r->print($scrout); return; } @@ -821,7 +789,7 @@ Prints the advanced search form. ###################################################################### sub print_advanced_search_form{ my ($r,$closebutton,$hidden_fields) = @_; - my $bodytag=&Apache::loncommon::bodytag('Advanced Catalog Search'). + my $bread_crumb = &Apache::lonhtmlcommon::breadcrumbs(undef,'Searching', 'Search_Advanced', undef,undef, @@ -834,9 +802,9 @@ sub print_advanced_search_form{ $closebutton END - my $scrout=&search_html_header(); + my $scrout= &Apache::loncommon::start_page('Advanced Catalog Search'); $scrout .= <<"ENDHEADER"; -$bodytag +$bread_crumb

$advanced_buttons @@ -902,7 +870,10 @@ ENDHEADER &titlefield(&mt('Domains')).''. &Apache::loncommon::domain_select('domains', $env{'form.domains'},1). - ''.$/; + '
'.$/; # # Misc metadata $scrout.=''. @@ -1028,9 +999,8 @@ ENDHEADER $scrout.=< - - ENDDOCUMENT + $scrout .= &Apache::loncommon::end_page(); $r->print($scrout); return; } @@ -1077,7 +1047,9 @@ sub viewoptiontext { 'xml' => 'XML/SGML', 'compact' => 'Compact View', 'fielded' => 'Fielded Format', - 'summary' => 'Summary View'); + 'summary' => 'Summary View', + 'summarypreview' => 'Summary Preview', + 'detailedpreview' => 'Detailed Citation Preview'); return $desc{$code}; } @@ -1537,10 +1509,10 @@ sub parse_advanced_search { ## ## Deal with restrictions to given domains ## - my ($libraries_to_query,$pretty_domains_string,$domain_sql_restriction) = - &parse_domain_restrictions(); - push(@queries,$domain_sql_restriction); - $pretty_search_string .= $pretty_domains_string."
\n"; + my ($libraries_to_query,$pretty_domains_string) = &parse_domain_restrictions(); + if ($pretty_domains_string) { + $pretty_search_string .= $pretty_domains_string."
\n"; + } # if (@queries) { $query="SELECT * FROM metadata WHERE (".join(") AND (",@queries).')'; @@ -1563,21 +1535,17 @@ sub parse_domain_restrictions { # my %domain_hash = (); my $pretty_domains_string; - my $domain_sql_restriction; foreach (@allowed_domains) { $domain_hash{$_}++; } if ($domain_hash{'any'}) { $pretty_domains_string = "In all LON-CAPA domains."; - $domain_sql_restriction = undef; } else { if (@allowed_domains > 1) { $pretty_domains_string = "In LON-CAPA domains:"; } else { $pretty_domains_string = "In LON-CAPA domain "; } - $domain_sql_restriction = - '(domain="'.join('" OR domain="',@allowed_domains).'")'; foreach (sort @allowed_domains) { $pretty_domains_string .= "".$_." "; } @@ -1588,8 +1556,7 @@ sub parse_domain_restrictions { } } return ($libraries_to_query, - $pretty_domains_string, - $domain_sql_restriction); + $pretty_domains_string); } ###################################################################### @@ -1618,8 +1585,7 @@ sub parse_basic_search { $env{"form.$_"}=&Apache::lonnet::unescape($env{"form.$_"}); $env{"form.$_"}=~s/[^\w\/\s\(\)\=\-\"\']//g; } - my ($libraries_to_query,$pretty_domains_string,$domain_sql_restriction) = - &parse_domain_restrictions(); + my ($libraries_to_query,$pretty_domains_string) = &parse_domain_restrictions(); # # Check to see if enough of a query is filled in my $search_string = $env{'form.basicexp'}; @@ -1642,9 +1608,6 @@ sub parse_basic_search { return; } push(@Queries,$SQLQuery); - if (defined($domain_sql_restriction) && $domain_sql_restriction ne '') { - push(@Queries,$domain_sql_restriction); - } #foreach my $q (@Queries) { # &Apache::lonnet::logthis(' '.$q); #} @@ -2047,7 +2010,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. ". - ""); + &Apache::loncommon::end_page()); return undef; } ## @@ -2056,7 +2019,8 @@ 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 stored.". + &Apache::loncommon::end_page()); &Apache::lonnet::logthis("lonsearchcat: unable to get lonmysql to". " connect to database."); &Apache::lonnet::logthis(&Apache::lonmysql::get_error()); @@ -2064,7 +2028,8 @@ sub ensure_db_and_table { } my $table_check = &Apache::lonmysql::check_table($table); if (! defined($table_check)) { - $r->print("A MySQL error has occurred."); + $r->print("A MySQL error has occurred.". + &Apache::loncommon::end_page()); &Apache::lonnet::logthis("lonmysql was unable to determine the status". " of table ".$table); return undef; @@ -2093,10 +2058,6 @@ a link to change the search query. ###################################################################### sub print_sort_form { my ($r,$pretty_query_string) = @_; - my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1). - &Apache::lonhtmlcommon::breadcrumbs - (undef,'Searching','Searching',undef,undef, - $env{'form.catalogmode'} ne 'groupsearch'); ## my %SortableFields=&Apache::lonlocal::texthash( @@ -2122,18 +2083,15 @@ sub print_sort_form { ## my $total_results = &Apache::lonmysql::number_of_rows($table); if (! defined($total_results)) { - $r->print("A MySQL error has occurred."); + $r->print("A MySQL error has occurred.". + &Apache::loncommon::end_page()); &Apache::lonnet::logthis("lonmysql was unable to determine the number". " of rows in table ".$table); &Apache::lonnet::logthis(&Apache::lonmysql::get_error()); return; } - my $result; - my $html=&Apache::lonxml::xmlbegin(); - $result.=< - -Results - -$bodytag -

+END + + my $start_page = &Apache::loncommon::start_page('Results',$js, + {'only_body' => 1}); + my $breadcrumbs= + &Apache::lonhtmlcommon::breadcrumbs + (undef,'Searching','Searching',undef,undef, + $env{'form.catalogmode'} ne 'groupsearch'); + + my $result = < END @@ -2168,10 +2135,8 @@ There are $total_results matches to your Search:$pretty_query_string

- - END - $r->print($result); + $r->print($result.&Apache::loncommon::end_page()); return; } @@ -2288,7 +2253,7 @@ sub update_status { } { - my $max_time = 40; # seconds for the search to complete + my $max_time = 300; # seconds for the search to complete my $start_time = 0; my $last_time = 0; @@ -2363,20 +2328,19 @@ results into MySQL. ###################################################################### sub run_search { my ($r,$query,$customquery,$customshow,$serverlist,$pretty_string) = @_; - my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1); - $bodytag.=&Apache::lonhtmlcommon::breadcrumbs - (undef,'Searching','Searching',undef,undef, - $env{'form.catalogmode'} ne 'groupsearch'); + my $connection = $r->connection; # # Print run_search header # - my $html=&Apache::lonxml::xmlbegin(); + my $start_page = &Apache::loncommon::start_page('Search Status',undef, + {'only_body' => 1}); + my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs + (undef,'Searching','Searching',undef,undef, + $env{'form.catalogmode'} ne 'groupsearch'); $r->print(< -Search Status -$bodytag +$start_page +$breadcrumbs
END @@ -2411,12 +2375,14 @@ END my $table =$env{'form.table'}; if (! defined($table) || $table eq '' || $table =~ /\D/ ) { $r->print("Unable to determine table id to store search results in.". - "The search has been aborted."); + "The search has been aborted.". + &Apache::loncommon::end_page()); return; } my $table_status = &Apache::lonmysql::check_table($table); if (! defined($table_status)) { - $r->print("Unable to determine status of table."); + $r->print("Unable to determine status of table.". + &Apache::loncommon::end_page()); &Apache::lonnet::logthis("Bogus table id of $table for ". "$env{'user.name'} @ $env{'user.domain'}"); &Apache::lonnet::logthis("lonmysql error = ". @@ -2430,7 +2396,8 @@ END &Apache::lonmysql::get_debug()); &Apache::lonnet::logthis('table status = "'.$table_status.'"'); $r->print("The table id,$table, we tried to use is invalid.". - "The search has been aborted."); + "The search has been aborted.". + &Apache::loncommon::end_page()); return; } ## @@ -2522,8 +2489,11 @@ END my %Fields = &parse_raw_result($result,$server); $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)); + # # Store the result in the mysql database my $result = &Apache::lonmysql::store_row($table,\%Fields); @@ -2556,7 +2526,7 @@ END # We have run out of time or run out of servers to talk to and # results to get, so let the client know the top frame needs to be # loaded from /adm/searchcat - $r->print(""); + $r->print(&Apache::loncommon::end_page()); # if ($env{'form.catalogmode'} ne 'groupsearch') { $r->print(" SCRIPT - $result.=< -$bodytag + + my $start_page = &Apache::loncommon::start_page(undef,$js, + {'only_body' =>1}); + my $result=< $importbutton @@ -3113,13 +3096,10 @@ END ###################################################################### ###################################################################### sub search_status_header { - my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1); - my $html=&Apache::lonxml::xmlbegin(); + my $start_page = &Apache::loncommon::start_page('Search Status',undef, + {'only_body' => 1}); return < -Search Status -$bodytag +$start_page

Search Status

Sending search request to LON-CAPA servers.
ENDSTATUS @@ -3141,16 +3121,17 @@ sub print_frames_interface { "&persistent_db_id=".$env{'form.persistent_db_id'}; my $run_search_link = $basic_link."&phase=run_search"; my $results_link = &results_link(); - my $html=&Apache::lonxml::xmlbegin(); + my $html = &Apache::lonxml::xmlbegin(); + my $head = &Apache::loncommon::headtag('LON-CAPA Digital Library Search Results'); + my $end_head = &Apache::loncommon::endheadtag(); my $result = <<"ENDFRAMES"; $html - +$head -LON-CAPA Digital Library Search Results - +$end_head @@ -3328,6 +3309,16 @@ sub detailed_citation_view { return $result; } +sub detailed_citation_preview { + my ($prefix,%values)=@_; + return '
'. + &detailed_citation_view($prefix,%values). + ''. + &Apache::lonindexer::showpreview($values{'url'}). + '

'; +} + + ###################################################################### ###################################################################### @@ -3369,6 +3360,15 @@ END return $result; } +sub summary_preview { + my ($prefix,%values)=@_; + return '
'. + &summary_view($prefix,%values). + ''. + &Apache::lonindexer::showpreview($values{'url'}). + '

'; +} + ###################################################################### ###################################################################### @@ -3563,17 +3563,13 @@ sub output_unparsed_phrase_error { } else { $errorstring = &mt('Unable to understand the search phrase [_1]:[_2].',$field,$env{'form.'.$field}); } - my $bodytag = &Apache::loncommon::bodytag('Search'); my $heading = &mt('Unparsed Field'); my $revise = &mt('Revise search request'); # make query information persistent to allow for subsequent revision - my $html=&Apache::lonxml::xmlbegin(); + my $start_page = &Apache::loncommon::start_page('Search'); + my $end_page = &Apache::loncommon::end_page(); $r->print(< -The LearningOnline Network with CAPA - -$bodytag +$start_page $hidden_fields $closebutton @@ -3585,8 +3581,7 @@ $errorstring

$revise

- - +$end_page ENDPAGE } @@ -3612,17 +3607,13 @@ $parms is extra information to include i ###################################################################### sub output_blank_field_error { my ($r,$closebutton,$parms,$hidden_fields)=@_; - my $bodytag=&Apache::loncommon::bodytag('Search'); 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 $html=&Apache::lonxml::xmlbegin(); + my $start_page = &Apache::loncommon::start_page('Search'); + my $end_page = &Apache::loncommon::end_page(); $r->print(< -The LearningOnline Network with CAPA - -$bodytag +$start_page $hidden_fields $closebutton @@ -3634,8 +3625,7 @@ $errormsg

$revise 

- - +$end_page ENDPAGE return; } @@ -3662,16 +3652,10 @@ Inputs: sub output_date_error { my ($r,$message,$closebutton,$hidden_fields)=@_; # make query information persistent to allow for subsequent revision - my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1); - my $html=&Apache::lonxml::xmlbegin(); + my $start_page = &Apache::loncommon::start_page('Search'); + my $end_page = &Apache::loncommon::end_page(); $r->print(< -The LearningOnline Network with CAPA - -$bodytag - -

Search Catalog

+$start_page $hidden_fields $message

- - +$end_page RESULTS } @@ -3723,6 +3706,7 @@ sub cleanup { } &untiehash(); &Apache::lonmysql::disconnect_from_db(); + return OK; } __END__