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