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