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