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