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

banghart lon-capa-cvs@mail.lon-capa.org
Thu, 15 Dec 2005 22:18:58 -0000


banghart		Thu Dec 15 17:18:58 2005 EDT

  Modified files:              
    /loncom/interface	lonmeta.pm 
  Log:
  	Restricted changes now appear properly.
  
  
Index: loncom/interface/lonmeta.pm
diff -u loncom/interface/lonmeta.pm:1.138 loncom/interface/lonmeta.pm:1.139
--- loncom/interface/lonmeta.pm:1.138	Tue Dec 13 19:12:13 2005
+++ loncom/interface/lonmeta.pm	Thu Dec 15 17:18:57 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Metadata display handler
 #
-# $Id: lonmeta.pm,v 1.138 2005/12/14 00:12:13 banghart Exp $
+# $Id: lonmeta.pm,v 1.139 2005/12/15 22:18:57 banghart Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1046,67 +1046,6 @@
 	}
 	$r->print('<br />'.$bombs);
     } else {
-        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},
-                     '<>&"').
-                     '</'.$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>');
-                }
-            } 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;
-		    $r->print('<p><font color="blue">'.&mt('Wrote Metadata').
-			      ' '.&Apache::lonlocal::locallocaltime(time).
-			      '</font></p>');
-                }
-            }
-        }        
         my $displayfile='Catalog Information for '.$disuri;
         if ($disuri=~/\/default$/) {
             my $dir=$disuri;
@@ -1143,10 +1082,14 @@
                  'lowestgradelevel','highestgradelevel','sourceavail','sourcerights',
                  'obsolete','obsoletereplacement');
         }
-        if (! $Apache::lonpublisher::metadatafields{'courserestricted'}) {
+        if ((! $Apache::lonpublisher::metadatafields{'courserestricted'}) &&
+                (! $env{'form.new_courserestricted'})) {
             $Apache::lonpublisher::metadatafields{'courserestricted'}=
                 'none';
-        } 
+        } elsif ($env{'form.new_courserestricted'}) {
+            $Apache::lonpublisher::metadatafields{'courserestricted'}=
+                $env{'form.new_courserestricted'}; 
+        }           
         if (! $Apache::lonpublisher::metadatafields{'copyright'}) {
                 $Apache::lonpublisher::metadatafields{'copyright'}=
                 'default';
@@ -1189,6 +1132,67 @@
         
     }
     $r->print('</form>');
+            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},
+                     '<>&"').
+                     '</'.$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>');
+                }
+            } 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;
+		    $r->print('<p><font color="blue">'.&mt('Wrote Metadata').
+			      ' '.&Apache::lonlocal::locallocaltime(time).
+			      '</font></p>');
+                }
+            }
+        }
     return;
 }