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