From f0f56253984fbb6fad49a5c470c30632ae190121 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 6 Jan 2008 21:53:26 +0000 Subject: [PATCH] Fix: Boucle infinie sur calendrier --- htdocs/lib/datepicker.php | 71 +++++++++++++++++++++++------------- htdocs/lib/functions.inc.php | 20 ++++++---- 2 files changed, 59 insertions(+), 32 deletions(-) diff --git a/htdocs/lib/datepicker.php b/htdocs/lib/datepicker.php index 3931809454e..2553c034ec1 100644 --- a/htdocs/lib/datepicker.php +++ b/htdocs/lib/datepicker.php @@ -49,7 +49,7 @@ if (isset($_GET["mode"]) && $_GET["mode"] == 'test') else { //print ''."\n"; - print ''."\n"; + print 'Calendar'."\n"; } @@ -88,7 +88,7 @@ function xyzToUnixTimestamp($mysqldate){ $year=substr($mysqldate,0,4); $month=substr($mysqldate,4,2); $day=substr($mysqldate,6,2); - $unixtimestamp=dolibarr_mktime(0,0,0,$month,$day,$year); + $unixtimestamp=dolibarr_mktime(12,0,0,$month,$day,$year); return $unixtimestamp; } @@ -96,7 +96,7 @@ function displayBox($selectedDate,$month,$year){ global $dolibarr_main_url_root,$langs,$conf; //print "$selectedDate,$month,$year"; - $thedate=dolibarr_mktime(0,0,0,$month,1,$year); + $thedate=dolibarr_mktime(12,0,0,$month,1,$year); //print "thedate=$thedate"; $today=mktime(); $todayArray=dolibarr_getdate($today); @@ -120,7 +120,7 @@ function displayBox($selectedDate,$month,$year){ echo $langs->trans($selectMonth).", ".$selectYear; ?> - + << @@ -130,30 +130,41 @@ function displayBox($selectedDate,$month,$year){ >> - trans("ShortSunday") ?> - trans("ShortMonday") ?> - trans("ShortTuesday") ?> - trans("ShortWednesday") ?> - trans("ShortThursday") ?> - trans("ShortFriday") ?> - trans("ShortSaturday") ?> + trans("ShortSunday") ?> + trans("ShortMonday") ?> + trans("ShortTuesday") ?> + trans("ShortWednesday") ?> + trans("ShortThursday") ?> + trans("ShortFriday") ?> + trans("ShortSaturday") ?> - "; - if($firstdate==$mydate){ - // firstdate, so we may have to put in blanks + if($firstdate==$mydate) // At first run + { echo ""; - for($i=0;$i<$mydate["wday"];$i++) + $cols=0; + for($i=0;$i< $mydate["wday"];$i++) + { echo " "; + $cols++; + } + } + else + { + if ($mydate["wday"]==0) + { + echo ""; + $cols=0; + } } $dayclass="dpReg"; @@ -165,18 +176,28 @@ function displayBox($selectedDate,$month,$year){ echo " onMouseOver=\"dpHighlightDay(".$mydate["year"].",".dolibarr_date("n",$thedate).",".$mydate["mday"].",tradMonths)\""; echo " onClick=\"dpClickDay(".$mydate["year"].",".dolibarr_date("n",$thedate).",".$mydate["mday"].",'".$conf->format_date_short_java."')\""; echo ">".sprintf("%02s",$mydate["mday"]).""; + $cols++; + + if ($mydate["wday"]==6) echo "\n"; - if($mydate["wday"]==6) echo ""; //$thedate=strtotime("tomorrow",$thedate); $day++; - $thedate=dolibarr_mktime(0,0,0,$month,$day,$year); - $mydate=dolibarr_getdate($thedate); + $thedate=dolibarr_mktime(12,0,0,$month,$day,$year); + if ($thedate == '') + { + $stoploop=1; + } + else + { + $mydate=dolibarr_getdate($thedate); + if ($firstdate["month"] != $mydate["month"]) $stoploop=1; + } } - if($mydate["wday"]!=0){ - for($i=6;$i>=$mydate["wday"];$i--) - echo " "; - echo ""; + if ($cols < 7) + { + for($i=6; $i>=$cols; $i--) echo " "; + echo "\n"; } ?> 31) return ''; - if ($month > 12) return ''; - if ($min < 0 || $min > 60) return ''; - if ($hour < 0 || $hour > 24) return ''; - if ($min < 0 || $min > 60) return ''; + if ($check) + { + if (! $month || ! $day) return ''; + if ($day > 31) return ''; + if ($month > 12) return ''; + if ($min < 0 || $min > 60) return ''; + if ($hour < 0 || $hour > 24) return ''; + if ($min < 0 || $min > 60) return ''; + } $usealternatemethod=false; if ($year <= 1970) $usealternatemethod=true; // <= 1970