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