dolibarr 21.0.0-beta
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-2024 Frédéric France <frederic.france@free.fr>
11 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <https://www.gnu.org/licenses/>.
25 */
26
27
34// Load Dolibarr environment
35require '../../main.inc.php';
36require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
37require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
38require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
41if (isModEnabled('project')) {
42 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
43}
44
53if (!isset($conf->global->AGENDA_MAX_EVENTS_DAY_VIEW)) {
54 $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW = 3;
55}
56
57if (!getDolGlobalString('AGENDA_EXT_NB')) {
58 $conf->global->AGENDA_EXT_NB = 5;
59}
60$MAXAGENDA = getDolGlobalString('AGENDA_EXT_NB');
61$DELAYFORCACHE = 300; // 300 seconds
62
63$disabledefaultvalues = GETPOSTINT('disabledefaultvalues');
64
65$check_holiday = GETPOSTINT('check_holiday');
66$filter = GETPOST("search_filter", 'alpha', 3) ? GETPOST("search_filter", 'alpha', 3) : GETPOST("filter", 'alpha', 3);
67$filtert = GETPOST("search_filtert", "intcomma", 3) ? GETPOST("search_filtert", "intcomma", 3) : GETPOST("filtert", "intcomma", 3);
68$usergroup = GETPOST("search_usergroup", "intcomma", 3) ? GETPOST("search_usergroup", "intcomma", 3) : GETPOST("usergroup", "intcomma", 3);
69$showbirthday = empty($conf->use_javascript_ajax) ? GETPOSTINT("showbirthday") : 1;
70$search_categ_cus = GETPOST("search_categ_cus", 'intcomma', 3) ? GETPOST("search_categ_cus", 'intcomma', 3) : 0;
71
72// If not choice done on calendar owner (like on left menu link "Agenda"), we filter on user.
73if (empty($filtert) && !getDolGlobalString('AGENDA_ALL_CALENDARS')) {
74 $filtert = $user->id;
75}
76
77$newparam = '';
78
79$sortfield = GETPOST('sortfield', 'aZ09comma');
80$sortorder = GETPOST('sortorder', 'aZ09comma');
81$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
82if (empty($page) || $page == -1) {
83 $page = 0;
84} // If $page is not defined, or '' or -1
85$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
86$offset = $limit * $page;
87if (!$sortorder) {
88 $sortorder = "ASC";
89}
90if (!$sortfield) {
91 $sortfield = "a.datec";
92}
93
94// Security check
95$socid = GETPOSTINT("search_socid") ? GETPOSTINT("search_socid") : GETPOSTINT("socid");
96if ($user->socid) {
97 $socid = $user->socid;
98}
99if ($socid < 0) {
100 $socid = '';
101}
102
103$canedit = 1;
104if (!$user->hasRight('agenda', 'myactions', 'read')) {
106}
107if (!$user->hasRight('agenda', 'allactions', 'read')) {
108 $canedit = 0;
109}
110if (!$user->hasRight('agenda', 'allactions', 'read') || $filter == 'mine') { // If no permission to see all, we show only affected to me
111 $filtert = $user->id;
112}
113
114$action = GETPOST('action', 'aZ09');
115
116$mode = GETPOST('mode', 'aZ09');
117if (empty($mode) && preg_match('/show_/', $action)) {
118 $mode = $action; // For backward compatibility
119}
120$resourceid = GETPOST("search_resourceid", 'int');
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 = GETPOSTINT("search_projectid", 3) ? 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');
129$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
130
131$dateselect = dol_mktime(0, 0, 0, GETPOSTINT('dateselectmonth'), GETPOSTINT('dateselectday'), GETPOSTINT('dateselectyear'));
132if ($dateselect > 0) {
133 $day = GETPOSTINT('dateselectday');
134 $month = GETPOSTINT('dateselectmonth');
135 $year = GETPOSTINT('dateselectyear');
136}
137
138// Set actioncode (this code must be same for setting actioncode into peruser, listacton and index)
139if (GETPOST('search_actioncode', 'array:aZ09')) {
140 $actioncode = GETPOST('search_actioncode', 'array:aZ09', 3);
141 if (!count($actioncode)) {
142 $actioncode = '0';
143 }
144} else {
145 $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')));
146}
147if (is_scalar($actioncode) && $actioncode == '-1') {
148 $actioncode = '';
149}
150
151if ($status == '' && !GETPOSTISSET('search_status')) {
152 $status = ((!getDolGlobalString('AGENDA_DEFAULT_FILTER_STATUS') || $disabledefaultvalues) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_STATUS);
153}
154
155$defaultview = getDolGlobalString('AGENDA_DEFAULT_VIEW', 'show_month'); // default for app
156$defaultview = getDolUserString('AGENDA_DEFAULT_VIEW', $defaultview); // default for user
157if (empty($mode) && !GETPOSTISSET('mode')) {
158 $mode = $defaultview;
159}
160if ($mode == 'default') { // When action is default, we want a calendar view and not the list
161 $mode = (($defaultview != 'show_list') ? $defaultview : 'show_month');
162}
163if (GETPOST('viewcal') && GETPOST('mode') != 'show_day' && GETPOST('mode') != 'show_week') {
164 $mode = 'show_month';
165 $day = '';
166} // View by month
167if (GETPOST('viewweek') || GETPOST('mode') == 'show_week') {
168 $mode = 'show_week';
169 $week = ($week ? $week : date("W"));
170 $day = ($day ? $day : date("d"));
171} // View by week
172if (GETPOST('viewday') || GETPOST('mode') == 'show_day') {
173 $mode = 'show_day';
174 $day = ($day ? $day : date("d"));
175} // View by day
176
177$object = new ActionComm($db);
178
179// Load translation files required by the page
180$langs->loadLangs(array('agenda', 'other', 'commercial'));
181
182// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
183$hookmanager->initHooks(array('agenda'));
184
185$result = restrictedArea($user, 'agenda', 0, 'actioncomm&societe', 'myactions|allactions', 'fk_soc', 'id');
186if ($user->socid && $socid) {
187 $result = restrictedArea($user, 'societe', $socid);
188}
189
190
191/*
192 * Actions
193 */
194
195if (GETPOST("viewlist", 'alpha') || $mode == 'show_list') {
196 $param = '';
197 if (is_array($_POST)) {
198 foreach ($_POST as $key => $val) {
199 if ($key == 'token') {
200 continue;
201 }
202 $param .= '&'.$key.'='.urlencode($val);
203 }
204 }
205 if (!preg_match('/action=/', $param)) {
206 $param .= ($param ? '&' : '').'mode=show_list';
207 }
208 //print $param;
209 header("Location: ".DOL_URL_ROOT.'/comm/action/list.php?'.$param);
210 exit;
211}
212
213if (GETPOST("viewperuser", 'alpha') || $mode == 'show_peruser') {
214 $param = '';
215 if (is_array($_POST)) {
216 foreach ($_POST as $key => $val) {
217 if ($key == 'token') {
218 continue;
219 }
220 $param .= '&'.$key.'='.urlencode($val);
221 }
222 }
223 //print $param;
224 header("Location: ".DOL_URL_ROOT.'/comm/action/peruser.php?'.$param);
225 exit;
226}
227
228
229/*
230 * View
231 */
232
233$parameters = array(
234 'socid' => $socid,
235 'status' => $status,
236 'year' => $year,
237 'month' => $month,
238 'day' => $day,
239 'type' => $type,
240 'maxprint' => $maxprint,
241 'filter' => $filter,
242 'filtert' => $filtert,
243 'showbirthday' => $showbirthday,
244 'canedit' => $canedit,
245 'optioncss' => $optioncss,
246 'actioncode' => $actioncode,
247 'pid' => $pid,
248 'resourceid' => $resourceid,
249 'usergroup' => $usergroup,
250);
251$reshook = $hookmanager->executeHooks('beforeAgenda', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
252if ($reshook < 0) {
253 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
254}
255
256$help_url = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:M&oacute;dulo_Agenda|DE:Modul_Terminplanung';
257llxHeader('', $langs->trans("Agenda"), $help_url);
258
259$form = new Form($db);
260$companystatic = new Societe($db);
261$contactstatic = new Contact($db);
262$userstatic = new User($db);
263
264$now = dol_now();
265$nowarray = dol_getdate($now);
266$nowyear = $nowarray['year'];
267$nowmonth = $nowarray['mon'];
268$nowday = $nowarray['mday'];
269
270$listofextcals = array();
271
272// Define list of external calendars (global admin setup)
273if (!getDolGlobalString('AGENDA_DISABLE_EXT')) {
274 $i = 0;
275 while ($i < $MAXAGENDA) {
276 $i++;
277 $source = 'AGENDA_EXT_SRC'.$i;
278 $name = 'AGENDA_EXT_NAME'.$i;
279 $offsettz = 'AGENDA_EXT_OFFSETTZ'.$i;
280 $color = 'AGENDA_EXT_COLOR'.$i;
281 $default = 'AGENDA_EXT_ACTIVEBYDEFAULT'.$i;
282 $buggedfile = 'AGENDA_EXT_BUGGEDFILE'.$i;
283 if (getDolGlobalString($source) && getDolGlobalString($name)) {
284 // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight'
285 $listofextcals[] = array(
286 'type' => 'globalsetup',
287 'src' => getDolGlobalString($source),
289 'offsettz' => (int) getDolGlobalInt($offsettz, 0),
290 'color' => dol_string_nohtmltag(getDolGlobalString($color)),
291 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
292 'default' => dol_string_nohtmltag(getDolGlobalString($default)),
293 'buggedfile' => dol_string_nohtmltag(getDolGlobalString('buggedfile', ''))
294 );
295 }
296 }
297}
298
299// Define list of external calendars (user setup)
300if (!getDolUserString('AGENDA_DISABLE_EXT')) {
301 $i = 0;
302 while ($i < $MAXAGENDA) {
303 $i++;
304 $source = 'AGENDA_EXT_SRC_'.$user->id.'_'.$i;
305 $name = 'AGENDA_EXT_NAME_'.$user->id.'_'.$i;
306 $offsettz = 'AGENDA_EXT_OFFSETTZ_'.$user->id.'_'.$i;
307 $color = 'AGENDA_EXT_COLOR_'.$user->id.'_'.$i;
308 $enabled = 'AGENDA_EXT_ENABLED_'.$user->id.'_'.$i;
309 $default = 'AGENDA_EXT_ACTIVEBYDEFAULT_'.$user->id.'_'.$i;
310 $buggedfile = 'AGENDA_EXT_BUGGEDFILE_'.$user->id.'_'.$i;
311
312 if (getDolUserString($source) && getDolUserString($name)) {
313 // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight'
314 $listofextcals[] = array(
315 'type' => 'usersetup',
316 'src' => getDolUserString($source),
317 'name' => dol_string_nohtmltag(getDolUserString($name)),
318 'offsettz' => (int) (empty($user->conf->$offsettz) ? 0 : $user->conf->$offsettz),
319 'color' => dol_string_nohtmltag(getDolUserString($color)),
320 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
321 'default' => dol_string_nohtmltag(getDolUserString($default)),
322 'buggedfile' => dol_string_nohtmltag(isset($user->conf->buggedfile) ? $user->conf->buggedfile : '')
323 );
324 }
325 }
326}
327$firstdaytoshow = 0;
328$max_day_in_month = 0;
329$lastdaytoshow = 0;
330$tmpday = 0;
331$datestart = 0;
332$dateend = 0;
333$first_day = 0;
334$first_month = 0;
335$first_year = 0;
336$prev_day = 0;
337$prev_month = 0;
338$prev_year = 0;
339$max_day_in_prev_month = 0;
340$next_day = 0;
341$next_month = 0;
342$next_year = 0;
343if (empty($mode) || $mode == 'show_month') {
344 $prev = dol_get_prev_month($month, $year);
345 $prev_year = $prev['year'];
346 $prev_month = $prev['month'];
347 $next = dol_get_next_month($month, $year);
348 $next_year = $next['year'];
349 $next_month = $next['month'];
350
351 $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
352 $max_day_in_month = (int) date("t", dol_mktime(12, 0, 0, $month, 1, $year, 'gmt')); // Nb of days in next month
353 // 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)
354 $tmpday = - (int) date("w", dol_mktime(12, 0, 0, $month, 1, $year, 'gmt')) + 2; // date('w') is 0 for sunday
355 $tmpday += ((isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1) - 1);
356 if ($tmpday >= 1) {
357 $tmpday -= 7; // If tmpday is 0 we start with sunday, if -6, we start with monday of previous week.
358 }
359 // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
360 $firstdaytoshow = dol_mktime(0, 0, 0, $prev_month, $max_day_in_prev_month + $tmpday, $prev_year, 'tzuserrel');
361 $next_day = 7 - ($max_day_in_month + 1 - $tmpday) % 7;
362 if ($next_day < 6) {
363 $next_day += 7;
364 }
365 $lastdaytoshow = dol_mktime(0, 0, 0, $next_month, $next_day, $next_year, 'tzuserrel');
366}
367if ($mode == 'show_week') {
368 $prev = dol_get_first_day_week($day, $month, $year);
369 $prev_year = $prev['prev_year'];
370 $prev_month = $prev['prev_month'];
371 $prev_day = $prev['prev_day'];
372 $first_day = $prev['first_day'];
373 $first_month = $prev['first_month'];
374 $first_year = $prev['first_year'];
375
376 $week = $prev['week'];
377
378 $day = (int) $day;
379 $next = dol_get_next_week($first_day, (int) $week, $first_month, $first_year);
380 $next_year = $next['year'];
381 $next_month = $next['month'];
382 $next_day = $next['day'];
383
384 // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
385 $firstdaytoshow = dol_mktime(0, 0, 0, $first_month, $first_day, $first_year, 'tzuserrel');
386 $lastdaytoshow = dol_time_plus_duree($firstdaytoshow, 7, 'd');
387
388 $max_day_in_month = date("t", dol_mktime(0, 0, 0, $month, 1, $year, 'gmt'));
389
390 $tmpday = $first_day;
391}
392if ($mode == 'show_day') {
393 $prev = dol_get_prev_day($day, $month, $year);
394 $prev_year = $prev['year'];
395 $prev_month = $prev['month'];
396 $prev_day = $prev['day'];
397 $next = dol_get_next_day($day, $month, $year);
398 $next_year = $next['year'];
399 $next_month = $next['month'];
400 $next_day = $next['day'];
401 // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
402 $firstdaytoshow = dol_mktime(0, 0, 0, $prev_month, $prev_day, $prev_year, 'tzuserrel');
403 $lastdaytoshow = dol_mktime(0, 0, 0, $next_month, $next_day, $next_year, 'tzuserrel');
404}
405//print 'xx'.$prev_year.'-'.$prev_month.'-'.$prev_day;
406//print 'xx'.$next_year.'-'.$next_month.'-'.$next_day;
407//print dol_print_date($firstdaytoshow,'dayhour').' '.dol_print_date($lastdaytoshow,'dayhour');
408
409/*$title = $langs->trans("DoneAndToDoActions");
410 if ($status == 'done') $title = $langs->trans("DoneActions");
411 if ($status == 'todo') $title = $langs->trans("ToDoActions");
412 */
413
414$param = '';
415if ($actioncode || GETPOSTISSET('search_actioncode')) {
416 if (is_array($actioncode)) {
417 foreach ($actioncode as $str_action) {
418 $param .= "&search_actioncode[]=".urlencode($str_action);
419 }
420 } else {
421 $param .= "&search_actioncode=".urlencode($actioncode);
422 }
423}
424if ($resourceid > 0) {
425 $param .= "&search_resourceid=".urlencode((string) ($resourceid));
426}
427if ($status || GETPOSTISSET('status') || GETPOSTISSET('search_status')) {
428 $param .= "&search_status=".urlencode($status);
429}
430if ($filter) {
431 $param .= "&search_filter=".urlencode($filter);
432}
433if ($filtert) {
434 $param .= "&search_filtert=".urlencode($filtert);
435}
436if ($usergroup > 0) {
437 $param .= "&search_usergroup=".urlencode((string) ($usergroup));
438}
439if ($socid > 0) {
440 $param .= "&search_socid=".urlencode((string) ($socid));
441}
442if ($showbirthday) {
443 $param .= "&search_showbirthday=1";
444}
445if ($pid) {
446 $param .= "&search_projectid=".urlencode((string) ($pid));
447}
448if ($type) {
449 $param .= "&search_type=".urlencode($type);
450}
451$param .= "&maxprint=".urlencode((string) ($maxprint));
452if ($mode == 'show_day' || $mode == 'show_week' || $mode == 'show_month') {
453 $param .= '&mode='.urlencode($mode);
454}
455if ($search_categ_cus != 0) {
456 $param .= '&search_categ_cus='.urlencode((string) ($search_categ_cus));
457}
458
459// Show navigation bar
460$nav = '';
461$nav .= '<div class="navselectiondate inline-block nowraponall">';
462if (empty($mode) || $mode == 'show_month') {
463 $nav .= "<a href=\"?year=".$prev_year."&month=".$prev_month.$param."\"><i class=\"fa fa-chevron-left\"></i></a> &nbsp;\n";
464 $nav .= " <span id=\"month_name\">".dol_print_date(dol_mktime(0, 0, 0, $month, 1, $year), "%b %Y");
465 $nav .= " </span>\n";
466 $nav .= " &nbsp; <a href=\"?year=".$next_year."&month=".$next_month.$param."\"><i class=\"fa fa-chevron-right\"></i></a>\n";
467 $picto = 'calendar';
468}
469if ($mode == 'show_week') {
470 $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";
471 $nav .= " <span id=\"month_name\">".dol_print_date(dol_mktime(0, 0, 0, $first_month, $first_day, $first_year), "%Y").", ".$langs->trans("WeekShort")." ".$week;
472 $nav .= " </span>\n";
473 $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";
474 $picto = 'calendarweek';
475}
476if ($mode == 'show_day') {
477 $nav .= "<a href=\"?year=".$prev_year."&month=".$prev_month."&day=".$prev_day.$param."\"><i class=\"fa fa-chevron-left\"></i></a> &nbsp;\n";
478 $nav .= " <span id=\"month_name\">".dol_print_date(dol_mktime(0, 0, 0, $month, $day, $year), "daytextshort");
479 $nav .= " </span>\n";
480 $nav .= " &nbsp; <a href=\"?year=".$next_year."&month=".$next_month."&day=".$next_day.$param."\"><i class=\"fa fa-chevron-right\"></i></a>\n";
481 $picto = 'calendarday';
482}
483if (empty($conf->dol_optimize_smallscreen)) {
484 $nav .= ' &nbsp; <a href="?year='.$nowyear.'&month='.$nowmonth.'&day='.$nowday.$param.'" class="datenowlink">'.$langs->trans("Today").'</a> ';
485}
486$nav .= '</div>';
487
488$nav .= $form->selectDate($dateselect, 'dateselect', 0, 0, 1, '', 1, 0);
489//$nav .= ' <input type="submit" class="button button-save" name="submitdateselect" value="'.$langs->trans("Refresh").'">';
490$nav .= '<button type="submit" class="liste_titre button_search valignmiddle" name="button_search_x" value="x"><span class="fa fa-search"></span></button>';
491
492// Must be after the nav definition
493$paramnodate = $param;
494$param .= '&year='.$year.'&month='.$month.($day ? '&day='.$day : '');
495//print 'x'.$param;
496
497
498
499
500/*$tabactive = '';
501 if ($mode == 'show_month') $tabactive = 'cardmonth';
502 if ($mode == 'show_week') $tabactive = 'cardweek';
503 if ($mode == 'show_day') $tabactive = 'cardday';
504 if ($mode == 'show_list') $tabactive = 'cardlist';
505 if ($mode == 'show_pertuser') $tabactive = 'cardperuser';
506 if ($mode == 'show_pertype') $tabactive = 'cardpertype';
507 */
508
509$paramnoaction = preg_replace('/mode=[a-z_]+/', '', preg_replace('/action=[a-z_]+/', '', $param));
510$paramnoactionodate = preg_replace('/mode=[a-z_]+/', '', preg_replace('/action=[a-z_]+/', '', $paramnodate));
511
512$head = calendars_prepare_head($paramnoaction);
513
514print '<form method="POST" id="searchFormList" class="listactionsfilter" action="'.$_SERVER["PHP_SELF"].'">'."\n";
515if ($optioncss != '') {
516 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
517}
518print '<input type="hidden" name="token" value="'.newToken().'">';
519print '<input type="hidden" name="mode" value="'.$mode.'">';
520
521
522$viewmode = '<div class="navmode inline-block">';
523
524$viewmode .= '<a class="btnTitle'.($mode == 'list' ? ' btnTitleSelected' : '').' reposition" href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&restore_lastsearch_values=1'.$paramnoactionodate.'">';
525//$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
526$viewmode .= img_picto($langs->trans("List"), 'object_calendarlist', 'class="imgforviewmode pictoactionview block"');
527//$viewmode .= '</span>';
528$viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone inline-block width75 divoverflow">'.$langs->trans("ViewList").'</span></a>';
529
530$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.'">';
531//$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
532$viewmode .= img_picto($langs->trans("ViewCal"), 'object_calendarmonth', 'class="pictoactionview block"');
533//$viewmode .= '</span>';
534$viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone inline-block width75 divoverflow">'.$langs->trans("ViewCal").'</span></a>';
535
536$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.'">';
537//$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
538$viewmode .= img_picto($langs->trans("ViewWeek"), 'object_calendarweek', 'class="pictoactionview block"');
539//$viewmode .= '</span>';
540$viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone inline-block width75 divoverflow">'.$langs->trans("ViewWeek").'</span></a>';
541
542$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.'">';
543//$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
544$viewmode .= img_picto($langs->trans("ViewDay"), 'object_calendarday', 'class="pictoactionview block"');
545//$viewmode .= '</span>';
546$viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone inline-block width75 divoverflow">'.$langs->trans("ViewDay").'</span></a>';
547
548$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.'">';
549//$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
550$viewmode .= img_picto($langs->trans("ViewPerUser"), 'object_calendarperuser', 'class="pictoactionview block"');
551//$viewmode .= '</span>';
552$viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone inline-block width75 divoverflow" title="'.dolPrintHTML($langs->trans("ViewPerUser")).'">'.$langs->trans("ViewPerUser").'</span></a>';
553
554// Add more views from hooks
555$parameters = array();
556$object = null;
557$reshook = $hookmanager->executeHooks('addCalendarView', $parameters, $object, $action);
558if (empty($reshook)) {
559 $viewmode .= $hookmanager->resPrint;
560} elseif ($reshook > 1) {
561 $viewmode = $hookmanager->resPrint;
562}
563
564$viewmode .= '</div>';
565
566$viewmode .= '<span class="marginrightonly"></span>'; // To add a space before the navigation tools
567
568
569$newparam = '';
570$newcardbutton = '';
571if ($user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create')) {
572 $tmpforcreatebutton = dol_getdate(dol_now('tzuserrel'), true);
573
574 $newparam .= '&month='.((int) $month).'&year='.((int) $tmpforcreatebutton['year']).'&mode='.urlencode($mode);
575
576 //$param='month='.$monthshown.'&year='.$year;
577 //$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
578
579 $urltocreateaction = DOL_URL_ROOT.'/comm/action/card.php?action=create';
580 $urltocreateaction .= '&apyear='.$tmpforcreatebutton['year'].'&apmonth='.$tmpforcreatebutton['mon'].'&apday='.$tmpforcreatebutton['mday'].'&aphour='.$tmpforcreatebutton['hours'].'&apmin='.$tmpforcreatebutton['minutes'];
581 $urltocreateaction .= '&backtopage='.urlencode($_SERVER["PHP_SELF"].($newparam ? '?'.$newparam : ''));
582
583 $newcardbutton .= dolGetButtonTitle($langs->trans("AddAction"), '', 'fa fa-plus-circle', $urltocreateaction);
584}
585
586// Define the legend/list of calendard to show
587$s = '';
588$link = '';
589
590
591$showextcals = $listofextcals;
592$bookcalcalendars = array();
593
594// Load Bookcal Calendars
595if (isModEnabled("bookcal")) {
596 $sql = "SELECT ba.rowid, bc.label, bc.ref, bc.rowid as id_cal";
597 $sql .= " FROM ".MAIN_DB_PREFIX."bookcal_availabilities as ba";
598 $sql .= " JOIN ".MAIN_DB_PREFIX."bookcal_calendar as bc";
599 $sql .= " ON bc.rowid = ba.fk_bookcal_calendar";
600 $sql .= " WHERE bc.status = 1";
601 $sql .= " AND ba.status = 1";
602 if (!empty($filtert) && $filtert != -1) {
603 $sql .= " AND bc.visibility = ".(int) $filtert ;
604 }
605 $resql = $db->query($sql);
606 if ($resql) {
607 $num = $db->num_rows($resql);
608 $i = 0;
609 while ($i < $num) {
610 $objp = $db->fetch_object($resql);
611 $label = !empty($objp->label) ? $objp->label : $objp->ref;
612 $bookcalcalendars["calendars"][] = array("id" => $objp->id_cal, "label" => $label);
613 $bookcalcalendars["availabilitieslink"][$objp->rowid] = $objp->id_cal;
614 $i++;
615 }
616 } else {
617 dol_print_error($db);
618 }
619}
620
621if (!empty($conf->use_javascript_ajax)) { // If javascript on
622 $s .= "\n".'<!-- Div to calendars selectors -->'."\n";
623
624 $s .= '<script type="text/javascript">'."\n";
625 $s .= 'jQuery(document).ready(function () {'."\n";
626 $s .= 'jQuery(".check_birthday").click(function() { console.log("Toggle birthdays"); jQuery(".family_birthday").toggle(); });'."\n";
627 $s .= 'jQuery(".check_holiday").click(function() { console.log("Toggle holidays"); jQuery(".family_holiday").toggle(); });'."\n";
628 if (isModEnabled("bookcal") && !empty($bookcalcalendars["calendars"])) {
629 foreach ($bookcalcalendars["calendars"] as $key => $value) {
630 $s .= 'jQuery(".check_bookcal_calendar_'.$value['id'].'").click(function() { console.log("Toggle Bookcal Calendar '.$value['id'].'"); jQuery(".family_bookcal_calendar_'.$value['id'].'").toggle(); });'."\n";
631 }
632 }
633 if ($mode == "show_week" || $mode == "show_month" || empty($mode)) {
634 // Code to enable drag and drop
635 $s .= 'jQuery( "div.sortable" ).sortable({connectWith: ".sortable", placeholder: "ui-state-highlight", items: "div.movable", receive: function( event, ui ) {'."\n";
636 // Code to submit form
637 $s .= 'console.log("submit form to record new event");'."\n";
638 //$s.='console.log(event.target);';
639 $s .= 'var newval = jQuery(event.target).closest("div.dayevent").attr("id");'."\n";
640 $s .= 'console.log("found parent div.dayevent with id = "+newval);'."\n";
641 $s .= 'var frm=jQuery("#searchFormList");'."\n";
642 $s .= 'var newurl = ui.item.find("a.cal_event").attr("href");'."\n";
643 $s .= 'console.log("Found url on href of a.cal_event"+newurl+", we submit form with actionmove=mupdate");'."\n";
644 $s .= 'frm.attr("action", newurl).children("#newdate").val(newval);frm.submit();}'."\n";
645 $s .= '});'."\n";
646 }
647 $s .= '});'."\n";
648 $s .= '</script>'."\n";
649
650 // Local calendar
651 $s .= '<div class="nowrap inline-block minheight30"><input type="checkbox" id="check_mytasks" name="check_mytasks" value="1" checked disabled><label class="labelcalendar"><span class="check_holiday_text"> '.$langs->trans("LocalAgenda").' &nbsp; </span></label></div>';
652
653 // Holiday calendar
654 if ($user->hasRight("holiday", "read")) {
655 $s .= '
656 <div class="nowrap inline-block minheight30"><input type="checkbox" id="check_holiday" name="check_holiday" value="1" class="check_holiday"' . ($check_holiday
657 ? ' checked' : '') . '>
658 <label for="check_holiday" class="labelcalendar">
659 <span class="check_holiday_text">' . $langs->trans("Holidays") . '</span>
660 </label> &nbsp;
661 </div>';
662 }
663
664 // External calendars
665 if (is_array($showextcals) && count($showextcals) > 0) {
666 $s .= '<script type="text/javascript">'."\n";
667 $s .= 'jQuery(document).ready(function () {
668 jQuery("div input[name^=\"check_ext\"]").each(function(index, elem) {
669 var name = jQuery(elem).attr("name");
670 if (jQuery(elem).is(":checked")) {
671 jQuery(".family_ext" + name.replace("check_ext", "")).show();
672 } else {
673 jQuery(".family_ext" + name.replace("check_ext", "")).hide();
674 }
675 });
676
677 jQuery("div input[name^=\"check_ext\"]").click(function() {
678 var name = $(this).attr("name");
679 jQuery(".family_ext" + name.replace("check_ext", "")).toggle();
680 });
681 });' . "\n";
682 $s .= '</script>'."\n";
683
684 foreach ($showextcals as $val) {
685 $htmlname = md5($val['name']); // not used for security purpose, only to get a string with no special char
686
687 if (!empty($val['default']) || GETPOSTINT('check_ext'.$htmlname)) {
688 $default = "checked";
689 } else {
690 $default = '';
691 }
692
693 $tooltip = $langs->trans("Cache").' '.round($DELAYFORCACHE / 60).'mn';
694
695 $s .= '<div class="nowrap inline-block minheight30"><input type="checkbox" id="check_ext'.$htmlname.'" name="check_ext'.$htmlname.'" value="1" '.$default.'><label for="check_ext'.$htmlname.'" title="'.dol_escape_htmltag($tooltip).'" class="labelcalendar">'.dol_escape_htmltag($val['name']).'</label> &nbsp; </div>';
696 }
697 }
698
699 // Birthdays
700 $s .= '<div class="nowrap inline-block minheight30"><input type="checkbox" id="check_birthday" name="check_birthday" class="check_birthday"><label for="check_birthday" class="labelcalendar"> <span class="check_birthday_text">'.$langs->trans("AgendaShowBirthdayEvents").'</span></label> &nbsp; </div>';
701
702 // Bookcal Calendar
703 if (isModEnabled("bookcal")) {
704 if (!empty($bookcalcalendars["calendars"])) {
705 foreach ($bookcalcalendars["calendars"] as $key => $value) {
706 $label = $value['label'];
707 $s .= '<div class="nowrap inline-block minheight30">';
708 $s .= '<input '.(GETPOST('check_bookcal_calendar_'.$value['id']) ? "checked" : "").' type="checkbox" id="check_bookcal_calendar_'.$value['id'].'" name="check_bookcal_calendar_'.$value['id'].'" class="check_bookcal_calendar_'.$value['id'].'">';
709 $s .= '<label for="check_bookcal_calendar_'.$value['id'].'" class="labelcalendar">';
710 $s .= '<span class="check_bookcal_calendar_'.$value['id'].'_text">'.$langs->trans("AgendaShowBookcalCalendar", $label).'</span>';
711 $s .= '</label> &nbsp; </div>';
712 }
713 }
714 }
715
716 // Calendars from hooks
717 $parameters = array();
718 $reshook = $hookmanager->executeHooks('addCalendarChoice', $parameters, $object, $action);
719 if (empty($reshook)) {
720 $s .= $hookmanager->resPrint;
721 } elseif ($reshook > 1) {
722 $s = $hookmanager->resPrint;
723 }
724
725 $s .= "\n".'<!-- End div to calendars selectors -->'."\n";
726} else { // If javascript off
727 $newparam = $param; // newparam is for birthday links
728 $newparam = preg_replace('/showbirthday=[0-1]/i', 'showbirthday='.(empty($showbirthday) ? 1 : 0), $newparam);
729 if (!preg_match('/showbirthday=/i', $newparam)) {
730 $newparam .= '&showbirthday=1';
731 }
732 $link = '<a href="'.$_SERVER['PHP_SELF'].'?'.dol_escape_htmltag($newparam);
733 $link .= '">';
734 if (empty($showbirthday)) {
735 $link .= $langs->trans("AgendaShowBirthdayEvents");
736 } else {
737 $link .= $langs->trans("AgendaHideBirthdayEvents");
738 }
739 $link .= '</a>';
740}
741
742
743// Load events from database into $eventarray
744$eventarray = array();
745
746
747// DEFAULT CALENDAR + AUTOEVENT CALENDAR + CONFERENCEBOOTH CALENDAR
748$sql = 'SELECT ';
749if ($usergroup > 0) {
750 $sql .= " DISTINCT";
751}
752$sql .= ' a.id, a.label,';
753$sql .= ' a.datep,';
754$sql .= ' a.datep2,';
755$sql .= ' a.percent,';
756$sql .= ' a.fk_user_author,a.fk_user_action,';
757$sql .= ' a.transparency, a.priority, a.fulldayevent, a.location,';
758$sql .= ' a.fk_soc, a.fk_contact, a.fk_project, a.fk_bookcal_calendar,';
759$sql .= ' a.fk_element, a.elementtype,';
760$sql .= ' ca.code as type_code, ca.libelle as type_label, ca.color as type_color, ca.type as type_type, ca.picto as type_picto';
761
762$parameters = array();
763$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
764$sql .= $hookmanager->resPrint;
765
766$sql .= ' FROM '.MAIN_DB_PREFIX.'c_actioncomm as ca, '.MAIN_DB_PREFIX."actioncomm as a";
767// We must filter on resource table
768if ($resourceid > 0) {
769 $sql .= ", ".MAIN_DB_PREFIX."element_resources as r";
770}
771// We must filter on assignment table
772if ($filtert > 0 || $usergroup > 0) {
773 $sql .= ", ".MAIN_DB_PREFIX."actioncomm_resources as ar";
774}
775if ($usergroup > 0) {
776 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_user = ar.fk_element";
777}
778$sql .= ' WHERE a.fk_action = ca.id';
779$sql .= ' AND a.entity IN ('.getEntity('agenda').')';
780// Condition on actioncode
781if (!empty($actioncode)) {
782 if (!getDolGlobalString('AGENDA_USE_EVENT_TYPE')) {
783 if ($actioncode == 'AC_NON_AUTO') {
784 $sql .= " AND ca.type != 'systemauto'";
785 } elseif ($actioncode == 'AC_ALL_AUTO') {
786 $sql .= " AND ca.type = 'systemauto'";
787 } else {
788 if ($actioncode == 'AC_OTH') {
789 $sql .= " AND ca.type != 'systemauto'";
790 }
791 if ($actioncode == 'AC_OTH_AUTO') {
792 $sql .= " AND ca.type = 'systemauto'";
793 }
794 }
795 } else {
796 if ($actioncode == 'AC_NON_AUTO') {
797 $sql .= " AND ca.type != 'systemauto'";
798 } elseif ($actioncode == 'AC_ALL_AUTO') {
799 $sql .= " AND ca.type = 'systemauto'";
800 } else {
801 if (is_array($actioncode)) {
802 $sql .= " AND ca.code IN (".$db->sanitize("'".implode("','", $actioncode)."'", 1).")";
803 } else {
804 $sql .= " AND ca.code IN (".$db->sanitize("'".implode("','", explode(',', $actioncode))."'", 1).")";
805 }
806 }
807 }
808}
809if ($resourceid > 0) {
810 $sql .= " AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = ".((int) $resourceid);
811}
812if ($pid) {
813 $sql .= " AND a.fk_project=".((int) $pid);
814}
815// If the internal user must only see his customers, force searching by him
816$search_sale = 0;
817if (isModEnabled("societe") && !$user->hasRight('societe', 'client', 'voir')) {
818 $search_sale = $user->id;
819}
820// Search on sale representative
821if ($search_sale && $search_sale != '-1') {
822 if ($search_sale == -2) {
823 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = a.fk_soc)";
824 } elseif ($search_sale > 0) {
825 $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = a.fk_soc AND sc.fk_user = ".((int) $search_sale).")";
826 }
827}
828// Search on socid
829if ($socid) {
830 $sql .= " AND a.fk_soc = ".((int) $socid);
831}
832// We must filter on assignment table
833if ($filtert > 0 || $usergroup > 0) {
834 $sql .= " AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
835}
836//var_dump($day.' '.$month.' '.$year);
837if ($mode == 'show_day') {
838 $sql .= " AND (";
839 $sql .= " (a.datep BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel'))."'";
840 $sql .= " AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel'))."')";
841 $sql .= " OR ";
842 $sql .= " (a.datep2 BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel'))."'";
843 $sql .= " AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel'))."')";
844 $sql .= " OR ";
845 $sql .= " (a.datep < '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel'))."'";
846 $sql .= " AND a.datep2 > '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel'))."')";
847 $sql .= ')';
848} else {
849 // To limit array
850 $sql .= " AND (";
851 $sql .= " (a.datep BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, 1, $year) - (60 * 60 * 24 * 7))."'"; // Start 7 days before
852 $sql .= " AND '".$db->idate(dol_mktime(23, 59, 59, $month, 28, $year) + (60 * 60 * 24 * 10))."')"; // End 7 days after + 3 to go from 28 to 31
853 $sql .= " OR ";
854 $sql .= " (a.datep2 BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, 1, $year) - (60 * 60 * 24 * 7))."'";
855 $sql .= " AND '".$db->idate(dol_mktime(23, 59, 59, $month, 28, $year) + (60 * 60 * 24 * 10))."')";
856 $sql .= " OR ";
857 $sql .= " (a.datep < '".$db->idate(dol_mktime(0, 0, 0, $month, 1, $year) - (60 * 60 * 24 * 7))."'";
858 $sql .= " AND a.datep2 > '".$db->idate(dol_mktime(23, 59, 59, $month, 28, $year) + (60 * 60 * 24 * 10))."')";
859 $sql .= ')';
860}
861if ($type) {
862 $sql .= " AND ca.id = ".((int) $type);
863}
864if ($status == '0') {
865 // To do (not started)
866 $sql .= " AND a.percent = 0";
867}
868if ($status == 'na') {
869 // Not applicable
870 $sql .= " AND a.percent = -1";
871}
872if ($status == '50') {
873 // Running already started
874 $sql .= " AND (a.percent > 0 AND a.percent < 100)";
875}
876if ($status == 'done' || $status == '100') {
877 $sql .= " AND (a.percent = 100)";
878}
879if ($status == 'todo') {
880 $sql .= " AND (a.percent >= 0 AND a.percent < 100)";
881}
882// We must filter on assignment table
883if ($filtert > 0 || $usergroup > 0) {
884 $sql .= " AND (";
885 if ($filtert > 0) {
886 $sql .= "ar.fk_element = ".((int) $filtert);
887 }
888 if ($usergroup > 0) {
889 $sql .= ($filtert > 0 ? " OR " : "")." ugu.fk_usergroup = ".((int) $usergroup);
890 }
891 $sql .= ")";
892}
893
894// Search in categories, -1 is all and -2 is no categories
895if ($search_categ_cus != -1) {
896 if ($search_categ_cus == -2) {
897 $sql .= " AND NOT EXISTS (SELECT ca.fk_actioncomm FROM ".MAIN_DB_PREFIX."categorie_actioncomm as ca WHERE ca.fk_actioncomm = a.id)";
898 } elseif ($search_categ_cus > 0) {
899 $sql .= " AND EXISTS (SELECT ca.fk_actioncomm FROM ".MAIN_DB_PREFIX."categorie_actioncomm as ca WHERE ca.fk_actioncomm = a.id AND ca.fk_categorie IN (".$db->sanitize($search_categ_cus)."))";
900 }
901}
902
903// Sort on date
904$sql .= ' ORDER BY datep';
905//print $sql;
906
907dol_syslog("comm/action/index.php", LOG_DEBUG);
908$resql = $db->query($sql);
909if ($resql) {
910 $num = $db->num_rows($resql);
911
912 $MAXONSAMEPAGE = 10000; // Useless to have more. Protection to avoid memory overload when high number of event (for example after a mass import)
913 $i = 0;
914 while ($i < $num && $i < $MAXONSAMEPAGE) {
915 $obj = $db->fetch_object($resql);
916
917 // Discard auto action if option is on
918 if (getDolGlobalString('AGENDA_ALWAYS_HIDE_AUTO') && $obj->type_code == 'AC_OTH_AUTO') {
919 $i++;
920 continue;
921 }
922
923 // Create a new object action
924 $event = new ActionComm($db);
925
926 $event->id = $obj->id;
927 $event->ref = $event->id;
928
929 $event->fulldayevent = $obj->fulldayevent;
930
931 // event->datep and event->datef must be GMT date.
932 if ($event->fulldayevent) {
933 $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
934 $event->datep = $db->jdate($obj->datep, $tzforfullday ? 'tzuser' : 'tzserver'); // If saved in $tzforfullday = gmt, we must invert date to be in user tz
935 $event->datef = $db->jdate($obj->datep2, $tzforfullday ? 'tzuser' : 'tzserver');
936 } else {
937 // Example: $obj->datep = '1970-01-01 01:00:00', jdate will return 0 if TZ of PHP server is Europe/Berlin (+1)
938 $event->datep = $db->jdate($obj->datep, 'tzserver');
939 $event->datef = $db->jdate($obj->datep2, 'tzserver');
940 }
941 //$event->datep_formated_gmt = dol_print_date($event->datep, 'dayhour', 'gmt');
942 //var_dump($obj->id.' '.$obj->datep.' '.dol_print_date($obj->datep, 'dayhour', 'gmt'));
943 //var_dump($obj->id.' '.$event->datep.' '.dol_print_date($event->datep, 'dayhour', 'gmt'));
944
945 $event->type_code = $obj->type_code;
946 $event->type_label = $obj->type_label;
947 $event->type_color = $obj->type_color;
948 $event->type = $obj->type_type;
949 $event->type_picto = $obj->type_picto;
950
951 $event->label = $obj->label;
952 $event->percentage = $obj->percent;
953
954 $event->authorid = $obj->fk_user_author; // user id of creator
955 $event->userownerid = $obj->fk_user_action; // user id of owner
956 $event->fetch_userassigned(); // This load $event->userassigned
957
958 $event->priority = $obj->priority;
959 $event->location = $obj->location;
960 $event->transparency = $obj->transparency;
961 $event->fk_element = $obj->fk_element;
962 $event->elementid = $obj->fk_element;
963 $event->elementtype = $obj->elementtype;
964
965 $event->fk_project = $obj->fk_project;
966
967 $event->socid = $obj->fk_soc;
968 $event->contact_id = $obj->fk_contact;
969 $event->fk_bookcal_calendar = $obj->fk_bookcal_calendar;
970 if (!empty($event->fk_bookcal_calendar)) {
971 $event->type = "bookcal_calendar";
972 }
973
974 // Defined date_start_in_calendar and date_end_in_calendar property
975 // They are date start and end of action but modified to not be outside calendar view.
976 $event->date_start_in_calendar = $event->datep;
977 if ($event->datef != '' && $event->datef >= $event->datep) {
978 $event->date_end_in_calendar = $event->datef;
979 } else {
980 $event->date_end_in_calendar = $event->datep;
981 }
982
983 // Check values
984 if ($event->date_end_in_calendar < $firstdaytoshow || $event->date_start_in_calendar >= $lastdaytoshow) {
985 // This record is out of visible range
986 } else {
987 if ($event->date_start_in_calendar < $firstdaytoshow) {
988 $event->date_start_in_calendar = $firstdaytoshow;
989 }
990 if ($event->date_end_in_calendar >= $lastdaytoshow) {
991 $event->date_end_in_calendar = ($lastdaytoshow - 1);
992 }
993
994 // Add an entry in actionarray for each day
995 $daycursor = $event->date_start_in_calendar;
996 $annee = (int) dol_print_date($daycursor, '%Y', 'tzuserrel');
997 $mois = (int) dol_print_date($daycursor, '%m', 'tzuserrel');
998 $jour = (int) dol_print_date($daycursor, '%d', 'tzuserrel');
999
1000 $daycursorend = $event->date_end_in_calendar;
1001 $anneeend = (int) dol_print_date($daycursorend, '%Y', 'tzuserrel');
1002 $moisend = (int) dol_print_date($daycursorend, '%m', 'tzuserrel');
1003 $jourend = (int) dol_print_date($daycursorend, '%d', 'tzuserrel');
1004
1005 //var_dump(dol_print_date($event->date_start_in_calendar, 'dayhour', 'gmt')); // Hour at greenwich
1006 //var_dump($annee.'-'.$mois.'-'.$jour);
1007 //print 'annee='.$annee.' mois='.$mois.' jour='.$jour.'<br>';
1008
1009 // Loop on each day covered by action to prepare an index to show on calendar
1010 $loop = true;
1011 $j = 0;
1012 $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt'); // $mois, $jour, $annee has been set for user tz
1013 $daykeyend = dol_mktime(0, 0, 0, $moisend, $jourend, $anneeend, 'gmt'); // $moisend, $jourend, $anneeend has been set for user tz
1014 /*
1015 print 'GMT '.$event->date_start_in_calendar.' '.dol_print_date($event->date_start_in_calendar, 'dayhour', 'gmt').'<br>';
1016 print 'TZSERVER '.$event->date_start_in_calendar.' '.dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzserver').'<br>';
1017 print 'TZUSERREL '.$event->date_start_in_calendar.' '.dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzuserrel').'<br>';
1018 print 'GMT '.$event->date_end_in_calendar.' '.dol_print_date($event->date_end_in_calendar, 'dayhour', 'gmt').'<br>';
1019 print 'TZSERVER '.$event->date_end_in_calendar.' '.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzserver').'<br>';
1020 print 'TZUSER '.$event->date_end_in_calendar.' '.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzuserrel').'<br>';
1021 */
1022 do {
1023 //if ($event->id==408)
1024 //print 'daykey='.$daykey.' daykeyend='.$daykeyend.' '.dol_print_date($daykey, 'dayhour', 'gmt').' - '.dol_print_date($event->datep, 'dayhour', 'gmt').' '.dol_print_date($event->datef, 'dayhour', 'gmt').'<br>';
1025 //print 'daykey='.$daykey.' daykeyend='.$daykeyend.' '.dol_print_date($daykey, 'dayhour', 'tzuserrel').' - '.dol_print_date($event->datep, 'dayhour', 'tzuserrel').' '.dol_print_date($event->datef, 'dayhour', 'tzuserrel').'<br>';
1026
1027 $eventarray[$daykey][] = $event;
1028 $j++;
1029
1030 $daykey += 60 * 60 * 24;
1031 //if ($daykey > $event->date_end_in_calendar) {
1032 if ($daykey > $daykeyend) {
1033 $loop = false;
1034 }
1035 } while ($loop);
1036 //var_dump($eventarray);
1037 //print 'Event '.$i.' id='.$event->id.' (start='.dol_print_date($event->datep).'-end='.dol_print_date($event->datef);
1038 //print ' startincalendar='.dol_print_date($event->date_start_in_calendar).'-endincalendar='.dol_print_date($event->date_end_in_calendar).') was added in '.$j.' different index key of array<br>';
1039 }
1040
1041 $parameters['obj'] = $obj;
1042 $reshook = $hookmanager->executeHooks('hookEventElements', $parameters, $event, $action); // Note that $action and $object may have been modified by some hooks
1043 $event = $hookmanager->resPrint;
1044 if ($reshook < 0) {
1045 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1046 }
1047
1048 $i++;
1049 }
1050} else {
1051 dol_print_error($db);
1052}
1053//var_dump($eventarray);
1054
1055
1056// BIRTHDATES CALENDAR
1057// Complete $eventarray with birthdates
1058if ($showbirthday) {
1059 // Add events in array
1060 $sql = 'SELECT sp.rowid, sp.lastname, sp.firstname, sp.birthday';
1061 $sql .= ' FROM '.MAIN_DB_PREFIX.'socpeople as sp';
1062 $sql .= ' WHERE (priv=0 OR (priv=1 AND fk_user_creat='.((int) $user->id).'))';
1063 $sql .= " AND sp.entity IN (".getEntity('contact').")";
1064 if ($mode == 'show_day') {
1065 $sql .= ' AND MONTH(birthday) = '.((int) $month);
1066 $sql .= ' AND DAY(birthday) = '.((int) $day);
1067 } else {
1068 $sql .= ' AND MONTH(birthday) = '.((int) $month);
1069 }
1070 $sql .= ' ORDER BY birthday';
1071
1072 dol_syslog("comm/action/index.php", LOG_DEBUG);
1073 $resql = $db->query($sql);
1074 if ($resql) {
1075 $num = $db->num_rows($resql);
1076 $i = 0;
1077 while ($i < $num) {
1078 $obj = $db->fetch_object($resql);
1079
1080 $event = new ActionComm($db);
1081
1082 $event->id = $obj->rowid; // We put contact id in action id for birthdays events
1083 $event->ref = $event->id;
1084
1085 $datebirth = dol_stringtotime($obj->birthday, 1);
1086 //print 'ee'.$obj->birthday.'-'.$datebirth;
1087 $datearray = dol_getdate($datebirth, true);
1088 $event->datep = dol_mktime(0, 0, 0, $datearray['mon'], $datearray['mday'], $year, true); // For full day events, date are also GMT but they won't but converted during output
1089 $event->datef = $event->datep;
1090
1091 $event->type_code = 'BIRTHDAY';
1092 $event->type_label = '';
1093 $event->type_color = '';
1094 $event->type = 'birthdate';
1095 $event->type_picto = 'birthdate';
1096
1097 $event->label = $langs->trans("Birthday").' '.dolGetFirstLastname($obj->firstname, $obj->lastname);
1098 $event->percentage = 100;
1099 $event->fulldayevent = 1;
1100
1101 $event->contact_id = $obj->rowid;
1102
1103 $event->date_start_in_calendar = $db->jdate($event->datep);
1104 $event->date_end_in_calendar = $db->jdate($event->datef);
1105
1106 // Add an entry in eventarray for each day
1107 $daycursor = $event->datep;
1108 $annee = (int) dol_print_date($daycursor, '%Y', 'tzuserrel');
1109 $mois = (int) dol_print_date($daycursor, '%m', 'tzuserrel');
1110 $jour = (int) dol_print_date($daycursor, '%d', 'tzuserrel');
1111
1112 $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
1113
1114 $eventarray[$daykey][] = $event;
1115
1116 /*$loop = true;
1117 $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee);
1118 do {
1119 $eventarray[$daykey][] = $event;
1120 $daykey += 60 * 60 * 24;
1121 if ($daykey > $event->date_end_in_calendar) $loop = false;
1122 } while ($loop);
1123 */
1124 $i++;
1125 }
1126 } else {
1127 dol_print_error($db);
1128 }
1129}
1130
1131if ($user->hasRight("holiday", "read")) {
1132 // LEAVE-HOLIDAY CALENDAR
1133 $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";
1134 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as x, ".MAIN_DB_PREFIX."user as u";
1135 $sql .= " WHERE u.rowid = x.fk_user";
1136 $sql .= " AND u.statut = '1'"; // Show only active users (0 = inactive user, 1 = active user)
1137 $sql .= " AND (x.statut = '2' OR x.statut = '3')"; // Show only public leaves (2 = leave wait for approval, 3 = leave approved)
1138
1139 if ($mode == 'show_day') {
1140 // Request only leaves for the current selected day
1141 $sql .= " AND '".$db->escape($year)."-".$db->escape($month)."-".$db->escape($day)."' BETWEEN x.date_debut AND x.date_fin"; // date_debut and date_fin are date without time
1142 } elseif ($mode == 'show_week') {
1143 // Restrict on current month (we get more, but we will filter later)
1144 $sql .= " AND date_debut < '".$db->idate(dol_get_last_day($year, $month))."'";
1145 $sql .= " AND date_fin >= '".$db->idate(dol_get_first_day($year, $month))."'";
1146 } elseif ($mode == 'show_month') {
1147 // Restrict on current month
1148 $sql .= " AND date_debut <= '".$db->idate(dol_get_last_day($year, $month))."'";
1149 $sql .= " AND date_fin >= '".$db->idate(dol_get_first_day($year, $month))."'";
1150 }
1151
1152 $resql = $db->query($sql);
1153 if ($resql) {
1154 $num = $db->num_rows($resql);
1155 $i = 0;
1156
1157 while ($i < $num) {
1158 $obj = $db->fetch_object($resql);
1159
1160 $event = new ActionComm($db);
1161
1162 // Need the id of the leave object for link to it
1163 $event->id = $obj->rowid;
1164 $event->ref = $event->id;
1165
1166 $event->type_code = 'HOLIDAY';
1167 $event->type_label = '';
1168 $event->type_color = '';
1169 $event->type = 'holiday';
1170 $event->type_picto = 'holiday';
1171
1172 $event->datep = $db->jdate($obj->date_start) + (empty($halfday) || $halfday == 1 ? 0 : 12 * 60 * 60 - 1);
1173 $event->datef = $db->jdate($obj->date_end) + (empty($halfday) || $halfday == -1 ? 24 : 12) * 60 * 60 - 1;
1174 $event->date_start_in_calendar = $event->datep;
1175 $event->date_end_in_calendar = $event->datef;
1176
1177 if ($obj->status == 3) {
1178 // Show no symbol for leave with state "leave approved"
1179 $event->percentage = -1;
1180 } elseif ($obj->status == 2) {
1181 // Show TO-DO symbol for leave with state "leave wait for approval"
1182 $event->percentage = 0;
1183 }
1184
1185 if ($obj->halfday == 1) {
1186 $event->label = $obj->lastname.' ('.$langs->trans("Morning").')';
1187 } elseif ($obj->halfday == -1) {
1188 $event->label = $obj->lastname.' ('.$langs->trans("Afternoon").')';
1189 } else {
1190 $event->label = $obj->lastname;
1191 }
1192
1193 $daycursor = $event->date_start_in_calendar;
1194 $annee = (int) dol_print_date($daycursor, '%Y', 'tzuserrel');
1195 $mois = (int) dol_print_date($daycursor, '%m', 'tzuserrel');
1196 $jour = (int) dol_print_date($daycursor, '%d', 'tzuserrel');
1197
1198 $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
1199 do {
1200 $eventarray[$daykey][] = $event;
1201
1202 $daykey += 60 * 60 * 24;
1203 } while ($daykey <= $event->date_end_in_calendar);
1204
1205 $i++;
1206 }
1207 }
1208}
1209
1210// EXTERNAL CALENDAR
1211// Complete $eventarray with external import Ical
1212if (count($listofextcals)) {
1213 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/ical.class.php';
1214
1215 foreach ($listofextcals as $key => $extcal) {
1216 $url = $extcal['src']; // Example: https://www.google.com/calendar/ical/eldy10%40gmail.com/private-cde92aa7d7e0ef6110010a821a2aaeb/basic.ics
1217 $namecal = $extcal['name'];
1218 $offsettz = $extcal['offsettz'];
1219 $colorcal = $extcal['color'];
1220 $buggedfile = $extcal['buggedfile'];
1221
1222 $pathforcachefile = dol_sanitizePathName($conf->user->dir_temp).'/'.dol_sanitizeFileName('extcal_'.$namecal.'_user'.$user->id).'.cache';
1223 //var_dump($pathforcachefile);exit;
1224
1225 $ical = new ICal();
1226 $ical->parse($url, $pathforcachefile, $DELAYFORCACHE);
1227 if ($ical->error) {
1228 // Save error message for extcal
1229 $listofextcals[$key]['error'] = $ical->error;
1230 $s .= '<br><div class="warning">'.dol_escape_htmltag($listofextcals[$key]['name']).': '.$url.'<br>Error message: '.dol_escape_htmltag($ical->error).'</div>';
1231 }
1232
1233 // After this $ical->cal['VEVENT'] contains array of events, $ical->cal['DAYLIGHT'] contains daylight info, $ical->cal['STANDARD'] contains non daylight info, ...
1234 //var_dump($ical->cal); exit;
1235 $icalevents = array();
1236 if (is_array($ical->get_event_list())) {
1237 $icalevents = array_merge($icalevents, $ical->get_event_list()); // Add $ical->cal['VEVENT']
1238 }
1239 if (is_array($ical->get_freebusy_list())) {
1240 $icalevents = array_merge($icalevents, $ical->get_freebusy_list()); // Add $ical->cal['VFREEBUSY']
1241 }
1242
1243 if (count($icalevents) > 0) {
1244 // Duplicate all repeatable events into new entries
1245 $moreicalevents = array();
1246 foreach ($icalevents as $icalevent) {
1247 if (isset($icalevent['RRULE']) && is_array($icalevent['RRULE'])) { //repeatable event
1248 //if ($event->date_start_in_calendar < $firstdaytoshow) $event->date_start_in_calendar=$firstdaytoshow;
1249 //if ($event->date_end_in_calendar > $lastdaytoshow) $event->date_end_in_calendar=($lastdaytoshow-1);
1250 if ($icalevent['DTSTART;VALUE=DATE']) { //fullday event
1251 $datecurstart = dol_stringtotime($icalevent['DTSTART;VALUE=DATE'], 1);
1252 $datecurend = dol_stringtotime($icalevent['DTEND;VALUE=DATE'], 1) - 1; // We remove one second to get last second of day
1253 } elseif (is_array($icalevent['DTSTART']) && !empty($icalevent['DTSTART']['unixtime'])) {
1254 $datecurstart = $icalevent['DTSTART']['unixtime'];
1255 $datecurend = $icalevent['DTEND']['unixtime'];
1256 if (!empty($ical->cal['DAYLIGHT']['DTSTART']) && $datecurstart) {
1257 //var_dump($ical->cal);
1258 $tmpcurstart = $datecurstart;
1259 $tmpcurend = $datecurend;
1260 $tmpdaylightstart = dol_mktime(0, 0, 0, 1, 1, 1970, 1) + (int) $ical->cal['DAYLIGHT']['DTSTART'];
1261 $tmpdaylightend = dol_mktime(0, 0, 0, 1, 1, 1970, 1) + (int) $ical->cal['STANDARD']['DTSTART'];
1262 //var_dump($tmpcurstart);var_dump($tmpcurend); var_dump($ical->cal['DAYLIGHT']['DTSTART']);var_dump($ical->cal['STANDARD']['DTSTART']);
1263 // Edit datecurstart and datecurend
1264 if ($tmpcurstart >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend) {
1265 $datecurstart -= ((int) $ical->cal['DAYLIGHT']['TZOFFSETTO']) * 36;
1266 } else {
1267 $datecurstart -= ((int) $ical->cal['STANDARD']['TZOFFSETTO']) * 36;
1268 }
1269 if ($tmpcurend >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend) {
1270 $datecurend -= ((int) $ical->cal['DAYLIGHT']['TZOFFSETTO']) * 36;
1271 } else {
1272 $datecurend -= ((int) $ical->cal['STANDARD']['TZOFFSETTO']) * 36;
1273 }
1274 }
1275 // datecurstart and datecurend are now GMT date
1276 //var_dump($datecurstart); var_dump($datecurend); exit;
1277 } else {
1278 // Not a recognized record
1279 dol_syslog("Found a not recognized repeatable record with unknown date start", LOG_ERR);
1280 continue;
1281 }
1282 //print 'xx'.$datecurstart;exit;
1283
1284 $interval = (empty($icalevent['RRULE']['INTERVAL']) ? 1 : $icalevent['RRULE']['INTERVAL']);
1285 $until = empty($icalevent['RRULE']['UNTIL']) ? 0 : dol_stringtotime($icalevent['RRULE']['UNTIL'], 1);
1286 $maxrepeat = empty($icalevent['RRULE']['COUNT']) ? 0 : $icalevent['RRULE']['COUNT'];
1287 if ($until && ($until + ($datecurend - $datecurstart)) < $firstdaytoshow) {
1288 continue; // We discard repeatable event that end before start date to show
1289 }
1290 if ($datecurstart >= $lastdaytoshow) {
1291 continue; // We discard repeatable event that start after end date to show
1292 }
1293
1294 $numofevent = 0;
1295 while (($datecurstart < $lastdaytoshow) && (empty($maxrepeat) || ($numofevent < $maxrepeat))) {
1296 if ($datecurend >= $firstdaytoshow) { // We add event
1297 $newevent = $icalevent;
1298 unset($newevent['RRULE']);
1299 if ($icalevent['DTSTART;VALUE=DATE']) {
1300 $newevent['DTSTART;VALUE=DATE'] = dol_print_date($datecurstart, '%Y%m%d');
1301 $newevent['DTEND;VALUE=DATE'] = dol_print_date($datecurend + 1, '%Y%m%d');
1302 } else {
1303 $newevent['DTSTART'] = $datecurstart;
1304 $newevent['DTEND'] = $datecurend;
1305 }
1306 $moreicalevents[] = $newevent;
1307 }
1308 // Jump on next occurrence
1309 $numofevent++;
1310 $savdatecurstart = $datecurstart;
1311 if ($icalevent['RRULE']['FREQ'] == 'DAILY') {
1312 $datecurstart = dol_time_plus_duree($datecurstart, $interval, 'd');
1313 $datecurend = dol_time_plus_duree($datecurend, $interval, 'd');
1314 }
1315 if ($icalevent['RRULE']['FREQ'] == 'WEEKLY') {
1316 $datecurstart = dol_time_plus_duree($datecurstart, $interval, 'w');
1317 $datecurend = dol_time_plus_duree($datecurend, $interval, 'w');
1318 } elseif ($icalevent['RRULE']['FREQ'] == 'MONTHLY') {
1319 $datecurstart = dol_time_plus_duree($datecurstart, $interval, 'm');
1320 $datecurend = dol_time_plus_duree($datecurend, $interval, 'm');
1321 } elseif ($icalevent['RRULE']['FREQ'] == 'YEARLY') {
1322 $datecurstart = dol_time_plus_duree($datecurstart, $interval, 'y');
1323 $datecurend = dol_time_plus_duree($datecurend, $interval, 'y');
1324 }
1325 // Test to avoid infinite loop ($datecurstart must increase)
1326 if ($savdatecurstart >= $datecurstart) {
1327 dol_syslog("Found a rule freq ".$icalevent['RRULE']['FREQ']." not managed by dolibarr code. Assume 1 week frequency.", LOG_ERR);
1328 $datecurstart += 3600 * 24 * 7;
1329 $datecurend += 3600 * 24 * 7;
1330 }
1331 }
1332 }
1333 }
1334 $icalevents = array_merge($icalevents, $moreicalevents);
1335
1336 // Loop on each entry into cal file to know if entry is qualified and add an ActionComm into $eventarray
1337 foreach ($icalevents as $icalevent) {
1338 //var_dump($icalevent);
1339
1340 //print $icalevent['SUMMARY'].'->';
1341 //var_dump($icalevent);exit;
1342 if (!empty($icalevent['RRULE'])) {
1343 continue; // We found a repeatable event. It was already split into unitary events, so we discard general rule.
1344 }
1345
1346 // Create a new object action
1347 $event = new ActionComm($db);
1348 $addevent = false;
1349 if (isset($icalevent['DTSTART;VALUE=DATE'])) { // fullday event
1350 // For full day events, date are also GMT but they won't but converted using tz during output
1351 $datestart = dol_stringtotime($icalevent['DTSTART;VALUE=DATE'], 1);
1352 if (empty($icalevent['DTEND;VALUE=DATE'])) {
1353 $dateend = $datestart + 86400 - 1;
1354 } else {
1355 $dateend = dol_stringtotime($icalevent['DTEND;VALUE=DATE'], 1) - 1; // We remove one second to get last second of day
1356 }
1357 //print 'x'.$datestart.'-'.$dateend;exit;
1358 //print dol_print_date($dateend,'dayhour','gmt');
1359 $event->fulldayevent = 1;
1360 $addevent = true;
1361 } elseif (!is_array($icalevent['DTSTART'])) { // not fullday event (DTSTART is not array. It is a value like '19700101T000000Z' for 00:00 in greenwitch)
1362 $datestart = $icalevent['DTSTART'];
1363 $dateend = empty($icalevent['DTEND']) ? $datestart : $icalevent['DTEND'];
1364
1365 $datestart += +($offsettz * 3600);
1366 $dateend += +($offsettz * 3600);
1367
1368 $addevent = true;
1369 //var_dump($offsettz);
1370 //var_dump(dol_print_date($datestart, 'dayhour', 'gmt'));
1371 } elseif (isset($icalevent['DTSTART']['unixtime'])) { // File contains a local timezone + a TZ (for example when using bluemind)
1372 $datestart = $icalevent['DTSTART']['unixtime'];
1373 $dateend = $icalevent['DTEND']['unixtime'];
1374
1375 $datestart += +($offsettz * 3600);
1376 $dateend += +($offsettz * 3600);
1377
1378 // $buggedfile is set to uselocalandtznodaylight if conf->global->AGENDA_EXT_BUGGEDFILEx = 'uselocalandtznodaylight'
1379 if ($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
1380 // TODO
1381 }
1382 // $buggedfile is set to uselocalandtzdaylight if conf->global->AGENDA_EXT_BUGGEDFILEx = 'uselocalandtzdaylight' (for example with bluemind)
1383 if ($buggedfile === 'uselocalandtzdaylight') { // unixtime is a local date that does take daylight into account, TZID is +2 for example for 'Europe/Paris' in summer
1384 $localtzs = new DateTimeZone(preg_replace('/"/', '', $icalevent['DTSTART']['TZID']));
1385 $localtze = new DateTimeZone(preg_replace('/"/', '', $icalevent['DTEND']['TZID']));
1386 $localdts = new DateTime(dol_print_date($datestart, 'dayrfc', 'gmt'), $localtzs);
1387 $localdte = new DateTime(dol_print_date($dateend, 'dayrfc', 'gmt'), $localtze);
1388 $tmps = -1 * $localtzs->getOffset($localdts);
1389 $tmpe = -1 * $localtze->getOffset($localdte);
1390 $datestart += $tmps;
1391 $dateend += $tmpe;
1392 //var_dump($datestart);
1393 }
1394 $addevent = true;
1395 }
1396
1397 if ($addevent) {
1398 $event->id = $icalevent['UID'];
1399 $event->ref = $event->id;
1400 $userId = $userstatic->findUserIdByEmail($namecal);
1401 if (!empty($userId) && $userId > 0) {
1402 $event->userassigned[$userId] = $userId;
1403 $event->percentage = -1;
1404 }
1405
1406 $event->type_code = "ICALEVENT";
1407 $event->type_label = $namecal;
1408 $event->type_color = $colorcal;
1409 $event->type = 'icalevent';
1410 $event->type_picto = 'rss';
1411
1412 $event->icalname = $namecal;
1413 $event->icalcolor = $colorcal;
1414 $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.
1415 $event->datep = $datestart + $usertime;
1416 $event->datef = $dateend + $usertime;
1417
1418 if (isset($icalevent['SUMMARY']) && $icalevent['SUMMARY']) {
1419 $event->label = dol_string_nohtmltag($icalevent['SUMMARY']);
1420 } elseif (isset($icalevent['DESCRIPTION']) && $icalevent['DESCRIPTION']) {
1421 $event->label = dol_nl2br(dol_string_nohtmltag($icalevent['DESCRIPTION']), 1);
1422 } else {
1423 $event->label = $langs->trans("ExtSiteNoLabel");
1424 }
1425
1426 // Priority (see https://www.kanzaki.com/docs/ical/priority.html)
1427 // LOW = 0 to 4
1428 // MEDIUM = 5
1429 // HIGH = 6 to 9
1430 if (!empty($icalevent['PRIORITY'])) {
1431 $event->priority = $icalevent['PRIORITY'];
1432 }
1433
1434 // Transparency (see https://www.kanzaki.com/docs/ical/transp.html)
1435 if (!empty($icalevent['TRANSP'])) {
1436 if ($icalevent['TRANSP'] == "TRANSPARENT") {
1437 $event->transparency = 0; // 0 = available / free
1438 }
1439 if ($icalevent['TRANSP'] == "OPAQUE") {
1440 $event->transparency = 1; // 1 = busy
1441 }
1442
1443 // TODO: MS outlook states
1444 // X-MICROSOFT-CDO-BUSYSTATUS:FREE + TRANSP:TRANSPARENT => Available / Free
1445 // X-MICROSOFT-CDO-BUSYSTATUS:FREE + TRANSP:OPAQUE => Work another place
1446 // X-MICROSOFT-CDO-BUSYSTATUS:TENTATIVE + TRANSP:OPAQUE => With reservations
1447 // X-MICROSOFT-CDO-BUSYSTATUS:BUSY + TRANSP:OPAQUE => Busy
1448 // X-MICROSOFT-CDO-BUSYSTATUS:OOF + TRANSP:OPAQUE => Away from the office / off-site
1449 }
1450
1451 if (!empty($icalevent['LOCATION'])) {
1452 $event->location = $icalevent['LOCATION'];
1453 }
1454
1455 $event->date_start_in_calendar = $event->datep;
1456
1457 if ($event->datef != '' && $event->datef >= $event->datep) {
1458 $event->date_end_in_calendar = $event->datef;
1459 } else {
1460 $event->date_end_in_calendar = $event->datep;
1461 }
1462
1463 // Add event into $eventarray if date range are ok.
1464 if ($event->date_end_in_calendar < $firstdaytoshow || $event->date_start_in_calendar >= $lastdaytoshow) {
1465 //print 'x'.$datestart.'-'.$dateend;exit;
1466 //print 'x'.$datestart.'-'.$dateend;exit;
1467 //print 'x'.$datestart.'-'.$dateend;exit;
1468 // This record is out of visible range
1469 } else {
1470 if ($event->date_start_in_calendar < $firstdaytoshow) {
1471 $event->date_start_in_calendar = $firstdaytoshow;
1472 }
1473 if ($event->date_end_in_calendar >= $lastdaytoshow) {
1474 $event->date_end_in_calendar = ($lastdaytoshow - 1);
1475 }
1476
1477 // Add an entry in actionarray for each day
1478 $daycursor = $event->date_start_in_calendar;
1479 $annee = (int) dol_print_date($daycursor, '%Y', 'tzuserrel');
1480 $mois = (int) dol_print_date($daycursor, '%m', 'tzuserrel');
1481 $jour = (int) dol_print_date($daycursor, '%d', 'tzuserrel');
1482
1483 // Loop on each day covered by action to prepare an index to show on calendar
1484 $loop = true;
1485 $j = 0;
1486 // daykey must be date that represent day box in calendar so must be a user time
1487 $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
1488 $daykeygmt = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
1489 do {
1490 //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').' ';
1491 $eventarray[$daykey][] = $event;
1492 $daykey += 60 * 60 * 24;
1493 $daykeygmt += 60 * 60 * 24; // Add one day
1494 if (($event->fulldayevent ? $daykeygmt : $daykey) > $event->date_end_in_calendar) {
1495 $loop = false;
1496 }
1497 } while ($loop);
1498 }
1499 }
1500 }
1501 }
1502 }
1503}
1504
1505// Complete $eventarray with events coming from external module
1506$parameters = array();
1507$object = null;
1508$reshook = $hookmanager->executeHooks('getCalendarEvents', $parameters, $object, $action);
1509if (!empty($hookmanager->resArray['eventarray'])) {
1510 foreach ($hookmanager->resArray['eventarray'] as $keyDate => $events) {
1511 if (!isset($eventarray[$keyDate])) {
1512 $eventarray[$keyDate] = array();
1513 }
1514 $eventarray[$keyDate] = array_merge($eventarray[$keyDate], $events);
1515 }
1516}
1517
1518// Sort events
1519foreach ($eventarray as $keyDate => &$dateeventarray) {
1520 usort($dateeventarray, 'sort_events_by_date');
1521}
1522
1523
1524$maxnbofchar = 0;
1525$cachethirdparties = array();
1526$cachecontacts = array();
1527$cacheusers = array();
1528
1529// Define theme_datacolor array
1530$color_file = DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/theme_vars.inc.php";
1531if (is_readable($color_file)) {
1532 include $color_file;
1533}
1534if (!is_array($theme_datacolor)) {
1535 $theme_datacolor = array(array(137, 86, 161), array(60, 147, 183), array(250, 190, 80), array(80, 166, 90), array(190, 190, 100), array(91, 115, 247), array(140, 140, 220), array(190, 120, 120), array(115, 125, 150), array(100, 170, 20), array(150, 135, 125), array(85, 135, 150), array(150, 135, 80), array(150, 80, 150));
1536}
1537
1538$massactionbutton = '';
1539
1540print_barre_liste($langs->trans("Agenda"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, -1, 'object_action', 0, $nav.'<span class="marginleftonly"></span>'.$newcardbutton, '', $limit, 1, 0, 1, $viewmode);
1541
1542// Show div with list of calendars
1543print $s;
1544
1545
1546if (empty($mode) || $mode == 'show_month') { // View by month
1547 $newparam = $param; // newparam is for birthday links
1548 $newparam = preg_replace('/showbirthday=/i', 'showbirthday_=', $newparam); // To avoid replacement when replace day= is done
1549 $newparam = preg_replace('/mode=show_month&?/i', '', $newparam);
1550 $newparam = preg_replace('/mode=show_week&?/i', '', $newparam);
1551 $newparam = preg_replace('/day=[0-9]+&?/i', '', $newparam);
1552 $newparam = preg_replace('/month=[0-9]+&?/i', '', $newparam);
1553 $newparam = preg_replace('/year=[0-9]+&?/i', '', $newparam);
1554 $newparam = preg_replace('/viewcal=[0-9]+&?/i', '', $newparam);
1555 $newparam = preg_replace('/showbirthday_=/i', 'showbirthday=', $newparam); // Restore correct parameter
1556 $newparam .= '&viewcal=1';
1557
1558 print '<div class="liste_titre liste_titre_bydiv centpercent">';
1559 print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, '', $filtert, '', $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid, $search_categ_cus);
1560 print '</div>';
1561
1562 print '<div class="div-table-responsive-no-min sectioncalendarbymonth maxscreenheightless300">';
1563 print '<table class="centpercent noborder nocellnopadd cal_pannel cal_month listwithfilterbefore">';
1564 print ' <tr class="liste_titre">';
1565 // Column title of weeks numbers
1566 echo ' <td class="center">#</td>';
1567 $i = 0;
1568 while ($i < 7) {
1569 print ' <td class="center bold uppercase tdfordaytitle'.($i == 0 ? ' borderleft' : '').'">';
1570 $numdayinweek = (($i + (isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1)) % 7);
1571 if (!empty($conf->dol_optimize_smallscreen)) {
1572 $labelshort = array(0 => 'SundayMin', 1 => 'MondayMin', 2 => 'TuesdayMin', 3 => 'WednesdayMin', 4 => 'ThursdayMin', 5 => 'FridayMin', 6 => 'SaturdayMin');
1573 print $langs->trans($labelshort[$numdayinweek]);
1574 } else {
1575 print $langs->trans("Day".$numdayinweek);
1576 }
1577 print ' </td>'."\n";
1578 $i++;
1579 }
1580 echo ' </tr>'."\n";
1581
1582 $todayarray = dol_getdate($now, true);
1583 $todaytms = dol_mktime(0, 0, 0, $todayarray['mon'], $todayarray['mday'], $todayarray['year']);
1584
1585 // In loops, tmpday contains day nb in current month (can be zero or negative for days of previous month)
1586 //var_dump($eventarray);
1587 for ($iter_week = 0; $iter_week < 6; $iter_week++) {
1588 echo " <tr>\n";
1589 // Get date of the current day, format 'yyyy-mm-dd'
1590 if ($tmpday <= 0) { // If number of the current day is in previous month
1591 $currdate0 = sprintf("%04d", $prev_year).sprintf("%02d", $prev_month).sprintf("%02d", $max_day_in_prev_month + $tmpday);
1592 } elseif ($tmpday <= $max_day_in_month) { // If number of the current day is in current month
1593 $currdate0 = sprintf("%04d", $year).sprintf("%02d", $month).sprintf("%02d", $tmpday);
1594 } else { // If number of the current day is in next month
1595 $currdate0 = sprintf("%04d", $next_year).sprintf("%02d", $next_month).sprintf("%02d", $tmpday - $max_day_in_month);
1596 }
1597 // Get week number for the targeted date '$currdate0'
1598 $numweek0 = date("W", strtotime(date($currdate0)));
1599 // Show the week number, and define column width
1600 echo ' <td class="center weeknumber opacitymedium" width="2%">'.$numweek0.'</td>';
1601
1602 for ($iter_day = 0; $iter_day < 7; $iter_day++) {
1603 if ($tmpday <= 0) {
1604 /* Show days before the beginning of the current month (previous month) */
1605 $style = 'cal_other_month cal_past';
1606 if ($iter_day == 6) {
1607 $style .= ' cal_other_month_right';
1608 }
1609 echo ' <td class="'.$style.' nowrap tdtop" width="14%">';
1610 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1611 show_day_events($db, $max_day_in_prev_month + $tmpday, $prev_month, $prev_year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
1612 echo " </td>\n";
1613 } elseif ($tmpday <= $max_day_in_month) {
1614 /* Show days of the current month */
1615 $curtime = dol_mktime(0, 0, 0, $month, $tmpday, $year);
1616 $style = 'cal_current_month';
1617 if ($iter_day == 6) {
1618 $style .= ' cal_current_month_right';
1619 }
1620 $today = 0;
1621 if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $month && $todayarray['year'] == $year) {
1622 $today = 1;
1623 }
1624 if ($today) {
1625 $style = 'cal_today';
1626 }
1627 if ($curtime < $todaytms) {
1628 $style .= ' cal_past';
1629 }
1630 //var_dump($todayarray['mday']."==".$tmpday." && ".$todayarray['mon']."==".$month." && ".$todayarray['year']."==".$year.' -> '.$style);
1631 echo ' <td class="'.$style.' nowrap tdtop" width="14%">';
1632 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1633 show_day_events($db, $tmpday, $month, $year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam, 0, 60, 0, $bookcalcalendars);
1634 echo "</td>\n";
1635 } else {
1636 /* Show days after the current month (next month) */
1637 $style = 'cal_other_month';
1638 if ($iter_day == 6) {
1639 $style .= ' cal_other_month_right';
1640 }
1641 echo ' <td class="'.$style.' nowrap tdtop" width="14%">';
1642 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1643 show_day_events($db, $tmpday - $max_day_in_month, $next_month, $next_year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
1644 echo "</td>\n";
1645 }
1646 $tmpday++;
1647 }
1648 echo " </tr>\n";
1649 }
1650 print "</table>\n";
1651 print '</div>';
1652
1653 print '<input type="hidden" name="actionmove" value="mupdate">';
1654 print '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($_SERVER['PHP_SELF']).'?mode=show_month&'.dol_escape_htmltag($_SERVER['QUERY_STRING']).'">';
1655 print '<input type="hidden" name="newdate" id="newdate">';
1656} elseif ($mode == 'show_week') {
1657 // View by week
1658 $newparam = $param; // newparam is for birthday links
1659 $newparam = preg_replace('/showbirthday=/i', 'showbirthday_=', $newparam); // To avoid replacement when replace day= is done
1660 $newparam = preg_replace('/mode=show_month&?/i', '', $newparam);
1661 $newparam = preg_replace('/mode=show_week&?/i', '', $newparam);
1662 $newparam = preg_replace('/day=[0-9]+&?/i', '', $newparam);
1663 $newparam = preg_replace('/month=[0-9]+&?/i', '', $newparam);
1664 $newparam = preg_replace('/year=[0-9]+&?/i', '', $newparam);
1665 $newparam = preg_replace('/viewweek=[0-9]+&?/i', '', $newparam);
1666 $newparam = preg_replace('/showbirthday_=/i', 'showbirthday=', $newparam); // Restore correct parameter
1667 $newparam .= '&viewweek=1';
1668
1669 print '<div class="liste_titre liste_titre_bydiv centpercent">';
1670 print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, '', $filtert, '', $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid);
1671 print '</div>';
1672
1673 print '<div class="div-table-responsive-no-min sectioncalendarbyweek maxscreenheightless300">';
1674 print '<table class="centpercent noborder nocellnopadd cal_pannel cal_month listwithfilterbefore">';
1675 print ' <tr class="liste_titre">';
1676 $i = 0;
1677 while ($i < 7) {
1678 echo ' <td class="center bold uppercase tdfordaytitle">'.$langs->trans("Day".(($i + (isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1)) % 7))."</td>\n";
1679 $i++;
1680 }
1681 echo " </tr>\n";
1682
1683 echo " <tr>\n";
1684
1685 for ($iter_day = 0; $iter_day < 7; $iter_day++) {
1686 // Show days of the current week
1687 $curtime = dol_time_plus_duree($firstdaytoshow, $iter_day, 'd'); // $firstdaytoshow is in timezone of server
1688 $tmpday = (int) dol_print_date($curtime, '%d', 'tzuserrel');
1689 $tmpmonth = (int) dol_print_date($curtime, '%m', 'tzuserrel');
1690 $tmpyear = (int) dol_print_date($curtime, '%Y', 'tzuserrel');
1691
1692 $style = 'cal_current_month';
1693 if ($iter_day == 6) {
1694 $style .= ' cal_other_month_right';
1695 }
1696
1697 $today = 0;
1698 $todayarray = dol_getdate($now, true);
1699 if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $tmpmonth && $todayarray['year'] == $tmpyear) {
1700 $today = 1;
1701 }
1702 if ($today) {
1703 $style = 'cal_today';
1704 }
1705
1706 echo ' <td class="'.$style.'" width="14%" valign="top">';
1707 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1708 show_day_events($db, $tmpday, $tmpmonth, $tmpyear, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, 0, $bookcalcalendars);
1709 echo " </td>\n";
1710 }
1711 echo " </tr>\n";
1712
1713 print "</table>\n";
1714 print '</div>';
1715
1716 echo '<input type="hidden" name="actionmove" value="mupdate">';
1717 echo '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($_SERVER['PHP_SELF']).'?mode=show_week&'.dol_escape_htmltag($_SERVER['QUERY_STRING']).'">';
1718 echo '<input type="hidden" name="newdate" id="newdate">';
1719} else { // View by day
1720 $newparam = $param; // newparam is for birthday links
1721 $newparam = preg_replace('/mode=show_month&?/i', '', $newparam);
1722 $newparam = preg_replace('/mode=show_week&?/i', '', $newparam);
1723 $newparam = preg_replace('/viewday=[0-9]+&?/i', '', $newparam);
1724 $newparam .= '&viewday=1';
1725 // Code to show just one day
1726 $style = 'cal_current_month cal_current_month_oneday';
1727 $today = 0;
1728 $todayarray = dol_getdate($now, true);
1729 if ($todayarray['mday'] == $day && $todayarray['mon'] == $month && $todayarray['year'] == $year) {
1730 $today = 1;
1731 }
1732 //if ($today) $style='cal_today';
1733
1734 $timestamp = dol_mktime(12, 0, 0, $month, $day, $year);
1735 $arraytimestamp = dol_getdate($timestamp);
1736
1737 print '<div class="liste_titre liste_titre_bydiv centpercent">';
1738 print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, '', $filtert, '', $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid);
1739 print '</div>';
1740
1741 print '<div class="div-table-responsive-no-min sectioncalendarbyday maxscreenheightless300">';
1742 echo '<table class="tagtable centpercent noborder nocellnopadd cal_pannel cal_month listwithfilterbefore" style="margin-bottom: 10px !important;">';
1743
1744 echo ' <tr class="tagtr liste_titre">';
1745 echo ' <td class="tagtd center bold uppercase">'.$langs->trans("Day".$arraytimestamp['wday'])."</td>\n";
1746 echo " </tr>\n";
1747
1748 /*
1749 echo ' <div class="tagtr">';
1750 echo ' <div class="tagtd width100"></div>';
1751 echo ' <div class="tagtd center">';
1752 echo show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, -1);
1753 echo ' </div>'."\n";
1754 echo " </div>\n";
1755 */
1756
1757 print '<tr><td>';
1758
1759 /* WIP View per hour */
1760 $useviewhour = 0;
1761 if ($useviewhour) {
1762 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
1763
1764 $maxheightwin = (isset($_SESSION["dol_screenheight"]) && $_SESSION["dol_screenheight"] > 500) ? ($_SESSION["dol_screenheight"] - 200) : 660; // Also into index.php file
1765
1766 echo '<div style="max-height: '.$maxheightwin.'px;">';
1767 echo '<div class="tagtable centpercent calendarviewcontainer">';
1768
1769 $maxnbofchar = 80;
1770
1771 $tmp = explode('-', getDolGlobalString('MAIN_DEFAULT_WORKING_HOURS'));
1772 $minhour = round((float) $tmp[0], 0);
1773 $maxhour = round((float) $tmp[1], 0);
1774 if ($minhour > 23) {
1775 $minhour = 23;
1776 }
1777 if ($maxhour < 1) {
1778 $maxhour = 1;
1779 }
1780 if ($maxhour <= $minhour) {
1781 $maxhour = $minhour + 1;
1782 }
1783
1784 $i = 0;
1785 $j = 0;
1786 while ($i < 24) {
1787 echo ' <div class="tagtr calendarviewcontainertr">'."\n";
1788 echo ' <div class="tagtd width100 tdtop">'.dol_print_date($i * 3600, 'hour', 'gmt').'</div>';
1789 echo ' <div class="tagtd '.$style.' tdtop"></div>'."\n";
1790 echo ' </div>'."\n";
1791 $i++;
1792 $j++;
1793 }
1794
1795 echo '</div></div>';
1796
1797 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1798 show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, 1, $bookcalcalendars);
1799
1800 print '</div>';
1801 } else {
1802 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
1803
1804 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1805 show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, 0, $bookcalcalendars);
1806
1807 print '</div>';
1808 }
1809
1810
1811 print '</td></tr>';
1812
1813 echo '</table>';
1814 print '</div>';
1815}
1816
1817print "\n".'</form>';
1818
1819// End of page
1820llxFooter();
1821$db->close();
1822
1823
1843function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventarray, $maxprint = 0, $maxnbofchar = 16, $newparam = '', $showinfo = 0, $minheight = 60, $nonew = 0, $bookcalcalendarsarray = array())
1844{
1845 global $user, $conf, $langs;
1846 global $action, $mode, $filter, $filtert, $status, $actioncode, $usergroup; // Filters used into search form
1847 global $theme_datacolor;
1848 global $cachethirdparties, $cachecontacts, $cacheusers, $colorindexused;
1849 global $hookmanager;
1850
1851 '@phan-var-force array{0:array{0:int,1:int,2:int},1:array{0:int,1:int,2:int},2:array{0:int,1:int,2:int},3:array{0:int,1:int,2:int}} $theme_datacolor
1852 @phan-var-force User[] $cacheusers
1853 @phan-var-force array<int<0,3>> $colorindexused';
1854
1855 if ($conf->use_javascript_ajax) { // Enable the "Show more button..."
1856 $conf->global->MAIN_JS_SWITCH_AGENDA = 1;
1857 }
1858
1859 $dateint = sprintf("%04d", $year).sprintf("%02d", $month).sprintf("%02d", $day);
1860
1861 //print 'show_day_events day='.$day.' month='.$month.' year='.$year.' dateint='.$dateint;
1862
1863 print "\n";
1864
1865 $curtime = dol_mktime(0, 0, 0, $month, $day, $year);
1866 $urltoshow = DOL_URL_ROOT.'/comm/action/index.php?mode=show_day&day='.str_pad((string) $day, 2, "0", STR_PAD_LEFT).'&month='.str_pad((string) $month, 2, "0", STR_PAD_LEFT).'&year='.$year.$newparam;
1867 $urltocreate = '';
1868 if ($user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create')) {
1869 $newparam .= '&month='.str_pad((string) $month, 2, "0", STR_PAD_LEFT).'&year='.$year;
1870 $hourminsec = '100000';
1871 $urltocreate = DOL_URL_ROOT.'/comm/action/card.php?action=create&datep='.sprintf("%04d%02d%02d", $year, $month, $day).$hourminsec.'&backtopage='.urlencode($_SERVER["PHP_SELF"].($newparam ? '?'.$newparam : ''));
1872 }
1873
1874 // Line with title of day
1875 print '<div id="dayevent_'.$dateint.'" class="dayevent tagtable centpercent nobordernopadding">'."\n";
1876
1877 if ($nonew <= 0) {
1878 print '<div class="tagtr cursorpointer" onclick="window.location=\''.$urltocreate.'\';"><div class="nowrap tagtd"><div class="left inline-block">';
1879 print '<a class="dayevent-aday" style="color: #666" href="'.$urltoshow.'">';
1880 if ($showinfo) {
1881 print dol_print_date($curtime, 'daytextshort');
1882 } else {
1883 print dol_print_date($curtime, '%d');
1884 }
1885 print '</a>';
1886 print '</div><div class="nowrap floatright inline-block marginrightonly">';
1887 if ($user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create')) {
1888 print '<a class="cursoradd" href="'.$urltocreate.'">'; // Explicit link, useful for nojs interfaces
1889 print img_picto($langs->trans("NewAction"), 'edit_add.png');
1890 print '</a>';
1891 }
1892 print '</div></div></div>'."\n";
1893 }
1894
1895 if ($nonew < 0) {
1896 print '</div>';
1897 return;
1898 }
1899
1900 // Line with td contains all div of each events
1901 print '<div class="tagtr">';
1902 print '<div class="tagtd centpercent agendacell sortable">';
1903
1904 //$curtime = dol_mktime (0, 0, 0, $month, $day, $year);
1905 $i = 0;
1906 $ireallyshown = 0;
1907 $itoshow = 0;
1908 $numother = 0;
1909 $numbirthday = 0;
1910 $numical = 0;
1911 $numicals = array();
1912 $ymd = sprintf("%04d", $year).sprintf("%02d", $month).sprintf("%02d", $day);
1913
1914 $colorindexused[$user->id] = 0; // Color index for current user (user->id) is always 0
1915 $nextindextouse = is_array($colorindexused) ? count($colorindexused) : 0; // At first run this is 0, so fist user has 0, next 1, ...
1916 //var_dump($colorindexused);
1917
1918 include_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
1919 $tmpholiday = new Holiday($db);
1920
1921 foreach ($eventarray as $daykey => $notused) { // daykey is the 'YYYYMMDD' to show according to user
1922 $annee = (int) dol_print_date($daykey, '%Y', 'gmt'); // We use gmt because we want the value represented by string 'YYYYMMDD'
1923 $mois = (int) dol_print_date($daykey, '%m', 'gmt'); // We use gmt because we want the value represented by string 'YYYYMMDD'
1924 $jour = (int) dol_print_date($daykey, '%d', 'gmt'); // We use gmt because we want the value represented by string 'YYYYMMDD'
1925
1926 //print 'event daykey='.$daykey.' dol_print_date(daykey)='.dol_print_date($daykey, 'dayhour', 'gmt').' jour='.$jour.' mois='.$mois.' annee='.$annee."<br>\n";
1927 //print 'event daykey='.$daykey.' dol_print_date(daykey)='.dol_print_date($daykey, 'dayhour', 'gmt').' day='.$day.' month='.$month.' year='.$year."<br>\n";
1928
1929 if ($day == $jour && $month == $mois && $year == $annee) {
1930 foreach ($eventarray[$daykey] as $index => $event) {
1931 if ($i < $maxprint || $maxprint == 0 || getDolGlobalString('MAIN_JS_SWITCH_AGENDA')) {
1932 $keysofuserassigned = array_keys($event->userassigned);
1933 $ponct = ($event->date_start_in_calendar == $event->date_end_in_calendar);
1934
1935 // Define $color (Hex string like '0088FF') and $cssclass of event
1936 $color = -1;
1937 $cssclass = '';
1938 $colorindex = -1;
1939 if (in_array($user->id, $keysofuserassigned)) {
1940 $cssclass = 'family_mytasks';
1941
1942 if (empty($cacheusers[$event->userownerid])) {
1943 $newuser = new User($db);
1944 $newuser->fetch($event->userownerid);
1945 $cacheusers[$event->userownerid] = $newuser;
1946 }
1947 //var_dump($cacheusers[$event->userownerid]->color);
1948
1949 // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
1950 if (!empty($cacheusers[$event->userownerid]->color)) {
1951 $color = $cacheusers[$event->userownerid]->color;
1952 }
1953 } elseif ($event->type_code == 'ICALEVENT') { // Event come from external ical file
1954 $numical++;
1955 if (!empty($event->icalname)) {
1956 if (!isset($numicals[dol_string_nospecial($event->icalname)])) {
1957 $numicals[dol_string_nospecial($event->icalname)] = 0;
1958 }
1959 $numicals[dol_string_nospecial($event->icalname)]++;
1960 }
1961
1962 $color = ($event->icalcolor ? $event->icalcolor : -1);
1963 $cssclass = (!empty($event->icalname) ? 'family_ext'.md5($event->icalname) : 'family_other');
1964 } elseif ($event->type_code == 'BIRTHDAY') {
1965 $numbirthday++;
1966 $colorindex = 2;
1967 $cssclass = 'family_birthday ';
1968 $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
1969 } elseif ($event->type == 'bookcal_calendar') {
1970 $numbirthday++;
1971 $colorindex = 3;
1972 $cssclass = 'family_bookcal_calendar_'.(!empty($bookcalcalendarsarray["availabilitieslink"]) ? $bookcalcalendarsarray["availabilitieslink"][$event->fk_bookcal_calendar] : "");
1973 $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
1974 } else {
1975 $numother++;
1976 $color = ($event->icalcolor ? $event->icalcolor : -1);
1977 $cssclass = (!empty($event->icalname) ? 'family_ext'.md5($event->icalname) : 'family_other');
1978
1979 if (empty($cacheusers[$event->userownerid])) {
1980 $newuser = new User($db);
1981 $newuser->fetch($event->userownerid);
1982 $cacheusers[$event->userownerid] = $newuser;
1983 }
1984 //var_dump($cacheusers[$event->userownerid]->color);
1985
1986 // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
1987 if (!empty($cacheusers[$event->userownerid]->color)) {
1988 $color = $cacheusers[$event->userownerid]->color;
1989 }
1990 }
1991
1992 if ($color < 0) { // Color was not set on user card. Set color according to color index.
1993 // Define color index if not yet defined
1994 $idusertouse = ($event->userownerid ? $event->userownerid : 0);
1995 if (isset($colorindexused[$idusertouse])) {
1996 $colorindex = $colorindexused[$idusertouse]; // Color already assigned to this user
1997 } else {
1998 $colorindex = $nextindextouse;
1999 $colorindexused[$idusertouse] = $colorindex;
2000 if (!empty($theme_datacolor[$nextindextouse + 1])) {
2001 $nextindextouse++; // Prepare to use next color
2002 }
2003 }
2004 if (isset($theme_datacolor[$colorindex])) {
2005 $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
2006 } elseif (getDolGlobalString('THEME_ELDY_BACKBODY')) {
2007 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
2008 $color = colorArrayToHex(explode(',', getDolGlobalString('THEME_ELDY_BACKBODY')));
2009 } else {
2010 $color = "ffffff";
2011 }
2012 }
2013 $cssclass = $cssclass.' eventday_'.$ymd;
2014
2015 // Defined style to disable drag and drop feature
2016 if ($event->type_code == 'AC_OTH_AUTO') {
2017 $cssclass .= " unmovable";
2018 } elseif ($event->type_code == 'HOLIDAY') {
2019 $cssclass .= " unmovable";
2020 } elseif ($event->type_code == 'BIRTHDAY') {
2021 $cssclass .= " unmovable";
2022 } elseif ($event->type_code == 'ICALEVENT') {
2023 $cssclass .= " unmovable";
2024 } elseif ($event->date_start_in_calendar && $event->date_end_in_calendar && date('Ymd', $event->date_start_in_calendar) != date('Ymd', $event->date_end_in_calendar)) {
2025 // If the event is on several days
2026 $tmpyearend = dol_print_date($event->date_start_in_calendar, '%Y', 'tzuserrel');
2027 $tmpmonthend = dol_print_date($event->date_start_in_calendar, '%m', 'tzuserrel');
2028 $tmpdayend = dol_print_date($event->date_start_in_calendar, '%d', 'tzuserrel');
2029 //var_dump($tmpyearend.' '.$tmpmonthend.' '.$tmpdayend);
2030 if ($tmpyearend != $annee || $tmpmonthend != $mois || $tmpdayend != $jour) {
2031 $cssclass .= " unmovable unmovable-mustusefirstdaytodrag";
2032 } else {
2033 $cssclass .= ' movable cursormove';
2034 }
2035 } else {
2036 if ($user->hasRight('agenda', 'allactions', 'create') ||
2037 (($event->authorid == $user->id || $event->userownerid == $user->id) && $user->hasRight('agenda', 'myactions', 'create'))) {
2038 $cssclass .= " movable cursormove";
2039 } else {
2040 $cssclass .= " unmovable";
2041 }
2042 }
2043
2044 $h = '';
2045 $nowrapontd = 1;
2046 if ($mode == 'show_day') {
2047 $h = 'height: 100%; ';
2048 $nowrapontd = 0;
2049 }
2050 if ($mode == 'show_week') {
2051 $h = 'height: 100%; ';
2052 $nowrapontd = 0;
2053 }
2054
2055 // Show event box
2056 print "\n";
2057 print '<!-- start event '.$i.' -->'."\n";
2058
2059 $morecss = '';
2060 if ($maxprint && $ireallyshown >= $maxprint) {
2061 $morecss = 'showifmore';
2062 }
2063 if ($event->type == 'birthdate' && !GETPOST('check_birthday')) {
2064 $morecss = 'hidden';
2065 }
2066 if ($event->type == 'holiday' && !GETPOST('check_holiday')) {
2067 $morecss = 'hidden';
2068 }
2069 /* I comment this because it hides event recorded from bookcal online page
2070 if ($event->type == 'bookcal_calendar' && !GETPOST('check_bookcal_calendar_'.$bookcalcalendarsarray["availabilitieslink"][$event->fk_bookcal_calendar])) {
2071 $morecss = 'hidden';
2072 } */
2073 if ($morecss != 'hidden') {
2074 $itoshow++;
2075 }
2076 if ($morecss != 'showifmore' && $morecss != 'hidden') {
2077 $ireallyshown++;
2078 }
2079
2080 //var_dump($event->type.' - '.$morecss.' - '.$cssclass.' - '.$i.' - '.$ireallyshown.' - '.$itoshow);
2081 if (isModEnabled("bookcal") && $event->type == 'bookcal_calendar') {
2082 print '<div id="event_'.$ymd.'_'.$i.'" class="event family_'.$event->type.'_'.$bookcalcalendarsarray["availabilitieslink"][$event->fk_bookcal_calendar].' '.$cssclass.($morecss ? ' '.$morecss : '').'"';
2083 } else {
2084 print '<div id="event_'.$ymd.'_'.$i.'" class="event family_'.$event->type.' '.$cssclass.($morecss ? ' '.$morecss : '').'"';
2085 }
2086 //print ' style="height: 100px;';
2087 //print ' position: absolute; top: 40px; width: 50%;';
2088 //print '"';
2089 print '>';
2090
2091 //var_dump($event->userassigned);
2092 //var_dump($event->transparency);
2093 print '<table class="centpercent cal_event';
2094 print(empty($event->transparency) ? ' cal_event_notbusy' : ' cal_event_busy');
2095 //if (empty($event->transparency) && empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) print ' opacitymedium'; // Not busy
2096 print '" style="'.$h;
2097 $colortouse = $color;
2098 // If colortouse is similar than background, we force to change it.
2099 if (empty($event->transparency) && !getDolGlobalString('AGENDA_NO_TRANSPARENT_ON_NOT_BUSY')) {
2100 print 'background: #f0f0f0;';
2101 print 'border-left: 5px solid #'.$colortouse.';';
2102 } else {
2103 print 'background: #f0f0f0;';
2104 print 'border-left: 5px solid #'.dol_color_minus($colortouse, -3).';';
2105 //print 'background: -webkit-gradient(linear, left top, left bottom, from(#'.dol_color_minus($colortouse, -3).'), to(#'.dol_color_minus($colortouse, -1).'));';
2106 }
2107 //print 'background: #'.$colortouse.';';
2108 //print 'background: -webkit-gradient(linear, left top, left bottom, from(#'.dol_color_minus($color, -3).'), to(#'.dol_color_minus($color, -1).'));';
2109 //if (!empty($event->transparency)) print 'background: #'.$color.'; background: -webkit-gradient(linear, left top, left bottom, from(#'.$color.'), to(#'.dol_color_minus($color,1).'));';
2110 //else print 'background-color: transparent !important; background: none; border: 1px solid #bbb;';
2111 //print ' -moz-border-radius:4px;"';
2112 //print 'border: 1px solid #ccc" width="100%"';
2113 print '">';
2114 print '<tr>';
2115 print '<td class="tdoverflow nobottom small centpercent '.($nowrapontd ? 'nowrap ' : '').'cal_event'.($event->type_code == 'BIRTHDAY' ? ' cal_event_birthday' : '').'">';
2116 print '<!-- left section of event -->';
2117
2118 $daterange = '';
2119
2120 if ($event->type_code == 'BIRTHDAY') {
2121 // It's birthday calendar
2122 $picb = '<i class="fas fa-birthday-cake inline-block valignmiddle"></i>';
2123 //$pice = '<i class="fas fa-briefcase inline-block"></i>';
2124 //$typea = ($objp->typea == 'birth') ? $picb : $pice;
2125 //var_dump($event);
2126 print $picb.' '.$langs->trans("Birthday").'<br>';
2127 //print img_picto($langs->trans("Birthday"), 'birthday-cake').' ';
2128
2129 $tmpid = $event->id;
2130
2131 if (empty($cachecontacts[$tmpid])) {
2132 $newcontact = new Contact($db);
2133 $newcontact->fetch($tmpid);
2134 $cachecontacts[$tmpid] = $newcontact;
2135 }
2136 print $cachecontacts[$tmpid]->getNomUrl(1, '', 0, '', -1, 0, 'valignmiddle inline-block');
2137
2138 //$event->picto = 'birthday-cake';
2139 //print $event->getNomUrl(1, $maxnbofchar, 'cal_event', 'birthday', 'contact');
2140 /*$listofcontacttoshow = '';
2141 $listofcontacttoshow .= '<br>'.$cacheusers[$tmpid]->getNomUrl(-1, '', 0, 0, 0, 0, '', 'paddingright valignmiddle');
2142 print $listofcontacttoshow;
2143 */
2144 } elseif ($event->type_code == 'HOLIDAY') {
2145 // It's holiday calendar
2146 $tmpholiday->fetch($event->id);
2147
2148 print $tmpholiday->getNomUrl(1, -1, 0, 'valignmiddle inline-block');
2149
2150 $tmpid = $tmpholiday->fk_user;
2151 if (empty($cacheusers[$tmpid])) {
2152 $newuser = new User($db);
2153 $newuser->fetch($tmpid);
2154 $cacheusers[$tmpid] = $newuser;
2155 }
2156
2157 $listofusertoshow = '';
2158 $listofusertoshow .= '<br>'.$cacheusers[$tmpid]->getNomUrl(-1, '', 0, 0, 0, 0, '', 'paddingright valignmiddle inline-block');
2159 print $listofusertoshow;
2160 }
2161
2162 $parameters = array();
2163 $reshook = $hookmanager->executeHooks('eventOptions', $parameters, $event, $action); // Note that $action and $object may have been modified by some hooks
2164 if ($reshook < 0) {
2165 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2166 } else {
2167 '@phan-var-force ActionComm $event';
2168 if (empty($reshook)) {
2169 // Other calendar
2170 /*
2171 if (empty($event->fulldayevent)) {
2172 //print $event->getNomUrl(2).' ';
2173 }
2174 */
2175
2176 // Date
2177 if (empty($event->fulldayevent)) {
2178 // Show hours (start ... end)
2179 $tmpyearstart = dol_print_date($event->date_start_in_calendar, '%Y', 'tzuserrel');
2180 $tmpmonthstart = dol_print_date($event->date_start_in_calendar, '%m', 'tzuserrel');
2181 $tmpdaystart = dol_print_date($event->date_start_in_calendar, '%d', 'tzuserrel');
2182 $tmpyearend = dol_print_date($event->date_end_in_calendar, '%Y', 'tzuserrel');
2183 $tmpmonthend = dol_print_date($event->date_end_in_calendar, '%m', 'tzuserrel');
2184 $tmpdayend = dol_print_date($event->date_end_in_calendar, '%d', 'tzuserrel');
2185
2186 // Hour start
2187 if ($tmpyearstart == $annee && $tmpmonthstart == $mois && $tmpdaystart == $jour) {
2188 $daterange .= dol_print_date($event->date_start_in_calendar, 'hour', 'tzuserrel');
2189 if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) {
2190 if ($tmpyearstart == $tmpyearend && $tmpmonthstart == $tmpmonthend && $tmpdaystart == $tmpdayend) {
2191 $daterange .= '-';
2192 }
2193 //else
2194 //print '...';
2195 }
2196 }
2197 if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) {
2198 if ($tmpyearstart != $tmpyearend || $tmpmonthstart != $tmpmonthend || $tmpdaystart != $tmpdayend) {
2199 $daterange .= '...';
2200 }
2201 }
2202 // Hour end
2203 if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) {
2204 if ($tmpyearend == $annee && $tmpmonthend == $mois && $tmpdayend == $jour) {
2205 $daterange .= dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel');
2206 }
2207 }
2208 } else {
2209 if ($showinfo) {
2210 print $langs->trans("EventOnFullDay")."<br>\n";
2211 }
2212 }
2213
2214 // Show title
2215 $titletoshow = $daterange;
2216 $titletoshow .= ($titletoshow ? ' ' : '').dol_escape_htmltag($event->label);
2217
2218 if ($event->type_code != 'ICALEVENT') {
2219 $savlabel = $event->label;
2220 $event->label = $titletoshow;
2221 // Note: List of users are inside $event->userassigned. Link may be clickable depending on permissions of user.
2222 $titletoshow = (($event->type_picto || $event->type_code) ? $event->getTypePicto() : '');
2223 $titletoshow .= $event->getNomUrl(0, $maxnbofchar, 'cal_event cal_event_title valignmiddle', '', 0, 0); // do not add 'inline-block' in css here: it makes the title transformed completely into '...'
2224 $event->label = $savlabel;
2225 }
2226
2227 // Loop on each assigned user
2228 $listofusertoshow = '';
2229 $posuserassigned = 0;
2230 foreach ($event->userassigned as $tmpid => $tmpdata) {
2231 if (!$posuserassigned && $titletoshow) {
2232 $listofusertoshow .= '<br>';
2233 }
2234 $posuserassigned++;
2235 if (empty($cacheusers[$tmpid])) {
2236 $newuser = new User($db);
2237 $newuser->fetch($tmpid);
2238 $cacheusers[$tmpid] = $newuser;
2239 }
2240
2241 $listofusertoshow .= $cacheusers[$tmpid]->getNomUrl(-3, '', 0, 0, 0, 0, '', 'valignmiddle inline-block');
2242 }
2243
2244 print $titletoshow;
2245 print $listofusertoshow.' &nbsp;';
2246
2247 if ($event->type_code == 'ICALEVENT') {
2248 print '<br>('.dol_trunc($event->icalname, $maxnbofchar).')';
2249 }
2250
2251 $thirdparty_id = ($event->socid > 0 ? $event->socid : ((is_object($event->societe) && $event->societe->id > 0) ? $event->societe->id : 0));
2252 $contact_id = ($event->contact_id > 0 ? $event->contact_id : ((is_object($event->contact) && $event->contact->id > 0) ? $event->contact->id : 0));
2253
2254 // If action related to company / contact
2255 $linerelatedto = '';
2256 if ($thirdparty_id > 0) {
2257 if (!isset($cachethirdparties[$thirdparty_id]) || !is_object($cachethirdparties[$thirdparty_id])) {
2258 $thirdparty = new Societe($db);
2259 $thirdparty->fetch($thirdparty_id);
2260 $cachethirdparties[$thirdparty_id] = $thirdparty;
2261 } else {
2262 $thirdparty = $cachethirdparties[$thirdparty_id];
2263 }
2264 if (!empty($thirdparty->id)) {
2265 $linerelatedto .= $thirdparty->getNomUrl(1, '', 0, 0, -1, 0, '', 'valignmiddle inline-block');
2266 }
2267 }
2268 if (!empty($contact_id) && $contact_id > 0) {
2269 if (empty($cachecontacts[$contact_id]) || !is_object($cachecontacts[$contact_id])) {
2270 $contact = new Contact($db);
2271 $contact->fetch($contact_id);
2272 $cachecontacts[$contact_id] = $contact;
2273 } else {
2274 $contact = $cachecontacts[$contact_id];
2275 }
2276 if ($linerelatedto) {
2277 $linerelatedto .= '&nbsp;';
2278 }
2279 if (!empty($contact->id)) {
2280 $linerelatedto .= $contact->getNomUrl(1, '', 0, '', -1, 0, 'valignmiddle inline-block');
2281 }
2282 }
2283 if (!empty($event->fk_element) && $event->fk_element > 0 && !empty($event->elementtype) && getDolGlobalString('AGENDA_SHOW_LINKED_OBJECT')) {
2284 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
2285 if ($linerelatedto) {
2286 $linerelatedto .= '<br>';
2287 }
2288 $linerelatedto .= dolGetElementUrl($event->fk_element, $event->elementtype, 1);
2289 }
2290 if ($linerelatedto) {
2291 print ' '.$linerelatedto;
2292 }
2293 } elseif (!empty($reshook)) {
2294 print $hookmanager->resPrint;
2295 }
2296 }
2297
2298 // Show location
2299 if ($showinfo) {
2300 if ($event->location) {
2301 print '<br>';
2302 print $langs->trans("Location").': '.$event->location;
2303 }
2304 }
2305
2306 print '</td>';
2307 // Status - Percent
2308 $withstatus = 0;
2309 if ($event->type_code != 'BIRTHDAY' && $event->type_code != 'ICALEVENT') {
2310 $withstatus = 1;
2311 if ($event->percentage >= 0) {
2312 $withstatus = 2;
2313 }
2314 }
2315 print '<td class="nobottom right nowrap cal_event_right'.($withstatus >= 2 ? ' cal_event_right_status' : '').'">';
2316 if ($withstatus) {
2317 print $event->getLibStatut(3, 1);
2318 } else {
2319 print '&nbsp;';
2320 }
2321 print '</td></tr></table>';
2322 print '</div><!-- end event '.$i.' -->'."\n";
2323
2324 $i++;
2325 } else {
2326 print '<a href="'.DOL_URL_ROOT.'/comm/action/index.php?mode='.$mode.'&maxprint=0&month='.((int) $monthshown).'&year='.((int) $year);
2327 print($status ? '&status='.$status : '').($filter ? '&filter='.urlencode($filter) : '');
2328 print($filtert ? '&search_filtert='.urlencode((string) $filtert) : '');
2329 print($usergroup ? '&search_usergroup='.urlencode($usergroup) : '');
2330 print($actioncode != '' ? '&search_actioncode='.urlencode($actioncode) : '');
2331 print '">'.img_picto("all", "1downarrow_selected.png").' ...';
2332 print ' +'.(count($eventarray[$daykey]) - $maxprint);
2333 print '</a>';
2334 break;
2335 //$ok=false; // To avoid to show twice the link
2336 }
2337 }
2338
2339 break;
2340 }
2341 }
2342 if (!$i) { // No events
2343 print '&nbsp;';
2344 }
2345
2346 if (getDolGlobalString('MAIN_JS_SWITCH_AGENDA') && $itoshow > $ireallyshown && $maxprint) {
2347 print '<div class="center cursorpointer" id="more_'.$ymd.'">'.img_picto("All", "angle-double-down", 'class="warning"').' +'.($itoshow - $ireallyshown).'</div>';
2348 //print ' +'.(count($eventarray[$daykey])-$maxprint);
2349
2350 print '<script type="text/javascript">'."\n";
2351 print 'jQuery(document).ready(function () {'."\n";
2352 print ' var open=0;'."\n";
2353 print ' jQuery("#more_'.$ymd.'").click(function() { console.log("Click on showmore for '.$ymd.'"); reinit_day_'.$ymd.'(); event.stopImmediatePropagation(); });'."\n";
2354 print ' function reinit_day_'.$ymd.'() {'."\n";
2355 print ' jQuery(".eventday_'.$ymd.'.showifmore").toggle();'."\n";
2356 print ' open = open + 1; if (open > 1) { open = 0; }'."\n";
2357 print ' if (open) { ';
2358 print ' jQuery("#more_'.$ymd.'").html(\''.img_picto("All", "angle-double-up", 'class="warning"').'\');'."\n";
2359 print ' } else { ';
2360 print ' jQuery("#more_'.$ymd.'").html(\''.img_picto("All", "angle-double-down", 'class="warning"').' +'.($itoshow - $ireallyshown).'\');'."\n";
2361 print ' }'."\n";
2362 print ' }'."\n";
2363 print '});'."\n";
2364 print '</script>'."\n";
2365 }
2366
2367 print '</div></div>'; // td tr
2368
2369 print '</div>'; // table
2370 print "\n";
2371}
2372
2373
2382function dol_color_minus($color, $minus, $minusunit = 16)
2383{
2384 $newcolor = $color;
2385 if ($minusunit == 16 && is_array($newcolor)) {
2386 $newcolor[0] = dechex(max(min(hexdec($newcolor[0]) - $minus, 15), 0));
2387 $newcolor[2] = dechex(max(min(hexdec($newcolor[2]) - $minus, 15), 0));
2388 $newcolor[4] = dechex(max(min(hexdec($newcolor[4]) - $minus, 15), 0));
2389 } else {
2390 // Not yet implemented
2391 }
2392 return $newcolor;
2393}
2394
2402function sort_events_by_date($a, $b)
2403{
2404 // Sort holidays at first
2405 if ($a->type_code === 'HOLIDAY') {
2406 return -1;
2407 }
2408 if ($b->type_code === 'HOLIDAY') {
2409 return 1;
2410 }
2411
2412 // datep => Event start time
2413 // datef => Event end time
2414
2415 // Events have different start time
2416 if ($a->datep !== $b->datep) {
2417 return $a->datep - $b->datep;
2418 }
2419
2420 // Events have same start time and no end time
2421 if ((!is_numeric($b->datef)) || (!is_numeric($a->datef))) {
2422 return sort_events_by_percentage($a, $b);
2423 }
2424
2425 // Events have the same start time and same end time
2426 if ($b->datef === $a->datef) {
2427 return sort_events_by_percentage($a, $b);
2428 }
2429
2430 // Events have the same start time, but have different end time -> longest event first
2431 return $b->datef - $a->datef;
2432}
2433
2441function sort_events_by_percentage($a, $b)
2442{
2443 // Sort events with no percentage before each other
2444 // (useful to sort holidays, sick days or similar on the top)
2445
2446 if ($a->percentage < 0) {
2447 return -1;
2448 }
2449
2450 if ($b->percentage < 0) {
2451 return 1;
2452 }
2453
2454 return $b->percentage - $a->percentage;
2455}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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)
Show filter form in agenda view.
calendars_prepare_head($param)
Define head array for tabs of agenda setup pages.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:87
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:71
print $object position
Definition edit.php:204
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.
show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventarray, $maxprint=0, $maxnbofchar=16, $newparam='', $showinfo=0, $minheight=60, $nonew=0, $bookcalcalendarsarray=array())
Show event of a particular day.
Definition index.php:1843
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:171
dol_get_prev_month($month, $year)
Return previous month.
Definition date.lib.php:519
dol_get_next_day($day, $month, $year)
Return next day.
Definition date.lib.php:504
dol_get_next_week($day, $week, $month, $year)
Return next week.
Definition date.lib.php:578
dol_get_first_day_week($day, $month, $year, $gm=false)
Return first day of week for a date.
Definition date.lib.php:675
dol_get_prev_day($day, $month, $year)
Return previous day.
Definition date.lib.php:488
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition date.lib.php:600
dol_get_next_month($month, $year)
Return next month.
Definition date.lib.php:538
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:125
dol_stringtotime($string, $gm=1)
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:431
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:619
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...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
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.
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
getDolUserString($key, $default='', $tmpuser=null)
Return Dolibarr user constant string value.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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).
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_sanitizePathName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a path name.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
conf($dolibarr_main_document_root)
Load conf file (file must exists)
Definition inc.php:420
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
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.