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