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

banghart lon-capa-cvs@mail.lon-capa.org
Wed, 28 Sep 2005 13:29:18 -0000


banghart		Wed Sep 28 09:29:18 2005 EDT

  Modified files:              
    /loncom/interface	lonparmset.pm 
  Log:
  	Identifying default instructor metadata fields, displaying
  	update screen. Doesn't work. Saving work in progress.
  
  
Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.251 loncom/interface/lonparmset.pm:1.252
--- loncom/interface/lonparmset.pm:1.251	Fri Sep 23 16:16:50 2005
+++ loncom/interface/lonparmset.pm	Wed Sep 28 09:29:17 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set parameters for assessments
 #
-# $Id: lonparmset.pm,v 1.251 2005/09/23 20:16:50 albertel Exp $
+# $Id: lonparmset.pm,v 1.252 2005/09/28 13:29:17 banghart Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2750,6 +2750,36 @@
     return;
 }
 ### Set instructor defined metadata
+sub output_row {
+    my ($field_name) = @_;
+    my $output;
+    my $meta_hash_ref=$env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name};
+    my $values=$$meta_hash_ref{'values'};
+    my $checked;
+    unless (defined($$meta_hash_ref{'active'})) {
+        $$meta_hash_ref{'active'} = 'no';
+        $$meta_hash_ref{'stu_add_values'} = 'yes';
+        $$meta_hash_ref{'values'} = 'Type a list of values separated by commas.';
+        $$meta_hash_ref{'stu_pick_many'} = 'yes';
+    }
+    $output.='<tr><td><strong>'.$field_name.'</strong></td>';
+    $output.='<td><input name="'.$field_name.'_values" type="text" value="'.$$meta_hash_ref{'values'}.'" /></td>';
+    if ($$meta_hash_ref{'stu_add_values'}eq'yes') {
+        $checked = ' CHECKED ';
+    } else {
+        $checked = ' ';
+    }
+    $output.='<td><center><input type="checkbox" name="'.$field_name.'_onlyone"" value="one"'.$checked.' /></center></td>';
+    if ($$meta_hash_ref{'stu_pick_many'}eq'yes') {
+        $checked = ' CHECKED ';
+    } else {
+        $checked = ' ';
+    }
+    $output.='<td><input type="checkbox" name="'.$field_name.'_stuadd" value="one"'.$checked.' /></td>';
+    $output.='</tr>';
+    
+    return ($output);
+}
 sub setinstmeta {
     my ($r)=@_;
     my $next_meta;
@@ -2766,6 +2796,38 @@
     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.'};
+    my $save_field = '';
+    my %meta_hash;
+    if ($env{'form.instmeta'}) {
+        foreach my $field (sort %env) {
+            if ($field=~m/^form.(.+)_(.+)$/) {
+                my $meta_field = $1;
+                my $meta_key = $2;
+                if ($save_field eq $meta_field) {
+                    %meta_hash = {$meta_key=>[$env{$field}]};
+            	} else {
+            	    if ($save_field ne '') {
+            	        %meta_hash = {active=>'yes'};			
+                        my $value = \%meta_hash;
+                        my $name = $save_field;
+                        $r->print('Saving '.$name.' meta<br />');
+                        $put_result = &Apache::lonnet::put('environment',
+                                                  {$name=>$value},$dom,$crs);
+                    }
+                    $save_field = $meta_field;
+                    %meta_hash = {$meta_key=>[$env{$field}]};
+                }
+            }
+            
+              
+        }
+        %meta_hash = {active=>'yes'};
+        my $value = \%meta_hash;
+        my $name = $save_field;
+        $r->print('Saving '.$name.' meta<br />');
+        $put_result = &Apache::lonnet::put('environment',
+                                     {$name=>$value},$dom,$crs);
+    }
     foreach my $field (%env) {
         # start by looking for populated fields
         if ($field=~m/type(\d+)/) {
@@ -2787,30 +2849,35 @@
                                                   {$name=>$value},$dom,$crs);
         }
     } 
-    &Apache::lonnet::coursedescription($env{'request.course.id'});      
-    foreach my $key (sort keys %env) {
-        if ($key=~m/^course\.$env{'request.course.id'}\.metadata\.(.+)$/) {
-            my $meta_data_item = $1;
-            my $meta_hash=$env{$key};
-            $output.='<tr><td>'.$meta_data_item.'</td>';
-            $output.='<td>Select one: <input type="checkbox" name="" value="one" /><br />';
-            $output.='Select many: <input type="checkbox" name="type" value="many" /></td>';
-            $output.='<td><input name="values" type="text" value="$env{$key_base.$item_num.'.'" /></td></tr>';
-        }
-    }
-    $output.='<tr><td><i>Create new instructor metadata item</i><br />';
-    $output.='<input type="text" name="titlenew" /></td>';
-    $output.='<td>students must pick only one: <input type="checkbox" name="pickonenew" value="one" /><br />';
-    $output.='Allow student to type extra info: <input type="checkbox" name="typeextranew" value="extra" /></td>';
-    $output.='<td><input name="valuesnew" type="text" value="" /></td></tr>';
-    $output.='<input type="hidden" name="serial" value="'.$next_meta.'" />';
-    $output.='<input type="hidden" name="state" value="save" /></tr>';
+    &Apache::lonnet::coursedescription($env{'request.course.id'});
+    $output.= &output_row("Title");
+    $output.= &output_row("Subject");
+    $output.= &output_row("Keywords");     
+#    foreach my $key (sort keys %env) {
+#        if ($key=~m/^course\.$env{'request.course.id'}\.metadata\.(.+)$/) {
+#            my $meta_data_item = $1;
+#            my $meta_hash=$env{$key};
+#            # keys are 'values', stu_pick_many, stu_add_values, active
+#            
+#            $output.='<tr><td>'.$meta_data_item.'</td>';
+#            $output.='<td>Select one: <input type="checkbox" name="" value="one" /><br />';
+#            $output.='Select many: <input type="checkbox" name="type" value="many" /></td>';
+#            $output.='<td><input name="values" type="text" value="$env{$key_base.$item_num.'.'" /></td></tr>';
+#        }
+#    }
+#    $output.='<tr><td><i>Create new instructor metadata item</i><br />';
+#    $output.='<input type="text" name="titlenew" /></td>';
+#    $output.='<td>students must pick only one: <input type="checkbox" name="pickonenew" value="one" /><br />';
+#    $output.='Allow student to type extra info: <input type="checkbox" name="typeextranew" value="extra" /></td>';
+#    $output.='<td><input name="valuesnew" type="text" value="" /></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">
         
         <p>
         <table border=2>
-        <tr><th>Title</th><th>Options</th><th>Choices</th></tr>
+        <tr><th>Metadata Item</th><th>Values</th><th>Only One Choice</th><th>Student Can Add Choices</th></tr>
         $output
         </table>
         <input type="submit" name="instmeta" value="Update Instructor Metadata">