dolibarr  9.0.0
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 <http://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 = 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->societe_id) $socid=$user->societe_id;
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','alpha');
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 // Set actioncode (this code must be same for setting actioncode into peruser, listacton and index)
93 if (GETPOST('search_actioncode','array'))
94 {
95  $actioncode=GETPOST('search_actioncode','array',3);
96  if (! count($actioncode)) $actioncode='0';
97 }
98 else
99 {
100  $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));
101 }
102 if ($actioncode == '' && empty($actioncodearray)) $actioncode=(empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE)?'':$conf->global->AGENDA_DEFAULT_FILTER_TYPE);
103 
104 if ($status == '' && ! GETPOSTISSET('search_status')) $status=(empty($conf->global->AGENDA_DEFAULT_FILTER_STATUS)?'':$conf->global->AGENDA_DEFAULT_FILTER_STATUS);
105 
106 $defaultview = (empty($conf->global->AGENDA_DEFAULT_VIEW) ? 'show_month' : $conf->global->AGENDA_DEFAULT_VIEW);
107 $defaultview = (empty($user->conf->AGENDA_DEFAULT_VIEW) ? $defaultview : $user->conf->AGENDA_DEFAULT_VIEW);
108 if (empty($action) && ! GETPOSTISSET('action')) $action=$defaultview;
109 if ($action == 'default') // When action is default, we want a calendar view and not the list
110 {
111  $action = (($defaultview != 'show_list') ? $defaultview : 'show_month');
112 }
113 if (GETPOST('viewcal','none') && GETPOST('action','alpha') != 'show_day' && GETPOST('action','alpha') != 'show_week') {
114  $action='show_month'; $day='';
115 } // View by month
116 if (GETPOST('viewweek','none') || GETPOST('action','alpha') == 'show_week') {
117  $action='show_week'; $week=($week?$week:date("W")); $day=($day?$day:date("d"));
118 } // View by week
119 if (GETPOST('viewday','none') || GETPOST('action','alpha') == 'show_day') {
120  $action='show_day'; $day=($day?$day:date("d"));
121 } // View by day
122 
123 // Load translation files required by the page
124 $langs->loadLangs(array('agenda', 'other', 'commercial'));
125 
126 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
127 $hookmanager->initHooks(array('agenda'));
128 
129 
130 /*
131  * Actions
132  */
133 
134 if (GETPOST("viewlist",'alpha') || $action == 'show_list')
135 {
136  $param='';
137  if (is_array($_POST))
138  {
139  foreach($_POST as $key => $val)
140  {
141  if ($key=='token') continue;
142  $param.='&'.$key.'='.urlencode($val);
143  }
144  }
145  //print $param;
146  header("Location: ".DOL_URL_ROOT.'/comm/action/list.php?'.$param);
147  exit;
148 }
149 
150 if (GETPOST("viewperuser",'alpha') || $action == 'show_peruser')
151 {
152  $param='';
153  if (is_array($_POST))
154  {
155  foreach($_POST as $key => $val)
156  {
157  if ($key=='token') continue;
158  $param.='&'.$key.'='.urlencode($val);
159  }
160  }
161  //print $param;
162  header("Location: ".DOL_URL_ROOT.'/comm/action/peruser.php?'.$param);
163  exit;
164 }
165 
166 if ($action =='delete_action')
167 {
168  $event = new ActionComm($db);
169  $event->fetch($actionid);
170  $result=$event->delete();
171 }
172 
173 
174 /*
175  * View
176  */
177 
178 $help_url='EN:Module_Agenda_En|FR:Module_Agenda|ES:M&oacute;dulo_Agenda';
179 llxHeader('',$langs->trans("Agenda"),$help_url);
180 
181 $form=new Form($db);
182 $companystatic=new Societe($db);
183 $contactstatic=new Contact($db);
184 
185 $now=dol_now();
186 $nowarray=dol_getdate($now);
187 $nowyear=$nowarray['year'];
188 $nowmonth=$nowarray['mon'];
189 $nowday=$nowarray['mday'];
190 
191 $listofextcals=array();
192 
193 // Define list of external calendars (global admin setup)
194 if (empty($conf->global->AGENDA_DISABLE_EXT))
195 {
196  $i=0;
197  while($i < $MAXAGENDA)
198  {
199  $i++;
200  $source='AGENDA_EXT_SRC'.$i;
201  $name='AGENDA_EXT_NAME'.$i;
202  $offsettz='AGENDA_EXT_OFFSETTZ'.$i;
203  $color='AGENDA_EXT_COLOR'.$i;
204  $buggedfile='AGENDA_EXT_BUGGEDFILE'.$i;
205  if (! empty($conf->global->$source) && ! empty($conf->global->$name))
206  {
207  // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight'
208  $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));
209  }
210  }
211 }
212 // Define list of external calendars (user setup)
213 if (empty($user->conf->AGENDA_DISABLE_EXT))
214 {
215  $i=0;
216  while($i < $MAXAGENDA)
217  {
218  $i++;
219  $source='AGENDA_EXT_SRC_'.$user->id.'_'.$i;
220  $name='AGENDA_EXT_NAME_'.$user->id.'_'.$i;
221  $offsettz='AGENDA_EXT_OFFSETTZ_'.$user->id.'_'.$i;
222  $color='AGENDA_EXT_COLOR_'.$user->id.'_'.$i;
223  $enabled='AGENDA_EXT_ENABLED_'.$user->id.'_'.$i;
224  $buggedfile='AGENDA_EXT_BUGGEDFILE_'.$user->id.'_'.$i;
225  if (! empty($user->conf->$source) && ! empty($user->conf->$name))
226  {
227  // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight'
228  $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));
229  }
230  }
231 }
232 
233 if (empty($action) || $action=='show_month')
234 {
235  $prev = dol_get_prev_month($month, $year);
236  $prev_year = $prev['year'];
237  $prev_month = $prev['month'];
238  $next = dol_get_next_month($month, $year);
239  $next_year = $next['year'];
240  $next_month = $next['month'];
241 
242  $max_day_in_prev_month = date("t",dol_mktime(0,0,0,$prev_month,1,$prev_year)); // Nb of days in previous month
243  $max_day_in_month = date("t",dol_mktime(0,0,0,$month,1,$year)); // Nb of days in next month
244  // 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)
245  $tmpday = -date("w",dol_mktime(12,0,0,$month,1,$year,true))+2; // date('w') is 0 fo sunday
246  $tmpday+=((isset($conf->global->MAIN_START_WEEK)?$conf->global->MAIN_START_WEEK:1)-1);
247  if ($tmpday >= 1) $tmpday -= 7; // If tmpday is 0 we start with sunday, if -6, we start with monday of previous week.
248  // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
249  $firstdaytoshow=dol_mktime(0,0,0,$prev_month,$max_day_in_prev_month+$tmpday,$prev_year);
250  $next_day=7 - ($max_day_in_month+1-$tmpday) % 7;
251  if ($next_day < 6) $next_day+=7;
252  $lastdaytoshow=dol_mktime(0,0,0,$next_month,$next_day,$next_year);
253 }
254 if ($action=='show_week')
255 {
256  $prev = dol_get_first_day_week($day, $month, $year);
257  $prev_year = $prev['prev_year'];
258  $prev_month = $prev['prev_month'];
259  $prev_day = $prev['prev_day'];
260  $first_day = $prev['first_day'];
261  $first_month= $prev['first_month'];
262  $first_year = $prev['first_year'];
263 
264  $week = $prev['week'];
265 
266  $day = (int) $day;
267  $next = dol_get_next_week($first_day, $week, $first_month, $first_year);
268  $next_year = $next['year'];
269  $next_month = $next['month'];
270  $next_day = $next['day'];
271 
272  // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
273  $firstdaytoshow=dol_mktime(0,0,0,$first_month,$first_day,$first_year);
274  $lastdaytoshow=dol_time_plus_duree($firstdaytoshow, 7, 'd');
275 
276  $max_day_in_month = date("t",dol_mktime(0,0,0,$month,1,$year));
277 
278  $tmpday = $first_day;
279 }
280 if ($action == 'show_day')
281 {
282  $prev = dol_get_prev_day($day, $month, $year);
283  $prev_year = $prev['year'];
284  $prev_month = $prev['month'];
285  $prev_day = $prev['day'];
286  $next = dol_get_next_day($day, $month, $year);
287  $next_year = $next['year'];
288  $next_month = $next['month'];
289  $next_day = $next['day'];
290 
291  // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
292  $firstdaytoshow=dol_mktime(0,0,0,$prev_month,$prev_day,$prev_year);
293  $lastdaytoshow=dol_mktime(0,0,0,$next_month,$next_day,$next_year);
294 }
295 //print 'xx'.$prev_year.'-'.$prev_month.'-'.$prev_day;
296 //print 'xx'.$next_year.'-'.$next_month.'-'.$next_day;
297 //print dol_print_date($firstdaytoshow,'day');
298 //print dol_print_date($lastdaytoshow,'day');
299 
300 $title=$langs->trans("DoneAndToDoActions");
301 if ($status == 'done') $title=$langs->trans("DoneActions");
302 if ($status == 'todo') $title=$langs->trans("ToDoActions");
303 
304 $param='';
305 if ($actioncode || isset($_GET['search_actioncode']) || isset($_POST['search_actioncode'])) {
306  if(is_array($actioncode)) {
307  foreach($actioncode as $str_action) $param.="&search_actioncode[]=".urlencode($str_action);
308  } else $param.="&search_actioncode=".urlencode($actioncode);
309 }
310 if ($resourceid > 0) $param.="&search_resourceid=".urlencode($resourceid);
311 if ($status || isset($_GET['status']) || isset($_POST['status'])) $param.="&search_status=".urlencode($status);
312 if ($filter) $param.="&search_filter=".urlencode($filter);
313 if ($filtert) $param.="&search_filtert=".urlencode($filtert);
314 if ($usergroup) $param.="&search_usergroup=".urlencode($usergroup);
315 if ($socid) $param.="&search_socid=".urlencode($socid);
316 if ($showbirthday) $param.="&search_showbirthday=1";
317 if ($pid) $param.="&search_projectid=".urlencode($pid);
318 if ($type) $param.="&search_type=".urlencode($type);
319 if ($action == 'show_day' || $action == 'show_week' || $action == 'show_month') $param.='&action='.urlencode($action);
320 $param.="&maxprint=".urlencode($maxprint);
321 
322 // Show navigation bar
323 if (empty($action) || $action=='show_month')
324 {
325  $nav ="<a href=\"?year=".$prev_year."&amp;month=".$prev_month.$param."\"><i class=\"fa fa-chevron-left\"></i></a> &nbsp;\n";
326  $nav.=" <span id=\"month_name\">".dol_print_date(dol_mktime(0,0,0,$month,1,$year),"%b %Y");
327  $nav.=" </span>\n";
328  $nav.=" &nbsp; <a href=\"?year=".$next_year."&amp;month=".$next_month.$param."\"><i class=\"fa fa-chevron-right\"></i></a>\n";
329  $nav.=" &nbsp; (<a href=\"?year=".$nowyear."&amp;month=".$nowmonth.$param."\">".$langs->trans("Today")."</a>)";
330  $picto='calendar';
331 }
332 if ($action=='show_week')
333 {
334  $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";
335  $nav.=" <span id=\"month_name\">".dol_print_date(dol_mktime(0,0,0,$first_month,$first_day,$first_year),"%Y").", ".$langs->trans("Week")." ".$week;
336  $nav.=" </span>\n";
337  $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";
338  $nav.=" &nbsp; (<a href=\"?year=".$nowyear."&amp;month=".$nowmonth."&amp;day=".$nowday.$param."\">".$langs->trans("Today")."</a>)";
339  $picto='calendarweek';
340 }
341 if ($action=='show_day')
342 {
343  $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";
344  $nav.=" <span id=\"month_name\">".dol_print_date(dol_mktime(0,0,0,$month,$day,$year),"daytextshort");
345  $nav.=" </span>\n";
346  $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";
347  $nav.=" &nbsp; (<a href=\"?year=".$nowyear."&amp;month=".$nowmonth."&amp;day=".$nowday.$param."\">".$langs->trans("Today")."</a>)";
348  $picto='calendarday';
349 }
350 
351 // Must be after the nav definition
352 $param.='&year='.$year.'&month='.$month.($day?'&day='.$day:'');
353 //print 'x'.$param;
354 
355 
356 
357 
358 $tabactive='';
359 if ($action == 'show_month') $tabactive='cardmonth';
360 if ($action == 'show_week') $tabactive='cardweek';
361 if ($action == 'show_day') $tabactive='cardday';
362 if ($action == 'show_list') $tabactive='cardlist';
363 
364 $paramnoaction=preg_replace('/action=[a-z_]+/','',$param);
365 
366 $head = calendars_prepare_head($paramnoaction);
367 
368 print '<form method="POST" id="searchFormList" class="listactionsfilter" action="'.$_SERVER["PHP_SELF"].'">'."\n";
369 if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
370 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
371 
372 dol_fiche_head($head, $tabactive, $langs->trans('Agenda'), 0, 'action');
373 print_actions_filter($form,$canedit,$status,$year,$month,$day,$showbirthday,0,$filtert,0,$pid,$socid,$action,$listofextcals,$actioncode,$usergroup,'', $resourceid);
374 dol_fiche_end();
375 
376 
377 // Define the legend/list of calendard to show
378 $s=''; $link='';
379 
380 $showextcals=$listofextcals;
381 
382 if (! empty($conf->use_javascript_ajax)) // If javascript on
383 {
384  $s.="\n".'<!-- Div to calendars selectors -->'."\n";
385  $s.='<script type="text/javascript">' . "\n";
386  $s.='jQuery(document).ready(function () {' . "\n";
387  $s.='jQuery("#check_birthday").click(function() { console.log("Toggle birthday"); jQuery(".family_birthday").toggle(); });' . "\n";
388  $s.='jQuery(".family_birthday").toggle();' . "\n";
389  if ($action=="show_week" || $action=="show_month" || empty($action))
390  {
391  // Code to enable drag and drop
392  $s.='jQuery( "div.sortable" ).sortable({connectWith: ".sortable", placeholder: "ui-state-highlight", items: "div.movable", receive: function( event, ui ) {'."\n";
393  // Code to submit form
394  $s.='console.log("submit form to record new event");'."\n";
395  //$s.='console.log(event.target);';
396  $s.='var newval = jQuery(event.target).closest("div.dayevent").attr("id");'."\n";
397  $s.='console.log("found parent div.dayevent with id = "+newval);'."\n";
398  $s.='var frm=jQuery("#searchFormList");'."\n";
399  $s.='var newurl = ui.item.find("a.cal_event").attr("href");'."\n";
400  $s.='console.log(newurl);'."\n";
401  $s.='frm.attr("action", newurl).children("#newdate").val(newval);frm.submit();}'."\n";
402  $s.='});'."\n";
403  }
404  $s.='});' . "\n";
405  $s.='</script>' . "\n";
406 
407  // Local calendar
408  $s.='<div class="nowrap clear inline-block minheight20"><input type="checkbox" id="check_mytasks" name="check_mytasks" checked disabled> ' . $langs->trans("LocalAgenda").' &nbsp; </div>';
409 
410  // External calendars
411  if (is_array($showextcals) && count($showextcals) > 0)
412  {
413  $s.='<script type="text/javascript">' . "\n";
414  $s.='jQuery(document).ready(function () {
415  jQuery("table input[name^=\"check_ext\"]").click(function() {
416  var name = $(this).attr("name");
417  jQuery(".family_ext" + name.replace("check_ext", "")).toggle();
418  });
419  });' . "\n";
420  $s.='</script>' . "\n";
421 
422  foreach ($showextcals as $val)
423  {
424  $htmlname = md5($val['name']);
425  $s.='<div class="nowrap inline-block"><input type="checkbox" id="check_ext' . $htmlname . '" name="check_ext' . $htmlname . '" checked> ' . $val['name'] . ' &nbsp; </div>';
426  }
427  }
428 
429  // Birthdays
430  $s.='<div class="nowrap inline-block"><input type="checkbox" id="check_birthday" name="check_birthday"> '.$langs->trans("AgendaShowBirthdayEvents").' &nbsp; </div>';
431 
432  // Calendars from hooks
433  $parameters=array(); $object=null;
434  $reshook=$hookmanager->executeHooks('addCalendarChoice',$parameters,$object,$action);
435  if (empty($reshook))
436  {
437  $s.= $hookmanager->resPrint;
438  }
439  elseif ($reshook > 1)
440  {
441  $s = $hookmanager->resPrint;
442  }
443 }
444 else // If javascript off
445 {
446  $newparam=$param; // newparam is for birthday links
447  $newparam=preg_replace('/showbirthday=[0-1]/i','showbirthday='.(empty($showbirthday)?1:0),$newparam);
448  if (! preg_match('/showbirthday=/i',$newparam)) $newparam.='&showbirthday=1';
449  $link='<a href="'.dol_escape_htmltag($_SERVER['PHP_SELF']);
450  $link.='?'.dol_escape_htmltag($newparam);
451  $link.='">';
452  if (empty($showbirthday)) $link.=$langs->trans("AgendaShowBirthdayEvents");
453  else $link.=$langs->trans("AgendaHideBirthdayEvents");
454  $link.='</a>';
455 }
456 
457 print load_fiche_titre($s, $link.' &nbsp; &nbsp; '.$nav, '', 0, 0, 'tablelistofcalendars');
458 
459 
460 // Load events from database into $eventarray
461 $eventarray=array();
462 
463 $sql = 'SELECT ';
464 if ($usergroup > 0) $sql.=" DISTINCT";
465 $sql.= ' a.id, a.label,';
466 $sql.= ' a.datep,';
467 $sql.= ' a.datep2,';
468 $sql.= ' a.percent,';
469 $sql.= ' a.fk_user_author,a.fk_user_action,';
470 $sql.= ' a.transparency, a.priority, a.fulldayevent, a.location,';
471 $sql.= ' a.fk_soc, a.fk_contact,';
472 $sql.= ' a.fk_element, a.elementtype,';
473 $sql.= ' ca.code as type_code, ca.libelle as type_label, ca.color as type_color';
474 $sql.= ' FROM '.MAIN_DB_PREFIX.'c_actioncomm as ca, '.MAIN_DB_PREFIX."actioncomm as a";
475 if (! $user->rights->societe->client->voir && ! $socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
476 // We must filter on resource table
477 if ($resourceid > 0) $sql.=", ".MAIN_DB_PREFIX."element_resources as r";
478 // We must filter on assignement table
479 if ($filtert > 0 || $usergroup > 0) $sql.=", ".MAIN_DB_PREFIX."actioncomm_resources as ar";
480 if ($usergroup > 0) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_user = ar.fk_element";
481 $sql.= ' WHERE a.fk_action = ca.id';
482 $sql.= ' AND a.entity IN ('.getEntity('agenda').')';
483 // Condition on actioncode
484 if (! empty($actioncode))
485 {
486  if (empty($conf->global->AGENDA_USE_EVENT_TYPE))
487  {
488  if ($actioncode == 'AC_NON_AUTO') $sql.= " AND ca.type != 'systemauto'";
489  elseif ($actioncode == 'AC_ALL_AUTO') $sql.= " AND ca.type = 'systemauto'";
490  else
491  {
492  if ($actioncode == 'AC_OTH') $sql.= " AND ca.type != 'systemauto'";
493  if ($actioncode == 'AC_OTH_AUTO') $sql.= " AND ca.type = 'systemauto'";
494  }
495  }
496  else
497  {
498  if ($actioncode == 'AC_NON_AUTO') $sql.= " AND ca.type != 'systemauto'";
499  elseif ($actioncode == 'AC_ALL_AUTO') $sql.= " AND ca.type = 'systemauto'";
500  else
501  {
502  if (is_array($actioncode))
503  {
504  $sql.=" AND ca.code IN ('".implode("','", $actioncode)."')";
505  }
506  else
507  {
508  $sql.=" AND ca.code IN ('".implode("','", explode(',', $actioncode))."')";
509  }
510  }
511  }
512 }
513 if ($resourceid > 0) $sql.=" AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = ".$db->escape($resourceid);
514 if ($pid) $sql.=" AND a.fk_project=".$db->escape($pid);
515 if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND (a.fk_soc IS NULL OR sc.fk_user = " .$user->id . ")";
516 if ($socid > 0) $sql.= ' AND a.fk_soc = '.$socid;
517 // We must filter on assignement table
518 if ($filtert > 0 || $usergroup > 0) $sql.= " AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
519 if ($action == 'show_day')
520 {
521  $sql.= " AND (";
522  $sql.= " (a.datep BETWEEN '".$db->idate(dol_mktime(0,0,0,$month,$day,$year))."'";
523  $sql.= " AND '".$db->idate(dol_mktime(23,59,59,$month,$day,$year))."')";
524  $sql.= " OR ";
525  $sql.= " (a.datep2 BETWEEN '".$db->idate(dol_mktime(0,0,0,$month,$day,$year))."'";
526  $sql.= " AND '".$db->idate(dol_mktime(23,59,59,$month,$day,$year))."')";
527  $sql.= " OR ";
528  $sql.= " (a.datep < '".$db->idate(dol_mktime(0,0,0,$month,$day,$year))."'";
529  $sql.= " AND a.datep2 > '".$db->idate(dol_mktime(23,59,59,$month,$day,$year))."')";
530  $sql.= ')';
531 }
532 else
533 {
534  // To limit array
535  $sql.= " AND (";
536  $sql.= " (a.datep BETWEEN '".$db->idate(dol_mktime(0,0,0,$month,1,$year)-(60*60*24*7))."'"; // Start 7 days before
537  $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
538  $sql.= " OR ";
539  $sql.= " (a.datep2 BETWEEN '".$db->idate(dol_mktime(0,0,0,$month,1,$year)-(60*60*24*7))."'";
540  $sql.= " AND '".$db->idate(dol_mktime(23,59,59,$month,28,$year)+(60*60*24*10))."')";
541  $sql.= " OR ";
542  $sql.= " (a.datep < '".$db->idate(dol_mktime(0,0,0,$month,1,$year)-(60*60*24*7))."'";
543  $sql.= " AND a.datep2 > '".$db->idate(dol_mktime(23,59,59,$month,28,$year)+(60*60*24*10))."')";
544  $sql.= ')';
545 }
546 if ($type) $sql.= " AND ca.id = ".$type;
547 if ($status == '0') { $sql.= " AND a.percent = 0"; }
548 if ($status == '-1') { $sql.= " AND a.percent = -1"; } // Not applicable
549 if ($status == '50') { $sql.= " AND (a.percent > 0 AND a.percent < 100)"; } // Running already started
550 if ($status == 'done' || $status == '100') { $sql.= " AND (a.percent = 100)"; }
551 if ($status == 'todo') { $sql.= " AND (a.percent >= 0 AND a.percent < 100)"; }
552 // We must filter on assignement table
553 if ($filtert > 0 || $usergroup > 0)
554 {
555  $sql.= " AND (";
556  if ($filtert > 0) $sql.= "ar.fk_element = ".$filtert;
557  if ($usergroup > 0) $sql.= ($filtert>0?" OR ":"")." ugu.fk_usergroup = ".$usergroup;
558  $sql.= ")";
559 }
560 // Sort on date
561 $sql.= ' ORDER BY datep';
562 //print $sql;
563 
564 
565 dol_syslog("comm/action/index.php", LOG_DEBUG);
566 $resql=$db->query($sql);
567 if ($resql)
568 {
569  $num = $db->num_rows($resql);
570 
571  $MAXONSAMEPAGE=10000; // Useless to have more. Protection to avoid memory overload when high number of event (for example after a mass import)
572  $i=0;
573  while ($i < $num && $i < $MAXONSAMEPAGE)
574  {
575  $obj = $db->fetch_object($resql);
576 
577  // Discard auto action if option is on
578  if (! empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO) && $obj->type_code == 'AC_OTH_AUTO')
579  {
580  $i++;
581  continue;
582  }
583 
584  // Create a new object action
585  $event=new ActionComm($db);
586  $event->id=$obj->id;
587 
588  $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
589  $event->datef=$db->jdate($obj->datep2);
590  //var_dump($obj->datep);
591  //var_dump($event->datep);
592 
593  $event->type_code=$obj->type_code;
594  $event->type_label=$obj->type_label;
595  $event->type_color=$obj->type_color;
596 
597  $event->libelle=$obj->label;
598  $event->label=$obj->label;
599  $event->percentage=$obj->percent;
600  $event->authorid=$obj->fk_user_author; // user id of creator
601  $event->userownerid=$obj->fk_user_action; // user id of owner
602  $event->fetch_userassigned(); // This load $event->userassigned
603  $event->priority=$obj->priority;
604  $event->fulldayevent=$obj->fulldayevent;
605  $event->location=$obj->location;
606  $event->transparency=$obj->transparency;
607  $event->fk_element=$obj->fk_element;
608  $event->elementtype=$obj->elementtype;
609 
610  $event->societe->id=$obj->fk_soc;
611  $event->thirdparty_id=$obj->fk_soc;
612  $event->contact->id=$obj->fk_contact;
613  $event->contact_id=$obj->fk_contact;
614 
615  // Defined date_start_in_calendar and date_end_in_calendar property
616  // They are date start and end of action but modified to not be outside calendar view.
617  if ($event->percentage <= 0)
618  {
619  $event->date_start_in_calendar=$event->datep;
620  if ($event->datef != '' && $event->datef >= $event->datep) $event->date_end_in_calendar=$event->datef;
621  else $event->date_end_in_calendar=$event->datep;
622  }
623  else
624  {
625  $event->date_start_in_calendar=$event->datep;
626  if ($event->datef != '' && $event->datef >= $event->datep) $event->date_end_in_calendar=$event->datef;
627  else $event->date_end_in_calendar=$event->datep;
628  }
629  // Define ponctual property
630  if ($event->date_start_in_calendar == $event->date_end_in_calendar)
631  {
632  $event->ponctuel=1;
633  }
634 
635  // Check values
636  if ($event->date_end_in_calendar < $firstdaytoshow ||
637  $event->date_start_in_calendar >= $lastdaytoshow)
638  {
639  // This record is out of visible range
640  }
641  else
642  {
643  if ($event->date_start_in_calendar < $firstdaytoshow) $event->date_start_in_calendar=$firstdaytoshow;
644  if ($event->date_end_in_calendar >= $lastdaytoshow) $event->date_end_in_calendar=($lastdaytoshow-1);
645 
646  // Add an entry in actionarray for each day
647  $daycursor=$event->date_start_in_calendar;
648  $annee = date('Y',$daycursor);
649  $mois = date('m',$daycursor);
650  $jour = date('d',$daycursor);
651 
652  // Loop on each day covered by action to prepare an index to show on calendar
653  $loop=true; $j=0;
654  $daykey=dol_mktime(0,0,0,$mois,$jour,$annee);
655  do
656  {
657  //if ($event->id==408) print 'daykey='.$daykey.' '.$event->datep.' '.$event->datef.'<br>';
658 
659  $eventarray[$daykey][]=$event;
660  $j++;
661 
662  $daykey+=60*60*24;
663  if ($daykey > $event->date_end_in_calendar) $loop=false;
664  }
665  while ($loop);
666 
667  //print 'Event '.$i.' id='.$event->id.' (start='.dol_print_date($event->datep).'-end='.dol_print_date($event->datef);
668  //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>';
669  }
670  $i++;
671  }
672 }
673 else
674 {
675  dol_print_error($db);
676 }
677 
678 // Complete $eventarray with birthdates
679 if ($showbirthday)
680 {
681  // Add events in array
682  $sql = 'SELECT sp.rowid, sp.lastname, sp.firstname, sp.birthday';
683  $sql.= ' FROM '.MAIN_DB_PREFIX.'socpeople as sp';
684  $sql.= ' WHERE (priv=0 OR (priv=1 AND fk_user_creat='.$user->id.'))';
685  $sql.= " AND sp.entity IN (".getEntity('socpeople').")";
686  if ($action == 'show_day')
687  {
688  $sql.= ' AND MONTH(birthday) = '.$month;
689  $sql.= ' AND DAY(birthday) = '.$day;
690  }
691  else
692  {
693  $sql.= ' AND MONTH(birthday) = '.$month;
694  }
695  $sql.= ' ORDER BY birthday';
696 
697  dol_syslog("comm/action/index.php", LOG_DEBUG);
698  $resql=$db->query($sql);
699  if ($resql)
700  {
701  $num = $db->num_rows($resql);
702  $i=0;
703  while ($i < $num)
704  {
705  $obj = $db->fetch_object($resql);
706  $event=new ActionComm($db);
707  $event->id=$obj->rowid; // We put contact id in action id for birthdays events
708  $datebirth=dol_stringtotime($obj->birthday,1);
709  //print 'ee'.$obj->birthday.'-'.$datebirth;
710  $datearray=dol_getdate($datebirth,true);
711  $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
712  $event->datef=$event->datep;
713  $event->type_code='BIRTHDAY';
714  $event->libelle=$langs->trans("Birthday").' '.dolGetFirstLastname($obj->firstname,$obj->lastname);
715  $event->percentage=100;
716  $event->fulldayevent=1;
717 
718  $event->date_start_in_calendar=$event->datep;
719  $event->date_end_in_calendar=$event->datef;
720  $event->ponctuel=0;
721 
722  // Add an entry in actionarray for each day
723  $daycursor=$event->date_start_in_calendar;
724  $annee = date('Y',$daycursor);
725  $mois = date('m',$daycursor);
726  $jour = date('d',$daycursor);
727 
728  $loop=true;
729  $daykey=dol_mktime(0,0,0,$mois,$jour,$annee);
730  do
731  {
732  $eventarray[$daykey][]=$event;
733  $daykey+=60*60*24;
734  if ($daykey > $event->date_end_in_calendar) $loop=false;
735  }
736  while ($loop);
737  $i++;
738  }
739  }
740  else
741  {
742  dol_print_error($db);
743  }
744 }
745 
746 // Complete $eventarray with external import Ical
747 if (count($listofextcals))
748 {
749  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/ical.class.php';
750  foreach($listofextcals as $extcal)
751  {
752  $url=$extcal['src']; // Example: https://www.google.com/calendar/ical/eldy10%40gmail.com/private-cde92aa7d7e0ef6110010a821a2aaeb/basic.ics
753  $namecal = $extcal['name'];
754  $offsettz = $extcal['offsettz'];
755  $colorcal = $extcal['color'];
756  $buggedfile = $extcal['buggedfile'];
757  //print "url=".$url." namecal=".$namecal." colorcal=".$colorcal." buggedfile=".$buggedfile;
758  $ical=new ICal();
759  $ical->parse($url);
760 
761  // After this $ical->cal['VEVENT'] contains array of events, $ical->cal['DAYLIGHT'] contains daylight info, $ical->cal['STANDARD'] contains non daylight info, ...
762  //var_dump($ical->cal); exit;
763  $icalevents=array();
764  if (is_array($ical->get_event_list())) $icalevents=array_merge($icalevents,$ical->get_event_list()); // Add $ical->cal['VEVENT']
765  if (is_array($ical->get_freebusy_list())) $icalevents=array_merge($icalevents,$ical->get_freebusy_list()); // Add $ical->cal['VFREEBUSY']
766 
767  if (count($icalevents)>0)
768  {
769  // Duplicate all repeatable events into new entries
770  $moreicalevents=array();
771  foreach($icalevents as $icalevent)
772  {
773  if (isset($icalevent['RRULE']) && is_array($icalevent['RRULE'])) //repeatable event
774  {
775  //if ($event->date_start_in_calendar < $firstdaytoshow) $event->date_start_in_calendar=$firstdaytoshow;
776  //if ($event->date_end_in_calendar > $lastdaytoshow) $event->date_end_in_calendar=($lastdaytoshow-1);
777  if ($icalevent['DTSTART;VALUE=DATE']) //fullday event
778  {
779  $datecurstart=dol_stringtotime($icalevent['DTSTART;VALUE=DATE'],1);
780  $datecurend=dol_stringtotime($icalevent['DTEND;VALUE=DATE'],1)-1; // We remove one second to get last second of day
781  }
782  else if (is_array($icalevent['DTSTART']) && ! empty($icalevent['DTSTART']['unixtime']))
783  {
784  $datecurstart=$icalevent['DTSTART']['unixtime'];
785  $datecurend=$icalevent['DTEND']['unixtime'];
786  if (! empty($ical->cal['DAYLIGHT']['DTSTART']) && $datecurstart)
787  {
788  //var_dump($ical->cal);
789  $tmpcurstart=$datecurstart;
790  $tmpcurend=$datecurend;
791  $tmpdaylightstart=dol_mktime(0,0,0,1,1,1970,1) + (int) $ical->cal['DAYLIGHT']['DTSTART'];
792  $tmpdaylightend=dol_mktime(0,0,0,1,1,1970,1) + (int) $ical->cal['STANDARD']['DTSTART'];
793  //var_dump($tmpcurstart);var_dump($tmpcurend); var_dump($ical->cal['DAYLIGHT']['DTSTART']);var_dump($ical->cal['STANDARD']['DTSTART']);
794  // Edit datecurstart and datecurend
795  if ($tmpcurstart >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend) $datecurstart-=((int) $ical->cal['DAYLIGHT']['TZOFFSETTO'])*36;
796  else $datecurstart-=((int) $ical->cal['STANDARD']['TZOFFSETTO'])*36;
797  if ($tmpcurend >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend) $datecurend-=((int) $ical->cal['DAYLIGHT']['TZOFFSETTO'])*36;
798  else $datecurend-=((int) $ical->cal['STANDARD']['TZOFFSETTO'])*36;
799  }
800  // datecurstart and datecurend are now GMT date
801  //var_dump($datecurstart); var_dump($datecurend); exit;
802  }
803  else
804  {
805  // Not a recongized record
806  dol_syslog("Found a not recognized repeatable record with unknown date start", LOG_ERR);
807  continue;
808  }
809  //print 'xx'.$datecurstart;exit;
810 
811  $interval=(empty($icalevent['RRULE']['INTERVAL'])?1:$icalevent['RRULE']['INTERVAL']);
812  $until=empty($icalevent['RRULE']['UNTIL'])?0:dol_stringtotime($icalevent['RRULE']['UNTIL'],1);
813  $maxrepeat=empty($icalevent['RRULE']['COUNT'])?0:$icalevent['RRULE']['COUNT'];
814  if ($until && ($until+($datecurend-$datecurstart)) < $firstdaytoshow) continue; // We discard repeatable event that end before start date to show
815  if ($datecurstart >= $lastdaytoshow) continue; // We discard repeatable event that start after end date to show
816 
817  $numofevent=0;
818  while (($datecurstart < $lastdaytoshow) && (empty($maxrepeat) || ($numofevent < $maxrepeat)))
819  {
820  if ($datecurend >= $firstdaytoshow) // We add event
821  {
822  $newevent=$icalevent;
823  unset($newevent['RRULE']);
824  if ($icalevent['DTSTART;VALUE=DATE'])
825  {
826  $newevent['DTSTART;VALUE=DATE']=dol_print_date($datecurstart,'%Y%m%d');
827  $newevent['DTEND;VALUE=DATE']=dol_print_date($datecurend+1,'%Y%m%d');
828  }
829  else
830  {
831  $newevent['DTSTART']=$datecurstart;
832  $newevent['DTEND']=$datecurend;
833  }
834  $moreicalevents[]=$newevent;
835  }
836  // Jump on next occurence
837  $numofevent++;
838  $savdatecurstart=$datecurstart;
839  if ($icalevent['RRULE']['FREQ']=='DAILY')
840  {
841  $datecurstart=dol_time_plus_duree($datecurstart, $interval, 'd');
842  $datecurend=dol_time_plus_duree($datecurend, $interval, 'd');
843  }
844  if ($icalevent['RRULE']['FREQ']=='WEEKLY')
845  {
846  $datecurstart=dol_time_plus_duree($datecurstart, $interval, 'w');
847  $datecurend=dol_time_plus_duree($datecurend, $interval, 'w');
848  }
849  elseif ($icalevent['RRULE']['FREQ']=='MONTHLY')
850  {
851  $datecurstart=dol_time_plus_duree($datecurstart, $interval, 'm');
852  $datecurend=dol_time_plus_duree($datecurend, $interval, 'm');
853  }
854  elseif ($icalevent['RRULE']['FREQ']=='YEARLY')
855  {
856  $datecurstart=dol_time_plus_duree($datecurstart, $interval, 'y');
857  $datecurend=dol_time_plus_duree($datecurend, $interval, 'y');
858  }
859  // Test to avoid infinite loop ($datecurstart must increase)
860  if ($savdatecurstart >= $datecurstart)
861  {
862  dol_syslog("Found a rule freq ".$icalevent['RRULE']['FREQ']." not managed by dolibarr code. Assume 1 week frequency.", LOG_ERR);
863  $datecurstart+=3600*24*7;
864  $datecurend+=3600*24*7;
865  }
866  }
867  }
868  }
869  $icalevents=array_merge($icalevents,$moreicalevents);
870 
871  // Loop on each entry into cal file to know if entry is qualified and add an ActionComm into $eventarray
872  foreach($icalevents as $icalevent)
873  {
874  //var_dump($icalevent);
875 
876  //print $icalevent['SUMMARY'].'->'.var_dump($icalevent).'<br>';exit;
877  if (! empty($icalevent['RRULE'])) continue; // We found a repeatable event. It was already split into unitary events, so we discard general rule.
878 
879  // Create a new object action
880  $event=new ActionComm($db);
881  $addevent = false;
882  if (isset($icalevent['DTSTART;VALUE=DATE'])) // fullday event
883  {
884  // For full day events, date are also GMT but they wont but converted using tz during output
885  $datestart=dol_stringtotime($icalevent['DTSTART;VALUE=DATE'],1);
886  $dateend=dol_stringtotime($icalevent['DTEND;VALUE=DATE'],1)-1; // We remove one second to get last second of day
887  //print 'x'.$datestart.'-'.$dateend;exit;
888  //print dol_print_date($dateend,'dayhour','gmt');
889  $event->fulldayevent=1;
890  $addevent=true;
891  }
892  elseif (!is_array($icalevent['DTSTART'])) // not fullday event (DTSTART is not array. It is a value like '19700101T000000Z' for 00:00 in greenwitch)
893  {
894  $datestart=$icalevent['DTSTART'];
895  $dateend=$icalevent['DTEND'];
896 
897  $datestart+=+($offsettz * 3600);
898  $dateend+=+($offsettz * 3600);
899 
900  $addevent=true;
901  //var_dump($offsettz);
902  //var_dump(dol_print_date($datestart, 'dayhour', 'gmt'));
903  }
904  elseif (isset($icalevent['DTSTART']['unixtime'])) // File contains a local timezone + a TZ (for example when using bluemind)
905  {
906  $datestart=$icalevent['DTSTART']['unixtime'];
907  $dateend=$icalevent['DTEND']['unixtime'];
908 
909  $datestart+=+($offsettz * 3600);
910  $dateend+=+($offsettz * 3600);
911 
912  // $buggedfile is set to uselocalandtznodaylight if conf->global->AGENDA_EXT_BUGGEDFILEx = 'uselocalandtznodaylight'
913  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
914  {
915  // TODO
916  }
917  // $buggedfile is set to uselocalandtzdaylight if conf->global->AGENDA_EXT_BUGGEDFILEx = 'uselocalandtzdaylight' (for example with bluemind)
918  if ($buggedfile === 'uselocalandtzdaylight') // unixtime is a local date that does take daylight into account, TZID is +2 for example for 'Europe/Paris' in summer
919  {
920  $localtzs = new DateTimeZone(preg_replace('/"/','',$icalevent['DTSTART']['TZID']));
921  $localtze = new DateTimeZone(preg_replace('/"/','',$icalevent['DTEND']['TZID']));
922  $localdts = new DateTime(dol_print_date($datestart,'dayrfc','gmt'), $localtzs);
923  $localdte = new DateTime(dol_print_date($dateend,'dayrfc','gmt'), $localtze);
924  $tmps=-1*$localtzs->getOffset($localdts);
925  $tmpe=-1*$localtze->getOffset($localdte);
926  $datestart+=$tmps;
927  $dateend+=$tmpe;
928  //var_dump($datestart);
929  }
930  $addevent=true;
931  }
932 
933  if ($addevent)
934  {
935  $event->id=$icalevent['UID'];
936  $event->icalname=$namecal;
937  $event->icalcolor=$colorcal;
938  $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.
939  $event->datep=$datestart+$usertime;
940  $event->datef=$dateend+$usertime;
941  $event->type_code="ICALEVENT";
942 
943  if($icalevent['SUMMARY']) $event->libelle=$icalevent['SUMMARY'];
944  elseif($icalevent['DESCRIPTION']) $event->libelle=dol_nl2br($icalevent['DESCRIPTION'],1);
945  else $event->libelle = $langs->trans("ExtSiteNoLabel");
946 
947  $event->date_start_in_calendar=$event->datep;
948 
949  if ($event->datef != '' && $event->datef >= $event->datep) $event->date_end_in_calendar=$event->datef;
950  else $event->date_end_in_calendar=$event->datep;
951 
952  // Define ponctual property
953  if ($event->date_start_in_calendar == $event->date_end_in_calendar)
954  {
955  $event->ponctuel=1;
956  //print 'x'.$datestart.'-'.$dateend;exit;
957  }
958 
959  // Add event into $eventarray if date range are ok.
960  if ($event->date_end_in_calendar < $firstdaytoshow || $event->date_start_in_calendar >= $lastdaytoshow)
961  {
962  //print 'x'.$datestart.'-'.$dateend;exit;
963  //print 'x'.$datestart.'-'.$dateend;exit;
964  //print 'x'.$datestart.'-'.$dateend;exit;
965  // This record is out of visible range
966  }
967  else
968  {
969  if ($event->date_start_in_calendar < $firstdaytoshow) $event->date_start_in_calendar=$firstdaytoshow;
970  if ($event->date_end_in_calendar >= $lastdaytoshow) $event->date_end_in_calendar=($lastdaytoshow - 1);
971 
972  // Add an entry in actionarray for each day
973  $daycursor=$event->date_start_in_calendar;
974  $annee = date('Y',$daycursor);
975  $mois = date('m',$daycursor);
976  $jour = date('d',$daycursor);
977 
978  // Loop on each day covered by action to prepare an index to show on calendar
979  $loop=true; $j=0;
980  // daykey must be date that represent day box in calendar so must be a user time
981  $daykey=dol_mktime(0,0,0,$mois,$jour,$annee);
982  $daykeygmt=dol_mktime(0,0,0,$mois,$jour,$annee,true,0);
983  do
984  {
985  //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').' ';
986  $eventarray[$daykey][]=$event;
987  $daykey+=60*60*24; $daykeygmt+=60*60*24; // Add one day
988  if (($event->fulldayevent ? $daykeygmt : $daykey) > $event->date_end_in_calendar) $loop=false;
989  }
990  while ($loop);
991  }
992  }
993  }
994  }
995  }
996 }
997 
998 
999 
1000 // Complete $eventarray with events coming from external module
1001 $parameters=array(); $object=null;
1002 $reshook=$hookmanager->executeHooks('getCalendarEvents',$parameters,$object,$action);
1003 if (! empty($hookmanager->resArray['eventarray'])) {
1004  foreach ($hookmanager->resArray['eventarray'] as $keyDate => $events) {
1005  if (!isset($eventarray[$keyDate])) {
1006  $eventarray[$keyDate]=array();
1007  }
1008  $eventarray[$keyDate]=array_merge($eventarray[$keyDate], $events);
1009  }
1010 }
1011 
1012 
1013 
1014 $maxnbofchar=0;
1015 $cachethirdparties=array();
1016 $cachecontacts=array();
1017 $cacheusers=array();
1018 
1019 // Define theme_datacolor array
1020 $color_file = DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/graph-color.php";
1021 if (is_readable($color_file))
1022 {
1023  include_once $color_file;
1024 }
1025 if (! is_array($theme_datacolor)) $theme_datacolor=array(array(120,130,150), array(200,160,180), array(190,190,220));
1026 
1027 
1028 if (empty($action) || $action == 'show_month') // View by month
1029 {
1030  $newparam=$param; // newparam is for birthday links
1031  $newparam=preg_replace('/showbirthday=/i','showbirthday_=',$newparam); // To avoid replacement when replace day= is done
1032  $newparam=preg_replace('/action=show_month&?/i','',$newparam);
1033  $newparam=preg_replace('/action=show_week&?/i','',$newparam);
1034  $newparam=preg_replace('/day=[0-9]+&?/i','',$newparam);
1035  $newparam=preg_replace('/month=[0-9]+&?/i','',$newparam);
1036  $newparam=preg_replace('/year=[0-9]+&?/i','',$newparam);
1037  $newparam=preg_replace('/viewcal=[0-9]+&?/i','',$newparam);
1038  $newparam=preg_replace('/showbirthday_=/i','showbirthday=',$newparam); // Restore correct parameter
1039  $newparam.='&viewcal=1';
1040 
1041 
1042  print '<div class="div-table-responsive-no-min">';
1043  print '<table width="100%" class="noborder nocellnopadd cal_pannel cal_month">';
1044  print ' <tr class="liste_titre">';
1045  $i=0;
1046  while ($i < 7)
1047  {
1048  print ' <td align="center">';
1049  $numdayinweek=(($i+(isset($conf->global->MAIN_START_WEEK)?$conf->global->MAIN_START_WEEK:1)) % 7);
1050  if (! empty($conf->dol_optimize_smallscreen))
1051  {
1052  $labelshort=array(0=>'SundayMin',1=>'MondayMin',2=>'TuesdayMin',3=>'WednesdayMin',4=>'ThursdayMin',5=>'FridayMin',6=>'SaturdayMin');
1053  print $langs->trans($labelshort[$numdayinweek]);
1054  }
1055  else print $langs->trans("Day".$numdayinweek);
1056  print ' </td>'."\n";
1057  $i++;
1058  }
1059  echo ' </tr>'."\n";
1060 
1061  $todayarray=dol_getdate($now,'fast');
1062  $todaytms=dol_mktime(0, 0, 0, $todayarray['mon'], $todayarray['mday'], $todayarray['year']);
1063 
1064  // In loops, tmpday contains day nb in current month (can be zero or negative for days of previous month)
1065  //var_dump($eventarray);
1066  for ($iter_week = 0; $iter_week < 6 ; $iter_week++)
1067  {
1068  echo " <tr>\n";
1069  for ($iter_day = 0; $iter_day < 7; $iter_day++)
1070  {
1071  /* Show days before the beginning of the current month (previous month) */
1072  if ($tmpday <= 0)
1073  {
1074  $style='cal_other_month cal_past';
1075  if ($iter_day == 6) $style.=' cal_other_month_right';
1076  echo ' <td class="'.$style.' nowrap" width="14%" valign="top">';
1077  show_day_events($db, $max_day_in_prev_month + $tmpday, $prev_month, $prev_year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
1078  echo " </td>\n";
1079  }
1080  /* Show days of the current month */
1081  elseif ($tmpday <= $max_day_in_month)
1082  {
1083  $curtime = dol_mktime(0, 0, 0, $month, $tmpday, $year);
1084  $style='cal_current_month';
1085  if ($iter_day == 6) $style.=' cal_current_month_right';
1086  $today=0;
1087  if ($todayarray['mday']==$tmpday && $todayarray['mon']==$month && $todayarray['year']==$year) $today=1;
1088  if ($today) $style='cal_today';
1089  if ($curtime < $todaytms) $style.=' cal_past';
1090  //var_dump($todayarray['mday']."==".$tmpday." && ".$todayarray['mon']."==".$month." && ".$todayarray['year']."==".$year.' -> '.$style);
1091  echo ' <td class="'.$style.' nowrap" width="14%" valign="top">';
1092  show_day_events($db, $tmpday, $month, $year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
1093  echo " </td>\n";
1094  }
1095  /* Show days after the current month (next month) */
1096  else
1097  {
1098  $style='cal_other_month';
1099  if ($iter_day == 6) $style.=' cal_other_month_right';
1100  echo ' <td class="'.$style.' nowrap" width="14%" valign="top">';
1101  show_day_events($db, $tmpday - $max_day_in_month, $next_month, $next_year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
1102  echo "</td>\n";
1103  }
1104  $tmpday++;
1105  }
1106  echo " </tr>\n";
1107  }
1108  print "</table>\n";
1109  print '</div>';
1110 
1111  print '<input type="hidden" name="actionmove" value="mupdate">';
1112  print '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($_SERVER['PHP_SELF']).'?'.dol_escape_htmltag($_SERVER['QUERY_STRING']).'">';
1113  print '<input type="hidden" name="newdate" id="newdate">' ;
1114 }
1115 elseif ($action == 'show_week') // View by week
1116 {
1117  $newparam=$param; // newparam is for birthday links
1118  $newparam=preg_replace('/showbirthday=/i','showbirthday_=',$newparam); // To avoid replacement when replace day= is done
1119  $newparam=preg_replace('/action=show_month&?/i','',$newparam);
1120  $newparam=preg_replace('/action=show_week&?/i','',$newparam);
1121  $newparam=preg_replace('/day=[0-9]+&?/i','',$newparam);
1122  $newparam=preg_replace('/month=[0-9]+&?/i','',$newparam);
1123  $newparam=preg_replace('/year=[0-9]+&?/i','',$newparam);
1124  $newparam=preg_replace('/viewweek=[0-9]+&?/i','',$newparam);
1125  $newparam=preg_replace('/showbirthday_=/i','showbirthday=',$newparam); // Restore correct parameter
1126  $newparam.='&viewweek=1';
1127 
1128  print '<div class="div-table-responsive-no-min">';
1129  print '<table width="100%" class="noborder nocellnopadd cal_pannel cal_month">';
1130  print ' <tr class="liste_titre">';
1131  $i=0;
1132  while ($i < 7)
1133  {
1134  echo ' <td align="center">'.$langs->trans("Day".(($i+(isset($conf->global->MAIN_START_WEEK)?$conf->global->MAIN_START_WEEK:1)) % 7))."</td>\n";
1135  $i++;
1136  }
1137  echo " </tr>\n";
1138 
1139  echo " <tr>\n";
1140 
1141  for ($iter_day = 0; $iter_day < 7; $iter_day++)
1142  {
1143  // Show days of the current week
1144  $curtime = dol_time_plus_duree($firstdaytoshow, $iter_day, 'd');
1145  $tmparray = dol_getdate($curtime, true);
1146  $tmpday = $tmparray['mday'];
1147  $tmpmonth = $tmparray['mon'];
1148  $tmpyear = $tmparray['year'];
1149 
1150  $style='cal_current_month';
1151  if ($iter_day == 6) $style.=' cal_other_month_right';
1152  $today=0;
1153  $todayarray=dol_getdate($now,'fast');
1154  if ($todayarray['mday']==$tmpday && $todayarray['mon']==$tmpmonth && $todayarray['year']==$tmpyear) $today=1;
1155  if ($today) $style='cal_today';
1156 
1157  echo ' <td class="'.$style.'" width="14%" valign="top">';
1158  show_day_events($db, $tmpday, $tmpmonth, $tmpyear, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300);
1159  echo " </td>\n";
1160  }
1161  echo " </tr>\n";
1162 
1163  print "</table>\n";
1164  print '</div>';
1165 
1166  echo '<input type="hidden" name="actionmove" value="mupdate">';
1167  echo '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($_SERVER['PHP_SELF']).'?'.dol_escape_htmltag($_SERVER['QUERY_STRING']).'">';
1168  echo '<input type="hidden" name="newdate" id="newdate">' ;
1169 }
1170 else // View by day
1171 {
1172  $newparam=$param; // newparam is for birthday links
1173  $newparam=preg_replace('/action=show_month&?/i','',$newparam);
1174  $newparam=preg_replace('/action=show_week&?/i','',$newparam);
1175  $newparam=preg_replace('/viewday=[0-9]+&?/i','',$newparam);
1176  $newparam.='&viewday=1';
1177  // Code to show just one day
1178  $style='cal_current_month cal_current_month_oneday';
1179  $today=0;
1180  $todayarray=dol_getdate($now,'fast');
1181  if ($todayarray['mday']==$day && $todayarray['mon']==$month && $todayarray['year']==$year) $today=1;
1182  //if ($today) $style='cal_today';
1183 
1184  $timestamp=dol_mktime(12,0,0,$month,$day,$year);
1185  $arraytimestamp=dol_getdate($timestamp);
1186 
1187  //echo '<table class="tagtable centpercent noborder nocellnopadd cal_pannel cal_month">';
1188  echo '<table class="tagtable centpercent noborder nocellnopadd cal_pannel cal_month noborderbottom" style="margin-bottom: 5px !important;">';
1189 
1190  echo ' <tr class="tagtr liste_titre">';
1191  echo ' <td class="tagtd width100"></td>';
1192  echo ' <td class="tagtd center">'.$langs->trans("Day".$arraytimestamp['wday'])."</td>\n";
1193  echo " </td>\n";
1194 
1195  /*
1196  echo ' <div class="tagtr">';
1197  echo ' <div class="tagtd width100"></div>';
1198  echo ' <div class="tagtd center">';
1199  echo show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, -1);
1200  echo ' </div>'."\n";
1201  echo " </div>\n";
1202  */
1203 
1204  echo '</table>';
1205 
1206  /* WIP View per hour */
1207  $useviewhour = 0;
1208  if ($useviewhour)
1209  {
1210  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
1211 
1212  $maxheightwin=(isset($_SESSION["dol_screenheight"]) && $_SESSION["dol_screenheight"] > 500)?($_SESSION["dol_screenheight"]-200):660; // Also into index.php file
1213 
1214  echo '<div style="max-height: '.$maxheightwin.'px;">';
1215  echo '<div class="tagtable centpercent calendarviewcontainer">';
1216 
1217  $maxnbofchar=80;
1218 
1219  $tmp = explode('-', $conf->global->MAIN_DEFAULT_WORKING_HOURS);
1220  $minhour = round($tmp[0],0);
1221  $maxhour = round($tmp[1],0);
1222  if ($minhour > 23) $minhour = 23;
1223  if ($maxhour < 1) $maxhour = 1;
1224  if ($maxhour <= $minhour) { $maxhour = $minhour + 1; }
1225 
1226  $i = 0;
1227  $j = 0;
1228  while ($i < 24)
1229  {
1230  echo ' <div class="tagtr calendarviewcontainertr">'."\n";
1231  echo ' <div class="tagtd width100 tdtop">'.dol_print_date($i*3600, 'hour', 'gmt').'</div>';
1232  echo ' <div class="tagtd '.$style.' tdtop">';
1233  echo " </div>\n";
1234  echo " </div>\n";
1235  $i++;
1236  $j++;
1237  }
1238 
1239  echo '</div></div>';
1240 
1241  show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, 1);
1242 
1243  print '</div>';
1244  }
1245  else
1246  {
1247  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
1248 
1249  show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, 0);
1250 
1251  print '</div>';
1252  }
1253 }
1254 
1255 print "\n".'</form>';
1256 
1257 // End of page
1258 llxFooter();
1259 $db->close();
1260 
1261 
1280 function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventarray, $maxprint=0, $maxnbofchar=16, $newparam='', $showinfo=0, $minheight=60, $nonew=0)
1281 {
1282  global $user, $conf, $langs;
1283  global $action, $filter, $filtert, $status, $actioncode, $usergroup; // Filters used into search form
1284  global $theme_datacolor;
1285  global $cachethirdparties, $cachecontacts, $cacheusers, $colorindexused;
1286 
1287  $dateint = sprintf("%04d",$year).sprintf("%02d",$month).sprintf("%02d",$day);
1288 
1289  print "\n";
1290 
1291  // Line with title of day
1292  $curtime = dol_mktime(0, 0, 0, $month, $day, $year);
1293  print '<div id="dayevent_'.$dateint.'" class="dayevent tagtable centpercent nobordernopadding">'."\n";
1294 
1295  if ($nonew <= 0)
1296  {
1297  print '<div class="tagtr"><div class="nowrap float">';
1298  print '<a style="color: #666" href="'.DOL_URL_ROOT.'/comm/action/index.php?';
1299  print 'action=show_day&day='.str_pad($day, 2, "0", STR_PAD_LEFT).'&month='.str_pad($month, 2, "0", STR_PAD_LEFT).'&year='.$year;
1300  print $newparam;
1301  print '">';
1302  if ($showinfo) print dol_print_date($curtime,'daytextshort');
1303  else print dol_print_date($curtime,'%d');
1304  print '</a>';
1305  print '</div><div class="floatright nowrap">';
1306  if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create)
1307  {
1308  $newparam.='&month='.str_pad($month, 2, "0", STR_PAD_LEFT).'&year='.$year;
1309 
1310  //$param='month='.$monthshown.'&year='.$year;
1311  $hourminsec='100000';
1312  print '<a href="'.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:'')).'">';
1313  print img_picto($langs->trans("NewAction"),'edit_add.png');
1314  print '</a>';
1315  }
1316  print '</div></div>'."\n";
1317  }
1318 
1319  if ($nonew < 0)
1320  {
1321  print '</div>';
1322  return;
1323  }
1324 
1325  // Line with td contains all div of each events
1326  print '<div class="tagtr">';
1327  print '<div class="tagtd centpercent agendacell sortable">';
1328 
1329  //$curtime = dol_mktime (0, 0, 0, $month, $day, $year);
1330  $i=0; $numother=0; $numbirthday=0; $numical=0; $numicals=array();
1331  $ymd=sprintf("%04d",$year).sprintf("%02d",$month).sprintf("%02d",$day);
1332 
1333  $colorindexused[$user->id] = 0; // Color index for current user (user->id) is always 0
1334  $nextindextouse=is_array($colorindexused)?count($colorindexused):0; // At first run this is 0, so fist user has 0, next 1, ...
1335  //var_dump($colorindexused);
1336 
1337  foreach ($eventarray as $daykey => $notused)
1338  {
1339  $annee = date('Y',$daykey);
1340  $mois = date('m',$daykey);
1341  $jour = date('d',$daykey);
1342  if ($day==$jour && $month==$mois && $year==$annee)
1343  {
1344  foreach ($eventarray[$daykey] as $index => $event)
1345  {
1346  if ($i < $maxprint || $maxprint == 0 || ! empty($conf->global->MAIN_JS_SWITCH_AGENDA))
1347  {
1348  $keysofuserassigned=array_keys($event->userassigned);
1349  $ponct=($event->date_start_in_calendar == $event->date_end_in_calendar);
1350 
1351  // Define $color (Hex string like '0088FF') and $cssclass of event
1352  $color=-1; $cssclass=''; $colorindex=-1;
1353  if (in_array($user->id, $keysofuserassigned))
1354  {
1355  $cssclass='family_mytasks';
1356 
1357  if (empty($cacheusers[$event->userownerid]))
1358  {
1359  $newuser=new User($db);
1360  $newuser->fetch($event->userownerid);
1361  $cacheusers[$event->userownerid]=$newuser;
1362  }
1363  //var_dump($cacheusers[$event->userownerid]->color);
1364 
1365  // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
1366  if (! empty($cacheusers[$event->userownerid]->color)) $color=$cacheusers[$event->userownerid]->color;
1367  }
1368  else if ($event->type_code == 'ICALEVENT') // Event come from external ical file
1369  {
1370  $numical++;
1371  if (! empty($event->icalname)) {
1372  if (! isset($numicals[dol_string_nospecial($event->icalname)])) {
1373  $numicals[dol_string_nospecial($event->icalname)] = 0;
1374  }
1375  $numicals[dol_string_nospecial($event->icalname)]++;
1376  }
1377 
1378  $color=($event->icalcolor?$event->icalcolor:-1);
1379  $cssclass=(! empty($event->icalname)?'family_ext'.md5($event->icalname):'family_other');
1380  }
1381  else if ($event->type_code == 'BIRTHDAY')
1382  {
1383  $numbirthday++; $colorindex=2; $cssclass='family_birthday unmovable'; $color=sprintf("%02x%02x%02x",$theme_datacolor[$colorindex][0],$theme_datacolor[$colorindex][1],$theme_datacolor[$colorindex][2]);
1384  }
1385  else
1386  {
1387  $numother++;
1388  $color=($event->icalcolor?$event->icalcolor:-1);
1389  $cssclass=(! empty($event->icalname)?'family_ext'.md5($event->icalname):'family_other');
1390 
1391  if (empty($cacheusers[$event->userownerid]))
1392  {
1393  $newuser=new User($db);
1394  $newuser->fetch($event->userownerid);
1395  $cacheusers[$event->userownerid]=$newuser;
1396  }
1397  //var_dump($cacheusers[$event->userownerid]->color);
1398 
1399  // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
1400  if (! empty($cacheusers[$event->userownerid]->color)) $color=$cacheusers[$event->userownerid]->color;
1401  }
1402 
1403  if ($color < 0) // Color was not set on user card. Set color according to color index.
1404  {
1405  // Define color index if not yet defined
1406  $idusertouse=($event->userownerid?$event->userownerid:0);
1407  if (isset($colorindexused[$idusertouse]))
1408  {
1409  $colorindex=$colorindexused[$idusertouse]; // Color already assigned to this user
1410  }
1411  else
1412  {
1413  $colorindex=$nextindextouse;
1414  $colorindexused[$idusertouse]=$colorindex;
1415  if (! empty($theme_datacolor[$nextindextouse+1])) $nextindextouse++; // Prepare to use next color
1416  }
1417  //print '|'.($color).'='.($idusertouse?$idusertouse:0).'='.$colorindex.'<br>';
1418  // Define color
1419  $color=sprintf("%02x%02x%02x",$theme_datacolor[$colorindex][0],$theme_datacolor[$colorindex][1],$theme_datacolor[$colorindex][2]);
1420  }
1421  $cssclass=$cssclass.' '.$cssclass.'_day_'.$ymd;
1422 
1423  // Defined style to disable drag and drop feature
1424  if ($event->type_code =='AC_OTH_AUTO')
1425  {
1426  $cssclass.= " unmovable";
1427  }
1428  else if ($event->type_code == 'ICALEVENT')
1429  {
1430  $cssclass.= " unmovable";
1431  }
1432  else if ($event->date_end_in_calendar && date('Ymd',$event->date_start_in_calendar) != date('Ymd',$event->date_end_in_calendar))
1433  {
1434  $tmpyearend = date('Y',$event->date_end_in_calendar);
1435  $tmpmonthend = date('m',$event->date_end_in_calendar);
1436  $tmpdayend = date('d',$event->date_end_in_calendar);
1437  if ($tmpyearend == $annee && $tmpmonthend == $mois && $tmpdayend == $jour)
1438  {
1439  $cssclass.= " unmovable";
1440  }
1441  }
1442  else{
1443  if ($user->rights->agenda->allactions->create ||
1444  (($event->authorid == $user->id || $event->userownerid == $user->id) && $user->rights->agenda->myactions->create))
1445  {
1446  $cssclass.= " movable cursormove";
1447  }else{
1448  $cssclass.= " unmovable";
1449  }
1450  }
1451 
1452  $h=''; $nowrapontd=1;
1453  if ($action == 'show_day') { $h='height: 100%; '; $nowrapontd=0; }
1454  if ($action == 'show_week') { $h='height: 100%; '; $nowrapontd=0; }
1455 
1456  // Show rect of event
1457  print "\n";
1458  print '<!-- start event '.$i.' -->'."\n";
1459  print '<div id="event_'.$ymd.'_'.$i.'" class="event '.$cssclass.'"';
1460  //print ' style="height: 100px;';
1461  //print ' position: absolute; top: 40px; width: 50%;';
1462  //print '"';
1463  print '>';
1464 
1465  //var_dump($event->userassigned);
1466  //var_dump($event->transparency);
1467  print '<table class="centpercent cal_event'.(empty($event->transparency)?' cal_event_notbusy':' cal_event_busy').'" style="'.$h;
1468  if (empty($event->transparency) && empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY))
1469  {
1470  print 'border: 2px solid #'.$color.';';
1471  }
1472  else
1473  {
1474  print 'background: #'.$color.';';
1475  print 'background: -webkit-gradient(linear, left top, left bottom, from(#'.dol_color_minus($color, -3).'), to(#'.dol_color_minus($color, -1).'));';
1476  }
1477  //if (! empty($event->transparency)) print 'background: #'.$color.'; background: -webkit-gradient(linear, left top, left bottom, from(#'.$color.'), to(#'.dol_color_minus($color,1).'));';
1478  //else print 'background-color: transparent !important; background: none; border: 1px solid #bbb;';
1479  //print ' -moz-border-radius:4px;"';
1480  //print 'border: 1px solid #ccc" width="100%"';
1481  print '">';
1482  print '<tr>';
1483  print '<td class="tdoverflow nobottom centpercent '.($nowrapontd?'nowrap ':'').'cal_event'.($event->type_code == 'BIRTHDAY'?' cal_event_birthday':'').'">';
1484 
1485  $daterange='';
1486 
1487  if ($event->type_code == 'BIRTHDAY') // It's a birthday
1488  {
1489  print $event->getNomUrl(1,$maxnbofchar,'cal_event','birthday','contact');
1490  }
1491  if ($event->type_code != 'BIRTHDAY')
1492  {
1493  // Picto
1494  if (empty($event->fulldayevent))
1495  {
1496  //print $event->getNomUrl(2).' ';
1497  }
1498 
1499  // Date
1500  if (empty($event->fulldayevent))
1501  {
1502  // Show hours (start ... end)
1503  $tmpyearstart = date('Y',$event->date_start_in_calendar);
1504  $tmpmonthstart = date('m',$event->date_start_in_calendar);
1505  $tmpdaystart = date('d',$event->date_start_in_calendar);
1506  $tmpyearend = date('Y',$event->date_end_in_calendar);
1507  $tmpmonthend = date('m',$event->date_end_in_calendar);
1508  $tmpdayend = date('d',$event->date_end_in_calendar);
1509  // Hour start
1510  if ($tmpyearstart == $annee && $tmpmonthstart == $mois && $tmpdaystart == $jour)
1511  {
1512  $daterange.=dol_print_date($event->date_start_in_calendar,'%H:%M'); // Il faudrait utiliser ici tzuser, mais si on ne peut pas car qd on rentre un date dans fiche action, en input la conversion local->gmt se base sur le TZ server et non user
1513  if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar)
1514  {
1515  if ($tmpyearstart == $tmpyearend && $tmpmonthstart == $tmpmonthend && $tmpdaystart == $tmpdayend)
1516  $daterange.='-';
1517  //else
1518  //print '...';
1519  }
1520  }
1521  if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar)
1522  {
1523  if ($tmpyearstart != $tmpyearend || $tmpmonthstart != $tmpmonthend || $tmpdaystart != $tmpdayend)
1524  {
1525  $daterange.='...';
1526  }
1527  }
1528  // Hour end
1529  if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar)
1530  {
1531  if ($tmpyearend == $annee && $tmpmonthend == $mois && $tmpdayend == $jour)
1532  $daterange.=dol_print_date($event->date_end_in_calendar,'%H:%M'); // Il faudrait utiliser ici tzuser, mais si on ne peut pas car qd on rentre un date dans fiche action, en input la conversion local->gmt se base sur le TZ server et non user
1533  }
1534  }
1535  else
1536  {
1537  if ($showinfo)
1538  {
1539  print $langs->trans("EventOnFullDay")."<br>\n";
1540  }
1541  }
1542 
1543  // Show title
1544  $titletoshow = $daterange;
1545  $titletoshow.=($titletoshow?' ':'').$event->libelle;
1546 
1547  if ($event->type_code == 'ICALEVENT') print $titletoshow;
1548  else
1549  {
1550  $savlabel=$event->label?$event->label:$event->libelle;
1551  $event->label=$titletoshow;
1552  $event->libelle=$titletoshow;
1553  print $event->getNomUrl(0,$maxnbofchar,'cal_event','',0,1);
1554  $event->label=$savlabel;
1555  $event->libelle=$savlabel;
1556  }
1557 
1558  // Loop on each assigned user
1559  $listofusertoshow='';
1560  $posuserassigned=0;
1561  foreach($event->userassigned as $tmpid => $tmpdata)
1562  {
1563  if (! $posuserassigned && $titletoshow) $listofusertoshow.='<br>';
1564  $posuserassigned++;
1565  if (empty($cacheusers[$tmpid]))
1566  {
1567  $newuser=new User($db);
1568  $newuser->fetch($tmpid);
1569  $cacheusers[$tmpid]=$newuser;
1570  }
1571 
1572  $listofusertoshow.=$cacheusers[$tmpid]->getNomUrl(-3, '', 0, 0, 0, 0, '', 'paddingright valigntextbottom');
1573  }
1574  print $listofusertoshow;
1575 
1576  if ($event->type_code == 'ICALEVENT') print '<br>('.dol_trunc($event->icalname,$maxnbofchar).')';
1577 
1578  // If action related to company / contact
1579  $linerelatedto='';
1580  if (! empty($event->societe->id) && $event->societe->id > 0)
1581  {
1582  if (! isset($cachethirdparties[$event->societe->id]) || ! is_object($cachethirdparties[$event->societe->id]))
1583  {
1584  $thirdparty=new Societe($db);
1585  $thirdparty->fetch($event->societe->id);
1586  $cachethirdparties[$event->societe->id]=$thirdparty;
1587  }
1588  else $thirdparty=$cachethirdparties[$event->societe->id];
1589  if (! empty($thirdparty->id)) $linerelatedto.=$thirdparty->getNomUrl(1,'',0);
1590  }
1591  if (! empty($event->contact->id) && $event->contact->id > 0)
1592  {
1593  if (! is_object($cachecontacts[$event->contact->id]))
1594  {
1595  $contact=new Contact($db);
1596  $contact->fetch($event->contact->id);
1597  $cachecontacts[$event->contact->id]=$contact;
1598  }
1599  else $contact=$cachecontacts[$event->contact->id];
1600  if ($linerelatedto) $linerelatedto.='&nbsp;';
1601  if (! empty($contact->id)) $linerelatedto.=$contact->getNomUrl(1,'',0);
1602  }
1603  if (! empty($event->fk_element) && $event->fk_element > 0 && ! empty($event->elementtype) && ! empty($conf->global->AGENDA_SHOW_LINKED_OBJECT))
1604  {
1605  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
1606  if ($linerelatedto) $linerelatedto.='<br>';
1607  $linerelatedto.=dolGetElementUrl($event->fk_element,$event->elementtype,1);
1608  }
1609  if ($linerelatedto) print '<br>'.$linerelatedto;
1610  }
1611 
1612  // Show location
1613  if ($showinfo)
1614  {
1615  if ($event->location)
1616  {
1617  print '<br>';
1618  print $langs->trans("Location").': '.$event->location;
1619  }
1620  }
1621 
1622  print '</td>';
1623  // Status - Percent
1624  $withstatus=0;
1625  if ($event->type_code != 'BIRTHDAY' && $event->type_code != 'ICALEVENT')
1626  {
1627  $withstatus=1;
1628  if ($event->percentage >= 0) $withstatus=2;
1629  }
1630  print '<td class="nobottom right nowrap cal_event_right'.($withstatus >= 2 ?' cal_event_right_status':'').'">';
1631  if ($withstatus) print $event->getLibStatut(3,1);
1632  else print '&nbsp;';
1633  print '</td></tr></table>';
1634  print '</div><!-- end event '.$i.' -->'."\n";
1635  $i++;
1636  }
1637  else
1638  {
1639  print '<a href="'.DOL_URL_ROOT.'/comm/action/index.php?action='.$action.'&maxprint=0&month='.$monthshown.'&year='.$year;
1640  print ($status?'&status='.$status:'').($filter?'&filter='.$filter:'');
1641  print ($filtert?'&filtert='.$filtert:'');
1642  print ($usergroup?'&usergroup='.$usergroup:'');
1643  print ($actioncode!=''?'&actioncode='.$actioncode:'');
1644  print '">'.img_picto("all","1downarrow_selected.png").' ...';
1645  print ' +'.(count($eventarray[$daykey])-$maxprint);
1646  print '</a>';
1647  break;
1648  //$ok=false; // To avoid to show twice the link
1649  }
1650  }
1651 
1652  break;
1653  }
1654  }
1655  if (! $i) print '&nbsp;';
1656 
1657  if (! empty($conf->global->MAIN_JS_SWITCH_AGENDA) && $i > $maxprint && $maxprint)
1658  {
1659  print '<div id="more_'.$ymd.'">'.img_picto("all","1downarrow_selected.png").' +'.$langs->trans("More").'...</div>';
1660  //print ' +'.(count($eventarray[$daykey])-$maxprint);
1661  print '<script type="text/javascript">'."\n";
1662  print 'jQuery(document).ready(function () {'."\n";
1663  print 'jQuery("#more_'.$ymd.'").click(function() { reinit_day_'.$ymd.'(); });'."\n";
1664 
1665  print 'function reinit_day_'.$ymd.'() {'."\n";
1666  print 'var nb=0;'."\n";
1667  // TODO Loop on each element of day $ymd and start to toggle once $maxprint has been reached
1668  print 'jQuery(".family_mytasks_day_'.$ymd.'").toggle();';
1669  print '}'."\n";
1670 
1671  print '});'."\n";
1672 
1673  print '</script>'."\n";
1674  }
1675 
1676  print '</div></div>'; // td tr
1677 
1678  print '</div>'; // table
1679  print "\n";
1680 }
1681 
1682 
1691 function dol_color_minus($color, $minus, $minusunit = 16)
1692 {
1693  $newcolor=$color;
1694  if ($minusunit == 16)
1695  {
1696  $newcolor[0]=dechex(max(min(hexdec($newcolor[0])-$minus, 15), 0));
1697  $newcolor[2]=dechex(max(min(hexdec($newcolor[2])-$minus, 15), 0));
1698  $newcolor[4]=dechex(max(min(hexdec($newcolor[4])-$minus, 15), 0));
1699  }
1700  else
1701  {
1702  // Not yet implemented
1703  }
1704  return $newcolor;
1705 }
llxFooter()
Footer empty.
Definition: index.php:44
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->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) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
dol_get_prev_month($month, $year)
Return previous month.
Definition: date.lib.php:371
Class to manage agenda events (actions)
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Class to manage contact/addresses.
dol_get_first_day_week($day, $month, $year, $gm=false)
Return first day of week for a date.
Definition: date.lib.php:495
calendars_prepare_head($param)
Define head array for tabs of agenda setup pages.
Definition: agenda.lib.php:510
Class to manage Dolibarr users.
Definition: user.class.php:41
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
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:295
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
dol_get_prev_day($day, $month, $year)
Return previous day.
Definition: date.lib.php:342
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
if(! GETPOST('transkey', 'alphanohtml') &&! GETPOST('transphrase', 'alphanohtml')) else
View.
Definition: notice.php:43
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
dol_get_next_week($day, $week, $month, $year)
Return next week.
Definition: date.lib.php:433
Class to manage generation of HTML components Only common components must be here.
Class to read/parse ICal calendars.
Definition: ical.class.php:32
GETPOSTISSET($paramname)
Return true if we are in a context of submitting a parameter.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
type
Definition: viewcat.php:284
Class to manage third parties objects (customers, suppliers, prospects...)
llxHeader()
Header empty.
Definition: index.php:36
dol_get_next_month($month, $year)
Return next month.
Definition: date.lib.php:392
dol_fiche_end($notab=0)
Show tab footer of a card.
dol_get_next_day($day, $month, $year)
Return next day.
Definition: date.lib.php:357
if(GETPOST('cancel', 'alpha')) if(! GETPOST( 'confirmmassaction', 'alpha') &&$massaction !='presend' &&$massaction !='confirm_presend')
Draft customers invoices.
Definition: list.php:156
dol_now($mode='gmt')
Return date for now.
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dolGetElementUrl($objectid, $objecttype, $withpicto=0, $option='')
Return link url to an object.
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.
dol_getdate($timestamp, $fast=false)
Return an array with locale date info.
dol_time_plus_duree($time, $duration_value, $duration_unit)
Add a delay to a date.
Definition: date.lib.php:116
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it&#39;s its name (generic function)
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='')
Clean a string from all punctuation characters to use it as a ref or login.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.