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