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