--- loncom/interface/lonmeta.pm 2005/12/19 20:07:13 1.141 +++ loncom/interface/lonmeta.pm 2005/12/19 21:33:54 1.145 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Metadata display handler # -# $Id: lonmeta.pm,v 1.141 2005/12/19 20:07:13 albertel Exp $ +# $Id: lonmeta.pm,v 1.145 2005/12/19 21:33:54 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -292,7 +292,7 @@ sub fieldnames { sub portfolio_display_uri { my ($uri)=@_; - $uri =~ s|.*/portfolio(/.*)$|$1|; + $uri =~ s|.*/(portfolio/.*)$|$1|; my ($res_uri,$meta_uri) = ($uri,$uri); if ($uri =~ /\.meta$/) { @@ -300,14 +300,17 @@ sub portfolio_display_uri { } else { $meta_uri .= '.meta'; } - return ($res_uri,$meta_uri); + + my ($path) = ($res_uri =~ m|(.*)/[^/]*$|); + + return ($res_uri,$meta_uri,$path); } sub pre_select_course { my ($r,$uri) = @_; my $output; my $fn=&Apache::lonnet::filelocation('',$uri); - my ($res_uri,$meta_uri) = &portfolio_display_uri($uri); + my ($res_uri,$meta_uri,$path) = &portfolio_display_uri($uri); %Apache::lonpublisher::metadatafields=(); %Apache::lonpublisher::metadatakeys=(); my $result=&Apache::lonnet::getfile($fn); @@ -322,6 +325,12 @@ sub pre_select_course { $r->print($output.'
'); $r->print(''); + + $r->print('

'. + ''. + ''. + '
'); + return; } sub select_course { @@ -1142,7 +1151,7 @@ ENDEDIT } else { $r->print("This resource is not associated with a course.
"); } - foreach my $field_name(@fields) { + foreach my $field_name (@fields) { if (defined($env{'form.new_'.$field_name})) { $Apache::lonpublisher::metadatafields{$field_name}= @@ -1152,12 +1161,12 @@ ENDEDIT # handle restrictions here if (($env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.'.$field_name.'.options'} =~ m/active/) || ($field_name eq 'courserestricted')){ - $output.=('

'.$lt{$field_name}.': '. + $output.=("\n".'

'.$lt{$field_name}.': '. &prettyinput($field_name, $Apache::lonpublisher::metadatafields{$field_name}, 'new_'.$field_name,'defaultmeta', undef,undef,undef,undef, - $Apache::lonpublisher::metadatafields{'courserestricted'}).'

'); + $Apache::lonpublisher::metadatafields{'courserestricted'}).'

'."\n"); } } else { @@ -1168,73 +1177,74 @@ ENDEDIT } } - - $r->print($output.'
&"'). + ''; + } + &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('

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

'); + } else { + $r->print('

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

'); + } + } else { + if (! ($mfh=Apache::File->new('>'.$fn))) { + $r->print('

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

'); + } else { + print $mfh $file_content; + $r->print('

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

'); + } + } + } + + $r->print($output.'
'); } $r->print(''); - if ($env{'form.store'}) { - my $mfh; - my $formname='store'; - my $file_content; - foreach my $meta_field (keys %env) { - 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}, - '<>&"'). - ''; - } - 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('

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

'); - } else { - $r->print('

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

'); - } - } else { - if (! ($mfh=Apache::File->new('>'.$fn))) { - $r->print('

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

'); - } else { - print $mfh $file_content; - $r->print('

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

'); - } - } - } + return; }