--- loncom/interface/lonmeta.pm 2006/03/16 22:12:17 1.153
+++ loncom/interface/lonmeta.pm 2006/08/04 22:14:38 1.163
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Metadata display handler
#
-# $Id: lonmeta.pm,v 1.153 2006/03/16 22:12:17 albertel Exp $
+# $Id: lonmeta.pm,v 1.163 2006/08/04 22:14:38 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -39,6 +39,8 @@ use Apache::lonpublisher;
use Apache::lonlocal;
use Apache::lonmysql;
use Apache::lonmsg;
+use lib '/home/httpd/lib/perl/';
+use LONCAPA;
############################################################
@@ -71,20 +73,7 @@ sub get_dynamic_metadata_from_sql {
if (! defined($authordom) || ! defined($author)) {
return ();
}
- my @Fields = ('url','count','course','course_list',
- 'goto','goto_list',
- 'comefrom','comefrom_list',
- 'sequsage','sequsage_list',
- 'stdno','stdno_list',
- 'dependencies',
- 'avetries','avetries_list',
- 'difficulty','difficulty_list',
- 'disc','disc_list',
- 'clear','technical','correct',
- 'helpful','depth');
- #
- my $query = 'SELECT '.join(',',@Fields).
- ' FROM metadata WHERE url LIKE "'.$url.'%"';
+ 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]);
@@ -106,13 +95,9 @@ sub get_dynamic_metadata_from_sql {
while (my $result = <$fh>) {
chomp($result);
next if (! $result);
- my @Data =
- map {
- &Apache::lonnet::unescape($_);
- } split(',',$result);
- my $url = $Data[0];
- for (my $i=0;$i<=$#Fields;$i++) {
- $ReturnHash{$url}->{$Fields[$i]}=$Data[$i];
+ my %hash=&LONCAPA::lonmetadata::metadata_col_to_hash(map { &unescape($_) } split(/\,/,$result));
+ foreach my $key (keys(%hash)) {
+ $ReturnHash{$hash{'url'}}->{$key}=$hash{$key};
}
}
$finished = 1;
@@ -296,25 +281,52 @@ sub fieldnames {
}
sub portfolio_linked_path {
- my ($path) = @_;
- my $result = &Apache::portfolio::make_anchor('portfolio','/');
+ my ($path,$group,$port_path) = @_;
+
+ my $start = 'portfolio';
+ if ($group) {
+ $start = "groups/$group/".$start;
+ }
+ my $result = &Apache::portfolio::make_anchor($port_path,$start,'/');
+
my $fullpath = '/';
my (undef,@tree) = split('/',$path);
my $filename = pop(@tree);
foreach my $dir (@tree) {
$fullpath .= $dir.'/';
$result .= '/';
- $result .= &Apache::portfolio::make_anchor($dir,$fullpath);
+ $result .= &Apache::portfolio::make_anchor($port_path,$dir,$fullpath);
}
$result .= "/$filename";
return $result;
}
+sub get_port_path_and_group {
+ my ($uri)=@_;
+
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+
+ my ($port_path,$group);
+ if ($uri =~ m{^/editupload/\Q$cdom\E/\Q$cnum\E/groups/}) {
+ $group = (split('/',$uri))[5];
+ $port_path = '/adm/coursegrp_portfolio';
+ } else {
+ $port_path = '/adm/portfolio';
+ }
+ if ($env{'form.group'} ne $group) {
+ $env{'form.group'} = $group;
+ }
+ return ($port_path,$group);
+}
+
sub portfolio_display_uri {
my ($uri,$as_links)=@_;
+
+ my ($port_path,$group) = &get_port_path_and_group($uri);
+
$uri =~ s|.*/(portfolio/.*)$|$1|;
my ($res_uri,$meta_uri) = ($uri,$uri);
-
if ($uri =~ /\.meta$/) {
$res_uri =~ s/\.meta//;
} else {
@@ -322,10 +334,9 @@ sub portfolio_display_uri {
}
my ($path) = ($res_uri =~ m|^portfolio(.*/)[^/]*$|);
-
if ($as_links) {
- $res_uri = &portfolio_linked_path($res_uri);
- $meta_uri = &portfolio_linked_path($meta_uri);
+ $res_uri = &portfolio_linked_path($res_uri,$group,$port_path);
+ $meta_uri = &portfolio_linked_path($meta_uri,$group,$port_path);
}
return ($res_uri,$meta_uri,$path);
}
@@ -350,8 +361,10 @@ sub pre_select_course {
&mt('Associate Resource With Selected Course').'">');
$r->print('');
- $r->print('
');
@@ -486,7 +499,9 @@ sub prettyprint {
my @Courses = split(/\s*\,\s*/,$value);
my $Str='';
foreach my $course (@Courses) {
- my %courseinfo = &Apache::lonnet::coursedescription($course);
+ my %courseinfo =
+ &Apache::lonnet::coursedescription($course,
+ {'one_time' => 1});
if (! exists($courseinfo{'num'}) || $courseinfo{'num'} eq '') {
next;
}
@@ -701,14 +716,13 @@ sub handler {
#
my ($resdomain,$resuser)=
(&Apache::lonnet::declutter($uri)=~/^(\w+)\/(\w+)\//);
-
if ($uri=~m:/adm/bombs/(.*)$:) {
$r->print(&Apache::loncommon::start_page('Error Messages'));
# Looking for all bombs?
&report_bombs($r,$uri);
- } elsif ($uri=~/\/portfolio\//) {
+ } elsif ($uri=~m|^/editupload/[^/]+/[^/]+/portfolio/|) {
($resdomain,$resuser)=
- (&Apache::lonnet::declutter($uri)=~m|^(\w+)/(\w+)/portfolio|);
+ (&Apache::lonnet::declutter($uri)=~m|^(\w+)/(\w+)/portfolio|);
$r->print(&Apache::loncommon::start_page('Edit Portfolio File Catalog Information',
undef,
{'domain' => $resdomain,}));
@@ -717,7 +731,7 @@ sub handler {
} else {
&pre_select_course($r,$uri);
}
- } elsif ($uri=~/^\/\~/) {
+ } elsif ($uri=~m|^/~|) {
# Construction space
$r->print(&Apache::loncommon::start_page('Edit Catalog nformation',
undef,
@@ -783,6 +797,7 @@ ENDCLEAR
sub present_uneditable_metadata {
my ($r,$uri) = @_;
#
+ my $uploaded = ($uri =~ m|/uploaded/|);
my %content=();
# Read file
foreach (split(/\,/,&Apache::lonnet::metadata($uri,'keys'))) {
@@ -795,16 +810,18 @@ sub present_uneditable_metadata {
my $disuri=&Apache::lonnet::clutter($uri);
$disuri=~s/^\/adm\/wrapper//;
# version
- my $currentversion=&Apache::lonnet::getversion($disuri);
my $versiondisplay='';
- if ($thisversion) {
- $versiondisplay=&mt('Version').': '.$thisversion.
- ' ('.&mt('most recent version').': '.
- ($currentversion>0 ?
- $currentversion :
- &mt('information not available')).')';
- } else {
- $versiondisplay='Version: '.$currentversion;
+ if (!$uploaded) {
+ my $currentversion=&Apache::lonnet::getversion($disuri);
+ if ($thisversion) {
+ $versiondisplay=&mt('Version').': '.$thisversion.
+ ' ('.&mt('most recent version').': '.
+ ($currentversion>0 ?
+ $currentversion :
+ &mt('information not available')).')';
+ } else {
+ $versiondisplay='Version: '.$currentversion;
+ }
}
# crumbify displayed URL uri target prefix form size
$disuri=&Apache::lonhtmlcommon::crumbs($disuri,undef, undef, undef,'+1');
@@ -824,30 +841,38 @@ sub present_uneditable_metadata {
if (! defined($title)) {
$title = 'Untitled Resource';
}
- foreach ('title',
- 'author',
- 'subject',
- 'keywords',
- 'notes',
- 'abstract',
- 'lowestgradelevel',
- 'highestgradelevel',
- 'standards',
- 'mime',
- 'language',
- 'creationdate',
- 'lastrevisiondate',
- 'owner',
- 'copyright',
- 'customdistributionfile',
- 'sourceavail',
- 'sourcerights',
- 'obsolete',
- 'obsoletereplacement') {
- $table.=''.$lt{$_}.
+ 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');
+ }
+ foreach my $field (@fields) {
+ $table.=' |
'.$lt{$field}.
' | '.
- &prettyprint($_,$content{$_}).' |
';
- delete $content{$_};
+ &prettyprint($field,$content{$field}).'';
+ delete($content{$field});
}
#
$r->print(<
ENDHEAD
- if ($env{'user.adv'}) {
+ if (!$uploaded && $env{'user.adv'}) {
&print_dynamic_metadata($r,$uri,\%content);
}
return;
@@ -944,7 +969,9 @@ sub print_dynamic_metadata {
foreach my $identifier (sort(keys(%{$dynmeta{'stats'}}))) {
my $data = $dynmeta{'stats'}->{$identifier};
my $course = $data->{'course'};
- my %courseinfo = &Apache::lonnet::coursedescription($course);
+ my %courseinfo =
+ &Apache::lonnet::coursedescription($course,
+ {'one_time' => 1});
if (! exists($courseinfo{'num'}) || $courseinfo{'num'} eq '') {
&Apache::lonnet::logthis('lookup for '.$course.' failed');
next;
@@ -1069,7 +1096,7 @@ sub present_editable_metadata {
# Header
my $disuri=$uri;
my $fn=&Apache::lonnet::filelocation('',$uri);
- $disuri=~s/^\/\~/\/priv\//;
+ $disuri=~s{^/\~}{/priv/};
$disuri=~s/\.meta$//;
my $meta_uri = $disuri;
my $path;
@@ -1077,7 +1104,7 @@ sub present_editable_metadata {
($disuri, $meta_uri, $path) = &portfolio_display_uri($disuri,1);
}
my $target=$uri;
- $target=~s/^\/\~/\/res\/$env{'request.role.domain'}\//;
+ $target=~s{^/\~}{/res/$env{'request.role.domain'}/};
$target=~s/\.meta$//;
my $bombs=&Apache::lonmsg::retrieve_author_res_msg($target);
if ($bombs) {
@@ -1144,7 +1171,8 @@ ENDEDIT
my $output;
my @fields;
if ($file_type eq 'portfolio') {
- @fields = ('author','title','subject','keywords','abstract','notes','lowestgradelevel',
+ @fields = ('author','title','subject','keywords','abstract',
+ 'notes','lowestgradelevel',
'highestgradelevel','standards');
} else {
@fields = ('author','title','subject','keywords','abstract','notes',
@@ -1163,9 +1191,18 @@ ENDEDIT
}
if (! $Apache::lonpublisher::metadatafields{'copyright'}) {
$Apache::lonpublisher::metadatafields{'copyright'}=
- 'default';
+ 'default';
}
if ($file_type eq 'portfolio') {
+ if (! $Apache::lonpublisher::metadatafields{'mime'}) {
+ ($Apache::lonpublisher::metadatafields{'mime'}) =
+ ( $target=~/\.(\w+)$/ );
+ }
+ if (! $Apache::lonpublisher::metadatafields{'owner'}) {
+ $Apache::lonpublisher::metadatafields{'owner'} =
+ $env{'user.name'}.':'.$env{'user.domain'};
+ }
+
if ($Apache::lonpublisher::metadatafields{'courserestricted'} ne 'none') {
$r->print(&mt('Associated with course [_1]',''.$env{$Apache::lonpublisher::metadatafields{'courserestricted'}.".description"}.
'').'
');
@@ -1231,22 +1268,13 @@ ENDEDIT
'<>&"').
''.$tag.'>';
}
- if ($fn =~ m|/portfolio/|) {
+ if ($fn =~ m|^$Apache::lonnet::perlvar{'lonDocRoot'}/userfiles/portfolio/|) {
my ($path, $new_fn) = ($fn =~ m|/(portfolio.*)/([^/]*)$|);
- $env{'form.'.$formname}=$file_content."\n";
- $env{'form.'.$formname.'.filename'}=$new_fn;
- my $result =&Apache::lonnet::userfileupload($formname,'',
- $path);
-
- if ($result =~ /(error|notfound)/) {
- $r->print(''.
- &mt('Could not write metadata').', '.
- &mt('FAIL').'
');
- } else {
- $r->print(''.&mt('Wrote Metadata').
- ' '.&Apache::lonlocal::locallocaltime(time).
- '
');
- }
+ $r->print(&store_portfolio_metadata($formname,$file_content,$path,
+ $new_fn));
+ } elsif ($fn =~ m|^$Apache::lonnet::perlvar{'lonDocRoot'}/userfiles/groups/\w+/portfolio/|) {
+ my ($path, $new_fn) = ($fn =~ m|/(groups/\w+/portfolio.*)/([^/]*)$|);
+ $r->print(&store_portfolio_metadata($formname,$file_content,$path,$new_fn));
} else {
if (! ($mfh=Apache::File->new('>'.$fn))) {
$r->print(''.
@@ -1265,8 +1293,13 @@ ENDEDIT
&mt('Store Catalog Information').'">');
if ($file_type eq 'portfolio') {
+ my ($port_path,$group) = &get_port_path_and_group($uri);
+ if ($group) {
+ $r->print('');
+ }
$r->print('
-