dolibarr  17.0.4
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 (empty($user->rights->agenda->myactions->read)) {
94 }
95 if (empty($user->rights->agenda->allactions->read)) {
96  $canedit = 0;
97 }
98 if (empty($user->rights->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 $nav = "<a href=\"?year=".$prev_year."&amp;month=".$prev_month."&amp;day=".$prev_day.$param."\">".img_previous($langs->trans("Previous"))."</a>\n";
369 $nav .= " <span id=\"month_name\">".dol_print_date(dol_mktime(0, 0, 0, $first_month, $first_day, $first_year), "%Y")."</span> \n";
370 $nav .= "<a href=\"?year=".$next_year."&amp;month=".$next_month."&amp;day=".$next_day.$param."\">".img_next($langs->trans("Next"))."</a>\n";
371 if (empty($conf->dol_optimize_smallscreen)) {
372  $nav .= " &nbsp; (<a href=\"?year=".$nowyear."&amp;month=".$nowmonth."&amp;day=".$nowday.$param."\">".$langs->trans("Today")."</a>)";
373 }
374 
375 $nav .= $form->selectDate($dateselect, 'dateselect', 0, 0, 1, '', 1, 0);
376 $nav .= ' <button type="submit" class="liste_titre button_search" name="button_search_x" value="x"><span class="fa fa-search"></span></button>';
377 
378 // Must be after the nav definition
379 $param .= '&year='.urlencode($year).'&month='.urlencode($month).($day ? '&day='.urlencode($day) : '');
380 //print 'x'.$param;
381 
382 
383 $paramnoaction = preg_replace('/action=[a-z_]+/', '', $param);
384 
385 $head = calendars_prepare_head($paramnoaction);
386 
387 print '<form method="POST" id="searchFormList" class="listactionsfilter" action="'.$_SERVER["PHP_SELF"].'">'."\n";
388 
389 $showextcals = $listofextcals;
390 // Legend
391 if ($conf->use_javascript_ajax) {
392  $s = '';
393  $s .= '<script type="text/javascript">'."\n";
394  $s .= 'jQuery(document).ready(function () {'."\n";
395  $s .= 'jQuery("#check_mytasks").click(function() { jQuery(".family_mytasks").toggle(); jQuery(".family_other").toggle(); });'."\n";
396  $s .= 'jQuery("#check_birthday").click(function() { jQuery(".family_birthday").toggle(); });'."\n";
397  $s .= 'jQuery(".family_birthday").toggle();'."\n";
398  if ($mode == "show_week" || $mode == "show_month" || empty($mode)) {
399  $s .= 'jQuery( "td.sortable" ).sortable({connectWith: ".sortable",placeholder: "ui-state-highlight",items: "div:not(.unsortable)", receive: function( event, ui ) {';
400  }
401  $s .= '});'."\n";
402  $s .= '</script>'."\n";
403  if (!empty($conf->use_javascript_ajax)) {
404  $s .= '<div class="nowrap clear float"><input type="checkbox" id="check_mytasks" name="check_mytasks" checked disabled> '.$langs->trans("LocalAgenda").' &nbsp; </div>';
405  if (is_array($showextcals) && count($showextcals) > 0) {
406  foreach ($showextcals as $val) {
407  $htmlname = md5($val['name']);
408  $s .= '<script type="text/javascript">'."\n";
409  $s .= 'jQuery(document).ready(function () {'."\n";
410  $s .= ' jQuery("#check_ext'.$htmlname.'").click(function() {';
411  $s .= ' /* alert("'.$htmlname.'"); */';
412  $s .= ' jQuery(".family_ext'.$htmlname.'").toggle();';
413  $s .= ' });'."\n";
414  $s .= '});'."\n";
415  $s .= '</script>'."\n";
416  $s .= '<div class="nowrap float"><input type="checkbox" id="check_ext'.$htmlname.'" name="check_ext'.$htmlname.'" checked> '.$val ['name'].' &nbsp; </div>';
417  }
418  }
419 
420  //$s.='<div class="nowrap float"><input type="checkbox" id="check_birthday" name="check_birthday"> '.$langs->trans("AgendaShowBirthdayEvents").' &nbsp; </div>';
421 
422  // Calendars from hooks
423  $parameters = array();
424  $reshook = $hookmanager->executeHooks('addCalendarChoice', $parameters, $object, $action);
425  if (empty($reshook)) {
426  $s .= $hookmanager->resPrint;
427  } elseif ($reshook > 1) {
428  $s = $hookmanager->resPrint;
429  }
430  }
431 }
432 
433 $massactionbutton = '';
434 
435 $viewmode = '';
436 $viewmode .= '<a class="btnTitle reposition" href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&restore_lastsearch_values=1'.$paramnoactionodate.'">';
437 //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
438 $viewmode .= img_picto($langs->trans("List"), 'object_calendarlist', 'class="imgforviewmode pictoactionview block"');
439 //$viewmode .= '</span>';
440 $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewList").'</span></a>';
441 
442 $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.'">';
443 //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
444 $viewmode .= img_picto($langs->trans("ViewCal"), 'object_calendarmonth', 'class="pictoactionview block"');
445 //$viewmode .= '</span>';
446 $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewCal").'</span></a>';
447 
448 $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.'">';
449 //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
450 $viewmode .= img_picto($langs->trans("ViewWeek"), 'object_calendarweek', 'class="pictoactionview block"');
451 //$viewmode .= '</span>';
452 $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewWeek").'</span></a>';
453 
454 $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.'">';
455 //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
456 $viewmode .= img_picto($langs->trans("ViewDay"), 'object_calendarday', 'class="pictoactionview block"');
457 //$viewmode .= '</span>';
458 $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewDay").'</span></a>';
459 
460 $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.'">';
461 //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
462 $viewmode .= img_picto($langs->trans("ViewPerUser"), 'object_calendarperuser', 'class="pictoactionview block"');
463 //$viewmode .= '</span>';
464 $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewPerUser").'</span></a>';
465 
466 $viewmode .= '<span class="marginrightonly"></span>';
467 
468 // Add more views from hooks
469 $parameters = array(); $object = null;
470 $reshook = $hookmanager->executeHooks('addCalendarView', $parameters, $object, $action);
471 if (empty($reshook)) {
472  $viewmode .= $hookmanager->resPrint;
473 } elseif ($reshook > 1) {
474  $viewmode = $hookmanager->resPrint;
475 }
476 
477 $newparam = '';
478 $newcardbutton = '';
479 if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create) {
480  $tmpforcreatebutton = dol_getdate(dol_now(), true);
481 
482  $newparam .= '&month='.str_pad($month, 2, "0", STR_PAD_LEFT).'&year='.$tmpforcreatebutton['year'];
483 
484  //$param='month='.$monthshown.'&year='.$year;
485  $hourminsec = '100000';
486  $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 : '')));
487 }
488 
489 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);
490 
491 
492 $link = '';
493 //print load_fiche_titre('', $link.' &nbsp; &nbsp; '.$nav.' '.$newcardbutton, '');
494 
495 // Local calendar
496 $newtitle = '<div class="nowrap clear inline-block minheight30">';
497 $newtitle .= '<input type="checkbox" id="check_mytasks" name="check_mytasks" checked disabled> '.$langs->trans("LocalAgenda").' &nbsp; ';
498 $newtitle .= '</div>';
499 //$newtitle=$langs->trans($title);
500 
501 $s = $newtitle;
502 
503 print $s;
504 
505 print '<div class="liste_titre liste_titre_bydiv centpercent">';
506 print_actions_filter($form, $canedit, $search_status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid);
507 print '</div>';
508 
509 
510 // Get event in an array
511 $eventarray = array();
512 
513 
514 // DEFAULT CALENDAR + AUTOEVENT CALENDAR + CONFERENCEBOOTH CALENDAR
515 $sql = 'SELECT';
516 if ($usergroup > 0) {
517  $sql .= " DISTINCT";
518 }
519 $sql .= ' a.id, a.label,';
520 $sql .= ' a.datep,';
521 $sql .= ' a.datep2,';
522 $sql .= ' a.percent,';
523 $sql .= ' a.fk_user_author,a.fk_user_action,';
524 $sql .= ' a.transparency, a.priority, a.fulldayevent, a.location,';
525 $sql .= ' a.fk_soc, a.fk_contact, a.fk_element, a.elementtype, a.fk_project,';
526 $sql .= ' ca.code, ca.libelle as type_label, ca.color, ca.type as type_type, ca.picto as type_picto';
527 $sql .= ' FROM '.MAIN_DB_PREFIX.'c_actioncomm as ca, '.MAIN_DB_PREFIX."actioncomm as a";
528 if (empty($user->rights->societe->client->voir) && !$socid) {
529  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
530 }
531 // We must filter on resource table
532 if ($resourceid > 0) {
533  $sql .= ", ".MAIN_DB_PREFIX."element_resources as r";
534 }
535 // We must filter on assignement table
536 if ($filtert > 0 || $usergroup > 0) {
537  $sql .= ", ".MAIN_DB_PREFIX."actioncomm_resources as ar";
538 }
539 if ($usergroup > 0) {
540  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_user = ar.fk_element";
541 }
542 $sql .= ' WHERE a.fk_action = ca.id';
543 $sql .= ' AND a.entity IN ('.getEntity('agenda').')';
544 // Condition on actioncode
545 if (!empty($actioncode)) {
546  if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
547  if ($actioncode == 'AC_NON_AUTO') {
548  $sql .= " AND ca.type != 'systemauto'";
549  } elseif ($actioncode == 'AC_ALL_AUTO') {
550  $sql .= " AND ca.type = 'systemauto'";
551  } else {
552  if ($actioncode == 'AC_OTH') {
553  $sql .= " AND ca.type != 'systemauto'";
554  }
555  if ($actioncode == 'AC_OTH_AUTO') {
556  $sql .= " AND ca.type = 'systemauto'";
557  }
558  }
559  } else {
560  if ($actioncode == 'AC_NON_AUTO') {
561  $sql .= " AND ca.type != 'systemauto'";
562  } elseif ($actioncode == 'AC_ALL_AUTO') {
563  $sql .= " AND ca.type = 'systemauto'";
564  } else {
565  if (is_array($actioncode)) {
566  $sql .= " AND ca.code IN (".$db->sanitize("'".implode("','", $actioncode)."'", 1).")";
567  } else {
568  $sql .= " AND ca.code IN (".$db->sanitize("'".implode("','", explode(',', $actioncode))."'", 1).")";
569  }
570  }
571  }
572 }
573 if ($resourceid > 0) {
574  $sql .= " AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = ".((int) $resourceid);
575 }
576 if ($pid) {
577  $sql .= " AND a.fk_project=".((int) $pid);
578 }
579 if (empty($user->rights->societe->client->voir) && !$socid) {
580  $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = ".((int) $user->id).")";
581 }
582 if ($socid > 0) {
583  $sql .= ' AND a.fk_soc = '.((int) $socid);
584 }
585 // We must filter on assignement table
586 if ($filtert > 0 || $usergroup > 0) {
587  $sql .= " AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
588 }
589 if ($mode == 'show_day') {
590  $sql .= " AND (";
591  $sql .= " (a.datep BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel'))."'";
592  $sql .= " AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel'))."')";
593  $sql .= " OR ";
594  $sql .= " (a.datep2 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.datep < '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel'))."'";
598  $sql .= " AND a.datep2 > '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel'))."')";
599  $sql .= ')';
600 } else {
601  // To limit array
602  $sql .= " AND (";
603  $sql .= " (a.datep BETWEEN '".$db->idate(dol_mktime(0, 0, 0, 1, 1, $year) - (60 * 60 * 24 * 7))."'"; // Start 7 days before
604  $sql .= " AND '".$db->idate(dol_mktime(23, 59, 59, 12, 31, $year) + (60 * 60 * 24 * 7))."')"; // End 7 days after
605  $sql .= " OR ";
606  $sql .= " (a.datep2 BETWEEN '".$db->idate(dol_mktime(0, 0, 0, 1, 1, $year) - (60 * 60 * 24 * 7))."'";
607  $sql .= " AND '".$db->idate(dol_mktime(23, 59, 59, 12, 31, $year) + (60 * 60 * 24 * 7))."')";
608  $sql .= " OR ";
609  $sql .= " (a.datep < '".$db->idate(dol_mktime(0, 0, 0, 12, 1, $year) - (60 * 60 * 24 * 7))."'";
610  $sql .= " AND a.datep2 > '".$db->idate(dol_mktime(23, 59, 59, 12, 31, $year) + (60 * 60 * 24 * 7))."')";
611  $sql .= ')';
612 }
613 if ($type) {
614  $sql .= " AND ca.id = ".((int) $type);
615 }
616 if ($status == '0') {
617  $sql .= " AND a.percent = 0";
618 }
619 if ($status === 'na') {
620  // Not applicable
621  $sql .= " AND a.percent = -1";
622 }
623 if ($status == '50') {
624  // Running already started
625  $sql .= " AND (a.percent > 0 AND a.percent < 100)";
626 }
627 if ($status == 'done' || $status == '100') {
628  $sql .= " AND (a.percent = 100)";
629 }
630 if ($status == 'todo') {
631  $sql .= " AND (a.percent >= 0 AND a.percent < 100)";
632 }
633 // We must filter on assignement table
634 if ($filtert > 0 || $usergroup > 0) {
635  $sql .= " AND (";
636  if ($filtert > 0) {
637  $sql .= "ar.fk_element = ".$filtert;
638  }
639  if ($usergroup > 0) {
640  $sql .= ($filtert > 0 ? " OR " : "")." ugu.fk_usergroup = ".((int) $usergroup);
641  }
642  $sql .= ")";
643 }
644 // Sort on date
645 $sql .= ' ORDER BY fk_user_action, datep'; //fk_user_action
646 //print $sql;
647 
648 dol_syslog("comm/action/pertype.php", LOG_DEBUG);
649 $resql = $db->query($sql);
650 if ($resql) {
651  $num = $db->num_rows($resql);
652  $i = 0;
653  while ($i < $num) {
654  $obj = $db->fetch_object($resql);
655 
656  // Discard auto action if option is on
657  if (!empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO) && $obj->code == 'AC_OTH_AUTO') {
658  $i++;
659  continue;
660  }
661 
662  $datep = $db->jdate($obj->datep);
663  $datep2 = $db->jdate($obj->datep2);
664 
665  // Create a new object action
666  $event = new ActionComm($db);
667  $event->id = $obj->id;
668  $event->datep = $datep; // datep and datef are GMT date
669  $event->datef = $datep2;
670  $event->type_code = $obj->code;
671  $event->type_color = $obj->color;
672  $event->label = $obj->label;
673  $event->percentage = $obj->percent;
674  $event->authorid = $obj->fk_user_author; // user id of creator
675  $event->userownerid = $obj->fk_user_action; // user id of owner
676  $event->priority = $obj->priority;
677  $event->fulldayevent = $obj->fulldayevent;
678  $event->location = $obj->location;
679  $event->transparency = $obj->transparency;
680 
681  $event->fk_project = $obj->fk_project;
682 
683  $event->socid = $obj->fk_soc;
684  $event->contact_id = $obj->fk_contact;
685 
686  $event->fk_element = $obj->fk_element;
687  $event->elementtype = $obj->elementtype;
688 
689  // Defined date_start_in_calendar and date_end_in_calendar property
690  // They are date start and end of action but modified to not be outside calendar view.
691  if ($event->percentage <= 0) {
692  $event->date_start_in_calendar = $datep;
693  if ($datep2 != '' && $datep2 >= $datep) {
694  $event->date_end_in_calendar = $datep2;
695  } else {
696  $event->date_end_in_calendar = $datep;
697  }
698  } else {
699  $event->date_start_in_calendar = $datep;
700  if ($datep2 != '' && $datep2 >= $datep) {
701  $event->date_end_in_calendar = $datep2;
702  } else {
703  $event->date_end_in_calendar = $datep;
704  }
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; $j = 0;
731  $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
732  do {
733  //if ($event->id==408) print 'daykey='.$daykey.' '.$event->datep.' '.$event->datef.'<br>';
734 
735  $eventarray[$daykey][] = $event;
736  $j++;
737 
738  $daykey += 60 * 60 * 24;
739  if ($daykey > $event->date_end_in_calendar) {
740  $loop = false;
741  }
742  } while ($loop);
743 
744  //print 'Event '.$i.' id='.$event->id.' (start='.dol_print_date($event->datep).'-end='.dol_print_date($event->datef);
745  //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>';
746  }
747  $i++;
748  }
749  $db->free($resql);
750 } else {
751  dol_print_error($db);
752 }
753 
754 $maxnbofchar = 18;
755 $cachethirdparties = array();
756 $cachecontacts = array();
757 $cacheusers = array();
758 
759 // Define theme_datacolor array
760 $color_file = DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/theme_vars.inc.php";
761 if (is_readable($color_file)) {
762  include $color_file;
763 }
764 if (!is_array($theme_datacolor)) {
765  $theme_datacolor = array(array(120, 130, 150), array(200, 160, 180), array(190, 190, 220));
766 }
767 
768 
769 $newparam = $param; // newparam is for birthday links
770 $newparam = preg_replace('/showbirthday=/i', 'showbirthday_=', $newparam); // To avoid replacement when replace day= is done
771 $newparam = preg_replace('/mode=show_month&?/i', '', $newparam);
772 $newparam = preg_replace('/mode=show_week&?/i', '', $newparam);
773 $newparam = preg_replace('/day=[0-9]+&?/i', '', $newparam);
774 $newparam = preg_replace('/month=[0-9]+&?/i', '', $newparam);
775 $newparam = preg_replace('/year=[0-9]+&?/i', '', $newparam);
776 $newparam = preg_replace('/viewweek=[0-9]+&?/i', '', $newparam);
777 $newparam = preg_replace('/showbirthday_=/i', 'showbirthday=', $newparam); // Restore correct parameter
778 $newparam .= '&viewweek=1';
779 
780 print '<input type="hidden" name="action" value="mupdate">';
781 echo '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($_SERVER['PHP_SELF']).'?'.dol_escape_htmltag($_SERVER['QUERY_STRING']).'">';
782 echo '<input type="hidden" name="token" value="'.newToken().'">';
783 echo '<input type="hidden" name="newdate" id="newdate">';
784 
785 
786 // Line header with list of days
787 
788 //print "begin_d=".$begin_d." end_d=".$end_d;
789 
790 echo '<div class="div-table-responsive">';
791 
792 echo '<table class="centpercent nocellnopadd cal_month">';
793 
794 echo '<tr class="liste_titre">';
795 echo '<td></td>';
796 $i = 0; // 0 = sunday,
797 echo '<td align="center" colspan="'.($end_d - $begin_d).'">';
798 echo $langs->trans("Year");
799 print "<br>";
800 print $year;
801 echo "</td>\n";
802 echo "</tr>\n";
803 
804 echo '<tr class="liste_titre">';
805 echo '<td></td>';
806 $i = 0;
807 for ($h = $begin_d; $h < $end_d; $h++) {
808  echo '<td class="center">';
809  print '<small style="font-family: courier">'.sprintf("%02d", $h).'</small>';
810  print "</td>";
811 }
812 echo "</td>\n";
813 echo "</tr>\n";
814 
815 
816 $typeofevents = array();
817 
818 // Load array of colors by type
819 $colorsbytype = array();
820 $labelbytype = array();
821 $sql = "SELECT code, color, libelle as label FROM ".MAIN_DB_PREFIX."c_actioncomm ORDER BY position";
822 $resql = $db->query($sql);
823 while ($obj = $db->fetch_object($resql)) {
824  $typeofevents[$obj->code] = $obj->code;
825  $colorsbytype[$obj->code] = $obj->color;
826  $labelbytype[$obj->code] = $obj->label;
827 }
828 
829 // Loop on each user to show calendar
830 $todayarray = dol_getdate($now, 'fast');
831 $sav = $tmpday;
832 $showheader = true;
833 $var = false;
834 foreach ($typeofevents as $typeofevent) {
835  $var = !$var;
836  echo "<tr>";
837  echo '<td class="cal_current_month cal_peruserviewname'.($var ? ' cal_impair' : '').'">'.$typeofevent.'</td>';
838  $tmpday = $sav;
839 
840  // Lopp on each day of week
841  $i = 0;
842  for ($iter_day = 0; $iter_day < 8; $iter_day++) {
843  if (($i + 1) < $begin_d || ($i + 1) > $end_d) {
844  $i++;
845  continue;
846  }
847 
848  // Show days of the current week
849  $curtime = dol_time_plus_duree($firstdaytoshow, $iter_day, 'd');
850  // $curtime is a gmt time, but we want the day, month, year in user TZ
851  $tmpday = dol_print_date($curtime, "%d", "tzuserrel");
852  $tmpmonth = dol_print_date($curtime, "%m", "tzuserrel");
853  $tmpyear = dol_print_date($curtime, "%Y", "tzuserrel");
854  //var_dump($curtime.' '.$tmpday.' '.$tmpmonth.' '.$tmpyear);
855 
856  $style = 'cal_current_month';
857  if ($iter_day == 6) {
858  $style .= ' cal_other_month';
859  }
860  $today = 0;
861  if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $tmpmonth && $todayarray['year'] == $tmpyear) {
862  $today = 1;
863  }
864  if ($today) {
865  $style = 'cal_today_peruser';
866  }
867 
868  show_day_events_pertype($typeofevent, $tmpday, $tmpmonth, $tmpyear, 0, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, $showheader, $colorsbytype, $var);
869 
870  $i++;
871  }
872  echo "</tr>\n";
873  $showheader = false;
874 }
875 
876 echo "</table>\n";
877 echo "<br>";
878 
879 echo '</div>';
880 
881 if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
882  $langs->load("commercial");
883  print '<br>'.$langs->trans("Legend").': <br>';
884  foreach ($colorsbytype as $code => $color) {
885  if ($color) {
886  print '<div style="float: left; padding: 2px; margin-right: 6px;"><div style="'.($color ? 'background: #'.$color.';' : '').'width:16px; float: left; margin-right: 4px;">&nbsp;</div>';
887  print $langs->trans("Action".$code) != "Action".$code ? $langs->trans("Action".$code) : $labelbytype[$code];
888  //print $code;
889  print '</div>';
890  }
891  }
892  //$color=sprintf("%02x%02x%02x",$theme_datacolor[0][0],$theme_datacolor[0][1],$theme_datacolor[0][2]);
893  print '<div style="float: left; padding: 2px; margin-right: 6px;"><div class="peruser_busy" style="width:16px; float: left; margin-right: 4px;">&nbsp;</div>';
894  print $langs->trans("Other");
895  print '</div>';
896  /* TODO Show this if at least one cumulated event
897  print '<div style="float: left; padding: 2px; margin-right: 6px;"><div style="background: #222222; width:16px; float: left; margin-right: 4px;">&nbsp;</div>';
898  print $langs->trans("SeveralEvents");
899  print '</div>';
900  */
901 }
902 
903 print "\n".'</form>';
904 print "\n";
905 
906 // Add js code to manage click on a box
907 print '<script type="text/javascript">
908 jQuery(document).ready(function() {
909  jQuery(".onclickopenref").click(function() {
910  var ref=$(this).attr(\'ref\');
911  var res = ref.split("_");
912  var userid = res[1];
913  var year = res[2];
914  var month = res[3];
915  var day = res[4];
916  var hour = res[5];
917  var min = res[6];
918  var ids = res[7];
919  if (ids == \'none\') /* No event */
920  {
921  /* alert(\'no event\'); */
922  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).'"
923  window.location.href = url;
924  }
925  else if (ids.indexOf(",") > -1) /* There is several events */
926  {
927  /* alert(\'several events\'); */
928  url = "'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&filtert="+userid+"&dateselectyear="+year+"&dateselectmonth="+month+"&dateselectday="+day;
929  window.location.href = url;
930  }
931  else /* One event */
932  {
933  /* alert(\'one event\'); */
934  url = "'.DOL_URL_ROOT.'/comm/action/card.php?action=view&id="+ids
935  window.location.href = url;
936  }
937  });
938 });
939 </script>';
940 
941 // End of page
942 llxFooter();
943 $db->close();
944 
945 
946 
947 
968 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)
969 {
970  global $db;
971  global $user, $conf, $langs, $hookmanager, $action;
972  global $filter, $filtert, $status, $actioncode; // Filters used into search form
973  global $theme_datacolor; // Array with a list of different we can use (come from theme)
974  global $cachethirdparties, $cachecontacts, $cacheusers, $cacheprojects, $colorindexused;
975  global $begin_h, $end_h;
976 
977  $cases1 = array(); // Color first half hour
978  $cases2 = array(); // Color second half hour
979 
980  $i = 0; $nummytasks = 0; $numother = 0; $numbirthday = 0; $numical = 0; $numicals = array();
981  $ymd = sprintf("%04d", $year).sprintf("%02d", $month).sprintf("%02d", $day);
982 
983  $nextindextouse = count($colorindexused); // At first run, this is 0, so fist user has 0, next 1, ...
984  //if ($username->id && $day==1) {
985  //var_dump($eventarray);
986  //}
987 
988  // We are in a particular day for $username, now we scan all events
989  foreach ($eventarray as $daykey => $notused) {
990  $annee = dol_print_date($daykey, '%Y', 'tzuserrel');
991  $mois = dol_print_date($daykey, '%m', 'tzuserrel');
992  $jour = dol_print_date($daykey, '%d', 'tzuserrel');
993 
994  if ($day == $jour && (int) $month == (int) $mois && $year == $annee) { // Is it the day we are looking for when calling function ?
995  // Scan all event for this date
996  foreach ($eventarray[$daykey] as $index => $event) {
997  //print 'daykey='.$daykey.' '.$year.'-'.$month.'-'.$day.' -> '.$event->id.' '.$index.' '.$annee.'-'.$mois.'-'.$jour."<br>\n";
998  //var_dump($event);
999 
1000  $keysofuserassigned = array_keys($event->userassigned);
1001  if (!in_array($username->id, $keysofuserassigned)) {
1002  continue; // We discard record if event is from another user than user we want to show
1003  }
1004  //if ($username->id != $event->userownerid) continue; // We discard record if event is from another user than user we want to show
1005 
1006  $parameters = array();
1007  $reshook = $hookmanager->executeHooks('formatEvent', $parameters, $event, $action); // Note that $action and $object may have been modified by some hooks
1008  if ($reshook < 0) {
1009  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1010  }
1011 
1012  $ponct = ($event->date_start_in_calendar == $event->date_end_in_calendar);
1013 
1014  // Define $color (Hex string like '0088FF') and $cssclass of event
1015  $color = -1; $cssclass = ''; $colorindex = -1;
1016  if (in_array($user->id, $keysofuserassigned)) {
1017  $nummytasks++; $cssclass = 'family_mytasks';
1018  if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
1019  $color = $event->type_color;
1020  }
1021  } elseif ($event->type_code == 'ICALEVENT') {
1022  $numical++;
1023  if (!empty($event->icalname)) {
1024  if (!isset($numicals[dol_string_nospecial($event->icalname)])) {
1025  $numicals[dol_string_nospecial($event->icalname)] = 0;
1026  }
1027  $numicals[dol_string_nospecial($event->icalname)]++;
1028  }
1029 
1030  $color = $event->icalcolor;
1031  $cssclass = (!empty($event->icalname) ? 'family_ext'.md5($event->icalname) : 'family_other unsortable');
1032  } elseif ($event->type_code == 'BIRTHDAY') {
1033  $numbirthday++; $colorindex = 2; $cssclass = 'family_birthday unsortable'; $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
1034  } else {
1035  $numother++; $cssclass = 'family_other';
1036  if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
1037  $color = $event->type_color;
1038  }
1039  }
1040 
1041  if ($color < 0) { // Color was not set on user card. Set color according to color index.
1042  // Define color index if not yet defined
1043  $idusertouse = ($event->userownerid ? $event->userownerid : 0);
1044  if (isset($colorindexused[$idusertouse])) {
1045  $colorindex = $colorindexused[$idusertouse]; // Color already assigned to this user
1046  } else {
1047  $colorindex = $nextindextouse;
1048  $colorindexused[$idusertouse] = $colorindex;
1049  if (!empty($theme_datacolor[$nextindextouse + 1])) {
1050  $nextindextouse++; // Prepare to use next color
1051  }
1052  }
1053  // Define color
1054  $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
1055  }
1056  //$cssclass=$cssclass.' '.$cssclass.'_day_'.$ymd;
1057 
1058  // Define all rects with event (cases1 is first half hour, cases2 is second half hour)
1059  for ($h = $begin_h; $h < $end_h; $h++) {
1060  //if ($username->id == 1 && $day==1) print 'h='.$h;
1061  $newcolor = ''; //init
1062  if (empty($event->fulldayevent)) {
1063  $a = dol_mktime((int) $h, 0, 0, $month, $day, $year, 'tzuserrel', 0);
1064  $b = dol_mktime((int) $h, 30, 0, $month, $day, $year, 'tzuserrel', 0);
1065  $c = dol_mktime((int) $h + 1, 0, 0, $month, $day, $year, 'tzuserrel', 0);
1066 
1067  $dateendtouse = $event->date_end_in_calendar;
1068  if ($dateendtouse == $event->date_start_in_calendar) {
1069  $dateendtouse++;
1070  }
1071 
1072  //print dol_print_date($event->date_start_in_calendar,'dayhour').'-'.dol_print_date($a,'dayhour').'-'.dol_print_date($b,'dayhour').'<br>';
1073 
1074  if ($event->date_start_in_calendar < $b && $dateendtouse > $a) {
1075  $busy = $event->transparency;
1076  $cases1[$h][$event->id]['busy'] = $busy;
1077  $cases1[$h][$event->id]['string'] = dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzuserrel');
1078  if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) {
1079  $tmpa = dol_getdate($event->date_start_in_calendar, true);
1080  $tmpb = dol_getdate($event->date_end_in_calendar, true);
1081  if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
1082  $cases1[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel');
1083  } else {
1084  $cases1[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzuserrel');
1085  }
1086  }
1087  if ($event->label) {
1088  $cases1[$h][$event->id]['string'] .= ' - '.$event->label;
1089  }
1090  $cases1[$h][$event->id]['typecode'] = $event->type_code;
1091  $cases1[$h][$event->id]['color'] = $color;
1092  if ($event->fk_project > 0) {
1093  if (empty($cacheprojects[$event->fk_project])) {
1094  $tmpproj = new Project($db);
1095  $tmpproj->fetch($event->fk_project);
1096  $cacheprojects[$event->fk_project] = $tmpproj;
1097  }
1098  $cases1[$h][$event->id]['string'] .= ', '.$langs->trans("Project").': '.$cacheprojects[$event->fk_project]->ref.' - '.$cacheprojects[$event->fk_project]->title;
1099  }
1100  if ($event->socid > 0) {
1101  if (empty($cachethirdparties[$event->socid])) {
1102  $tmpthirdparty = new Societe($db);
1103  $tmpthirdparty->fetch($event->socid);
1104  $cachethirdparties[$event->socid] = $tmpthirdparty;
1105  }
1106  $cases1[$h][$event->id]['string'] .= ', '.$cachethirdparties[$event->socid]->name;
1107  }
1108  if ($event->contact_id > 0) {
1109  if (empty($cachecontacts[$event->contact_id])) {
1110  $tmpcontact = new Contact($db);
1111  $tmpcontact->fetch($event->contact_id);
1112  $cachecontacts[$event->contact_id] = $tmpcontact;
1113  }
1114  $cases1[$h][$event->id]['string'] .= ', '.$cachecontacts[$event->contact_id]->getFullName($langs);
1115  }
1116  }
1117  if ($event->date_start_in_calendar < $c && $dateendtouse > $b) {
1118  $busy = $event->transparency;
1119  $cases2[$h][$event->id]['busy'] = $busy;
1120  $cases2[$h][$event->id]['string'] = dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzuserrel');
1121  if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) {
1122  $tmpa = dol_getdate($event->date_start_in_calendar, true);
1123  $tmpb = dol_getdate($event->date_end_in_calendar, true);
1124  if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
1125  $cases2[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel');
1126  } else {
1127  $cases2[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzuserrel');
1128  }
1129  }
1130  if ($event->label) {
1131  $cases2[$h][$event->id]['string'] .= ' - '.$event->label;
1132  }
1133  $cases2[$h][$event->id]['typecode'] = $event->type_code;
1134  $cases2[$h][$event->id]['color'] = $color;
1135  if ($event->fk_project > 0) {
1136  if (empty($cacheprojects[$event->fk_project])) {
1137  $tmpproj = new Project($db);
1138  $tmpproj->fetch($event->fk_project);
1139  $cacheprojects[$event->fk_project] = $tmpproj;
1140  }
1141  $cases2[$h][$event->id]['string'] .= ', '.$langs->trans("Project").': '.$cacheprojects[$event->fk_project]->ref.' - '.$cacheprojects[$event->fk_project]->title;
1142  }
1143  if ($event->socid > 0) {
1144  if (empty($cachethirdparties[$event->socid])) {
1145  $tmpthirdparty = new Societe($db);
1146  $tmpthirdparty->fetch($event->socid);
1147  $cachethirdparties[$event->socid] = $tmpthirdparty;
1148  }
1149  $cases2[$h][$event->id]['string'] .= ', '.$cachethirdparties[$event->socid]->name;
1150  }
1151  if ($event->contact_id > 0) {
1152  if (empty($cachecontacts[$event->contact_id])) {
1153  $tmpcontact = new Contact($db);
1154  $tmpcontact->fetch($event->contact_id);
1155  $cachecontacts[$event->contact_id] = $tmpcontact;
1156  }
1157  $cases2[$h][$event->id]['string'] .= ', '.$cachecontacts[$event->contact_id]->getFullName($langs);
1158  }
1159  }
1160  } else {
1161  $busy = $event->transparency;
1162  $cases1[$h][$event->id]['busy'] = $busy;
1163  $cases2[$h][$event->id]['busy'] = $busy;
1164  $cases1[$h][$event->id]['string'] = $event->label;
1165  $cases2[$h][$event->id]['string'] = $event->label;
1166  $cases1[$h][$event->id]['typecode'] = $event->type_code;
1167  $cases2[$h][$event->id]['typecode'] = $event->type_code;
1168  $cases1[$h][$event->id]['color'] = $color;
1169  $cases2[$h][$event->id]['color'] = $color;
1170  }
1171  }
1172  $i++;
1173  }
1174 
1175  break; // We found the date we were looking for. No need to search anymore.
1176  }
1177  }
1178 
1179  // Now output $casesX from start hour to end hour
1180  for ($h = $begin_h; $h < $end_h; $h++) {
1181  $color1 = ''; $color2 = '';
1182  $style1 = ''; $style2 = '';
1183  $string1 = '&nbsp;'; $string2 = '&nbsp;';
1184  $title1 = ''; $title2 = '';
1185  if (isset($cases1[$h]) && $cases1[$h] != '') {
1186  //$title1.=count($cases1[$h]).' '.(count($cases1[$h])==1?$langs->trans("Event"):$langs->trans("Events"));
1187  if (count($cases1[$h]) > 1) {
1188  $title1 .= count($cases1[$h]).' '.(count($cases1[$h]) == 1 ? $langs->trans("Event") : $langs->trans("Events"));
1189  }
1190  $string1 = '&nbsp;';
1191  if (empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) {
1192  $style1 = 'peruser_notbusy';
1193  } else {
1194  $style1 = 'peruser_busy';
1195  }
1196  foreach ($cases1[$h] as $id => $ev) {
1197  if ($ev['busy']) {
1198  $style1 = 'peruser_busy';
1199  }
1200  }
1201  }
1202  if (isset($cases2[$h]) && $cases2[$h] != '') {
1203  //$title2.=count($cases2[$h]).' '.(count($cases2[$h])==1?$langs->trans("Event"):$langs->trans("Events"));
1204  if (count($cases2[$h]) > 1) {
1205  $title2 .= count($cases2[$h]).' '.(count($cases2[$h]) == 1 ? $langs->trans("Event") : $langs->trans("Events"));
1206  }
1207  $string2 = '&nbsp;';
1208  if (empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) {
1209  $style2 = 'peruser_notbusy';
1210  } else {
1211  $style2 = 'peruser_busy';
1212  }
1213  foreach ($cases2[$h] as $id => $ev) {
1214  if ($ev['busy']) {
1215  $style2 = 'peruser_busy';
1216  }
1217  }
1218  }
1219 
1220  $ids1 = '';
1221  $ids2 = '';
1222  if (!empty($cases1[$h]) && is_array($cases1[$h]) && count($cases1[$h]) && array_keys($cases1[$h])) {
1223  $ids1 = join(',', array_keys($cases1[$h]));
1224  }
1225  if (!empty($cases2[$h]) && is_array($cases2[$h]) && count($cases2[$h]) && array_keys($cases2[$h])) {
1226  $ids2 = join(',', array_keys($cases2[$h]));
1227  }
1228 
1229  if ($h == $begin_h) {
1230  echo '<td class="'.$style.'_peruserleft cal_peruser'.($var ? ' cal_impair '.$style.'_impair' : '').'">';
1231  } else {
1232  echo '<td class="'.$style.' cal_peruser'.($var ? ' cal_impair '.$style.'_impair' : '').'">';
1233  }
1234  if (!empty($cases1[$h]) && is_array($cases1[$h]) && count($cases1[$h]) == 1) { // only 1 event
1235  $output = array_slice($cases1[$h], 0, 1);
1236  $title1 = $langs->trans("Ref").' '.$ids1.($title1 ? ' - '.$title1 : '');
1237  if ($output[0]['string']) {
1238  $title1 .= ($title1 ? ' - ' : '').$output[0]['string'];
1239  }
1240  if ($output[0]['color']) {
1241  $color1 = $output[0]['color'];
1242  }
1243  } elseif (!empty($cases1[$h]) && is_array($cases1[$h]) && count($cases1[$h]) > 1) {
1244  $title1 = $langs->trans("Ref").' '.$ids1.($title1 ? ' - '.$title1 : '');
1245  $color1 = '222222';
1246  }
1247 
1248  if (!empty($cases2[$h]) && is_array($cases2[$h]) && count($cases2[$h]) == 1) { // only 1 event
1249  $output = array_slice($cases2[$h], 0, 1);
1250  $title2 = $langs->trans("Ref").' '.$ids2.($title2 ? ' - '.$title2 : '');
1251  if ($output[0]['string']) {
1252  $title2 .= ($title2 ? ' - ' : '').$output[0]['string'];
1253  }
1254  if ($output[0]['color']) {
1255  $color2 = $output[0]['color'];
1256  }
1257  } elseif (!empty($cases2[$h]) && is_array($cases2[$h]) && count($cases2[$h]) > 1) {
1258  $title2 = $langs->trans("Ref").' '.$ids2.($title2 ? ' - '.$title2 : '');
1259  $color2 = '222222';
1260  }
1261  print '<table class="nobordernopadding" width="100%">';
1262  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.'"' : '').'>';
1263  print $string1;
1264  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.'"' : '').'>';
1265  print $string2;
1266  print '</td></tr>';
1267  print '</table>';
1268  print '</td>';
1269  }
1270 }
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') &&!empty($user->rights->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') &&!empty($user->rights->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)) $resql
Social contributions to pay.
Definition: index.php:745
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:479
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:575
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition: date.lib.php:121
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_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
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.
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='')
Clean a string from all punctuation characters to use it as a ref or login.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
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.