dolibarr 21.0.0-beta
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 .= " ,".MAIN_DB_PREFIX."c_actioncomm as c";
461// We must filter on resource table
462if ($resourceid > 0) {
463 $sql .= ", ".MAIN_DB_PREFIX."element_resources as r";
464}
465// We must filter on assignment table
466if ($filtert > 0 || $usergroup > 0) {
467 $sql .= ", ".MAIN_DB_PREFIX."actioncomm_resources as ar";
468}
469if ($usergroup > 0) {
470 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_user = ar.fk_element";
471}
472$sql .= " WHERE c.id = a.fk_action";
473$sql .= ' AND a.entity IN ('.getEntity('agenda').')';
474// Condition on actioncode
475if (!empty($actioncode)) {
476 if (!getDolGlobalString('AGENDA_USE_EVENT_TYPE')) {
477 if ($actioncode == 'AC_NON_AUTO') {
478 $sql .= " AND c.type != 'systemauto'";
479 } elseif ($actioncode == 'AC_ALL_AUTO') {
480 $sql .= " AND c.type = 'systemauto'";
481 } else {
482 if ($actioncode == 'AC_OTH') {
483 $sql .= " AND c.type != 'systemauto'";
484 }
485 if ($actioncode == 'AC_OTH_AUTO') {
486 $sql .= " AND c.type = 'systemauto'";
487 }
488 }
489 } else {
490 if ($actioncode == 'AC_NON_AUTO') {
491 $sql .= " AND c.type != 'systemauto'";
492 } elseif ($actioncode == 'AC_ALL_AUTO') {
493 $sql .= " AND c.type = 'systemauto'";
494 } else {
495 if (is_array($actioncode)) {
496 $sql .= " AND c.code IN (".$db->sanitize("'".implode("','", $actioncode)."'", 1).")";
497 } elseif ($actioncode !== '-1') {
498 $sql .= " AND c.code IN (".$db->sanitize("'".implode("','", explode(',', $actioncode))."'", 1).")";
499 }
500 }
501 }
502}
503if ($resourceid > 0) {
504 $sql .= " AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = ".((int) $resourceid);
505}
506if ($pid) {
507 $sql .= " AND a.fk_project=".((int) $pid);
508}
509// If the internal user must only see his customers, force searching by him
510$search_sale = 0;
511if (isModEnabled("societe") && !$user->hasRight('societe', 'client', 'voir')) {
512 $search_sale = $user->id;
513}
514// Search on sale representative
515if ($search_sale && $search_sale != '-1') {
516 if ($search_sale == -2) {
517 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = a.fk_soc)";
518 } elseif ($search_sale > 0) {
519 $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).")";
520 }
521}
522// Search on socid
523if ($socid) {
524 $sql .= " AND a.fk_soc = ".((int) $socid);
525}
526// We must filter on assignment table
527if ($filtert > 0 || $usergroup > 0) {
528 $sql .= " AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
529}
530if ($type) {
531 $sql .= " AND c.id = ".((int) $type);
532}
533if ($search_status == '0') {
534 $sql .= " AND a.percent = 0";
535}
536if ($search_status == 'na') {
537 $sql .= " AND a.percent = -1";
538} // Not applicable
539if ($search_status == '50') {
540 $sql .= " AND (a.percent > 0 AND a.percent < 100)";
541} // Running already started
542if ($search_status == '100') {
543 $sql .= " AND a.percent = 100";
544}
545if ($search_status == 'done') {
546 $sql .= " AND (a.percent = 100)";
547}
548if ($search_status == 'todo') {
549 $sql .= " AND (a.percent >= 0 AND a.percent < 100)";
550}
551if ($search_id) {
552 $sql .= natural_search("a.id", $search_id, 1);
553}
554if ($search_title) {
555 $sql .= natural_search("a.label", $search_title);
556}
557if ($search_note) {
558 $sql .= natural_search('a.note', $search_note);
559}
560// We must filter on assignment table
561if ($filtert > 0 || $usergroup > 0) {
562 $sql .= " AND (";
563 if ($filtert > 0) {
564 $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
565 }
566 if ($usergroup > 0) {
567 $sql .= ($filtert > 0 ? " OR " : "")." ugu.fk_usergroup = ".((int) $usergroup);
568 }
569 $sql .= ")";
570}
571
572// The second or of next test is to take event with no end date (we suppose duration is 1 hour in such case)
573if ($dateselect > 0) {
574 $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)."'))";
575}
576if ($datestart_dtstart > 0) {
577 $sql .= " AND a.datep >= '".$db->idate($datestart_dtstart)."'";
578}
579if ($datestart_dtend > 0) {
580 $sql .= " AND a.datep <= '".$db->idate($datestart_dtend)."'";
581}
582if ($dateend_dtstart > 0) {
583 $sql .= " AND a.datep2 >= '".$db->idate($dateend_dtstart)."'";
584}
585if ($dateend_dtend > 0) {
586 $sql .= " AND a.datep2 <= '".$db->idate($dateend_dtend)."'";
587}
588
589// Search in categories, -1 is all and -2 is no categories
590if ($search_categ_cus != -1) {
591 if ($search_categ_cus == -2) {
592 $sql .= " AND NOT EXISTS (SELECT ca.fk_actioncomm FROM ".MAIN_DB_PREFIX."categorie_actioncomm as ca WHERE ca.fk_actioncomm = a.id)";
593 } elseif ($search_categ_cus > 0) {
594 $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)."))";
595 }
596}
597
598// Add where from extra fields
599include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
600
601// Add where from hooks
602$parameters = array();
603$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
604$sql .= $hookmanager->resPrint;
605
606// Count total nb of records
607$nbtotalofrecords = '';
608if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
609 /* The fast and low memory method to get and count full list converts the sql into a sql count */
610 $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
611 $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
612
613 $resql = $db->query($sqlforcount);
614 if ($resql) {
615 $objforcount = $db->fetch_object($resql);
616 $nbtotalofrecords = $objforcount->nbtotalofrecords;
617 } else {
618 dol_print_error($db);
619 }
620
621 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
622 $page = 0;
623 $offset = 0;
624 }
625 $db->free($resql);
626}
627
628// Complete request and execute it with limit
629$sql .= $db->order($sortfield, $sortorder);
630if ($limit) {
631 $sql .= $db->plimit($limit + 1, $offset);
632}
633
634$resql = $db->query($sql);
635if (!$resql) {
636 dol_print_error($db);
637 exit;
638}
639
640$num = $db->num_rows($resql);
641
642$arrayofselected = is_array($toselect) ? $toselect : array();
643
644// Local calendar
645$newtitle = '<div class="nowrap clear inline-block minheight30">';
646$newtitle .= '<input type="checkbox" id="check_mytasks" name="check_mytasks" checked disabled> '.$langs->trans("LocalAgenda").' &nbsp; ';
647$newtitle .= '</div>';
648//$newtitle=$langs->trans($title);
649
650$tabactive = 'cardlist';
651
652$head = calendars_prepare_head($param);
653
654print '<form method="POST" id="searchFormList" class="listactionsfilter" action="'.$_SERVER["PHP_SELF"].'">'."\n";
655
656if ($optioncss != '') {
657 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
658}
659print '<input type="hidden" name="token" value="'.newToken().'">';
660print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
661print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
662print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
663print '<input type="hidden" name="type" value="'.$type.'">';
664$nav = '';
665
666if ($filter) {
667 $nav .= '<input type="hidden" name="search_filter" value="'.$filter.'">';
668}
669if ($showbirthday) {
670 $nav .= '<input type="hidden" name="search_showbirthday" value="1">';
671}
672print $nav;
673
674//print dol_get_fiche_head($head, $tabactive, $langs->trans('Agenda'), 0, 'action');
675//print_actions_filter($form, $canedit, $search_status, $year, $month, $day, $showbirthday, '', $filtert, '', $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid);
676//print dol_get_fiche_end();
677
678
679$s = $newtitle;
680
681// Calendars from hooks
682$parameters = array();
683$reshook = $hookmanager->executeHooks('addCalendarChoice', $parameters, $object, $action);
684if (empty($reshook)) {
685 $s .= $hookmanager->resPrint;
686} elseif ($reshook > 1) {
687 $s = $hookmanager->resPrint;
688}
689
690$viewyear = is_object($object) ? dol_print_date($object->datep, '%Y') : '';
691$viewmonth = is_object($object) ? dol_print_date($object->datep, '%m') : '';
692$viewday = is_object($object) ? dol_print_date($object->datep, '%d') : '';
693
694$viewmode = '<div class="navmode inline-block">';
695
696$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.'">';
697//$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
698$viewmode .= img_picto($langs->trans("List"), 'object_calendarlist', 'class="imgforviewmode pictoactionview block"');
699//$viewmode .= '</span>';
700$viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone inline-block width75 divoverflow">'.$langs->trans("ViewList").'</span></a>';
701
702$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.'">';
703//$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
704$viewmode .= img_picto($langs->trans("ViewCal"), 'object_calendarmonth', 'class="pictoactionview block"');
705//$viewmode .= '</span>';
706$viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone inline-block width75 divoverflow">'.$langs->trans("ViewCal").'</span></a>';
707
708$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.'">';
709//$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
710$viewmode .= img_picto($langs->trans("ViewWeek"), 'object_calendarweek', 'class="pictoactionview block"');
711//$viewmode .= '</span>';
712$viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone inline-block width75 divoverflow">'.$langs->trans("ViewWeek").'</span></a>';
713
714$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.'">';
715//$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
716$viewmode .= img_picto($langs->trans("ViewDay"), 'object_calendarday', 'class="pictoactionview block"');
717//$viewmode .= '</span>';
718$viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone inline-block width75 divoverflow">'.$langs->trans("ViewDay").'</span></a>';
719
720$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.'">';
721//$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
722$viewmode .= img_picto($langs->trans("ViewPerUser"), 'object_calendarperuser', 'class="pictoactionview block"');
723//$viewmode .= '</span>';
724$viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone inline-block width75 divoverflow" title="'.dolPrintHTML($langs->trans("ViewPerUser")).'">'.$langs->trans("ViewPerUser").'</span></a>';
725
726// Add more views from hooks
727$parameters = array();
728$reshook = $hookmanager->executeHooks('addCalendarView', $parameters, $object, $action);
729if (empty($reshook)) {
730 $viewmode .= $hookmanager->resPrint;
731} elseif ($reshook > 1) {
732 $viewmode = $hookmanager->resPrint;
733}
734
735$viewmode .= '</div>';
736
737$viewmode .= '<span class="marginrightonly"></span>';
738
739
740$tmpforcreatebutton = dol_getdate(dol_now(), true);
741
742$newparam = '&month='.str_pad((string) $month, 2, "0", STR_PAD_LEFT).'&year='.$tmpforcreatebutton['year'];
743
744$url = DOL_URL_ROOT.'/comm/action/card.php?action=create';
745$url .= '&apyear='.$tmpforcreatebutton['year'].'&apmonth='.$tmpforcreatebutton['mon'].'&apday='.$tmpforcreatebutton['mday'].'&aphour='.$tmpforcreatebutton['hours'].'&apmin='.$tmpforcreatebutton['minutes'];
746$url .= '&backtopage='.urlencode($_SERVER["PHP_SELF"].($newparam ? '?'.$newparam : ''));
747
748$newcardbutton = dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', $url, '', (int) ($user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create')));
749
750$param .= '&mode='.urlencode($mode);
751
752print_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);
753
754print $s;
755
756$objecttmp = new ActionComm($db);
757include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
758
759$moreforfilter = '';
760
761$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
762$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields
763if ($massactionbutton) {
764 $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
765}
766$i = 0;
767
768print '<div class="liste_titre liste_titre_bydiv centpercent">';
769print_actions_filter($form, $canedit, $search_status, $year, $month, $day, $showbirthday, '', $filtert, '', $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid, $search_categ_cus);
770print '</div>';
771
772$moreforfilter = 1;
773
774print '<div class="div-table-responsive">';
775print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
776
777print '<tr class="liste_titre_filter">';
778// Action column
779if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
780 print '<td class="liste_titre" align="middle">';
781 $searchpicto = $form->showFilterButtons('left');
782 print $searchpicto;
783 print '</td>';
784}
785if (!empty($arrayfields['a.id']['checked'])) {
786 print '<td class="liste_titre"><input type="text" class="maxwidth50" name="search_id" value="'.$search_id.'"></td>';
787}
788if (!empty($arrayfields['owner']['checked'])) {
789 print '<td class="liste_titre"></td>';
790}
791if (!empty($arrayfields['c.libelle']['checked'])) {
792 print '<td class="liste_titre"></td>';
793}
794if (!empty($arrayfields['a.label']['checked'])) {
795 print '<td class="liste_titre"><input type="text" class="maxwidth75" name="search_title" value="'.$search_title.'"></td>';
796}
797if (!empty($arrayfields['a.note']['checked'])) {
798 print '<td class="liste_titre"><input type="text" class="maxwidth75" name="search_note" value="'.$search_note.'"></td>';
799}
800if (!empty($arrayfields['a.datep']['checked'])) {
801 print '<td class="liste_titre nowraponall" align="center">';
802 print '<div class="nowrap">';
803 print $form->selectDate($datestart_dtstart, 'datestart_dtstart', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'), 'tzuserrel');
804 print '</div>';
805 print '<div class="nowrap">';
806 print $form->selectDate($datestart_dtend, 'datestart_dtend', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('To'), 'tzuserrel');
807 print '</div>';
808 print '</td>';
809}
810if (!empty($arrayfields['a.datep2']['checked'])) {
811 print '<td class="liste_titre nowraponall" align="center">';
812 print '<div class="nowrap">';
813 print $form->selectDate($dateend_dtstart, 'dateend_dtstart', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'), 'tzuserrel');
814 print '</div>';
815 print '<div class="nowrap">';
816 print $form->selectDate($dateend_dtend, 'dateend_dtend', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('To'), 'tzuserrel');
817 print '</div>';
818 print '</td>';
819}
820if (!empty($arrayfields['s.nom']['checked'])) {
821 print '<td class="liste_titre"></td>';
822}
823if (!empty($arrayfields['a.fk_contact']['checked'])) {
824 print '<td class="liste_titre"></td>';
825}
826if (!empty($arrayfields['a.fk_element']['checked'])) {
827 print '<td class="liste_titre"></td>';
828}
829
830// Extra fields
831include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
832
833// Fields from hook
834$parameters = array('arrayfields' => $arrayfields);
835$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
836print $hookmanager->resPrint;
837
838if (!empty($arrayfields['a.datec']['checked'])) {
839 print '<td class="liste_titre"></td>';
840}
841if (!empty($arrayfields['a.tms']['checked'])) {
842 print '<td class="liste_titre"></td>';
843}
844if (!empty($arrayfields['a.percent']['checked'])) {
845 print '<td class="liste_titre center parentonrightofpage">';
846 $formactions->form_select_status_action('formaction', $search_status, 1, 'search_status', 1, 2, 'search_status width100 onrightofpage');
847 print '</td>';
848}
849// Action column
850if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
851 print '<td class="liste_titre center">';
852 $searchpicto = $form->showFilterButtons();
853 print $searchpicto;
854 print '</td>';
855}
856print '</tr>'."\n";
857
858$totalarray = array();
859$totalarray['nbfield'] = 0;
860
861// Fields title label
862// --------------------------------------------------------------------
863print '<tr class="liste_titre">';
864if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
865 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
866 $totalarray['nbfield']++;
867}
868if (!empty($arrayfields['a.id']['checked'])) {
869 // @phan-suppress-next-line PhanTypeInvalidDimOffset
870 print_liste_field_titre($arrayfields['a.id']['label'], $_SERVER["PHP_SELF"], "a.id", $param, "", "", $sortfield, $sortorder);
871 $totalarray['nbfield']++;
872}
873if (!empty($arrayfields['owner']['checked'])) {
874 print_liste_field_titre($arrayfields['owner']['label'], $_SERVER["PHP_SELF"], "", $param, "", "", $sortfield, $sortorder);
875 $totalarray['nbfield']++;
876}
877if (!empty($arrayfields['c.libelle']['checked'])) {
878 print_liste_field_titre($arrayfields['c.libelle']['label'], $_SERVER["PHP_SELF"], "c.libelle", $param, "", "", $sortfield, $sortorder);
879 $totalarray['nbfield']++;
880}
881if (!empty($arrayfields['a.label']['checked'])) {
882 print_liste_field_titre($arrayfields['a.label']['label'], $_SERVER["PHP_SELF"], "a.label", $param, "", "", $sortfield, $sortorder);
883 $totalarray['nbfield']++;
884}
885if (!empty($arrayfields['a.note']['checked'])) {
886 print_liste_field_titre($arrayfields['a.note']['label'], $_SERVER["PHP_SELF"], "a.note", $param, "", "", $sortfield, $sortorder);
887 $totalarray['nbfield']++;
888}
889//if (!empty($conf->global->AGENDA_USE_EVENT_TYPE))
890if (!empty($arrayfields['a.datep']['checked'])) {
891 print_liste_field_titre($arrayfields['a.datep']['label'], $_SERVER["PHP_SELF"], "a.datep,a.id", $param, '', '', $sortfield, $sortorder, 'center ');
892 $totalarray['nbfield']++;
893}
894if (!empty($arrayfields['a.datep2']['checked'])) {
895 print_liste_field_titre($arrayfields['a.datep2']['label'], $_SERVER["PHP_SELF"], "a.datep2", $param, '', '', $sortfield, $sortorder, 'center ');
896 $totalarray['nbfield']++;
897}
898if (!empty($arrayfields['s.nom']['checked'])) {
899 print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", $param, "", "", $sortfield, $sortorder);
900 $totalarray['nbfield']++;
901}
902if (!empty($arrayfields['a.fk_contact']['checked'])) {
903 print_liste_field_titre($arrayfields['a.fk_contact']['label'], $_SERVER["PHP_SELF"], "", $param, "", "", $sortfield, $sortorder);
904 $totalarray['nbfield']++;
905}
906if (!empty($arrayfields['a.fk_element']['checked'])) {
907 print_liste_field_titre($arrayfields['a.fk_element']['label'], $_SERVER["PHP_SELF"], "", $param, "", "", $sortfield, $sortorder);
908 $totalarray['nbfield']++;
909}
910// Extra fields
911include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
912// Hook fields
913$parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
914$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
915print $hookmanager->resPrint;
916
917if (!empty($arrayfields['a.datec']['checked'])) {
918 print_liste_field_titre($arrayfields['a.datec']['label'], $_SERVER["PHP_SELF"], "a.datec,a.id", $param, "", '', $sortfield, $sortorder, 'center ');
919 $totalarray['nbfield']++;
920}
921if (!empty($arrayfields['a.tms']['checked'])) {
922 print_liste_field_titre($arrayfields['a.tms']['label'], $_SERVER["PHP_SELF"], "a.tms,a.id", $param, "", '', $sortfield, $sortorder, 'center ');
923 $totalarray['nbfield']++;
924}
925// Status
926if (!empty($arrayfields['a.percent']['checked'])) {
927 print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "a.percent", $param, "", '', $sortfield, $sortorder, 'center ');
928 $totalarray['nbfield']++;
929}
930if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
931 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'maxwidthsearch center ');
932 $totalarray['nbfield']++;
933}
934print "</tr>\n";
935
936$now = dol_now();
937$delay_warning = getDolGlobalInt('MAIN_DELAY_ACTIONS_TODO') * 24 * 60 * 60;
938$today_start_time = dol_mktime(0, 0, 0, (int) date('m', $now), (int) date('d', $now), (int) date('Y', $now));
939
940require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
941$caction = new CActionComm($db);
942$arraylist = $caction->liste_array(1, 'code', '', (!getDolGlobalString('AGENDA_USE_EVENT_TYPE') ? 1 : 0), '', 1);
943$contactListCache = array();
944
945// Loop on record
946// --------------------------------------------------------------------
947$i = 0;
948//$savnbfield = $totalarray['nbfield'];
949//$totalarray['nbfield'] = 0;
950$imaxinloop = ($limit ? min($num, $limit) : $num);
951$cache_user_list = array();
952while ($i < $imaxinloop) {
953 $obj = $db->fetch_object($resql);
954 if (empty($obj)) {
955 break; // Should not happen
956 }
957
958 // Store properties in $object
959 $object->setVarsFromFetchObj($obj);
960
961 // Discard auto action if option is on
962 if (getDolGlobalString('AGENDA_ALWAYS_HIDE_AUTO') && $obj->type_code == 'AC_OTH_AUTO') {
963 $i++;
964 continue;
965 }
966
967 $actionstatic->id = $obj->id;
968 $actionstatic->ref = $obj->id;
969 $actionstatic->code = $obj->code;
970 $actionstatic->type_code = $obj->type_code;
971 $actionstatic->type_label = $obj->type_label;
972 $actionstatic->type_picto = $obj->type_picto;
973 $actionstatic->type_color = $obj->type_color;
974 $actionstatic->label = $obj->label;
975 $actionstatic->location = $obj->location;
976 $actionstatic->note_private = dol_htmlentitiesbr($obj->note);
977 $actionstatic->datep = $db->jdate($obj->dp);
978 $actionstatic->percentage = $obj->percent;
979 $actionstatic->authorid = $obj->fk_user_author;
980 $actionstatic->userownerid = $obj->fk_user_action;
981
982 // Initialize $this->userassigned && this->socpeopleassigned array && this->userownerid
983 // but only if we need it
984 if (!empty($arrayfields['a.fk_contact']['checked'])) {
985 $actionstatic->fetchResources();
986 }
987
988 // cache of user list (owners)
989 if ($obj->fk_user_action > 0 && !isset($cache_user_list[$obj->fk_user_action])) {
990 $userstatic = new User($db);
991 $res = $userstatic->fetch($obj->fk_user_action);
992 if ($res > 0) {
993 $cache_user_list[$obj->fk_user_action] = $userstatic;
994 }
995 }
996
997 // get event style for user owner
998 $event_owner_style = '';
999 // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
1000 if ($obj->fk_user_action > 0 && $cache_user_list[$obj->fk_user_action]->color != '') {
1001 $event_owner_style .= 'border-left: #' . $cache_user_list[$obj->fk_user_action]->color . ' 5px solid;';
1002 }
1003
1004 // get event style for start and end date
1005 $event_more_class = '';
1006 $event_start_date_css = '';
1007 $event_end_date_css = '';
1008 $event_start_date_time = $actionstatic->datep;
1009 if ($event_start_date_time > $now) {
1010 // future event
1011 $event_more_class = 'event-future';
1012 $event_start_date_css = $event_end_date_css = $event_more_class;
1013 } else {
1014 if ($obj->fulldayevent == 1) {
1015 $today_start_date_time = $today_start_time;
1016 } else {
1017 $today_start_date_time = $now;
1018 }
1019
1020 // check event end date
1021 $event_end_date_time = $db->jdate($obj->dp2);
1022 if ($event_end_date_time != null && $event_end_date_time < $today_start_date_time) {
1023 // past event
1024 $event_more_class = 'event-past';
1025 } elseif ($event_end_date_time == null && $event_start_date_time < $today_start_date_time) {
1026 // past event
1027 $event_more_class = 'event-past';
1028 } else {
1029 // current event
1030 $event_more_class = 'event-current';
1031 }
1032 $event_start_date_css = $event_end_date_css = $event_more_class;
1033 }
1034 $event_start_date_css = $event_end_date_css = $event_more_class;
1035
1036 print '<tr class="oddeven' . ($event_more_class != '' ? ' '.$event_more_class : '') . '">';
1037 // Action column
1038 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1039 print '<td class="nowrap center">';
1040 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1041 $selected = 0;
1042 if (in_array($obj->id, $arrayofselected)) {
1043 $selected = 1;
1044 }
1045 print '<input id="cb'.$obj->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->id.'"'.($selected ? ' checked="checked"' : '').'>';
1046 }
1047 print '</td>';
1048 }
1049 // Ref
1050 if (!empty($arrayfields['a.id']['checked'])) {
1051 print '<td class="nowraponall">';
1052 print $actionstatic->getNomUrl(1, -1);
1053 print '</td>';
1054 }
1055
1056 // User owner
1057 if (!empty($arrayfields['owner']['checked'])) {
1058 //print '<td class="tdoverflowmax150"' . ($event_owner_style != '' ? ' style="'.$event_owner_style.'"' : '') . '>';
1059 print '<td class="tdoverflowmax150">';
1060 if ($obj->fk_user_action > 0 && !isset($cache_user_list[$obj->fk_user_action])) {
1061 $userstatic = new User($db);
1062 $res = $userstatic->fetch($obj->fk_user_action);
1063 if ($res > 0) {
1064 $cache_user_list[$obj->fk_user_action] = $userstatic;
1065 }
1066 }
1067 if (isset($cache_user_list[$obj->fk_user_action])) {
1068 print $cache_user_list[$obj->fk_user_action]->getNomUrl(-1);
1069 } else {
1070 print '&nbsp;';
1071 }
1072 print '</td>';
1073 }
1074
1075 // Type
1076 if (!empty($arrayfields['c.libelle']['checked'])) {
1077 print '<td class="nowraponall">';
1078 print $actionstatic->getTypePicto();
1079 $labeltype = $obj->type_code;
1080 if (!getDolGlobalString('AGENDA_USE_EVENT_TYPE') && empty($arraylist[$labeltype])) {
1081 $labeltype = 'AC_OTH';
1082 }
1083 if (!empty($actionstatic->code) && preg_match('/^TICKET_MSG/', $actionstatic->code)) {
1084 $labeltype = $langs->trans("Message");
1085 } else {
1086 if (!empty($arraylist[$labeltype])) {
1087 $labeltype = $arraylist[$labeltype];
1088 }
1089 if ($obj->type_code == 'AC_OTH_AUTO' && ($obj->type_code != $obj->code) && $labeltype && !empty($arraylist[$obj->code])) {
1090 $labeltype .= ' - '.$arraylist[$obj->code]; // Use code in priority on type_code
1091 }
1092 }
1093 print dol_trunc($labeltype, 28);
1094 print '</td>';
1095 }
1096
1097 // Label
1098 if (!empty($arrayfields['a.label']['checked'])) {
1099 print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($actionstatic->label).'">';
1100 print $actionstatic->label;
1101 print '</td>';
1102 }
1103
1104 // Description
1105 if (!empty($arrayfields['a.note']['checked'])) {
1106 $text = dolGetFirstLineOfText(dol_string_nohtmltag($actionstatic->note_private, 1));
1107 print '<td class="tdoverflow200" title="'.dol_escape_htmltag($text).'">';
1108 print $form->textwithtooltip(dol_trunc($text, 48), $actionstatic->note_private);
1109 print '</td>';
1110 }
1111
1112 $formatToUse = $obj->fulldayevent ? 'day' : 'dayhour';
1113
1114 // Start date
1115 if (!empty($arrayfields['a.datep']['checked'])) {
1116 print '<td class="center nowraponall'.($event_start_date_css ? ' '.$event_start_date_css : '').'"><span>';
1117 if (empty($obj->fulldayevent)) {
1118 print dol_print_date($db->jdate($obj->dp), $formatToUse, 'tzuserrel');
1119 } else {
1120 $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
1121 print dol_print_date($db->jdate($obj->dp), $formatToUse, ($tzforfullday ? $tzforfullday : 'tzuserrel'));
1122 }
1123 print '</span>';
1124 $late = 0;
1125 if ($actionstatic->hasDelay() && $actionstatic->percentage >= 0 && $actionstatic->percentage < 100) {
1126 $late = 1;
1127 }
1128 if ($late) {
1129 print img_warning($langs->trans("Late")).' ';
1130 }
1131 print '</td>';
1132 }
1133
1134 // End date
1135 if (!empty($arrayfields['a.datep2']['checked'])) {
1136 print '<td class="center nowraponall'.($event_end_date_css ? ' '.$event_end_date_css : '').'"><span>';
1137 if (empty($obj->fulldayevent)) {
1138 print dol_print_date($db->jdate($obj->dp2), $formatToUse, 'tzuserrel');
1139 } else {
1140 $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
1141 print dol_print_date($db->jdate($obj->dp2), $formatToUse, ($tzforfullday ? $tzforfullday : 'tzuserrel'));
1142 }
1143 print '</span>';
1144 print '</td>';
1145 }
1146
1147 // Third party
1148 if (!empty($arrayfields['s.nom']['checked'])) {
1149 print '<td class="tdoverflowmax150">';
1150 if ($obj->socid > 0) {
1151 $societestatic->id = $obj->socid;
1152 $societestatic->client = (int) $obj->client;
1153 $societestatic->name = (string) $obj->societe;
1154 $societestatic->email = $obj->socemail;
1155
1156 print $societestatic->getNomUrl(1, '', 28);
1157 } else {
1158 print '&nbsp;';
1159 }
1160 print '</td>';
1161 }
1162
1163 // Contact
1164 if (!empty($arrayfields['a.fk_contact']['checked'])) {
1165 print '<td class="tdoverflowmax100">';
1166
1167 if (!empty($actionstatic->socpeopleassigned)) {
1168 $contactList = array();
1169 foreach ($actionstatic->socpeopleassigned as $socpeopleassigned) {
1170 if (!isset($contactListCache[$socpeopleassigned['id']])) {
1171 // if no cache found we fetch it
1172 $contact = new Contact($db);
1173 if ($contact->fetch($socpeopleassigned['id']) > 0) {
1174 $contactListCache[$socpeopleassigned['id']] = $contact->getNomUrl(1, '', 0);
1175 $contactList[] = $contact->getNomUrl(1, '', 0);
1176 }
1177 } else {
1178 // use cache
1179 $contactList[] = $contactListCache[$socpeopleassigned['id']];
1180 }
1181 }
1182 if (!empty($contactList)) {
1183 print implode(', ', $contactList);
1184 }
1185 } elseif ($obj->fk_contact > 0) { //keep for retrocompatibility with faraway event
1186 $contactstatic->id = $obj->fk_contact;
1187 $contactstatic->email = $obj->email;
1188 $contactstatic->lastname = $obj->lastname;
1189 $contactstatic->firstname = $obj->firstname;
1190 $contactstatic->phone_pro = $obj->phone_pro;
1191 $contactstatic->phone_mobile = $obj->phone_mobile;
1192 $contactstatic->phone_perso = $obj->phone_perso;
1193 $contactstatic->country_id = $obj->country_id;
1194 print $contactstatic->getNomUrl(1, '', 0);
1195 } else {
1196 print "&nbsp;";
1197 }
1198 print '</td>';
1199 }
1200
1201 // Linked object
1202 if (!empty($arrayfields['a.fk_element']['checked'])) {
1203 print '<td class="tdoverflowmax150">';
1204 //var_dump($obj->fkelement.' '.$obj->elementtype);
1205 if ($obj->fk_element > 0 && !empty($obj->elementtype)) {
1206 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
1207 print dolGetElementUrl($obj->fk_element, $obj->elementtype, 1);
1208 } else {
1209 print "&nbsp;";
1210 }
1211 print '</td>';
1212 }
1213
1214 // Extra fields
1215 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1216 // Fields from hook
1217 $parameters = array('arrayfields' => $arrayfields, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
1218 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
1219 print $hookmanager->resPrint;
1220
1221 // Date creation
1222 if (!empty($arrayfields['a.datec']['checked'])) {
1223 // Status/Percent
1224 print '<td align="center" class="nowrap">'.dol_print_date($db->jdate($obj->datec), 'dayhour', 'tzuserrel').'</td>';
1225 }
1226 // Date update
1227 if (!empty($arrayfields['a.tms']['checked'])) {
1228 print '<td align="center" class="nowrap">'.dol_print_date($db->jdate($obj->datem), 'dayhour', 'tzuserrel').'</td>';
1229 }
1230 if (!empty($arrayfields['a.percent']['checked'])) {
1231 // Status/Percent
1232 $datep = $db->jdate($obj->dp);
1233 print '<td align="center" class="nowrap">'.$actionstatic->LibStatut($obj->percent, 5, 0, $datep).'</td>';
1234 }
1235 // Action column
1236 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1237 print '<td class="nowrap center">';
1238 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1239 $selected = 0;
1240 if (in_array($obj->id, $arrayofselected)) {
1241 $selected = 1;
1242 }
1243 print '<input id="cb'.$obj->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->id.'"'.($selected ? ' checked="checked"' : '').'>';
1244 }
1245 print '</td>';
1246 }
1247
1248 print '</tr>'."\n";
1249
1250 $i++;
1251}
1252// If no record found
1253if ($num == 0) {
1254 print '<tr><td colspan="'.$totalarray['nbfield'].'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1255}
1256
1257
1258print '</table>'."\n";
1259print '</div>'."\n";
1260
1261print '</form>'."\n";
1262
1263$db->free($resql);
1264
1265// End of page
1266llxFooter();
1267$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.
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.
llxFooter()
Footer empty.
Definition document.php:107
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_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.