--- loncom/interface/lonsearchcat.pm 2008/02/14 18:04:09 1.291 +++ loncom/interface/lonsearchcat.pm 2009/02/10 09:30:16 1.304 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Search Catalog # -# $Id: lonsearchcat.pm,v 1.291 2008/02/14 18:04:09 bisitz Exp $ +# $Id: lonsearchcat.pm,v 1.304 2009/02/10 09:30:16 schafran Exp $ # # Copyright Michigan State University Board of Trustees # @@ -281,8 +281,9 @@ sub handler { $closebutton .="onClick='self.close()'"; } $closebutton .= ">"; + my $txt_import = &mt('IMPORT'); $importbutton=< END } else { @@ -518,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/$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($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.','','').'
'); } } @@ -698,7 +704,7 @@ sub print_basic_search_form { '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.=(< @@ -759,11 +765,6 @@ sub setup_basic_search { $r->dir_config('lonDefDomain')), $r->dir_config('lonDefDomain')). ''; - if ($area eq 'res') { - $inclext= ''; - } $adv_search_link = ''.&searchhelp().''.''. ''. - ''.(' 'x3).$adv_search_link.''.'
'. - ''.(' 'x1).$userelatedwords.''.'
'. - ''.(' 'x1).$onlysearchdomain.''.'
'. - ''.(' 'x1).$inclext.''.'
'. + ''.(' 'x3).$adv_search_link.''.'
'. + ''.(' 'x1).$userelatedwords.''.'
'. + ''.(' 'x1).$onlysearchdomain.''.'
'. + ''.(' 'x1).$inclext.''.'
'. '
'. ''.$/; # @@ -926,11 +927,6 @@ ENDHEADER &Apache::loncommon::domain_select('domains', $env{'form.domains'},1). '
' - } $scrout .= ''.$/; # # Misc metadata @@ -1044,7 +1040,7 @@ ENDHEADER # Creation/Modification date limits $scrout .= '

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

'; $scrout .= "\n\n"; - $scrout .= "\n"; + $scrout .= "\n"; my $cafter = &Apache::lonhtmlcommon::date_setter('advsearch', # formname 'creationdate1', # fieldname @@ -1163,7 +1159,7 @@ Outputs: text for box with view options ###################################################################### ###################################################################### sub viewoptions { - my $scrout; + my $scrout = ''; if (! defined($env{'form.viewselect'})) { $env{'form.viewselect'}='detailed'; } @@ -1176,8 +1172,9 @@ sub viewoptions { $env{'form.show'}, undef, (10,20,50,100,1000,10000)); - $scrout .= (' 'x2).&mt('[_1] Records per Page',$countselect). - ''.$/; + $scrout .= (' 'x2) + .&mt('[_1] Records per Page',$countselect) + .''.$/; return $scrout; } @@ -1403,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. @@ -1648,7 +1645,7 @@ sub parse_advanced_search { # if (@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).'))'; + $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).')'; } @@ -1711,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. @@ -1750,7 +1747,7 @@ sub parse_basic_search { #} 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).')'; + $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); } @@ -2126,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; } @@ -2494,8 +2495,6 @@ sub run_search { $r->print(< - END # Remove leading and trailing
$pretty_string =~ s:^\s*
::i; @@ -2506,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(); @@ -2561,18 +2560,22 @@ END my $server; my $status; my $revise = &revise_button(); - $r->print(< -
- - - - - - -
 ".&mt('(Month - Day - Year)')."
 ".&mt('Month[_1]Day[_2]Year',' 'x14,' 'x6)."
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); @@ -2644,8 +2647,6 @@ END 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)); @@ -2899,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). ''.