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

banghart lon-capa-cvs@mail.lon-capa.org
Mon, 11 Sep 2006 22:48:47 -0000


banghart		Mon Sep 11 18:48:47 2006 EDT

  Modified files:              
    /loncom/interface	lonmeta.pm 
  Log:
  	Saving work in progress. Working toward student side of added
  	metadata fields. Not there yet.
  
  
Index: loncom/interface/lonmeta.pm
diff -u loncom/interface/lonmeta.pm:1.173 loncom/interface/lonmeta.pm:1.174
--- loncom/interface/lonmeta.pm:1.173	Fri Aug 25 19:05:52 2006
+++ loncom/interface/lonmeta.pm	Mon Sep 11 18:48:47 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Metadata display handler
 #
-# $Id: lonmeta.pm,v 1.173 2006/08/25 23:05:52 banghart Exp $
+# $Id: lonmeta.pm,v 1.174 2006/09/11 22:48:47 banghart Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -237,12 +237,6 @@
     
     if (! defined($file_type) || $file_type ne 'portfolio') {
         %fields = 
-	    (%fields,
-	     'courserestricted' => 'Course Restricting Metadata');
-    }
-         
-    if (! defined($file_type) || $file_type ne 'portfolio') {
-        %fields = 
         (%fields,
          'domain' => 'Domain',
          'mime' => 'MIME Type',
@@ -607,9 +601,11 @@
             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')) {
+             || ($type eq  'abstract')|| ($type eq  'title')|| ($type eq  'standards')
+             || (exists($env{'course.'.$env{'request.course.id'}.'metadata.'.$type.'.added'}))) {
             if ($values) {
                 if ($only_one) {
                     $output .= (&Apache::loncommon::select_form($cur_values_inst[0],'new_'.$type,%meta_options));
@@ -1189,10 +1185,19 @@
         my %lt=&fieldnames($file_type);
 	my $output;
 	my @fields;
+	my $added_metadata_fields;
 	if ($file_type eq 'portfolio') {
-	    @fields =  ('author','title','subject','keywords','abstract',
-			'notes','lowestgradelevel',
-	                'highestgradelevel','standards');
+	    if(exists ($env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.fieldlist'})) {
+	        # retrieve fieldnames (in order) from the course restricted list
+	        @fields = (split /,/,$env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.fieldlist'});
+	    } else {
+	        # no saved field list, use default list
+	        @fields =  ('author','title','subject','keywords','abstract',
+			    'notes','lowestgradelevel',
+	                    'highestgradelevel','standards');
+	        $added_metadata_fields = &Apache::lonparmset::get_added_meta_fieldnames();
+	        $env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.fieldlist'} = join (",",@fields);
+	    }
 	} else {
 	    @fields = ('author','title','subject','keywords','abstract','notes',
                  'copyright','customdistributionfile','language',
@@ -1234,7 +1239,6 @@
 	    }
 	}
         foreach my $field_name (@fields) {
-
             if (defined($env{'form.new_'.$field_name})) {
                 $Apache::lonpublisher::metadatafields{$field_name}=
                     join(',',&Apache::loncommon::get_env_multiple('form.new_'.$field_name));
@@ -1260,6 +1264,12 @@
                
             }
         }
+        foreach my $field_name (keys(%$added_metadata_fields)) {
+            my $course = $env{'request.course.id'};
+            $output.=('<p>'.$$added_metadata_fields{$field_name}.': '.
+                    &prettyinput($field_name,$env{'course.'.$env{'request.course.id'}.'metadata.'.$field_name.'.value'},
+                    'new_'.$field_name,'addedmeta').'</p>')
+        }
 	if ($env{'form.store'}) {
 	    my $mfh;
 	    my $formname='store'; 
@@ -1269,21 +1279,21 @@
 		    join (',', &Apache::loncommon::get_env_multiple('form.new_keywords'));
 	    }
 
-	    foreach (sort keys %Apache::lonpublisher::metadatafields) {
-		next if ($_ =~ /\./);
-		my $unikey=$_;
+	    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 (split(/\,/,
+		foreach my $key (split(/\,/,
 			       $Apache::lonpublisher::metadatakeys{$unikey})
 			 ) {
 		    my $value=
-			$Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
+			$Apache::lonpublisher::metadatafields{$unikey.'.'.$key};
 		    $value=~s/\"/\'\'/g;
-		    $file_content.=' '.$_.'="'.$value.'"' ;
-		    # print $mfh ' '.$_.'="'.$value.'"';
+		    $file_content.=' '.$key.'="'.$value.'"' ;
+		    # print $mfh ' '.$key.'="'.$value.'"';
 		}
 		$file_content.= '>'.
 		    &HTML::Entities::encode