[LON-CAPA-cvs] cvs: loncom(version_2_3_X) /interface lonmeta.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Thu, 18 Jan 2007 23:20:57 -0000
This is a MIME encoded message
--albertel1169162457
Content-Type: text/plain
albertel Thu Jan 18 18:20:57 2007 EDT
Modified files: (Branch: version_2_3_X)
/loncom/interface lonmeta.pm
Log:
- backport 1.199 1.200
--albertel1169162457
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20070118182057.txt"
Index: loncom/interface/lonmeta.pm
diff -u loncom/interface/lonmeta.pm:1.195 loncom/interface/lonmeta.pm:1.195.2.1
--- loncom/interface/lonmeta.pm:1.195 Fri Jan 12 15:04:16 2007
+++ loncom/interface/lonmeta.pm Thu Jan 18 18:20:56 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Metadata display handler
#
-# $Id: lonmeta.pm,v 1.195 2007/01/12 20:04:16 raeburn Exp $
+# $Id: lonmeta.pm,v 1.195.2.1 2007/01/18 23:20:56 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -383,7 +383,40 @@
$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().
+ '<td><input type="checkbox" name="transfer_'.
+ $field_name.'" value="1" /></td><td>'.
+ $field_name.'</td><td>'.$value.'</td>'.
+ &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).'<br />'."\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.').'<br /><br />'.
+ &Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_header_row().
+ '<th>Copy to notes?</th>'."\n".
+ '<th>Field name</th>'."\n".
+ '<th>Values</th>'."\n".
+ &Apache::loncommon::end_data_table_header_row().
+ $transfernotes.
+ &Apache::loncommon::end_data_table().'<br />';
+ }
+ }
+ }
+ }
$output .= '<select name="new_courserestricted" >';
$output .= '<option value="none" '.$selected.'>'.
&mt('None').'</option>'.$/;
@@ -608,11 +641,10 @@
return (&select_course());
# return ('<input type="hidden" name="new_courserestricted" value="'.$course_key.'" />');
}
- 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')
- || (exists($env{'course.'.$env{'request.course.id'}.'.metadata.'.$type.'.added'}))) {
+ || (exists($env{$course_key.'.metadata.'.$type.'.added'}))) {
if ($values) {
if ($only_one) {
$output .= (&Apache::loncommon::select_form($cur_values_inst[0],'new_'.$type,%meta_options));
@@ -1191,6 +1223,22 @@
} else {
&Apache::lonpublisher::metaeval($result);
}
+ if ($env{'form.new_courserestricted'}) {
+ my $new_assoc_course = $env{'form.new_courserestricted'};
+ my $prev_courserestricted = $Apache::lonpublisher::metadatafields{'courserestricted'};
+ if (($prev_courserestricted) &&
+ ($prev_courserestricted ne $new_assoc_course)) {
+ my $transfers = [];
+ foreach my $key (keys(%env)) {
+ if ($key =~ /^form\.transfer_(.+)$/) {
+ push(@{$transfers},$1);
+ }
+ }
+ if (@{$transfers} > 0) {
+ &store_transferred_addedfields($fn,$uri,$transfers);
+ }
+ }
+ }
$r->print(<<ENDEDIT);
<h1>$displayfile</h1>
<form method="post" action="" name="defaultmeta">
@@ -1316,57 +1364,8 @@
}
$output .= &Apache::loncommon::end_data_table();
if ($env{'form.store'}) {
- my $mfh;
- my $formname='store';
- my $file_content;
- 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},
- '<>&"').
- '</'.$tag.'>';
- }
- 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,$uri));
- } else {
- if (! ($mfh=Apache::File->new('>'.$fn))) {
- $r->print('<p><font color="red">'.
- &mt('Could not write metadata').', '.
- &mt('FAIL').'</font></p>');
- } else {
- print $mfh ($file_content);
- close($mfh);
- &update_metadata_table($uri);
- $r->print('<p><font color="blue">'.&mt('Wrote Metadata').
- ' '.&Apache::lonlocal::locallocaltime(time).
- '</font></p>');
- }
- }
+ my ($outcome,$result) = &store_metadata($fn,$uri,'store');
+ $r->print($result);
}
$r->print($output.'<br /><input type="submit" name="store" value="'.
&mt('Store Catalog Information').'" />');
@@ -1391,20 +1390,114 @@
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},'<>&"').
+ '</'.$tag.'>';
+ }
+ 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 .= '<p><font color="red">';
+ 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').'</font></p>';
+ $outcome = 'fail';
+ } else {
+ print $mfh ($file_content);
+ close($mfh);
+ &update_metadata_table($uri);
+ $output .= '<p><font color="blue">';
+ if ($caller eq 'transfer') {
+ $output .= &mt('Transferred data in added fields to notes');
+ } else {
+ $output .= &mt('Wrote Metadata');
+ }
+ $output .= ' '.&Apache::lonlocal::locallocaltime(time).
+ '</font></p>';
+ $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) = @_;
+ my ($formname,$content,$path,$new_fn,$uri,$caller) = @_;
+ my ($outcome,$output);
$env{'form.'.$formname}=$content."\n";
$env{'form.'.$formname.'.filename'}=$new_fn;
my $result =&Apache::lonnet::userfileupload($formname,'',$path);
if ($result =~ /(error|notfound)/) {
- return '<p><font color="red">'.
- &mt('Could not write metadata').', '.
- &mt('FAIL').'</font></p>';
+ $output = '<p><font color="red">';
+ 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').'</font></p>';
+ $outcome = 'fail';
} else {
&update_metadata_table($uri);
- return '<p><font color="blue">'.&mt('Wrote Metadata').
- ' '.&Apache::lonlocal::locallocaltime(time).'</font></p>';
+ $output = '<p><font color="blue">';
+ if ($caller eq 'transfer') {
+ $output .= &mt('Transferred data in added fields to notes');
+ } else {
+ $output .= &mt('Wrote Metadata');
+ }
+ $output .= ' '.&Apache::lonlocal::locallocaltime(time).
+ '</font></p>';
+ $outcome = 'ok';
}
+ return ($outcome,$output);
}
sub update_metadata_table {
--albertel1169162457--