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