[LON-CAPA-cvs] cvs: loncom /interface lonmeta.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Mon, 19 Dec 2005 21:13:45 -0000
albertel Mon Dec 19 16:13:45 2005 EDT
Modified files:
/loncom/interface lonmeta.pm
Log:
- saving portfolio metadata works again
Index: loncom/interface/lonmeta.pm
diff -u loncom/interface/lonmeta.pm:1.142 loncom/interface/lonmeta.pm:1.143
--- loncom/interface/lonmeta.pm:1.142 Mon Dec 19 15:08:40 2005
+++ loncom/interface/lonmeta.pm Mon Dec 19 16:13:45 2005
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Metadata display handler
#
-# $Id: lonmeta.pm,v 1.142 2005/12/19 20:08:40 albertel Exp $
+# $Id: lonmeta.pm,v 1.143 2005/12/19 21:13:45 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1142,7 +1142,7 @@
} else {
$r->print("This resource is not associated with a course.<br />");
}
- foreach my $field_name(@fields) {
+ foreach my $field_name (@fields) {
if (defined($env{'form.new_'.$field_name})) {
$Apache::lonpublisher::metadatafields{$field_name}=
@@ -1152,12 +1152,12 @@
# handle restrictions here
if (($env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.'.$field_name.'.options'} =~ m/active/) ||
($field_name eq 'courserestricted')){
- $output.=('<p>'.$lt{$field_name}.': '.
+ $output.=("\n".'<p>'.$lt{$field_name}.': '.
&prettyinput($field_name,
$Apache::lonpublisher::metadatafields{$field_name},
'new_'.$field_name,'defaultmeta',
undef,undef,undef,undef,
- $Apache::lonpublisher::metadatafields{'courserestricted'}).'</p>');
+ $Apache::lonpublisher::metadatafields{'courserestricted'}).'</p>'."\n");
}
} else {
@@ -1168,75 +1168,74 @@
}
}
-
- $r->print($output.'<br /><input type="submit" name="store" value="'.
- &mt('Store Catalog Information').'">');
-
- }
- $r->print('</form>');
-
- if ($env{'form.store'}) {
- my $mfh;
- my $formname='store';
- my $file_content;
- foreach my $meta_field (keys %env) {
+ 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 (sort keys %Apache::lonpublisher::metadatafields) {
- next if ($_ =~ /\./);
- my $unikey=$_;
- $unikey=~/^([A-Za-z]+)/;
- my $tag=$1;
- $tag=~tr/A-Z/a-z/;
- $file_content.= "\n\<$tag";
- foreach (split(/\,/,
- $Apache::lonpublisher::metadatakeys{$unikey})
- ) {
- my $value=
- $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
- $value=~s/\"/\'\'/g;
- $file_content.=' '.$_.'="'.$value.'"' ;
- # print $mfh ' '.$_.'="'.$value.'"';
- }
- $file_content.= '>'.
- &HTML::Entities::encode
- ($Apache::lonpublisher::metadatafields{$unikey},
- '<>&"').
- '</'.$tag.'>';
- }
- if ($fn =~ /\/portfolio\//) {
- $fn =~ /\/portfolio\/(.*)$/;
- my $new_fn = '/'.$1;
- $env{'form.'.$formname}=$file_content."\n";
- $env{'form.'.$formname.'.filename'}=$new_fn;
- &Apache::lonnet::userfileupload('uploaddoc','',
- 'portfolio'.$env{'form.currentpath'});
- if (&Apache::lonnet::userfileupload($formname,'','portfolio') eq 'error: no uploaded file') {
- $r->print('<p><font color="red">'.
- &mt('Could not write metadata').', '.
- &mt('FAIL').'</font></p>');
- } else {
- $r->print('<p><font color="blue">'.&mt('Wrote Metadata').
- ' '.&Apache::lonlocal::locallocaltime(time).
- '</font></p>');
+
+ foreach (sort keys %Apache::lonpublisher::metadatafields) {
+ next if ($_ =~ /\./);
+ my $unikey=$_;
+ $unikey=~/^([A-Za-z]+)/;
+ my $tag=$1;
+ $tag=~tr/A-Z/a-z/;
+ $file_content.= "\n\<$tag";
+ foreach (split(/\,/,
+ $Apache::lonpublisher::metadatakeys{$unikey})
+ ) {
+ my $value=
+ $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
+ $value=~s/\"/\'\'/g;
+ $file_content.=' '.$_.'="'.$value.'"' ;
+ # print $mfh ' '.$_.'="'.$value.'"';
+ }
+ $file_content.= '>'.
+ &HTML::Entities::encode
+ ($Apache::lonpublisher::metadatafields{$unikey},
+ '<>&"').
+ '</'.$tag.'>';
}
- } else {
- if (! ($mfh=Apache::File->new('>'.$fn))) {
- $r->print('<p><font color="red">'.
- &mt('Could not write metadata').', '.
- &mt('FAIL').'</font></p>');
+ &Apache::lonnet::logthis(" file ".$file_content);
+ if ($fn =~ m|/portfolio/|) {
+ my ($path, $new_fn) = ($fn =~ m|/(portfolio.*)/([^/]*)$|);
+ $env{'form.'.$formname}=$file_content."\n";
+ $env{'form.'.$formname.'.filename'}=$new_fn;
+ my $result =&Apache::lonnet::userfileupload($formname,'',
+ $path);
+
+ if ($result =~ /(error|notfound)/) {
+ $r->print('<p><font color="red">'.
+ &mt('Could not write metadata').', '.
+ &mt('FAIL').'</font></p>');
+ } else {
+ $r->print('<p><font color="blue">'.&mt('Wrote Metadata').
+ ' '.&Apache::lonlocal::locallocaltime(time).
+ '</font></p>');
+ }
} else {
- print $mfh $file_content;
- $r->print('<p><font color="blue">'.&mt('Wrote Metadata').
- ' '.&Apache::lonlocal::locallocaltime(time).
- '</font></p>');
+ 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;
+ $r->print('<p><font color="blue">'.&mt('Wrote Metadata').
+ ' '.&Apache::lonlocal::locallocaltime(time).
+ '</font></p>');
+ }
}
}
+
+ $r->print($output.'<br /><input type="submit" name="store" value="'.
+ &mt('Store Catalog Information').'">');
+
}
-
+ $r->print('</form>');
+
return;
}