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