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