--- loncom/interface/lonmeta.pm 2006/08/16 18:06:47 1.170
+++ loncom/interface/lonmeta.pm 2007/01/02 19:38:17 1.193
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Metadata display handler
#
-# $Id: lonmeta.pm,v 1.170 2006/08/16 18:06:47 banghart Exp $
+# $Id: lonmeta.pm,v 1.193 2007/01/02 19:38:17 raeburn 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();
}
@@ -95,7 +94,8 @@ sub get_dynamic_metadata_from_sql {
while (my $result = <$fh>) {
chomp($result);
next if (! $result);
- my %hash=&LONCAPA::lonmetadata::metadata_col_to_hash(map { &unescape($_) } split(/\,/,$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};
}
@@ -111,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.'___';
@@ -235,13 +235,7 @@ sub fieldnames {
'lowestgradelevel' => 'Lowest Grade Level',
'highestgradelevel' => 'Highest Grade Level');
- if (! defined($file_type) || $file_type ne 'portfolio') {
- %fields =
- (%fields,
- 'courserestricted' => 'Course Restricting Metadata');
- }
-
- if (! defined($file_type) || $file_type ne 'portfolio') {
+ if ( !defined($file_type) || ($file_type ne 'portfolio' && $file_type ne 'groups') ) {
%fields =
(%fields,
'domain' => 'Domain',
@@ -454,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
@@ -474,7 +468,7 @@ sub prettyprint {
($type eq 'sequsage_list') ||
($type eq 'dependencies')) {
return ' '.$lt{$field_name}.': '.
+ 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".&Apache::loncommon::start_data_table_row();
+ $output .= (' '.$lt{$field_name}.': '.
- &prettyinput($field_name,
- $Apache::lonpublisher::metadatafields{$field_name},
- 'new_'.$field_name,'defaultmeta').' '.
&mt('Could not write metadata').', '.
&mt('FAIL').' '.&mt('Wrote Metadata').
' '.&Apache::lonlocal::locallocaltime(time).
''.join("\n",map {
- my $url = &Apache::lonnet::clutter($_);
+ my $url = &Apache::lonnet::clutter_with_no_wrapper($_);
my $title = &Apache::lonnet::gettitle($url);
if ($title eq '') {
$title = 'Untitled';
@@ -511,6 +505,7 @@ sub prettyprint {
if ($type=~/\_list/) {
my @Courses = split(/\s*\,\s*/,$value);
my $Str='
';
+ my %descriptions;
foreach my $course (@Courses) {
my %courseinfo =
&Apache::lonnet::coursedescription($course,
@@ -518,10 +513,16 @@ sub prettyprint {
if (! exists($courseinfo{'num'}) || $courseinfo{'num'} eq '') {
next;
}
- $Str .= '
';
}
# No pretty print found
@@ -607,9 +608,11 @@ sub prettyinput {
return (&select_course());
# return ('');
}
+ my $course = $env{'request.course.id'};
if (($type eq 'keywords') || ($type eq 'subject')
|| ($type eq 'author')||($type eq 'notes')
- || ($type eq 'abstract')|| ($type eq 'title')|| ($type eq 'standards')) {
+ || ($type eq 'abstract')|| ($type eq 'title')|| ($type eq 'standards')
+ || (exists($env{'course.'.$env{'request.course.id'}.'.metadata.'.$type.'.added'}))) {
if ($values) {
if ($only_one) {
$output .= (&Apache::loncommon::select_form($cur_values_inst[0],'new_'.$type,%meta_options));
@@ -624,7 +627,7 @@ sub prettyinput {
$relatedvalue);
}
return ($output);
- }
+ }
if (($type eq 'lowestgradelevel') ||
($type eq 'highestgradelevel')) {
return &Apache::loncommon::select_level_form($value,$fieldname).
@@ -719,33 +722,47 @@ sub prettyinput {
# Main Handler
sub handler {
my $r=shift;
- #
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
- ['currentpath']);
+ ['currentpath','changecourse']);
my $uri=$r->uri;
#
# Set document type
&Apache::loncommon::content_type($r,'text/html');
$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',
+ undef,
+ {'domain' => $resdomain,}));
+ &present_editable_metadata($r,$uri,'groups');
} elsif ($uri=~m|^/~|) {
# Construction space
$r->print(&Apache::loncommon::start_page('Edit Catalog nformation',
@@ -775,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);
@@ -822,8 +839,7 @@ sub present_uneditable_metadata {
# displayed url
my ($thisversion)=($uri=~/\.(\d+)\.(\w+)\.meta$/);
$uri=~s/\.meta$//;
- my $disuri=&Apache::lonnet::clutter($uri);
- $disuri=~s/^\/adm\/wrapper//;
+ my $disuri=&Apache::lonnet::clutter_with_no_wrapper($uri);
# version
my $versiondisplay='';
if (!$uploaded) {
@@ -1043,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'})) {
@@ -1106,7 +1122,7 @@ sub print_dynamic_metadata {
#####################################################
#####################################################
sub present_editable_metadata {
- my ($r,$uri, $file_type) = @_;
+ my ($r,$uri,$file_type) = @_;
# Construction Space Call
# Header
my $disuri=$uri;
@@ -1185,19 +1201,36 @@ ENDEDIT
my %lt=&fieldnames($file_type);
my $output;
my @fields;
- if ($file_type eq 'portfolio') {
- @fields = ('author','title','subject','keywords','abstract',
- 'notes','lowestgradelevel',
- 'highestgradelevel','standards');
+ my $added_metadata_fields;
+ my @added_order;
+ 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'}));
+ } 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();
+ if ($env{'course.'.$env{'request.course.id'}.'.metadata.addedorder'}) {
+ @added_order = split(/,/,$env{'course.'.$env{'request.course.id'}.'.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');
+ 'copyright','customdistributionfile','language',
+ 'standards',
+ 'lowestgradelevel','highestgradelevel','sourceavail','sourcerights',
+ 'obsolete','obsoletereplacement');
+ }
+ if ($file_type eq 'groups') {
+ $Apache::lonpublisher::metadatafields{'courserestricted'}=
+ 'course.'.$env{'request.course.id'};
}
if ((! $Apache::lonpublisher::metadatafields{'courserestricted'}) &&
- (! $env{'form.new_courserestricted'})) {
+ (! $env{'form.new_courserestricted'}) && (! $file_type eq 'groups')) {
$Apache::lonpublisher::metadatafields{'courserestricted'}=
'none';
} elsif ($env{'form.new_courserestricted'}) {
@@ -1208,7 +1241,7 @@ ENDEDIT
$Apache::lonpublisher::metadatafields{'copyright'}=
'default';
}
- if ($file_type eq 'portfolio') {
+ if (($file_type eq 'portfolio') || ($file_type eq 'groups')) {
if (! $Apache::lonpublisher::metadatafields{'mime'}) {
($Apache::lonpublisher::metadatafields{'mime'}) =
( $target=~/\.(\w+)$/ );
@@ -1219,14 +1252,36 @@ 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.
');
}
}
+ 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}=
join(',',&Apache::loncommon::get_env_multiple('form.new_'.$field_name));
@@ -1234,24 +1289,29 @@ ENDEDIT
if ($Apache::lonpublisher::metadatafields{'courserestricted'} ne 'none'
&& exists($env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.'.$field_name.'.options'})) {
# handle restrictions here
- if (($env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.'.$field_name.'.options'} =~ m/active/) ||
- ($field_name eq 'courserestricted')){
- $output.=("\n".' '.
&prettyinput($field_name,
$Apache::lonpublisher::metadatafields{$field_name},
'new_'.$field_name,'defaultmeta',
undef,undef,undef,undef,
- $Apache::lonpublisher::metadatafields{'courserestricted'}).''."\n");
+ $Apache::lonpublisher::metadatafields{'courserestricted'}).' ');
+ $output .= &Apache::loncommon::end_data_table_row();
}
} else {
- $output.=(' '.
+ &prettyinput($field_name,
+ $Apache::lonpublisher::metadatafields{$field_name},
+ 'new_'.$field_name,'defaultmeta').' '.&Apache::loncommon::end_data_table_row());
}
}
+ $output .= &Apache::loncommon::end_data_table();
if ($env{'form.store'}) {
my $mfh;
my $formname='store';
@@ -1260,22 +1320,20 @@ ENDEDIT
$Apache::lonpublisher::metadatafields{'keywords'} =
join (',', &Apache::loncommon::get_env_multiple('form.new_keywords'));
}
-
- foreach (sort keys %Apache::lonpublisher::metadatafields) {
- next if ($_ =~ /\./);
- my $unikey=$_;
- $unikey=~/^([A-Za-z]+)/;
+ foreach my $field (sort(keys(%Apache::lonpublisher::metadatafields))) {
+ next if ($field =~ /\./);
+ my $unikey=$field;
+ $unikey=~/^([A-Za-z_]+)/;
my $tag=$1;
$tag=~tr/A-Z/a-z/;
$file_content.= "\n\<$tag";
- foreach (split(/\,/,
- $Apache::lonpublisher::metadatakeys{$unikey})
- ) {
+ foreach my $key (split(/\,/,
+ $Apache::lonpublisher::metadatakeys{$unikey})
+ ) {
my $value=
- $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
+ $Apache::lonpublisher::metadatafields{$unikey.'.'.$key};
$value=~s/\"/\'\'/g;
- $file_content.=' '.$_.'="'.$value.'"' ;
- # print $mfh ' '.$_.'="'.$value.'"';
+ $file_content.=' '.$key.'="'.$value.'"' ;
}
$file_content.= '>'.
&HTML::Entities::encode
@@ -1283,52 +1341,44 @@ ENDEDIT
'<>&"').
''.$tag.'>';
}
- if ($fn =~ m|^$Apache::lonnet::perlvar{'lonDocRoot'}/userfiles/portfolio/|) {
- my ($path, $new_fn) = ($fn =~ m|/(portfolio.*)/([^/]*)$|);
+ if ($fn =~ m|^$Apache::lonnet::perlvar{'lonDocRoot'}/userfiles|) {
+ my ($path, $new_fn);
+ if ($fn =~ m|$match_name/groups/\w+/portfolio/|) {
+ ($path, $new_fn) = ($fn =~ m|/(groups/\w+/portfolio.*)/([^/]*)$|);
+ } else {
+ ($path, $new_fn) = ($fn =~ m|/(portfolio.*)/([^/]*)$|);
+ }
$r->print(&store_portfolio_metadata($formname,$file_content,$path,
- $new_fn));
- unless ($env{'form.associate'}) {
- $r->print(&Apache::portfolio::done("Return to Portfolio",'/adm/portfolio'));
- return;
- }
- } 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));
- unless ($env{'form.associate'}) {
- $r->print(&Apache::portfolio::done("Return to Portfolio",'/adm/portfolio'));
- return;
- }
- } else {
- if (! ($mfh=Apache::File->new('>'.$fn))) {
+ $new_fn,$uri));
+ } else {
+ if (! ($mfh=Apache::File->new('>'.$fn))) {
$r->print('
');
- if ($file_type eq 'portfolio') {
+ if ($file_type eq 'portfolio' || $file_type eq 'groups') {
my ($port_path,$group) = &get_port_path_and_group($uri);
- if ($group) {
+ if ($group ne '') {
$r->print('');
}
$r->print('');
- $r->print('
-
'.&mt('Wrote Metadata'). ' '.&Apache::lonlocal::locallocaltime(time).'
'; } } +sub update_metadata_table { + my ($uri) = @_; + my ($group,$file_name); + my ($udom,$uname,$remainder) = + ($uri=~m -^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$-); + + if ($remainder =~ /^groups\/(\w+)\/portfolio(\/.+)$/) { + $group = $1; + $file_name = $2; + } elsif ($remainder =~ /^portfolio(\/.+)$/) { + $file_name = $1; + } + $file_name =~ s/\.meta$//; + my $current_permissions = + &Apache::lonnet::get_portfile_permissions($udom,$uname); + my %access_controls = + &Apache::lonnet::get_access_controls($current_permissions,$group, + $group.$file_name); + my $access_hash = $access_controls{$file_name}; + my $available = 0; + if (ref($access_hash) eq 'HASH') { + foreach my $key (keys(%{$access_hash})) { + my ($num,$scope,$end,$start) = + ($key =~ /^([^:]+):([a-z]+)_(\d*)_?(\d*)$/); + if ($scope eq 'public' || $scope eq 'guest') { + $available = 1; + last; + } + } + } + if ($available) { + my $result = + &Apache::lonnet::update_portfolio_table($uname,$udom, + $file_name,'portfolio_metadata',$group); + } +} + + 1; __END__