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