dolibarr  x.y.z
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 if (!$sortfield) {
67  $sortfield = "a.datec";
68 }
69 
70 $sortorder = GETPOST('sortorder', 'aZ09comma');
71 if (!$sortorder) {
72  $sortorder = "ASC";
73 }
74 
75 // Page
76 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
77 if (empty($page) || $page == -1) {
78  $page = 0;
79 } // If $page is not defined, or '' or -1
80 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
81 $offset = $limit * $page;
82 
83 
84 
85 // Security check
86 $socid = GETPOST("search_socid", "int") ?GETPOST("search_socid", "int") : GETPOST("socid", "int");
87 if ($user->socid) {
88  $socid = $user->socid;
89 }
90 if ($socid < 0) {
91  $socid = '';
92 }
93 
94 // Permissions
95 $canedit = 1;
96 if (empty($user->rights->agenda->myactions->read)) {
98 }
99 if (empty($user->rights->agenda->allactions->read)) {
100  $canedit = 0;
101 }
102 if (empty($user->rights->agenda->allactions->read) || $filter == 'mine') { // If no permission to see all, we show only affected to me
103  $filtert = $user->id;
104 }
105 
106 $mode = 'show_pertype';
107 $resourceid = GETPOST("search_resourceid", "int") ? GETPOST("search_resourceid", "int") : GETPOST("resourceid", "int");
108 $year = GETPOST("year", "int") ? GETPOST("year", "int") : date("Y");
109 $month = GETPOST("month", "int") ? GETPOST("month", "int") : date("m");
110 $week = GETPOST("week", "int") ? GETPOST("week", "int") : date("W");
111 $day = GETPOST("day", "int") ? GETPOST("day", "int") : date("d");
112 $pid = GETPOSTISSET("search_projectid") ? GETPOST("search_projectid", "int", 3) : GETPOST("projectid", "int", 3);
113 $status = GETPOSTISSET("search_status") ? GETPOST("search_status", 'alpha') : GETPOST("status", 'alpha');
114 $type = GETPOSTISSET("search_type") ? GETPOST("search_type", 'alpha') : GETPOST("type", 'alpha');
115 $maxprint = ((GETPOST("maxprint", 'int') != '') ? GETPOST("maxprint", 'int') : $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW);
116 $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
117 
118 // Set actioncode (this code must be same for setting actioncode into peruser, listacton and index)
119 if (GETPOST('search_actioncode', 'array')) {
120  $actioncode = GETPOST('search_actioncode', 'array', 3);
121  if (!count($actioncode)) {
122  $actioncode = '0';
123  }
124 } else {
125  $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));
126 }
127 
128 $dateselect = dol_mktime(0, 0, 0, GETPOST('dateselectmonth', 'int'), GETPOST('dateselectday', 'int'), GETPOST('dateselectyear', 'int'));
129 if ($dateselect > 0) {
130  $day = GETPOST('dateselectday', 'int');
131  $month = GETPOST('dateselectmonth', 'int');
132  $year = GETPOST('dateselectyear', 'int');
133 }
134 
135 // working hours
136 $tmp = empty($conf->global->MAIN_DEFAULT_WORKING_HOURS) ? '9-18' : $conf->global->MAIN_DEFAULT_WORKING_HOURS;
137 $tmp = str_replace(' ', '', $tmp); // FIX 7533
138 $tmparray = explode('-', $tmp);
139 $begin_h = GETPOST('begin_h', 'int') != '' ?GETPOST('begin_h', 'int') : ($tmparray[0] != '' ? $tmparray[0] : 9);
140 $end_h = GETPOST('end_h', 'int') ?GETPOST('end_h', 'int') : ($tmparray[1] != '' ? $tmparray[1] : 18);
141 if ($begin_h < 0 || $begin_h > 23) {
142  $begin_h = 9;
143 }
144 if ($end_h < 1 || $end_h > 24) {
145  $end_h = 18;
146 }
147 if ($end_h <= $begin_h) {
148  $end_h = $begin_h + 1;
149 }
150 
151 // working days
152 $tmp = empty($conf->global->MAIN_DEFAULT_WORKING_DAYS) ? '1-5' : $conf->global->MAIN_DEFAULT_WORKING_DAYS;
153 $tmp = str_replace(' ', '', $tmp); // FIX 7533
154 $tmparray = explode('-', $tmp);
155 $begin_d = 1;
156 $end_d = 53;
157 
158 if ($status == '' && !GETPOSTISSET('search_status')) {
159  $status = ((empty($conf->global->AGENDA_DEFAULT_FILTER_STATUS) || $disabledefaultvalues) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_STATUS);
160 }
161 if (empty($mode) && !GETPOSTISSET('mode')) {
162  $mode = (empty($conf->global->AGENDA_DEFAULT_VIEW) ? 'show_month' : $conf->global->AGENDA_DEFAULT_VIEW);
163 }
164 
165 // View by month
166 if (GETPOST('viewcal', 'alpha') && $mode != 'show_day' && $mode != 'show_week' && $mode != 'show_peruser') {
167  $mode = 'show_month'; $day = '';
168 }
169 // View by week
170 if (GETPOST('viewweek', 'alpha') || $mode == 'show_week') {
171  $mode = 'show_week'; $week = ($week ? $week : date("W")); $day = ($day ? $day : date("d"));
172 }
173 // View by day
174 if (GETPOST('viewday', 'alpha') || $mode == 'show_day') {
175  $mode = 'show_day'; $day = ($day ? $day : date("d"));
176 }
177 // View by year
178 if (GETPOST('viewyear', 'alpha') || $mode == 'show_year') {
179  $mode = 'show_year';
180 }
181 
182 // Initialize object
183 $object = new ActionComm($db);
184 
185 // Load translation files required by the page
186 $langs->loadLangs(array('users', 'agenda', 'other', 'commercial'));
187 
188 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
189 $hookmanager->initHooks(array('agenda'));
190 
191 $result = restrictedArea($user, 'agenda', 0, '', 'myactions');
192 if ($user->socid && $socid) {
193  $result = restrictedArea($user, 'societe', $socid);
194 }
195 
196 $search_status = $status;
197 
198 
199 /*
200  * Actions
201  */
202 
203 /*
204 if ($action == 'delete_action' && $user->rights->agenda->delete) {
205  $event = new ActionComm($db);
206  $event->fetch($actionid);
207  $event->fetch_optionals();
208  $event->fetch_userassigned();
209  $event->oldcopy = dol_clone($event);
210 
211  $result = $event->delete();
212 }
213 */
214 
215 
216 /*
217  * View
218  */
219 
220 $parameters = array(
221  'socid' => $socid,
222  'status' => $status,
223  'year' => $year,
224  'month' => $month,
225  'day' => $day,
226  'type' => $type,
227  'maxprint' => $maxprint,
228  'filter' => $filter,
229  'filtert' => $filtert,
230  'showbirthday' => $showbirthday,
231  'canedit' => $canedit,
232  'optioncss' => $optioncss,
233  'actioncode' => $actioncode,
234  'pid' => $pid,
235  'resourceid' => $resourceid,
236  'usergroup' => $usergroup,
237 );
238 
239 $reshook = $hookmanager->executeHooks('beforeAgendaPerType', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
240 if ($reshook < 0) {
241  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
242 }
243 
244 $form = new Form($db);
245 $companystatic = new Societe($db);
246 
247 $help_url = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:M&oacute;dulo_Agenda|DE:Modul_Terminplanung';
248 llxHeader('', $langs->trans("Agenda"), $help_url);
249 
250 $now = dol_now();
251 $nowarray = dol_getdate($now);
252 $nowyear = $nowarray['year'];
253 $nowmonth = $nowarray['mon'];
254 $nowday = $nowarray['mday'];
255 
256 
257 // Define list of all external calendars (global setup)
258 $listofextcals = array();
259 
260 $prev = dol_get_first_day($year, $month);
261 $first_day = 1;
262 $first_month = 1;
263 $first_year = $year;
264 
265 $week = $prev['week'];
266 
267 $day = (int) $day;
268 $next = dol_get_next_day($day, $month, $year);
269 $next_year = $year + 1;
270 $next_month = $month;
271 $next_day = $day;
272 
273 $max_day_in_month = date("t", dol_mktime(0, 0, 0, $month, 1, $year));
274 
275 $tmpday = $first_day;
276 //print 'xx'.$prev_year.'-'.$prev_month.'-'.$prev_day;
277 //print 'xx'.$next_year.'-'.$next_month.'-'.$next_day;
278 
279 $title = $langs->trans("DoneAndToDoActions");
280 if ($status == 'done') {
281  $title = $langs->trans("DoneActions");
282 }
283 if ($status == 'todo') {
284  $title = $langs->trans("ToDoActions");
285 }
286 
287 $param = '';
288 if ($actioncode || GETPOSTISSET('search_actioncode')) {
289  if (is_array($actioncode)) {
290  foreach ($actioncode as $str_action) {
291  $param .= "&search_actioncode[]=".urlencode($str_action);
292  }
293  } else {
294  $param .= "&search_actioncode=".urlencode($actioncode);
295  }
296 }
297 if ($resourceid > 0) {
298  $param .= "&search_resourceid=".urlencode($resourceid);
299 }
300 if ($status || GETPOSTISSET('status') || GETPOSTISSET('search_status')) {
301  $param .= "&search_status=".urlencode($status);
302 }
303 if ($filter) {
304  $param .= "&search_filter=".urlencode($filter);
305 }
306 if ($filtert) {
307  $param .= "&search_filtert=".urlencode($filtert);
308 }
309 if ($usergroup > 0) {
310  $param .= "&search_usergroup=".urlencode($usergroup);
311 }
312 if ($socid > 0) {
313  $param .= "&search_socid=".urlencode($socid);
314 }
315 if ($showbirthday) {
316  $param .= "&search_showbirthday=1";
317 }
318 if ($pid) {
319  $param .= "&search_projectid=".urlencode($pid);
320 }
321 if ($type) {
322  $param .= "&search_type=".urlencode($type);
323 }
324 if ($mode == 'show_day' || $mode == 'show_week' || $mode == 'show_month' || $mode != 'show_peruser') {
325  $param .= '&mode='.urlencode($mode);
326 }
327 if ($begin_h != '') {
328  $param .= '&begin_h='.urlencode($begin_h);
329 }
330 if ($end_h != '') {
331  $param .= '&end_h='.urlencode($end_h);
332 }
333 if ($begin_d != '') {
334  $param .= '&begin_d='.urlencode($begin_d);
335 }
336 if ($end_d != '') {
337  $param .= '&end_d='.urlencode($end_d);
338 }
339 $param .= "&maxprint=".urlencode($maxprint);
340 
341 $paramnoactionodate = $param;
342 
343 $prev = dol_get_first_day($year, 1);
344 $prev_year = $year - 1;
345 $prev_month = $month;
346 $prev_day = $day;
347 $first_day = 1;
348 $first_month = 1;
349 $first_year = $year;
350 
351 $week = $prev['week'];
352 
353 $day = (int) $day;
354 $next = dol_get_next_day(31, 12, $year);
355 $next_year = $year + 1;
356 $next_month = $month;
357 $next_day = $day;
358 
359 // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
360 $firstdaytoshow = dol_mktime(0, 0, 0, $first_month, $first_day, $first_year, 'tzuserrel');
361 $lastdaytoshow = dol_time_plus_duree($firstdaytoshow, 7, 'd');
362 //print $firstday.'-'.$first_month.'-'.$first_year;
363 //print dol_print_date($firstdaytoshow,'dayhour');
364 //print dol_print_date($lastdaytoshow,'dayhour');
365 
366 $max_day_in_month = date("t", dol_mktime(0, 0, 0, $month, 1, $year, 'gmt'));
367 
368 $tmpday = $first_day;
369 $picto = 'calendarweek';
370 
371 $nav = "<a href=\"?year=".$prev_year."&amp;month=".$prev_month."&amp;day=".$prev_day.$param."\">".img_previous($langs->trans("Previous"))."</a>\n";
372 $nav .= " <span id=\"month_name\">".dol_print_date(dol_mktime(0, 0, 0, $first_month, $first_day, $first_year), "%Y")."</span> \n";
373 $nav .= "<a href=\"?year=".$next_year."&amp;month=".$next_month."&amp;day=".$next_day.$param."\">".img_next($langs->trans("Next"))."</a>\n";
374 if (empty($conf->dol_optimize_smallscreen)) {
375  $nav .= " &nbsp; (<a href=\"?year=".$nowyear."&amp;month=".$nowmonth."&amp;day=".$nowday.$param."\">".$langs->trans("Today")."</a>)";
376 }
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 
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))."')";
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))."')";
599  $sql .= " OR ";
600  $sql .= " (a.datep < '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year))."'";
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 == '-1') {
623  $sql .= " AND a.percent = -1";
624 } // Not applicable
625 if ($status == '50') {
626  $sql .= " AND (a.percent > 0 AND a.percent < 100)";
627 } // Running already started
628 if ($status == 'done' || $status == '100') {
629  $sql .= " AND (a.percent = 100)";
630 }
631 if ($status == 'todo') {
632  $sql .= " AND (a.percent >= 0 AND a.percent < 100)";
633 }
634 // We must filter on assignement table
635 if ($filtert > 0 || $usergroup > 0) {
636  $sql .= " AND (";
637  if ($filtert > 0) {
638  $sql .= "ar.fk_element = ".$filtert;
639  }
640  if ($usergroup > 0) {
641  $sql .= ($filtert > 0 ? " OR " : "")." ugu.fk_usergroup = ".((int) $usergroup);
642  }
643  $sql .= ")";
644 }
645 // Sort on date
646 $sql .= ' ORDER BY fk_user_action, datep'; //fk_user_action
647 //print $sql;
648 
649 dol_syslog("comm/action/pertype.php", LOG_DEBUG);
650 $resql = $db->query($sql);
651 if ($resql) {
652  $num = $db->num_rows($resql);
653  $i = 0;
654  while ($i < $num) {
655  $obj = $db->fetch_object($resql);
656 
657  // Discard auto action if option is on
658  if (!empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO) && $obj->code == 'AC_OTH_AUTO') {
659  $i++;
660  continue;
661  }
662 
663  $datep = $db->jdate($obj->datep);
664  $datep2 = $db->jdate($obj->datep2);
665 
666  // Create a new object action
667  $event = new ActionComm($db);
668  $event->id = $obj->id;
669  $event->datep = $datep; // datep and datef are GMT date
670  $event->datef = $datep2;
671  $event->type_code = $obj->code;
672  $event->type_color = $obj->color;
673  $event->label = $obj->label;
674  $event->percentage = $obj->percent;
675  $event->authorid = $obj->fk_user_author; // user id of creator
676  $event->userownerid = $obj->fk_user_action; // user id of owner
677  $event->priority = $obj->priority;
678  $event->fulldayevent = $obj->fulldayevent;
679  $event->location = $obj->location;
680  $event->transparency = $obj->transparency;
681 
682  $event->fk_project = $obj->fk_project;
683 
684  $event->socid = $obj->fk_soc;
685  $event->contact_id = $obj->fk_contact;
686 
687  $event->fk_element = $obj->fk_element;
688  $event->elementtype = $obj->elementtype;
689 
690  // Defined date_start_in_calendar and date_end_in_calendar property
691  // They are date start and end of action but modified to not be outside calendar view.
692  if ($event->percentage <= 0) {
693  $event->date_start_in_calendar = $datep;
694  if ($datep2 != '' && $datep2 >= $datep) {
695  $event->date_end_in_calendar = $datep2;
696  } else {
697  $event->date_end_in_calendar = $datep;
698  }
699  } else {
700  $event->date_start_in_calendar = $datep;
701  if ($datep2 != '' && $datep2 >= $datep) {
702  $event->date_end_in_calendar = $datep2;
703  } else {
704  $event->date_end_in_calendar = $datep;
705  }
706  }
707 
708  // Check values
709  if ($event->date_end_in_calendar < $firstdaytoshow ||
710  $event->date_start_in_calendar >= $lastdaytoshow) {
711  // This record is out of visible range
712  unset($event);
713  } else {
714  //print $i.' - '.dol_print_date($this->date_start_in_calendar, 'dayhour').' - '.dol_print_date($this->date_end_in_calendar, 'dayhour').'<br>'."\n";
715  $event->fetch_userassigned(); // This load $event->userassigned
716 
717  if ($event->date_start_in_calendar < $firstdaytoshow) {
718  $event->date_start_in_calendar = $firstdaytoshow;
719  }
720  if ($event->date_end_in_calendar >= $lastdaytoshow) {
721  $event->date_end_in_calendar = ($lastdaytoshow - 1);
722  }
723 
724  // Add an entry in actionarray for each day
725  $daycursor = $event->date_start_in_calendar;
726  $annee = dol_print_date($daycursor, '%Y', 'tzuserrel');
727  $mois = dol_print_date($daycursor, '%m', 'tzuserrel');
728  $jour = dol_print_date($daycursor, '%d', 'tzuserrel');
729 
730  // Loop on each day covered by action to prepare an index to show on calendar
731  $loop = true; $j = 0;
732  $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
733  do {
734  //if ($event->id==408) print 'daykey='.$daykey.' '.$event->datep.' '.$event->datef.'<br>';
735 
736  $eventarray[$daykey][] = $event;
737  $j++;
738 
739  $daykey += 60 * 60 * 24;
740  if ($daykey > $event->date_end_in_calendar) {
741  $loop = false;
742  }
743  } while ($loop);
744 
745  //print 'Event '.$i.' id='.$event->id.' (start='.dol_print_date($event->datep).'-end='.dol_print_date($event->datef);
746  //print ' startincalendar='.dol_print_date($event->date_start_in_calendar).'-endincalendar='.dol_print_date($event->date_end_in_calendar).') was added in '.$j.' different index key of array<br>';
747  }
748  $i++;
749  }
750  $db->free($resql);
751 } else {
752  dol_print_error($db);
753 }
754 
755 $maxnbofchar = 18;
756 $cachethirdparties = array();
757 $cachecontacts = array();
758 $cacheusers = array();
759 
760 // Define theme_datacolor array
761 $color_file = DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/theme_vars.inc.php";
762 if (is_readable($color_file)) {
763  include $color_file;
764 }
765 if (!is_array($theme_datacolor)) {
766  $theme_datacolor = array(array(120, 130, 150), array(200, 160, 180), array(190, 190, 220));
767 }
768 
769 
770 $newparam = $param; // newparam is for birthday links
771 $newparam = preg_replace('/showbirthday=/i', 'showbirthday_=', $newparam); // To avoid replacement when replace day= is done
772 $newparam = preg_replace('/mode=show_month&?/i', '', $newparam);
773 $newparam = preg_replace('/mode=show_week&?/i', '', $newparam);
774 $newparam = preg_replace('/day=[0-9]+&?/i', '', $newparam);
775 $newparam = preg_replace('/month=[0-9]+&?/i', '', $newparam);
776 $newparam = preg_replace('/year=[0-9]+&?/i', '', $newparam);
777 $newparam = preg_replace('/viewweek=[0-9]+&?/i', '', $newparam);
778 $newparam = preg_replace('/showbirthday_=/i', 'showbirthday=', $newparam); // Restore correct parameter
779 $newparam .= '&viewweek=1';
780 
781 print '<input type="hidden" name="action" value="mupdate">';
782 echo '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($_SERVER['PHP_SELF']).'?'.dol_escape_htmltag($_SERVER['QUERY_STRING']).'">';
783 echo '<input type="hidden" name="token" value="'.newToken().'">';
784 echo '<input type="hidden" name="newdate" id="newdate">';
785 
786 
787 // Line header with list of days
788 
789 //print "begin_d=".$begin_d." end_d=".$end_d;
790 
791 
792 echo '<table width="100%" class="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  $tmparray = dol_getdate($curtime, 'fast');
851  $tmpday = $tmparray['mday'];
852  $tmpmonth = $tmparray['mon'];
853  $tmpyear = $tmparray['year'];
854 
855  $style = 'cal_current_month';
856  if ($iter_day == 6) {
857  $style .= ' cal_other_month';
858  }
859  $today = 0;
860  if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $tmpmonth && $todayarray['year'] == $tmpyear) {
861  $today = 1;
862  }
863  if ($today) {
864  $style = 'cal_today_peruser';
865  }
866 
867  show_day_events_pertype($typeofevent, $tmpday, $tmpmonth, $tmpyear, 0, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, $showheader, $colorsbytype, $var);
868 
869  $i++;
870  }
871  echo "</tr>\n";
872  $showheader = false;
873 }
874 
875 echo "</table>\n";
876 echo "<br>";
877 
878 if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
879  $langs->load("commercial");
880  print '<br>'.$langs->trans("Legend").': <br>';
881  foreach ($colorsbytype as $code => $color) {
882  if ($color) {
883  print '<div style="float: left; padding: 2px; margin-right: 6px;"><div style="'.($color ? 'background: #'.$color.';' : '').'width:16px; float: left; margin-right: 4px;">&nbsp;</div>';
884  print $langs->trans("Action".$code) != "Action".$code ? $langs->trans("Action".$code) : $labelbytype[$code];
885  //print $code;
886  print '</div>';
887  }
888  }
889  //$color=sprintf("%02x%02x%02x",$theme_datacolor[0][0],$theme_datacolor[0][1],$theme_datacolor[0][2]);
890  print '<div style="float: left; padding: 2px; margin-right: 6px;"><div class="peruser_busy" style="width:16px; float: left; margin-right: 4px;">&nbsp;</div>';
891  print $langs->trans("Other");
892  print '</div>';
893  /* TODO Show this if at least one cumulated event
894  print '<div style="float: left; padding: 2px; margin-right: 6px;"><div style="background: #222222; width:16px; float: left; margin-right: 4px;">&nbsp;</div>';
895  print $langs->trans("SeveralEvents");
896  print '</div>';
897  */
898 }
899 
900 print "\n".'</form>';
901 print "\n";
902 
903 // Add js code to manage click on a box
904 print '<script type="text/javascript">
905 jQuery(document).ready(function() {
906  jQuery(".onclickopenref").click(function() {
907  var ref=$(this).attr(\'ref\');
908  var res = ref.split("_");
909  var userid = res[1];
910  var year = res[2];
911  var month = res[3];
912  var day = res[4];
913  var hour = res[5];
914  var min = res[6];
915  var ids = res[7];
916  if (ids == \'none\') /* No event */
917  {
918  /* alert(\'no event\'); */
919  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).'"
920  window.location.href = url;
921  }
922  else if (ids.indexOf(",") > -1) /* There is several events */
923  {
924  /* alert(\'several events\'); */
925  url = "'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&filtert="+userid+"&dateselectyear="+year+"&dateselectmonth="+month+"&dateselectday="+day;
926  window.location.href = url;
927  }
928  else /* One event */
929  {
930  /* alert(\'one event\'); */
931  url = "'.DOL_URL_ROOT.'/comm/action/card.php?action=view&id="+ids
932  window.location.href = url;
933  }
934  });
935 });
936 </script>';
937 
938 // End of page
939 llxFooter();
940 $db->close();
941 
942 
943 
944 
965 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)
966 {
967  global $db;
968  global $user, $conf, $langs, $hookmanager, $action;
969  global $filter, $filtert, $status, $actioncode; // Filters used into search form
970  global $theme_datacolor; // Array with a list of different we can use (come from theme)
971  global $cachethirdparties, $cachecontacts, $cacheusers, $cacheprojects, $colorindexused;
972  global $begin_h, $end_h;
973 
974  $cases1 = array(); // Color first half hour
975  $cases2 = array(); // Color second half hour
976 
977  $i = 0; $nummytasks = 0; $numother = 0; $numbirthday = 0; $numical = 0; $numicals = array();
978  $ymd = sprintf("%04d", $year).sprintf("%02d", $month).sprintf("%02d", $day);
979 
980  $nextindextouse = count($colorindexused); // At first run, this is 0, so fist user has 0, next 1, ...
981  //if ($username->id && $day==1) {
982  //var_dump($eventarray);
983  //}
984 
985  // We are in a particular day for $username, now we scan all events
986  foreach ($eventarray as $daykey => $notused) {
987  $annee = dol_print_date($daykey, '%Y');
988  $mois = dol_print_date($daykey, '%m');
989  $jour = dol_print_date($daykey, '%d');
990 
991  if ($day == $jour && $month == $mois && $year == $annee) { // Is it the day we are looking for when calling function ?
992  // Scan all event for this date
993  foreach ($eventarray[$daykey] as $index => $event) {
994  //print $daykey.' '.$year.'-'.$month.'-'.$day.' -> '.$event->id.' '.$index.' '.$annee.'-'.$mois.'-'.$jour."<br>\n";
995  //var_dump($event);
996 
997  $keysofuserassigned = array_keys($event->userassigned);
998  if (!in_array($username->id, $keysofuserassigned)) {
999  continue; // We discard record if event is from another user than user we want to show
1000  }
1001  //if ($username->id != $event->userownerid) continue; // We discard record if event is from another user than user we want to show
1002 
1003  $parameters = array();
1004  $reshook = $hookmanager->executeHooks('formatEvent', $parameters, $event, $action); // Note that $action and $object may have been modified by some hooks
1005  if ($reshook < 0) {
1006  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1007  }
1008 
1009  $ponct = ($event->date_start_in_calendar == $event->date_end_in_calendar);
1010 
1011  // Define $color (Hex string like '0088FF') and $cssclass of event
1012  $color = -1; $cssclass = ''; $colorindex = -1;
1013  if (in_array($user->id, $keysofuserassigned)) {
1014  $nummytasks++; $cssclass = 'family_mytasks';
1015  if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
1016  $color = $event->type_color;
1017  }
1018  } elseif ($event->type_code == 'ICALEVENT') {
1019  $numical++;
1020  if (!empty($event->icalname)) {
1021  if (!isset($numicals[dol_string_nospecial($event->icalname)])) {
1022  $numicals[dol_string_nospecial($event->icalname)] = 0;
1023  }
1024  $numicals[dol_string_nospecial($event->icalname)]++;
1025  }
1026 
1027  $color = $event->icalcolor;
1028  $cssclass = (!empty($event->icalname) ? 'family_ext'.md5($event->icalname) : 'family_other unsortable');
1029  } elseif ($event->type_code == 'BIRTHDAY') {
1030  $numbirthday++; $colorindex = 2; $cssclass = 'family_birthday unsortable'; $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
1031  } else {
1032  $numother++; $cssclass = 'family_other';
1033  if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
1034  $color = $event->type_color;
1035  }
1036  }
1037 
1038  if ($color < 0) { // Color was not set on user card. Set color according to color index.
1039  // Define color index if not yet defined
1040  $idusertouse = ($event->userownerid ? $event->userownerid : 0);
1041  if (isset($colorindexused[$idusertouse])) {
1042  $colorindex = $colorindexused[$idusertouse]; // Color already assigned to this user
1043  } else {
1044  $colorindex = $nextindextouse;
1045  $colorindexused[$idusertouse] = $colorindex;
1046  if (!empty($theme_datacolor[$nextindextouse + 1])) {
1047  $nextindextouse++; // Prepare to use next color
1048  }
1049  }
1050  // Define color
1051  $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
1052  }
1053  //$cssclass=$cssclass.' '.$cssclass.'_day_'.$ymd;
1054 
1055  // Define all rects with event (cases1 is first half hour, cases2 is second half hour)
1056  for ($h = $begin_h; $h < $end_h; $h++) {
1057  //if ($username->id == 1 && $day==1) print 'h='.$h;
1058  $newcolor = ''; //init
1059  if (empty($event->fulldayevent)) {
1060  $a = dol_mktime((int) $h, 0, 0, $month, $day, $year, 'tzuserrel', 0);
1061  $b = dol_mktime((int) $h, 30, 0, $month, $day, $year, 'tzuserrel', 0);
1062  $c = dol_mktime((int) $h + 1, 0, 0, $month, $day, $year, 'tzuserrel', 0);
1063 
1064  $dateendtouse = $event->date_end_in_calendar;
1065  if ($dateendtouse == $event->date_start_in_calendar) {
1066  $dateendtouse++;
1067  }
1068 
1069  //print dol_print_date($event->date_start_in_calendar,'dayhour').'-'.dol_print_date($a,'dayhour').'-'.dol_print_date($b,'dayhour').'<br>';
1070 
1071  if ($event->date_start_in_calendar < $b && $dateendtouse > $a) {
1072  $busy = $event->transparency;
1073  $cases1[$h][$event->id]['busy'] = $busy;
1074  $cases1[$h][$event->id]['string'] = dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzuserrel');
1075  if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) {
1076  $tmpa = dol_getdate($event->date_start_in_calendar, true);
1077  $tmpb = dol_getdate($event->date_end_in_calendar, true);
1078  if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
1079  $cases1[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel');
1080  } else {
1081  $cases1[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzuserrel');
1082  }
1083  }
1084  if ($event->label) {
1085  $cases1[$h][$event->id]['string'] .= ' - '.$event->label;
1086  }
1087  $cases1[$h][$event->id]['typecode'] = $event->type_code;
1088  $cases1[$h][$event->id]['color'] = $color;
1089  if ($event->fk_project > 0) {
1090  if (empty($cacheprojects[$event->fk_project])) {
1091  $tmpproj = new Project($db);
1092  $tmpproj->fetch($event->fk_project);
1093  $cacheprojects[$event->fk_project] = $tmpproj;
1094  }
1095  $cases1[$h][$event->id]['string'] .= ', '.$langs->trans("Project").': '.$cacheprojects[$event->fk_project]->ref.' - '.$cacheprojects[$event->fk_project]->title;
1096  }
1097  if ($event->socid > 0) {
1098  if (empty($cachethirdparties[$event->socid])) {
1099  $tmpthirdparty = new Societe($db);
1100  $tmpthirdparty->fetch($event->socid);
1101  $cachethirdparties[$event->socid] = $tmpthirdparty;
1102  }
1103  $cases1[$h][$event->id]['string'] .= ', '.$cachethirdparties[$event->socid]->name;
1104  }
1105  if ($event->contact_id > 0) {
1106  if (empty($cachecontacts[$event->contact_id])) {
1107  $tmpcontact = new Contact($db);
1108  $tmpcontact->fetch($event->contact_id);
1109  $cachecontacts[$event->contact_id] = $tmpcontact;
1110  }
1111  $cases1[$h][$event->id]['string'] .= ', '.$cachecontacts[$event->contact_id]->getFullName($langs);
1112  }
1113  }
1114  if ($event->date_start_in_calendar < $c && $dateendtouse > $b) {
1115  $busy = $event->transparency;
1116  $cases2[$h][$event->id]['busy'] = $busy;
1117  $cases2[$h][$event->id]['string'] = dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzuserrel');
1118  if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) {
1119  $tmpa = dol_getdate($event->date_start_in_calendar, true);
1120  $tmpb = dol_getdate($event->date_end_in_calendar, true);
1121  if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) {
1122  $cases2[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel');
1123  } else {
1124  $cases2[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzuserrel');
1125  }
1126  }
1127  if ($event->label) {
1128  $cases2[$h][$event->id]['string'] .= ' - '.$event->label;
1129  }
1130  $cases2[$h][$event->id]['typecode'] = $event->type_code;
1131  $cases2[$h][$event->id]['color'] = $color;
1132  if ($event->fk_project > 0) {
1133  if (empty($cacheprojects[$event->fk_project])) {
1134  $tmpproj = new Project($db);
1135  $tmpproj->fetch($event->fk_project);
1136  $cacheprojects[$event->fk_project] = $tmpproj;
1137  }
1138  $cases2[$h][$event->id]['string'] .= ', '.$langs->trans("Project").': '.$cacheprojects[$event->fk_project]->ref.' - '.$cacheprojects[$event->fk_project]->title;
1139  }
1140  if ($event->socid > 0) {
1141  if (empty($cachethirdparties[$event->socid])) {
1142  $tmpthirdparty = new Societe($db);
1143  $tmpthirdparty->fetch($event->socid);
1144  $cachethirdparties[$event->socid] = $tmpthirdparty;
1145  }
1146  $cases2[$h][$event->id]['string'] .= ', '.$cachethirdparties[$event->socid]->name;
1147  }
1148  if ($event->contact_id > 0) {
1149  if (empty($cachecontacts[$event->contact_id])) {
1150  $tmpcontact = new Contact($db);
1151  $tmpcontact->fetch($event->contact_id);
1152  $cachecontacts[$event->contact_id] = $tmpcontact;
1153  }
1154  $cases2[$h][$event->id]['string'] .= ', '.$cachecontacts[$event->contact_id]->getFullName($langs);
1155  }
1156  }
1157  } else {
1158  $busy = $event->transparency;
1159  $cases1[$h][$event->id]['busy'] = $busy;
1160  $cases2[$h][$event->id]['busy'] = $busy;
1161  $cases1[$h][$event->id]['string'] = $event->label;
1162  $cases2[$h][$event->id]['string'] = $event->label;
1163  $cases1[$h][$event->id]['typecode'] = $event->type_code;
1164  $cases2[$h][$event->id]['typecode'] = $event->type_code;
1165  $cases1[$h][$event->id]['color'] = $color;
1166  $cases2[$h][$event->id]['color'] = $color;
1167  }
1168  }
1169  $i++;
1170  }
1171 
1172  break; // We found the date we were looking for. No need to search anymore.
1173  }
1174  }
1175 
1176  // Now output $casesX
1177  for ($h = $begin_h; $h < $end_h; $h++) {
1178  $color1 = ''; $color2 = '';
1179  $style1 = ''; $style2 = '';
1180  $string1 = '&nbsp;'; $string2 = '&nbsp;';
1181  $title1 = ''; $title2 = '';
1182  if (isset($cases1[$h]) && $cases1[$h] != '') {
1183  //$title1.=count($cases1[$h]).' '.(count($cases1[$h])==1?$langs->trans("Event"):$langs->trans("Events"));
1184  if (count($cases1[$h]) > 1) {
1185  $title1 .= count($cases1[$h]).' '.(count($cases1[$h]) == 1 ? $langs->trans("Event") : $langs->trans("Events"));
1186  }
1187  $string1 = '&nbsp;';
1188  if (empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) {
1189  $style1 = 'peruser_notbusy';
1190  } else {
1191  $style1 = 'peruser_busy';
1192  }
1193  foreach ($cases1[$h] as $id => $ev) {
1194  if ($ev['busy']) {
1195  $style1 = 'peruser_busy';
1196  }
1197  }
1198  }
1199  if (isset($cases2[$h]) && $cases2[$h] != '') {
1200  //$title2.=count($cases2[$h]).' '.(count($cases2[$h])==1?$langs->trans("Event"):$langs->trans("Events"));
1201  if (count($cases2[$h]) > 1) {
1202  $title2 .= count($cases2[$h]).' '.(count($cases2[$h]) == 1 ? $langs->trans("Event") : $langs->trans("Events"));
1203  }
1204  $string2 = '&nbsp;';
1205  if (empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) {
1206  $style2 = 'peruser_notbusy';
1207  } else {
1208  $style2 = 'peruser_busy';
1209  }
1210  foreach ($cases2[$h] as $id => $ev) {
1211  if ($ev['busy']) {
1212  $style2 = 'peruser_busy';
1213  }
1214  }
1215  }
1216 
1217  $ids1 = ''; $ids2 = '';
1218  if (count($cases1[$h]) && array_keys($cases1[$h])) {
1219  $ids1 = join(',', array_keys($cases1[$h]));
1220  }
1221  if (count($cases2[$h]) && array_keys($cases2[$h])) {
1222  $ids2 = join(',', array_keys($cases2[$h]));
1223  }
1224 
1225  if ($h == $begin_h) {
1226  echo '<td class="'.$style.'_peruserleft cal_peruser'.($var ? ' cal_impair '.$style.'_impair' : '').'">';
1227  } else {
1228  echo '<td class="'.$style.' cal_peruser'.($var ? ' cal_impair '.$style.'_impair' : '').'">';
1229  }
1230  if (count($cases1[$h]) == 1) { // only 1 event
1231  $output = array_slice($cases1[$h], 0, 1);
1232  $title1 = $langs->trans("Ref").' '.$ids1.($title1 ? ' - '.$title1 : '');
1233  if ($output[0]['string']) {
1234  $title1 .= ($title1 ? ' - ' : '').$output[0]['string'];
1235  }
1236  if ($output[0]['color']) {
1237  $color1 = $output[0]['color'];
1238  }
1239  } elseif (count($cases1[$h]) > 1) {
1240  $title1 = $langs->trans("Ref").' '.$ids1.($title1 ? ' - '.$title1 : '');
1241  $color1 = '222222';
1242  }
1243 
1244  if (count($cases2[$h]) == 1) { // only 1 event
1245  $output = array_slice($cases2[$h], 0, 1);
1246  $title2 = $langs->trans("Ref").' '.$ids2.($title2 ? ' - '.$title2 : '');
1247  if ($output[0]['string']) {
1248  $title2 .= ($title2 ? ' - ' : '').$output[0]['string'];
1249  }
1250  if ($output[0]['color']) {
1251  $color2 = $output[0]['color'];
1252  }
1253  } elseif (count($cases2[$h]) > 1) {
1254  $title2 = $langs->trans("Ref").' '.$ids2.($title2 ? ' - '.$title2 : '');
1255  $color2 = '222222';
1256  }
1257  print '<table class="nobordernopadding" width="100%">';
1258  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.'"' : '').'>';
1259  print $string1;
1260  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.'"' : '').'>';
1261  print $string2;
1262  print '</td></tr>';
1263  print '</table>';
1264  print '</td>';
1265  }
1266 }
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.