dolibarr  20.0.0-beta
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-2019 Frédéric France <frederic.france@netlogic.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
34 require '../../main.inc.php';
35 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
41 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
42 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
43 
44 
45 if (!isset($conf->global->AGENDA_MAX_EVENTS_DAY_VIEW)) {
46  $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW = 3;
47 }
48 
49 $action = GETPOST('action', 'aZ09');
50 
51 $disabledefaultvalues = GETPOSTINT('disabledefaultvalues');
52 
53 $filter = GETPOST("search_filter", 'alpha', 3) ? GETPOST("search_filter", 'alpha', 3) : GETPOST("filter", 'alpha', 3);
54 $filtert = GETPOSTINT("search_filtert", 3) ? GETPOSTINT("search_filtert", 3) : GETPOSTINT("filtert", 3);
55 $usergroup = GETPOSTINT("search_usergroup", 3) ? GETPOSTINT("search_usergroup", 3) : GETPOSTINT("usergroup", 3);
56 //if (! ($usergroup > 0) && ! ($filtert > 0)) $filtert = $user->id;
57 //$showbirthday = empty($conf->use_javascript_ajax)?GETPOST("showbirthday","int"):1;
58 $showbirthday = 0;
59 
60 // If not choice done on calendar owner, we filter on user.
61 /*if (empty($filtert) && empty($conf->global->AGENDA_ALL_CALENDARS))
62 {
63  $filtert = $user->id;
64 }*/
65 
66 $sortfield = GETPOST('sortfield', 'aZ09comma');
67 $sortorder = GETPOST('sortorder', 'aZ09comma');
68 $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
69 if (empty($page) || $page == -1) {
70  $page = 0;
71 } // If $page is not defined, or '' or -1
72 $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
73 $offset = $limit * $page;
74 if (!$sortorder) {
75  $sortorder = "ASC";
76 }
77 if (!$sortfield) {
78  $sortfield = "a.datec";
79 }
80 
81 $socid = GETPOSTINT("search_socid") ? GETPOSTINT("search_socid") : GETPOSTINT("socid");
82 if ($user->socid) {
83  $socid = $user->socid;
84 }
85 if ($socid < 0) {
86  $socid = '';
87 }
88 
89 $canedit = 1;
90 if (!$user->hasRight('agenda', 'myactions', 'read')) {
92 }
93 if (!$user->hasRight('agenda', 'allactions', 'read')) {
94  $canedit = 0;
95 }
96 if (!$user->hasRight('agenda', 'allactions', 'read') || $filter == 'mine') { // If no permission to see all, we show only affected to me
97  $filtert = $user->id;
98 }
99 
100 $mode = 'show_peruser';
101 $resourceid = GETPOSTINT("search_resourceid") ? GETPOSTINT("search_resourceid") : GETPOSTINT("resourceid");
102 $year = GETPOSTINT("year") ? GETPOSTINT("year") : idate("Y");
103 $month = GETPOSTINT("month") ? GETPOSTINT("month") : idate("m");
104 $week = GETPOSTINT("week") ? GETPOSTINT("week") : idate("W");
105 $day = GETPOSTINT("day") ? GETPOSTINT("day") : idate("d");
106 $pid = GETPOSTISSET("search_projectid") ? GETPOSTINT("search_projectid", 3) : GETPOSTINT("projectid", 3);
107 $status = GETPOSTISSET("search_status") ? GETPOST("search_status", 'aZ09') : GETPOST("status", 'aZ09'); // status may be 0, 50, 100, 'todo', 'na' or -1
108 $type = GETPOSTISSET("search_type") ? GETPOST("search_type", 'alpha') : GETPOST("type", 'alpha');
109 $maxprint = ((GETPOSTINT("maxprint") != '') ? GETPOSTINT("maxprint") : $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW);
110 $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
111 $search_categ_cus = GETPOSTINT("search_categ_cus", 3) ? GETPOSTINT("search_categ_cus", 3) : 0;
112 // Set actioncode (this code must be same for setting actioncode into peruser, listacton and index)
113 if (GETPOST('search_actioncode', 'array:aZ09')) {
114  $actioncode = GETPOST('search_actioncode', 'array:aZ09', 3);
115  if (!count($actioncode)) {
116  $actioncode = '0';
117  }
118 } else {
119  $actioncode = GETPOST("search_actioncode", "alpha", 3) ? GETPOST("search_actioncode", "alpha", 3) : (GETPOST("search_actioncode", "alpha") == '0' ? '0' : ((!getDolGlobalString('AGENDA_DEFAULT_FILTER_TYPE') || $disabledefaultvalues) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE));
120 }
121 
122 $dateselect = dol_mktime(0, 0, 0, GETPOSTINT('dateselectmonth'), GETPOSTINT('dateselectday'), GETPOSTINT('dateselectyear'));
123 if ($dateselect > 0) {
124  $day = GETPOSTINT('dateselectday');
125  $month = GETPOSTINT('dateselectmonth');
126  $year = GETPOSTINT('dateselectyear');
127 }
128 
129 $tmp = !getDolGlobalString('MAIN_DEFAULT_WORKING_HOURS') ? '9-18' : $conf->global->MAIN_DEFAULT_WORKING_HOURS;
130 $tmp = str_replace(' ', '', $tmp); // FIX 7533
131 $tmparray = explode('-', $tmp);
132 $begin_h = GETPOSTISSET('begin_h') ? GETPOSTINT('begin_h') : ($tmparray[0] != '' ? $tmparray[0] : 9);
133 $end_h = GETPOSTISSET('end_h') ? GETPOSTINT('end_h') : ($tmparray[1] != '' ? $tmparray[1] : 18);
134 if ($begin_h < 0 || $begin_h > 23) {
135  $begin_h = 9;
136 }
137 if ($end_h < 1 || $end_h > 24) {
138  $end_h = 18;
139 }
140 if ($end_h <= $begin_h) {
141  $end_h = $begin_h + 1;
142 }
143 
144 $tmp = !getDolGlobalString('MAIN_DEFAULT_WORKING_DAYS') ? '1-5' : $conf->global->MAIN_DEFAULT_WORKING_DAYS;
145 $tmp = str_replace(' ', '', $tmp); // FIX 7533
146 $tmparray = explode('-', $tmp);
147 $begin_d = GETPOSTISSET('begin_d') ? GETPOSTINT('begin_d') : ($tmparray[0] != '' ? $tmparray[0] : 1);
148 $end_d = GETPOSTISSET('end_d') ? GETPOSTINT('end_d') : ($tmparray[1] != '' ? $tmparray[1] : 5);
149 if ($begin_d < 1 || $begin_d > 7) {
150  $begin_d = 1;
151 }
152 if ($end_d < 1 || $end_d > 7) {
153  $end_d = 7;
154 }
155 if ($end_d < $begin_d) {
156  $end_d = $begin_d + 1;
157 }
158 
159 if ($status == '' && !GETPOSTISSET('search_status')) {
160  $status = ((!getDolGlobalString('AGENDA_DEFAULT_FILTER_STATUS') || $disabledefaultvalues) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_STATUS);
161 }
162 
163 if (empty($mode) && !GETPOSTISSET('mode')) {
164  $mode = (!getDolGlobalString('AGENDA_DEFAULT_VIEW') ? 'show_month' : $conf->global->AGENDA_DEFAULT_VIEW);
165 }
166 
167 if (GETPOST('viewcal', 'alpha') && $mode != 'show_day' && $mode != 'show_week' && $mode != 'show_peruser') {
168  $mode = 'show_month';
169  $day = '';
170 } // View by month
171 if (GETPOST('viewweek', 'alpha') || $mode == 'show_week') {
172  $mode = 'show_week';
173  $week = ($week ? $week : idate("W"));
174  $day = ($day ? $day : idate("d"));
175 } // View by week
176 if (GETPOST('viewday', 'alpha') || $mode == 'show_day') {
177  $mode = 'show_day';
178  $day = ($day ? $day : idate("d"));
179 } // View by day
180 
181 $object = new ActionComm($db);
182 
183 // Load translation files required by the page
184 $langs->loadLangs(array('users', 'agenda', 'other', 'commercial'));
185 
186 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
187 $hookmanager->initHooks(array('agenda'));
188 
189 $result = restrictedArea($user, 'agenda', 0, '', 'myactions');
190 if ($user->socid && $socid) {
191  $result = restrictedArea($user, 'societe', $socid);
192 }
193 
194 $search_status = $status;
195 
196 
197 /*
198  * Actions
199  */
200 
201 // None
202 
203 
204 /*
205  * View
206  */
207 
208 $parameters = array(
209  'socid' => $socid,
210  'status' => $status,
211  'year' => $year,
212  'month' => $month,
213  'day' => $day,
214  'type' => $type,
215  'maxprint' => $maxprint,
216  'filter' => $filter,
217  'filtert' => $filtert,
218  'showbirthday' => $showbirthday,
219  'canedit' => $canedit,
220  'optioncss' => $optioncss,
221  'actioncode' => $actioncode,
222  'pid' => $pid,
223  'resourceid' => $resourceid,
224  'usergroup' => $usergroup,
225 );
226 $reshook = $hookmanager->executeHooks('beforeAgendaPerUser', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
227 if ($reshook < 0) {
228  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
229 }
230 
231 $form = new Form($db);
232 $companystatic = new Societe($db);
233 
234 $help_url = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:M&oacute;dulo_Agenda|DE:Modul_Terminplanung';
235 llxHeader('', $langs->trans("Agenda"), $help_url);
236 
237 $now = dol_now();
238 $nowarray = dol_getdate($now);
239 $nowyear = $nowarray['year'];
240 $nowmonth = $nowarray['mon'];
241 $nowday = $nowarray['mday'];
242 
243 
244 // Define list of all external calendars (global setup)
245 $listofextcals = array();
246 
247 $prev = dol_get_first_day_week($day, $month, $year);
248 $first_day = $prev['first_day'];
249 $first_month = $prev['first_month'];
250 $first_year = $prev['first_year'];
251 
252 $week = $prev['week'];
253 
254 $day = (int) $day;
255 $next = dol_get_next_week($day, $week, $month, $year);
256 $next_year = $next['year'];
257 $next_month = $next['month'];
258 $next_day = $next['day'];
259 
260 $max_day_in_month = idate("t", dol_mktime(0, 0, 0, $month, 1, $year));
261 
262 $tmpday = $first_day;
263 //print 'xx'.$prev_year.'-'.$prev_month.'-'.$prev_day;
264 //print 'xx'.$next_year.'-'.$next_month.'-'.$next_day;
265 
266 $title = $langs->trans("DoneAndToDoActions");
267 if ($status == 'done') {
268  $title = $langs->trans("DoneActions");
269 }
270 if ($status == 'todo') {
271  $title = $langs->trans("ToDoActions");
272 }
273 
274 $param = '';
275 if ($actioncode || GETPOSTISSET('search_actioncode')) {
276  if (is_array($actioncode)) {
277  foreach ($actioncode as $str_action) {
278  $param .= "&search_actioncode[]=".urlencode($str_action);
279  }
280  } else {
281  $param .= "&search_actioncode=".urlencode($actioncode);
282  }
283 }
284 if ($resourceid > 0) {
285  $param .= "&search_resourceid=".urlencode((string) ($resourceid));
286 }
287 
288 if ($status || GETPOSTISSET('status') || GETPOSTISSET('search_status')) {
289  $param .= "&search_status=".urlencode($status);
290 }
291 if ($filter) {
292  $param .= "&search_filter=".urlencode($filter);
293 }
294 if ($filtert) {
295  $param .= "&search_filtert=".urlencode($filtert);
296 }
297 if ($usergroup > 0) {
298  $param .= "&search_usergroup=".urlencode((string) ($usergroup));
299 }
300 if ($socid > 0) {
301  $param .= "&search_socid=".urlencode((string) ($socid));
302 }
303 if ($showbirthday) {
304  $param .= "&search_showbirthday=1";
305 }
306 if ($pid) {
307  $param .= "&search_projectid=".urlencode((string) ($pid));
308 }
309 if ($type) {
310  $param .= "&search_type=".urlencode($type);
311 }
312 if ($mode != 'show_peruser') {
313  $param .= '&mode='.urlencode($mode);
314 }
315 if ($begin_h != '') {
316  $param .= '&begin_h='.((int) $begin_h);
317 }
318 if ($end_h != '') {
319  $param .= '&end_h='.((int) $end_h);
320 }
321 if ($begin_d != '') {
322  $param .= '&begin_d='.((int) $begin_d);
323 }
324 if ($end_d != '') {
325  $param .= '&end_d='.((int) $end_d);
326 }
327 if ($search_categ_cus != 0) {
328  $param .= '&search_categ_cus='.urlencode((string) ($search_categ_cus));
329 }
330 $param .= "&maxprint=".urlencode((string) ($maxprint));
331 
332 $paramnoactionodate = $param;
333 
334 $prev = dol_get_first_day_week($day, $month, $year);
335 //print "day=".$day." month=".$month." year=".$year;
336 //var_dump($prev); exit;
337 $prev_year = $prev['prev_year'];
338 $prev_month = $prev['prev_month'];
339 $prev_day = $prev['prev_day'];
340 $first_day = $prev['first_day'];
341 $first_month = $prev['first_month'];
342 $first_year = $prev['first_year'];
343 
344 $week = $prev['week'];
345 
346 $day = (int) $day;
347 $next = dol_get_next_week($first_day, $week, $first_month, $first_year);
348 $next_year = $next['year'];
349 $next_month = $next['month'];
350 $next_day = $next['day'];
351 
352 // Define firstdaytoshow and lastdaytoshow. Warning: lastdaytoshow is last second to show + 1
353 // $firstdaytoshow and lastdaytoshow become a gmt dates to use to search/compare because first_xxx are in tz idea and we used tzuserrel
354 $firstdaytoshow = dol_mktime(0, 0, 0, $first_month, $first_day, $first_year, 'tzuserrel');
355 $nb_weeks_to_show = (getDolGlobalString('AGENDA_NB_WEEKS_IN_VIEW_PER_USER')) ? ((int) $conf->global->AGENDA_NB_WEEKS_IN_VIEW_PER_USER * 7) : 7;
356 $lastdaytoshow = dol_time_plus_duree($firstdaytoshow, $nb_weeks_to_show, 'd');
357 //print $firstday.'-'.$first_month.'-'.$first_year;
358 //print dol_print_date($firstdaytoshow, 'dayhour', 'gmt');
359 //print dol_print_date($lastdaytoshow,'dayhour', 'gmt');
360 
361 $max_day_in_month = idate("t", dol_mktime(0, 0, 0, $month, 1, $year, 'gmt'));
362 
363 $tmpday = $first_day;
364 $picto = 'calendarweek';
365 
366 // Show navigation bar
367 $nav = '<div class="navselectiondate inline-block nowraponall">';
368 $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";
369 $nav .= " <span id=\"month_name\">".dol_print_date(dol_mktime(0, 0, 0, $first_month, $first_day, $first_year), "%Y").", ".$langs->trans("Week")." ".$week;
370 $nav .= " </span>\n";
371 $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";
372 if (empty($conf->dol_optimize_smallscreen)) {
373  $nav .= " &nbsp; <a href=\"?year=".$nowyear."&amp;month=".$nowmonth."&amp;day=".$nowday.$param.'" class="datenowlink">'.$langs->trans("Today").'</a> ';
374 }
375 $nav .= '</div>';
376 $nav .= $form->selectDate($dateselect, 'dateselect', 0, 0, 1, '', 1, 0);
377 $nav .= ' <button type="submit" class="liste_titre button_search" name="button_search_x" value="x"><span class="fa fa-search"></span></button>';
378 
379 // Must be after the nav definition
380 $param .= '&year='.urlencode((string) ($year)).'&month='.urlencode((string) ($month)).($day ? '&day='.urlencode((string) ($day)) : '');
381 //print 'x'.$param;
382 
383 
384 $paramnoaction = preg_replace('/action=[a-z_]+/', '', $param);
385 
386 $head = calendars_prepare_head($paramnoaction);
387 
388 print '<form method="POST" id="searchFormList" class="listactionsfilter" action="'.$_SERVER["PHP_SELF"].'">'."\n";
389 
390 $showextcals = $listofextcals;
391 // Legend
392 if ($conf->use_javascript_ajax) {
393  $s = '';
394  $s .= '<script type="text/javascript">'."\n";
395  $s .= 'jQuery(document).ready(function () {'."\n";
396  $s .= 'jQuery("#check_mytasks").click(function() { jQuery(".family_mytasks").toggle(); jQuery(".family_other").toggle(); });'."\n";
397  $s .= 'jQuery("#check_birthday").click(function() { jQuery(".family_birthday").toggle(); });'."\n";
398  $s .= 'jQuery(".family_birthday").toggle();'."\n";
399  if ($mode == "show_week" || $mode == "show_month" || empty($mode)) {
400  $s .= 'jQuery( "td.sortable" ).sortable({connectWith: ".sortable",placeholder: "ui-state-highlight",items: "div:not(.unsortable)", receive: function( event, ui ) {';
401  }
402  $s .= '});'."\n";
403  $s .= '</script>'."\n";
404  if (!empty($conf->use_javascript_ajax)) {
405  $s .= '<div class="nowrap clear float"><input type="checkbox" id="check_mytasks" name="check_mytasks" checked disabled> '.$langs->trans("LocalAgenda").' &nbsp; </div>';
406  if (is_array($showextcals) && count($showextcals) > 0) {
407  foreach ($showextcals as $val) {
408  $htmlname = md5($val['name']);
409  $s .= '<script type="text/javascript">'."\n";
410  $s .= 'jQuery(document).ready(function () {'."\n";
411  $s .= ' jQuery("#check_ext'.$htmlname.'").click(function() {';
412  $s .= ' /* alert("'.$htmlname.'"); */';
413  $s .= ' jQuery(".family_ext'.$htmlname.'").toggle();';
414  $s .= ' });'."\n";
415  $s .= '});'."\n";
416  $s .= '</script>'."\n";
417  $s .= '<div class="nowrap float"><input type="checkbox" id="check_ext'.$htmlname.'" name="check_ext'.$htmlname.'" checked> '.$val ['name'].' &nbsp; </div>';
418  }
419  }
420 
421  //$s.='<div class="nowrap float"><input type="checkbox" id="check_birthday" name="check_birthday"> '.$langs->trans("AgendaShowBirthdayEvents").' &nbsp; </div>';
422 
423  // Calendars from hooks
424  $parameters = array();
425  $reshook = $hookmanager->executeHooks('addCalendarChoice', $parameters, $object, $action);
426  if (empty($reshook)) {
427  $s .= $hookmanager->resPrint;
428  } elseif ($reshook > 1) {
429  $s = $hookmanager->resPrint;
430  }
431  }
432 }
433 
434 $massactionbutton = '';
435 
436 $viewmode = '';
437 $viewmode .= '<a class="btnTitle reposition" href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&restore_lastsearch_values=1'.$paramnoactionodate.'">';
438 //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
439 $viewmode .= img_picto($langs->trans("List"), 'object_calendarlist', 'class="imgforviewmode pictoactionview block"');
440 //$viewmode .= '</span>';
441 $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewList").'</span></a>';
442 
443 $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.'">';
444 //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
445 $viewmode .= img_picto($langs->trans("ViewCal"), 'object_calendarmonth', 'class="pictoactionview block"');
446 //$viewmode .= '</span>';
447 $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewCal").'</span></a>';
448 
449 $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.'">';
450 //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
451 $viewmode .= img_picto($langs->trans("ViewWeek"), 'object_calendarweek', 'class="pictoactionview block"');
452 //$viewmode .= '</span>';
453 $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewWeek").'</span></a>';
454 
455 $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.'">';
456 //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
457 $viewmode .= img_picto($langs->trans("ViewDay"), 'object_calendarday', 'class="pictoactionview block"');
458 //$viewmode .= '</span>';
459 $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewDay").'</span></a>';
460 
461 $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.'">';
462 //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
463 $viewmode .= img_picto($langs->trans("ViewPerUser"), 'object_calendarperuser', 'class="pictoactionview block"');
464 //$viewmode .= '</span>';
465 $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewPerUser").'</span></a>';
466 
467 $viewmode .= '<span class="marginrightonly"></span>';
468 
469 // Add more views from hooks
470 $parameters = array();
471 $object = null;
472 $reshook = $hookmanager->executeHooks('addCalendarView', $parameters, $object, $action);
473 if (empty($reshook)) {
474  $viewmode .= $hookmanager->resPrint;
475 } elseif ($reshook > 1) {
476  $viewmode = $hookmanager->resPrint;
477 }
478 
479 
480 $newparam = '';
481 $newcardbutton = '';
482 if ($user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create')) {
483  $tmpforcreatebutton = dol_getdate(dol_now(), true);
484 
485  $newparam .= '&month='.urlencode(str_pad((string) $month, 2, "0", STR_PAD_LEFT)).'&year='.((int) $tmpforcreatebutton['year']);
486  if ($begin_h !== '') {
487  $newparam .= '&begin_h='.((int) $begin_h);
488  }
489  if ($end_h !== '') {
490  $newparam .= '&end_h='.((int) $end_h);
491  }
492  if ($begin_d !== '') {
493  $newparam .= '&begin_d='.((int) $begin_d);
494  }
495  if ($end_d !== '') {
496  $newparam .= '&end_d='.((int) $end_d);
497  }
498 
499  $urltocreateaction = DOL_URL_ROOT.'/comm/action/card.php?action=create';
500  $urltocreateaction .= '&apyear='.$tmpforcreatebutton['year'].'&apmonth='.$tmpforcreatebutton['mon'].'&apday='.$tmpforcreatebutton['mday'].'&aphour='.$tmpforcreatebutton['hours'].'&apmin='.$tmpforcreatebutton['minutes'];
501  $urltocreateaction .= '&backtopage='.urlencode($_SERVER["PHP_SELF"].($newparam ? '?'.$newparam : ''));
502 
503  $newcardbutton .= dolGetButtonTitle($langs->trans("AddAction"), '', 'fa fa-plus-circle', $urltocreateaction);
504 }
505 
506 $num = '';
507 
508 print_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);
509 
510 $link = '';
511 //print load_fiche_titre('', $link.' &nbsp; &nbsp; '.$nav.' '.$newcardbutton, '');
512 
513 // Local calendar
514 $newtitle = '<div class="nowrap clear inline-block minheight30">';
515 $newtitle .= '<input type="checkbox" id="check_mytasks" name="check_mytasks" checked disabled> '.$langs->trans("LocalAgenda").' &nbsp; ';
516 $newtitle .= '</div>';
517 //$newtitle=$langs->trans($title);
518 
519 $s = $newtitle;
520 
521 print $s;
522 
523 print '<div class="liste_titre liste_titre_bydiv centpercent">';
524 print_actions_filter($form, $canedit, $search_status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid, $search_categ_cus);
525 print '</div>';
526 
527 
528 // Get event in an array
529 $eventarray = array();
530 
531 
532 // DEFAULT CALENDAR + AUTOEVENT CALENDAR + CONFERENCEBOOTH CALENDAR
533 $sql = "SELECT";
534 if ($usergroup > 0) {
535  $sql .= " DISTINCT";
536 }
537 $sql .= " a.id, a.label,";
538 $sql .= " a.datep,";
539 $sql .= " a.datep2,";
540 $sql .= " a.percent,";
541 $sql .= " a.fk_user_author,a.fk_user_action,";
542 $sql .= " a.transparency, a.priority, a.fulldayevent, a.location,";
543 $sql .= " a.fk_soc, a.fk_contact, a.fk_element, a.elementtype, a.fk_project,";
544 $sql .= " ca.code, ca.libelle as type_label, ca.color, ca.type as type_type, ca.picto as type_picto";
545 $sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm as ca, ".MAIN_DB_PREFIX."actioncomm as a";
546 // We must filter on resource table
547 if ($resourceid > 0) {
548  $sql .= ", ".MAIN_DB_PREFIX."element_resources as r";
549 }
550 // We must filter on assignment table
551 if ($filtert > 0 || $usergroup > 0) {
552  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."actioncomm_resources as ar";
553  $sql .= " ON ar.fk_actioncomm = a.id AND ar.element_type='user'";
554  if ($filtert > 0) {
555  $sql .= " AND ar.fk_element = ".((int) $filtert);
556  }
557  if ($usergroup > 0) {
558  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_user = ar.fk_element AND ugu.fk_usergroup = ".((int) $usergroup);
559  }
560 }
561 
562 $sql .= " WHERE a.fk_action = ca.id";
563 $sql .= " AND a.entity IN (".getEntity('agenda').")";
564 // Condition on actioncode
565 if (!empty($actioncode)) {
566  if (!getDolGlobalString('AGENDA_USE_EVENT_TYPE')) {
567  if ($actioncode == 'AC_NON_AUTO') {
568  $sql .= " AND ca.type != 'systemauto'";
569  } elseif ($actioncode == 'AC_ALL_AUTO') {
570  $sql .= " AND ca.type = 'systemauto'";
571  } else {
572  if ($actioncode == 'AC_OTH') {
573  $sql .= " AND ca.type != 'systemauto'";
574  }
575  if ($actioncode == 'AC_OTH_AUTO') {
576  $sql .= " AND ca.type = 'systemauto'";
577  }
578  }
579  } else {
580  if ($actioncode == 'AC_NON_AUTO') {
581  $sql .= " AND ca.type != 'systemauto'";
582  } elseif ($actioncode == 'AC_ALL_AUTO') {
583  $sql .= " AND ca.type = 'systemauto'";
584  } else {
585  if (is_array($actioncode)) {
586  $sql .= " AND ca.code IN (".$db->sanitize("'".implode("','", $actioncode)."'", 1).")";
587  } else {
588  $sql .= " AND ca.code IN (".$db->sanitize("'".implode("','", explode(',', $actioncode))."'", 1).")";
589  }
590  }
591  }
592 }
593 if ($resourceid > 0) {
594  $sql .= " AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = ".((int) $resourceid);
595 }
596 if ($pid) {
597  $sql .= " AND a.fk_project = ".((int) $pid);
598 }
599 // If the internal user must only see his customers, force searching by him
600 $search_sale = 0;
601 if (!$user->hasRight('societe', 'client', 'voir')) {
602  $search_sale = $user->id;
603 }
604 // Search on sale representative
605 if ($search_sale && $search_sale != '-1') {
606  if ($search_sale == -2) {
607  $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = a.fk_soc)";
608  } elseif ($search_sale > 0) {
609  $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).")";
610  }
611 }
612 // Search on socid
613 if ($socid) {
614  $sql .= " AND a.fk_soc = ".((int) $socid);
615 }
616 
617 if ($mode == 'show_day') {
618  $sql .= " AND (";
619  $sql .= " (a.datep BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel'))."'";
620  $sql .= " AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel'))."')";
621  $sql .= " OR ";
622  $sql .= " (a.datep2 BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel'))."'";
623  $sql .= " AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel'))."')";
624  $sql .= " OR ";
625  $sql .= " (a.datep < '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel'))."'";
626  $sql .= " AND a.datep2 > '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel'))."')";
627  $sql .= ")";
628 } else {
629  // To limit array
630  $sql .= " AND (";
631  $sql .= " (a.datep BETWEEN '".$db->idate($firstdaytoshow - (60 * 60 * 24 * 2))."'"; // Start 2 day before $firstdaytoshow
632  $sql .= " AND '".$db->idate($lastdaytoshow + (60 * 60 * 24 * 2))."')"; // End 2 day after $lastdaytoshow
633  $sql .= " OR ";
634  $sql .= " (a.datep2 BETWEEN '".$db->idate($firstdaytoshow - (60 * 60 * 24 * 2))."'";
635  $sql .= " AND '".$db->idate($lastdaytoshow + (60 * 60 * 24 * 2))."')";
636  $sql .= " OR ";
637  $sql .= " (a.datep < '".$db->idate($firstdaytoshow - (60 * 60 * 24 * 2))."'";
638  $sql .= " AND a.datep2 > '".$db->idate($lastdaytoshow + (60 * 60 * 24 * 2))."')";
639  $sql .= ")";
640 }
641 if ($type) {
642  $sql .= " AND ca.id = ".((int) $type);
643 }
644 if ($status == '0') {
645  $sql .= " AND a.percent = 0";
646 }
647 if ($status === 'na') {
648  // Not applicable
649  $sql .= " AND a.percent = -1";
650 }
651 if ($status == '50') {
652  // Running already started
653  $sql .= " AND (a.percent > 0 AND a.percent < 100)";
654 }
655 if ($status == 'done' || $status == '100') {
656  $sql .= " AND (a.percent = 100)";
657 }
658 if ($status == 'todo') {
659  $sql .= " AND (a.percent >= 0 AND a.percent < 100)";
660 }
661 // Search in categories, -1 is all and -2 is no categories
662 if ($search_categ_cus != -1) {
663  if ($search_categ_cus == -2) {
664  $sql .= " AND NOT EXISTS (SELECT ca.fk_actioncomm FROM ".MAIN_DB_PREFIX."categorie_actioncomm as ca WHERE ca.fk_actioncomm = a.id)";
665  } elseif ($search_categ_cus > 0) {
666  $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)."))";
667  }
668 }
669 // Sort on date
670 $sql .= $db->order("fk_user_action, datep");
671 //print $sql;
672 
673 dol_syslog("comm/action/peruser.php", LOG_DEBUG);
674 $resql = $db->query($sql);
675 if ($resql) {
676  $num = $db->num_rows($resql);
677 
678  $i = 0;
679  while ($i < $num) {
680  $obj = $db->fetch_object($resql);
681  //print $obj->fk_user_action.' '.$obj->id."<br>";
682 
683  // Discard auto action if option is on
684  if (getDolGlobalString('AGENDA_ALWAYS_HIDE_AUTO') && $obj->code == 'AC_OTH_AUTO') {
685  $i++;
686  continue;
687  }
688 
689  $datep = $db->jdate($obj->datep);
690  $datep2 = $db->jdate($obj->datep2);
691 
692 
693  // Create a new object action
694  $event = new ActionComm($db);
695  $event->id = $obj->id;
696  $event->datep = $datep; // datep and datef are GMT date
697  $event->datef = $datep2;
698  $event->type_code = $obj->code;
699  $event->type_color = $obj->color;
700  $event->label = $obj->label;
701  $event->percentage = $obj->percent;
702  $event->authorid = $obj->fk_user_author; // user id of creator
703  $event->userownerid = $obj->fk_user_action; // user id of owner
704  $event->priority = $obj->priority;
705  $event->fulldayevent = $obj->fulldayevent;
706  $event->location = $obj->location;
707  $event->transparency = $obj->transparency;
708 
709  $event->fk_project = $obj->fk_project;
710 
711  $event->socid = $obj->fk_soc;
712  $event->contact_id = $obj->fk_contact;
713 
714  $event->fk_element = $obj->fk_element;
715  $event->elementtype = $obj->elementtype;
716 
717  // Defined date_start_in_calendar and date_end_in_calendar property
718  // They are date start and end of action but modified to not be outside calendar view.
719  $event->date_start_in_calendar = $datep;
720  if ($datep2 != '' && $datep2 >= $datep) {
721  $event->date_end_in_calendar = $datep2;
722  } else {
723  $event->date_end_in_calendar = $datep;
724  }
725 
726  //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";
727 
728  // Check values
729  if ($event->date_end_in_calendar < $firstdaytoshow ||
730  $event->date_start_in_calendar >= $lastdaytoshow) {
731  // This record is out of visible range
732  unset($event);
733  } else {
734  //print $i.' - eventid='.$event->id.' '.dol_print_date($event->date_start_in_calendar, 'dayhour').' - '.dol_print_date($event->date_end_in_calendar, 'dayhour').'<br>'."\n";
735  $event->fetch_userassigned(); // This load $event->userassigned
736 
737  if ($event->date_start_in_calendar < $firstdaytoshow) {
738  $event->date_start_in_calendar = $firstdaytoshow;
739  }
740  if ($event->date_end_in_calendar >= $lastdaytoshow) {
741  $event->date_end_in_calendar = ($lastdaytoshow - 1);
742  }
743 
744  // Add an entry in actionarray for each day
745  $daycursor = $event->date_start_in_calendar;
746  $annee = dol_print_date($daycursor, '%Y', 'tzuserrel');
747  $mois = dol_print_date($daycursor, '%m', 'tzuserrel');
748  $jour = dol_print_date($daycursor, '%d', 'tzuserrel');
749  //print $daycursor.' '.dol_print_date($daycursor, 'dayhour', 'gmt').' '.$event->id.' -> '.$annee.'-'.$mois.'-'.$jour.'<br>';
750 
751  // Loop on each day covered by action to prepare an index to show on calendar
752  $loop = true;
753  $j = 0;
754  $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
755  do {
756  //print 'Add event into eventarray for daykey='.$daykey.'='.dol_print_date($daykey, 'dayhour', 'gmt').' '.$event->id.' '.$event->datep.' '.$event->datef.'<br>';
757 
758  $eventarray[$daykey][] = $event;
759  $j++;
760 
761  $daykey += 60 * 60 * 24;
762  if ($daykey > $event->date_end_in_calendar) {
763  $loop = false;
764  }
765  } while ($loop);
766 
767  //print 'Event '.$i.' id='.$event->id.' (start='.dol_print_date($event->datep).'-end='.dol_print_date($event->datef);
768  //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>';
769  }
770  $i++;
771  }
772  $db->free($resql);
773 } else {
774  dol_print_error($db);
775 }
776 
777 $maxnbofchar = 18;
778 $cachethirdparties = array();
779 $cachecontacts = array();
780 $cacheusers = array();
781 
782 // Define theme_datacolor array
783 $color_file = DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/theme_vars.inc.php";
784 if (is_readable($color_file)) {
785  include $color_file;
786 }
787 if (!is_array($theme_datacolor)) {
788  $theme_datacolor = array(array(120, 130, 150), array(200, 160, 180), array(190, 190, 220));
789 }
790 
791 
792 $newparam = $param; // newparam is for birthday links
793 $newparam = preg_replace('/showbirthday=/i', 'showbirthday_=', $newparam); // To avoid replacement when replace day= is done
794 $newparam = preg_replace('/mode=show_month&?/i', '', $newparam);
795 $newparam = preg_replace('/mode=show_week&?/i', '', $newparam);
796 $newparam = preg_replace('/day=[0-9]+&?/i', '', $newparam);
797 $newparam = preg_replace('/month=[0-9]+&?/i', '', $newparam);
798 $newparam = preg_replace('/year=[0-9]+&?/i', '', $newparam);
799 $newparam = preg_replace('/viewweek=[0-9]+&?/i', '', $newparam);
800 $newparam = preg_replace('/showbirthday_=/i', 'showbirthday=', $newparam); // Restore correct parameter
801 $newparam .= '&viewweek=1';
802 
803 echo '<input type="hidden" name="actionmove" value="mupdate">';
804 echo '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($_SERVER['PHP_SELF']).'?'.dol_escape_htmltag($_SERVER['QUERY_STRING']).'">';
805 echo '<input type="hidden" name="newdate" id="newdate">';
806 
807 
808 // Line header with list of days
809 
810 //print "begin_d=".$begin_d." end_d=".$end_d;
811 
812 $currentdaytoshow = $firstdaytoshow;
813 echo '<div class="div-table-responsive">';
814 //print dol_print_date($currentdaytoshow, 'dayhour', 'gmt');
815 
816 while ($currentdaytoshow < $lastdaytoshow) {
817  echo '<table class="centpercent noborder nocellnopadd cal_month">';
818 
819  echo '<tr class="liste_titre">';
820  echo '<td class="nopaddingtopimp nopaddingbottomimp nowraponsmartphone">';
821 
822  if ($canedit && $mode == 'show_peruser') {
823  // Filter on hours
824  print img_picto('', 'clock', 'class="fawidth30 inline-block paddingleft"');
825  print '<span class="hideonsmartphone" title="'.$langs->trans("VisibleTimeRange").'">'.$langs->trans("Hours").'</span>';
826  print "\n".'<div class="ui-grid-a inline-block"><div class="ui-block-a nowraponall">';
827  print '<input type="number" class="short" name="begin_h" value="'.$begin_h.'" min="0" max="23">';
828  if (empty($conf->dol_use_jmobile)) {
829  print ' - ';
830  } else {
831  print '</div><div class="ui-block-b">';
832  }
833  print '<input type="number" class="short" name="end_h" value="'.$end_h.'" min="1" max="24">';
834  if (empty($conf->dol_use_jmobile)) {
835  print ' '.$langs->trans("H");
836  }
837  print '</div></div>';
838 
839  print '<br>';
840 
841  // Filter on days
842  print img_picto('', 'clock', 'class="fawidth30 inline-block paddingleft"');
843  print '<span class="hideonsmartphone" title="'.$langs->trans("VisibleDaysRange").'">'.$langs->trans("DaysOfWeek").'</span>';
844  print "\n".'<div class="ui-grid-a inline-block"><div class="ui-block-a nowraponall">';
845  print '<input type="number" class="short" name="begin_d" value="'.$begin_d.'" min="1" max="7">';
846  if (empty($conf->dol_use_jmobile)) {
847  print ' - ';
848  } else {
849  print '</div><div class="ui-block-b">';
850  }
851  print '<input type="number" class="short" name="end_d" value="'.$end_d.'" min="1" max="7">';
852  print '</div></div>';
853  }
854 
855  print '</td>';
856  $i = 0; // 0 = sunday,
857  while ($i < 7) {
858  if (($i + 1) < $begin_d || ($i + 1) > $end_d) {
859  $i++;
860  continue;
861  }
862  echo '<td align="center" colspan="'.($end_h - $begin_h).'">';
863  echo '<span class="bold spandayofweek">'.$langs->trans("Day".(($i + (isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1)) % 7)).'</span>';
864  print "<br>";
865  if ($i) {
866  print dol_print_date(dol_time_plus_duree($currentdaytoshow, $i, 'd'), 'day', 'tzuserrel');
867  } else {
868  print dol_print_date($currentdaytoshow, 'day', 'tzuserrel');
869  }
870  echo "</td>\n";
871  $i++;
872  }
873  echo "</tr>\n";
874 
875  echo '<tr class="liste_titre">';
876  echo '<td></td>';
877  $i = 0;
878  while ($i < 7) {
879  if (($i + 1) < $begin_d || ($i + 1) > $end_d) {
880  $i++;
881  continue;
882  }
883  for ($h = $begin_h; $h < $end_h; $h++) {
884  echo '<td class="center">';
885  print '<small style="font-family: courier">'.sprintf("%02d", $h).'</small>';
886  print "</td>";
887  }
888  echo "</td>\n";
889  $i++;
890  }
891  echo "</tr>\n";
892 
893 
894  // Define $usernames
895  $usernames = array(); //init
896  $usernamesid = array();
897  /* Use this to have list of users only if users have events */
898  if (getDolGlobalString('AGENDA_SHOWOWNERONLY_ONPERUSERVIEW')) {
899  foreach ($eventarray as $daykey => $notused) {
900  // Get all assigned users for each event
901  foreach ($eventarray[$daykey] as $index => $event) {
902  $event->fetch_userassigned();
903  $listofuserid = $event->userassigned;
904  foreach ($listofuserid as $userid => $tmp) {
905  if (!in_array($userid, $usernamesid)) {
906  $usernamesid[$userid] = $userid;
907  }
908  }
909  }
910  }
911  } else {
912  /* Use this list to have for all users */
913  $sql = "SELECT u.rowid, u.lastname as lastname, u.firstname, u.statut, u.login, u.admin, u.entity";
914  $sql .= " FROM ".$db->prefix()."user as u";
915  if (isModEnabled('multicompany') && getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE')) {
916  $sql .= " WHERE u.rowid IN (";
917  $sql .= " SELECT ug.fk_user FROM ".$db->prefix()."usergroup_user as ug";
918  $sql .= " WHERE ug.entity IN (".getEntity('usergroup').")";
919  if ($usergroup > 0) {
920  $sql .= " AND ug.fk_usergroup = ".((int) $usergroup);
921  }
922  $sql .= ")";
923  } else {
924  if ($usergroup > 0) {
925  $sql .= " LEFT JOIN ".$db->prefix()."usergroup_user as ug ON u.rowid = ug.fk_user";
926  }
927  $sql .= " WHERE u.entity IN (".getEntity('user').")";
928  if ($usergroup > 0) {
929  $sql .= " AND ug.fk_usergroup = ".((int) $usergroup);
930  }
931  }
932  $sql .= " AND u.statut = 1";
933  if ($filtert > 0) {
934  $sql .= " AND u.rowid = ".((int) $filtert);
935  }
936  if ($usergroup > 0) {
937  $sql .= " AND ug.fk_usergroup = ".((int) $usergroup);
938  }
939  if ($user->socid > 0) {
940  // External users should see only contacts of their company
941  $sql .= " AND u.fk_soc = ".((int) $user->socid);
942  }
943 
944  //print $sql;
945  $resql = $db->query($sql);
946  if ($resql) {
947  $num = $db->num_rows($resql);
948  $i = 0;
949  if ($num) {
950  while ($i < $num) {
951  $obj = $db->fetch_object($resql);
952  $usernamesid[$obj->rowid] = $obj->rowid;
953  $i++;
954  }
955  }
956  } else {
957  dol_print_error($db);
958  }
959  }
960  //var_dump($usernamesid);
961  foreach ($usernamesid as $id) {
962  $tmpuser = new User($db);
963  $result = $tmpuser->fetch($id);
964  $usernames[] = $tmpuser;
965  }
966 
967  // Load array of colors by type
968  $colorsbytype = array();
969  $labelbytype = array();
970  $sql = "SELECT code, color, libelle as label FROM ".MAIN_DB_PREFIX."c_actioncomm ORDER BY position";
971  $resql = $db->query($sql);
972  while ($obj = $db->fetch_object($resql)) {
973  $colorsbytype[$obj->code] = $obj->color;
974  $labelbytype[$obj->code] = $obj->label;
975  }
976 
977  // Loop on each user to show calendar
978  $todayarray = dol_getdate($now, 'fast');
979  $sav = $tmpday;
980  $showheader = true;
981  $var = false;
982  foreach ($usernames as $username) {
983  //if ($username->login != 'admin') continue;
984 
985  $var = !$var;
986  echo "<tr>";
987  echo '<td class="tdoverflowmax100 cal_current_month cal_peruserviewname'.($var ? ' cal_impair' : '').'">';
988  print $username->getNomUrl(-1, '', 0, 0, 20, 1, '', 'paddingleft');
989  print '</td>';
990  $tmpday = $sav;
991 
992  // Lopp on each day of week
993  $i = 0;
994  for ($iter_day = 0; $iter_day < 8; $iter_day++) {
995  if (($i + 1) < $begin_d || ($i + 1) > $end_d) {
996  $i++;
997  continue;
998  }
999 
1000  // Show days of the current week
1001  $curtime = dol_time_plus_duree($currentdaytoshow, $iter_day, 'd');
1002  // $curtime is a gmt time, but we want the day, month, year in user TZ
1003  $tmpday = dol_print_date($curtime, "%d", "tzuserrel");
1004  $tmpmonth = dol_print_date($curtime, "%m", "tzuserrel");
1005  $tmpyear = dol_print_date($curtime, "%Y", "tzuserrel");
1006  //var_dump($curtime.' '.$tmpday.' '.$tmpmonth.' '.$tmpyear);
1007 
1008  $style = 'cal_current_month';
1009  if ($iter_day == 6) {
1010  $style .= ' cal_other_month';
1011  }
1012  $today = 0;
1013  if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $tmpmonth && $todayarray['year'] == $tmpyear) {
1014  $today = 1;
1015  }
1016  if ($today) {
1017  $style = 'cal_today_peruser';
1018  }
1019 
1020  show_day_events2($username, $tmpday, $tmpmonth, $tmpyear, 0, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, $showheader, $colorsbytype, $var);
1021 
1022  $i++;
1023  }
1024  echo "</tr>\n";
1025  $showheader = false;
1026  }
1027 
1028  echo "</table>\n";
1029  echo "<br>";
1030 
1031  $currentdaytoshow = dol_time_plus_duree($currentdaytoshow, 7, 'd');
1032 }
1033 
1034 echo '</div>';
1035 
1036 if (getDolGlobalString('AGENDA_USE_EVENT_TYPE') && getDolGlobalString('AGENDA_USE_COLOR_PER_EVENT_TYPE')) {
1037  $langs->load("commercial");
1038  print '<br>'.$langs->trans("Legend").': <br>';
1039  foreach ($colorsbytype as $code => $color) {
1040  if ($color) {
1041  print '<div style="float: left; padding: 2px; margin-right: 6px;"><div style="'.($color ? 'background: #'.$color.';' : '').'width:16px; float: left; margin-right: 4px;">&nbsp;</div>';
1042  print $langs->trans("Action".$code) != "Action".$code ? $langs->trans("Action".$code) : $labelbytype[$code];
1043  //print $code;
1044  print '</div>';
1045  }
1046  }
1047  //$color=sprintf("%02x%02x%02x",$theme_datacolor[0][0],$theme_datacolor[0][1],$theme_datacolor[0][2]);
1048  print '<div style="float: left; padding: 2px; margin-right: 6px;"><div class="peruser_busy" style="width:16px; float: left; margin-right: 4px;">&nbsp;</div>';
1049  print $langs->trans("Other");
1050  print '</div>';
1051  /* TODO Show this if at least one cumulated event
1052  print '<div style="float: left; padding: 2px; margin-right: 6px;"><div style="background: #222222; width:16px; float: left; margin-right: 4px;">&nbsp;</div>';
1053  print $langs->trans("SeveralEvents");
1054  print '</div>';
1055  */
1056 }
1057 
1058 print "\n".'</form>';
1059 print "\n";
1060 
1061 // Add js code to manage click on a box
1062 print '<script type="text/javascript">
1063 jQuery(document).ready(function() {
1064  jQuery(".onclickopenref").click(function() {
1065  console.log("We click on a class onclickopenref");
1066 
1067  var ref=$(this).attr(\'ref\');
1068  var res = ref.split("_");
1069  var userid = res[1];
1070  var year = res[2];
1071  var month = res[3];
1072  var day = res[4];
1073  var hour = res[5];
1074  var min = res[6];
1075  var ids = res[7];
1076  if (ids == \'none\') /* No event */
1077  {
1078  /* alert(\'no event\'); */
1079  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 : '')).'"
1080  window.location.href = url;
1081  }
1082  else if (ids.indexOf(",") > -1) /* There is several events */
1083  {
1084  /* alert(\'several events\'); */
1085  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;
1086  window.location.href = url;
1087  }
1088  else /* One event */
1089  {
1090  /* alert(\'one event\'); */
1091  url = "'.DOL_URL_ROOT.'/comm/action/card.php?action=view&id="+ids
1092  window.location.href = url;
1093  }
1094  });
1095 });
1096 </script>';
1097 
1098 // End of page
1099 llxFooter();
1100 $db->close();
1101 
1102 
1103 
1104 
1125 function 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)
1126 {
1127  global $db;
1128  global $user, $conf, $langs, $hookmanager, $action;
1129  global $filter, $filtert, $status, $actioncode; // Filters used into search form
1130  global $theme_datacolor; // Array with a list of different we can use (come from theme)
1131  global $cachethirdparties, $cachecontacts, $cacheusers, $cacheprojects, $colorindexused;
1132  global $begin_h, $end_h;
1133 
1134  $cases1 = array(); // Color first half hour
1135  $cases2 = array(); // Color second half hour
1136  $cases3 = array(); // Color third half hour
1137  $cases4 = array(); // Color 4th half hour
1138 
1139  $i = 0;
1140  $numother = 0;
1141  $numbirthday = 0;
1142  $numical = 0;
1143  $numicals = array();
1144  //$ymd = sprintf("%04d", $year).sprintf("%02d", $month).sprintf("%02d", $day);
1145 
1146  $colorindexused[$user->id] = 0; // Color index for current user (user->id) is always 0
1147  $nextindextouse = count($colorindexused); // At first run this is 0, so first user has 0, next 1, ...
1148  //if ($username->id && $day==1) {
1149  //var_dump($eventarray);
1150  //}
1151  //var_dump("------ username=".$username->login." for day=".$day);
1152 
1153  // We are in a particular day for $username, now we scan all events
1154  foreach ($eventarray as $daykey => $notused) {
1155  $annee = dol_print_date($daykey, '%Y', 'tzuserrel');
1156  $mois = dol_print_date($daykey, '%m', 'tzuserrel');
1157  $jour = dol_print_date($daykey, '%d', 'tzuserrel');
1158  //var_dump("daykey=$daykey day=$day jour=$jour, month=$month mois=$mois, year=$year annee=$annee");
1159 
1160 
1161  if ($day == $jour && (int) $month == (int) $mois && $year == $annee) { // Is it the day we are looking for when calling function ?
1162  //var_dump("day=$day jour=$jour month=$month mois=$mois year=$year annee=$annee");
1163 
1164  // Scan all event for this date
1165  foreach ($eventarray[$daykey] as $index => $event) {
1166  //print 'daykey='.$daykey.'='.dol_print_date($daykey, 'dayhour', 'gmt').' '.$year.'-'.$month.'-'.$day.' -> This event: '.$event->id.' '.$index.' is open for this daykey '.$annee.'-'.$mois.'-'.$jour."<br>\n";
1167  //var_dump($event);
1168 
1169  $keysofuserassigned = array_keys($event->userassigned);
1170  $ponct = ($event->date_start_in_calendar == $event->date_end_in_calendar);
1171 
1172  if (!in_array($username->id, $keysofuserassigned)) {
1173  continue; // We discard record if event is from another user than user we want to show
1174  }
1175  //if ($username->id != $event->userownerid) continue; // We discard record if event is from another user than user we want to show
1176 
1177  $parameters = array();
1178  $reshook = $hookmanager->executeHooks('formatEvent', $parameters, $event, $action); // Note that $action and $object may have been modified by some hooks
1179  if ($reshook < 0) {
1180  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1181  }
1182 
1183  // Define $color (Hex string like '0088FF') and $cssclass of event
1184  $color = -1;
1185  $cssclass = '';
1186  $colorindex = -1;
1187  if (in_array($user->id, $keysofuserassigned)) {
1188  $cssclass = 'family_mytasks';
1189 
1190  if (empty($cacheusers[$event->userownerid])) {
1191  $newuser = new User($db);
1192  $newuser->fetch($event->userownerid);
1193  $cacheusers[$event->userownerid] = $newuser;
1194  }
1195  //var_dump($cacheusers[$event->userownerid]->color);
1196 
1197  // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
1198  if (!empty($cacheusers[$event->userownerid]->color)) {
1199  $color = $cacheusers[$event->userownerid]->color;
1200  }
1201 
1202  if (getDolGlobalString('AGENDA_USE_COLOR_PER_EVENT_TYPE')) {
1203  $color = $event->type_color;
1204  }
1205  } elseif ($event->type_code == 'ICALEVENT') {
1206  $numical++;
1207  if (!empty($event->icalname)) {
1208  if (!isset($numicals[dol_string_nospecial($event->icalname)])) {
1209  $numicals[dol_string_nospecial($event->icalname)] = 0;
1210  }
1211  $numicals[dol_string_nospecial($event->icalname)]++;
1212  }
1213 
1214  $color = $event->icalcolor;
1215  $cssclass = (!empty($event->icalname) ? 'family_ext'.md5($event->icalname) : 'family_other unsortable');
1216  } elseif ($event->type_code == 'BIRTHDAY') {
1217  $numbirthday++;
1218  $colorindex = 2;
1219  $cssclass = 'family_birthday unsortable';
1220  $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
1221  } else {
1222  $numother++;
1223  $color = ($event->icalcolor ? $event->icalcolor : -1);
1224  $cssclass = (!empty($event->icalname) ? 'family_ext'.md5($event->icalname) : 'family_other');
1225 
1226  if (empty($cacheusers[$event->userownerid])) {
1227  $newuser = new User($db);
1228  $newuser->fetch($event->userownerid);
1229  $cacheusers[$event->userownerid] = $newuser;
1230  }
1231  //var_dump($cacheusers[$event->userownerid]->color);
1232 
1233  // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
1234  if (!empty($cacheusers[$event->userownerid]->color)) {
1235  $color = $cacheusers[$event->userownerid]->color;
1236  }
1237 
1238  if (getDolGlobalString('AGENDA_USE_COLOR_PER_EVENT_TYPE')) {
1239  $color = $event->type_color;
1240  }
1241  }
1242 
1243  if ($color < 0) { // Color was not set on user card. Set color according to color index.
1244  // Define color index if not yet defined
1245  $idusertouse = ($event->userownerid ? $event->userownerid : 0);
1246  if (isset($colorindexused[$idusertouse])) {
1247  $colorindex = $colorindexused[$idusertouse]; // Color already assigned to this user
1248  } else {
1249  $colorindex = $nextindextouse;
1250  $colorindexused[$idusertouse] = $colorindex;
1251  if (!empty($theme_datacolor[$nextindextouse + 1])) {
1252  $nextindextouse++; // Prepare to use next color
1253  }
1254  }
1255  // Define color
1256  $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
1257  }
1258 
1259  // 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)
1260  for ($h = $begin_h; $h < $end_h; $h++) {
1261  //if ($username->id == 1 && $day==1) print 'h='.$h;
1262  $newcolor = ''; //init
1263  if (empty($event->fulldayevent)) {
1264  $a = dol_mktime((int) $h, 0, 0, $month, $day, $year, 'tzuserrel', 0);
1265  $b = dol_mktime((int) $h, 15, 0, $month, $day, $year, 'tzuserrel', 0);
1266  $b1 = dol_mktime((int) $h, 30, 0, $month, $day, $year, 'tzuserrel', 0);
1267  $b2 = dol_mktime((int) $h, 45, 0, $month, $day, $year, 'tzuserrel', 0);
1268  $c = dol_mktime((int) $h + 1, 0, 0, $month, $day, $year, 'tzuserrel', 0);
1269 
1270  $dateendtouse = $event->date_end_in_calendar;
1271  if ($dateendtouse == $event->date_start_in_calendar) {
1272  $dateendtouse++;
1273  }
1274 
1275  //print dol_print_date($event->date_start_in_calendar,'dayhour').'-'.dol_print_date($a,'dayhour').'-'.dol_print_date($b,'dayhour').'<br>';
1276 
1277  if ($event->date_start_in_calendar < $b && $dateendtouse > $a) {
1278  $busy = $event->transparency;
1279  $cases1[$h][$event->id]['busy'] = $busy;
1280  $cases1[$h][$event->id]['string'] = dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzuserrel');
1281  if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) {
1282  $tmpa = dol_getdate($event->date_start_in_calendar, true);
1283  $tmpb = dol_getdate($event->date_end_in_calendar, true);
1284  if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
1285  $cases1[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel');
1286  } else {
1287  $cases1[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzuserrel');
1288  }
1289  }
1290  if ($event->label) {
1291  $cases1[$h][$event->id]['string'] .= ' - '.$event->label;
1292  }
1293  $cases1[$h][$event->id]['typecode'] = $event->type_code;
1294  $cases1[$h][$event->id]['color'] = $color;
1295  if ($event->fk_project > 0) {
1296  if (empty($cacheprojects[$event->fk_project])) {
1297  $tmpproj = new Project($db);
1298  $tmpproj->fetch($event->fk_project);
1299  $cacheprojects[$event->fk_project] = $tmpproj;
1300  }
1301  $cases1[$h][$event->id]['string'] .= ', '.$langs->trans("Project").': '.$cacheprojects[$event->fk_project]->ref.' - '.$cacheprojects[$event->fk_project]->title;
1302  }
1303  if ($event->socid > 0) {
1304  if (empty($cachethirdparties[$event->socid])) {
1305  $tmpthirdparty = new Societe($db);
1306  $tmpthirdparty->fetch($event->socid);
1307  $cachethirdparties[$event->socid] = $tmpthirdparty;
1308  }
1309  $cases1[$h][$event->id]['string'] .= ', '.$cachethirdparties[$event->socid]->name;
1310  }
1311  if ($event->contact_id > 0) {
1312  if (empty($cachecontacts[$event->contact_id])) {
1313  $tmpcontact = new Contact($db);
1314  $tmpcontact->fetch($event->contact_id);
1315  $cachecontacts[$event->contact_id] = $tmpcontact;
1316  }
1317  $cases1[$h][$event->id]['string'] .= ', '.$cachecontacts[$event->contact_id]->getFullName($langs);
1318  }
1319  }
1320  if ($event->date_start_in_calendar < $b1 && $dateendtouse > $b) {
1321  $busy = $event->transparency;
1322  $cases2[$h][$event->id]['busy'] = $busy;
1323  $cases2[$h][$event->id]['string'] = dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzuserrel');
1324  if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) {
1325  $tmpa = dol_getdate($event->date_start_in_calendar, true);
1326  $tmpb = dol_getdate($event->date_end_in_calendar, true);
1327  if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
1328  $cases2[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel');
1329  } else {
1330  $cases2[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzuserrel');
1331  }
1332  }
1333  if ($event->label) {
1334  $cases2[$h][$event->id]['string'] .= ' - '.$event->label;
1335  }
1336  $cases2[$h][$event->id]['typecode'] = $event->type_code;
1337  $cases2[$h][$event->id]['color'] = $color;
1338  if ($event->fk_project > 0) {
1339  if (empty($cacheprojects[$event->fk_project])) {
1340  $tmpproj = new Project($db);
1341  $tmpproj->fetch($event->fk_project);
1342  $cacheprojects[$event->fk_project] = $tmpproj;
1343  }
1344  $cases2[$h][$event->id]['string'] .= ', '.$langs->trans("Project").': '.$cacheprojects[$event->fk_project]->ref.' - '.$cacheprojects[$event->fk_project]->title;
1345  }
1346  if ($event->socid > 0) {
1347  if (empty($cachethirdparties[$event->socid])) {
1348  $tmpthirdparty = new Societe($db);
1349  $tmpthirdparty->fetch($event->socid);
1350  $cachethirdparties[$event->socid] = $tmpthirdparty;
1351  }
1352  $cases2[$h][$event->id]['string'] .= ', '.$cachethirdparties[$event->socid]->name;
1353  }
1354  if ($event->contact_id > 0) {
1355  if (empty($cachecontacts[$event->contact_id])) {
1356  $tmpcontact = new Contact($db);
1357  $tmpcontact->fetch($event->contact_id);
1358  $cachecontacts[$event->contact_id] = $tmpcontact;
1359  }
1360  $cases2[$h][$event->id]['string'] .= ', '.$cachecontacts[$event->contact_id]->getFullName($langs);
1361  }
1362  }
1363  if ($event->date_start_in_calendar < $b2 && $dateendtouse > $b1) {
1364  $busy = $event->transparency;
1365  $cases3[$h][$event->id]['busy'] = $busy;
1366  $cases3[$h][$event->id]['string'] = dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzuserrel');
1367  if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) {
1368  $tmpa = dol_getdate($event->date_start_in_calendar, true);
1369  $tmpb = dol_getdate($event->date_end_in_calendar, true);
1370  if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
1371  $cases3[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel');
1372  } else {
1373  $cases3[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzuserrel');
1374  }
1375  }
1376  if ($event->label) {
1377  $cases3[$h][$event->id]['string'] .= ' - '.$event->label;
1378  }
1379  $cases3[$h][$event->id]['typecode'] = $event->type_code;
1380  $cases3[$h][$event->id]['color'] = $color;
1381  if ($event->fk_project > 0) {
1382  if (empty($cacheprojects[$event->fk_project])) {
1383  $tmpproj = new Project($db);
1384  $tmpproj->fetch($event->fk_project);
1385  $cacheprojects[$event->fk_project] = $tmpproj;
1386  }
1387  $cases3[$h][$event->id]['string'] .= ', '.$langs->trans("Project").': '.$cacheprojects[$event->fk_project]->ref.' - '.$cacheprojects[$event->fk_project]->title;
1388  }
1389  if ($event->socid > 0) {
1390  if (empty($cachethirdparties[$event->socid])) {
1391  $tmpthirdparty = new Societe($db);
1392  $tmpthirdparty->fetch($event->socid);
1393  $cachethirdparties[$event->socid] = $tmpthirdparty;
1394  }
1395  $cases3[$h][$event->id]['string'] .= ', '.$cachethirdparties[$event->socid]->name;
1396  }
1397  if ($event->contact_id > 0) {
1398  if (empty($cachecontacts[$event->contact_id])) {
1399  $tmpcontact = new Contact($db);
1400  $tmpcontact->fetch($event->contact_id);
1401  $cachecontacts[$event->contact_id] = $tmpcontact;
1402  }
1403  $cases2[$h][$event->id]['string'] .= ', '.$cachecontacts[$event->contact_id]->getFullName($langs);
1404  }
1405  }
1406  if ($event->date_start_in_calendar < $c && $dateendtouse > $b2) {
1407  $busy = $event->transparency;
1408  $cases4[$h][$event->id]['busy'] = $busy;
1409  $cases4[$h][$event->id]['string'] = dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzuserrel');
1410  if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) {
1411  $tmpa = dol_getdate($event->date_start_in_calendar, true);
1412  $tmpb = dol_getdate($event->date_end_in_calendar, true);
1413  if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
1414  $cases4[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel');
1415  } else {
1416  $cases4[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzuserrel');
1417  }
1418  }
1419  if ($event->label) {
1420  $cases4[$h][$event->id]['string'] .= ' - '.$event->label;
1421  }
1422  $cases4[$h][$event->id]['typecode'] = $event->type_code;
1423  $cases4[$h][$event->id]['color'] = $color;
1424  if ($event->fk_project > 0) {
1425  if (empty($cacheprojects[$event->fk_project])) {
1426  $tmpproj = new Project($db);
1427  $tmpproj->fetch($event->fk_project);
1428  $cacheprojects[$event->fk_project] = $tmpproj;
1429  }
1430  $cases4[$h][$event->id]['string'] .= ', '.$langs->trans("Project").': '.$cacheprojects[$event->fk_project]->ref.' - '.$cacheprojects[$event->fk_project]->title;
1431  }
1432  if ($event->socid > 0) {
1433  if (empty($cachethirdparties[$event->socid])) {
1434  $tmpthirdparty = new Societe($db);
1435  $tmpthirdparty->fetch($event->socid);
1436  $cachethirdparties[$event->socid] = $tmpthirdparty;
1437  }
1438  $cases4[$h][$event->id]['string'] .= ', '.$cachethirdparties[$event->socid]->name;
1439  }
1440  if ($event->contact_id > 0) {
1441  if (empty($cachecontacts[$event->contact_id])) {
1442  $tmpcontact = new Contact($db);
1443  $tmpcontact->fetch($event->contact_id);
1444  $cachecontacts[$event->contact_id] = $tmpcontact;
1445  }
1446  $cases4[$h][$event->id]['string'] .= ', '.$cachecontacts[$event->contact_id]->getFullName($langs);
1447  }
1448  }
1449  } else {
1450  $busy = $event->transparency;
1451  $cases1[$h][$event->id]['busy'] = $busy;
1452  $cases2[$h][$event->id]['busy'] = $busy;
1453  $cases3[$h][$event->id]['busy'] = $busy;
1454  $cases4[$h][$event->id]['busy'] = $busy;
1455  $cases1[$h][$event->id]['string'] = $event->label;
1456  $cases2[$h][$event->id]['string'] = $event->label;
1457  $cases3[$h][$event->id]['string'] = $event->label;
1458  $cases4[$h][$event->id]['string'] = $event->label;
1459  $cases1[$h][$event->id]['typecode'] = $event->type_code;
1460  $cases2[$h][$event->id]['typecode'] = $event->type_code;
1461  $cases3[$h][$event->id]['typecode'] = $event->type_code;
1462  $cases4[$h][$event->id]['typecode'] = $event->type_code;
1463  $cases1[$h][$event->id]['color'] = $color;
1464  $cases2[$h][$event->id]['color'] = $color;
1465  $cases3[$h][$event->id]['color'] = $color;
1466  $cases4[$h][$event->id]['color'] = $color;
1467  }
1468  }
1469  $i++;
1470  }
1471 
1472  break; // We found the date we were looking for. No need to search anymore.
1473  }
1474  }
1475 
1476  // Now output $casesX from start hour to end hour
1477  for ($h = $begin_h; $h < $end_h; $h++) {
1478  $color1 = '';
1479  $color2 = '';
1480  $color3 = '';
1481  $color4 = '';
1482  $style1 = '';
1483  $style2 = '';
1484  $style3 = '';
1485  $style4 = '';
1486  $string1 = '&nbsp;';
1487  $string2 = '&nbsp;';
1488  $string3 = '&nbsp;';
1489  $string4 = '&nbsp;';
1490  $title1 = '';
1491  $title2 = '';
1492  $title3 = '';
1493  $title4 = '';
1494  if (isset($cases1[$h]) && $cases1[$h] != '') {
1495  //$title1.=count($cases1[$h]).' '.(count($cases1[$h])==1?$langs->trans("Event"):$langs->trans("Events"));
1496  if (count($cases1[$h]) > 1) {
1497  $title1 .= count($cases1[$h]).' '.(count($cases1[$h]) == 1 ? $langs->trans("Event") : $langs->trans("Events"));
1498  }
1499 
1500  if (!getDolGlobalString('AGENDA_NO_TRANSPARENT_ON_NOT_BUSY')) {
1501  $style1 = 'peruser_notbusy';
1502  } else {
1503  $style1 = 'peruser_busy';
1504  }
1505  foreach ($cases1[$h] as $id => $ev) {
1506  if ($ev['busy']) {
1507  $style1 = 'peruser_busy';
1508  }
1509  }
1510  }
1511  if (isset($cases2[$h]) && $cases2[$h] != '') {
1512  //$title2.=count($cases2[$h]).' '.(count($cases2[$h])==1?$langs->trans("Event"):$langs->trans("Events"));
1513  if (count($cases2[$h]) > 1) {
1514  $title2 .= count($cases2[$h]).' '.(count($cases2[$h]) == 1 ? $langs->trans("Event") : $langs->trans("Events"));
1515  }
1516 
1517  if (!getDolGlobalString('AGENDA_NO_TRANSPARENT_ON_NOT_BUSY')) {
1518  $style2 = 'peruser_notbusy';
1519  } else {
1520  $style2 = 'peruser_busy';
1521  }
1522  foreach ($cases2[$h] as $id => $ev) {
1523  if ($ev['busy']) {
1524  $style2 = 'peruser_busy';
1525  }
1526  }
1527  }
1528  if (isset($cases3[$h]) && $cases3[$h] != '') {
1529  //$title3.=count($cases3[$h]).' '.(count($cases3[$h])==1?$langs->trans("Event"):$langs->trans("Events"));
1530  if (count($cases3[$h]) > 1) {
1531  $title3 .= count($cases3[$h]).' '.(count($cases3[$h]) == 1 ? $langs->trans("Event") : $langs->trans("Events"));
1532  }
1533 
1534  if (!getDolGlobalString('AGENDA_NO_TRANSPARENT_ON_NOT_BUSY')) {
1535  $style3 = 'peruser_notbusy';
1536  } else {
1537  $style3 = 'peruser_busy';
1538  }
1539  foreach ($cases3[$h] as $id => $ev) {
1540  if ($ev['busy']) {
1541  $style3 = 'peruser_busy';
1542  }
1543  }
1544  }
1545  if (isset($cases4[$h]) && $cases4[$h] != '') {
1546  //$title4.=count($cases3[$h]).' '.(count($cases3[$h])==1?$langs->trans("Event"):$langs->trans("Events"));
1547  if (count($cases4[$h]) > 1) {
1548  $title4 .= count($cases4[$h]).' '.(count($cases4[$h]) == 1 ? $langs->trans("Event") : $langs->trans("Events"));
1549  }
1550 
1551  if (!getDolGlobalString('AGENDA_NO_TRANSPARENT_ON_NOT_BUSY')) {
1552  $style4 = 'peruser_notbusy';
1553  } else {
1554  $style4 = 'peruser_busy';
1555  }
1556  foreach ($cases4[$h] as $id => $ev) {
1557  if ($ev['busy']) {
1558  $style4 = 'peruser_busy';
1559  }
1560  }
1561  }
1562 
1563  $ids1 = '';
1564  $ids2 = '';
1565  $ids3 = '';
1566  $ids4 = '';
1567  if (!empty($cases1[$h]) && is_array($cases1[$h]) && count($cases1[$h]) && array_keys($cases1[$h])) {
1568  $ids1 = implode(', ', array_keys($cases1[$h]));
1569  }
1570  if (!empty($cases2[$h]) && is_array($cases2[$h]) && count($cases2[$h]) && array_keys($cases2[$h])) {
1571  $ids2 = implode(', ', array_keys($cases2[$h]));
1572  }
1573  if (!empty($cases3[$h]) && is_array($cases3[$h]) && count($cases3[$h]) && array_keys($cases3[$h])) {
1574  $ids3 = implode(',', array_keys($cases3[$h]));
1575  }
1576  if (!empty($cases4[$h]) && is_array($cases4[$h]) && count($cases4[$h]) && array_keys($cases4[$h])) {
1577  $ids4 = implode(',', array_keys($cases4[$h]));
1578  }
1579 
1580  if ($h == $begin_h) {
1581  echo '<td class="'.$style.'_peruserleft cal_peruser'.($var ? ' cal_impair '.$style.'_impair' : '').'">';
1582  } else {
1583  echo '<td class="'.$style.' cal_peruser'.($var ? ' cal_impair '.$style.'_impair' : '').'">';
1584  }
1585  // only 1 event
1586  if (!empty($cases1[$h]) && is_array($cases1[$h]) && count($cases1[$h]) == 1) {
1587  $output = array_slice($cases1[$h], 0, 1);
1588  $title1 = $langs->trans("Ref").' '.$ids1.($title1 ? ' - '.$title1 : '');
1589  if ($output[0]['string']) {
1590  $title1 .= ($title1 ? ' - ' : '').$output[0]['string'];
1591  }
1592  if ($output[0]['color']) {
1593  $color1 = $output[0]['color'];
1594  }
1595  } elseif (!empty($cases1[$h]) && is_array($cases1[$h]) && count($cases1[$h]) > 1) {
1596  $title1 = $langs->trans("Ref").' '.$ids1.($title1 ? ' - '.$title1 : '');
1597  $color1 = '222222';
1598  }
1599 
1600  // only 1 event
1601  if (!empty($cases2[$h]) && is_array($cases2[$h]) && count($cases2[$h]) == 1) {
1602  $output = array_slice($cases2[$h], 0, 1);
1603  $title2 = $langs->trans("Ref").' '.$ids2.($title2 ? ' - '.$title2 : '');
1604  if ($output[0]['string']) {
1605  $title2 .= ($title2 ? ' - ' : '').$output[0]['string'];
1606  }
1607  if ($output[0]['color']) {
1608  $color2 = $output[0]['color'];
1609  }
1610  } elseif (!empty($cases2[$h]) && is_array($cases2[$h]) && count($cases2[$h]) > 1) {
1611  $title2 = $langs->trans("Ref").' '.$ids2.($title2 ? ' - '.$title2 : '');
1612  $color2 = '222222';
1613  }
1614 
1615  // only 1 event
1616  if (!empty($cases3[$h]) && is_array($cases3[$h]) && count($cases3[$h]) == 1) {
1617  $output = array_slice($cases3[$h], 0, 1);
1618  $title3 = $langs->trans("Ref").' '.$ids3.($title3 ? ' - '.$title3 : '');
1619  if ($output[0]['string']) {
1620  $title3 .= ($title3 ? ' - ' : '').$output[0]['string'];
1621  }
1622  if ($output[0]['color']) {
1623  $color3 = $output[0]['color'];
1624  }
1625  } elseif (!empty($cases3[$h]) && is_array($cases3[$h]) && count($cases3[$h]) > 1) {
1626  $title3 = $langs->trans("Ref").' '.$ids3.($title3 ? ' - '.$title3 : '');
1627  $color3 = '222222';
1628  }
1629 
1630  // only 1 event
1631  if (!empty($cases4[$h]) && is_array($cases4[$h]) && count($cases4[$h]) == 1) {
1632  $output = array_slice($cases4[$h], 0, 1);
1633  $title4 = $langs->trans("Ref").' '.$ids3.($title4 ? ' - '.$title4 : '');
1634  if ($output[0]['string']) {
1635  $title4 .= ($title4 ? ' - ' : '').$output[0]['string'];
1636  }
1637  if ($output[0]['color']) {
1638  $color4 = $output[0]['color'];
1639  }
1640  } elseif (!empty($cases4[$h]) && is_array($cases4[$h]) && count($cases4[$h]) > 1) {
1641  $title4 = $langs->trans("Ref").' '.$ids4.($title4 ? ' - '.$title4 : '');
1642  $color4 = '222222';
1643  }
1644 
1645  print '<table class="nobordernopadding case centpercent">';
1646  print '<tr>';
1647  print '<td ';
1648  if ($style1 == 'peruser_notbusy') {
1649  print 'style="border: 1px solid #'.($color1 ? $color1 : "888").' !important" ';
1650  } elseif ($color1) {
1651  print($color1 ? 'style="background: #'.$color1.';"' : '');
1652  }
1653  print 'class="';
1654  print($style1 ? $style1.' ' : '');
1655  print 'onclickopenref 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.'"' : '').'>';
1656  print $string1;
1657  print '</td>';
1658 
1659  print '<td ';
1660  if ($style2 == 'peruser_notbusy') {
1661  print 'style="border: 1px solid #'.($color2 ? $color2 : "888").' !important" ';
1662  } elseif ($color2) {
1663  print($color2 ? 'style="background: #'.$color2.';"' : '');
1664  }
1665  print 'class="';
1666  print($style2 ? $style2.' ' : '');
1667  print 'onclickopenref 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.'"' : '').'>';
1668  print $string2;
1669  print '</td>';
1670 
1671  print '<td ';
1672  if ($style3 == 'peruser_notbusy') {
1673  print 'style="border: 1px solid #'.($color3 ? $color3 : "888").' !important" ';
1674  } elseif ($color3) {
1675  print($color3 ? 'style="background: #'.$color3.';"' : '');
1676  }
1677  print 'class="';
1678  print($style3 ? $style3.' ' : '');
1679  print 'onclickopenref 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.'"' : '').'>';
1680  print $string3;
1681  print '</td>';
1682 
1683  print '<td ';
1684  if ($style4 == 'peruser_notbusy') {
1685  print 'style="border: 1px solid #'.($color4 ? $color4 : "888").' !important" ';
1686  } elseif ($color4) {
1687  print($color4 ? 'style="background: #'.$color4.';"' : '');
1688  }
1689  print 'class="';
1690  print($style4 ? $style4.' ' : '');
1691  print 'onclickopenref 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.'"' : '').'>';
1692  print $string4;
1693  print '</td>';
1694 
1695  print '</tr>';
1696  print '</table>';
1697  print '</td>';
1698  }
1699 }
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
print_actions_filter( $form, $canedit, $status, $year, $month, $day, $showbirthday, $filtera, $filtert, $filtered, $pid, $socid, $action, $showextcals=array(), $actioncode='', $usergroupid=0, $excludetype='', $resourceid=0, $search_categ_cus=0)
Show filter form in agenda view.
Definition: agenda.lib.php:52
calendars_prepare_head($param)
Define head array for tabs of agenda setup pages.
Definition: agenda.lib.php:514
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:55
llxFooter()
Empty footer.
Definition: wrapper.php:69
Class to manage agenda events (actions)
Class to manage contact/addresses.
Class to manage generation of HTML components Only common components must be here.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
Definition: user.class.php:50
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:745
dol_get_next_week($day, $week, $month, $year)
Return next week.
Definition: date.lib.php:573
dol_get_first_day_week($day, $month, $year, $gm=false)
Return first day of week for a date.
Definition: date.lib.php:670
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition: date.lib.php:124
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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_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).
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_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...
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.