--- loncom/interface/lonsearchcat.pm 2006/06/13 14:42:24 1.269 +++ loncom/interface/lonsearchcat.pm 2009/02/26 16:17:30 1.305 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Search Catalog # -# $Id: lonsearchcat.pm,v 1.269 2006/06/13 14:42:24 www Exp $ +# $Id: lonsearchcat.pm,v 1.305 2009/02/26 16:17:30 schafran Exp $ # # Copyright Michigan State University Board of Trustees # @@ -78,7 +78,6 @@ use HTML::Entities(); use Parse::RecDescent; use Apache::lonnavmaps; use Apache::lonindexer(); -use lib '/home/httpd/lib/perl/'; use LONCAPA; ###################################################################### @@ -139,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','inhibitmenu']); ## ## 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 @@ -171,25 +170,33 @@ sub handler { '_'.$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?'. + &Apache::loncommon::inhibit_menu_check(). + '&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)) { @@ -249,11 +256,17 @@ sub handler { if (exists($env{'form.mode'})) { $hidden_fields .= &hidden_field('mode'); } + if (exists($env{'form.area'})) { + $hidden_fields .= &hidden_field('area'); + } + if (exists($env{'form.inhibitmenu'})) { + $hidden_fields .= &hidden_field('inhibitmenu'); + } ## ## Configure dynamic components of interface ## if ($env{'form.catalogmode'} eq 'interactive') { - $closebutton=" END } else { @@ -294,16 +308,22 @@ END } # if ($env{'form.searchmode'} eq 'advanced') { + my $srchtype = 'Catalog'; + if ($env{'form.area'} eq 'portfolio') { + $srchtype = 'Portfolio'; + } &Apache::lonhtmlcommon::add_breadcrumb - ({href=>'/adm/searchcat?phase=disp_adv&'. - 'catalogmode='.$env{'form.catalogmode'}. + ({href=>'/adm/searchcat?'.&Apache::loncommon::inhibit_menu_check(). + '&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 - ({href=>'/adm/searchcat?phase=disp_adv&'. + ({href=>'/adm/searchcat?'.&Apache::loncommon::inhibit_menu_check(). + '&phase=disp_adv'. 'catalogmode='.$env{'form.catalogmode'}. '&launch='.$env{'form.launch'}. '&mode='.$env{'form.mode'}, @@ -318,7 +338,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, @@ -328,7 +349,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); @@ -358,14 +379,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); @@ -374,7 +395,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); @@ -498,72 +519,77 @@ sub course_search { my $totaldiscussions = 0; $r->print('

'.&mt('Discussion postings').':
'); my $navmap = Apache::lonnavmaps::navmap->new(); - my @allres=$navmap->retrieveResources(); - my %discussiontime = &Apache::lonnet::dump('discussiontimes', - $env{'course.'.$env{'request.course.id'}.'.domain'}, - $env{'course.'.$env{'request.course.id'}.'.num'}); - foreach my $resource (@allres) { - my $result = ''; - my $applies = 0; - my $symb = $resource->symb(); - my $ressymb = $symb; - if ($symb =~ m#(___adm/\w+/\w+)/(\d+)/bulletinboard$#) { - $ressymb = 'bulletin___'.$2.$1.'/'.$2.'/bulletinboard'; - unless ($ressymb =~ m#bulletin___\d+___adm/wrapper#) { - $ressymb=~s#(bulletin___\d+___)#$1adm/wrapper/#; + if (defined($navmap)) { + my @allres=$navmap->retrieveResources(); + my %discussiontime = &Apache::lonnet::dump('discussiontimes', + $env{'course.'.$env{'request.course.id'}.'.domain'}, + $env{'course.'.$env{'request.course.id'}.'.num'}); + foreach my $resource (@allres) { + my $result = ''; + my $applies = 0; + my $symb = $resource->symb(); + my $ressymb = $symb; + 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/#; + } } - } - if (defined($discussiontime{$ressymb})) { - my %contrib = &Apache::lonnet::restore($ressymb,$env{'request.course.id'}, - $env{'course.'.$env{'request.course.id'}.'.domain'}, - $env{'course.'.$env{'request.course.id'}.'.num'}); - if ($contrib{'version'}) { - for (my $id=1;$id<=$contrib{'version'};$id++) { - unless (($contrib{'hidden'}=~/\.$id\./) || ($contrib{'deleted'}=~/\.$id\./)) { - if ($contrib{$id.':subject'}) { - $result .= $contrib{$id.':subject'}; - } - if ($contrib{$id.':message'}) { - $result .= $contrib{$id.':message'}; - } - if ($contrib{$id,':attachmenturl'}) { - if ($contrib{$id,':attachmenturl'} =~ m-/([^/]+)$-) { - $result .= $1; + if (defined($discussiontime{$ressymb})) { + my %contrib = &Apache::lonnet::restore($ressymb,$env{'request.course.id'}, + $env{'course.'.$env{'request.course.id'}.'.domain'}, + $env{'course.'.$env{'request.course.id'}.'.num'}); + if ($contrib{'version'}) { + for (my $id=1;$id<=$contrib{'version'};$id++) { + unless (($contrib{'hidden'}=~/\.$id\./) || ($contrib{'deleted'}=~/\.$id\./)) { + if ($contrib{$id.':subject'}) { + $result .= $contrib{$id.':subject'}; + } + if ($contrib{$id.':message'}) { + $result .= $contrib{$id.':message'}; + } + if ($contrib{$id,':attachmenturl'}) { + if ($contrib{$id,':attachmenturl'} =~ m-/([^/]+)$-) { + $result .= $1; + } } + $applies = &checkwords($result,$applies,@allwords); } - $applies = &checkwords($result,$applies,@allwords); } } } - } # Does this discussion apply? - if ($applies) { - my ($map,$ind,$url)=&Apache::lonnet::decode_symb($ressymb); - my $disctype = &mt('resource'); - if ($url =~ m#/bulletinboard$#) { - if ($url =~m#^adm/wrapper/adm/.*/bulletinboard$#) { - $url =~s#^adm/wrapper##; + if ($applies) { + my ($map,$ind,$url)=&Apache::lonnet::decode_symb($ressymb); + my $disctype = &mt('resource'); + if ($url =~ m#/bulletinboard$#) { + if ($url =~m#^adm/wrapper/adm/.*/bulletinboard$#) { + $url =~s#^adm/wrapper##; + } + $disctype = &mt('discussion board'); + } else { + $url = '/res/'.$url; } - $disctype = &mt('bulletin board'); - } else { - $url = '/res/'.$url; - } - if ($url =~ /\?/) { - $url .= '&symb='; + if ($url =~ /\?/) { + $url .= '&symb='; + } else { + $url .= '?symb='; + } + $url .= &escape($resource->symb()); + my $title = $resource->compTitle(); + $r->print('
'. + ($title?$title:$url).'  - '. + $disctype.'
'); + $totaldiscussions++; } else { - $url .= '?symb='; + $r->print(' .'); } - $url .= &escape($resource->symb()); - my $title = $resource->compTitle(); - $r->print('
'. - ($title?$title:$url).'  - '.$disctype.'
'); - $totaldiscussions++; - } else { - $r->print(' .'); } - } - unless ($totaldiscussions) { - $r->print('

'.&mt('No matches found in postings').'.

'); + unless ($totaldiscussions) { + $r->print('

'.&mt('No matches found in postings').'.

'); + } + } else { + $r->print('
'.&mt('An error occurred retrieving information about resources in the course.').'
'.&mt('It is recommended that you [_1]re-initialize the course[_2] and then try your search again.','','').'
'); } } @@ -664,76 +690,21 @@ sub print_basic_search_form { my $bread_crumb = &Apache::lonhtmlcommon::breadcrumbs('Searching','Search_Basic', $env{'form.catalogmode'} ne 'import'); - my $scrout = &Apache::loncommon::start_page('Search').$bread_crumb; + my $scrout = &Apache::loncommon::start_page('Content Library').$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', - $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', 'note' => 'Enter terms or phrases, then press "Search" below', 'use' => 'use related words', 'full' =>'fulltext search (time consuming)', - 'disc' => 'search discussion postings (resources and bulletin boards)', + 'disc' => 'search discussion postings (resources and discussion boards)', ); $scrout.=(< @@ -777,6 +748,75 @@ 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 = ''; + $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; +} + ###################################################################### ###################################################################### @@ -803,7 +843,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 +869,7 @@ ENDHEADER ''; my %fields=&Apache::lonmeta::fieldnames(); # - $scrout .= '

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

'; + $scrout .= '

'.&mt("Standard $srchtype Metadata").'

'; $scrout .= "\n"; $scrout .= '\n"; @@ -845,7 +900,7 @@ ENDHEADER $env{'form.'.$field.'_related'}, 50); if ($related_word_search{$field}) { - $scrout .= 'related words'; + $scrout .= &mt('related words'); } else { $scrout .= ''.$/; + '
'.$/; + if ($env{'form.area'} ne 'portfolio') { + $scrout.=''.$/; + } $scrout.=''; - $scrout .= "
 '. (' 'x2).&searchhelp()."
 '; } @@ -871,20 +926,21 @@ ENDHEADER &titlefield(&mt('Domains')).''. &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,66 +948,99 @@ 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').'

'; $scrout .= "\n\n"; + $scrout .= "\n"; my $cafter = &Apache::lonhtmlcommon::date_setter('advsearch', # formname 'creationdate1', # fieldname @@ -970,10 +1059,10 @@ ENDHEADER '', # state 1, # no_hh_mm_ss ); - $scrout .= &mt(''. - ''. - ''. - '',$cafter,$cbefore); + $scrout .= '' + .'' + .'' + .''; my $lafter = &Apache::lonhtmlcommon::date_setter('advsearch', 'revisiondate1', @@ -992,10 +1081,10 @@ ENDHEADER '', # state 1, # no_hh_mm_ss ); - $scrout .= &mt(''. - ''. - ''. - '',$lafter,$lbefore); + $scrout .= '' + .'' + .'' + .''; $scrout.="
 ".&mt('Month[_1]Day[_2]Year',' 'x14,' 'x6)."
Created between[_1]
and [_2]
'.&mt('Created between').''.$cafter.'
'.&mt('and').''.$cbefore.'
Last modified between [_1]
and[_2]
'.&mt('Last modified between').''.$lafter.'
'.&mt('and').''.$lbefore.'
\n"; $scrout.=<'.$/; + $scrout .= (' 'x2) + .&mt('[_1] Records per Page',$countselect) + .''.$/; return $scrout; } @@ -1310,7 +1400,7 @@ sub parse_advanced_search { 'lastrevisiondatestart_month','lastrevisiondatestart_day', 'lastrevisiondatestart_year','lastrevisiondateend_month', 'lastrevisiondateend_day','lastrevisiondateend_year') { - $env{'form.'.$field}=~s/[^\w\/\s\(\)\=\-\"\']//g; + $env{'form.'.$field}=~s/[^\w\/\s\(\)\=\-\"\'.\*]//g; } foreach ('mode','form','element') { # is this required? Hmmm. @@ -1343,6 +1433,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 +1530,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 +1644,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 < UTC_TIMESTAMP() AND (pa.end IS NULL OR pa.end > UTC_TIMESTAMP())) AND (".join(') AND (',@queries).'))'; + } else { + $query="SELECT * FROM metadata WHERE (".join(") AND (",@queries).')'; + } } elsif ($customquery) { $query = ''; } @@ -1540,21 +1672,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); @@ -1578,7 +1708,7 @@ sub parse_basic_search { # # Clean up fields for safety for my $field ('basicexp') { - $env{"form.$field"}=~s/[^\w\s\'\"\!\(\)\-]//g; + $env{"form.$field"}=~s/[^\w\s\'\"\!\(\)\-\*]//g; } foreach ('mode','form','element') { # is this required? Hmmm. @@ -1596,10 +1726,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 +1745,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 < UTC_TIMESTAMP() AND (pa.end IS NULL OR pa.end > UTC_TIMESTAMP())) AND '.join(" AND ",@Queries).')'; + } else { + $final_query = 'SELECT * FROM metadata WHERE '.join(" AND ",@Queries); + } # + 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 +1863,7 @@ sub process_phrase_input { $item[1]; } term: - /[\w\Q:!@#$%^&*()+_=|{}<>,.;\\\/?\E]+/ { + /[\w\Q:!@#$%^&*()+_=|{}<>,.;\\\/?\E\-]+/ { $item[1]; } ENDGRAMMAR @@ -1982,6 +2123,10 @@ sub copyright_check { ($env{'user.domain'} ne $resdom)) { return 0; } + # Check for custom rights + if ($Metadata->{'copyright'} eq 'custom') { + return &Apache::lonnet::customaccess('bre',$Metadata->{'url'}); + } return 1; } @@ -2010,7 +2155,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 +2165,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,7 +2249,7 @@ 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 'import'); @@ -2114,7 +2259,7 @@ $start_page $breadcrumbs - + END #

Sort Results

@@ -2129,14 +2274,11 @@ END # } # $result.="\n"; my $revise = &revise_button(); - $result.=< -There are $total_results matches to your query. $revise -

-Search:$pretty_query_string -

- -END + $result.='

' + .&mt('There are [_1] matches to your query.',$total_results) + .' '.$revise.'

' + .'

'.&mt('Search: ').$pretty_query_string + .'

'; $r->print($result.&Apache::loncommon::end_page()); return; } @@ -2173,7 +2315,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. @@ -2182,8 +2324,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', @@ -2196,7 +2339,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},], @@ -2302,13 +2450,14 @@ Returns: html string for a 'revise searc ###################################################################### ###################################################################### sub revise_button { + my $revisetext = &mt('Revise search'); my $revise_phase = 'disp_basic'; $revise_phase = 'disp_adv' if ($env{'form.searchmode'} eq 'advanced'); my $newloc = '/adm/searchcat'. '?persistent_db_id='.$env{'form.persistent_db_id'}. '&cleargroupsort=1'. '&phase='.$revise_phase; - my $result = qq{ }; return $result; } @@ -2328,22 +2477,24 @@ 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 'import'); $r->print(< - END # Remove leading and trailing
$pretty_string =~ s:^\s*
::i; @@ -2354,7 +2505,7 @@ END pop(@Lines); } if (@Lines > 2) { - $pretty_string = join '
',(@Lines[0..2],'....
'); + $pretty_string = join '
',(@Lines[0..2],'...
'); } $r->print(&mt("Search: [_1]",$pretty_string)); $r->rflush(); @@ -2368,14 +2519,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; @@ -2404,21 +2556,26 @@ END ## ## Prepare for the big loop. my $hitcountsum; + my %matches; my $server; my $status; my $revise = &revise_button(); - $r->print(< -StatusTotal MatchesTime Remaining - - - - -$revise - - - -END + $r->print('
'."\n". + ''."\n". + '' + .'' + .'' + .&Apache::loncommon::end_data_table_header_row() + .&Apache::loncommon::start_data_table_row() + .'' + .'' + .'' + .&Apache::loncommon::end_data_table_row() + .&Apache::loncommon::end_data_table() + .'
'."\n". + &Apache::loncommon::start_data_table()); + $r->print(&Apache::loncommon::start_data_table_header_row() + .''.&mt('Status').''.&mt('Total Matches').''.&mt('Time Remaining').' '.$revise.'
'); $r->rflush(); &reset_timing(); &update_seconds($r); @@ -2458,7 +2615,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)); @@ -2487,14 +2644,18 @@ 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 - next if ((! $env{'form.inclext'}) && ($Fields{'url'}=~/^\/ext\//)); # 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); @@ -2581,7 +2742,7 @@ Prints the results out for selection and ###################################################################### ###################################################################### sub display_results { - my ($r,$importbutton,$closebutton,$diropendb) = @_; + my ($r,$importbutton,$closebutton,$diropendb,$area) = @_; my $connection = $r->connection; $r->print(&search_results_header($importbutton,$closebutton)); ## @@ -2606,7 +2767,7 @@ sub display_results { if ($env{'form.catalogmode'} eq 'import') { if (! tie(%groupsearch_db,'GDBM_File',$diropendb, &GDBM_WRCREAT(),0640)) { - $r->print('Unable to store import results.'. + $r->print('Unable to save import results.'. &Apache::loncommon::end_page()); $r->rflush(); return; @@ -2651,7 +2812,8 @@ sub display_results { $r->print(&hidden_field('table'). &hidden_field('phase'). &hidden_field('persistent_db_id'). - &hidden_field('start') + &hidden_field('start'). + &hidden_field('area') ); # # Build sorting selector @@ -2672,6 +2834,16 @@ sub display_results { {key =>'lowestgradelevel'}, {key =>'highestgradelevel'}, {key =>'standards',desc=>'Standards'}, + ); + if ($area eq 'portfolio') { + push(@fields, + ( + {key => 'scope'}, + {key => 'keynum'}, + )); + } else { + push(@fields, + ( {key =>'count',desc=>'Number of accesses'}, {key =>'stdno',desc=>'Students Attempting'}, {key =>'avetries',desc=>'Average Number of Tries'}, @@ -2682,7 +2854,8 @@ sub display_results { {key =>'correct',desc=>'Evaluation: Material is Correct'}, {key =>'helpful',desc=>'Evaluation: Material is Helpful'}, {key =>'depth',desc=>'Evaluation: Material has Depth'}, - ); + )); + } my %fieldnames = &Apache::lonmeta::fieldnames(); my @field_order; foreach my $field_data (@fields) { @@ -2699,7 +2872,13 @@ sub display_results { my %sort_fields = map {$_->{'key'},$_->{'desc'}} @fields; $sort_fields{'select_form_order'} = \@field_order; $env{'form.sortorder'} = 'desc' if (! exists($env{'form.sortorder'})); - $env{'form.sortfield'} = 'count' if (! exists($env{'form.sortfield'})); + if (! exists($env{'form.sortfield'})) { + if ($area eq 'portfolio') { + $env{'form.sortfield'} = 'owner'; + } else { + $env{'form.sortfield'} = 'count'; + } + } if (! exists($env{'form.sortorder'})) { if ($env{'form.sortfield'}=~/^(count|stdno|disc|clear|technical|correct|helpful)$/) { $env{'form.sortorder'}='desc'; @@ -2721,7 +2900,7 @@ sub display_results { ## Output links (if necessary) for 'prev' and 'next' pages. $r->print ('
'. - ''.$sortform.''. + ''.$sortform.''. ''. &prev_next_buttons($min,$env{'form.show'},$total_results). ''. @@ -2763,12 +2942,16 @@ sub display_results { my @Results = &Apache::lonmysql::get_rows($table,$sort_command); ## ## Loop through the results and output them. + my $tabletype = 'metadata'; + if ($area eq 'portfolio') { + $tabletype = 'portfolio_search'; + } foreach my $row (@Results) { if ($connection->aborted()) { &cleanup(); return; } - my %Fields = %{&parse_row(@$row)}; + my %Fields = %{&parse_row($tabletype,@$row)}; my $output="

\n"; if (! defined($Fields{'title'}) || $Fields{'title'} eq '') { $Fields{'title'} = 'Untitled'; @@ -2821,8 +3004,8 @@ sub catalogmode_output { $title=~ s/\'/\\\'/g; if ($env{'form.catalogmode'} eq 'interactive') { $output.=< + END } @@ -2831,7 +3014,7 @@ END $groupsearch_db{"pre_${fnum}_title"}=$title; $output.=< - END @@ -2852,10 +3035,10 @@ Parse a row returned from the database. ###################################################################### ###################################################################### sub parse_row { - my @Row = @_; + my ($tabletype,@Row) = @_; my %Fields; if (! scalar(@Datatypes)) { - &set_up_table_structure(); + &set_up_table_structure($tabletype); } for (my $i=0;$i<=$#Row;$i++) { $Fields{$Datatypes[$i]->{'name'}}=&unescape($Row[$i]); @@ -2891,12 +3074,13 @@ The 'title' field is set to "Untitled" i ########################################################### ########################################################### sub parse_raw_result { - my ($result,$hostname) = @_; + my ($result,$hostname,$tabletype) = @_; # conclude from self to others regarding fields my %Fields=&LONCAPA::lonmetadata::metadata_col_to_hash - (map { + ($tabletype, + map { &unescape($_); - } (split(/\,/,$result)) ); + } (split(/\,/,$result)) ); return %Fields; } @@ -3057,28 +3241,29 @@ function changeURL(val) { SCRIPT } } + my $inhibit_menu = "&".&Apache::loncommon::inhibit_menu_check(); $js.=< SCRIPT @@ -3093,18 +3278,6 @@ 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 +3382,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"; + ''.$values{'title'}."\n"; $result .= "

\n"; $result .= ''.$values{'author'}.','. ' '.$values{'owner'}.'
'; @@ -3279,11 +3452,8 @@ sub detailed_citation_view { if (exists($field->{'type'}) && $field->{'type'} eq 'list') { $result .= ''.&mt($field->{'translate'}).''; foreach my $item (split(',',$values{$field->{'name'}})){ - $result .= - &Apache::lonhtmlcommon::crumbs($item, - (($env{'form.catalogmode'} eq 'import')?'_top':'preview'), - '/res', - (($env{'form.catalogmode'} eq 'import')?'parent.statusframe.document.forms.statusform':''),2,0,1); + $item = &Apache::lonnet::clutter($item); + $result .= &display_url($item,[2,0,1]); } } elsif (exists($field->{'format'}) && $field->{'format'} ne ''){ $result.= &mt($field->{'translate'}, @@ -3291,11 +3461,7 @@ sub detailed_citation_view { $values{$field->{'name'}}))."
\n"; } else { if ($field->{'special'} eq 'url link') { - $result.= - &Apache::lonhtmlcommon::crumbs($jumpurl, - (($env{'form.catalogmode'} eq 'import')?'_top':'preview'), - '', - (($env{'form.catalogmode'} eq 'import')?'parent.statusframe.document.forms.statusform':''),3,0,1); + $result .= &display_url($jumpurl,[3,0,1]); } else { $result.= &mt($field->{'translate'}, $values{$field->{'name'}}); @@ -3351,15 +3517,13 @@ sub summary_view { $result .= ' '.$tmp.' '; } my $jumpurl=$values{'url'}; - $jumpurl=~s/^\/ext\//http\:\/\//; - my $link=&Apache::lonhtmlcommon::crumbs($jumpurl, - (($env{'form.catalogmode'} eq 'import')?'_top':'preview'), - '', - (($env{'form.catalogmode'} eq 'import')?'parent.statusframe.document.forms.statusform':''),2,0,1); + $jumpurl=~s|^/ext/|http://|; + my $link = &display_url($jumpurl,[2,0,1]); $result.=<$values{'title'}$link +$values{'title'}
+$link
$values{'author'}, $values{'owner'} -- $values{'lastrevisiondate'}
$values{'copyrighttag'}
$values{'extrashow'} @@ -3392,11 +3556,10 @@ sub summary_preview { sub compact_view { my ($prefix,%values) = @_; my $jumpurl=$values{'url'}; - $jumpurl=~s/^\/ext\//http\:\/\//; - my $link=&Apache::lonhtmlcommon::crumbs($jumpurl, - (($env{'form.catalogmode'} eq 'import')?'_top':'preview'), - '', - (($env{'form.catalogmode'} eq 'import')?'parent.statusframe.document.forms.statusform':''),1,1,1).' '; + $jumpurl=~s|^/ext/|http://|; + + my $link = &display_url($jumpurl,[1,1,1]); + my $result = $prefix.''; if (exists($env{'form.sortfield'}) && @@ -3405,12 +3568,30 @@ sub compact_view { if (! defined($tmp)) { $tmp = 'undefined'; } $result .= ' '.$tmp.' '; } - $result.=' '. - $values{'title'}.''.(' 'x2).$link. - ''.$values{'author'}.' ('.$values{'domain'}.')
'; + $jumpurl = &HTML::Entities::encode($jumpurl,'<>&"'); + $result.=' '. + ''. + &HTML::Entities::encode($values{'title'},'<>&"').' '. + $link.' '.$values{'author'}.' ('.$values{'domain'}.')
'; return $result; } +sub display_url { + my ($url,$crumb_args) = @_; + my $link; + if ($url=~m|^/ext/|) { + $url=~s|^/ext/|http://|; + $link=''.$url.''; + } elsif ($url=~m{^(http://|/uploaded/)}) { + $link=''.$url.''; + } else { + $link=&Apache::lonhtmlcommon::crumbs($url, + 'preview', + '', + (($env{'form.catalogmode'} eq 'import')?'parent.statusframe.document.forms.statusform':''),@{$crumb_args}).' '; + } + return $link; +} ###################################################################### ###################################################################### @@ -3428,14 +3609,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'}
+
$values{'url'}
END foreach my $field ('title','author','domain','subject','keywords','notes', 'mimetag','language','creationdate','lastrevisiondate',