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

banghart lon-capa-cvs@mail.lon-capa.org
Tue, 30 Aug 2005 01:25:56 -0000


banghart		Mon Aug 29 21:25:56 2005 EDT

  Modified files:              
    /loncom/interface	lonparmset.pm 
  Log:
  	More progress on instructor entry, and the beginnings of saving
  	the user input for instructor defined metadata. Doesn't work yet.
  
  
Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.245 loncom/interface/lonparmset.pm:1.246
--- loncom/interface/lonparmset.pm:1.245	Mon Aug 29 20:40:12 2005
+++ loncom/interface/lonparmset.pm	Mon Aug 29 21:25:53 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set parameters for assessments
 #
-# $Id: lonparmset.pm,v 1.245 2005/08/30 00:40:12 banghart Exp $
+# $Id: lonparmset.pm,v 1.246 2005/08/30 01:25:53 banghart Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2730,6 +2730,7 @@
     my $next_meta;
     my $output;
     my $item_num;
+    my $put_result;
     if ($env{'form.serial'}) {
         $next_meta = $env{'form.serial'};
     } else {
@@ -2745,60 +2746,60 @@
     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
     my $key_base = $env{'course.'.$env{'request.course.id'}.'.metadata.'};
-    if ($env{'form.state'}eq 'add') {
-        $r->print('<strong>Compose a new metadata item:</strong><br />');
-        $r->print('<form method="post" action="/adm/parmset">');
-        $r->print ('Title of item: '.&Apache::lonhtmlcommon::textbox("title",undef,undef,undef).'<br />');
-        $r->print ('List if items (comma separated): '.&Apache::lonhtmlcommon::textbox("values",undef,undef,undef).'<br />');
-        $r->print ('Select one: <input type="radio" name="type" value="one"><br />');
-        $r->print ('Select many: <input type="radio" name="type" value="many"><br />');
-        $r->print('<input type="hidden" name="serial" value="'.$next_meta.'" />');
-        $r->print('<input type="hidden" name="action" value="setinstmeta" />');
-        $r->print('<input type="hidden" name="state" value="save" />');
-        $r->print('<input type="submit" value="Save Metadata">');
-        $r->print('</form>');
-    } elsif ($env{'form.state'}eq 'save') {
-        $r->print('Here we save the metadata');
-        $key_base.=$env{'form.serial'}.'.';
-        $r->print('The title: '.$env{'form.title'}.'<br>');
-        $r->print('The values: '.$env{'form.values'}.'<br>');
-        $r->print('The type: '.$env{'form.type'}.'<br>');
-        $r->print('The number: '.$env{'form.serial'}.'<br>');
-        my $name = 'metadata.'.$env{'form.serial'}.'.title';
-        my $value = $env{'form.title'};
-        my $put_result = &Apache::lonnet::put('environment',
+    foreach my $field (%env) {
+        # start by looking for populated fields
+        if ($field=~m/type(\d+)/) {
+            my $item_num = $1;
+            my $name = 'metadata.'.$item_num.'.type';
+            my $value = $env{'form.type'.$item_num};
+            $put_result = &Apache::lonnet::put('environment',
                                                   {$name=>$value},$dom,$crs);
-        $r->print('the put result was: '.$put_result.'<br />');
-        $name = 'metadata.'.$env{'form.serial'}.'.type';
-        $value = $env{'form.type'};
-        $put_result = &Apache::lonnet::put('environment',
+            $name = 'metadata.'.$item_num.'.values';
+            $value = $env{'form.values'.$item_num};
+            $put_result = &Apache::lonnet::put('environment',
                                                   {$name=>$value},$dom,$crs);
-        $name = 'metadata.'.$env{'form.serial'}.'.values';
-        $value = $env{'form.values'};
-        $put_result = &Apache::lonnet::put('environment',
+        }
+        if ($field=~m/newfield/) {
+            my $item_num = $env{'form.serial'};
+            my $name = 'metadata.'.$item_num.'.type';
+            my $value = $env{'form.typenew'};
+            $put_result = &Apache::lonnet::put('environment',
                                                   {$name=>$value},$dom,$crs);
-        &Apache::lonnet::coursedescription($env{'request.course.id'});        
-    } else {
+            $name = 'metadata.'.$item_num.'.values';
+            $value = $env{'form.valuesnew'};
+            $put_result = &Apache::lonnet::put('environment',
+                                                  {$name=>$value},$dom,$crs);
+            $name = 'metadata.'.$item_num.'.title';
+            $value = $env{'form.titlenew'};
+            $put_result = &Apache::lonnet::put('environment',
+                                                  {$name=>$value},$dom,$crs);
+            
+        }
         
-        foreach my $key (sort keys %env) {
-            if ($key=~m/^course\.$env{'request.course.id'}\.metadata\.\d+\.title$/) {
-                $key=~m/^course\.$env{'request.course.id'}\.metadata\.(\d+)\.title/;
-                $item_num = $1;
-                if ($1 ge $next_meta) {
-                    $next_meta = $1 + 1;
-                }
-                $output.='<tr><td>'.$env{$key}.'</td>';
-                $output.='<td>Select one: <input type="radio" name="type'.$item_num.'" value="one" /><br />';
-                $output.='Select many: <input type="radio" name="type'.$item_num.'" value="many" /></td>';
-                $output.='<td><input name="values'.$item_num.'" type="text" value="'.$env{$key.'.values'}.'" /></td></tr>';
-            }
+              
+    } 
+    &Apache::lonnet::coursedescription($env{'request.course.id'});      
+    foreach my $key (sort keys %env) {
+        if ($key=~m/^course\.$env{'request.course.id'}\.metadata\.\d+\.title$/) {
+            $key=~m/(^course\.$env{'request.course.id'}\.metadata\.)(\d+)\.title/;
+            $key_base = $1;
+            $item_num = $2;
+            if ($item_num ge $next_meta) {
+                $next_meta = $item_num + 1;
+            }
+            $output.='<tr><td>'.$env{$key}.'</td>';
+            $output.='<td>Select one: <input type="radio" name="type'.$item_num.'" value="one" /><br />';
+            $output.='Select many: <input type="radio" name="type'.$item_num.'" value="many" /></td>';
+            $output.='<td><input name="values'.$item_num.'" type="text" value="'.$env{$key_base.$item_num.'.values'}.'" /></td></tr>';
         }
+    }
     $output.='<tr><td><i>Create new instructor metadata item</i><br />';
-    $output.='<input type="text" name="newitem" /></td>';
+    $output.='<input type="text" name="titlenew" /></td>';
     $output.='<td>Select one: <input type="radio" name="typenew" value="one" /><br />';
     $output.='Select many: <input type="radio" name="typenew" value="many" /></td>';
     $output.='<td><input name="valuesnew" type="text" value="" /></td></tr>';
-    $output.='<td><input type="hidden" name="serial" value="'.$next_meta.'" /></td></tr>';
+    $output.='<input type="hidden" name="serial" value="'.$next_meta.'" />';
+    $output.='<input type="hidden" name="state" value="save" /></tr>';
     $r->print(<<ENDenv);       
         <form method="post" action="/adm/parmset?action=setinstmeta" name="form">
         
@@ -2812,7 +2813,7 @@
 
 ENDenv
         
-    }
+    
     $r->print('</body>
                 </html>');
     return 'ok';