dolibarr 25.0.0-alpha
index.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2003 Eric Seigne <erics@rycks.com>
4 * Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2014 Cedric GROSS <c.gross@kreiz-it.fr>
8 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
9 * Copyright (C) 2017 Open-DSI <support@open-dsi.fr>
10 * Copyright (C) 2021-2026 Frédéric France <frederic.france@free.fr>
11 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
12 * Copyright (C) 2026 Anthony Berton <anthony.berton@bb2a.fr>
13 * Copyright (C) 2026 Joachim Kueter <git-jk@bloxera.com>
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 3 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <https://www.gnu.org/licenses/>.
27 */
28
29
36// Load Dolibarr environment
37require '../../main.inc.php';
45require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
46require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
47require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
48require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
49require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
50require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
51require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
52
53$MAXAGENDA = getDolGlobalString('AGENDA_EXT_NB', 6);
54$DELAYFORCACHE = 300; // 300 seconds
55
56$action = GETPOST('action', 'aZ09');
57$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
58$mode = GETPOST('mode', 'aZ09');
59if (empty($mode) && preg_match('/show_/', $action)) {
60 $mode = $action; // For backward compatibility
61}
62
63$disabledefaultvalues = GETPOSTINT('disabledefaultvalues');
64
65$check_holiday = GETPOSTINT('check_holiday');
66$check_birthday = !empty($conf->use_javascript_ajax) ? GETPOSTINT("check_birthday") : 1;
67$filter = GETPOST("search_filter", 'alpha', 3) ? GETPOST("search_filter", 'alpha', 3) : GETPOST("filter", 'alpha', 3);
68$filtert = GETPOST("search_filtert", "intcomma", 3) ? GETPOST("search_filtert", "intcomma", 3) : GETPOST("filtert", "intcomma", 3);
69$usergroup = GETPOST("search_usergroup", "intcomma", 3) ? GETPOST("search_usergroup", "intcomma", 3) : GETPOST("usergroup", "intcomma", 3);
70$usergroupids = array_map('intval', array_filter(explode(',', $usergroup)));
71$search_categ_cus = GETPOST("search_categ_cus", 'intcomma', 3) ? GETPOST("search_categ_cus", 'intcomma', 3) : 0;
72
73// If no choice done on calendar owner (like on left menu link "Agenda"), we filter on current user by default.
74if (empty($filtert) && !getDolGlobalString('AGENDA_ALL_CALENDARS')) {
75 $filtert = (string) $user->id;
76}
77if (empty($filtert)) {
78 $filtert = -1;
79}
80
81$newparam = '';
82
83// Pagination parameters
84$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
85$sortfield = GETPOST('sortfield', 'aZ09comma');
86$sortorder = GETPOST('sortorder', 'aZ09comma');
87$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
88if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
89 // If $page is not defined, or '' or -1 or if we click on clear filters
90 $page = 0;
91}
92$offset = $limit * $page;
93if (!$sortorder) {
94 $sortorder = "ASC";
95}
96if (!$sortfield) {
97 $sortfield = "a.datec";
98}
99
100// Security check
101$socid = GETPOSTINT("search_socid") ? GETPOSTINT("search_socid") : GETPOSTINT("socid");
102if ($user->socid) {
103 $socid = $user->socid;
104}
105if ($socid < 0) {
106 $socid = '';
107}
108
109$canedit = 1;
110if (!$user->hasRight('agenda', 'myactions', 'read')) {
112}
113if (!$user->hasRight('agenda', 'allactions', 'read')) {
114 $canedit = 0;
115}
116if (!$user->hasRight('agenda', 'allactions', 'read') || $filter == 'mine') { // If no permission to see all, we show only affected to me
117 $filtert = (string) $user->id;
118}
119
120$resourceid = GETPOSTINT("search_resourceid");
121$year = GETPOSTINT("year") ? GETPOSTINT("year") : date("Y");
122$month = GETPOSTINT("month") ? GETPOSTINT("month") : date("m");
123$week = GETPOSTINT("week") ? GETPOSTINT("week") : date("W");
124$day = GETPOSTINT("day") ? GETPOSTINT("day") : date("d");
125$pid = GETPOSTISSET("search_projectid") ? GETPOSTINT("search_projectid", 3) : GETPOSTINT("projectid", 3);
126$status = GETPOSTISSET("search_status") ? GETPOST("search_status", 'aZ09') : GETPOST("status", 'aZ09'); // status may be 0, 50, 100, 'todo', 'na' or -1
127$type = GETPOSTISSET("search_type") ? GETPOST("search_type", 'aZ09') : GETPOST("type", 'aZ09');
128$maxprint = GETPOSTISSET("maxprint") ? GETPOSTINT("maxprint") : getDolGlobalInt('AGENDA_MAX_EVENTS_DAY_VIEW', 3);
129
130$dateselect = dol_mktime(0, 0, 0, GETPOSTINT('dateselectmonth'), GETPOSTINT('dateselectday'), GETPOSTINT('dateselectyear'));
131if ($dateselect > 0) {
132 $day = GETPOSTINT('dateselectday');
133 $month = GETPOSTINT('dateselectmonth');
134 $year = GETPOSTINT('dateselectyear');
135}
136
137// Set actioncode (this code must be same for setting actioncode into peruser, listacton and index)
138if (GETPOST('search_actioncode', 'array:aZ09')) {
139 $actioncode = GETPOST('search_actioncode', 'array:aZ09', 3);
140 if (!count($actioncode)) {
141 $actioncode = '0';
142 }
143} else {
144 $actioncode = GETPOST("search_actioncode", "alpha", 3) ? GETPOST("search_actioncode", "alpha", 3) : (GETPOST("search_actioncode") == '0' ? '0' : ((!getDolGlobalString('AGENDA_DEFAULT_FILTER_TYPE') || $disabledefaultvalues) ? '' : getDolGlobalString('AGENDA_DEFAULT_FILTER_TYPE')));
145}
146if (is_scalar($actioncode) && $actioncode == '-1') {
147 $actioncode = '';
148}
149
150if ($status == '' && !GETPOSTISSET('search_status')) {
151 $status = ((!getDolGlobalString('AGENDA_DEFAULT_FILTER_STATUS') || $disabledefaultvalues) ? '' : getDolGlobalString('AGENDA_DEFAULT_FILTER_STATUS'));
152}
153
154$defaultview = getDolGlobalString('AGENDA_DEFAULT_VIEW', 'show_month'); // default for app
155$defaultview = getDolUserString('AGENDA_DEFAULT_VIEW', $defaultview); // default for user
156if (empty($mode) && !GETPOSTISSET('mode')) {
157 $mode = $defaultview;
158}
159if ($mode == 'default') { // When action is default, we want a calendar view and not the list
160 $mode = (($defaultview != 'show_list') ? $defaultview : 'show_month');
161}
162// View by month
163if (GETPOST('viewcal') && GETPOST('mode') != 'show_day' && GETPOST('mode') != 'show_week') {
164 $mode = 'show_month';
165 $day = '';
166}
167// View by week
168if (GETPOST('viewweek') || GETPOST('mode') == 'show_week') {
169 $mode = 'show_week';
170 $week = ($week ? $week : date("W"));
171 $day = ($day ? $day : date("d"));
172}
173// View by day
174if (GETPOST('viewday') || GETPOST('mode') == 'show_day') {
175 $mode = 'show_day';
176 $day = ($day ? $day : date("d"));
177}
178
179$object = new ActionComm($db);
180
181// Load translation files required by the page
182$langs->loadLangs(array('agenda', 'other', 'commercial'));
183
184// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
185$hookmanager->initHooks(array('agenda'));
186
187$result = restrictedArea($user, 'agenda', 0, 'actioncomm&societe', 'myactions|allactions', 'fk_soc', 'id');
188if ($user->socid && $socid) {
189 $result = restrictedArea($user, 'societe', $socid);
190}
191
192require_once DOL_DOCUMENT_ROOT.'/core/redirect_if_setup_not_complete.inc.php';
193
194
195/*
196 * Actions
197 */
198
199if (GETPOST("viewlist", 'alpha') || $mode == 'show_list') {
200 $param = '';
201 if (is_array($_POST)) {
202 foreach ($_POST as $key => $val) {
203 if ($key == 'token') {
204 continue;
205 }
206 $param .= '&'.urlencode($key).'='.urlencode($val);
207 }
208 }
209 if (!preg_match('/action=/', $param)) {
210 $param .= ($param ? '&' : '').'mode=show_list';
211 }
212 //print $param;
213 header("Location: ".DOL_URL_ROOT.'/comm/action/list.php?'.$param);
214 exit;
215}
216
217if (GETPOST("viewperuser", 'alpha') || $mode == 'show_peruser') {
218 $param = '';
219 if (is_array($_POST)) {
220 foreach ($_POST as $key => $val) {
221 if ($key == 'token') {
222 continue;
223 }
224 $param .= '&'.urlencode($key).'='.urlencode($val);
225 }
226 }
227 //print $param;
228 header("Location: ".DOL_URL_ROOT.'/comm/action/peruser.php?'.$param);
229 exit;
230}
231
232
233/*
234 * View
235 */
236
237$parameters = array(
238 'socid' => $socid,
239 'status' => $status,
240 'year' => $year,
241 'month' => $month,
242 'day' => $day,
243 'type' => $type,
244 'maxprint' => $maxprint,
245 'filter' => $filter,
246 'filtert' => $filtert,
247 'showbirthday' => $check_birthday,
248 'canedit' => $canedit,
249 'optioncss' => $optioncss,
250 'actioncode' => $actioncode,
251 'pid' => $pid,
252 'resourceid' => $resourceid,
253 'usergroup' => $usergroup,
254);
255$reshook = $hookmanager->executeHooks('beforeAgenda', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
256if ($reshook < 0) {
257 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
258}
259
260$form = new Form($db);
261$companystatic = new Societe($db);
262$contactstatic = new Contact($db);
263$userstatic = new User($db);
264
265$help_url = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:M&oacute;dulo_Agenda|DE:Modul_Terminplanung';
266llxHeader('', $langs->trans("Agenda"), $help_url);
267
268$now = dol_now();
269$nowarray = dol_getdate($now);
270$nowyear = $nowarray['year'];
271$nowmonth = $nowarray['mon'];
272$nowday = $nowarray['mday'];
273
274$listofextcals = array();
275
276// Define list of external calendars (global admin setup)
277if (!getDolGlobalString('AGENDA_DISABLE_EXT')) {
278 $i = 0;
279 while ($i < $MAXAGENDA) {
280 $i++;
281 $source = 'AGENDA_EXT_SRC'.$i;
282 $name = 'AGENDA_EXT_NAME'.$i;
283 $offsettz = 'AGENDA_EXT_OFFSETTZ'.$i;
284 $color = 'AGENDA_EXT_COLOR'.$i;
285 $enabled = 'AGENDA_EXT_ENABLED'.$i;
286 $default = 'AGENDA_EXT_ACTIVEBYDEFAULT'.$i;
287 $buggedfile = 'AGENDA_EXT_BUGGEDFILE'.$i;
288 if (getDolGlobalString($source) && getDolGlobalString($name) && getDolGlobalString($enabled)) {
289 // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight'
290 $listofextcals[] = array(
291 'type' => 'globalsetup',
292 'src' => getDolGlobalString($source),
294 'offsettz' => (int) getDolGlobalInt($offsettz, 0),
295 'color' => dol_string_nohtmltag(getDolGlobalString($color)),
296 'cachedelay' => getDolGlobalInt('AGENDA_EXT_CACHE'.$i, 0),
297 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
298 'default' => dol_string_nohtmltag(getDolGlobalString($default)),
299 'buggedfile' => dol_string_nohtmltag(getDolGlobalString($buggedfile, ''))
300 );
301 }
302 }
303}
304
305// Define list of external calendars (user setup)
306if (!getDolGlobalString('AGENDA_DISABLE_EXT')) {
307 $i = 0;
308 while ($i < $MAXAGENDA) {
309 $i++;
310 $source = 'AGENDA_EXT_SRC_'.$user->id.'_'.$i;
311 $name = 'AGENDA_EXT_NAME_'.$user->id.'_'.$i;
312 $offsettz = 'AGENDA_EXT_OFFSETTZ_'.$user->id.'_'.$i;
313 $color = 'AGENDA_EXT_COLOR_'.$user->id.'_'.$i;
314 $enabled = 'AGENDA_EXT_ENABLED_'.$user->id.'_'.$i;
315 $default = 'AGENDA_EXT_ACTIVEBYDEFAULT_'.$user->id.'_'.$i;
316 $buggedfile = 'AGENDA_EXT_BUGGEDFILE_'.$user->id.'_'.$i;
317
318 if (getDolUserString($source) && getDolUserString($name)) {
319 // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight'
320 $listofextcals[] = array(
321 'type' => 'usersetup',
322 'src' => getDolUserString($source),
323 'name' => dol_string_nohtmltag(getDolUserString($name)),
324 'offsettz' => (int) (empty($user->conf->$offsettz) ? 0 : $user->conf->$offsettz),
325 'color' => dol_string_nohtmltag(getDolUserString($color)),
326 'cachedelay' => getDolUserInt('AGENDA_EXT_CACHE_'.$user->id.'_'.$i, 0),
327 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
328 'default' => dol_string_nohtmltag(getDolUserString($default)),
329 'buggedfile' => dol_string_nohtmltag($buggedfile)
330 );
331 }
332 }
333}
334
335$firstdaytoshow = 0;
336$max_day_in_month = 0;
337$lastdaytoshow = 0;
338$tmpday = 0;
339$datestart = 0;
340$dateend = 0;
341$first_day = 0;
342$first_month = 0;
343$first_year = 0;
344$prev_day = 0;
345$prev_month = 0;
346$prev_year = 0;
347$max_day_in_prev_month = 0;
348$next_day = 0;
349$next_month = 0;
350$next_year = 0;
351if (empty($mode) || $mode == 'show_month') {
352 $prev = dol_get_prev_month($month, $year);
353 $prev_year = $prev['year'];
354 $prev_month = $prev['month'];
355 $next = dol_get_next_month($month, $year);
356 $next_year = $next['year'];
357 $next_month = $next['month'];
358
359 $max_day_in_prev_month = (int) date("t", dol_mktime(12, 0, 0, $prev_month, 1, $prev_year, 'gmt')); // Nb of days in previous month
360 $max_day_in_month = (int) date("t", dol_mktime(12, 0, 0, $month, 1, $year, 'gmt')); // Nb of days in next month
361 // tmpday is a negative or null cursor to know how many days before the 1st to show on month view (if tmpday=0, 1st is monday)
362 $tmpday = - (int) date("w", dol_mktime(12, 0, 0, $month, 1, $year, 'gmt')) + 2; // date('w') is 0 for sunday
363 $tmpday += (getDolGlobalInt('MAIN_START_WEEK', 1) - 1);
364 if ($tmpday >= 1) {
365 $tmpday -= 7; // If tmpday is 0 we start with sunday, if -6, we start with monday of previous week.
366 }
367 // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
368 $firstdaytoshow = dol_mktime(0, 0, 0, $prev_month, $max_day_in_prev_month + $tmpday, $prev_year, 'tzuserrel');
369 $next_day = 7 - ($max_day_in_month + 1 - $tmpday) % 7;
370 if ($next_day < 6) {
371 $next_day += 7;
372 }
373 $lastdaytoshow = dol_mktime(0, 0, 0, $next_month, $next_day, $next_year, 'tzuserrel');
374}
375if ($mode == 'show_week') {
376 $prev = dol_get_first_day_week($day, $month, $year);
377 $prev_year = $prev['prev_year'];
378 $prev_month = $prev['prev_month'];
379 $prev_day = $prev['prev_day'];
380 $first_day = $prev['first_day'];
381 $first_month = $prev['first_month'];
382 $first_year = $prev['first_year'];
383
384 $week = $prev['week'];
385
386 $day = (int) $day;
387 $next = dol_get_next_week($first_day, (int) $week, $first_month, $first_year);
388 $next_year = $next['year'];
389 $next_month = $next['month'];
390 $next_day = $next['day'];
391
392 // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
393 $firstdaytoshow = dol_mktime(0, 0, 0, $first_month, $first_day, $first_year, 'tzuserrel');
394 $lastdaytoshow = dol_time_plus_duree($firstdaytoshow, 7, 'd');
395
396 $max_day_in_month = date("t", dol_mktime(0, 0, 0, $month, 1, $year, 'gmt'));
397
398 $tmpday = $first_day;
399}
400if ($mode == 'show_day') {
401 $prev = dol_get_prev_day($day, $month, $year);
402 $prev_year = $prev['year'];
403 $prev_month = $prev['month'];
404 $prev_day = $prev['day'];
405 $next = dol_get_next_day($day, $month, $year);
406 $next_year = $next['year'];
407 $next_month = $next['month'];
408 $next_day = $next['day'];
409 // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
410 $firstdaytoshow = dol_mktime(0, 0, 0, $prev_month, $prev_day, $prev_year, 'tzuserrel');
411 $lastdaytoshow = dol_mktime(0, 0, 0, $next_month, $next_day, $next_year, 'tzuserrel');
412}
413//print 'xx'.$prev_year.'-'.$prev_month.'-'.$prev_day;
414//print 'xx'.$next_year.'-'.$next_month.'-'.$next_day;
415//print dol_print_date($firstdaytoshow,'dayhour').' '.dol_print_date($lastdaytoshow,'dayhour');
416
417/*$title = $langs->trans("DoneAndToDoActions");
418if ($status == 'done') {
419 $title = $langs->trans("DoneActions");
420}
421if ($status == 'todo') {
422 $title = $langs->trans("ToDoActions");
423}
424*/
425
426$param = '';
427if ($actioncode || GETPOSTISSET('search_actioncode')) {
428 if (is_array($actioncode)) {
429 foreach ($actioncode as $str_action) {
430 if ($str_action != '-1') {
431 $param .= "&search_actioncode[]=".urlencode($str_action);
432 }
433 }
434 } else {
435 $param .= "&search_actioncode=".urlencode($actioncode);
436 }
437}
438if ($resourceid > 0) {
439 $param .= "&search_resourceid=".urlencode((string) ($resourceid));
440}
441if ($status || GETPOSTISSET('status') || GETPOSTISSET('search_status')) {
442 $param .= "&search_status=".urlencode($status);
443}
444if ($filter) {
445 $param .= "&search_filter=".urlencode((string) $filter);
446}
447if ($filtert) {
448 $param .= "&search_filtert=".urlencode((string) $filtert);
449}
450if ($usergroup > 0) {
451 $param .= "&search_usergroup=".urlencode((string) ($usergroup));
452}
453if ($socid > 0) {
454 $param .= "&search_socid=".urlencode((string) ($socid));
455}
456if ($check_birthday) {
457 $param .= "&check_birthday=1";
458}
459if ($check_holiday) {
460 $param .= "&check_holiday=1";
461}
462if ($pid) {
463 $param .= "&search_projectid=".urlencode((string) ($pid));
464}
465if ($type) {
466 $param .= "&search_type=".urlencode($type);
467}
468$param .= "&maxprint=".urlencode((string) ($maxprint));
469if ($mode == 'show_day' || $mode == 'show_week' || $mode == 'show_month') {
470 $param .= '&mode='.urlencode($mode);
471}
472if ($search_categ_cus != 0) {
473 $param .= '&search_categ_cus='.urlencode((string) ($search_categ_cus));
474}
475if ($check_holiday) {
476 $param .= '&check_holiday=1';
477}
478
479// Show navigation bar
480$nav = '';
481$nav .= '<div class="navselectiondate inline-block nowraponall">';
482if (empty($mode) || $mode == 'show_month') {
483 $nav .= "<a href=\"?year=".$prev_year."&month=".$prev_month.$param."\"><i class=\"fa fa-chevron-left\"></i></a> &nbsp;\n";
484 $nav .= " <span id=\"month_name\">".dol_print_date(dol_mktime(0, 0, 0, $month, 1, $year), "%b %Y");
485 $nav .= " </span>\n";
486 $nav .= " &nbsp; <a href=\"?year=".$next_year."&month=".$next_month.$param."\"><i class=\"fa fa-chevron-right\"></i></a>\n";
487 $picto = 'calendar';
488}
489if ($mode == 'show_week') {
490 $nav .= "<a href=\"?year=".$prev_year."&month=".$prev_month."&day=".$prev_day.$param."\"><i class=\"fa fa-chevron-left\" title=\"".dol_escape_htmltag($langs->trans("Previous"))."\"></i></a> &nbsp;\n";
491 $nav .= " <span id=\"month_name\">".dol_print_date(dol_mktime(0, 0, 0, $first_month, $first_day, $first_year), "%Y").", ".$langs->trans("WeekShort")." ".$week;
492 $nav .= " </span>\n";
493 $nav .= " &nbsp; <a href=\"?year=".$next_year."&month=".$next_month."&day=".$next_day.$param."\"><i class=\"fa fa-chevron-right\" title=\"".dol_escape_htmltag($langs->trans("Next"))."\"></i></a>\n";
494 $picto = 'calendarweek';
495}
496if ($mode == 'show_day') {
497 $nav .= "<a href=\"?year=".$prev_year."&month=".$prev_month."&day=".$prev_day.$param."\"><i class=\"fa fa-chevron-left\"></i></a> &nbsp;\n";
498 $nav .= " <span id=\"month_name\">".dol_print_date(dol_mktime(0, 0, 0, $month, $day, $year), "daytextshort");
499 $nav .= " </span>\n";
500 $nav .= " &nbsp; <a href=\"?year=".$next_year."&month=".$next_month."&day=".$next_day.$param."\"><i class=\"fa fa-chevron-right\"></i></a>\n";
501 $picto = 'calendarday';
502}
503if (empty($conf->dol_optimize_smallscreen)) {
504 $nav .= ' <a href="?year='.$nowyear.'&month='.$nowmonth.'&day='.$nowday.$param.'" class="datenowlink marginleftonly marginrightonly">'.$langs->trans("Today").'</a> ';
505}
506$nav .= '</div>';
507
508$nav .= $form->selectDate($dateselect, 'dateselect', 0, 0, 1, '', 1, 0);
509//$nav .= ' <input type="submit" class="button button-save" name="submitdateselect" value="'.$langs->trans("Refresh").'">';
510$nav .= '<button type="submit" class="liste_titre button_search valignmiddle" name="button_search_x" value="x"><span class="fa fa-search"></span></button>';
511
512// Must be after the nav definition
513$paramnodate = $param;
514$param .= '&year='.$year.'&month='.$month.($day ? '&day='.$day : '');
515//print 'x'.$param;
516
517
518
519
520/*$tabactive = '';
521 if ($mode == 'show_month') $tabactive = 'cardmonth';
522 if ($mode == 'show_week') $tabactive = 'cardweek';
523 if ($mode == 'show_day') $tabactive = 'cardday';
524 if ($mode == 'show_list') $tabactive = 'cardlist';
525 if ($mode == 'show_pertuser') $tabactive = 'cardperuser';
526 if ($mode == 'show_pertype') $tabactive = 'cardpertype';
527 */
528
529$paramnoaction = preg_replace('/mode=[a-z_]+/', '', preg_replace('/action=[a-z_]+/', '', $param));
530$paramnoactionodate = preg_replace('/mode=[a-z_]+/', '', preg_replace('/action=[a-z_]+/', '', $paramnodate));
531
532$head = calendars_prepare_head($paramnoaction);
533
534print '<form method="POST" id="searchFormList" class="listactionsfilter" action="'.$_SERVER["PHP_SELF"].'" spellcheck="false">'."\n";
535if ($optioncss != '') {
536 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
537}
538print '<input type="hidden" name="token" value="'.newToken().'">';
539print '<input type="hidden" name="mode" value="'.$mode.'">';
540
541
542$viewmode = '<div class="navmode inline-block">';
543
544$viewmode .= '<a class="btnTitle'.($mode == 'list' ? ' btnTitleSelected' : '').' reposition" href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&restore_lastsearch_values=1'.$paramnoactionodate.'">';
545//$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
546$viewmode .= img_picto($langs->trans("List"), 'object_calendarlist', 'class="imgforviewmode pictoactionview block"');
547//$viewmode .= '</span>';
548$viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone inline-block width75 divoverflow">'.$langs->trans("ViewList").'</span></a>';
549
550$viewmode .= '<a class="btnTitle'.($mode == 'show_month' ? ' btnTitleSelected' : '').' reposition" href="'.DOL_URL_ROOT.'/comm/action/index.php?mode=show_month&year='.(isset($object->datep) ? dol_print_date($object->datep, '%Y') : $year).'&month='.(isset($object->datep) ? dol_print_date($object->datep, '%m') : $month).'&day='.(isset($object->datep) ? dol_print_date($object->datep, '%d') : $day).$paramnoactionodate.'">';
551//$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
552$viewmode .= img_picto($langs->trans("ViewCal"), 'object_calendarmonth', 'class="pictoactionview block"');
553//$viewmode .= '</span>';
554$viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone inline-block width75 divoverflow">'.$langs->trans("ViewCal").'</span></a>';
555
556$viewmode .= '<a class="btnTitle'.($mode == 'show_week' ? ' btnTitleSelected' : '').' reposition" href="'.DOL_URL_ROOT.'/comm/action/index.php?mode=show_week&year='.(isset($object->datep) ? dol_print_date($object->datep, '%Y') : $year).'&month='.(isset($object->datep) ? dol_print_date($object->datep, '%m') : $month).'&day='.(isset($object->datep) ? dol_print_date($object->datep, '%d') : $day).$paramnoactionodate.'">';
557//$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
558$viewmode .= img_picto($langs->trans("ViewWeek"), 'object_calendarweek', 'class="pictoactionview block"');
559//$viewmode .= '</span>';
560$viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone inline-block width75 divoverflow">'.$langs->trans("ViewWeek").'</span></a>';
561
562$viewmode .= '<a class="btnTitle'.($mode == 'show_day' ? ' btnTitleSelected' : '').' reposition" href="'.DOL_URL_ROOT.'/comm/action/index.php?mode=show_day&year='.(isset($object->datep) ? dol_print_date($object->datep, '%Y') : $year).'&month='.(isset($object->datep) ? dol_print_date($object->datep, '%m') : $month).'&day='.(isset($object->datep) ? dol_print_date($object->datep, '%d') : $day).$paramnoactionodate.'">';
563//$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
564$viewmode .= img_picto($langs->trans("ViewDay"), 'object_calendarday', 'class="pictoactionview block"');
565//$viewmode .= '</span>';
566$viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone inline-block width75 divoverflow">'.$langs->trans("ViewDay").'</span></a>';
567
568$viewmode .= '<a class="btnTitle'.($mode == 'show_peruser' ? ' btnTitleSelected' : '').' reposition" href="'.DOL_URL_ROOT.'/comm/action/peruser.php?mode=show_peruser&year='.(isset($object->datep) ? dol_print_date($object->datep, '%Y') : $year).'&month='.(isset($object->datep) ? dol_print_date($object->datep, '%m') : $month).'&day='.(isset($object->datep) ? dol_print_date($object->datep, '%d') : $day).$paramnoactionodate.'">';
569//$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
570$viewmode .= img_picto($langs->trans("ViewPerUser"), 'object_calendarperuser', 'class="pictoactionview block"');
571//$viewmode .= '</span>';
572$viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone inline-block width75 divoverflow" title="'.dolPrintHTML($langs->trans("ViewPerUser")).'">'.$langs->trans("ViewPerUser").'</span></a>';
573
574// Add more views from hooks
575$parameters = array();
576$object = null;
577$reshook = $hookmanager->executeHooks('addCalendarView', $parameters, $object, $action);
578if (empty($reshook)) {
579 $viewmode .= $hookmanager->resPrint;
580} elseif ($reshook > 1) {
581 $viewmode = $hookmanager->resPrint;
582}
583
584$viewmode .= '</div>';
585
586$viewmode .= '<span class="marginrightonly"></span>'; // To add a space before the navigation tools
587
588
589$newparam = '';
590$newcardbutton = '';
591if ($user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create')) {
592 $tmpforcreatebutton = dol_getdate(dol_now('tzuserrel'), true, 'gmt');
593
594 $newparam .= '&month='.((int) $month).'&year='.((int) $tmpforcreatebutton['year']).'&mode='.urlencode($mode);
595
596 //$param='month='.$monthshown.'&year='.$year;
597 //$hourminsec = dol_print_date(dol_mktime(10, 0, 0, 1, 1, 1970, 'gmt'), '%H', 'gmt').'0000'; // Set $hourminsec to '100000' to auto set hour to 10:00 at creation
598
599 $urltocreateaction = DOL_URL_ROOT.'/comm/action/card.php?action=create';
600 $urltocreateaction .= '&apyear='.$tmpforcreatebutton['year'].'&apmonth='.$tmpforcreatebutton['mon'].'&apday='.$tmpforcreatebutton['mday'].'&aphour='.$tmpforcreatebutton['hours'].'&apmin='.$tmpforcreatebutton['minutes'];
601 $urltocreateaction .= '&backtopage='.urlencode($_SERVER["PHP_SELF"].($newparam ? '?'.$newparam : ''));
602
603 $newcardbutton .= dolGetButtonTitle($langs->trans("AddAction"), '', 'fa fa-plus-circle', $urltocreateaction);
604}
605
606// Define the legend/list of calendard to show
607$s = '';
608
609
610$showextcals = $listofextcals;
611$bookcalcalendars = array();
612
613// Load Bookcal Calendars
614if (isModEnabled("bookcal")) {
615 $sql = "SELECT ba.rowid, bc.label, bc.ref, bc.rowid as id_cal";
616 $sql .= " FROM ".MAIN_DB_PREFIX."bookcal_availabilities as ba";
617 $sql .= " JOIN ".MAIN_DB_PREFIX."bookcal_calendar as bc";
618 $sql .= " ON bc.rowid = ba.fk_bookcal_calendar";
619 $sql .= " WHERE bc.status = 1";
620 $sql .= " AND ba.status = 1";
621 $sql .= " AND bc.entity IN (".getEntity('agenda').")"; // bookcal is a "virtual view" of agenda
622 if (!empty($filtert) && $filtert != '-1') {
623 $sql .= " AND bc.visibility IN (".$db->sanitize($filtert, 0, 0, 0, 0).")";
624 }
625 $resql = $db->query($sql);
626 if ($resql) {
627 $num = $db->num_rows($resql);
628 $i = 0;
629 while ($i < $num) {
630 $objp = $db->fetch_object($resql);
631 $label = !empty($objp->label) ? $objp->label : $objp->ref;
632 $bookcalcalendars["calendars"][$objp->id_cal] = array("id" => $objp->id_cal, "label" => $label);
633 $bookcalcalendars["availabilitieslink"][$objp->rowid] = $objp->id_cal;
634 $i++;
635 }
636 } else {
637 dol_print_error($db);
638 }
639}
640
641if (!empty($conf->use_javascript_ajax)) { // If javascript on
642 $s .= "\n".'<!-- Div to calendars selectors -->'."\n";
643
644 $s .= '<script type="text/javascript">'."\n";
645 $s .= 'jQuery(document).ready(function () {'."\n";
646 $s .= 'jQuery(".check_birthday").click(function() { console.log("Toggle class .family_birthday"); jQuery(".family_birthday").toggle(); });'."\n";
647 $s .= 'jQuery(".check_holiday").click(function() { console.log("Toggle class .family_holiday"); jQuery(".family_holiday").toggle(); jQuery(this).closest("form").submit(); });'."\n";
648 if (isModEnabled("bookcal") && !empty($bookcalcalendars["calendars"])) {
649 foreach ($bookcalcalendars["calendars"] as $key => $value) {
650 $s .= 'jQuery(".check_bookcal_calendar_'.$value['id'].'").click(function() { console.log("Toggle Bookcal Calendar '.$value['id'].'"); jQuery(".family_bookcal_calendar_'.$value['id'].'").toggle(); });'."\n";
651 }
652 }
653 if ($mode == "show_week" || $mode == "show_month" || empty($mode)) {
654 // Code to enable drag and drop
655 $s .= 'jQuery( "div.sortable" ).sortable({connectWith: ".sortable", placeholder: "ui-state-highlight", items: "div.movable", receive: function( event, ui ) {'."\n";
656 // Code to submit form
657 $s .= 'console.log("submit form to record new event");'."\n";
658 //$s.='console.log(event.target);';
659 $s .= 'var newval = jQuery(event.target).closest("div.dayevent").attr("id");'."\n";
660 $s .= 'console.log("found parent div.dayevent with id = "+newval);'."\n";
661 $s .= 'var frm=jQuery("#searchFormList");'."\n";
662 $s .= 'var newurl = ui.item.find("a.cal_event").attr("href");'."\n";
663 $s .= 'console.log("Found url on href of a.cal_event"+newurl+", we submit form with actionmove=mupdate");'."\n";
664 $s .= 'frm.attr("action", newurl).children("#newdate").val(newval);frm.submit();}'."\n";
665 $s .= '});'."\n";
666 }
667 $s .= '});'."\n";
668 $s .= '</script>'."\n";
669
670 // Local calendar
671 $s .= '<div class="nowrap inline-block minheight30 hideonsmartphone"><input type="checkbox" id="check_mytasks" name="check_mytasks" value="1" checked disabled><label class="labelcalendar"><span class="check_local_text small"> '.$langs->trans("LocalAgenda").' &nbsp; </span></label></div>';
672
673 // Holiday calendar
674 if ($user->hasRight("holiday", "read")) {
675 $s .= '
676 <div class="nowrap inline-block minheight30"><input type="checkbox" id="check_holiday" name="check_holiday" value="1" class="marginleftonly check_holiday"' . ($check_holiday ? ' checked' : '') . '>
677 <label for="check_holiday" class="labelcalendar">
678 <span class="check_holiday_text small">' . $langs->trans("Holidays") . '</span>
679 </label> &nbsp;
680 </div>';
681 }
682
683 // External calendars
684 if (is_array($showextcals) && count($showextcals) > 0) {
685 $s .= '<script type="text/javascript">'."\n";
686 $s .= 'jQuery(document).ready(function () {
687 jQuery("div input[name^=\"check_ext\"]").each(function(index, elem) {
688 var name = jQuery(elem).attr("name");
689 if (jQuery(elem).is(":checked")) {
690 jQuery(".family_ext" + name.replace("check_ext", "")).show();
691 } else {
692 jQuery(".family_ext" + name.replace("check_ext", "")).hide();
693 }
694 });
695
696 jQuery("div input[name^=\"check_ext\"]").click(function() {
697 var name = $(this).attr("name");
698 jQuery(".family_ext" + name.replace("check_ext", "")).toggle();
699 });
700 });' . "\n";
701 $s .= '</script>'."\n";
702
703 foreach ($showextcals as $val) {
704 $htmlname = md5($val['name']); // not used for security purpose, only to get a string with no special char
705
706 if (!empty($val['default']) || GETPOSTINT('check_ext'.$htmlname)) {
707 $default = "checked";
708 } else {
709 $default = '';
710 }
711
712 $cachedelayshown = (!empty($val['cachedelay']) && $val['cachedelay'] > 0 ? (int) $val['cachedelay'] : $DELAYFORCACHE);
713 $tooltip = $langs->trans("Cache").' '.($cachedelayshown < 120 ? $cachedelayshown.'s' : round($cachedelayshown / 60).'mn');
714
715 $s .= '<div class="nowrap inline-block minheight30"><input type="checkbox" id="check_ext'.$htmlname.'" class="marginleftonly check_ext_'.$htmlname.'" name="check_ext'.$htmlname.'" value="1" '.$default.'><label for="check_ext'.$htmlname.'" title="'.dol_escape_htmltag($tooltip).'" class="labelcalendar"><span class="check_ext_text small">'.dol_escape_htmltag($val['name']).'</small></label> &nbsp; </div>';
716 }
717 }
718
719 // Birthdays
720 $s .= '<div class="nowrap inline-block minheight30"><input type="checkbox" id="check_birthday" name="check_birthday" class="marginleftonly check_birthday" value="1" '. (GETPOSTINT('check_birthday') ? ' checked' : '') .'><label for="check_birthday" class="labelcalendar"><span class="check_birthday_text small">'.$langs->trans("AgendaShowBirthdayEvents").'</span></label> &nbsp; </div>';
721
722 // Bookcal Calendar
723 if (isModEnabled("bookcal")) {
724 if (!empty($bookcalcalendars["calendars"])) {
725 foreach ($bookcalcalendars["calendars"] as $key => $value) {
726 $label = $value['label'];
727 $s .= '<div class="nowrap inline-block minheight30">';
728 $s .= '<input '.(GETPOST('check_bookcal_calendar_'.$value['id']) ? "checked" : "").' type="checkbox" id="check_bookcal_calendar_'.$value['id'].'" name="check_bookcal_calendar_'.$value['id'].'" class="marginleftonly check_bookcal_calendar_'.$value['id'].'">';
729 $s .= '<label for="check_bookcal_calendar_'.$value['id'].'" class="labelcalendar">';
730 $s .= '<span class="check_bookcal_calendar_'.$value['id'].'_text">'.$langs->trans("AgendaShowBookcalCalendar", $label).'</span>';
731 $s .= '</label> &nbsp; </div>';
732 }
733 }
734 }
735
736 // Calendars from hooks
737 $parameters = array();
738 $reshook = $hookmanager->executeHooks('addCalendarChoice', $parameters, $object, $action);
739 if (empty($reshook)) {
740 $s .= $hookmanager->resPrint;
741 } elseif ($reshook > 1) {
742 $s = $hookmanager->resPrint;
743 }
744
745 $s .= "\n".'<!-- End div to calendars selectors -->'."\n";
746} else { // If javascript off
747 $newparam = $param; // newparam is for birthday links
748 $newparam = preg_replace('/check_birthday=[0-1]/i', 'check_birthday='.(empty($check_birthday) ? 1 : 0), $newparam);
749 if (!preg_match('/check_birthday=/i', $newparam)) {
750 $newparam .= '&check_birthday=1';
751 }
752 $s = '<a href="'.$_SERVER['PHP_SELF'].'?'.dol_escape_htmltag($newparam);
753 $s .= '">';
754 if (empty($check_birthday)) {
755 $s .= $langs->trans("AgendaShowBirthdayEvents");
756 } else {
757 $s .= $langs->trans("AgendaHideBirthdayEvents");
758 }
759 $s .= '</a>';
760}
761
762
763// Load events from database into $eventarray
764$filters = array(
765 'usergroup' => $usergroup,
766 'filtert' => $filtert,
767 'resourceid' => $resourceid,
768 'actioncode' => $actioncode,
769 'pid' => $pid,
770 'socid' => $socid,
771 'type' => $type,
772 'status' => $status,
773 'search_categ_cus' => $search_categ_cus,
774);
775$agendaeventresult = agenda_build_eventarray($db, $hookmanager, $user, $object, $action, $mode, $year, $month, $day, $firstdaytoshow, $lastdaytoshow, $filters);
776$eventarray = $agendaeventresult['eventarray'];
777$nbevents = $agendaeventresult['nbevents'];
778$MAXONSAMEPAGE = $agendaeventresult['maxonsamepage'];
779
780
781// BIRTHDATES CALENDAR
782agenda_get_birthday_events($db, $langs, $user, $mode, $month, $day, $year, $eventarray, $nbevents, $firstdaytoshow, $lastdaytoshow);
783
784
785// LEAVE-HOLIDAY CALENDAR
786if ($user->hasRight("holiday", "read")) {
787 $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.statut, x.rowid, x.date_debut as date_start, x.date_fin as date_end, x.halfday, x.statut as status";
788 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as x, ".MAIN_DB_PREFIX."user as u";
789 $sql .= " WHERE u.rowid = x.fk_user";
790 $sql .= " AND u.statut = '1'"; // Show only active users (0 = inactive user, 1 = active user)
791 $sql .= " AND (x.statut = '2' OR x.statut = '3')"; // Show only public leaves (2 = leave wait for approval, 3 = leave approved)
792 if ($mode == 'show_day') {
793 // Request only leaves for the current selected day
794 $sql .= " AND '".$db->escape($year."-".$month."-".$day)."' BETWEEN x.date_debut AND x.date_fin"; // date_debut and date_fin are date without time
795 } elseif ($mode == 'show_week') {
796 // Restrict on current month (we get more, but we will filter later)
797 $sql .= " AND x.date_debut < '".$db->idate(dol_get_last_day($year, $month))."'";
798 $sql .= " AND x.date_fin >= '".$db->idate(dol_get_first_day($year, $month))."'";
799 } elseif ($mode == 'show_month') {
800 // Restrict on current month
801 $sql .= " AND x.date_debut <= '".$db->idate(dol_get_last_day($year, $month))."'";
802 $sql .= " AND x.date_fin >= '".$db->idate(dol_get_first_day($year, $month))."'";
803 }
804 if (!$user->hasRight('holiday', 'readall') || $filtert == '-3') {
805 // Restrict on users of current user and his children
806 $sql .= " AND x.fk_user IN(".$db->sanitize(implode(", ", $user->getAllChildIds(1))).") ";
807 }
808 if ($filtert > 0) {
809 // Restrict on user
810 $sql .= " AND x.fk_user = ".((int) $filtert);
811 }
812
813 $resql = $db->query($sql);
814 if ($resql) {
815 $num = $db->num_rows($resql);
816 $i = 0;
817 $nbevents += $num;
818
819 while ($i < $num) {
820 $obj = $db->fetch_object($resql);
821
822 $event = new ActionComm($db);
823
824 // Need the id of the leave object for link to it
825 $event->id = $obj->rowid;
826 $event->ref = (string) $event->id;
827
828 $event->type_code = 'HOLIDAY';
829 $event->type_label = '';
830 $event->type_color = '';
831 $event->type = 'holiday';
832 $event->type_picto = 'holiday';
833
834 // date_debut and date_fin are dates without time, so they must be read and rendered in GMT to
835 // stay independent from the server and user timezones (otherwise the calendar day box is shifted).
836 $event->datep = (int) $db->jdate($obj->date_start, 'gmt') + (empty($obj->halfday) || $obj->halfday == 1 ? 0 : 12) * 60 * 60;
837 $event->datef = (int) $db->jdate($obj->date_end, 'gmt') + (empty($obj->halfday) || $obj->halfday == -1 ? 24 : 12) * 60 * 60 - 1;
838 $event->date_start_in_calendar = $event->datep;
839 $event->date_end_in_calendar = $event->datef;
840
841 if ($obj->status == 3) {
842 // Show no symbol for leave with state "leave approved"
843 $event->percentage = -1;
844 } elseif ($obj->status == 2) {
845 // Show TO-DO symbol for leave with state "leave wait for approval"
846 $event->percentage = 0;
847 }
848
849 $event->label = $langs->trans("Holiday");
850
851 $daycursor = $event->date_start_in_calendar;
852 $annee = (int) dol_print_date($daycursor, '%Y', 'gmt');
853 $mois = (int) dol_print_date($daycursor, '%m', 'gmt');
854 $jour = (int) dol_print_date($daycursor, '%d', 'gmt');
855
856 $daycursorend = $event->date_end_in_calendar;
857 $anneeend = (int) dol_print_date($daycursorend, '%Y', 'gmt');
858 $moisend = (int) dol_print_date($daycursorend, '%m', 'gmt');
859 $jourend = (int) dol_print_date($daycursorend, '%d', 'gmt');
860
861 // daykey must be date that represent day box in calendar so must be a user time
862 $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
863 $daykeygmt = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
864 $ifornbofdays = 0;
865 do {
866 $ifornbofdays++;
867
868 $firstdayofholiday = ($ifornbofdays == 1);
869 $lastdayofholiday = ($daykeygmt == dol_get_first_hour($event->date_end_in_calendar, 'gmt'));
870
871 /*
872 var_dump(dol_print_date($daykeygmt, 'dayhour', 'gmt'));
873 var_dump(dol_print_date(dol_get_first_hour($event->date_end_in_calendar, 'gmt'), 'dayhour', 'gmt'));
874 var_dump($lastdayofholiday);
875 var_dump($obj->halfday);
876 */
877
878 if ((in_array($obj->halfday, array(1, 2)) == 1 && $lastdayofholiday) || (in_array($obj->halfday, array(-1, 2)) && $firstdayofholiday)) {
879 // We create a copy of event because we want tochange the label
880 $newevent = dol_clone($event, 1);
881 if (in_array($obj->halfday, array(1, 2)) && $lastdayofholiday) {
882 $newevent->label .= ' ('.$langs->trans("Morning").')';
883 } elseif (in_array($obj->halfday, array(-1, 2)) && $firstdayofholiday) {
884 $newevent->label .= ' ('.$langs->trans("Afternoon").')';
885 }
886 $eventarray[$daykey][] = $newevent; // We need to use ->gtTypePicto, getXXXon object, so clone must be PHP clone.
887 } else {
888 $eventarray[$daykey][] = $event; // We can use the event unchanged
889 }
890
891 $daykey += 60 * 60 * 24;
892 $daykeygmt += 60 * 60 * 24;
893 } while ($daykey <= $event->date_end_in_calendar);
894
895 $i++;
896 }
897 }
898}
899
900// EXTERNAL CALENDAR
901// Complete $eventarray with external import Ical
902if (count($listofextcals)) {
903 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/ical.class.php';
904
905 foreach ($listofextcals as $key => $extcal) {
906 $url = $extcal['src']; // Example: https://www.google.com/calendar/ical/eldy10%40gmail.com/private-cde92aa7d7e0ef6110010a821a2aaeb/basic.ics
907 $namecal = $extcal['name'];
908 $offsettz = $extcal['offsettz'];
909 $colorcal = $extcal['color'];
910 $buggedfile = $extcal['buggedfile'];
911
912 if ($extcal['type'] == 'globalsetup') {
913 // Calendar defined by the admin: one cache file shared by all users, stored in the temp directory of the module (the name depends on the url)
914 dol_mkdir($conf->agenda->dir_temp);
915 $pathforcachefile = dol_sanitizePathName($conf->agenda->dir_temp).'/'.dol_sanitizeFileName('extcal_'.$namecal.'_'.substr(md5($url), 0, 12)).'.cache';
916 } else {
917 // Calendar defined by the user: one cache file per user
918 $pathforcachefile = dol_sanitizePathName($conf->user->dir_temp).'/'.dol_sanitizeFileName('extcal_'.$namecal.'_user'.$user->id).'.cache';
919 }
920 //var_dump($pathforcachefile);exit;
921
922 $ical = new ICal();
923 $ical->parse($url, $pathforcachefile, (!empty($extcal['cachedelay']) && $extcal['cachedelay'] > 0 ? (int) $extcal['cachedelay'] : $DELAYFORCACHE));
924 if ($ical->error) {
925 // Save error message for extcal
926 $listofextcals[$key]['error'] = $ical->error;
927 $s .= '<br><div class="warning">'.dol_escape_htmltag($listofextcals[$key]['name']).': '.$url.'<br>Error message: '.dol_escape_htmltag($ical->error).'</div>';
928 }
929
930 // After this $ical->cal['VEVENT'] contains array of events, $ical->cal['DAYLIGHT'] contains daylight info, $ical->cal['STANDARD'] contains non daylight info, ...
931 //var_dump($ical->cal); exit;
932 $icalevents = array();
933 $tmparray = $ical->get_event_list();
934 if (is_array($tmparray)) {
935 $icalevents = array_merge($icalevents, $tmparray); // Add $ical->cal['VEVENT']
936 }
937 $tmparray = $ical->get_freebusy_list();
938 if (is_array($tmparray)) {
939 $icalevents = array_merge($icalevents, $tmparray); // Add $ical->cal['VFREEBUSY']
940 }
941 if (getDolGlobalString('AGENDA_EXT_SHOW_TODO')) {
942 $icalevents = array_merge($icalevents, $ical->getTodoAndJournalAsEvents()); // Add $ical->cal['VTODO'] and $ical->cal['VJOURNAL']
943 }
944
945 $nbevents += count($icalevents);
946
947 if (count($icalevents) > 0) {
948 // Duplicate all repeatable events into new entries
949 $moreicalevents = array();
950 foreach ($icalevents as $icalkey => $icalevent) {
951 if (!$ical->hasStartDate($icalevent)) {
952 dol_syslog("Skip external calendar component without a valid DTSTART", LOG_WARNING);
953 continue;
954 }
955
956 $hasrrule = (isset($icalevent['RRULE']) && is_array($icalevent['RRULE']));
957 $tzidwall = false; // True if the dates are local dates of a time zone known by PHP: we compute the occurrences with these local dates, then we convert each one to a real time
958 $tzidname = '';
959 if ($hasrrule || !empty($icalevent['RDATE'])) { //repeatable event
960 //if ($event->date_start_in_calendar < $firstdaytoshow) $event->date_start_in_calendar=$firstdaytoshow;
961 //if ($event->date_end_in_calendar > $lastdaytoshow) $event->date_end_in_calendar=($lastdaytoshow-1);
962 if (isset($icalevent['DTSTART;VALUE=DATE'])) { //fullday event
963 $datecurstart = dol_stringtotime($icalevent['DTSTART;VALUE=DATE'], 1);
964 $datecurend = (empty($icalevent['DTEND;VALUE=DATE']) ? $datecurstart + 86400 : dol_stringtotime($icalevent['DTEND;VALUE=DATE'], 1)) - 1; // We remove one second to get last second of day
965 } elseif (isset($icalevent['DTSTART']) && !is_array($icalevent['DTSTART'])) { // Date in GMT (like 19970714T173000Z)
966 $datecurstart = $icalevent['DTSTART'];
967 $datecurend = empty($icalevent['DTEND']) ? $datecurstart : $icalevent['DTEND'];
968 } elseif (is_array($icalevent['DTSTART']) && isset($icalevent['DTSTART']['unixtime']) && $icalevent['DTSTART']['unixtime'] !== '') {
969 $datecurstart = $icalevent['DTSTART']['unixtime'];
970 $datecurend = empty($icalevent['DTEND']['unixtime']) ? $datecurstart : $icalevent['DTEND']['unixtime'];
971 $tzidname = (string) ($icalevent['DTSTART']['TZID'] ?? '');
972 $tzidwall = (empty($buggedfile) && $ical->isTzidKnown($tzidname));
973 if (!$tzidwall && !empty($ical->cal['DAYLIGHT']['DTSTART']) && $datecurstart) {
974 //var_dump($ical->cal);
975 $tmpcurstart = $datecurstart;
976 $tmpcurend = $datecurend;
977 $tmpdaylightstart = dol_mktime(0, 0, 0, 1, 1, 1970, 1) + (int) $ical->cal['DAYLIGHT']['DTSTART'];
978 $tmpdaylightend = dol_mktime(0, 0, 0, 1, 1, 1970, 1) + (int) $ical->cal['STANDARD']['DTSTART'];
979 //var_dump($tmpcurstart);var_dump($tmpcurend); var_dump($ical->cal['DAYLIGHT']['DTSTART']);var_dump($ical->cal['STANDARD']['DTSTART']);
980 // Edit datecurstart and datecurend
981 if ($tmpcurstart >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend) {
982 $datecurstart -= ((int) $ical->cal['DAYLIGHT']['TZOFFSETTO']) * 36;
983 } else {
984 $datecurstart -= ((int) $ical->cal['STANDARD']['TZOFFSETTO']) * 36;
985 }
986 if ($tmpcurend >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend) {
987 $datecurend -= ((int) $ical->cal['DAYLIGHT']['TZOFFSETTO']) * 36;
988 } else {
989 $datecurend -= ((int) $ical->cal['STANDARD']['TZOFFSETTO']) * 36;
990 }
991 }
992 // datecurstart and datecurend are now GMT date
993 //var_dump($datecurstart); var_dump($datecurend); exit;
994 } else {
995 // Not a recognized record
996 dol_syslog("Found a not recognized repeatable record with unknown date start", LOG_ERR);
997 continue;
998 }
999 //print 'xx'.$datecurstart;exit;
1000
1001 // Days excluded from the recurrence (EXDATE). $exdateshift converts a start into the day as written in the file (a TZID date is a local time)
1002 $exdates = (isset($icalevent['EXDATE']) && is_array($icalevent['EXDATE'])) ? $icalevent['EXDATE'] : [];
1003 $exdateshift = (isset($icalevent['DTSTART']) && is_array($icalevent['DTSTART']) && !empty($icalevent['DTSTART']['unixtime'])) ? ((int) $icalevent['DTSTART']['unixtime'] - (int) $datecurstart) : 0;
1004 $firstdatecurstart = $datecurstart;
1005 $occurrenceduration = $datecurend - $datecurstart;
1006
1007 $interval = 1;
1008 $until = 0;
1009 $maxrepeat = 0;
1010
1011 if ($hasrrule) {
1012 // We can expand a rule with FREQ and, as BYxxx parts, only BYDAY, BYMONTHDAY, BYMONTH. For the others (BYSETPOS...), we keep the first occurrence only.
1013 $unsupportedrule = !$ical->isRRuleSupported($icalevent['RRULE']);
1014 if ($unsupportedrule) {
1015 dol_syslog("Found a repeatable record with a rule not managed by dolibarr code (".json_encode($icalevent['RRULE'])."). Only first occurrence is shown.", LOG_WARNING);
1016 unset($icalevents[$icalkey]['RRULE']);
1017 $hasrrule = false;
1018 }
1019 }
1020
1021 if ($hasrrule) {
1022 $interval = (empty($icalevent['RRULE']['INTERVAL']) ? 1 : $icalevent['RRULE']['INTERVAL']);
1023 $until = empty($icalevent['RRULE']['UNTIL']) ? 0 : dol_stringtotime($icalevent['RRULE']['UNTIL'], 1);
1024 $maxrepeat = empty($icalevent['RRULE']['COUNT']) ? 0 : $icalevent['RRULE']['COUNT'];
1025 if ($until && ($until + ($datecurend - $datecurstart)) < $firstdaytoshow) {
1026 $hasrrule = false; // We discard repeatable event that end before start date to show
1027 }
1028 if ($datecurstart >= $lastdaytoshow + ($tzidwall ? 86400 : 0)) {
1029 $hasrrule = false; // We discard repeatable event that start after end date to show
1030 }
1031 }
1032
1033 if ($hasrrule && ($tzidwall || in_array($icalevent['RRULE']['FREQ'] ?? '', ['MINUTELY', 'HOURLY']) || count(array_filter(array_keys($icalevent['RRULE']), function (string $rulekey): bool {
1034 return strpos($rulekey, 'BY') === 0;
1035 })) > 0)) {
1036 // Rule with a BYxxx part, or hourly or by minute: we compute the occurrences from the dates as written in the file
1037 foreach ($ical->expandRRule($icalevent['RRULE'], (int) $datecurstart + $exdateshift, (int) $lastdaytoshow + $exdateshift, ($until ? (int) $until + $exdateshift : 0), (int) $firstdaytoshow + $exdateshift - $occurrenceduration - 86400) as $occurrencewall) {
1038 if ($tzidwall) {
1039 // The occurrence is a local date of the time zone of the event: real time of its start and end (daylight saving time of this date)
1040 $occurrencestart = (int) $ical->tzidToTimestamp($occurrencewall, $tzidname);
1041 $occurrenceend = (int) $ical->tzidToTimestamp($occurrencewall + $occurrenceduration, $tzidname);
1042 } else {
1043 $occurrencestart = $occurrencewall - $exdateshift;
1044 $occurrenceend = $occurrencestart + $occurrenceduration;
1045 }
1046 if ($occurrenceend < $firstdaytoshow || in_array(gmdate('Ymd', $occurrencewall), $exdates)) {
1047 continue;
1048 }
1049 $newevent = $icalevent;
1050 unset($newevent['RRULE']);
1051 if (!empty($icalevent['DTSTART;VALUE=DATE'])) {
1052 $newevent['DTSTART;VALUE=DATE'] = dol_print_date($occurrencestart, '%Y%m%d');
1053 $newevent['DTEND;VALUE=DATE'] = dol_print_date($occurrenceend + 1, '%Y%m%d');
1054 } else {
1055 $newevent['DTSTART'] = $occurrencestart;
1056 $newevent['DTEND'] = $occurrenceend;
1057 }
1058 $moreicalevents[] = $newevent;
1059 }
1060 } elseif ($hasrrule) {
1061 $numofevent = 0;
1062 while (($datecurstart < $lastdaytoshow) && (empty($maxrepeat) || ($numofevent < $maxrepeat)) && (empty($until) || $datecurstart <= $until)) {
1063 if ($datecurend >= $firstdaytoshow && !in_array(gmdate('Ymd', (int) $datecurstart + $exdateshift), $exdates)) { // We add event (if not excluded)
1064 $newevent = $icalevent;
1065 unset($newevent['RRULE']);
1066 if (!empty($icalevent['DTSTART;VALUE=DATE'])) {
1067 $newevent['DTSTART;VALUE=DATE'] = dol_print_date($datecurstart, '%Y%m%d');
1068 $newevent['DTEND;VALUE=DATE'] = dol_print_date($datecurend + 1, '%Y%m%d');
1069 } else {
1070 $newevent['DTSTART'] = $datecurstart;
1071 $newevent['DTEND'] = $datecurend;
1072 }
1073 $moreicalevents[] = $newevent;
1074 }
1075 // Jump on next occurrence
1076 $numofevent++;
1077 $savdatecurstart = $datecurstart;
1078 if ($icalevent['RRULE']['FREQ'] == 'DAILY') {
1079 $datecurstart = dol_time_plus_duree($datecurstart, $interval, 'd');
1080 $datecurend = dol_time_plus_duree($datecurend, $interval, 'd');
1081 }
1082 if ($icalevent['RRULE']['FREQ'] == 'WEEKLY') {
1083 $datecurstart = dol_time_plus_duree($datecurstart, $interval, 'w');
1084 $datecurend = dol_time_plus_duree($datecurend, $interval, 'w');
1085 } elseif ($icalevent['RRULE']['FREQ'] == 'MONTHLY') {
1086 $datecurstart = dol_time_plus_duree($datecurstart, $interval, 'm');
1087 $datecurend = dol_time_plus_duree($datecurend, $interval, 'm');
1088 } elseif ($icalevent['RRULE']['FREQ'] == 'YEARLY') {
1089 $datecurstart = dol_time_plus_duree($datecurstart, $interval, 'y');
1090 $datecurend = dol_time_plus_duree($datecurend, $interval, 'y');
1091 }
1092 // Test to avoid infinite loop ($datecurstart must increase)
1093 if ($savdatecurstart >= $datecurstart) {
1094 dol_syslog("Found a rule freq ".$icalevent['RRULE']['FREQ']." not managed by dolibarr code. Assume 1 week frequency.", LOG_ERR);
1095 $datecurstart += 3600 * 24 * 7;
1096 $datecurend += 3600 * 24 * 7;
1097 }
1098 }
1099 }
1100
1101 // Dates added to the recurrence (RDATE), with the duration of the first occurrence
1102 if (!empty($icalevent['RDATE']) && is_array($icalevent['RDATE'])) {
1103 $rdatewall = 0;
1104 foreach ($icalevent['RDATE'] as $rdate) {
1105 if (!empty($icalevent['DTSTART;VALUE=DATE'])) {
1106 $rdatestart = dol_stringtotime(substr($rdate, 0, 8), 1);
1107 } else {
1108 $rdatewall = $ical->ical_date_to_unix($rdate);
1109 $rdatestart = ($tzidwall ? (int) $ical->tzidToTimestamp($rdatewall, $tzidname) : $rdatewall - $exdateshift);
1110 }
1111 $rdateend = $rdatestart + $occurrenceduration;
1112 if (($tzidwall ? $rdatewall : $rdatestart) == $firstdatecurstart || $rdateend < $firstdaytoshow || $rdatestart >= $lastdaytoshow || in_array(gmdate('Ymd', ($tzidwall ? $rdatewall : $rdatestart + $exdateshift)), $exdates)) {
1113 continue;
1114 }
1115 $newevent = $icalevent;
1116 unset($newevent['RRULE'], $newevent['RDATE']);
1117 if (!empty($icalevent['DTSTART;VALUE=DATE'])) {
1118 $newevent['DTSTART;VALUE=DATE'] = dol_print_date($rdatestart, '%Y%m%d');
1119 $newevent['DTEND;VALUE=DATE'] = dol_print_date($rdateend + 1, '%Y%m%d');
1120 } else {
1121 $newevent['DTSTART'] = $rdatestart;
1122 $newevent['DTEND'] = $rdateend;
1123 }
1124 $moreicalevents[] = $newevent;
1125 }
1126 }
1127 }
1128 }
1129 $icalevents = array_merge($icalevents, $moreicalevents);
1130
1131 // Loop on each entry into cal file to know if entry is qualified and add an ActionComm into $eventarray
1132 foreach ($icalevents as $icalevent) {
1133 //var_dump($icalevent);
1134
1135 if (!$ical->hasStartDate($icalevent)) {
1136 continue;
1137 }
1138
1139 //print $icalevent['SUMMARY'].'->';
1140 //var_dump($icalevent);exit;
1141 if (!empty($icalevent['RRULE'])) {
1142 continue; // We found a repeatable event. It was already split into unitary events, so we discard general rule.
1143 }
1144
1145 // Create a new object action
1146 $event = new ActionComm($db);
1147 $addevent = false;
1148 if (isset($icalevent['DTSTART;VALUE=DATE'])) { // fullday event
1149 // For full day events, date are also GMT but they won't but converted using tz during output
1150 $datestart = dol_stringtotime($icalevent['DTSTART;VALUE=DATE'], 1);
1151 if (empty($icalevent['DTEND;VALUE=DATE'])) {
1152 $dateend = $datestart + 86400 - 1;
1153 } else {
1154 $dateend = dol_stringtotime($icalevent['DTEND;VALUE=DATE'], 1) - 1; // We remove one second to get last second of day
1155 }
1156 //print 'x'.$datestart.'-'.$dateend;exit;
1157 //print dol_print_date($dateend,'dayhour','gmt');
1158 $event->fulldayevent = 1;
1159 $addevent = true;
1160 } elseif (!is_array($icalevent['DTSTART'])) { // not fullday event (DTSTART is not array. It is a value like '19700101T000000Z' for 00:00 in greenwitch)
1161 $datestart = $icalevent['DTSTART'];
1162 $dateend = empty($icalevent['DTEND']) ? $datestart : $icalevent['DTEND'];
1163
1164 $datestart += +($offsettz * 3600);
1165 $dateend += +($offsettz * 3600);
1166
1167 $addevent = true;
1168 //var_dump($offsettz);
1169 //var_dump(dol_print_date($datestart, 'dayhour', 'gmt'));
1170 } elseif (isset($icalevent['DTSTART']['unixtime'])) { // File contains a local timezone + a TZ (for example when using bluemind)
1171 $datestart = $icalevent['DTSTART']['unixtime'];
1172 $dateend = $icalevent['DTEND']['unixtime'];
1173
1174 // Local date of a time zone known by PHP: we convert it to a real time (daylight saving time of this date)
1175 $tzidconverted = false;
1176 if (empty($buggedfile)) {
1177 $tzidstart = $ical->tzidToTimestamp((int) $datestart, (string) ($icalevent['DTSTART']['TZID'] ?? ''));
1178 if ($tzidstart !== null) {
1179 $tzidend = $ical->tzidToTimestamp((int) $dateend, (string) ($icalevent['DTEND']['TZID'] ?? ($icalevent['DTSTART']['TZID'] ?? '')));
1180 $datestart = $tzidstart;
1181 $dateend = ($tzidend !== null ? $tzidend : $tzidstart + ((int) $dateend - (int) $icalevent['DTSTART']['unixtime']));
1182 $tzidconverted = true;
1183 }
1184 }
1185
1186 $datestart += +($offsettz * 3600);
1187 $dateend += +($offsettz * 3600);
1188
1189 // $buggedfile is set to uselocalandtznodaylight if conf->global->AGENDA_EXT_BUGGEDFILEx = 'uselocalandtznodaylight'
1190 if (!$tzidconverted && $buggedfile === 'uselocalandtznodaylight') { // unixtime is a local date that does not take daylight into account, TZID is +1 for example for 'Europe/Paris' in summer instead of 2
1191 // TODO
1192 }
1193 // $buggedfile is set to uselocalandtzdaylight if conf->global->AGENDA_EXT_BUGGEDFILEx = 'uselocalandtzdaylight' (for example with bluemind)
1194 if (!$tzidconverted && $buggedfile === 'uselocalandtzdaylight') { // unixtime is a local date that does take daylight into account, TZID is +2 for example for 'Europe/Paris' in summer
1195 $localtzs = new DateTimeZone((string) preg_replace('/"/', '', $icalevent['DTSTART']['TZID']));
1196 $localtze = new DateTimeZone((string) preg_replace('/"/', '', $icalevent['DTEND']['TZID']));
1197 $localdts = new DateTime(dol_print_date($datestart, 'dayrfc', 'gmt'), $localtzs);
1198 $localdte = new DateTime(dol_print_date($dateend, 'dayrfc', 'gmt'), $localtze);
1199 $tmps = -1 * $localtzs->getOffset($localdts);
1200 $tmpe = -1 * $localtze->getOffset($localdte);
1201 $datestart += $tmps;
1202 $dateend += $tmpe;
1203 //var_dump($datestart);
1204 }
1205 $addevent = true;
1206 }
1207
1208 if ($addevent) {
1209 $event->id = $icalevent['UID'];
1210 $event->ref = (string) $event->id;
1211 $userId = $userstatic->findUserIdByEmail($namecal);
1212 if (!empty($userId) && $userId > 0) {
1213 $event->userassigned[$userId] = array('id' => $userId, 'transparency' => 1);
1214 $event->percentage = -1;
1215 }
1216
1217 $event->type_code = "ICALEVENT";
1218 $event->type_label = $namecal;
1219 $event->type_color = $colorcal;
1220 $event->type = 'icalevent';
1221 $event->type_picto = 'rss';
1222
1223 $event->icalname = $namecal;
1224 $event->icalcolor = $colorcal;
1225 $usertime = 0; // We don't modify date because we want to have date into memory datep and datef stored as GMT date. Compensation will be done during output.
1226 $event->datep = (int) ($datestart + $usertime);
1227 $event->datef = (int) ($dateend + $usertime);
1228
1229 // Event of class PRIVATE or CONFIDENTIAL: the details are hidden, only the time is shown (unless AGENDA_EXT_SHOW_PRIVATE is set)
1230 $isprivate = (isset($icalevent['CLASS']) && is_string($icalevent['CLASS']) && in_array(strtoupper(trim($icalevent['CLASS'])), ['PRIVATE', 'CONFIDENTIAL']) && !getDolGlobalString('AGENDA_EXT_SHOW_PRIVATE'));
1231
1232 if ($isprivate) {
1233 $event->label = $langs->trans("Private");
1234 } elseif (isset($icalevent['SUMMARY']) && $icalevent['SUMMARY']) {
1235 $event->label = dol_string_nohtmltag($icalevent['SUMMARY']);
1236 } elseif (isset($icalevent['DESCRIPTION']) && $icalevent['DESCRIPTION']) {
1237 $event->label = dol_nl2br(dol_string_nohtmltag($icalevent['DESCRIPTION']), 1);
1238 } else {
1239 $event->label = $langs->trans("ExtSiteNoLabel");
1240 }
1241
1242 // Priority (see https://www.kanzaki.com/docs/ical/priority.html)
1243 // LOW = 0 to 4
1244 // MEDIUM = 5
1245 // HIGH = 6 to 9
1246 if (!empty($icalevent['PRIORITY'])) {
1247 $event->priority = $icalevent['PRIORITY'];
1248 }
1249
1250 // Transparency (see https://www.kanzaki.com/docs/ical/transp.html)
1251 if (!empty($icalevent['TRANSP'])) {
1252 if ($icalevent['TRANSP'] == "TRANSPARENT") {
1253 $event->transparency = 0; // 0 = available / free
1254 }
1255 if ($icalevent['TRANSP'] == "OPAQUE") {
1256 $event->transparency = 1; // 1 = busy
1257 }
1258
1259 // TODO: MS outlook states
1260 // X-MICROSOFT-CDO-BUSYSTATUS:FREE + TRANSP:TRANSPARENT => Available / Free
1261 // X-MICROSOFT-CDO-BUSYSTATUS:FREE + TRANSP:OPAQUE => Work another place
1262 // X-MICROSOFT-CDO-BUSYSTATUS:TENTATIVE + TRANSP:OPAQUE => With reservations
1263 // X-MICROSOFT-CDO-BUSYSTATUS:BUSY + TRANSP:OPAQUE => Busy
1264 // X-MICROSOFT-CDO-BUSYSTATUS:OOF + TRANSP:OPAQUE => Away from the office / off-site
1265 }
1266
1267 if (!empty($icalevent['LOCATION']) && !$isprivate) {
1268 $event->location = $icalevent['LOCATION'];
1269 }
1270
1271 // More details, shown into the tooltip of the event (not for a private event)
1272 $event->icaldetails = array();
1273 if (!$isprivate) {
1274 foreach (array('DESCRIPTION' => 'description', 'ORGANIZER' => 'organizer', 'URL' => 'url', 'CATEGORIES' => 'categories', 'GEO' => 'geo') as $icalproperty => $detailkey) {
1275 if (!empty($icalevent[$icalproperty]) && is_string($icalevent[$icalproperty])) {
1276 $event->icaldetails[$detailkey] = $icalevent[$icalproperty];
1277 }
1278 }
1279 if (!empty($icalevent['ATTENDEE']) && is_array($icalevent['ATTENDEE'])) {
1280 $event->icaldetails['attendees'] = $icalevent['ATTENDEE'];
1281 }
1282 }
1283
1284 $event->date_start_in_calendar = $event->datep;
1285
1286 if ((int) $event->datef != 0 && $event->datef >= $event->datep) {
1287 $event->date_end_in_calendar = $event->datef;
1288 } else {
1289 $event->date_end_in_calendar = $event->datep;
1290 }
1291
1292 // Add event into $eventarray if date range are ok.
1293 if ($event->date_end_in_calendar < $firstdaytoshow || $event->date_start_in_calendar >= $lastdaytoshow) {
1294 //print 'x'.$datestart.'-'.$dateend;exit;
1295 //print 'x'.$datestart.'-'.$dateend;exit;
1296 //print 'x'.$datestart.'-'.$dateend;exit;
1297 // This record is out of visible range
1298 } else {
1299 if ($event->date_start_in_calendar < $firstdaytoshow) {
1300 $event->date_start_in_calendar = $firstdaytoshow;
1301 }
1302 if ($event->date_end_in_calendar >= $lastdaytoshow) {
1303 $event->date_end_in_calendar = ($lastdaytoshow - 1);
1304 }
1305
1306 // Add an entry in actionarray for each day
1307 $daycursor = $event->date_start_in_calendar;
1308 $annee = (int) dol_print_date($daycursor, '%Y', 'tzuserrel');
1309 $mois = (int) dol_print_date($daycursor, '%m', 'tzuserrel');
1310 $jour = (int) dol_print_date($daycursor, '%d', 'tzuserrel');
1311
1312 // Loop on each day covered by action to prepare an index to show on calendar
1313 $loop = true;
1314 $j = 0;
1315 // daykey must be date that represent day box in calendar so must be a user time
1316 $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
1317 $daykeygmt = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
1318 do {
1319 //if ($event->fulldayevent) print dol_print_date($daykeygmt,'dayhour','gmt').'-'.dol_print_date($daykey,'dayhour','gmt').'-'.dol_print_date($event->date_end_in_calendar,'dayhour','gmt').' ';
1320 $eventarray[$daykey][] = $event;
1321 $daykey += 60 * 60 * 24;
1322 $daykeygmt += 60 * 60 * 24; // Add one day
1323 if (($event->fulldayevent ? $daykeygmt : $daykey) > $event->date_end_in_calendar) {
1324 $loop = false;
1325 }
1326 } while ($loop);
1327 }
1328 }
1329 }
1330 }
1331 }
1332}
1333
1334// Complete $eventarray with events coming from external module
1335$parameters = array();
1336$object = null;
1337$reshook = $hookmanager->executeHooks('getCalendarEvents', $parameters, $object, $action);
1338if (!empty($hookmanager->resArray['eventarray'])) {
1339 foreach ($hookmanager->resArray['eventarray'] as $keyDate => $events) {
1340 if (!isset($eventarray[$keyDate])) {
1341 $eventarray[$keyDate] = array();
1342 }
1343 $eventarray[$keyDate] = array_merge($eventarray[$keyDate], $events);
1344 }
1345}
1346
1347// Sort events
1348foreach ($eventarray as $keyDate => &$dateeventarray) {
1349 usort($dateeventarray, 'sort_events_by_date');
1350}
1351
1352
1353$maxnbofchar = 0;
1354$cachethirdparties = array();
1355$cachecontacts = array();
1356$cacheusers = array();
1357// default values
1359 array(137, 86, 161),
1360 array(60, 147, 183),
1361 array(250, 190, 80),
1362 array(80, 166, 90),
1363 array(190, 190, 100),
1364 array(91, 115, 247),
1365 array(140, 140, 220),
1366 array(190, 120, 120),
1367 array(115, 125, 150),
1368 array(100, 170, 20),
1369 array(150, 135, 125),
1370 array(85, 135, 150),
1371 array(150, 135, 80),
1372 array(150, 80, 150)
1373);
1374
1375// Define theme_datacolor array
1376$color_file = dol_getThemeFilePath('theme_vars.inc.php');
1377if ($color_file && is_readable($color_file)) {
1378 global $theme_datacolor;
1379 include $color_file;
1381}
1382
1383$massactionbutton = '';
1384
1385print_barre_liste($langs->trans("Agenda"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, 1, -1, 'object_action', 0, $nav.'<span class="marginleftonly"></span>'.$newcardbutton, '', $limit, 1, 0, 1, $viewmode);
1386
1387if ($nbevents > $MAXONSAMEPAGE) {
1388 print info_admin('Number of results has been truncated to '.$MAXONSAMEPAGE, 0, 0, 'warning').'<br>';
1389}
1390
1391// Show div with list of calendars
1392print $s;
1393
1394
1395if (empty($mode) || $mode == 'show_month') { // View by month
1396 $newparam = $param; // newparam is for birthday links
1397 $newparam = preg_replace('/check_birthday=/i', 'check_birthday_=', $newparam); // To avoid replacement when replace day= is done
1398 $newparam = preg_replace('/mode=show_month&?/i', '', $newparam);
1399 $newparam = preg_replace('/mode=show_week&?/i', '', $newparam);
1400 $newparam = preg_replace('/day=[0-9]+&?/i', '', $newparam);
1401 $newparam = preg_replace('/month=[0-9]+&?/i', '', $newparam);
1402 $newparam = preg_replace('/year=[0-9]+&?/i', '', $newparam);
1403 $newparam = preg_replace('/viewcal=[0-9]+&?/i', '', $newparam);
1404 $newparam = preg_replace('/check_birthday_=/i', 'check_birthday=', $newparam); // Restore correct parameter
1405 $newparam .= '&viewcal=1';
1406
1407 print '<div class="liste_titre liste_titre_bydiv centpercent">';
1408 print_actions_filter($form, $canedit, $status, $year, $month, $day, $check_birthday, '', $filtert, '', $pid, $socid, $action, -1, $actioncode, $usergroupids, '', $resourceid, $search_categ_cus);
1409 print '</div>';
1410
1411 print '<div class="div-table-responsive-no-min sectioncalendarbymonth maxscreenheightless300">';
1412 print '<table class="centpercent noborder nocellnopadd cal_pannel cal_month listwithfilterbefore">';
1413 print ' <tr class="liste_titre stickyagenda">';
1414 // Column title of weeks numbers
1415 echo ' <td class="center">#</td>';
1416 $i = 0;
1417 while ($i < 7) {
1418 print ' <td class="center bold uppercase tdfordaytitle'.($i == 0 ? ' borderleft' : '').'">';
1419 $numdayinweek = (($i + (getDolGlobalInt('MAIN_START_WEEK', 1))) % 7);
1420 if (!empty($conf->dol_optimize_smallscreen)) {
1421 $labelshort = array(0 => 'SundayMin', 1 => 'MondayMin', 2 => 'TuesdayMin', 3 => 'WednesdayMin', 4 => 'ThursdayMin', 5 => 'FridayMin', 6 => 'SaturdayMin');
1422 print $langs->trans($labelshort[$numdayinweek]);
1423 } else {
1424 print $langs->trans("Day".$numdayinweek);
1425 }
1426 print ' </td>'."\n";
1427 $i++;
1428 }
1429 echo ' </tr>'."\n";
1430
1431 $todayarray = dol_getdate($now, true);
1432 $todaytms = dol_mktime(0, 0, 0, $todayarray['mon'], $todayarray['mday'], $todayarray['year']);
1433
1434 // In loops, tmpday contains day nb in current month (can be zero or negative for days of previous month)
1435 //var_dump($eventarray);
1436 for ($iter_week = 0; $iter_week < 6; $iter_week++) {
1437 echo " <tr>\n";
1438 // Get date of the current day, format 'yyyy-mm-dd'
1439 if ($tmpday <= 0) { // If number of the current day is in previous month
1440 $currdate0 = sprintf("%04d", $prev_year).sprintf("%02d", $prev_month).sprintf("%02d", $max_day_in_prev_month + $tmpday);
1441 } elseif ($tmpday <= $max_day_in_month) { // If number of the current day is in current month
1442 $currdate0 = sprintf("%04d", $year).sprintf("%02d", $month).sprintf("%02d", $tmpday);
1443 } else { // If number of the current day is in next month
1444 $currdate0 = sprintf("%04d", $next_year).sprintf("%02d", $next_month).sprintf("%02d", $tmpday - $max_day_in_month);
1445 }
1446 // Get week number for the targeted date '$currdate0'
1447 $numweek0 = date("W", strtotime(date($currdate0)));
1448 // Show the week number, and define column width
1449 echo ' <td class="center weeknumber opacitymedium" width="2%">'.$numweek0.'</td>';
1450
1451 for ($iter_day = 0; $iter_day < 7; $iter_day++) {
1452 if ($tmpday <= 0) {
1453 /* Show days before the beginning of the current month (previous month) */
1454 $style = 'cal_other_month cal_past';
1455 if ($iter_day == 6) {
1456 $style .= ' cal_other_month_right';
1457 }
1458 echo ' <td class="'.$style.' nowrap tdtop" width="14%">';
1459 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1460 show_day_events($db, $max_day_in_prev_month + $tmpday, $prev_month, $prev_year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
1461 echo " </td>\n";
1462 } elseif ($tmpday <= $max_day_in_month) {
1463 /* Show days of the current month */
1464 $curtime = dol_mktime(0, 0, 0, $month, $tmpday, $year);
1465 $style = 'cal_current_month';
1466 if ($iter_day == 6) {
1467 $style .= ' cal_current_month_right';
1468 }
1469 $today = 0;
1470 if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $month && $todayarray['year'] == $year) {
1471 $today = 1;
1472 }
1473 if ($today) {
1474 $style = 'cal_today';
1475 }
1476 if ($curtime < $todaytms) {
1477 $style .= ' cal_past';
1478 }
1479 //var_dump($todayarray['mday']."==".$tmpday." && ".$todayarray['mon']."==".$month." && ".$todayarray['year']."==".$year.' -> '.$style);
1480 echo ' <td class="'.$style.' nowrap tdtop" width="14%">';
1481 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1482 show_day_events($db, $tmpday, $month, $year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam, 0, 60, 0, $bookcalcalendars);
1483 echo "</td>\n";
1484 } else {
1485 /* Show days after the current month (next month) */
1486 $style = 'cal_other_month';
1487 if ($iter_day == 6) {
1488 $style .= ' cal_other_month_right';
1489 }
1490 echo ' <td class="'.$style.' nowrap tdtop" width="14%">';
1491 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1492 show_day_events($db, $tmpday - $max_day_in_month, $next_month, $next_year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
1493 echo "</td>\n";
1494 }
1495 $tmpday++;
1496 }
1497 echo " </tr>\n";
1498 }
1499 print "</table>\n";
1500 print '</div>';
1501
1502 print '<input type="hidden" name="actionmove" value="mupdate">';
1503 print '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($_SERVER['PHP_SELF']).'?mode=show_month&'.dol_escape_htmltag($_SERVER['QUERY_STRING']).'">';
1504 print '<input type="hidden" name="newdate" id="newdate">';
1505} elseif ($mode == 'show_week') {
1506 // View by week
1507 $newparam = $param; // newparam is for birthday links
1508 $newparam = preg_replace('/check_birthday=/i', 'check_birthday_=', $newparam); // To avoid replacement when replace day= is done
1509 $newparam = preg_replace('/mode=show_month&?/i', '', $newparam);
1510 $newparam = preg_replace('/mode=show_week&?/i', '', $newparam);
1511 $newparam = preg_replace('/day=[0-9]+&?/i', '', $newparam);
1512 $newparam = preg_replace('/month=[0-9]+&?/i', '', $newparam);
1513 $newparam = preg_replace('/year=[0-9]+&?/i', '', $newparam);
1514 $newparam = preg_replace('/viewweek=[0-9]+&?/i', '', $newparam);
1515 $newparam = preg_replace('/check_birthday_=/i', 'check_birthday=', $newparam); // Restore correct parameter
1516 $newparam .= '&viewweek=1';
1517
1518 print '<div class="liste_titre liste_titre_bydiv centpercent">';
1519 print_actions_filter($form, $canedit, $status, $year, $month, $day, $check_birthday, '', $filtert, '', $pid, $socid, $action, -1, $actioncode, $usergroupids, '', $resourceid);
1520 print '</div>';
1521
1522 print '<div class="div-table-responsive-no-min sectioncalendarbyweek maxscreenheightless300">';
1523 print '<table class="centpercent noborder nocellnopadd cal_pannel cal_month listwithfilterbefore">';
1524 print ' <tr class="liste_titre">';
1525 $i = 0;
1526 while ($i < 7) {
1527 echo ' <td class="center bold uppercase tdfordaytitle">'.$langs->trans("Day".(($i + (getDolGlobalInt('MAIN_START_WEEK', 1))) % 7))."</td>\n";
1528 $i++;
1529 }
1530 echo " </tr>\n";
1531
1532 echo ' <tr class="trcalweek">'."\n";
1533
1534 for ($iter_day = 0; $iter_day < 7; $iter_day++) {
1535 // Show days of the current week
1536 $curtime = dol_time_plus_duree($firstdaytoshow, $iter_day, 'd'); // $firstdaytoshow is in timezone of server
1537 $tmpday = (int) dol_print_date($curtime, '%d', 'tzuserrel');
1538 $tmpmonth = (int) dol_print_date($curtime, '%m', 'tzuserrel');
1539 $tmpyear = (int) dol_print_date($curtime, '%Y', 'tzuserrel');
1540
1541 $style = 'cal_current_month';
1542 if ($iter_day == 6) {
1543 $style .= ' cal_other_month_right';
1544 }
1545
1546 $today = 0;
1547 $todayarray = dol_getdate($now, true);
1548 if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $tmpmonth && $todayarray['year'] == $tmpyear) {
1549 $today = 1;
1550 }
1551 if ($today) {
1552 $style = 'cal_today';
1553 }
1554
1555 echo ' <td class="'.$style.'" width="14%" valign="top">';
1556 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1557 show_day_events($db, $tmpday, $tmpmonth, $tmpyear, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, 0, $bookcalcalendars);
1558 echo " </td>\n";
1559 }
1560 echo " </tr>\n";
1561
1562 print "</table>\n";
1563 print '</div>';
1564
1565 echo '<input type="hidden" name="actionmove" value="mupdate">';
1566 echo '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($_SERVER['PHP_SELF']).'?mode=show_week&'.dol_escape_htmltag($_SERVER['QUERY_STRING']).'">';
1567 echo '<input type="hidden" name="newdate" id="newdate">';
1568} else { // View by day
1569 $newparam = $param; // newparam is for birthday links
1570 $newparam = preg_replace('/mode=show_month&?/i', '', $newparam);
1571 $newparam = preg_replace('/mode=show_week&?/i', '', $newparam);
1572 $newparam = preg_replace('/viewday=[0-9]+&?/i', '', $newparam);
1573 $newparam .= '&viewday=1';
1574 // Code to show just one day
1575 $style = 'cal_current_month cal_current_month_oneday';
1576 $today = 0;
1577 $todayarray = dol_getdate($now, true);
1578 if ($todayarray['mday'] == $day && $todayarray['mon'] == $month && $todayarray['year'] == $year) {
1579 $today = 1;
1580 }
1581 //if ($today) $style='cal_today';
1582
1583 $timestamp = dol_mktime(12, 0, 0, $month, $day, $year);
1584 $arraytimestamp = dol_getdate($timestamp);
1585
1586 print '<div class="liste_titre liste_titre_bydiv centpercent">';
1587 print_actions_filter($form, $canedit, $status, $year, $month, $day, $check_birthday, '', $filtert, '', $pid, $socid, $action, -1, $actioncode, $usergroupids, '', $resourceid);
1588 print '</div>';
1589
1590 print '<div class="div-table-responsive-no-min sectioncalendarbyday maxscreenheightless300">';
1591 echo '<table class="tagtable centpercent noborder nocellnopadd cal_pannel cal_month listwithfilterbefore" style="margin-bottom: 10px !important;">';
1592
1593 echo ' <tr class="tagtr liste_titre">';
1594 echo ' <td class="tagtd center bold uppercase">'.$langs->trans("Day".$arraytimestamp['wday'])."</td>\n";
1595 echo " </tr>\n";
1596
1597 /*
1598 echo ' <div class="tagtr">';
1599 echo ' <div class="tagtd width100"></div>';
1600 echo ' <div class="tagtd center">';
1601 echo show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, -1);
1602 echo ' </div>'."\n";
1603 echo " </div>\n";
1604 */
1605
1606 print '<tr class="trcalday"><td class="tdtop">';
1607
1608 /* WIP View per hour */
1609 $useviewhour = 0;
1610 if ($useviewhour) {
1611 print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
1612
1613 $maxheightwin = (isset($_SESSION["dol_screenheight"]) && $_SESSION["dol_screenheight"] > 500) ? ($_SESSION["dol_screenheight"] - 200) : 660; // Also into index.php file
1614
1615 echo '<div style="max-height: '.$maxheightwin.'px;">';
1616 echo '<div class="tagtable centpercent calendarviewcontainer">';
1617
1618 $maxnbofchar = 80;
1619
1620 $tmp = explode('-', getDolGlobalString('MAIN_DEFAULT_WORKING_HOURS'));
1621 $minhour = round((float) $tmp[0], 0);
1622 $maxhour = round((float) $tmp[1], 0);
1623 if ($minhour > 23) {
1624 $minhour = 23;
1625 }
1626 if ($maxhour < 1) {
1627 $maxhour = 1;
1628 }
1629 if ($maxhour <= $minhour) {
1630 $maxhour = $minhour + 1;
1631 }
1632
1633 $i = 0;
1634 $j = 0;
1635 while ($i < 24) {
1636 echo ' <div class="tagtr calendarviewcontainertr">'."\n";
1637 echo ' <div class="tagtd width100 tdtop">'.dol_print_date($i * 3600, 'hour', 'gmt').'</div>';
1638 echo ' <div class="tagtd '.$style.' tdtop"></div>'."\n";
1639 echo ' </div>'."\n";
1640 $i++;
1641 $j++;
1642 }
1643
1644 echo '</div></div>';
1645
1646 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1647 show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, 1, $bookcalcalendars);
1648
1649 print '</div>';
1650 } else {
1651 print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
1652
1653 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1654 show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, 0, $bookcalcalendars);
1655
1656 print '</div>';
1657 }
1658
1659
1660 print '</td></tr>';
1661
1662 echo '</table>';
1663 print '</div>';
1664}
1665
1666print "\n".'</form>';
1667
1668// End of page
1669llxFooter();
1670$db->close();
1671
1672
1680function sort_events_by_date($a, $b)
1681{
1682 // Sort holidays at first
1683 if ($a->type_code === 'HOLIDAY') {
1684 return -1;
1685 }
1686 if ($b->type_code === 'HOLIDAY') {
1687 return 1;
1688 }
1689
1690 // datep => Event start time
1691 // datef => Event end time
1692
1693 // Events have different start time
1694 // Note: datep may be empty or non numeric on an incomplete event. The (int) cast must be on each
1695 // operand, not on the result, or PHP 8 throws "Unsupported operand types: string - int" before it
1696 // is reached. datef is already guarded with is_numeric() below for the same reason.
1697 if ($a->datep !== $b->datep) {
1698 return (int) $a->datep - (int) $b->datep;
1699 }
1700
1701 // Events have same start time and no end time
1702 if ((!is_numeric($b->datef)) || (!is_numeric($a->datef))) {
1703 return sort_events_by_percentage($a, $b);
1704 }
1705
1706 // Events have the same start time and same end time
1707 if ($b->datef === $a->datef) {
1708 return sort_events_by_percentage($a, $b);
1709 }
1710
1711 // Events have the same start time, but have different end time -> longest event first
1712 return (int) ($b->datef - $a->datef);
1713}
1714
1723{
1724 // Sort events with no percentage before each other
1725 // (useful to sort holidays, sick days or similar on the top)
1726
1727 if ($a->percentage < 0) {
1728 return -1;
1729 }
1730
1731 if ($b->percentage < 0) {
1732 return 1;
1733 }
1734
1735 return (int) ($b->percentage - $a->percentage);
1736}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
agenda_get_birthday_events($db, $langs, $user, $mode, $month, $day, $year, &$eventarray, &$nbevents, $firstdaytoshow, $lastdaytoshow)
Complete an agenda calendar event array with contact birthday pseudo-events.
print_actions_filter( $form, $canedit, $status, $year, $month, $day, $showbirthday, $filtera, $filtert, $filtered, $pid, $socid, $action, $showextcals=array(), $actioncode='', $usergroupid=0, $excludetype='', $resourceid=0, $search_categ_cus=0, $search_import_key='')
Show filter form in agenda view.
calendars_prepare_head($param)
Define head array for tabs of agenda setup pages.
agenda_build_eventarray($db, $hookmanager, $user, &$object, &$action, $mode, $year, $month, $day, $firstdaytoshow, $lastdaytoshow, $filters, $sincedatec=null)
Build $eventarray (list of ActionComm objects, indexed by day) for the agenda calendar views (month/w...
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage agenda events (actions)
Class to manage contact/addresses.
Class to manage generation of HTML components Only common components must be here.
Class to read/parse ICal calendars.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
$theme_datacolor
Definition index.php:1358
sort_events_by_percentage($a, $b)
Sort events by percentage.
Definition index.php:1722
$cacheusers
Definition index.php:1356
sort_events_by_date($a, $b)
Sort events by date.
Definition index.php:1680
dol_get_prev_month($month, $year)
Return previous month.
Definition date.lib.php:545
dol_get_first_hour($date, $gm='tzserver')
Return GMT time for first hour of a given GMT date (it removes hours, min and second part)
Definition date.lib.php:686
dol_get_next_day($day, $month, $year)
Return next day.
Definition date.lib.php:530
dol_get_next_week($day, $week, $month, $year)
Return next week.
Definition date.lib.php:604
dol_get_first_day_week($day, $month, $year, $gm=false)
Return first day of week for a date.
Definition date.lib.php:701
dol_get_prev_day($day, $month, $year)
Return previous day.
Definition date.lib.php:514
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition date.lib.php:626
dol_get_next_month($month, $year)
Return next month.
Definition date.lib.php:564
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:645
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0, $tz='')
Add a delay to a date.
Definition date.lib.php:127
dol_stringtotime($string, $gm=1, $processnotimeasnoon=0)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
Definition date.lib.php:452
dol_now($mode='gmt')
Return date for now.
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...
getDolUserInt($key, $default=0, $tmpuser=null)
Return Dolibarr user constant int value.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_getThemeFilePath($file, $theme='')
Return the full filesystem path of a file located in the currently selected theme directory.
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
dol_sanitizePathName($str, $newstr='_', $unaccent=0, $allowdash=0)
Clean a string to use it as a path name.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolUserString($key, $default='', $tmpuser=null)
Return Dolibarr user constant string value.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
Show information in HTML for admin users or standard users.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183
conf($dolibarr_main_document_root, $realpathconf=null)
Load conf file (file must exists)
Definition inc.php:431
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date
Definition receipt.php:492
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.