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