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