--- loncom/interface/lonsearchcat.pm 2005/04/07 06:56:23 1.243 +++ loncom/interface/lonsearchcat.pm 2006/03/15 20:56:16 1.256 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Search Catalog # -# $Id: lonsearchcat.pm,v 1.243 2005/04/07 06:56:23 albertel Exp $ +# $Id: lonsearchcat.pm,v 1.256 2006/03/15 20:56:16 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); @@ -195,18 +198,11 @@ 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 &error_page($r,$msg); } } } else { @@ -226,10 +222,8 @@ 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 &error_page($r,$msg); } } ## @@ -283,12 +277,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 +360,19 @@ 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 &error_page($r,$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 &error_page($r,$msg); + } ## ## Print out the frames interface ## @@ -408,6 +383,14 @@ END return OK; } +sub error_page { + my ($r,$msg) = @_; + $r->print(&Apache::loncommon::start_page('Search Error'). + &mt($msg). + &Apache::loncommon::end_page()); + return OK; +} + # # The mechanism used to store values away and retrieve them does not # handle the case of missing environment variables being significant. @@ -469,7 +452,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 +468,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 +569,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 +645,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 +662,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 +777,7 @@ ENDCOURSESEARCH ENDENDCOURSE } - $scrout.=(< - -ENDDOCUMENT + $scrout .= &Apache::loncommon::end_page(); $r->print($scrout); return; } @@ -821,7 +796,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 +809,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 @@ -860,10 +835,12 @@ ENDHEADER 'abstract' => 1, 'standards'=> 1, 'mime' => 1, + 'subject' => 1, ); # - foreach my $field ('title','author','owner','authorspace','modifyinguser', - 'keywords','notes','abstract','standards','mime') { + foreach my $field ('title','author','subject','owner','authorspace', + 'modifyinguser','keywords','notes','abstract', + 'standards','mime') { $scrout.=''.&titlefield($fields{$field}).''. &Apache::lonmeta::prettyinput($field, $env{'form.'.$field}, @@ -900,7 +877,10 @@ ENDHEADER &titlefield(&mt('Domains')).''. &Apache::loncommon::domain_select('domains', $env{'form.domains'},1). - ''.$/; + '
'.$/; # # Misc metadata $scrout.=''. @@ -1026,9 +1006,8 @@ ENDHEADER $scrout.=< - - ENDDOCUMENT + $scrout .= &Apache::loncommon::end_page(); $r->print($scrout); return; } @@ -1075,7 +1054,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}; } @@ -1535,10 +1516,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).')'; @@ -1557,30 +1538,21 @@ sub parse_domain_restrictions { if (! exists($env{'form.domains'}) || $env{'form.domains'} eq '') { return (undef,'',undef); } - my @allowed_domains; - if (ref($env{'form.domains'})) { - @allowed_domains = @{$env{'form.domains'}}; - } else { - @allowed_domains = ($env{'form.domains'}); - } + my @allowed_domains = &Apache::loncommon::get_env_multiple('form.domains'); # 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 .= "".$_." "; } @@ -1591,8 +1563,7 @@ sub parse_domain_restrictions { } } return ($libraries_to_query, - $pretty_domains_string, - $domain_sql_restriction); + $pretty_domains_string); } ###################################################################### @@ -1621,8 +1592,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'}; @@ -1645,9 +1615,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); #} @@ -2050,7 +2017,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; } ## @@ -2059,7 +2026,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()); @@ -2067,7 +2035,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; @@ -2125,17 +2094,20 @@ 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(); + my $html = &Apache::lonxml::xmlbegin(); + my $head = &Apache::lonxml::headtag('Results'); + my $end_head = &Apache::loncommon::endheadtag(); $result.=< +$head -Results - +$end_head $bodytag

@@ -2171,10 +2142,8 @@ There are $total_results matches to your Search:$pretty_query_string

- - END - $r->print($result); + $r->print($result.&Apache::loncommon::end_page()); return; } @@ -2291,7 +2260,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; @@ -2374,11 +2343,11 @@ sub run_search { # # Print run_search header # - my $html=&Apache::lonxml::xmlbegin(); + my $html = &Apache::lonxml::xmlbegin(); + my $head = &Apache::loncommon::head('Search Status'); $r->print(< -Search Status +$head $bodytag
@@ -2414,12 +2383,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 = ". @@ -2433,7 +2404,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; } ## @@ -2525,8 +2497,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); @@ -2559,7 +2534,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 + + my $end_head = &Apache::loncommon::endheadtag(); + my $bodytag = &Apache::loncommon::bodytag(undef,undef,undef,1); $result.=< +$end_head $bodytag @@ -3184,12 +3107,12 @@ END ###################################################################### ###################################################################### sub search_status_header { - my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1); - my $html=&Apache::lonxml::xmlbegin(); + my $bodytag = &Apache::loncommon::bodytag(undef,undef,undef,1); + my $html = &Apache::lonxml::xmlbegin(); + my $head = &Apache::loncommon::head('Search Status'); return < -Search Status +$head $bodytag

Search Status

Sending search request to LON-CAPA servers.
@@ -3212,16 +3135,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 @@ -3293,9 +3217,11 @@ extra custom metadata to show. sub detailed_citation_view { my ($prefix,%values) = @_; my $result; + my $jumpurl=$values{'url'}; + $jumpurl=~s/^\/ext\//http\:\/\//; $result .= ''.$prefix. ''.' '. - '
'.$values{'title'}."\n"; $result .= "

\n"; $result .= ''.$values{'author'}.','. @@ -3364,7 +3290,7 @@ sub detailed_citation_view { foreach my $item (split(',',$values{$field->{'name'}})){ $result .= '

  • '. ''.$item.'
  • '; + 'href="'.$jumpurl.'">'.$item.''; } $result .= ''; } elsif (exists($field->{'format'}) && $field->{'format'} ne ''){ @@ -3375,7 +3301,7 @@ sub detailed_citation_view { if ($field->{'special'} eq 'url link') { $result.= &mt($field->{'translate'}, - ''. $values{$field->{'name'}}. ''); @@ -3397,6 +3323,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'}). + '

    '; +} + + ###################################################################### ###################################################################### @@ -3411,20 +3347,23 @@ sub summary_view { my ($prefix,%values) = @_; my $icon=&Apache::loncommon::icon($values{'url'}); my $result=qq{$prefix}; - if (exists($ENV{'form.sortfield'}) && - $ENV{'form.sortfield'} !~ /^(default| + if (exists($env{'form.sortfield'}) && + $env{'form.sortfield'} !~ /^(default| author| url| title| owner| lastrevisiondate| copyright)$/x) { - my $tmp = $values{$ENV{'form.sortfield'}}; + my $tmp = $values{$env{'form.sortfield'}}; if (! defined($tmp)) { $tmp = 'undefined'; } $result .= ' '.$tmp.' '; } + my $jumpurl=$values{'url'}; + $jumpurl=~s/^\/ext\//http\:\/\//; + $result.=<$values{'title'}
    $values{'author'}, $values{'owner'} -- $values{'lastrevisiondate'}
    $values{'copyrighttag'}
    @@ -3435,6 +3374,15 @@ END return $result; } +sub summary_preview { + my ($prefix,%values)=@_; + return '
    '. + &summary_view($prefix,%values). + ''. + &Apache::lonindexer::showpreview($values{'url'}). + '

    '; +} + ###################################################################### ###################################################################### @@ -3448,17 +3396,20 @@ END ###################################################################### sub compact_view { my ($prefix,%values) = @_; + my $jumpurl=$values{'url'}; + $jumpurl=~s/^\/ext\//http\:\/\//; + my $result = $prefix.''; - if (exists($ENV{'form.sortfield'}) && - $ENV{'form.sortfield'} !~ /^(default|author|url|title)$/) { - my $tmp = $values{$ENV{'form.sortfield'}}; + if (exists($env{'form.sortfield'}) && + $env{'form.sortfield'} !~ /^(default|author|url|title)$/) { + my $tmp = $values{$env{'form.sortfield'}}; if (! defined($tmp)) { $tmp = 'undefined'; } $result .= ' '.$tmp.' '; } - $result.=' '. + $result.=' '. $values{'title'}.''.(' 'x2). - ''.$values{'author'}.'
    '; + ''.$values{'author'}.' ('.$values{'domain'}.')
    '; return $result; } @@ -3478,11 +3429,14 @@ sub fielded_format_view { my ($prefix,%values) = @_; my $icon=&Apache::loncommon::icon($values{'url'}); my %Translated = &Apache::lonmeta::fieldnames(); + my $jumpurl=$values{'url'}; + $jumpurl=~s/^\/ext\//http\:\/\//; + my $result=<
    URL:
    -
    $values{'url'}
    END foreach my $field ('title','author','domain','subject','keywords','notes', @@ -3623,17 +3577,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 @@ -3645,8 +3595,7 @@ $errorstring

    $revise

    - - +$end_page ENDPAGE } @@ -3676,13 +3625,10 @@ sub output_blank_field_error { 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 @@ -3694,8 +3640,7 @@ $errormsg

    $revise 

    - - +$end_page ENDPAGE return; } @@ -3722,16 +3667,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 } @@ -3783,6 +3721,7 @@ sub cleanup { } &untiehash(); &Apache::lonmysql::disconnect_from_db(); + return OK; } __END__