--- loncom/interface/lonmeta.pm 2002/10/25 13:50:48 1.24 +++ loncom/interface/lonmeta.pm 2009/04/21 15:38:02 1.231 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Metadata display handler # -# $Id: lonmeta.pm,v 1.24 2002/10/25 13:50:48 www Exp $ +# $Id: lonmeta.pm,v 1.231 2009/04/21 15:38:02 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -17,400 +17,1669 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License +# You should have received a copy of the GNU General Public License # along with LON-CAPA; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # /home/httpd/html/adm/gpl.txt # # http://www.lon-capa.org/ -# -# (TeX Content Handler -# -# 05/29/00,05/30,10/11 Gerd Kortemeyer) -# -# 10/19,10/21,10/23,11/27,08/09/01,12/22,12/24,12/25 Gerd Kortemeyer + package Apache::lonmeta; use strict; +use LONCAPA::lonmetadata(); use Apache::Constants qw(:common); -use Apache::lonnet(); +use Apache::lonnet; use Apache::loncommon(); +use Apache::lonhtmlcommon(); use Apache::lonmsg; use Apache::lonpublisher; +use Apache::lonlocal; +use Apache::lonmysql; +use Apache::lonmsg; +use LONCAPA qw(:DEFAULT :match); -# ----------------------------------------- Fetch and evaluate dynamic metadata +sub get_dynamic_metadata_from_sql { + my ($url) = shift(); + my ($authordom,$author)=($url=~m{^/res/($match_domain)/($match_username)/}); + if (! defined($authordom)) { + $authordom = shift(); + } + if (! defined($author)) { + $author = shift(); + } + if (! defined($authordom) || ! defined($author)) { + return (); + } + my $query = 'SELECT * FROM metadata WHERE url LIKE "'.$url.'%"'; + my $server = &Apache::lonnet::homeserver($author,$authordom); + my $reply = &Apache::lonnet::metadata_query($query,undef,undef, + ,[$server]); + return () if (! defined($reply) || ref($reply) ne 'HASH'); + my $filename = $reply->{$server}; + if (! defined($filename) || $filename =~ /^error/) { + return (); + } + my $max_time = time + 10; # wait 10 seconds for results at most + my %ReturnHash; + # + # Look for results + my $finished = 0; + while (! $finished && time < $max_time) { + my $datafile=$Apache::lonnet::perlvar{'lonDaemons'}.'/tmp/'.$filename; + if (! -e "$datafile.end") { next; } + my $fh; + if (!($fh=Apache::File->new($datafile))) { next; } + while (my $result = <$fh>) { + chomp($result); + next if (! $result); + my %hash=&LONCAPA::lonmetadata::metadata_col_to_hash('metadata', + map { &unescape($_) } split(/\,/,$result)); + foreach my $key (keys(%hash)) { + $ReturnHash{$hash{'url'}}->{$key}=$hash{$key}; + } + } + $finished = 1; + } + # + return %ReturnHash; +} + + +# Fetch and evaluate dynamic metadata sub dynamicmeta { my $url=&Apache::lonnet::declutter(shift); $url=~s/\.meta$//; - my ($adomain,$aauthor)=($url=~/^(\w+)\/(\w+)\//); + my ($adomain,$aauthor)=($url=~/^($match_domain)\/($match_username)\//); my $regexp=$url; $regexp=~s/(\W)/\\$1/g; $regexp='___'.$regexp.'___'; my %evaldata=&Apache::lonnet::dump('nohist_resevaldata',$adomain, $aauthor,$regexp); - my %sum; - my %cnt; - my %listitems=('count' => 'add', - 'course' => 'add', - 'avetries' => 'avg', - 'stdno' => 'add', - 'difficulty' => 'avg', - 'clear' => 'avg', - 'technical' => 'avg', - 'helpful' => 'avg', - 'correct' => 'avg', - 'depth' => 'avg', - 'comments' => 'app', - 'usage' => 'cnt' - ); - foreach (keys %evaldata) { - $_=~/___(\w+)$/; - if (defined($cnt{$1})) { $cnt{$1}++; } else { $cnt{$1}=1; } - unless ($listitems{$1} eq 'app') { - if (defined($sum{$1})) { - $sum{$1}+=$evaldata{$_}; - } else { - $sum{$1}=$evaldata{$_}; - } - } else { - if (defined($sum{$1})) { - if ($evaldata{$_}) { - $sum{$1}.='
  | '; + $output.=''.(' ' x2).' | '; } else { - $output.=''. - ' | '; + $output.=' | '. + ' | '; } $output.=' | '; if ($val>20) { - $output.=' | '. - ' | '; + $output.=' | '. + ' | '; } else { - $output.=' |   | '; + $output.=''.(' ' x2).' | '; } - $output.='('.$value.') |
'; + $output.=' | '; } else { - $output.=' | '; + $output.=' | '; } } - $output.=' | ('.$value.') |
Author(s) | -$content{'author'} |
Subject | -$content{'subject'} |
Keyword(s) | -$content{'keywords'} |
Notes | -$content{'notes'} |
Abstract | -$content{'abstract'} |
MIME Type | -$mime ($content{'mime'}) |
Language | -$language |
Creation Date | -$creationdate |
-Last Revision Date | $lastrevisiondate |
Publisher/Owner | -$content{'owner'} |
Copyright/Distribution | -$content{'copyright'} - |
'.$items{$_}.' | '. -$dynmeta{$_}." |
'.$items{$_}.' | '. -$dynmeta{$_}." |
'.$items{$_}.' | '. -&diffgraph($dynmeta{$_})." |
'.$items{$_}.' | '. -&evalgraph($dynmeta{$_})." |
'.$dynmeta{'comments'}.''); - $r->print( - '
'. + &mt('This resource has been marked obsolete by the author(s)'). + '
'; + } + # + my %lt=&fieldnames(); + my $table=''; + my $title = $content{'title'}; + if (! defined($title)) { + $title = 'Untitled Resource'; + } + my @fields; + if ($uploaded) { + @fields = ('title','author','subject','keywords','notes','abstract', + 'lowestgradelevel','highestgradelevel','standards','mime', + 'owner'); + } else { + @fields = ('title', + 'author', + 'subject', + 'keywords', + 'notes', + 'abstract', + 'lowestgradelevel', + 'highestgradelevel', + 'standards', + 'mime', + 'language', + 'creationdate', + 'lastrevisiondate', + 'owner', + 'copyright', + 'customdistributionfile', + 'sourceavail', + 'sourcerights', + 'obsolete', + 'obsoletereplacement'); + } + my $rownum = 0; + foreach my $field (@fields) { + my $lastrow = ''; + $rownum ++; + $lastrow = 1 if ($rownum == @fields); + $table.=&Apache::lonhtmlcommon::row_title($lt{$field}) + .&prettyprint($field,$content{$field}) + .&Apache::lonhtmlcommon::row_closure($lastrow); + delete($content{$field}); + } + # + $r->print("'
+ .$disuri.'
'
+ .$obsoletewarning
+ .$versiondisplay
+ .'
' + .&mt('No Access or Usages Statistics are available for this resource.') + .'
' + ); + } + # + # Assessment statistics + if ($uri=~/\.(problem|exam|quiz|assess|survey|form)$/) { + if (exists($dynmeta{'stdno'}) || + exists($dynmeta{'avetries'}) || + exists($dynmeta{'difficulty'}) || + exists($dynmeta{'disc'})) { + # This is an assessment, print assessment data + $r->print('' + .&mt('No new dynamic data found.') + .'
' + ); + } + } else { + $r->print('' + .&mt('No Evaluation Data is available for this resource.') + .'
' + ); + } + # Evaluation Comments + $uri=~/^\/res\/($match_domain)\/($match_username)\//; + if ((($env{'user.domain'} eq $1) && ($env{'user.name'} eq $2)) + || ($env{'user.role.ca./'.$1.'/'.$2})) { + $r->print(''.$dynmeta{'comments'}.''); + } else { + $r->print('
' + .&mt('There are no Evaluation Comments on this resource.') + .'
' + ); + } + my $bombs = &Apache::lonmsg::retrieve_author_res_msg($uri); + if (defined($bombs) && $bombs ne '') { + $r->print('' + .'