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