2006-03-12 00:03:05 +01:00
|
|
|
|
<?php
|
|
|
|
|
|
/* Copyright (C) phpBSM
|
2007-09-09 15:55:00 +02:00
|
|
|
|
* Copyright (C) 2005-2007 Laurent Destailleur <eldy@users.sourceforge.net>
|
2007-11-01 21:39:36 +01:00
|
|
|
|
* Copyright (C) 2005-2007 Regis Houssin <regis@dolibarr.fr>
|
2007-12-03 04:52:57 +01:00
|
|
|
|
*
|
2007-09-09 15:55:00 +02:00
|
|
|
|
* This file is a modified version of datepicker.php from phpBSM to fix some
|
|
|
|
|
|
* bugs, to add new features and to dramatically increase speed.
|
2006-03-12 00:03:05 +01:00
|
|
|
|
*
|
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
|
*
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
*
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
\file htdocs/lib/datepicker.php
|
|
|
|
|
|
\brief Fichier de gestion de la popup de selection de date eldy
|
2008-01-20 22:53:43 +01:00
|
|
|
|
\version $Id$
|
2006-03-12 00:03:05 +01:00
|
|
|
|
*/
|
2007-12-03 04:52:57 +01:00
|
|
|
|
|
2007-09-09 13:16:33 +02:00
|
|
|
|
if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1');
|
|
|
|
|
|
//if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
|
|
|
|
|
|
if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
|
|
|
|
|
|
//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); // Not disabled cause need to do translations
|
2006-03-12 00:03:05 +01:00
|
|
|
|
|
2008-01-20 22:53:43 +01:00
|
|
|
|
// This is to make Dolibarr working with Plesk
|
|
|
|
|
|
set_include_path($_SERVER['DOCUMENT_ROOT'].'/htdocs');
|
|
|
|
|
|
|
2006-03-12 00:03:05 +01:00
|
|
|
|
require_once("../master.inc.php");
|
2007-09-09 13:16:33 +02:00
|
|
|
|
|
2008-01-26 21:22:40 +01:00
|
|
|
|
$langs->load("main");
|
|
|
|
|
|
|
2007-09-09 13:16:33 +02:00
|
|
|
|
|
2007-12-03 04:52:57 +01:00
|
|
|
|
// URL http://mydolibarr/lib/datepicker.php?mode=test&m=10&y=2038 can be used for tests
|
2008-01-26 21:22:40 +01:00
|
|
|
|
print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'."\n";
|
|
|
|
|
|
print '<html><head>';
|
2007-09-09 15:55:00 +02:00
|
|
|
|
if (isset($_GET["mode"]) && $_GET["mode"] == 'test')
|
|
|
|
|
|
{
|
2008-10-06 23:31:05 +02:00
|
|
|
|
print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/lib/lib_head.js"></script>'."\n";
|
2007-12-21 18:18:32 +01:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2008-01-26 21:22:40 +01:00
|
|
|
|
print '<title>Calendar</title>';
|
2007-09-09 15:55:00 +02:00
|
|
|
|
}
|
2008-01-26 21:22:40 +01:00
|
|
|
|
// Define tradMonths javascript array
|
|
|
|
|
|
$tradTemp=array($langs->trans("January"),
|
|
|
|
|
|
$langs->trans("February"),
|
|
|
|
|
|
$langs->trans("March"),
|
|
|
|
|
|
$langs->trans("April"),
|
|
|
|
|
|
$langs->trans("May"),
|
|
|
|
|
|
$langs->trans("June"),
|
|
|
|
|
|
$langs->trans("July"),
|
|
|
|
|
|
$langs->trans("August"),
|
|
|
|
|
|
$langs->trans("September"),
|
|
|
|
|
|
$langs->trans("October"),
|
|
|
|
|
|
$langs->trans("November"),
|
|
|
|
|
|
$langs->trans("December")
|
|
|
|
|
|
);
|
2008-10-06 23:31:05 +02:00
|
|
|
|
print '<script type="text/javascript">';
|
2008-01-26 21:22:40 +01:00
|
|
|
|
print 'var tradMonths = '.php2js($tradTemp).';';
|
|
|
|
|
|
print '</script>'."\n";
|
|
|
|
|
|
print '</head><body>'."\n";
|
2007-09-09 15:55:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
2007-12-03 05:03:49 +01:00
|
|
|
|
$qualified=true;
|
2006-03-12 00:03:05 +01:00
|
|
|
|
|
2007-12-03 05:03:49 +01:00
|
|
|
|
if (! isset($_GET["sd"])) $_GET["sd"]="00000000";
|
|
|
|
|
|
|
|
|
|
|
|
if (! isset($_GET["m"])) $qualified=false;
|
|
|
|
|
|
if (! isset($_GET["y"])) $qualified=false;
|
2007-12-03 04:52:57 +01:00
|
|
|
|
if (isset($_GET["m"]) && isset($_GET["y"]))
|
2007-12-03 05:03:49 +01:00
|
|
|
|
{
|
|
|
|
|
|
if ($_GET["m"] < 1) $qualified=false;
|
|
|
|
|
|
if ($_GET["m"] > 12) $qualified=false;
|
|
|
|
|
|
if ($_GET["y"] < 0) $qualified=false;
|
|
|
|
|
|
if ($_GET["y"] > 9999) $qualified=false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If parameters provided, we show calendar
|
|
|
|
|
|
if ($qualified)
|
2006-03-12 00:03:05 +01:00
|
|
|
|
{
|
2007-12-03 04:52:57 +01:00
|
|
|
|
//print $_GET["cm"].",".$_GET["sd"].",".$_GET["m"].",".$_GET["y"];exit;
|
|
|
|
|
|
displayBox($_GET["sd"],$_GET["m"],$_GET["y"]);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2009-02-20 23:53:15 +01:00
|
|
|
|
dol_print_error('','ErrorBadParameters');
|
2006-03-12 00:03:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-12-21 18:18:32 +01:00
|
|
|
|
print '</body></html>'."\n";
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-03-12 00:03:05 +01:00
|
|
|
|
function xyzToUnixTimestamp($mysqldate){
|
|
|
|
|
|
$year=substr($mysqldate,0,4);
|
|
|
|
|
|
$month=substr($mysqldate,4,2);
|
|
|
|
|
|
$day=substr($mysqldate,6,2);
|
2009-02-20 23:53:15 +01:00
|
|
|
|
$unixtimestamp=dol_mktime(12,0,0,$month,$day,$year);
|
2006-03-12 00:03:05 +01:00
|
|
|
|
return $unixtimestamp;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function displayBox($selectedDate,$month,$year){
|
2006-03-12 00:51:59 +01:00
|
|
|
|
global $dolibarr_main_url_root,$langs,$conf;
|
2006-03-12 00:03:05 +01:00
|
|
|
|
|
|
|
|
|
|
//print "$selectedDate,$month,$year";
|
2009-02-20 23:53:15 +01:00
|
|
|
|
$thedate=dol_mktime(12,0,0,$month,1,$year);
|
2007-09-09 15:55:00 +02:00
|
|
|
|
//print "thedate=$thedate";
|
|
|
|
|
|
$today=mktime();
|
2009-01-07 11:57:36 +01:00
|
|
|
|
$todayArray=dol_getdate($today);
|
2006-03-12 00:03:05 +01:00
|
|
|
|
if($selectedDate != "00000000")
|
|
|
|
|
|
{
|
|
|
|
|
|
$selDate=xyzToUnixTimestamp($selectedDate);
|
2009-02-20 23:53:15 +01:00
|
|
|
|
$xyz=dol_date("Ymd",$selDate);
|
2006-03-12 00:03:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
$selDate=0;
|
|
|
|
|
|
$xyz=0;
|
|
|
|
|
|
}
|
|
|
|
|
|
?>
|
2007-12-21 18:18:32 +01:00
|
|
|
|
<table class="dp" cellspacing="0" cellpadding="0" border="0">
|
2006-03-12 00:03:05 +01:00
|
|
|
|
<tr>
|
2007-12-21 18:18:32 +01:00
|
|
|
|
<td colspan="6" class="dpHead">
|
2007-06-04 17:44:49 +02:00
|
|
|
|
<?php
|
2009-02-20 23:53:15 +01:00
|
|
|
|
$selectMonth = dol_date("F", $thedate);
|
|
|
|
|
|
$selectYear = dol_date("Y", $thedate);
|
2007-06-04 17:44:49 +02:00
|
|
|
|
echo $langs->trans($selectMonth).", ".$selectYear;
|
|
|
|
|
|
?>
|
|
|
|
|
|
</td>
|
2008-01-06 22:53:26 +01:00
|
|
|
|
<td class="dpHead"><button type="button" class="dpInvisibleButtons" id="DPCancel" onClick="closeDPBox();">X</button></td>
|
2006-03-12 00:03:05 +01:00
|
|
|
|
</tr>
|
|
|
|
|
|
<tr>
|
|
|
|
|
|
<td class="dpButtons" onClick="loadMonth('<?php echo $dolibarr_main_url_root.'/lib/' ?>','<?php echo $month?>','<?php echo $year-1?>','<?php echo $xyz ?>')"><<</td>
|
|
|
|
|
|
<td class="dpButtons" onClick="loadMonth('<?php echo $dolibarr_main_url_root.'/lib/' ?>','<?php if($month==1) echo "12"; else echo $month-1?>','<?php if($month==1) echo $year-1; else echo $year?>','<?php echo $xyz ?>')"><</td>
|
2009-02-20 23:53:15 +01:00
|
|
|
|
<td colspan="3" class="dpButtons" onClick="loadMonth('<?php echo $dolibarr_main_url_root.'/lib/' ?>','<?php echo dol_date('m',$today)?>','<?php echo $todayArray["year"]?>','<?php echo $xyz ?>')"><?php echo $langs->trans("MonthOfDay") ?></td>
|
2006-03-12 00:03:05 +01:00
|
|
|
|
<td class="dpButtons" onClick="loadMonth('<?php echo $dolibarr_main_url_root.'/lib/' ?>','<?php if($month==12) echo "1"; else echo $month+1?>','<?php if($month==12) echo $year+1; else echo $year;?>','<?php echo $xyz ?>')">></td>
|
|
|
|
|
|
<td class="dpButtons" onClick="loadMonth('<?php echo $dolibarr_main_url_root.'/lib/' ?>','<?php echo $month?>','<?php echo $year+1?>','<?php echo $xyz ?>')">>></td>
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
<tr class="dpDayNames">
|
2008-01-06 22:53:26 +01:00
|
|
|
|
<td width="14%"><?php echo $langs->trans("ShortSunday") ?></td>
|
|
|
|
|
|
<td width="14%"><?php echo $langs->trans("ShortMonday") ?></td>
|
|
|
|
|
|
<td width="15%"><?php echo $langs->trans("ShortTuesday") ?></td>
|
|
|
|
|
|
<td width="14%"><?php echo $langs->trans("ShortWednesday") ?></td>
|
|
|
|
|
|
<td width="15%"><?php echo $langs->trans("ShortThursday") ?></td>
|
|
|
|
|
|
<td width="14%"><?php echo $langs->trans("ShortFriday") ?></td>
|
|
|
|
|
|
<td width="14%"><?php echo $langs->trans("ShortSaturday") ?></td>
|
2006-03-12 00:03:05 +01:00
|
|
|
|
</tr>
|
2008-01-06 22:53:26 +01:00
|
|
|
|
<?php
|
2007-09-09 15:55:00 +02:00
|
|
|
|
//print "x ".$thedate." y";
|
2009-01-07 11:57:36 +01:00
|
|
|
|
$firstdate=dol_getdate($thedate);
|
2006-03-12 00:03:05 +01:00
|
|
|
|
$mydate=$firstdate;
|
2007-06-04 22:03:40 +02:00
|
|
|
|
|
2007-09-09 15:55:00 +02:00
|
|
|
|
// Loop on each day of month
|
2008-01-06 22:53:26 +01:00
|
|
|
|
$stoploop=0; $day=1; $cols=0;
|
|
|
|
|
|
while (! $stoploop)
|
2006-03-12 00:03:05 +01:00
|
|
|
|
{
|
2007-09-09 15:55:00 +02:00
|
|
|
|
//print_r($mydate);
|
2008-01-06 22:53:26 +01:00
|
|
|
|
if($firstdate==$mydate) // At first run
|
|
|
|
|
|
{
|
2006-03-12 00:03:05 +01:00
|
|
|
|
echo "<TR class=\"dpWeek\">";
|
2008-01-06 22:53:26 +01:00
|
|
|
|
$cols=0;
|
|
|
|
|
|
for($i=0;$i< $mydate["wday"];$i++)
|
|
|
|
|
|
{
|
2006-03-12 00:03:05 +01:00
|
|
|
|
echo "<TD> </TD>";
|
2008-01-06 22:53:26 +01:00
|
|
|
|
$cols++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($mydate["wday"]==0)
|
|
|
|
|
|
{
|
|
|
|
|
|
echo "<TR class=\"dpWeek\">";
|
|
|
|
|
|
$cols=0;
|
|
|
|
|
|
}
|
2006-03-12 00:03:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$dayclass="dpReg";
|
|
|
|
|
|
if($thedate==$selDate) $dayclass="dpSelected";
|
|
|
|
|
|
elseif($thedate==$today) $dayclass="dpToday";
|
|
|
|
|
|
|
|
|
|
|
|
// Sur click dans calendrier, appelle fonction dpClickDay
|
2006-03-12 00:51:59 +01:00
|
|
|
|
echo "<TD class=\"".$dayclass."\"";
|
2009-02-20 23:53:15 +01:00
|
|
|
|
echo " onMouseOver=\"dpHighlightDay(".$mydate["year"].",".dol_date("n",$thedate).",".$mydate["mday"].",tradMonths)\"";
|
|
|
|
|
|
echo " onClick=\"dpClickDay(".$mydate["year"].",".dol_date("n",$thedate).",".$mydate["mday"].",'".$conf->format_date_short_java."')\"";
|
2006-03-12 00:51:59 +01:00
|
|
|
|
echo ">".sprintf("%02s",$mydate["mday"])."</TD>";
|
2008-01-06 22:53:26 +01:00
|
|
|
|
$cols++;
|
|
|
|
|
|
|
|
|
|
|
|
if ($mydate["wday"]==6) echo "</TR>\n";
|
2006-03-12 00:03:05 +01:00
|
|
|
|
|
2007-09-09 15:55:00 +02:00
|
|
|
|
//$thedate=strtotime("tomorrow",$thedate);
|
|
|
|
|
|
$day++;
|
2009-02-20 23:53:15 +01:00
|
|
|
|
$thedate=dol_mktime(12,0,0,$month,$day,$year);
|
2008-01-06 22:53:26 +01:00
|
|
|
|
if ($thedate == '')
|
|
|
|
|
|
{
|
|
|
|
|
|
$stoploop=1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2009-01-07 11:57:36 +01:00
|
|
|
|
$mydate=dol_getdate($thedate);
|
2008-01-06 22:53:26 +01:00
|
|
|
|
if ($firstdate["month"] != $mydate["month"]) $stoploop=1;
|
|
|
|
|
|
}
|
2006-03-12 00:03:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2008-01-06 22:53:26 +01:00
|
|
|
|
if ($cols < 7)
|
|
|
|
|
|
{
|
|
|
|
|
|
for($i=6; $i>=$cols; $i--) echo "<TD> </TD>";
|
|
|
|
|
|
echo "</TR>\n";
|
2006-03-12 00:03:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
?>
|
|
|
|
|
|
<tr><td id="dpExp" class="dpExplanation" colspan="7"><?php
|
|
|
|
|
|
if($selDate)
|
|
|
|
|
|
{
|
2009-01-07 11:57:36 +01:00
|
|
|
|
$tempDate=dol_getdate($selDate);
|
2008-01-07 10:19:39 +01:00
|
|
|
|
print $langs->trans($selectMonth)." ";
|
2006-03-12 00:03:05 +01:00
|
|
|
|
print sprintf("%02s",$tempDate["mday"]);
|
2008-01-07 10:19:39 +01:00
|
|
|
|
print ", ".$selectYear;
|
2006-03-12 00:03:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
else
|
2008-01-07 10:19:39 +01:00
|
|
|
|
{
|
2006-03-12 00:03:05 +01:00
|
|
|
|
print "Click a Date";
|
2008-01-07 10:19:39 +01:00
|
|
|
|
}
|
2006-03-12 00:03:05 +01:00
|
|
|
|
?></td></tr>
|
|
|
|
|
|
</table>
|
|
|
|
|
|
<?php
|
|
|
|
|
|
}//end function
|
2008-01-26 21:22:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* \brief Convertit une variable php en variable javascript
|
|
|
|
|
|
* \param var variable php
|
|
|
|
|
|
* \return result variable javascript
|
|
|
|
|
|
*/
|
|
|
|
|
|
function php2js($var)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (is_array($var))
|
|
|
|
|
|
{
|
|
|
|
|
|
$array = array();
|
|
|
|
|
|
foreach ($var as $a_var)
|
|
|
|
|
|
{
|
|
|
|
|
|
$array[] = php2js($a_var);
|
|
|
|
|
|
}
|
|
|
|
|
|
$result = "[" . join(",", $array) . "]";
|
|
|
|
|
|
return $result;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (is_bool($var))
|
|
|
|
|
|
{
|
|
|
|
|
|
$result = $var ? "true" : "false";
|
|
|
|
|
|
return $result;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (is_int($var) || is_integer($var) || is_double($var) || is_float($var))
|
|
|
|
|
|
{
|
|
|
|
|
|
$result = $var;
|
|
|
|
|
|
return $result;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (is_string($var))
|
|
|
|
|
|
{
|
|
|
|
|
|
$result = "\"" . addslashes(stripslashes($var)) . "\"";
|
|
|
|
|
|
return $result;
|
|
|
|
|
|
}
|
|
|
|
|
|
// autres cas: objets, on ne les g<>re pas
|
|
|
|
|
|
$result = FALSE;
|
|
|
|
|
|
return $result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2006-03-12 00:03:05 +01:00
|
|
|
|
?>
|