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