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