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