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

matthew lon-capa-cvs@mail.lon-capa.org
Fri, 20 Jun 2003 14:34:04 -0000


matthew		Fri Jun 20 10:34:04 2003 EDT

  Modified files:              
    /loncom/interface	lonparmset.pm 
  Log:
  Course parameter setting:
     Expire spreadsheets when the default assessment spreadsheet is changed.
     Output cleanups.
     Reindentation of code.
  
  
Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.104 loncom/interface/lonparmset.pm:1.105
--- loncom/interface/lonparmset.pm:1.104	Fri Jun 20 10:21:03 2003
+++ loncom/interface/lonparmset.pm	Fri Jun 20 10:34:04 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set parameters for assessments
 #
-# $Id: lonparmset.pm,v 1.104 2003/06/20 14:21:03 matthew Exp $
+# $Id: lonparmset.pm,v 1.105 2003/06/20 14:34:04 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1371,7 +1371,7 @@
 
 =item crsenv
 
-Show course data and parameters.  This is a large routine that should
+Show and set course data and parameters.  This is a large routine that should
 be simplified and shortened... someday.
 
 Inputs: $r
@@ -1389,50 +1389,63 @@
                              'Set Course Environment Parameters');
     my $dom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
     my $crs = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
-# -------------------------------------------------- Go through list of changes
+
+    #
+    # Go through list of changes
     foreach (keys %ENV) {
-	if ($_=~/^form\.(.+)\_setparmval$/) {
-            my $name=$1;
-            my $value=$ENV{'form.'.$name.'_value'};
-            if ($name eq 'newp') {
-                $name=$ENV{'form.newp_name'};
-            }
-            if ($name eq 'url') {
-		$value=~s/^\/res\///;
-                my $bkuptime=time;
-                my @tmp = &Apache::lonnet::get
-                    ('environment',['url'],$dom,$crs);
-                $setoutput.='Backing up previous URL: '.
-                    &Apache::lonnet::put
-                        ('environment',
-                         {'top level map backup '.$bkuptime => $tmp[1] },
-                         $dom,$crs).
-                    '<br>';
+        next if ($_!~/^form\.(.+)\_setparmval$/);
+        my $name  = $1;
+        my $value = $ENV{'form.'.$name.'_value'};
+        if ($name eq 'newp') {
+            $name = $ENV{'form.newp_name'};
+        }
+        if ($name eq 'url') {
+            $value=~s/^\/res\///;
+            my $bkuptime=time;
+            my @tmp = &Apache::lonnet::get
+                ('environment',['url'],$dom,$crs);
+            $setoutput.='Backing up previous URL: '.
+                &Apache::lonnet::put
+                ('environment',
+                 {'top level map backup '.$bkuptime => $tmp[1] },
+                 $dom,$crs).
+                     '<br>';
+        }
+        #
+        # Deal with modified default spreadsheets
+        if ($name =~ /^spreadsheet_default_(classcalc|
+                                            studentcalc|
+                                            assesscalc)$/x) {
+            my $sheettype = $1; 
+            if ($sheettype eq 'classcalc') {
+                # no need to do anything since viewing the sheet will
+                # cause it to be updated. 
+            } elsif ($sheettype eq 'studentcalc') {
+                # expire all the student spreadsheets
+                &Apache::lonnet::expirespread('','','studentcalc');
+            } else {
+                # expire all the assessment spreadsheets 
+                #    this includes non-default spreadsheets, but better to
+                #    be safe than sorry.
+                &Apache::lonnet::expirespread('','','assesscalc');
+                # expire all the student spreadsheets
+                &Apache::lonnet::expirespread('','','studentcalc');
             }
-            if ($name =~ /^spreadsheet_default_(classcalc|
-                                                studentcalc|
-                                                assesscalc)$/x) {
-                my $sheettype = $1; 
-                if ($sheettype eq 'classcalc') {
-                    # no need to do anything since viewing the sheet will
-                    # cause it to be updated. 
-                } elsif ($sheettype eq 'studentcalc') {
-                    # expire all the student spreadsheets
-                    &Apache::lonnet::expirespread('','','studentcalc');
-                } else {
-                    # expire all the default assessment spreadsheets
-                }
+        }
+        #
+        # Let the user know we made the changes
+        if ($name) {
+            my $put_result = &Apache::lonnet::put('environment',
+                                                  {$name=>$value},$dom,$crs);
+            if ($put_result eq 'ok') {
+                $setoutput.='Set <b>'.$name.'</b> to <b>'.$value.'</b>.<br />';
+            } else {
+                $setoutput.='Unable to set <b>'.$name.'</b> to '.
+                    '<b>'.$value.'</b> due to '.$put_result.'.<br />';
             }
-
-            if ($name) {
-                $setoutput.='Setting <tt>'.$name.'</tt> to <tt>'.
-                    $value.'</tt>: '.
-                    &Apache::lonnet::put
-                            ('environment',{$name=>$value},$dom,$crs).
-                    '<br>';
-	    }
         }
     }
+
 # -------------------------------------------------------- Get parameters again
 
     my %values=&Apache::lonnet::dump('environment',$dom,$crs);