--- loncom/interface/lonsearchcat.pm 2006/03/06 18:23:10 1.255 +++ loncom/interface/lonsearchcat.pm 2006/09/26 15:24:18 1.276 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Search Catalog # -# $Id: lonsearchcat.pm,v 1.255 2006/03/06 18:23:10 www Exp $ +# $Id: lonsearchcat.pm,v 1.276 2006/09/26 15:24:18 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -78,6 +78,8 @@ use HTML::Entities(); use Parse::RecDescent; use Apache::lonnavmaps; use Apache::lonindexer(); +use lib '/home/httpd/lib/perl/'; +use LONCAPA; ###################################################################### ###################################################################### @@ -116,9 +118,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; } @@ -140,7 +139,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']); + 'cleargroupsort','titleelement','area']); ## ## 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 @@ -156,7 +155,7 @@ sub handler { ## my $domain = $r->dir_config('lonDefDomain'); $diropendb= "/home/httpd/perl/tmp/". - "$env{'user.domain'}_$env{'user.name'}_searchcat.db"; + "$env{'user.domain'}_$env{'user.name'}_sel_res.db"; # # set the name of the persistent database # $env{'form.persistent_db_id'} can only have digits in it. @@ -165,10 +164,10 @@ 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'}). + &escape($domain). + '_'.&escape($env{'user.name'}). '_'.$env{'form.persistent_db_id'}.'_persistent_search.db'; ## &Apache::lonhtmlcommon::clear_breadcrumbs(); @@ -198,18 +197,13 @@ 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.'; + &Apache::loncommon::simple_error_page($r,'Search Error', + $msg); + return OK; } } } else { @@ -221,7 +215,7 @@ END untie %groupsearch_db if (tied(%groupsearch_db)); if (($env{'form.cleargroupsort'} eq '1') || (($env{'form.launch'} eq '1') && - ($env{'form.catalogmode'} eq 'groupsearch'))) { + ($env{'form.catalogmode'} eq 'import'))) { if (tie(%groupsearch_db,'GDBM_File',$diropendb,&GDBM_WRCREAT(),0640)) { &start_fresh_session(); untie %groupsearch_db; @@ -229,9 +223,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'); + my $msg = 'Unable to tie hash to db file.'; + &Apache::loncommon::simple_error_page($r,'Search Error', + $msg); return OK; } } @@ -255,6 +249,9 @@ END if (exists($env{'form.mode'})) { $hidden_fields .= &hidden_field('mode'); } + if (exists($env{'form.area'})) { + $hidden_fields .= &hidden_field('area'); + } ## ## Configure dynamic components of interface ## @@ -266,7 +263,7 @@ END $closebutton .="onClick='self.close()'"; } $closebutton .=">\n"; - } elsif ($env{'form.catalogmode'} eq 'groupsearch') { + } elsif ($env{'form.catalogmode'} eq 'import') { $closebutton="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.'; + &Apache::loncommon::simple_error_page($r,'Search Error', + $msg); + return OK; } 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.'; + &Apache::loncommon::simple_error_page($r,'Search Error', + $msg); + return OK; + } ## ## Print out the frames interface ## @@ -467,7 +455,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; @@ -484,9 +471,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; @@ -569,7 +557,7 @@ sub course_search { } else { $url .= '?symb='; } - $url .= &Apache::lonnet::escape($resource->symb()); + $url .= &escape($resource->symb()); my $title = $resource->compTitle(); $r->print('
'. ($title?$title:$url).'  - '.$disctype.'
'); @@ -584,7 +572,7 @@ sub course_search { } # =================================================== Done going through course - $r->print(''); + $r->print(&Apache::loncommon::end_page()); } # =============================== This pulls up a resource and its dependencies @@ -605,7 +593,7 @@ sub checkonthis { my ($extension)=($url=~/\.(\w+)$/); if (&Apache::loncommon::fileembstyle($extension) eq 'ssi' && ($url) && ($fulltext)) { - $result.=&Apache::lonnet::ssi_body($url.'?symb='.&Apache::lonnet::escape($symb)); + $result.=&Apache::lonnet::ssi_body($url.'?symb='.&escape($symb)); } $result=~s/\s+/ /gs; my $applies = 0; @@ -621,7 +609,7 @@ sub checkonthis { $href=&Apache::lonenc::encrypted($href) .'?symb='.&Apache::lonenc::encrypted($symb); } else { - $href.='?symb='.&Apache::lonnet::escape($symb); + $href.='?symb='.&escape($symb); } $r->print(''.($title?$title:$url). '
'); @@ -660,16 +648,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; -} ###################################################################### ###################################################################### @@ -686,76 +664,18 @@ 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'). - &Apache::lonhtmlcommon::breadcrumbs(undef,'Searching','Search_Basic', - undef,undef, - $env{'form.catalogmode'} ne 'groupsearch'); - my $scrout = &search_html_header().$bodytag; + my $result = ($env{'form.catalogmode'} ne 'import'); + my $bread_crumb = + &Apache::lonhtmlcommon::breadcrumbs('Searching','Search_Basic', + $env{'form.catalogmode'} ne 'import'); + my $scrout = &Apache::loncommon::start_page('Search').$bread_crumb; +# Search form for resource space if (&Apache::lonnet::allowed('bre',$env{'request.role.domain'})) { - # Define interface components - my $userelatedwords= ''; - my $onlysearchdomain=''; - my $inclext= ''; - my $adv_search_link = - ''.&mt('Advanced Search').''; - # - $scrout.='
'. - ''. - $hidden_fields; - # - $scrout .= '
'.$/; - if ($env{'request.course.id'}) { - $scrout .= '

'.&mt('LON-CAPA Catalog Search').'

'; - } else { - # No need to tell them they are searching - $scrout.= ('
'x2); - } - $scrout.=''. - ''. - ''. - ''.$/; - # - $scrout .= ''.$/; - $scrout .= '
'. - &Apache::lonhtmlcommon::textbox - ('basicexp', - &HTML::Entities::encode($env{'form.basicexp'},'<>&"'),50 - ). - '
'. - ''.&searchhelp().''.'
'. - ''.(' 'x3).$adv_search_link.''.'
'. - ''.(' 'x1).$userelatedwords.''.'
'. - ''.(' 'x1).$onlysearchdomain.''.'
'. - ''.(' 'x1).$inclext.''.'
'. - '
'. - ''. - ''. - (' 'x2).$closebutton.(' 'x2). - &viewoptions(). - ''. - '
'.$/.'
'.'
'; + $scrout .= &setup_basic_search($r,'res',$hidden_fields,$closebutton); + $scrout .= '

'; } +# Search form for accessible portfolio files + $scrout.= &setup_basic_search($r,'portfolio',$hidden_fields,$closebutton); if ($env{'request.course.id'}) { my %lt=&Apache::lonlocal::texthash('srch' => 'Search', 'header' => 'Course Search', @@ -802,13 +722,79 @@ ENDCOURSESEARCH ENDENDCOURSE } - $scrout.=(< - -ENDDOCUMENT + $scrout .= &Apache::loncommon::end_page(); $r->print($scrout); return; } + +sub setup_basic_search { + my ($r,$area,$hidden_fields,$closebutton) = @_; + # Define interface components + my %lt = &Apache::lonlocal::texthash ( + res => 'LON-CAPA Catalog Search', + portfolio => 'Portfolio Search', + ); + my ($userelatedwords,$onlysearchdomain,$inclext,$adv_search_link,$scrout); + $userelatedwords = ''; + $onlysearchdomain = ''; + if ($area eq 'res') { + $inclext= ''; + } + $adv_search_link = ''.&mt('Advanced Search').''; + # + $scrout.='
'. + ''. + $hidden_fields; + if (!exists($env{'form.area'})) { + $scrout .= ''; + } + # + $scrout .= '
'.$/; +# if ($env{'request.course.id'}) { + $scrout .= '

'.$lt{$area}.'

'; +# } else { + # No need to tell them they are searching +# $scrout.= ('
'x2); +# } + $scrout.=''. + ''. + ''. + ''.$/; + # + $scrout .= ''.$/; + $scrout .= '
'. + &Apache::lonhtmlcommon::textbox('basicexp', + $env{'form.basicexp'},50). + '
'. + ''.&searchhelp().''.'
'. + ''.(' 'x3).$adv_search_link.''.'
'. + ''.(' 'x1).$userelatedwords.''.'
'. + ''.(' 'x1).$onlysearchdomain.''.'
'. + ''.(' 'x1).$inclext.''.'
'. + '
'. + ''. + ''. + (' 'x2).$closebutton.(' 'x2). &viewoptions(). + ''. + '
'.$/.'
'.'
'; + return $scrout; +} + ###################################################################### ###################################################################### @@ -824,11 +810,9 @@ Prints the advanced search form. ###################################################################### sub print_advanced_search_form{ my ($r,$closebutton,$hidden_fields) = @_; - my $bodytag=&Apache::loncommon::bodytag('Advanced Catalog Search'). - &Apache::lonhtmlcommon::breadcrumbs(undef,'Searching', - 'Search_Advanced', - undef,undef, - $env{'form.catalogmode'} ne 'groupsearch'); + my $bread_crumb = + &Apache::lonhtmlcommon::breadcrumbs('Searching','Search_Advanced', + $env{'form.catalogmode'} ne 'import'); my %lt=&Apache::lonlocal::texthash('srch' => 'Search', 'reset' => 'Reset', 'help' => 'Help'); @@ -837,9 +821,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 @@ -905,20 +889,26 @@ ENDHEADER &titlefield(&mt('Domains')).''. &Apache::loncommon::domain_select('domains', $env{'form.domains'},1). - '
'.$/; + '
' + } + $scrout .= ''.$/; # # Misc metadata - $scrout.=''. - &titlefield(&mt('Copyright/Distribution')).''. - &Apache::lonmeta::selectbox('copyright', - $env{'form.copyright'}, - \&Apache::loncommon::copyrightdescription, - ( undef, - &Apache::loncommon::copyrightids) - ).''.$/; + if ($env{'form.area'} ne 'portfolio') { + $scrout.=''. + &titlefield(&mt('Copyright/Distribution')). + ''. + &Apache::lonmeta::selectbox('copyright', + $env{'form.copyright'}, + \&Apache::loncommon::copyrightdescription, + ( undef, + &Apache::loncommon::copyrightids) + ).''.$/; + } $scrout.=''. &titlefield(&mt('Language')).''. &Apache::lonmeta::selectbox('language', @@ -926,62 +916,94 @@ ENDHEADER \&Apache::loncommon::languagedescription, ('any',&Apache::loncommon::languageids) ).''; - $scrout .= "\n"; - # - # Dynamic metadata - $scrout .= '

'.&mt('Problem Statistics').'

'; - $scrout .= "\n"; - $scrout .= ''. - ''."\n"; - foreach my $statistic - ({ name=>'count', - description=>'Network-wide number of accesses (hits)',}, - { name=>'stdno', - description=> - 'Total number of students who have worked on this problem',}, - { name => 'avetries', - description=>'Average number of tries till solved',}, - { name => 'difficulty', - description=>'Degree of difficulty',}, - { name => 'disc', - description=>'Degree of discrimination'}) { - $scrout .= ''.$/; - } $scrout .= "
 '.&mt('Minimum').''.&mt('Maximum').'
'. - &titlefield(&mt($statistic->{'description'})). - ''. - ''. - ''. - ''. - '
\n"; - $scrout .= '

'.&mt('Evaluation Data').'

'; - $scrout .= "\n"; - $scrout .= ''. - ''."\n"; - foreach my $evaluation - ( { name => 'clear', - description => 'Material presented in clear way'}, - { name =>'depth', - description => 'Material covered with sufficient depth'}, - { name => 'helpful', - description => 'Material is helpful'}, - { name => 'correct', - description => 'Material appears to be correct'}, - { name => 'technical', - description => 'Resource is technically correct'}){ - $scrout .= ''.$/; + + + if ($env{'form.area'} eq 'portfolio') { + # Added fields + $scrout .= '

'.&mt('Custom Metadata fields').'

'; + $scrout .= "
 '.&mt('Minimum').''.&mt('Maximum').'
'. - &titlefield(&mt($evaluation->{'description'})). - ''. - ''. - ''. - ''. - '
\n"; + $scrout .= ''.''. + ''. + ''; + for (my $j=1; $j<=$env{'form.numaddedfields'}; $j++) { + my $num = $j+1; + $scrout .= ''. + ''; + } + my $numadded = 1 + $env{'form.numaddedfields'}; + $scrout .= ''. + '
 '. + &mt('Field Name').''. + &mt('Field Value(s)').'
'.&mt('1: '). + ''. + '
'.&mt('Custom metadata [_1]: ',$num). + ''. + '
 
'. + ''. + '
'; + } else { + # + # Dynamic metadata + $scrout .= '

'.&mt('Problem Statistics').'

'; + $scrout .= "\n"; + $scrout .= ''.''."\n"; + foreach my $statistic + ({ name=>'count', + description=>'Network-wide number of accesses (hits)',}, + { name=>'stdno', + description=> + 'Total number of students who have worked on this problem',}, + { name => 'avetries', + description=>'Average number of tries till solved',}, + { name => 'difficulty', + description=>'Degree of difficulty',}, + { name => 'disc', + description=>'Degree of discrimination'}) { + $scrout .= ''.$/; + } + $scrout .= "
 '. + &mt('Minimum').''. + &mt('Maximum').'
'. + &titlefield(&mt($statistic->{'description'})). + ''. + ''. + '
\n"; + $scrout .= '

'.&mt('Evaluation Data').'

'; + $scrout .= "\n"; + $scrout .= ''.''."\n"; + foreach my $evaluation + ( { name => 'clear', + description => 'Material presented in clear way'}, + { name =>'depth', + description => 'Material covered with sufficient depth'}, + { name => 'helpful', + description => 'Material is helpful'}, + { name => 'correct', + description => 'Material appears to be correct'}, + { name => 'technical', + description => 'Resource is technically correct'}){ + $scrout .= ''.$/; + } + $scrout .= "
 '. + &mt('Minimum').''. + &mt('Maximum').'
'. + &titlefield(&mt($evaluation->{'description'})). + ''. + ''. + ''. + '
\n"; } - $scrout .= "\n"; # # Creation/Modification date limits $scrout .= '

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

'; @@ -1034,9 +1056,8 @@ ENDHEADER $scrout.=< - - ENDDOCUMENT + $scrout .= &Apache::loncommon::end_page(); $r->print($scrout); return; } @@ -1184,7 +1205,7 @@ sub get_persistent_form_data { # End kludge (hopefully) next if (exists($env{$name})); my @values = map { - &Apache::lonnet::unescape($_); + &unescape($_); } split(',',$persistent_db{$name}); next if (@values <1); if ($arrays_allowed{$name}) { @@ -1230,7 +1251,7 @@ sub get_persistent_data { next; } my @values = map { - &Apache::lonnet::unescape($_); + &unescape($_); } split(',',$persistent_db{$name}); if (@values <= 1) { push @Values,$values[0]; @@ -1267,7 +1288,7 @@ sub make_persistent { foreach my $name (keys(%save)) { my @values = (ref($save{$name}) ? @{$save{$name}} : ($save{$name})); # We handle array references, but not recursively. - my $store = join(',', map { &Apache::lonnet::escape($_); } @values ); + my $store = join(',', map { &escape($_); } @values ); $persistent_db{$name} = $store; } untie(%persistent_db); @@ -1350,7 +1371,7 @@ sub parse_advanced_search { foreach ('mode','form','element') { # is this required? Hmmm. next if (! exists($env{'form.'.$_})); - $env{'form.'.$_}=&Apache::lonnet::unescape($env{'form.'.$_}); + $env{'form.'.$_}=&unescape($env{'form.'.$_}); $env{'form.'.$_}=~s/[^\w\/\s\(\)\=\-\"\']//g; } # Preprocess the category form element. @@ -1464,29 +1485,40 @@ sub parse_advanced_search { &Apache::loncommon::copyrightdescription($env{'form.copyright'}). "
\n"; } - # - # Statistics - foreach my $field (@StatsFields,@EvalFields) { - my ($min,$max); - if (exists($env{'form.'.$field.'_min'}) && - $env{'form.'.$field.'_min'} ne '') { - $min = $env{'form.'.$field.'_min'}; - } - if (exists($env{'form.'.$field.'_max'}) && - $env{'form.'.$field.'_max'} ne '') { - $max = $env{'form.'.$field.'_max'}; - } - next if (! defined($max) && ! defined($min)); - if (defined($min) && defined($max)) { - ($min,$max) = sort {$a <=>$b} ($min,$max); - } - if (defined($min) && $min =~ /^(\d+\.\d+|\d+|\.\d+)$/) { - push(@queries,'('.$field.'>'.$min.')'); - $pretty_search_string.=$font.$field.'>'.$min.'
'; - } - if (defined($max) && $max =~ /^(\d+\.\d+|\d+|\.\d+)$/) { - push(@queries,'('.$field.'<'.$max.')'); - $pretty_search_string.=$font.$field.'<'.$max.'
'; + if ($env{'form.area'} eq 'portfolio') { + # + # Added metadata fields + for (my $i=0; $i<$env{'form.numaddedfields'} ; $i++) { + if (($env{'form.addedfield_'.$i} ne '') && + ($env{'form.addedvalue_'.$i} ne '')) { + my $stuff = 1; #FIXME + } + } + } else { + # + # Statistics + foreach my $field (@StatsFields,@EvalFields) { + my ($min,$max); + if (exists($env{'form.'.$field.'_min'}) && + $env{'form.'.$field.'_min'} ne '') { + $min = $env{'form.'.$field.'_min'}; + } + if (exists($env{'form.'.$field.'_max'}) && + $env{'form.'.$field.'_max'} ne '') { + $max = $env{'form.'.$field.'_max'}; + } + next if (! defined($max) && ! defined($min)); + if (defined($min) && defined($max)) { + ($min,$max) = sort {$a <=>$b} ($min,$max); + } + if (defined($min) && $min =~ /^(\d+\.\d+|\d+|\.\d+)$/) { + push(@queries,'('.$field.'>'.$min.')'); + $pretty_search_string.=$font.$field.'>'.$min.'
'; + } + if (defined($max) && $max =~ /^(\d+\.\d+|\d+|\.\d+)$/) { + push(@queries,'('.$field.'<'.$max.')'); + $pretty_search_string.=$font.$field.'<'.$max.'
'; + } } } # @@ -1575,12 +1607,12 @@ sub parse_domain_restrictions { $domain_hash{$_}++; } if ($domain_hash{'any'}) { - $pretty_domains_string = "In all LON-CAPA domains."; + $pretty_domains_string = &mt("in all LON-CAPA domains."); } else { if (@allowed_domains > 1) { - $pretty_domains_string = "In LON-CAPA domains:"; + $pretty_domains_string = &mt("in LON-CAPA domains:"); } else { - $pretty_domains_string = "In LON-CAPA domain "; + $pretty_domains_string = &mt("in LON-CAPA domain "); } foreach (sort @allowed_domains) { $pretty_domains_string .= "".$_." "; @@ -1618,7 +1650,7 @@ sub parse_basic_search { foreach ('mode','form','element') { # is this required? Hmmm. next unless (exists($env{"form.$_"})); - $env{"form.$_"}=&Apache::lonnet::unescape($env{"form.$_"}); + $env{"form.$_"}=&unescape($env{"form.$_"}); $env{"form.$_"}=~s/[^\w\/\s\(\)\=\-\"\']//g; } my ($libraries_to_query,$pretty_domains_string) = &parse_domain_restrictions(); @@ -1631,10 +1663,13 @@ sub parse_basic_search { } my $pretty_search_string=$search_string; my @Queries; - my $searchfield = 'concat_ws(" ",'.join(',', - ('title','author','subject', - 'notes','abstract','keywords') - ).')'; + my @fields = ('title','author','subject','notes','abstract','keywords'); + my $searchfield; + if ($env{'form.area'} eq 'portfolio') { + $searchfield = 'concat_ws(" ",pm.'.join(',pm.',@fields).')'; + } else { + $searchfield = 'concat_ws(" ",'.join(',',@fields).')'; + } my ($error,$SQLQuery) = &process_phrase_input($search_string, $env{'form.related'}, $searchfield); @@ -1647,14 +1682,22 @@ sub parse_basic_search { #foreach my $q (@Queries) { # &Apache::lonnet::logthis(' '.$q); #} - my $final_query = 'SELECT * FROM metadata WHERE '.join(" AND ",@Queries); + 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).')'; + } else { + $final_query = 'SELECT * FROM metadata WHERE '.join(" AND ",@Queries); + } # + if ($env{'form.related'}) { + $pretty_search_string.=' '.&mt('(including related words)'); + } if (defined($pretty_domains_string) && $pretty_domains_string ne '') { $pretty_search_string .= ' '.$pretty_domains_string; } $pretty_search_string .= "
\n"; $pretty_search_string =~ s:^
and ::; - #&Apache::lonnet::logthis('simple search final query = '.$/.$final_query); + &Apache::lonnet::logthis('simple search final query = '.$/.$final_query); return ($final_query,$pretty_search_string, $libraries_to_query); } @@ -2046,7 +2089,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; } ## @@ -2055,7 +2098,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()); @@ -2063,7 +2107,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; @@ -2092,10 +2137,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( @@ -2121,18 +2162,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, + {'no_title' => 1}); + my $breadcrumbs= + &Apache::lonhtmlcommon::breadcrumbs('Searching','Searching', + $env{'form.catalogmode'} ne 'import'); + + my $result = < + + END #

Sort Results

@@ -2164,13 +2211,11 @@ END

There are $total_results matches to your query. $revise

-Search:$pretty_query_string +Search: $pretty_query_string

- - END - $r->print($result); + $r->print($result.&Apache::loncommon::end_page()); return; } @@ -2206,7 +2251,7 @@ my @Fullindicies; Creates the table of search results by calling lonmysql. Stores the table id in $env{'form.table'} -Inputs: none. +Inputs: search area - either res or portfolio Returns: the identifier of the table on success, undef on error. @@ -2215,8 +2260,9 @@ Returns: the identifier of the table on ###################################################################### ###################################################################### sub set_up_table_structure { + my ($tabletype) = @_; my ($datatypes,$fullindicies) = - &LONCAPA::lonmetadata::describe_metadata_storage(); + &LONCAPA::lonmetadata::describe_metadata_storage($tabletype); # Copy the table description before modifying it... @Datatypes = @{$datatypes}; unshift(@Datatypes,{name => 'id', @@ -2229,7 +2275,12 @@ sub set_up_table_structure { } sub create_results_table { - &set_up_table_structure(); + my ($area) = @_; + if ($area eq 'portfolio') { + &set_up_table_structure('portfolio_search'); + } else { + &set_up_table_structure('metadata'); + } my $table = &Apache::lonmysql::create_table ( { columns => \@Datatypes, FULLTEXT => [{'columns' => \@Fullindicies},], @@ -2361,23 +2412,26 @@ 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 ($r,$query,$customquery,$customshow,$serverlist, + $pretty_string,$area) = @_; + my $tabletype = 'metadata'; + if ($area eq 'portfolio') { + $tabletype = 'portfolio_search'; + } my $connection = $r->connection; # # Print run_search header # - my $html=&Apache::lonxml::xmlbegin(); + my $start_page = &Apache::loncommon::start_page('Search Status',undef, + {'no_title' => 1}); + my $breadcrumbs = + &Apache::lonhtmlcommon::breadcrumbs('Searching','Searching', + $env{'form.catalogmode'} ne 'import'); $r->print(< -Search Status -$bodytag +$start_page +$breadcrumbs
- + END # Remove leading and trailing
$pretty_string =~ s:^\s*
::i; @@ -2410,12 +2464,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 = ". @@ -2429,12 +2485,14 @@ 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; } ## ## Prepare for the big loop. my $hitcountsum; + my %matches; my $server; my $status; my $revise = &revise_button(); @@ -2489,7 +2547,7 @@ END delete ($Server_status{$server}); next; } - $status=~s|/||g; + $status=~s|/||g; my $datafile=$r->dir_config('lonDaemons').'/tmp/'.$status; if (-e $datafile && ! -e "$datafile.end") { &update_status($r,&mt('Receiving results from [_1]',$server)); @@ -2518,7 +2576,7 @@ END next if (! $result); # # Parse the result. - my %Fields = &parse_raw_result($result,$server); + my %Fields = &parse_raw_result($result,$server,$tabletype); $Fields{'hostname'} = $server; # # Skip if external and we did not want that @@ -2526,6 +2584,12 @@ END # Skip based on copyright next if (! ©right_check(\%Fields)); + if ($area eq 'portfolio') { + next if (defined($matches{$Fields{'url'}})); + # Skip if inaccessible + next if (!&Apache::lonnet::portfolio_access($Fields{'url'})); + $matches{$Fields{'url'}} = 1; + } # # Store the result in the mysql database my $result = &Apache::lonmysql::store_row($table,\%Fields); @@ -2558,8 +2622,8 @@ 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(""); -# if ($env{'form.catalogmode'} ne 'groupsearch') { + $r->print(&Apache::loncommon::end_page()); +# if ($env{'form.catalogmode'} ne 'import') { $r->print(" SCRIPT - $result.=< -$bodytag - - + + my $start_page = &Apache::loncommon::start_page(undef,$js, + {'only_body' =>1}); + my $result=< $importbutton END return $result; } -###################################################################### -###################################################################### -sub search_status_header { - my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1); - my $html=&Apache::lonxml::xmlbegin(); - return < -Search Status -$bodytag -

Search Status

-Sending search request to LON-CAPA servers.
-ENDSTATUS -} - sub results_link { my $basic_link = "/adm/searchcat?"."&table=".$env{'form.table'}. "&persistent_db_id=".$env{'form.persistent_db_id'}; @@ -3151,21 +3227,27 @@ 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 $result = <<"ENDFRAMES"; -$html - - -LON-CAPA Digital Library Search Results - - +JS + + my $start_page = + &Apache::loncommon::start_page('LON-CAPA Digital Library Search Results', + $js, + {'frameset' => 1, + 'add_entries' => { + 'rows' => "150,*",},}); + my $end_page = + &Apache::loncommon::end_page({'frameset' => 1}); + + my $result = <<"ENDFRAMES"; +$start_page - - +$end_page ENDFRAMES $r->print($result); @@ -3233,11 +3315,11 @@ sub detailed_citation_view { my ($prefix,%values) = @_; my $result; my $jumpurl=$values{'url'}; - $jumpurl=~s/^\/ext\//http\:\/\//; + $jumpurl=~s|^/ext/|http://|; $result .= ''.$prefix. - ''.' '. + ''.' '. ''.$values{'title'}."\n"; + 'target="preview">'.$values{'title'}."\n"; $result .= "

\n"; $result .= ''.$values{'author'}.','. ' '.$values{'owner'}.'
'; @@ -3301,25 +3383,29 @@ sub detailed_citation_view { next if (! exists($values{$field->{'name'}}) || $values{$field->{'name'}} eq ''); if (exists($field->{'type'}) && $field->{'type'} eq 'list') { - $result .= ''.&mt($field->{'translate'}).'

    '; + $result .= ''.&mt($field->{'translate'}).''; foreach my $item (split(',',$values{$field->{'name'}})){ - $result .= '
  • '. - ''.$item.'
  • '; + $result .= + &Apache::lonhtmlcommon::crumbs(&Apache::lonnet::clutter($item), + 'preview', + '', + (($env{'form.catalogmode'} eq 'import')?'parent.statusframe.document.forms.statusform':''),2,0,1); } - $result .= '
'; } elsif (exists($field->{'format'}) && $field->{'format'} ne ''){ $result.= &mt($field->{'translate'}, sprintf($field->{'format'}, $values{$field->{'name'}}))."
\n"; } else { if ($field->{'special'} eq 'url link') { - $result.= - &mt($field->{'translate'}, - ''. - $values{$field->{'name'}}. - ''); + 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); + } } else { $result.= &mt($field->{'translate'}, $values{$field->{'name'}}); @@ -3375,11 +3461,19 @@ sub summary_view { $result .= ' '.$tmp.' '; } my $jumpurl=$values{'url'}; - $jumpurl=~s/^\/ext\//http\:\/\//; - + 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); + } $result.=<$values{'title'}
+ target='preview'>$values{'title'}$link $values{'author'}, $values{'owner'} -- $values{'lastrevisiondate'}
$values{'copyrighttag'}
$values{'extrashow'} @@ -3412,8 +3506,16 @@ sub summary_preview { sub compact_view { my ($prefix,%values) = @_; my $jumpurl=$values{'url'}; - $jumpurl=~s/^\/ext\//http\:\/\//; - + 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).' '; + } my $result = $prefix.''; if (exists($env{'form.sortfield'}) && @@ -3422,8 +3524,8 @@ sub compact_view { if (! defined($tmp)) { $tmp = 'undefined'; } $result .= ' '.$tmp.' '; } - $result.=' '. - $values{'title'}.''.(' 'x2). + $result.=' '. + $values{'title'}.''.(' 'x2).$link. ''.$values{'author'}.' ('.$values{'domain'}.')
'; return $result; } @@ -3445,14 +3547,14 @@ sub fielded_format_view { my $icon=&Apache::loncommon::icon($values{'url'}); my %Translated = &Apache::lonmeta::fieldnames(); my $jumpurl=$values{'url'}; - $jumpurl=~s/^\/ext\//http\:\/\//; + $jumpurl=~s|^/ext/|http://|; my $result=<
URL:
$values{'url'}
+ target='preview'>$values{'url'} END foreach my $field ('title','author','domain','subject','keywords','notes', 'mimetag','language','creationdate','lastrevisiondate', @@ -3592,17 +3694,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 @@ -3614,8 +3712,7 @@ $errorstring

$revise

- - +$end_page ENDPAGE } @@ -3641,17 +3738,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 @@ -3663,8 +3756,7 @@ $errormsg

$revise 

- - +$end_page ENDPAGE return; } @@ -3691,16 +3783,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 }