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