--- loncom/interface/lonsearchcat.pm 2004/04/23 17:52:55 1.216 +++ loncom/interface/lonsearchcat.pm 2004/05/05 14:14:10 1.222 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Search Catalog # -# $Id: lonsearchcat.pm,v 1.216 2004/04/23 17:52:55 matthew Exp $ +# $Id: lonsearchcat.pm,v 1.222 2004/05/05 14:14:10 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -117,7 +117,7 @@ sub handler { my $loaderror=&Apache::lonnet::overloaderror($r); if ($loaderror) { return $loaderror; } - + # my $closebutton; # button that closes the search window # This button is different for the RAT compared to # normal invocation. @@ -185,11 +185,13 @@ sub handler { bug=>'Searching',}); } # - if (! &get_persistent_form_data($persistent_db_file)) { - if ($ENV{'form.phase'} =~ /(run_search|results)/) { - &Apache::lonnet::logthis("lonsearchcat:Unable to recover data ". - "from $persistent_db_file"); - $r->print(<print(< LON-CAPA Search Error $bodytag @@ -198,8 +200,11 @@ error and has been logged. Please alert END - return OK; + return OK; + } } + } else { + &clean_up_environment(); } ## ## Clear out old values from groupsearch database @@ -286,7 +291,7 @@ END $ENV{'form.phase'} = 'disp_basic' if (! exists($ENV{'form.phase'})); $ENV{'form.show'} = 20 if (! exists($ENV{'form.show'})); # - $ENV{'form.searchmode'} = 'basic'; + $ENV{'form.searchmode'} = 'basic' if (! exists($ENV{'form.searchmode'})); if ($ENV{'form.phase'} eq 'adv_search' || $ENV{'form.phase'} eq 'disp_adv') { $ENV{'form.searchmode'} = 'advanced'; @@ -389,6 +394,34 @@ END return OK; } +# +# The mechanism used to store values away and retrieve them does not +# handle the case of missing environment variables being significant. +# +# This routine sets non existant checkbox form elements to ''. +# +sub clean_up_environment { + if ($ENV{'form.phase'} eq 'basic_search') { + if (! exists($ENV{'form.related'})) { + $ENV{'form.related'} = ''; + } + if (! exists($ENV{'form.domains'})) { + $ENV{'form.domains'} = ''; + } + } elsif ($ENV{'form.phase'} eq 'adv_search') { + foreach my $field ('title','keywords','notes', + 'abstract','standards','mime') { + if (! exists($ENV{'form.'.$field.'_related'})) { + $ENV{'form.'.$field.'_related'} = ''; + } + } + } elsif ($ENV{'form.phase'} eq 'course_search') { + if (! exists($ENV{'form.crsrelated'})) { + $ENV{'form.crsrelated'} = ''; + } + } +} + ###################################################################### ###################################################################### ## @@ -405,8 +438,7 @@ my $totalfound; sub course_search { my $r=shift; - my $bodytag=&Apache::loncommon::bodytag('Course Search'). - &Apache::loncommon::help_open_bug('Searching'); + my $bodytag=&Apache::loncommon::bodytag('Course Search'); my $pretty_search_string = ''.$ENV{'form.courseexp'}.''; my $search_string = $ENV{'form.courseexp'}; my @New_Words; @@ -504,13 +536,6 @@ sub search_html_header { The LearningOnline Network with CAPA - ENDHEADER return $Str; @@ -532,7 +557,7 @@ Prints the form for the basic search. S sub print_basic_search_form { my ($r,$closebutton,$hidden_fields) = @_; my $bodytag=&Apache::loncommon::bodytag('Search'). - &Apache::lonhtmlcommon::breadcrumbs(undef,'Searching','Finding_Resources', + &Apache::lonhtmlcommon::breadcrumbs(undef,'Searching','Searching', undef,undef,! $ENV{'form.launch'}); my $scrout = &search_html_header().$bodytag; if (&Apache::lonnet::allowed('bre',$ENV{'request.role.domain'})) { @@ -540,12 +565,15 @@ sub print_basic_search_form { my $userelatedwords= &mt('[_1] use related words', &Apache::lonhtmlcommon::checkbox - ('related',$ENV{'form.related'})); + ('related',$ENV{'form.related'},'related')); my $onlysearchdomain= &mt('[_1] only search domain [_2]', - &Apache::lonhtmlcommon::checkbox - ('domains',$ENV{'form.domains'}), - $r->dir_config('lonDefDomain')); + &Apache::lonhtmlcommon::checkbox('domains', + $ENV{'form.domains'}, + $r->dir_config('lonDefDomain') + ), + $r->dir_config('lonDefDomain') + ); my $adv_search_link = ' + my $advanced_buttons=<<"END"; $closebutton - END - my $bodytag=&Apache::loncommon::bodytag('Advanced Catalog Search'). - &Apache::lonhtmlcommon::breadcrumbs(undef,'Searching', - 'Finding_Resources', - undef,undef, - ! $ENV{'form.launch'}); - my $searchhelp=&searchhelp(); my $scrout=&search_html_header(); $scrout .= <<"ENDHEADER"; $bodytag
+

$advanced_buttons ENDHEADER $scrout.=(' 'x2).&viewoptions().'

'.$hidden_fields. ''; my %fields=&Apache::lonmeta::fieldnames(); # - $scrout.= '

'.$searchhelp.'

'. - "\n"; + $scrout .= '

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

'; + $scrout .= "
\n"; + $scrout .= '\n"; my %related_word_search = - ('title'=>1, - 'author'=>0, - 'owner'=>0, - 'authorspace'=>0, - 'modifyinguser'=>0, - 'keywords'=>1, - 'notes'=>1, - 'abstract'=>1, - 'standards'=>1, - 'mime'=>1, + ('title' => 1, + 'author' => 0, + 'owner' => 0, + 'authorspace' => 0, + 'modifyinguser'=> 0, + 'keywords' => 1, + 'notes' => 1, + 'abstract' => 1, + 'standards'=> 1, + 'mime' => 1, ); # foreach my $field ('title','author','owner','authorspace','modifyinguser', @@ -736,9 +765,82 @@ ENDHEADER &Apache::loncommon::domain_select('domains', $ENV{'form.domains'},1). ''.$/; - $scrout .= "
 '. + (' 'x2).&searchhelp()."
\n
"; + # + # Misc metadata + $scrout.=''. + &titlefield(&mt('Copyright/Distribution')).''. + &Apache::lonmeta::selectbox('copyright', + '',, + \&Apache::loncommon::copyrightdescription, + ( undef, + &Apache::loncommon::copyrightids) + ).''.$/; + $scrout.=''. + &titlefield(&mt('Language')).''. + &Apache::lonmeta::selectbox('language', + 'notset',, + \&Apache::loncommon::languagedescription, + ('any',&Apache::loncommon::languageids) + ).''; + $scrout .= "\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 .= ''.$/; + } + $scrout .= "
 '.&mt('Minimum').''.&mt('Maximum').'
'. + &titlefield(&mt($evaluation->{'description'})). + ''. + ''. + ''. + ''. + '
\n"; # # Creation/Modification date limits + $scrout .= '

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

'; $scrout .= "\n\n"; my $cafter = &Apache::lonhtmlcommon::date_setter('advsearch', # formname @@ -1082,10 +1184,11 @@ Parse advanced search form and return th sub parse_advanced_search { my ($r,$closebutton,$hidden_fields)=@_; my @BasicFields = ('title','author','subject','keywords','url','version', - 'notes','abstract','extension','language','owner', + 'notes','abstract','extension','owner', # 'custommetadata','customshow', 'modifyinguser','standards','mime'); - + my @StatsFields = &statfields(); + my @EvalFields = &evalfields(); my $fillflag=0; my $pretty_search_string = "
\n"; # Clean up fields for safety @@ -1097,6 +1200,7 @@ sub parse_advanced_search { 'lastrevisiondatestart_year','lastrevisiondateend_month', 'lastrevisiondateend_day','lastrevisiondateend_year') { $ENV{'form.'.$field}=~s/[^\w\/\s\(\)\=\-\"\']//g; + $ENV{'form.'.$field}=~s/(not\s*$|^\s*(and|or)|)//gi; } foreach ('mode','form','element') { # is this required? Hmmm. @@ -1109,11 +1213,20 @@ sub parse_advanced_search { ref($ENV{'form.category'})); # # Check to see if enough information was filled in - for my $field (@BasicFields) { + foreach my $field (@BasicFields) { if (&filled($ENV{'form.'.$field})) { $fillflag++; } } + foreach my $field (@StatsFields,@EvalFields) { + if (&filled($ENV{'form.'.$field.'_max'})) { + $fillflag++; + } + if (&filled($ENV{'form.'.$field.'_min'})) { + $fillflag++; + } + } + for my $field ('lowestgradelevel','highestgradelevel') { if ( $ENV{'form.'.$field} =~ /^\d+$/ && $ENV{'form.'.$field} > 0) { @@ -1198,6 +1311,31 @@ sub parse_advanced_search { "
\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.'
'; + } + } + # # Evaluate date windows my $cafter = &Apache::lonhtmlcommon::get_date_from_form('creationdate1'); @@ -1262,6 +1400,7 @@ sub parse_advanced_search { } elsif ($customquery) { $query = ''; } +# &Apache::lonnet::logthis('query = '.$/.$query); return ($query,$customquery,$customshow,$libraries_to_query, $pretty_search_string); } @@ -1270,7 +1409,7 @@ sub parse_domain_restrictions { my $libraries_to_query = undef; # $ENV{'form.domains'} can be either a scalar or an array reference. # We need an array. - if (! exists($ENV{'form.domains'})) { + if (! exists($ENV{'form.domains'}) || $ENV{'form.domains'} eq '') { return (undef,''); } my @allowed_domains; @@ -1335,12 +1474,13 @@ sub parse_basic_search { &parse_domain_restrictions(); # # Check to see if enough of a query is filled in - unless (&filled($ENV{'form.basicexp'})) { + my $search_string = $ENV{'form.basicexp'}; + $search_string =~ s/(not\s*$|^\s*(and|or)|)//gi; + if (! &filled($search_string)) { &output_blank_field_error($r,$closebutton,'phase=disp_basic'); return OK; } my $pretty_search_string = ''.$ENV{'form.basicexp'}.''; - my $search_string = $ENV{'form.basicexp'}; if ($ENV{'form.related'}) { my @New_Words; ($search_string,@New_Words) = &related_version($ENV{'form.basicexp'}); @@ -2692,32 +2832,95 @@ extra custom metadata to show. ###################################################################### sub detailed_citation_view { my ($prefix,%values) = @_; - my $icon=&Apache::loncommon::icon($values{'url'}); - my $result=<$prefix$values{'title'} -

-$values{'author'}, $values{'owner'}
- -Subject: $values{'subject'}
-Keyword(s): $values{'keywords'}
-Notes: $values{'notes'}
-MIME Type: $values{'mimetag'}
-Language: $values{'language'}
-Copyright/Distribution: $values{'copyrighttag'}
-

-$values{'extrashow'} -

-$values{'shortabstract'} -

-
-END + my $icon= + my $result; + $result .= ''.$prefix. + ''. + ''.$values{'title'}."\n"; + $result .= "

\n"; + $result .= ''.$values{'author'}.','. + ' '.$values{'owner'}.'
'; + foreach my $field + ( + { name=>'subject', + translate => 'Subject: [_1]',}, + { name=>'keywords', + translate => 'Keywords: [_1]',}, + { name=>'notes', + translate => 'Notes: [_1]',}, + { name=>'mimetag', + translate => 'MIME Type: [_1]',}, + { name=>'standards', + translate => 'Standards:[_1]',}, + { name=>'copyrighttag', + translate => 'Copyright/Distribution: [_1]',}, + { name=>'stdno', + translate => 'Number of Students: [_1]',}, + { name=>'avetries', + translate => 'Average Tries: [_1]',}, + { name=>'disc', + translate => 'Degree of Discrimination: [_1]',}, + { name=>'difficulty', + translate => 'Degree of Difficulty: [_1]',}, + { name=>'clear', + translate => 'Clear: [_1]',}, + { name=>'depth', + translate => 'Depth: [_1]',}, + { name=>'helpful', + translate => 'Helpful: [_1]',}, + { name=>'correct', + translate => 'Correcy: [_1]',}, + { name=>'technical', + translate => 'Technical: [_1]',}, + ) { + $result.= &mt($field->{'translate'},$values{$field->{'name'}}). + "
\n"; + } + $result .= "

".$values{'extrashow'}. + '

'.$values{'shortabstract'}.'

'; + $result .= '
'."\n"; return $result; } ###################################################################### ###################################################################### +sub has_stat_data { + my ($values) = @_; + if ( (defined($values->{'count'}) && $values->{'count'} ne '') || + (defined($values->{'stdno'}) && $values->{'stdno'} ne '') || + (defined($values->{'disc'}) && $values->{'disc'} ne '') || + (defined($values->{'avetries'}) && $values->{'avetries'} ne '') || + (defined($values->{'difficulty'}) && $values->{'difficulty'} ne '')) { + return 1; + } + return 0; +} + +sub statfields { + return ('count','stdno','disc','avetries','difficulty'); +} + +sub has_eval_data { + my ($values) = @_; + if ( (defined($values->{'clear'}) && $values->{'clear'} ne '') || + (defined($values->{'technical'}) && $values->{'technical'} ne '') || + (defined($values->{'correct'}) && $values->{'correct'} ne '') || + (defined($values->{'helpful'}) && $values->{'helpful'} ne '') || + (defined($values->{'depth'}) && $values->{'depth'} ne '')) { + return 1; + } + return 0; +} + +sub evalfields { + return ('clear','technical','correct','helpful','depth'); +} + +###################################################################### +###################################################################### + =pod =item &summary_view() @@ -2778,28 +2981,35 @@ END sub fielded_format_view { my ($prefix,%values) = @_; my $icon=&Apache::loncommon::icon($values{'url'}); + my %Translated = &Apache::lonmeta::fieldnames(); my $result=< -URL: $values{'url'} -
-Title: $values{'title'}
-Author(s): $values{'author'}
-Subject: $values{'subject'}
-Keyword(s): $values{'keywords'}
-Notes: $values{'notes'}
-MIME Type: $values{'mimetag'}
-Language: $values{'language'}
-Creation Date: $values{'creationdate'}
-Last Revision Date: $values{'lastrevisiondate'}
-Publisher/Owner: $values{'owner'}
-Copyright/Distribution: $values{'copyrighttag'}
-Repository Location: $values{'hostname'}
-Abstract: $values{'shortabstract'}
-$values{'extrashow'} -

-
+
+
URL:
+
$values{'url'}
END + foreach my $field ('title','author','subject','keywords','notes', + 'mimetag','language','creationdate','lastrevisiondate', + 'owner','copyrighttag','hostname','abstract') { + $result .= (' 'x4).'
'.$Translated{$field}.'
'."\n". + (' 'x8).'
'.$values{$field}.'
'."\n"; + } + if (&has_stat_data(\%values)) { + foreach my $field (&statfields()) { + $result .= (' 'x4).'
'.$Translated{$field}.'
'."\n". + (' 'x8).'
'.$values{$field}.'
'."\n"; + } + } + if (&has_eval_data(\%values)) { + foreach my $field (&evalfields()) { + $result .= (' 'x4).'
'.$Translated{$field}.'
'."\n". + (' 'x8).'
'.$values{$field}.'
'."\n"; + } + } + $result .= "
\n"; + $result .= $values{'extrashow'}; + $result .= '
'."\n"; return $result; } @@ -2818,33 +3028,54 @@ END ###################################################################### sub xml_sgml_view { my ($prefix,%values) = @_; - my $xml = < -$values{'url'} -$values{'title'} -$values{'author'} -$values{'subject'} -$values{'keywords'} -$values{'notes'} - -$values{'mime'} -$values{'mimetag'} - - -$values{'language'} -$values{'languagetag'} - -$values{'creationdate'} -$values{'lastrevisiondate'} -$values{'owner'} - -$values{'copyright'} -$values{'copyrighttag'} - -$values{'hostname'} -$values{'shortabstract'} - -END + my $xml = ''."\n"; + # The usual suspects + foreach my $field ('url','title','author','subject','keywords','notes') { + $xml .= qq{<$field>$values{$field}}."\n"; + } + # + $xml .= "\n"; + foreach my $field ('mime','mimetag') { + $xml .= qq{<$field>$values{$field}}."\n"; + } + $xml .= "\n"; + # + $xml .= "\n"; + foreach my $field ('language','languagetag') { + $xml .= qq{<$field>$values{$field}}."\n"; + } + $xml .= "\n"; + # + foreach my $field ('creationdate','lastrevisiondate','owner') { + $xml .= qq{<$field>$values{$field}}."\n"; + } + # + $xml .= "\n"; + foreach my $field ('copyright','copyrighttag') { + $xml .= qq{<$field>$values{$field}}."\n"; + } + $xml .= "\n"; + $xml .= qq{$values{'hostname'}}. + "\n"; + $xml .= qq{$values{'shortabstract'}}."\n"; + # + if (&has_stat_data(\%values)){ + $xml .= "\n"; + foreach my $field (&statfields()) { + $xml .= qq{<$field>$values{$field}}."\n"; + } + $xml .= "\n"; + } + # + if (&has_eval_data(\%values)) { + $xml .= "\n"; + foreach my $field (&evalfields) { + $xml .= qq{<$field>$values{$field}}."\n"; + } + $xml .= "\n"; + } + # + $xml .= "\n"; $xml = &HTML::Entities::encode($xml,'<>&'); my $result=<