dolibarr  13.0.2
index.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-2018 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) 2015 Marcos García <marcosgdf@gmail.com>
9  * Copyright (C) 2017 Open-DSI <support@open-dsi.fr>
10  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <https://www.gnu.org/licenses/>.
24  */
25 
26 
33 require '../../main.inc.php';
34 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
39 if (!empty($conf->projet->enabled)) {
40  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
41 }
42 
43 if (!isset($conf->global->AGENDA_MAX_EVENTS_DAY_VIEW)) $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW = 3;
44 
45 if (empty($conf->global->AGENDA_EXT_NB)) $conf->global->AGENDA_EXT_NB = 5;
46 $MAXAGENDA = $conf->global->AGENDA_EXT_NB;
47 
48 $filter = GETPOST("search_filter", 'alpha', 3) ?GETPOST("search_filter", 'alpha', 3) : GETPOST("filter", 'alpha', 3);
49 $filtert = GETPOST("search_filtert", "int", 3) ?GETPOST("search_filtert", "int", 3) : GETPOST("filtert", "int", 3);
50 $usergroup = GETPOST("search_usergroup", "int", 3) ?GETPOST("search_usergroup", "int", 3) : GETPOST("usergroup", "int", 3);
51 $showbirthday = empty($conf->use_javascript_ajax) ?GETPOST("showbirthday", "int") : 1;
52 
53 // If not choice done on calendar owner (like on left menu link "Agenda"), we filter on user.
54 if (empty($filtert) && empty($conf->global->AGENDA_ALL_CALENDARS))
55 {
56  $filtert = $user->id;
57 }
58 
59 $sortfield = GETPOST("sortfield", 'alpha');
60 $sortorder = GETPOST("sortorder", 'alpha');
61 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
62 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
63 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
64 $offset = $limit * $page;
65 if (!$sortorder) $sortorder = "ASC";
66 if (!$sortfield) $sortfield = "a.datec";
67 
68 // Security check
69 $socid = GETPOST("search_socid", "int") ?GETPOST("search_socid", "int") : GETPOST("socid", "int");
70 if ($user->socid) $socid = $user->socid;
71 $result = restrictedArea($user, 'agenda', 0, '', 'myactions');
72 if ($socid < 0) $socid = '';
73 
74 $canedit = 1;
75 if (!$user->rights->agenda->myactions->read) accessforbidden();
76 if (!$user->rights->agenda->allactions->read) $canedit = 0;
77 if (!$user->rights->agenda->allactions->read || $filter == 'mine') // If no permission to see all, we show only affected to me
78 {
79  $filtert = $user->id;
80 }
81 
82 $action = GETPOST('action', 'aZ09');
83 $resourceid = GETPOST("search_resourceid", "int");
84 $year = GETPOST("year", "int") ?GETPOST("year", "int") : date("Y");
85 $month = GETPOST("month", "int") ?GETPOST("month", "int") : date("m");
86 $week = GETPOST("week", "int") ?GETPOST("week", "int") : date("W");
87 $day = GETPOST("day", "int") ?GETPOST("day", "int") : date("d");
88 $pid = GETPOST("search_projectid", "int", 3) ?GETPOST("search_projectid", "int", 3) : GETPOST("projectid", "int", 3);
89 $status = GETPOST("search_status", 'aZ09') ?GETPOST("search_status", 'aZ09') : GETPOST("status", 'aZ09'); // status may be 0, 50, 100, 'todo'
90 $type = GETPOST("search_type", 'aZ09') ?GETPOST("search_type", 'aZ09') : GETPOST("type", 'aZ09');
91 $maxprint = (isset($_GET["maxprint"]) ?GETPOST("maxprint") : $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW);
92 $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
93 
94 $dateselect = dol_mktime(0, 0, 0, GETPOST('dateselectmonth', 'int'), GETPOST('dateselectday', 'int'), GETPOST('dateselectyear', 'int'));
95 if ($dateselect > 0)
96 {
97  $day = GETPOST('dateselectday', 'int');
98  $month = GETPOST('dateselectmonth', 'int');
99  $year = GETPOST('dateselectyear', 'int');
100 }
101 
102 // Set actioncode (this code must be same for setting actioncode into peruser, listacton and index)
103 if (GETPOST('search_actioncode', 'array'))
104 {
105  $actioncode = GETPOST('search_actioncode', 'array', 3);
106  if (!count($actioncode)) $actioncode = '0';
107 } else {
108  $actioncode = GETPOST("search_actioncode", "alpha", 3) ?GETPOST("search_actioncode", "alpha", 3) : (GETPOST("search_actioncode") == '0' ? '0' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE));
109 }
110 if ($actioncode == '' && empty($actioncodearray)) $actioncode = (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE);
111 
112 if ($status == '' && !GETPOSTISSET('search_status')) $status = (empty($conf->global->AGENDA_DEFAULT_FILTER_STATUS) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_STATUS);
113 
114 $defaultview = (empty($conf->global->AGENDA_DEFAULT_VIEW) ? 'show_month' : $conf->global->AGENDA_DEFAULT_VIEW);
115 $defaultview = (empty($user->conf->AGENDA_DEFAULT_VIEW) ? $defaultview : $user->conf->AGENDA_DEFAULT_VIEW);
116 if (empty($action) && !GETPOSTISSET('action')) $action = $defaultview;
117 if ($action == 'default') // When action is default, we want a calendar view and not the list
118 {
119  $action = (($defaultview != 'show_list') ? $defaultview : 'show_month');
120 }
121 if (GETPOST('viewcal', 'restricthtml') && GETPOST('action', 'alpha') != 'show_day' && GETPOST('action', 'alpha') != 'show_week') {
122  $action = 'show_month'; $day = '';
123 } // View by month
124 if (GETPOST('viewweek', 'restricthtml') || GETPOST('action', 'alpha') == 'show_week') {
125  $action = 'show_week'; $week = ($week ? $week : date("W")); $day = ($day ? $day : date("d"));
126 } // View by week
127 if (GETPOST('viewday', 'restricthtml') || GETPOST('action', 'alpha') == 'show_day') {
128  $action = 'show_day'; $day = ($day ? $day : date("d"));
129 } // View by day
130 
131 // Load translation files required by the page
132 $langs->loadLangs(array('agenda', 'other', 'commercial'));
133 
134 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
135 $hookmanager->initHooks(array('agenda'));
136 
137 
138 /*
139  * Actions
140  */
141 
142 if (GETPOST("viewlist", 'alpha') || $action == 'show_list')
143 {
144  $param = '';
145  if (is_array($_POST))
146  {
147  foreach ($_POST as $key => $val)
148  {
149  if ($key == 'token') continue;
150  $param .= '&'.$key.'='.urlencode($val);
151  }
152  }
153  if (!preg_match('/action=/', $param)) $param .= ($param ? '&' : '').'action=show_list';
154  //print $param;
155  header("Location: ".DOL_URL_ROOT.'/comm/action/list.php?'.$param);
156  exit;
157 }
158 
159 if (GETPOST("viewperuser", 'alpha') || $action == 'show_peruser')
160 {
161  $param = '';
162  if (is_array($_POST))
163  {
164  foreach ($_POST as $key => $val)
165  {
166  if ($key == 'token') continue;
167  $param .= '&'.$key.'='.urlencode($val);
168  }
169  }
170  //print $param;
171  header("Location: ".DOL_URL_ROOT.'/comm/action/peruser.php?'.$param);
172  exit;
173 }
174 
175 if ($action == 'delete_action')
176 {
177  $event = new ActionComm($db);
178  $event->fetch($actionid);
179  $event->fetch_optionals();
180  $event->fetch_userassigned();
181  $event->oldcopy = clone $event;
182 
183  $result = $event->delete();
184 }
185 
186 
187 /*
188  * View
189  */
190 $parameters = array(
191  'socid' => $socid,
192  'status' => $status,
193  'year' => $year,
194  'month' => $month,
195  'day' => $day,
196  'type' => $type,
197  'maxprint' => $maxprint,
198  'filter' => $filter,
199  'filtert' => $filtert,
200  'showbirthday' => $showbirthday,
201  'canedit' => $canedit,
202  'optioncss' => $optioncss,
203  'actioncode' => $actioncode,
204  'pid' => $pid,
205  'resourceid' => $resourceid,
206  'usergroup' => $usergroup,
207 );
208 $reshook = $hookmanager->executeHooks('beforeAgenda', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
209 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
210 
211 $help_url = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:M&oacute;dulo_Agenda';
212 llxHeader('', $langs->trans("Agenda"), $help_url);
213 
214 $form = new Form($db);
215 $companystatic = new Societe($db);
216 $contactstatic = new Contact($db);
217 $userstatic = new User($db);
218 
219 $now = dol_now();
220 $nowarray = dol_getdate($now);
221 $nowyear = $nowarray['year'];
222 $nowmonth = $nowarray['mon'];
223 $nowday = $nowarray['mday'];
224 
225 $listofextcals = array();
226 
227 // Define list of external calendars (global admin setup)
228 if (empty($conf->global->AGENDA_DISABLE_EXT))
229 {
230  $i = 0;
231  while ($i < $MAXAGENDA)
232  {
233  $i++;
234  $source = 'AGENDA_EXT_SRC'.$i;
235  $name = 'AGENDA_EXT_NAME'.$i;
236  $offsettz = 'AGENDA_EXT_OFFSETTZ'.$i;
237  $color = 'AGENDA_EXT_COLOR'.$i;
238  $buggedfile = 'AGENDA_EXT_BUGGEDFILE'.$i;
239  if (!empty($conf->global->$source) && !empty($conf->global->$name))
240  {
241  // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight'
242  $listofextcals[] = array('src'=>$conf->global->$source, 'name'=>$conf->global->$name, 'offsettz'=>$conf->global->$offsettz, 'color'=>$conf->global->$color, 'buggedfile'=>(isset($conf->global->buggedfile) ? $conf->global->buggedfile : 0));
243  }
244  }
245 }
246 // Define list of external calendars (user setup)
247 if (empty($user->conf->AGENDA_DISABLE_EXT))
248 {
249  $i = 0;
250  while ($i < $MAXAGENDA)
251  {
252  $i++;
253  $source = 'AGENDA_EXT_SRC_'.$user->id.'_'.$i;
254  $name = 'AGENDA_EXT_NAME_'.$user->id.'_'.$i;
255  $offsettz = 'AGENDA_EXT_OFFSETTZ_'.$user->id.'_'.$i;
256  $color = 'AGENDA_EXT_COLOR_'.$user->id.'_'.$i;
257  $enabled = 'AGENDA_EXT_ENABLED_'.$user->id.'_'.$i;
258  $buggedfile = 'AGENDA_EXT_BUGGEDFILE_'.$user->id.'_'.$i;
259  if (!empty($user->conf->$source) && !empty($user->conf->$name))
260  {
261  // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight'
262  $listofextcals[] = array('src'=>$user->conf->$source, 'name'=>$user->conf->$name, 'offsettz'=>$user->conf->$offsettz, 'color'=>$user->conf->$color, 'buggedfile'=>(isset($user->conf->buggedfile) ? $user->conf->buggedfile : 0));
263  }
264  }
265 }
266 
267 if (empty($action) || $action == 'show_month')
268 {
269  $prev = dol_get_prev_month($month, $year);
270  $prev_year = $prev['year'];
271  $prev_month = $prev['month'];
272  $next = dol_get_next_month($month, $year);
273  $next_year = $next['year'];
274  $next_month = $next['month'];
275 
276  $max_day_in_prev_month = date("t", dol_mktime(0, 0, 0, $prev_month, 1, $prev_year, 'gmt')); // Nb of days in previous month
277  $max_day_in_month = date("t", dol_mktime(0, 0, 0, $month, 1, $year)); // Nb of days in next month
278  // tmpday is a negative or null cursor to know how many days before the 1st to show on month view (if tmpday=0, 1st is monday)
279  $tmpday = -date("w", dol_mktime(12, 0, 0, $month, 1, $year, 'gmt')) + 2; // date('w') is 0 fo sunday
280  $tmpday += ((isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1) - 1);
281  if ($tmpday >= 1) $tmpday -= 7; // If tmpday is 0 we start with sunday, if -6, we start with monday of previous week.
282  // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
283  $firstdaytoshow = dol_mktime(0, 0, 0, $prev_month, $max_day_in_prev_month + $tmpday, $prev_year, 'tzuserrel');
284  $next_day = 7 - ($max_day_in_month + 1 - $tmpday) % 7;
285  if ($next_day < 6) $next_day += 7;
286  $lastdaytoshow = dol_mktime(0, 0, 0, $next_month, $next_day, $next_year, 'tzuserrel');
287 }
288 if ($action == 'show_week')
289 {
290  $prev = dol_get_first_day_week($day, $month, $year);
291  $prev_year = $prev['prev_year'];
292  $prev_month = $prev['prev_month'];
293  $prev_day = $prev['prev_day'];
294  $first_day = $prev['first_day'];
295  $first_month = $prev['first_month'];
296  $first_year = $prev['first_year'];
297 
298  $week = $prev['week'];
299 
300  $day = (int) $day;
301  $next = dol_get_next_week($first_day, $week, $first_month, $first_year);
302  $next_year = $next['year'];
303  $next_month = $next['month'];
304  $next_day = $next['day'];
305 
306  // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
307  $firstdaytoshow = dol_mktime(0, 0, 0, $first_month, $first_day, $first_year, 'tzuserrel');
308  $lastdaytoshow = dol_time_plus_duree($firstdaytoshow, 7, 'd');
309 
310  $max_day_in_month = date("t", dol_mktime(0, 0, 0, $month, 1, $year, 'gmt'));
311 
312  $tmpday = $first_day;
313 }
314 if ($action == 'show_day')
315 {
316  $prev = dol_get_prev_day($day, $month, $year);
317  $prev_year = $prev['year'];
318  $prev_month = $prev['month'];
319  $prev_day = $prev['day'];
320  $next = dol_get_next_day($day, $month, $year);
321  $next_year = $next['year'];
322  $next_month = $next['month'];
323  $next_day = $next['day'];
324 
325  // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
326  $firstdaytoshow = dol_mktime(0, 0, 0, $prev_month, $prev_day, $prev_year, 'tzuserrel');
327  $lastdaytoshow = dol_mktime(0, 0, 0, $next_month, $next_day, $next_year, 'tzuserrel');
328 }
329 //print 'xx'.$prev_year.'-'.$prev_month.'-'.$prev_day;
330 //print 'xx'.$next_year.'-'.$next_month.'-'.$next_day;
331 //print dol_print_date($firstdaytoshow,'day');
332 //print dol_print_date($lastdaytoshow,'day');
333 
334 /*$title = $langs->trans("DoneAndToDoActions");
335 if ($status == 'done') $title = $langs->trans("DoneActions");
336 if ($status == 'todo') $title = $langs->trans("ToDoActions");
337 */
338 
339 $param = '';
340 if ($actioncode || GETPOSTISSET('search_actioncode')) {
341  if (is_array($actioncode)) {
342  foreach ($actioncode as $str_action) $param .= "&search_actioncode[]=".urlencode($str_action);
343  } else $param .= "&search_actioncode=".urlencode($actioncode);
344 }
345 if ($resourceid > 0) $param .= "&search_resourceid=".urlencode($resourceid);
346 if ($status || GETPOSTISSET('status')) $param .= "&search_status=".urlencode($status);
347 if ($filter) $param .= "&search_filter=".urlencode($filter);
348 if ($filtert) $param .= "&search_filtert=".urlencode($filtert);
349 if ($usergroup) $param .= "&search_usergroup=".urlencode($usergroup);
350 if ($socid) $param .= "&search_socid=".urlencode($socid);
351 if ($showbirthday) $param .= "&search_showbirthday=1";
352 if ($pid) $param .= "&search_projectid=".urlencode($pid);
353 if ($type) $param .= "&search_type=".urlencode($type);
354 if ($action == 'show_day' || $action == 'show_week' || $action == 'show_month') $param .= '&action='.urlencode($action);
355 $param .= "&maxprint=".urlencode($maxprint);
356 
357 // Show navigation bar
358 if (empty($action) || $action == 'show_month')
359 {
360  $nav = "<a href=\"?year=".$prev_year."&amp;month=".$prev_month.$param."\"><i class=\"fa fa-chevron-left\"></i></a> &nbsp;\n";
361  $nav .= " <span id=\"month_name\">".dol_print_date(dol_mktime(0, 0, 0, $month, 1, $year), "%b %Y");
362  $nav .= " </span>\n";
363  $nav .= " &nbsp; <a href=\"?year=".$next_year."&amp;month=".$next_month.$param."\"><i class=\"fa fa-chevron-right\"></i></a>\n";
364  if (empty($conf->dol_optimize_smallscreen)) {
365  $nav .= " &nbsp; <a href=\"?year=".$nowyear."&amp;month=".$nowmonth.$param."\">".$langs->trans("Today")."</a> ";
366  }
367  $picto = 'calendar';
368 }
369 if ($action == 'show_week')
370 {
371  $nav = "<a href=\"?year=".$prev_year."&amp;month=".$prev_month."&amp;day=".$prev_day.$param."\"><i class=\"fa fa-chevron-left\" title=\"".dol_escape_htmltag($langs->trans("Previous"))."\"></i></a> &nbsp;\n";
372  $nav .= " <span id=\"month_name\">".dol_print_date(dol_mktime(0, 0, 0, $first_month, $first_day, $first_year), "%Y").", ".$langs->trans("Week")." ".$week;
373  $nav .= " </span>\n";
374  $nav .= " &nbsp; <a href=\"?year=".$next_year."&amp;month=".$next_month."&amp;day=".$next_day.$param."\"><i class=\"fa fa-chevron-right\" title=\"".dol_escape_htmltag($langs->trans("Next"))."\"></i></a>\n";
375  if (empty($conf->dol_optimize_smallscreen)) {
376  $nav .= " &nbsp; <a href=\"?year=".$nowyear."&amp;month=".$nowmonth."&amp;day=".$nowday.$param."\">".$langs->trans("Today")."</a> ";
377  }
378  $picto = 'calendarweek';
379 }
380 if ($action == 'show_day')
381 {
382  $nav = "<a href=\"?year=".$prev_year."&amp;month=".$prev_month."&amp;day=".$prev_day.$param."\"><i class=\"fa fa-chevron-left\"></i></a> &nbsp;\n";
383  $nav .= " <span id=\"month_name\">".dol_print_date(dol_mktime(0, 0, 0, $month, $day, $year), "daytextshort");
384  $nav .= " </span>\n";
385  $nav .= " &nbsp; <a href=\"?year=".$next_year."&amp;month=".$next_month."&amp;day=".$next_day.$param."\"><i class=\"fa fa-chevron-right\"></i></a>\n";
386  if (empty($conf->dol_optimize_smallscreen)) {
387  $nav .= " &nbsp; <a href=\"?year=".$nowyear."&amp;month=".$nowmonth."&amp;day=".$nowday.$param."\">".$langs->trans("Today")."</a> ";
388  }
389  $picto = 'calendarday';
390 }
391 
392 $nav .= $form->selectDate($dateselect, 'dateselect', 0, 0, 1, '', 1, 0);
393 //$nav .= ' <input type="submit" name="submitdateselect" class="button" value="'.$langs->trans("Refresh").'">';
394 $nav .= '<button type="submit" class="liste_titre button_search" name="button_search_x" value="x"><span class="fa fa-search"></span></button>';
395 
396 // Must be after the nav definition
397 $param .= '&year='.$year.'&month='.$month.($day ? '&day='.$day : '');
398 //print 'x'.$param;
399 
400 
401 
402 
403 /*$tabactive = '';
404 if ($action == 'show_month') $tabactive = 'cardmonth';
405 if ($action == 'show_week') $tabactive = 'cardweek';
406 if ($action == 'show_day') $tabactive = 'cardday';
407 if ($action == 'show_list') $tabactive = 'cardlist';
408 if ($action == 'show_pertuser') $tabactive = 'cardperuser';
409 if ($action == 'show_pertype') $tabactive = 'cardpertype';
410 */
411 
412 $paramnoaction = preg_replace('/action=[a-z_]+/', '', $param);
413 
414 $head = calendars_prepare_head($paramnoaction);
415 
416 print '<form method="POST" id="searchFormList" class="listactionsfilter" action="'.$_SERVER["PHP_SELF"].'">'."\n";
417 if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
418 print '<input type="hidden" name="token" value="'.newToken().'">';
419 
420 //print dol_get_fiche_head($head, $tabactive, $langs->trans('Agenda'), 0, 'action');
421 //print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, $listofextcals, $actioncode, $usergroup, '', $resourceid);
422 //print dol_get_fiche_end();
423 
424 $viewmode = '';
425 $viewmode .= '<a class="btnTitle reposition" href="'.DOL_URL_ROOT.'/comm/action/list.php?action=show_list&restore_lastsearch_values=1">';
426 //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
427 $viewmode .= img_picto($langs->trans("List"), 'object_list-alt', 'class="pictoactionview block"');
428 //$viewmode .= '</span>';
429 $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewList").'</span></a>';
430 
431 $viewmode .= '<a class="btnTitle'.($action == 'show_month' ? ' btnTitleSelected' : '').' reposition" href="'.DOL_URL_ROOT.'/comm/action/index.php?action=show_month&year='.dol_print_date($object->datep, '%Y').'&month='.dol_print_date($object->datep, '%m').'&day='.dol_print_date($object->datep, '%d').'">';
432 //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
433 $viewmode .= img_picto($langs->trans("ViewCal"), 'object_calendar', 'class="pictoactionview block"');
434 //$viewmode .= '</span>';
435 $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewCal").'</span></a>';
436 
437 $viewmode .= '<a class="btnTitle'.($action == 'show_week' ? ' btnTitleSelected' : '').' reposition" href="'.DOL_URL_ROOT.'/comm/action/index.php?action=show_week&year='.dol_print_date($object->datep, '%Y').'&month='.dol_print_date($object->datep, '%m').'&day='.dol_print_date($object->datep, '%d').'">';
438 //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
439 $viewmode .= img_picto($langs->trans("ViewWeek"), 'object_calendarweek', 'class="pictoactionview block"');
440 //$viewmode .= '</span>';
441 $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewWeek").'</span></a>';
442 
443 $viewmode .= '<a class="btnTitle'.($action == 'show_day' ? ' btnTitleSelected' : '').' reposition" href="'.DOL_URL_ROOT.'/comm/action/index.php?action=show_day&year='.dol_print_date($object->datep, '%Y').'&month='.dol_print_date($object->datep, '%m').'&day='.dol_print_date($object->datep, '%d').'">';
444 //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
445 $viewmode .= img_picto($langs->trans("ViewDay"), 'object_calendarday', 'class="pictoactionview block"');
446 //$viewmode .= '</span>';
447 $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewDay").'</span></a>';
448 
449 $viewmode .= '<a class="btnTitle reposition marginrightonly" href="'.DOL_URL_ROOT.'/comm/action/peruser.php?action=show_peruser&year='.dol_print_date($object->datep, '%Y').'&month='.dol_print_date($object->datep, '%m').'&day='.dol_print_date($object->datep, '%d').'">';
450 //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
451 $viewmode .= img_picto($langs->trans("ViewPerUser"), 'object_calendarperuser', 'class="pictoactionview block"');
452 //$viewmode .= '</span>';
453 $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewPerUser").'</span></a>';
454 
455 $viewmode .= '<span class="marginrightonly"></span>';
456 
457 // Add more views from hooks
458 $parameters = array(); $object = null;
459 $reshook = $hookmanager->executeHooks('addCalendarView', $parameters, $object, $action);
460 if (empty($reshook)) {
461  $viewmode .= $hookmanager->resPrint;
462 } elseif ($reshook > 1) {
463  $viewmode = $hookmanager->resPrint;
464 }
465 
466 
467 $newcardbutton = '';
468 if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create)
469 {
470  $tmpforcreatebutton = dol_getdate(dol_now(), true);
471 
472  $newparam .= '&month='.str_pad($month, 2, "0", STR_PAD_LEFT).'&year='.$tmpforcreatebutton['year'];
473 
474  //$param='month='.$monthshown.'&year='.$year;
475  $hourminsec = '100000';
476  $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 : '')));
477 }
478 
479 // Define the legend/list of calendard to show
480 $s = ''; $link = '';
481 
482 $showextcals = $listofextcals;
483 
484 if (!empty($conf->use_javascript_ajax)) // If javascript on
485 {
486  $s .= "\n".'<!-- Div to calendars selectors -->'."\n";
487  $s .= '<script type="text/javascript">'."\n";
488  $s .= 'jQuery(document).ready(function () {'."\n";
489  $s .= 'jQuery(".check_birthday").click(function() { console.log("Toggle birthday"); jQuery(".family_birthday").toggle(); });'."\n";
490  $s .= 'jQuery(".family_birthday").toggle();'."\n";
491  if ($action == "show_week" || $action == "show_month" || empty($action))
492  {
493  // Code to enable drag and drop
494  $s .= 'jQuery( "div.sortable" ).sortable({connectWith: ".sortable", placeholder: "ui-state-highlight", items: "div.movable", receive: function( event, ui ) {'."\n";
495  // Code to submit form
496  $s .= 'console.log("submit form to record new event");'."\n";
497  //$s.='console.log(event.target);';
498  $s .= 'var newval = jQuery(event.target).closest("div.dayevent").attr("id");'."\n";
499  $s .= 'console.log("found parent div.dayevent with id = "+newval);'."\n";
500  $s .= 'var frm=jQuery("#searchFormList");'."\n";
501  $s .= 'var newurl = ui.item.find("a.cal_event").attr("href");'."\n";
502  $s .= 'console.log(newurl);'."\n";
503  $s .= 'frm.attr("action", newurl).children("#newdate").val(newval);frm.submit();}'."\n";
504  $s .= '});'."\n";
505  }
506  $s .= '});'."\n";
507  $s .= '</script>'."\n";
508 
509  // Local calendar
510  $s .= '<div class="nowrap inline-block minheight30"><input type="checkbox" id="check_mytasks" name="check_mytasks" checked disabled> '.$langs->trans("LocalAgenda").' &nbsp; </div>';
511 
512  // External calendars
513  if (is_array($showextcals) && count($showextcals) > 0)
514  {
515  $s .= '<script type="text/javascript">'."\n";
516  $s .= 'jQuery(document).ready(function () {
517  jQuery("div input[name^=\"check_ext\"]").click(function() {
518  var name = $(this).attr("name");
519  jQuery(".family_ext" + name.replace("check_ext", "")).toggle();
520  });
521  });' . "\n";
522  $s .= '</script>'."\n";
523 
524  foreach ($showextcals as $val)
525  {
526  $htmlname = md5($val['name']);
527  $s .= '<div class="nowrap inline-block"><input type="checkbox" id="check_ext'.$htmlname.'" name="check_ext'.$htmlname.'" checked> <label for="check_ext'.$htmlname.'">'.$val['name'].'</label> &nbsp; </div>';
528  }
529  }
530 
531  // Birthdays
532  $s .= '<div class="nowrap inline-block"><input type="checkbox" id="check_birthday" name="check_birthday" class="check_birthday"><label for="check_birthday"> <span class="check_birthday_text">'.$langs->trans("AgendaShowBirthdayEvents").'</span></label> &nbsp; </div>';
533 
534  // Calendars from hooks
535  $parameters = array(); $object = null;
536  $reshook = $hookmanager->executeHooks('addCalendarChoice', $parameters, $object, $action);
537  if (empty($reshook))
538  {
539  $s .= $hookmanager->resPrint;
540  } elseif ($reshook > 1)
541  {
542  $s = $hookmanager->resPrint;
543  }
544 } else // If javascript off
545 {
546  $newparam = $param; // newparam is for birthday links
547  $newparam = preg_replace('/showbirthday=[0-1]/i', 'showbirthday='.(empty($showbirthday) ? 1 : 0), $newparam);
548  if (!preg_match('/showbirthday=/i', $newparam)) $newparam .= '&showbirthday=1';
549  $link = '<a href="'.dol_escape_htmltag($_SERVER['PHP_SELF']);
550  $link .= '?'.dol_escape_htmltag($newparam);
551  $link .= '">';
552  if (empty($showbirthday)) $link .= $langs->trans("AgendaShowBirthdayEvents");
553  else $link .= $langs->trans("AgendaHideBirthdayEvents");
554  $link .= '</a>';
555 }
556 
557 // Load events from database into $eventarray
558 $eventarray = array();
559 
560 $sql = 'SELECT ';
561 if ($usergroup > 0) $sql .= " DISTINCT";
562 $sql .= ' a.id, a.label,';
563 $sql .= ' a.datep,';
564 $sql .= ' a.datep2,';
565 $sql .= ' a.percent,';
566 $sql .= ' a.fk_user_author,a.fk_user_action,';
567 $sql .= ' a.transparency, a.priority, a.fulldayevent, a.location,';
568 $sql .= ' a.fk_soc, a.fk_contact, a.fk_project,';
569 $sql .= ' a.fk_element, a.elementtype,';
570 $sql .= ' ca.code as type_code, ca.libelle as type_label, ca.color as type_color';
571 $sql .= ' FROM '.MAIN_DB_PREFIX.'c_actioncomm as ca, '.MAIN_DB_PREFIX."actioncomm as a";
572 if (!$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
573 // We must filter on resource table
574 if ($resourceid > 0) $sql .= ", ".MAIN_DB_PREFIX."element_resources as r";
575 // We must filter on assignement table
576 if ($filtert > 0 || $usergroup > 0) $sql .= ", ".MAIN_DB_PREFIX."actioncomm_resources as ar";
577 if ($usergroup > 0) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_user = ar.fk_element";
578 $sql .= ' WHERE a.fk_action = ca.id';
579 $sql .= ' AND a.entity IN ('.getEntity('agenda').')';
580 // Condition on actioncode
581 if (!empty($actioncode))
582 {
583  if (empty($conf->global->AGENDA_USE_EVENT_TYPE))
584  {
585  if ($actioncode == 'AC_NON_AUTO') $sql .= " AND ca.type != 'systemauto'";
586  elseif ($actioncode == 'AC_ALL_AUTO') $sql .= " AND ca.type = 'systemauto'";
587  else {
588  if ($actioncode == 'AC_OTH') $sql .= " AND ca.type != 'systemauto'";
589  if ($actioncode == 'AC_OTH_AUTO') $sql .= " AND ca.type = 'systemauto'";
590  }
591  } else {
592  if ($actioncode == 'AC_NON_AUTO') $sql .= " AND ca.type != 'systemauto'";
593  elseif ($actioncode == 'AC_ALL_AUTO') $sql .= " AND ca.type = 'systemauto'";
594  else {
595  if (is_array($actioncode))
596  {
597  $sql .= " AND ca.code IN ('".implode("','", $actioncode)."')";
598  } else {
599  $sql .= " AND ca.code IN ('".implode("','", explode(',', $actioncode))."')";
600  }
601  }
602  }
603 }
604 if ($resourceid > 0) $sql .= " AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = ".$db->escape($resourceid);
605 if ($pid) $sql .= " AND a.fk_project=".$db->escape($pid);
606 if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = ".$user->id.")";
607 if ($socid > 0) $sql .= ' AND a.fk_soc = '.$socid;
608 // We must filter on assignement table
609 if ($filtert > 0 || $usergroup > 0) $sql .= " AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
610 //var_dump($day.' '.$month.' '.$year);
611 if ($action == 'show_day')
612 {
613  $sql .= " AND (";
614  $sql .= " (a.datep BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel'))."'";
615  $sql .= " AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel'))."')";
616  $sql .= " OR ";
617  $sql .= " (a.datep2 BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel'))."'";
618  $sql .= " AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel'))."')";
619  $sql .= " OR ";
620  $sql .= " (a.datep < '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel'))."'";
621  $sql .= " AND a.datep2 > '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel'))."')";
622  $sql .= ')';
623 } else {
624  // To limit array
625  $sql .= " AND (";
626  $sql .= " (a.datep BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, 1, $year) - (60 * 60 * 24 * 7))."'"; // Start 7 days before
627  $sql .= " AND '".$db->idate(dol_mktime(23, 59, 59, $month, 28, $year) + (60 * 60 * 24 * 10))."')"; // End 7 days after + 3 to go from 28 to 31
628  $sql .= " OR ";
629  $sql .= " (a.datep2 BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, 1, $year) - (60 * 60 * 24 * 7))."'";
630  $sql .= " AND '".$db->idate(dol_mktime(23, 59, 59, $month, 28, $year) + (60 * 60 * 24 * 10))."')";
631  $sql .= " OR ";
632  $sql .= " (a.datep < '".$db->idate(dol_mktime(0, 0, 0, $month, 1, $year) - (60 * 60 * 24 * 7))."'";
633  $sql .= " AND a.datep2 > '".$db->idate(dol_mktime(23, 59, 59, $month, 28, $year) + (60 * 60 * 24 * 10))."')";
634  $sql .= ')';
635 }
636 if ($type) $sql .= " AND ca.id = ".$type;
637 if ($status == '0') { $sql .= " AND a.percent = 0"; }
638 if ($status == '-1') { $sql .= " AND a.percent = -1"; } // Not applicable
639 if ($status == '50') { $sql .= " AND (a.percent > 0 AND a.percent < 100)"; } // Running already started
640 if ($status == 'done' || $status == '100') { $sql .= " AND (a.percent = 100)"; }
641 if ($status == 'todo') { $sql .= " AND (a.percent >= 0 AND a.percent < 100)"; }
642 // We must filter on assignement table
643 if ($filtert > 0 || $usergroup > 0)
644 {
645  $sql .= " AND (";
646  if ($filtert > 0) $sql .= "ar.fk_element = ".$filtert;
647  if ($usergroup > 0) $sql .= ($filtert > 0 ? " OR " : "")." ugu.fk_usergroup = ".$usergroup;
648  $sql .= ")";
649 }
650 // Sort on date
651 $sql .= ' ORDER BY datep';
652 //print $sql;
653 
654 
655 dol_syslog("comm/action/index.php", LOG_DEBUG);
656 $resql = $db->query($sql);
657 if ($resql)
658 {
659  $num = $db->num_rows($resql);
660 
661  $MAXONSAMEPAGE = 10000; // Useless to have more. Protection to avoid memory overload when high number of event (for example after a mass import)
662  $i = 0;
663  while ($i < $num && $i < $MAXONSAMEPAGE)
664  {
665  $obj = $db->fetch_object($resql);
666 
667  // Discard auto action if option is on
668  if (!empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO) && $obj->type_code == 'AC_OTH_AUTO')
669  {
670  $i++;
671  continue;
672  }
673 
674  // Create a new object action
675  $event = new ActionComm($db);
676 
677  $event->id = $obj->id;
678  $event->ref = $event->id;
679 
680  $event->datep = $db->jdate($obj->datep); // datep and datef are GMT date. Example: 1970-01-01 01:00:00, jdate will return 0 if TZ of PHP server is Europe/Berlin
681  $event->datef = $db->jdate($obj->datep2);
682  //var_dump($obj->datep);
683  //var_dump($event->datep);
684 
685  $event->type_code = $obj->type_code;
686  $event->type_label = $obj->type_label;
687  $event->type_color = $obj->type_color;
688 
689  $event->libelle = $obj->label; // deprecated
690  $event->label = $obj->label;
691  $event->percentage = $obj->percent;
692  $event->authorid = $obj->fk_user_author; // user id of creator
693  $event->userownerid = $obj->fk_user_action; // user id of owner
694  $event->fetch_userassigned(); // This load $event->userassigned
695  $event->priority = $obj->priority;
696  $event->fulldayevent = $obj->fulldayevent;
697  $event->location = $obj->location;
698  $event->transparency = $obj->transparency;
699  $event->fk_element = $obj->fk_element;
700  $event->elementtype = $obj->elementtype;
701 
702  $event->fk_project = $obj->fk_project;
703 
704  $event->thirdparty_id = $obj->fk_soc;
705  $event->contact_id = $obj->fk_contact;
706 
707  // Defined date_start_in_calendar and date_end_in_calendar property
708  // They are date start and end of action but modified to not be outside calendar view.
709  $event->date_start_in_calendar = $event->datep;
710  if ($event->datef != '' && $event->datef >= $event->datep) $event->date_end_in_calendar = $event->datef;
711  else $event->date_end_in_calendar = $event->datep;
712  // Define ponctual property
713  if ($event->date_start_in_calendar == $event->date_end_in_calendar)
714  {
715  $event->ponctuel = 1;
716  }
717 
718  // Check values
719  if ($event->date_end_in_calendar < $firstdaytoshow || $event->date_start_in_calendar >= $lastdaytoshow) {
720  // This record is out of visible range
721  } else {
722  if ($event->date_start_in_calendar < $firstdaytoshow) $event->date_start_in_calendar = $firstdaytoshow;
723  if ($event->date_end_in_calendar >= $lastdaytoshow) $event->date_end_in_calendar = ($lastdaytoshow - 1);
724 
725  // Add an entry in actionarray for each day
726  $daycursor = $event->date_start_in_calendar;
727  $annee = dol_print_date($daycursor, '%Y', 'tzuserrel');
728  $mois = dol_print_date($daycursor, '%m', 'tzuserrel');
729  $jour = dol_print_date($daycursor, '%d', 'tzuserrel');
730  //var_dump(dol_print_date($event->date_start_in_calendar, 'dayhour', 'gmt'));
731  //var_dump($annee.'-'.$mois.'-'.$jour);
732 
733  // Loop on each day covered by action to prepare an index to show on calendar
734  $loop = true; $j = 0;
735  $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
736  do {
737  //if ($event->id==408) print 'daykey='.$daykey.' '.$event->datep.' '.$event->datef.'<br>';
738 
739  $eventarray[$daykey][] = $event;
740  $j++;
741 
742  $daykey += 60 * 60 * 24;
743  if ($daykey > $event->date_end_in_calendar) $loop = false;
744  } while ($loop);
745 
746  //print 'Event '.$i.' id='.$event->id.' (start='.dol_print_date($event->datep).'-end='.dol_print_date($event->datef);
747  //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>';
748  }
749  $i++;
750  }
751 } else {
752  dol_print_error($db);
753 }
754 
755 // Complete $eventarray with birthdates
756 if ($showbirthday)
757 {
758  // Add events in array
759  $sql = 'SELECT sp.rowid, sp.lastname, sp.firstname, sp.birthday';
760  $sql .= ' FROM '.MAIN_DB_PREFIX.'socpeople as sp';
761  $sql .= ' WHERE (priv=0 OR (priv=1 AND fk_user_creat='.$user->id.'))';
762  $sql .= " AND sp.entity IN (".getEntity('socpeople').")";
763  if ($action == 'show_day')
764  {
765  $sql .= ' AND MONTH(birthday) = '.$month;
766  $sql .= ' AND DAY(birthday) = '.$day;
767  } else {
768  $sql .= ' AND MONTH(birthday) = '.$month;
769  }
770  $sql .= ' ORDER BY birthday';
771 
772  dol_syslog("comm/action/index.php", LOG_DEBUG);
773  $resql = $db->query($sql);
774  if ($resql)
775  {
776  $num = $db->num_rows($resql);
777  $i = 0;
778  while ($i < $num)
779  {
780  $obj = $db->fetch_object($resql);
781  $event = new ActionComm($db);
782 
783  $event->id = $obj->rowid; // We put contact id in action id for birthdays events
784  $event->ref = $event->id;
785 
786  $datebirth = dol_stringtotime($obj->birthday, 1);
787  //print 'ee'.$obj->birthday.'-'.$datebirth;
788  $datearray = dol_getdate($datebirth, true);
789  $event->datep = dol_mktime(0, 0, 0, $datearray['mon'], $datearray['mday'], $year, true); // For full day events, date are also GMT but they wont but converted during output
790  $event->datef = $event->datep;
791  $event->type_code = 'BIRTHDAY';
792  $event->label = $langs->trans("Birthday").' '.dolGetFirstLastname($obj->firstname, $obj->lastname);
793  $event->percentage = 100;
794  $event->fulldayevent = 1;
795 
796  $event->date_start_in_calendar = $event->datep;
797  $event->date_end_in_calendar = $event->datef;
798  $event->ponctuel = 0;
799 
800  // Add an entry in actionarray for each day
801  $daycursor = $event->date_start_in_calendar;
802  $annee = dol_print_date($daycursor, '%Y');
803  $mois = dol_print_date($daycursor, '%m');
804  $jour = dol_print_date($daycursor, '%d');
805 
806  $loop = true;
807  $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee);
808  do {
809  $eventarray[$daykey][] = $event;
810  $daykey += 60 * 60 * 24;
811  if ($daykey > $event->date_end_in_calendar) $loop = false;
812  } while ($loop);
813  $i++;
814  }
815  } else {
816  dol_print_error($db);
817  }
818 }
819 
820 if ($conf->global->AGENDA_SHOW_HOLIDAYS)
821 {
822  $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.statut, x.rowid, x.date_debut as date_start, x.date_fin as date_end, x.halfday, x.statut as status";
823  $sql .= " FROM ".MAIN_DB_PREFIX."holiday as x, ".MAIN_DB_PREFIX."user as u";
824  $sql .= " WHERE u.rowid = x.fk_user";
825  $sql .= " AND u.statut = '1'"; // Show only active users (0 = inactive user, 1 = active user)
826  $sql .= " AND (x.statut = '2' OR x.statut = '3')"; // Show only public leaves (2 = leave wait for approval, 3 = leave approved)
827 
828  if ($action == 'show_day')
829  {
830  // Request only leaves for the current selected day
831  $sql .= " AND '".$db->escape($year)."-".$db->escape($month)."-".$db->escape($day)."' BETWEEN x.date_debut AND x.date_fin";
832  } elseif ($action == 'show_week')
833  {
834  // TODO: Add filter to reduce database request
835  } elseif ($action == 'show_month')
836  {
837  // TODO: Add filter to reduce database request
838  }
839 
840  $resql = $db->query($sql);
841  if ($resql)
842  {
843  $num = $db->num_rows($resql);
844  $i = 0;
845 
846  while ($i < $num)
847  {
848  $obj = $db->fetch_object($resql);
849 
850  $dateStartArray = dol_getdate(dol_stringtotime($obj->date_start, 1), true);
851  $dateEndArray = dol_getdate(dol_stringtotime($obj->date_end, 1), true);
852 
853  $event = new ActionComm($db);
854 
855  // Need the id of the leave object for link to it
856  $event->id = $obj->rowid;
857  $event->ref = $event->id;
858 
859  $event->type_code = 'HOLIDAY';
860  $event->datep = dol_mktime(0, 0, 0, $dateStartArray['mon'], $dateStartArray['mday'], $dateStartArray['year'], true);
861  $event->datef = dol_mktime(0, 0, 0, $dateEndArray['mon'], $dateEndArray['mday'], $dateEndArray['year'], true);
862  $event->date_start_in_calendar = $event->datep;
863  $event->date_end_in_calendar = $event->datef;
864 
865  if ($obj->status == 3)
866  {
867  // Show no symbol for leave with state "leave approved"
868  $event->percentage = -1;
869  } elseif ($obj->status == 2)
870  {
871  // Show TO-DO symbol for leave with state "leave wait for approval"
872  $event->percentage = 0;
873  }
874 
875  if ($obj->halfday == 1)
876  {
877  $event->label = $obj->lastname.' ('.$langs->trans("Morning").')';
878  } elseif ($obj->halfday == -1)
879  {
880  $event->label = $obj->lastname.' ('.$langs->trans("Afternoon").')';
881  } else {
882  $event->label = $obj->lastname;
883  }
884 
885  $daycursor = $event->date_start_in_calendar;
886  $annee = dol_print_date($daycursor, '%Y');
887  $mois = dol_print_date($daycursor, '%m');
888  $jour = dol_print_date($daycursor, '%d');
889 
890  $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee);
891 
892  do {
893  $eventarray[$daykey][] = $event;
894 
895  $daykey += 60 * 60 * 24;
896  } while ($daykey <= $event->date_end_in_calendar);
897 
898  $i++;
899  }
900  }
901 }
902 
903 // Complete $eventarray with external import Ical
904 if (count($listofextcals))
905 {
906  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/ical.class.php';
907  foreach ($listofextcals as $extcal)
908  {
909  $url = $extcal['src']; // Example: https://www.google.com/calendar/ical/eldy10%40gmail.com/private-cde92aa7d7e0ef6110010a821a2aaeb/basic.ics
910  $namecal = $extcal['name'];
911  $offsettz = $extcal['offsettz'];
912  $colorcal = $extcal['color'];
913  $buggedfile = $extcal['buggedfile'];
914  //print "url=".$url." namecal=".$namecal." colorcal=".$colorcal." buggedfile=".$buggedfile;
915  $ical = new ICal();
916  $ical->parse($url);
917 
918  // After this $ical->cal['VEVENT'] contains array of events, $ical->cal['DAYLIGHT'] contains daylight info, $ical->cal['STANDARD'] contains non daylight info, ...
919  //var_dump($ical->cal); exit;
920  $icalevents = array();
921  if (is_array($ical->get_event_list())) $icalevents = array_merge($icalevents, $ical->get_event_list()); // Add $ical->cal['VEVENT']
922  if (is_array($ical->get_freebusy_list())) $icalevents = array_merge($icalevents, $ical->get_freebusy_list()); // Add $ical->cal['VFREEBUSY']
923 
924  if (count($icalevents) > 0)
925  {
926  // Duplicate all repeatable events into new entries
927  $moreicalevents = array();
928  foreach ($icalevents as $icalevent)
929  {
930  if (isset($icalevent['RRULE']) && is_array($icalevent['RRULE'])) //repeatable event
931  {
932  //if ($event->date_start_in_calendar < $firstdaytoshow) $event->date_start_in_calendar=$firstdaytoshow;
933  //if ($event->date_end_in_calendar > $lastdaytoshow) $event->date_end_in_calendar=($lastdaytoshow-1);
934  if ($icalevent['DTSTART;VALUE=DATE']) //fullday event
935  {
936  $datecurstart = dol_stringtotime($icalevent['DTSTART;VALUE=DATE'], 1);
937  $datecurend = dol_stringtotime($icalevent['DTEND;VALUE=DATE'], 1) - 1; // We remove one second to get last second of day
938  } elseif (is_array($icalevent['DTSTART']) && !empty($icalevent['DTSTART']['unixtime']))
939  {
940  $datecurstart = $icalevent['DTSTART']['unixtime'];
941  $datecurend = $icalevent['DTEND']['unixtime'];
942  if (!empty($ical->cal['DAYLIGHT']['DTSTART']) && $datecurstart)
943  {
944  //var_dump($ical->cal);
945  $tmpcurstart = $datecurstart;
946  $tmpcurend = $datecurend;
947  $tmpdaylightstart = dol_mktime(0, 0, 0, 1, 1, 1970, 1) + (int) $ical->cal['DAYLIGHT']['DTSTART'];
948  $tmpdaylightend = dol_mktime(0, 0, 0, 1, 1, 1970, 1) + (int) $ical->cal['STANDARD']['DTSTART'];
949  //var_dump($tmpcurstart);var_dump($tmpcurend); var_dump($ical->cal['DAYLIGHT']['DTSTART']);var_dump($ical->cal['STANDARD']['DTSTART']);
950  // Edit datecurstart and datecurend
951  if ($tmpcurstart >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend) $datecurstart -= ((int) $ical->cal['DAYLIGHT']['TZOFFSETTO']) * 36;
952  else $datecurstart -= ((int) $ical->cal['STANDARD']['TZOFFSETTO']) * 36;
953  if ($tmpcurend >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend) $datecurend -= ((int) $ical->cal['DAYLIGHT']['TZOFFSETTO']) * 36;
954  else $datecurend -= ((int) $ical->cal['STANDARD']['TZOFFSETTO']) * 36;
955  }
956  // datecurstart and datecurend are now GMT date
957  //var_dump($datecurstart); var_dump($datecurend); exit;
958  } else {
959  // Not a recongized record
960  dol_syslog("Found a not recognized repeatable record with unknown date start", LOG_ERR);
961  continue;
962  }
963  //print 'xx'.$datecurstart;exit;
964 
965  $interval = (empty($icalevent['RRULE']['INTERVAL']) ? 1 : $icalevent['RRULE']['INTERVAL']);
966  $until = empty($icalevent['RRULE']['UNTIL']) ? 0 : dol_stringtotime($icalevent['RRULE']['UNTIL'], 1);
967  $maxrepeat = empty($icalevent['RRULE']['COUNT']) ? 0 : $icalevent['RRULE']['COUNT'];
968  if ($until && ($until + ($datecurend - $datecurstart)) < $firstdaytoshow) continue; // We discard repeatable event that end before start date to show
969  if ($datecurstart >= $lastdaytoshow) continue; // We discard repeatable event that start after end date to show
970 
971  $numofevent = 0;
972  while (($datecurstart < $lastdaytoshow) && (empty($maxrepeat) || ($numofevent < $maxrepeat)))
973  {
974  if ($datecurend >= $firstdaytoshow) // We add event
975  {
976  $newevent = $icalevent;
977  unset($newevent['RRULE']);
978  if ($icalevent['DTSTART;VALUE=DATE'])
979  {
980  $newevent['DTSTART;VALUE=DATE'] = dol_print_date($datecurstart, '%Y%m%d');
981  $newevent['DTEND;VALUE=DATE'] = dol_print_date($datecurend + 1, '%Y%m%d');
982  } else {
983  $newevent['DTSTART'] = $datecurstart;
984  $newevent['DTEND'] = $datecurend;
985  }
986  $moreicalevents[] = $newevent;
987  }
988  // Jump on next occurence
989  $numofevent++;
990  $savdatecurstart = $datecurstart;
991  if ($icalevent['RRULE']['FREQ'] == 'DAILY')
992  {
993  $datecurstart = dol_time_plus_duree($datecurstart, $interval, 'd');
994  $datecurend = dol_time_plus_duree($datecurend, $interval, 'd');
995  }
996  if ($icalevent['RRULE']['FREQ'] == 'WEEKLY')
997  {
998  $datecurstart = dol_time_plus_duree($datecurstart, $interval, 'w');
999  $datecurend = dol_time_plus_duree($datecurend, $interval, 'w');
1000  } elseif ($icalevent['RRULE']['FREQ'] == 'MONTHLY')
1001  {
1002  $datecurstart = dol_time_plus_duree($datecurstart, $interval, 'm');
1003  $datecurend = dol_time_plus_duree($datecurend, $interval, 'm');
1004  } elseif ($icalevent['RRULE']['FREQ'] == 'YEARLY')
1005  {
1006  $datecurstart = dol_time_plus_duree($datecurstart, $interval, 'y');
1007  $datecurend = dol_time_plus_duree($datecurend, $interval, 'y');
1008  }
1009  // Test to avoid infinite loop ($datecurstart must increase)
1010  if ($savdatecurstart >= $datecurstart)
1011  {
1012  dol_syslog("Found a rule freq ".$icalevent['RRULE']['FREQ']." not managed by dolibarr code. Assume 1 week frequency.", LOG_ERR);
1013  $datecurstart += 3600 * 24 * 7;
1014  $datecurend += 3600 * 24 * 7;
1015  }
1016  }
1017  }
1018  }
1019  $icalevents = array_merge($icalevents, $moreicalevents);
1020 
1021  // Loop on each entry into cal file to know if entry is qualified and add an ActionComm into $eventarray
1022  foreach ($icalevents as $icalevent)
1023  {
1024  //var_dump($icalevent);
1025 
1026  //print $icalevent['SUMMARY'].'->'.var_dump($icalevent).'<br>';exit;
1027  if (!empty($icalevent['RRULE'])) continue; // We found a repeatable event. It was already split into unitary events, so we discard general rule.
1028 
1029  // Create a new object action
1030  $event = new ActionComm($db);
1031  $addevent = false;
1032  if (isset($icalevent['DTSTART;VALUE=DATE'])) // fullday event
1033  {
1034  // For full day events, date are also GMT but they wont but converted using tz during output
1035  $datestart = dol_stringtotime($icalevent['DTSTART;VALUE=DATE'], 1);
1036  $dateend = dol_stringtotime($icalevent['DTEND;VALUE=DATE'], 1) - 1; // We remove one second to get last second of day
1037  //print 'x'.$datestart.'-'.$dateend;exit;
1038  //print dol_print_date($dateend,'dayhour','gmt');
1039  $event->fulldayevent = 1;
1040  $addevent = true;
1041  } elseif (!is_array($icalevent['DTSTART'])) // not fullday event (DTSTART is not array. It is a value like '19700101T000000Z' for 00:00 in greenwitch)
1042  {
1043  $datestart = $icalevent['DTSTART'];
1044  $dateend = $icalevent['DTEND'];
1045 
1046  $datestart += +($offsettz * 3600);
1047  $dateend += +($offsettz * 3600);
1048 
1049  $addevent = true;
1050  //var_dump($offsettz);
1051  //var_dump(dol_print_date($datestart, 'dayhour', 'gmt'));
1052  } elseif (isset($icalevent['DTSTART']['unixtime'])) // File contains a local timezone + a TZ (for example when using bluemind)
1053  {
1054  $datestart = $icalevent['DTSTART']['unixtime'];
1055  $dateend = $icalevent['DTEND']['unixtime'];
1056 
1057  $datestart += +($offsettz * 3600);
1058  $dateend += +($offsettz * 3600);
1059 
1060  // $buggedfile is set to uselocalandtznodaylight if conf->global->AGENDA_EXT_BUGGEDFILEx = 'uselocalandtznodaylight'
1061  if ($buggedfile === 'uselocalandtznodaylight') // unixtime is a local date that does not take daylight into account, TZID is +1 for example for 'Europe/Paris' in summer instead of 2
1062  {
1063  // TODO
1064  }
1065  // $buggedfile is set to uselocalandtzdaylight if conf->global->AGENDA_EXT_BUGGEDFILEx = 'uselocalandtzdaylight' (for example with bluemind)
1066  if ($buggedfile === 'uselocalandtzdaylight') // unixtime is a local date that does take daylight into account, TZID is +2 for example for 'Europe/Paris' in summer
1067  {
1068  $localtzs = new DateTimeZone(preg_replace('/"/', '', $icalevent['DTSTART']['TZID']));
1069  $localtze = new DateTimeZone(preg_replace('/"/', '', $icalevent['DTEND']['TZID']));
1070  $localdts = new DateTime(dol_print_date($datestart, 'dayrfc', 'gmt'), $localtzs);
1071  $localdte = new DateTime(dol_print_date($dateend, 'dayrfc', 'gmt'), $localtze);
1072  $tmps = -1 * $localtzs->getOffset($localdts);
1073  $tmpe = -1 * $localtze->getOffset($localdte);
1074  $datestart += $tmps;
1075  $dateend += $tmpe;
1076  //var_dump($datestart);
1077  }
1078  $addevent = true;
1079  }
1080 
1081  if ($addevent)
1082  {
1083  $event->id = $icalevent['UID'];
1084  $event->ref = $event->id;
1085  $userId = $userstatic->findUserIdByEmail($namecal);
1086  if (!empty($userId) && $userId > 0)
1087  {
1088  $event->userassigned[$userId] = $userId;
1089  $event->percentage = -1;
1090  }
1091  else {
1092  $event->type_code = "ICALEVENT";
1093  }
1094 
1095  $event->icalname = $namecal;
1096  $event->icalcolor = $colorcal;
1097  $usertime = 0; // We dont modify date because we want to have date into memory datep and datef stored as GMT date. Compensation will be done during output.
1098  $event->datep = $datestart + $usertime;
1099  $event->datef = $dateend + $usertime;
1100 
1101  if ($icalevent['SUMMARY']) $event->label = $icalevent['SUMMARY'];
1102  elseif ($icalevent['DESCRIPTION']) $event->label = dol_nl2br($icalevent['DESCRIPTION'], 1);
1103  else $event->label = $langs->trans("ExtSiteNoLabel");
1104 
1105  // Priority (see https://www.kanzaki.com/docs/ical/priority.html)
1106  // LOW = 0 to 4
1107  // MEDIUM = 5
1108  // HIGH = 6 to 9
1109  if ($icalevent['PRIORITY']) $event->priority = $icalevent['PRIORITY'];
1110 
1111  // Transparency (see https://www.kanzaki.com/docs/ical/transp.html)
1112  if ($icalevent['TRANSP'])
1113  {
1114  if ($icalevent['TRANSP'] == "TRANSPARENT") $event->transparency = 0; // 0 = available / free
1115  if ($icalevent['TRANSP'] == "OPAQUE") $event->transparency = 1; // 1 = busy
1116 
1117  // TODO: MS outlook states
1118  // X-MICROSOFT-CDO-BUSYSTATUS:FREE + TRANSP:TRANSPARENT => Available / Free
1119  // X-MICROSOFT-CDO-BUSYSTATUS:FREE + TRANSP:OPAQUE => Work another place
1120  // X-MICROSOFT-CDO-BUSYSTATUS:TENTATIVE + TRANSP:OPAQUE => With reservations
1121  // X-MICROSOFT-CDO-BUSYSTATUS:BUSY + TRANSP:OPAQUE => Busy
1122  // X-MICROSOFT-CDO-BUSYSTATUS:OOF + TRANSP:OPAQUE => Away from the office / off-site
1123  }
1124 
1125  if ($icalevent['LOCATION']) $event->location = $icalevent['LOCATION'];
1126 
1127  $event->date_start_in_calendar = $event->datep;
1128 
1129  if ($event->datef != '' && $event->datef >= $event->datep) $event->date_end_in_calendar = $event->datef;
1130  else $event->date_end_in_calendar = $event->datep;
1131 
1132  // Define ponctual property
1133  if ($event->date_start_in_calendar == $event->date_end_in_calendar)
1134  {
1135  $event->ponctuel = 1;
1136  //print 'x'.$datestart.'-'.$dateend;exit;
1137  }
1138 
1139  // Add event into $eventarray if date range are ok.
1140  if ($event->date_end_in_calendar < $firstdaytoshow || $event->date_start_in_calendar >= $lastdaytoshow)
1141  {
1142  //print 'x'.$datestart.'-'.$dateend;exit;
1143  //print 'x'.$datestart.'-'.$dateend;exit;
1144  //print 'x'.$datestart.'-'.$dateend;exit;
1145  // This record is out of visible range
1146  } else {
1147  if ($event->date_start_in_calendar < $firstdaytoshow) $event->date_start_in_calendar = $firstdaytoshow;
1148  if ($event->date_end_in_calendar >= $lastdaytoshow) $event->date_end_in_calendar = ($lastdaytoshow - 1);
1149 
1150  // Add an entry in actionarray for each day
1151  $daycursor = $event->date_start_in_calendar;
1152  $annee = date('Y', $daycursor);
1153  $mois = date('m', $daycursor);
1154  $jour = date('d', $daycursor);
1155 
1156  // Loop on each day covered by action to prepare an index to show on calendar
1157  $loop = true; $j = 0;
1158  // daykey must be date that represent day box in calendar so must be a user time
1159  $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee);
1160  $daykeygmt = dol_mktime(0, 0, 0, $mois, $jour, $annee, true, 0);
1161  do {
1162  //if ($event->fulldayevent) print dol_print_date($daykeygmt,'dayhour','gmt').'-'.dol_print_date($daykey,'dayhour','gmt').'-'.dol_print_date($event->date_end_in_calendar,'dayhour','gmt').' ';
1163  $eventarray[$daykey][] = $event;
1164  $daykey += 60 * 60 * 24; $daykeygmt += 60 * 60 * 24; // Add one day
1165  if (($event->fulldayevent ? $daykeygmt : $daykey) > $event->date_end_in_calendar) $loop = false;
1166  } while ($loop);
1167  }
1168  }
1169  }
1170  }
1171  }
1172 }
1173 
1174 
1175 
1176 // Complete $eventarray with events coming from external module
1177 $parameters = array(); $object = null;
1178 $reshook = $hookmanager->executeHooks('getCalendarEvents', $parameters, $object, $action);
1179 if (!empty($hookmanager->resArray['eventarray'])) {
1180  foreach ($hookmanager->resArray['eventarray'] as $keyDate => $events) {
1181  if (!isset($eventarray[$keyDate])) {
1182  $eventarray[$keyDate] = array();
1183  }
1184  $eventarray[$keyDate] = array_merge($eventarray[$keyDate], $events);
1185  }
1186 }
1187 
1188 // Sort events
1189 foreach ($eventarray as $keyDate => &$dateeventarray)
1190 {
1191  usort($dateeventarray, 'sort_events_by_date');
1192 }
1193 
1194 
1195 $maxnbofchar = 0;
1196 $cachethirdparties = array();
1197 $cachecontacts = array();
1198 $cacheusers = array();
1199 
1200 // Define theme_datacolor array
1201 $color_file = DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/theme_vars.inc.php";
1202 if (is_readable($color_file))
1203 {
1204  include_once $color_file;
1205 }
1206 if (!is_array($theme_datacolor)) $theme_datacolor = array(array(120, 130, 150), array(200, 160, 180), array(190, 190, 220));
1207 
1208 
1209 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);
1210 
1211 print $s;
1212 
1213 
1214 if (empty($action) || $action == 'show_month') // View by month
1215 {
1216  $newparam = $param; // newparam is for birthday links
1217  $newparam = preg_replace('/showbirthday=/i', 'showbirthday_=', $newparam); // To avoid replacement when replace day= is done
1218  $newparam = preg_replace('/action=show_month&?/i', '', $newparam);
1219  $newparam = preg_replace('/action=show_week&?/i', '', $newparam);
1220  $newparam = preg_replace('/day=[0-9]+&?/i', '', $newparam);
1221  $newparam = preg_replace('/month=[0-9]+&?/i', '', $newparam);
1222  $newparam = preg_replace('/year=[0-9]+&?/i', '', $newparam);
1223  $newparam = preg_replace('/viewcal=[0-9]+&?/i', '', $newparam);
1224  $newparam = preg_replace('/showbirthday_=/i', 'showbirthday=', $newparam); // Restore correct parameter
1225  $newparam .= '&viewcal=1';
1226 
1227  print '<div class="liste_titre liste_titre_bydiv centpercent">';
1228  print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid);
1229  print '</div>';
1230 
1231  print '<div class="div-table-responsive-no-min sectioncalendarbymonth maxscreenheightless300">';
1232  print '<table width="100%" class="noborder nocellnopadd cal_pannel cal_month">';
1233  print ' <tr class="liste_titre">';
1234  // Column title of weeks numbers
1235  echo ' <td align="center">#</td>';
1236  $i = 0;
1237  while ($i < 7)
1238  {
1239  print ' <td class="center bold uppercase tdfordaytitle">';
1240  $numdayinweek = (($i + (isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1)) % 7);
1241  if (!empty($conf->dol_optimize_smallscreen))
1242  {
1243  $labelshort = array(0=>'SundayMin', 1=>'MondayMin', 2=>'TuesdayMin', 3=>'WednesdayMin', 4=>'ThursdayMin', 5=>'FridayMin', 6=>'SaturdayMin');
1244  print $langs->trans($labelshort[$numdayinweek]);
1245  } else print $langs->trans("Day".$numdayinweek);
1246  print ' </td>'."\n";
1247  $i++;
1248  }
1249  echo ' </tr>'."\n";
1250 
1251  $todayarray = dol_getdate($now, 'fast');
1252  $todaytms = dol_mktime(0, 0, 0, $todayarray['mon'], $todayarray['mday'], $todayarray['year']);
1253 
1254  // In loops, tmpday contains day nb in current month (can be zero or negative for days of previous month)
1255  //var_dump($eventarray);
1256  for ($iter_week = 0; $iter_week < 6; $iter_week++) {
1257  echo " <tr>\n";
1258  // Get date of the current day, format 'yyyy-mm-dd'
1259  if ($tmpday <= 0) // If number of the current day is in previous month
1260  {
1261  $currdate0 = sprintf("%04d", $prev_year).sprintf("%02d", $prev_month).sprintf("%02d", $max_day_in_prev_month + $tmpday);
1262  }
1263  elseif ($tmpday <= $max_day_in_month) // If number of the current day is in current month
1264  {
1265  $currdate0 = sprintf("%04d", $year).sprintf("%02d", $month).sprintf("%02d", $tmpday);
1266  }
1267  else // If number of the current day is in next month
1268  {
1269  $currdate0 = sprintf("%04d", $next_year).sprintf("%02d", $next_month).sprintf("%02d", $tmpday - $max_day_in_month);
1270  }
1271  // Get week number for the targeted date '$currdate0'
1272  $numweek0 = date("W", strtotime(date($currdate0)));
1273  // Show the week number, and define column width
1274  echo ' <td class="center weeknumber opacitymedium" width="2%">'.$numweek0.'</td>';
1275 
1276  for ($iter_day = 0; $iter_day < 7; $iter_day++) {
1277  if ($tmpday <= 0) {
1278  /* Show days before the beginning of the current month (previous month) */
1279  $style = 'cal_other_month cal_past';
1280  if ($iter_day == 6) $style .= ' cal_other_month_right';
1281  echo ' <td class="'.$style.' nowrap tdtop" width="14%">';
1282  show_day_events($db, $max_day_in_prev_month + $tmpday, $prev_month, $prev_year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
1283  echo " </td>\n";
1284  } elseif ($tmpday <= $max_day_in_month) {
1285  /* Show days of the current month */
1286  $curtime = dol_mktime(0, 0, 0, $month, $tmpday, $year);
1287  $style = 'cal_current_month';
1288  if ($iter_day == 6) $style .= ' cal_current_month_right';
1289  $today = 0;
1290  if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $month && $todayarray['year'] == $year) $today = 1;
1291  if ($today) $style = 'cal_today';
1292  if ($curtime < $todaytms) $style .= ' cal_past';
1293  //var_dump($todayarray['mday']."==".$tmpday." && ".$todayarray['mon']."==".$month." && ".$todayarray['year']."==".$year.' -> '.$style);
1294  echo ' <td class="'.$style.' nowrap tdtop" width="14%">';
1295  show_day_events($db, $tmpday, $month, $year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
1296  echo "</td>\n";
1297  } else {
1298  /* Show days after the current month (next month) */
1299  $style = 'cal_other_month';
1300  if ($iter_day == 6) $style .= ' cal_other_month_right';
1301  echo ' <td class="'.$style.' nowrap tdtop" width="14%">';
1302  show_day_events($db, $tmpday - $max_day_in_month, $next_month, $next_year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
1303  echo "</td>\n";
1304  }
1305  $tmpday++;
1306  }
1307  echo " </tr>\n";
1308  }
1309  print "</table>\n";
1310  print '</div>';
1311 
1312  print '<input type="hidden" name="actionmove" value="mupdate">';
1313  print '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($_SERVER['PHP_SELF']).'?'.dol_escape_htmltag($_SERVER['QUERY_STRING']).'">';
1314  print '<input type="hidden" name="newdate" id="newdate">';
1315 } elseif ($action == 'show_week') {
1316  // View by week
1317  $newparam = $param; // newparam is for birthday links
1318  $newparam = preg_replace('/showbirthday=/i', 'showbirthday_=', $newparam); // To avoid replacement when replace day= is done
1319  $newparam = preg_replace('/action=show_month&?/i', '', $newparam);
1320  $newparam = preg_replace('/action=show_week&?/i', '', $newparam);
1321  $newparam = preg_replace('/day=[0-9]+&?/i', '', $newparam);
1322  $newparam = preg_replace('/month=[0-9]+&?/i', '', $newparam);
1323  $newparam = preg_replace('/year=[0-9]+&?/i', '', $newparam);
1324  $newparam = preg_replace('/viewweek=[0-9]+&?/i', '', $newparam);
1325  $newparam = preg_replace('/showbirthday_=/i', 'showbirthday=', $newparam); // Restore correct parameter
1326  $newparam .= '&viewweek=1';
1327 
1328  print '<div class="liste_titre liste_titre_bydiv centpercent"><div class="divsearchfield">';
1329  print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid);
1330  print '</div></div>';
1331 
1332  print '<div class="div-table-responsive-no-min sectioncalendarbyweek maxscreenheightless300">';
1333  print '<table width="100%" class="noborder nocellnopadd cal_pannel cal_month">';
1334  print ' <tr class="liste_titre">';
1335  $i = 0;
1336  while ($i < 7) {
1337  echo ' <td class="center bold uppercase tdfordaytitle">'.$langs->trans("Day".(($i + (isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1)) % 7))."</td>\n";
1338  $i++;
1339  }
1340  echo " </tr>\n";
1341 
1342  echo " <tr>\n";
1343 
1344  for ($iter_day = 0; $iter_day < 7; $iter_day++) {
1345  // Show days of the current week
1346  $curtime = dol_time_plus_duree($firstdaytoshow, $iter_day, 'd'); // $firstdaytoshow is in timezone of server
1347  $tmpday = dol_print_date($curtime, '%d', 'tzuserrel');
1348  $tmpmonth = dol_print_date($curtime, '%m', 'tzuserrel');
1349  $tmpyear = dol_print_date($curtime, '%Y', 'tzuserrel');
1350 
1351  $style = 'cal_current_month';
1352  if ($iter_day == 6) $style .= ' cal_other_month_right';
1353 
1354  $today = 0;
1355  $todayarray = dol_getdate($now, 'fast');
1356  if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $tmpmonth && $todayarray['year'] == $tmpyear) $today = 1;
1357  if ($today) $style = 'cal_today';
1358 
1359  echo ' <td class="'.$style.'" width="14%" valign="top">';
1360  show_day_events($db, $tmpday, $tmpmonth, $tmpyear, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300);
1361  echo " </td>\n";
1362  }
1363  echo " </tr>\n";
1364 
1365  print "</table>\n";
1366  print '</div>';
1367 
1368  echo '<input type="hidden" name="actionmove" value="mupdate">';
1369  echo '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($_SERVER['PHP_SELF']).'?'.dol_escape_htmltag($_SERVER['QUERY_STRING']).'">';
1370  echo '<input type="hidden" name="newdate" id="newdate">';
1371 } else // View by day
1372 {
1373  $newparam = $param; // newparam is for birthday links
1374  $newparam = preg_replace('/action=show_month&?/i', '', $newparam);
1375  $newparam = preg_replace('/action=show_week&?/i', '', $newparam);
1376  $newparam = preg_replace('/viewday=[0-9]+&?/i', '', $newparam);
1377  $newparam .= '&viewday=1';
1378  // Code to show just one day
1379  $style = 'cal_current_month cal_current_month_oneday';
1380  $today = 0;
1381  $todayarray = dol_getdate($now, 'fast');
1382  if ($todayarray['mday'] == $day && $todayarray['mon'] == $month && $todayarray['year'] == $year) $today = 1;
1383  //if ($today) $style='cal_today';
1384 
1385  $timestamp = dol_mktime(12, 0, 0, $month, $day, $year);
1386  $arraytimestamp = dol_getdate($timestamp);
1387 
1388  print '<div class="liste_titre liste_titre_bydiv centpercent"><div class="divsearchfield">';
1389  print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid);
1390  print '</div></div>';
1391 
1392  print '<div class="div-table-responsive-no-min sectioncalendarbyday maxscreenheightless300">';
1393  echo '<table class="tagtable centpercent noborder nocellnopadd cal_pannel cal_month noborderbottom" style="margin-bottom: 5px !important;">';
1394 
1395  echo ' <tr class="tagtr liste_titre">';
1396  echo ' <td class="tagtd center bold uppercase">'.$langs->trans("Day".$arraytimestamp['wday'])."</td>\n";
1397  echo " </td>\n";
1398 
1399  /*
1400  echo ' <div class="tagtr">';
1401  echo ' <div class="tagtd width100"></div>';
1402  echo ' <div class="tagtd center">';
1403  echo show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, -1);
1404  echo ' </div>'."\n";
1405  echo " </div>\n";
1406  */
1407 
1408  echo '</table>';
1409  print '</div>';
1410 
1411  /* WIP View per hour */
1412  $useviewhour = 0;
1413  if ($useviewhour)
1414  {
1415  print '<div class="div-table-responsive-no-min borderbottom">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
1416 
1417  $maxheightwin = (isset($_SESSION["dol_screenheight"]) && $_SESSION["dol_screenheight"] > 500) ? ($_SESSION["dol_screenheight"] - 200) : 660; // Also into index.php file
1418 
1419  echo '<div style="max-height: '.$maxheightwin.'px;">';
1420  echo '<div class="tagtable centpercent calendarviewcontainer">';
1421 
1422  $maxnbofchar = 80;
1423 
1424  $tmp = explode('-', $conf->global->MAIN_DEFAULT_WORKING_HOURS);
1425  $minhour = round($tmp[0], 0);
1426  $maxhour = round($tmp[1], 0);
1427  if ($minhour > 23) $minhour = 23;
1428  if ($maxhour < 1) $maxhour = 1;
1429  if ($maxhour <= $minhour) { $maxhour = $minhour + 1; }
1430 
1431  $i = 0;
1432  $j = 0;
1433  while ($i < 24)
1434  {
1435  echo ' <div class="tagtr calendarviewcontainertr">'."\n";
1436  echo ' <div class="tagtd width100 tdtop">'.dol_print_date($i * 3600, 'hour', 'gmt').'</div>';
1437  echo ' <div class="tagtd '.$style.' tdtop"></div>'."\n";
1438  echo ' </div>'."\n";
1439  $i++;
1440  $j++;
1441  }
1442 
1443  echo '</div></div>';
1444 
1445  show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, 1);
1446 
1447  print '</div>';
1448  } else {
1449  print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
1450 
1451  show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, 0);
1452 
1453  print '</div>';
1454  }
1455 }
1456 
1457 print "\n".'</form>';
1458 
1459 // End of page
1460 llxFooter();
1461 $db->close();
1462 
1463 
1482 function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventarray, $maxprint = 0, $maxnbofchar = 16, $newparam = '', $showinfo = 0, $minheight = 60, $nonew = 0)
1483 {
1484  global $user, $conf, $langs;
1485  global $action, $filter, $filtert, $status, $actioncode, $usergroup; // Filters used into search form
1486  global $theme_datacolor;
1487  global $cachethirdparties, $cachecontacts, $cacheusers, $colorindexused;
1488 
1489  $dateint = sprintf("%04d", $year).sprintf("%02d", $month).sprintf("%02d", $day);
1490 
1491  print "\n";
1492 
1493  $curtime = dol_mktime(0, 0, 0, $month, $day, $year);
1494  $urltoshow = DOL_URL_ROOT.'/comm/action/index.php?action=show_day&day='.str_pad($day, 2, "0", STR_PAD_LEFT).'&month='.str_pad($month, 2, "0", STR_PAD_LEFT).'&year='.$year.$newparam;
1495  $urltocreate = '';
1496  if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create)
1497  {
1498  $newparam .= '&month='.str_pad($month, 2, "0", STR_PAD_LEFT).'&year='.$year;
1499  $hourminsec = '100000';
1500  $urltocreate = DOL_URL_ROOT.'/comm/action/card.php?action=create&datep='.sprintf("%04d%02d%02d", $year, $month, $day).$hourminsec.'&backtopage='.urlencode($_SERVER["PHP_SELF"].($newparam ? '?'.$newparam : ''));
1501  }
1502 
1503  // Line with title of day
1504  print '<div id="dayevent_'.$dateint.'" class="dayevent tagtable centpercent nobordernopadding">'."\n";
1505 
1506  if ($nonew <= 0)
1507  {
1508  print '<div class="tagtr cursorpointer" onclick="window.location=\''.$urltocreate.'\';"><div class="nowrap tagtd"><div class="left inline-block">';
1509  print '<a class="dayevent-aday" style="color: #666" href="'.$urltoshow.'">';
1510  if ($showinfo) print dol_print_date($curtime, 'daytextshort');
1511  else print dol_print_date($curtime, '%d');
1512  print '</a>';
1513  print '</div><div class="nowrap floatright inline-block marginrightonly">';
1514  if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create)
1515  {
1516  print '<a class="cursoradd" href="'.$urltocreate.'">'; // Explicit link, usefull for nojs interfaces
1517  print img_picto($langs->trans("NewAction"), 'edit_add.png');
1518  print '</a>';
1519  }
1520  print '</div></div></div>'."\n";
1521  }
1522 
1523  if ($nonew < 0)
1524  {
1525  print '</div>';
1526  return;
1527  }
1528 
1529  // Line with td contains all div of each events
1530  print '<div class="tagtr">';
1531  print '<div class="tagtd centpercent agendacell sortable">';
1532 
1533  //$curtime = dol_mktime (0, 0, 0, $month, $day, $year);
1534  $i = 0; $numother = 0; $numbirthday = 0; $numical = 0; $numicals = array();
1535  $ymd = sprintf("%04d", $year).sprintf("%02d", $month).sprintf("%02d", $day);
1536 
1537  $colorindexused[$user->id] = 0; // Color index for current user (user->id) is always 0
1538  $nextindextouse = is_array($colorindexused) ?count($colorindexused) : 0; // At first run this is 0, so fist user has 0, next 1, ...
1539  //var_dump($colorindexused);
1540 
1541  foreach ($eventarray as $daykey => $notused)
1542  {
1543  $annee = dol_print_date($daykey, '%Y');
1544  $mois = dol_print_date($daykey, '%m');
1545  $jour = dol_print_date($daykey, '%d');
1546 
1547  if ($day == $jour && $month == $mois && $year == $annee)
1548  {
1549  foreach ($eventarray[$daykey] as $index => $event)
1550  {
1551  if ($i < $maxprint || $maxprint == 0 || !empty($conf->global->MAIN_JS_SWITCH_AGENDA))
1552  {
1553  $keysofuserassigned = array_keys($event->userassigned);
1554  $ponct = ($event->date_start_in_calendar == $event->date_end_in_calendar);
1555 
1556  // Define $color (Hex string like '0088FF') and $cssclass of event
1557  $color = -1; $cssclass = ''; $colorindex = -1;
1558  if (in_array($user->id, $keysofuserassigned))
1559  {
1560  $cssclass = 'family_mytasks';
1561 
1562  if (empty($cacheusers[$event->userownerid]))
1563  {
1564  $newuser = new User($db);
1565  $newuser->fetch($event->userownerid);
1566  $cacheusers[$event->userownerid] = $newuser;
1567  }
1568  //var_dump($cacheusers[$event->userownerid]->color);
1569 
1570  // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
1571  if (!empty($cacheusers[$event->userownerid]->color)) $color = $cacheusers[$event->userownerid]->color;
1572  } elseif ($event->type_code == 'ICALEVENT') // Event come from external ical file
1573  {
1574  $numical++;
1575  if (!empty($event->icalname)) {
1576  if (!isset($numicals[dol_string_nospecial($event->icalname)])) {
1577  $numicals[dol_string_nospecial($event->icalname)] = 0;
1578  }
1579  $numicals[dol_string_nospecial($event->icalname)]++;
1580  }
1581 
1582  $color = ($event->icalcolor ? $event->icalcolor : -1);
1583  $cssclass = (!empty($event->icalname) ? 'family_ext'.md5($event->icalname) : 'family_other');
1584  } elseif ($event->type_code == 'BIRTHDAY')
1585  {
1586  $numbirthday++; $colorindex = 2; $cssclass = 'family_birthday unmovable'; $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
1587  } else {
1588  $numother++;
1589  $color = ($event->icalcolor ? $event->icalcolor : -1);
1590  $cssclass = (!empty($event->icalname) ? 'family_ext'.md5($event->icalname) : 'family_other');
1591 
1592  if (empty($cacheusers[$event->userownerid]))
1593  {
1594  $newuser = new User($db);
1595  $newuser->fetch($event->userownerid);
1596  $cacheusers[$event->userownerid] = $newuser;
1597  }
1598  //var_dump($cacheusers[$event->userownerid]->color);
1599 
1600  // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
1601  if (!empty($cacheusers[$event->userownerid]->color)) $color = $cacheusers[$event->userownerid]->color;
1602  }
1603 
1604  if ($color < 0) // Color was not set on user card. Set color according to color index.
1605  {
1606  // Define color index if not yet defined
1607  $idusertouse = ($event->userownerid ? $event->userownerid : 0);
1608  if (isset($colorindexused[$idusertouse]))
1609  {
1610  $colorindex = $colorindexused[$idusertouse]; // Color already assigned to this user
1611  } else {
1612  $colorindex = $nextindextouse;
1613  $colorindexused[$idusertouse] = $colorindex;
1614  if (!empty($theme_datacolor[$nextindextouse + 1])) $nextindextouse++; // Prepare to use next color
1615  }
1616  //print '|'.($color).'='.($idusertouse?$idusertouse:0).'='.$colorindex.'<br>';
1617  // Define color
1618  $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
1619  }
1620  $cssclass = $cssclass.' '.$cssclass.'_day_'.$ymd;
1621 
1622  // Defined style to disable drag and drop feature
1623  if ($event->type_code == 'AC_OTH_AUTO')
1624  {
1625  $cssclass .= " unmovable";
1626  } elseif ($event->type_code == 'ICALEVENT')
1627  {
1628  $cssclass .= " unmovable";
1629  } elseif ($event->date_end_in_calendar && date('Ymd', $event->date_start_in_calendar) != date('Ymd', $event->date_end_in_calendar)) {
1630  $tmpyearend = date('Y', $event->date_end_in_calendar);
1631  $tmpmonthend = date('m', $event->date_end_in_calendar);
1632  $tmpdayend = date('d', $event->date_end_in_calendar);
1633  if ($tmpyearend != $annee || $tmpmonthend != $mois || $tmpdayend != $jour)
1634  {
1635  $cssclass .= " unmovable";
1636  }
1637  } else {
1638  if ($user->rights->agenda->allactions->create ||
1639  (($event->authorid == $user->id || $event->userownerid == $user->id) && $user->rights->agenda->myactions->create))
1640  {
1641  $cssclass .= " movable cursormove";
1642  } else {
1643  $cssclass .= " unmovable";
1644  }
1645  }
1646 
1647  $h = ''; $nowrapontd = 1;
1648  if ($action == 'show_day') { $h = 'height: 100%; '; $nowrapontd = 0; }
1649  if ($action == 'show_week') { $h = 'height: 100%; '; $nowrapontd = 0; }
1650 
1651  // Show rect of event
1652  print "\n";
1653  print '<!-- start event '.$i.' -->'."\n";
1654  print '<div id="event_'.$ymd.'_'.$i.'" class="event '.$cssclass.'"';
1655  //print ' style="height: 100px;';
1656  //print ' position: absolute; top: 40px; width: 50%;';
1657  //print '"';
1658  print '>';
1659 
1660  //var_dump($event->userassigned);
1661  //var_dump($event->transparency);
1662  print '<table class="centpercent cal_event';
1663  print (empty($event->transparency) ? ' cal_event_notbusy' : ' cal_event_busy');
1664  //if (empty($event->transparency) && empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) print ' opacitymedium'; // Not busy
1665  print '" style="'.$h;
1666  $colortouse = $color;
1667  // If colortouse is similar than background, we force to change it.
1668  if (empty($event->transparency) && empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY))
1669  {
1670  print 'background: #f0f0f0;';
1671  print 'border-left: 5px solid #'.$colortouse.';';
1672  } else {
1673  print 'background: #f0f0f0;';
1674  print 'border-left: 5px solid #'.dol_color_minus($colortouse, -3).';';
1675  //print 'background: -webkit-gradient(linear, left top, left bottom, from(#'.dol_color_minus($colortouse, -3).'), to(#'.dol_color_minus($colortouse, -1).'));';
1676  }
1677  //print 'background: #'.$colortouse.';';
1678  //print 'background: -webkit-gradient(linear, left top, left bottom, from(#'.dol_color_minus($color, -3).'), to(#'.dol_color_minus($color, -1).'));';
1679  //if (! empty($event->transparency)) print 'background: #'.$color.'; background: -webkit-gradient(linear, left top, left bottom, from(#'.$color.'), to(#'.dol_color_minus($color,1).'));';
1680  //else print 'background-color: transparent !important; background: none; border: 1px solid #bbb;';
1681  //print ' -moz-border-radius:4px;"';
1682  //print 'border: 1px solid #ccc" width="100%"';
1683  print '">';
1684  print '<tr>';
1685  print '<td class="tdoverflow nobottom centpercent '.($nowrapontd ? 'nowrap ' : '').'cal_event'.($event->type_code == 'BIRTHDAY' ? ' cal_event_birthday' : '').'">';
1686 
1687  $daterange = '';
1688 
1689  if ($event->type_code == 'BIRTHDAY') // It's a birthday
1690  {
1691  print $event->getNomUrl(1, $maxnbofchar, 'cal_event', 'birthday', 'contact');
1692  } elseif ($event->type_code == 'HOLIDAY')
1693  {
1694  print $event->getNomUrl(1, $maxnbofchar, 'cal_event', 'holiday', 'user');
1695  } elseif ($event->type_code != 'BIRTHDAY' && $event->type_code != 'HOLIDAY')
1696  {
1697  // Picto
1698  if (empty($event->fulldayevent))
1699  {
1700  //print $event->getNomUrl(2).' ';
1701  }
1702 
1703  // Date
1704  if (empty($event->fulldayevent))
1705  {
1706  // Show hours (start ... end)
1707  $tmpyearstart = dol_print_date($event->date_start_in_calendar, '%Y', 'tzuserrel');
1708  $tmpmonthstart = dol_print_date($event->date_start_in_calendar, '%m', 'tzuserrel');
1709  $tmpdaystart = dol_print_date($event->date_start_in_calendar, '%d', 'tzuserrel');
1710  $tmpyearend = dol_print_date($event->date_end_in_calendar, '%Y', 'tzuserrel');
1711  $tmpmonthend = dol_print_date($event->date_end_in_calendar, '%m', 'tzuserrel');
1712  $tmpdayend = dol_print_date($event->date_end_in_calendar, '%d', 'tzuserrel');
1713 
1714  // Hour start
1715  if ($tmpyearstart == $annee && $tmpmonthstart == $mois && $tmpdaystart == $jour)
1716  {
1717  $daterange .= dol_print_date($event->date_start_in_calendar, 'hour', 'tzuserrel');
1718  if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar)
1719  {
1720  if ($tmpyearstart == $tmpyearend && $tmpmonthstart == $tmpmonthend && $tmpdaystart == $tmpdayend)
1721  $daterange .= '-';
1722  //else
1723  //print '...';
1724  }
1725  }
1726  if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar)
1727  {
1728  if ($tmpyearstart != $tmpyearend || $tmpmonthstart != $tmpmonthend || $tmpdaystart != $tmpdayend)
1729  {
1730  $daterange .= '...';
1731  }
1732  }
1733  // Hour end
1734  if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar)
1735  {
1736  if ($tmpyearend == $annee && $tmpmonthend == $mois && $tmpdayend == $jour)
1737  $daterange .= dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel');
1738  }
1739  } else {
1740  if ($showinfo)
1741  {
1742  print $langs->trans("EventOnFullDay")."<br>\n";
1743  }
1744  }
1745 
1746  // Show title
1747  $titletoshow = $daterange;
1748  $titletoshow .= ($titletoshow ? ' ' : '').($event->label ? $event->label : $event->libelle);
1749 
1750  if ($event->type_code != 'ICALEVENT') {
1751  $savlabel = $event->label ? $event->label : $event->libelle;
1752  $event->label = $titletoshow;
1753  $event->libelle = $titletoshow;
1754  // Note: List of users are inside $event->userassigned. Link may be clickable depending on permissions of user.
1755  $titletoshow = $event->getNomUrl(0, $maxnbofchar, 'cal_event cal_event_title', '', 0, 0);
1756  $event->label = $savlabel;
1757  $event->libelle = $savlabel;
1758  }
1759 
1760  // Loop on each assigned user
1761  $listofusertoshow = '';
1762  $posuserassigned = 0;
1763  foreach ($event->userassigned as $tmpid => $tmpdata)
1764  {
1765  if (!$posuserassigned && $titletoshow) $listofusertoshow .= '<br>';
1766  $posuserassigned++;
1767  if (empty($cacheusers[$tmpid]))
1768  {
1769  $newuser = new User($db);
1770  $newuser->fetch($tmpid);
1771  $cacheusers[$tmpid] = $newuser;
1772  }
1773 
1774  $listofusertoshow .= $cacheusers[$tmpid]->getNomUrl(-3, '', 0, 0, 0, 0, '', 'paddingright valigntextbottom');
1775  }
1776 
1777  print $titletoshow;
1778  print $listofusertoshow;
1779 
1780  if ($event->type_code == 'ICALEVENT') print '<br>('.dol_trunc($event->icalname, $maxnbofchar).')';
1781 
1782  $thirdparty_id = ($event->thirdparty_id > 0 ? $event->thirdparty_id : ((is_object($event->societe) && $event->societe->id > 0) ? $event->societe->id : 0));
1783  $contact_id = ($event->contact_id > 0 ? $event->contact_id : ((is_object($event->contact) && $event->contact->id > 0) ? $event->contact->id : 0));
1784 
1785  // If action related to company / contact
1786  $linerelatedto = '';
1787  if ($thirdparty_id > 0)
1788  {
1789  if (!isset($cachethirdparties[$thirdparty_id]) || !is_object($cachethirdparties[$thirdparty_id]))
1790  {
1791  $thirdparty = new Societe($db);
1792  $thirdparty->fetch($thirdparty_id);
1793  $cachethirdparties[$thirdparty_id] = $thirdparty;
1794  } else $thirdparty = $cachethirdparties[$thirdparty_id];
1795  if (!empty($thirdparty->id)) $linerelatedto .= $thirdparty->getNomUrl(1, '', 0);
1796  }
1797  if (!empty($contact_id) && $contact_id > 0)
1798  {
1799  if (!is_object($cachecontacts[$contact_id]))
1800  {
1801  $contact = new Contact($db);
1802  $contact->fetch($contact_id);
1803  $cachecontacts[$contact_id] = $contact;
1804  } else $contact = $cachecontacts[$contact_id];
1805  if ($linerelatedto) $linerelatedto .= '&nbsp;';
1806  if (!empty($contact->id)) $linerelatedto .= $contact->getNomUrl(1, '', 0);
1807  }
1808  if (!empty($event->fk_element) && $event->fk_element > 0 && !empty($event->elementtype) && !empty($conf->global->AGENDA_SHOW_LINKED_OBJECT))
1809  {
1810  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
1811  if ($linerelatedto) $linerelatedto .= '<br>';
1812  $linerelatedto .= dolGetElementUrl($event->fk_element, $event->elementtype, 1);
1813  }
1814  if ($linerelatedto) print '<br>'.$linerelatedto;
1815  }
1816 
1817  // Show location
1818  if ($showinfo)
1819  {
1820  if ($event->location)
1821  {
1822  print '<br>';
1823  print $langs->trans("Location").': '.$event->location;
1824  }
1825  }
1826 
1827  print '</td>';
1828  // Status - Percent
1829  $withstatus = 0;
1830  if ($event->type_code != 'BIRTHDAY' && $event->type_code != 'ICALEVENT')
1831  {
1832  $withstatus = 1;
1833  if ($event->percentage >= 0) $withstatus = 2;
1834  }
1835  print '<td class="nobottom right nowrap cal_event_right'.($withstatus >= 2 ? ' cal_event_right_status' : '').'">';
1836  if ($withstatus) print $event->getLibStatut(3, 1);
1837  else print '&nbsp;';
1838  print '</td></tr></table>';
1839  print '</div><!-- end event '.$i.' -->'."\n";
1840  $i++;
1841  } else {
1842  print '<a href="'.DOL_URL_ROOT.'/comm/action/index.php?action='.$action.'&maxprint=0&month='.$monthshown.'&year='.$year;
1843  print ($status ? '&status='.$status : '').($filter ? '&filter='.$filter : '');
1844  print ($filtert ? '&search_filtert='.$filtert : '');
1845  print ($usergroup ? '&search_usergroup='.$usergroup : '');
1846  print ($actioncode != '' ? '&search_actioncode='.$actioncode : '');
1847  print '">'.img_picto("all", "1downarrow_selected.png").' ...';
1848  print ' +'.(count($eventarray[$daykey]) - $maxprint);
1849  print '</a>';
1850  break;
1851  //$ok=false; // To avoid to show twice the link
1852  }
1853  }
1854 
1855  break;
1856  }
1857  }
1858  if (!$i) { // No events
1859  print '&nbsp;';
1860  }
1861 
1862  if (!empty($conf->global->MAIN_JS_SWITCH_AGENDA) && $i > $maxprint && $maxprint)
1863  {
1864  print '<div id="more_'.$ymd.'">'.img_picto("all", "1downarrow_selected.png").' +'.$langs->trans("More").'...</div>';
1865  //print ' +'.(count($eventarray[$daykey])-$maxprint);
1866  print '<script type="text/javascript">'."\n";
1867  print 'jQuery(document).ready(function () {'."\n";
1868  print 'jQuery("#more_'.$ymd.'").click(function() { reinit_day_'.$ymd.'(); });'."\n";
1869 
1870  print 'function reinit_day_'.$ymd.'() {'."\n";
1871  print 'var nb=0;'."\n";
1872  // TODO Loop on each element of day $ymd and start to toggle once $maxprint has been reached
1873  print 'jQuery(".family_mytasks_day_'.$ymd.'").toggle();';
1874  print '}'."\n";
1875 
1876  print '});'."\n";
1877 
1878  print '</script>'."\n";
1879  }
1880 
1881  print '</div></div>'; // td tr
1882 
1883  print '</div>'; // table
1884  print "\n";
1885 }
1886 
1887 
1896 function dol_color_minus($color, $minus, $minusunit = 16)
1897 {
1898  $newcolor = $color;
1899  if ($minusunit == 16)
1900  {
1901  $newcolor[0] = dechex(max(min(hexdec($newcolor[0]) - $minus, 15), 0));
1902  $newcolor[2] = dechex(max(min(hexdec($newcolor[2]) - $minus, 15), 0));
1903  $newcolor[4] = dechex(max(min(hexdec($newcolor[4]) - $minus, 15), 0));
1904  } else {
1905  // Not yet implemented
1906  }
1907  return $newcolor;
1908 }
1909 
1917 function sort_events_by_date($a, $b)
1918 {
1919  // Sort holidays at first
1920  if ($a->type_code === 'HOLIDAY')
1921  {
1922  return -1;
1923  }
1924 
1925  if ($b->type_code === 'HOLIDAY')
1926  {
1927  return 1;
1928  }
1929 
1930  // datep => Event start time
1931  // datef => Event end time
1932 
1933  // Events have different start time
1934  if ($a->datep !== $b->datep)
1935  {
1936  return $a->datep - $b->datep;
1937  }
1938 
1939  // Events have same start time and no end time
1940  if ((!is_numeric($b->datef)) || (!is_numeric($a->datef)))
1941  {
1942  return sort_events_by_percentage($a, $b);
1943  }
1944 
1945  // Events have the same start time and same end time
1946  if ($b->datef === $a->datef)
1947  {
1948  return sort_events_by_percentage($a, $b);
1949  }
1950 
1951  // Events have the same start time, but have different end time -> longest event first
1952  return $b->datef - $a->datef;
1953 }
1954 
1962 function sort_events_by_percentage($a, $b)
1963 {
1964  // Sort events with no percentage before each other
1965  // (usefull to sort holidays, sick days or similar on the top)
1966 
1967  if ($a->percentage < 0)
1968  {
1969  return -1;
1970  }
1971 
1972  if ($b->percentage < 0)
1973  {
1974  return 1;
1975  }
1976 
1977  return $b->percentage - $a->percentage;
1978 }
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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_get_prev_month($month, $year)
Return previous month.
Definition: date.lib.php:398
Class to manage agenda events (actions)
Class to manage contact/addresses.
dolGetButtonTitle($label, $helpText= '', $iconClass= 'fa fa-file', $url= '', $id= '', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_first_day_week($day, $month, $year, $gm=false)
Return first day of week for a date.
Definition: date.lib.php:553
dol_now($mode= 'auto')
Return date for now.
calendars_prepare_head($param)
Define head array for tabs of agenda setup pages.
Definition: agenda.lib.php:466
Class to manage Dolibarr users.
Definition: user.class.php:44
dol_stringtotime($string, $gm=1)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
Definition: date.lib.php:319
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
dol_get_prev_day($day, $month, $year)
Return previous day.
Definition: date.lib.php:367
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options= '', $sortfield= '', $sortorder= '', $morehtmlcenter= '', $num=-1, $totalnboflines= '', $picto= 'generic', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow= '')
Print a title with navigation controls for pagination.
dol_get_next_week($day, $week, $month, $year)
Return next week.
Definition: date.lib.php:459
Class to manage generation of HTML components Only common components must be here.
Class to read/parse ICal calendars.
Definition: ical.class.php:33
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_get_next_month($month, $year)
Return next month.
Definition: date.lib.php:418
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
dol_get_next_day($day, $month, $year)
Return next day.
Definition: date.lib.php:383
dol_getdate($timestamp, $fast=false, $forcetimezone= '')
Return an array with locale date info.
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
if(!GETPOST('transkey', 'alphanohtml')&&!GETPOST('transphrase', 'alphanohtml')) else
View.
Definition: notice.php:44
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=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 Calling this function terminate execution ...
print $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
print $_SERVER["PHP_SELF"] n
Edit parameters.
Definition: categories.php:101
llxFooter()
Empty footer.
Definition: wrapper.php:59
dol_time_plus_duree($time, $duration_value, $duration_unit)
Add a delay to a date.
Definition: date.lib.php:114
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:105
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...