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

albertel lon-capa-cvs-allow@mail.lon-capa.org
Fri, 02 Nov 2007 23:30:56 -0000


albertel		Fri Nov  2 19:30:56 2007 EDT

  Modified files:              
    /loncom/interface	lonparmset.pm 
  Log:
  - make the date_interval; setter in parmset the same as in the table mode
  
  
Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.384 loncom/interface/lonparmset.pm:1.385
--- loncom/interface/lonparmset.pm:1.384	Fri Nov  2 19:29:49 2007
+++ loncom/interface/lonparmset.pm	Fri Nov  2 19:30:56 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set parameters for assessments
 #
-# $Id: lonparmset.pm,v 1.384 2007/11/02 23:29:49 albertel Exp $
+# $Id: lonparmset.pm,v 1.385 2007/11/02 23:30:56 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2503,7 +2503,7 @@
             if ($tuname) {
 		$tkey=~s/\.\[useropt\:$tuname\:$tudom\]\./\./;
 	    }
-	    if ($cmd eq 'set' || $cmd eq 'datepointer') {
+	    if ($cmd eq 'set' || $cmd eq 'datepointer' || $cmd eq 'dateinterval') {
 		my ($data, $typeof, $text);
 		if ($cmd eq 'set') {
 		    $data=$env{$_};
@@ -2513,6 +2513,10 @@
 		    $data=&Apache::lonhtmlcommon::get_date_from_form($env{$_});
 		    $typeof=$env{'form.typeof_'.$thiskey};
 		    $text = &mt('Saved modified date for');
+		} elsif ($cmd eq 'dateinterval') {
+		    $data=&get_date_interval_from_form($thiskey);
+		    $typeof=$env{'form.typeof_'.$thiskey};
+		    $text = &mt('Saved modified date for');
 		}
 		if (defined($data) and $$olddata{$thiskey} ne $data) { 
 		    if ($tuname) {
@@ -2727,6 +2731,9 @@
 '<input type="hidden" name="datepointer_'.$thiskey.'" value="'.$jskey.'" />'.
 &date_sanity_info($$resourcedata{$thiskey})
 			  );
+	    } elsif ($thistype eq 'date_interval') {
+		$r->print(&date_interval_selector($thiskey,
+						  $$resourcedata{$thiskey}));
 	    } elsif ($thistype =~ m/^string/) {
 		$r->print(&string_selector($thistype,$thiskey,
 					   $$resourcedata{$thiskey}));
@@ -2741,9 +2748,49 @@
     return $foundkeys;
 }
 
+
+sub date_interval_selector {
+    my ($thiskey, $showval) = @_;
+    my $result;
+    &Apache::lonnet::logthis($showval);
+    foreach my $which (['days', 86400, 31],
+		       ['hours', 3600, 23],
+		       ['minutes', 60, 59],
+		       ['seconds',  1, 59]) {
+	my ($name, $factor, $max) = @{ $which };
+	my $amount = int($showval/$factor);
+	$showval  %= $factor;
+	&Apache::lonnet::logthis("$amount $factor $showval");
+	my %select = ((map {$_ => $_} (0..$max)),
+		      'select_form_order' => [0..$max]);
+	$result .= &Apache::loncommon::select_form($amount,$name.'_'.$thiskey,
+						   %select);
+	$result .= ' '.&mt($name);
+    }
+    $result .= '<input type="hidden" name="dateinterval_'.$thiskey.'" />';
+    return $result;
+
+}
+
+sub get_date_interval_from_form {
+    my ($key) = @_;
+    my $seconds = 0;
+    foreach my $which (['days', 86400],
+		       ['hours', 3600],
+		       ['minutes', 60],
+		       ['seconds',  1]) {
+	my ($name, $factor) = @{ $which };
+	if (defined($env{'form.'.$name.'_'.$key})) {
+	    $seconds += $env{'form.'.$name.'_'.$key} * $factor;
+	}
+    }
+    return $seconds;
+}
+
+
 sub default_selector {
     my ($thiskey, $showval) = @_;
-    return '<input type="text" name="set_'.$thiskey.'" value="'.$showval.'">' ;
+    return '<input type="text" name="set_'.$thiskey.'" value="'.$showval.'" />';
 }
 
 my %strings =