clean datepicker

This commit is contained in:
Frédéric FRANCE 2018-09-16 11:26:39 +02:00 committed by GitHub
parent f7c2bd877a
commit 2f633857af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -66,18 +66,19 @@ else
} }
// Define tradMonths javascript array (we define this in datapicker AND in parent page to avoid errors with IE8) // Define tradMonths javascript array (we define this in datapicker AND in parent page to avoid errors with IE8)
$tradTemp=array($langs->trans("January"), $tradTemp=array(
$langs->trans("February"), $langs->trans("January"),
$langs->trans("March"), $langs->trans("February"),
$langs->trans("April"), $langs->trans("March"),
$langs->trans("May"), $langs->trans("April"),
$langs->trans("June"), $langs->trans("May"),
$langs->trans("July"), $langs->trans("June"),
$langs->trans("August"), $langs->trans("July"),
$langs->trans("September"), $langs->trans("August"),
$langs->trans("October"), $langs->trans("September"),
$langs->trans("November"), $langs->trans("October"),
$langs->trans("December") $langs->trans("November"),
$langs->trans("December")
); );
print '<script type="text/javascript">'; print '<script type="text/javascript">';
print 'var tradMonths = ['; print 'var tradMonths = [';
@ -96,25 +97,22 @@ $qualified=true;
if (! isset($_GET["sd"])) $_GET["sd"]="00000000"; if (! isset($_GET["sd"])) $_GET["sd"]="00000000";
if (! isset($_GET["m"])) $qualified=false; if (! isset($_GET["m"]) || ! isset($_GET["y"])) $qualified=false;
if (! isset($_GET["y"])) $qualified=false;
if (isset($_GET["m"]) && isset($_GET["y"])) if (isset($_GET["m"]) && isset($_GET["y"]))
{ {
if ($_GET["m"] < 1) $qualified=false; if ($_GET["m"] < 1 || $_GET["m"] > 12) $qualified=false;
if ($_GET["m"] > 12) $qualified=false; if ($_GET["y"] < 0 || $_GET["y"] > 9999) $qualified=false;
if ($_GET["y"] < 0) $qualified=false;
if ($_GET["y"] > 9999) $qualified=false;
} }
// If parameters provided, we show calendar // If parameters provided, we show calendar
if ($qualified) if ($qualified)
{ {
//print $_GET["cm"].",".$_GET["sd"].",".$_GET["m"].",".$_GET["y"];exit; //print $_GET["cm"].",".$_GET["sd"].",".$_GET["m"].",".$_GET["y"];exit;
displayBox(GETPOST("sd",'alpha'),GETPOST("m",'int'),GETPOST("y",'int')); displayBox(GETPOST("sd",'alpha'), GETPOST("m",'int'), GETPOST("y",'int'));
} }
else else
{ {
dol_print_error('','ErrorBadParameters'); dol_print_error('', 'ErrorBadParameters');
} }
@ -195,9 +193,7 @@ function displayBox($selectedDate,$month,$year)
{ {
echo '<td width="', (int) (($i+1)*100/7) - (int) ($i*100/7), '%">', $langs->trans($day_names[($i + $startday) % 7]), '</td>', "\n"; echo '<td width="', (int) (($i+1)*100/7) - (int) ($i*100/7), '%">', $langs->trans($day_names[($i + $startday) % 7]), '</td>', "\n";
} }
?> print '</tr>';
</tr>
<?php
//print "x ".$thedate." y"; // $thedate = first day of month //print "x ".$thedate." y"; // $thedate = first day of month
$firstdate=dol_getdate($thedate); $firstdate=dol_getdate($thedate);
//var_dump($firstdateofweek); //var_dump($firstdateofweek);
@ -210,7 +206,7 @@ function displayBox($selectedDate,$month,$year)
//print_r($mydate); //print_r($mydate);
if ($mydate < $firstdate) // At first run if ($mydate < $firstdate) // At first run
{ {
echo "<TR class=\"dpWeek\">"; echo "<tr class=\"dpWeek\">";
//echo $conf->global->MAIN_START_WEEK.' '.$firstdate["wday"].' '.$startday; //echo $conf->global->MAIN_START_WEEK.' '.$firstdate["wday"].' '.$startday;
$cols=0; $cols=0;
for ($i = 0; $i < 7; $i++) for ($i = 0; $i < 7; $i++)
@ -221,7 +217,7 @@ function displayBox($selectedDate,$month,$year)
$mydate = $firstdate; $mydate = $firstdate;
break; break;
} }
echo "<TD>&nbsp;</TD>"; echo "<td>&nbsp;</td>";
$cols++; $cols++;
} }
} }
@ -229,7 +225,7 @@ function displayBox($selectedDate,$month,$year)
{ {
if ($mydate["wday"] == $startday) if ($mydate["wday"] == $startday)
{ {
echo "<TR class=\"dpWeek\">"; echo "<tr class=\"dpWeek\">";
$cols=0; $cols=0;
} }
} }
@ -245,17 +241,17 @@ function displayBox($selectedDate,$month,$year)
} }
// Sur click dans calendrier, appelle fonction dpClickDay // Sur click dans calendrier, appelle fonction dpClickDay
echo "<TD class=\"".$dayclass."\""; echo "<td class=\"".$dayclass."\"";
echo " onMouseOver=\"dpHighlightDay(".$mydate["year"].",parseInt('".dol_print_date($thedate,"%m")."',10),".$mydate["mday"].",tradMonths)\""; echo " onMouseOver=\"dpHighlightDay(".$mydate["year"].",parseInt('".dol_print_date($thedate,"%m")."',10),".$mydate["mday"].",tradMonths)\"";
echo " onClick=\"dpClickDay(".$mydate["year"].",parseInt('".dol_print_date($thedate,"%m")."',10),".$mydate["mday"].",'".$langs->trans("FormatDateShortJavaInput")."')\""; echo " onClick=\"dpClickDay(".$mydate["year"].",parseInt('".dol_print_date($thedate,"%m")."',10),".$mydate["mday"].",'".$langs->trans("FormatDateShortJavaInput")."')\"";
echo ">".sprintf("%02s",$mydate["mday"])."</TD>"; echo ">".sprintf("%02s",$mydate["mday"])."</td>";
$cols++; $cols++;
if (($mydate["wday"] + 1) % 7 == $startday) echo "</TR>\n"; if (($mydate["wday"] + 1) % 7 == $startday) echo "</TR>\n";
//$thedate=strtotime("tomorrow",$thedate); //$thedate=strtotime("tomorrow",$thedate);
$day++; $day++;
$thedate=dol_mktime(12,0,0,$month,$day,$year); $thedate=dol_mktime(12, 0, 0, $month, $day, $year);
if ($thedate == '') if ($thedate == '')
{ {
$stoploop=1; $stoploop=1;
@ -269,8 +265,8 @@ function displayBox($selectedDate,$month,$year)
if ($cols < 7) if ($cols < 7)
{ {
for($i=6; $i>=$cols; $i--) echo "<TD>&nbsp;</TD>"; for($i=6; $i>=$cols; $i--) echo "<td>&nbsp;</td>";
echo "</TR>\n"; echo "</tr>\n";
} }
?> ?>
<tr> <tr>