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