dolibarr  17.0.4
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 
233 $sqlfields = $sql; // $sql fields to remove for count total
234 
235 $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
236 if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
237  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
238 }
239 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."mrp_production as lineparent ON t.fk_parent_line = lineparent.rowid";
240 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."mrp_mo as moparent ON lineparent.fk_mo = moparent.rowid";
241 // Add table from hooks
242 $parameters = array();
243 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
244 $sql .= $hookmanager->resPrint;
245 if ($object->ismultientitymanaged == 1) {
246  $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
247 } else {
248  $sql .= " WHERE 1 = 1";
249 }
250 
251 foreach ($search as $key => $val) {
252  if (array_key_exists($key, $object->fields)) {
253  if ($key == 'status' && $search[$key] == -1) {
254  continue;
255  }
256  if ($key == 'fk_parent_line' && $search[$key] != '') {
257  $sql .= natural_search('moparent.ref', $search[$key], 0);
258  continue;
259  }
260 
261  if ($key == 'status') {
262  $sql .= natural_search('t.status', $search[$key], 0);
263  continue;
264  }
265 
266 
267  $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
268  if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
269  if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
270  $search[$key] = '';
271  }
272  $mode_search = 2;
273  }
274  if ($search[$key] != '') {
275  $sql .= natural_search("t.".$db->escape($key), $search[$key], (($key == 'status') ? 2 : $mode_search));
276  }
277  } else {
278  if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
279  $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
280  if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
281  if (preg_match('/_dtstart$/', $key)) {
282  $sql .= " AND t.".$db->escape($columnName)." >= '".$db->idate($search[$key])."'";
283  }
284  if (preg_match('/_dtend$/', $key)) {
285  $sql .= " AND t.".$db->escape($columnName)." <= '".$db->idate($search[$key])."'";
286  }
287  }
288  }
289  }
290 }
291 if ($search_all) {
292  $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
293 }
294 //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
295 // Add where from extra fields
296 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
297 // Add where from hooks
298 $parameters = array();
299 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
300 $sql .= $hookmanager->resPrint;
301 
302 /* If a group by is required
303 $sql.= " GROUP BY ";
304 foreach($object->fields as $key => $val) {
305  $sql .= "t.".$key.", ";
306 }
307 // Add fields from extrafields
308 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
309  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
310  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.", " : "");
311  }
312 }
313 // Add where from hooks
314 $parameters=array();
315 $reshook=$hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
316 $sql.=$hookmanager->resPrint;
317 $sql=preg_replace('/,\s*$/','', $sql);
318 */
319 
320 // Count total nb of records
321 $nbtotalofrecords = '';
322 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
323  /* The fast and low memory method to get and count full list converts the sql into a sql count */
324  $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
325  $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
326  $resql = $db->query($sqlforcount);
327  if ($resql) {
328  $objforcount = $db->fetch_object($resql);
329  $nbtotalofrecords = $objforcount->nbtotalofrecords;
330  } else {
331  dol_print_error($db);
332  }
333 
334  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
335  $page = 0;
336  $offset = 0;
337  }
338  $db->free($resql);
339 }
340 
341 // Complete request and execute it with limit
342 $sql .= $db->order($sortfield, $sortorder);
343 if ($limit) {
344  $sql .= $db->plimit($limit + 1, $offset);
345 }
346 
347 $resql = $db->query($sql);
348 if (!$resql) {
349  dol_print_error($db);
350  exit;
351 }
352 
353 $num = $db->num_rows($resql);
354 
355 // Direct jump if only one record found
356 if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
357  $obj = $db->fetch_object($resql);
358  $id = $obj->rowid;
359  header("Location: ".dol_buildpath('/mrp/mo_card.php', 1).'?id='.$id);
360  exit;
361 }
362 
363 
364 // Output page
365 // --------------------------------------------------------------------
366 
367 llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', '');
368 
369 
370 $arrayofselected = is_array($toselect) ? $toselect : array();
371 
372 $param = '';
373 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
374  $param .= '&contextpage='.urlencode($contextpage);
375 }
376 if ($limit > 0 && $limit != $conf->liste_limit) {
377  $param .= '&limit='.urlencode($limit);
378 }
379 foreach ($search as $key => $val) {
380  if (is_array($search[$key]) && count($search[$key])) {
381  foreach ($search[$key] as $skey) {
382  if ($skey != '') {
383  $param .= '&search_'.$key.'[]='.urlencode($skey);
384  }
385  }
386  } elseif ($search[$key] != '') {
387  $param .= '&search_'.$key.'='.urlencode($search[$key]);
388  }
389 }
390 if ($optioncss != '') {
391  $param .= '&optioncss='.urlencode($optioncss);
392 }
393 // Add $param from extra fields
394 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
395 // Add $param from hooks
396 $parameters = array();
397 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
398 $param .= $hookmanager->resPrint;
399 
400 // List of mass actions available
401 $arrayofmassactions = array(
402  //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
403  //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
404  //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
405  //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
406 );
407 if ($permissiontodelete) {
408  $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
409 }
410 if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
411  $arrayofmassactions = array();
412 }
413 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
414 
415 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
416 if ($optioncss != '') {
417  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
418 }
419 print '<input type="hidden" name="token" value="'.newToken().'">';
420 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
421 print '<input type="hidden" name="action" value="list">';
422 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
423 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
424 print '<input type="hidden" name="page" value="'.$page.'">';
425 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
426 
427 $newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/mrp/mo_card.php?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
428 
429 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
430 
431 // Add code for pre mass action (confirmation or email presend form)
432 $topicmail = "SendMoRef";
433 $modelmail = "mo";
434 $objecttmp = new Mo($db);
435 $trackid = 'mo'.$object->id;
436 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
437 
438 if ($search_all) {
439  foreach ($fieldstosearchall as $key => $val) {
440  $fieldstosearchall[$key] = $langs->trans($val);
441  }
442  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
443 }
444 
445 $moreforfilter = '';
446 /*$moreforfilter.='<div class="divsearchfield">';
447 $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
448 $moreforfilter.= '</div>';*/
449 
450 $parameters = array();
451 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
452 if (empty($reshook)) {
453  $moreforfilter .= $hookmanager->resPrint;
454 } else {
455  $moreforfilter = $hookmanager->resPrint;
456 }
457 
458 if (!empty($moreforfilter)) {
459  print '<div class="liste_titre liste_titre_bydiv centpercent">';
460  print $moreforfilter;
461  print '</div>';
462 }
463 
464 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
465 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')); // This also change content of $arrayfields
466 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
467 
468 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
469 print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
470 
471 
472 // Fields title search
473 // --------------------------------------------------------------------
474 print '<tr class="liste_titre">';
475 // Action column
476 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
477  print '<td class="liste_titre maxwidthsearch">';
478  $searchpicto = $form->showFilterButtons('left');
479  print $searchpicto;
480  print '</td>';
481 }
482 foreach ($object->fields as $key => $val) {
483  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
484  if ($key == 'status') {
485  $cssforfield .= ($cssforfield ? ' ' : '').'center';
486  } elseif ($key == 'fk_parent_line') {
487  $cssforfield .= ($cssforfield ? ' ' : '').'center';
488  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
489  $cssforfield .= ($cssforfield ? ' ' : '').'center';
490  } elseif (in_array($val['type'], array('timestamp'))) {
491  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
492  } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
493  $cssforfield .= ($cssforfield ? ' ' : '').'right';
494  }
495  if (!empty($arrayfields['t.'.$key]['checked'])) {
496  print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
497  if ($key == 'fk_parent_line') {
498  print '<input type="text" class="flat maxwidth75" name="search_fk_parent_line">';
499  print '</td>';
500  continue;
501  }
502  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
503  print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
504  } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
505  print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', 'maxwidth125', 1);
506  } elseif (!preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
507  print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
508  } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
509  print '<div class="nowrap">';
510  print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
511  print '</div>';
512  print '<div class="nowrap">';
513  print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
514  print '</div>';
515  }
516  print '</td>';
517  }
518 }
519 // Extra fields
520 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
521 
522 // Fields from hook
523 $parameters = array('arrayfields'=>$arrayfields);
524 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
525 print $hookmanager->resPrint;
526 // Action column
527 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
528  print '<td class="liste_titre maxwidthsearch">';
529  $searchpicto = $form->showFilterButtons();
530  print $searchpicto;
531  print '</td>';
532 }
533 print '</tr>'."\n";
534 
535 
536 // Fields title label
537 // --------------------------------------------------------------------
538 print '<tr class="liste_titre">';
539 // Action column
540 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
541  print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
542 }
543 foreach ($object->fields as $key => $val) {
544  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
545  if ($key == 'status') {
546  $cssforfield .= ($cssforfield ? ' ' : '').'center';
547  } elseif ($key == 'fk_parent_line') {
548  $cssforfield .= ($cssforfield ? ' ' : '').'center';
549  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
550  $cssforfield .= ($cssforfield ? ' ' : '').'center';
551  } elseif (in_array($val['type'], array('timestamp'))) {
552  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
553  } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
554  $cssforfield .= ($cssforfield ? ' ' : '').'right';
555  }
556  if (!empty($arrayfields['t.'.$key]['checked'])) {
557  print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
558  }
559 }
560 // Extra fields
561 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
562 // Hook fields
563 $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
564 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
565 print $hookmanager->resPrint;
566 // Action column
567 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
568  print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
569 }
570 print '</tr>'."\n";
571 
572 
573 // Detect if we need a fetch on each output line
574 $needToFetchEachLine = 0;
575 if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
576  foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
577  if (preg_match('/\$object/', $val)) {
578  $needToFetchEachLine++; // There is at least one compute field that use $object
579  }
580  }
581 }
582 
583 
584 // Loop on record
585 // --------------------------------------------------------------------
586 $i = 0;
587 $totalarray = array();
588 $totalarray['nbfield'] = 0;
589 while ($i < ($limit ? min($num, $limit) : $num)) {
590  $obj = $db->fetch_object($resql);
591  if (empty($obj)) {
592  break; // Should not happen
593  }
594 
595  // Store properties in $object
596  $object->setVarsFromFetchObj($obj);
597 
598  // Show here line of result
599  print '<tr class="oddeven">';
600  // Action column
601  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
602  print '<td class="nowrap center">';
603  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
604  $selected = 0;
605  if (in_array($object->id, $arrayofselected)) {
606  $selected = 1;
607  }
608  print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
609  }
610  print '</td>';
611  }
612  foreach ($object->fields as $key => $val) {
613  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
614  if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
615  $cssforfield .= ($cssforfield ? ' ' : '').'center';
616  } elseif ($key == 'status') {
617  $cssforfield .= ($cssforfield ? ' ' : '').'center';
618  } elseif ($key == 'fk_parent_line') {
619  $cssforfield .= ($cssforfield ? ' ' : '').'center';
620  }
621 
622  if (in_array($val['type'], array('timestamp'))) {
623  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
624  } elseif ($key == 'ref') {
625  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
626  }
627 
628  if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
629  $cssforfield .= ($cssforfield ? ' ' : '').'right';
630  }
631 
632  if (!empty($arrayfields['t.'.$key]['checked'])) {
633  print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '').'>';
634  if ($key == 'status') {
635  print $object->getLibStatut(5);
636  } elseif ($key == 'fk_parent_line') {
637  $moparent = $object->getMoParent();
638  if (is_object($moparent)) print $moparent->getNomUrl(1);
639  } elseif ($key == 'rowid') {
640  print $object->showOutputField($val, $key, $object->id, '');
641  } else {
642  print $object->showOutputField($val, $key, $object->$key, '');
643  }
644  print '</td>';
645  if (!$i) {
646  $totalarray['nbfield']++;
647  }
648  if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
649  if (!$i) {
650  $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
651  }
652  if (!isset($totalarray['val'])) {
653  $totalarray['val'] = array();
654  }
655  if (!isset($totalarray['val']['t.'.$key])) {
656  $totalarray['val']['t.'.$key] = 0;
657  }
658  $totalarray['val']['t.'.$key] += $object->$key;
659  }
660  }
661  }
662  // Extra fields
663  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
664  // Fields from hook
665  $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
666  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
667  print $hookmanager->resPrint;
668  // Action column
669  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
670  print '<td class="nowrap center">';
671  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
672  $selected = 0;
673  if (in_array($object->id, $arrayofselected)) {
674  $selected = 1;
675  }
676  print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
677  }
678  print '</td>';
679  }
680  if (!$i) {
681  $totalarray['nbfield']++;
682  }
683 
684  print '</tr>'."\n";
685 
686  $i++;
687 }
688 
689 // Show total line
690 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
691 
692 
693 // If no record found
694 if ($num == 0) {
695  $colspan = 1;
696  foreach ($arrayfields as $key => $val) {
697  if (!empty($val['checked'])) {
698  $colspan++;
699  }
700  }
701  print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
702 }
703 
704 
705 $db->free($resql);
706 
707 $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
708 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
709 print $hookmanager->resPrint;
710 
711 print '</table>'."\n";
712 print '</div>'."\n";
713 
714 print '</form>'."\n";
715 
716 if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
717  $hidegeneratedfilelistifempty = 1;
718  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
719  $hidegeneratedfilelistifempty = 0;
720  }
721 
722  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
723  $formfile = new FormFile($db);
724 
725  // Show list of available documents
726  $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
727  $urlsource .= str_replace('&amp;', '&', $param);
728 
729  $filedir = $diroutputmassaction;
730  $genallowed = $permissiontoread;
731  $delallowed = $permissiontoadd;
732 
733  print $formfile->showdocuments('massfilesarea_mrp', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
734 }
735 
736 // End of page
737 llxFooter();
738 $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 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:36
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.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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.