--- loncom/interface/lonsearchcat.pm 2004/04/23 17:52:55 1.216 +++ loncom/interface/lonsearchcat.pm 2004/05/09 22:55:17 1.225 @@ -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.225 2004/05/09 22:55:17 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 @@ -226,24 +231,19 @@ END $hidden_fields = ''."\n"; if (exists($ENV{'form.catalogmode'})) { - $hidden_fields .= ''."\n"; + $hidden_fields .= &hidden_field('catalogmode'); } if (exists($ENV{'form.form'})) { - $hidden_fields .= ''."\n"; + $hidden_fields .= &hidden_field('form'); } if (exists($ENV{'form.element'})) { - $hidden_fields .= ''."\n"; + $hidden_fields .= &hidden_field('element'); } if (exists($ENV{'form.titleelement'})) { - $hidden_fields .= ''."\n"; + $hidden_fields .= &hidden_field('titleelement'); } if (exists($ENV{'form.mode'})) { - $hidden_fields .= ''."\n"; + $hidden_fields .= &hidden_field('mode'); } ## ## Configure dynamic components of interface @@ -286,7 +286,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 +389,42 @@ 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'} = ''; + } + } +} + +sub hidden_field { + my ($name,$value) = @_; + if (! defined($value)) { + $value = $ENV{'form.'.$name}; + } + return ''.$/; +} + ###################################################################### ###################################################################### ## @@ -405,8 +441,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 +539,6 @@ sub search_html_header { The LearningOnline Network with CAPA - ENDHEADER return $Str; @@ -532,7 +560,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 +568,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 = ''. ''. - (' 'x2).$closebutton.(' 'x2).&viewoptions(). + (' 'x2).$closebutton.(' 'x2). + &viewoptions(). ''. ''.$/; $scrout .= ''.$/.''.''; @@ -656,45 +688,46 @@ Prints the advanced search form. ###################################################################### sub print_advanced_search_form{ my ($r,$closebutton,$hidden_fields) = @_; + my $bodytag=&Apache::loncommon::bodytag('Advanced Catalog Search'). + &Apache::lonhtmlcommon::breadcrumbs(undef,'Searching', + 'Searching', + undef,undef, + ! $ENV{'form.launch'}); + my %lt=&Apache::lonlocal::texthash('srch' => 'Search', 'reset' => 'Reset', 'help' => 'Help'); - my $advanced_buttons = <<"END"; -

+ 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 +769,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 @@ -857,7 +963,7 @@ Outputs: text for box with view options ###################################################################### ###################################################################### sub viewoptions { - my $scrout="\n".''; + my $scrout; if (! defined($ENV{'form.viewselect'})) { $ENV{'form.viewselect'}='detailed'; } @@ -1082,10 +1188,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 +1204,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 +1217,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) { @@ -1131,8 +1248,8 @@ sub parse_advanced_search { my $font = ''; # Evaluate logical expression AND/OR/NOT phrase fields. foreach my $field (@BasicFields) { - if ($ENV{'form.'.$field}) { - my $searchphrase = $ENV{'form.'.$field}; + next if (!defined($ENV{'form.'.$field}) || $ENV{'form.'.$field} eq ''); + foreach my $searchphrase(&process_phrase_input($ENV{'form.'.$field})){ $pretty_search_string .= $font."$field contains ". $searchphrase.""; if ($ENV{'form.'.$field.'_related'}) { @@ -1146,7 +1263,7 @@ sub parse_advanced_search { } } $pretty_search_string .= "
\n"; - push @queries,&build_SQL_query($field,$searchphrase); + push @queries,&build_SQL_query($field,$searchphrase); } } # @@ -1198,6 +1315,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'); @@ -1258,10 +1400,11 @@ sub parse_advanced_search { $pretty_search_string .= $pretty_domains_string."
\n"; # if (@queries) { - $query="select * from metadata where ".join(" AND ",@queries); + $query="SELET * FROM metadata WHERE ".join(" AND ",@queries); } elsif ($customquery) { $query = ''; } +# &Apache::lonnet::logthis('query = '.$/.$query); return ($query,$customquery,$customshow,$libraries_to_query, $pretty_search_string); } @@ -1270,7 +1413,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,39 +1478,80 @@ 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'}); - if (@New_Words) { - $pretty_search_string .= " with related words: @New_Words."; + my $pretty_search_string=''; + my @Queries; + my $concatarg=join(',', + ('title', 'author', 'subject', 'notes', 'abstract', + 'keywords')); + foreach my $search (&process_phrase_input($search_string)){ + if ($ENV{'form.related'}) { + $pretty_search_string .= ' and
' if ($pretty_search_string ne ''); + $pretty_search_string .= ''.$search.''; + my @New_Words; + ($search,@New_Words) = &related_version($search); + next if (! $search); + if (@New_Words) { + $pretty_search_string .= + " with related words: @New_Words"; + } } else { - $pretty_search_string .= " with no related words."; + $pretty_search_string .= ' and ' if ($pretty_search_string ne ''); + $pretty_search_string .= ''.$search.''; } + # + # Build SQL query string based on form page + push(@Queries, + &build_SQL_query('concat_ws(" ",'.$concatarg.')',$search)); } + my $final_query = 'SELECT * FROM metadata WHERE '.join(" AND ",@Queries); # - # Build SQL query string based on form page - my $query=''; - my $concatarg=join(',', - ('title', 'author', 'subject', 'notes', 'abstract', - 'keywords')); - $concatarg='title' if $ENV{'form.titleonly'}; - $query=&build_SQL_query('concat_ws(" ",'.$concatarg.')',$search_string); if (defined($pretty_domains_string) && $pretty_domains_string ne '') { $pretty_search_string .= ' '.$pretty_domains_string; } $pretty_search_string .= "
\n"; - my $final_query = 'SELECT * FROM metadata WHERE '.$query; - # &Apache::lonnet::logthis($final_query); + $pretty_search_string =~ s:^
and ::; +# &Apache::lonnet::logthis($final_query); return ($final_query,$pretty_search_string, $libraries_to_query); } +sub process_phrase_input { + my ($phrase)=@_; + my @Phrases; + # &Apache::lonnet::logthis('phrase = :'.$phrase.':'); + my $in_quotes = 0; + my @Words = split(/\s+/,$phrase); + foreach my $word (@Words) { + $word =~ s/(\w+)\"(\w+)/$1$2/g; + if ($in_quotes) { + if ($word =~ s/(\")$//) { + $in_quotes = 0; + } + if ($Phrases[-1] ne '') { + $Phrases[-1] .= ' '; + } + $Phrases[-1] .= $word; + } else { + if ($word =~ s/^(\")//) { + $in_quotes=1; + } + push(@Phrases,$word); + } + } + # + #foreach my $p (@Phrases) { + # &Apache::lonnet::logthis(' subphrase = '.$p); + #} + # + return @Phrases; +} + ###################################################################### ###################################################################### @@ -1386,19 +1570,13 @@ Note: Using this twice on a string is pr ###################################################################### ###################################################################### sub related_version { - my $search_string = shift; - my $result = $search_string; - my %New_Words = (); - while ($search_string =~ /(\w+)/cg) { - my $word = $1; - next if (lc($word) =~ /\b(or|and|not)\b/); - my @Words = &Apache::loncommon::get_related_words($word); - @Words = ($#Words>4? @Words[0..4] : @Words); - foreach (@Words) { $New_Words{$_}++;} - my $replacement = join " OR ", ($word,@Words); - $result =~ s/(\b)$word(\b)/$1($replacement)$2/g; - } - return $result,sort(keys(%New_Words)); + my ($word) = @_; + return (undef) if (lc($word) =~ /\b(or|and|not)\b/); + my @Words = &Apache::loncommon::get_related_words($word); + # Only use 4 related words + @Words = ($#Words>4? @Words[0..4] : @Words); + my $result = join " OR ", ($word,@Words); + return $result,sort(@Words); } ###################################################################### @@ -1422,7 +1600,9 @@ sub build_SQL_query { -build => 'Text::Query::Build'); $q->prepare($logic_statement); my $matchexp=${$q}{'matchexp'}; chomp $matchexp; + &Apache::lonnet::logthis('matchexp = '.$matchexp); my $sql_query=&recursive_SQL_query_build($field_name,$matchexp); + &Apache::lonnet::logthis('sql_query = '.$sql_query); return $sql_query; } @@ -1692,7 +1872,11 @@ a link to change the search query. ###################################################################### sub print_sort_form { my ($r,$pretty_query_string) = @_; - my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1); + my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1). + &Apache::lonhtmlcommon::breadcrumbs + (undef,'Searching','Searching',undef,undef, + ! ($ENV{'form.catalogmode'} eq 'groupsearch')); + ## my %SortableFields=&Apache::lonlocal::texthash( id => 'Default', @@ -1958,6 +2142,10 @@ results into MySQL. sub run_search { my ($r,$query,$customquery,$customshow,$serverlist,$pretty_string) = @_; my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1); + $bodytag.= + &Apache::lonhtmlcommon::breadcrumbs(undef,'Searching','Searching', + undef,undef,! $ENV{'form.launch'}); + my $connection = $r->connection; # # Print run_search header @@ -2141,13 +2329,13 @@ END # results to get, so let the client know the top frame needs to be # loaded from /adm/searchcat $r->print(""); - if ($ENV{'form.catalogmode'} ne 'groupsearch') { +# if ($ENV{'form.catalogmode'} ne 'groupsearch') { $r->print(""); - } +# } return; } @@ -2168,32 +2356,16 @@ sub prev_next_buttons { my ($current_min,$show,$total,$parms) = @_; return '' if ($show eq 'all'); # No links if you get them all at once. # - # Create links - my $prev_min = $current_min - $show; - $prev_min = 1 if $prev_min < 1; - my $prevlink = - qq{}; - # - my $next_min = $current_min + $show; - $next_min = $current_min if ($next_min > $total); - my $nextlink = - qq{}; - my $reloadlink = - qq{}; - # - # Determine which parameters to pass - my $String = '[_1]prev[_2]   [_3]reload[_4]   [_5]next[_6]'; - if ($prev_min == $current_min) { - $String =~ s:\[_[12]\]::g; - } - if ($next_min == $current_min) { - $String =~ s:\[_[56]\]::g; - } - my $links = &mt($String, - $prevlink, '', - $reloadlink,'', - $nextlink, ''); - return $links; + # Create buttons + my $buttons = ''; + $buttons .= ' 'x3; + $buttons .= '$total_results); my $min = $ENV{'form.start'}; my $max; if ($ENV{'form.show'} eq 'all') { @@ -2267,14 +2446,19 @@ sub display_results { $max = $total_results if ($max > $total_results); } ## + ## Output form elements + $r->print(&hidden_field('table'). + &hidden_field('phase'). + &hidden_field('persistent_db_id'). + &hidden_field('start') + ); + ## ## Output links (if necessary) for 'prev' and 'next' pages. $r->print - ('
'. - &prev_next_buttons($min,$ENV{'form.show'},$total_results, - "table=".$ENV{'form.table'}. - "&phase=results". - "&persistent_db_id=".$ENV{'form.persistent_db_id'}) - ."
\n" + ('
'. + &prev_next_buttons($min,$ENV{'form.show'},$total_results). + ''. + &viewoptions().'
' ); if ($total_results == 0) { $r->print(''. @@ -2613,7 +2797,7 @@ SCRIPT $result.=< $bodytag - + $importbutton END @@ -2671,6 +2855,41 @@ ENDFRAMES ###################################################################### ###################################################################### +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 Metadata Viewing Functions @@ -2692,26 +2911,108 @@ 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 $result; + $result .= ''.$prefix. + ''.' '. + ''.$values{'title'}."\n"; + $result .= "

\n"; + $result .= ''.$values{'author'}.','. + ' '.$values{'owner'}.'
'; + foreach my $field + ( + { name=>'url', + translate => 'URL: [_1]', + special => 'url link',}, + { 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=>'count', + format => "%d", + translate => 'Access Count: [_1]',}, + { name=>'stdno', + format => "%d", + translate => 'Number of Students: [_1]',}, + { name=>'avetries', + format => "%.2f", + translate => 'Average Tries: [_1]',}, + { name=>'disc', + format => "%.2f", + translate => 'Degree of Discrimination: [_1]',}, + { name=>'difficulty', + format => "%.2f", + translate => 'Degree of Difficulty: [_1]',}, + { name=>'clear', + format => "%.2f", + translate => 'Clear: [_1]',}, + { name=>'depth', + format => "%.2f", + translate => 'Depth: [_1]',}, + { name=>'helpful', + format => "%.2f", + translate => 'Helpful: [_1]',}, + { name=>'correct', + format => "%.2f", + translate => 'Correct: [_1]',}, + { name=>'technical', + format => "%.2f", + translate => 'Technical: [_1]',}, + { name=>'comefrom_list', + type => 'list', + translate => 'Resources that lead up to this resource in maps',}, + { name=>'goto_list', + type => 'list', + translate => 'Resources that follow this resource in maps',}, + { name=>'usage_list', + type => 'list', + translate => 'Resources using or importing resource',}, + ) { + next if (! exists($values{$field->{'name'}}) || + $values{$field->{'name'}} eq ''); + if (exists($field->{'type'}) && $field->{'type'} eq 'list') { + $result .= ''.&mt($field->{'translate'}).'

    '; + foreach my $item (split(',',$values{$field->{'name'}})){ + $result .= '
  • '. + ''.$item.'
  • '; + } + $result .= '
'; + } elsif (exists($field->{'format'}) && $field->{'format'} ne ''){ + $result.= &mt($field->{'translate'}, + sprintf($field->{'format'}, + $values{$field->{'name'}})).'
'."\n"; + } else { + if ($field->{'special'} eq 'url link') { + $result.= + &mt($field->{'translate'}, + ''. + $values{$field->{'name'}}. + ''); + } else { + $result.= &mt($field->{'translate'}, + $values{$field->{'name'}}); + } + $result .= "
\n"; + } + } + $result .= "

"; + if (exists($values{'extrashow'}) && $values{'extrashow'} ne '') { + $result .= '

'.$values{'extrashow'}.'

'; + } + if (exists($values{'shortabstract'}) && $values{'shortabstract'} ne '') { + $result .= '

'.$values{'shortabstract'}.'

'; + } + $result .= '
'."\n"; return $result; } @@ -2729,7 +3030,8 @@ sub summary_view { my ($prefix,%values) = @_; my $icon=&Apache::loncommon::icon($values{'url'}); my $result=<  +$values{'author'}
$values{'title'}
$values{'owner'} -- $values{'lastrevisiondate'}
@@ -2754,12 +3056,11 @@ END ###################################################################### sub compact_view { my ($prefix,%values) = @_; - my $icon=&Apache::loncommon::icon($values{'url'}); - my $result=< -$values{'title'} -$values{'author'}
-END + my $result = + $prefix.' '. + $values{'title'}.''.(' 'x2). + ''.$values{'author'}.'
'; return $result; } @@ -2778,28 +3079,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 +3126,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=<