dolibarr  20.0.0-alpha
pertype.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2003 Eric Seigne <erics@rycks.com>
4  * Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
5  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6  * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
7  * Copyright (C) 2014 Cedric GROSS <c.gross@kreiz-it.fr>
8  * Copyright (C) 2018-2019 Frédéric France <frederic.france@netlogic.fr>
9  * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <https://www.gnu.org/licenses/>.
23  */
24 
25 
32 // Load Dolibarr environment
33 require '../../main.inc.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
37 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
41 require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
42 
43 
44 if (!isset($conf->global->AGENDA_MAX_EVENTS_DAY_VIEW)) {
45  $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW = 3;
46 }
47 
48 $action = GETPOST('action', 'aZ09');
49 
50 $disabledefaultvalues = GETPOSTINT('disabledefaultvalues');
51 
52 $filter = GETPOST("search_filter", 'alpha', 3) ? GETPOST("search_filter", 'alpha', 3) : GETPOST("filter", 'alpha', 3);
53 $filtert = GETPOSTINT("search_filtert", 3) ? GETPOSTINT("search_filtert", 3) : GETPOSTINT("filtert", 3);
54 $usergroup = GETPOSTINT("search_usergroup", 3) ? GETPOSTINT("search_usergroup", 3) : GETPOSTINT("usergroup", 3);
55 //if (! ($usergroup > 0) && ! ($filtert > 0)) $filtert = $user->id;
56 
57 // $showbirthday = empty($conf->use_javascript_ajax)?GETPOST("showbirthday","int"):1;
58 $showbirthday = 0; // will be hidden here
59 
60 // If not choice done on calendar owner, we filter on user.
61 if (empty($filtert) && !getDolGlobalString('AGENDA_ALL_CALENDARS')) {
62  $filtert = $user->id;
63 }
64 
65 // Sorting
66 $sortfield = GETPOST('sortfield', 'aZ09comma');
67 $sortorder = GETPOST('sortorder', 'aZ09comma');
68 $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
69 if (empty($page) || $page == -1) {
70  $page = 0;
71 } // If $page is not defined, or '' or -1
72 $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
73 $offset = $limit * $page;
74 if (!$sortorder) {
75  $sortorder = "ASC";
76 }
77 if (!$sortfield) {
78  $sortfield = "a.datec";
79 }
80 
81 
82 // Security check
83 $socid = GETPOSTINT("search_socid") ? GETPOSTINT("search_socid") : GETPOSTINT("socid");
84 if ($user->socid) {
85  $socid = $user->socid;
86 }
87 if ($socid < 0) {
88  $socid = '';
89 }
90 
91 // Permissions
92 $canedit = 1;
93 if (!$user->hasRight('agenda', 'myactions', 'read')) {
95 }
96 if (!$user->hasRight('agenda', 'allactions', 'read')) {
97  $canedit = 0;
98 }
99 if (!$user->hasRight('agenda', 'allactions', 'read') || $filter == 'mine') { // If no permission to see all, we show only affected to me
100  $filtert = $user->id;
101 }
102 
103 $mode = 'show_pertype';
104 $resourceid = GETPOSTINT("search_resourceid") ? GETPOSTINT("search_resourceid") : GETPOSTINT("resourceid");
105 $year = GETPOSTINT("year") ? GETPOSTINT("year") : date("Y");
106 $month = GETPOSTINT("month") ? GETPOSTINT("month") : date("m");
107 $week = GETPOSTINT("week") ? GETPOSTINT("week") : date("W");
108 $day = GETPOSTINT("day") ? GETPOSTINT("day") : date("d");
109 $pid = GETPOSTISSET("search_projectid") ? GETPOSTINT("search_projectid", 3) : GETPOSTINT("projectid", 3);
110 $status = GETPOSTISSET("search_status") ? GETPOST("search_status", 'aZ09') : GETPOST("status", 'aZ09');
111 $type = GETPOSTISSET("search_type") ? GETPOST("search_type", 'alpha') : GETPOST("type", 'alpha');
112 $maxprint = ((GETPOSTINT("maxprint") != '') ? GETPOSTINT("maxprint") : $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW);
113 $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
114 
115 // Set actioncode (this code must be same for setting actioncode into peruser, listacton and index)
116 if (GETPOST('search_actioncode', 'array:aZ09')) {
117  $actioncode = GETPOST('search_actioncode', 'array:aZ09', 3);
118  if (!count($actioncode)) {
119  $actioncode = '0';
120  }
121 } else {
122  $actioncode = GETPOST("search_actioncode", "alpha", 3) ? GETPOST("search_actioncode", "alpha", 3) : (GETPOST("search_actioncode", "alpha") == '0' ? '0' : ((!getDolGlobalString('AGENDA_DEFAULT_FILTER_TYPE') || $disabledefaultvalues) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE));
123 }
124 
125 $dateselect = dol_mktime(0, 0, 0, GETPOSTINT('dateselectmonth'), GETPOSTINT('dateselectday'), GETPOSTINT('dateselectyear'));
126 if ($dateselect > 0) {
127  $day = GETPOSTINT('dateselectday');
128  $month = GETPOSTINT('dateselectmonth');
129  $year = GETPOSTINT('dateselectyear');
130 }
131 
132 // working hours
133 $tmp = !getDolGlobalString('MAIN_DEFAULT_WORKING_HOURS') ? '9-18' : $conf->global->MAIN_DEFAULT_WORKING_HOURS;
134 $tmp = str_replace(' ', '', $tmp); // FIX 7533
135 $tmparray = explode('-', $tmp);
136 $begin_h = GETPOSTINT('begin_h') != '' ? GETPOSTINT('begin_h') : ($tmparray[0] != '' ? $tmparray[0] : 9);
137 $end_h = GETPOSTINT('end_h') ? GETPOSTINT('end_h') : ($tmparray[1] != '' ? $tmparray[1] : 18);
138 if ($begin_h < 0 || $begin_h > 23) {
139  $begin_h = 9;
140 }
141 if ($end_h < 1 || $end_h > 24) {
142  $end_h = 18;
143 }
144 if ($end_h <= $begin_h) {
145  $end_h = $begin_h + 1;
146 }
147 
148 // working days
149 $tmp = !getDolGlobalString('MAIN_DEFAULT_WORKING_DAYS') ? '1-5' : $conf->global->MAIN_DEFAULT_WORKING_DAYS;
150 $tmp = str_replace(' ', '', $tmp); // FIX 7533
151 $tmparray = explode('-', $tmp);
152 $begin_d = 1;
153 $end_d = 53;
154 
155 if ($status == '' && !GETPOSTISSET('search_status')) {
156  $status = ((!getDolGlobalString('AGENDA_DEFAULT_FILTER_STATUS') || $disabledefaultvalues) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_STATUS);
157 }
158 if (empty($mode) && !GETPOSTISSET('mode')) {
159  $mode = (!getDolGlobalString('AGENDA_DEFAULT_VIEW') ? 'show_month' : $conf->global->AGENDA_DEFAULT_VIEW);
160 }
161 
162 // View by month
163 if (GETPOST('viewcal', 'alpha') && $mode != 'show_day' && $mode != 'show_week' && $mode != 'show_peruser') {
164  $mode = 'show_month';
165  $day = '';
166 }
167 // View by week
168 if (GETPOST('viewweek', 'alpha') || $mode == 'show_week') {
169  $mode = 'show_week';
170  $week = ($week ? $week : date("W"));
171  $day = ($day ? $day : date("d"));
172 }
173 // View by day
174 if (GETPOST('viewday', 'alpha') || $mode == 'show_day') {
175  $mode = 'show_day';
176  $day = ($day ? $day : date("d"));
177 }
178 // View by year
179 if (GETPOST('viewyear', 'alpha') || $mode == 'show_year') {
180  $mode = 'show_year';
181 }
182 
183 // Initialize object
184 $object = new ActionComm($db);
185 
186 // Load translation files required by the page
187 $langs->loadLangs(array('users', 'agenda', 'other', 'commercial'));
188 
189 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
190 $hookmanager->initHooks(array('agenda'));
191 
192 $result = restrictedArea($user, 'agenda', 0, '', 'myactions');
193 if ($user->socid && $socid) {
194  $result = restrictedArea($user, 'societe', $socid);
195 }
196 
197 $search_status = $status;
198 
199 
200 /*
201  * Actions
202  */
203 
204 // None
205 
206 
207 /*
208  * View
209  */
210 
211 $parameters = array(
212  'socid' => $socid,
213  'status' => $status,
214  'year' => $year,
215  'month' => $month,
216  'day' => $day,
217  'type' => $type,
218  'maxprint' => $maxprint,
219  'filter' => $filter,
220  'filtert' => $filtert,
221  'showbirthday' => $showbirthday,
222  'canedit' => $canedit,
223  'optioncss' => $optioncss,
224  'actioncode' => $actioncode,
225  'pid' => $pid,
226  'resourceid' => $resourceid,
227  'usergroup' => $usergroup,
228 );
229 
230 $reshook = $hookmanager->executeHooks('beforeAgendaPerType', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
231 if ($reshook < 0) {
232  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
233 }
234 
235 $form = new Form($db);
236 $companystatic = new Societe($db);
237 
238 $help_url = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:M&oacute;dulo_Agenda|DE:Modul_Terminplanung';
239 llxHeader('', $langs->trans("Agenda"), $help_url);
240 
241 $now = dol_now();
242 $nowarray = dol_getdate($now);
243 $nowyear = $nowarray['year'];
244 $nowmonth = $nowarray['mon'];
245 $nowday = $nowarray['mday'];
246 
247 
248 // Define list of all external calendars (global setup)
249 $listofextcals = array();
250 
251 $prev = dol_get_first_day($year, $month);
252 $first_day = 1;
253 $first_month = 1;
254 $first_year = $year;
255 
256 $week = $prev['week'];
257 
258 $day = (int) $day;
259 $next = dol_get_next_day($day, $month, $year);
260 $next_year = $year + 1;
261 $next_month = $month;
262 $next_day = $day;
263 
264 $max_day_in_month = date("t", dol_mktime(0, 0, 0, $month, 1, $year));
265 
266 $tmpday = $first_day;
267 //print 'xx'.$prev_year.'-'.$prev_month.'-'.$prev_day;
268 //print 'xx'.$next_year.'-'.$next_month.'-'.$next_day;
269 
270 $title = $langs->trans("DoneAndToDoActions");
271 if ($status == 'done') {
272  $title = $langs->trans("DoneActions");
273 }
274 if ($status == 'todo') {
275  $title = $langs->trans("ToDoActions");
276 }
277 
278 $param = '';
279 if ($actioncode || GETPOSTISSET('search_actioncode')) {
280  if (is_array($actioncode)) {
281  foreach ($actioncode as $str_action) {
282  $param .= "&search_actioncode[]=".urlencode($str_action);
283  }
284  } else {
285  $param .= "&search_actioncode=".urlencode($actioncode);
286  }
287 }
288 if ($resourceid > 0) {
289  $param .= "&search_resourceid=".urlencode((string) ($resourceid));
290 }
291 if ($status || GETPOSTISSET('status') || GETPOSTISSET('search_status')) {
292  $param .= "&search_status=".urlencode($status);
293 }
294 if ($filter) {
295  $param .= "&search_filter=".urlencode($filter);
296 }
297 if ($filtert) {
298  $param .= "&search_filtert=".urlencode($filtert);
299 }
300 if ($usergroup > 0) {
301  $param .= "&search_usergroup=".urlencode((string) ($usergroup));
302 }
303 if ($socid > 0) {
304  $param .= "&search_socid=".urlencode((string) ($socid));
305 }
306 if ($showbirthday) {
307  $param .= "&search_showbirthday=1";
308 }
309 if ($pid) {
310  $param .= "&search_projectid=".urlencode((string) ($pid));
311 }
312 if ($type) {
313  $param .= "&search_type=".urlencode($type);
314 }
315 if ($mode != 'show_pertype') {
316  $param .= '&mode='.urlencode($mode);
317 }
318 if ($begin_h != '') {
319  $param .= '&begin_h='.urlencode($begin_h);
320 }
321 if ($end_h != '') {
322  $param .= '&end_h='.urlencode($end_h);
323 }
324 if ($begin_d != '') {
325  $param .= '&begin_d='.urlencode((string) ($begin_d));
326 }
327 if ($end_d != '') {
328  $param .= '&end_d='.urlencode((string) ($end_d));
329 }
330 $param .= "&maxprint=".urlencode((string) ($maxprint));
331 
332 $paramnoactionodate = $param;
333 
334 $prev = dol_get_first_day($year, 1);
335 $prev_year = $year - 1;
336 $prev_month = $month;
337 $prev_day = $day;
338 $first_day = 1;
339 $first_month = 1;
340 $first_year = $year;
341 
342 $week = $prev['week'];
343 
344 $day = (int) $day;
345 $next = dol_get_next_day(31, 12, $year);
346 $next_year = $year + 1;
347 $next_month = $month;
348 $next_day = $day;
349 
350 // Define firstdaytoshow and lastdaytoshow. Warning: lastdaytoshow is last second to show + 1
351 // $firstdaytoshow and lastdaytoshow become a gmt dates to use to search/compare because first_xxx are in tz idea and we used tzuserrel
352 $firstdaytoshow = dol_mktime(0, 0, 0, $first_month, $first_day, $first_year, 'tzuserrel');
353 $lastdaytoshow = dol_time_plus_duree($firstdaytoshow, 7, 'd');
354 //print $firstday.'-'.$first_month.'-'.$first_year;
355 //print dol_print_date($firstdaytoshow, 'dayhour', 'gmt');
356 //print dol_print_date($lastdaytoshow,'dayhour', 'gmt');
357 
358 $max_day_in_month = date("t", dol_mktime(0, 0, 0, $month, 1, $year, 'gmt'));
359 
360 $tmpday = $first_day;
361 $picto = 'calendarweek';
362 
363 // Show navigation bar
364 $nav = '<div class="navselectiondate inline-block nowraponall">';
365 $nav .= "<a href=\"?year=".$prev_year."&amp;month=".$prev_month."&amp;day=".$prev_day.$param."\">".img_previous($langs->trans("Previous"))."</a>\n";
366 $nav .= " <span id=\"month_name\">".dol_print_date(dol_mktime(0, 0, 0, $first_month, $first_day, $first_year), "%Y")."</span> \n";
367 $nav .= "<a href=\"?year=".$next_year."&amp;month=".$next_month."&amp;day=".$next_day.$param."\">".img_next($langs->trans("Next"))."</a>\n";
368 if (empty($conf->dol_optimize_smallscreen)) {
369  $nav .= " &nbsp; (<a href=\"?year=".$nowyear."&amp;month=".$nowmonth."&amp;day=".$nowday.$param.'" class="datenowlink">'.$langs->trans("Today")."</a>)";
370 }
371 $nav .= '</div>';
372 
373 $nav .= $form->selectDate($dateselect, 'dateselect', 0, 0, 1, '', 1, 0);
374 $nav .= ' <button type="submit" class="liste_titre button_search" name="button_search_x" value="x"><span class="fa fa-search"></span></button>';
375 
376 // Must be after the nav definition
377 $param .= '&year='.urlencode((string) ($year)).'&month='.urlencode((string) ($month)).($day ? '&day='.urlencode((string) ($day)) : '');
378 //print 'x'.$param;
379 
380 
381 $paramnoaction = preg_replace('/action=[a-z_]+/', '', $param);
382 
383 $head = calendars_prepare_head($paramnoaction);
384 
385 print '<form method="POST" id="searchFormList" class="listactionsfilter" action="'.$_SERVER["PHP_SELF"].'">'."\n";
386 
387 $showextcals = $listofextcals;
388 // Legend
389 if ($conf->use_javascript_ajax) {
390  $s = '';
391  $s .= '<script type="text/javascript">'."\n";
392  $s .= 'jQuery(document).ready(function () {'."\n";
393  $s .= 'jQuery("#check_mytasks").click(function() { jQuery(".family_mytasks").toggle(); jQuery(".family_other").toggle(); });'."\n";
394  $s .= 'jQuery("#check_birthday").click(function() { jQuery(".family_birthday").toggle(); });'."\n";
395  $s .= 'jQuery(".family_birthday").toggle();'."\n";
396  if ($mode == "show_week" || $mode == "show_month" || empty($mode)) {
397  $s .= 'jQuery( "td.sortable" ).sortable({connectWith: ".sortable",placeholder: "ui-state-highlight",items: "div:not(.unsortable)", receive: function( event, ui ) {';
398  }
399  $s .= '});'."\n";
400  $s .= '</script>'."\n";
401  if (!empty($conf->use_javascript_ajax)) {
402  $s .= '<div class="nowrap clear float"><input type="checkbox" id="check_mytasks" name="check_mytasks" checked disabled> '.$langs->trans("LocalAgenda").' &nbsp; </div>';
403  if (is_array($showextcals) && count($showextcals) > 0) {
404  foreach ($showextcals as $val) {
405  $htmlname = md5($val['name']);
406  $s .= '<script type="text/javascript">'."\n";
407  $s .= 'jQuery(document).ready(function () {'."\n";
408  $s .= ' jQuery("#check_ext'.$htmlname.'").click(function() {';
409  $s .= ' /* alert("'.$htmlname.'"); */';
410  $s .= ' jQuery(".family_ext'.$htmlname.'").toggle();';
411  $s .= ' });'."\n";
412  $s .= '});'."\n";
413  $s .= '</script>'."\n";
414  $s .= '<div class="nowrap float"><input type="checkbox" id="check_ext'.$htmlname.'" name="check_ext'.$htmlname.'" checked> '.$val ['name'].' &nbsp; </div>';
415  }
416  }
417 
418  //$s.='<div class="nowrap float"><input type="checkbox" id="check_birthday" name="check_birthday"> '.$langs->trans("AgendaShowBirthdayEvents").' &nbsp; </div>';
419 
420  // Calendars from hooks
421  $parameters = array();
422  $reshook = $hookmanager->executeHooks('addCalendarChoice', $parameters, $object, $action);
423  if (empty($reshook)) {
424  $s .= $hookmanager->resPrint;
425  } elseif ($reshook > 1) {
426  $s = $hookmanager->resPrint;
427  }
428  }
429 }
430 
431 $massactionbutton = '';
432 
433 $viewmode = '';
434 $viewmode .= '<a class="btnTitle reposition" href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&restore_lastsearch_values=1'.$paramnoactionodate.'">';
435 //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
436 $viewmode .= img_picto($langs->trans("List"), 'object_calendarlist', 'class="imgforviewmode pictoactionview block"');
437 //$viewmode .= '</span>';
438 $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewList").'</span></a>';
439 
440 $viewmode .= '<a class="btnTitle reposition" href="'.DOL_URL_ROOT.'/comm/action/index.php?mode=show_month&year='.dol_print_date($object->datep, '%Y').'&month='.dol_print_date($object->datep, '%m').'&day='.dol_print_date($object->datep, '%d').$paramnoactionodate.'">';
441 //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
442 $viewmode .= img_picto($langs->trans("ViewCal"), 'object_calendarmonth', 'class="pictoactionview block"');
443 //$viewmode .= '</span>';
444 $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewCal").'</span></a>';
445 
446 $viewmode .= '<a class="btnTitle reposition" href="'.DOL_URL_ROOT.'/comm/action/index.php?mode=show_week&year='.dol_print_date($object->datep, '%Y').'&month='.dol_print_date($object->datep, '%m').'&day='.dol_print_date($object->datep, '%d').$paramnoactionodate.'">';
447 //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
448 $viewmode .= img_picto($langs->trans("ViewWeek"), 'object_calendarweek', 'class="pictoactionview block"');
449 //$viewmode .= '</span>';
450 $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewWeek").'</span></a>';
451 
452 $viewmode .= '<a class="btnTitle reposition" href="'.DOL_URL_ROOT.'/comm/action/index.php?mode=show_day&year='.dol_print_date($object->datep, '%Y').'&month='.dol_print_date($object->datep, '%m').'&day='.dol_print_date($object->datep, '%d').$paramnoactionodate.'">';
453 //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
454 $viewmode .= img_picto($langs->trans("ViewDay"), 'object_calendarday', 'class="pictoactionview block"');
455 //$viewmode .= '</span>';
456 $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewDay").'</span></a>';
457 
458 $viewmode .= '<a class="btnTitle btnTitleSelected reposition marginrightonly" href="'.DOL_URL_ROOT.'/comm/action/peruser.php?mode=show_peruser&year='.dol_print_date($object->datep, '%Y').'&month='.dol_print_date($object->datep, '%m').'&day='.dol_print_date($object->datep, '%d').$paramnoactionodate.'">';
459 //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
460 $viewmode .= img_picto($langs->trans("ViewPerUser"), 'object_calendarperuser', 'class="pictoactionview block"');
461 //$viewmode .= '</span>';
462 $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewPerUser").'</span></a>';
463 
464 $viewmode .= '<span class="marginrightonly"></span>';
465 
466 // Add more views from hooks
467 $parameters = array();
468 $object = null;
469 $reshook = $hookmanager->executeHooks('addCalendarView', $parameters, $object, $action);
470 if (empty($reshook)) {
471  $viewmode .= $hookmanager->resPrint;
472 } elseif ($reshook > 1) {
473  $viewmode = $hookmanager->resPrint;
474 }
475 
476 $newparam = '';
477 $newcardbutton = '';
478 if ($user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create')) {
479  $tmpforcreatebutton = dol_getdate(dol_now(), true);
480 
481  $newparam .= '&month='.str_pad($month, 2, "0", STR_PAD_LEFT).'&year='.$tmpforcreatebutton['year'];
482 
483  $urltocreateaction = DOL_URL_ROOT.'/comm/action/card.php?action=create';
484  $urltocreateaction .= '&apyear='.$tmpforcreatebutton['year'].'&apmonth='.$tmpforcreatebutton['mon'].'&apday='.$tmpforcreatebutton['mday'].'&aphour='.$tmpforcreatebutton['hours'].'&apmin='.$tmpforcreatebutton['minutes'];
485  $urltocreateaction .= '&backtopage='.urlencode($_SERVER["PHP_SELF"].($newparam ? '?'.$newparam : ''));
486 
487  $newcardbutton .= dolGetButtonTitle($langs->trans("AddAction"), '', 'fa fa-plus-circle', $urltocreateaction);
488 }
489 
490 print_barre_liste($langs->trans("Agenda"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, -1, 'object_action', 0, $nav.'<span class="marginleftonly"></span>'.$newcardbutton, '', $limit, 1, 0, 1, $viewmode);
491 
492 
493 $link = '';
494 //print load_fiche_titre('', $link.' &nbsp; &nbsp; '.$nav.' '.$newcardbutton, '');
495 
496 // Local calendar
497 $newtitle = '<div class="nowrap clear inline-block minheight30">';
498 $newtitle .= '<input type="checkbox" id="check_mytasks" name="check_mytasks" checked disabled> '.$langs->trans("LocalAgenda").' &nbsp; ';
499 $newtitle .= '</div>';
500 //$newtitle=$langs->trans($title);
501 
502 $s = $newtitle;
503 
504 print $s;
505 
506 print '<div class="liste_titre liste_titre_bydiv centpercent">';
507 print_actions_filter($form, $canedit, $search_status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid);
508 print '</div>';
509 
510 
511 // Get event in an array
512 $eventarray = array();
513 
514 
515 // DEFAULT CALENDAR + AUTOEVENT CALENDAR + CONFERENCEBOOTH CALENDAR
516 $sql = 'SELECT';
517 if ($usergroup > 0) {
518  $sql .= " DISTINCT";
519 }
520 $sql .= ' a.id, a.label,';
521 $sql .= ' a.datep,';
522 $sql .= ' a.datep2,';
523 $sql .= ' a.percent,';
524 $sql .= ' a.fk_user_author,a.fk_user_action,';
525 $sql .= ' a.transparency, a.priority, a.fulldayevent, a.location,';
526 $sql .= ' a.fk_soc, a.fk_contact, a.fk_element, a.elementtype, a.fk_project,';
527 $sql .= ' ca.code, ca.libelle as type_label, ca.color, ca.type as type_type, ca.picto as type_picto';
528 $sql .= ' FROM '.MAIN_DB_PREFIX.'c_actioncomm as ca, '.MAIN_DB_PREFIX."actioncomm as a";
529 // We must filter on resource table
530 if ($resourceid > 0) {
531  $sql .= ", ".MAIN_DB_PREFIX."element_resources as r";
532 }
533 // We must filter on assignment table
534 if ($filtert > 0 || $usergroup > 0) {
535  $sql .= ", ".MAIN_DB_PREFIX."actioncomm_resources as ar";
536 }
537 if ($usergroup > 0) {
538  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_user = ar.fk_element";
539 }
540 $sql .= ' WHERE a.fk_action = ca.id';
541 $sql .= ' AND a.entity IN ('.getEntity('agenda').')';
542 // Condition on actioncode
543 if (!empty($actioncode)) {
544  if (!getDolGlobalString('AGENDA_USE_EVENT_TYPE')) {
545  if ($actioncode == 'AC_NON_AUTO') {
546  $sql .= " AND ca.type != 'systemauto'";
547  } elseif ($actioncode == 'AC_ALL_AUTO') {
548  $sql .= " AND ca.type = 'systemauto'";
549  } else {
550  if ($actioncode == 'AC_OTH') {
551  $sql .= " AND ca.type != 'systemauto'";
552  }
553  if ($actioncode == 'AC_OTH_AUTO') {
554  $sql .= " AND ca.type = 'systemauto'";
555  }
556  }
557  } else {
558  if ($actioncode == 'AC_NON_AUTO') {
559  $sql .= " AND ca.type != 'systemauto'";
560  } elseif ($actioncode == 'AC_ALL_AUTO') {
561  $sql .= " AND ca.type = 'systemauto'";
562  } else {
563  if (is_array($actioncode)) {
564  $sql .= " AND ca.code IN (".$db->sanitize("'".implode("','", $actioncode)."'", 1).")";
565  } else {
566  $sql .= " AND ca.code IN (".$db->sanitize("'".implode("','", explode(',', $actioncode))."'", 1).")";
567  }
568  }
569  }
570 }
571 if ($resourceid > 0) {
572  $sql .= " AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = ".((int) $resourceid);
573 }
574 if ($pid) {
575  $sql .= " AND a.fk_project = ".((int) $pid);
576 }
577 // If the internal user must only see his customers, force searching by him
578 $search_sale = 0;
579 if (!$user->hasRight('societe', 'client', 'voir')) {
580  $search_sale = $user->id;
581 }
582 // Search on sale representative
583 if ($search_sale && $search_sale != '-1') {
584  if ($search_sale == -2) {
585  $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = a.fk_soc)";
586  } elseif ($search_sale > 0) {
587  $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).")";
588  }
589 }
590 // Search on socid
591 if ($socid) {
592  $sql .= " AND a.fk_soc = ".((int) $socid);
593 }
594 // We must filter on assignment table
595 if ($filtert > 0 || $usergroup > 0) {
596  $sql .= " AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
597 }
598 if ($mode == 'show_day') {
599  $sql .= " AND (";
600  $sql .= " (a.datep BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel'))."'";
601  $sql .= " AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel'))."')";
602  $sql .= " OR ";
603  $sql .= " (a.datep2 BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel'))."'";
604  $sql .= " AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel'))."')";
605  $sql .= " OR ";
606  $sql .= " (a.datep < '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel'))."'";
607  $sql .= " AND a.datep2 > '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel'))."')";
608  $sql .= ')';
609 } else {
610  // To limit array
611  $sql .= " AND (";
612  $sql .= " (a.datep BETWEEN '".$db->idate(dol_mktime(0, 0, 0, 1, 1, $year) - (60 * 60 * 24 * 7))."'"; // Start 7 days before
613  $sql .= " AND '".$db->idate(dol_mktime(23, 59, 59, 12, 31, $year) + (60 * 60 * 24 * 7))."')"; // End 7 days after
614  $sql .= " OR ";
615  $sql .= " (a.datep2 BETWEEN '".$db->idate(dol_mktime(0, 0, 0, 1, 1, $year) - (60 * 60 * 24 * 7))."'";
616  $sql .= " AND '".$db->idate(dol_mktime(23, 59, 59, 12, 31, $year) + (60 * 60 * 24 * 7))."')";
617  $sql .= " OR ";
618  $sql .= " (a.datep < '".$db->idate(dol_mktime(0, 0, 0, 12, 1, $year) - (60 * 60 * 24 * 7))."'";
619  $sql .= " AND a.datep2 > '".$db->idate(dol_mktime(23, 59, 59, 12, 31, $year) + (60 * 60 * 24 * 7))."')";
620  $sql .= ')';
621 }
622 if ($type) {
623  $sql .= " AND ca.id = ".((int) $type);
624 }
625 if ($status == '0') {
626  $sql .= " AND a.percent = 0";
627 }
628 if ($status === 'na') {
629  // Not applicable
630  $sql .= " AND a.percent = -1";
631 }
632 if ($status == '50') {
633  // Running already started
634  $sql .= " AND (a.percent > 0 AND a.percent < 100)";
635 }
636 if ($status == 'done' || $status == '100') {
637  $sql .= " AND (a.percent = 100)";
638 }
639 if ($status == 'todo') {
640  $sql .= " AND (a.percent >= 0 AND a.percent < 100)";
641 }
642 // We must filter on assignment table
643 if ($filtert > 0 || $usergroup > 0) {
644  $sql .= " AND (";
645  if ($filtert > 0) {
646  $sql .= "ar.fk_element = ".$filtert;
647  }
648  if ($usergroup > 0) {
649  $sql .= ($filtert > 0 ? " OR " : "")." ugu.fk_usergroup = ".((int) $usergroup);
650  }
651  $sql .= ")";
652 }
653 // Sort on date
654 $sql .= ' ORDER BY fk_user_action, datep'; //fk_user_action
655 //print $sql;
656 
657 dol_syslog("comm/action/pertype.php", LOG_DEBUG);
658 $resql = $db->query($sql);
659 if ($resql) {
660  $num = $db->num_rows($resql);
661  $i = 0;
662  while ($i < $num) {
663  $obj = $db->fetch_object($resql);
664 
665  // Discard auto action if option is on
666  if (getDolGlobalString('AGENDA_ALWAYS_HIDE_AUTO') && $obj->code == 'AC_OTH_AUTO') {
667  $i++;
668  continue;
669  }
670 
671  $datep = $db->jdate($obj->datep);
672  $datep2 = $db->jdate($obj->datep2);
673 
674  // Create a new object action
675  $event = new ActionComm($db);
676  $event->id = $obj->id;
677  $event->datep = $datep; // datep and datef are GMT date
678  $event->datef = $datep2;
679  $event->type_code = $obj->code;
680  $event->type_color = $obj->color;
681  $event->label = $obj->label;
682  $event->percentage = $obj->percent;
683  $event->authorid = $obj->fk_user_author; // user id of creator
684  $event->userownerid = $obj->fk_user_action; // user id of owner
685  $event->priority = $obj->priority;
686  $event->fulldayevent = $obj->fulldayevent;
687  $event->location = $obj->location;
688  $event->transparency = $obj->transparency;
689 
690  $event->fk_project = $obj->fk_project;
691 
692  $event->socid = $obj->fk_soc;
693  $event->contact_id = $obj->fk_contact;
694 
695  $event->fk_element = $obj->fk_element;
696  $event->elementtype = $obj->elementtype;
697 
698  // Defined date_start_in_calendar and date_end_in_calendar property
699  // They are date start and end of action but modified to not be outside calendar view.
700  $event->date_start_in_calendar = $datep;
701  if ($datep2 != '' && $datep2 >= $datep) {
702  $event->date_end_in_calendar = $datep2;
703  } else {
704  $event->date_end_in_calendar = $datep;
705  }
706 
707  // Check values
708  if ($event->date_end_in_calendar < $firstdaytoshow ||
709  $event->date_start_in_calendar >= $lastdaytoshow) {
710  // This record is out of visible range
711  unset($event);
712  } else {
713  //print $i.' - '.dol_print_date($this->date_start_in_calendar, 'dayhour').' - '.dol_print_date($this->date_end_in_calendar, 'dayhour').'<br>'."\n";
714  $event->fetch_userassigned(); // This load $event->userassigned
715 
716  if ($event->date_start_in_calendar < $firstdaytoshow) {
717  $event->date_start_in_calendar = $firstdaytoshow;
718  }
719  if ($event->date_end_in_calendar >= $lastdaytoshow) {
720  $event->date_end_in_calendar = ($lastdaytoshow - 1);
721  }
722 
723  // Add an entry in actionarray for each day
724  $daycursor = $event->date_start_in_calendar;
725  $annee = dol_print_date($daycursor, '%Y', 'tzuserrel');
726  $mois = dol_print_date($daycursor, '%m', 'tzuserrel');
727  $jour = dol_print_date($daycursor, '%d', 'tzuserrel');
728 
729  // Loop on each day covered by action to prepare an index to show on calendar
730  $loop = true;
731  $j = 0;
732  $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
733  do {
734  //if ($event->id==408) print 'daykey='.$daykey.' '.$event->datep.' '.$event->datef.'<br>';
735 
736  $eventarray[$daykey][] = $event;
737  $j++;
738 
739  $daykey += 60 * 60 * 24;
740  if ($daykey > $event->date_end_in_calendar) {
741  $loop = false;
742  }
743  } while ($loop);
744 
745  //print 'Event '.$i.' id='.$event->id.' (start='.dol_print_date($event->datep).'-end='.dol_print_date($event->datef);
746  //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>';
747  }
748  $i++;
749  }
750  $db->free($resql);
751 } else {
752  dol_print_error($db);
753 }
754 
755 $maxnbofchar = 18;
756 $cachethirdparties = array();
757 $cachecontacts = array();
758 $cacheusers = array();
759 
760 // Define theme_datacolor array
761 $color_file = DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/theme_vars.inc.php";
762 if (is_readable($color_file)) {
763  include $color_file;
764 }
765 if (!is_array($theme_datacolor)) {
766  $theme_datacolor = array(array(120, 130, 150), array(200, 160, 180), array(190, 190, 220));
767 }
768 
769 
770 $newparam = $param; // newparam is for birthday links
771 $newparam = preg_replace('/showbirthday=/i', 'showbirthday_=', $newparam); // To avoid replacement when replace day= is done
772 $newparam = preg_replace('/mode=show_month&?/i', '', $newparam);
773 $newparam = preg_replace('/mode=show_week&?/i', '', $newparam);
774 $newparam = preg_replace('/day=[0-9]+&?/i', '', $newparam);
775 $newparam = preg_replace('/month=[0-9]+&?/i', '', $newparam);
776 $newparam = preg_replace('/year=[0-9]+&?/i', '', $newparam);
777 $newparam = preg_replace('/viewweek=[0-9]+&?/i', '', $newparam);
778 $newparam = preg_replace('/showbirthday_=/i', 'showbirthday=', $newparam); // Restore correct parameter
779 $newparam .= '&viewweek=1';
780 
781 print '<input type="hidden" name="action" value="mupdate">';
782 echo '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($_SERVER['PHP_SELF']).'?'.dol_escape_htmltag($_SERVER['QUERY_STRING']).'">';
783 echo '<input type="hidden" name="token" value="'.newToken().'">';
784 echo '<input type="hidden" name="newdate" id="newdate">';
785 
786 
787 // Line header with list of days
788 
789 //print "begin_d=".$begin_d." end_d=".$end_d;
790 
791 echo '<div class="div-table-responsive">';
792 
793 echo '<table class="centpercent nocellnopadd cal_month">';
794 
795 echo '<tr class="liste_titre">';
796 echo '<td></td>';
797 $i = 0; // 0 = sunday,
798 echo '<td align="center" colspan="'.($end_d - $begin_d).'">';
799 echo $langs->trans("Year");
800 print "<br>";
801 print $year;
802 echo "</td>\n";
803 echo "</tr>\n";
804 
805 echo '<tr class="liste_titre">';
806 echo '<td></td>';
807 $i = 0;
808 for ($h = $begin_d; $h < $end_d; $h++) {
809  echo '<td class="center">';
810  print '<small style="font-family: courier">'.sprintf("%02d", $h).'</small>';
811  print "</td>";
812 }
813 echo "</td>\n";
814 echo "</tr>\n";
815 
816 
817 $typeofevents = array();
818 
819 // Load array of colors by type
820 $colorsbytype = array();
821 $labelbytype = array();
822 $sql = "SELECT code, color, libelle as label FROM ".MAIN_DB_PREFIX."c_actioncomm ORDER BY position";
823 $resql = $db->query($sql);
824 while ($obj = $db->fetch_object($resql)) {
825  $typeofevents[$obj->code] = $obj->code;
826  $colorsbytype[$obj->code] = $obj->color;
827  $labelbytype[$obj->code] = $obj->label;
828 }
829 
830 // Loop on each user to show calendar
831 $todayarray = dol_getdate($now, 'fast');
832 $sav = $tmpday;
833 $showheader = true;
834 $var = false;
835 foreach ($typeofevents as $typeofevent) {
836  $var = !$var;
837  echo "<tr>";
838  echo '<td class="cal_current_month cal_peruserviewname'.($var ? ' cal_impair' : '').'">'.$typeofevent.'</td>';
839  $tmpday = $sav;
840 
841  // Lopp on each day of week
842  $i = 0;
843  for ($iter_day = 0; $iter_day < 8; $iter_day++) {
844  if (($i + 1) < $begin_d || ($i + 1) > $end_d) {
845  $i++;
846  continue;
847  }
848 
849  // Show days of the current week
850  $curtime = dol_time_plus_duree($firstdaytoshow, $iter_day, 'd');
851  // $curtime is a gmt time, but we want the day, month, year in user TZ
852  $tmpday = dol_print_date($curtime, "%d", "tzuserrel");
853  $tmpmonth = dol_print_date($curtime, "%m", "tzuserrel");
854  $tmpyear = dol_print_date($curtime, "%Y", "tzuserrel");
855  //var_dump($curtime.' '.$tmpday.' '.$tmpmonth.' '.$tmpyear);
856 
857  $style = 'cal_current_month';
858  if ($iter_day == 6) {
859  $style .= ' cal_other_month';
860  }
861  $today = 0;
862  if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $tmpmonth && $todayarray['year'] == $tmpyear) {
863  $today = 1;
864  }
865  if ($today) {
866  $style = 'cal_today_peruser';
867  }
868 
869  show_day_events_pertype($typeofevent, $tmpday, $tmpmonth, $tmpyear, 0, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, $showheader, $colorsbytype, $var);
870 
871  $i++;
872  }
873  echo "</tr>\n";
874  $showheader = false;
875 }
876 
877 echo "</table>\n";
878 echo "<br>";
879 
880 echo '</div>';
881 
882 if (getDolGlobalString('AGENDA_USE_EVENT_TYPE')) {
883  $langs->load("commercial");
884  print '<br>'.$langs->trans("Legend").': <br>';
885  foreach ($colorsbytype as $code => $color) {
886  if ($color) {
887  print '<div style="float: left; padding: 2px; margin-right: 6px;"><div style="'.($color ? 'background: #'.$color.';' : '').'width:16px; float: left; margin-right: 4px;">&nbsp;</div>';
888  print $langs->trans("Action".$code) != "Action".$code ? $langs->trans("Action".$code) : $labelbytype[$code];
889  //print $code;
890  print '</div>';
891  }
892  }
893  //$color=sprintf("%02x%02x%02x",$theme_datacolor[0][0],$theme_datacolor[0][1],$theme_datacolor[0][2]);
894  print '<div style="float: left; padding: 2px; margin-right: 6px;"><div class="peruser_busy" style="width:16px; float: left; margin-right: 4px;">&nbsp;</div>';
895  print $langs->trans("Other");
896  print '</div>';
897  /* TODO Show this if at least one cumulated event
898  print '<div style="float: left; padding: 2px; margin-right: 6px;"><div style="background: #222222; width:16px; float: left; margin-right: 4px;">&nbsp;</div>';
899  print $langs->trans("SeveralEvents");
900  print '</div>';
901  */
902 }
903 
904 print "\n".'</form>';
905 print "\n";
906 
907 // Add js code to manage click on a box
908 print '<script type="text/javascript">
909 jQuery(document).ready(function() {
910  jQuery(".onclickopenref").click(function() {
911  var ref=$(this).attr(\'ref\');
912  var res = ref.split("_");
913  var userid = res[1];
914  var year = res[2];
915  var month = res[3];
916  var day = res[4];
917  var hour = res[5];
918  var min = res[6];
919  var ids = res[7];
920  if (ids == \'none\') /* No event */
921  {
922  /* alert(\'no event\'); */
923  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).'"
924  window.location.href = url;
925  }
926  else if (ids.indexOf(",") > -1) /* There is several events */
927  {
928  /* alert(\'several events\'); */
929  url = "'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&filtert="+userid+"&dateselectyear="+year+"&dateselectmonth="+month+"&dateselectday="+day;
930  window.location.href = url;
931  }
932  else /* One event */
933  {
934  /* alert(\'one event\'); */
935  url = "'.DOL_URL_ROOT.'/comm/action/card.php?action=view&id="+ids
936  window.location.href = url;
937  }
938  });
939 });
940 </script>';
941 
942 // End of page
943 llxFooter();
944 $db->close();
945 
946 
947 
948 
969 function show_day_events_pertype($username, $day, $month, $year, $monthshown, $style, &$eventarray, $maxprint = 0, $maxnbofchar = 16, $newparam = '', $showinfo = 0, $minheight = 60, $showheader = false, $colorsbytype = array(), $var = false)
970 {
971  global $db;
972  global $user, $conf, $langs, $hookmanager, $action;
973  global $filter, $filtert, $status, $actioncode; // Filters used into search form
974  global $theme_datacolor; // Array with a list of different we can use (come from theme)
975  global $cachethirdparties, $cachecontacts, $cacheusers, $cacheprojects, $colorindexused;
976  global $begin_h, $end_h;
977 
978  $cases1 = array(); // Color first half hour
979  $cases2 = array(); // Color second half hour
980 
981  $i = 0;
982  $nummytasks = 0;
983  $numother = 0;
984  $numbirthday = 0;
985  $numical = 0;
986  $numicals = array();
987  $ymd = sprintf("%04d", $year).sprintf("%02d", $month).sprintf("%02d", $day);
988 
989  $nextindextouse = count($colorindexused); // At first run, this is 0, so fist user has 0, next 1, ...
990  //if ($username->id && $day==1) {
991  //var_dump($eventarray);
992  //}
993 
994  // We are in a particular day for $username, now we scan all events
995  foreach ($eventarray as $daykey => $notused) {
996  $annee = dol_print_date($daykey, '%Y', 'tzuserrel');
997  $mois = dol_print_date($daykey, '%m', 'tzuserrel');
998  $jour = dol_print_date($daykey, '%d', 'tzuserrel');
999 
1000  if ($day == $jour && (int) $month == (int) $mois && $year == $annee) { // Is it the day we are looking for when calling function ?
1001  // Scan all event for this date
1002  foreach ($eventarray[$daykey] as $index => $event) {
1003  //print 'daykey='.$daykey.' '.$year.'-'.$month.'-'.$day.' -> '.$event->id.' '.$index.' '.$annee.'-'.$mois.'-'.$jour."<br>\n";
1004  //var_dump($event);
1005 
1006  $keysofuserassigned = array_keys($event->userassigned);
1007  if (!in_array($username->id, $keysofuserassigned)) {
1008  continue; // We discard record if event is from another user than user we want to show
1009  }
1010  //if ($username->id != $event->userownerid) continue; // We discard record if event is from another user than user we want to show
1011 
1012  $parameters = array();
1013  $reshook = $hookmanager->executeHooks('formatEvent', $parameters, $event, $action); // Note that $action and $object may have been modified by some hooks
1014  if ($reshook < 0) {
1015  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1016  }
1017 
1018  $ponct = ($event->date_start_in_calendar == $event->date_end_in_calendar);
1019 
1020  // Define $color (Hex string like '0088FF') and $cssclass of event
1021  $color = -1;
1022  $cssclass = '';
1023  $colorindex = -1;
1024  if (in_array($user->id, $keysofuserassigned)) {
1025  $nummytasks++;
1026  $cssclass = 'family_mytasks';
1027  if (getDolGlobalString('AGENDA_USE_EVENT_TYPE')) {
1028  $color = $event->type_color;
1029  }
1030  } elseif ($event->type_code == 'ICALEVENT') {
1031  $numical++;
1032  if (!empty($event->icalname)) {
1033  if (!isset($numicals[dol_string_nospecial($event->icalname)])) {
1034  $numicals[dol_string_nospecial($event->icalname)] = 0;
1035  }
1036  $numicals[dol_string_nospecial($event->icalname)]++;
1037  }
1038 
1039  $color = $event->icalcolor;
1040  $cssclass = (!empty($event->icalname) ? 'family_ext'.md5($event->icalname) : 'family_other unsortable');
1041  } elseif ($event->type_code == 'BIRTHDAY') {
1042  $numbirthday++;
1043  $colorindex = 2;
1044  $cssclass = 'family_birthday unsortable';
1045  $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
1046  } else {
1047  $numother++;
1048  $cssclass = 'family_other';
1049  if (getDolGlobalString('AGENDA_USE_EVENT_TYPE')) {
1050  $color = $event->type_color;
1051  }
1052  }
1053 
1054  if ($color < 0) { // Color was not set on user card. Set color according to color index.
1055  // Define color index if not yet defined
1056  $idusertouse = ($event->userownerid ? $event->userownerid : 0);
1057  if (isset($colorindexused[$idusertouse])) {
1058  $colorindex = $colorindexused[$idusertouse]; // Color already assigned to this user
1059  } else {
1060  $colorindex = $nextindextouse;
1061  $colorindexused[$idusertouse] = $colorindex;
1062  if (!empty($theme_datacolor[$nextindextouse + 1])) {
1063  $nextindextouse++; // Prepare to use next color
1064  }
1065  }
1066  // Define color
1067  $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
1068  }
1069  //$cssclass=$cssclass.' '.$cssclass.'_day_'.$ymd;
1070 
1071  // Define all rects with event (cases1 is first half hour, cases2 is second half hour)
1072  for ($h = $begin_h; $h < $end_h; $h++) {
1073  //if ($username->id == 1 && $day==1) print 'h='.$h;
1074  $newcolor = ''; //init
1075  if (empty($event->fulldayevent)) {
1076  $a = dol_mktime((int) $h, 0, 0, $month, $day, $year, 'tzuserrel', 0);
1077  $b = dol_mktime((int) $h, 30, 0, $month, $day, $year, 'tzuserrel', 0);
1078  $c = dol_mktime((int) $h + 1, 0, 0, $month, $day, $year, 'tzuserrel', 0);
1079 
1080  $dateendtouse = $event->date_end_in_calendar;
1081  if ($dateendtouse == $event->date_start_in_calendar) {
1082  $dateendtouse++;
1083  }
1084 
1085  //print dol_print_date($event->date_start_in_calendar,'dayhour').'-'.dol_print_date($a,'dayhour').'-'.dol_print_date($b,'dayhour').'<br>';
1086 
1087  if ($event->date_start_in_calendar < $b && $dateendtouse > $a) {
1088  $busy = $event->transparency;
1089  $cases1[$h][$event->id]['busy'] = $busy;
1090  $cases1[$h][$event->id]['string'] = dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzuserrel');
1091  if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) {
1092  $tmpa = dol_getdate($event->date_start_in_calendar, true);
1093  $tmpb = dol_getdate($event->date_end_in_calendar, true);
1094  if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
1095  $cases1[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel');
1096  } else {
1097  $cases1[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzuserrel');
1098  }
1099  }
1100  if ($event->label) {
1101  $cases1[$h][$event->id]['string'] .= ' - '.$event->label;
1102  }
1103  $cases1[$h][$event->id]['typecode'] = $event->type_code;
1104  $cases1[$h][$event->id]['color'] = $color;
1105  if ($event->fk_project > 0) {
1106  if (empty($cacheprojects[$event->fk_project])) {
1107  $tmpproj = new Project($db);
1108  $tmpproj->fetch($event->fk_project);
1109  $cacheprojects[$event->fk_project] = $tmpproj;
1110  }
1111  $cases1[$h][$event->id]['string'] .= ', '.$langs->trans("Project").': '.$cacheprojects[$event->fk_project]->ref.' - '.$cacheprojects[$event->fk_project]->title;
1112  }
1113  if ($event->socid > 0) {
1114  if (empty($cachethirdparties[$event->socid])) {
1115  $tmpthirdparty = new Societe($db);
1116  $tmpthirdparty->fetch($event->socid);
1117  $cachethirdparties[$event->socid] = $tmpthirdparty;
1118  }
1119  $cases1[$h][$event->id]['string'] .= ', '.$cachethirdparties[$event->socid]->name;
1120  }
1121  if ($event->contact_id > 0) {
1122  if (empty($cachecontacts[$event->contact_id])) {
1123  $tmpcontact = new Contact($db);
1124  $tmpcontact->fetch($event->contact_id);
1125  $cachecontacts[$event->contact_id] = $tmpcontact;
1126  }
1127  $cases1[$h][$event->id]['string'] .= ', '.$cachecontacts[$event->contact_id]->getFullName($langs);
1128  }
1129  }
1130  if ($event->date_start_in_calendar < $c && $dateendtouse > $b) {
1131  $busy = $event->transparency;
1132  $cases2[$h][$event->id]['busy'] = $busy;
1133  $cases2[$h][$event->id]['string'] = dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzuserrel');
1134  if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) {
1135  $tmpa = dol_getdate($event->date_start_in_calendar, true);
1136  $tmpb = dol_getdate($event->date_end_in_calendar, true);
1137  if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
1138  $cases2[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel');
1139  } else {
1140  $cases2[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzuserrel');
1141  }
1142  }
1143  if ($event->label) {
1144  $cases2[$h][$event->id]['string'] .= ' - '.$event->label;
1145  }
1146  $cases2[$h][$event->id]['typecode'] = $event->type_code;
1147  $cases2[$h][$event->id]['color'] = $color;
1148  if ($event->fk_project > 0) {
1149  if (empty($cacheprojects[$event->fk_project])) {
1150  $tmpproj = new Project($db);
1151  $tmpproj->fetch($event->fk_project);
1152  $cacheprojects[$event->fk_project] = $tmpproj;
1153  }
1154  $cases2[$h][$event->id]['string'] .= ', '.$langs->trans("Project").': '.$cacheprojects[$event->fk_project]->ref.' - '.$cacheprojects[$event->fk_project]->title;
1155  }
1156  if ($event->socid > 0) {
1157  if (empty($cachethirdparties[$event->socid])) {
1158  $tmpthirdparty = new Societe($db);
1159  $tmpthirdparty->fetch($event->socid);
1160  $cachethirdparties[$event->socid] = $tmpthirdparty;
1161  }
1162  $cases2[$h][$event->id]['string'] .= ', '.$cachethirdparties[$event->socid]->name;
1163  }
1164  if ($event->contact_id > 0) {
1165  if (empty($cachecontacts[$event->contact_id])) {
1166  $tmpcontact = new Contact($db);
1167  $tmpcontact->fetch($event->contact_id);
1168  $cachecontacts[$event->contact_id] = $tmpcontact;
1169  }
1170  $cases2[$h][$event->id]['string'] .= ', '.$cachecontacts[$event->contact_id]->getFullName($langs);
1171  }
1172  }
1173  } else {
1174  $busy = $event->transparency;
1175  $cases1[$h][$event->id]['busy'] = $busy;
1176  $cases2[$h][$event->id]['busy'] = $busy;
1177  $cases1[$h][$event->id]['string'] = $event->label;
1178  $cases2[$h][$event->id]['string'] = $event->label;
1179  $cases1[$h][$event->id]['typecode'] = $event->type_code;
1180  $cases2[$h][$event->id]['typecode'] = $event->type_code;
1181  $cases1[$h][$event->id]['color'] = $color;
1182  $cases2[$h][$event->id]['color'] = $color;
1183  }
1184  }
1185  $i++;
1186  }
1187 
1188  break; // We found the date we were looking for. No need to search anymore.
1189  }
1190  }
1191 
1192  // Now output $casesX from start hour to end hour
1193  for ($h = $begin_h; $h < $end_h; $h++) {
1194  $color1 = '';
1195  $color2 = '';
1196  $style1 = '';
1197  $style2 = '';
1198  $string1 = '&nbsp;';
1199  $string2 = '&nbsp;';
1200  $title1 = '';
1201  $title2 = '';
1202  if (isset($cases1[$h]) && $cases1[$h] != '') {
1203  //$title1.=count($cases1[$h]).' '.(count($cases1[$h])==1?$langs->trans("Event"):$langs->trans("Events"));
1204  if (count($cases1[$h]) > 1) {
1205  $title1 .= count($cases1[$h]).' '.(count($cases1[$h]) == 1 ? $langs->trans("Event") : $langs->trans("Events"));
1206  }
1207 
1208  if (!getDolGlobalString('AGENDA_NO_TRANSPARENT_ON_NOT_BUSY')) {
1209  $style1 = 'peruser_notbusy';
1210  } else {
1211  $style1 = 'peruser_busy';
1212  }
1213  foreach ($cases1[$h] as $id => $ev) {
1214  if ($ev['busy']) {
1215  $style1 = 'peruser_busy';
1216  }
1217  }
1218  }
1219  if (isset($cases2[$h]) && $cases2[$h] != '') {
1220  //$title2.=count($cases2[$h]).' '.(count($cases2[$h])==1?$langs->trans("Event"):$langs->trans("Events"));
1221  if (count($cases2[$h]) > 1) {
1222  $title2 .= count($cases2[$h]).' '.(count($cases2[$h]) == 1 ? $langs->trans("Event") : $langs->trans("Events"));
1223  }
1224 
1225  if (!getDolGlobalString('AGENDA_NO_TRANSPARENT_ON_NOT_BUSY')) {
1226  $style2 = 'peruser_notbusy';
1227  } else {
1228  $style2 = 'peruser_busy';
1229  }
1230  foreach ($cases2[$h] as $id => $ev) {
1231  if ($ev['busy']) {
1232  $style2 = 'peruser_busy';
1233  }
1234  }
1235  }
1236 
1237  $ids1 = '';
1238  $ids2 = '';
1239  if (!empty($cases1[$h]) && is_array($cases1[$h]) && count($cases1[$h]) && array_keys($cases1[$h])) {
1240  $ids1 = implode(',', array_keys($cases1[$h]));
1241  }
1242  if (!empty($cases2[$h]) && is_array($cases2[$h]) && count($cases2[$h]) && array_keys($cases2[$h])) {
1243  $ids2 = implode(',', array_keys($cases2[$h]));
1244  }
1245 
1246  if ($h == $begin_h) {
1247  echo '<td class="'.$style.'_peruserleft cal_peruser'.($var ? ' cal_impair '.$style.'_impair' : '').'">';
1248  } else {
1249  echo '<td class="'.$style.' cal_peruser'.($var ? ' cal_impair '.$style.'_impair' : '').'">';
1250  }
1251  if (!empty($cases1[$h]) && is_array($cases1[$h]) && count($cases1[$h]) == 1) { // only 1 event
1252  $output = array_slice($cases1[$h], 0, 1);
1253  $title1 = $langs->trans("Ref").' '.$ids1.($title1 ? ' - '.$title1 : '');
1254  if ($output[0]['string']) {
1255  $title1 .= ($title1 ? ' - ' : '').$output[0]['string'];
1256  }
1257  if ($output[0]['color']) {
1258  $color1 = $output[0]['color'];
1259  }
1260  } elseif (!empty($cases1[$h]) && is_array($cases1[$h]) && count($cases1[$h]) > 1) {
1261  $title1 = $langs->trans("Ref").' '.$ids1.($title1 ? ' - '.$title1 : '');
1262  $color1 = '222222';
1263  }
1264 
1265  if (!empty($cases2[$h]) && is_array($cases2[$h]) && count($cases2[$h]) == 1) { // only 1 event
1266  $output = array_slice($cases2[$h], 0, 1);
1267  $title2 = $langs->trans("Ref").' '.$ids2.($title2 ? ' - '.$title2 : '');
1268  if ($output[0]['string']) {
1269  $title2 .= ($title2 ? ' - ' : '').$output[0]['string'];
1270  }
1271  if ($output[0]['color']) {
1272  $color2 = $output[0]['color'];
1273  }
1274  } elseif (!empty($cases2[$h]) && is_array($cases2[$h]) && count($cases2[$h]) > 1) {
1275  $title2 = $langs->trans("Ref").' '.$ids2.($title2 ? ' - '.$title2 : '');
1276  $color2 = '222222';
1277  }
1278  print '<table class="nobordernopadding" width="100%">';
1279  print '<tr><td '.($color1 ? 'style="background: #'.$color1.';"' : '').'class="'.($style1 ? $style1.' ' : '').'onclickopenref center'.($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.'"' : '').'>';
1280  print $string1;
1281  print '</td><td '.($color2 ? 'style="background: #'.$color2.';"' : '').'class="'.($style2 ? $style2.' ' : '').'onclickopenref center'.($title1 ? ' cursorpointer' : '').'" ref="ref_'.$username->id.'_'.sprintf("%04d", $year).'_'.sprintf("%02d", $month).'_'.sprintf("%02d", $day).'_'.sprintf("%02d", $h).'_30_'.($ids2 ? $ids2 : 'none').'"'.($title2 ? ' title="'.$title2.'"' : '').'>';
1282  print $string2;
1283  print '</td></tr>';
1284  print '</table>';
1285  print '</td>';
1286  }
1287 }
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
print_actions_filter( $form, $canedit, $status, $year, $month, $day, $showbirthday, $filtera, $filtert, $filtered, $pid, $socid, $action, $showextcals=array(), $actioncode='', $usergroupid=0, $excludetype='', $resourceid=0, $search_categ_cus=0)
Show filter form in agenda view.
Definition: agenda.lib.php:52
calendars_prepare_head($param)
Define head array for tabs of agenda setup pages.
Definition: agenda.lib.php:514
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
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...)
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:744
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_get_next_day($day, $month, $year)
Return next day.
Definition: date.lib.php:498
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:594
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition: date.lib.php:123
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='', $keepspaces=0)
Clean a string from all punctuation characters to use it as a ref or login.
dol_now($mode='auto')
Return date for now.
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).
img_previous($titlealt='default', $moreatt='')
Show previous logo.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_next($titlealt='default', $moreatt='')
Show next logo.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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.