dolibarr 25.0.0-alpha
list.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013-2018 Jean-François FERRY <hello@librethic.io>
3 * Copyright (C) 2016 Christophe Battarel <christophe@altairis.fr>
4 * Copyright (C) 2018 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2019-2021 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2019-2020 Laurent Destailleur <eldy@users.sourceforge.net>
7 * Copyright (C) 2023 Charlene Benke <charlene@patas-monkey.com>
8 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
9 * Copyright (C) 2024 Benjamin Falière <benjamin.faliere@altairis.fr>
10 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
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';
41require_once DOL_DOCUMENT_ROOT.'/ticket/class/actions_ticket.class.php';
42require_once DOL_DOCUMENT_ROOT.'/core/class/html.formticket.class.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
44require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
45require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
46include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
47include_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
48include_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
49
50// Load translation files required by the page
51$langs->loadLangs(array("ticket", "companies", "other", "projects", "contracts"));
52
53// Get parameters
54$action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
55$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
56$show_files = GETPOSTINT('show_files'); // Show files area generated by bulk actions ?
57$confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
58$cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
59$toselect = GETPOST('toselect', 'array:int'); // Array of ids of elements selected into a list
60$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'ticketlist'; // To manage different context of search
61$backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
62$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
63$mode = GETPOST('mode', 'alpha');
64
65$id = GETPOSTINT('id');
66$socid = GETPOSTINT('socid');
67$contractid = GETPOSTINT('contractid');
68$projectid = GETPOSTINT('projectid');
69$project_ref = GETPOST('project_ref', 'alpha');
70$search_societe = GETPOST('search_societe', 'alpha');
71$search_alias = GETPOST('search_alias', 'alpha');
72$search_fk_project = GETPOSTINT('search_fk_project') ? GETPOSTINT('search_fk_project') : GETPOSTINT('projectid');
73$search_fk_contract = GETPOSTINT('search_fk_contract') ? GETPOSTINT('search_fk_contract') : GETPOSTINT('contractid');
74
75$search_date_start = dol_mktime(0, 0, 0, GETPOSTINT('search_date_startmonth'), GETPOSTINT('search_date_startday'), GETPOSTINT('search_date_startyear'));
76$search_date_end = dol_mktime(23, 59, 59, GETPOSTINT('search_date_endmonth'), GETPOSTINT('search_date_endday'), GETPOSTINT('search_date_endyear'));
77$search_dateread_start = dol_mktime(0, 0, 0, GETPOSTINT('search_dateread_startmonth'), GETPOSTINT('search_dateread_startday'), GETPOSTINT('search_dateread_startyear'));
78$search_dateread_end = dol_mktime(23, 59, 59, GETPOSTINT('search_dateread_endmonth'), GETPOSTINT('search_dateread_endday'), GETPOSTINT('search_dateread_endyear'));
79$search_dateclose_start = dol_mktime(0, 0, 0, GETPOSTINT('search_dateclose_startmonth'), GETPOSTINT('search_dateclose_startday'), GETPOSTINT('search_dateclose_startyear'));
80$search_dateclose_end = dol_mktime(23, 59, 59, GETPOSTINT('search_dateclose_endmonth'), GETPOSTINT('search_dateclose_endday'), GETPOSTINT('search_dateclose_endyear'));
81
82
83// Load variable for pagination
84$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
85$sortfield = GETPOST('sortfield', 'aZ09comma');
86$sortorder = GETPOST('sortorder', 'aZ09comma');
87$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
88if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
89 // If $page is not defined, or '' or -1 or if we click on clear filters
90 $page = 0;
91}
92$offset = $limit * $page;
93$pageprev = $page - 1;
94$pagenext = $page + 1;
95
96// Initialize a technical objects
97$object = new Ticket($db);
98$extrafields = new ExtraFields($db);
99$diroutputmassaction = $conf->ticket->dir_output.'/temp/massgeneration/'.$user->id;
100if ($socid > 0) {
101 $hookmanager->initHooks(array('thirdpartyticket', 'globalcard'));
102} elseif ($projectid > 0) {
103 $hookmanager->initHooks(array('projectticket', 'globalcard'));
104} else {
105 $hookmanager->initHooks(array('ticketlist'));
106}
107// Fetch optionals attributes and labels
108$extrafields->fetch_name_optionals_label($object->table_element);
109$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
110
111// Default sort order (if not yet defined by previous GETPOST)
112if (!$sortfield) {
113 $sortfield = "t.datec";
114}
115if (!$sortorder) {
116 $sortorder = "DESC";
117}
118
119/*if (GETPOST('search_fk_status', 'alpha') == 'non_closed') {
120 $_GET['search_fk_statut'][] = 'openall'; // For backward compatibility
121}*/
122
123// Initialize array of search criteria
124$search_all = trim(GETPOST("search_all", 'alphanohtml'));
125$search = array();
126foreach ($object->fields as $key => $val) {
127 if (GETPOSTISARRAY('search_'.$key)) {
128 $search[$key] = GETPOST('search_'.$key, 'array:alpha');
129 } elseif (GETPOST('search_'.$key, 'alpha') !== '') {
130 $search[$key] = GETPOST('search_'.$key, 'alpha');
131 } else {
132 $search[$key] = "";
133 }
134 if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
135 $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOSTINT('search_'.$key.'_dtstartmonth'), GETPOSTINT('search_'.$key.'_dtstartday'), GETPOSTINT('search_'.$key.'_dtstartyear'));
136 $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOSTINT('search_'.$key.'_dtendmonth'), GETPOSTINT('search_'.$key.'_dtendday'), GETPOSTINT('search_'.$key.'_dtendyear'));
137 }
138}
139
140// List of fields to search into when doing a "search in all"
141$fieldstosearchall = array();
142foreach ($object->fields as $key => $val) {
143 if (!empty($val['searchall'])) {
144 $fieldstosearchall['t.'.$key] = $val['label'];
145 }
146}
147$fieldstosearchall['s.name_alias'] = "AliasNameShort";
148$fieldstosearchall['s.zip'] = "Zip";
149$fieldstosearchall['s.town'] = "Town";
150
151// Definition of array of fields for columns
152$arrayfields = array();
153foreach ($object->fields as $key => $val) {
154 // If $val['visible']==0, then we never show the field
155 if (!empty($val['visible'])) {
156 $visible = (int) dol_eval((string) $val['visible'], 1);
157 $arrayfields['t.'.$key] = array(
158 'label' => $val['label'],
159 'checked' => (($visible < 0) ? '0' : '1'),
160 'enabled' => (string) (int) (abs($visible) != 3 && (bool) dol_eval((string) $val['enabled'], 1)),
161 'position' => $val['position'],
162 'help' => isset($val['help']) ? $val['help'] : ''
163 );
164 }
165}
166// Alias name of third party, shown on the right of the third party column
167$arrayfields['s.name_alias'] = array('label' => 'AliasNameShort', 'checked' => '0', 'enabled' => (string) (int) isModEnabled('societe'), 'position' => 51);
168// Extra fields
169include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
170// Add hook to complete $arrayfield
171$parameters = array('arrayfields' => &$arrayfields);
172$reshook = $hookmanager->executeHooks('completeArrayFields', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
173
174$object->fields = dol_sort_array($object->fields, 'position');
175$arrayfields = dol_sort_array($arrayfields, 'position');
176
177
178// Security check
179if (!$user->hasRight('ticket', 'read')) {
181}
182// restrict view to current user's company
183if ($user->socid > 0) {
184 $socid = $user->socid;
185}
186
187// Store current page url
188$url_page_current = DOL_URL_ROOT.'/ticket/list.php';
189
190if ($project_ref) {
191 $tmpproject = new Project($db);
192 $tmpproject->fetch(0, $project_ref);
193 $projectid = $tmpproject->id;
194 $search_fk_project = $projectid;
195}
196
197$permissiontoread = $user->hasRight('ticket', 'read');
198$permissiontoadd = $user->hasRight('ticket', 'write');
199$permissiontodelete = $user->hasRight('ticket', 'delete');
200
201$error = 0;
202
203
204/*
205 * Actions
206 */
207
208if (GETPOST('cancel', 'alpha')) {
209 $action = 'list';
210 $massaction = '';
211}
212if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'presendonclose' && $massaction != 'close') {
213 $massaction = '';
214}
215
216$parameters = array('arrayfields' => &$arrayfields);
217if ($socid > 0) {
218 $parameters['socid'] = $socid;
219}
220if ($projectid > 0) {
221 $parameters['projectid'] = $projectid;
222}
223$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
224if ($reshook < 0) {
225 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
226}
227
228if (empty($reshook)) {
229 // Selection of new fields
230 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
231
232 // Purge search criteria
233 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
234 foreach ($object->fields as $key => $val) {
235 $search[$key] = '';
236 if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
237 $search[$key.'_dtstart'] = '';
238 $search[$key.'_dtend'] = '';
239 }
240 }
241 $toselect = array();
242 $search_array_options = array();
243 $search_societe = '';
244 $search_alias = '';
245 $search_date_start = '';
246 $search_date_end = '';
247 $search_dateread_start = '';
248 $search_dateread_end = '';
249 $search_dateclose_start = '';
250 $search_dateclose_end = '';
251 }
252 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
253 || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
254 $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
255 }
256
257 // Mass actions
258 $objectclass = 'Ticket';
259 $objectlabel = 'Ticket';
260 $uploaddir = $conf->ticket->dir_output;
261
262 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
263
264 // Close records
265 if (!$error && $massaction == 'close' && $permissiontoadd) { // @phpstan-ignore-line $error may have been modified by the actions_massactions.inc.php
266 $objecttmp = new Ticket($db);
267 $db->begin();
268
269 $nbok = 0;
270 foreach ($toselect as $toselectid) {
271 $result = $objecttmp->fetch($toselectid);
272 if ($result > 0) {
273 $result = $objecttmp->close($user);
274 if ($result < 0) {
275 setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
276 $error++;
277 break;
278 } else {
279 $nbok++;
280 }
281 } else {
282 setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
283 $error++;
284 break;
285 }
286 }
287
288 if (!$error) {
289 setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
290 $db->commit();
291 } else {
292 $db->rollback();
293 }
294 //var_dump($listofobjectthirdparties);exit;
295 }
296
297 // Reopen records
298 if (!$error && $massaction == 'reopen' && $permissiontoadd) {
299 $objecttmp = new Ticket($db);
300 $db->begin();
301
302 $nbok = 0;
303 foreach ($toselect as $toselectid) {
304 $result = $objecttmp->fetch($toselectid);
305 if ($result > 0) {
306 if ($objecttmp->status == Ticket::STATUS_CLOSED || $objecttmp->status == Ticket::STATUS_CANCELED) {
307 // Set status
308 $result = $objecttmp->setStatut(Ticket::STATUS_ASSIGNED, null, '', 'TICKET_MODIFY');
309
310 if ($result < 0) {
311 setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
312 $error++;
313 break;
314 } else {
315 $nbok++;
316 }
317 } else {
318 $langs->load("errors");
319 setEventMessages($langs->trans("ErrorObjectMustHaveStatusClosedToBeReOpened", $objecttmp->ref), null, 'errors');
320 $error++;
321 break;
322 }
323 } else {
324 setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
325 $error++;
326 break;
327 }
328 }
329
330 if (!$error) {
331 setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
332 $db->commit();
333 } else {
334 $db->rollback();
335 }
336 //var_dump($listofobjectthirdparties);exit;
337 }
338}
339
340
341
342/*
343 * View
344 */
345
346$form = new Form($db);
347$formTicket = new FormTicket($db);
348
349$now = dol_now();
350
351$user_temp = new User($db);
352$socstatic = new Societe($db);
353
354$help_url = '';
355
356$moretitle = '';
357if ($socid > 0) {
358 $socstatic->fetch($socid);
359 $moretitle = $langs->trans("ThirdParty") . ' - ';
360 if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $socstatic->name) {
361 $moretitle = $socstatic->name . ' - ';
362 }
363}
364
365$title = $moretitle . $langs->trans('Tickets');
366$morejs = array();
367$morecss = array();
368
369
370// Build and execute select
371// --------------------------------------------------------------------
372$sql = 'SELECT ';
373$sql .= $object->getFieldList('t');
374$sql .= ", s.name_alias as thirdparty_alias";
375// Add fields from extrafields
376if (!empty($extrafields->attributes[$object->table_element]['label'])) {
377 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
378 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
379 }
380}
381// Add fields from hooks
382$parameters = array();
383$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
384$sql .= $hookmanager->resPrint;
385$sql = preg_replace('/,\s*$/', '', $sql);
386
387$sqlfields = $sql; // $sql fields to remove for count total
388
389$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
390if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
391 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
392}
393// Add table from hooks
394$parameters = array();
395$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
396$sql .= $hookmanager->resPrint;
397$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON (t.fk_soc = s.rowid)";
398$sql .= " WHERE t.entity IN (".getEntity($object->element).")";
399if ($socid > 0) {
400 $sql .= " AND t.fk_soc = ".((int) $socid);
401}
402
403foreach ($search as $key => $val) {
404 $tmpkey = 't.' . $key;
405 if ($key == 'fk_statut' && !empty($search['fk_statut'])) {
406 $newarrayofstatus = array();
407 if (is_array($search['fk_statut'])) {
408 foreach ($search['fk_statut'] as $key2 => $val2) {
409 if (in_array($val2, array('openall', 'closeall'))) {
410 continue;
411 }
412 $newarrayofstatus[] = $val2;
413 }
414 }
415 if ($search['fk_statut'] === 'openall' || (is_array($search['fk_statut']) && in_array('openall', $search['fk_statut']))) {
416 $newarrayofstatus[] = Ticket::STATUS_NOT_READ;
417 $newarrayofstatus[] = Ticket::STATUS_READ;
418 $newarrayofstatus[] = Ticket::STATUS_ASSIGNED;
419 $newarrayofstatus[] = Ticket::STATUS_IN_PROGRESS;
420 $newarrayofstatus[] = Ticket::STATUS_NEED_MORE_INFO;
421 $newarrayofstatus[] = Ticket::STATUS_WAITING;
422 }
423 if ($search['fk_statut'] === 'closeall' || (is_array($search['fk_statut']) && in_array('closeall', $search['fk_statut']))) {
424 $newarrayofstatus[] = Ticket::STATUS_CLOSED;
425 $newarrayofstatus[] = Ticket::STATUS_CANCELED;
426 }
427 if (count($newarrayofstatus)) {
428 $sql .= natural_search($tmpkey, implode(',', $newarrayofstatus), 2);
429 }
430 continue;
431 } elseif ($key == 'fk_user_assign' || $key == 'fk_user_create' || $key == 'fk_project' || $key == 'fk_contract') {
432 if ($search[$key] > 0) {
433 $sql .= natural_search($tmpkey, $search[$key], 2);
434 }
435 continue;
436 } elseif ($key == 'type_code') {
437 $newarrayoftypecodes = is_array($search[$key]) ? $search[$key] : (!empty($search[$key]) ? explode(',', $search[$key]) : array());
438 if (count($newarrayoftypecodes)) {
439 $sql .= natural_search($tmpkey, implode(',', $newarrayoftypecodes), 3);
440 }
441 continue;
442 }
443
444 $mode_search = ((!empty($object->fields[$key]) && ($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key]))) ? 1 : 0);
445 // $search[$key] can be an array of values, or a string. We add filter if array not empty or if it is a string.
446 if ((is_array($search[$key]) && !empty($search[$key])) || (!is_array($search[$key]) && $search[$key] != '')) {
447 $sql .= natural_search($tmpkey, $search[$key], $mode_search);
448 }
449}
450if ($search_all) {
451 $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
452}
453if ($search_societe) {
454 $sql .= natural_search('s.nom', $search_societe);
455}
456if ($search_alias) {
457 $sql .= natural_search('s.name_alias', $search_alias);
458}
459if ($search_fk_project > 0) {
460 $sql .= natural_search('t.fk_project', (string) $search_fk_project, 2);
461}
462if ($search_fk_contract > 0) {
463 $sql .= natural_search('t.fk_contract', (string) $search_fk_contract, 2);
464}
465if ($search_date_start) {
466 $sql .= " AND t.datec >= '".$db->idate($search_date_start)."'";
467}
468if ($search_date_end) {
469 $sql .= " AND t.datec <= '".$db->idate($search_date_end)."'";
470}
471if ($search_dateread_start) {
472 $sql .= " AND t.date_read >= '".$db->idate($search_dateread_start)."'";
473}
474if ($search_dateread_end) {
475 $sql .= " AND t.date_read <= '".$db->idate($search_dateread_end)."'";
476}
477if ($search_dateclose_start) {
478 $sql .= " AND t.date_close >= '".$db->idate($search_dateclose_start)."'";
479}
480if ($search_dateclose_end) {
481 $sql .= " AND t.date_close <= '".$db->idate($search_dateclose_end)."'";
482}
483
484if (!$user->socid && ($mode == "mine" || (!$user->admin && getDolGlobalString('TICKET_LIMIT_VIEW_ASSIGNED_ONLY')))) {
485 $sql .= " AND (t.fk_user_assign = ".((int) $user->id);
486 if (!getDolGlobalString('TICKET_LIMIT_VIEW_ASSIGNED_ONLY')) {
487 $sql .= " OR t.fk_user_create = ".((int) $user->id);
488 }
489 $sql .= ")";
490}
491
492// Add where from extra fields
493include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
494// Add where from hooks
495$parameters = array();
496$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
497$sql .= $hookmanager->resPrint;
498
499// Count total nb of records
500$nbtotalofrecords = '';
501if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
502 /* The fast and low memory method to get and count full list converts the sql into a sql count */
503 $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
504 $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
505 $resql = $db->query($sqlforcount);
506 if ($resql) {
507 $objforcount = $db->fetch_object($resql);
508 $nbtotalofrecords = $objforcount->nbtotalofrecords;
509 } else {
510 dol_print_error($db);
511 }
512
513 if (($page * $limit) > (int) $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
514 $page = 0;
515 $offset = 0;
516 }
517 $db->free($resql);
518}
519
520// Complete request and execute it with limit
521$sql .= $db->order($sortfield, $sortorder);
522if ($limit) {
523 $sql .= $db->plimit($limit + 1, $offset);
524}
525
526$resql = $db->query($sql);
527if (!$resql) {
528 dol_print_error($db);
529 exit;
530}
531
532$num = $db->num_rows($resql);
533
534// Direct jump if only one record found
535if ($num == 1 && getDolGlobalString('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
536 $obj = $db->fetch_object($resql);
537 $id = $obj->rowid;
538 header("Location: ".DOL_URL_ROOT.'/ticket/card.php?id='.$id);
539 exit;
540}
541
542
543// Output page
544// --------------------------------------------------------------------
545
546llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'mod-ticket page-list bodyforlist');
547
548if ($socid && !$projectid && !$project_ref && $user->hasRight('societe', 'lire')) {
549 $socstat = new Societe($db);
550 $res = $socstat->fetch($socid);
551 if ($res > 0) {
552 $tmpobject = $object;
553 $object = $socstat; // $object must be of type Societe when calling societe_prepare_head
554 $head = societe_prepare_head($socstat);
555 $object = $tmpobject;
556
557 print dol_get_fiche_head($head, 'ticket', $langs->trans("ThirdParty"), -1, 'company');
558
559 dol_banner_tab($socstat, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
560
561 print '<div class="fichecenter">';
562
563 print '<div class="underbanner clearboth"></div>';
564 print '<table class="border centpercent tableforfield">';
565
566 // Type Prospect/Customer/Supplier
567 print '<tr><td class="titlefield">'.$langs->trans('NatureOfThirdParty').'</td><td>';
568 print $socstat->getTypeUrl(1);
569 print '</td></tr>';
570
571 // Customer code
572 if ($socstat->client && !empty($socstat->code_client)) {
573 print '<tr><td class="titlefield">';
574 print $langs->trans('CustomerCode').'</td><td>';
575 print showValueWithClipboardCPButton(dol_escape_htmltag($socstat->code_client));
576 $tmpcheck = $socstat->check_codeclient();
577 if ($tmpcheck != 0 && $tmpcheck != -5) {
578 print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
579 }
580 print '</td>';
581 print '</tr>';
582 }
583 // Supplier code
584 if ($socstat->fournisseur && !empty($socstat->code_fournisseur)) {
585 print '<tr><td class="titlefield">';
586 print $langs->trans('SupplierCode').'</td><td>';
587 print showValueWithClipboardCPButton(dol_escape_htmltag($socstat->code_fournisseur));
588 $tmpcheck = $socstat->check_codefournisseur();
589 if ($tmpcheck != 0 && $tmpcheck != -5) {
590 print ' <span class="error">('.$langs->trans("WrongSupplierCode").')</span>';
591 }
592 print '</td>';
593 print '</tr>';
594 }
595
596 print '</table>';
597 print '</div>';
598 print dol_get_fiche_end();
599
600 print '<br>';
601 }
602}
603
604if ($projectid > 0 || $project_ref) {
605 $projectstat = new Project($db);
606 if ($projectstat->fetch($projectid, $project_ref) > 0) {
607 $projectid = $projectstat->id;
608 $projectstat->fetch_thirdparty();
609
610 $savobject = $object;
611 $object = $projectstat;
612
613 // To verify role of users
614 //$userAccess = $object->restrictedProjectArea($user,'read');
615 $userWrite = $projectstat->restrictedProjectArea($user, 'write');
616 //$userDelete = $object->restrictedProjectArea($user,'delete');
617 //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
618
619 $head = project_prepare_head($projectstat);
620 print dol_get_fiche_head($head, 'ticket', $langs->trans("Project"), -1, ($projectstat->public ? 'projectpub' : 'project'));
621
622 // Project card
623
624 $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
625
626 $morehtmlref = '<div class="refidno">';
627 // Title
628 $morehtmlref .= $object->title;
629 // Thirdparty
630 if (!empty($object->thirdparty->id) && $object->thirdparty->id > 0) {
631 $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'project');
632 }
633 $morehtmlref .= '</div>';
634
635 // Define a complementary filter for search of next/prev ref.
636 if (!$user->hasRight('projet', 'all', 'lire')) {
637 $objectsListId = $object->getProjectsAuthorizedForUser($user, 0, 0);
638 $object->next_prev_filter = "rowid:IN:".$db->sanitize(count($objectsListId) ? implode(',', array_keys($objectsListId)) : '0');
639 }
640
641 dol_banner_tab($object, 'project_ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
642
643 print '<div class="fichecenter">';
644 print '<div class="underbanner clearboth"></div>';
645
646 print '<table class="border tableforfield centpercent">';
647
648 // Visibility
649 print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
650 if ($projectstat->public) {
651 print img_picto($langs->trans('SharedProject'), 'world', 'class="paddingrightonly"');
652 print $langs->trans('SharedProject');
653 } else {
654 print img_picto($langs->trans('PrivateProject'), 'private', 'class="paddingrightonly"');
655 print $langs->trans('PrivateProject');
656 }
657 print '</td></tr>';
658
659 print "</table>";
660
661 print '</div>';
662 print dol_get_fiche_end();
663
664 print '<br>';
665
666 $object = $savobject;
667 } else {
668 print "ErrorRecordNotFound";
669 }
670}
671
672$arrayofselected = is_array($toselect) ? $toselect : array();
673
674$param = '';
675if (!empty($mode)) {
676 $param .= '&mode='.urlencode($mode);
677}
678if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
679 $param .= '&contextpage='.urlencode($contextpage);
680}
681if ($limit > 0 && $limit != $conf->liste_limit) {
682 $param .= '&limit='.((int) $limit);
683}
684if ($optioncss != '') {
685 $param .= '&optioncss='.urlencode($optioncss);
686}
687foreach ($search as $key => $val) {
688 if (is_array($search[$key])) {
689 foreach ($search[$key] as $skey) {
690 if ($skey != '') {
691 $param .= '&search_'.$key.'[]='.urlencode($skey);
692 }
693 }
694 } elseif (preg_match('/(_dtstart|_dtend)$/', $key) && !empty($val)) {
695 $param .= '&search_'.$key.'month='.(GETPOSTINT('search_'.$key.'month'));
696 $param .= '&search_'.$key.'day='.(GETPOSTINT('search_'.$key.'day'));
697 $param .= '&search_'.$key.'year='.(GETPOSTINT('search_'.$key.'year'));
698 } elseif ($search[$key] != '') {
699 $param .= '&search_'.$key.'='.urlencode($search[$key]);
700 }
701}
702// Add $param from extra fields
703include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
704// Add $param from hooks
705$parameters = array('param' => &$param);
706$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
707$param .= $hookmanager->resPrint;
708if ($socid > 0) {
709 $param .= '&socid='.urlencode((string) ($socid));
710}
711if ($search_societe) {
712 $param .= '&search_societe='.urlencode($search_societe);
713}
714if ($search_alias) {
715 $param .= '&search_alias='.urlencode($search_alias);
716}
717if ($projectid > 0) {
718 $param .= '&projectid='.urlencode((string) ($projectid));
719}
720if ($contractid > 0) {
721 $param .= '&contractid='.urlencode((string) ($contractid));
722}
723if ($search_date_start) {
724 $tmparray = dol_getdate($search_date_start);
725 $param .= '&search_date_startday='.((int) $tmparray['mday']);
726 $param .= '&search_date_startmonth='.((int) $tmparray['mon']);
727 $param .= '&search_date_startyear='.((int) $tmparray['year']);
728}
729if ($search_date_end) {
730 $tmparray = dol_getdate($search_date_end);
731 $param .= '&search_date_endday='.((int) $tmparray['mday']);
732 $param .= '&search_date_endmonth='.((int) $tmparray['mon']);
733 $param .= '&search_date_endyear='.((int) $tmparray['year']);
734}
735if ($search_dateread_start) {
736 $tmparray = dol_getdate($search_dateread_start);
737 $param .= '&search_dateread_startday='.((int) $tmparray['mday']);
738 $param .= '&search_dateread_startmonth='.((int) $tmparray['mon']);
739 $param .= '&search_dateread_startyear='.((int) $tmparray['year']);
740}
741if ($search_dateread_end) {
742 $tmparray = dol_getdate($search_dateread_end);
743 $param .= '&search_dateread_endday='.((int) $tmparray['mday']);
744 $param .= '&search_dateread_endmonth='.((int) $tmparray['mon']);
745 $param .= '&search_dateread_endyear='.((int) $tmparray['year']);
746}
747if ($search_dateclose_start) {
748 $tmparray = dol_getdate($search_dateclose_start);
749 $param .= '&search_dateclose_startday='.((int) $tmparray['mday']);
750 $param .= '&search_dateclose_startmonth='.((int) $tmparray['mon']);
751 $param .= '&search_dateclose_startyear='.((int) $tmparray['year']);
752}
753if ($search_dateclose_end) {
754 $tmparray = dol_getdate($search_dateclose_end);
755 $param .= '&search_date_endday='.((int) $tmparray['mday']);
756 $param .= '&search_date_endmonth='.((int) $tmparray['mon']);
757 $param .= '&search_date_endyear='.((int) $tmparray['year']);
758}
759// List of mass actions available
760$arrayofmassactions = array(
761 //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
762 //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
763);
764if ($permissiontoadd) {
765 $arrayofmassactions['presendonclose'] = img_picto('', 'close_title', 'class="pictofixedwidth"').$langs->trans("Close");
766 $arrayofmassactions['reopen'] = img_picto('', 'folder-open', 'class="pictofixedwidth"').$langs->trans("ReOpen");
767}
768if ($permissiontodelete) {
769 $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
770}
771if (GETPOSTINT('nomassaction') || in_array($massaction, array('presend', 'predelete'))) {
772 $arrayofmassactions = array();
773}
774$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
775
776print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
777if ($optioncss != '') {
778 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
779}
780print '<input type="hidden" name="token" value="'.newToken().'">';
781print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
782print '<input type="hidden" name="action" value="list">';
783print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
784print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
785print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
786print '<input type="hidden" name="page_y" value="">';
787print '<input type="hidden" name="mode" value="'.$mode.'" >';
788
789if ($socid) {
790 print '<input type="hidden" name="socid" value="'.$socid.'" >';
791}
792if ($projectid) {
793 print '<input type="hidden" name="projectid" value="'.$projectid.'" >';
794}
795
796$url = DOL_URL_ROOT.'/ticket/card.php?action=create&mode=init'.($socid ? '&socid='.$socid : '').($projectid ? '&origin=projet_project&originid='.$projectid : '');
797if (!empty($socid)) {
798 $url .= '&socid='.$socid;
799}
800$newcardbutton = '';
801$newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss' => 'reposition'));
802$newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss' => 'reposition'));
803$newcardbutton .= dolGetButtonTitle($langs->trans('Statistics'), '', 'fa fa-chart-bar imgforviewmode', DOL_URL_ROOT.'/ticket/stats/index.php?mode=statistics&objecttype=ticket@ticket'.preg_replace('/(&|\?)*(mode|groupby)=[^&]+/', '', $param), '', ($mode == 'statistics' ? 2 : 1), array('morecss' => 'reposition'));
804$newcardbutton .= dolGetButtonTitleSeparator();
805$newcardbutton .= dolGetButtonTitle($langs->trans('NewTicket'), '', 'fa fa-plus-circle', $url, '', $user->hasRight('ticket', 'write'));
806
807$picto = 'ticket';
808/*if ($socid > 0) {
809 $picto = '';
810}*/
811
812print_barre_liste($langs->trans('Tickets'), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $picto, 0, $newcardbutton, '', $limit, 0, 0, 1); // @phan-suppress-current-line PhanPluginSuspiciousParamOrder
813
814if ($mode == 'mine') {
815 print '<div class="opacitymedium">'.$langs->trans('TicketAssignedToMeInfos').'</div><br>';
816}
817// Add code for pre mass action (confirmation or email presend form)
818$topicmail = "SendTicketRef";
819$modelmail = "ticket";
820$objecttmp = new Ticket($db);
821$trackid = 'tic'.$object->id;
822include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
823
824// confirm auto send on close
825if ($massaction == 'presendonclose') {
826 $hidden_form = array([
827 "type" => "hidden",
828 "name" => "massaction",
829 "value" => "close"
830 ]);
831 $selectedchoice = getDolGlobalString('TICKET_NOTIFY_AT_CLOSING') ? "yes" : "no";
832 print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassTicketClosingSendEmail"), $langs->trans("ConfirmMassTicketClosingSendEmailQuestion"), 'confirm_send_close', $hidden_form, $selectedchoice, 0, 200, 500, 1);
833}
834
835if ($search_all) {
836 $setupstring = '';
837 foreach ($fieldstosearchall as $key => $val) {
838 $fieldstosearchall[$key] = $langs->trans($val);
839 $setupstring .= $key."=".$val.";";
840 }
841 print '<!-- Search done like if TICKET_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
842 print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).implode(', ', $fieldstosearchall).'</div>'."\n";
843}
844
845$moreforfilter = '';
846/*$moreforfilter.='<div class="divsearchfield">';
847$moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
848$moreforfilter.= '</div>';*/
849
850$parameters = array();
851$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
852if (empty($reshook)) {
853 $moreforfilter .= $hookmanager->resPrint;
854} else {
855 $moreforfilter = $hookmanager->resPrint;
856}
857
858if (!empty($moreforfilter)) {
859 print '<div class="liste_titre liste_titre_bydiv centpercent">';
860 print $moreforfilter;
861 print '</div>';
862}
863
864$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
865$htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, $conf->main_checkbox_left_column); // This also change content of $arrayfields
866$selectedfields = ($mode != 'kanban' ? $htmlofselectarray : '');
867$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
868
869print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
870print '<div class="div-table-responsive-inside">';
871print '<table class="tagtable noborder nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
872
873
874// Fields title search
875// --------------------------------------------------------------------
876print '<tr class="liste_titre_filter">';
877// Action column
878if ($conf->main_checkbox_left_column) {
879 print '<td class="liste_titre maxwidthsearch center">';
880 $searchpicto = $form->showFilterButtons('left');
881 print $searchpicto;
882 print '</td>';
883}
884foreach ($object->fields as $key => $val) {
885 $searchkey = empty($search[$key]) ? '' : $search[$key];
886 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
887 if ($key == 'fk_statut') {
888 $cssforfield .= ($cssforfield ? ' ' : '').'center';
889 } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
890 $cssforfield .= ($cssforfield ? ' ' : '').'center';
891 } elseif (in_array($val['type'], array('timestamp'))) {
892 $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
893 } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('id', 'rowid', 'ref', 'status')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
894 $cssforfield .= ($cssforfield ? ' ' : '').'right';
895 }
896 if (!empty($arrayfields['t.'.$key]['checked'])) {
897 if ($key == 'progress') {
898 print '<td class="liste_titre right'.($cssforfield ? ' '.$cssforfield : '').'">';
899 print '<input type="text" class="flat maxwidth50" name="search_'.$key.'" value="'.dol_escape_htmltag(empty($search[$key]) ? '' : $search[$key]).'">';
900 print '</td>';
901 } elseif ($key == 'type_code') {
902 print '<td class="liste_titre">';
903 $formTicket->selectTypesTickets(empty($search[$key]) ? '' : $search[$key], 'search_'.$key, '', 2, 1, 1, 0, (!empty($val['css']) ? $val['css'] : 'maxwidth150'), 1);
904 print '</td>';
905 } elseif ($key == 'category_code') {
906 print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
907 $formTicket->selectGroupTickets(dol_escape_htmltag(empty($search[$key]) ? '' : $search[$key]), 'search_'.$key, '', 2, 1, 1, 0, (!empty($val['css']) ? $val['css'] : 'maxwidth150'));
908 print '</td>';
909 } elseif ($key == 'severity_code') {
910 print '<td class="liste_titre center'.($cssforfield ? ' '.$cssforfield : '').'">';
911 $formTicket->selectSeveritiesTickets(dol_escape_htmltag(empty($search[$key]) ? '' : $search[$key]), 'search_'.$key, '', 2, 1, 1, 0, (!empty($val['css']) ? $val['css'] : 'maxwidth150'));
912 print '</td>';
913 } elseif ($key == 'fk_user_assign' || $key == 'fk_user_create') {
914 print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
915 print $form->select_dolusers((empty($search[$key]) ? '' : $search[$key]), 'search_'.$key, 1, null, 0, '', '', '0', 0, 0, '', 0, '', (!empty($val['css']) ? $val['css'] : 'maxwidth100'));
916 print '</td>';
917 } elseif ($key == 'fk_statut') {
918 $arrayofstatus = array();
919 $langs->load("ticket");
920 $arrayofstatus['openall'] = array('id' => 'openall', 'labelhtml' => '<b>-- '.$langs->trans('OpenAll').'</b>', 'label' => '-- '.$langs->trans('OpenAll'));
921 foreach ($object->labelStatusShort as $key2 => $val2) {
922 if ($key2 == Ticket::STATUS_CLOSED) {
923 $arrayofstatus['closeall'] = array('id' => 'closeall', 'labelhtml' => '<b>-- '.$langs->trans('ClosedAll').'</b>', 'label' => '-- '.$langs->trans('ClosedAll'));
924 }
925 $arrayofstatus[$key2] = array('id' => $key2, 'labelhtml' => $val2, 'label' => $val2);
926 }
927 print '<td class="liste_titre center parentonrightofpage'.($cssforfield ? ' '.$cssforfield : '').'">';
928 //var_dump($arrayofstatus);
929 //var_dump($search['fk_statut']);
930 //var_dump(array_values($search[$key]));
931 $selectedarray = null;
932 if (!empty($search[$key])) {
933 if (is_array($search[$key])) {
934 $selectedarray = array_values($search[$key]);
935 } else {
936 $selectedarray = array($search[$key]); // Compatibility with "Default search filters"
937 }
938 }
939 print Form::multiselectarray('search_fk_statut', $arrayofstatus, $selectedarray, 0, 0, 'search_status width150 onrightofpage', 1, 0, '', '', '');
940 print '</td>';
941 } elseif ($key == "fk_soc") {
942 print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'"><input type="text" class="flat maxwidth75" name="search_societe" value="'.dol_escape_htmltag($search_societe).'"></td>';
943 } elseif ($key == "datec" || $key == 'date_read' || $key == 'date_close') {
944 print '<td class="liste_titre center">';
945 print '<div class="nowrap">';
946 switch ($key) {
947 case 'datec':
948 print $form->selectDate($search_date_start ?: -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
949 break;
950 case 'date_read':
951 print $form->selectDate($search_dateread_start ?: -1, 'search_dateread_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
952 break;
953 case 'date_close':
954 print $form->selectDate($search_dateclose_start ?: -1, 'search_dateclose_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"));
955 }
956 print '</div>';
957 print '<div class="nowrap">';
958 switch ($key) {
959 case 'datec':
960 print $form->selectDate($search_date_end ?: -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
961 break;
962 case 'date_read':
963 print $form->selectDate($search_dateread_end ?: -1, 'search_dateread_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
964 break;
965 case 'date_close':
966 print $form->selectDate($search_dateclose_end ?: -1, 'search_dateclose_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
967 }
968 print '</div>';
969 print '</td>';
970 } else {
971 print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
972 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
973 print $form->selectarray('search_'.$key, $val['arrayofkeyval'], $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
974 } elseif (strpos($val['type'], 'integer:') === 0) {
975 print $object->showInputField($val, $key, !empty($search[$key]) ? $search[$key] : "", '', '', 'search_', 'maxwidth150', 1);
976 } elseif (!preg_match('/^(date|timestamp)/', $val['type'])) {
977 print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(empty($search[$key]) ? '' : $search[$key]).'">';
978 }
979 print '</td>';
980 }
981 }
982 if ($key == 'fk_soc' && !empty($arrayfields['s.name_alias']['checked'])) {
983 print '<td class="liste_titre"><input type="text" class="flat maxwidth75" name="search_alias" value="'.dolPrintHTMLForAttribute($search_alias).'"></td>';
984 }
985}
986// Extra fields
987include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
988
989// Fields from hook
990$parameters = array('arrayfields' => $arrayfields);
991$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
992print $hookmanager->resPrint;
993// Action column
994if (!$conf->main_checkbox_left_column) {
995 print '<td class="liste_titre center maxwidthsearch">';
996 $searchpicto = $form->showFilterButtons();
997 print $searchpicto;
998 print '</td>';
999}
1000print '</tr>'."\n";
1001
1002$totalarray = array();
1003$totalarray['nbfield'] = 0;
1004
1005// Fields title label
1006// --------------------------------------------------------------------
1007print '<tr class="liste_titre">';
1008if ($conf->main_checkbox_left_column) {
1009 print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
1010 $totalarray['nbfield']++;
1011}
1012foreach ($object->fields as $key => $val) {
1013 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
1014 if ($key == 'fk_statut' || $key == 'severity_code') {
1015 $cssforfield .= ($cssforfield ? ' ' : '').'center';
1016 } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
1017 $cssforfield .= ($cssforfield ? ' ' : '').'center';
1018 } elseif (in_array($val['type'], array('timestamp'))) {
1019 $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
1020 } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('id', 'rowid', 'ref', 'status')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
1021 $cssforfield .= ($cssforfield ? ' ' : '').'right';
1022 }
1023 $cssforfield = preg_replace('/small\s*/', '', $cssforfield); // the 'small' css must not be used for the title label
1024 if (!empty($arrayfields['t.'.$key]['checked'])) {
1025 print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''), 0, (empty($val['helplist']) ? '' : $val['helplist']))."\n";
1026 $totalarray['nbfield']++;
1027 }
1028 if ($key == 'fk_soc' && !empty($arrayfields['s.name_alias']['checked'])) {
1029 print getTitleFieldOfList($arrayfields['s.name_alias']['label'], 0, $_SERVER['PHP_SELF'], 's.name_alias', '', $param, '', $sortfield, $sortorder)."\n";
1030 $totalarray['nbfield']++;
1031 }
1032}
1033// Extra fields
1034include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1035// Hook fields
1036$parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder, 'totalarray' => &$totalarray);
1037$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1038print $hookmanager->resPrint;
1039if (!$conf->main_checkbox_left_column) {
1040 print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
1041 $totalarray['nbfield']++;
1042}
1043print '</tr>'."\n";
1044
1045
1046// Detect if we need a fetch on each output line
1047$needToFetchEachLine = 0;
1048if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
1049 foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
1050 if (!is_null($val) && preg_match('/\$object/', $val)) {
1051 $needToFetchEachLine++; // There is at least one compute field that use $object
1052 }
1053 }
1054}
1055
1056
1057// Loop on record
1058// --------------------------------------------------------------------
1059$i = 0;
1060$savnbfield = $totalarray['nbfield'];
1061$totalarray = array();
1062$totalarray['nbfield'] = 0;
1063$imaxinloop = ($limit ? min($num, $limit) : $num);
1064$cacheofoutputfield = array();
1065while ($i < $imaxinloop) {
1066 $obj = $db->fetch_object($resql);
1067 if (empty($obj)) {
1068 break; // Should not happen
1069 }
1070
1071 // Store properties in $object
1072 $object->setVarsFromFetchObj($obj);
1073 $object->type_code = $obj->type_code;
1074 $object->status = $object->fk_statut; // because field name is fk_statut
1075
1076 if ($mode == 'kanban') {
1077 if ($i == 0) {
1078 print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
1079 print '<div class="box-flex-container kanban">';
1080 }
1081
1082 // get infos needed from object
1083 // TODO Create a cache on users
1084 $arraydata = array();
1085 if ($obj->fk_user_assign > 0) {
1086 $user_temp->fetch($obj->fk_user_assign);
1087 $arraydata['user_assignment'] = $user_temp->getNomUrl(-3);
1088 }
1089 $arraydata['selected'] = in_array($object->id, $arrayofselected);
1090
1091 // Output Kanban
1092 print $object->getKanbanView('', $arraydata);
1093 if ($i == ($imaxinloop - 1)) {
1094 print '</div>';
1095 print '</td></tr>';
1096 }
1097 } else {
1098 // Show line of result
1099 $j = 0;
1100 print '<tr data-rowid="'.$object->id.'" class="oddeven row-with-select">';
1101
1102 // Action column
1103 if ($conf->main_checkbox_left_column) {
1104 print '<td class="nowrap center">';
1105 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1106 $selected = 0;
1107 if (in_array($object->id, $arrayofselected)) {
1108 $selected = 1;
1109 }
1110 print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
1111 }
1112 print '</td>';
1113 if (!$i) {
1114 $totalarray['nbfield']++;
1115 }
1116 }
1117 // Fields
1118 foreach ($object->fields as $key => $val) {
1119 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
1120 if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
1121 $cssforfield .= ($cssforfield ? ' ' : '').'center';
1122 }
1123
1124 if (in_array($val['type'], array('timestamp'))) {
1125 $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
1126 }
1127 if (in_array($key, array('ref', 'fk_project'))) {
1128 $cssforfield .= ($cssforfield ? ' ' : '').'nowraponall';
1129 }
1130 if (in_array($key, array('subject'))) {
1131 $cssforfield = 'minwidth200 tdoverflowbydiv';
1132 }
1133
1134 if ($key == 'fk_statut' || $key == 'severity_code') {
1135 $cssforfield .= ($cssforfield ? ' ' : '').'center';
1136 }
1137 if (!empty($arrayfields['t.'.$key]['checked'])) {
1138 print '<td'.($cssforfield ? ' class="'.$cssforfield.((preg_match('/tdoverflow/', $cssforfield) && !in_array($val['type'], array('ip', 'url')) && !is_numeric($object->$key)) ? ' classfortooltip' : '').'"' : '');
1139 if (preg_match('/tdoverflow/', $cssforfield) && !in_array($val['type'], array('ip', 'url')) && !is_numeric($object->$key)) {
1140 print ' title="'.dolPrintHTMLForAttribute((string) $object->$key).'"';
1141 }
1142 print '>';
1143 if ($key == 'fk_statut') {
1144 print $object->getLibStatut(5);
1145 } elseif ($key == 'subject') {
1146 print '<div class="small twolinesmax lineheightsmall minwidth150 maxwidth250 classfortooltip">';
1147 print dolPrintHTML($obj->subject);
1148 print '</div>';
1149 } elseif ($key == 'type_code') {
1150 $s = $langs->getLabelFromKey($db, 'TicketTypeShort'.$object->type_code, 'c_ticket_type', 'code', 'label', $object->type_code);
1151 print '<span title="'.dolPrintHTMLForAttribute($s).'">';
1152 print $s;
1153 print '</span>';
1154 } elseif ($key == 'category_code') {
1155 $s = $langs->getLabelFromKey($db, 'TicketCategoryShort'.$object->category_code, 'c_ticket_category', 'code', 'label', $object->category_code);
1156 print '<span title="'.dolPrintHTMLForAttribute($s).'">';
1157 print $s;
1158 print '</span>';
1159 } elseif ($key == 'severity_code') {
1160 $s = $langs->getLabelFromKey($db, 'TicketSeverityShort'.$object->severity_code, 'c_ticket_severity', 'code', 'label', $object->severity_code);
1161 print '<span title="'.dolPrintHTMLForAttribute($s).'">';
1162 print $s;
1163 print '</span>';
1164 } elseif ($key == 'tms') {
1165 print dol_print_date($db->jdate($obj->$key), 'dayhour', 'tzuser');
1166 } elseif ($key == 'fk_user_create') {
1167 if ($object->fk_user_create > 0) {
1168 if (isset($conf->cache['user'][$object->fk_user_create])) {
1169 $user_temp = $conf->cache['user'][$object->fk_user_create];
1170 } else {
1171 $user_temp = new User($db);
1172 $user_temp->fetch($object->fk_user_create);
1173 $conf->cache['user'][$object->fk_user_create] = $user_temp;
1174 }
1175 print $user_temp->getNomUrl(-1);
1176 }
1177 } elseif ($key == 'fk_user_assign') {
1178 if ($object->fk_user_assign > 0) {
1179 if (isset($conf->cache['user'][$object->fk_user_assign])) {
1180 $user_temp = $conf->cache['user'][$object->fk_user_assign];
1181 } else {
1182 $user_temp = new User($db);
1183 $user_temp->fetch($object->fk_user_assign);
1184 $conf->cache['user'][$object->fk_user_assign] = $user_temp;
1185 }
1186 print $user_temp->getNomUrl(-1);
1187 }
1188 } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
1189 print $object->showOutputField($val, $key, $db->jdate($obj->$key), '');
1190 } elseif ($key == 'ref') {
1191 print $object->showOutputField($val, $key, $obj->$key, '');
1192
1193 // display a warning on untreated tickets
1194 $is_open = ($object->status != Ticket::STATUS_CLOSED && $object->status != Ticket::STATUS_CANCELED);
1195 $should_show_warning = (getDolGlobalString('TICKET_DELAY_SINCE_LAST_RESPONSE') || getDolGlobalString('TICKET_DELAY_BEFORE_FIRST_RESPONSE'));
1196 if ($is_open && $should_show_warning) {
1197 $date_last_msg_sent = (int) $object->date_last_msg_sent;
1198 $hour_diff = ($now - $date_last_msg_sent) / 3600 ;
1199
1200 if (getDolGlobalString('TICKET_DELAY_BEFORE_FIRST_RESPONSE') && $date_last_msg_sent == 0) {
1201 $creation_date = $object->datec;
1202 $hour_diff_creation = ($now - $creation_date) / 3600 ;
1203 if ($hour_diff_creation > getDolGlobalInt('TICKET_DELAY_BEFORE_FIRST_RESPONSE')) {
1204 print " " . img_picto($langs->trans('Late') . ' : ' . $langs->trans('TicketsDelayForFirstResponseTooLong', getDolGlobalString('TICKET_DELAY_BEFORE_FIRST_RESPONSE')), 'warning', 'style="color: red;"', 0, 0, 0, '', '');
1205 }
1206 } elseif (getDolGlobalString('TICKET_DELAY_SINCE_LAST_RESPONSE') && $hour_diff > getDolGlobalInt('TICKET_DELAY_SINCE_LAST_RESPONSE')) {
1207 print " " . img_picto($langs->trans('Late') . ' : ' . $langs->trans('TicketsDelayFromLastResponseTooLong', getDolGlobalString('TICKET_DELAY_SINCE_LAST_RESPONSE')), 'warning');
1208 }
1209 }
1210 } else { // Example: key=fk_soc, obj->key=123 val=array('type'=>'integer', ...
1211 $tmp = explode(':', $val['type']);
1212 if ($tmp[0] == 'integer' && !empty($tmp[1]) && class_exists($tmp[1])) {
1213 // It is a type of an foreign field. We will try to reduce the number of fetch that the showOutputField is making.
1214 //var_dump('eeee-'.$key.'-'.$obj->$key.'-'.$val['type']);
1215 if ($key && $obj->$key && $val['type'] && array_key_exists($key.'-'.$obj->$key.'-'.$val['type'], $cacheofoutputfield)) {
1216 $result = $cacheofoutputfield[$key.'-'.$obj->$key.'-'.$val['type']];
1217 } else {
1218 $result = $object->showOutputField($val, $key, $obj->$key, '');
1219 $cacheofoutputfield[$key.'-'.$obj->$key.'-'.$val['type']] = $result;
1220 }
1221 } else {
1222 $result = $object->showOutputField($val, $key, $obj->$key, '');
1223 }
1224 print $result;
1225 }
1226
1227 print '</td>';
1228 if (!$i) {
1229 $totalarray['nbfield']++;
1230 }
1231 if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
1232 if (!$i) {
1233 $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
1234 }
1235 if (!isset($totalarray['val'])) {
1236 $totalarray['val'] = array();
1237 }
1238 if (!isset($totalarray['val']['t.'.$key])) {
1239 $totalarray['val']['t.'.$key] = 0;
1240 }
1241 $totalarray['val']['t.'.$key] += $object->$key;
1242 }
1243 }
1244 if ($key == 'fk_soc' && !empty($arrayfields['s.name_alias']['checked'])) {
1245 print '<td class="tdoverflowmax150" title="'.dolPrintHTMLForAttribute($obj->thirdparty_alias).'">';
1246 print '<span class="spantitle">'.dolPrintHTML($obj->thirdparty_alias).'</span>';
1247 print '</td>';
1248 if (!$i) {
1249 $totalarray['nbfield']++;
1250 }
1251 }
1252 }
1253 // Extra fields
1254 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1255 // Fields from hook
1256 $parameters = array('arrayfields' => $arrayfields, 'object' => $object, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
1257 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1258 print $hookmanager->resPrint;
1259
1260 // Action column
1261 if (!$conf->main_checkbox_left_column) {
1262 print '<td class="nowrap center">';
1263 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1264 $selected = 0;
1265 if (in_array($object->id, $arrayofselected)) {
1266 $selected = 1;
1267 }
1268 print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
1269 }
1270 print '</td>';
1271 if (!$i) {
1272 $totalarray['nbfield']++;
1273 }
1274 }
1275
1276 print '</tr>'."\n";
1277 }
1278
1279 $i++;
1280}
1281
1282// Show total line
1283include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
1284
1285
1286// If no record found
1287if ($num == 0) {
1288 $colspan = 1;
1289 foreach ($arrayfields as $key => $val) {
1290 if (!empty($val['checked'])) {
1291 $colspan++;
1292 }
1293 }
1294 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1295}
1296
1297
1298$db->free($resql);
1299
1300$parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
1301$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
1302print $hookmanager->resPrint;
1303
1304print '</table>'."\n";
1305print '</div>'."\n";
1306print '</div>'."\n"; // end div-responsive-inside
1307
1308print '</form>'."\n";
1309
1310
1311
1312if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
1313 $hidegeneratedfilelistifempty = 1;
1314 if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
1315 $hidegeneratedfilelistifempty = 0;
1316 }
1317
1318 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
1319 $formfile = new FormFile($db);
1320
1321 // Show list of available documents
1322 $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
1323 $urlsource .= str_replace('&amp;', '&', $param);
1324
1325 $filedir = $diroutputmassaction;
1326 $genallowed = $permissiontoread;
1327 $delallowed = $permissiontoadd;
1328
1329 print $formfile->showdocuments('massfilesarea_ticket', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
1330}
1331
1332// End of page
1333llxFooter();
1334$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage standard extra fields.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
static multiselectarray($htmlname, $array, $selected=array(), $key_in_label=0, $value_as_key=0, $morecss='', $translate=0, $width=0, $moreattrib='', $nu='', $placeholder='', $addjscombo=-1)
Show a multiselect form from an array.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
const STATUS_NOT_READ
Status.
Class to manage Dolibarr users.
societe_prepare_head(Societe $object, $subtabs='')
Return array of tabs to used on pages for third parties cards.
dol_now($mode='gmt')
Return date for now.
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...
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
GETPOSTISARRAY($paramname, $method=0)
Return true if the parameter $paramname is submit from a POST OR GET as an array.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:542
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.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
dolGetButtonTitleSeparator($moreClass="")
Add space between dolGetButtonTitle.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183
Class to generate the form for creating a new ticket.
project_prepare_head(Project $project, $moreparam='')
Prepare array with list of tabs.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.