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