dolibarr  13.0.2
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')) { $page = 0; } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
52 $offset = $limit * $page;
53 $pageprev = $page - 1;
54 $pagenext = $page + 1;
55 //if (! $sortfield) $sortfield="p.date_fin";
56 //if (! $sortorder) $sortorder="DESC";
57 
58 // Initialize technical objects
59 $object = new BOM($db);
60 $extrafields = new ExtraFields($db);
61 $diroutputmassaction = $conf->bom->dir_output.'/temp/massgeneration/'.$user->id;
62 $hookmanager->initHooks(array('bomlist')); // Note that conf->hooks_modules contains array
63 
64 // Fetch optionals attributes and labels
65 $extrafields->fetch_name_optionals_label($object->table_element);
66 
67 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
68 
69 // Default sort order (if not yet defined by previous GETPOST)
70 if (!$sortfield) $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
71 if (!$sortorder) $sortorder = "ASC";
72 
73 // Security check
74 if (empty($conf->bom->enabled)) accessforbidden('Module not enabled');
75 $socid = 0;
76 if ($user->socid > 0) // Protection if external user
77 {
78  //$socid = $user->socid;
80 }
81 //$result = restrictedArea($user, 'bom', $id, '');
82 
83 // Initialize array of search criterias
84 $search_all = GETPOST("search_all", 'alpha');
85 $search = array();
86 foreach ($object->fields as $key => $val)
87 {
88  if (GETPOST('search_'.$key, 'alpha') !== '') $search[$key] = GETPOST('search_'.$key, 'alpha');
89 }
90 
91 // List of fields to search into when doing a "search in all"
92 $fieldstosearchall = array();
93 foreach ($object->fields as $key => $val)
94 {
95  if ($val['searchall']) $fieldstosearchall['t.'.$key] = $val['label'];
96 }
97 
98 // Definition of fields for list
99 $arrayfields = array();
100 foreach ($object->fields as $key => $val)
101 {
102  // If $val['visible']==0, then we never show the field
103  if (!empty($val['visible'])) $arrayfields['t.'.$key] = array('label'=>$val['label'], 'checked'=>(($val['visible'] < 0) ? 0 : 1), 'enabled'=>($val['enabled'] && ($val['visible'] != 3)), 'position'=>$val['position']);
104 }
105 // Extra fields
106 if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0)
107 {
108  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val)
109  {
110  if (!empty($extrafields->attributes[$object->table_element]['list'][$key])) {
111  $arrayfields["ef.".$key] = array(
112  'label'=>$extrafields->attributes[$object->table_element]['label'][$key],
113  'checked'=>(($extrafields->attributes[$object->table_element]['list'][$key] < 0) ? 0 : 1),
114  'position'=>$extrafields->attributes[$object->table_element]['pos'][$key],
115  'enabled'=>(abs($extrafields->attributes[$object->table_element]['list'][$key]) != 3 && $extrafields->attributes[$object->table_element]['perms'][$key])
116  );
117  }
118  }
119 }
120 $object->fields = dol_sort_array($object->fields, 'position');
121 $arrayfields = dol_sort_array($arrayfields, 'position');
122 
123 $permissiontoread = $user->rights->bom->read;
124 $permissiontoadd = $user->rights->bom->write;
125 $permissiontodelete = $user->rights->bom->delete;
126 
127 
128 /*
129  * Actions
130  */
131 
132 if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
133 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; }
134 
135 $parameters = array();
136 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
137 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
138 
139 if (empty($reshook))
140 {
141  // Selection of new fields
142  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
143 
144  // Purge search criteria
145  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
146  {
147  foreach ($object->fields as $key => $val)
148  {
149  $search[$key] = '';
150  }
151  $toselect = '';
152  $search_array_options = array();
153  }
154  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
155  || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha'))
156  {
157  $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
158  }
159 
160  // Mass actions
161  $objectclass = 'BOM';
162  $objectlabel = 'BillOfMaterials';
163  $permissiontoread = $user->rights->bom->read;
164  $permissiontodelete = $user->rights->bom->delete;
165  $uploaddir = $conf->bom->dir_output;
166  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
167 
168 
169  // Validate records
170  if (!$error && $massaction == 'disable' && $permissiontoadd)
171  {
172  $objecttmp = new $objectclass($db);
173 
174  if (!$error)
175  {
176  $db->begin();
177 
178  $nbok = 0;
179  foreach ($toselect as $toselectid)
180  {
181  $result = $objecttmp->fetch($toselectid);
182  if ($result > 0)
183  {
184  if ($objecttmp->status != $objecttmp::STATUS_VALIDATED)
185  {
186  $langs->load("errors");
187  setEventMessages($langs->trans("ErrorObjectMustHaveStatusActiveToBeDisabled", $objecttmp->ref), null, 'errors');
188  $error++;
189  break;
190  }
191 
192  // Can be 'cancel()' or 'close()'
193  $result = $objecttmp->cancel($user);
194  if ($result < 0)
195  {
196  setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
197  $error++;
198  break;
199  } else $nbok++;
200  } else {
201  setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
202  $error++;
203  break;
204  }
205  }
206 
207  if (!$error)
208  {
209  if ($nbok > 1) setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
210  else setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
211  $db->commit();
212  } else {
213  $db->rollback();
214  }
215  //var_dump($listofobjectthirdparties);exit;
216  }
217  }
218 
219  // Validate records
220  if (!$error && $massaction == 'enable' && $permissiontoadd)
221  {
222  $objecttmp = new $objectclass($db);
223 
224  if (!$error)
225  {
226  $db->begin();
227 
228  $nbok = 0;
229  foreach ($toselect as $toselectid)
230  {
231  $result = $objecttmp->fetch($toselectid);
232  if ($result > 0)
233  {
234  if ($objecttmp->status != $objecttmp::STATUS_DRAFT && $objecttmp->status != $objecttmp::STATUS_CANCELED)
235  {
236  $langs->load("errors");
237  setEventMessages($langs->trans("ErrorObjectMustHaveStatusDraftOrDisabledToBeActivated", $objecttmp->ref), null, 'errors');
238  $error++;
239  break;
240  }
241 
242  // Can be 'cancel()' or 'close()'
243  $result = $objecttmp->validate($user);
244  if ($result < 0)
245  {
246  setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
247  $error++;
248  break;
249  } else $nbok++;
250  } else {
251  setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
252  $error++;
253  break;
254  }
255  }
256 
257  if (!$error)
258  {
259  if ($nbok > 1) setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
260  else setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
261  $db->commit();
262  } else {
263  $db->rollback();
264  }
265  //var_dump($listofobjectthirdparties);exit;
266  }
267  }
268 }
269 
270 
271 /*
272  * View
273  */
274 
275 $form = new Form($db);
276 
277 $now = dol_now();
278 
279 //$help_url="EN:Module_BillOfMaterials|FR:Module_BillOfMaterials_FR|ES:Módulo_BillOfMaterials";
280 $help_url = '';
281 $title = $langs->trans('ListOfBOMs');
282 
283 
284 // Build and execute select
285 // --------------------------------------------------------------------
286 $sql = 'SELECT ';
287 foreach ($object->fields as $key => $val)
288 {
289  $sql .= 't.'.$key.', ';
290 }
291 // Add fields from extrafields
292 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
293  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.' as options_'.$key.', ' : '');
294 }
295 // Add fields from hooks
296 $parameters = array();
297 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
298 $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
299 $sql = preg_replace('/,\s*$/', '', $sql);
300 $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
301 if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
302 if ($object->ismultientitymanaged == 1) $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
303 else $sql .= " WHERE 1 = 1";
304 foreach ($search as $key => $val)
305 {
306  if ($key == 'status' && $search[$key] == -1) continue;
307  $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
308  if (strpos($object->fields[$key]['type'], 'integer:') === 0) {
309  if ($search[$key] == '-1') $search[$key] = '';
310  $mode_search = 2;
311  }
312  if ($search[$key] != '') $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
313 }
314 
315 if ($search_all) $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
316 // Add where from extra fields
317 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
318 // Add where from hooks
319 $parameters = array();
320 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
321 $sql .= $hookmanager->resPrint;
322 
323 /* If a group by is required
324 $sql.= " GROUP BY "
325 foreach($object->fields as $key => $val)
326 {
327  $sql.='t.'.$key.', ';
328 }
329 // Add fields from extrafields
330 if (! empty($extrafields->attributes[$object->table_element]['label'])) {
331  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
332 }
333 // Add where from hooks
334 $parameters=array();
335 $reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters); // Note that $action and $object may have been modified by hook
336 $sql.=$hookmanager->resPrint;
337 $sql=preg_replace('/,\s*$/','', $sql);
338 */
339 
340 $sql .= $db->order($sortfield, $sortorder);
341 
342 // Count total nb of records
343 $nbtotalofrecords = '';
344 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
345 {
346  $resql = $db->query($sql);
347  $nbtotalofrecords = $db->num_rows($resql);
348  if (($page * $limit) > $nbtotalofrecords) // if total of record found is smaller than page * limit, goto and load page 0
349  {
350  $page = 0;
351  $offset = 0;
352  }
353 }
354 // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
355 if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit)))
356 {
357  $num = $nbtotalofrecords;
358 } else {
359  if ($limit) $sql .= $db->plimit($limit + 1, $offset);
360 
361  $resql = $db->query($sql);
362  if (!$resql)
363  {
364  dol_print_error($db);
365  exit;
366  }
367 
368  $num = $db->num_rows($resql);
369 }
370 
371 // Direct jump if only one record found
372 if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page)
373 {
374  $obj = $db->fetch_object($resql);
375  $id = $obj->rowid;
376  header("Location: ".DOL_URL_ROOT.'/bom/bom_card.php?id='.$id);
377  exit;
378 }
379 
380 
381 // Output page
382 // --------------------------------------------------------------------
383 
384 llxHeader('', $title, $help_url);
385 
386 $arrayofselected = is_array($toselect) ? $toselect : array();
387 
388 $param = '';
389 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
390 if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
391 foreach ($search as $key => $val)
392 {
393  if (is_array($search[$key]) && count($search[$key])) foreach ($search[$key] as $skey) $param .= '&search_'.$key.'[]='.urlencode($skey);
394  else $param .= '&search_'.$key.'='.urlencode($search[$key]);
395 }
396 if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss);
397 // Add $param from extra fields
398 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
399 
400 // List of mass actions available
401 $arrayofmassactions = array(
402  //'presend'=>$langs->trans("SendByMail"),
403  'enable'=>$langs->trans("Enable"),
404  'disable'=>$langs->trans("Disable"),
405 );
406 if ($permissiontodelete) $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
407 if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array();
408 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
409 
410 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
411 if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
412 print '<input type="hidden" name="token" value="'.newToken().'">';
413 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
414 print '<input type="hidden" name="action" value="list">';
415 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
416 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
417 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
418 
419 $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);
420 
421 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'bom', 0, $newcardbutton, '', $limit, 0, 0, 1);
422 
423 // Add code for pre mass action (confirmation or email presend form)
424 $topicmail = "SendBillOfMaterialsRef";
425 $modelmail = "bom";
426 $objecttmp = new BOM($db);
427 $trackid = 'bom'.$object->id;
428 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
429 
430 if ($search_all)
431 {
432  foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val);
433  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
434 }
435 
436 $moreforfilter = '';
437 /*$moreforfilter.='<div class="divsearchfield">';
438 $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
439 $moreforfilter.= '</div>';*/
440 
441 $parameters = array();
442 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
443 if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
444 else $moreforfilter = $hookmanager->resPrint;
445 
446 if (!empty($moreforfilter))
447 {
448  print '<div class="liste_titre liste_titre_bydiv centpercent">';
449  print $moreforfilter;
450  print '</div>';
451 }
452 
453 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
454 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
455 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
456 
457 print '<div class="div-table-responsive">';
458 print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
459 
460 
461 // Fields title search
462 // --------------------------------------------------------------------
463 print '<tr class="liste_titre">';
464 foreach ($object->fields as $key => $val)
465 {
466  $cssforfield = (empty($val['css']) ? '' : $val['css']);
467  if ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center';
468  elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center';
469  elseif (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
470  elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') $cssforfield .= ($cssforfield ? ' ' : '').'right';
471  if (!empty($arrayfields['t.'.$key]['checked']))
472  {
473  print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
474  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) print $form->selectarray('search_'.$key, $val['arrayofkeyval'], $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
475  elseif (strpos($val['type'], 'integer:') === 0) {
476  print $object->showInputField($val, $key, $search[$key], '', '', 'search_', 'maxwidth150', 1);
477  } elseif (!preg_match('/^(date|timestamp)/', $val['type'])) print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag($search[$key]).'">';
478  print '</td>';
479  }
480 }
481 // Extra fields
482 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
483 
484 // Fields from hook
485 $parameters = array('arrayfields'=>$arrayfields);
486 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
487 print $hookmanager->resPrint;
488 // Action column
489 print '<td class="liste_titre maxwidthsearch">';
490 $searchpicto = $form->showFilterButtons();
491 print $searchpicto;
492 print '</td>';
493 print '</tr>'."\n";
494 
495 
496 // Fields title label
497 // --------------------------------------------------------------------
498 print '<tr class="liste_titre">';
499 foreach ($object->fields as $key => $val)
500 {
501  $cssforfield = (empty($val['css']) ? '' : $val['css']);
502  if ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center';
503  elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center';
504  elseif (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
505  elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') $cssforfield .= ($cssforfield ? ' ' : '').'right';
506  if (!empty($arrayfields['t.'.$key]['checked']))
507  {
508  print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
509  }
510 }
511 // Extra fields
512 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
513 // Hook fields
514 $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
515 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
516 print $hookmanager->resPrint;
517 // Action column
518 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
519 print '</tr>'."\n";
520 
521 
522 // Detect if we need a fetch on each output line
523 $needToFetchEachLine = 0;
524 if (is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0)
525 {
526  foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val)
527  {
528  if (preg_match('/\$object/', $val)) $needToFetchEachLine++; // There is at least one compute field that use $object
529  }
530 }
531 
532 
533 // Loop on record
534 // --------------------------------------------------------------------
535 $i = 0;
536 $totalarray = array();
537 while ($i < ($limit ? min($num, $limit) : $num))
538 {
539  $obj = $db->fetch_object($resql);
540  if (empty($obj)) break; // Should not happen
541 
542  // Store properties in $object
543  $object->setVarsFromFetchObj($obj);
544 
545  // Show here line of result
546  print '<tr class="oddeven">';
547  foreach ($object->fields as $key => $val)
548  {
549  $cssforfield = (empty($val['css']) ? '' : $val['css']);
550  if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'center';
551  elseif ($key == 'status') $cssforfield .= ($cssforfield ? ' ' : '').'center';
552 
553  if (in_array($val['type'], array('timestamp'))) $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
554  elseif ($key == 'ref') $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
555 
556  if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $key != 'status') $cssforfield .= ($cssforfield ? ' ' : '').'right';
557  if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
558 
559  if (!empty($arrayfields['t.'.$key]['checked']))
560  {
561  print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '').'>';
562  if ($key == 'status') print $object->getLibStatut(5);
563  else print $object->showOutputField($val, $key, $object->$key, '');
564  print '</td>';
565  if (!$i) $totalarray['nbfield']++;
566  if (!empty($val['isameasure']))
567  {
568  if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
569  $totalarray['val']['t.'.$key] += $object->$key;
570  }
571  }
572  }
573  // Extra fields
574  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
575  // Fields from hook
576  $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
577  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
578  print $hookmanager->resPrint;
579  // Action column
580  print '<td class="nowrap center">';
581  if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
582  {
583  $selected = 0;
584  if (in_array($object->id, $arrayofselected)) $selected = 1;
585  print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
586  }
587  print '</td>';
588  if (!$i) $totalarray['nbfield']++;
589 
590  print '</tr>'."\n";
591 
592  $i++;
593 }
594 
595 // Show total line
596 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
597 
598 
599 // If no record found
600 if ($num == 0)
601 {
602  $colspan = 1;
603  foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; }
604  print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
605 }
606 
607 
608 $db->free($resql);
609 
610 $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
611 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
612 print $hookmanager->resPrint;
613 
614 print '</table>'."\n";
615 print '</div>'."\n";
616 
617 print '</form>'."\n";
618 
619 
620 if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords))
621 {
622  $hidegeneratedfilelistifempty = 1;
623  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) $hidegeneratedfilelistifempty = 0;
624 
625  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
626  $formfile = new FormFile($db);
627 
628  // Show list of available documents
629  $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
630  $urlsource .= str_replace('&amp;', '&', $param);
631 
632  $filedir = $diroutputmassaction;
633  $genallowed = $permissiontoread;
634  $delallowed = $permissiontoadd;
635 
636  print $formfile->showdocuments('massfilesarea_bom', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
637 }
638 
639 // End of page
640 llxFooter();
641 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
foreach($object->fields as $key=> $val) if(is_array($extrafields->attributes[$object->table_element]['label'])&&count($extrafields->attributes[$object->table_element]['label']) > 0) $object fields
Class for BOM.
Definition: bom.class.php:32
dol_now($mode= 'auto')
Return date for now.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:108
price($amount, $form=0, $outlangs= '', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code= '')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage standard extra fields.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options= '', $sortfield= '', $sortorder= '', $morehtmlcenter= '', $num=-1, $totalnboflines= '', $picto= 'generic', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow= '')
Print a title with navigation controls for pagination.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
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 ...
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...
Class to offer components to list and upload files.
print $_SERVER["PHP_SELF"]
Edit parameters.
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...
print
Draft customers invoices.
Definition: index.php:89
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
print $_SERVER["PHP_SELF"] n
Edit parameters.
Definition: categories.php:101
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip= '', $forcenowrapcolumntitle=0)
Get title line of an array.
llxFooter()
Empty footer.
Definition: wrapper.php:59
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:105
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...