');
}
# Check discussions if requested
@@ -496,72 +530,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 .= &Apache::lonnet::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.','','').'
');
}
}
@@ -587,7 +626,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 +642,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,80 +697,25 @@ 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');
- my $scrout = &Apache::loncommon::start_page('Search').$bread_crumb;
+ $env{'form.catalogmode'} ne 'import');
+ 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.='';
+ $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.=(<
@@ -743,7 +727,6 @@ $hidden_fields
@@ -775,6 +759,91 @@ 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.='';
+ return $scrout;
+}
+
######################################################################
######################################################################
@@ -792,30 +861,57 @@ 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');
my $advanced_buttons=<<"END";
+
$closebutton
+
END
- my $scrout= &Apache::loncommon::start_page('Advanced Catalog Search');
- $scrout .= <<"ENDHEADER";
-$bread_crumb
-';
+
$scrout .= &Apache::loncommon::end_page();
$r->print($scrout);
return;
@@ -1072,17 +1212,20 @@ sub viewoptions {
if (! defined($env{'form.viewselect'})) {
$env{'form.viewselect'}='detailed';
}
- $scrout.=&Apache::lonmeta::selectbox('viewselect',
- $env{'form.viewselect'},
- \&viewoptiontext,
- sort(keys(%Views)));
- $scrout.= ' ';
+ $scrout .= ''
+ .&mt('Type:').' '
+ .&Apache::lonmeta::selectbox('viewselect',
+ $env{'form.viewselect'},
+ \&viewoptiontext,
+ sort(keys(%Views)))
+ .'';
my $countselect = &Apache::lonmeta::selectbox('show',
$env{'form.show'},
undef,
(10,20,50,100,1000,10000));
- $scrout .= (' 'x2).&mt('[_1] Records per Page',$countselect).
- ''.$/;
+ $scrout .= ' '
+ .&mt('Records per Page:').' '.$countselect
+ .''.$/;
return $scrout;
}
@@ -1147,7 +1290,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}) {
@@ -1193,7 +1336,7 @@ sub get_persistent_data {
next;
}
my @values = map {
- &Apache::lonnet::unescape($_);
+ &unescape($_);
} split(',',$persistent_db{$name});
if (@values <= 1) {
push @Values,$values[0];
@@ -1230,7 +1373,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);
@@ -1308,12 +1451,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.
@@ -1341,6 +1484,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);
@@ -1427,29 +1581,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.' ';
+ }
}
}
#
@@ -1514,7 +1695,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 = '';
}
@@ -1538,21 +1723,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);
@@ -1576,12 +1759,12 @@ 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.
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();
@@ -1594,10 +1777,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);
@@ -1610,14 +1796,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);
}
@@ -1720,7 +1914,7 @@ sub process_phrase_input {
$item[1];
}
term:
- /[\w\Q:!@#$%^&*()+_=|{}<>,.;\\\/?\E]+/ {
+ /[\w\Q:!@#$%^&*()+_=|{}<>,.;\\\/?\E\-]+/ {
$item[1];
}
ENDGRAMMAR
@@ -1980,6 +2174,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;
}
@@ -2007,9 +2205,13 @@ sub ensure_db_and_table {
## Sanity check the table id.
##
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());
+ $r->print(&Apache::loncommon::start_page(&mt('Error'))
+. '
table: |'.$table.'|
' # SB
+ .'
'
+ .&mt('Unable to retrieve search results. '
+ .'Unable to determine the table results were saved in.')
+ .&Apache::loncommon::end_page()
+ );
return undef;
}
##
@@ -2018,7 +2220,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.");
@@ -2091,27 +2293,29 @@ sub print_sort_form {
}
my $js =<
+//
END
- my $start_page = &Apache::loncommon::start_page('Results',$js,
- {'only_body' => 1});
+ my $start_page = &Apache::loncommon::start_page('Results',$js);
my $breadcrumbs=
&Apache::lonhtmlcommon::breadcrumbs('Searching','Searching',
- $env{'form.catalogmode'} ne 'groupsearch');
+ $env{'form.catalogmode'} ne 'import');
my $result = <
-
+
-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;
}
@@ -2170,7 +2371,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.
@@ -2179,8 +2380,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',
@@ -2193,7 +2395,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},],
@@ -2237,16 +2444,28 @@ Returns: Nothing.
sub update_count_status {
my ($r,$text) = @_;
$text =~ s/\'/\\\'/g;
- $r->print
- ("\n");
+ $r->print(<
+SCRIPT
+
$r->rflush();
}
sub update_status {
my ($r,$text) = @_;
$text =~ s/\'/\\\'/g;
- $r->print
- ("\n");
+ $r->print(<
+SCRIPT
+
$r->rflush();
}
@@ -2273,9 +2492,14 @@ sub update_seconds {
my ($r) = @_;
my $time = &time_left();
if (($last_time-$time) > 0) {
- $r->print("\n");
+ $r->print(<
+SCRIPT
+
$r->rflush();
}
$last_time = $time;
@@ -2299,14 +2523,15 @@ 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{ };
+ '&cleargroupsort=1'.
+ '&phase='.$revise_phase;
+ my $result = qq{ };
return $result;
}
@@ -2325,22 +2550,23 @@ 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});
+ my $start_page = &Apache::loncommon::start_page('Search Status',undef);
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;
@@ -2351,7 +2577,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();
@@ -2365,14 +2591,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;
@@ -2401,21 +2628,26 @@ END
##
## Prepare for the big loop.
my $hitcountsum;
+ my %matches;
my $server;
my $status;
my $revise = &revise_button();
- $r->print(<
-
'
+ .&mt('Internal Error - Bad view selected.')
+ .'
'."\n");
$r->rflush();
return;
}
##
## $checkbox_num is a count of the number of checkboxes output on the
- ## page this is used only during catalogmode=groupsearch.
+ ## page this is used only during catalogmode=import.
my $checkbox_num = 0;
##
## Get the catalog controls setup
##
my $action = "/adm/searchcat?phase=results";
##
- ## Deal with groupsearch by opening the groupsearch db file.
- if ($env{'form.catalogmode'} eq 'groupsearch') {
+ ## Deal with import by opening the import db file.
+ 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('
'.
+ &mt('Unable to save import results.').
+ '
'.
+ ''.
&Apache::loncommon::end_page());
$r->rflush();
return;
@@ -2617,7 +2858,10 @@ sub display_results {
## Get the number of results
my $total_results = &Apache::lonmysql::number_of_rows($table);
if (! defined($total_results)) {
- $r->print("A MySQL error has occurred.".
+ $r->print('
'.
+ &mt('A MySQL error has occurred.').
+ '
'.
+ ''.
&Apache::loncommon::end_page());
&Apache::lonnet::logthis("lonmysql was unable to determine the number".
" of rows in table ".$table);
@@ -2648,7 +2892,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
@@ -2669,6 +2914,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'},
@@ -2679,7 +2934,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) {
@@ -2696,7 +2952,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';
@@ -2704,37 +2966,40 @@ sub display_results {
$env{'form.sortorder'}='asc';
}
}
- my $sortform = &mt('Sort by [_1] [_2]',
- &Apache::loncommon::select_form($env{'form.sortfield'},
+ my $sortform = ''
+ .&mt('Sort by:').' '
+ .&Apache::loncommon::select_form($env{'form.sortfield'},
'sortfield',
- %sort_fields),
- &Apache::loncommon::select_form($env{'form.sortorder'},
+ %sort_fields)
+ .' '
+ .&Apache::loncommon::select_form($env{'form.sortorder'},
'sortorder',
(asc =>&mt('Ascending'),
desc=>&mt('Descending')
))
- );
+ .'';
##
- ## Output links (if necessary) for 'prev' and 'next' pages.
- $r->print
- ('
'.
mt('Results [_1] to [_2] out of [_3]',
$min,$max,$total_results).
- "\n");
+ "
\n");
}
##
## Get results from MySQL table
@@ -2760,13 +3025,18 @@ 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';
+ }
+ $r->print(&Apache::loncommon::start_data_table());
foreach my $row (@Results) {
if ($connection->aborted()) {
&cleanup();
return;
}
- my %Fields = %{&parse_row(@$row)};
- my $output="
\n";
+ my %Fields = %{&parse_row($tabletype,@$row)};
+ my $output;
if (! defined($Fields{'title'}) || $Fields{'title'} eq '') {
$Fields{'title'} = 'Untitled';
}
@@ -2775,21 +3045,27 @@ sub display_results {
# Render the result into html
$output.= &$viewfunction($prefix,%Fields);
# Print them out as they come in.
- $r->print($output);
+ $r->print(&Apache::loncommon::start_data_table_row()
+ .'
'
+ .$output
+ .'
'
+ .&Apache::loncommon::end_data_table_row()
+ );
$r->rflush();
}
+ $r->print(&Apache::loncommon::end_data_table());
if (@Results < 1) {
- $r->print(&mt("There were no results matching your query"));
+ $r->print('
'
+ .&mt('There were no results matching your query.')
+ .'
$end_page
ENDPAGE
@@ -3657,16 +3950,18 @@ sub output_date_error {
# make query information persistent to allow for subsequent revision
my $start_page = &Apache::loncommon::start_page('Search');
my $end_page = &Apache::loncommon::end_page();
+ my $heading = &mt('Error');
$r->print(<
$hidden_fields
+onclick='this.form.submit();' />
$closebutton
+
-