--- loncom/interface/lonsearchcat.pm 2006/05/01 19:37:34 1.263 +++ loncom/interface/lonsearchcat.pm 2007/05/02 01:33:49 1.286 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Search Catalog # -# $Id: lonsearchcat.pm,v 1.263 2006/05/01 19:37:34 albertel Exp $ +# $Id: lonsearchcat.pm,v 1.286 2007/05/02 01:33:49 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -78,6 +78,7 @@ use HTML::Entities(); use Parse::RecDescent; use Apache::lonnavmaps; use Apache::lonindexer(); +use LONCAPA; ###################################################################### ###################################################################### @@ -137,7 +138,7 @@ sub handler { &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['catalogmode','launch','acts','mode','form','element','pause', 'phase','persistent_db_id','table','start','show', - 'cleargroupsort','titleelement']); + '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 @@ -153,7 +154,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. @@ -164,30 +165,37 @@ sub handler { } 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(); + + my @allowed_searches = ('portfolio'); + if (&Apache::lonnet::allowed('bre',$env{'request.role.domain'})) { + push(@allowed_searches,'res'); + } if (exists($env{'request.course.id'}) && $env{'request.course.id'} ne '') { - &Apache::lonhtmlcommon::add_breadcrumb - ({href=>'/adm/searchcat?'. - 'catalogmode='.$env{'form.catalogmode'}. - '&launch='.$env{'form.launch'}. - '&mode='.$env{'form.mode'}, - text=>"Course and Catalog Search", - target=>'_top', - bug=>'Searching',}); - } else { - &Apache::lonhtmlcommon::add_breadcrumb - ({href=>'/adm/searchcat?'. - 'catalogmode='.$env{'form.catalogmode'}. - '&launch='.$env{'form.launch'}. - '&mode='.$env{'form.mode'}, - text=>"Catalog Search", + 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'; + } + } + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>'/adm/searchcat?'. + 'catalogmode='.$env{'form.catalogmode'}. + '&launch='.$env{'form.launch'}. + '&mode='.$env{'form.mode'}, + text=>"$crumb_text", target=>'_top', bug=>'Searching',}); - } # if ($env{'form.phase'} !~ m/(basic|adv|course)_search/) { if (! &get_persistent_form_data($persistent_db_file)) { @@ -213,7 +221,7 @@ sub handler { 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; @@ -247,6 +255,9 @@ sub handler { 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 ## @@ -258,7 +269,7 @@ sub handler { $closebutton .="onClick='self.close()'"; } $closebutton .=">\n"; - } elsif ($env{'form.catalogmode'} eq 'groupsearch') { + } elsif ($env{'form.catalogmode'} eq 'import') { $closebutton="'/adm/searchcat?phase=disp_adv&'. 'catalogmode='.$env{'form.catalogmode'}. '&launch='.$env{'form.launch'}. '&mode='.$env{'form.mode'}, - text=>"Advanced Search", + text=>"Advanced $srchtype Search", bug=>'Searching',}); } elsif ($env{'form.searchmode'} eq 'course search') { &Apache::lonhtmlcommon::add_breadcrumb @@ -316,7 +331,8 @@ END } elsif ($env{'form.phase'} eq 'disp_adv') { &print_advanced_search_form($r,$closebutton,$hidden_fields); } elsif ($env{'form.phase'} eq 'results') { - &display_results($r,$importbutton,$closebutton,$diropendb); + &display_results($r,$importbutton,$closebutton,$diropendb, + $env{'form.area'}); } elsif ($env{'form.phase'} =~ /^(sort|run_search)$/) { my ($query,$customquery,$customshow,$libraries,$pretty_string) = &get_persistent_data($persistent_db_file, @@ -326,7 +342,7 @@ END &print_sort_form($r,$pretty_string); } elsif ($env{'form.phase'} eq 'run_search') { &run_search($r,$query,$customquery,$customshow, - $libraries,$pretty_string); + $libraries,$pretty_string,$env{'form.area'}); } } elsif ($env{'form.phase'} eq 'course_search') { &course_search($r); @@ -356,14 +372,14 @@ END $persistent_db_file); # # Set up table - if (! defined(&create_results_table())) { + if (! defined(&create_results_table($env{'form.area'}))) { my $errorstring=&Apache::lonmysql::get_error(); &Apache::lonnet::logthis('lonsearchcat.pm: Unable to create '. 'needed table. lonmysql error:'. $errorstring); my $msg = - 'Unable to create table in which to store search results. '. + 'Unable to create table in which to save search results. '. 'The search has been aborted.'; &Apache::loncommon::simple_error_page($r,'Search Error', $msg); @@ -372,7 +388,7 @@ END delete($env{'form.launch'}); if (! &make_form_data_persistent($r,$persistent_db_file)) { my $msg= - 'Unable to properly store search information. '. + 'Unable to properly save search information. '. 'The search has been aborted.'; &Apache::loncommon::simple_error_page($r,'Search Error', $msg); @@ -505,7 +521,7 @@ sub course_search { my $applies = 0; my $symb = $resource->symb(); my $ressymb = $symb; - if ($symb =~ m#(___adm/\w+/\w+)/(\d+)/bulletinboard$#) { + if ($symb =~ m#(___adm/$LONCAPA::domain_re/$LONCAPA::username_re)/(\d+)/bulletinboard$#) { $ressymb = 'bulletin___'.$2.$1.'/'.$2.'/bulletinboard'; unless ($ressymb =~ m#bulletin___\d+___adm/wrapper#) { $ressymb=~s#(bulletin___\d+___)#$1adm/wrapper/#; @@ -551,7 +567,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.'
'); @@ -587,7 +603,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; @@ -603,7 +619,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). '
'); @@ -658,75 +674,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 $result = ($env{'form.catalogmode'} ne 'import'); my $bread_crumb = &Apache::lonhtmlcommon::breadcrumbs('Searching','Search_Basic', - $env{'form.catalogmode'} ne 'groupsearch'); + $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', @@ -777,6 +736,79 @@ ENDENDCOURSE $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; +} + ###################################################################### ###################################################################### @@ -794,7 +826,7 @@ sub print_advanced_search_form{ my ($r,$closebutton,$hidden_fields) = @_; my $bread_crumb = &Apache::lonhtmlcommon::breadcrumbs('Searching','Search_Advanced', - $env{'form.catalogmode'} ne 'groupsearch'); + $env{'form.catalogmode'} ne 'import'); my %lt=&Apache::lonlocal::texthash('srch' => 'Search', 'reset' => 'Reset', 'help' => 'Help'); @@ -803,7 +835,22 @@ sub print_advanced_search_form{ $closebutton END - my $scrout= &Apache::loncommon::start_page('Advanced Catalog Search'); + 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
@@ -814,7 +861,7 @@ ENDHEADER ''; my %fields=&Apache::lonmeta::fieldnames(); # - $scrout .= '

'.&mt('Standard Metadata').'

'; + $scrout .= '

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

'; $scrout .= "\n"; $scrout .= '\n"; @@ -871,20 +918,26 @@ ENDHEADER &titlefield(&mt('Domains')).''.$/; + '
' + } + $scrout .= ''.$/; # # Misc metadata - $scrout.=''.$/; + if ($env{'form.area'} ne 'portfolio') { + $scrout.=''.$/; + } $scrout.=''; - $scrout .= "
 '. (' 'x2).&searchhelp()."
'. &Apache::loncommon::domain_select('domains', $env{'form.domains'},1). - '
'. - &titlefield(&mt('Copyright/Distribution')).''. - &Apache::lonmeta::selectbox('copyright', - $env{'form.copyright'}, - \&Apache::loncommon::copyrightdescription, - ( undef, - &Apache::loncommon::copyrightids) - ).'
'. + &titlefield(&mt('Copyright/Distribution')). + ''. + &Apache::lonmeta::selectbox('copyright', + $env{'form.copyright'}, + \&Apache::loncommon::copyrightdescription, + ( undef, + &Apache::loncommon::copyrightids) + ).'
'. &titlefield(&mt('Language')).''. &Apache::lonmeta::selectbox('language', @@ -892,62 +945,94 @@ ENDHEADER \&Apache::loncommon::languagedescription, ('any',&Apache::loncommon::languageids) ).'
\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 + my $curnumadd = $env{'form.numaddedfields'}; + if ($curnumadd eq '') { + $curnumadd = 1; + } + $scrout .= '

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

'; + $scrout .= "
 '.&mt('Minimum').''.&mt('Maximum').'
'. - &titlefield(&mt($evaluation->{'description'})). - ''. - ''. - ''. - ''. - '
\n"; + $scrout .= ''.''; + + for (my $j=0; $j<$curnumadd; $j++) { + my $num = $j+1; + $scrout .= ''. + ''; + } + $scrout .= '
 '. + &mt('Field Name').''. + &mt('Field Value(s)').'
'.&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=> + 'Statistics calculated for number of students',}, + { 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').'

'; @@ -1149,7 +1234,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}) { @@ -1195,7 +1280,7 @@ sub get_persistent_data { next; } my @values = map { - &Apache::lonnet::unescape($_); + &unescape($_); } split(',',$persistent_db{$name}); if (@values <= 1) { push @Values,$values[0]; @@ -1232,7 +1317,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); @@ -1310,12 +1395,12 @@ 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. 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. @@ -1343,6 +1428,17 @@ sub parse_advanced_search { $fillflag++; } } + if ($env{'form.area'} eq 'portfolio') { + # Added metadata fields + for (my $i=0; $i<$env{'form.numaddedfields'} ; $i++) { + my $field = $env{'form.addedfield_'.$i}; + $field =~ s/^\s*(\S*)\s*$/$1/; + $field =~ s/\W/_/g; + if ($field ne '') { + $fillflag++; + } + } + } if (! $fillflag) { &output_blank_field_error($r,$closebutton, 'phase=disp_adv',$hidden_fields); @@ -1429,29 +1525,56 @@ 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++) { + my $field = $env{'form.addedfield_'.$i}; + $field =~ s/^\s*(\S*)\s*$/$1/; + $field =~ s/\W/_/g; + $field =~ tr/A-Z/a-z/; + if ($field ne '') { + my $value = $env{'form.addedvalues_'.$i}; + if ($value ne '') { + $value =~ s/'/''/g; #' stupid emacs + my ($error,$query) = + &process_phrase_input($value,0,'pf.value'); + if (!defined($error)) { + push(@queries,"pf.field = '$field' AND $query"); + $pretty_search_string .= + $font.$field.': '. + $env{'form.addedvalues_'.$i}.'
'; + } + } else { + push(@queries,"pf.field = '$field' AND pf.value IS NULL"); + } + } + } + } 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.'
'; + } } } # @@ -1516,7 +1639,11 @@ sub parse_advanced_search { } # if (@queries) { - $query="SELECT * FROM metadata WHERE (".join(") AND (",@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).'))'; + } else { + $query="SELECT * FROM metadata WHERE (".join(") AND (",@queries).')'; + } } elsif ($customquery) { $query = ''; } @@ -1540,21 +1667,19 @@ 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 .= "".$_." "; } - foreach (keys(%Apache::lonnet::libserv)) { - if (exists($domain_hash{$Apache::lonnet::hostdom{$_}})) { - push @$libraries_to_query,$_; - } - } + my %servers = &Apache::lonnet::get_servers(\@allowed_domains, + 'library'); + $libraries_to_query = [keys(%servers)]; } return ($libraries_to_query, $pretty_domains_string); @@ -1583,7 +1708,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(); @@ -1596,10 +1721,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); @@ -1612,14 +1740,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); } @@ -1722,7 +1858,7 @@ sub process_phrase_input { $item[1]; } term: - /[\w\Q:!@#$%^&*()+_=|{}<>,.;\\\/?\E]+/ { + /[\w\Q:!@#$%^&*()+_=|{}<>,.;\\\/?\E\-]+/ { $item[1]; } ENDGRAMMAR @@ -2010,7 +2146,7 @@ sub ensure_db_and_table { ## if (! defined($table) || $table eq '' || $table =~ /\D/ ) { $r->print("Unable to retrieve search results. ". - "Unable to determine the table results were stored in. ". + "Unable to determine the table results were saved in. ". &Apache::loncommon::end_page()); return undef; } @@ -2020,7 +2156,7 @@ sub ensure_db_and_table { my $connection_result = &Apache::lonmysql::connect_to_db(); if (!defined($connection_result)) { $r->print("Unable to connect to the MySQL database where your results". - " are stored.". + " are saved.". &Apache::loncommon::end_page()); &Apache::lonnet::logthis("lonsearchcat: unable to get lonmysql to". " connect to database."); @@ -2104,16 +2240,17 @@ sub print_sort_form { END my $start_page = &Apache::loncommon::start_page('Results',$js, - {'only_body' => 1}); + {'no_title' => 1}); my $breadcrumbs= &Apache::lonhtmlcommon::breadcrumbs('Searching','Searching', - $env{'form.catalogmode'} ne 'groupsearch'); + $env{'form.catalogmode'} ne 'import'); my $result = < - + + + END #

Sort Results

@@ -2132,7 +2269,7 @@ END

There are $total_results matches to your query. $revise

-Search:$pretty_query_string +Search: $pretty_query_string

END @@ -2172,7 +2309,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. @@ -2181,8 +2318,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', @@ -2195,7 +2333,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},], @@ -2327,22 +2470,26 @@ results into MySQL. ###################################################################### ###################################################################### sub run_search { - my ($r,$query,$customquery,$customshow,$serverlist,$pretty_string) = @_; - + 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 $start_page = &Apache::loncommon::start_page('Search Status',undef, - {'only_body' => 1}); + {'no_title' => 1}); my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Searching','Searching', - $env{'form.catalogmode'} ne 'groupsearch'); + $env{'form.catalogmode'} ne 'import'); $r->print(< - + END # Remove leading and trailing
$pretty_string =~ s:^\s*
::i; @@ -2367,14 +2514,15 @@ END @Servers_to_contact = ($serverlist); } } else { - @Servers_to_contact = sort(keys(%Apache::lonnet::libserv)); + my %all_library_servers = &Apache::lonnet::all_library(); + @Servers_to_contact = sort(keys(%all_library_servers)); } my %Server_status; # # Check on the mysql table we will use to store results. my $table =$env{'form.table'}; if (! defined($table) || $table eq '' || $table =~ /\D/ ) { - $r->print("Unable to determine table id to store search results in.". + $r->print("Unable to determine table id to save search results in.". "The search has been aborted.". &Apache::loncommon::end_page()); return; @@ -2403,6 +2551,7 @@ END ## ## Prepare for the big loop. my $hitcountsum; + my %matches; my $server; my $status; my $revise = &revise_button(); @@ -2457,7 +2606,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)); @@ -2486,7 +2635,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 @@ -2494,6 +2643,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); @@ -2527,7 +2682,7 @@ END # results to get, so let the client know the top frame needs to be # loaded from /adm/searchcat $r->print(&Apache::loncommon::end_page()); -# if ($env{'form.catalogmode'} ne 'groupsearch') { +# if ($env{'form.catalogmode'} ne 'import') { $r->print(" SCRIPT @@ -3086,25 +3264,12 @@ SCRIPT {'only_body' =>1}); my $result=< - +
$importbutton END return $result; } -###################################################################### -###################################################################### -sub search_status_header { - my $start_page = &Apache::loncommon::start_page('Search Status',undef, - {'only_body' => 1}); - return <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'}; @@ -3209,11 +3374,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'}.'
'; @@ -3277,25 +3442,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'}}); @@ -3351,11 +3520,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'} @@ -3388,8 +3565,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'}) && @@ -3398,8 +3583,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; } @@ -3421,14 +3606,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',