--- loncom/interface/lonsearchcat.pm 2005/02/17 08:29:43 1.238 +++ loncom/interface/lonsearchcat.pm 2005/04/01 19:57:23 1.242 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Search Catalog # -# $Id: lonsearchcat.pm,v 1.238 2005/02/17 08:29:43 albertel Exp $ +# $Id: lonsearchcat.pm,v 1.242 2005/04/01 19:57:23 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1535,8 +1535,9 @@ sub parse_advanced_search { ## ## Deal with restrictions to given domains ## - my ($libraries_to_query,$pretty_domains_string) = + my ($libraries_to_query,$pretty_domains_string,$domain_sql_restriction) = &parse_domain_restrictions(); + push(@queries,$domain_sql_restriction); $pretty_search_string .= $pretty_domains_string."
\n"; # if (@queries) { @@ -1544,7 +1545,7 @@ sub parse_advanced_search { } elsif ($customquery) { $query = ''; } - # &Apache::lonnet::logthis('query = '.$/.$query); + #&Apache::lonnet::logthis('advanced query = '.$/.$query); return ($query,$customquery,$customshow,$libraries_to_query, $pretty_search_string); } @@ -1554,7 +1555,7 @@ sub parse_domain_restrictions { # $ENV{'form.domains'} can be either a scalar or an array reference. # We need an array. if (! exists($ENV{'form.domains'}) || $ENV{'form.domains'} eq '') { - return (undef,''); + return (undef,'',undef); } my @allowed_domains; if (ref($ENV{'form.domains'})) { @@ -1565,17 +1566,21 @@ sub parse_domain_restrictions { # my %domain_hash = (); my $pretty_domains_string; + my $domain_sql_restriction; foreach (@allowed_domains) { $domain_hash{$_}++; } if ($domain_hash{'any'}) { $pretty_domains_string = "In all LON-CAPA domains."; + $domain_sql_restriction = undef; } else { if (@allowed_domains > 1) { $pretty_domains_string = "In LON-CAPA domains:"; } else { $pretty_domains_string = "In LON-CAPA domain "; } + $domain_sql_restriction = + '(domain="'.join('" OR domain="',@allowed_domains).'")'; foreach (sort @allowed_domains) { $pretty_domains_string .= "".$_." "; } @@ -1585,7 +1590,9 @@ sub parse_domain_restrictions { } } } - return ($libraries_to_query,$pretty_domains_string); + return ($libraries_to_query, + $pretty_domains_string, + $domain_sql_restriction); } ###################################################################### @@ -1614,7 +1621,7 @@ sub parse_basic_search { $ENV{"form.$_"}=&Apache::lonnet::unescape($ENV{"form.$_"}); $ENV{"form.$_"}=~s/[^\w\/\s\(\)\=\-\"\']//g; } - my ($libraries_to_query,$pretty_domains_string) = + my ($libraries_to_query,$pretty_domains_string,$domain_sql_restriction) = &parse_domain_restrictions(); # # Check to see if enough of a query is filled in @@ -1638,6 +1645,9 @@ sub parse_basic_search { return; } push(@Queries,$SQLQuery); + if (defined($domain_sql_restriction) && $domain_sql_restriction ne '') { + push(@Queries,$domain_sql_restriction); + } #foreach my $q (@Queries) { # &Apache::lonnet::logthis(' '.$q); #} @@ -1648,7 +1658,7 @@ sub parse_basic_search { } $pretty_search_string .= "
\n"; $pretty_search_string =~ s:^
and ::; - # &Apache::lonnet::logthis($final_query); + #&Apache::lonnet::logthis('simple search final query = '.$/.$final_query); return ($final_query,$pretty_search_string, $libraries_to_query); } @@ -2436,7 +2446,7 @@ END - + @@ -2483,8 +2493,8 @@ END delete ($Server_status{$server}); next; } - $status=~/^([\.\w]+)$/; - my $datafile=$r->dir_config('lonDaemons').'/tmp/'.$1; + $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)); next; @@ -2675,71 +2685,65 @@ sub display_results { ); # # Build sorting selector - my @field_order = ('default', - 'title', - 'author', - 'subject', - 'url', - 'keywords', - 'version', - 'language', - 'creationdate'=>, - 'lastrevisiondate', - 'owner', - 'copyright', - 'authorspace', - 'lowestgradeleve', - 'highestgradelevel', - 'standards', - 'count', - 'stdno', - 'avetries', - 'difficulty', - 'disc', - 'clear', - 'technical', - 'correct', - 'helpful', - 'depth', - ); - my %sort_fields = ('default' => 'Default', - 'title' => 'Title', - 'author' => 'Author', - 'subject' => 'Subject', - 'url' => 'URL', - 'keywords' => 'Keywords', - 'version' => 'Version', - 'language' => 'Language', - 'creationdate'=> 'Creation Date', - 'lastrevisiondate' => 'Last Revision Date', - 'owner' => 'Owner', - 'copyright' => 'Copyright', - 'authorspace' => 'Authorspace', - 'lowestgradeleve' => 'Lowest Grade Level', - 'highestgradelevel' => 'Highest Grade Level', - 'standards' => 'Standards', - 'count' => 'Number of Accesses', - 'stdno' => 'Students Attempting', - 'avetries' => 'Average Number of Tries', - 'difficulty' => 'Mean Degree of Difficulty', - 'disc' => 'Mean Degree of Discrimination', - 'clear' => 'Evaluation: Clear', - 'technical' => 'Evaluation: Technically Correct', - 'correct' => 'Evaluation: Material is Correct', - 'helpful' => 'Evaluation: Material is Helpful', - 'depth' => 'Evaluation: Material has Depth', - 'select_form_order' => \@field_order, - ); - - my $sortform = &mt('Sort by [_1]', + my @fields = + ( + {key=>'default' }, + {key=>'title' }, + {key =>'author' }, + {key =>'subject'}, + {key =>'url',desc=>'URL'}, + {key =>'keywords'}, + {key =>'language'}, + {key =>'creationdate'}, + {key =>'lastrevisiondate'}, + {key =>'owner'}, + {key =>'copyright'}, + {key =>'authorspace'}, + {key =>'lowestgradelevel'}, + {key =>'highestgradelevel'}, + {key =>'standards',desc=>'Standards'}, + {key =>'count',desc=>'Number of accesses'}, + {key =>'stdno',desc=>'Students Attempting'}, + {key =>'avetries',desc=>'Average Number of Tries'}, + {key =>'difficulty',desc=>'Mean Degree of Difficulty'}, + {key =>'disc',desc=>'Mean Degree of Discrimination'}, + {key =>'clear',desc=>'Evaluation: Clear'}, + {key =>'technical',desc=>'Evaluation: Technically Correct'}, + {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) { + push(@field_order,$field_data->{'key'}); + if (! exists($field_data->{'desc'})) { + $field_data->{'desc'}=$fieldnames{$field_data->{'key'}}; + } else { + if (! defined($field_data->{'desc'})) { + $field_data->{'desc'} = ucfirst($field_data->{'key'}); + } + $field_data->{'desc'} = &mt($field_data->{'desc'}); + } + } + my %sort_fields = map {$_->{'key'},$_->{'desc'}} @fields; + $sort_fields{'select_form_order'} = \@field_order; + $ENV{'form.sortorder'} = 'asc' if (! exists($ENV{'form.sortorder'})); + my $sortform = &mt('Sort by [_1] [_2]', &Apache::loncommon::select_form($ENV{'form.sortfield'}, 'sortfield', - %sort_fields)); + %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 ('
StatusTotal MatchesTime Remaining
$revise
'. - $sortform. + ''.$sortform.''. ''. &prev_next_buttons($min,$ENV{'form.show'},$total_results). ''. @@ -2759,10 +2763,22 @@ sub display_results { ## ## Get results from MySQL table my $sort_command = 'id>='.$min.' AND id<='.$max; + my $order; + if (exists($ENV{'form.sortorder'})) { + if ($ENV{'form.sortorder'} eq 'asc') { + $order = 'ASC'; + } elsif ($ENV{'form.sortorder'} eq 'desc') { + $order = 'DESC'; + } else { + $order = ''; + } + } else { + $order = ''; + } if ($ENV{'form.sortfield'} ne 'default' && exists($sort_fields{$ENV{'form.sortfield'}})) { $sort_command = $ENV{'form.sortfield'}.' IS NOT NULL '. - 'ORDER BY '.$ENV{'form.sortfield'}. + 'ORDER BY '.$ENV{'form.sortfield'}.' '.$order. ' LIMIT '.($min-1).','.($max-$min); } my @Results = &Apache::lonmysql::get_rows($table,$sort_command); @@ -3326,12 +3342,23 @@ sub detailed_citation_view { sub summary_view { my ($prefix,%values) = @_; my $icon=&Apache::loncommon::icon($values{'url'}); - my $result=<  + my $result=qq{$prefix}; + if (exists($ENV{'form.sortfield'}) && + $ENV{'form.sortfield'} !~ /^(default| + author| + url| + title| + owner| + lastrevisiondate| + copyright)$/x) { + my $tmp = $values{$ENV{'form.sortfield'}}; + if (! defined($tmp)) { $tmp = 'undefined'; } + $result .= ' '.$tmp.' '; + } + $result.=<$values{'author'}
-$values{'title'}
-$values{'owner'} -- $values{'lastrevisiondate'}
+ target='search_preview'>$values{'title'}
+$values{'author'}, $values{'owner'} -- $values{'lastrevisiondate'}
$values{'copyrighttag'}
$values{'extrashow'}

@@ -3354,8 +3381,14 @@ END sub compact_view { my ($prefix,%values) = @_; my $result = - $prefix.' '. + $prefix.''; + if (exists($ENV{'form.sortfield'}) && + $ENV{'form.sortfield'} !~ /^(default|author|url|title)$/) { + my $tmp = $values{$ENV{'form.sortfield'}}; + if (! defined($tmp)) { $tmp = 'undefined'; } + $result .= ' '.$tmp.' '; + } + $result.=' '. $values{'title'}.''.(' 'x2). ''.$values{'author'}.'
'; return $result; @@ -3384,7 +3417,7 @@ $prefix
$values{'url'}
END - foreach my $field ('title','author','subject','keywords','notes', + foreach my $field ('title','author','domain','subject','keywords','notes', 'mimetag','language','creationdate','lastrevisiondate', 'owner','copyrighttag','hostname','abstract') { $result .= (' 'x4).'
'.$Translated{$field}.'
'."\n". @@ -3425,7 +3458,7 @@ sub xml_sgml_view { my ($prefix,%values) = @_; my $xml = ''."\n"; # The usual suspects - foreach my $field ('url','title','author','subject','keywords','notes') { + foreach my $field ('url','title','author','subject','keywords','notes','domain') { $xml .= qq{<$field>$values{$field}}."\n"; } #