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