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