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