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

www lon-capa-cvs@mail.lon-capa.org
Mon, 06 Jun 2005 15:13:47 -0000


www		Mon Jun  6 11:13:47 2005 EDT

  Modified files:              
    /loncom/interface	lonparmset.pm 
  Log:
  Set overview mode works, sort of.
  
  
Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.211 loncom/interface/lonparmset.pm:1.212
--- loncom/interface/lonparmset.pm:1.211	Sun Jun  5 22:25:09 2005
+++ loncom/interface/lonparmset.pm	Mon Jun  6 11:13:46 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set parameters for assessments
 #
-# $Id: lonparmset.pm,v 1.211 2005/06/06 02:25:09 www Exp $
+# $Id: lonparmset.pm,v 1.212 2005/06/06 15:13:46 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -927,43 +927,25 @@
 
 sub sectionmenu {
     my ($r,$selectedsections)=@_;
+    my %sectionhash=();
 
-    my ($classlist,$field_names) = 
-	&Apache::loncoursedata::get_classlist(
-		       $env{'request.course.id'},
-		       $env{'course.'.$env{'request.course.id'}.'.domain'},
-		       $env{'course.'.$env{'request.course.id'}.'.num'});
-    my %Sections=();
-    while (my ($student,$student_data) = each (%$classlist)) {
-	my $studenthash = ();
-        for (my $i=0; $i< scalar(@$field_names);$i++) {
-            my $field = $field_names->[$i];
-            # Store the data
-            $studenthash->{$field}=$student_data->[$i];
-        }
-	my $section = $studenthash->{'section'};
-        if (! defined($section) || $section =~/^\s*$/ || $section == -1) {
-            $studenthash->{'section'} = 'none';
-            $section = $studenthash->{'section'};
-        }
-        $Sections{$section}++;
-    }
-    my @Sections = sort {$a cmp $b} keys(%Sections);
-    unshift(@Sections,'all');
-
-    $r->print('<select name="Section" multiple="true" size="8" >');
-
-    foreach my $s (@Sections) {
-        $r->print('    <option value="'.$s.'"');
-        foreach (@{$selectedsections}) {
-            if ($s eq $_) {
-                $r->print(' selected');
-                last;
-            }
-        }
-        $r->print('>'.$s."</option>\n");
+    if (&Apache::loncommon::get_sections(
+                 $env{'course.'.$env{'request.course.id'}.'.domain'},
+                 $env{'course.'.$env{'request.course.id'}.'.num'},
+					 \%sectionhash)) {
+	$r->print('<select name="Section" multiple="true" size="8" >');
+	foreach my $s ('all',sort keys %sectionhash) {
+	    $r->print('    <option value="'.$s.'"');
+	    foreach (@{$selectedsections}) {
+		if ($s eq $_) {
+		    $r->print(' selected');
+		    last;
+		}
+	    }
+	    $r->print('>'.$s."</option>\n");
+	}
+	$r->print("</select>\n");
     }
-    $r->print("</select>\n");
 }
 
 sub keysplit {
@@ -1212,7 +1194,7 @@
     } else {
         my ($map,$id,$resource)=&Apache::lonnet::decode_symb($pssymb);
         $r->print(&mt('Specific Resource').": ".$resource.
-                  '<input type="hidden" value="'.$pssymb.'" name="symb">');
+                  '<input type="hidden" value="'.$pssymb.'" name="symb"><br />');
     }
     &usermenu($r,$uname,$id,$udom,$csec);    
 
@@ -1967,9 +1949,12 @@
 	    }
 	    if ($cmd eq 'set') {
 		my $data=$env{$_};
-		if ($$olddata{$thiskey} ne $data) { 
+                my $typeof=$env{'form.typeof_'.$thiskey};
+ 		if ($$olddata{$thiskey} ne $data) { 
 		    if ($tuname) {
-			if (&Apache::lonnet::put('resourcedata',{$tkey=>$data},$tudom,$tuname) eq 'ok') {
+			if (&Apache::lonnet::put('resourcedata',{$tkey=>$data,
+								 $tkey.'.type' => $typeof},
+						 $tudom,$tuname) eq 'ok') {
 			    $r->print('<br />'.&mt('Stored modified parameter for').' '.
 				      &Apache::loncommon::plainname($tuname,$tudom));
 			} else {
@@ -1979,7 +1964,8 @@
 			&Apache::lonnet::devalidateuserresdata($tuname,$tudom);
 		    } else {
 			$newdata{$thiskey}=$data;
-                    } 
+ 			$newdata{$thiskey.'.type'}=$typeof; 
+                   } 
 		}
 	    } elsif ($cmd eq 'del') {
 		if ($tuname) {
@@ -1995,9 +1981,12 @@
 		}
 	    } elsif ($cmd eq 'datepointer') {
 		my $data=&Apache::lonhtmlcommon::get_date_from_form($env{$_});
+                my $typeof=$env{'form.typeof_'.$thiskey};
 		if (defined($data) and $$olddata{$thiskey} ne $data) { 
 		    if ($tuname) {
-			if (&Apache::lonnet::put('resourcedata',{$tkey=>$data},$tudom,$tuname) eq 'ok') {
+			if (&Apache::lonnet::put('resourcedata',{$tkey=>$data,
+								 $tkey.'.type' => $typeof},
+						 $tudom,$tuname) eq 'ok') {
 			    $r->print('<br />'.&mt('Stored modified date for').' '.&Apache::loncommon::plainname($tuname,$tudom));
 			} else {
 			    $r->print('<h2><font color="red">'.
@@ -2005,7 +1994,8 @@
 			}
 			&Apache::lonnet::devalidateuserresdata($tuname,$tudom);
 		    } else {
-			$newdata{$thiskey}=$data; 
+			$newdata{$thiskey}=$data;
+			$newdata{$thiskey.'.type'}=$typeof; 
 		    }
 		}
 	    }
@@ -2026,7 +2016,7 @@
     }
     if ($putentries) {
 	if (&Apache::lonnet::put('resourcedata',\%newdata,$dom,$crs) eq 'ok') {
-	    $r->print('<h2>'.&mt('Stored [_1] parameter(s)</h2>',$putentries));
+	    $r->print('<h3>'.&mt('Stored [_1] parameter(s)',$putentries/2).'</h3>');
 	} else {
 	    $r->print('<h2><font color="red">'.
 		      &mt('Error storing parameters').'</font></h2>');
@@ -2201,8 +2191,8 @@
     &partmenu($r,\%allparts,\@psprt);
     $r->print('</td><td>');
     &sectionmenu($r,\@selected_sections);
-    $r->print('</td></tr></table>');
-    
+    $r->print('</td></tr></table>'.
+	      '<p><input type="submit" name="dis" value="'.&mt('Display').'" /></p>');
 
 # Build the list data hash from the specified parms
 
@@ -2212,35 +2202,40 @@
     foreach my $cat (@pscat) {
 	foreach my $section (@selected_sections) {
 	    foreach my $part (@psprt) {
-                my $newparmkey=$env{'request.course.id'};
+                my $rootparmkey=$env{'request.course.id'};
                 if (($section ne 'all') && ($section ne 'none') && ($section)) {
-		    $newparmkey.='.['.$section.']';
+		    $rootparmkey.='.['.$section.']';
 		}
 		if ($parmlev eq 'general') {
 # course-level parameter
+		    my $newparmkey=$rootparmkey.'.'.$part.'.'.$cat;
+		    $$listdata{$newparmkey}=1;
+		    $$listdata{$newparmkey.'.type'}=$defkeytype{$cat};
 		} elsif ($parmlev eq 'map') {
-		    foreach my $map (keys %allmaps) {
-			if (($pschp ne 'all') && ($pschp ne $map)) { next; }
-			$newparmkey.='.'.$allmaps{$map}.'.'.$part.'.'.$cat;
+# map-level parameter
+		    foreach my $mapid (keys %allmaps) {
+			if (($pschp ne 'all') && ($pschp ne $mapid)) { next; }
+			my $newparmkey=$rootparmkey.'.'.$allmaps{$mapid}.'___(all).'.$part.'.'.$cat;
                         $$listdata{$newparmkey}=1;
                         $$listdata{$newparmkey.'.type'}=$defkeytype{$cat};
 		    }
-# map-level parameter
 		} else {
 # resource-level parameter
-
+		    foreach my $rid (@ids) {
+			my ($map,$resid,$url)=&Apache::lonnet::decode_symb($symbp{$rid});
+			if (($pschp ne 'all') && ($allmaps{$pschp} ne $map)) { next; }
+			my $newparmkey=$rootparmkey.'.'.$symbp{$rid}.'.'.$part.'.'.$cat;
+                        $$listdata{$newparmkey}=1;
+                        $$listdata{$newparmkey.'.type'}=$defkeytype{$cat};
+		    }
 		}
 	    }
 	}
     }
 
+    if (($env{'form.store'}) || ($env{'form.dis'})) {
 
-
-    $r->print(join("\n<br />",keys %{$listdata}));
-
-    if ($env{'form.dis'}) {
-
-	&storedata($r,$crs,$dom);
+	if ($env{'form.store'}) { &storedata($r,$crs,$dom); }
 
 # Read modified data
 
@@ -2251,7 +2246,8 @@
 	&listdata($r,$resourcedata,$listdata);
     }
     $r->print(&tableend().
-	     '<p><input type="submit" name="dis" value="'.&mt('Submit').'" /></p></form></body></html>');
+	     ((($env{'form.store'}) || ($env{'form.dis'}))?'<p><input type="submit" name="store" value="'.&mt('Store').'" /></p>':'').
+	      '</form></body></html>');
 }
 
 sub overview {