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

matthew lon-capa-cvs@mail.lon-capa.org
Fri, 23 Apr 2004 17:49:26 -0000


matthew		Fri Apr 23 13:49:26 2004 EDT

  Modified files:              
    /loncom/interface	lonhtmlcommon.pm 
  Log:
  &date_setter: Added parameter no_hh_mm_ss, to omit the hrs, min, and
  seconds fields.
  &get_date_from_form: hrs, min, sec now default to 0 if not defined.  
  Still requires day, month, and year be defined.
  
  
Index: loncom/interface/lonhtmlcommon.pm
diff -u loncom/interface/lonhtmlcommon.pm:1.66 loncom/interface/lonhtmlcommon.pm:1.67
--- loncom/interface/lonhtmlcommon.pm:1.66	Mon Apr 19 12:43:03 2004
+++ loncom/interface/lonhtmlcommon.pm	Fri Apr 23 13:49:25 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common html routines
 #
-# $Id: lonhtmlcommon.pm,v 1.66 2004/04/19 16:43:03 matthew Exp $
+# $Id: lonhtmlcommon.pm,v 1.67 2004/04/23 17:49:25 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -219,10 +219,14 @@
 ##############################################
 ##############################################
 sub date_setter {
-    my ($formname,$dname,$currentvalue,$special,$includeempty,$state) = @_;
+    my ($formname,$dname,$currentvalue,$special,$includeempty,$state,
+        $no_hh_mm_ss) = @_;
     if (! defined($state) || $state ne 'disabled') {
         $state = '';
     }
+    if (! defined($no_hh_mm_ss)) {
+        $no_hh_mm_ss = 0;
+    }
     if (! defined($currentvalue) || $currentvalue eq 'now') {
 	unless ($includeempty) {
 	    $currentvalue = time;
@@ -305,6 +309,7 @@
     $result .= "  <nobr><select name=\"$dname\_month\" ".$special.' '.
         $state.' '.
         "onChange=\"javascript:$dname\_checkday()\" >\n";
+    # Month
     my @Months = qw/January February  March     April   May      June 
                     July    August    September October November December/;
     # Pad @Months with a bogus value to make indexing easier
@@ -316,39 +321,47 @@
         $result .= "> ".&mt($Months[$m])." </option>\n";
     }
     $result .= "  </select>\n";
+    # Day
     $result .= "  <input type=\"text\" name=\"$dname\_day\" ".$state.' '.
             "value=\"$mday\" size=\"3\" ".$special.' '.
             "onChange=\"javascript:$dname\_checkday()\" />\n";
+    # Year
     $result .= "  <input type=\"year\" name=\"$dname\_year\" ".$state.' '.
             "value=\"$year\" size=\"5\" ".$special.' '.
             "onChange=\"javascript:$dname\_checkday()\" />\n";
     $result .= "&nbsp;&nbsp;";
-    $result .= "  <select name=\"$dname\_hour\" ".$special." ".$state.' '.">\n";
-    if ($includeempty) { $result.="<option value=''></option>"; }
-    for (my $h = 0;$h<24;$h++) {
-        $result .= "      <option value=\"$h\" ";
-        $result .= "selected " if (defined($hour) && $hour == $h);
-        $result .= "> ";
-	my $timest='';
-        if ($h == 0) {
-            $timest .= "12 am";
-        } elsif($h == 12) {
-            $timest .= "12 noon";
-        } elsif($h < 12) {
-            $timest .= "$h am";
-        } else {
-            $timest .= $h-12 ." pm";
-        }
-	$timest=&mt($timest);
-        $result .= $timest." </option>\n";
-    } 
-    $result .= "  </select>\n";
-    $result .= "  <input type=\"text\" name=\"$dname\_minute\" ".$special.' '.
-        $state.' '.
-        "value=\"$min\" size=\"3\" /> m\n";
-    $result .= "  <input type=\"text\" name=\"$dname\_second\" ".$special.' '.
-        $state.' '.
-        "value=\"$sec\" size=\"3\" /> s\n";
+    if (! $no_hh_mm_ss) {
+        # Hours
+        $result .= "  <select name=\"$dname\_hour\" ".$special." ".$state.' '.
+            ">\n";
+        if ($includeempty) { $result.="<option value=''></option>"; }
+        for (my $h = 0;$h<24;$h++) {
+            $result .= "      <option value=\"$h\" ";
+            $result .= "selected " if (defined($hour) && $hour == $h);
+            $result .= "> ";
+            my $timest='';
+            if ($h == 0) {
+                $timest .= "12 am";
+            } elsif($h == 12) {
+                $timest .= "12 noon";
+            } elsif($h < 12) {
+                $timest .= "$h am";
+            } else {
+                $timest .= $h-12 ." pm";
+            }
+            $timest=&mt($timest);
+            $result .= $timest." </option>\n";
+        } 
+        $result .= "  </select>\n";
+        $result .= "  <input type=\"text\" name=\"$dname\_minute\" ".
+            $special.' '.
+            $state.' '.
+            "value=\"$min\" size=\"3\" /> m\n";
+        $result .= "  <input type=\"text\" name=\"$dname\_second\" ".
+            $special.' '.
+            $state.' '.
+            "value=\"$sec\" size=\"3\" /> s\n";
+    }
     $result .= "<a href=\"javascript:$dname\_opencalendar()\">".
     &mt('Select Date')."</a></nobr>\n<!-- end $dname date setting form -->\n";
     return $result;
@@ -393,6 +406,8 @@
             $sec = $tmpsec;
         }
 	if (!defined($tmpsec) || $tmpsec eq '') { $sec = 0; }
+    } else {
+        $sec = 0;
     }
     if (defined($ENV{'form.'.$dname.'_minute'})) {
         my $tmpmin = $ENV{'form.'.$dname.'_minute'};
@@ -400,12 +415,16 @@
             $min = $tmpmin;
         }
 	if (!defined($tmpmin) || $tmpmin eq '') { $min = 0; }
+    } else {
+        $min = 0;
     }
     if (defined($ENV{'form.'.$dname.'_hour'})) {
         my $tmphour = $ENV{'form.'.$dname.'_hour'};
         if (($tmphour =~ /^\d+$/) && ($tmphour >= 0) && ($tmphour < 24)) {
             $hour = $tmphour;
         }
+    } else {
+        $hour = 0;
     }
     if (defined($ENV{'form.'.$dname.'_day'})) {
         my $tmpday = $ENV{'form.'.$dname.'_day'};