dolibarr  16.0.5
list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
24 // Load Dolibarr environment
25 require '../../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/product/inventory/class/inventory.class.php';
30 
31 // Load translation files required by the page
32 $langs->loadLangs(array("stocks", "other"));
33 
34 $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
35 $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
36 $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
37 $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
38 $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
39 $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
40 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'inventorylist'; // To manage different context of search
41 $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
42 $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
43 
44 $id = GETPOST('id', 'int');
45 
46 // Load variable for pagination
47 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
48 $sortfield = GETPOST('sortfield', 'aZ09comma');
49 $sortorder = GETPOST('sortorder', 'aZ09comma');
50 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
51 if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) {
52  // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
53  $page = 0;
54 }
55 $offset = $limit * $page;
56 $pageprev = $page - 1;
57 $pagenext = $page + 1;
58 
59 // Initialize technical objects
60 $object = new Inventory($db);
61 $extrafields = new ExtraFields($db);
62 // no inventory docs yet
63 // $diroutputmassaction = $conf->inventory->dir_output.'/temp/massgeneration/'.$user->id;
64 $diroutputmassaction = null;
65 $hookmanager->initHooks(array('inventorylist')); // Note that conf->hooks_modules contains array
66 // Fetch optionals attributes and labels
67 $extrafields->fetch_name_optionals_label($object->table_element);
68 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
69 
70 // Default sort order (if not yet defined by previous GETPOST)
71 if (!$sortfield) {
72  reset($object->fields); // Reset is required to avoid key() to return null.
73  $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
74 }
75 if (!$sortorder) {
76  $sortorder = "ASC";
77 }
78 
79 // Initialize array of search criterias
80 $search_all = GETPOST('search_all', 'alphanohtml');
81 $search = array();
82 foreach ($object->fields as $key => $val) {
83  if (GETPOST('search_'.$key, 'alpha') !== '') {
84  $search[$key] = GETPOST('search_'.$key, 'alpha');
85  }
86  if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
87  $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int'));
88  $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int'));
89  }
90 }
91 
92 // List of fields to search into when doing a "search in all"
93 $fieldstosearchall = array();
94 foreach ($object->fields as $key => $val) {
95  if (!empty($val['searchall'])) {
96  $fieldstosearchall['t.'.$key] = $val['label'];
97  }
98 }
99 
100 // Definition of array of fields for columns
101 $arrayfields = array();
102 foreach ($object->fields as $key => $val) {
103  // If $val['visible']==0, then we never show the field
104  if (!empty($val['visible'])) {
105  $visible = (int) dol_eval($val['visible'], 1, 1, '1');
106  $arrayfields['t.'.$key] = array(
107  'label'=>$val['label'],
108  'checked'=>(($visible < 0) ? 0 : 1),
109  'enabled'=>($visible != 3 && dol_eval($val['enabled'], 1, 1, '1')),
110  'position'=>$val['position'],
111  'help'=> isset($val['help']) ? $val['help'] : ''
112  );
113  }
114 }
115 // Extra fields
116 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
117 
118 $object->fields = dol_sort_array($object->fields, 'position');
119 $arrayfields = dol_sort_array($arrayfields, 'position');
120 
121 $permissiontoread = $user->rights->stock->lire;
122 $permissiontoadd = $user->rights->stock->creer;
123 $permissiontodelete = $user->rights->stock->supprimer;
124 
125 // Security check
126 $socid = 0;
127 if ($user->socid > 0) { // Protection if external user
128  //$socid = $user->socid;
129  accessforbidden();
130 }
131 if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
132  $result = restrictedArea($user, 'stock');
133 } else {
134  $result = restrictedArea($user, 'stock', 0, '', 'inventory_advance');
135 }
136 
137 
138 /*
139  * Actions
140  */
141 
142 if (GETPOST('cancel', 'alpha')) {
143  $action = 'list';
144  $massaction = '';
145 }
146 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
147  $massaction = '';
148 }
149 
150 $parameters = array();
151 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
152 if ($reshook < 0) {
153  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
154 }
155 
156 if (empty($reshook)) {
157  // Selection of new fields
158  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
159 
160  // Purge search criteria
161  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
162  foreach ($object->fields as $key => $val) {
163  $search[$key] = '';
164  if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
165  $search[$key.'_dtstart'] = '';
166  $search[$key.'_dtend'] = '';
167  }
168  }
169  $toselect = array();
170  $search_array_options = array();
171  }
172  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
173  || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
174  $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
175  }
176 
177  // Mass actions
178  $objectclass = 'Inventory';
179  $objectlabel = 'Inventory';
180  $uploaddir = $conf->stock->dir_output;
181  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
182 }
183 
184 
185 
186 /*
187  * View
188  */
189 
190 $form = new Form($db);
191 
192 $now = dol_now();
193 
194 //$help_url="EN:Module_Inventory|FR:Module_Inventory_FR|ES:Módulo_Inventory";
195 $help_url = '';
196 $title = $langs->trans('ListOfInventories');
197 $morejs = array();
198 $morecss = array();
199 
200 
201 // Build and execute select
202 // --------------------------------------------------------------------
203 $sql = 'SELECT ';
204 $sql .= $object->getFieldList('t');
205 // Add fields from extrafields
206 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
207  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
208  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
209  }
210 }
211 // Add fields from hooks
212 $parameters = array();
213 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
214 $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
215 $sql = preg_replace('/,\s*$/', '', $sql);
216 $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
217 if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
218  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
219 }
220 // Add table from hooks
221 $parameters = array();
222 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
223 $sql .= $hookmanager->resPrint;
224 if ($object->ismultientitymanaged == 1) {
225  $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
226 } else {
227  $sql .= " WHERE 1 = 1";
228 }
229 foreach ($search as $key => $val) {
230  if (array_key_exists($key, $object->fields)) {
231  if ($key == 'status' && $search[$key] == -1) {
232  continue;
233  }
234  $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
235  if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
236  if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
237  $search[$key] = '';
238  }
239  $mode_search = 2;
240  }
241  if ($search[$key] != '') {
242  $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
243  }
244  } else {
245  if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
246  $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
247  if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
248  if (preg_match('/_dtstart$/', $key)) {
249  $sql .= " AND t.".$columnName." >= '".$db->idate($search[$key])."'";
250  }
251  if (preg_match('/_dtend$/', $key)) {
252  $sql .= " AND t." . $columnName . " <= '" . $db->idate($search[$key]) . "'";
253  }
254  }
255  }
256  }
257 }
258 
259 if ($search_all) {
260  $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
261 }
262 //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
263 // Add where from extra fields
264 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
265 // Add where from hooks
266 $parameters = array();
267 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
268 $sql .= $hookmanager->resPrint;
269 
270 /* If a group by is required
271 $sql.= " GROUP BY ";
272 foreach($object->fields as $key => $val)
273 {
274  $sql .= "t.".$key.", ";
275 }
276 // Add fields from extrafields
277 if (! empty($extrafields->attributes[$object->table_element]['label'])) {
278  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
279 }
280 // Add where from hooks
281 $parameters=array();
282 $reshook=$hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
283 $sql.=$hookmanager->resPrint;
284 $sql=preg_replace('/,\s*$/','', $sql);
285 */
286 
287 $sql .= $db->order($sortfield, $sortorder);
288 
289 // Count total nb of records
290 $nbtotalofrecords = '';
291 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
292  $resql = $db->query($sql);
293  $nbtotalofrecords = $db->num_rows($resql);
294  if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
295  $page = 0;
296  $offset = 0;
297  }
298 }
299 // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
300 if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
301  $num = $nbtotalofrecords;
302 } else {
303  if ($limit) {
304  $sql .= $db->plimit($limit + 1, $offset);
305  }
306 
307  $resql = $db->query($sql);
308  if (!$resql) {
309  dol_print_error($db);
310  exit;
311  }
312 
313  $num = $db->num_rows($resql);
314 }
315 
316 // Direct jump if only one record found
317 if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
318  $obj = $db->fetch_object($resql);
319  $id = $obj->rowid;
320  header("Location: ".DOL_URL_ROOT.'/inventory/card.php?id='.$id);
321  exit;
322 }
323 
324 
325 // Output page
326 // --------------------------------------------------------------------
327 
328 llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'classforhorizontalscrolloftabs');
329 
330 $arrayofselected = is_array($toselect) ? $toselect : array();
331 
332 $param = '';
333 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
334  $param .= '&contextpage='.urlencode($contextpage);
335 }
336 if ($limit > 0 && $limit != $conf->liste_limit) {
337  $param .= '&limit='.urlencode($limit);
338 }
339 foreach ($search as $key => $val) {
340  if (is_array($search[$key]) && count($search[$key])) {
341  foreach ($search[$key] as $skey) {
342  $param .= '&search_'.$key.'[]='.urlencode($skey);
343  }
344  } else {
345  $param .= '&search_'.$key.'='.urlencode($search[$key]);
346  }
347 }
348 if ($optioncss != '') {
349  $param .= '&optioncss='.urlencode($optioncss);
350 }
351 // Add $param from extra fields
352 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
353 // Add $param from hooks
354 $parameters = array();
355 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
356 $param .= $hookmanager->resPrint;
357 
358 // List of mass actions available
359 $arrayofmassactions = array(
360  //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
361  //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
362  //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
363  //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
364 );
365 if ($permissiontodelete) {
366  $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
367 }
368 if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
369  $arrayofmassactions = array();
370 }
371 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
372 
373 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
374 if ($optioncss != '') {
375  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
376 }
377 print '<input type="hidden" name="token" value="'.newToken().'">';
378 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
379 print '<input type="hidden" name="action" value="list">';
380 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
381 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
382 print '<input type="hidden" name="page" value="'.$page.'">';
383 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
384 
385 $newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/product/inventory/card.php?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
386 
387 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
388 
389 // Add code for pre mass action (confirmation or email presend form)
390 $topicmail = "Information";
391 $modelmail = "inventory";
392 $objecttmp = new Inventory($db);
393 $trackid = 'stockinv'.$object->id;
394 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
395 
396 if ($search_all) {
397  foreach ($fieldstosearchall as $key => $val) {
398  $fieldstosearchall[$key] = $langs->trans($val);
399  }
400  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
401 }
402 
403 $moreforfilter = '';
404 /*$moreforfilter.='<div class="divsearchfield">';
405 $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
406 $moreforfilter.= '</div>';*/
407 
408 $parameters = array();
409 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
410 if (empty($reshook)) {
411  $moreforfilter .= $hookmanager->resPrint;
412 } else {
413  $moreforfilter = $hookmanager->resPrint;
414 }
415 
416 if (!empty($moreforfilter)) {
417  print '<div class="liste_titre liste_titre_bydiv centpercent">';
418  print $moreforfilter;
419  print '</div>';
420 }
421 
422 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
423 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
424 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
425 
426 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
427 print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
428 
429 
430 // Fields title search
431 // --------------------------------------------------------------------
432 print '<tr class="liste_titre">';
433 foreach ($object->fields as $key => $val) {
434  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
435  if ($key == 'status') {
436  $cssforfield .= ($cssforfield ? ' ' : '').'center';
437  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
438  $cssforfield .= ($cssforfield ? ' ' : '').'center';
439  } elseif (in_array($val['type'], array('timestamp'))) {
440  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
441  } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
442  $cssforfield .= ($cssforfield ? ' ' : '').'right';
443  }
444  if (!empty($arrayfields['t.'.$key]['checked'])) {
445  print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
446  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
447  print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
448  } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
449  print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', 'maxwidth125', 1);
450  } elseif (!preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
451  print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
452  } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
453  print '<div class="nowrap">';
454  print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
455  print '</div>';
456  print '<div class="nowrap">';
457  print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
458  print '</div>';
459  }
460  print '</td>';
461  }
462 }
463 // Extra fields
464 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
465 
466 // Fields from hook
467 $parameters = array('arrayfields'=>$arrayfields);
468 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
469 print $hookmanager->resPrint;
470 // Action column
471 print '<td class="liste_titre maxwidthsearch">';
472 $searchpicto = $form->showFilterButtons();
473 print $searchpicto;
474 print '</td>';
475 print '</tr>'."\n";
476 
477 
478 // Fields title label
479 // --------------------------------------------------------------------
480 print '<tr class="liste_titre">';
481 foreach ($object->fields as $key => $val) {
482  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
483  if ($key == 'status') {
484  $cssforfield .= ($cssforfield ? ' ' : '').'center';
485  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
486  $cssforfield .= ($cssforfield ? ' ' : '').'center';
487  } elseif (in_array($val['type'], array('timestamp'))) {
488  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
489  } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
490  $cssforfield .= ($cssforfield ? ' ' : '').'right';
491  }
492  if (!empty($arrayfields['t.'.$key]['checked'])) {
493  print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
494  }
495 }
496 // Extra fields
497 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
498 // Hook fields
499 $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
500 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
501 print $hookmanager->resPrint;
502 // Action column
503 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
504 print '</tr>'."\n";
505 
506 
507 // Detect if we need a fetch on each output line
508 $needToFetchEachLine = 0;
509 if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
510  foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
511  if (preg_match('/\$object/', $val)) {
512  $needToFetchEachLine++; // There is at least one compute field that use $object
513  }
514  }
515 }
516 
517 // Loop on record
518 // --------------------------------------------------------------------
519 $i = 0;
520 $totalarray = array();
521 $totalarray['nbfield'] = 0;
522 while ($i < ($limit ? min($num, $limit) : $num)) {
523  $obj = $db->fetch_object($resql);
524  if (empty($obj)) {
525  break; // Should not happen
526  }
527 
528  // Store properties in $object
529  $object->setVarsFromFetchObj($obj);
530 
531  // Show here line of result
532  print '<tr class="oddeven">';
533  foreach ($object->fields as $key => $val) {
534  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
535  if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
536  $cssforfield .= ($cssforfield ? ' ' : '').'center';
537  } elseif ($key == 'status') {
538  $cssforfield .= ($cssforfield ? ' ' : '').'center';
539  }
540 
541  if (in_array($val['type'], array('timestamp'))) {
542  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
543  } elseif ($key == 'ref') {
544  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
545  }
546 
547  if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
548  $cssforfield .= ($cssforfield ? ' ' : '').'right';
549  }
550 
551  if (!empty($arrayfields['t.'.$key]['checked'])) {
552  print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '').'>';
553  if ($key == 'status') {
554  print $object->getLibStatut(5);
555  } elseif ($key == 'rowid') {
556  print $object->showOutputField($val, $key, $object->id, '');
557  } else {
558  print $object->showOutputField($val, $key, $object->$key, '');
559  }
560  print '</td>';
561  if (!$i) {
562  $totalarray['nbfield']++;
563  }
564  if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
565  if (!$i) {
566  $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
567  }
568  if (!isset($totalarray['val'])) {
569  $totalarray['val'] = array();
570  }
571  if (!isset($totalarray['val']['t.'.$key])) {
572  $totalarray['val']['t.'.$key] = 0;
573  }
574  $totalarray['val']['t.'.$key] += $object->$key;
575  }
576  }
577  }
578  // Extra fields
579  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
580  // Fields from hook
581  $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
582  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
583  print $hookmanager->resPrint;
584  // Action column
585  print '<td class="nowrap center">';
586  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
587  $selected = 0;
588  if (in_array($object->id, $arrayofselected)) {
589  $selected = 1;
590  }
591  print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
592  }
593  print '</td>';
594  if (!$i) {
595  $totalarray['nbfield']++;
596  }
597 
598  print '</tr>'."\n";
599 
600  $i++;
601 }
602 
603 // Show total line
604 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
605 
606 
607 // If no record found
608 if ($num == 0) {
609  $colspan = 1;
610  foreach ($arrayfields as $key => $val) {
611  if (!empty($val['checked'])) {
612  $colspan++;
613  }
614  }
615  print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
616 }
617 
618 
619 $db->free($resql);
620 
621 $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
622 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
623 print $hookmanager->resPrint;
624 
625 print '</table>'."\n";
626 print '</div>'."\n";
627 
628 print '</form>'."\n";
629 // no inventory docs yet
630 /*
631 if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
632  $hidegeneratedfilelistifempty = 1;
633  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
634  $hidegeneratedfilelistifempty = 0;
635  }
636 
637  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
638  $formfile = new FormFile($db);
639 
640  // Show list of available documents
641  $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
642  $urlsource .= str_replace('&amp;', '&', $param);
643 
644  $filedir = $diroutputmassaction;
645  $genallowed = $permissiontoread;
646  $delallowed = $permissiontoadd;
647 
648  print $formfile->showdocuments('massfilesarea_mymodule', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
649 }
650 */
651 // End of page
652 llxFooter();
653 $db->close();
dol_escape_htmltag
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.
Definition: functions.lib.php:1468
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
getTitleFieldOfList
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
Definition: functions.lib.php:5049
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
dol_sort_array
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...
Definition: functions.lib.php:8385
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
Inventory
Class for Inventory.
Definition: inventory.class.php:36
$help_url
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:116
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
dolGetButtonTitle
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.
Definition: functions.lib.php:10605
print_barre_liste
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.
Definition: functions.lib.php:5257
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
natural_search
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...
Definition: functions.lib.php:9420
dol_eval
dol_eval($s, $returnvalue=0, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
Definition: functions.lib.php:8611
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->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->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
dol_mktime
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...
Definition: functions.lib.php:2757
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59