--- loncom/interface/lonmeta.pm 2006/12/05 02:55:53 1.190 +++ 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.190 2006/12/05 02:55:53 albertel Exp $ +# $Id: lonmeta.pm,v 1.193 2007/01/02 19:38:17 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -235,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', @@ -1252,11 +1252,18 @@ ENDEDIT } if ($Apache::lonpublisher::metadatafields{'courserestricted'} ne 'none') { - $r->print(&mt('Associated with course [_1]', + 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.
'); } @@ -1342,7 +1349,7 @@ ENDEDIT ($path, $new_fn) = ($fn =~ m|/(portfolio.*)/([^/]*)$|); } $r->print(&store_portfolio_metadata($formname,$file_content,$path, - $new_fn)); + $new_fn,$uri)); } else { if (! ($mfh=Apache::File->new('>'.$fn))) { $r->print('

'. @@ -1350,6 +1357,8 @@ ENDEDIT &mt('FAIL').'

'); } else { print $mfh ($file_content); + close($mfh); + &update_metadata_table($uri); $r->print('

'.&mt('Wrote Metadata'). ' '.&Apache::lonlocal::locallocaltime(time). '

'); @@ -1359,16 +1368,16 @@ ENDEDIT $r->print($output.'
'); - 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('

'); - if ($group) { + if ($group ne '') { $r->print(''); - } + } $r->print(''. ''); } @@ -1380,7 +1389,7 @@ ENDEDIT } sub store_portfolio_metadata { - my ($formname,$content,$path,$new_fn) = @_; + my ($formname,$content,$path,$new_fn,$uri) = @_; $env{'form.'.$formname}=$content."\n"; $env{'form.'.$formname.'.filename'}=$new_fn; my $result =&Apache::lonnet::userfileupload($formname,'',$path); @@ -1389,11 +1398,50 @@ sub store_portfolio_metadata { &mt('Could not write metadata').', '. &mt('FAIL').'

'; } else { + &update_metadata_table($uri); return '

'.&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__