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