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