dolibarr 25.0.0-alpha
peruser.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-2014 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) 2018-2026 Frédéric France <frederic.france@free.fr>
9 * Copyright (C) 2023 Florian HENRY <florian.henry@scopen.fr>
10 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
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';
42require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
43require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
44require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
45require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
46require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
47require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
48require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
49require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
50
51$MAXAGENDA = getDolGlobalString('AGENDA_EXT_NB', 6);
52$DELAYFORCACHE = 300; // 300 seconds
53
54$disabledefaultvalues = GETPOSTINT('disabledefaultvalues');
55
56$action = GETPOST('action', 'aZ09');
57
58$check_holiday = GETPOSTINT('check_holiday');
59$filter = GETPOST("search_filter", 'alpha', 3) ? GETPOST("search_filter", 'alpha', 3) : GETPOST("filter", 'alpha', 3);
60$filtert = GETPOST("search_filtert", "intcomma", 3) ? GETPOST("search_filtert", "intcomma", 3) : GETPOST("filtert", "intcomma", 3);
61$usergroup = GETPOSTINT("search_usergroup", 3) ? GETPOSTINT("search_usergroup", 3) : GETPOSTINT("usergroup", 3);
62$showbirthday = getDolGlobalInt('AGENDA_ENABLE_SHOW_BIRTHDAY_PER_USER'); // disabled by default
63
64// Pagination parameters
65$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
66$sortfield = GETPOST('sortfield', 'aZ09comma');
67$sortorder = GETPOST('sortorder', 'aZ09comma');
68$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
69if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
70 // If $page is not defined, or '' or -1 or if we click on clear filters
71 $page = 0;
72}
73$offset = $limit * $page;
74if (!$sortorder) {
75 $sortorder = "ASC";
76}
77if (!$sortfield) {
78 $sortfield = "a.datec";
79}
80
81// Security check
82$socid = GETPOSTINT("search_socid") ? GETPOSTINT("search_socid") : GETPOSTINT("socid");
83if ($user->socid) {
84 $socid = $user->socid;
85}
86if ($socid < 0) {
87 $socid = '';
88}
89
90$canedit = 1; // can read events of others
91if (!$user->hasRight('agenda', 'myactions', 'read')) {
93}
94if (!$user->hasRight('agenda', 'allactions', 'read')) {
95 $canedit = 0;
96}
97if (!$user->hasRight('agenda', 'allactions', 'read') || $filter == 'mine') { // If no permission to see all, we show only affected to me
98 $filtert = (string) $user->id;
99}
100
101$mode = 'show_peruser';
102$resourceid = GETPOSTINT("search_resourceid") ? GETPOSTINT("search_resourceid") : GETPOSTINT("resourceid");
103$year = GETPOSTINT("year") ? GETPOSTINT("year") : date("Y");
104$month = GETPOSTINT("month") ? GETPOSTINT("month") : date("m");
105$week = GETPOSTINT("week") ? GETPOSTINT("week") : date("W");
106$day = GETPOSTINT("day") ? GETPOSTINT("day") : date("d");
107$pid = GETPOSTISSET("search_projectid") ? GETPOSTINT("search_projectid", 3) : GETPOSTINT("projectid", 3);
108$status = GETPOSTISSET("search_status") ? GETPOST("search_status", 'aZ09') : GETPOST("status", 'aZ09'); // status may be 0, 50, 100, 'todo', 'na' or -1
109$type = GETPOSTISSET("search_type") ? GETPOST("search_type", 'aZ09') : GETPOST("type", 'aZ09');
110$maxprint = GETPOSTISSET("maxprint") ? GETPOSTINT("maxprint") : getDolGlobalInt('AGENDA_MAX_EVENTS_DAY_VIEW', 3);
111$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
112$search_categ_cus = GETPOSTINT("search_categ_cus", 3) ? GETPOSTINT("search_categ_cus", 3) : 0;
113// Set actioncode (this code must be same for setting actioncode into peruser, listacton and index)
114if (GETPOST('search_actioncode', 'array:aZ09')) {
115 $actioncode = GETPOST('search_actioncode', 'array:aZ09', 3);
116 if (!count($actioncode)) {
117 $actioncode = '0';
118 }
119} else {
120 $actioncode = GETPOST("search_actioncode", "alpha", 3) ? GETPOST("search_actioncode", "alpha", 3) : (GETPOST("search_actioncode", "alpha") == '0' ? '0' : ((!getDolGlobalString('AGENDA_DEFAULT_FILTER_TYPE') || $disabledefaultvalues) ? '' : getDolGlobalString('AGENDA_DEFAULT_FILTER_TYPE')));
121}
122
123$dateselect = dol_mktime(0, 0, 0, GETPOSTINT('dateselectmonth'), GETPOSTINT('dateselectday'), GETPOSTINT('dateselectyear'));
124if ($dateselect > 0) {
125 $day = GETPOSTINT('dateselectday');
126 $month = GETPOSTINT('dateselectmonth');
127 $year = GETPOSTINT('dateselectyear');
128}
129
130// working hours
131$tmp = getDolGlobalString('MAIN_DEFAULT_WORKING_HOURS', '9-18');
132$tmp = str_replace(' ', '', $tmp); // FIX 7533
133$tmparray = explode('-', $tmp);
134$begin_h = GETPOSTISSET('begin_h') ? GETPOSTINT('begin_h') : ($tmparray[0] != '' ? $tmparray[0] : 9);
135$end_h = GETPOSTISSET('end_h') ? GETPOSTINT('end_h') : ($tmparray[1] != '' ? $tmparray[1] : 18);
136if ($begin_h < 0 || $begin_h > 23) {
137 $begin_h = 9;
138}
139if ($end_h < 1 || $end_h > 24) {
140 $end_h = 18;
141}
142if ($end_h <= $begin_h) {
143 $end_h = $begin_h + 1;
144}
145
146// working days
147$tmp = getDolGlobalString('MAIN_DEFAULT_WORKING_DAYS', '1-5');
148$tmp = str_replace(' ', '', $tmp); // FIX 7533
149$tmparray = explode('-', $tmp);
150$begin_d = GETPOSTISSET('begin_d') ? GETPOSTINT('begin_d') : ($tmparray[0] != '' ? $tmparray[0] : 1);
151$end_d = GETPOSTISSET('end_d') ? GETPOSTINT('end_d') : ($tmparray[1] != '' ? $tmparray[1] : 5);
152if ($begin_d < 1 || $begin_d > 7) {
153 $begin_d = 1;
154}
155if ($end_d < 1 || $end_d > 7) {
156 $end_d = 7;
157}
158if ($end_d < $begin_d) {
159 $end_d = $begin_d + 1;
160}
161
162if ($status == '' && !GETPOSTISSET('search_status')) {
163 $status = ((!getDolGlobalString('AGENDA_DEFAULT_FILTER_STATUS') || $disabledefaultvalues) ? '' : getDolGlobalString('AGENDA_DEFAULT_FILTER_STATUS'));
164}
165
166if (empty($mode) && !GETPOSTISSET('mode')) {
167 $mode = getDolGlobalString('AGENDA_DEFAULT_VIEW', 'show_peruser');
168}
169
170// View by month
171if (GETPOST('viewcal', 'alpha') && $mode != 'show_day' && $mode != 'show_week' && $mode != 'show_peruser') {
172 $mode = 'show_month';
173 $day = '';
174}
175// View by week
176if (GETPOST('viewweek', 'alpha') || $mode == 'show_week') {
177 $mode = 'show_week';
178 $week = ($week ? $week : date("W"));
179 $day = ($day ? $day : date("d"));
180}
181// View by day
182if (GETPOST('viewday', 'alpha') || $mode == 'show_day') {
183 $mode = 'show_day';
184 $day = ($day ? $day : date("d"));
185}
186
187$labelbytype = array(); // Ensure variable exists
188
189$object = new ActionComm($db);
190
191// Load translation files required by the page
192$langs->loadLangs(array('users', 'agenda', 'other', 'commercial'));
193
194// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
195$hookmanager->initHooks(array('agenda'));
196
197$result = restrictedArea($user, 'agenda', 0, 'actioncomm&societe', 'myactions|allactions', 'fk_soc', 'id');
198if ($user->socid && $socid) {
199 $result = restrictedArea($user, 'societe', $socid);
200}
201
202$search_status = $status;
203
204
205/*
206 * Actions
207 */
208
209// None
210
211
212/*
213 * View
214 */
215
216$parameters = array(
217 'socid' => $socid,
218 'status' => $status,
219 'year' => $year,
220 'month' => $month,
221 'day' => $day,
222 'type' => $type,
223 'maxprint' => $maxprint,
224 'filter' => $filter,
225 'filtert' => $filtert,
226 'showbirthday' => $showbirthday,
227 'canedit' => $canedit,
228 'optioncss' => $optioncss,
229 'actioncode' => $actioncode,
230 'pid' => $pid,
231 'resourceid' => $resourceid,
232 'usergroup' => $usergroup,
233);
234$reshook = $hookmanager->executeHooks('beforeAgendaPerUser', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
235if ($reshook < 0) {
236 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
237}
238
239$form = new Form($db);
240$companystatic = new Societe($db);
241
242$help_url = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:M&oacute;dulo_Agenda|DE:Modul_Terminplanung';
243llxHeader('', $langs->trans("Agenda"), $help_url);
244
245$now = dol_now();
246$nowarray = dol_getdate($now);
247$nowyear = $nowarray['year'];
248$nowmonth = $nowarray['mon'];
249$nowday = $nowarray['mday'];
250
251
252$listofextcals = array();
253
254// Define list of external calendars (global admin setup)
255$i = 0;
256while ($i < $MAXAGENDA) {
257 $i++;
258 $source = 'AGENDA_EXT_SRC'.$i;
259 $name = 'AGENDA_EXT_NAME'.$i;
260 $offsettz = 'AGENDA_EXT_OFFSETTZ'.$i;
261 $color = 'AGENDA_EXT_COLOR'.$i;
262 $enabled = 'AGENDA_EXT_ENABLED'.$i;
263 $default = 'AGENDA_EXT_ACTIVEBYDEFAULT'.$i;
264 $buggedfile = 'AGENDA_EXT_BUGGEDFILE'.$i;
265 if (getDolGlobalString($source) && getDolGlobalString($name) && getDolGlobalString($enabled)) {
266 // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight'
267 $listofextcals[] = array(
268 'type' => 'globalsetup',
269 'src' => getDolGlobalString($source),
271 'offsettz' => (int) getDolGlobalInt($offsettz, 0),
272 'color' => dol_string_nohtmltag(getDolGlobalString($color)),
273 'cachedelay' => getDolGlobalInt('AGENDA_EXT_CACHE'.$i, 0),
274 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
275 'default' => dol_string_nohtmltag(getDolGlobalString($default)),
276 'buggedfile' => dol_string_nohtmltag(getDolGlobalString('buggedfile', ''))
277 );
278 }
279}
280
281// Define list of external calendars (user setup)
282$i = 0;
283while ($i < $MAXAGENDA) {
284 $i++;
285 $source = 'AGENDA_EXT_SRC_'.$user->id.'_'.$i;
286 $name = 'AGENDA_EXT_NAME_'.$user->id.'_'.$i;
287 $offsettz = 'AGENDA_EXT_OFFSETTZ_'.$user->id.'_'.$i;
288 $color = 'AGENDA_EXT_COLOR_'.$user->id.'_'.$i;
289 $enabled = 'AGENDA_EXT_ENABLED_'.$user->id.'_'.$i;
290 $default = 'AGENDA_EXT_ACTIVEBYDEFAULT_'.$user->id.'_'.$i;
291 $buggedfile = 'AGENDA_EXT_BUGGEDFILE_'.$user->id.'_'.$i;
292
293 if (getDolUserString($source) && getDolUserString($name)) {
294 // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight'
295 $listofextcals[] = array(
296 'type' => 'usersetup',
297 'src' => getDolUserString($source),
298 'name' => dol_string_nohtmltag(getDolUserString($name)),
299 'offsettz' => (int) (empty($user->conf->$offsettz) ? 0 : $user->conf->$offsettz),
300 'color' => dol_string_nohtmltag(getDolUserString($color)),
301 'cachedelay' => getDolUserInt('AGENDA_EXT_CACHE_'.$user->id.'_'.$i, 0),
302 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
303 'default' => dol_string_nohtmltag(getDolUserString($default)),
304 'buggedfile' => dol_string_nohtmltag(isset($user->conf->buggedfile) ? $user->conf->buggedfile : '')
305 );
306 }
307}
308
309
310$prev = dol_get_first_day_week($day, $month, $year);
311$first_day = $prev['first_day'];
312$first_month = $prev['first_month'];
313$first_year = $prev['first_year'];
314
315$week = $prev['week'];
316
317$day = (int) $day;
318$next = dol_get_next_week($day, (int) $week, $month, $year);
319$next_year = $next['year'];
320$next_month = $next['month'];
321$next_day = $next['day'];
322
323$max_day_in_month = date("t", dol_mktime(0, 0, 0, $month, 1, $year));
324
325$tmpday = $first_day;
326//print 'xx'.$prev_year.'-'.$prev_month.'-'.$prev_day;
327//print 'xx'.$next_year.'-'.$next_month.'-'.$next_day;
328
329$title = $langs->trans("DoneAndToDoActions");
330if ($status == 'done') {
331 $title = $langs->trans("DoneActions");
332}
333if ($status == 'todo') {
334 $title = $langs->trans("ToDoActions");
335}
336
337$param = '';
338if (($actioncode && $actioncode !== '-1') || GETPOSTISSET('search_actioncode')) {
339 if (is_array($actioncode)) {
340 foreach ($actioncode as $str_action) {
341 if ($str_action != '-1') {
342 $param .= "&search_actioncode[]=".urlencode($str_action);
343 }
344 }
345 } else {
346 $param .= "&search_actioncode=".urlencode($actioncode);
347 }
348}
349if ($resourceid > 0) {
350 $param .= "&search_resourceid=".urlencode((string) ($resourceid));
351}
352
353if ($status || GETPOSTISSET('status') || GETPOSTISSET('search_status')) {
354 $param .= "&search_status=".urlencode($status);
355}
356if ($filter) {
357 $param .= "&search_filter=".urlencode((string) $filter);
358}
359if ($filtert) {
360 $param .= "&search_filtert=".urlencode((string) $filtert);
361}
362if ($usergroup > 0) {
363 $param .= "&search_usergroup=".urlencode((string) ($usergroup));
364}
365if ($socid > 0) {
366 $param .= "&search_socid=".urlencode((string) ($socid));
367}
368if ($showbirthday) { // Always false @phpstan-ignore-line
369 $param .= "&search_showbirthday=1";
370}
371if ($pid) {
372 $param .= "&search_projectid=".urlencode((string) ($pid));
373}
374if ($type) {
375 $param .= "&search_type=".urlencode($type);
376}
377if ($mode != 'show_peruser') {
378 $param .= '&mode='.urlencode((string) $mode);
379}
380if ($begin_h != '') {
381 $param .= '&begin_h='.((int) $begin_h);
382}
383if ($end_h != '') {
384 $param .= '&end_h='.((int) $end_h);
385}
386if ($begin_d != '') {
387 $param .= '&begin_d='.((int) $begin_d);
388}
389if ($end_d != '') {
390 $param .= '&end_d='.((int) $end_d);
391}
392if ($search_categ_cus != 0) {
393 $param .= '&search_categ_cus='.urlencode((string) ($search_categ_cus));
394}
395if ($check_holiday) {
396 $param .= '&check_holiday=1';
397}
398$param .= "&maxprint=".urlencode((string) ($maxprint));
399
400$paramnoactionodate = $param;
401
402$prev = dol_get_first_day_week($day, $month, $year);
403//print "day=".$day." month=".$month." year=".$year;
404//var_dump($prev); exit;
405$prev_year = $prev['prev_year'];
406$prev_month = $prev['prev_month'];
407$prev_day = $prev['prev_day'];
408$first_day = $prev['first_day'];
409$first_month = $prev['first_month'];
410$first_year = $prev['first_year'];
411
412$week = $prev['week'];
413
414$day = (int) $day;
415$next = dol_get_next_week($first_day, (int) $week, $first_month, $first_year);
416$next_year = $next['year'];
417$next_month = $next['month'];
418$next_day = $next['day'];
419
420// Define firstdaytoshow and lastdaytoshow. Warning: lastdaytoshow is last second to show + 1
421// $firstdaytoshow and lastdaytoshow become a gmt dates to use to search/compare because first_xxx are in tz idea and we used tzuserrel
422$firstdaytoshow = dol_mktime(0, 0, 0, $first_month, $first_day, $first_year, 'tzuserrel');
423$nb_weeks_to_show = (getDolGlobalString('AGENDA_NB_WEEKS_IN_VIEW_PER_USER')) ? ((int) $conf->global->AGENDA_NB_WEEKS_IN_VIEW_PER_USER * 7) : 7;
424$lastdaytoshow = dol_time_plus_duree($firstdaytoshow, $nb_weeks_to_show, 'd');
425//print $firstday.'-'.$first_month.'-'.$first_year;
426//print dol_print_date($firstdaytoshow, 'dayhour', 'gmt');
427//print dol_print_date($lastdaytoshow,'dayhour', 'gmt');
428
429$max_day_in_month = idate("t", dol_mktime(0, 0, 0, $month, 1, $year, 'gmt'));
430
431$tmpday = $first_day;
432$picto = 'calendarweek';
433
434// Show navigation bar
435$nav = '<div class="navselectiondate inline-block nowraponall">';
436$nav .= "<a href=\"?year=".$prev_year."&amp;month=".$prev_month."&amp;day=".$prev_day.$param."\"><i class=\"fa fa-chevron-left\" title=\"".dol_escape_htmltag($langs->trans("Previous"))."\"></i></a> &nbsp; \n";
437$nav .= " <span id=\"month_name\">".dol_print_date(dol_mktime(0, 0, 0, $first_month, $first_day, $first_year), "%Y").", ".$langs->trans("WeekShort")." ".$week;
438$nav .= " </span>\n";
439$nav .= " &nbsp; <a href=\"?year=".$next_year."&amp;month=".$next_month."&amp;day=".$next_day.$param."\"><i class=\"fa fa-chevron-right\" title=\"".dol_escape_htmltag($langs->trans("Next"))."\"></i></a>\n";
440if (empty($conf->dol_optimize_smallscreen)) {
441 $nav .= ' <a href="?year='.$nowyear.'&month='.$nowmonth.'&day='.$nowday.$param.'" class="datenowlink marginleftonly marginrightonly">'.$langs->trans("Today").'</a> ';
442}
443$nav .= '</div>';
444$nav .= $form->selectDate($dateselect, 'dateselect', 0, 0, 1, '', 1, 0);
445//$nav .= ' <input type="submit" class="button button-save" name="submitdateselect" value="'.$langs->trans("Refresh").'">';
446$nav .= '<button type="submit" class="liste_titre button_search valignmiddle" name="button_search_x" value="x"><span class="fa fa-search"></span></button>';
447
448// Must be after the nav definition
449$paramnodate = $param;
450$param .= '&year='.$year.'&month='.$month.($day ? '&day='.$day : '');
451//print 'x'.$param;
452
453
454$paramnoaction = preg_replace('/mode=[a-z_]+/', '', preg_replace('/action=[a-z_]+/', '', $param));
455$paramnoactionodate = preg_replace('/mode=[a-z_]+/', '', preg_replace('/action=[a-z_]+/', '', $paramnodate));
456
457$head = calendars_prepare_head($paramnoaction);
458
459print '<form method="POST" id="searchFormList" class="listactionsfilter" action="'.$_SERVER["PHP_SELF"].'" spellcheck="false">'."\n";
460if ($optioncss != '') {
461 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
462}
463print '<input type="hidden" name="token" value="'.newToken().'">';
464print '<input type="hidden" name="mode" value="'.$mode.'">';
465
466
467$mode = 'show_peruser';
468$massactionbutton = '';
469
470
471$viewmode = '<div class="navmode inline-block">';
472
473$viewmode .= '<a class="btnTitle reposition" href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&restore_lastsearch_values=1'.$paramnoactionodate.'">';
474//$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
475$viewmode .= img_picto($langs->trans("List"), 'object_calendarlist', 'class="imgforviewmode pictoactionview block"');
476//$viewmode .= '</span>';
477$viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone inline-block width75 divoverflow">'.$langs->trans("ViewList").'</span></a>';
478
479$viewmode .= '<a class="btnTitle reposition" href="'.DOL_URL_ROOT.'/comm/action/index.php?mode=show_month&year='.dol_print_date($object->datep, '%Y').'&month='.dol_print_date($object->datep, '%m').'&day='.dol_print_date($object->datep, '%d').$paramnoactionodate.'">';
480//$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
481$viewmode .= img_picto($langs->trans("ViewCal"), 'object_calendarmonth', 'class="pictoactionview block"');
482//$viewmode .= '</span>';
483$viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone inline-block width75 divoverflow">'.$langs->trans("ViewCal").'</span></a>';
484
485$viewmode .= '<a class="btnTitle reposition" href="'.DOL_URL_ROOT.'/comm/action/index.php?mode=show_week&year='.dol_print_date($object->datep, '%Y').'&month='.dol_print_date($object->datep, '%m').'&day='.dol_print_date($object->datep, '%d').$paramnoactionodate.'">';
486//$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
487$viewmode .= img_picto($langs->trans("ViewWeek"), 'object_calendarweek', 'class="pictoactionview block"');
488//$viewmode .= '</span>';
489$viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone inline-block width75 divoverflow">'.$langs->trans("ViewWeek").'</span></a>';
490
491$viewmode .= '<a class="btnTitle reposition" href="'.DOL_URL_ROOT.'/comm/action/index.php?mode=show_day&year='.dol_print_date($object->datep, '%Y').'&month='.dol_print_date($object->datep, '%m').'&day='.dol_print_date($object->datep, '%d').$paramnoactionodate.'">';
492//$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
493$viewmode .= img_picto($langs->trans("ViewDay"), 'object_calendarday', 'class="pictoactionview block"');
494//$viewmode .= '</span>';
495$viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone inline-block width75 divoverflow">'.$langs->trans("ViewDay").'</span></a>';
496
497$viewmode .= '<a class="btnTitle btnTitleSelected reposition marginrightonly" href="'.DOL_URL_ROOT.'/comm/action/peruser.php?mode=show_peruser&year='.dol_print_date($object->datep, '%Y').'&month='.dol_print_date($object->datep, '%m').'&day='.dol_print_date($object->datep, '%d').$paramnoactionodate.'">';
498//$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
499$viewmode .= img_picto($langs->trans("ViewPerUser"), 'object_calendarperuser', 'class="pictoactionview block"');
500//$viewmode .= '</span>';
501$viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone inline-block width75 divoverflow" title="'.dolPrintHTML($langs->trans("ViewPerUser")).'">'.$langs->trans("ViewPerUser").'</span></a>';
502
503// Add more views from hooks
504$parameters = array();
505$object = null;
506$reshook = $hookmanager->executeHooks('addCalendarView', $parameters, $object, $action);
507if (empty($reshook)) {
508 $viewmode .= $hookmanager->resPrint;
509} elseif ($reshook > 1) {
510 $viewmode = $hookmanager->resPrint;
511}
512
513$viewmode .= '</div>';
514
515$viewmode .= '<span class="marginrightonly"></span>'; // To add a space before the navigation tools
516
517
518$newparam = '';
519$newcardbutton = '';
520if ($user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create')) {
521 $tmpforcreatebutton = dol_getdate(dol_now('tzuserrel'), true);
522
523 $newparam .= '&month='.urlencode(str_pad((string) $month, 2, "0", STR_PAD_LEFT)).'&year='.((int) $tmpforcreatebutton['year']);
524 if ($begin_h !== '') {
525 $newparam .= '&begin_h='.((int) $begin_h);
526 }
527 if ($end_h !== '') {
528 $newparam .= '&end_h='.((int) $end_h);
529 }
530 if ($begin_d !== '') {
531 $newparam .= '&begin_d='.((int) $begin_d);
532 }
533 if ($end_d !== '') {
534 $newparam .= '&end_d='.((int) $end_d);
535 }
536
537 $urltocreateaction = DOL_URL_ROOT.'/comm/action/card.php?action=create';
538 $urltocreateaction .= '&apyear='.$tmpforcreatebutton['year'].'&apmonth='.$tmpforcreatebutton['mon'].'&apday='.$tmpforcreatebutton['mday'].'&aphour='.$tmpforcreatebutton['hours'].'&apmin='.$tmpforcreatebutton['minutes'];
539 $urltocreateaction .= '&backtopage='.urlencode($_SERVER["PHP_SELF"].'?'.$newparam);
540
541 $newcardbutton .= dolGetButtonTitle($langs->trans("AddAction"), '', 'fa fa-plus-circle', $urltocreateaction);
542}
543
544
545$link = '';
546
547// Define the legend/list of calendard to show
548$s = '';
549
550$showextcals = $listofextcals;
551$bookcalcalendars = array();
552
553// Load Bookcal Calendars
554if (isModEnabled("bookcal")) {
555 $sql = "SELECT ba.rowid, bc.label, bc.ref, bc.rowid as id_cal";
556 $sql .= " FROM ".MAIN_DB_PREFIX."bookcal_availabilities as ba";
557 $sql .= " JOIN ".MAIN_DB_PREFIX."bookcal_calendar as bc";
558 $sql .= " ON bc.rowid = ba.fk_bookcal_calendar";
559 $sql .= " WHERE bc.status = 1";
560 $sql .= " AND ba.status = 1";
561 $sql .= " AND bc.entity IN (".getEntity('agenda').")"; // bookcal is a "virtual view" of agenda
562 if (!empty($filtert) && $filtert != '-1' && $filtert != '-2') {
563 $sql .= " AND bc.visibility IN (".$db->sanitize($filtert, 0, 0, 0, 0).")";
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"][$objp->id_cal] = 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
584 $s .= '<script type="text/javascript">'."\n";
585 $s .= 'jQuery(document).ready(function () {'."\n";
586 $s .= 'jQuery(".check_birthday").click(function() { console.log("Click on .check_birthday so we toggle class .peruser_birthday"); jQuery(".peruser_birthday").addClass("peruser_birthday_imp"); });'."\n";
587
588 $s .= 'jQuery(".check_holiday").click(function() {';
589 $s .= ' console.log("Click on .check_holiday so we toggle class .peruser_holiday");';
590 $s .= ' if (jQuery(".peruser_holiday").hasClass("peruser_holiday_imp")) {';
591 $s .= ' jQuery(".peruser_holiday").removeClass("peruser_holiday_imp");';
592 $s .= ' } else { ';
593 $s .= ' jQuery(".peruser_holiday").addClass("peruser_holiday_imp");';
594 $s .= ' }';
595 // add check_holiday params to navigation links when click on check holiday input
596 $s .= ' var checkHoliday = jQuery(this).is(":checked") ? 1 : 0;';
597 $s .= ' jQuery(".navselectiondate a, .navmode a").each(function(index, elem) { ';
598 $s .= ' var navLinkElem = jQuery(elem);';
599 $s .= ' var navLinkHref = navLinkElem.attr("href");';
600 $s .= ' var navLinkParts = navLinkHref.split("?");';
601 $s .= ' var navLinkPath = navLinkParts[0];';
602 $s .= ' var navLinkParams = new URLSearchParams(navLinkParts[1] || "");';
603 $s .= ' navLinkParams.set("check_holiday", checkHoliday);';
604 $s .= ' navLinkElem.attr("href", navLinkPath + "?" + navLinkParams.toString());';
605 $s .= ' });';
606 $s .= '});'."\n";
607
608 if (isModEnabled("bookcal") && !empty($bookcalcalendars["calendars"])) {
609 foreach ($bookcalcalendars["calendars"] as $key => $value) {
610 $s .= 'jQuery(".check_bookcal_calendar_'.$value['id'].'").click(function() { console.log("Toggle Bookcal Calendar '.$value['id'].'"); jQuery(".family_bookcal_calendar_'.$value['id'].'").toggle(); });'."\n";
611 }
612 }
613 $s .= '});'."\n";
614 $s .= '</script>'."\n";
615
616 // Local calendar
617 $s .= '<div class="nowrap inline-block minheight30 hideonsmartphone"><input type="checkbox" id="check_mytasks" name="check_mytasks" value="1" class="check_mytasks" checked disabled><label class="labelcalendar"><span class="check_local_text small"> '.$langs->trans("LocalAgenda").' &nbsp; </span></label></div>';
618
619 // Holiday calendar
620 if ($user->hasRight("holiday", "read")) {
621 $s .= '
622 <div class="nowrap inline-block minheight30"><input type="checkbox" id="check_holiday" name="check_holiday small" value="1" class="marginleftonly check_holiday"' . ($check_holiday ? ' checked' : '') . '>
623 <label for="check_holiday" class="labelcalendar">
624 <span class="check_holiday_text small">' . $langs->trans("Holidays") . '</span>
625 </label> &nbsp;
626 </div>';
627 }
628
629 // External calendars
630 if (is_array($showextcals) && count($showextcals) > 0) { // @phpstan-ignore-line $showextcals is always an array
631 $s .= '<script type="text/javascript">'."\n";
632 $s .= 'jQuery(document).ready(function () {
633 jQuery("div input[name^=\"check_ext\"]").each(function(index, elem) {
634 var name = jQuery(elem).attr("name");
635 if (jQuery(elem).is(":checked")) {
636 jQuery(".family_ext" + name.replace("check_ext", "")).show();
637 } else {
638 jQuery(".family_ext" + name.replace("check_ext", "")).hide();
639 }
640 });
641
642 jQuery("div input[name^=\"check_ext\"]").click(function() {
643 var name = $(this).attr("name");
644 jQuery(".family_ext" + name.replace("check_ext", "")).toggle();
645 });
646 });' . "\n";
647 $s .= '</script>'."\n";
648
649 foreach ($showextcals as $val) {
650 $htmlname = md5($val['name']); // not used for security purpose, only to get a string with no special char
651
652 if (!empty($val['default']) || GETPOSTINT('check_ext'.$htmlname)) {
653 $default = "checked";
654 } else {
655 $default = '';
656 }
657
658 $cachedelayshown = (!empty($val['cachedelay']) && $val['cachedelay'] > 0 ? (int) $val['cachedelay'] : $DELAYFORCACHE);
659 $tooltip = $langs->trans("Cache").' '.($cachedelayshown < 120 ? $cachedelayshown.'s' : round($cachedelayshown / 60).'mn');
660
661 $s .= '<div class="nowrap inline-block minheight30"><input type="checkbox" id="check_ext'.$htmlname.'" class="marginleftonly check_ext_'.$htmlname.'" name="check_ext'.$htmlname.'" value="1" '.$default.'><label for="check_ext'.$htmlname.'" title="'.dol_escape_htmltag($tooltip).'" class="labelcalendar"><span class="check_ext_text small">'.dol_escape_htmltag($val['name']).'</small></label> &nbsp; </div>';
662 }
663 }
664
665 // Birthdays
666 //$s .= '<div class="nowrap inline-block minheight30"><input type="checkbox" id="check_birthday" name="check_birthday" class="marginleftonly check_birthday" value="1" '. (GETPOSTINT('check_birthday') ? ' checked' : '') .'><label for="check_birthday" class="labelcalendar"> <span class="check_birthday_text">'.$langs->trans("AgendaShowBirthdayEvents").'</span></label> &nbsp; </div>';
667
668 // Bookcal Calendar
669 /*
670 if (isModEnabled("bookcal")) {
671 if (!empty($bookcalcalendars["calendars"])) {
672 foreach ($bookcalcalendars["calendars"] as $key => $value) {
673 $label = $value['label'];
674 $s .= '<div class="nowrap inline-block minheight30">';
675 $s .= '<input '.(GETPOST('check_bookcal_calendar_'.$value['id']) ? "checked" : "").' type="checkbox" id="check_bookcal_calendar_'.$value['id'].'" name="check_bookcal_calendar_'.$value['id'].'" class="check_bookcal_calendar_'.$value['id'].'">';
676 $s .= '<label for="check_bookcal_calendar_'.$value['id'].'" class="labelcalendar">';
677 $s .= '<span class="check_bookcal_calendar_'.$value['id'].'_text">'.$langs->trans("AgendaShowBookcalCalendar", $label).'</span>';
678 $s .= '</label> &nbsp; </div>';
679 }
680 }
681 }
682 */
683
684 // Calendars from hooks
685 $parameters = array();
686 $reshook = $hookmanager->executeHooks('addCalendarChoice', $parameters, $object, $action);
687 if (empty($reshook)) {
688 $s .= $hookmanager->resPrint;
689 } elseif ($reshook > 1) {
690 $s = $hookmanager->resPrint;
691 }
692
693 $s .= "\n".'<!-- End div to calendars selectors -->'."\n";
694} else { // If javascript off
695 $newparam = $param; // newparam is for birthday links
696 $newparam = preg_replace('/showbirthday=[0-1]/i', 'showbirthday='.($showbirthday ? '1' : '0'), $newparam); // Always false @phpstan-ignore-line
697 if (!preg_match('/showbirthday=/i', $newparam)) {
698 $newparam .= '&showbirthday=1';
699 }
700 $link = '<a href="'.$_SERVER['PHP_SELF'].'?'.dol_escape_htmltag($newparam);
701 $link .= '">';
702 if ($showbirthday) { // Always false @phpstan-ignore-line
703 $link .= $langs->trans("AgendaShowBirthdayEvents");
704 } else {
705 $link .= $langs->trans("AgendaHideBirthdayEvents");
706 }
707 $link .= '</a>';
708}
709
710
711// Load events from database into $eventarray
712$eventarray = array();
713$nbevents = 0;
714
715// DEFAULT CALENDAR + AUTOEVENT CALENDAR + CONFERENCEBOOTH CALENDAR
716$sql = "SELECT";
717if ($usergroup > 0) {
718 $sql .= " DISTINCT";
719}
720$sql .= " a.id, a.label,";
721$sql .= " a.datep,";
722$sql .= " a.datep2,";
723$sql .= " a.percent,";
724$sql .= " a.fk_user_author, a.fk_user_action,";
725$sql .= " a.transparency, a.priority, a.fulldayevent, a.location,";
726$sql .= " a.fk_soc, a.fk_contact, a.fk_project, a.fk_bookcal_calendar,";
727$sql .= " a.fk_element, a.elementtype,";
728$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";
729
730// Add fields from hooks
731$parameters = array();
732$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
733$sql .= $hookmanager->resPrint;
734
735$sqlfields = $sql; // $sql fields to remove for count total
736
737$sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm as ca, ".MAIN_DB_PREFIX."actioncomm as a";
738// We must filter on resource table
739if ($resourceid > 0) {
740 $sql .= ", ".MAIN_DB_PREFIX."element_resources as r";
741}
742
743// We must filter on assignment table
744if (($filtert != '-1' && $filtert != '-2') || $usergroup > 0) {
745 // TODO Replace with a AND EXISTS
746 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."actioncomm_resources as ar";
747 $sql .= " ON ar.fk_actioncomm = a.id AND ar.element_type = 'user'";
748 if ($filtert != '' && $filtert != '-1' && $filtert != '-2' && $filtert != '-3') {
749 $sql .= " AND ar.fk_element IN (".$db->sanitize($filtert).")";
750 } elseif ($filtert == '-3') {
751 $sql .= " AND ar.fk_element IN (".$db->sanitize(implode(',', $user->getAllChildIds(1))).")";
752 }
753 if ($usergroup > 0) {
754 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_user = ar.fk_element AND ugu.fk_usergroup = ".((int) $usergroup);
755 }
756}
757
758// Add table from hooks
759$parameters = array();
760$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
761$sql .= $hookmanager->resPrint;
762
763$sql .= " WHERE a.fk_action = ca.id";
764$sql .= " AND a.entity IN (".getEntity('agenda').")"; // bookcal is a "virtual view" of agenda
765
766// Condition on actioncode
767if (!empty($actioncode)) {
768 if (!getDolGlobalString('AGENDA_USE_EVENT_TYPE')) {
769 if ((is_array($actioncode) && in_array('AC_NON_AUTO', $actioncode)) || $actioncode == 'AC_NON_AUTO') {
770 $sql .= " AND ca.type != 'systemauto'";
771 } elseif ((is_array($actioncode) && in_array('AC_ALL_AUTO', $actioncode)) || $actioncode == 'AC_ALL_AUTO') {
772 $sql .= " AND ca.type = 'systemauto'";
773 } else {
774 if ((is_array($actioncode) && in_array('AC_OTH', $actioncode)) || $actioncode == 'AC_OTH') {
775 $sql .= " AND ca.type != 'systemauto'";
776 }
777 if ((is_array($actioncode) && in_array('AC_OTH_AUTO', $actioncode)) || $actioncode == 'AC_OTH_AUTO') {
778 $sql .= " AND ca.type = 'systemauto'";
779 }
780 }
781 } else {
782 if ((is_array($actioncode) && in_array('AC_NON_AUTO', $actioncode)) || $actioncode === 'AC_NON_AUTO') {
783 $sql .= " AND ca.type != 'systemauto'";
784 } elseif ((is_array($actioncode) && in_array('AC_ALL_AUTO', $actioncode)) || $actioncode === 'AC_ALL_AUTO') {
785 $sql .= " AND ca.type = 'systemauto'";
786 } elseif ((is_array($actioncode) && !in_array('-1', $actioncode) && !in_array('-3', $actioncode)) || ($actioncode !== '-1' && $actioncode !== '-3')) {
787 if (is_array($actioncode)) {
788 foreach ($actioncode as $key => $val) {
789 if ($val == '-1' || $val == '-2') {
790 unset($actioncode[$key]);
791 }
792 }
793 if (!empty($actioncode)) {
794 $sql .= " AND ca.code IN (".$db->sanitize("'".implode("','", $actioncode)."'", 1).")";
795 }
796 } else {
797 $sql .= " AND ca.code IN (".$db->sanitize("'".implode("','", explode(',', $actioncode))."'", 1).")";
798 }
799 }
800 }
801}
802if ($resourceid > 0) {
803 $sql .= " AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = ".((int) $resourceid);
804}
805if ($pid) {
806 $sql .= " AND a.fk_project = ".((int) $pid);
807}
808// If the internal user must only see his customers, force searching by him
809$search_sale = 0;
810if (isModEnabled("societe") && !$user->hasRight('societe', 'client', 'voir')) {
811 $search_sale = $user->id;
812}
813// Search on sale representative
814if ($search_sale && $search_sale != '-1') {
815 if ($search_sale == -2) {
816 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = a.fk_soc)";
817 } elseif ($search_sale > 0) {
818 $sql .= " AND (a.fk_soc IS NULL OR EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = a.fk_soc AND sc.fk_user = ".((int) $search_sale)."))";
819 }
820}
821// Search on socid
822if ($socid) {
823 $sql .= " AND a.fk_soc = ".((int) $socid);
824}
825
826if ($mode == 'show_day') {
827 $sql .= " AND (";
828 $sql .= " (a.datep BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel'))."'";
829 $sql .= " AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel'))."')";
830 $sql .= " OR ";
831 $sql .= " (a.datep2 BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel'))."'";
832 $sql .= " AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel'))."')";
833 $sql .= " OR ";
834 $sql .= " (a.datep < '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel'))."'";
835 $sql .= " AND a.datep2 > '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel'))."')";
836 $sql .= ")";
837} else {
838 // To limit array
839 $sql .= " AND (";
840 $sql .= " (a.datep BETWEEN '".$db->idate($firstdaytoshow - (60 * 60 * 24 * 2))."'"; // Start 2 day before $firstdaytoshow
841 $sql .= " AND '".$db->idate($lastdaytoshow + (60 * 60 * 24 * 2))."')"; // End 2 day after $lastdaytoshow
842 $sql .= " OR ";
843 $sql .= " (a.datep2 BETWEEN '".$db->idate($firstdaytoshow - (60 * 60 * 24 * 2))."'";
844 $sql .= " AND '".$db->idate($lastdaytoshow + (60 * 60 * 24 * 2))."')";
845 $sql .= " OR ";
846 $sql .= " (a.datep < '".$db->idate($firstdaytoshow - (60 * 60 * 24 * 2))."'";
847 $sql .= " AND a.datep2 > '".$db->idate($lastdaytoshow + (60 * 60 * 24 * 2))."')";
848 $sql .= ")";
849}
850if ($type) {
851 $sql .= " AND ca.id = ".((int) $type);
852}
853if ($status == '0') {
854 // To do (not started)
855 $sql .= " AND a.percent = 0";
856}
857if ($status === 'na') {
858 // Not applicable
859 $sql .= " AND a.percent = -1";
860}
861if ($status == '50') {
862 // Running already started
863 $sql .= " AND (a.percent > 0 AND a.percent < 100)";
864}
865if ($status == 'done' || $status == '100') {
866 $sql .= " AND (a.percent = 100)";
867}
868if ($status == 'todo') {
869 $sql .= " AND (a.percent >= 0 AND a.percent < 100)";
870}
871// We must filter on assignment table
872if (($filtert > 0 || $filtert == -3) || $usergroup > 0) {
873 // TODO Replace with a AND EXISTS
874 $sql .= " AND (";
875 if ($filtert > 0) {
876 $sql .= "ar.fk_element = ".((int) $filtert);
877 } elseif ($filtert == -3) {
878 $sql .= "ar.fk_element IN (".$db->sanitize(implode(',', $user->getAllChildIds(1))).")";
879 }
880 if ($usergroup > 0) {
881 $sql .= ($filtert > 0 ? " OR " : "")." ugu.fk_usergroup = ".((int) $usergroup);
882 }
883 $sql .= ")";
884}
885
886// Search in categories, -1 is all and -2 is no categories
887if ($search_categ_cus != -1) {
888 if ($search_categ_cus == -2) {
889 $sql .= " AND NOT EXISTS (SELECT ca.fk_actioncomm FROM ".MAIN_DB_PREFIX."categorie_actioncomm as ca WHERE ca.fk_actioncomm = a.id)";
890 } elseif ($search_categ_cus > 0) {
891 $sql .= " AND EXISTS (SELECT ca.fk_actioncomm FROM ".MAIN_DB_PREFIX."categorie_actioncomm as ca WHERE ca.fk_actioncomm = a.id AND ca.fk_categorie IN (".$db->sanitize((string) $search_categ_cus)."))";
892 }
893}
894// Sort on date
895$sql .= $db->order("fk_user_action, datep");
896//print $sql;
897
898dol_syslog("comm/action/peruser.php", LOG_DEBUG);
899$resql = $db->query($sql);
900if ($resql) {
901 $num = $db->num_rows($resql);
902
903 $MAXONSAMEPAGE = getDolGlobalInt('AGENDA_MAX_ON_SAME_PAGE', 5000); // Useless to have more. Protection to avoid memory overload when high number of event (for example after a mass import)
904 $i = 0;
905 while ($i < $num && $i < $MAXONSAMEPAGE) {
906 $obj = $db->fetch_object($resql);
907 //print $obj->fk_user_action.' '.$obj->id."<br>";
908
909 // Discard auto action if option is on
910 if (getDolGlobalString('AGENDA_ALWAYS_HIDE_AUTO') && $obj->type_code == 'AC_OTH_AUTO') {
911 $i++;
912 continue;
913 }
914
915 $datep = $db->jdate($obj->datep);
916 $datep2 = $db->jdate($obj->datep2);
917
918
919 // Create a new object action
920 $event = new ActionComm($db);
921
922 $event->id = $obj->id;
923 $event->ref = (string) $event->id;
924
925 $event->fulldayevent = $obj->fulldayevent;
926
927 // event->datep and event->datef must be GMT date.
928 if ($event->fulldayevent) {
929 $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
930 $event->datep = $db->jdate($obj->datep, $tzforfullday ? 'tzuser' : 'tzserver'); // If saved in $tzforfullday = gmt, we must invert date to be in user tz
931 $event->datef = $db->jdate($obj->datep2, $tzforfullday ? 'tzuser' : 'tzserver');
932 } else {
933 // Example: $obj->datep = '1970-01-01 01:00:00', jdate will return 0 if TZ of PHP server is Europe/Berlin (+1)
934 $event->datep = $db->jdate($obj->datep, 'tzserver');
935 $event->datef = $db->jdate($obj->datep2, 'tzserver');
936 }
937 //$event->datep_formated_gmt = dol_print_date($event->datep, 'dayhour', 'gmt');
938 //var_dump($obj->id.' '.$obj->datep.' '.dol_print_date($obj->datep, 'dayhour', 'gmt'));
939 //var_dump($obj->id.' '.$event->datep.' '.dol_print_date($event->datep, 'dayhour', 'gmt'));
940
941 $event->type_code = $obj->type_code;
942 $event->type_label = $obj->type_label;
943 $event->type_color = $obj->type_color;
944 $event->type = $obj->type_type;
945 $event->type_picto = $obj->type_picto;
946
947 $event->label = $obj->label;
948 $event->percentage = $obj->percent;
949 $event->authorid = $obj->fk_user_author; // user id of creator
950 $event->userownerid = $obj->fk_user_action; // user id of owner
951 $event->fetch_userassigned(); // This load $event->userassigned
952
953 $event->priority = $obj->priority;
954 $event->location = $obj->location;
955 $event->transparency = $obj->transparency;
956 $event->fk_element = $obj->fk_element;
957 $event->elementid = $obj->fk_element;
958 $event->elementtype = $obj->elementtype;
959
960 $event->fk_project = $obj->fk_project;
961
962 $event->socid = $obj->fk_soc;
963 $event->contact_id = $obj->fk_contact;
964 $event->fk_bookcal_calendar = $obj->fk_bookcal_calendar;
965 if (!empty($event->fk_bookcal_calendar)) {
966 $event->type = "bookcal_calendar";
967 }
968
969 // Defined date_start_in_calendar and date_end_in_calendar property
970 // They are date start and end of action but modified to not be outside calendar view.
971 $event->date_start_in_calendar = $event->datep;
972 if ($event->datef != '' && $event->datef >= $event->datep) {
973 $event->date_end_in_calendar = $event->datef;
974 } else {
975 $event->date_end_in_calendar = $event->datep;
976 }
977
978 //print '<br>'.$i.' - eventid='.$event->id.' '.dol_print_date($event->date_start_in_calendar, 'dayhour').' '.dol_print_date($firstdaytoshow, 'dayhour').' - '.dol_print_date($event->date_end_in_calendar, 'dayhour').' '.dol_print_date($lastdaytoshow, 'dayhour').'<br>'."\n";
979
980 // Check values
981 if ($event->date_end_in_calendar < $firstdaytoshow || $event->date_start_in_calendar >= $lastdaytoshow) {
982 // This record is out of visible range
983 unset($event);
984 } else {
985 if ($event->date_start_in_calendar < $firstdaytoshow) {
986 $event->date_start_in_calendar = $firstdaytoshow;
987 }
988 if ($event->date_end_in_calendar >= $lastdaytoshow) {
989 $event->date_end_in_calendar = ($lastdaytoshow - 1);
990 }
991
992 // Add an entry in actionarray for each day
993 $daycursor = $event->date_start_in_calendar;
994 $annee = (int) dol_print_date($daycursor, '%Y', 'tzuserrel');
995 $mois = (int) dol_print_date($daycursor, '%m', 'tzuserrel');
996 $jour = (int) dol_print_date($daycursor, '%d', 'tzuserrel');
997
998 $daycursorend = $event->date_end_in_calendar;
999 $anneeend = (int) dol_print_date($daycursorend, '%Y', 'tzuserrel');
1000 $moisend = (int) dol_print_date($daycursorend, '%m', 'tzuserrel');
1001 $jourend = (int) dol_print_date($daycursorend, '%d', 'tzuserrel');
1002
1003 // Loop on each day covered by action to prepare an index to show on calendar
1004 $loop = true;
1005 $j = 0;
1006 $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt'); // $mois, $jour, $annee has been set for user tz
1007 $daykeyend = dol_mktime(0, 0, 0, $moisend, $jourend, $anneeend, 'gmt'); // $moisend, $jourend, $anneeend has been set for user tz
1008 /*
1009 print 'GMT '.$event->date_start_in_calendar.' '.dol_print_date($event->date_start_in_calendar, 'dayhour', 'gmt').'<br>';
1010 print 'TZSERVER '.$event->date_start_in_calendar.' '.dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzserver').'<br>';
1011 print 'TZUSERREL '.$event->date_start_in_calendar.' '.dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzuserrel').'<br>';
1012 print 'GMT '.$event->date_end_in_calendar.' '.dol_print_date($event->date_end_in_calendar, 'dayhour', 'gmt').'<br>';
1013 print 'TZSERVER '.$event->date_end_in_calendar.' '.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzserver').'<br>';
1014 print 'TZUSER '.$event->date_end_in_calendar.' '.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzuserrel').'<br>';
1015 */
1016 do {
1017 //if ($event->id==408)
1018 //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>';
1019 //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>';
1020
1021 $eventarray[$daykey][] = $event;
1022 $j++;
1023
1024 $daykey += 60 * 60 * 24;
1025 //if ($daykey > $event->date_end_in_calendar) {
1026 if ($daykey > $daykeyend) {
1027 $loop = false;
1028 }
1029 } while ($loop);
1030 //var_dump($eventarray);
1031 //print 'Event '.$i.' id='.$event->id.' (start='.dol_print_date($event->datep).'-end='.dol_print_date($event->datef);
1032 //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>';
1033 }
1034
1035 $parameters['obj'] = $obj;
1036 $reshook = $hookmanager->executeHooks('hookEventElements', $parameters, $event, $action); // Note that $action and $object may have been modified by some hooks
1037 $event = $hookmanager->resPrint;
1038 if ($reshook < 0) {
1039 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1040 }
1041
1042 $i++;
1043 }
1044 $db->free($resql);
1045} else {
1046 dol_print_error($db);
1047}
1048//var_dump($eventarray);
1049
1050
1051// BIRTHDATES CALENDAR
1052// Complete $eventarray with birthdates
1053if ($showbirthday) { // always false @phpstan-ignore-line
1054 agenda_get_birthday_events($db, $langs, $user, $mode, $month, $day, $year, $eventarray, $nbevents, $firstdaytoshow, $lastdaytoshow);
1055}
1056
1057// LEAVE-HOLIDAY CALENDAR
1058if ($user->hasRight("holiday", "read")) {
1059 $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";
1060 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as x, ".MAIN_DB_PREFIX."user as u";
1061 $sql .= " WHERE u.rowid = x.fk_user";
1062 $sql .= " AND u.statut = '1'"; // Show only active users (0 = inactive user, 1 = active user)
1063 $sql .= " AND (x.statut = '2' OR x.statut = '3')"; // Show only public leaves (2 = leave wait for approval, 3 = leave approved)
1064 // Restrict on current month (we get more, but we will filter later)
1065 $sql .= " AND x.date_debut < '".$db->idate(dol_get_last_day($year, $month))."'";
1066 $sql .= " AND x.date_fin >= '".$db->idate(dol_get_first_day($year, $month))."'";
1067 if (!$user->hasRight('holiday', 'readall')) {
1068 $sql .= " AND x.fk_user IN(".$db->sanitize(implode(", ", $user->getAllChildIds(1))).") ";
1069 }
1070
1071 $resql = $db->query($sql);
1072 if ($resql) {
1073 $num = $db->num_rows($resql);
1074 $i = 0;
1075
1076 while ($i < $num) {
1077 $obj = $db->fetch_object($resql);
1078
1079 $event = new ActionComm($db);
1080
1081 // Need the id of the leave object for link to it
1082 $event->id = $obj->rowid;
1083 $event->ref = (string) $event->id;
1084
1085 $event->type_code = 'HOLIDAY';
1086 $event->type_label = '';
1087 $event->type_color = '';
1088 $event->type = 'holiday';
1089 $event->type_picto = 'holiday';
1090
1091 // date_debut and date_fin are dates without time, so they must be read and rendered in GMT to
1092 // stay independent from the server and user timezones (otherwise the calendar day box is shifted).
1093 $event->datep = (int) $db->jdate($obj->date_start, 'gmt') + ((empty($obj->halfday) || $obj->halfday == 1) ? 0 : 12) * 60 * 60;
1094 $event->datef = (int) $db->jdate($obj->date_end, 'gmt') + ((empty($obj->halfday) || $obj->halfday == -1) ? 24 : 12) * 60 * 60 - 1;
1095 $event->date_start_in_calendar = $event->datep;
1096 $event->date_end_in_calendar = $event->datef;
1097
1098 $event->transparency = 1;
1099
1100 $event->userownerid = $obj->uid; // user id of owner
1101 $event->userassigned = array($obj->uid => array('id' => $obj->uid, 'transparency' => 1));
1102
1103 if ($obj->status == 3) {
1104 // Show no symbol for leave with state "leave approved"
1105 $event->percentage = -1;
1106 } elseif ($obj->status == 2) {
1107 // Show TO-DO symbol for leave with state "leave wait for approval"
1108 $event->percentage = 0;
1109 }
1110
1111
1112 $daycursor = $event->date_start_in_calendar;
1113 $annee = (int) dol_print_date($daycursor, '%Y', 'gmt');
1114 $mois = (int) dol_print_date($daycursor, '%m', 'gmt');
1115 $jour = (int) dol_print_date($daycursor, '%d', 'gmt');
1116
1117 $daycursorend = $event->date_end_in_calendar;
1118 $anneeend = (int) dol_print_date($daycursorend, '%Y', 'gmt');
1119 $moisend = (int) dol_print_date($daycursorend, '%m', 'gmt');
1120 $jourend = (int) dol_print_date($daycursorend, '%d', 'gmt');
1121
1122 // daykey must be date that represent day box in calendar so must be a user time
1123 $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
1124 $daykeygmt = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
1125 $ifornbofdays = 0;
1126 do {
1127 $ifornbofdays++;
1128
1129 $firstdayofholiday = ($ifornbofdays == 1);
1130 $lastdayofholiday = ($daykeygmt == dol_get_first_hour($event->date_end_in_calendar, 'gmt'));
1131
1132 //var_dump(dol_print_date($daykeygmt, 'dayhour', 'gmt'));
1133
1134 if ((in_array($obj->halfday, array(1, 2)) == 1 && $lastdayofholiday) || (in_array($obj->halfday, array(-1, 2)) && $firstdayofholiday)) {
1135 // We create a copy of event because we want tochange the label
1136 $newevent = dol_clone($event, 1);
1137 if (in_array($obj->halfday, array(1, 2)) && $lastdayofholiday) {
1138 $newevent->label .= ' ('.$langs->trans("Morning").')';
1139 } elseif (in_array($obj->halfday, array(-1, 2)) && $firstdayofholiday) {
1140 $newevent->label .= ' ('.$langs->trans("Afternoon").')';
1141 }
1142 $eventarray[$daykey][] = $newevent; // We need to use ->gtTypePicto, getXXXon object, so clone must be PHP clone.
1143 } else {
1144 $eventarray[$daykey][] = $event; // We can use the event unchanged
1145 }
1146
1147 $daykey += 60 * 60 * 24;
1148 $daykeygmt += 60 * 60 * 24;
1149 } while ($daykey <= $event->date_end_in_calendar);
1150
1151 $i++;
1152 }
1153 }
1154}
1155
1156// EXTERNAL CALENDAR
1157// Complete $eventarray with external import Ical
1158if (count($listofextcals)) {
1159 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/ical.class.php';
1160
1161 foreach ($listofextcals as $key => $extcal) {
1162 $url = $extcal['src']; // Example: https://www.google.com/calendar/ical/eldy10%40gmail.com/private-cde92aa7d7e0ef6110010a821a2aaeb/basic.ics
1163 $namecal = $extcal['name'];
1164 $offsettz = $extcal['offsettz'];
1165 $colorcal = $extcal['color'];
1166 $buggedfile = $extcal['buggedfile'];
1167
1168 if ($extcal['type'] == 'globalsetup') {
1169 // Calendar defined by the admin: one cache file shared by all users, stored in the temp directory of the module (the name depends on the url)
1170 dol_mkdir($conf->agenda->dir_temp);
1171 $pathforcachefile = dol_sanitizePathName($conf->agenda->dir_temp).'/'.dol_sanitizeFileName('extcal_'.$namecal.'_'.substr(md5($url), 0, 12)).'.cache';
1172 } else {
1173 // Calendar defined by the user: one cache file per user
1174 $pathforcachefile = dol_sanitizePathName($conf->user->dir_temp).'/'.dol_sanitizeFileName('extcal_'.$namecal.'_user'.$user->id).'.cache';
1175 }
1176 //var_dump($pathforcachefile);exit;
1177
1178 $ical = new ICal();
1179 $ical->parse($url, $pathforcachefile, (!empty($extcal['cachedelay']) && $extcal['cachedelay'] > 0 ? (int) $extcal['cachedelay'] : $DELAYFORCACHE));
1180 if ($ical->error) {
1181 // Save error message for extcal
1182 $listofextcals[$key]['error'] = $ical->error;
1183 $s .= '<br><div class="warning">'.dol_escape_htmltag($listofextcals[$key]['name']).': '.$url.'<br>Error message: '.dol_escape_htmltag($ical->error).'</div>';
1184 }
1185
1186 // After this $ical->cal['VEVENT'] contains array of events, $ical->cal['DAYLIGHT'] contains daylight info, $ical->cal['STANDARD'] contains non daylight info, ...
1187 //var_dump($ical->cal); exit;
1188 $icalevents = array();
1189 if (is_array($ical->get_event_list())) {
1190 $icalevents = array_merge($icalevents, $ical->get_event_list()); // Add $ical->cal['VEVENT']
1191 }
1192 if (is_array($ical->get_freebusy_list())) {
1193 $icalevents = array_merge($icalevents, $ical->get_freebusy_list()); // Add $ical->cal['VFREEBUSY']
1194 }
1195 if (getDolGlobalString('AGENDA_EXT_SHOW_TODO')) {
1196 $icalevents = array_merge($icalevents, $ical->getTodoAndJournalAsEvents()); // Add $ical->cal['VTODO'] and $ical->cal['VJOURNAL']
1197 }
1198
1199 if (count($icalevents) > 0) {
1200 // Duplicate all repeatable events into new entries
1201 $moreicalevents = array();
1202 foreach ($icalevents as $icalkey => $icalevent) {
1203 if (!$ical->hasStartDate($icalevent)) {
1204 dol_syslog("Skip external calendar component without a valid DTSTART", LOG_WARNING);
1205 continue;
1206 }
1207
1208 $hasrrule = (isset($icalevent['RRULE']) && is_array($icalevent['RRULE']));
1209 $tzidwall = false; // True if the dates are local dates of a time zone known by PHP: we compute the occurrences with these local dates, then we convert each one to a real time
1210 $tzidname = '';
1211 if ($hasrrule || !empty($icalevent['RDATE'])) { //repeatable event
1212 //if ($event->date_start_in_calendar < $firstdaytoshow) $event->date_start_in_calendar=$firstdaytoshow;
1213 //if ($event->date_end_in_calendar > $lastdaytoshow) $event->date_end_in_calendar=($lastdaytoshow-1);
1214 if (isset($icalevent['DTSTART;VALUE=DATE'])) { //fullday event
1215 $datecurstart = dol_stringtotime($icalevent['DTSTART;VALUE=DATE'], 1);
1216 $datecurend = (empty($icalevent['DTEND;VALUE=DATE']) ? $datecurstart + 86400 : dol_stringtotime($icalevent['DTEND;VALUE=DATE'], 1)) - 1; // We remove one second to get last second of day
1217 } elseif (isset($icalevent['DTSTART']) && !is_array($icalevent['DTSTART'])) { // Date in GMT (like 19970714T173000Z)
1218 $datecurstart = $icalevent['DTSTART'];
1219 $datecurend = empty($icalevent['DTEND']) ? $datecurstart : $icalevent['DTEND'];
1220 } elseif (is_array($icalevent['DTSTART']) && isset($icalevent['DTSTART']['unixtime']) && $icalevent['DTSTART']['unixtime'] !== '') {
1221 $datecurstart = $icalevent['DTSTART']['unixtime']; // can't be empty
1222 $datecurend = empty($icalevent['DTEND']['unixtime']) ? $datecurstart : $icalevent['DTEND']['unixtime'];
1223 $tzidname = (string) ($icalevent['DTSTART']['TZID'] ?? '');
1224 $tzidwall = (empty($buggedfile) && $ical->isTzidKnown($tzidname));
1225 if (!$tzidwall && !empty($ical->cal['DAYLIGHT']['DTSTART']) /* && $datecurstart */) {
1226 //var_dump($ical->cal);
1227 $tmpcurstart = $datecurstart;
1228 $tmpcurend = $datecurend;
1229 $tmpdaylightstart = dol_mktime(0, 0, 0, 1, 1, 1970, 1) + (int) $ical->cal['DAYLIGHT']['DTSTART'];
1230 $tmpdaylightend = dol_mktime(0, 0, 0, 1, 1, 1970, 1) + (int) $ical->cal['STANDARD']['DTSTART'];
1231 //var_dump($tmpcurstart);var_dump($tmpcurend); var_dump($ical->cal['DAYLIGHT']['DTSTART']);var_dump($ical->cal['STANDARD']['DTSTART']);
1232 // Edit datecurstart and datecurend
1233 if ($tmpcurstart >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend) {
1234 $datecurstart -= ((int) $ical->cal['DAYLIGHT']['TZOFFSETTO']) * 36;
1235 } else {
1236 $datecurstart -= ((int) $ical->cal['STANDARD']['TZOFFSETTO']) * 36;
1237 }
1238 if ($tmpcurend >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend) {
1239 $datecurend -= ((int) $ical->cal['DAYLIGHT']['TZOFFSETTO']) * 36;
1240 } else {
1241 $datecurend -= ((int) $ical->cal['STANDARD']['TZOFFSETTO']) * 36;
1242 }
1243 }
1244 // datecurstart and datecurend are now GMT date
1245 //var_dump($datecurstart); var_dump($datecurend); exit;
1246 } else {
1247 // Not a recognized record
1248 dol_syslog("Found a not recognized repeatable record with unknown date start", LOG_ERR);
1249 continue;
1250 }
1251 //print 'xx'.$datecurstart;exit;
1252
1253 // Days excluded from the recurrence (EXDATE). $exdateshift converts a start into the day as written in the file (a TZID date is a local time)
1254 $exdates = (isset($icalevent['EXDATE']) && is_array($icalevent['EXDATE'])) ? $icalevent['EXDATE'] : [];
1255 $exdateshift = (isset($icalevent['DTSTART']) && is_array($icalevent['DTSTART']) && !empty($icalevent['DTSTART']['unixtime'])) ? ((int) $icalevent['DTSTART']['unixtime'] - (int) $datecurstart) : 0;
1256 $firstdatecurstart = $datecurstart;
1257 $occurrenceduration = $datecurend - $datecurstart;
1258
1259 $interval = 1;
1260 $until = 0;
1261 $maxrepeat = 0;
1262
1263 if ($hasrrule) {
1264 // We can expand a rule with FREQ and, as BYxxx parts, only BYDAY, BYMONTHDAY, BYMONTH. For the others (BYSETPOS...), we keep the first occurrence only.
1265 $unsupportedrule = !$ical->isRRuleSupported($icalevent['RRULE']);
1266 if ($unsupportedrule) {
1267 dol_syslog("Found a repeatable record with a rule not managed by dolibarr code (".json_encode($icalevent['RRULE'])."). Only first occurrence is shown.", LOG_WARNING);
1268 unset($icalevents[$icalkey]['RRULE']);
1269 $hasrrule = false;
1270 }
1271 }
1272
1273 if ($hasrrule) {
1274 $interval = (empty($icalevent['RRULE']['INTERVAL']) ? 1 : $icalevent['RRULE']['INTERVAL']);
1275 $until = empty($icalevent['RRULE']['UNTIL']) ? 0 : dol_stringtotime($icalevent['RRULE']['UNTIL'], 1);
1276 $maxrepeat = empty($icalevent['RRULE']['COUNT']) ? 0 : $icalevent['RRULE']['COUNT'];
1277 if ($until && ($until + ($datecurend - $datecurstart)) < $firstdaytoshow) {
1278 $hasrrule = false; // We discard repeatable event that end before start date to show
1279 }
1280 if ($datecurstart >= $lastdaytoshow + ($tzidwall ? 86400 : 0)) {
1281 $hasrrule = false; // We discard repeatable event that start after end date to show
1282 }
1283 }
1284
1285 if ($hasrrule && ($tzidwall || in_array($icalevent['RRULE']['FREQ'] ?? '', ['MINUTELY', 'HOURLY']) || count(array_filter(array_keys($icalevent['RRULE']), function (string $rulekey): bool {
1286 return strpos($rulekey, 'BY') === 0;
1287 })) > 0)) {
1288 // Rule with a BYxxx part, or hourly or by minute: we compute the occurrences from the dates as written in the file
1289 foreach ($ical->expandRRule($icalevent['RRULE'], (int) $datecurstart + $exdateshift, (int) $lastdaytoshow + $exdateshift, ($until ? (int) $until + $exdateshift : 0), (int) $firstdaytoshow + $exdateshift - $occurrenceduration - 86400) as $occurrencewall) {
1290 if ($tzidwall) {
1291 // The occurrence is a local date of the time zone of the event: real time of its start and end (daylight saving time of this date)
1292 $occurrencestart = (int) $ical->tzidToTimestamp($occurrencewall, $tzidname);
1293 $occurrenceend = (int) $ical->tzidToTimestamp($occurrencewall + $occurrenceduration, $tzidname);
1294 } else {
1295 $occurrencestart = $occurrencewall - $exdateshift;
1296 $occurrenceend = $occurrencestart + $occurrenceduration;
1297 }
1298 if ($occurrenceend < $firstdaytoshow || in_array(gmdate('Ymd', $occurrencewall), $exdates)) {
1299 continue;
1300 }
1301 $newevent = $icalevent;
1302 unset($newevent['RRULE']);
1303 if (!empty($icalevent['DTSTART;VALUE=DATE'])) {
1304 $newevent['DTSTART;VALUE=DATE'] = dol_print_date($occurrencestart, '%Y%m%d');
1305 $newevent['DTEND;VALUE=DATE'] = dol_print_date($occurrenceend + 1, '%Y%m%d');
1306 } else {
1307 $newevent['DTSTART'] = $occurrencestart;
1308 $newevent['DTEND'] = $occurrenceend;
1309 }
1310 $moreicalevents[] = $newevent;
1311 }
1312 } elseif ($hasrrule) {
1313 $numofevent = 0;
1314 while (($datecurstart < $lastdaytoshow) && (empty($maxrepeat) || ($numofevent < $maxrepeat)) && (empty($until) || $datecurstart <= $until)) {
1315 if ($datecurend >= $firstdaytoshow && !in_array(gmdate('Ymd', (int) $datecurstart + $exdateshift), $exdates)) { // We add event (if not excluded)
1316 $newevent = $icalevent;
1317 unset($newevent['RRULE']);
1318 if (!empty($icalevent['DTSTART;VALUE=DATE'])) {
1319 $newevent['DTSTART;VALUE=DATE'] = dol_print_date($datecurstart, '%Y%m%d');
1320 $newevent['DTEND;VALUE=DATE'] = dol_print_date($datecurend + 1, '%Y%m%d');
1321 } else {
1322 $newevent['DTSTART'] = $datecurstart;
1323 $newevent['DTEND'] = $datecurend;
1324 }
1325 $moreicalevents[] = $newevent;
1326 }
1327 // Jump on next occurrence
1328 $numofevent++;
1329 $savdatecurstart = $datecurstart;
1330 if ($icalevent['RRULE']['FREQ'] == 'DAILY') {
1331 $datecurstart = dol_time_plus_duree($datecurstart, $interval, 'd');
1332 $datecurend = dol_time_plus_duree($datecurend, $interval, 'd');
1333 }
1334 if ($icalevent['RRULE']['FREQ'] == 'WEEKLY') {
1335 $datecurstart = dol_time_plus_duree($datecurstart, $interval, 'w');
1336 $datecurend = dol_time_plus_duree($datecurend, $interval, 'w');
1337 } elseif ($icalevent['RRULE']['FREQ'] == 'MONTHLY') {
1338 $datecurstart = dol_time_plus_duree($datecurstart, $interval, 'm');
1339 $datecurend = dol_time_plus_duree($datecurend, $interval, 'm');
1340 } elseif ($icalevent['RRULE']['FREQ'] == 'YEARLY') {
1341 $datecurstart = dol_time_plus_duree($datecurstart, $interval, 'y');
1342 $datecurend = dol_time_plus_duree($datecurend, $interval, 'y');
1343 }
1344 // Test to avoid infinite loop ($datecurstart must increase)
1345 if ($savdatecurstart >= $datecurstart) {
1346 dol_syslog("Found a rule freq ".$icalevent['RRULE']['FREQ']." not managed by dolibarr code. Assume 1 week frequency.", LOG_ERR);
1347 $datecurstart += 3600 * 24 * 7;
1348 $datecurend += 3600 * 24 * 7;
1349 }
1350 }
1351 }
1352
1353 // Dates added to the recurrence (RDATE), with the duration of the first occurrence
1354 if (!empty($icalevent['RDATE']) && is_array($icalevent['RDATE'])) {
1355 $rdatewall = 0;
1356 foreach ($icalevent['RDATE'] as $rdate) {
1357 if (!empty($icalevent['DTSTART;VALUE=DATE'])) {
1358 $rdatestart = dol_stringtotime(substr($rdate, 0, 8), 1);
1359 } else {
1360 $rdatewall = $ical->ical_date_to_unix($rdate);
1361 $rdatestart = ($tzidwall ? (int) $ical->tzidToTimestamp($rdatewall, $tzidname) : $rdatewall - $exdateshift);
1362 }
1363 $rdateend = $rdatestart + $occurrenceduration;
1364 if (($tzidwall ? $rdatewall : $rdatestart) == $firstdatecurstart || $rdateend < $firstdaytoshow || $rdatestart >= $lastdaytoshow || in_array(gmdate('Ymd', ($tzidwall ? $rdatewall : $rdatestart + $exdateshift)), $exdates)) {
1365 continue;
1366 }
1367 $newevent = $icalevent;
1368 unset($newevent['RRULE'], $newevent['RDATE']);
1369 if (!empty($icalevent['DTSTART;VALUE=DATE'])) {
1370 $newevent['DTSTART;VALUE=DATE'] = dol_print_date($rdatestart, '%Y%m%d');
1371 $newevent['DTEND;VALUE=DATE'] = dol_print_date($rdateend + 1, '%Y%m%d');
1372 } else {
1373 $newevent['DTSTART'] = $rdatestart;
1374 $newevent['DTEND'] = $rdateend;
1375 }
1376 $moreicalevents[] = $newevent;
1377 }
1378 }
1379 }
1380 }
1381 $icalevents = array_merge($icalevents, $moreicalevents);
1382
1383 // Loop on each entry into cal file to know if entry is qualified and add an ActionComm into $eventarray
1384 foreach ($icalevents as $icalevent) {
1385 //var_dump($icalevent);
1386
1387 //print $icalevent['SUMMARY'].'->';
1388 //var_dump($icalevent);exit;
1389 if (!empty($icalevent['RRULE'])) {
1390 continue; // We found a repeatable event. It was already split into unitary events, so we discard general rule.
1391 }
1392
1393 // Create a new object action
1394 $event = new ActionComm($db);
1395 $addevent = false;
1396 $datestart = null;
1397 $dateend = null;
1398 if (!$ical->hasStartDate($icalevent)) {
1399 continue;
1400 }
1401
1402 if (isset($icalevent['DTSTART;VALUE=DATE'])) { // fullday event
1403 // For full day events, date are also GMT but they won't but converted using tz during output
1404 $datestart = dol_stringtotime($icalevent['DTSTART;VALUE=DATE'], 1);
1405 if (empty($icalevent['DTEND;VALUE=DATE'])) {
1406 $dateend = $datestart + 86400 - 1;
1407 } else {
1408 $dateend = dol_stringtotime($icalevent['DTEND;VALUE=DATE'], 1) - 1; // We remove one second to get last second of day
1409 }
1410 //print 'x'.$datestart.'-'.$dateend;exit;
1411 //print dol_print_date($dateend,'dayhour','gmt');
1412 $event->fulldayevent = 1;
1413 $addevent = true;
1414 } elseif (!is_array($icalevent['DTSTART'])) { // not fullday event (DTSTART is not array. It is a value like '19700101T000000Z' for 00:00 in greenwitch)
1415 $datestart = $icalevent['DTSTART'];
1416 $dateend = empty($icalevent['DTEND']) ? $datestart : $icalevent['DTEND'];
1417
1418 $datestart += +($offsettz * 3600);
1419 $dateend += +($offsettz * 3600);
1420
1421 $addevent = true;
1422 //var_dump($offsettz);
1423 //var_dump(dol_print_date($datestart, 'dayhour', 'gmt'));
1424 } elseif (isset($icalevent['DTSTART']['unixtime'])) { // File contains a local timezone + a TZ (for example when using bluemind)
1425 $datestart = $icalevent['DTSTART']['unixtime'];
1426 $dateend = $icalevent['DTEND']['unixtime'];
1427
1428 // Local date of a time zone known by PHP: we convert it to a real time (daylight saving time of this date)
1429 $tzidconverted = false;
1430 if (empty($buggedfile)) {
1431 $tzidstart = $ical->tzidToTimestamp((int) $datestart, (string) ($icalevent['DTSTART']['TZID'] ?? ''));
1432 if ($tzidstart !== null) {
1433 $tzidend = $ical->tzidToTimestamp((int) $dateend, (string) ($icalevent['DTEND']['TZID'] ?? ($icalevent['DTSTART']['TZID'] ?? '')));
1434 $datestart = $tzidstart;
1435 $dateend = ($tzidend !== null ? $tzidend : $tzidstart + ((int) $dateend - (int) $icalevent['DTSTART']['unixtime']));
1436 $tzidconverted = true;
1437 }
1438 }
1439
1440 $datestart += +($offsettz * 3600);
1441 $dateend += +($offsettz * 3600);
1442
1443 // $buggedfile is set to uselocalandtznodaylight if conf->global->AGENDA_EXT_BUGGEDFILEx = 'uselocalandtznodaylight'
1444 if (!$tzidconverted && $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
1445 // TODO
1446 }
1447 // $buggedfile is set to uselocalandtzdaylight if conf->global->AGENDA_EXT_BUGGEDFILEx = 'uselocalandtzdaylight' (for example with bluemind)
1448 if (!$tzidconverted && $buggedfile === 'uselocalandtzdaylight') { // unixtime is a local date that does take daylight into account, TZID is +2 for example for 'Europe/Paris' in summer
1449 $localtzs = new DateTimeZone((string) preg_replace('/"/', '', $icalevent['DTSTART']['TZID']));
1450 $localtze = new DateTimeZone((string) preg_replace('/"/', '', $icalevent['DTEND']['TZID']));
1451 $localdts = new DateTime(dol_print_date($datestart, 'dayrfc', 'gmt'), $localtzs);
1452 $localdte = new DateTime(dol_print_date($dateend, 'dayrfc', 'gmt'), $localtze);
1453 $tmps = -1 * $localtzs->getOffset($localdts);
1454 $tmpe = -1 * $localtze->getOffset($localdte);
1455 $datestart += $tmps;
1456 $dateend += $tmpe;
1457 //var_dump($datestart);
1458 }
1459 $addevent = true;
1460 }
1461
1462 if ($addevent && $datestart !== null && $dateend !== null) {
1463 $event->id = $icalevent['UID'];
1464 $event->ref = (string) $event->id;
1465 $userstatic = new User($db);
1466 $userId = $userstatic->findUserIdByEmail($namecal);
1467 if (!empty($userId) && $userId > 0) {
1468 $event->userassigned[$userId] = [
1469 'id' => $userId,
1470 'transparency' => 1,
1471 ];
1472 $event->percentage = -1;
1473 }
1474
1475 $event->type_code = "ICALEVENT";
1476 $event->type_label = $namecal;
1477 $event->type_color = $colorcal;
1478 $event->type = 'icalevent';
1479 $event->type_picto = 'rss';
1480
1481 $event->icalname = $namecal;
1482 $event->icalcolor = $colorcal;
1483 $usertime = 0; // We don't modify date because we want to have date into memory datep and datef stored as GMT date. Compensation will be done during output.
1484 $event->datep = (int) ($datestart + $usertime);
1485 $event->datef = (int) ($dateend + $usertime);
1486
1487 // Event of class PRIVATE or CONFIDENTIAL: the details are hidden, only the time is shown (unless AGENDA_EXT_SHOW_PRIVATE is set)
1488 $isprivate = (isset($icalevent['CLASS']) && is_string($icalevent['CLASS']) && in_array(strtoupper(trim($icalevent['CLASS'])), ['PRIVATE', 'CONFIDENTIAL']) && !getDolGlobalString('AGENDA_EXT_SHOW_PRIVATE'));
1489
1490 if ($isprivate) {
1491 $event->label = $langs->trans("Private");
1492 } elseif (isset($icalevent['SUMMARY']) && $icalevent['SUMMARY']) {
1493 $event->label = dol_string_nohtmltag($icalevent['SUMMARY']);
1494 } elseif (isset($icalevent['DESCRIPTION']) && $icalevent['DESCRIPTION']) {
1495 $event->label = dol_nl2br(dol_string_nohtmltag($icalevent['DESCRIPTION']), 1);
1496 } else {
1497 $event->label = $langs->trans("ExtSiteNoLabel");
1498 }
1499
1500 // Priority (see https://www.kanzaki.com/docs/ical/priority.html)
1501 // LOW = 0 to 4
1502 // MEDIUM = 5
1503 // HIGH = 6 to 9
1504 if (!empty($icalevent['PRIORITY'])) {
1505 $event->priority = $icalevent['PRIORITY'];
1506 }
1507
1508 // Transparency (see https://www.kanzaki.com/docs/ical/transp.html)
1509 if (!empty($icalevent['TRANSP'])) {
1510 if ($icalevent['TRANSP'] == "TRANSPARENT") {
1511 $event->transparency = 0; // 0 = available / free
1512 }
1513 if ($icalevent['TRANSP'] == "OPAQUE") {
1514 $event->transparency = 1; // 1 = busy
1515 }
1516
1517 // TODO: MS outlook states
1518 // X-MICROSOFT-CDO-BUSYSTATUS:FREE + TRANSP:TRANSPARENT => Available / Free
1519 // X-MICROSOFT-CDO-BUSYSTATUS:FREE + TRANSP:OPAQUE => Work another place
1520 // X-MICROSOFT-CDO-BUSYSTATUS:TENTATIVE + TRANSP:OPAQUE => With reservations
1521 // X-MICROSOFT-CDO-BUSYSTATUS:BUSY + TRANSP:OPAQUE => Busy
1522 // X-MICROSOFT-CDO-BUSYSTATUS:OOF + TRANSP:OPAQUE => Away from the office / off-site
1523 }
1524
1525 if (!empty($icalevent['LOCATION']) && !$isprivate) {
1526 $event->location = $icalevent['LOCATION'];
1527 }
1528
1529 // More details, shown into the tooltip of the event (not for a private event)
1530 $event->icaldetails = array();
1531 if (!$isprivate) {
1532 foreach (array('DESCRIPTION' => 'description', 'ORGANIZER' => 'organizer', 'URL' => 'url', 'CATEGORIES' => 'categories', 'GEO' => 'geo') as $icalproperty => $detailkey) {
1533 if (!empty($icalevent[$icalproperty]) && is_string($icalevent[$icalproperty])) {
1534 $event->icaldetails[$detailkey] = $icalevent[$icalproperty];
1535 }
1536 }
1537 if (!empty($icalevent['ATTENDEE']) && is_array($icalevent['ATTENDEE'])) {
1538 $event->icaldetails['attendees'] = $icalevent['ATTENDEE'];
1539 }
1540 }
1541
1542 $event->date_start_in_calendar = $event->datep;
1543
1544 if ((int) $event->datef != 0 && $event->datef >= $event->datep) {
1545 $event->date_end_in_calendar = $event->datef;
1546 } else {
1547 $event->date_end_in_calendar = $event->datep;
1548 }
1549
1550 // Add event into $eventarray if date range are ok.
1551 if ($event->date_end_in_calendar < $firstdaytoshow || $event->date_start_in_calendar >= $lastdaytoshow) {
1552 //print 'x'.$datestart.'-'.$dateend;exit;
1553 //print 'x'.$datestart.'-'.$dateend;exit;
1554 //print 'x'.$datestart.'-'.$dateend;exit;
1555 // This record is out of visible range
1556 } else {
1557 if ($event->date_start_in_calendar < $firstdaytoshow) {
1558 $event->date_start_in_calendar = $firstdaytoshow;
1559 }
1560 if ($event->date_end_in_calendar >= $lastdaytoshow) {
1561 $event->date_end_in_calendar = ($lastdaytoshow - 1);
1562 }
1563
1564 // Add an entry in actionarray for each day
1565 $daycursor = $event->date_start_in_calendar;
1566 $annee = (int) dol_print_date($daycursor, '%Y', 'tzuserrel');
1567 $mois = (int) dol_print_date($daycursor, '%m', 'tzuserrel');
1568 $jour = (int) dol_print_date($daycursor, '%d', 'tzuserrel');
1569
1570 // Loop on each day covered by action to prepare an index to show on calendar
1571 $loop = true;
1572 $j = 0;
1573 // daykey must be date that represent day box in calendar so must be a user time
1574 $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
1575 $daykeygmt = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
1576 do {
1577 //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').' ';
1578 $eventarray[$daykey][] = $event;
1579 $daykey += 60 * 60 * 24;
1580 $daykeygmt += 60 * 60 * 24; // Add one day
1581 if (($event->fulldayevent ? $daykeygmt : $daykey) > $event->date_end_in_calendar) {
1582 $loop = false;
1583 }
1584 } while ($loop);
1585 }
1586 }
1587 }
1588 }
1589 }
1590}
1591
1592// Complete $eventarray with events coming from external module
1593$parameters = array();
1594$object = null;
1595$reshook = $hookmanager->executeHooks('getCalendarEvents', $parameters, $object, $action);
1596if (!empty($hookmanager->resArray['eventarray'])) {
1597 foreach ($hookmanager->resArray['eventarray'] as $keyDate => $events) {
1598 if (!isset($eventarray[$keyDate])) {
1599 $eventarray[$keyDate] = array();
1600 }
1601 $eventarray[$keyDate] = array_merge($eventarray[$keyDate], $events);
1602 }
1603}
1604
1605// Sort events
1606/*
1607foreach ($eventarray as $keyDate => &$dateeventarray) {
1608 usort($dateeventarray, 'sort_events_by_date');
1609}
1610*/
1611
1612$maxnbofchar = 18;
1613$cachethirdparties = array();
1614$cachecontacts = array();
1615$cacheusers = array();
1616// default values
1617$theme_datacolor = array(
1618 array(137, 86, 161),
1619 array(60, 147, 183),
1620 array(250, 190, 80),
1621 array(80, 166, 90),
1622 array(190, 190, 100),
1623 array(91, 115, 247),
1624 array(140, 140, 220),
1625 array(190, 120, 120),
1626 array(115, 125, 150),
1627 array(100, 170, 20),
1628 array(150, 135, 125),
1629 array(85, 135, 150),
1630 array(150, 135, 80),
1631 array(150, 80, 150)
1632);
1633// Define theme_datacolor array
1634$color_file = dol_getThemeFilePath('theme_vars.inc.php');
1635if ($color_file && is_readable($color_file)) {
1636 include $color_file;
1637 global $theme_datacolor;
1638}
1639
1640$massactionbutton = '';
1641
1642$num = 0;
1643
1644print_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);
1645
1646$link = '';
1647
1648// Show div with list of calendars
1649print $s;
1650
1651// Top filters
1652print '<div class="liste_titre liste_titre_bydiv centpercent">';
1653print_actions_filter($form, $canedit, $search_status, $year, $month, $day, $showbirthday, '', (string) $filtert, '', $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid, $search_categ_cus);
1654print '</div>';
1655
1656
1657$newparam = $param; // newparam is for birthday links
1658$newparam = preg_replace('/showbirthday=/i', 'showbirthday_=', $newparam); // To avoid replacement when replace day= is done
1659$newparam = preg_replace('/mode=show_month&?/i', '', $newparam);
1660$newparam = preg_replace('/mode=show_week&?/i', '', $newparam);
1661$newparam = preg_replace('/day=[0-9]+&?/i', '', $newparam);
1662$newparam = preg_replace('/month=[0-9]+&?/i', '', $newparam);
1663$newparam = preg_replace('/year=[0-9]+&?/i', '', $newparam);
1664$newparam = preg_replace('/viewweek=[0-9]+&?/i', '', $newparam);
1665$newparam = preg_replace('/showbirthday_=/i', 'showbirthday=', $newparam); // Restore correct parameter
1666$newparam .= '&viewweek=1';
1667
1668echo '<input type="hidden" name="actionmove" value="mupdate">';
1669echo '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($_SERVER['PHP_SELF']).'?'.dol_escape_htmltag($_SERVER['QUERY_STRING']).'">';
1670echo '<input type="hidden" name="newdate" id="newdate">';
1671
1672
1673// Line header with list of days
1674
1675//print "begin_d=".$begin_d." end_d=".$end_d;
1676
1677$currentdaytoshow = $firstdaytoshow;
1678echo '<div class="div-table-responsive">';
1679//print dol_print_date($currentdaytoshow, 'dayhour', 'gmt');
1680
1681$colorsbytype = array();
1682
1683while ($currentdaytoshow < $lastdaytoshow) {
1684 echo '<table class="centpercent noborder nocellnopadd cal_month cal_peruser listwithfilterbefore">';
1685
1686 echo '<tr class="liste_titre">';
1687 echo '<td class="nopaddingtopimp nopaddingbottomimp nowraponsmartphone">';
1688
1689 if ($canedit /* && $mode == 'show_peruser' */) { // mode is forced to show_peruser
1690 // Filter on days
1691 print '<span class="hideonsmartphone" title="'.$langs->trans("VisibleDaysRange").'">';
1692 print img_picto('', 'clock', 'class="fawidth30 inline-block marginleftonly"');
1693 print $langs->trans("DaysOfWeek").'</span>';
1694 print "\n";
1695 print '<div class="ui-grid-a inline-block"><div class="ui-block-a nowraponall">';
1696 print '<input type="number" class="shortbis" name="begin_d" value="'.$begin_d.'" min="1" max="7">';
1697 if (empty($conf->dol_use_jmobile)) {
1698 print ' - ';
1699 } else {
1700 print '</div><div class="ui-block-b">';
1701 }
1702 print '<input type="number" class="shortbis" name="end_d" value="'.$end_d.'" min="1" max="7">';
1703 print '</div></div>';
1704 }
1705
1706 print '</td>';
1707 $i = 0; // 0 = sunday,
1708 while ($i < 7) {
1709 if (($i + 1) < $begin_d || ($i + 1) > $end_d) {
1710 $i++;
1711 continue;
1712 }
1713 echo '<td align="center" colspan="'.($end_h - $begin_h).'">';
1714 echo '<span class="bold spandayofweek">'.$langs->trans("Day".(($i + getDolGlobalInt('MAIN_START_WEEK', 1)) % 7)).'</span>';
1715 print "<br>";
1716 if ($i) {
1717 $valtoshow = dol_time_plus_duree($currentdaytoshow, $i, 'd');
1718 } else {
1719 $valtoshow = $currentdaytoshow;
1720 }
1721 if (dol_print_date($valtoshow, '%Y%m%d') == dol_print_date(dol_now(), '%Y%m%d')) {
1722 echo '<span class="badgeliketopmenu">';
1723 }
1724 print dol_print_date($valtoshow, 'dayreduceformat', 'tzuserrel');
1725 if (dol_print_date($valtoshow, '%Y%m%d') == dol_print_date(dol_now(), '%Y%m%d')) {
1726 echo '</span>';
1727 }
1728 echo "</td>\n";
1729 $i++;
1730 }
1731 echo "</tr>\n";
1732
1733 echo '<tr class="liste_titre">';
1734 echo '<td>';
1735
1736 // Filter on hours
1737 print '<span class="hideonsmartphone" title="'.$langs->trans("VisibleTimeRange").'">';
1738 print img_picto('', 'clock', 'class="fawidth30 inline-block marginleftonly"');
1739 print $langs->trans("Hours").'</span>';
1740 print "\n";
1741 print '<div class="ui-grid-a inline-block"><div class="ui-block-a nowraponall">';
1742 print '<input type="number" class="shortbis" name="begin_h" value="'.$begin_h.'" min="0" max="23">';
1743 if (empty($conf->dol_use_jmobile)) {
1744 print ' - ';
1745 } else {
1746 print '</div><div class="ui-block-b">';
1747 }
1748 print '<input type="number" class="shortbis" name="end_h" value="'.$end_h.'" min="1" max="24">';
1749 if (empty($conf->dol_use_jmobile)) {
1750 print ' '.$langs->trans("HourShort");
1751 }
1752 print '</div></div>';
1753
1754 echo '</td>';
1755 $i = 0;
1756 while ($i < 7) {
1757 if (($i + 1) < $begin_d || ($i + 1) > $end_d) {
1758 $i++;
1759 continue;
1760 }
1761 for ($h = $begin_h; $h < $end_h; $h++) {
1762 echo '<td class="center">';
1763 print '<small style="font-family: courier">'.sprintf("%02d", $h).'</small>';
1764 print "</td>";
1765 }
1766 echo "</td>\n";
1767 $i++;
1768 }
1769 echo "</tr>\n";
1770
1771
1772 // Define $usernames
1773 $usernames = array(); //init
1774 $usernamesid = array();
1775 /* Use this to have list of users only if users have events */
1776 if (getDolGlobalString('AGENDA_SHOWOWNERONLY_ONPERUSERVIEW')) {
1777 foreach ($eventarray as $daykey => $notused) {
1778 // Get all assigned users for each event
1779 foreach ($eventarray[$daykey] as $index => $event) {
1780 $event->fetch_userassigned();
1781 $listofuserid = $event->userassigned;
1782 foreach ($listofuserid as $userid => $tmp) {
1783 if (!in_array($userid, $usernamesid)) {
1784 $usernamesid[$userid] = $userid;
1785 }
1786 }
1787 }
1788 }
1789 } else {
1790 /* Use this list to have lines of all users to show */
1791 $sql = "SELECT u.rowid, u.lastname as lastname, u.firstname, u.statut, u.login, u.admin, u.entity";
1792 $sql .= " FROM ".$db->prefix()."user as u";
1793 if (isModEnabled('multicompany') && getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE')) {
1794 $sql .= " WHERE u.rowid IN (";
1795 $sql .= " SELECT ug.fk_user FROM ".$db->prefix()."usergroup_user as ug";
1796 $sql .= " WHERE ug.entity IN (".getEntity('usergroup').")";
1797 if ($usergroup > 0) {
1798 $sql .= " AND ug.fk_usergroup = ".((int) $usergroup);
1799 }
1800 $sql .= ")";
1801 } else {
1802 if ($usergroup > 0) {
1803 $sql .= " LEFT JOIN ".$db->prefix()."usergroup_user as ug ON u.rowid = ug.fk_user";
1804 }
1805 $sql .= " WHERE u.entity IN (".getEntity('user').")";
1806 if ($usergroup > 0) {
1807 $sql .= " AND ug.fk_usergroup = ".((int) $usergroup);
1808 }
1809 }
1810 $sql .= " AND u.statut = 1";
1811 if ($filtert > 0) {
1812 $sql .= " AND u.rowid = ".((int) $filtert);
1813 }
1814 if ($usergroup > 0) {
1815 $sql .= " AND ug.fk_usergroup = ".((int) $usergroup);
1816 }
1817 if ($user->socid > 0) {
1818 // External users should see only contacts of their company
1819 $sql .= " AND u.fk_soc = ".((int) $user->socid);
1820 }
1821 // Filter on users in hierarchy
1822 if (!$canedit || $filtert == '-3') { // If we can't read event of others
1823 if (!$user->hasRight('user', 'user', 'lire') || $filtert == '-3') {
1824 $usersInHierarchy = $user->getAllChildIds(1);
1825 $sql .= " AND u.rowid IN (".$db->sanitize(implode(',', $usersInHierarchy)).")";
1826 }
1827 }
1828
1829 //print $sql;
1830 $resql = $db->query($sql);
1831 if ($resql) {
1832 $num = $db->num_rows($resql);
1833 $i = 0;
1834 if ($num) {
1835 while ($i < $num) {
1836 $obj = $db->fetch_object($resql);
1837 $usernamesid[$obj->rowid] = $obj->rowid;
1838 $i++;
1839 }
1840 }
1841 } else {
1842 dol_print_error($db);
1843 }
1844 }
1845 //var_dump($usernamesid);
1846 foreach ($usernamesid as $id) {
1847 $tmpuser = new User($db);
1848 $result = $tmpuser->fetch($id);
1849 $usernames[] = $tmpuser;
1850 }
1851
1852 // Load array of colors by type
1853 $labelbytype = array();
1854 $sql = "SELECT code, color, libelle as label FROM ".MAIN_DB_PREFIX."c_actioncomm ORDER BY position";
1855 $resql = $db->query($sql);
1856 while ($obj = $db->fetch_object($resql)) {
1857 $colorsbytype[$obj->code] = $obj->color;
1858 $labelbytype[$obj->code] = $obj->label;
1859 }
1860
1861 // Loop on each user to show calendar
1862 $todayarray = dol_getdate($now, true);
1863 $sav = $tmpday;
1864 $showheader = true;
1865 $var = false;
1866 foreach ($usernames as $username) {
1867 //if ($username->login != 'admin') continue;
1868
1869 $var = !$var;
1870
1871 echo "<tr>";
1872 echo '<td class="tdoverflowmax100 cal_current_month cal_peruserviewname'.($var ? ' cal_impair' : '').' nopaddingtopimp nopaddingbottomimp noheightimp">';
1873 print '<span class="paddingrightimp">';
1874 print $username->getNomUrl(-1, '', 0, 0, 20, 1, '', 'paddingleft');
1875 print '</span>';
1876 print '</td>';
1877 $tmpday = $sav;
1878
1879 // Lopp on each day of week
1880 $i = 0;
1881 for ($iter_day = 0; $iter_day < 8; $iter_day++) {
1882 if (($i + 1) < $begin_d || ($i + 1) > $end_d) {
1883 $i++;
1884 continue;
1885 }
1886
1887 // Show days of the current week
1888 $curtime = dol_time_plus_duree($currentdaytoshow, $iter_day, 'd');
1889 // $curtime is a gmt time, but we want the day, month, year in user TZ
1890 $tmpday = (int) dol_print_date($curtime, "%d", "tzuserrel");
1891 $tmpmonth = (int) dol_print_date($curtime, "%m", "tzuserrel");
1892 $tmpyear = (int) dol_print_date($curtime, "%Y", "tzuserrel");
1893 //var_dump($curtime.' '.$tmpday.' '.$tmpmonth.' '.$tmpyear);
1894
1895 $style = 'cal_current_month';
1896 if ($iter_day == 6) {
1897 $style .= ' cal_other_month';
1898 }
1899 $today = 0;
1900 if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $tmpmonth && $todayarray['year'] == $tmpyear) {
1901 $today = 1;
1902 }
1903 if ($today) {
1904 $style = 'cal_today_peruser';
1905 }
1906
1907 show_day_events2($username, $tmpday, $tmpmonth, $tmpyear, 0, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, $showheader, $colorsbytype, $var);
1908
1909 $i++;
1910 }
1911 echo "</tr>\n";
1912 $showheader = false;
1913 }
1914
1915 echo "</table>\n";
1916 echo "<br>";
1917
1918 $currentdaytoshow = dol_time_plus_duree($currentdaytoshow, 7, 'd');
1919}
1920
1921echo '</div>';
1922
1923if (getDolGlobalString('AGENDA_USE_EVENT_TYPE') && getDolGlobalString('AGENDA_USE_COLOR_PER_EVENT_TYPE')) {
1924 $langs->load("commercial");
1925 print '<br>'.$langs->trans("Legend").': <br>';
1926 foreach ($colorsbytype as $code => $color) {
1927 if ($color) {
1928 print '<div style="float: left; padding: 2px; margin-right: 6px;"><div style="background: #'.$color.'; width:16px; float: left; margin-right: 4px;">&nbsp;</div>';
1929 print $langs->trans("Action".$code) != "Action".$code ? $langs->trans("Action".$code) : $labelbytype[$code];
1930 //print $code;
1931 print '</div>';
1932 }
1933 }
1934 //$color=sprintf("%02x%02x%02x",$theme_datacolor[0][0],$theme_datacolor[0][1],$theme_datacolor[0][2]);
1935 print '<div style="float: left; padding: 2px; margin-right: 6px;"><div class="peruser_busy" style="width:16px; float: left; margin-right: 4px;">&nbsp;</div>';
1936 print $langs->trans("Other");
1937 print '</div>';
1938 /* TODO Show this if at least one cumulated event
1939 print '<div style="float: left; padding: 2px; margin-right: 6px;"><div style="background: #222222; width:16px; float: left; margin-right: 4px;">&nbsp;</div>';
1940 print $langs->trans("SeveralEvents");
1941 print '</div>';
1942 */
1943}
1944
1945print "\n".'</form>';
1946
1947print "\n";
1948
1949// Add js code to manage click on a box
1950print '<script type="text/javascript">
1951jQuery(document).ready(function() {
1952 jQuery(".onclickopenref").click(function() {
1953 var ref=$(this).attr(\'ref\');
1954 var res = ref.split("_");
1955 var type = res[0];
1956 var userid = res[1];
1957 var year = res[2];
1958 var month = res[3];
1959 var day = res[4];
1960 var hour = res[5];
1961 var min = res[6];
1962 var ids = res[7];
1963
1964 console.log("We click on a class onclickopenref in page peruser with ref="+ref+" type="+type);
1965
1966 if (ids == \'none\') /* No event */
1967 {
1968 /* alert(\'no event\'); */
1969 url = "'.DOL_URL_ROOT.'/comm/action/card.php?action=create&assignedtouser="+userid+"&datep="+year+month+day+hour+min+"00&backtopage='.urlencode($_SERVER["PHP_SELF"].'?year='.$year.'&month='.$month.'&day='.$day.($begin_h !== '' ? '&begin_h='.$begin_h : '').($end_h !== '' ? '&end_h='.$end_h : '').($begin_d !== '' ? '&begin_d='.$begin_d : '').($end_d !== '' ? '&end_d='.$end_d : '')).'"
1970 window.location.href = url;
1971 }
1972 else if (ids.indexOf(",") > -1) /* There is several events */
1973 {
1974 /* alert(\'several events\'); */
1975 url = "'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&search_actioncode="+jQuery("#search_actioncode").val()+"&search_status="+jQuery("#selectsearch_status").val()+"&filtert="+userid+"&dateselectyear="+year+"&dateselectmonth="+month+"&dateselectday="+day;
1976 window.location.href = url;
1977 } else { /* One event */
1978 /* alert(\'one event\'); */
1979 if (type == \'holiday\') {
1980 url = "'.DOL_URL_ROOT.'/holiday/card.php?id="+ids
1981 } else {
1982 url = "'.DOL_URL_ROOT.'/comm/action/card.php?action=view&id="+ids
1983 }
1984 window.location.href = url;
1985 }
1986 });
1987});
1988</script>';
1989
1990// End of page
1991llxFooter();
1992$db->close();
1993
1994
1995
1996
2017function show_day_events2($username, $day, $month, $year, $monthshown, $style, &$eventarray, $maxprint = 0, $maxnbofchar = 16, $newparam = '', $showinfo = 0, $minheight = 60, $showheader = false, $colorsbytype = array(), $var = false)
2018{
2019 global $db;
2020 global $user, $conf, $langs, $hookmanager, $action;
2021 global $filter, $filtert, $status, $actioncode; // Filters used into search form
2022 global $theme_datacolor; // Array with a list of different we can use (come from theme)
2023 global $cachethirdparties, $cachecontacts, $cacheusers, $cacheprojects, $colorindexused;
2024 global $begin_h, $end_h;
2025
2026 $cases1 = array(); // Color first half hour
2027 $cases2 = array(); // Color second half hour
2028 $cases3 = array(); // Color third half hour
2029 $cases4 = array(); // Color 4th half hour
2030
2037 '
2038 @phan-var-force array<int,array<int,array<string,string|int|bool>>> $cases1
2039 @phan-var-force array<int,array<int,array<string,string|int|bool>>> $cases2
2040 @phan-var-force array<int,array<int,array<string,string|int|bool>>> $cases3
2041 @phan-var-force array<int,array<int,array<string,string|int|bool>>> $cases4
2042 ';
2043
2044 $i = 0;
2045 $numother = 0;
2046 $numbirthday = 0;
2047 $numical = 0;
2048 $numicals = array();
2049 //$ymd = sprintf("%04d", $year).sprintf("%02d", $month).sprintf("%02d", $day);
2050
2051 $colorindexused[$user->id] = 0; // Color index for current user (user->id) is always 0
2052 $nextindextouse = count($colorindexused); // At first run this is 0, so first user has 0, next 1, ...
2053 //if ($username->id && $day==1) {
2054 //var_dump($eventarray);
2055 //}
2056 //var_dump("------ username=".$username->login." for day=".$day);
2057
2058 // We are in a particular day for $username, now we scan all events
2059 foreach ($eventarray as $daykey => $notused) {
2060 $annee = (int) dol_print_date($daykey, '%Y', 'tzuserrel');
2061 $mois = (int) dol_print_date($daykey, '%m', 'tzuserrel');
2062 $jour = (int) dol_print_date($daykey, '%d', 'tzuserrel');
2063 //var_dump("daykey=$daykey day=$day jour=$jour, month=$month mois=$mois, year=$year annee=$annee ".dol_print_date($daykey, 'dayhour', 'gmt'));
2064 //var_dump($notused);
2065
2066 if ($day == $jour && (int) $month == $mois && $year == $annee) { // Is it the day we are looking for when calling function ?
2067 //var_dump("day=$day jour=$jour month=$month mois=$mois year=$year annee=$annee");
2068
2069 // Scan all events for this date
2070 foreach ($eventarray[$daykey] as $index => $event) {
2071 //print 'daykey='.$daykey.'='.dol_print_date($daykey, 'dayhour', 'gmt').' '.$year.'-'.$month.'-'.$day.' -> The event id '.$event->id.' index '.$index.' is open for this daykey '.$annee.'-'.$mois.'-'.$jour."<br>\n";
2072 //var_dump($event);
2073
2074 $keysofuserassigned = array_keys($event->userassigned);
2075
2076 if (!in_array($username->id, $keysofuserassigned)) {
2077 continue; // We discard record if event is from another user than user we want to show
2078 }
2079 //if ($username->id != $event->userownerid) continue; // We discard record if event is from another user than user we want to show
2080
2081 $parameters = array();
2082 $reshook = $hookmanager->executeHooks('formatEvent', $parameters, $event, $action); // Note that $action and $object may have been modified by some hooks
2083 if ($reshook < 0) {
2084 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2085 }
2086
2087 // Define $color (Hex string like '0088FF') and $cssclass of event
2088 $color = -1;
2089 $cssclass = '';
2090 $colorindex = -1;
2091
2092 if ($event->type_code == 'HOLIDAY') {
2093 $cssclass = 'family_holiday';
2094 }
2095
2096 if (in_array($user->id, $keysofuserassigned)) {
2097 $cssclass = 'family_mytasks';
2098
2099 if (empty($cacheusers[$event->userownerid])) {
2100 $newuser = new User($db);
2101 $newuser->fetch($event->userownerid);
2102 $cacheusers[$event->userownerid] = $newuser;
2103 }
2104 //var_dump($cacheusers[$event->userownerid]->color);
2105
2106 // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
2107 if (!empty($cacheusers[$event->userownerid]->color)) {
2108 $color = $cacheusers[$event->userownerid]->color;
2109 }
2110
2111 if (getDolGlobalString('AGENDA_USE_COLOR_PER_EVENT_TYPE')) {
2112 $color = $event->type_color;
2113 }
2114 } elseif ($event->type_code == 'ICALEVENT') {
2115 $numical++;
2116 if (!empty($event->icalname)) {
2117 if (!isset($numicals[dol_string_nospecial($event->icalname)])) {
2118 $numicals[dol_string_nospecial($event->icalname)] = 0;
2119 }
2120 $numicals[dol_string_nospecial($event->icalname)]++;
2121 }
2122
2123 $color = $event->icalcolor;
2124 $cssclass = (!empty($event->icalname) ? 'family_ext'.md5($event->icalname) : 'family_other unsortable');
2125 } elseif ($event->type_code == 'BIRTHDAY') {
2126 $numbirthday++;
2127 $colorindex = 2;
2128 $cssclass = 'family_birthday unsortable';
2129 $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
2130 } else {
2131 $numother++;
2132 $color = ($event->icalcolor ? $event->icalcolor : -1);
2133 $cssclass = (!empty($event->icalname) ? 'family_ext'.md5($event->icalname) : 'family_other');
2134
2135 if (empty($cacheusers[$event->userownerid])) {
2136 $newuser = new User($db);
2137 $newuser->fetch($event->userownerid);
2138 $cacheusers[$event->userownerid] = $newuser;
2139 }
2140 //var_dump($cacheusers[$event->userownerid]->color);
2141
2142 // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
2143 if (!empty($cacheusers[$event->userownerid]->color)) {
2144 $color = $cacheusers[$event->userownerid]->color;
2145 }
2146
2147 if (getDolGlobalString('AGENDA_USE_COLOR_PER_EVENT_TYPE')) {
2148 $color = $event->type_color;
2149 }
2150 }
2151
2152 if ($color < 0) { // Color was not set on user card. Set color according to color index.
2153 // Define color index if not yet defined
2154 $idusertouse = ($event->userownerid ? $event->userownerid : 0);
2155 if (isset($colorindexused[$idusertouse])) {
2156 $colorindex = $colorindexused[$idusertouse]; // Color already assigned to this user
2157 } else {
2158 $colorindex = $nextindextouse;
2159 $colorindexused[$idusertouse] = $colorindex;
2160 if (!empty($theme_datacolor[$nextindextouse + 1])) {
2161 $nextindextouse++; // Prepare to use next color
2162 }
2163 }
2164 // Define color
2165 $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
2166 }
2167
2168 // Define all rects with event (cases1 is first quarter hour, cases2 is second quarter hour, cases3 is second thirds hour, cases4 is 4th quarter hour)
2169 for ($h = $begin_h; $h < $end_h; $h++) {
2170 //if ($username->id == 1 && $day==1) print 'h='.$h;
2171 $newcolor = ''; //init
2172 if (empty($event->fulldayevent)) {
2173 $a = dol_mktime((int) $h, 0, 0, $month, $day, $year, 'tzuserrel', 0);
2174 $b = dol_mktime((int) $h, 15, 0, $month, $day, $year, 'tzuserrel', 0);
2175 $b1 = dol_mktime((int) $h, 30, 0, $month, $day, $year, 'tzuserrel', 0);
2176 $b2 = dol_mktime((int) $h, 45, 0, $month, $day, $year, 'tzuserrel', 0);
2177 $c = dol_mktime((int) $h + 1, 0, 0, $month, $day, $year, 'tzuserrel', 0);
2178
2179 $dateendtouse = $event->date_end_in_calendar;
2180 if ($dateendtouse == $event->date_start_in_calendar) {
2181 $dateendtouse++;
2182 }
2183
2184 //print dol_print_date($event->date_start_in_calendar,'dayhour').'-'.dol_print_date($a,'dayhour').'-'.dol_print_date($b,'dayhour').'<br>';
2185 if ($event->date_start_in_calendar < $b && $dateendtouse > $a) {
2186 $busy = $event->transparency;
2187 $cases1[$h][$event->id]['busy'] = $busy;
2188 $cases1[$h][$event->id]['string'] = dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzuserrel');
2189 if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) {
2190 $tmpa = dol_getdate($event->date_start_in_calendar, true);
2191 $tmpb = dol_getdate($event->date_end_in_calendar, true);
2192 if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
2193 $cases1[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel');
2194 } else {
2195 $cases1[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzuserrel');
2196 }
2197 }
2198 if ($event->label) {
2199 $cases1[$h][$event->id]['string'] .= ' - '.$event->label;
2200 }
2201 $cases1[$h][$event->id]['typecode'] = $event->type_code;
2202 if ($event->type_code == 'HOLIDAY') {
2203 $cases1[$h][$event->id]['css'] = 'peruser_holiday ';
2204 if (GETPOSTINT('check_holiday')) {
2205 $cases1[$h][$event->id]['css'] .= 'peruser_holiday_imp ';
2206 }
2207 } else {
2208 $cases1[$h][$event->id]['color'] = $color;
2209
2210 if ($event->fk_project > 0) {
2211 if (empty($cacheprojects[$event->fk_project])) {
2212 $tmpproj = new Project($db);
2213 $tmpproj->fetch($event->fk_project);
2214 $cacheprojects[$event->fk_project] = $tmpproj;
2215 }
2216 $cases1[$h][$event->id]['string'] .= ', '.$langs->trans("Project").': '.$cacheprojects[$event->fk_project]->ref.' - '.$cacheprojects[$event->fk_project]->title;
2217 }
2218 if ($event->socid > 0) {
2219 if (empty($cachethirdparties[$event->socid])) {
2220 $tmpthirdparty = new Societe($db);
2221 $tmpthirdparty->fetch($event->socid);
2222 $cachethirdparties[$event->socid] = $tmpthirdparty;
2223 }
2224 $cases1[$h][$event->id]['string'] .= ', '.$cachethirdparties[$event->socid]->name;
2225 }
2226 if ($event->contact_id > 0) {
2227 if (empty($cachecontacts[$event->contact_id])) {
2228 $tmpcontact = new Contact($db);
2229 $tmpcontact->fetch($event->contact_id);
2230 $cachecontacts[$event->contact_id] = $tmpcontact;
2231 }
2232 $cases1[$h][$event->id]['string'] .= ', '.$cachecontacts[$event->contact_id]->getFullName($langs);
2233 }
2234 }
2235 }
2236 if ($event->date_start_in_calendar < $b1 && $dateendtouse > $b) {
2237 $busy = $event->transparency;
2238 $cases2[$h][$event->id]['busy'] = $busy;
2239 $cases2[$h][$event->id]['string'] = dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzuserrel');
2240 if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) {
2241 $tmpa = dol_getdate($event->date_start_in_calendar, true);
2242 $tmpb = dol_getdate($event->date_end_in_calendar, true);
2243 if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
2244 $cases2[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel');
2245 } else {
2246 $cases2[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzuserrel');
2247 }
2248 }
2249 if ($event->label) {
2250 $cases2[$h][$event->id]['string'] .= ' - '.$event->label;
2251 }
2252 $cases2[$h][$event->id]['typecode'] = $event->type_code;
2253 if ($event->type_code == 'HOLIDAY') {
2254 $cases2[$h][$event->id]['css'] = 'peruser_holiday ';
2255 if (GETPOSTINT('check_holiday')) {
2256 $cases2[$h][$event->id]['css'] .= 'peruser_holiday_imp ';
2257 }
2258 } else {
2259 $cases2[$h][$event->id]['color'] = $color;
2260
2261 if ($event->fk_project > 0) {
2262 if (empty($cacheprojects[$event->fk_project])) {
2263 $tmpproj = new Project($db);
2264 $tmpproj->fetch($event->fk_project);
2265 $cacheprojects[$event->fk_project] = $tmpproj;
2266 }
2267 $cases2[$h][$event->id]['string'] .= ', '.$langs->trans("Project").': '.$cacheprojects[$event->fk_project]->ref.' - '.$cacheprojects[$event->fk_project]->title;
2268 }
2269 if ($event->socid > 0) {
2270 if (empty($cachethirdparties[$event->socid])) {
2271 $tmpthirdparty = new Societe($db);
2272 $tmpthirdparty->fetch($event->socid);
2273 $cachethirdparties[$event->socid] = $tmpthirdparty;
2274 }
2275 $cases2[$h][$event->id]['string'] .= ', '.$cachethirdparties[$event->socid]->name;
2276 }
2277 if ($event->contact_id > 0) {
2278 if (empty($cachecontacts[$event->contact_id])) {
2279 $tmpcontact = new Contact($db);
2280 $tmpcontact->fetch($event->contact_id);
2281 $cachecontacts[$event->contact_id] = $tmpcontact;
2282 }
2283 $cases2[$h][$event->id]['string'] .= ', '.$cachecontacts[$event->contact_id]->getFullName($langs);
2284 }
2285 }
2286 }
2287 if ($event->date_start_in_calendar < $b2 && $dateendtouse > $b1) {
2288 $busy = $event->transparency;
2289 $cases3[$h][$event->id]['busy'] = $busy;
2290 $cases3[$h][$event->id]['string'] = dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzuserrel');
2291 if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) {
2292 $tmpa = dol_getdate($event->date_start_in_calendar, true);
2293 $tmpb = dol_getdate($event->date_end_in_calendar, true);
2294 if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
2295 $cases3[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel');
2296 } else {
2297 $cases3[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzuserrel');
2298 }
2299 }
2300 if ($event->label) {
2301 $cases3[$h][$event->id]['string'] .= ' - '.$event->label;
2302 }
2303 $cases3[$h][$event->id]['typecode'] = $event->type_code;
2304 if ($event->type_code == 'HOLIDAY') {
2305 $cases3[$h][$event->id]['css'] .= 'peruser_holiday ';
2306 if (GETPOSTINT('check_holiday')) {
2307 $cases3[$h][$event->id]['css'] .= 'peruser_holiday_imp ';
2308 }
2309 } else {
2310 $cases3[$h][$event->id]['color'] = $color;
2311
2312 if ($event->fk_project > 0) {
2313 if (empty($cacheprojects[$event->fk_project])) {
2314 $tmpproj = new Project($db);
2315 $tmpproj->fetch($event->fk_project);
2316 $cacheprojects[$event->fk_project] = $tmpproj;
2317 }
2318 $cases3[$h][$event->id]['string'] .= ', '.$langs->trans("Project").': '.$cacheprojects[$event->fk_project]->ref.' - '.$cacheprojects[$event->fk_project]->title;
2319 }
2320 if ($event->socid > 0) {
2321 if (empty($cachethirdparties[$event->socid])) {
2322 $tmpthirdparty = new Societe($db);
2323 $tmpthirdparty->fetch($event->socid);
2324 $cachethirdparties[$event->socid] = $tmpthirdparty;
2325 }
2326 $cases3[$h][$event->id]['string'] .= ', '.$cachethirdparties[$event->socid]->name;
2327 }
2328 if ($event->contact_id > 0) {
2329 if (empty($cachecontacts[$event->contact_id])) {
2330 $tmpcontact = new Contact($db);
2331 $tmpcontact->fetch($event->contact_id);
2332 $cachecontacts[$event->contact_id] = $tmpcontact;
2333 }
2334 $cases3[$h][$event->id]['string'] .= ', '.$cachecontacts[$event->contact_id]->getFullName($langs);
2335 }
2336 }
2337 }
2338 if ($event->date_start_in_calendar < $c && $dateendtouse > $b2) {
2339 $busy = $event->transparency;
2340 $cases4[$h][$event->id]['busy'] = $busy;
2341 $cases4[$h][$event->id]['string'] = dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzuserrel');
2342 if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) {
2343 $tmpa = dol_getdate($event->date_start_in_calendar, true);
2344 $tmpb = dol_getdate($event->date_end_in_calendar, true);
2345 if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
2346 $cases4[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel');
2347 } else {
2348 $cases4[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzuserrel');
2349 }
2350 }
2351 if ($event->label) {
2352 $cases4[$h][$event->id]['string'] .= ' - '.$event->label;
2353 }
2354 $cases4[$h][$event->id]['typecode'] = $event->type_code;
2355 if ($event->type_code == 'HOLIDAY') {
2356 $cases4[$h][$event->id]['css'] = 'peruser_holiday ';
2357 if (GETPOSTINT('check_holiday')) {
2358 $cases4[$h][$event->id]['css'] .= 'peruser_holiday_imp ';
2359 }
2360 } else {
2361 $cases4[$h][$event->id]['color'] = $color;
2362
2363 if ($event->fk_project > 0) {
2364 if (empty($cacheprojects[$event->fk_project])) {
2365 $tmpproj = new Project($db);
2366 $tmpproj->fetch($event->fk_project);
2367 $cacheprojects[$event->fk_project] = $tmpproj;
2368 }
2369 $cases4[$h][$event->id]['string'] .= ', '.$langs->trans("Project").': '.$cacheprojects[$event->fk_project]->ref.' - '.$cacheprojects[$event->fk_project]->title;
2370 }
2371 if ($event->socid > 0) {
2372 if (empty($cachethirdparties[$event->socid])) {
2373 $tmpthirdparty = new Societe($db);
2374 $tmpthirdparty->fetch($event->socid);
2375 $cachethirdparties[$event->socid] = $tmpthirdparty;
2376 }
2377 $cases4[$h][$event->id]['string'] .= ', '.$cachethirdparties[$event->socid]->name;
2378 }
2379 if ($event->contact_id > 0) {
2380 if (empty($cachecontacts[$event->contact_id])) {
2381 $tmpcontact = new Contact($db);
2382 $tmpcontact->fetch($event->contact_id);
2383 $cachecontacts[$event->contact_id] = $tmpcontact;
2384 }
2385 $cases4[$h][$event->id]['string'] .= ', '.$cachecontacts[$event->contact_id]->getFullName($langs);
2386 }
2387 }
2388 }
2389 } else {
2390 $busy = $event->transparency;
2391 $cases1[$h][$event->id]['busy'] = $busy;
2392 $cases2[$h][$event->id]['busy'] = $busy;
2393 $cases3[$h][$event->id]['busy'] = $busy;
2394 $cases4[$h][$event->id]['busy'] = $busy;
2395 $cases1[$h][$event->id]['string'] = $event->label;
2396 $cases2[$h][$event->id]['string'] = $event->label;
2397 $cases3[$h][$event->id]['string'] = $event->label;
2398 $cases4[$h][$event->id]['string'] = $event->label;
2399 $cases1[$h][$event->id]['typecode'] = $event->type_code;
2400 $cases2[$h][$event->id]['typecode'] = $event->type_code;
2401 $cases3[$h][$event->id]['typecode'] = $event->type_code;
2402 $cases4[$h][$event->id]['typecode'] = $event->type_code;
2403 $cases1[$h][$event->id]['color'] = $color;
2404 $cases2[$h][$event->id]['color'] = $color;
2405 $cases3[$h][$event->id]['color'] = $color;
2406 $cases4[$h][$event->id]['color'] = $color;
2407 $cases1[$h][$event->id]['css'] = '';
2408 $cases2[$h][$event->id]['css'] = '';
2409 $cases3[$h][$event->id]['css'] = '';
2410 $cases4[$h][$event->id]['css'] = '';
2411 }
2412 }
2413 $i++;
2414 }
2415
2416 break; // We found the date we were looking for. No need to search anymore.
2417 }
2418 }
2419
2420 // Now output $casesX from start hour to end hour
2421 for ($h = $begin_h; $h < $end_h; $h++) {
2422 $color1 = '';
2423 $color2 = '';
2424 $color3 = '';
2425 $color4 = '';
2426 $style1 = 'onclickopenref ';
2427 $style2 = 'onclickopenref ';
2428 $style3 = 'onclickopenref ';
2429 $style4 = 'onclickopenref ';
2430 $string1 = '&nbsp;';
2431 $string2 = '&nbsp;';
2432 $string3 = '&nbsp;';
2433 $string4 = '&nbsp;';
2434 $title1 = '';
2435 $title2 = '';
2436 $title3 = '';
2437 $title4 = '';
2438 if (isset($cases1[$h])) {
2439 //$title1.=count($cases1[$h]).' '.(count($cases1[$h])==1?$langs->trans("Event"):$langs->trans("Events"));
2440 if (count($cases1[$h]) > 1) {
2441 $title1 .= count($cases1[$h]).' '.(count($cases1[$h]) == 1 ? $langs->trans("Event") : $langs->trans("Events"));
2442 }
2443
2444 $peruserbusyadded = 0;
2445 $perusernotbusyadded = 0;
2446 foreach ($cases1[$h] as $id => $ev) {
2447 if (!empty($ev['busy']) && !getDolGlobalString('AGENDA_NO_TRANSPARENT_ON_NOT_BUSY')) {
2448 $style1 .= $peruserbusyadded ? '' : ' peruser_busy';
2449 $peruserbusyadded++;
2450 } else {
2451 $style1 .= $perusernotbusyadded ? '' : 'peruser_notbusy ';
2452 $perusernotbusyadded++;
2453 }
2454 if (!empty($ev['css'])) {
2455 $style1 .= $ev['css'].' ';
2456 }
2457 }
2458 }
2459 if (isset($cases2[$h])) {
2460 //$title2.=count($cases2[$h]).' '.(count($cases2[$h])==1?$langs->trans("Event"):$langs->trans("Events"));
2461 if (count($cases2[$h]) > 1) {
2462 $title2 .= count($cases2[$h]).' '.(count($cases2[$h]) == 1 ? $langs->trans("Event") : $langs->trans("Events"));
2463 }
2464
2465 $peruserbusyadded = 0;
2466 $perusernotbusyadded = 0;
2467 foreach ($cases2[$h] as $id => $ev) {
2468 if (!empty($ev['busy']) && !getDolGlobalString('AGENDA_NO_TRANSPARENT_ON_NOT_BUSY')) {
2469 $style2 .= $peruserbusyadded ? '' : ' peruser_busy';
2470 $peruserbusyadded++;
2471 } else {
2472 $style2 .= $perusernotbusyadded ? '' : 'peruser_notbusy ';
2473 $perusernotbusyadded++;
2474 }
2475 if (!empty($ev['css'])) {
2476 $style2 .= $ev['css'].' ';
2477 }
2478 }
2479 }
2480 if (isset($cases3[$h])) {
2481 //$title3.=count($cases3[$h]).' '.(count($cases3[$h])==1?$langs->trans("Event"):$langs->trans("Events"));
2482 if (count($cases3[$h]) > 1) {
2483 $title3 .= count($cases3[$h]).' '.(count($cases3[$h]) == 1 ? $langs->trans("Event") : $langs->trans("Events"));
2484 }
2485
2486 $peruserbusyadded = 0;
2487 $perusernotbusyadded = 0;
2488 foreach ($cases3[$h] as $id => $ev) {
2489 if (!empty($ev['busy']) && !getDolGlobalString('AGENDA_NO_TRANSPARENT_ON_NOT_BUSY')) {
2490 $style3 .= $peruserbusyadded ? '' : ' peruser_busy';
2491 $peruserbusyadded++;
2492 } else {
2493 $style3 .= $perusernotbusyadded ? '' : 'peruser_notbusy ';
2494 $perusernotbusyadded++;
2495 }
2496 if (!empty($ev['css'])) {
2497 $style3 .= $ev['css'].' ';
2498 }
2499 }
2500 }
2501 if (isset($cases4[$h])) {
2502 //$title4.=count($cases3[$h]).' '.(count($cases3[$h])==1?$langs->trans("Event"):$langs->trans("Events"));
2503 if (count($cases4[$h]) > 1) {
2504 $title4 .= count($cases4[$h]).' '.(count($cases4[$h]) == 1 ? $langs->trans("Event") : $langs->trans("Events"));
2505 }
2506
2507 $peruserbusyadded = 0;
2508 $perusernotbusyadded = 0;
2509 foreach ($cases4[$h] as $id => $ev) {
2510 if (!empty($ev['busy']) && !getDolGlobalString('AGENDA_NO_TRANSPARENT_ON_NOT_BUSY')) {
2511 $style4 .= $peruserbusyadded ? '' : ' peruser_busy';
2512 $peruserbusyadded++;
2513 } else {
2514 $style4 .= $perusernotbusyadded ? '' : 'peruser_notbusy ';
2515 $perusernotbusyadded++;
2516 }
2517 if (!empty($ev['css'])) {
2518 $style4 .= $ev['css'].' ';
2519 }
2520 }
2521 }
2522
2523 $ids1 = '';
2524 $ids2 = '';
2525 $ids3 = '';
2526 $ids4 = '';
2527 if (!empty($cases1[$h]) && is_array($cases1[$h]) && count($cases1[$h]) && array_keys($cases1[$h])) {
2528 $ids1 = implode(', ', array_keys($cases1[$h]));
2529 }
2530 if (!empty($cases2[$h]) && is_array($cases2[$h]) && count($cases2[$h]) && array_keys($cases2[$h])) {
2531 $ids2 = implode(', ', array_keys($cases2[$h]));
2532 }
2533 if (!empty($cases3[$h]) && is_array($cases3[$h]) && count($cases3[$h]) && array_keys($cases3[$h])) {
2534 $ids3 = implode(',', array_keys($cases3[$h]));
2535 }
2536 if (!empty($cases4[$h]) && is_array($cases4[$h]) && count($cases4[$h]) && array_keys($cases4[$h])) {
2537 $ids4 = implode(',', array_keys($cases4[$h]));
2538 }
2539
2540 if ($h == $begin_h) {
2541 echo '<td class="'.$style.'_peruserleft cal_peruser'.($var ? ' cal_impair '.$style.'_impair' : '').'">';
2542 } else {
2543 echo '<td class="'.$style.' cal_peruser'.($var ? ' cal_impair '.$style.'_impair' : '').'">';
2544 }
2545
2546 // only 1 event in first quarter
2547 $ref1 = 'ref';
2548 if (!empty($cases1[$h]) && is_array($cases1[$h]) && count($cases1[$h]) == 1) {
2549 $output = array_values(array_slice($cases1[$h], 0, 1));
2550 if ($output[0]['typecode'] == 'HOLIDAY') {
2551 $ref1 = 'holiday';
2552 $title1 = $langs->trans("Holiday");
2553 } else {
2554 $title1 = $langs->trans("Ref").' '.$ids1.($title1 ? ' - '.$title1 : '');
2555 if ($output[0]['string']) {
2556 $title1 .= ' - '.$output[0]['string'];
2557 }
2558 }
2559 if ($output[0]['color']) {
2560 $color1 = $output[0]['color'];
2561 }
2562 } elseif (!empty($cases1[$h]) && is_array($cases1[$h]) && count($cases1[$h]) > 1) {
2563 $title1 = $langs->trans("Ref").' '.$ids1.($title1 ? ' - '.$title1 : '');
2564 $color1 = '222222';
2565 }
2566
2567 // only 1 event in second quarter
2568 $ref2 = 'ref';
2569 if (!empty($cases2[$h]) && is_array($cases2[$h]) && count($cases2[$h]) == 1) {
2570 $output = array_values(array_slice($cases2[$h], 0, 1));
2571 if ($output[0]['typecode'] == 'HOLIDAY') {
2572 $ref2 = 'holiday';
2573 $title2 = $langs->trans("Holiday");
2574 } else {
2575 $title2 = $langs->trans("Ref").' '.$ids2.($title2 ? ' - '.$title2 : '');
2576 if ($output[0]['string']) {
2577 $title2 .= ' - '.$output[0]['string'];
2578 }
2579 }
2580 if ($output[0]['color']) {
2581 $color2 = $output[0]['color'];
2582 }
2583 } elseif (!empty($cases2[$h]) && is_array($cases2[$h]) && count($cases2[$h]) > 1) {
2584 $title2 = $langs->trans("Ref").' '.$ids2.($title2 ? ' - '.$title2 : '');
2585 $color2 = '222222';
2586 }
2587
2588 // only 1 event in third quarter
2589 $ref3 = 'ref';
2590 if (!empty($cases3[$h]) && is_array($cases3[$h]) && count($cases3[$h]) == 1) {
2591 $output = array_values(array_slice($cases3[$h], 0, 1));
2592 if ($output[0]['typecode'] == 'HOLIDAY') {
2593 $ref3 = 'holiday';
2594 $title3 = $langs->trans("Holiday");
2595 } else {
2596 $title3 = $langs->trans("Ref").' '.$ids3.($title3 ? ' - '.$title3 : '');
2597 if ($output[0]['string']) {
2598 $title3 .= ' - '.$output[0]['string'];
2599 }
2600 }
2601 if ($output[0]['color']) {
2602 $color3 = $output[0]['color'];
2603 }
2604 } elseif (!empty($cases3[$h]) && is_array($cases3[$h]) && count($cases3[$h]) > 1) {
2605 $title3 = $langs->trans("Ref").' '.$ids3.($title3 ? ' - '.$title3 : '');
2606 $color3 = '222222';
2607 }
2608
2609 // only 1 event in fourth quarter
2610 $ref4 = 'ref';
2611 if (!empty($cases4[$h]) && is_array($cases4[$h]) && count($cases4[$h]) == 1) {
2612 $output = array_values(array_slice($cases4[$h], 0, 1));
2613 if ($output[0]['typecode'] == 'HOLIDAY') {
2614 $ref4 = 'holiday';
2615 $title4 = $langs->trans("Holiday");
2616 } else {
2617 $title4 = $langs->trans("Ref").' '.$ids4.($title4 ? ' - '.$title4 : '');
2618 if ($output[0]['string']) {
2619 $title4 .= ' - '.$output[0]['string'];
2620 }
2621 }
2622 if ($output[0]['color']) {
2623 $color4 = $output[0]['color'];
2624 }
2625 } elseif (!empty($cases4[$h]) && is_array($cases4[$h]) && count($cases4[$h]) > 1) {
2626 $title4 = $langs->trans("Ref").' '.$ids4.($title4 ? ' - '.$title4 : '');
2627 $color4 = '222222';
2628 }
2629
2630 print '<table class="nobordernopadding case centpercent">';
2631 print '<tr>';
2632 print '<td ';
2633 if (preg_match('/peruser_notbusy/', $style1)) {
2634 print 'style="border: 1px solid #'.($color1 ? $color1 : "888").' !important" ';
2635 } elseif ($color1) {
2636 print 'style="background: #'.$color1.'; "';
2637 }
2638 print 'class="';
2639 print $style1;
2640 print 'center'.($title1 ? ' classfortooltip' : '').($title1 ? ' cursorpointer' : '').'"';
2641 print 'ref="'.$ref1.'_'.$username->id.'_'.sprintf("%04d", $year).'_'.sprintf("%02d", $month).'_'.sprintf("%02d", $day).'_'.sprintf("%02d", $h).'_00_'.($ids1 ? $ids1 : 'none').'"';
2642 print ($title1 ? ' title="'.$title1.'"' : '').'>';
2643 print $string1;
2644 print '</td>';
2645
2646 print '<td ';
2647 if (preg_match('/peruser_notbusy/', $style2)) {
2648 print 'style="border: 1px solid #'.($color2 ? $color2 : "888").' !important" ';
2649 } elseif ($color2) {
2650 print 'style="background: #'.$color2.'; "';
2651 }
2652 print 'class="';
2653 print $style2;
2654 print 'center'.($title2 ? ' classfortooltip' : '').($title2 ? ' cursorpointer' : '').'"';
2655 print ' ref="'.$ref2.'_'.$username->id.'_'.sprintf("%04d", $year).'_'.sprintf("%02d", $month).'_'.sprintf("%02d", $day).'_'.sprintf("%02d", $h).'_15_'.($ids2 ? $ids2 : 'none').'"';
2656 print ($title2 ? ' title="'.$title2.'"' : '').'>';
2657 print $string2;
2658 print '</td>';
2659
2660 print '<td ';
2661 if (preg_match('/peruser_notbusy/', $style3)) {
2662 print 'style="border: 1px solid #'.($color3 ? $color3 : "888").' !important" ';
2663 } elseif ($color3) {
2664 print 'style="background: #'.$color3.'; "';
2665 }
2666 print 'class="';
2667 print $style3;
2668 print 'center'.($title3 ? ' classfortooltip' : '').($title3 ? ' cursorpointer' : '').'"';
2669 print ' ref="'.$ref3.'_'.$username->id.'_'.sprintf("%04d", $year).'_'.sprintf("%02d", $month).'_'.sprintf("%02d", $day).'_'.sprintf("%02d", $h).'_30_'.($ids3 ? $ids3 : 'none').'"';
2670 print ($title3 ? ' title="'.$title3.'"' : '').'>';
2671 print $string3;
2672 print '</td>';
2673
2674 print '<td ';
2675 if (preg_match('/peruser_notbusy/', $style4)) {
2676 print 'style="border: 1px solid #'.($color4 ? $color4 : "888").' !important" ';
2677 } elseif ($color4) {
2678 print 'style="background: #'.$color4.'; "';
2679 }
2680 print 'class="';
2681 print $style4;
2682 print 'center'.($title4 ? ' classfortooltip' : '').($title4 ? ' cursorpointer' : '').'"';
2683 print ' ref="'.$ref4.'_'.$username->id.'_'.sprintf("%04d", $year).'_'.sprintf("%02d", $month).'_'.sprintf("%02d", $day).'_'.sprintf("%02d", $h).'_45_'.($ids4 ? $ids4 : 'none').'"';
2684 print ($title4 ? ' title="'.$title4.'"' : '').'>';
2685 print $string4;
2686 print '</td>';
2687
2688 print '</tr>';
2689 print '</table>';
2690 print '</td>';
2691 }
2692}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
agenda_get_birthday_events($db, $langs, $user, $mode, $month, $day, $year, &$eventarray, &$nbevents, $firstdaytoshow, $lastdaytoshow)
Complete an agenda calendar event array with contact birthday pseudo-events.
print_actions_filter( $form, $canedit, $status, $year, $month, $day, $showbirthday, $filtera, $filtert, $filtered, $pid, $socid, $action, $showextcals=array(), $actioncode='', $usergroupid=0, $excludetype='', $resourceid=0, $search_categ_cus=0, $search_import_key='')
Show filter form in agenda view.
calendars_prepare_head($param)
Define head array for tabs of agenda setup pages.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
$c
Definition line.php:353
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage agenda events (actions)
Class to manage contact/addresses.
Class to manage generation of HTML components Only common components must be here.
Class to read/parse ICal calendars.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
$theme_datacolor
Definition index.php:1358
$cacheusers
Definition index.php:1356
dol_get_first_hour($date, $gm='tzserver')
Return GMT time for first hour of a given GMT date (it removes hours, min and second part)
Definition date.lib.php:686
dol_get_next_week($day, $week, $month, $year)
Return next week.
Definition date.lib.php:604
dol_get_first_day_week($day, $month, $year, $gm=false)
Return first day of week for a date.
Definition date.lib.php:701
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition date.lib.php:626
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:645
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0, $tz='')
Add a delay to a date.
Definition date.lib.php:127
dol_stringtotime($string, $gm=1, $processnotimeasnoon=0)
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:452
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
getDolUserInt($key, $default=0, $tmpuser=null)
Return Dolibarr user constant int value.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_getThemeFilePath($file, $theme='')
Return the full filesystem path of a file located in the currently selected theme directory.
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='', $keepspaces=0)
Clean a string from all punctuation characters to use it as a ref or login.
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
dol_sanitizePathName($str, $newstr='_', $unaccent=0, $allowdash=0)
Clean a string to use it as a path name.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolUserString($key, $default='', $tmpuser=null)
Return Dolibarr user constant string value.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
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_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183
conf($dolibarr_main_document_root, $realpathconf=null)
Load conf file (file must exists)
Definition inc.php:431
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date
Definition receipt.php:492
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
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.