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