dolibarr  17.0.4
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 // Get Parameters
35 $id = GETPOST('id', 'int');
36 $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
37 $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
38 $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
39 $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
40 $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
41 $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
42 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'bomlist'; // To manage different context of search
43 $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
44 $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
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 
309 $sqlfields = $sql; // $sql fields to remove for count total
310 
311 $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
312 if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
313  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
314 }
315 // Add table from hooks
316 $parameters = array();
317 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
318 $sql .= $hookmanager->resPrint;
319 if ($object->ismultientitymanaged == 1) {
320  $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
321 } else {
322  $sql .= " WHERE 1 = 1";
323 }
324 foreach ($search as $key => $val) {
325  if (array_key_exists($key, $object->fields)) {
326  if ($key == 'status' && $search[$key] == -1) {
327  continue;
328  }
329  $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
330  if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
331  if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
332  $search[$key] = '';
333  }
334  $mode_search = 2;
335  }
336  if ($search[$key] != '') {
337  $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
338  }
339  } else {
340  if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
341  $columnName=preg_replace('/(_dtstart|_dtend)$/', '', $key);
342  if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
343  if (preg_match('/_dtstart$/', $key)) {
344  $sql .= " AND t." . $columnName . " >= '" . $db->idate($search[$key]) . "'";
345  }
346  if (preg_match('/_dtend$/', $key)) {
347  $sql .= " AND t." . $columnName . " <= '" . $db->idate($search[$key]) . "'";
348  }
349  }
350  }
351  }
352 }
353 
354 if ($search_all) {
355  $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
356 }
357 //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
358 // Add where from extra fields
359 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
360 // Add where from hooks
361 $parameters = array();
362 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
363 $sql .= $hookmanager->resPrint;
364 
365 /* If a group by is required
366 $sql.= " GROUP BY ";
367 foreach($object->fields as $key => $val)
368 {
369  $sql .= "t.".$key.", ";
370 }
371 // Add fields from extrafields
372 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
373  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
374  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
375  }
376 }
377 // Add where from hooks
378 $parameters=array();
379 $reshook=$hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
380 $sql.=$hookmanager->resPrint;
381 $sql=preg_replace('/,\s*$/','', $sql);
382 */
383 
384 // Count total nb of records
385 $nbtotalofrecords = '';
386 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
387  /* The fast and low memory method to get and count full list converts the sql into a sql count */
388  $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
389  $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
390  $resql = $db->query($sqlforcount);
391  if ($resql) {
392  $objforcount = $db->fetch_object($resql);
393  $nbtotalofrecords = $objforcount->nbtotalofrecords;
394  } else {
395  dol_print_error($db);
396  }
397 
398  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
399  $page = 0;
400  $offset = 0;
401  }
402  $db->free($resql);
403 }
404 
405 // Complete request and execute it with limit
406 $sql .= $db->order($sortfield, $sortorder);
407 if ($limit) {
408  $sql .= $db->plimit($limit + 1, $offset);
409 }
410 
411 $resql = $db->query($sql);
412 if (!$resql) {
413  dol_print_error($db);
414  exit;
415 }
416 
417 $num = $db->num_rows($resql);
418 
419 // Direct jump if only one record found
420 if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
421  $obj = $db->fetch_object($resql);
422  $id = $obj->rowid;
423  header("Location: ".DOL_URL_ROOT.'/bom/bom_card.php?id='.$id);
424  exit;
425 }
426 
427 
428 // Output page
429 // --------------------------------------------------------------------
430 
431 llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', '');
432 
433 $arrayofselected = is_array($toselect) ? $toselect : array();
434 
435 $param = '';
436 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
437  $param .= '&contextpage='.urlencode($contextpage);
438 }
439 if ($limit > 0 && $limit != $conf->liste_limit) {
440  $param .= '&limit='.urlencode($limit);
441 }
442 foreach ($search as $key => $val) {
443  if (is_array($search[$key]) && count($search[$key])) {
444  foreach ($search[$key] as $skey) {
445  $param .= '&search_'.$key.'[]='.urlencode($skey);
446  }
447  } else {
448  $param .= '&search_'.$key.'='.urlencode($search[$key]);
449  }
450 }
451 if ($optioncss != '') {
452  $param .= '&optioncss='.urlencode($optioncss);
453 }
454 // Add $param from extra fields
455 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
456 // Add $param from hooks
457 $parameters = array();
458 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
459 $param .= $hookmanager->resPrint;
460 
461 // List of mass actions available
462 $arrayofmassactions = array(
463  //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
464  'enable'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Enable"),
465  'disable'=>img_picto('', 'close_title', 'class="pictofixedwidth"').$langs->trans("Disable"),
466 );
467 if ($permissiontodelete) {
468  $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
469 }
470 if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
471  $arrayofmassactions = array();
472 }
473 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
474 
475 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
476 if ($optioncss != '') {
477  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
478 }
479 print '<input type="hidden" name="token" value="'.newToken().'">';
480 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
481 print '<input type="hidden" name="action" value="list">';
482 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
483 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
484 print '<input type="hidden" name="page" value="'.$page.'">';
485 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
486 
487 $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);
488 
489 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
490 
491 // Add code for pre mass action (confirmation or email presend form)
492 $topicmail = "SendBillOfMaterialsRef";
493 $modelmail = "bom";
494 $objecttmp = new BOM($db);
495 $trackid = 'bom'.$object->id;
496 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
497 
498 if ($search_all) {
499  foreach ($fieldstosearchall as $key => $val) {
500  $fieldstosearchall[$key] = $langs->trans($val);
501  }
502  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
503 }
504 
505 $moreforfilter = '';
506 /*$moreforfilter.='<div class="divsearchfield">';
507 $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
508 $moreforfilter.= '</div>';*/
509 
510 $parameters = array();
511 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
512 if (empty($reshook)) {
513  $moreforfilter .= $hookmanager->resPrint;
514 } else {
515  $moreforfilter = $hookmanager->resPrint;
516 }
517 
518 if (!empty($moreforfilter)) {
519  print '<div class="liste_titre liste_titre_bydiv centpercent">';
520  print $moreforfilter;
521  print '</div>';
522 }
523 
524 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
525 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')); // This also change content of $arrayfields
526 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
527 
528 print '<div class="div-table-responsive">';
529 print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
530 
531 
532 // Fields title search
533 // --------------------------------------------------------------------
534 print '<tr class="liste_titre">';
535 
536 // Action column
537 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
538  print '<td class="liste_titre center">';
539  $searchpicto = $form->showFilterButtons('left');
540  print $searchpicto;
541  print '</td>';
542 }
543 
544 foreach ($object->fields as $key => $val) {
545  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
546  if ($key == 'status') {
547  $cssforfield .= ($cssforfield ? ' ' : '').'center';
548  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
549  $cssforfield .= ($cssforfield ? ' ' : '').'center';
550  } elseif (in_array($val['type'], array('timestamp'))) {
551  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
552  } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
553  $cssforfield .= ($cssforfield ? ' ' : '').'right';
554  }
555  if (!empty($arrayfields['t.'.$key]['checked'])) {
556  print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
557  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
558  print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100'.($key == 'status' ? ' search_status onrightofpage' : ''), 1);
559  } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
560  print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', 'maxwidth125', 1);
561  } elseif (!preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
562  print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
563  } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
564  print '<div class="nowrap">';
565  print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
566  print '</div>';
567  print '<div class="nowrap">';
568  print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
569  print '</div>';
570  }
571  print '</td>';
572  }
573 }
574 // Extra fields
575 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
576 
577 // Fields from hook
578 $parameters = array('arrayfields'=>$arrayfields);
579 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
580 print $hookmanager->resPrint;
581 // Action column
582 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
583  print '<td class="liste_titre center">';
584  $searchpicto = $form->showFilterButtons();
585  print $searchpicto;
586  print '</td>';
587 }
588 print '</tr>'."\n";
589 
590 
591 // Fields title label
592 // --------------------------------------------------------------------
593 print '<tr class="liste_titre">';
594 // Action column
595 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
596  print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
597 }
598 foreach ($object->fields as $key => $val) {
599  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
600  if ($key == 'status') {
601  $cssforfield .= ($cssforfield ? ' ' : '').'center';
602  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
603  $cssforfield .= ($cssforfield ? ' ' : '').'center';
604  } elseif (in_array($val['type'], array('timestamp'))) {
605  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
606  } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
607  $cssforfield .= ($cssforfield ? ' ' : '').'right';
608  }
609  if (!empty($arrayfields['t.'.$key]['checked'])) {
610  print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
611  }
612 }
613 // Extra fields
614 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
615 // Hook fields
616 $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
617 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
618 print $hookmanager->resPrint;
619 // Action column
620 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
621  print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
622 }
623 print '</tr>'."\n";
624 
625 
626 // Detect if we need a fetch on each output line
627 $needToFetchEachLine = 0;
628 if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
629  foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
630  if (preg_match('/\$object/', $val)) {
631  $needToFetchEachLine++; // There is at least one compute field that use $object
632  }
633  }
634 }
635 
636 
637 // Loop on record
638 // --------------------------------------------------------------------
639 $i = 0;
640 $totalarray = array();
641 $totalarray['nbfield'] = 0;
642 while ($i < ($limit ? min($num, $limit) : $num)) {
643  $obj = $db->fetch_object($resql);
644  if (empty($obj)) {
645  break; // Should not happen
646  }
647 
648  // Store properties in $object
649  $object->setVarsFromFetchObj($obj);
650 
651  // Show here line of result
652  print '<tr class="oddeven">';
653  // Action column
654  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
655  print '<td class="nowrap center">';
656  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
657  $selected = 0;
658  if (in_array($object->id, $arrayofselected)) {
659  $selected = 1;
660  }
661  print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
662  }
663  print '</td>';
664  }
665  foreach ($object->fields as $key => $val) {
666  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
667  if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
668  $cssforfield .= ($cssforfield ? ' ' : '').'center';
669  } elseif ($key == 'status') {
670  $cssforfield .= ($cssforfield ? ' ' : '').'center';
671  }
672 
673  if (in_array($val['type'], array('timestamp'))) {
674  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
675  } elseif ($key == 'ref') {
676  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
677  }
678 
679  if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
680  $cssforfield .= ($cssforfield ? ' ' : '').'right';
681  }
682 
683  if (!empty($arrayfields['t.'.$key]['checked'])) {
684  print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '').'>';
685  if ($key == 'status') {
686  print $object->getLibStatut(5);
687  } elseif ($key == 'rowid') {
688  print $object->showOutputField($val, $key, $object->id, '');
689  } else {
690  print $object->showOutputField($val, $key, $object->$key, '');
691  }
692  print '</td>';
693  if (!$i) {
694  $totalarray['nbfield']++;
695  }
696  if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
697  if (!$i) {
698  $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
699  }
700  if (!isset($totalarray['val'])) {
701  $totalarray['val'] = array();
702  }
703  if (!isset($totalarray['val']['t.'.$key])) {
704  $totalarray['val']['t.'.$key] = 0;
705  }
706  $totalarray['val']['t.'.$key] += $object->$key;
707  }
708  }
709  }
710  // Extra fields
711  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
712  // Fields from hook
713  $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
714  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
715  print $hookmanager->resPrint;
716  // Action column
717  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
718  print '<td class="nowrap center">';
719  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
720  $selected = 0;
721  if (in_array($object->id, $arrayofselected)) {
722  $selected = 1;
723  }
724  print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
725  }
726  print '</td>';
727  }
728  if (!$i) {
729  $totalarray['nbfield']++;
730  }
731 
732  print '</tr>'."\n";
733 
734  $i++;
735 }
736 
737 // Show total line
738 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
739 
740 
741 // If no record found
742 if ($num == 0) {
743  $colspan = 1;
744  foreach ($arrayfields as $key => $val) {
745  if (!empty($val['checked'])) {
746  $colspan++;
747  }
748  }
749  print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
750 }
751 
752 
753 $db->free($resql);
754 
755 $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
756 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
757 print $hookmanager->resPrint;
758 
759 print '</table>'."\n";
760 print '</div>'."\n";
761 
762 print '</form>'."\n";
763 
764 
765 if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
766  $hidegeneratedfilelistifempty = 1;
767  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
768  $hidegeneratedfilelistifempty = 0;
769  }
770 
771  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
772  $formfile = new FormFile($db);
773 
774  // Show list of available documents
775  $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
776  $urlsource .= str_replace('&amp;', '&', $param);
777 
778  $filedir = $diroutputmassaction;
779  $genallowed = $permissiontoread;
780  $delallowed = $permissiontoadd;
781 
782  print $formfile->showdocuments('massfilesarea_bom', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
783 }
784 
785 // End of page
786 llxFooter();
787 $db->close();
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class for BOM.
Definition: bom.class.php:37
Class to manage standard extra fields.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
dol_eval($s, $returnvalue=0, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
$nbtotalofrecords
Count total nb of records.
Definition: list.php:329
restrictedArea(User $user, $features, $object=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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.