dolibarr 21.0.3
list.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-2016 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2017 Open-DSI <support@open-dsi.fr>
7 * Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2020 Tobias Sekan <tobias.sekan@startmail.com>
9 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
10 * Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 */
25
32// Load Dolibarr environment
33require '../../main.inc.php';
34require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
35require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
39
40include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
41
50// Load translation files required by the page
51$langs->loadLangs(array("users", "companies", "agenda", "commercial", "other", "orders", "bills"));
52
53// Get Parameters
54$action = GETPOST('action', 'aZ09');
55$massaction = GETPOST('massaction', 'alpha');
56$confirm = GETPOST('confirm', 'alpha');
57$cancel = GETPOST('cancel', 'alpha');
58$toselect = GETPOST('toselect', 'array');
59$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'actioncommlist'; // To manage different context of search
60$optioncss = GETPOST('optioncss', 'alpha');
61
62
63$disabledefaultvalues = GETPOSTINT('disabledefaultvalues');
64
65$mode = GETPOST('mode', 'aZ09');
66if (empty($mode) && preg_match('/show_/', $action)) {
67 $mode = $action; // For backward compatibility
68}
69$resourceid = GETPOSTINT("search_resourceid") ? GETPOSTINT("search_resourceid") : GETPOSTINT("resourceid");
70$pid = GETPOSTINT("search_projectid", 3) ? GETPOSTINT("search_projectid", 3) : GETPOSTINT("projectid", 3);
71$search_status = (GETPOST("search_status", 'aZ09') != '') ? GETPOST("search_status", 'aZ09') : GETPOST("status", 'aZ09');
72$type = GETPOST('search_type', 'alphanohtml') ? GETPOST('search_type', 'alphanohtml') : GETPOST('type', 'alphanohtml');
73$year = GETPOSTINT("year");
74$month = GETPOSTINT("month");
75$day = GETPOSTINT("day");
76
77// Set actioncode (this code must be same for setting actioncode into peruser, listacton and index)
78if (GETPOST('search_actioncode', 'array')) {
79 $actioncode = GETPOST('search_actioncode', 'array', 3);
80 if (!count($actioncode)) {
81 $actioncode = '0';
82 }
83} else {
84 $actioncode = GETPOST("search_actioncode", "alpha", 3) ? GETPOST("search_actioncode", "alpha", 3) : (GETPOST("search_actioncode") == '0' ? '0' : ((!getDolGlobalString('AGENDA_DEFAULT_FILTER_TYPE') || $disabledefaultvalues) ? '' : getDolGlobalString('AGENDA_DEFAULT_FILTER_TYPE')));
85}
86
87// Search Fields
88$search_id = GETPOST('search_id', 'alpha');
89$search_title = GETPOST('search_title', 'alpha');
90$search_note = GETPOST('search_note', 'alpha');
91
92// $dateselect is a day included inside the event range
93$dateselect = dol_mktime(0, 0, 0, GETPOSTINT('dateselectmonth'), GETPOSTINT('dateselectday'), GETPOSTINT('dateselectyear'), 'tzuserrel');
94$datestart_dtstart = dol_mktime(0, 0, 0, GETPOSTINT('datestart_dtstartmonth'), GETPOSTINT('datestart_dtstartday'), GETPOSTINT('datestart_dtstartyear'), 'tzuserrel');
95$datestart_dtend = dol_mktime(23, 59, 59, GETPOSTINT('datestart_dtendmonth'), GETPOSTINT('datestart_dtendday'), GETPOSTINT('datestart_dtendyear'), 'tzuserrel');
96$dateend_dtstart = dol_mktime(0, 0, 0, GETPOSTINT('dateend_dtstartmonth'), GETPOSTINT('dateend_dtstartday'), GETPOSTINT('dateend_dtstartyear'), 'tzuserrel');
97$dateend_dtend = dol_mktime(23, 59, 59, GETPOSTINT('dateend_dtendmonth'), GETPOSTINT('dateend_dtendday'), GETPOSTINT('dateend_dtendyear'), 'tzuserrel');
98if ($search_status == '' && !GETPOSTISSET('search_status')) {
99 $search_status = ((!getDolGlobalString('AGENDA_DEFAULT_FILTER_STATUS') || $disabledefaultvalues) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_STATUS);
100}
101if (empty($mode) && !GETPOSTISSET('mode')) {
102 $mode = getDolGlobalString('AGENDA_DEFAULT_VIEW', 'show_list');
103}
104
105$filter = GETPOST("search_filter", 'alpha', 3) ? GETPOST("search_filter", 'alpha', 3) : GETPOST("filter", 'alpha', 3);
106$filtert = GETPOST("search_filtert", "intcomma", 3) ? GETPOST("search_filtert", "intcomma", 3) : GETPOST("filtert", "intcomma", 3);
107$usergroup = GETPOSTINT("search_usergroup", 3) ? GETPOSTINT("search_usergroup", 3) : GETPOSTINT("usergroup", 3);
108$showbirthday = empty($conf->use_javascript_ajax) ? (GETPOSTINT("search_showbirthday") ? GETPOSTINT("search_showbirthday") : GETPOSTINT("showbirthday")) : 1;
109$search_categ_cus = GETPOST("search_categ_cus", "intcomma", 3) ? GETPOST("search_categ_cus", "intcomma", 3) : 0;
110
111// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
112$object = new ActionComm($db);
113$hookmanager->initHooks(array('agendalist'));
114
115$extrafields = new ExtraFields($db);
116
117// fetch optionals attributes and labels
118$extrafields->fetch_name_optionals_label($object->table_element);
119
120$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
121// If not choice done on calendar owner, we filter on user.
122if (empty($filtert) && !getDolGlobalString('AGENDA_ALL_CALENDARS')) {
123 $filtert = $user->id;
124}
125
126// Pagination parameters
127$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
128$sortfield = GETPOST('sortfield', 'aZ09comma');
129$sortorder = GETPOST('sortorder', 'aZ09comma');
130$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
131if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
132 // If $page is not defined, or '' or -1 or if we click on clear filters
133 $page = 0;
134}
135$offset = $limit * $page;
136if (!$sortorder) {
137 $sortorder = "DESC,DESC";
138 if ($search_status == 'todo') {
139 $sortorder = "DESC,DESC";
140 }
141}
142if (!$sortfield) {
143 $sortfield = "a.datep,a.id";
144 if ($search_status == 'todo') {
145 $sortfield = "a.datep,a.id";
146 }
147}
148
149// Security check
150$socid = GETPOSTINT("search_socid") ? GETPOSTINT("search_socid") : GETPOSTINT("socid");
151if ($user->socid) {
152 $socid = $user->socid;
153}
154if ($socid < 0) {
155 $socid = '';
156}
157
158$canedit = 1;
159if (!$user->hasRight('agenda', 'myactions', 'read')) {
161}
162if (!$user->hasRight('agenda', 'allactions', 'read')) {
163 $canedit = 0;
164}
165if (!$user->hasRight('agenda', 'allactions', 'read') || $filter == 'mine') { // If no permission to see all, we show only affected to me
166 $filtert = $user->id;
167}
168
169$arrayfields = array(
170 'a.id' => array('label' => "Ref", 'checked' => 1),
171 'owner' => array('label' => "Owner", 'checked' => 1),
172 'c.libelle' => array('label' => "Type", 'checked' => 1),
173 'a.label' => array('label' => "Title", 'checked' => 1),
174 'a.note' => array('label' => 'Description', 'checked' => 0),
175 'a.datep' => array('label' => "DateStart", 'checked' => 1),
176 'a.datep2' => array('label' => "DateEnd", 'checked' => 1),
177 's.nom' => array('label' => "ThirdParty", 'checked' => 1),
178 'a.fk_contact' => array('label' => "Contact", 'checked' => 0),
179 'a.fk_element' => array('label' => "LinkedObject", 'checked' => 1, 'enabled' => (getDolGlobalString('AGENDA_SHOW_LINKED_OBJECT'))),
180 'a.datec' => array('label' => 'DateCreation', 'checked' => 0, 'position' => 510),
181 'a.tms' => array('label' => 'DateModification', 'checked' => 0, 'position' => 520),
182 'a.percent' => array('label' => "Status", 'checked' => 1, 'position' => 1000)
183);
184// Extra fields
185include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
186
187$object->fields = dol_sort_array($object->fields, 'position');
188$arrayfields = dol_sort_array($arrayfields, 'position');
189'@phan-var-force array<string,array{label:string,checked?:int<0,1>,position?:int,help?:string}> $arrayfields'; // dol_sort_array looses type for Phan
190
191$result = restrictedArea($user, 'agenda', 0, '', 'myactions');
192if ($user->socid && $socid) {
193 $result = restrictedArea($user, 'societe', $socid);
194}
195
196
197/*
198 * Actions
199 */
200
201if (GETPOST('cancel', 'alpha')) {
202 $mode = 'show_list';
203 $massaction = '';
204}
205
206if (GETPOST("viewcal") || GETPOST("viewweek") || GETPOST("viewday")) {
207 $param = '';
208 if (is_array($_POST)) {
209 foreach ($_POST as $key => $val) {
210 $param .= '&'.$key.'='.urlencode($val);
211 }
212 }
213 //print $param;
214 header("Location: ".DOL_URL_ROOT.'/comm/action/index.php?'.$param);
215 exit;
216}
217
218$parameters = array('id' => $socid);
219$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
220if ($reshook < 0) {
221 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
222}
223
224// Selection of new fields
225include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
226// Purge search criteria
227if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
228 //$actioncode='';
229 $search_id = '';
230 $search_title = '';
231 $search_note = '';
232 $datestart_dtstart = '';
233 $datestart_dtend = '';
234 $dateend_dtstart = '';
235 $dateend_dtend = '';
236 $actioncode = '';
237 $search_status = '';
238 $pid = '';
239 $socid = '';
240 $resourceid = '';
241 $filter = '';
242 $filtert = '';
243 $usergroup = '';
244 $toselect = array();
245 $search_array_options = array();
246}
247
248if (empty($reshook) && !empty($massaction)) {
249 unset($percent);
250
251 switch ($massaction) {
252 case 'set_all_events_to_todo':
253 $percent = ActionComm::EVENT_TODO;
254 break;
255
256 case 'set_all_events_to_in_progress':
258 break;
259
260 case 'set_all_events_to_finished':
262 break;
263 }
264
265 if (isset($percent)) {
266 foreach ($toselect as $toselectid) {
267 $result = $object->updatePercent($toselectid, $percent);
268 if ($result < 0) {
269 dol_print_error($db);
270 break;
271 }
272 }
273 }
274}
275
276// As mass deletion happens with a confirm step, $massaction is not use for the final step (deletion).
277if (empty($reshook)) {
278 $objectclass = 'ActionComm';
279 $objectlabel = 'Events';
280 $uploaddir = true;
281 // Only users that can delete any event can remove records.
282 $permissiontodelete = $user->hasRight('agenda', 'allactions', 'delete');
283 $permissiontoadd = $user->hasRight('agenda', 'myactions', 'create');
284 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
285}
286
287
288/*
289 * View
290 */
291
292$form = new Form($db);
293$userstatic = new User($db);
294$formactions = new FormActions($db);
295
296$actionstatic = new ActionComm($db);
297$societestatic = new Societe($db);
298$contactstatic = new Contact($db);
299
300$nav = '';
301$nav .= $form->selectDate($dateselect, 'dateselect', 0, 0, 1, '', 1, 0);
302$nav .= ' <input type="submit" name="submitdateselect" class="button" value="'.$langs->trans("Refresh").'">';
303
304$now = dol_now();
305
306$help_url = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:M&oacute;dulo_Agenda|DE:Modul_Terminplanung';
307$title = $langs->trans("Agenda");
308llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'bodyforlist');
309
310// Define list of all external calendars
311// $listofextcals = array(); Not used yet in lists
312
313$param = '';
314if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
315 $param .= '&contextpage='.urlencode($contextpage);
316}
317if ($limit > 0 && $limit != $conf->liste_limit) {
318 $param .= '&limit='.((int) $limit);
319}
320if ($actioncode != '') {
321 if (is_array($actioncode)) {
322 foreach ($actioncode as $str_action) {
323 $param .= "&search_actioncode[]=".urlencode($str_action);
324 }
325 } else {
326 $param .= "&search_actioncode=".urlencode($actioncode);
327 }
328}
329if ($resourceid > 0) {
330 $param .= "&search_resourceid=".urlencode((string) ($resourceid));
331}
332if ($search_status != '') {
333 $param .= "&search_status=".urlencode($search_status);
334}
335if ($filter) {
336 $param .= "&search_filter=".urlencode($filter);
337}
338if ($filtert) {
339 $param .= "&search_filtert=".urlencode($filtert);
340}
341if ($usergroup > 0) {
342 $param .= "&search_usergroup=".urlencode((string) ($usergroup));
343}
344if ($socid > 0) {
345 $param .= "&search_socid=".urlencode((string) ($socid));
346}
347if ($showbirthday) {
348 $param .= "&search_showbirthday=1";
349}
350if ($pid) {
351 $param .= "&search_projectid=".urlencode((string) ($pid));
352}
353if ($type) {
354 $param .= "&search_type=".urlencode($type);
355}
356if ($search_id != '') {
357 $param .= '&search_id='.urlencode($search_id);
358}
359if ($search_title != '') {
360 $param .= '&search_title='.urlencode($search_title);
361}
362if ($search_note != '') {
363 $param .= '&search_note='.urlencode($search_note);
364}
365if (GETPOSTINT('datestart_dtstartday')) {
366 $param .= '&datestart_dtstartday='.GETPOSTINT('datestart_dtstartday');
367}
368if (GETPOSTINT('datestart_dtstartmonth')) {
369 $param .= '&datestart_dtstartmonth='.GETPOSTINT('datestart_dtstartmonth');
370}
371if (GETPOSTINT('datestart_dtstartyear')) {
372 $param .= '&datestart_dtstartyear='.GETPOSTINT('datestart_dtstartyear');
373}
374if (GETPOSTINT('datestart_dtendday')) {
375 $param .= '&datestart_dtendday='.GETPOSTINT('datestart_dtendday');
376}
377if (GETPOSTINT('datestart_dtendmonth')) {
378 $param .= '&datestart_dtendmonth='.GETPOSTINT('datestart_dtendmonth');
379}
380if (GETPOSTINT('datestart_dtendyear')) {
381 $param .= '&datestart_dtendyear='.GETPOSTINT('datestart_dtendyear');
382}
383if (GETPOSTINT('dateend_dtstartday')) {
384 $param .= '&dateend_dtstartday='.GETPOSTINT('dateend_dtstartday');
385}
386if (GETPOSTINT('dateend_dtstartmonth')) {
387 $param .= '&dateend_dtstartmonth='.GETPOSTINT('dateend_dtstartmonth');
388}
389if (GETPOSTINT('dateend_dtstartyear')) {
390 $param .= '&dateend_dtstartyear='.GETPOSTINT('dateend_dtstartyear');
391}
392if (GETPOSTINT('dateend_dtendday')) {
393 $param .= '&dateend_dtendday='.GETPOSTINT('dateend_dtendday');
394}
395if (GETPOSTINT('dateend_dtendmonth')) {
396 $param .= '&dateend_dtendmonth='.GETPOSTINT('dateend_dtendmonth');
397}
398if (GETPOSTINT('dateend_dtendyear')) {
399 $param .= '&dateend_dtendyear='.GETPOSTINT('dateend_dtendyear');
400}
401if ($optioncss != '') {
402 $param .= '&optioncss='.urlencode($optioncss);
403}
404if ($search_categ_cus != 0) {
405 $param .= '&search_categ_cus='.urlencode((string) ($search_categ_cus));
406}
407
408// Add $param from extra fields
409include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
410
411$paramnoactionodate = $param;
412
413// List of mass actions available
414$arrayofmassactions = array(
415 'set_all_events_to_todo' => img_picto('', 'circle', 'class="pictofixedwidth font-status1"').$langs->trans("SetAllEventsToTodo"),
416 'set_all_events_to_in_progress' => img_picto('', 'stop-circle', 'class="pictofixedwidth font-status2"').$langs->trans("SetAllEventsToInProgress"),
417 'set_all_events_to_finished' => img_picto('', 'stop-circle', 'class="pictofixedwidth badge-status5"').$langs->trans("SetAllEventsToFinished"),
418);
419if ($user->hasRight('agenda', 'allactions', 'delete')) {
420 $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
421}
422if (isModEnabled('category') && $user->hasRight('agenda', 'myactions', 'create')) {
423 $arrayofmassactions['preaffecttag'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("AffectTag");
424}
425if (GETPOSTINT('nomassaction') || in_array($massaction, array('presend', 'predelete','preaffecttag'))) {
426 $arrayofmassactions = array();
427}
428$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
429
430$sql = "SELECT";
431if ($usergroup > 0) {
432 $sql .= " DISTINCT";
433}
434$sql .= " s.nom as societe, s.rowid as socid, s.client, s.email as socemail,";
435$sql .= " a.id, a.code, a.label, a.note, a.datep as dp, a.datep2 as dp2, a.fulldayevent, a.location,";
436$sql .= " a.fk_user_author, a.fk_user_action,";
437$sql .= " a.fk_contact, a.note, a.percent as percent,";
438$sql .= " a.fk_element, a.elementtype, a.datec, a.tms as datem,";
439$sql .= " c.code as type_code, c.libelle as type_label, c.color as type_color, c.type as type_type, c.picto as type_picto,";
440$sql .= " sp.lastname, sp.firstname, sp.email, sp.phone, sp.address, sp.phone as phone_pro, sp.phone_mobile, sp.phone_perso, sp.fk_pays as country_id";
441
442// Add fields from extrafields
443if (!empty($extrafields->attributes[$object->table_element]['label'])) {
444 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
445 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
446 }
447}
448
449// Add fields from hooks
450$parameters = array();
451$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
452$sql .= $hookmanager->resPrint;
453
454$sqlfields = $sql; // $sql fields to remove for count total
455
456$sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
457$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."actioncomm_extrafields as ef ON (a.id = ef.fk_object)";
458$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid";
459$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON a.fk_contact = sp.rowid";
460$sql .= " INNER JOIN ".MAIN_DB_PREFIX."c_actioncomm as c ON c.id = a.fk_action";
461// We must filter on resource table
462if ($resourceid > 0) {
463 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."element_resources as r ON r.element_type = 'action' AND r.element_id = a.id";
464}
465// We must filter on assignment table
466if ($filtert > 0 || $usergroup > 0) {
467 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."actioncomm_resources as ar ON ar.fk_actioncomm = a.id AND ar.element_type='user'";
468}
469if ($usergroup > 0) {
470 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_user = ar.fk_element";
471}
472
473// Add table from hooks
474$parameters = array();
475$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
476$sql .= $hookmanager->resPrint;
477
478$sql .= " WHERE a.entity IN (".getEntity('agenda').")";
479// Condition on actioncode
480if (!empty($actioncode)) {
481 if (!getDolGlobalString('AGENDA_USE_EVENT_TYPE')) {
482 if ($actioncode == 'AC_NON_AUTO') {
483 $sql .= " AND c.type != 'systemauto'";
484 } elseif ($actioncode == 'AC_ALL_AUTO') {
485 $sql .= " AND c.type = 'systemauto'";
486 } else {
487 if ($actioncode == 'AC_OTH') {
488 $sql .= " AND c.type != 'systemauto'";
489 }
490 if ($actioncode == 'AC_OTH_AUTO') {
491 $sql .= " AND c.type = 'systemauto'";
492 }
493 }
494 } else {
495 if ($actioncode === 'AC_NON_AUTO') {
496 $sql .= " AND c.type != 'systemauto'";
497 } elseif ($actioncode === 'AC_ALL_AUTO') {
498 $sql .= " AND c.type = 'systemauto'";
499 } else {
500 if (is_array($actioncode)) {
501 // Remove all -1 values
502 $actioncode = array_filter(
503 $actioncode,
508 function ($value) {
509 return ((string) $value !== '-1');
510 }
511 );
512 if (count($actioncode)) {
513 $sql .= " AND c.code IN (".$db->sanitize("'".implode("','", $actioncode)."'", 1).")";
514 }
515 } elseif ($actioncode !== '-1') {
516 $sql .= " AND c.code IN (".$db->sanitize("'".implode("','", explode(',', $actioncode))."'", 1).")";
517 }
518 }
519 }
520}
521if ($resourceid > 0) {
522 $sql .= " AND r.resource_id = ".((int) $resourceid);
523}
524if ($pid) {
525 $sql .= " AND a.fk_project=".((int) $pid);
526}
527
528// If the internal user must only see his customers, force searching by him
529$search_sale = 0;
530if (isModEnabled("societe") && !$user->hasRight('societe', 'client', 'voir')) {
531 $search_sale = $user->id;
532}
533// Search on sale representative
534if ($search_sale && $search_sale != '-1') {
535 if ($search_sale == -2) {
536 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = a.fk_soc)";
537 } elseif ($search_sale > 0) {
538 $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).")";
539 }
540}
541// Search on socid
542if ($socid > 0) {
543 $sql .= " AND a.fk_soc = ".((int) $socid);
544}
545if ($type) {
546 $sql .= " AND c.id = ".((int) $type);
547}
548if ($search_status == '0') {
549 $sql .= " AND a.percent = 0";
550}
551if ($search_status == 'na') {
552 $sql .= " AND a.percent = -1";
553} // Not applicable
554if ($search_status == '50') {
555 $sql .= " AND (a.percent > 0 AND a.percent < 100)";
556} // Running already started
557if ($search_status == '100') {
558 $sql .= " AND a.percent = 100";
559}
560if ($search_status == 'done') {
561 $sql .= " AND (a.percent = 100)";
562}
563if ($search_status == 'todo') {
564 $sql .= " AND (a.percent >= 0 AND a.percent < 100)";
565}
566if ($search_id) {
567 $sql .= natural_search("a.id", $search_id, 1);
568}
569if ($search_title) {
570 $sql .= natural_search("a.label", $search_title);
571}
572if ($search_note) {
573 $sql .= natural_search('a.note', $search_note);
574}
575// We must filter on assignment table
576if ($filtert > 0 || $usergroup > 0) {
577 $sql .= " AND (";
578 if ($filtert > 0) {
579 $sql .= "(ar.fk_element = ".((int) $filtert)." OR (ar.fk_element IS NULL AND a.fk_user_action = ".((int) $filtert)."))"; // The OR is for backward compatibility
580 }
581 if ($usergroup > 0) {
582 $sql .= ($filtert > 0 ? " OR " : "")." ugu.fk_usergroup = ".((int) $usergroup);
583 }
584 $sql .= ")";
585}
586
587// The second or of next test is to take event with no end date (we suppose duration is 1 hour in such case)
588if ($dateselect > 0) {
589 $sql .= " AND ((a.datep2 >= '".$db->idate($dateselect)."' AND a.datep <= '".$db->idate($dateselect + 3600 * 24 - 1)."') OR (a.datep2 IS NULL AND a.datep > '".$db->idate($dateselect - 3600)."' AND a.datep <= '".$db->idate($dateselect + 3600 * 24 - 1)."'))";
590}
591if ($datestart_dtstart > 0) {
592 $sql .= " AND a.datep >= '".$db->idate($datestart_dtstart)."'";
593}
594if ($datestart_dtend > 0) {
595 $sql .= " AND a.datep <= '".$db->idate($datestart_dtend)."'";
596}
597if ($dateend_dtstart > 0) {
598 $sql .= " AND a.datep2 >= '".$db->idate($dateend_dtstart)."'";
599}
600if ($dateend_dtend > 0) {
601 $sql .= " AND a.datep2 <= '".$db->idate($dateend_dtend)."'";
602}
603
604// Search in categories, -1 is all and -2 is no categories
605if ($search_categ_cus != -1) {
606 if ($search_categ_cus == -2) {
607 $sql .= " AND NOT EXISTS (SELECT ca.fk_actioncomm FROM ".MAIN_DB_PREFIX."categorie_actioncomm as ca WHERE ca.fk_actioncomm = a.id)";
608 } elseif ($search_categ_cus > 0) {
609 $sql .= " AND EXISTS (SELECT ca.fk_actioncomm FROM ".MAIN_DB_PREFIX."categorie_actioncomm as ca WHERE ca.fk_actioncomm = a.id AND ca.fk_categorie IN (".$db->sanitize($search_categ_cus)."))";
610 }
611}
612
613// Add where from extra fields
614include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
615
616// Add where from hooks
617$parameters = array();
618$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
619$sql .= $hookmanager->resPrint;
620
621// Count total nb of records
622$nbtotalofrecords = '';
623if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
624 /* The fast and low memory method to get and count full list converts the sql into a sql count */
625 $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
626 $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
627
628 $resql = $db->query($sqlforcount);
629 if ($resql) {
630 $objforcount = $db->fetch_object($resql);
631 $nbtotalofrecords = $objforcount->nbtotalofrecords;
632 } else {
633 dol_print_error($db);
634 }
635
636 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
637 $page = 0;
638 $offset = 0;
639 }
640 $db->free($resql);
641}
642
643// Complete request and execute it with limit
644$sql .= $db->order($sortfield, $sortorder);
645if ($limit) {
646 $sql .= $db->plimit($limit + 1, $offset);
647}
648
649$resql = $db->query($sql);
650if (!$resql) {
651 dol_print_error($db);
652 exit;
653}
654
655$num = $db->num_rows($resql);
656
657$arrayofselected = is_array($toselect) ? $toselect : array();
658
659// Local calendar
660$newtitle = '<div class="nowrap clear inline-block minheight30">';
661$newtitle .= '<input type="checkbox" id="check_mytasks" name="check_mytasks" checked disabled> '.$langs->trans("LocalAgenda").' &nbsp; ';
662$newtitle .= '</div>';
663//$newtitle=$langs->trans($title);
664
665$tabactive = 'cardlist';
666
667$head = calendars_prepare_head($param);
668
669print '<form method="POST" id="searchFormList" class="listactionsfilter" action="'.$_SERVER["PHP_SELF"].'">'."\n";
670
671if ($optioncss != '') {
672 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
673}
674print '<input type="hidden" name="token" value="'.newToken().'">';
675print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
676print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
677print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
678print '<input type="hidden" name="type" value="'.$type.'">';
679$nav = '';
680
681if ($filter) {
682 $nav .= '<input type="hidden" name="search_filter" value="'.$filter.'">';
683}
684if ($showbirthday) {
685 $nav .= '<input type="hidden" name="search_showbirthday" value="1">';
686}
687print $nav;
688
689//print dol_get_fiche_head($head, $tabactive, $langs->trans('Agenda'), 0, 'action');
690//print_actions_filter($form, $canedit, $search_status, $year, $month, $day, $showbirthday, '', $filtert, '', $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid);
691//print dol_get_fiche_end();
692
693
694$s = $newtitle;
695
696// Calendars from hooks
697$parameters = array();
698$reshook = $hookmanager->executeHooks('addCalendarChoice', $parameters, $object, $action);
699if (empty($reshook)) {
700 $s .= $hookmanager->resPrint;
701} elseif ($reshook > 1) {
702 $s = $hookmanager->resPrint;
703}
704
705$viewyear = is_object($object) ? dol_print_date($object->datep, '%Y') : '';
706$viewmonth = is_object($object) ? dol_print_date($object->datep, '%m') : '';
707$viewday = is_object($object) ? dol_print_date($object->datep, '%d') : '';
708
709$viewmode = '<div class="navmode inline-block">';
710
711$viewmode .= '<a class="btnTitle'.(($mode == 'list' || $mode == 'show_list') ? ' btnTitleSelected' : '').' btnTitleSelected reposition" href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&restore_lastsearch_values=1'.$paramnoactionodate.'">';
712//$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
713$viewmode .= img_picto($langs->trans("List"), 'object_calendarlist', 'class="imgforviewmode pictoactionview block"');
714//$viewmode .= '</span>';
715$viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone inline-block width75 divoverflow">'.$langs->trans("ViewList").'</span></a>';
716
717$viewmode .= '<a class="btnTitle'.($mode == 'show_month' ? ' btnTitleSelected' : '').' reposition" href="'.DOL_URL_ROOT.'/comm/action/index.php?mode=show_month&year='.$viewyear.'&month='.$viewmonth.'&day='.$viewday.$paramnoactionodate.'">';
718//$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
719$viewmode .= img_picto($langs->trans("ViewCal"), 'object_calendarmonth', 'class="pictoactionview block"');
720//$viewmode .= '</span>';
721$viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone inline-block width75 divoverflow">'.$langs->trans("ViewCal").'</span></a>';
722
723$viewmode .= '<a class="btnTitle'.($mode == 'show_week' ? ' btnTitleSelected' : '').' reposition" href="'.DOL_URL_ROOT.'/comm/action/index.php?mode=show_week&year='.$viewyear.'&month='.$viewmonth.'&day='.$viewday.$paramnoactionodate.'">';
724//$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
725$viewmode .= img_picto($langs->trans("ViewWeek"), 'object_calendarweek', 'class="pictoactionview block"');
726//$viewmode .= '</span>';
727$viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone inline-block width75 divoverflow">'.$langs->trans("ViewWeek").'</span></a>';
728
729$viewmode .= '<a class="btnTitle'.($mode == 'show_day' ? ' btnTitleSelected' : '').' reposition" href="'.DOL_URL_ROOT.'/comm/action/index.php?mode=show_day&year='.$viewyear.'&month='.$viewmonth.'&day='.$viewday.$paramnoactionodate.'">';
730//$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
731$viewmode .= img_picto($langs->trans("ViewDay"), 'object_calendarday', 'class="pictoactionview block"');
732//$viewmode .= '</span>';
733$viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone inline-block width75 divoverflow">'.$langs->trans("ViewDay").'</span></a>';
734
735$viewmode .= '<a class="btnTitle'.($mode == 'show_peruser' ? ' btnTitleSelected' : '').' reposition marginrightonly" href="'.DOL_URL_ROOT.'/comm/action/peruser.php?mode=show_peruser&year='.$viewyear.'&month='.$viewmonth.'&day='.$viewday.$paramnoactionodate.'">';
736//$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
737$viewmode .= img_picto($langs->trans("ViewPerUser"), 'object_calendarperuser', 'class="pictoactionview block"');
738//$viewmode .= '</span>';
739$viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone inline-block width75 divoverflow" title="'.dolPrintHTML($langs->trans("ViewPerUser")).'">'.$langs->trans("ViewPerUser").'</span></a>';
740
741// Add more views from hooks
742$parameters = array();
743$reshook = $hookmanager->executeHooks('addCalendarView', $parameters, $object, $action);
744if (empty($reshook)) {
745 $viewmode .= $hookmanager->resPrint;
746} elseif ($reshook > 1) {
747 $viewmode = $hookmanager->resPrint;
748}
749
750$viewmode .= '</div>';
751
752$viewmode .= '<span class="marginrightonly"></span>';
753
754$tmpforcreatebutton = dol_getdate(dol_now('tzuserrel'), true);
755
756$newparam = '&month='.str_pad((string) $month, 2, "0", STR_PAD_LEFT).'&year='.$tmpforcreatebutton['year'];
757
758$url = DOL_URL_ROOT.'/comm/action/card.php?action=create';
759$url .= '&apyear='.$tmpforcreatebutton['year'].'&apmonth='.$tmpforcreatebutton['mon'].'&apday='.$tmpforcreatebutton['mday'];
760$url .= '&aphour='.$tmpforcreatebutton['hours'].'&apmin='.$tmpforcreatebutton['minutes'];
761$url .= '&backtopage='.urlencode($_SERVER["PHP_SELF"].($newparam ? '?'.$newparam : ''));
762
763$newcardbutton = dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', $url, '', (int) ($user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create')));
764
765$param .= '&mode='.urlencode($mode);
766
767print_barre_liste($langs->trans("Agenda"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, is_numeric($nbtotalofrecords) ? -1 * $nbtotalofrecords : $nbtotalofrecords, 'object_action', 0, $nav.$newcardbutton, '', $limit, 0, 0, 1, $viewmode);
768
769print $s;
770
771$objecttmp = new ActionComm($db);
772include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
773
774$moreforfilter = '';
775
776$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
777$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields
778if ($massactionbutton) {
779 $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
780}
781$i = 0;
782
783print '<div class="liste_titre liste_titre_bydiv centpercent">';
784print_actions_filter($form, $canedit, $search_status, $year, $month, $day, $showbirthday, '', $filtert, '', $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid, $search_categ_cus);
785print '</div>';
786
787$moreforfilter = 1;
788
789print '<div class="div-table-responsive">';
790print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
791
792print '<tr class="liste_titre_filter">';
793// Action column
794if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
795 print '<td class="liste_titre" align="middle">';
796 $searchpicto = $form->showFilterButtons('left');
797 print $searchpicto;
798 print '</td>';
799}
800if (!empty($arrayfields['a.id']['checked'])) {
801 print '<td class="liste_titre"><input type="text" class="maxwidth50" name="search_id" value="'.$search_id.'"></td>';
802}
803if (!empty($arrayfields['owner']['checked'])) {
804 print '<td class="liste_titre"></td>';
805}
806if (!empty($arrayfields['c.libelle']['checked'])) {
807 print '<td class="liste_titre"></td>';
808}
809if (!empty($arrayfields['a.label']['checked'])) {
810 print '<td class="liste_titre"><input type="text" class="maxwidth75" name="search_title" value="'.$search_title.'"></td>';
811}
812if (!empty($arrayfields['a.note']['checked'])) {
813 print '<td class="liste_titre"><input type="text" class="maxwidth75" name="search_note" value="'.$search_note.'"></td>';
814}
815if (!empty($arrayfields['a.datep']['checked'])) {
816 print '<td class="liste_titre nowraponall" align="center">';
817 print '<div class="nowrap">';
818 print $form->selectDate($datestart_dtstart, 'datestart_dtstart', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'), 'tzuserrel');
819 print '</div>';
820 print '<div class="nowrap">';
821 print $form->selectDate($datestart_dtend, 'datestart_dtend', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('To'), 'tzuserrel');
822 print '</div>';
823 print '</td>';
824}
825if (!empty($arrayfields['a.datep2']['checked'])) {
826 print '<td class="liste_titre nowraponall" align="center">';
827 print '<div class="nowrap">';
828 print $form->selectDate($dateend_dtstart, 'dateend_dtstart', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'), 'tzuserrel');
829 print '</div>';
830 print '<div class="nowrap">';
831 print $form->selectDate($dateend_dtend, 'dateend_dtend', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('To'), 'tzuserrel');
832 print '</div>';
833 print '</td>';
834}
835if (!empty($arrayfields['s.nom']['checked'])) {
836 print '<td class="liste_titre"></td>';
837}
838if (!empty($arrayfields['a.fk_contact']['checked'])) {
839 print '<td class="liste_titre"></td>';
840}
841if (!empty($arrayfields['a.fk_element']['checked'])) {
842 print '<td class="liste_titre"></td>';
843}
844
845// Extra fields
846include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
847
848// Fields from hook
849$parameters = array('arrayfields' => $arrayfields);
850$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
851print $hookmanager->resPrint;
852
853if (!empty($arrayfields['a.datec']['checked'])) {
854 print '<td class="liste_titre"></td>';
855}
856if (!empty($arrayfields['a.tms']['checked'])) {
857 print '<td class="liste_titre"></td>';
858}
859if (!empty($arrayfields['a.percent']['checked'])) {
860 print '<td class="liste_titre center parentonrightofpage">';
861 $formactions->form_select_status_action('formaction', $search_status, 1, 'search_status', 1, 2, 'search_status width100 onrightofpage');
862 print '</td>';
863}
864// Action column
865if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
866 print '<td class="liste_titre center">';
867 $searchpicto = $form->showFilterButtons();
868 print $searchpicto;
869 print '</td>';
870}
871print '</tr>'."\n";
872
873$totalarray = array();
874$totalarray['nbfield'] = 0;
875
876// Fields title label
877// --------------------------------------------------------------------
878print '<tr class="liste_titre">';
879if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
880 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
881 $totalarray['nbfield']++;
882}
883if (!empty($arrayfields['a.id']['checked'])) {
884 // @phan-suppress-next-line PhanTypeInvalidDimOffset
885 print_liste_field_titre($arrayfields['a.id']['label'], $_SERVER["PHP_SELF"], "a.id", $param, "", "", $sortfield, $sortorder);
886 $totalarray['nbfield']++;
887}
888if (!empty($arrayfields['owner']['checked'])) {
889 print_liste_field_titre($arrayfields['owner']['label'], $_SERVER["PHP_SELF"], "", $param, "", "", $sortfield, $sortorder);
890 $totalarray['nbfield']++;
891}
892if (!empty($arrayfields['c.libelle']['checked'])) {
893 print_liste_field_titre($arrayfields['c.libelle']['label'], $_SERVER["PHP_SELF"], "c.libelle", $param, "", "", $sortfield, $sortorder);
894 $totalarray['nbfield']++;
895}
896if (!empty($arrayfields['a.label']['checked'])) {
897 print_liste_field_titre($arrayfields['a.label']['label'], $_SERVER["PHP_SELF"], "a.label", $param, "", "", $sortfield, $sortorder);
898 $totalarray['nbfield']++;
899}
900if (!empty($arrayfields['a.note']['checked'])) {
901 print_liste_field_titre($arrayfields['a.note']['label'], $_SERVER["PHP_SELF"], "a.note", $param, "", "", $sortfield, $sortorder);
902 $totalarray['nbfield']++;
903}
904if (!empty($arrayfields['a.datep']['checked'])) {
905 print_liste_field_titre($arrayfields['a.datep']['label'], $_SERVER["PHP_SELF"], "a.datep,a.id", $param, '', '', $sortfield, $sortorder, 'center ');
906 $totalarray['nbfield']++;
907}
908if (!empty($arrayfields['a.datep2']['checked'])) {
909 print_liste_field_titre($arrayfields['a.datep2']['label'], $_SERVER["PHP_SELF"], "a.datep2", $param, '', '', $sortfield, $sortorder, 'center ');
910 $totalarray['nbfield']++;
911}
912if (!empty($arrayfields['s.nom']['checked'])) {
913 print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", $param, "", "", $sortfield, $sortorder);
914 $totalarray['nbfield']++;
915}
916if (!empty($arrayfields['a.fk_contact']['checked'])) {
917 print_liste_field_titre($arrayfields['a.fk_contact']['label'], $_SERVER["PHP_SELF"], "", $param, "", "", $sortfield, $sortorder);
918 $totalarray['nbfield']++;
919}
920if (!empty($arrayfields['a.fk_element']['checked'])) {
921 print_liste_field_titre($arrayfields['a.fk_element']['label'], $_SERVER["PHP_SELF"], "", $param, "", "", $sortfield, $sortorder);
922 $totalarray['nbfield']++;
923}
924// Extra fields
925include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
926// Hook fields
927$parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
928$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
929print $hookmanager->resPrint;
930
931if (!empty($arrayfields['a.datec']['checked'])) {
932 print_liste_field_titre($arrayfields['a.datec']['label'], $_SERVER["PHP_SELF"], "a.datec,a.id", $param, "", '', $sortfield, $sortorder, 'center ');
933 $totalarray['nbfield']++;
934}
935if (!empty($arrayfields['a.tms']['checked'])) {
936 print_liste_field_titre($arrayfields['a.tms']['label'], $_SERVER["PHP_SELF"], "a.tms,a.id", $param, "", '', $sortfield, $sortorder, 'center ');
937 $totalarray['nbfield']++;
938}
939// Status
940if (!empty($arrayfields['a.percent']['checked'])) {
941 print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "a.percent", $param, "", '', $sortfield, $sortorder, 'center ');
942 $totalarray['nbfield']++;
943}
944if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
945 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'maxwidthsearch center ');
946 $totalarray['nbfield']++;
947}
948print "</tr>\n";
949
950$now = dol_now();
951$delay_warning = getDolGlobalInt('MAIN_DELAY_ACTIONS_TODO') * 24 * 60 * 60;
952$today_start_time = dol_mktime(0, 0, 0, (int) date('m', $now), (int) date('d', $now), (int) date('Y', $now));
953
954require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
955$caction = new CActionComm($db);
956$arraylist = $caction->liste_array(1, 'code', '', (!getDolGlobalString('AGENDA_USE_EVENT_TYPE') ? 1 : 0), '', 1);
957$contactListCache = array();
958
959// Loop on record
960// --------------------------------------------------------------------
961$i = 0;
962//$savnbfield = $totalarray['nbfield'];
963//$totalarray['nbfield'] = 0;
964$imaxinloop = ($limit ? min($num, $limit) : $num);
965$cache_user_list = array();
966while ($i < $imaxinloop) {
967 $obj = $db->fetch_object($resql);
968 if (empty($obj)) {
969 break; // Should not happen
970 }
971
972 // Store properties in $object
973 $object->setVarsFromFetchObj($obj);
974
975 // Discard auto action if option is on
976 if (getDolGlobalString('AGENDA_ALWAYS_HIDE_AUTO') && $obj->type_code == 'AC_OTH_AUTO') {
977 $i++;
978 continue;
979 }
980
981 $actionstatic->id = $obj->id;
982 $actionstatic->ref = $obj->id;
983 $actionstatic->code = $obj->code;
984 $actionstatic->type_code = $obj->type_code;
985 $actionstatic->type_label = $obj->type_label;
986 $actionstatic->type_picto = $obj->type_picto;
987 $actionstatic->type_color = $obj->type_color;
988 $actionstatic->label = $obj->label;
989 $actionstatic->location = $obj->location;
990 $actionstatic->note_private = dol_htmlentitiesbr($obj->note);
991 $actionstatic->datep = $db->jdate($obj->dp);
992 $actionstatic->percentage = $obj->percent;
993 $actionstatic->authorid = $obj->fk_user_author;
994 $actionstatic->userownerid = $obj->fk_user_action;
995
996 // Initialize $this->userassigned && this->socpeopleassigned array && this->userownerid
997 // but only if we need it
998 if (!empty($arrayfields['a.fk_contact']['checked'])) {
999 $actionstatic->fetchResources();
1000 }
1001
1002 // cache of user list (owners)
1003 if ($obj->fk_user_action > 0 && !isset($cache_user_list[$obj->fk_user_action])) {
1004 $userstatic = new User($db);
1005 $res = $userstatic->fetch($obj->fk_user_action);
1006 if ($res > 0) {
1007 $cache_user_list[$obj->fk_user_action] = $userstatic;
1008 }
1009 }
1010
1011 // get event style for user owner
1012 $event_owner_style = '';
1013 // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
1014 if ($obj->fk_user_action > 0 && $cache_user_list[$obj->fk_user_action]->color != '') {
1015 $event_owner_style .= 'border-left: #' . $cache_user_list[$obj->fk_user_action]->color . ' 5px solid;';
1016 }
1017
1018 // get event style for start and end date
1019 $event_more_class = '';
1020 $event_start_date_css = '';
1021 $event_end_date_css = '';
1022 $event_start_date_time = $actionstatic->datep;
1023 if ($event_start_date_time > $now) {
1024 // future event
1025 $event_more_class = 'event-future';
1026 $event_start_date_css = $event_end_date_css = $event_more_class;
1027 } else {
1028 if ($obj->fulldayevent == 1) {
1029 $today_start_date_time = $today_start_time;
1030 } else {
1031 $today_start_date_time = $now;
1032 }
1033
1034 // check event end date
1035 $event_end_date_time = $db->jdate($obj->dp2);
1036 if ($event_end_date_time != null && $event_end_date_time < $today_start_date_time) {
1037 // past event
1038 $event_more_class = 'event-past';
1039 } elseif ($event_end_date_time == null && $event_start_date_time < $today_start_date_time) {
1040 // past event
1041 $event_more_class = 'event-past';
1042 } else {
1043 // current event
1044 $event_more_class = 'event-current';
1045 }
1046 $event_start_date_css = $event_end_date_css = $event_more_class;
1047 }
1048 $event_start_date_css = $event_end_date_css = $event_more_class;
1049
1050 print '<tr class="oddeven' . ($event_more_class != '' ? ' '.$event_more_class : '') . '">';
1051 // Action column
1052 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1053 print '<td class="nowrap center">';
1054 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1055 $selected = 0;
1056 if (in_array($obj->id, $arrayofselected)) {
1057 $selected = 1;
1058 }
1059 print '<input id="cb'.$obj->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->id.'"'.($selected ? ' checked="checked"' : '').'>';
1060 }
1061 print '</td>';
1062 }
1063 // Ref
1064 if (!empty($arrayfields['a.id']['checked'])) {
1065 print '<td class="nowraponall">';
1066 print $actionstatic->getNomUrl(1, -1);
1067 print '</td>';
1068 }
1069
1070 // User owner
1071 if (!empty($arrayfields['owner']['checked'])) {
1072 //print '<td class="tdoverflowmax150"' . ($event_owner_style != '' ? ' style="'.$event_owner_style.'"' : '') . '>';
1073 print '<td class="tdoverflowmax150">';
1074 if ($obj->fk_user_action > 0 && !isset($cache_user_list[$obj->fk_user_action])) {
1075 $userstatic = new User($db);
1076 $res = $userstatic->fetch($obj->fk_user_action);
1077 if ($res > 0) {
1078 $cache_user_list[$obj->fk_user_action] = $userstatic;
1079 }
1080 }
1081 if (isset($cache_user_list[$obj->fk_user_action])) {
1082 print $cache_user_list[$obj->fk_user_action]->getNomUrl(-1);
1083 } else {
1084 print '&nbsp;';
1085 }
1086 print '</td>';
1087 }
1088
1089 // Type
1090 if (!empty($arrayfields['c.libelle']['checked'])) {
1091 print '<td class="nowraponall">';
1092 print $actionstatic->getTypePicto();
1093 $labeltype = $obj->type_code;
1094 if (!getDolGlobalString('AGENDA_USE_EVENT_TYPE') && empty($arraylist[$labeltype])) {
1095 $labeltype = 'AC_OTH';
1096 }
1097 if (!empty($actionstatic->code) && preg_match('/^TICKET_MSG/', $actionstatic->code)) {
1098 $labeltype = $langs->trans("Message");
1099 } else {
1100 if (!empty($arraylist[$labeltype])) {
1101 $labeltype = $arraylist[$labeltype];
1102 }
1103 if ($obj->type_code == 'AC_OTH_AUTO' && ($obj->type_code != $obj->code) && $labeltype && !empty($arraylist[$obj->code])) {
1104 $labeltype .= ' - '.$arraylist[$obj->code]; // Use code in priority on type_code
1105 }
1106 }
1107 print dol_trunc($labeltype, 28);
1108 print '</td>';
1109 }
1110
1111 // Label
1112 if (!empty($arrayfields['a.label']['checked'])) {
1113 print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($actionstatic->label).'">';
1114 print $actionstatic->label;
1115 print '</td>';
1116 }
1117
1118 // Description
1119 if (!empty($arrayfields['a.note']['checked'])) {
1120 $text = dolGetFirstLineOfText(dol_string_nohtmltag($actionstatic->note_private, 1));
1121 print '<td class="tdoverflow200" title="'.dol_escape_htmltag($text).'">';
1122 print $form->textwithtooltip(dol_trunc($text, 48), $actionstatic->note_private);
1123 print '</td>';
1124 }
1125
1126 $formatToUse = $obj->fulldayevent ? 'day' : 'dayhour';
1127
1128 // Start date
1129 if (!empty($arrayfields['a.datep']['checked'])) {
1130 print '<td class="center nowraponall'.($event_start_date_css ? ' '.$event_start_date_css : '').'"><span>';
1131 if (empty($obj->fulldayevent)) {
1132 print dol_print_date($db->jdate($obj->dp), $formatToUse, 'tzuserrel');
1133 } else {
1134 $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
1135 print dol_print_date($db->jdate($obj->dp), $formatToUse, ($tzforfullday ? $tzforfullday : 'tzuserrel'));
1136 }
1137 print '</span>';
1138 $late = 0;
1139 if ($actionstatic->hasDelay() && $actionstatic->percentage >= 0 && $actionstatic->percentage < 100) {
1140 $late = 1;
1141 }
1142 if ($late) {
1143 print img_warning($langs->trans("Late")).' ';
1144 }
1145 print '</td>';
1146 }
1147
1148 // End date
1149 if (!empty($arrayfields['a.datep2']['checked'])) {
1150 print '<td class="center nowraponall'.($event_end_date_css ? ' '.$event_end_date_css : '').'"><span>';
1151 if (empty($obj->fulldayevent)) {
1152 print dol_print_date($db->jdate($obj->dp2), $formatToUse, 'tzuserrel');
1153 } else {
1154 $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
1155 print dol_print_date($db->jdate($obj->dp2), $formatToUse, ($tzforfullday ? $tzforfullday : 'tzuserrel'));
1156 }
1157 print '</span>';
1158 print '</td>';
1159 }
1160
1161 // Third party
1162 if (!empty($arrayfields['s.nom']['checked'])) {
1163 print '<td class="tdoverflowmax150">';
1164 if ($obj->socid > 0) {
1165 $societestatic->id = $obj->socid;
1166 $societestatic->client = (int) $obj->client;
1167 $societestatic->name = (string) $obj->societe;
1168 $societestatic->email = $obj->socemail;
1169
1170 print $societestatic->getNomUrl(1, '', 28);
1171 } else {
1172 print '&nbsp;';
1173 }
1174 print '</td>';
1175 }
1176
1177 // Contact
1178 if (!empty($arrayfields['a.fk_contact']['checked'])) {
1179 print '<td class="tdoverflowmax100">';
1180
1181 if (!empty($actionstatic->socpeopleassigned)) {
1182 $contactList = array();
1183 foreach ($actionstatic->socpeopleassigned as $socpeopleassigned) {
1184 if (!isset($contactListCache[$socpeopleassigned['id']])) {
1185 // if no cache found we fetch it
1186 $contact = new Contact($db);
1187 if ($contact->fetch($socpeopleassigned['id']) > 0) {
1188 $contactListCache[$socpeopleassigned['id']] = $contact->getNomUrl(1, '', 0);
1189 $contactList[] = $contact->getNomUrl(1, '', 0);
1190 }
1191 } else {
1192 // use cache
1193 $contactList[] = $contactListCache[$socpeopleassigned['id']];
1194 }
1195 }
1196 if (!empty($contactList)) {
1197 print implode(', ', $contactList);
1198 }
1199 } elseif ($obj->fk_contact > 0) { //keep for retrocompatibility with faraway event
1200 $contactstatic->id = $obj->fk_contact;
1201 $contactstatic->email = $obj->email;
1202 $contactstatic->lastname = $obj->lastname;
1203 $contactstatic->firstname = $obj->firstname;
1204 $contactstatic->phone_pro = $obj->phone_pro;
1205 $contactstatic->phone_mobile = $obj->phone_mobile;
1206 $contactstatic->phone_perso = $obj->phone_perso;
1207 $contactstatic->country_id = $obj->country_id;
1208 print $contactstatic->getNomUrl(1, '', 0);
1209 } else {
1210 print "&nbsp;";
1211 }
1212 print '</td>';
1213 }
1214
1215 // Linked object
1216 if (!empty($arrayfields['a.fk_element']['checked'])) {
1217 print '<td class="tdoverflowmax150">';
1218 //var_dump($obj->fkelement.' '.$obj->elementtype);
1219 if ($obj->fk_element > 0 && !empty($obj->elementtype)) {
1220 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
1221 print dolGetElementUrl($obj->fk_element, $obj->elementtype, 1);
1222 } else {
1223 print "&nbsp;";
1224 }
1225 print '</td>';
1226 }
1227
1228 // Extra fields
1229 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1230 // Fields from hook
1231 $parameters = array('arrayfields' => $arrayfields, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
1232 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
1233 print $hookmanager->resPrint;
1234
1235 // Date creation
1236 if (!empty($arrayfields['a.datec']['checked'])) {
1237 // Status/Percent
1238 print '<td align="center" class="nowrap">'.dol_print_date($db->jdate($obj->datec), 'dayhour', 'tzuserrel').'</td>';
1239 }
1240 // Date update
1241 if (!empty($arrayfields['a.tms']['checked'])) {
1242 print '<td align="center" class="nowrap">'.dol_print_date($db->jdate($obj->datem), 'dayhour', 'tzuserrel').'</td>';
1243 }
1244 if (!empty($arrayfields['a.percent']['checked'])) {
1245 // Status/Percent
1246 $datep = $db->jdate($obj->dp);
1247 print '<td align="center" class="nowrap">'.$actionstatic->LibStatut($obj->percent, 5, 0, $datep).'</td>';
1248 }
1249 // Action column
1250 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1251 print '<td class="nowrap center">';
1252 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1253 $selected = 0;
1254 if (in_array($obj->id, $arrayofselected)) {
1255 $selected = 1;
1256 }
1257 print '<input id="cb'.$obj->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->id.'"'.($selected ? ' checked="checked"' : '').'>';
1258 }
1259 print '</td>';
1260 }
1261
1262 print '</tr>'."\n";
1263
1264 $i++;
1265}
1266// If no record found
1267if ($num == 0) {
1268 print '<tr><td colspan="'.$totalarray['nbfield'].'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1269}
1270
1271
1272print '</table>'."\n";
1273print '</div>'."\n";
1274
1275print '</form>'."\n";
1276
1277$db->free($resql);
1278
1279// End of page
1280llxFooter();
1281$db->close();
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)
const EVENT_FINISHED
Typical value for a event that is in a finished state.
const EVENT_IN_PROGRESS
Typical value for a event that is in a progress state.
const EVENT_TODO
Typical value for a event that is in a todo state.
Class to manage different types of events.
Class to manage contact/addresses.
Class to manage standard extra fields.
Class to manage building of HTML components.
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
dolGetElementUrl($objectid, $objecttype, $withpicto=0, $option='')
Return link url to an object.
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, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dolGetFirstLineOfText($text, $nboflines=1, $charset='UTF-8')
Return first line of text.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
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.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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).
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
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...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
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.