dolibarr  17.0.4
target_list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) ---Put here your own copyright and developer email---
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
25 // Load Dolibarr environment
26 require '../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
30 
31 // load webhook libraries
32 require_once DOL_DOCUMENT_ROOT.'/webhook/class/target.class.php';
33 
34 // for other modules
35 //dol_include_once('/othermodule/class/otherobject.class.php');
36 
37 // Load translation files required by the page
38 $langs->loadLangs(array('other'));
39 
40 // Get Parameters
41 $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
42 $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
43 $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
44 $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
45 $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
46 $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
47 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'targetlist'; // To manage different context of search
48 $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
49 $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
50 $mode = GETPOST('mode', 'aZ');
51 if (empty($mode)) {
52  $mode = 'modulesetup';
53 }
54 
55 $id = GETPOST('id', 'int');
56 
57 // Load variable for pagination
58 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
59 $sortfield = GETPOST('sortfield', 'aZ09comma');
60 $sortorder = GETPOST('sortorder', 'aZ09comma');
61 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
62 if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
63  // If $page is not defined, or '' or -1 or if we click on clear filters
64  $page = 0;
65 }
66 $offset = $limit * $page;
67 $pageprev = $page - 1;
68 $pagenext = $page + 1;
69 
70 // Initialize technical objects
71 $object = new Target($db);
72 $extrafields = new ExtraFields($db);
73 $diroutputmassaction = $conf->webhook->dir_output.'/temp/massgeneration/'.$user->id;
74 $hookmanager->initHooks(array('targetlist')); // Note that conf->hooks_modules contains array
75 
76 // Fetch optionals attributes and labels
77 $extrafields->fetch_name_optionals_label($object->table_element);
78 //$extrafields->fetch_name_optionals_label($object->table_element_line);
79 
80 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
81 
82 // Default sort order (if not yet defined by previous GETPOST)
83 if (!$sortfield) {
84  reset($object->fields); // Reset is required to avoid key() to return null.
85  $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
86 }
87 if (!$sortorder) {
88  $sortorder = "ASC";
89 }
90 
91 // Initialize array of search criterias
92 $search_all = GETPOST('search_all', 'alphanohtml');
93 $search = array();
94 foreach ($object->fields as $key => $val) {
95  if (GETPOST('search_'.$key, 'alpha') !== '') {
96  $search[$key] = GETPOST('search_'.$key, 'alpha');
97  }
98  if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
99  $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int'));
100  $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int'));
101  }
102 }
103 
104 // List of fields to search into when doing a "search in all"
105 $fieldstosearchall = array();
106 foreach ($object->fields as $key => $val) {
107  if (!empty($val['searchall'])) {
108  $fieldstosearchall['t.'.$key] = $val['label'];
109  }
110 }
111 
112 // Definition of array of fields for columns
113 $arrayfields = array();
114 foreach ($object->fields as $key => $val) {
115  // If $val['visible']==0, then we never show the field
116  if (!empty($val['visible'])) {
117  $visible = (int) dol_eval($val['visible'], 1);
118  $arrayfields['t.'.$key] = array(
119  'label'=>$val['label'],
120  'checked'=>(($visible < 0) ? 0 : 1),
121  'enabled'=>(abs($visible) != 3 && dol_eval($val['enabled'], 1)),
122  'position'=>$val['position'],
123  'help'=> isset($val['help']) ? $val['help'] : ''
124  );
125  }
126 }
127 
128 // Extra fields
129 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
130 
131 $object->fields = dol_sort_array($object->fields, 'position');
132 //$arrayfields['anotherfield'] = array('type'=>'integer', 'label'=>'AnotherField', 'checked'=>1, 'enabled'=>1, 'position'=>90, 'csslist'=>'right');
133 $arrayfields = dol_sort_array($arrayfields, 'position');
134 
135 // Permissions
136 // There is several ways to check permission.
137 // Set $enablepermissioncheck to 1 to enable a minimum low level of checks
138 $enablepermissioncheck = 0;
139 if ($enablepermissioncheck) {
140  $permissiontoread = $user->rights->webhook->target->read;
141  $permissiontoadd = $user->rights->webhook->target->write;
142  $permissiontodelete = $user->rights->webhook->target->delete;
143 } else {
144  $permissiontoread = 1;
145  $permissiontoadd = 1;
146  $permissiontodelete = 1;
147 }
148 
149 // Security check (enable the most restrictive one)
150 if ($user->socid > 0) accessforbidden();
151 //if ($user->socid > 0) accessforbidden();
152 //$socid = 0; if ($user->socid > 0) $socid = $user->socid;
153 //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
154 //restrictedArea($user, $object->element, 0, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
155 if (empty($conf->webhook->enabled)) accessforbidden('Module not enabled');
156 if (!$permissiontoread) accessforbidden();
157 
158 
159 /*
160  * Actions
161  */
162 
163 if (GETPOST('cancel', 'alpha')) {
164  $action = 'list';
165  $massaction = '';
166 }
167 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
168  $massaction = '';
169 }
170 
171 $parameters = array();
172 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
173 if ($reshook < 0) {
174  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
175 }
176 
177 if (empty($reshook)) {
178  // Selection of new fields
179  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
180 
181  // Purge search criteria
182  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
183  foreach ($object->fields as $key => $val) {
184  $search[$key] = '';
185  if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
186  $search[$key.'_dtstart'] = '';
187  $search[$key.'_dtend'] = '';
188  }
189  }
190  $toselect = array();
191  $search_array_options = array();
192  }
193  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
194  || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
195  $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
196  }
197 
198  // Mass actions
199  $objectclass = 'Target';
200  $objectlabel = 'Target';
201  $uploaddir = $conf->webhook->dir_output;
202  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
203 }
204 
205 
206 
207 /*
208  * View
209  */
210 
211 $form = new Form($db);
212 
213 $now = dol_now();
214 //$help_url = "EN:Module_Target|FR:Module_Target_FR|ES:Módulo_Target";
215 $help_url = '';
216 $title = $langs->trans('ListOf', $langs->transnoentitiesnoconv("Targets"));
217 
218 $morejs = array();
219 $morecss = array();
220 
221 // Build and execute select
222 // --------------------------------------------------------------------
223 $sql = 'SELECT ';
224 $sql .= $object->getFieldList('t');
225 // Add fields from extrafields
226 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
227  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
228  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
229  }
230 }
231 // Add fields from hooks
232 $parameters = array();
233 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
234 $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
235 $sql = preg_replace('/,\s*$/', '', $sql);
236 //$sql .= ", COUNT(rc.rowid) as anotherfield";
237 $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
238 //$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."anothertable as rc ON rc.parent = t.rowid";
239 if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
240  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
241 }
242 // Add table from hooks
243 $parameters = array();
244 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
245 $sql .= $hookmanager->resPrint;
246 if ($object->ismultientitymanaged == 1) {
247  $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
248 } else {
249  $sql .= " WHERE 1 = 1";
250 }
251 foreach ($search as $key => $val) {
252  if (array_key_exists($key, $object->fields)) {
253  if ($key == 'status' && $search[$key] == -1) {
254  continue;
255  }
256  $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
257  if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
258  if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
259  $search[$key] = '';
260  }
261  $mode_search = 2;
262  }
263  if ($search[$key] != '') {
264  $sql .= natural_search("t.".$db->escape($key), $search[$key], (($key == 'status') ? 2 : $mode_search));
265  }
266  } else {
267  if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
268  $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
269  if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
270  if (preg_match('/_dtstart$/', $key)) {
271  $sql .= " AND t.".$db->escape($columnName)." >= '".$db->idate($search[$key])."'";
272  }
273  if (preg_match('/_dtend$/', $key)) {
274  $sql .= " AND t.".$db->escape($columnName)." <= '".$db->idate($search[$key])."'";
275  }
276  }
277  }
278  }
279 }
280 if ($search_all) {
281  $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
282 }
283 //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
284 // Add where from extra fields
285 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
286 // Add where from hooks
287 $parameters = array();
288 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
289 $sql .= $hookmanager->resPrint;
290 
291 /* If a group by is required
292 $sql .= " GROUP BY ";
293 foreach($object->fields as $key => $val) {
294  $sql .= "t.".$db->escape($key).", ";
295 }
296 // Add fields from extrafields
297 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
298  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
299  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
300  }
301 }
302 // Add where from hooks
303 $parameters = array();
304 $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
305 $sql .= $hookmanager->resPrint;
306 $sql = preg_replace('/,\s*$/', '', $sql);
307 */
308 
309 // Add HAVING from hooks
310 /*
311 $parameters = array();
312 $reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object); // Note that $action and $object may have been modified by hook
313 $sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint;
314 */
315 
316 // Count total nb of records
317 $nbtotalofrecords = '';
318 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
319  /* This old and fast method to get and count full list returns all record so use a high amount of memory.
320  $resql = $db->query($sql);
321  $nbtotalofrecords = $db->num_rows($resql);
322  */
323  /* The slow method does not consume memory on mysql (not tested on pgsql) */
324  /*$resql = $db->query($sql, 0, 'auto', 1);
325  while ($db->fetch_object($resql)) {
326  if (empty($nbtotalofrecords)) {
327  $nbtotalofrecords = 1; // We can't make +1 because init value is ''
328  } else {
329  $nbtotalofrecords++;
330  }
331  }*/
332  /* The fast and low memory method to get and count full list converts the sql into a sql count */
333  $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\‍(\‍),=<>\:\-\']+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql);
334  $resql = $db->query($sqlforcount);
335  $objforcount = $db->fetch_object($resql);
336  $nbtotalofrecords = $objforcount->nbtotalofrecords;
337 
338  if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
339  $page = 0;
340  $offset = 0;
341  }
342  $db->free($resql);
343 }
344 
345 // Complete request and execute it with limit
346 $sql .= $db->order($sortfield, $sortorder);
347 if ($limit) {
348  $sql .= $db->plimit($limit + 1, $offset);
349 }
350 
351 $resql = $db->query($sql);
352 if (!$resql) {
353  dol_print_error($db);
354  exit;
355 }
356 
357 $num = $db->num_rows($resql);
358 
359 
360 // Direct jump if only one record found
361 if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
362  $obj = $db->fetch_object($resql);
363  $id = $obj->rowid;
364  header("Location: ".dol_buildpath('/webhook/target_card.php', 1).'?id='.$id);
365  exit;
366 }
367 
368 
369 // Output page
370 // --------------------------------------------------------------------
371 $title = $langs->trans("Targets");
372 llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', '');
373 
374 if ($mode == 'modulesetup') {
375  require_once 'lib/webhook.lib.php';
376 
377  $help_url = '';
378  $page_name = "WebhookSetup";
379  // Subheader
380  $linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
381  print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup');
382 
383  $head = webhookAdminPrepareHead();
384  print dol_get_fiche_head($head, 'targets', $langs->trans($page_name), -1, "webhook");
385 }
386 
387 // Example : Adding jquery code
388 // print '<script type="text/javascript">
389 // jQuery(document).ready(function() {
390 // function init_myfunc()
391 // {
392 // jQuery("#myid").removeAttr(\'disabled\');
393 // jQuery("#myid").attr(\'disabled\',\'disabled\');
394 // }
395 // init_myfunc();
396 // jQuery("#mybutton").click(function() {
397 // init_myfunc();
398 // });
399 // });
400 // </script>';
401 
402 $arrayofselected = is_array($toselect) ? $toselect : array();
403 
404 $param = '';
405 if (!empty($mode)) {
406  $param .= '&mode='.urlencode($mode);
407 }
408 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
409  $param .= '&contextpage='.urlencode($contextpage);
410 }
411 if ($limit > 0 && $limit != $conf->liste_limit) {
412  $param .= '&limit='.urlencode($limit);
413 }
414 foreach ($search as $key => $val) {
415  if (is_array($search[$key]) && count($search[$key])) {
416  foreach ($search[$key] as $skey) {
417  if ($skey != '') {
418  $param .= '&search_'.$key.'[]='.urlencode($skey);
419  }
420  }
421  } elseif ($search[$key] != '') {
422  $param .= '&search_'.$key.'='.urlencode($search[$key]);
423  }
424 }
425 if ($optioncss != '') {
426  $param .= '&optioncss='.urlencode($optioncss);
427 }
428 // Add $param from extra fields
429 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
430 // Add $param from hooks
431 $parameters = array();
432 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
433 $param .= $hookmanager->resPrint;
434 
435 // List of mass actions available
436 $arrayofmassactions = array(
437  //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
438  //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
439  //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
440  //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
441 );
442 if ($permissiontodelete) {
443  $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
444 }
445 if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
446  $arrayofmassactions = array();
447 }
448 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
449 
450 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
451 if ($optioncss != '') {
452  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
453 }
454 print '<input type="hidden" name="token" value="'.newToken().'">';
455 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
456 print '<input type="hidden" name="action" value="list">';
457 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
458 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
459 print '<input type="hidden" name="page" value="'.$page.'">';
460 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
461 print '<input type="hidden" name="mode" value="'.$mode.'">';
462 
463 
464 $newcardbutton = '';
465 //$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'));
466 //$newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-list-alt imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/^&mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss'=>'reposition'));
467 //$newcardbutton .= dolGetButtonTitleSeparator();
468 $newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/webhook/target_card.php', 1).'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']).'?mode=modulesetup', '', $permissiontoadd);
469 
470 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, "", 0, $newcardbutton, '', $limit, 0, 0, 1);
471 
472 // Add code for pre mass action (confirmation or email presend form)
473 $topicmail = "SendTargetRef";
474 $modelmail = "target";
475 $objecttmp = new Target($db);
476 $trackid = 'xxxx'.$object->id;
477 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
478 
479 if ($search_all) {
480  foreach ($fieldstosearchall as $key => $val) {
481  $fieldstosearchall[$key] = $langs->trans($val);
482  }
483  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
484 }
485 
486 $moreforfilter = '';
487 /*$moreforfilter.='<div class="divsearchfield">';
488 $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
489 $moreforfilter.= '</div>';*/
490 
491 $parameters = array();
492 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
493 if (empty($reshook)) {
494  $moreforfilter .= $hookmanager->resPrint;
495 } else {
496  $moreforfilter = $hookmanager->resPrint;
497 }
498 
499 if (!empty($moreforfilter)) {
500  print '<div class="liste_titre liste_titre_bydiv centpercent">';
501  print $moreforfilter;
502  print '</div>';
503 }
504 
505 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
506 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
507 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
508 
509 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
510 print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
511 
512 
513 // Fields title search
514 // --------------------------------------------------------------------
515 print '<tr class="liste_titre">';
516 foreach ($object->fields as $key => $val) {
517  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
518  if ($key == 'status') {
519  $cssforfield .= ($cssforfield ? ' ' : '').'center';
520  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
521  $cssforfield .= ($cssforfield ? ' ' : '').'center';
522  } elseif (in_array($val['type'], array('timestamp'))) {
523  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
524  } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
525  $cssforfield .= ($cssforfield ? ' ' : '').'right';
526  }
527  if (!empty($arrayfields['t.'.$key]['checked'])) {
528  print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
529  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
530  print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
531  } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
532  print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', 'maxwidth125', 1);
533  } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
534  print '<div class="nowrap">';
535  print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
536  print '</div>';
537  print '<div class="nowrap">';
538  print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
539  print '</div>';
540  } elseif ($key == 'lang') {
541  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
542  $formadmin = new FormAdmin($db);
543  print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth150 maxwidth200', 2);
544  } else {
545  print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
546  }
547  print '</td>';
548  }
549 }
550 // Extra fields
551 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
552 
553 // Fields from hook
554 $parameters = array('arrayfields'=>$arrayfields);
555 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
556 print $hookmanager->resPrint;
557 /*if (!empty($arrayfields['anotherfield']['checked'])) {
558  print '<td class="liste_titre"></td>';
559 }*/
560 // Action column
561 print '<td class="liste_titre maxwidthsearch">';
562 $searchpicto = $form->showFilterButtons();
563 print $searchpicto;
564 print '</td>';
565 print '</tr>'."\n";
566 
567 $totalarray = array();
568 $totalarray['nbfield'] = 0;
569 
570 // Fields title label
571 // --------------------------------------------------------------------
572 print '<tr class="liste_titre">';
573 foreach ($object->fields as $key => $val) {
574  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
575  if ($key == 'status') {
576  $cssforfield .= ($cssforfield ? ' ' : '').'center';
577  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
578  $cssforfield .= ($cssforfield ? ' ' : '').'center';
579  } elseif (in_array($val['type'], array('timestamp'))) {
580  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
581  } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
582  $cssforfield .= ($cssforfield ? ' ' : '').'right';
583  }
584  if (!empty($arrayfields['t.'.$key]['checked'])) {
585  print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
586  $totalarray['nbfield']++;
587  }
588 }
589 // Extra fields
590 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
591 // Hook fields
592 $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray);
593 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
594 print $hookmanager->resPrint;
595 /*if (!empty($arrayfields['anotherfield']['checked'])) {
596  print '<th class="liste_titre right">'.$langs->trans("AnotherField").'</th>';
597  $totalarray['nbfield']++;
598 }*/
599 // Action column
600 print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
601 $totalarray['nbfield']++;
602 print '</tr>'."\n";
603 
604 
605 // Detect if we need a fetch on each output line
606 $needToFetchEachLine = 0;
607 if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
608  foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
609  if (preg_match('/\$object/', $val)) {
610  $needToFetchEachLine++; // There is at least one compute field that use $object
611  }
612  }
613 }
614 
615 
616 // Loop on record
617 // --------------------------------------------------------------------
618 $i = 0;
619 $savnbfield = $totalarray['nbfield'];
620 $totalarray['nbfield'] = 0;
621 $imaxinloop = ($limit ? min($num, $limit) : $num);
622 while ($i < $imaxinloop) {
623  $obj = $db->fetch_object($resql);
624  if (empty($obj)) {
625  break; // Should not happen
626  }
627 
628  if (empty($obj->ref)) {
629  $obj->ref = $obj->rowid;
630  }
631 
632  // Store properties in $object
633  $object->setVarsFromFetchObj($obj);
634 
635  if ($mode == 'kanban') {
636  if ($i == 0) {
637  print '<tr><td colspan="'.$savnbfield.'">';
638  print '<div class="box-flex-container">';
639  }
640  // Output Kanban
641  print $object->getKanbanView('');
642  if ($i == ($imaxinloop - 1)) {
643  print '</div>';
644  print '</td></tr>';
645  }
646  } else {
647  // Show here line of result
648  $j = 0;
649  print '<tr data-rowid="'.$object->id.'" class="oddeven">';
650  foreach ($object->fields as $key => $val) {
651  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
652  if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
653  $cssforfield .= ($cssforfield ? ' ' : '').'center';
654  } elseif ($key == 'status') {
655  $cssforfield .= ($cssforfield ? ' ' : '').'center';
656  }
657 
658  if (in_array($val['type'], array('timestamp'))) {
659  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
660  } elseif ($key == 'ref') {
661  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
662  }
663 
664  if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
665  $cssforfield .= ($cssforfield ? ' ' : '').'right';
666  }
667  //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
668 
669  if (!empty($arrayfields['t.'.$key]['checked'])) {
670  print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '').'>';
671  if ($key == 'status') {
672  print $object->getLibStatut(5);
673  } elseif ($key == 'rowid') {
674  print $object->showOutputField($val, $key, $object->id, '');
675  } else {
676  print $object->showOutputField($val, $key, $object->$key, '');
677  }
678  print '</td>';
679  if (!$i) {
680  $totalarray['nbfield']++;
681  }
682  if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
683  if (!$i) {
684  $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
685  }
686  if (!isset($totalarray['val'])) {
687  $totalarray['val'] = array();
688  }
689  if (!isset($totalarray['val']['t.'.$key])) {
690  $totalarray['val']['t.'.$key] = 0;
691  }
692  $totalarray['val']['t.'.$key] += $object->$key;
693  }
694  }
695  }
696  // Extra fields
697  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
698  // Fields from hook
699  $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
700  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
701  print $hookmanager->resPrint;
702  /*if (!empty($arrayfields['anotherfield']['checked'])) {
703  print '<td class="right">'.$obj->anotherfield.'</td>';
704  }*/
705  // Action column
706  print '<td class="nowrap center">';
707  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
708  $selected = 0;
709  if (in_array($object->id, $arrayofselected)) {
710  $selected = 1;
711  }
712  print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
713  }
714  print '</td>';
715  if (!$i) {
716  $totalarray['nbfield']++;
717  }
718 
719  print '</tr>'."\n";
720  }
721 
722  $i++;
723 }
724 
725 // Show total line
726 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
727 
728 // If no record found
729 if ($num == 0) {
730  $colspan = 1;
731  foreach ($arrayfields as $key => $val) {
732  if (!empty($val['checked'])) {
733  $colspan++;
734  }
735  }
736  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
737 }
738 
739 
740 $db->free($resql);
741 
742 $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
743 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
744 print $hookmanager->resPrint;
745 
746 print '</table>'."\n";
747 print '</div>'."\n";
748 
749 print '</form>'."\n";
750 
751 if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
752  $hidegeneratedfilelistifempty = 1;
753  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
754  $hidegeneratedfilelistifempty = 0;
755  }
756 
757  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
758  $formfile = new FormFile($db);
759 
760  // Show list of available documents
761  $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
762  $urlsource .= str_replace('&amp;', '&', $param);
763 
764  $filedir = $diroutputmassaction;
765  $genallowed = $permissiontoread;
766  $delallowed = $permissiontoadd;
767 
768  print $formfile->showdocuments('massfilesarea_webhook', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
769 }
770 
771 // End of page
772 llxFooter();
773 $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 generate html code for admin pages.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class for Target.
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_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...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
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.
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_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.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
$nbtotalofrecords
Count total nb of records.
Definition: list.php:329
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
webhookAdminPrepareHead()
Prepare admin pages header.
Definition: webhook.lib.php:29