dolibarr  16.0.5
bom_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.'/bom/class/bom.class.php';
30 
31 // Load translation files required by the page
32 $langs->loadLangs(array("mrp", "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') : 'bomlist'; // 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  $page = 0;
53 } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
54 $offset = $limit * $page;
55 $pageprev = $page - 1;
56 $pagenext = $page + 1;
57 //if (! $sortfield) $sortfield="p.date_fin";
58 //if (! $sortorder) $sortorder="DESC";
59 
60 // Initialize technical objects
61 $object = new BOM($db);
62 $extrafields = new ExtraFields($db);
63 $diroutputmassaction = $conf->bom->dir_output.'/temp/massgeneration/'.$user->id;
64 $hookmanager->initHooks(array('bomlist')); // Note that conf->hooks_modules contains array
65 
66 // Fetch optionals attributes and labels
67 $extrafields->fetch_name_optionals_label($object->table_element);
68 
69 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
70 
71 // Default sort order (if not yet defined by previous GETPOST)
72 if (!$sortfield) {
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", 'alpha');
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);
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->bom->read;
122 $permissiontoadd = $user->rights->bom->write;
123 $permissiontodelete = $user->rights->bom->delete;
124 
125 // Security check
126 if ($user->socid > 0) {
127  // Protection if external user
128  accessforbidden();
129 }
130 $result = restrictedArea($user, 'bom');
131 
132 
133 /*
134  * Actions
135  */
136 
137 if (GETPOST('cancel', 'alpha')) {
138  $action = 'list';
139  $massaction = '';
140 }
141 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
142  $massaction = '';
143 }
144 
145 $parameters = array();
146 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
147 if ($reshook < 0) {
148  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
149 }
150 
151 if (empty($reshook)) {
152  // Selection of new fields
153  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
154 
155  // Purge search criteria
156  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
157  foreach ($object->fields as $key => $val) {
158  $search[$key] = '';
159  if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
160  $search[$key.'_dtstart'] = '';
161  $search[$key.'_dtend'] = '';
162  }
163  }
164  $toselect = array();
165  $search_array_options = array();
166  }
167  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
168  || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
169  $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
170  }
171 
172  // Mass actions
173  $objectclass = 'BOM';
174  $objectlabel = 'BillOfMaterials';
175  $permissiontoread = $user->rights->bom->read;
176  $permissiontodelete = $user->rights->bom->delete;
177  $uploaddir = $conf->bom->dir_output;
178  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
179 
180 
181  // Validate records
182  if (!$error && $massaction == 'disable' && $permissiontoadd) {
183  $objecttmp = new $objectclass($db);
184 
185  if (!$error) {
186  $db->begin();
187 
188  $nbok = 0;
189  foreach ($toselect as $toselectid) {
190  $result = $objecttmp->fetch($toselectid);
191  if ($result > 0) {
192  if ($objecttmp->status != $objecttmp::STATUS_VALIDATED) {
193  $langs->load("errors");
194  setEventMessages($langs->trans("ErrorObjectMustHaveStatusActiveToBeDisabled", $objecttmp->ref), null, 'errors');
195  $error++;
196  break;
197  }
198 
199  // Can be 'cancel()' or 'close()'
200  $result = $objecttmp->cancel($user);
201  if ($result < 0) {
202  setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
203  $error++;
204  break;
205  } else {
206  $nbok++;
207  }
208  } else {
209  setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
210  $error++;
211  break;
212  }
213  }
214 
215  if (!$error) {
216  if ($nbok > 1) {
217  setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
218  } else {
219  setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
220  }
221  $db->commit();
222  } else {
223  $db->rollback();
224  }
225  //var_dump($listofobjectthirdparties);exit;
226  }
227  }
228 
229  // Validate records
230  if (!$error && $massaction == 'enable' && $permissiontoadd) {
231  $objecttmp = new $objectclass($db);
232 
233  if (!$error) {
234  $db->begin();
235 
236  $nbok = 0;
237  foreach ($toselect as $toselectid) {
238  $result = $objecttmp->fetch($toselectid);
239  if ($result > 0) {
240  if ($objecttmp->status != $objecttmp::STATUS_DRAFT && $objecttmp->status != $objecttmp::STATUS_CANCELED) {
241  $langs->load("errors");
242  setEventMessages($langs->trans("ErrorObjectMustHaveStatusDraftOrDisabledToBeActivated", $objecttmp->ref), null, 'errors');
243  $error++;
244  break;
245  }
246 
247  // Can be 'cancel()' or 'close()'
248  $result = $objecttmp->validate($user);
249  if ($result < 0) {
250  setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
251  $error++;
252  break;
253  } else {
254  $nbok++;
255  }
256  } else {
257  setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
258  $error++;
259  break;
260  }
261  }
262 
263  if (!$error) {
264  if ($nbok > 1) {
265  setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
266  } else {
267  setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
268  }
269  $db->commit();
270  } else {
271  $db->rollback();
272  }
273  //var_dump($listofobjectthirdparties);exit;
274  }
275  }
276 }
277 
278 
279 /*
280  * View
281  */
282 
283 $form = new Form($db);
284 
285 $now = dol_now();
286 
287 $help_url = 'EN:Module_BOM';
288 $title = $langs->trans('ListOfBOMs');
289 $morejs = array();
290 $morecss = array();
291 
292 
293 // Build and execute select
294 // --------------------------------------------------------------------
295 $sql = 'SELECT ';
296 $sql .= $object->getFieldList('t');
297 // Add fields from extrafields
298 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
299  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
300  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key.' ' : '');
301  }
302 }
303 // Add fields from hooks
304 $parameters = array();
305 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
306 $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
307 $sql = preg_replace('/,\s*$/', '', $sql);
308 $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
309 if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
310  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
311 }
312 // Add table from hooks
313 $parameters = array();
314 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
315 $sql .= $hookmanager->resPrint;
316 if ($object->ismultientitymanaged == 1) {
317  $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
318 } else {
319  $sql .= " WHERE 1 = 1";
320 }
321 foreach ($search as $key => $val) {
322  if (array_key_exists($key, $object->fields)) {
323  if ($key == 'status' && $search[$key] == -1) {
324  continue;
325  }
326  $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
327  if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
328  if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
329  $search[$key] = '';
330  }
331  $mode_search = 2;
332  }
333  if ($search[$key] != '') {
334  $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
335  }
336  } else {
337  if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
338  $columnName=preg_replace('/(_dtstart|_dtend)$/', '', $key);
339  if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
340  if (preg_match('/_dtstart$/', $key)) {
341  $sql .= " AND t." . $columnName . " >= '" . $db->idate($search[$key]) . "'";
342  }
343  if (preg_match('/_dtend$/', $key)) {
344  $sql .= " AND t." . $columnName . " <= '" . $db->idate($search[$key]) . "'";
345  }
346  }
347  }
348  }
349 }
350 
351 if ($search_all) {
352  $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
353 }
354 //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
355 // Add where from extra fields
356 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
357 // Add where from hooks
358 $parameters = array();
359 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
360 $sql .= $hookmanager->resPrint;
361 
362 /* If a group by is required
363 $sql.= " GROUP BY ";
364 foreach($object->fields as $key => $val)
365 {
366  $sql .= "t.".$key.", ";
367 }
368 // Add fields from extrafields
369 if (! empty($extrafields->attributes[$object->table_element]['label'])) {
370  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
371  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
372  }
373 }
374 // Add where from hooks
375 $parameters=array();
376 $reshook=$hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
377 $sql.=$hookmanager->resPrint;
378 $sql=preg_replace('/,\s*$/','', $sql);
379 */
380 
381 $sql .= $db->order($sortfield, $sortorder);
382 
383 // Count total nb of records
384 $nbtotalofrecords = '';
385 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
386  $resql = $db->query($sql);
387  $nbtotalofrecords = $db->num_rows($resql);
388  if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
389  $page = 0;
390  $offset = 0;
391  }
392 }
393 // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
394 if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
395  $num = $nbtotalofrecords;
396 } else {
397  if ($limit) {
398  $sql .= $db->plimit($limit + 1, $offset);
399  }
400 
401  $resql = $db->query($sql);
402  if (!$resql) {
403  dol_print_error($db);
404  exit;
405  }
406 
407  $num = $db->num_rows($resql);
408 }
409 
410 // Direct jump if only one record found
411 if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
412  $obj = $db->fetch_object($resql);
413  $id = $obj->rowid;
414  header("Location: ".DOL_URL_ROOT.'/bom/bom_card.php?id='.$id);
415  exit;
416 }
417 
418 
419 // Output page
420 // --------------------------------------------------------------------
421 
422 llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', '');
423 
424 $arrayofselected = is_array($toselect) ? $toselect : array();
425 
426 $param = '';
427 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
428  $param .= '&contextpage='.urlencode($contextpage);
429 }
430 if ($limit > 0 && $limit != $conf->liste_limit) {
431  $param .= '&limit='.urlencode($limit);
432 }
433 foreach ($search as $key => $val) {
434  if (is_array($search[$key]) && count($search[$key])) {
435  foreach ($search[$key] as $skey) {
436  $param .= '&search_'.$key.'[]='.urlencode($skey);
437  }
438  } else {
439  $param .= '&search_'.$key.'='.urlencode($search[$key]);
440  }
441 }
442 if ($optioncss != '') {
443  $param .= '&optioncss='.urlencode($optioncss);
444 }
445 // Add $param from extra fields
446 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
447 // Add $param from hooks
448 $parameters = array();
449 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
450 $param .= $hookmanager->resPrint;
451 
452 // List of mass actions available
453 $arrayofmassactions = array(
454  //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
455  'enable'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Enable"),
456  'disable'=>img_picto('', 'close_title', 'class="pictofixedwidth"').$langs->trans("Disable"),
457 );
458 if ($permissiontodelete) {
459  $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
460 }
461 if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
462  $arrayofmassactions = array();
463 }
464 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
465 
466 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
467 if ($optioncss != '') {
468  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
469 }
470 print '<input type="hidden" name="token" value="'.newToken().'">';
471 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
472 print '<input type="hidden" name="action" value="list">';
473 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
474 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
475 print '<input type="hidden" name="page" value="'.$page.'">';
476 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
477 
478 $newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/bom/bom_card.php?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $user->rights->bom->write);
479 
480 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
481 
482 // Add code for pre mass action (confirmation or email presend form)
483 $topicmail = "SendBillOfMaterialsRef";
484 $modelmail = "bom";
485 $objecttmp = new BOM($db);
486 $trackid = 'bom'.$object->id;
487 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
488 
489 if ($search_all) {
490  foreach ($fieldstosearchall as $key => $val) {
491  $fieldstosearchall[$key] = $langs->trans($val);
492  }
493  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
494 }
495 
496 $moreforfilter = '';
497 /*$moreforfilter.='<div class="divsearchfield">';
498 $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
499 $moreforfilter.= '</div>';*/
500 
501 $parameters = array();
502 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
503 if (empty($reshook)) {
504  $moreforfilter .= $hookmanager->resPrint;
505 } else {
506  $moreforfilter = $hookmanager->resPrint;
507 }
508 
509 if (!empty($moreforfilter)) {
510  print '<div class="liste_titre liste_titre_bydiv centpercent">';
511  print $moreforfilter;
512  print '</div>';
513 }
514 
515 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
516 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
517 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
518 
519 print '<div class="div-table-responsive">';
520 print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
521 
522 
523 // Fields title search
524 // --------------------------------------------------------------------
525 print '<tr class="liste_titre">';
526 foreach ($object->fields as $key => $val) {
527  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
528  if ($key == 'status') {
529  $cssforfield .= ($cssforfield ? ' ' : '').'center';
530  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
531  $cssforfield .= ($cssforfield ? ' ' : '').'center';
532  } elseif (in_array($val['type'], array('timestamp'))) {
533  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
534  } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
535  $cssforfield .= ($cssforfield ? ' ' : '').'right';
536  }
537  if (!empty($arrayfields['t.'.$key]['checked'])) {
538  print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
539  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
540  print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
541  } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
542  print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', 'maxwidth125', 1);
543  } elseif (!preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
544  print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
545  } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
546  print '<div class="nowrap">';
547  print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
548  print '</div>';
549  print '<div class="nowrap">';
550  print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
551  print '</div>';
552  }
553  print '</td>';
554  }
555 }
556 // Extra fields
557 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
558 
559 // Fields from hook
560 $parameters = array('arrayfields'=>$arrayfields);
561 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
562 print $hookmanager->resPrint;
563 // Action column
564 print '<td class="liste_titre maxwidthsearch">';
565 $searchpicto = $form->showFilterButtons();
566 print $searchpicto;
567 print '</td>';
568 print '</tr>'."\n";
569 
570 
571 // Fields title label
572 // --------------------------------------------------------------------
573 print '<tr class="liste_titre">';
574 foreach ($object->fields as $key => $val) {
575  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
576  if ($key == 'status') {
577  $cssforfield .= ($cssforfield ? ' ' : '').'center';
578  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
579  $cssforfield .= ($cssforfield ? ' ' : '').'center';
580  } elseif (in_array($val['type'], array('timestamp'))) {
581  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
582  } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
583  $cssforfield .= ($cssforfield ? ' ' : '').'right';
584  }
585  if (!empty($arrayfields['t.'.$key]['checked'])) {
586  print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
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);
593 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
594 print $hookmanager->resPrint;
595 // Action column
596 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
597 print '</tr>'."\n";
598 
599 
600 // Detect if we need a fetch on each output line
601 $needToFetchEachLine = 0;
602 if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
603  foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
604  if (preg_match('/\$object/', $val)) {
605  $needToFetchEachLine++; // There is at least one compute field that use $object
606  }
607  }
608 }
609 
610 
611 // Loop on record
612 // --------------------------------------------------------------------
613 $i = 0;
614 $totalarray = array();
615 $totalarray['nbfield'] = 0;
616 while ($i < ($limit ? min($num, $limit) : $num)) {
617  $obj = $db->fetch_object($resql);
618  if (empty($obj)) {
619  break; // Should not happen
620  }
621 
622  // Store properties in $object
623  $object->setVarsFromFetchObj($obj);
624 
625  // Show here line of result
626  print '<tr class="oddeven">';
627  foreach ($object->fields as $key => $val) {
628  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
629  if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
630  $cssforfield .= ($cssforfield ? ' ' : '').'center';
631  } elseif ($key == 'status') {
632  $cssforfield .= ($cssforfield ? ' ' : '').'center';
633  }
634 
635  if (in_array($val['type'], array('timestamp'))) {
636  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
637  } elseif ($key == 'ref') {
638  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
639  }
640 
641  if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
642  $cssforfield .= ($cssforfield ? ' ' : '').'right';
643  }
644 
645  if (!empty($arrayfields['t.'.$key]['checked'])) {
646  print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '').'>';
647  if ($key == 'status') {
648  print $object->getLibStatut(5);
649  } elseif ($key == 'rowid') {
650  print $object->showOutputField($val, $key, $object->id, '');
651  } else {
652  print $object->showOutputField($val, $key, $object->$key, '');
653  }
654  print '</td>';
655  if (!$i) {
656  $totalarray['nbfield']++;
657  }
658  if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
659  if (!$i) {
660  $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
661  }
662  if (!isset($totalarray['val'])) {
663  $totalarray['val'] = array();
664  }
665  if (!isset($totalarray['val']['t.'.$key])) {
666  $totalarray['val']['t.'.$key] = 0;
667  }
668  $totalarray['val']['t.'.$key] += $object->$key;
669  }
670  }
671  }
672  // Extra fields
673  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
674  // Fields from hook
675  $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
676  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
677  print $hookmanager->resPrint;
678  // Action column
679  print '<td class="nowrap center">';
680  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
681  $selected = 0;
682  if (in_array($object->id, $arrayofselected)) {
683  $selected = 1;
684  }
685  print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
686  }
687  print '</td>';
688  if (!$i) {
689  $totalarray['nbfield']++;
690  }
691 
692  print '</tr>'."\n";
693 
694  $i++;
695 }
696 
697 // Show total line
698 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
699 
700 
701 // If no record found
702 if ($num == 0) {
703  $colspan = 1;
704  foreach ($arrayfields as $key => $val) {
705  if (!empty($val['checked'])) {
706  $colspan++;
707  }
708  }
709  print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
710 }
711 
712 
713 $db->free($resql);
714 
715 $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
716 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
717 print $hookmanager->resPrint;
718 
719 print '</table>'."\n";
720 print '</div>'."\n";
721 
722 print '</form>'."\n";
723 
724 
725 if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
726  $hidegeneratedfilelistifempty = 1;
727  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
728  $hidegeneratedfilelistifempty = 0;
729  }
730 
731  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
732  $formfile = new FormFile($db);
733 
734  // Show list of available documents
735  $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
736  $urlsource .= str_replace('&amp;', '&', $param);
737 
738  $filedir = $diroutputmassaction;
739  $genallowed = $permissiontoread;
740  $delallowed = $permissiontoadd;
741 
742  print $formfile->showdocuments('massfilesarea_bom', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
743 }
744 
745 // End of page
746 llxFooter();
747 $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
BOM
Class for BOM.
Definition: bom.class.php:34
$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
FormFile
Class to offer components to list and upload files.
Definition: html.formfile.class.php:36
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