[LON-CAPA-cvs] cvs: loncom /interface lonmeta.pm

banghart lon-capa-cvs@mail.lon-capa.org
Thu, 17 Mar 2005 21:32:17 -0000


banghart		Thu Mar 17 16:32:17 2005 EDT

  Modified files:              
    /loncom/interface	lonmeta.pm 
  Log:
  	Save portfolio meta data across network, keep other meta data
  	local.``
  
  
Index: loncom/interface/lonmeta.pm
diff -u loncom/interface/lonmeta.pm:1.93 loncom/interface/lonmeta.pm:1.94
--- loncom/interface/lonmeta.pm:1.93	Wed Mar 16 17:52:04 2005
+++ loncom/interface/lonmeta.pm	Thu Mar 17 16:32:17 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Metadata display handler
 #
-# $Id: lonmeta.pm,v 1.93 2005/03/16 22:52:04 matthew Exp $
+# $Id: lonmeta.pm,v 1.94 2005/03/17 21:32:17 banghart Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -919,7 +919,13 @@
         }
         %Apache::lonpublisher::metadatafields=();
         %Apache::lonpublisher::metadatakeys=();
-        &Apache::lonpublisher::metaeval(&Apache::lonnet::getfile($fn));
+        my $result=&Apache::lonnet::getfile($fn);
+        if ($result == -1){
+            $r->print('Unable to get '.$fn);
+            return ;
+        } else {
+            &Apache::lonpublisher::metaeval($result);
+        }
         $r->print(<<ENDEDIT);
 <h1>$displayfile</h1>
 <form method="post" name="defaultmeta">
@@ -956,35 +962,55 @@
         }
         if ($ENV{'form.store'}) {
             my $mfh;
-            if (!  ($mfh=Apache::File->new('>'.$fn))) {
-                $r->print('<p><font color="red">'.
-                          &mt('Could not write metadata').', '.
-                          &mt('FAIL').'</font></p>');
+            my $formname='store';
+            my $file_content;
+            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;
+                $ENV{'form.'.$formname.'.filename'}=$new_fn;
+                &Apache::lonnet::userfileupload('uploaddoc','',
+	        	 'portfolio'.$ENV{'form.currentpath'});
+	        my $status =&Apache::lonnet::userfileupload($formname,'','portfolio');
+                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>');
+                }
             } else {
-                foreach (sort keys %Apache::lonpublisher::metadatafields) {
-                    next if ($_ =~ /\./);
-                    my $unikey=$_;
-                    $unikey=~/^([A-Za-z]+)/;
-                    my $tag=$1;
-                    $tag=~tr/A-Z/a-z/;
-                    print $mfh "\n\<$tag";
-                    foreach (split(/\,/,
-                                 $Apache::lonpublisher::metadatakeys{$unikey})
-                             ) {
-                        my $value=
-                         $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
-                        $value=~s/\"/\'\'/g;
-                        print $mfh ' '.$_.'="'.$value.'"';
-                    }
-                    print $mfh '>'.
-                        &HTML::Entities::encode
-                        ($Apache::lonpublisher::metadatafields{$unikey},
-                         '<>&"').
-                         '</'.$tag.'>';
+                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="'.