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