--- loncom/interface/lonsearchcat.pm 2005/03/21 21:01:15 1.240 +++ loncom/interface/lonsearchcat.pm 2005/03/22 21:15:42 1.241 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Search Catalog # -# $Id: lonsearchcat.pm,v 1.240 2005/03/21 21:01:15 matthew Exp $ +# $Id: lonsearchcat.pm,v 1.241 2005/03/22 21:15:42 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1545,7 +1545,7 @@ sub parse_advanced_search { } elsif ($customquery) { $query = ''; } - &Apache::lonnet::logthis('advanced query = '.$/.$query); + #&Apache::lonnet::logthis('advanced query = '.$/.$query); return ($query,$customquery,$customshow,$libraries_to_query, $pretty_search_string); } @@ -1658,7 +1658,7 @@ sub parse_basic_search { } $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); } @@ -2685,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 ('
'. - $sortform. + ''.$sortform.''. ''. &prev_next_buttons($min,$ENV{'form.show'},$total_results). ''. @@ -2769,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); @@ -3336,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'}

@@ -3364,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;