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