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