dolibarr  16.0.5
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' => dol_string_nohtmltag(getDolGlobalString($name)),
281  'offsettz' => (int) getDolGlobalInt($offsettz, 0),
282  'color' => dol_string_nohtmltag(getDolGlobalString($color)),
283  'default' => dol_string_nohtmltag(getDolGlobalString($default)),
284  'buggedfile' => dol_string_nohtmltag(getDolGlobalString('buggedfile', ''))
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' => dol_string_nohtmltag($user->conf->$name),
306  'offsettz' => (int) (empty($user->conf->$offsettz) ? 0 : $user->conf->$offsettz),
307  'color' => dol_string_nohtmltag($user->conf->$color),
308  'default' => dol_string_nohtmltag($user->conf->$default),
309  'buggedfile' => dol_string_nohtmltag(isset($user->conf->buggedfile) ? $user->conf->buggedfile : '')
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  if ($user->rights->holiday->read) {
585  // Holiday calendar
586  $s .= '
587  <div class="nowrap inline-block minheight30"><input type="checkbox" id="check_holiday" name="check_holiday" value="1" class="check_holiday"' . ($check_holiday
588  ? ' checked' : '') . '>
589  <label for="check_holiday">
590  <span class="check_holiday_text">' . $langs->trans("Holidays") . '</span>
591  </label> &nbsp;
592  </div>';
593  }
594 
595  // External calendars
596  if (is_array($showextcals) && count($showextcals) > 0) {
597  $s .= '<script type="text/javascript">'."\n";
598  $s .= 'jQuery(document).ready(function () {
599  jQuery("div input[name^=\"check_ext\"]").each(function(index, elem) {
600  var name = jQuery(elem).attr("name");
601  if (jQuery(elem).is(":checked")) {
602  jQuery(".family_ext" + name.replace("check_ext", "")).show();
603  } else {
604  jQuery(".family_ext" + name.replace("check_ext", "")).hide();
605  }
606  });
607 
608  jQuery("div input[name^=\"check_ext\"]").click(function() {
609  var name = $(this).attr("name");
610  jQuery(".family_ext" + name.replace("check_ext", "")).toggle();
611  });
612  });' . "\n";
613  $s .= '</script>'."\n";
614 
615  foreach ($showextcals as $val) {
616  $htmlname = md5($val['name']);
617 
618  if (!empty($val['default']) || GETPOST('check_ext'.$htmlname, 'int')) {
619  $default = "checked";
620  } else {
621  $default = '';
622  }
623 
624  $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.'">'.dol_escape_htmltag($val['name']).'</label> &nbsp; </div>';
625  }
626  }
627 
628  // Birthdays
629  $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>';
630 
631  // Calendars from hooks
632  $parameters = array();
633  $reshook = $hookmanager->executeHooks('addCalendarChoice', $parameters, $object, $action);
634  if (empty($reshook)) {
635  $s .= $hookmanager->resPrint;
636  } elseif ($reshook > 1) {
637  $s = $hookmanager->resPrint;
638  }
639 
640  $s .= "\n".'<!-- End div to calendars selectors -->'."\n";
641 } else { // If javascript off
642  $newparam = $param; // newparam is for birthday links
643  $newparam = preg_replace('/showbirthday=[0-1]/i', 'showbirthday='.(empty($showbirthday) ? 1 : 0), $newparam);
644  if (!preg_match('/showbirthday=/i', $newparam)) {
645  $newparam .= '&showbirthday=1';
646  }
647  $link = '<a href="'.$_SERVER['PHP_SELF'].'?'.dol_escape_htmltag($newparam);
648  $link .= '">';
649  if (empty($showbirthday)) {
650  $link .= $langs->trans("AgendaShowBirthdayEvents");
651  } else {
652  $link .= $langs->trans("AgendaHideBirthdayEvents");
653  }
654  $link .= '</a>';
655 }
656 
657 
658 // Load events from database into $eventarray
659 $eventarray = array();
660 
661 
662 // DEFAULT CALENDAR + AUTOEVENT CALENDAR + CONFERENCEBOOTH CALENDAR
663 $sql = 'SELECT ';
664 if ($usergroup > 0) {
665  $sql .= " DISTINCT";
666 }
667 $sql .= ' a.id, a.label,';
668 $sql .= ' a.datep,';
669 $sql .= ' a.datep2,';
670 $sql .= ' a.percent,';
671 $sql .= ' a.fk_user_author,a.fk_user_action,';
672 $sql .= ' a.transparency, a.priority, a.fulldayevent, a.location,';
673 $sql .= ' a.fk_soc, a.fk_contact, a.fk_project,';
674 $sql .= ' a.fk_element, a.elementtype,';
675 $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';
676 $sql .= ' FROM '.MAIN_DB_PREFIX.'c_actioncomm as ca, '.MAIN_DB_PREFIX."actioncomm as a";
677 if (empty($user->rights->societe->client->voir) && !$socid) {
678  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
679 }
680 // We must filter on resource table
681 if ($resourceid > 0) {
682  $sql .= ", ".MAIN_DB_PREFIX."element_resources as r";
683 }
684 // We must filter on assignement table
685 if ($filtert > 0 || $usergroup > 0) {
686  $sql .= ", ".MAIN_DB_PREFIX."actioncomm_resources as ar";
687 }
688 if ($usergroup > 0) {
689  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_user = ar.fk_element";
690 }
691 $sql .= ' WHERE a.fk_action = ca.id';
692 $sql .= ' AND a.entity IN ('.getEntity('agenda').')';
693 // Condition on actioncode
694 if (!empty($actioncode)) {
695  if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
696  if ($actioncode == 'AC_NON_AUTO') {
697  $sql .= " AND ca.type != 'systemauto'";
698  } elseif ($actioncode == 'AC_ALL_AUTO') {
699  $sql .= " AND ca.type = 'systemauto'";
700  } else {
701  if ($actioncode == 'AC_OTH') {
702  $sql .= " AND ca.type != 'systemauto'";
703  }
704  if ($actioncode == 'AC_OTH_AUTO') {
705  $sql .= " AND ca.type = 'systemauto'";
706  }
707  }
708  } else {
709  if ($actioncode == 'AC_NON_AUTO') {
710  $sql .= " AND ca.type != 'systemauto'";
711  } elseif ($actioncode == 'AC_ALL_AUTO') {
712  $sql .= " AND ca.type = 'systemauto'";
713  } else {
714  if (is_array($actioncode)) {
715  $sql .= " AND ca.code IN (".$db->sanitize("'".implode("','", $actioncode)."'", 1).")";
716  } else {
717  $sql .= " AND ca.code IN (".$db->sanitize("'".implode("','", explode(',', $actioncode))."'", 1).")";
718  }
719  }
720  }
721 }
722 if ($resourceid > 0) {
723  $sql .= " AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = ".((int) $resourceid);
724 }
725 if ($pid) {
726  $sql .= " AND a.fk_project=".((int) $pid);
727 }
728 if (empty($user->rights->societe->client->voir) && !$socid) {
729  $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = ".((int) $user->id).")";
730 }
731 if ($socid > 0) {
732  $sql .= " AND a.fk_soc = ".((int) $socid);
733 }
734 // We must filter on assignement table
735 if ($filtert > 0 || $usergroup > 0) {
736  $sql .= " AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
737 }
738 //var_dump($day.' '.$month.' '.$year);
739 if ($mode == 'show_day') {
740  $sql .= " AND (";
741  $sql .= " (a.datep BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel'))."'";
742  $sql .= " AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel'))."')";
743  $sql .= " OR ";
744  $sql .= " (a.datep2 BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel'))."'";
745  $sql .= " AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel'))."')";
746  $sql .= " OR ";
747  $sql .= " (a.datep < '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel'))."'";
748  $sql .= " AND a.datep2 > '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel'))."')";
749  $sql .= ')';
750 } else {
751  // To limit array
752  $sql .= " AND (";
753  $sql .= " (a.datep BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, 1, $year) - (60 * 60 * 24 * 7))."'"; // Start 7 days before
754  $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
755  $sql .= " OR ";
756  $sql .= " (a.datep2 BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, 1, $year) - (60 * 60 * 24 * 7))."'";
757  $sql .= " AND '".$db->idate(dol_mktime(23, 59, 59, $month, 28, $year) + (60 * 60 * 24 * 10))."')";
758  $sql .= " OR ";
759  $sql .= " (a.datep < '".$db->idate(dol_mktime(0, 0, 0, $month, 1, $year) - (60 * 60 * 24 * 7))."'";
760  $sql .= " AND a.datep2 > '".$db->idate(dol_mktime(23, 59, 59, $month, 28, $year) + (60 * 60 * 24 * 10))."')";
761  $sql .= ')';
762 }
763 if ($type) {
764  $sql .= " AND ca.id = ".((int) $type);
765 }
766 if ($status == '0') {
767  $sql .= " AND a.percent = 0";
768 }
769 if ($status == '-1' || $status == 'na') {
770  // Not applicable
771  $sql .= " AND a.percent = -1";
772 }
773 if ($status == '50') {
774  // Running already started
775  $sql .= " AND (a.percent > 0 AND a.percent < 100)";
776 }
777 if ($status == 'done' || $status == '100') {
778  $sql .= " AND (a.percent = 100)";
779 }
780 if ($status == 'todo') {
781  $sql .= " AND (a.percent >= 0 AND a.percent < 100)";
782 }
783 // We must filter on assignement table
784 if ($filtert > 0 || $usergroup > 0) {
785  $sql .= " AND (";
786  if ($filtert > 0) {
787  $sql .= "ar.fk_element = ".((int) $filtert);
788  }
789  if ($usergroup > 0) {
790  $sql .= ($filtert > 0 ? " OR " : "")." ugu.fk_usergroup = ".((int) $usergroup);
791  }
792  $sql .= ")";
793 }
794 // Sort on date
795 $sql .= ' ORDER BY datep';
796 //print $sql;
797 
798 
799 dol_syslog("comm/action/index.php", LOG_DEBUG);
800 $resql = $db->query($sql);
801 if ($resql) {
802  $num = $db->num_rows($resql);
803 
804  $MAXONSAMEPAGE = 10000; // Useless to have more. Protection to avoid memory overload when high number of event (for example after a mass import)
805  $i = 0;
806  while ($i < $num && $i < $MAXONSAMEPAGE) {
807  $obj = $db->fetch_object($resql);
808 
809  // Discard auto action if option is on
810  if (!empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO) && $obj->type_code == 'AC_OTH_AUTO') {
811  $i++;
812  continue;
813  }
814 
815  // Create a new object action
816  $event = new ActionComm($db);
817 
818  $event->id = $obj->id;
819  $event->ref = $event->id;
820 
821  $event->fulldayevent = $obj->fulldayevent;
822 
823  // event->datep and event->datef must be GMT date.
824  if ($event->fulldayevent) {
825  $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
826  $event->datep = $db->jdate($obj->datep, $tzforfullday ? 'tzuser' : 'tzserver'); // If saved in $tzforfullday = gmt, we must invert date to be in user tz
827  $event->datef = $db->jdate($obj->datep2, $tzforfullday ? 'tzuser' : 'tzserver');
828  } else {
829  // Example: $obj->datep = '1970-01-01 01:00:00', jdate will return 0 if TZ of PHP server is Europe/Berlin (+1)
830  $event->datep = $db->jdate($obj->datep, 'tzserver');
831  $event->datef = $db->jdate($obj->datep2, 'tzserver');
832  }
833  //$event->datep_formated_gmt = dol_print_date($event->datep, 'dayhour', 'gmt');
834  //var_dump($obj->id.' '.$obj->datep.' '.dol_print_date($obj->datep, 'dayhour', 'gmt'));
835  //var_dump($obj->id.' '.$event->datep.' '.dol_print_date($event->datep, 'dayhour', 'gmt'));
836 
837  $event->type_code = $obj->type_code;
838  $event->type_label = $obj->type_label;
839  $event->type_color = $obj->type_color;
840  $event->type = $obj->type_type;
841  $event->type_picto = $obj->type_picto;
842 
843  $event->libelle = $obj->label; // deprecated
844  $event->label = $obj->label;
845  $event->percentage = $obj->percent;
846 
847  $event->authorid = $obj->fk_user_author; // user id of creator
848  $event->userownerid = $obj->fk_user_action; // user id of owner
849  $event->fetch_userassigned(); // This load $event->userassigned
850 
851  $event->priority = $obj->priority;
852  $event->location = $obj->location;
853  $event->transparency = $obj->transparency;
854  $event->fk_element = $obj->fk_element;
855  $event->elementtype = $obj->elementtype;
856 
857  $event->fk_project = $obj->fk_project;
858 
859  $event->socid = $obj->fk_soc;
860  $event->contact_id = $obj->fk_contact;
861 
862  // Defined date_start_in_calendar and date_end_in_calendar property
863  // They are date start and end of action but modified to not be outside calendar view.
864  $event->date_start_in_calendar = $event->datep;
865  if ($event->datef != '' && $event->datef >= $event->datep) {
866  $event->date_end_in_calendar = $event->datef;
867  } else {
868  $event->date_end_in_calendar = $event->datep;
869  }
870 
871  // Check values
872  if ($event->date_end_in_calendar < $firstdaytoshow || $event->date_start_in_calendar >= $lastdaytoshow) {
873  // This record is out of visible range
874  } else {
875  if ($event->date_start_in_calendar < $firstdaytoshow) {
876  $event->date_start_in_calendar = $firstdaytoshow;
877  }
878  if ($event->date_end_in_calendar >= $lastdaytoshow) {
879  $event->date_end_in_calendar = ($lastdaytoshow - 1);
880  }
881 
882  // Add an entry in actionarray for each day
883  $daycursor = $event->date_start_in_calendar;
884  $annee = dol_print_date($daycursor, '%Y', 'tzuserrel');
885  $mois = dol_print_date($daycursor, '%m', 'tzuserrel');
886  $jour = dol_print_date($daycursor, '%d', 'tzuserrel');
887 
888  $daycursorend = $event->date_end_in_calendar;
889  $anneeend = dol_print_date($daycursorend, '%Y', 'tzuserrel');
890  $moisend = dol_print_date($daycursorend, '%m', 'tzuserrel');
891  $jourend = dol_print_date($daycursorend, '%d', 'tzuserrel');
892 
893  //var_dump(dol_print_date($event->date_start_in_calendar, 'dayhour', 'gmt')); // Hour at greenwich
894  //var_dump($annee.'-'.$mois.'-'.$jour);
895  //print 'annee='.$annee.' mois='.$mois.' jour='.$jour.'<br>';
896 
897  // Loop on each day covered by action to prepare an index to show on calendar
898  $loop = true; $j = 0;
899  $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt'); // $mois, $jour, $annee has been set for user tz
900  $daykeyend = dol_mktime(0, 0, 0, $moisend, $jourend, $anneeend, 'gmt'); // $moisend, $jourend, $anneeend has been set for user tz
901  /*
902  print 'GMT '.$event->date_start_in_calendar.' '.dol_print_date($event->date_start_in_calendar, 'dayhour', 'gmt').'<br>';
903  print 'TZSERVER '.$event->date_start_in_calendar.' '.dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzserver').'<br>';
904  print 'TZUSERREL '.$event->date_start_in_calendar.' '.dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzuserrel').'<br>';
905  print 'GMT '.$event->date_end_in_calendar.' '.dol_print_date($event->date_end_in_calendar, 'dayhour', 'gmt').'<br>';
906  print 'TZSERVER '.$event->date_end_in_calendar.' '.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzserver').'<br>';
907  print 'TZUSER '.$event->date_end_in_calendar.' '.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzuserrel').'<br>';
908  */
909  do {
910  //if ($event->id==408)
911  //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>';
912  //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>';
913 
914  $eventarray[$daykey][] = $event;
915  $j++;
916 
917  $daykey += 60 * 60 * 24;
918  //if ($daykey > $event->date_end_in_calendar) {
919  if ($daykey > $daykeyend) {
920  $loop = false;
921  }
922  } while ($loop);
923  //var_dump($eventarray);
924  //print 'Event '.$i.' id='.$event->id.' (start='.dol_print_date($event->datep).'-end='.dol_print_date($event->datef);
925  //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>';
926  }
927  $i++;
928  }
929 } else {
930  dol_print_error($db);
931 }
932 //var_dump($eventarray);
933 
934 // BIRTHDATES CALENDAR
935 // Complete $eventarray with birthdates
936 if ($showbirthday) {
937  // Add events in array
938  $sql = 'SELECT sp.rowid, sp.lastname, sp.firstname, sp.birthday';
939  $sql .= ' FROM '.MAIN_DB_PREFIX.'socpeople as sp';
940  $sql .= ' WHERE (priv=0 OR (priv=1 AND fk_user_creat='.((int) $user->id).'))';
941  $sql .= " AND sp.entity IN (".getEntity('contact').")";
942  if ($mode == 'show_day') {
943  $sql .= ' AND MONTH(birthday) = '.((int) $month);
944  $sql .= ' AND DAY(birthday) = '.((int) $day);
945  } else {
946  $sql .= ' AND MONTH(birthday) = '.((int) $month);
947  }
948  $sql .= ' ORDER BY birthday';
949 
950  dol_syslog("comm/action/index.php", LOG_DEBUG);
951  $resql = $db->query($sql);
952  if ($resql) {
953  $num = $db->num_rows($resql);
954  $i = 0;
955  while ($i < $num) {
956  $obj = $db->fetch_object($resql);
957 
958  $event = new ActionComm($db);
959 
960  $event->id = $obj->rowid; // We put contact id in action id for birthdays events
961  $event->ref = $event->id;
962 
963  $datebirth = dol_stringtotime($obj->birthday, 1);
964  //print 'ee'.$obj->birthday.'-'.$datebirth;
965  $datearray = dol_getdate($datebirth, true);
966  $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
967  $event->datef = $event->datep;
968 
969  $event->type_code = 'BIRTHDAY';
970  $event->type_label = '';
971  $event->type_color = '';
972  $event->type = 'birthdate';
973  $event->type_picto = 'birthdate';
974 
975  $event->label = $langs->trans("Birthday").' '.dolGetFirstLastname($obj->firstname, $obj->lastname);
976  $event->percentage = 100;
977  $event->fulldayevent = 1;
978 
979  $event->date_start_in_calendar = $db->jdate($event->datep);
980  $event->date_end_in_calendar = $db->jdate($event->datef);
981 
982  // Add an entry in eventarray for each day
983  $daycursor = $event->datep;
984  $annee = dol_print_date($daycursor, '%Y', 'tzuserrel');
985  $mois = dol_print_date($daycursor, '%m', 'tzuserrel');
986  $jour = dol_print_date($daycursor, '%d', 'tzuserrel');
987 
988  $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
989 
990  $eventarray[$daykey][] = $event;
991 
992  /*$loop = true;
993  $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee);
994  do {
995  $eventarray[$daykey][] = $event;
996  $daykey += 60 * 60 * 24;
997  if ($daykey > $event->date_end_in_calendar) $loop = false;
998  } while ($loop);
999  */
1000  $i++;
1001  }
1002  } else {
1003  dol_print_error($db);
1004  }
1005 }
1006 
1007 if ($user->rights->holiday->read) {
1008  // LEAVE CALENDAR
1009  $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";
1010  $sql .= " FROM ".MAIN_DB_PREFIX."holiday as x, ".MAIN_DB_PREFIX."user as u";
1011  $sql .= " WHERE u.rowid = x.fk_user";
1012  $sql .= " AND u.statut = '1'"; // Show only active users (0 = inactive user, 1 = active user)
1013  $sql .= " AND (x.statut = '2' OR x.statut = '3')"; // Show only public leaves (2 = leave wait for approval, 3 = leave approved)
1014 
1015  if ($mode == 'show_day') {
1016  // Request only leaves for the current selected day
1017  $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
1018  } elseif ($mode == 'show_week') {
1019  // TODO: Add filter to reduce database request
1020  } elseif ($mode == 'show_month') {
1021  // TODO: Add filter to reduce database request
1022  }
1023 
1024  $resql = $db->query($sql);
1025  if ($resql) {
1026  $num = $db->num_rows($resql);
1027  $i = 0;
1028 
1029  while ($i < $num) {
1030  $obj = $db->fetch_object($resql);
1031 
1032  $event = new ActionComm($db);
1033 
1034  // Need the id of the leave object for link to it
1035  $event->id = $obj->rowid;
1036  $event->ref = $event->id;
1037 
1038  $event->type_code = 'HOLIDAY';
1039  $event->type_label = '';
1040  $event->type_color = '';
1041  $event->type = 'holiday';
1042  $event->type_picto = 'holiday';
1043 
1044  $event->datep = $db->jdate($obj->date_start) + (empty($halfday) || $halfday == 1 ? 0 : 12 * 60 * 60 - 1);
1045  $event->datef = $db->jdate($obj->date_end) + (empty($halfday) || $halfday == -1 ? 24 : 12) * 60 * 60 - 1;
1046  $event->date_start_in_calendar = $event->datep;
1047  $event->date_end_in_calendar = $event->datef;
1048 
1049  if ($obj->status == 3) {
1050  // Show no symbol for leave with state "leave approved"
1051  $event->percentage = -1;
1052  } elseif ($obj->status == 2) {
1053  // Show TO-DO symbol for leave with state "leave wait for approval"
1054  $event->percentage = 0;
1055  }
1056 
1057  if ($obj->halfday == 1) {
1058  $event->label = $obj->lastname.' ('.$langs->trans("Morning").')';
1059  } elseif ($obj->halfday == -1) {
1060  $event->label = $obj->lastname.' ('.$langs->trans("Afternoon").')';
1061  } else {
1062  $event->label = $obj->lastname;
1063  }
1064 
1065  $daycursor = $event->date_start_in_calendar;
1066  $annee = dol_print_date($daycursor, '%Y', 'tzuserrel');
1067  $mois = dol_print_date($daycursor, '%m', 'tzuserrel');
1068  $jour = dol_print_date($daycursor, '%d', 'tzuserrel');
1069 
1070  $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
1071  do {
1072  $eventarray[$daykey][] = $event;
1073 
1074  $daykey += 60 * 60 * 24;
1075  } while ($daykey <= $event->date_end_in_calendar);
1076 
1077  $i++;
1078  }
1079  }
1080 }
1081 
1082 // EXTERNAL CALENDAR
1083 // Complete $eventarray with external import Ical
1084 if (count($listofextcals)) {
1085  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/ical.class.php';
1086  foreach ($listofextcals as $extcal) {
1087  $url = $extcal['src']; // Example: https://www.google.com/calendar/ical/eldy10%40gmail.com/private-cde92aa7d7e0ef6110010a821a2aaeb/basic.ics
1088  $namecal = $extcal['name'];
1089  $offsettz = $extcal['offsettz'];
1090  $colorcal = $extcal['color'];
1091  $buggedfile = $extcal['buggedfile'];
1092 
1093  $ical = new ICal();
1094  $ical->parse($url);
1095 
1096  // After this $ical->cal['VEVENT'] contains array of events, $ical->cal['DAYLIGHT'] contains daylight info, $ical->cal['STANDARD'] contains non daylight info, ...
1097  //var_dump($ical->cal); exit;
1098  $icalevents = array();
1099  if (is_array($ical->get_event_list())) {
1100  $icalevents = array_merge($icalevents, $ical->get_event_list()); // Add $ical->cal['VEVENT']
1101  }
1102  if (is_array($ical->get_freebusy_list())) {
1103  $icalevents = array_merge($icalevents, $ical->get_freebusy_list()); // Add $ical->cal['VFREEBUSY']
1104  }
1105 
1106  if (count($icalevents) > 0) {
1107  // Duplicate all repeatable events into new entries
1108  $moreicalevents = array();
1109  foreach ($icalevents as $icalevent) {
1110  if (isset($icalevent['RRULE']) && is_array($icalevent['RRULE'])) { //repeatable event
1111  //if ($event->date_start_in_calendar < $firstdaytoshow) $event->date_start_in_calendar=$firstdaytoshow;
1112  //if ($event->date_end_in_calendar > $lastdaytoshow) $event->date_end_in_calendar=($lastdaytoshow-1);
1113  if ($icalevent['DTSTART;VALUE=DATE']) { //fullday event
1114  $datecurstart = dol_stringtotime($icalevent['DTSTART;VALUE=DATE'], 1);
1115  $datecurend = dol_stringtotime($icalevent['DTEND;VALUE=DATE'], 1) - 1; // We remove one second to get last second of day
1116  } elseif (is_array($icalevent['DTSTART']) && !empty($icalevent['DTSTART']['unixtime'])) {
1117  $datecurstart = $icalevent['DTSTART']['unixtime'];
1118  $datecurend = $icalevent['DTEND']['unixtime'];
1119  if (!empty($ical->cal['DAYLIGHT']['DTSTART']) && $datecurstart) {
1120  //var_dump($ical->cal);
1121  $tmpcurstart = $datecurstart;
1122  $tmpcurend = $datecurend;
1123  $tmpdaylightstart = dol_mktime(0, 0, 0, 1, 1, 1970, 1) + (int) $ical->cal['DAYLIGHT']['DTSTART'];
1124  $tmpdaylightend = dol_mktime(0, 0, 0, 1, 1, 1970, 1) + (int) $ical->cal['STANDARD']['DTSTART'];
1125  //var_dump($tmpcurstart);var_dump($tmpcurend); var_dump($ical->cal['DAYLIGHT']['DTSTART']);var_dump($ical->cal['STANDARD']['DTSTART']);
1126  // Edit datecurstart and datecurend
1127  if ($tmpcurstart >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend) {
1128  $datecurstart -= ((int) $ical->cal['DAYLIGHT']['TZOFFSETTO']) * 36;
1129  } else {
1130  $datecurstart -= ((int) $ical->cal['STANDARD']['TZOFFSETTO']) * 36;
1131  }
1132  if ($tmpcurend >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend) {
1133  $datecurend -= ((int) $ical->cal['DAYLIGHT']['TZOFFSETTO']) * 36;
1134  } else {
1135  $datecurend -= ((int) $ical->cal['STANDARD']['TZOFFSETTO']) * 36;
1136  }
1137  }
1138  // datecurstart and datecurend are now GMT date
1139  //var_dump($datecurstart); var_dump($datecurend); exit;
1140  } else {
1141  // Not a recongized record
1142  dol_syslog("Found a not recognized repeatable record with unknown date start", LOG_ERR);
1143  continue;
1144  }
1145  //print 'xx'.$datecurstart;exit;
1146 
1147  $interval = (empty($icalevent['RRULE']['INTERVAL']) ? 1 : $icalevent['RRULE']['INTERVAL']);
1148  $until = empty($icalevent['RRULE']['UNTIL']) ? 0 : dol_stringtotime($icalevent['RRULE']['UNTIL'], 1);
1149  $maxrepeat = empty($icalevent['RRULE']['COUNT']) ? 0 : $icalevent['RRULE']['COUNT'];
1150  if ($until && ($until + ($datecurend - $datecurstart)) < $firstdaytoshow) {
1151  continue; // We discard repeatable event that end before start date to show
1152  }
1153  if ($datecurstart >= $lastdaytoshow) {
1154  continue; // We discard repeatable event that start after end date to show
1155  }
1156 
1157  $numofevent = 0;
1158  while (($datecurstart < $lastdaytoshow) && (empty($maxrepeat) || ($numofevent < $maxrepeat))) {
1159  if ($datecurend >= $firstdaytoshow) { // We add event
1160  $newevent = $icalevent;
1161  unset($newevent['RRULE']);
1162  if ($icalevent['DTSTART;VALUE=DATE']) {
1163  $newevent['DTSTART;VALUE=DATE'] = dol_print_date($datecurstart, '%Y%m%d');
1164  $newevent['DTEND;VALUE=DATE'] = dol_print_date($datecurend + 1, '%Y%m%d');
1165  } else {
1166  $newevent['DTSTART'] = $datecurstart;
1167  $newevent['DTEND'] = $datecurend;
1168  }
1169  $moreicalevents[] = $newevent;
1170  }
1171  // Jump on next occurence
1172  $numofevent++;
1173  $savdatecurstart = $datecurstart;
1174  if ($icalevent['RRULE']['FREQ'] == 'DAILY') {
1175  $datecurstart = dol_time_plus_duree($datecurstart, $interval, 'd');
1176  $datecurend = dol_time_plus_duree($datecurend, $interval, 'd');
1177  }
1178  if ($icalevent['RRULE']['FREQ'] == 'WEEKLY') {
1179  $datecurstart = dol_time_plus_duree($datecurstart, $interval, 'w');
1180  $datecurend = dol_time_plus_duree($datecurend, $interval, 'w');
1181  } elseif ($icalevent['RRULE']['FREQ'] == 'MONTHLY') {
1182  $datecurstart = dol_time_plus_duree($datecurstart, $interval, 'm');
1183  $datecurend = dol_time_plus_duree($datecurend, $interval, 'm');
1184  } elseif ($icalevent['RRULE']['FREQ'] == 'YEARLY') {
1185  $datecurstart = dol_time_plus_duree($datecurstart, $interval, 'y');
1186  $datecurend = dol_time_plus_duree($datecurend, $interval, 'y');
1187  }
1188  // Test to avoid infinite loop ($datecurstart must increase)
1189  if ($savdatecurstart >= $datecurstart) {
1190  dol_syslog("Found a rule freq ".$icalevent['RRULE']['FREQ']." not managed by dolibarr code. Assume 1 week frequency.", LOG_ERR);
1191  $datecurstart += 3600 * 24 * 7;
1192  $datecurend += 3600 * 24 * 7;
1193  }
1194  }
1195  }
1196  }
1197  $icalevents = array_merge($icalevents, $moreicalevents);
1198 
1199  // Loop on each entry into cal file to know if entry is qualified and add an ActionComm into $eventarray
1200  foreach ($icalevents as $icalevent) {
1201  //var_dump($icalevent);
1202 
1203  //print $icalevent['SUMMARY'].'->';
1204  //var_dump($icalevent);exit;
1205  if (!empty($icalevent['RRULE'])) {
1206  continue; // We found a repeatable event. It was already split into unitary events, so we discard general rule.
1207  }
1208 
1209  // Create a new object action
1210  $event = new ActionComm($db);
1211  $addevent = false;
1212  if (isset($icalevent['DTSTART;VALUE=DATE'])) { // fullday event
1213  // For full day events, date are also GMT but they wont but converted using tz during output
1214  $datestart = dol_stringtotime($icalevent['DTSTART;VALUE=DATE'], 1);
1215  if (empty($icalevent['DTEND;VALUE=DATE'])) {
1216  $dateend = $datestart + 86400 - 1;
1217  } else {
1218  $dateend = dol_stringtotime($icalevent['DTEND;VALUE=DATE'], 1) - 1; // We remove one second to get last second of day
1219  }
1220  //print 'x'.$datestart.'-'.$dateend;exit;
1221  //print dol_print_date($dateend,'dayhour','gmt');
1222  $event->fulldayevent = 1;
1223  $addevent = true;
1224  } elseif (!is_array($icalevent['DTSTART'])) { // not fullday event (DTSTART is not array. It is a value like '19700101T000000Z' for 00:00 in greenwitch)
1225  $datestart = $icalevent['DTSTART'];
1226  $dateend = empty($icalevent['DTEND']) ? $datestart : $icalevent['DTEND'];
1227 
1228  $datestart += +($offsettz * 3600);
1229  $dateend += +($offsettz * 3600);
1230 
1231  $addevent = true;
1232  //var_dump($offsettz);
1233  //var_dump(dol_print_date($datestart, 'dayhour', 'gmt'));
1234  } elseif (isset($icalevent['DTSTART']['unixtime'])) { // File contains a local timezone + a TZ (for example when using bluemind)
1235  $datestart = $icalevent['DTSTART']['unixtime'];
1236  $dateend = $icalevent['DTEND']['unixtime'];
1237 
1238  $datestart += +($offsettz * 3600);
1239  $dateend += +($offsettz * 3600);
1240 
1241  // $buggedfile is set to uselocalandtznodaylight if conf->global->AGENDA_EXT_BUGGEDFILEx = 'uselocalandtznodaylight'
1242  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
1243  // TODO
1244  }
1245  // $buggedfile is set to uselocalandtzdaylight if conf->global->AGENDA_EXT_BUGGEDFILEx = 'uselocalandtzdaylight' (for example with bluemind)
1246  if ($buggedfile === 'uselocalandtzdaylight') { // unixtime is a local date that does take daylight into account, TZID is +2 for example for 'Europe/Paris' in summer
1247  $localtzs = new DateTimeZone(preg_replace('/"/', '', $icalevent['DTSTART']['TZID']));
1248  $localtze = new DateTimeZone(preg_replace('/"/', '', $icalevent['DTEND']['TZID']));
1249  $localdts = new DateTime(dol_print_date($datestart, 'dayrfc', 'gmt'), $localtzs);
1250  $localdte = new DateTime(dol_print_date($dateend, 'dayrfc', 'gmt'), $localtze);
1251  $tmps = -1 * $localtzs->getOffset($localdts);
1252  $tmpe = -1 * $localtze->getOffset($localdte);
1253  $datestart += $tmps;
1254  $dateend += $tmpe;
1255  //var_dump($datestart);
1256  }
1257  $addevent = true;
1258  }
1259 
1260  if ($addevent) {
1261  $event->id = $icalevent['UID'];
1262  $event->ref = $event->id;
1263  $userId = $userstatic->findUserIdByEmail($namecal);
1264  if (!empty($userId) && $userId > 0) {
1265  $event->userassigned[$userId] = $userId;
1266  $event->percentage = -1;
1267  }
1268 
1269  $event->type_code = "ICALEVENT";
1270  $event->type_label = $namecal;
1271  $event->type_color = $colorcal;
1272  $event->type = 'icalevent';
1273  $event->type_picto = 'rss';
1274 
1275  $event->icalname = $namecal;
1276  $event->icalcolor = $colorcal;
1277  $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.
1278  $event->datep = $datestart + $usertime;
1279  $event->datef = $dateend + $usertime;
1280 
1281  if ($icalevent['SUMMARY']) {
1282  $event->label = $icalevent['SUMMARY'];
1283  } elseif ($icalevent['DESCRIPTION']) {
1284  $event->label = dol_nl2br($icalevent['DESCRIPTION'], 1);
1285  } else {
1286  $event->label = $langs->trans("ExtSiteNoLabel");
1287  }
1288 
1289  // Priority (see https://www.kanzaki.com/docs/ical/priority.html)
1290  // LOW = 0 to 4
1291  // MEDIUM = 5
1292  // HIGH = 6 to 9
1293  if (!empty($icalevent['PRIORITY'])) {
1294  $event->priority = $icalevent['PRIORITY'];
1295  }
1296 
1297  // Transparency (see https://www.kanzaki.com/docs/ical/transp.html)
1298  if ($icalevent['TRANSP']) {
1299  if ($icalevent['TRANSP'] == "TRANSPARENT") {
1300  $event->transparency = 0; // 0 = available / free
1301  }
1302  if ($icalevent['TRANSP'] == "OPAQUE") {
1303  $event->transparency = 1; // 1 = busy
1304  }
1305 
1306  // TODO: MS outlook states
1307  // X-MICROSOFT-CDO-BUSYSTATUS:FREE + TRANSP:TRANSPARENT => Available / Free
1308  // X-MICROSOFT-CDO-BUSYSTATUS:FREE + TRANSP:OPAQUE => Work another place
1309  // X-MICROSOFT-CDO-BUSYSTATUS:TENTATIVE + TRANSP:OPAQUE => With reservations
1310  // X-MICROSOFT-CDO-BUSYSTATUS:BUSY + TRANSP:OPAQUE => Busy
1311  // X-MICROSOFT-CDO-BUSYSTATUS:OOF + TRANSP:OPAQUE => Away from the office / off-site
1312  }
1313 
1314  if (!empty($icalevent['LOCATION'])) {
1315  $event->location = $icalevent['LOCATION'];
1316  }
1317 
1318  $event->date_start_in_calendar = $event->datep;
1319 
1320  if ($event->datef != '' && $event->datef >= $event->datep) {
1321  $event->date_end_in_calendar = $event->datef;
1322  } else {
1323  $event->date_end_in_calendar = $event->datep;
1324  }
1325 
1326  // Add event into $eventarray if date range are ok.
1327  if ($event->date_end_in_calendar < $firstdaytoshow || $event->date_start_in_calendar >= $lastdaytoshow) {
1328  //print 'x'.$datestart.'-'.$dateend;exit;
1329  //print 'x'.$datestart.'-'.$dateend;exit;
1330  //print 'x'.$datestart.'-'.$dateend;exit;
1331  // This record is out of visible range
1332  } else {
1333  if ($event->date_start_in_calendar < $firstdaytoshow) {
1334  $event->date_start_in_calendar = $firstdaytoshow;
1335  }
1336  if ($event->date_end_in_calendar >= $lastdaytoshow) {
1337  $event->date_end_in_calendar = ($lastdaytoshow - 1);
1338  }
1339 
1340  // Add an entry in actionarray for each day
1341  $daycursor = $event->date_start_in_calendar;
1342  $annee = dol_print_date($daycursor, '%Y', 'tzuserrel');
1343  $mois = dol_print_date($daycursor, '%m', 'tzuserrel');
1344  $jour = dol_print_date($daycursor, '%d', 'tzuserrel');
1345 
1346  // Loop on each day covered by action to prepare an index to show on calendar
1347  $loop = true; $j = 0;
1348  // daykey must be date that represent day box in calendar so must be a user time
1349  $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
1350  $daykeygmt = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
1351  do {
1352  //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').' ';
1353  $eventarray[$daykey][] = $event;
1354  $daykey += 60 * 60 * 24; $daykeygmt += 60 * 60 * 24; // Add one day
1355  if (($event->fulldayevent ? $daykeygmt : $daykey) > $event->date_end_in_calendar) {
1356  $loop = false;
1357  }
1358  } while ($loop);
1359  }
1360  }
1361  }
1362  }
1363  }
1364 }
1365 
1366 
1367 
1368 // Complete $eventarray with events coming from external module
1369 $parameters = array(); $object = null;
1370 $reshook = $hookmanager->executeHooks('getCalendarEvents', $parameters, $object, $action);
1371 if (!empty($hookmanager->resArray['eventarray'])) {
1372  foreach ($hookmanager->resArray['eventarray'] as $keyDate => $events) {
1373  if (!isset($eventarray[$keyDate])) {
1374  $eventarray[$keyDate] = array();
1375  }
1376  $eventarray[$keyDate] = array_merge($eventarray[$keyDate], $events);
1377  }
1378 }
1379 
1380 // Sort events
1381 foreach ($eventarray as $keyDate => &$dateeventarray) {
1382  usort($dateeventarray, 'sort_events_by_date');
1383 }
1384 
1385 
1386 $maxnbofchar = 0;
1387 $cachethirdparties = array();
1388 $cachecontacts = array();
1389 $cacheusers = array();
1390 
1391 // Define theme_datacolor array
1392 $color_file = DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/theme_vars.inc.php";
1393 if (is_readable($color_file)) {
1394  include $color_file;
1395 }
1396 if (!is_array($theme_datacolor)) {
1397  $theme_datacolor = array(array(120, 130, 150), array(200, 160, 180), array(190, 190, 220));
1398 }
1399 
1400 $massactionbutton ='';
1401 
1402 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);
1403 
1404 // Show div with list of calendars
1405 print $s;
1406 
1407 
1408 if (empty($mode) || $mode == 'show_month') { // View by month
1409  $newparam = $param; // newparam is for birthday links
1410  $newparam = preg_replace('/showbirthday=/i', 'showbirthday_=', $newparam); // To avoid replacement when replace day= is done
1411  $newparam = preg_replace('/mode=show_month&?/i', '', $newparam);
1412  $newparam = preg_replace('/mode=show_week&?/i', '', $newparam);
1413  $newparam = preg_replace('/day=[0-9]+&?/i', '', $newparam);
1414  $newparam = preg_replace('/month=[0-9]+&?/i', '', $newparam);
1415  $newparam = preg_replace('/year=[0-9]+&?/i', '', $newparam);
1416  $newparam = preg_replace('/viewcal=[0-9]+&?/i', '', $newparam);
1417  $newparam = preg_replace('/showbirthday_=/i', 'showbirthday=', $newparam); // Restore correct parameter
1418  $newparam .= '&viewcal=1';
1419 
1420  print '<div class="liste_titre liste_titre_bydiv centpercent">';
1421  print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid);
1422  print '</div>';
1423 
1424  print '<div class="div-table-responsive-no-min sectioncalendarbymonth maxscreenheightless300">';
1425  print '<table class="centpercent noborder nocellnopadd cal_pannel cal_month">';
1426  print ' <tr class="liste_titre">';
1427  // Column title of weeks numbers
1428  echo ' <td class="center">#</td>';
1429  $i = 0;
1430  while ($i < 7) {
1431  print ' <td class="center bold uppercase tdfordaytitle'.($i == 0 ? ' borderleft' : '').'">';
1432  $numdayinweek = (($i + (isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1)) % 7);
1433  if (!empty($conf->dol_optimize_smallscreen)) {
1434  $labelshort = array(0=>'SundayMin', 1=>'MondayMin', 2=>'TuesdayMin', 3=>'WednesdayMin', 4=>'ThursdayMin', 5=>'FridayMin', 6=>'SaturdayMin');
1435  print $langs->trans($labelshort[$numdayinweek]);
1436  } else {
1437  print $langs->trans("Day".$numdayinweek);
1438  }
1439  print ' </td>'."\n";
1440  $i++;
1441  }
1442  echo ' </tr>'."\n";
1443 
1444  $todayarray = dol_getdate($now, 'fast');
1445  $todaytms = dol_mktime(0, 0, 0, $todayarray['mon'], $todayarray['mday'], $todayarray['year']);
1446 
1447  // In loops, tmpday contains day nb in current month (can be zero or negative for days of previous month)
1448  //var_dump($eventarray);
1449  for ($iter_week = 0; $iter_week < 6; $iter_week++) {
1450  echo " <tr>\n";
1451  // Get date of the current day, format 'yyyy-mm-dd'
1452  if ($tmpday <= 0) { // If number of the current day is in previous month
1453  $currdate0 = sprintf("%04d", $prev_year).sprintf("%02d", $prev_month).sprintf("%02d", $max_day_in_prev_month + $tmpday);
1454  } elseif ($tmpday <= $max_day_in_month) { // If number of the current day is in current month
1455  $currdate0 = sprintf("%04d", $year).sprintf("%02d", $month).sprintf("%02d", $tmpday);
1456  } else // If number of the current day is in next month
1457  {
1458  $currdate0 = sprintf("%04d", $next_year).sprintf("%02d", $next_month).sprintf("%02d", $tmpday - $max_day_in_month);
1459  }
1460  // Get week number for the targeted date '$currdate0'
1461  $numweek0 = date("W", strtotime(date($currdate0)));
1462  // Show the week number, and define column width
1463  echo ' <td class="center weeknumber opacitymedium" width="2%">'.$numweek0.'</td>';
1464 
1465  for ($iter_day = 0; $iter_day < 7; $iter_day++) {
1466  if ($tmpday <= 0) {
1467  /* Show days before the beginning of the current month (previous month) */
1468  $style = 'cal_other_month cal_past';
1469  if ($iter_day == 6) {
1470  $style .= ' cal_other_month_right';
1471  }
1472  echo ' <td class="'.$style.' nowrap tdtop" width="14%">';
1473  show_day_events($db, $max_day_in_prev_month + $tmpday, $prev_month, $prev_year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
1474  echo " </td>\n";
1475  } elseif ($tmpday <= $max_day_in_month) {
1476  /* Show days of the current month */
1477  $curtime = dol_mktime(0, 0, 0, $month, $tmpday, $year);
1478  $style = 'cal_current_month';
1479  if ($iter_day == 6) {
1480  $style .= ' cal_current_month_right';
1481  }
1482  $today = 0;
1483  if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $month && $todayarray['year'] == $year) {
1484  $today = 1;
1485  }
1486  if ($today) {
1487  $style = 'cal_today';
1488  }
1489  if ($curtime < $todaytms) {
1490  $style .= ' cal_past';
1491  }
1492  //var_dump($todayarray['mday']."==".$tmpday." && ".$todayarray['mon']."==".$month." && ".$todayarray['year']."==".$year.' -> '.$style);
1493  echo ' <td class="'.$style.' nowrap tdtop" width="14%">';
1494  show_day_events($db, $tmpday, $month, $year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
1495  echo "</td>\n";
1496  } else {
1497  /* Show days after the current month (next month) */
1498  $style = 'cal_other_month';
1499  if ($iter_day == 6) {
1500  $style .= ' cal_other_month_right';
1501  }
1502  echo ' <td class="'.$style.' nowrap tdtop" width="14%">';
1503  show_day_events($db, $tmpday - $max_day_in_month, $next_month, $next_year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
1504  echo "</td>\n";
1505  }
1506  $tmpday++;
1507  }
1508  echo " </tr>\n";
1509  }
1510  print "</table>\n";
1511  print '</div>';
1512 
1513  print '<input type="hidden" name="actionmove" value="mupdate">';
1514  print '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($_SERVER['PHP_SELF']).'?mode=show_month&'.dol_escape_htmltag($_SERVER['QUERY_STRING']).'">';
1515  print '<input type="hidden" name="newdate" id="newdate">';
1516 } elseif ($mode == 'show_week') {
1517  // View by week
1518  $newparam = $param; // newparam is for birthday links
1519  $newparam = preg_replace('/showbirthday=/i', 'showbirthday_=', $newparam); // To avoid replacement when replace day= is done
1520  $newparam = preg_replace('/mode=show_month&?/i', '', $newparam);
1521  $newparam = preg_replace('/mode=show_week&?/i', '', $newparam);
1522  $newparam = preg_replace('/day=[0-9]+&?/i', '', $newparam);
1523  $newparam = preg_replace('/month=[0-9]+&?/i', '', $newparam);
1524  $newparam = preg_replace('/year=[0-9]+&?/i', '', $newparam);
1525  $newparam = preg_replace('/viewweek=[0-9]+&?/i', '', $newparam);
1526  $newparam = preg_replace('/showbirthday_=/i', 'showbirthday=', $newparam); // Restore correct parameter
1527  $newparam .= '&viewweek=1';
1528 
1529  print '<div class="liste_titre liste_titre_bydiv centpercent"><div class="divsearchfield">';
1530  print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid);
1531  print '</div></div>';
1532 
1533  print '<div class="div-table-responsive-no-min sectioncalendarbyweek maxscreenheightless300">';
1534  print '<table class="centpercent noborder nocellnopadd cal_pannel cal_month">';
1535  print ' <tr class="liste_titre">';
1536  $i = 0;
1537  while ($i < 7) {
1538  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";
1539  $i++;
1540  }
1541  echo " </tr>\n";
1542 
1543  echo " <tr>\n";
1544 
1545  for ($iter_day = 0; $iter_day < 7; $iter_day++) {
1546  // Show days of the current week
1547  $curtime = dol_time_plus_duree($firstdaytoshow, $iter_day, 'd'); // $firstdaytoshow is in timezone of server
1548  $tmpday = dol_print_date($curtime, '%d', 'tzuserrel');
1549  $tmpmonth = dol_print_date($curtime, '%m', 'tzuserrel');
1550  $tmpyear = dol_print_date($curtime, '%Y', 'tzuserrel');
1551 
1552  $style = 'cal_current_month';
1553  if ($iter_day == 6) {
1554  $style .= ' cal_other_month_right';
1555  }
1556 
1557  $today = 0;
1558  $todayarray = dol_getdate($now, 'fast');
1559  if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $tmpmonth && $todayarray['year'] == $tmpyear) {
1560  $today = 1;
1561  }
1562  if ($today) {
1563  $style = 'cal_today';
1564  }
1565 
1566  echo ' <td class="'.$style.'" width="14%" valign="top">';
1567  show_day_events($db, $tmpday, $tmpmonth, $tmpyear, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300);
1568  echo " </td>\n";
1569  }
1570  echo " </tr>\n";
1571 
1572  print "</table>\n";
1573  print '</div>';
1574 
1575  echo '<input type="hidden" name="actionmove" value="mupdate">';
1576  echo '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($_SERVER['PHP_SELF']).'?mode=show_week&'.dol_escape_htmltag($_SERVER['QUERY_STRING']).'">';
1577  echo '<input type="hidden" name="newdate" id="newdate">';
1578 } else { // View by day
1579  $newparam = $param; // newparam is for birthday links
1580  $newparam = preg_replace('/mode=show_month&?/i', '', $newparam);
1581  $newparam = preg_replace('/mode=show_week&?/i', '', $newparam);
1582  $newparam = preg_replace('/viewday=[0-9]+&?/i', '', $newparam);
1583  $newparam .= '&viewday=1';
1584  // Code to show just one day
1585  $style = 'cal_current_month cal_current_month_oneday';
1586  $today = 0;
1587  $todayarray = dol_getdate($now, 'fast');
1588  if ($todayarray['mday'] == $day && $todayarray['mon'] == $month && $todayarray['year'] == $year) {
1589  $today = 1;
1590  }
1591  //if ($today) $style='cal_today';
1592 
1593  $timestamp = dol_mktime(12, 0, 0, $month, $day, $year);
1594  $arraytimestamp = dol_getdate($timestamp);
1595 
1596  print '<div class="liste_titre liste_titre_bydiv centpercent"><div class="divsearchfield">';
1597  print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid);
1598  print '</div></div>';
1599 
1600  print '<div class="div-table-responsive-no-min sectioncalendarbyday maxscreenheightless300">';
1601  echo '<table class="tagtable centpercent noborder nocellnopadd cal_pannel cal_month noborderbottom" style="margin-bottom: 5px !important;">';
1602 
1603  echo ' <tr class="tagtr liste_titre">';
1604  echo ' <td class="tagtd center bold uppercase">'.$langs->trans("Day".$arraytimestamp['wday'])."</td>\n";
1605  echo " </td>\n";
1606 
1607  /*
1608  echo ' <div class="tagtr">';
1609  echo ' <div class="tagtd width100"></div>';
1610  echo ' <div class="tagtd center">';
1611  echo show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, -1);
1612  echo ' </div>'."\n";
1613  echo " </div>\n";
1614  */
1615 
1616  echo '</table>';
1617  print '</div>';
1618 
1619  /* WIP View per hour */
1620  $useviewhour = 0;
1621  if ($useviewhour) {
1622  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
1623 
1624  $maxheightwin = (isset($_SESSION["dol_screenheight"]) && $_SESSION["dol_screenheight"] > 500) ? ($_SESSION["dol_screenheight"] - 200) : 660; // Also into index.php file
1625 
1626  echo '<div style="max-height: '.$maxheightwin.'px;">';
1627  echo '<div class="tagtable centpercent calendarviewcontainer">';
1628 
1629  $maxnbofchar = 80;
1630 
1631  $tmp = explode('-', $conf->global->MAIN_DEFAULT_WORKING_HOURS);
1632  $minhour = round($tmp[0], 0);
1633  $maxhour = round($tmp[1], 0);
1634  if ($minhour > 23) {
1635  $minhour = 23;
1636  }
1637  if ($maxhour < 1) {
1638  $maxhour = 1;
1639  }
1640  if ($maxhour <= $minhour) {
1641  $maxhour = $minhour + 1;
1642  }
1643 
1644  $i = 0;
1645  $j = 0;
1646  while ($i < 24) {
1647  echo ' <div class="tagtr calendarviewcontainertr">'."\n";
1648  echo ' <div class="tagtd width100 tdtop">'.dol_print_date($i * 3600, 'hour', 'gmt').'</div>';
1649  echo ' <div class="tagtd '.$style.' tdtop"></div>'."\n";
1650  echo ' </div>'."\n";
1651  $i++;
1652  $j++;
1653  }
1654 
1655  echo '</div></div>';
1656 
1657  show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, 1);
1658 
1659  print '</div>';
1660  } else {
1661  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
1662 
1663  show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, 0);
1664 
1665  print '</div>';
1666  }
1667 }
1668 
1669 print "\n".'</form>';
1670 
1671 // End of page
1672 llxFooter();
1673 $db->close();
1674 
1675 
1694 function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventarray, $maxprint = 0, $maxnbofchar = 16, $newparam = '', $showinfo = 0, $minheight = 60, $nonew = 0)
1695 {
1696  global $user, $conf, $langs;
1697  global $action, $mode, $filter, $filtert, $status, $actioncode, $usergroup; // Filters used into search form
1698  global $theme_datacolor;
1699  global $cachethirdparties, $cachecontacts, $cacheusers, $colorindexused;
1700 
1701  if ($conf->use_javascript_ajax) { // Enable the "Show more button..."
1702  $conf->global->MAIN_JS_SWITCH_AGENDA = 1;
1703  }
1704 
1705  $dateint = sprintf("%04d", $year).sprintf("%02d", $month).sprintf("%02d", $day);
1706 
1707  //print 'show_day_events day='.$day.' month='.$month.' year='.$year.' dateint='.$dateint;
1708 
1709  print "\n";
1710 
1711  $curtime = dol_mktime(0, 0, 0, $month, $day, $year);
1712  $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;
1713  $urltocreate = '';
1714  if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create) {
1715  $newparam .= '&month='.str_pad($month, 2, "0", STR_PAD_LEFT).'&year='.$year;
1716  $hourminsec = '100000';
1717  $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 : ''));
1718  }
1719 
1720  // Line with title of day
1721  print '<div id="dayevent_'.$dateint.'" class="dayevent tagtable centpercent nobordernopadding">'."\n";
1722 
1723  if ($nonew <= 0) {
1724  print '<div class="tagtr cursorpointer" onclick="window.location=\''.$urltocreate.'\';"><div class="nowrap tagtd"><div class="left inline-block">';
1725  print '<a class="dayevent-aday" style="color: #666" href="'.$urltoshow.'">';
1726  if ($showinfo) {
1727  print dol_print_date($curtime, 'daytextshort');
1728  } else {
1729  print dol_print_date($curtime, '%d');
1730  }
1731  print '</a>';
1732  print '</div><div class="nowrap floatright inline-block marginrightonly">';
1733  if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create) {
1734  print '<a class="cursoradd" href="'.$urltocreate.'">'; // Explicit link, usefull for nojs interfaces
1735  print img_picto($langs->trans("NewAction"), 'edit_add.png');
1736  print '</a>';
1737  }
1738  print '</div></div></div>'."\n";
1739  }
1740 
1741  if ($nonew < 0) {
1742  print '</div>';
1743  return;
1744  }
1745 
1746  // Line with td contains all div of each events
1747  print '<div class="tagtr">';
1748  print '<div class="tagtd centpercent agendacell sortable">';
1749 
1750  //$curtime = dol_mktime (0, 0, 0, $month, $day, $year);
1751  $i = 0; $ireallyshown = 0; $itoshow = 0; $numother = 0; $numbirthday = 0; $numical = 0; $numicals = array();
1752  $ymd = sprintf("%04d", $year).sprintf("%02d", $month).sprintf("%02d", $day);
1753 
1754  $colorindexused[$user->id] = 0; // Color index for current user (user->id) is always 0
1755  $nextindextouse = is_array($colorindexused) ?count($colorindexused) : 0; // At first run this is 0, so fist user has 0, next 1, ...
1756  //var_dump($colorindexused);
1757 
1758  include_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
1759  $tmpholiday = new Holiday($db);
1760 
1761  foreach ($eventarray as $daykey => $notused) { // daykey is the 'YYYYMMDD' to show according to user
1762  $annee = dol_print_date($daykey, '%Y', 'gmt'); // We use gmt because we want the value represented by string 'YYYYMMDD'
1763  $mois = dol_print_date($daykey, '%m', 'gmt'); // We use gmt because we want the value represented by string 'YYYYMMDD'
1764  $jour = dol_print_date($daykey, '%d', 'gmt'); // We use gmt because we want the value represented by string 'YYYYMMDD'
1765 
1766  //print 'event daykey='.$daykey.' dol_print_date(daykey)='.dol_print_date($daykey, 'dayhour', 'gmt').' jour='.$jour.' mois='.$mois.' annee='.$annee."<br>\n";
1767 
1768  if ($day == $jour && $month == $mois && $year == $annee) {
1769  foreach ($eventarray[$daykey] as $index => $event) {
1770  if ($i < $maxprint || $maxprint == 0 || !empty($conf->global->MAIN_JS_SWITCH_AGENDA)) {
1771  $keysofuserassigned = array_keys($event->userassigned);
1772  $ponct = ($event->date_start_in_calendar == $event->date_end_in_calendar);
1773 
1774  // Define $color (Hex string like '0088FF') and $cssclass of event
1775  $color = -1; $cssclass = ''; $colorindex = -1;
1776  if (in_array($user->id, $keysofuserassigned)) {
1777  $cssclass = 'family_mytasks';
1778 
1779  if (empty($cacheusers[$event->userownerid])) {
1780  $newuser = new User($db);
1781  $newuser->fetch($event->userownerid);
1782  $cacheusers[$event->userownerid] = $newuser;
1783  }
1784  //var_dump($cacheusers[$event->userownerid]->color);
1785 
1786  // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
1787  if (!empty($cacheusers[$event->userownerid]->color)) {
1788  $color = $cacheusers[$event->userownerid]->color;
1789  }
1790  } elseif ($event->type_code == 'ICALEVENT') { // Event come from external ical file
1791  $numical++;
1792  if (!empty($event->icalname)) {
1793  if (!isset($numicals[dol_string_nospecial($event->icalname)])) {
1794  $numicals[dol_string_nospecial($event->icalname)] = 0;
1795  }
1796  $numicals[dol_string_nospecial($event->icalname)]++;
1797  }
1798 
1799  $color = ($event->icalcolor ? $event->icalcolor : -1);
1800  $cssclass = (!empty($event->icalname) ? 'family_ext'.md5($event->icalname) : 'family_other');
1801  } elseif ($event->type_code == 'BIRTHDAY') {
1802  $numbirthday++; $colorindex = 2; $cssclass = 'family_birthday '; $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
1803  } else {
1804  $numother++;
1805  $color = ($event->icalcolor ? $event->icalcolor : -1);
1806  $cssclass = (!empty($event->icalname) ? 'family_ext'.md5($event->icalname) : 'family_other');
1807 
1808  if (empty($cacheusers[$event->userownerid])) {
1809  $newuser = new User($db);
1810  $newuser->fetch($event->userownerid);
1811  $cacheusers[$event->userownerid] = $newuser;
1812  }
1813  //var_dump($cacheusers[$event->userownerid]->color);
1814 
1815  // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
1816  if (!empty($cacheusers[$event->userownerid]->color)) {
1817  $color = $cacheusers[$event->userownerid]->color;
1818  }
1819  }
1820 
1821  if ($color < 0) { // Color was not set on user card. Set color according to color index.
1822  // Define color index if not yet defined
1823  $idusertouse = ($event->userownerid ? $event->userownerid : 0);
1824  if (isset($colorindexused[$idusertouse])) {
1825  $colorindex = $colorindexused[$idusertouse]; // Color already assigned to this user
1826  } else {
1827  $colorindex = $nextindextouse;
1828  $colorindexused[$idusertouse] = $colorindex;
1829  if (!empty($theme_datacolor[$nextindextouse + 1])) {
1830  $nextindextouse++; // Prepare to use next color
1831  }
1832  }
1833  //print '|'.($color).'='.($idusertouse?$idusertouse:0).'='.$colorindex.'<br>';
1834  // Define color
1835  $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
1836  }
1837  $cssclass = $cssclass.' eventday_'.$ymd;
1838 
1839  // Defined style to disable drag and drop feature
1840  if ($event->type_code == 'AC_OTH_AUTO') {
1841  $cssclass .= " unmovable";
1842  } elseif ($event->type_code == 'HOLIDAY') {
1843  $cssclass .= " unmovable";
1844  } elseif ($event->type_code == 'BIRTHDAY') {
1845  $cssclass .= " unmovable";
1846  } elseif ($event->type_code == 'ICALEVENT') {
1847  $cssclass .= " unmovable";
1848  } 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)) {
1849  // If the event is on several days
1850  $tmpyearend = dol_print_date($event->date_start_in_calendar, '%Y', 'tzuserrel');
1851  $tmpmonthend = dol_print_date($event->date_start_in_calendar, '%m', 'tzuserrel');
1852  $tmpdayend = dol_print_date($event->date_start_in_calendar, '%d', 'tzuserrel');
1853  //var_dump($tmpyearend.' '.$tmpmonthend.' '.$tmpdayend);
1854  if ($tmpyearend != $annee || $tmpmonthend != $mois || $tmpdayend != $jour) {
1855  $cssclass .= " unmovable unmovable-mustusefirstdaytodrag";
1856  } else {
1857  $cssclass .= ' movable cursormove';
1858  }
1859  } else {
1860  if ($user->rights->agenda->allactions->create ||
1861  (($event->authorid == $user->id || $event->userownerid == $user->id) && $user->rights->agenda->myactions->create)) {
1862  $cssclass .= " movable cursormove";
1863  } else {
1864  $cssclass .= " unmovable";
1865  }
1866  }
1867 
1868  $h = ''; $nowrapontd = 1;
1869  if ($mode == 'show_day') {
1870  $h = 'height: 100%; '; $nowrapontd = 0;
1871  }
1872  if ($mode == 'show_week') {
1873  $h = 'height: 100%; '; $nowrapontd = 0;
1874  }
1875 
1876  // Show event box
1877  print "\n";
1878  print '<!-- start event '.$i.' -->'."\n";
1879 
1880  $morecss = '';
1881  if ($maxprint && $ireallyshown >= $maxprint) {
1882  $morecss = 'showifmore';
1883  }
1884  if ($event->type == 'birthdate' && !GETPOST('check_birthday')) {
1885  $morecss = 'hidden';
1886  }
1887  if ($event->type == 'holiday' && !GETPOST('check_holiday')) {
1888  $morecss = 'hidden';
1889  }
1890  if ($morecss != 'hidden') {
1891  $itoshow++;
1892  }
1893  if ($morecss != 'showifmore' && $morecss != 'hidden') {
1894  $ireallyshown++;
1895  }
1896  //var_dump($event->type.' - '.$morecss.' - '.$cssclass.' - '.$i.' - '.$ireallyshown.' - '.$itoshow);
1897 
1898  print '<div id="event_'.$ymd.'_'.$i.'" class="event family_'.$event->type.' '.$cssclass.($morecss ? ' '.$morecss : '').'"';
1899  //print ' style="height: 100px;';
1900  //print ' position: absolute; top: 40px; width: 50%;';
1901  //print '"';
1902  print '>';
1903 
1904  //var_dump($event->userassigned);
1905  //var_dump($event->transparency);
1906  print '<table class="centpercent cal_event';
1907  print (empty($event->transparency) ? ' cal_event_notbusy' : ' cal_event_busy');
1908  //if (empty($event->transparency) && empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) print ' opacitymedium'; // Not busy
1909  print '" style="'.$h;
1910  $colortouse = $color;
1911  // If colortouse is similar than background, we force to change it.
1912  if (empty($event->transparency) && empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) {
1913  print 'background: #f0f0f0;';
1914  print 'border-left: 5px solid #'.$colortouse.';';
1915  } else {
1916  print 'background: #f0f0f0;';
1917  print 'border-left: 5px solid #'.dol_color_minus($colortouse, -3).';';
1918  //print 'background: -webkit-gradient(linear, left top, left bottom, from(#'.dol_color_minus($colortouse, -3).'), to(#'.dol_color_minus($colortouse, -1).'));';
1919  }
1920  //print 'background: #'.$colortouse.';';
1921  //print 'background: -webkit-gradient(linear, left top, left bottom, from(#'.dol_color_minus($color, -3).'), to(#'.dol_color_minus($color, -1).'));';
1922  //if (! empty($event->transparency)) print 'background: #'.$color.'; background: -webkit-gradient(linear, left top, left bottom, from(#'.$color.'), to(#'.dol_color_minus($color,1).'));';
1923  //else print 'background-color: transparent !important; background: none; border: 1px solid #bbb;';
1924  //print ' -moz-border-radius:4px;"';
1925  //print 'border: 1px solid #ccc" width="100%"';
1926  print '">';
1927  print '<tr>';
1928  print '<td class="tdoverflow nobottom centpercent '.($nowrapontd ? 'nowrap ' : '').'cal_event'.($event->type_code == 'BIRTHDAY' ? ' cal_event_birthday' : '').'">';
1929 
1930  $daterange = '';
1931 
1932  if ($event->type_code == 'BIRTHDAY') { // It's birthday calendar
1933  print $event->getNomUrl(1, $maxnbofchar, 'cal_event', 'birthday', 'contact');
1934  } elseif ($event->type_code == 'HOLIDAY') { // It's holiday calendar
1935  $tmpholiday->fetch($event->id);
1936 
1937  print $tmpholiday->getNomUrl(1);
1938 
1939  $tmpid = $tmpholiday->fk_user;
1940  if (empty($cacheusers[$tmpid])) {
1941  $newuser = new User($db);
1942  $newuser->fetch($tmpid);
1943  $cacheusers[$tmpid] = $newuser;
1944  }
1945 
1946  $listofusertoshow = '';
1947  $listofusertoshow .= '<br>'.$cacheusers[$tmpid]->getNomUrl(-1, '', 0, 0, 0, 0, '', 'paddingright valigntextbottom');
1948  print $listofusertoshow;
1949  } else { // Other calendar
1950  // Picto
1951  if (empty($event->fulldayevent)) {
1952  //print $event->getNomUrl(2).' ';
1953  }
1954 
1955  // Date
1956  if (empty($event->fulldayevent)) {
1957  // Show hours (start ... end)
1958  $tmpyearstart = dol_print_date($event->date_start_in_calendar, '%Y', 'tzuserrel');
1959  $tmpmonthstart = dol_print_date($event->date_start_in_calendar, '%m', 'tzuserrel');
1960  $tmpdaystart = dol_print_date($event->date_start_in_calendar, '%d', 'tzuserrel');
1961  $tmpyearend = dol_print_date($event->date_end_in_calendar, '%Y', 'tzuserrel');
1962  $tmpmonthend = dol_print_date($event->date_end_in_calendar, '%m', 'tzuserrel');
1963  $tmpdayend = dol_print_date($event->date_end_in_calendar, '%d', 'tzuserrel');
1964 
1965  // Hour start
1966  if ($tmpyearstart == $annee && $tmpmonthstart == $mois && $tmpdaystart == $jour) {
1967  $daterange .= dol_print_date($event->date_start_in_calendar, 'hour', 'tzuserrel');
1968  if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) {
1969  if ($tmpyearstart == $tmpyearend && $tmpmonthstart == $tmpmonthend && $tmpdaystart == $tmpdayend) {
1970  $daterange .= '-';
1971  }
1972  //else
1973  //print '...';
1974  }
1975  }
1976  if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) {
1977  if ($tmpyearstart != $tmpyearend || $tmpmonthstart != $tmpmonthend || $tmpdaystart != $tmpdayend) {
1978  $daterange .= '...';
1979  }
1980  }
1981  // Hour end
1982  if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) {
1983  if ($tmpyearend == $annee && $tmpmonthend == $mois && $tmpdayend == $jour) {
1984  $daterange .= dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel');
1985  }
1986  }
1987  } else {
1988  if ($showinfo) {
1989  print $langs->trans("EventOnFullDay")."<br>\n";
1990  }
1991  }
1992 
1993  // Show title
1994  $titletoshow = $daterange;
1995  $titletoshow .= ($titletoshow ? ' ' : '').($event->label ? $event->label : $event->libelle);
1996 
1997  if ($event->type_code != 'ICALEVENT') {
1998  $savlabel = $event->label ? $event->label : $event->libelle;
1999  $event->label = $titletoshow;
2000  $event->libelle = $titletoshow; // deprecatd
2001  // Note: List of users are inside $event->userassigned. Link may be clickable depending on permissions of user.
2002  $titletoshow = (($event->type_picto || $event->type_code) ? $event->getTypePicto() : '');
2003  $titletoshow .= $event->getNomUrl(0, $maxnbofchar, 'cal_event cal_event_title', '', 0, 0);
2004  $event->label = $savlabel;
2005  $event->libelle = $savlabel;
2006  }
2007 
2008  // Loop on each assigned user
2009  $listofusertoshow = '';
2010  $posuserassigned = 0;
2011  foreach ($event->userassigned as $tmpid => $tmpdata) {
2012  if (!$posuserassigned && $titletoshow) {
2013  $listofusertoshow .= '<br>';
2014  }
2015  $posuserassigned++;
2016  if (empty($cacheusers[$tmpid])) {
2017  $newuser = new User($db);
2018  $newuser->fetch($tmpid);
2019  $cacheusers[$tmpid] = $newuser;
2020  }
2021 
2022  $listofusertoshow .= $cacheusers[$tmpid]->getNomUrl(-3, '', 0, 0, 0, 0, '', 'paddingright valigntextbottom');
2023  }
2024 
2025  print $titletoshow;
2026  print $listofusertoshow;
2027 
2028  if ($event->type_code == 'ICALEVENT') {
2029  print '<br>('.dol_trunc($event->icalname, $maxnbofchar).')';
2030  }
2031 
2032  $thirdparty_id = ($event->socid > 0 ? $event->socid : ((is_object($event->societe) && $event->societe->id > 0) ? $event->societe->id : 0));
2033  $contact_id = ($event->contact_id > 0 ? $event->contact_id : ((is_object($event->contact) && $event->contact->id > 0) ? $event->contact->id : 0));
2034 
2035  // If action related to company / contact
2036  $linerelatedto = '';
2037  if ($thirdparty_id > 0) {
2038  if (!isset($cachethirdparties[$thirdparty_id]) || !is_object($cachethirdparties[$thirdparty_id])) {
2039  $thirdparty = new Societe($db);
2040  $thirdparty->fetch($thirdparty_id);
2041  $cachethirdparties[$thirdparty_id] = $thirdparty;
2042  } else {
2043  $thirdparty = $cachethirdparties[$thirdparty_id];
2044  }
2045  if (!empty($thirdparty->id)) {
2046  $linerelatedto .= $thirdparty->getNomUrl(1, '', 0);
2047  }
2048  }
2049  if (!empty($contact_id) && $contact_id > 0) {
2050  if (!is_object($cachecontacts[$contact_id])) {
2051  $contact = new Contact($db);
2052  $contact->fetch($contact_id);
2053  $cachecontacts[$contact_id] = $contact;
2054  } else {
2055  $contact = $cachecontacts[$contact_id];
2056  }
2057  if ($linerelatedto) {
2058  $linerelatedto .= '&nbsp;';
2059  }
2060  if (!empty($contact->id)) {
2061  $linerelatedto .= $contact->getNomUrl(1, '', 0);
2062  }
2063  }
2064  if (!empty($event->fk_element) && $event->fk_element > 0 && !empty($event->elementtype) && !empty($conf->global->AGENDA_SHOW_LINKED_OBJECT)) {
2065  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
2066  if ($linerelatedto) {
2067  $linerelatedto .= '<br>';
2068  }
2069  $linerelatedto .= dolGetElementUrl($event->fk_element, $event->elementtype, 1);
2070  }
2071  if ($linerelatedto) {
2072  print '<br>'.$linerelatedto;
2073  }
2074  }
2075 
2076  // Show location
2077  if ($showinfo) {
2078  if ($event->location) {
2079  print '<br>';
2080  print $langs->trans("Location").': '.$event->location;
2081  }
2082  }
2083 
2084  print '</td>';
2085  // Status - Percent
2086  $withstatus = 0;
2087  if ($event->type_code != 'BIRTHDAY' && $event->type_code != 'ICALEVENT') {
2088  $withstatus = 1;
2089  if ($event->percentage >= 0) {
2090  $withstatus = 2;
2091  }
2092  }
2093  print '<td class="nobottom right nowrap cal_event_right'.($withstatus >= 2 ? ' cal_event_right_status' : '').'">';
2094  if ($withstatus) {
2095  print $event->getLibStatut(3, 1);
2096  } else {
2097  print '&nbsp;';
2098  }
2099  print '</td></tr></table>';
2100  print '</div><!-- end event '.$i.' -->'."\n";
2101 
2102  $i++;
2103  } else {
2104  print '<a href="'.DOL_URL_ROOT.'/comm/action/index.php?mode='.$mode.'&maxprint=0&month='.((int) $monthshown).'&year='.((int) $year);
2105  print ($status ? '&status='.$status : '').($filter ? '&filter='.urlencode($filter) : '');
2106  print ($filtert ? '&search_filtert='.urlencode($filtert) : '');
2107  print ($usergroup ? '&search_usergroup='.urlencode($usergroup) : '');
2108  print ($actioncode != '' ? '&search_actioncode='.urlencode($actioncode) : '');
2109  print '">'.img_picto("all", "1downarrow_selected.png").' ...';
2110  print ' +'.(count($eventarray[$daykey]) - $maxprint);
2111  print '</a>';
2112  break;
2113  //$ok=false; // To avoid to show twice the link
2114  }
2115  }
2116 
2117  break;
2118  }
2119  }
2120  if (!$i) { // No events
2121  print '&nbsp;';
2122  }
2123 
2124  if (!empty($conf->global->MAIN_JS_SWITCH_AGENDA) && $itoshow > $ireallyshown && $maxprint) {
2125  print '<div class="center cursorpointer" id="more_'.$ymd.'">'.img_picto("All", "angle-double-down", 'class="warning"').' +'.($itoshow - $ireallyshown).'</div>';
2126  //print ' +'.(count($eventarray[$daykey])-$maxprint);
2127 
2128  print '<script type="text/javascript">'."\n";
2129  print 'jQuery(document).ready(function () {'."\n";
2130  print ' var open=0;'."\n";
2131  print ' jQuery("#more_'.$ymd.'").click(function() { console.log("Click on showmore for '.$ymd.'"); reinit_day_'.$ymd.'(); event.stopImmediatePropagation(); });'."\n";
2132  print ' function reinit_day_'.$ymd.'() {'."\n";
2133  print ' jQuery(".eventday_'.$ymd.'.showifmore").toggle();'."\n";
2134  print ' open = open + 1; if (open > 1) { open = 0; }'."\n";
2135  print ' if (open) { ';
2136  print ' jQuery("#more_'.$ymd.'").html(\''.img_picto("All", "angle-double-up", 'class="warning"').'\');'."\n";
2137  print ' } else { ';
2138  print ' jQuery("#more_'.$ymd.'").html(\''.img_picto("All", "angle-double-down", 'class="warning"').' +'.($itoshow - $ireallyshown).'\');'."\n";
2139  print ' }'."\n";
2140  print ' }'."\n";
2141  print '});'."\n";
2142  print '</script>'."\n";
2143  }
2144 
2145  print '</div></div>'; // td tr
2146 
2147  print '</div>'; // table
2148  print "\n";
2149 }
2150 
2151 
2160 function dol_color_minus($color, $minus, $minusunit = 16)
2161 {
2162  $newcolor = $color;
2163  if ($minusunit == 16) {
2164  $newcolor[0] = dechex(max(min(hexdec($newcolor[0]) - $minus, 15), 0));
2165  $newcolor[2] = dechex(max(min(hexdec($newcolor[2]) - $minus, 15), 0));
2166  $newcolor[4] = dechex(max(min(hexdec($newcolor[4]) - $minus, 15), 0));
2167  } else {
2168  // Not yet implemented
2169  }
2170  return $newcolor;
2171 }
2172 
2180 function sort_events_by_date($a, $b)
2181 {
2182  // Sort holidays at first
2183  if ($a->type_code === 'HOLIDAY') {
2184  return -1;
2185  }
2186  if ($b->type_code === 'HOLIDAY') {
2187  return 1;
2188  }
2189 
2190  // datep => Event start time
2191  // datef => Event end time
2192 
2193  // Events have different start time
2194  if ($a->datep !== $b->datep) {
2195  return $a->datep - $b->datep;
2196  }
2197 
2198  // Events have same start time and no end time
2199  if ((!is_numeric($b->datef)) || (!is_numeric($a->datef))) {
2200  return sort_events_by_percentage($a, $b);
2201  }
2202 
2203  // Events have the same start time and same end time
2204  if ($b->datef === $a->datef) {
2205  return sort_events_by_percentage($a, $b);
2206  }
2207 
2208  // Events have the same start time, but have different end time -> longest event first
2209  return $b->datef - $a->datef;
2210 }
2211 
2219 function sort_events_by_percentage($a, $b)
2220 {
2221  // Sort events with no percentage before each other
2222  // (usefull to sort holidays, sick days or similar on the top)
2223 
2224  if ($a->percentage < 0) {
2225  return -1;
2226  }
2227 
2228  if ($b->percentage < 0) {
2229  return 1;
2230  }
2231 
2232  return $b->percentage - $a->percentage;
2233 }
dol_getdate
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
Definition: functions.lib.php:2713
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
restrictedArea
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.
Definition: security.lib.php:234
ActionComm
Class to manage agenda events (actions)
Definition: actioncomm.class.php:38
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_nl2br
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
Definition: functions.lib.php:6963
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
calendars_prepare_head
calendars_prepare_head($param)
Define head array for tabs of agenda setup pages.
Definition: agenda.lib.php:474
print_actions_filter
print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, $filtera, $filtert, $filterd, $pid, $socid, $action, $showextcals=array(), $actioncode='', $usergroupid='', $excludetype='', $resourceid=0)
Show filter form in agenda view.
Definition: agenda.lib.php:50
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
llxFooter
llxFooter()
Footer empty.
Definition: index.php:71
dol_get_next_week
dol_get_next_week($day, $week, $month, $year)
Return next week.
Definition: date.lib.php:529
dolGetButtonTitle
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
Definition: functions.lib.php:10605
dol_string_nohtmltag
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
Definition: functions.lib.php:6694
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
Contact
Class to manage contact/addresses.
Definition: contact.class.php:40
print_barre_liste
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
Definition: functions.lib.php:5257
llxHeader
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
Definition: index.php:63
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:80
dol_get_prev_month
dol_get_prev_month($month, $year)
Return previous month.
Definition: date.lib.php:470
dolGetFirstLastname
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
Definition: functions.lib.php:8062
ICal
Class to read/parse ICal calendars.
Definition: ical.class.php:34
dol_time_plus_duree
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition: date.lib.php:121
User
Class to manage Dolibarr users.
Definition: user.class.php:44
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
show_day_events
show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventarray, $maxprint=0, $maxnbofchar=16, $newparam='', $showinfo=0, $minheight=60, $nonew=0)
Show event of a particular day.
Definition: index.php:1694
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
dol_get_next_month
dol_get_next_month($month, $year)
Return next month.
Definition: date.lib.php:489
dol_get_first_day_week
dol_get_first_day_week($day, $month, $year, $gm=false)
Return first day of week for a date.
Definition: date.lib.php:626
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
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
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
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 ...
Definition: security.lib.php:933
dol_mktime
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Definition: functions.lib.php:2757
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:93
dol_stringtotime
dol_stringtotime($string, $gm=1)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
Definition: date.lib.php:383
dol_get_prev_day
dol_get_prev_day($day, $month, $year)
Return previous day.
Definition: date.lib.php:439
dol_get_next_day
dol_get_next_day($day, $month, $year)
Return next day.
Definition: date.lib.php:455
if
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
Definition: journals_list.php:25