dolibarr 21.0.0-beta
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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
8 *
9 * This file is a modified version of datepicker.php from phpBSM to fix some
10 * bugs, to add new features and to dramatically increase speed.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 */
25
31if (!defined('NOREQUIREUSER')) {
32 define('NOREQUIREUSER', '1'); // disabled
33}
34//if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
35if (!defined('NOREQUIRESOC')) {
36 define('NOREQUIRESOC', '1');
37}
38//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); // Not disabled cause need to do translations
39if (!defined('NOCSRFCHECK')) {
40 define('NOCSRFCHECK', 1);
41}
42if (!defined('NOTOKENRENEWAL')) {
43 define('NOTOKENRENEWAL', 1);
44}
45if (!defined('NOLOGIN')) {
46 define('NOLOGIN', 1); // disabled
47}
48if (!defined('NOREQUIREMENU')) {
49 define('NOREQUIREMENU', 1);
50}
51if (!defined('NOREQUIREHTML')) {
52 define('NOREQUIREHTML', 1);
53}
54
55require_once '../main.inc.php';
56require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
57
66if (GETPOST('lang', 'aZ09')) {
67 $langs->setDefaultLang(GETPOST('lang', 'aZ09')); // If language was forced on URL by the main.inc.php
68}
69
70// Load translation files required by the page
71$langs->loadLangs(array("main", "agenda"));
72
73$right = ($langs->trans("DIRECTION") == 'rtl' ? 'left' : 'right');
74$left = ($langs->trans("DIRECTION") == 'rtl' ? 'right' : 'left');
75
76//var_dump($langs->defaultlang);
77//var_dump($conf->format_date_short_java);
78//var_dump($langs->trans("FormatDateShortJava"));
79
80
81// URL http://mydolibarr/core/datepicker.php?mode=test&m=10&y=2038 can be used for tests
82print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'."\n";
83print '<html>'."\n";
84print '<head>'."\n";
85if (GETPOST('mode') && GETPOST('mode') == 'test') {
86 print '<script nonce="'.getNonce().'" type="text/javascript" src="'.DOL_URL_ROOT.'/core/js/lib_head.js.php"></script>'."\n";
87} else {
88 print '<title>'.$langs->trans("Calendar").'</title>';
89}
90
91// Define tradMonths javascript array (we define this in datapicker AND in parent page to avoid errors with IE8)
92$tradTemp = array(
93 $langs->trans("January"),
94 $langs->trans("February"),
95 $langs->trans("March"),
96 $langs->trans("April"),
97 $langs->trans("May"),
98 $langs->trans("June"),
99 $langs->trans("July"),
100 $langs->trans("August"),
101 $langs->trans("September"),
102 $langs->trans("October"),
103 $langs->trans("November"),
104 $langs->trans("December")
105);
106print '<script nonce="'.getNonce().'" type="text/javascript">';
107print 'var tradMonths = [';
108foreach ($tradTemp as $val) {
109 print '"'.addslashes($val).'",';
110}
111print '""];';
112print '</script>'."\n";
113print '</head>'."\n";
114
115print '<body>'."\n";
116
117
118$qualified = true;
119
120// TODO Replace with GETPOST
121if (!isset($_GET["sd"])) {
122 $_GET["sd"] = "00000000";
123}
124if (!isset($_GET["m"]) || !isset($_GET["y"])) {
125 $qualified = false;
126}
127if (isset($_GET["m"]) && isset($_GET["y"])) {
128 if ($_GET["m"] < 1 || $_GET["m"] > 12) {
129 $qualified = false;
130 }
131 if ($_GET["y"] < 0 || $_GET["y"] > 9999) {
132 $qualified = false;
133 }
134}
135
136// If parameters provided, we show calendar
137if ($qualified) {
138 displayBox(GETPOST("sd", 'alpha'), GETPOSTINT("m"), GETPOSTINT("y"));
139} else {
140 dol_print_error(null, 'ErrorBadParameters');
141}
142
143
144print '</body></html>'."\n";
145
152function xyzToUnixTimestamp($mysqldate)
153{
154 $year = (int) substr($mysqldate, 0, 4);
155 $month = (int) substr($mysqldate, 4, 2);
156 $day = (int) substr($mysqldate, 6, 2);
157 $unixtimestamp = dol_mktime(12, 0, 0, $month, $day, $year);
158
159 return $unixtimestamp;
160}
161
170function displayBox($selectedDate, $month, $year)
171{
172 global $langs, $conf;
173
174 //print "$selectedDate,$month,$year";
175 $thedate = dol_mktime(12, 0, 0, $month, 1, $year);
176 //print "thedate=$thedate";
177 $today = dol_now();
178 $todayArray = dol_getdate($today);
179 if ($selectedDate != "00000000") {
180 $selDate = xyzToUnixTimestamp($selectedDate);
181 $xyz = dol_print_date($selDate, "%Y%m%d");
182 } else {
183 $selDate = 0;
184 $xyz = 0;
185 } ?>
186<table class="dp">
187 <tr>
188 <td colspan="6" class="dpHead"><?php
189 $selectMonth = dol_print_date($thedate, '%m');
190 $selectYear = dol_print_date($thedate, '%Y');
191 echo $langs->trans("Month".$selectMonth).", ".$selectYear; ?></td>
192 <td class="dpHead">
193 <button type="button" class="dpInvisibleButtons" id="DPCancel"
194 onClick="closeDPBox();">X</button>
195 </td>
196 </tr>
197 <tr>
198 <td class="dpButtons"
199 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>
200 <td class="dpButtons"
201 onClick="loadMonth('<?php echo DOL_URL_ROOT.'/core/' ?>','<?php if ($month == 1) {
202 echo "12";
203 } else {
204 echo $month - 1;
205 } ?>','<?php if ($month == 1) {
206 echo $year - 1;
207 } else {
208 echo $year;
209 } ?>','<?php echo $xyz ?>','<?php echo $langs->defaultlang ?>')">&lt;</td>
210 <td colspan="3" class="dpButtons"
211 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>
212 <td class="dpButtons"
213 onClick="loadMonth('<?php echo DOL_URL_ROOT.'/core/' ?>','<?php if ($month == 12) {
214 echo "1";
215 } else {
216 echo $month + 1;
217 } ?>','<?php if ($month == 12) {
218 echo $year + 1;
219 } else {
220 echo $year;
221 } ?>','<?php echo $xyz ?>','<?php echo $langs->defaultlang ?>')">&gt;</td>
222 <td class="dpButtons"
223 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>
224 </tr>
225 <tr class="dpDayNames">
226 <?php
227 $startday = isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1;
228 $day_names = array('ShortSunday', 'ShortMonday', 'ShortTuesday', 'ShortWednesday', 'ShortThursday', 'ShortFriday', 'ShortSaturday');
229 for ($i = 0; $i < 7; $i++) {
230 echo '<td width="', (int) (($i + 1) * 100 / 7) - (int) ($i * 100 / 7), '%">', $langs->trans($day_names[($i + $startday) % 7]), '</td>', "\n";
231 }
232 print '</tr>';
233 //print "x ".$thedate." y"; // $thedate = first day of month
234 $firstdate = dol_getdate($thedate);
235 //var_dump($firstdateofweek);
236 $mydate = dol_get_first_day_week(1, $month, $year, true); // mydate = cursor date
237
238 // Loop on each day of month
239 $stoploop = 0;
240 $day = 1;
241 $cols = 0;
242 while (!$stoploop) {
243 //print_r($mydate);
244 if ($mydate < $firstdate) { // At first run
245 echo "<tr class=\"dpWeek\">";
246 //echo $conf->global->MAIN_START_WEEK.' '.$firstdate["wday"].' '.$startday;
247 $cols = 0;
248 for ($i = 0; $i < 7; $i++) {
249 $w = ($i + $startday) % 7;
250 if ($w == $firstdate["wday"]) {
251 $mydate = $firstdate;
252 break;
253 }
254 echo "<td>&nbsp;</td>";
255 $cols++;
256 }
257 } else {
258 if ($mydate["wday"] == $startday) {
259 echo "<tr class=\"dpWeek\">";
260 $cols = 0;
261 }
262 }
263
264 $dayclass = "dpReg";
265 if ($thedate == $selDate) {
266 $dayclass = "dpSelected";
267 } elseif ($thedate == $today) {
268 $dayclass = "dpToday";
269 }
270
271 if ($langs->trans("FormatDateShortJavaInput") == "FormatDateShortJavaInput") {
272 print "ERROR FormatDateShortJavaInput not defined for language ".$langs->defaultlang;
273 exit;
274 }
275
276 // Sur click dans calendrier, appelle fonction dpClickDay
277 echo "<td class=\"".$dayclass."\"";
278 echo " onMouseOver=\"dpHighlightDay(".$mydate["year"].",parseInt('".dol_print_date($thedate, "%m")."',10),".$mydate["mday"].",tradMonths)\"";
279 echo " onClick=\"dpClickDay(".$mydate["year"].",parseInt('".dol_print_date($thedate, "%m")."',10),".$mydate["mday"].",'".$langs->trans("FormatDateShortJavaInput")."')\"";
280 echo ">".sprintf("%02d", $mydate["mday"])."</td>";
281 $cols++;
282
283 if (($mydate["wday"] + 1) % 7 == $startday) {
284 echo "</TR>\n";
285 }
286
287 //$thedate=strtotime("tomorrow",$thedate);
288 $day++;
289 $thedate = dol_mktime(12, 0, 0, $month, $day, $year);
290 if ($thedate == '') {
291 $stoploop = 1;
292 } else {
293 $mydate = dol_getdate($thedate);
294 if ($firstdate["month"] != $mydate["month"]) {
295 $stoploop = 1;
296 }
297 }
298 }
299
300 if ($cols < 7) {
301 for ($i = 6; $i >= $cols; $i--) {
302 echo "<td>&nbsp;</td>";
303 }
304 echo "</tr>\n";
305 } ?>
306 <tr>
307 <td id="dpExp" class="dpExplanation" colspan="7"><?php
308 if ($selDate) {
309 $tempDate = dol_getdate($selDate);
310 print $langs->trans("Month".$selectMonth)." ";
311 print sprintf("%02d", $tempDate["mday"]);
312 print ", ".$selectYear;
313 } else {
314 print "Click a Date";
315 } ?></td>
316 </tr>
317</table>
318 <?php
319}//end function
dol_get_first_day_week($day, $month, $year, $gm=false)
Return first day of week for a date.
Definition date.lib.php:675
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
treeview li table
No Email.
ui state ui widget content ui state ui widget header ui state a ui button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:149