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