--- loncom/interface/lonmeta.pm 2007/01/18 23:20:56 1.195.2.1 +++ loncom/interface/lonmeta.pm 2007/01/16 07:26:45 1.199 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Metadata display handler # -# $Id: lonmeta.pm,v 1.195.2.1 2007/01/18 23:20:56 albertel Exp $ +# $Id: lonmeta.pm,v 1.199 2007/01/16 07:26:45 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -383,40 +383,7 @@ sub select_course { $Apache::lonpublisher::metadatafields{'courserestricted'}; my $selected = ($current_restriction eq 'none' ? 'selected="selected"' : ''); - if ($current_restriction =~ /^course\.($match_domain\_$match_courseid)$/) { - my $assoc_crs = $1; - my $added_metadata_fields = &Apache::lonparmset::get_added_meta_fieldnames($assoc_crs); - if (ref($added_metadata_fields) eq 'HASH') { - if (keys(%{$added_metadata_fields}) > 0) { - my $transfernotes; - foreach my $field_name (keys(%{$added_metadata_fields})) { - my $value = $Apache::lonpublisher::metadatafields{$field_name}; - if ($value) { - $transfernotes .= - &Apache::loncommon::start_data_table_row(). - ''. - $field_name.''.$value.''. - &Apache::loncommon::end_data_table_row(); - } - } - if ($transfernotes ne '') { - my %courseinfo = &Apache::lonnet::coursedescription($assoc_crs,{'one_time' => 1}); - my $assoc_crs_description = $courseinfo{'description'}; - $output .= &mt('This resource is currently associated with a course ([_1]) which includes added metadata fields specific to the course.',$assoc_crs_description).'
'."\n". - &mt('You can choose to transfer data from the added fields to the "Notes" field if you are planning to change the course association.').'

'. - &Apache::loncommon::start_data_table(). - &Apache::loncommon::start_data_table_header_row(). - 'Copy to notes?'."\n". - 'Field name'."\n". - 'Values'."\n". - &Apache::loncommon::end_data_table_header_row(). - $transfernotes. - &Apache::loncommon::end_data_table().'
'; - } - } - } - } + $output .= ''); @@ -1390,134 +1396,32 @@ ENDEDIT return; } -sub store_metadata { - my ($fn,$uri,$caller) = @_; - my $mfh; - my $formname='store'; - my ($file_content,$output,$outcome); - if (&Apache::loncommon::get_env_multiple('form.new_keywords')) { - $Apache::lonpublisher::metadatafields{'keywords'} = - join (',', &Apache::loncommon::get_env_multiple('form.new_keywords')); - } - 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 my $key (split(/\,/,$Apache::lonpublisher::metadatakeys{$unikey})) { - my $value = $Apache::lonpublisher::metadatafields{$unikey.'.'.$key}; - $value=~s/\"/\'\'/g; - $file_content.=' '.$key.'="'.$value.'"' ; - } - $file_content.= '>'. - &HTML::Entities::encode - ($Apache::lonpublisher::metadatafields{$unikey},'<>&"'). - ''; - } - 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.*)/([^/]*)$|); - } - ($outcome,my $result) = - &store_portfolio_metadata($formname,$file_content, - $path,$new_fn,$uri,$caller); - $output .= $result; - } else { - if (! ($mfh=Apache::File->new('>'.$fn))) { - $output .= '

'; - if ($caller eq 'transfer') { - $output .= &mt('Could not transfer data in added fields to notes'); - } else { - $output .= &mt('Could not write metadata'); - } - $output .= ', '.&mt('FAIL').'

'; - $outcome = 'fail'; - } else { - print $mfh ($file_content); - close($mfh); - &update_metadata_table($uri); - $output .= '

'; - if ($caller eq 'transfer') { - $output .= &mt('Transferred data in added fields to notes'); - } else { - $output .= &mt('Wrote Metadata'); - } - $output .= ' '.&Apache::lonlocal::locallocaltime(time). - '

'; - $outcome = 'ok'; - } - } - return ($outcome,$output); -} - -sub store_transferred_addedfields { - my ($fn,$uri,$transfers) = @_; - foreach my $item (@{$transfers}) { - $Apache::lonpublisher::metadatafields{'notes'} .= - ' '.$item.' = '.$Apache::lonpublisher::metadatafields{$item}; - } - my ($outcome,$output) = &store_metadata($fn,$uri,'transfer'); - if ($outcome eq 'ok') { - foreach my $item (@{$transfers}) { - delete($Apache::lonpublisher::metadatafields{$item}); - } - } -} - sub store_portfolio_metadata { - my ($formname,$content,$path,$new_fn,$uri,$caller) = @_; - my ($outcome,$output); + 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); if ($result =~ /(error|notfound)/) { - $output = '

'; - if ($caller eq 'transfer') { - $output .= - &mt('Could not transfer data in added fields to notes'); - } else { - $output .= &mt('Could not write metadata'); - } - $output .= ', '.&mt('FAIL').'

'; - $outcome = 'fail'; + return '

'. + &mt('Could not write metadata').', '. + &mt('FAIL').'

'; } else { &update_metadata_table($uri); - $output = '

'; - if ($caller eq 'transfer') { - $output .= &mt('Transferred data in added fields to notes'); - } else { - $output .= &mt('Wrote Metadata'); - } - $output .= ' '.&Apache::lonlocal::locallocaltime(time). - '

'; - $outcome = 'ok'; + return '

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

'; } - return ($outcome,$output); } 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; - } + my ($type,$udom,$uname,$file_name,$group) = + &Apache::lonnet::parse_portfolio_url($uri); $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); + $file_name); my $access_hash = $access_controls{$file_name}; my $available = 0; if (ref($access_hash) eq 'HASH') {