dolibarr  13.0.2
datepicker.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) phpBSM
3  * Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2007 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
6  *
7  * This file is a modified version of datepicker.php from phpBSM to fix some
8  * bugs, to add new features and to dramatically increase speed.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <https://www.gnu.org/licenses/>.
22  */
23 
29 if (!defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // disabled
30 //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
31 if (!defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1');
32 //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); // Not disabled cause need to do translations
33 if (!defined('NOCSRFCHECK')) define('NOCSRFCHECK', 1);
34 if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', 1);
35 if (!defined('NOLOGIN')) define('NOLOGIN', 1); // disabled
36 if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', 1);
37 if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', 1);
38 
39 require_once '../main.inc.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
41 
42 if (GETPOST('lang', 'aZ09')) $langs->setDefaultLang(GETPOST('lang', 'aZ09')); // If language was forced on URL by the main.inc.php
43 
44 // Load translation files required by the page
45 $langs->loadLangs(array("main", "agenda"));
46 
47 $right = ($langs->trans("DIRECTION") == 'rtl' ? 'left' : 'right');
48 $left = ($langs->trans("DIRECTION") == 'rtl' ? 'right' : 'left');
49 
50 //var_dump($langs->defaultlang);
51 //var_dump($conf->format_date_short_java);
52 //var_dump($langs->trans("FormatDateShortJava"));
53 
54 
55 // URL http://mydolibarr/core/datepicker.php?mode=test&m=10&y=2038 can be used for tests
56 print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'."\n";
57 print '<html>'."\n";
58 print '<head>'."\n";
59 if (GETPOST('mode') && GETPOST('mode') == 'test')
60 {
61  print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/core/js/lib_head.js.php"></script>'."\n";
62 } else {
63  print '<title>'.$langs->trans("Calendar").'</title>';
64 }
65 
66 // Define tradMonths javascript array (we define this in datapicker AND in parent page to avoid errors with IE8)
67 $tradTemp = array(
68  $langs->trans("January"),
69  $langs->trans("February"),
70  $langs->trans("March"),
71  $langs->trans("April"),
72  $langs->trans("May"),
73  $langs->trans("June"),
74  $langs->trans("July"),
75  $langs->trans("August"),
76  $langs->trans("September"),
77  $langs->trans("October"),
78  $langs->trans("November"),
79  $langs->trans("December")
80 );
81 print '<script type="text/javascript">';
82 print 'var tradMonths = [';
83 foreach ($tradTemp as $val)
84 {
85  print '"'.addslashes($val).'",';
86 }
87 print '""];';
88 print '</script>'."\n";
89 print '</head>'."\n";
90 
91 print '<body>'."\n";
92 
93 
94 $qualified = true;
95 
96 if (!isset($_GET["sd"])) $_GET["sd"] = "00000000";
97 
98 if (!isset($_GET["m"]) || !isset($_GET["y"])) $qualified = false;
99 if (isset($_GET["m"]) && isset($_GET["y"]))
100 {
101  if ($_GET["m"] < 1 || $_GET["m"] > 12) $qualified = false;
102  if ($_GET["y"] < 0 || $_GET["y"] > 9999) $qualified = false;
103 }
104 
105 // If parameters provided, we show calendar
106 if ($qualified)
107 {
108  //print $_GET["cm"].",".$_GET["sd"].",".$_GET["m"].",".$_GET["y"];exit;
109  displayBox(GETPOST("sd", 'alpha'), GETPOST("m", 'int'), GETPOST("y", 'int'));
110 } else {
111  dol_print_error('', 'ErrorBadParameters');
112 }
113 
114 
115 print '</body></html>'."\n";
116 
123 function xyzToUnixTimestamp($mysqldate)
124 {
125  $year = substr($mysqldate, 0, 4);
126  $month = substr($mysqldate, 4, 2);
127  $day = substr($mysqldate, 6, 2);
128  $unixtimestamp = dol_mktime(12, 0, 0, $month, $day, $year);
129  return $unixtimestamp;
130 }
131 
140 function displayBox($selectedDate, $month, $year)
141 {
142  global $langs, $conf;
143 
144  //print "$selectedDate,$month,$year";
145  $thedate = dol_mktime(12, 0, 0, $month, 1, $year);
146  //print "thedate=$thedate";
147  $today = dol_now();
148  $todayArray = dol_getdate($today);
149  if ($selectedDate != "00000000")
150  {
151  $selDate = xyzToUnixTimestamp($selectedDate);
152  $xyz = dol_print_date($selDate, "%Y%m%d");
153  } else {
154  $selDate = 0;
155  $xyz = 0;
156  }
157  ?>
158 <table class="dp">
159  <tr>
160  <td colspan="6" class="dpHead"><?php
161  $selectMonth = dol_print_date($thedate, '%m');
162  $selectYear = dol_print_date($thedate, '%Y');
163  echo $langs->trans("Month".$selectMonth).", ".$selectYear;
164  ?></td>
165  <td class="dpHead">
166  <button type="button" class="dpInvisibleButtons" id="DPCancel"
167  onClick="closeDPBox();">X</button>
168  </td>
169  </tr>
170  <tr>
171  <td class="dpButtons"
172  onClick="loadMonth('<?php echo DOL_URL_ROOT.'/core/' ?>','<?php echo $month?>','<?php echo $year - 1?>','<?php echo $xyz ?>','<?php echo $langs->defaultlang ?>')">&lt;&lt;</td>
173  <td class="dpButtons"
174  onClick="loadMonth('<?php echo DOL_URL_ROOT.'/core/' ?>','<?php if ($month == 1) echo "12"; else echo $month - 1?>','<?php if ($month == 1) echo $year - 1; else echo $year?>','<?php echo $xyz ?>','<?php echo $langs->defaultlang ?>')">&lt;</td>
175  <td colspan="3" class="dpButtons"
176  onClick="loadMonth('<?php echo DOL_URL_ROOT.'/core/' ?>','<?php echo (int) dol_print_date($today, '%m')?>','<?php echo $todayArray["year"]?>','<?php echo $xyz ?>','<?php echo $langs->defaultlang ?>')"><?php echo '-' ?></td>
177  <td class="dpButtons"
178  onClick="loadMonth('<?php echo DOL_URL_ROOT.'/core/' ?>','<?php if ($month == 12) echo "1"; else echo $month + 1?>','<?php if ($month == 12) echo $year + 1; else echo $year; ?>','<?php echo $xyz ?>','<?php echo $langs->defaultlang ?>')">&gt;</td>
179  <td class="dpButtons"
180  onClick="loadMonth('<?php echo DOL_URL_ROOT.'/core/' ?>','<?php echo $month?>','<?php echo $year + 1?>','<?php echo $xyz ?>','<?php echo $langs->defaultlang ?>')">&gt;&gt;</td>
181  </tr>
182  <tr class="dpDayNames">
183  <?php
184  $startday = isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1;
185  $day_names = array('ShortSunday', 'ShortMonday', 'ShortTuesday', 'ShortWednesday', 'ShortThursday', 'ShortFriday', 'ShortSaturday');
186  for ($i = 0; $i < 7; $i++)
187  {
188  echo '<td width="', (int) (($i + 1) * 100 / 7) - (int) ($i * 100 / 7), '%">', $langs->trans($day_names[($i + $startday) % 7]), '</td>', "\n";
189  }
190  print '</tr>';
191  //print "x ".$thedate." y"; // $thedate = first day of month
192  $firstdate = dol_getdate($thedate);
193  //var_dump($firstdateofweek);
194  $mydate = dol_get_first_day_week(1, $month, $year, true); // mydate = cursor date
195 
196  // Loop on each day of month
197  $stoploop = 0; $day = 1; $cols = 0;
198  while (!$stoploop)
199  {
200  //print_r($mydate);
201  if ($mydate < $firstdate) // At first run
202  {
203  echo "<tr class=\"dpWeek\">";
204  //echo $conf->global->MAIN_START_WEEK.' '.$firstdate["wday"].' '.$startday;
205  $cols = 0;
206  for ($i = 0; $i < 7; $i++)
207  {
208  $w = ($i + $startday) % 7;
209  if ($w == $firstdate["wday"])
210  {
211  $mydate = $firstdate;
212  break;
213  }
214  echo "<td>&nbsp;</td>";
215  $cols++;
216  }
217  } else {
218  if ($mydate["wday"] == $startday)
219  {
220  echo "<tr class=\"dpWeek\">";
221  $cols = 0;
222  }
223  }
224 
225  $dayclass = "dpReg";
226  if ($thedate == $selDate) $dayclass = "dpSelected";
227  elseif ($thedate == $today) $dayclass = "dpToday";
228 
229  if ($langs->trans("FormatDateShortJavaInput") == "FormatDateShortJavaInput")
230  {
231  print "ERROR FormatDateShortJavaInput not defined for language ".$langs->defaultlang;
232  exit;
233  }
234 
235  // Sur click dans calendrier, appelle fonction dpClickDay
236  echo "<td class=\"".$dayclass."\"";
237  echo " onMouseOver=\"dpHighlightDay(".$mydate["year"].",parseInt('".dol_print_date($thedate, "%m")."',10),".$mydate["mday"].",tradMonths)\"";
238  echo " onClick=\"dpClickDay(".$mydate["year"].",parseInt('".dol_print_date($thedate, "%m")."',10),".$mydate["mday"].",'".$langs->trans("FormatDateShortJavaInput")."')\"";
239  echo ">".sprintf("%02s", $mydate["mday"])."</td>";
240  $cols++;
241 
242  if (($mydate["wday"] + 1) % 7 == $startday) echo "</TR>\n";
243 
244  //$thedate=strtotime("tomorrow",$thedate);
245  $day++;
246  $thedate = dol_mktime(12, 0, 0, $month, $day, $year);
247  if ($thedate == '')
248  {
249  $stoploop = 1;
250  } else {
251  $mydate = dol_getdate($thedate);
252  if ($firstdate["month"] != $mydate["month"]) $stoploop = 1;
253  }
254  }
255 
256  if ($cols < 7)
257  {
258  for ($i = 6; $i >= $cols; $i--) echo "<td>&nbsp;</td>";
259  echo "</tr>\n";
260  }
261  ?>
262  <tr>
263  <td id="dpExp" class="dpExplanation" colspan="7"><?php
264  if ($selDate)
265  {
266  $tempDate = dol_getdate($selDate);
267  print $langs->trans("Month".$selectMonth)." ";
268  print sprintf("%02s", $tempDate["mday"]);
269  print ", ".$selectYear;
270  } else {
271  print "Click a Date";
272  }
273  ?></td>
274  </tr>
275 </table>
276  <?php
277 }//end function
xyzToUnixTimestamp($mysqldate)
Convert date to timestamp.
Definition: datepicker.php:123
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_get_first_day_week($day, $month, $year, $gm=false)
Return first day of week for a date.
Definition: date.lib.php:553
dol_now($mode= 'auto')
Return date for now.
dol_getdate($timestamp, $fast=false, $forcetimezone= '')
Return an array with locale date info.
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
displayBox($selectedDate, $month, $year)
Show box.
Definition: datepicker.php:140
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:105