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

raeburn lon-capa-cvs@mail.lon-capa.org
Fri, 12 Jan 2007 20:04:16 -0000


raeburn		Fri Jan 12 15:04:16 2007 EDT

  Modified files:              
    /loncom/interface	lonmeta.pm lonparmset.pm 
  Log:
  Only display added metadata fields for in the metadata editing screen for portfolio files if the resource is associated with a course.
  
  Restrict added fields shown n the editing screen to those set for the specific course with which the resource is associated.
  
  
Index: loncom/interface/lonmeta.pm
diff -u loncom/interface/lonmeta.pm:1.194 loncom/interface/lonmeta.pm:1.195
--- loncom/interface/lonmeta.pm:1.194	Fri Jan 12 14:56:07 2007
+++ loncom/interface/lonmeta.pm	Fri Jan 12 15:04:16 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Metadata display handler
 #
-# $Id: lonmeta.pm,v 1.194 2007/01/12 19:56:07 raeburn Exp $
+# $Id: lonmeta.pm,v 1.195 2007/01/12 20:04:16 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1203,6 +1203,18 @@
 	my @fields;
 	my $added_metadata_fields;
 	my @added_order;
+        if ($file_type eq 'groups') {
+            $Apache::lonpublisher::metadatafields{'courserestricted'}=
+                'course.'.$env{'request.course.id'};
+        }
+        if ((! $Apache::lonpublisher::metadatafields{'courserestricted'}) &&
+                (! $env{'form.new_courserestricted'}) && (! $file_type eq 'groups')) {
+            $Apache::lonpublisher::metadatafields{'courserestricted'}=
+                'none';
+        } elsif ($env{'form.new_courserestricted'}) {
+            $Apache::lonpublisher::metadatafields{'courserestricted'}=
+                $env{'form.new_courserestricted'};
+        }
 	if ($file_type eq 'portfolio' || $file_type eq 'groups') {
 	    if(exists ($env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.fieldlist'})) {
 	        # retrieve fieldnames (in order) from the course restricted list
@@ -1212,11 +1224,14 @@
 	        @fields =  ('author','title','subject','keywords','abstract',
 			    'notes','lowestgradelevel',
 	                    'highestgradelevel','standards');
-	        $added_metadata_fields = &Apache::lonparmset::get_added_meta_fieldnames();
-	        if ($env{'course.'.$env{'request.course.id'}.'.metadata.addedorder'}) {
-	            @added_order = split(/,/,$env{'course.'.$env{'request.course.id'}.'.metadata.addedorder'});
-	        }
-	        $env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.fieldlist'} = join(",",@fields);
+                if ($Apache::lonpublisher::metadatafields{'courserestricted'} =~ /^course\.($match_domain\_$match_courseid)$/) {
+                    my $assoc_crs = $1;
+	            $added_metadata_fields = &Apache::lonparmset::get_added_meta_fieldnames($assoc_crs);
+	            if ($env{'course.'.$assoc_crs.'.metadata.addedorder'}) {
+	                @added_order = split(/,/,$env{'course.'.$assoc_crs.'.metadata.addedorder'});
+	            }
+	            $env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.fieldlist'} = join(",",@fields);
+                }
 	    }
 	} else {
 	    @fields = ('author','title','subject','keywords','abstract','notes',
@@ -1225,18 +1240,6 @@
 		       'lowestgradelevel','highestgradelevel','sourceavail','sourcerights',
 		       'obsolete','obsoletereplacement');
         }
-        if ($file_type eq 'groups') {
-            $Apache::lonpublisher::metadatafields{'courserestricted'}=
-                'course.'.$env{'request.course.id'}; 
-        }
-        if ((! $Apache::lonpublisher::metadatafields{'courserestricted'}) &&
-                (! $env{'form.new_courserestricted'}) && (! $file_type eq 'groups')) {
-            $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';
Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.356 loncom/interface/lonparmset.pm:1.357
--- loncom/interface/lonparmset.pm:1.356	Thu Jan  4 14:34:13 2007
+++ loncom/interface/lonparmset.pm	Fri Jan 12 15:04:16 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set parameters for assessments
 #
-# $Id: lonparmset.pm,v 1.356 2007/01/04 19:34:13 albertel Exp $
+# $Id: lonparmset.pm,v 1.357 2007/01/12 20:04:16 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3288,7 +3288,7 @@
                            {'metadata.addedorder'=>$ordered_fields},$dom,$crs); 	
 	&Apache::lonnet::appenv('course.'.$env{'request.course.id'}.'.metadata.addedorder' => $ordered_fields);
     }
-    my $fields = &get_added_meta_fieldnames();
+    my $fields = &get_added_meta_fieldnames($env{'request.course.id'});
     my $ordered_fields;
     my @fields_in_order = split /,/,$env{'course.'.$env{'request.course.id'}.'.metadata.addedorder'};
     if (!@fields_in_order) {
@@ -3354,7 +3354,7 @@
                              'metadata.'.$meta_field.'.options'=>""},$dom,$crs);
         $r->print('Added new Metadata Field '.$env{'form.fieldname'}." with result ".$put_result);
     } else {
-        my $fields = &get_deleted_meta_fieldnames();
+        my $fields = &get_deleted_meta_fieldnames($env{'request.course.id'});
         if ($fields) {
             $r->print('You may undelete previously deleted fields.<br />Check those you wish to undelete and click Undelete.<br />');
             $r->print('<form method="post" action="">');
@@ -3419,7 +3419,7 @@
     # Get the default metadata fields
     my %metadata_fields = &Apache::lonmeta::fieldnames('portfolio');
     # Now get possible added metadata fields
-    my $added_metadata_fields = &get_added_meta_fieldnames(\%metadata_fields);
+    my $added_metadata_fields = &get_added_meta_fieldnames($env{'request.course.id'});
     my $row_alt = 1;
     $output .= &Apache::loncommon::start_data_table();
     foreach my $field (sort(keys(%metadata_fields))) {
@@ -3455,9 +3455,10 @@
 }
 ##################################################
 sub get_added_meta_fieldnames {
+    my ($cid) = @_;
     my %fields;
     foreach my $key(%env) {
-        if ($key =~ m/\.metadata\.(.+)\.added$/) {
+        if ($key =~ m/\Q$cid\E\.metadata\.(.+)\.added$/) {
             my $field_name = $1;
             my ($display_field_name) = $env{$key};
             $fields{$field_name} = $display_field_name;
@@ -3466,10 +3467,10 @@
     return \%fields;
 }
 sub get_deleted_meta_fieldnames {
+    my ($cid) = @_;
     my %fields;
-    my ($default_fields) = @_;
     foreach my $key(%env) {
-        if ($key =~ m/\.metadata\.(.+)\.added$/) {
+        if ($key =~ m/\Q$cid\E\.metadata\.(.+)\.added$/) {
             my $field_name = $1;
             if ($env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.options'} =~ m/deleted/) {
                 my ($display_field_name) = $env{$key};