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