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