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