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

banghart lon-capa-cvs@mail.lon-capa.org
Sat, 07 Oct 2006 20:02:18 -0000


banghart		Sat Oct  7 16:02:18 2006 EDT

  Modified files:              
    /loncom/interface	lonparmset.pm 
  Log:
  	Allow retrieval of deleted metadata fields.
  
  
Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.338 loncom/interface/lonparmset.pm:1.339
--- loncom/interface/lonparmset.pm:1.338	Thu Sep 28 19:58:53 2006
+++ loncom/interface/lonparmset.pm	Sat Oct  7 16:02:16 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set parameters for assessments
 #
-# $Id: lonparmset.pm,v 1.338 2006/09/28 23:58:53 banghart Exp $
+# $Id: lonparmset.pm,v 1.339 2006/10/07 20:02:16 banghart Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3221,7 +3221,21 @@
     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Add Metadata Field'));
     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
-    if (exists($env{'form.fieldname'})) {
+    if (exists($env{'form.undelete'})) {
+        my @meta_fields = &Apache::loncommon::get_env_multiple('form.undelete');
+        foreach my $meta_field(@meta_fields) {
+            my $options = $env{'course.'.$env{'request.course.id'}.'.metadata.'.$meta_field.'.options'};
+            $options =~ s/deleted//;
+            $options =~ s/,,/,/;
+            my $put_result = &Apache::lonnet::put('environment',
+                                        {'metadata.'.$meta_field.'.options'=>$options},$dom,$crs);
+                                        
+            $r->print('Undeleted Metadata Field <strong>'.$env{'course.'.$env{'request.course.id'}.'.metadata.'.$meta_field.'.added'}."</strong> with result ".$put_result.'<br />');
+        }
+        $r->print('<form action="" method="post">');
+        $r->print('<input type="hidden" name="action" value="setrestrictmeta" />');
+        $r->print('<input type="submit" value="Continue" />');
+    } elsif (exists($env{'form.fieldname'})) {
         my $meta_field = $env{'form.fieldname'};
         my $display_field = $env{'form.fieldname'};
         $meta_field =~ s/\W/_/g;
@@ -3232,7 +3246,17 @@
                              'metadata.'.$meta_field.'.options'=>""},$dom,$crs);
         $r->print('Added new Metadata Field '.$env{'form.fieldname'}." with result ".$put_result);
     } else {
-        $r->print('<form method="post" action="/adm/parmset?action=addmetadata"');
+        my $fields = &get_deleted_meta_fieldnames();
+        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="">');
+            foreach my $key(keys(%$fields)) {
+                $r->print('<input type="checkbox" name="undelete" value="'.$key.'" />'.$$fields{$key}.'<br /');
+            }
+            $r->print('<input type="submit" name="undelete" value="Undelete" />');
+            $r->print('</form>');
+        }
+        $r->print('<hr /><strong>Or</strong> you may enter a new metadata field name.<form method="post" action="/adm/parmset?action=addmetadata"');
         $r->print('<input type="text" name="fieldname" /><br />');
         $r->print('<input type="submit" value="Add Metadata Field" />');
         $r->print('</form>');
@@ -3321,6 +3345,20 @@
     }
     return \%fields;
 }
+sub get_deleted_meta_fieldnames {
+    my %fields;
+    my ($default_fields) = @_;
+    foreach my $key(%env) {
+        if ($key =~ m/\.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};
+                $fields{$field_name} = $display_field_name;
+            }
+        }
+    }
+    return \%fields;
+}
 sub defaultsetter {
     my ($r) = @_;