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

www lon-capa-cvs@mail.lon-capa.org
Sat, 04 Jun 2005 15:26:16 -0000


www		Sat Jun  4 11:26:16 2005 EDT

  Modified files:              
    /loncom/interface	lonparmset.pm 
  Log:
  Bug #2396: include userdata into overview
  
  
Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.206 loncom/interface/lonparmset.pm:1.207
--- loncom/interface/lonparmset.pm:1.206	Fri Jun  3 17:19:04 2005
+++ loncom/interface/lonparmset.pm	Sat Jun  4 11:26:13 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set parameters for assessments
 #
-# $Id: lonparmset.pm,v 1.206 2005/06/03 21:19:04 www Exp $
+# $Id: lonparmset.pm,v 1.207 2005/06/04 15:26:13 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1805,7 +1805,8 @@
 ENDenv
 }
 ##################################################
-
+# Overview mode
+##################################################
 my $tableopen;
 
 sub tablestart {
@@ -1827,6 +1828,35 @@
     }
 }
 
+sub readdata {
+    my ($crs,$dom)=@_;
+# Read coursedata
+    my $resourcedata=&Apache::lonnet::get_courseresdata($crs,$dom);
+# Read userdata
+
+    my $classlist=&Apache::loncoursedata::get_classlist();
+    foreach (keys %$classlist) {
+        # the following undefs are for 'domain', and 'username' respectively.
+        if ($_=~/^(\w+)\:(\w+)$/) {
+	    my ($tuname,$tudom)=($1,$2);
+	    my $useropt=&Apache::lonnet::get_userresdata($tuname,$tudom);
+            foreach my $userkey (keys %{$useropt}) {
+		if ($userkey=~/^$env{'request.course.id'}/) {
+                    my $newkey=$userkey;
+		    $newkey=~s/^($env{'request.course.id'}\.)/$1\[useropt\:$tuname\:$tudom\]\./;
+		    $$resourcedata{$newkey}=$$useropt{$userkey};
+		}
+	    }
+	}
+    }
+    return $resourcedata;
+}
+
+sub extractuser {
+    my $key=shift;
+    return ($key=~/^$env{'request.course.id'}.\[useropt\:(\w+)\:(\w+)\]\./);
+}
+
 sub overview {
     my $r=shift;
     my $bodytag=&Apache::loncommon::bodytag(
@@ -1846,7 +1876,9 @@
 <input type="hidden" name="overview" value="1" />
 ENDOVER
 # Setting
-    my %olddata=&Apache::lonnet::dump('resourcedata',$dom,$crs);
+# Set userlevel immediately
+# Do an intermediate store of course level
+    my $olddata=&readdata($crs,$dom);
     my %newdata=();
     undef %newdata;
     my @deldata=();
@@ -1855,18 +1887,58 @@
 	if ($_=~/^form\.([a-z]+)\_(.+)$/) {
 	    my $cmd=$1;
 	    my $thiskey=$2;
+	    my ($tuname,$tudom)=&extractuser($thiskey);
+	    my $tkey=$thiskey;
+            if ($tuname) {
+		$tkey=~s/\.\[useropt\:$tuname\:$tudom\]\./\./;
+	    }
 	    if ($cmd eq 'set') {
 		my $data=$env{$_};
-		if ($olddata{$thiskey} ne $data) { $newdata{$thiskey}=$data; }
+		if ($$olddata{$thiskey} ne $data) { 
+		    if ($tuname) {
+			if (&Apache::lonnet::put('resourcedata',{$tkey=>$data},$tudom,$tuname) eq 'ok') {
+			    $r->print('<br />'.&mt('Stored modified parameter for').' '.
+				      &Apache::loncommon::plainname($tuname,$tudom));
+			} else {
+			    $r->print('<h2><font color="red">'.
+				      &mt('Error storing parameters').'</font></h2>');
+			}
+			&Apache::lonnet::devalidateuserresdata($tuname,$tudom);
+		    } else {
+			$newdata{$thiskey}=$data;
+                    } 
+		}
 	    } elsif ($cmd eq 'del') {
-		push (@deldata,$thiskey);
+		if ($tuname) {
+		    if (&Apache::lonnet::del('resourcedata',[$tkey],$tudom,$tuname) eq 'ok') {
+			$r->print('<br />'.&mt('Deleted parameter for').' '.&Apache::loncommon::plainname($tuname,$tudom));
+		    } else {
+			$r->print('<h2><font color="red">'.
+				  &mt('Error deleting parameters').'</font></h2>');
+		    }
+		    &Apache::lonnet::devalidateuserresdata($tuname,$tudom);
+		} else {
+		    push (@deldata,$thiskey);
+		}
 	    } elsif ($cmd eq 'datepointer') {
 		my $data=&Apache::lonhtmlcommon::get_date_from_form($env{$_});
-		if (defined($data) and $olddata{$thiskey} ne $data) { $newdata{$thiskey}=$data; }
+		if (defined($data) and $$olddata{$thiskey} ne $data) { 
+		    if ($tuname) {
+			if (&Apache::lonnet::put('resourcedata',{$tkey=>$data},$tudom,$tuname) eq 'ok') {
+			    $r->print('<br />'.&mt('Stored modified date for').' '.&Apache::loncommon::plainname($tuname,$tudom));
+			} else {
+			    $r->print('<h2><font color="red">'.
+				      &mt('Error storing parameters').'</font></h2>');
+			}
+			&Apache::lonnet::devalidateuserresdata($tuname,$tudom);
+		    } else {
+			$newdata{$thiskey}=$data; 
+		    }
+		}
 	    }
 	}
     }
-# Store
+# Store all course level
     my $delentries=$#deldata+1;
     my @newdatakeys=keys %newdata;
     my $putentries=$#newdatakeys+1;
@@ -1888,25 +1960,11 @@
 	}
 	&Apache::lonnet::devalidatecourseresdata($crs,$dom);
     }
-# Read coursedata
-    my $resourcedata=&Apache::lonnet::get_courseresdata($crs,$dom);
-# Read userdata
+# Read modified data
 
-    my $classlist=&Apache::loncoursedata::get_classlist();
-    foreach (keys %$classlist) {
-        # the following undefs are for 'domain', and 'username' respectively.
-        if ($_=~/^(\w+)\:(\w+)$/) {
-	    my ($tuname,$tudom)=($1,$2);
-	    my $useropt=&Apache::lonnet::get_userresdata($tuname,$tudom);
-            foreach my $userkey (keys %{$useropt}) {
-		if ($userkey=~/^$env{'request.course.id'}/) {
-                    my $newkey=$userkey;
-		    $newkey=~s/^($env{'request.course.id'}\.)/$1\[useropt\:$tuname\:$tudom\]\./;
-		    $$resourcedata{$newkey}=$$useropt{$userkey};
-		}
-	    }
-	}
-    }
+    my $resourcedata=&readdata($crs,$dom);
+
+# Start list output
 
     my $oldsection='';
     my $oldrealm='';
@@ -1916,20 +1974,20 @@
     my $foundkeys=0;
     foreach my $thiskey (sort keys %{$resourcedata}) {
 	if ($$resourcedata{$thiskey.'.type'}) {
-	    $r->print($thiskey);
-	    my ($course,$middle,$part,$name)=
-		($thiskey=~/^(\w+)\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/);
+	    my ($middle,$part,$name)=
+		($thiskey=~/^$env{'request.course.id'}\.(?:(.+)\.)*([\w\s]+)\.(\w+)$/);
 	    my $section=&mt('All Students');
-	    if ($middle=~/^\[(.*)\]\./) {
+	    if ($middle=~/^\[(.*)\]/) {
 		my $issection=$1;
 		if ($issection=~/^useropt\:(\w+)\:(\w+)/) {
 		    $section=&mt('User').": ".&Apache::loncommon::plainname($1,$2);
 		} else {
 		    $section=&mt('Group/Section').': '.$issection;
 		}
-		$middle=~s/^\[(.*)\]\.//;
+		$middle=~s/^\[(.*)\]//;
 	    }
-	    $middle=~s/\.$//;
+	    $middle=~s/\.+$//;
+	    $middle=~s/^\.+//;
 	    my $realm='<font color="red">'.&mt('All Resources').'</font>';
 	    if ($middle=~/^(.+)\_\_\_\(all\)$/) {
 		$realm='<font color="green">'.&mt('Folder/Map').': '.&Apache::lonnet::gettitle($1).' <br /><font color="#aaaaaa" size="-2">('.$1.')</font></font>';