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