--- loncom/interface/lonhtmlcommon.pm 2010/12/05 21:58:49 1.253.2.8 +++ loncom/interface/lonhtmlcommon.pm 2009/12/22 17:27:28 1.257 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common html routines # -# $Id: lonhtmlcommon.pm,v 1.253.2.8 2010/12/05 21:58:49 raeburn Exp $ +# $Id: lonhtmlcommon.pm,v 1.257 2009/12/22 17:27:28 faziophi Exp $ # # Copyright Michigan State University Board of Trustees # @@ -383,7 +383,8 @@ dname_hour, dname_min, and dname_sec. The current setting for this time parameter. A unix format time (time in seconds since the beginning of Jan 1st, 1970, GMT. -An undefined value is taken to indicate the value is the current time. +An undefined value is taken to indicate the value is the current time +unless it is requested to leave it empty. See $includeempty. Also, to be explicit, a value of 'now' also indicates the current time. =item $special @@ -393,6 +394,9 @@ the date_setter. See lonparmset for exa =item $includeempty +If it is set (true) and no date/time value is provided, +the date/time fields are left empty. + =item $state Specifies the initial state of the form elements. Either 'disabled' or empty. @@ -410,9 +414,13 @@ The method used to restrict user input w ############################################## sub date_setter { my ($formname,$dname,$currentvalue,$special,$includeempty,$state, - $no_hh_mm_ss,$defhour,$defmin,$defsec,$nolink,$hide_timezone) = @_; + $no_hh_mm_ss,$defhour,$defmin,$defsec,$nolink) = @_; my $now = time; - my $wasdefined=1; + + my $tzname; + my ($sec,$min,$hour,$mday,$month,$year) = ('', '', undef,''.''.''); + #other potentially useful values: wkday,yrday,is_daylight_savings + if (! defined($state) || $state ne 'disabled') { $state = ''; } @@ -420,33 +428,24 @@ sub date_setter { $no_hh_mm_ss = 0; } if ($currentvalue eq 'now') { - $currentvalue = $now; + $currentvalue = $now; } - if ((!defined($currentvalue)) || ($currentvalue eq '')) { - $wasdefined=0; - if ($includeempty) { - $currentvalue = 0; - } else { - $currentvalue = $now; - } + + # Default value: Set empty date field to current time + # unless empty inclusion is requested + if ((!$includeempty) && (!$currentvalue)) { + $currentvalue = $now; } - # other potentially useful values: wkday,yrday,is_daylight_savings - my $tzname; - my ($sec,$min,$hour,$mday,$month,$year)=('','',undef,'','',''); + # Do we have a date? Split it! if ($currentvalue) { - ($tzname,$sec,$min,$hour,$mday,$month,$year) = &get_timedates($currentvalue); - } - unless ($wasdefined) { - ($tzname,$sec,$min,$hour,$mday,$month,$year) = &get_timedates($now); - if (($defhour) || ($defmin) || ($defsec)) { - $sec=($defsec?$defsec:0); - $min=($defmin?$defmin:0); - $hour=($defhour?$defhour:0); - } elsif (!$includeempty) { - $sec=0; - $min=0; - $hour=0; - } + ($tzname,$sec,$min,$hour,$mday,$month,$year) = &get_timedates($currentvalue); + + #No values provided for hour, min, sec? Use default 0 + if (($defhour) || ($defmin) || ($defsec)) { + $sec = ($defsec ? $defsec : 0); + $min = ($defmin ? $defmin : 0); + $hour = ($defhour ? $defhour : 0); + } } my $result = "\n\n"; $result .= <}; } # - my $tzone; - unless ($hide_timezone) { - $tzone = ' '.$tzname.' '; - } + my $tzone = ' '.$tzname.' '; if ($no_hh_mm_ss) { $result .= &mt('[_1] [_2] [_3] ', $monthselector,$dayselector,$yearselector). @@ -646,7 +642,7 @@ Returns: Unix time represented in the fo ############################################## ############################################## sub get_date_from_form { - my ($dname,$timezone) = @_; + my ($dname) = @_; my ($sec,$min,$hour,$day,$month,$year); # if (defined($env{'form.'.$dname.'_second'})) { @@ -696,13 +692,7 @@ sub get_date_from_form { if (($year<1970) || ($year>2037)) { return undef; } if (defined($sec) && defined($min) && defined($hour) && defined($day) && defined($month) && defined($year)) { - if (defined($timezone)) { - if (&Apache::lonlocal::gettimezone($timezone) eq 'local') { - $timezone = &Apache::lonlocal::gettimezone(); - } - } else { - $timezone = &Apache::lonlocal::gettimezone(); - } + my $timezone = &Apache::lonlocal::gettimezone(); my $dt = DateTime->new( year => $year, month => $month, day => $day, @@ -1250,11 +1240,18 @@ ENDLINK } sub htmlareaheaders { - return if (&htmlareablocked()); - return if (!&htmlareabrowser()); - return (< -ENDHEADERS + +ENDEDITOR + } + $s.=(< + +ENDJQUERY + return $s; } # ----------------------------------------------------------------- Preferences @@ -1293,16 +1290,98 @@ sub htmlareaselectactive { my $output='