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

banghart lon-capa-cvs@mail.lon-capa.org
Wed, 28 Sep 2005 23:19:27 -0000


This is a MIME encoded message

--banghart1127949567
Content-Type: text/plain

banghart		Wed Sep 28 19:19:27 2005 EDT

  Modified files:              
    /loncom/interface	lonparmset.pm 
  Log:
  	Quick! Commit while it seems to work! Instructor side of 
  	setting most of the switches on metadata (still need ACTIVE
  	switch), as well as defining the three defaults.
  
  
--banghart1127949567
Content-Type: text/plain
Content-Disposition: attachment; filename="banghart-20050928191927.txt"

Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.252 loncom/interface/lonparmset.pm:1.253
--- loncom/interface/lonparmset.pm:1.252	Wed Sep 28 09:29:17 2005
+++ loncom/interface/lonparmset.pm	Wed Sep 28 19:19:25 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set parameters for assessments
 #
-# $Id: lonparmset.pm,v 1.252 2005/09/28 13:29:17 banghart Exp $
+# $Id: lonparmset.pm,v 1.253 2005/09/28 23:19:25 banghart Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2751,33 +2751,34 @@
 }
 ### Set instructor defined metadata
 sub output_row {
-    my ($field_name) = @_;
+    my ($r, $field_name) = @_;
     my $output;
-    my $meta_hash_ref=$env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name};
-    my $values=$$meta_hash_ref{'values'};
+    my $active=$env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.active'};
+    my $onlyone=$env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.onlyone'};
+    my $stuadd=$env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.stuadd'};
+    my $values=$env{'course.'.$env{'request.course.id'}.'.metadata.'.$field_name.'.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';
+    unless (defined($active)) {
+        $active = 'no';
+        $stuadd = 'yes';
+        $values = 'Type a list of values separated by commas.';
+        $onlyone = 'no';
     }
     $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') {
+    $output.='<td><input name="'.$field_name.'_values" type="text" value="'.$values.'" /></td>';
+    if ($onlyone eq 'no') {
         $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') {
+    $output.='<td><center><input type="checkbox" name="'.$field_name.'_onlyone"" value="yes"'.$checked.' /></center></td>';
+    if ($stuadd eq 'yes') {
         $checked = ' CHECKED ';
     } else {
         $checked = ' ';
     }
-    $output.='<td><input type="checkbox" name="'.$field_name.'_stuadd" value="one"'.$checked.' /></td>';
+    $output.='<td><input type="checkbox" name="'.$field_name.'_stuadd" value="yes"'.$checked.' /></td>';
     $output.='</tr>';
-    
     return ($output);
 }
 sub setinstmeta {
@@ -2797,46 +2798,48 @@
     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;
+    my $stuadd;
+    my $onlyone;
+    my $active;
     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);
-                    }
+                if ($save_field ne $meta_field) {
                     $save_field = $meta_field;
-                    %meta_hash = {$meta_key=>[$env{$field}]};
+            	    if ($env{'form.'.$meta_field.'_stuadd'}) {
+            	        $stuadd='yes';
+            	    } else {
+            	        $stuadd='no';
+            	    }
+            	    if ($env{'form.'.$meta_field.'_onlyone'}) {
+            	        $onlyone='no';
+            	    } else {
+            	        $onlyone='yes';
+            	    }
+            	    $active='yes';			
+                    my $name = 'metadata.'.$save_field;
+                     $put_result = &Apache::lonnet::put('environment',
+                                                  {'metadata.'.$meta_field.'.stuadd'=>$stuadd,
+                                                    'metadata.'.$meta_field.'.onlyone'=>$onlyone,
+                                                    'metadata.'.$meta_field.'.active'=>$active,
+                                                   'metadata.'.$meta_field.'.values'=>$env{'form.'.$meta_field.'_values'},
+                                                   },$dom,$crs);
                 }
             }
-            
-              
         }
-        %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+)/) {
 	    	my $name;
     		my $value;
-            $put_result = &Apache::lonnet::put('environment',
-                                                  {$name=>$value},$dom,$crs);
-            $put_result = &Apache::lonnet::put('environment',
-                                                  {$name=>$value},$dom,$crs);
+            # $put_result = &Apache::lonnet::put('environment',
+            #                                      {$name=>$value},$dom,$crs);
+            # $put_result = &Apache::lonnet::put('environment',
+            #                                      {$name=>$value},$dom,$crs);
         }
         if ($field=~m/newfield/) {
             my $name = 'metadata.'.$env{'form.titlenew'};
@@ -2845,33 +2848,14 @@
             				allow_type=>'no'};
             				
             my $value = \%meta_hash;
-            $put_result = &Apache::lonnet::put('environment',
-                                                  {$name=>$value},$dom,$crs);
+            # $put_result = &Apache::lonnet::put('environment',
+            #                                      {$name=>$value},$dom,$crs);
         }
     } 
     &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>';
+    $output.= &output_row($r, "Title");
+    $output.= &output_row($r, "Subject");
+    $output.= &output_row($r, "Keywords");     
     $r->print(<<ENDenv);       
         <form method="post" action="/adm/parmset?action=setinstmeta" name="form">
         

--banghart1127949567--