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

www lon-capa-cvs@mail.lon-capa.org
Thu, 17 Mar 2005 21:08:43 -0000


www		Thu Mar 17 16:08:43 2005 EDT

  Modified files:              
    /loncom/interface	lonparmset.pm 
  Log:
  Having a subroutine to set parameters seems like a good idea in lonparmset.
  
  It still needs globals, though.
  
  
Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.185 loncom/interface/lonparmset.pm:1.186
--- loncom/interface/lonparmset.pm:1.185	Thu Mar 17 15:01:11 2005
+++ loncom/interface/lonparmset.pm	Thu Mar 17 16:08:43 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set parameters for assessments
 #
-# $Id: lonparmset.pm,v 1.185 2005/03/17 20:01:11 albertel Exp $
+# $Id: lonparmset.pm,v 1.186 2005/03/17 21:08:43 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -195,6 +195,101 @@
     return ($result,@outpar);
 }
 
+
+##################################################
+##################################################
+#
+# Store a parameter
+#
+# Takes
+# - resource id
+# - name of parameter
+# - level
+# - new value
+# - new type
+sub storeparm {
+    my ($sresid,$spnam,$snum,$nval,$ntype)=@_;
+    $spnam=~s/\_([^\_]+)$/\.$1/;
+# ---------------------------------------------------------- Construct prefixes
+    
+    my $symbparm=$symbp{$sresid}.'.'.$spnam;
+    my $mapparm=$mapp{$sresid}.'___(all).'.$spnam;
+    
+    my $seclevel=$ENV{'request.course.id'}.'.['.$csec.'].'.$spnam;
+    my $seclevelr=$ENV{'request.course.id'}.'.['.$csec.'].'.$symbparm;
+    my $seclevelm=$ENV{'request.course.id'}.'.['.$csec.'].'.$mapparm;
+    
+    my $courselevel=$ENV{'request.course.id'}.'.'.$spnam;
+    my $courselevelr=$ENV{'request.course.id'}.'.'.$symbparm;
+    my $courselevelm=$ENV{'request.course.id'}.'.'.$mapparm;
+    
+    my $storeunder='';
+    if (($snum==11) || ($snum==3)) { $storeunder=$courselevel; }
+    if (($snum==10) || ($snum==2)) { $storeunder=$courselevelm; }
+    if (($snum==7) || ($snum==1)) { $storeunder=$courselevelr; }
+    if ($snum==6) { $storeunder=$seclevel; }
+    if ($snum==5) { $storeunder=$seclevelm; }
+    if ($snum==4) { $storeunder=$seclevelr; }
+    
+    my $delete;
+    if ($nval eq '') { $delete=1;}
+    my %storecontent = ($storeunder         => $nval,
+			$storeunder.'.type' => $ntype);
+    my $reply='';
+    if ($snum>3) {
+# ---------------------------------------------------------------- Store Course
+#
+# Expire sheets
+	&Apache::lonnet::expirespread('','','studentcalc');
+	if (($snum==7) || ($snum==4)) {
+	    &Apache::lonnet::expirespread('','','assesscalc',$symbp{$sresid});
+	} elsif (($snum==8) || ($snum==5)) {
+	    &Apache::lonnet::expirespread('','','assesscalc',$mapp{$sresid});
+	} else {
+	    &Apache::lonnet::expirespread('','','assesscalc');
+	}
+# Store parameter
+	if ($delete) {
+	    $reply=&Apache::lonnet::del
+		('resourcedata',[keys(%storecontent)],
+		 $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
+		 $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
+	} else {
+	    $reply=&Apache::lonnet::cput
+		('resourcedata',\%storecontent,
+		 $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
+		 $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
+	}
+    } else {
+# ------------------------------------------------------------------ Store User
+#
+# Expire sheets
+	&Apache::lonnet::expirespread($uname,$udom,'studentcalc');
+	if ($snum==1) {
+	    &Apache::lonnet::expirespread
+		($uname,$udom,'assesscalc',$symbp{$sresid});
+	} elsif ($snum==2) {
+	    &Apache::lonnet::expirespread
+		($uname,$udom,'assesscalc',$mapp{$sresid});
+	} else {
+	    &Apache::lonnet::expirespread($uname,$udom,'assesscalc');
+	}
+# Store parameter
+	if ($delete) {
+	    $reply=&Apache::lonnet::del
+		('resourcedata',[keys(%storecontent)],$udom,$uname);
+	} else {
+	    $reply=&Apache::lonnet::cput
+		('resourcedata',\%storecontent,$udom,$uname);
+	}
+    }
+    
+    if ($reply=~/^error\:(.*)/) {
+	return "<font color=red>Write Error: $1</font>";
+    }
+    return '';
+}
+
 ##################################################
 ##################################################
 
@@ -815,85 +910,9 @@
 
 # ---------------------------------------------------------- Anything to store?
     if ($ENV{'form.pres_marker'}) {
-	my ($sresid,$spnam,$snum)=split(/\&/,$ENV{'form.pres_marker'});
-	$spnam=~s/\_([^\_]+)$/\.$1/;
-# ---------------------------------------------------------- Construct prefixes
-
-	my $symbparm=$symbp{$sresid}.'.'.$spnam;
-	my $mapparm=$mapp{$sresid}.'___(all).'.$spnam;
-	
-	my $seclevel=$ENV{'request.course.id'}.'.['.$csec.'].'.$spnam;
-	my $seclevelr=$ENV{'request.course.id'}.'.['.$csec.'].'.$symbparm;
-	my $seclevelm=$ENV{'request.course.id'}.'.['.$csec.'].'.$mapparm;
-	
-	my $courselevel=$ENV{'request.course.id'}.'.'.$spnam;
-	my $courselevelr=$ENV{'request.course.id'}.'.'.$symbparm;
-	my $courselevelm=$ENV{'request.course.id'}.'.'.$mapparm;
-	
-	my $storeunder='';
-	if (($snum==11) || ($snum==3)) { $storeunder=$courselevel; }
-	if (($snum==10) || ($snum==2)) { $storeunder=$courselevelm; }
-	if (($snum==7) || ($snum==1)) { $storeunder=$courselevelr; }
-	if ($snum==6) { $storeunder=$seclevel; }
-	if ($snum==5) { $storeunder=$seclevelm; }
-	if ($snum==4) { $storeunder=$seclevelr; }
-	
-	my $delete;
-	if ($ENV{'form.pres_value'} eq '') { $delete=1;}
-        my %storecontent = ($storeunder         => $ENV{'form.pres_value'},
-                            $storeunder.'.type' => $ENV{'form.pres_type'});
-	my $reply='';
-	if ($snum>3) {
-# ---------------------------------------------------------------- Store Course
-#
-# Expire sheets
-	    &Apache::lonnet::expirespread('','','studentcalc');
-	    if (($snum==7) || ($snum==4)) {
-		&Apache::lonnet::expirespread('','','assesscalc',$symbp{$sresid});
-	    } elsif (($snum==8) || ($snum==5)) {
-		&Apache::lonnet::expirespread('','','assesscalc',$mapp{$sresid});
-	    } else {
-		&Apache::lonnet::expirespread('','','assesscalc');
-	    }
-# Store parameter
-	    if ($delete) {
-		$reply=&Apache::lonnet::del
-		    ('resourcedata',[keys(%storecontent)],
-		     $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
-		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
-	    } else {
-		$reply=&Apache::lonnet::cput
-		    ('resourcedata',\%storecontent,
-		     $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
-		     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
-	    }
-	} else {
-# ------------------------------------------------------------------ Store User
-#
-# Expire sheets
-	    &Apache::lonnet::expirespread($uname,$udom,'studentcalc');
-	    if ($snum==1) {
-		&Apache::lonnet::expirespread
-		    ($uname,$udom,'assesscalc',$symbp{$sresid});
-	    } elsif ($snum==2) {
-		&Apache::lonnet::expirespread
-		    ($uname,$udom,'assesscalc',$mapp{$sresid});
-	    } else {
-		&Apache::lonnet::expirespread($uname,$udom,'assesscalc');
-	    }
-# Store parameter
-	    if ($delete) {
-		$reply=&Apache::lonnet::del
-		    ('resourcedata',[keys(%storecontent)],$udom,$uname);
-	    } else {
-		$reply=&Apache::lonnet::cput
-		    ('resourcedata',\%storecontent,$udom,$uname);
-	    }
-	}
-
-	if ($reply=~/^error\:(.*)/) {
-	    $message.="<font color=red>Write Error: $1</font>";
-	}
+	$message.=&storeparm(split(/\&/,$ENV{'form.pres_marker'}),
+			     $ENV{'form.pres_value'},
+			     $ENV{'form.pres_type'});
 # ---------------------------------------------------------------- Done storing
 	$message.='<h3>'.&mt('Changes can take up to 10 minutes before being active for all students.').&Apache::loncommon::help_open_topic('Caching').'</h3>';
     }