--- loncom/interface/lonmeta.pm 2006/10/16 21:39:37 1.183
+++ loncom/interface/lonmeta.pm 2007/01/12 22:13:51 1.196
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Metadata display handler
#
-# $Id: lonmeta.pm,v 1.183 2006/10/16 21:39:37 albertel Exp $
+# $Id: lonmeta.pm,v 1.196 2007/01/12 22:13:51 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -39,8 +39,7 @@ use Apache::lonpublisher;
use Apache::lonlocal;
use Apache::lonmysql;
use Apache::lonmsg;
-use lib '/home/httpd/lib/perl/';
-use LONCAPA;
+use LONCAPA qw(:DEFAULT :match);
############################################################
@@ -63,7 +62,7 @@ use LONCAPA;
############################################################
sub get_dynamic_metadata_from_sql {
my ($url) = shift();
- my ($authordom,$author)=($url=~m:^/res/(\w+)/(\w+)/:);
+ my ($authordom,$author)=($url=~m{^/res/($match_domain)/($match_username)/});
if (! defined($authordom)) {
$authordom = shift();
}
@@ -112,7 +111,7 @@ sub get_dynamic_metadata_from_sql {
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.'___';
@@ -236,7 +235,7 @@ sub fieldnames {
'lowestgradelevel' => 'Lowest Grade Level',
'highestgradelevel' => 'Highest Grade Level');
- if (! defined($file_type) || $file_type ne 'portfolio') {
+ if ( !defined($file_type) || ($file_type ne 'portfolio' && $file_type ne 'groups') ) {
%fields =
(%fields,
'domain' => 'Domain',
@@ -449,7 +448,7 @@ sub prettyprint {
($type eq 'owner') ||
($type eq 'modifyinguser') ||
($type eq 'authorspace')) {
- $value=~s/(\w+)(\:|\@)(\w+)/&authordisplay($1,$3)/gse;
+ $value=~s/($match_username)(\:|\@)($match_domain)/&authordisplay($1,$3)/gse;
return $value;
}
# Gradelevel
@@ -724,7 +723,7 @@ sub prettyinput {
sub handler {
my $r=shift;
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
- ['currentpath']);
+ ['currentpath','changecourse']);
my $uri=$r->uri;
#
# Set document type
@@ -732,21 +731,32 @@ sub handler {
$r->send_http_header;
return OK if $r->header_only;
my ($resdomain,$resuser)=
- (&Apache::lonnet::declutter($uri)=~/^(\w+)\/(\w+)\//);
+ (&Apache::lonnet::declutter($uri)=~/^($match_domain)\/($match_username)\//);
if ($uri=~m:/adm/bombs/(.*)$:) {
$r->print(&Apache::loncommon::start_page('Error Messages'));
# Looking for all bombs?
&report_bombs($r,$uri);
} elsif ($uri=~m|^/editupload/[^/]+/[^/]+/portfolio/|) {
($resdomain,$resuser)=
- (&Apache::lonnet::declutter($uri)=~m|^(\w+)/(\w+)/portfolio|);
+ (&Apache::lonnet::declutter($uri)=~m|^($match_domain)/($match_name)/portfolio|);
$r->print(&Apache::loncommon::start_page('Edit Portfolio File Catalog Information',
undef,
{'domain' => $resdomain,}));
if ($env{'form.store'}) {
&present_editable_metadata($r,$uri,'portfolio');
} else {
- &pre_select_course($r,$uri);
+ my $fn=&Apache::lonnet::filelocation('',$uri);
+ %Apache::lonpublisher::metadatafields=();
+ %Apache::lonpublisher::metadatakeys=();
+ my $result=&Apache::lonnet::getfile($fn);
+ &Apache::lonpublisher::metaeval($result);
+ &Apache::lonnet::logthis("restricted is: ".$Apache::lonpublisher::metadatafields{'courserestricted'});
+ if ((!$Apache::lonpublisher::metadatafields{'courserestricted'}) ||
+ ($env{'form.changecourse'} eq 'true')) {
+ &pre_select_course($r,$uri);
+ } else {
+ &present_editable_metadata($r,$uri,'portfolio');
+ }
}
} elsif ($uri=~m|^/editupload/[^/]+/[^/]+/groups/|) {
$r->print(&Apache::loncommon::start_page('Edit Group Portfolio File Catalog Information',
@@ -782,7 +792,7 @@ sub report_bombs {
$uri =~ s:/adm/bombs/::;
$uri = &Apache::lonnet::declutter($uri);
$r->print('
'.&Apache::lonnet::clutter($uri).'
');
- my ($domain,$author)=($uri=~/^(\w+)\/(\w+)\//);
+ my ($domain,$author)=($uri=~/^($match_domain)\/($match_username)\//);
if (&Apache::loncacc::constructaccess('/~'.$author.'/',$domain)) {
if ($env{'form.clearbombs'}) {
&Apache::lonmsg::clear_author_res_msg($uri);
@@ -1049,7 +1059,7 @@ sub print_dynamic_metadata {
} else {
$r->print('
'.&mt('No Evaluation Data is available for this resource.').'
');
}
- $uri=~/^\/res\/(\w+)\/(\w+)\//;
+ $uri=~/^\/res\/($match_domain)\/($match_username)\//;
if ((($env{'user.domain'} eq $1) && ($env{'user.name'} eq $2))
|| ($env{'user.role.ca./'.$1.'/'.$2})) {
if (exists($dynmeta{'comments'})) {
@@ -1192,37 +1202,44 @@ ENDEDIT
my $output;
my @fields;
my $added_metadata_fields;
+ my @added_order;
+ if ($file_type eq 'groups') {
+ $Apache::lonpublisher::metadatafields{'courserestricted'}=
+ 'course.'.$env{'request.course.id'};
+ }
+ if ((! $Apache::lonpublisher::metadatafields{'courserestricted'}) &&
+ (! $env{'form.new_courserestricted'}) && (! $file_type eq 'groups')) {
+ $Apache::lonpublisher::metadatafields{'courserestricted'}=
+ 'none';
+ } elsif ($env{'form.new_courserestricted'}) {
+ $Apache::lonpublisher::metadatafields{'courserestricted'}=
+ $env{'form.new_courserestricted'};
+ }
if ($file_type eq 'portfolio' || $file_type eq 'groups') {
if(exists ($env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.fieldlist'})) {
# retrieve fieldnames (in order) from the course restricted list
- @fields = (split /,/,$env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.fieldlist'});
+ @fields = (split(/,/,$env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.fieldlist'}));
} else {
# no saved field list, use default list
@fields = ('author','title','subject','keywords','abstract',
'notes','lowestgradelevel',
'highestgradelevel','standards');
- $added_metadata_fields = &Apache::lonparmset::get_added_meta_fieldnames();
- $env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.fieldlist'} = join (",",@fields);
+ if ($Apache::lonpublisher::metadatafields{'courserestricted'} =~ /^course\.($match_domain\_$match_courseid)$/) {
+ my $assoc_crs = $1;
+ $added_metadata_fields = &Apache::lonparmset::get_added_meta_fieldnames($assoc_crs);
+ if ($env{'course.'.$assoc_crs.'.metadata.addedorder'}) {
+ @added_order = split(/,/,$env{'course.'.$assoc_crs.'.metadata.addedorder'});
+ }
+ $env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.fieldlist'} = join(",",@fields);
+ }
}
} else {
@fields = ('author','title','subject','keywords','abstract','notes',
- 'copyright','customdistributionfile','language',
- 'standards',
- 'lowestgradelevel','highestgradelevel','sourceavail','sourcerights',
- 'obsolete','obsoletereplacement');
- }
- if ($file_type eq 'groups') {
- $Apache::lonpublisher::metadatafields{'courserestricted'}=
- 'course.'.$env{'request.course.id'};
+ 'copyright','customdistributionfile','language',
+ 'standards',
+ 'lowestgradelevel','highestgradelevel','sourceavail','sourcerights',
+ 'obsolete','obsoletereplacement');
}
- if ((! $Apache::lonpublisher::metadatafields{'courserestricted'}) &&
- (! $env{'form.new_courserestricted'}) && (! $file_type eq 'groups')) {
- $Apache::lonpublisher::metadatafields{'courserestricted'}=
- 'none';
- } elsif ($env{'form.new_courserestricted'}) {
- $Apache::lonpublisher::metadatafields{'courserestricted'}=
- $env{'form.new_courserestricted'};
- }
if (! $Apache::lonpublisher::metadatafields{'copyright'}) {
$Apache::lonpublisher::metadatafields{'copyright'}=
'default';
@@ -1238,17 +1255,35 @@ ENDEDIT
}
if ($Apache::lonpublisher::metadatafields{'courserestricted'} ne 'none') {
- $r->print(&mt('Associated with course [_1]',''.$env{$Apache::lonpublisher::metadatafields{'courserestricted'}.".description"}.
- '').' ');
+ if ($file_type eq 'portfolio') {
+ $r->print(&mt('Associated with course [_1]',
+ ''.
+ $env{$Apache::lonpublisher::metadatafields{'courserestricted'}.
+ ".description"}.
+ '').' ');
+ } else {
+ $r->print(&mt('Associated with course [_1]',
+ ''.
+ $env{$Apache::lonpublisher::metadatafields{'courserestricted'}.
+ ".description"}.'').' ');
+ }
} else {
- $r->print("This resource is not associated with a course. ");
+ $r->print('This resource is not associated with a course. ');
}
}
- foreach my $field_name(keys (%$added_metadata_fields)) {
-
- push (@fields,$field_name);
- $lt{$field_name} = $$added_metadata_fields{$field_name};
+ if (@added_order) {
+ foreach my $field_name (@added_order) {
+ push(@fields,$field_name);
+ $lt{$field_name} = $$added_metadata_fields{$field_name};
+ }
+ } else {
+ foreach my $field_name (keys(%$added_metadata_fields)) {
+ push(@fields,$field_name);
+ $lt{$field_name} = $$added_metadata_fields{$field_name};
+ }
}
+ $output .= &Apache::loncommon::start_data_table();
+ my $row_alt = 1;
foreach my $field_name (@fields) {
if (defined($env{'form.new_'.$field_name})) {
$Apache::lonpublisher::metadatafields{$field_name}=
@@ -1260,22 +1295,26 @@ ENDEDIT
if ((($env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.'.$field_name.'.options'} =~ m/active/) ||
($field_name eq 'courserestricted'))&&
(!($env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.'.$field_name.'.options'} =~ m/deleted/))){
- $output.=("\n".'