dolibarr 20.0.0
mo_list.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
24// Load Dolibarr environment
25require '../main.inc.php';
26
27require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
31require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
32
33// load mrp libraries
34require_once __DIR__.'/class/mo.class.php';
35
36// for other modules
37//dol_include_once('/othermodule/class/otherobject.class.php');
38
39// Load translation files required by the page
40$langs->loadLangs(array("mrp", "other"));
41
42// Get parameters
43$action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
44$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
45$show_files = GETPOSTINT('show_files'); // Show files area generated by bulk actions ?
46$confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
47$cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
48$toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
49$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)).basename(__FILE__, '.php')); // To manage different context of search
50$backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
51$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
52$mode = GETPOST('mode', 'alpha');
53
54$id = GETPOSTINT('id');
55
56// Load variable for pagination
57$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
58$sortfield = GETPOST('sortfield', 'aZ09comma');
59$sortorder = GETPOST('sortorder', 'aZ09comma');
60$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
61if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
62 // If $page is not defined, or '' or -1 or if we click on clear filters
63 $page = 0;
64}
65$offset = $limit * $page;
66$pageprev = $page - 1;
67$pagenext = $page + 1;
68//if (! $sortfield) $sortfield="p.date_fin";
69//if (! $sortorder) $sortorder="DESC";
70
71// Initialize technical objects
72$object = new Mo($db);
73$extrafields = new ExtraFields($db);
74$diroutputmassaction = $conf->mrp->dir_output.'/temp/massgeneration/'.$user->id;
75$hookmanager->initHooks(array($contextpage)); // Note that conf->hooks_modules contains array of activated contexes
76
77// Fetch optionals attributes and labels
78$extrafields->fetch_name_optionals_label($object->table_element);
79
80$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
81
82// Default sort order (if not yet defined by previous GETPOST)
83if (!$sortfield) {
84 $sortfield = "t.ref"; // Set here default search field. By default 1st field in definition.
85}
86if (!$sortorder) {
87 $sortorder = "ASC";
88}
89
90// Initialize array of search criteria
91$search_all = trim(GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
92$search = array();
93foreach ($object->fields as $key => $val) {
94 if (GETPOST('search_'.$key, 'alpha') !== '') {
95 $search[$key] = GETPOST('search_'.$key, 'alpha');
96 }
97 if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
98 $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOSTINT('search_'.$key.'_dtstartmonth'), GETPOSTINT('search_'.$key.'_dtstartday'), GETPOSTINT('search_'.$key.'_dtstartyear'));
99 $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOSTINT('search_'.$key.'_dtendmonth'), GETPOSTINT('search_'.$key.'_dtendday'), GETPOSTINT('search_'.$key.'_dtendyear'));
100 }
101}
102
103// List of fields to search into when doing a "search in all"
104$fieldstosearchall = array();
105foreach ($object->fields as $key => $val) {
106 if (!empty($val['searchall'])) {
107 $fieldstosearchall['t.'.$key] = $val['label'];
108 }
109}
110
111// Definition of array of fields for columns
112$arrayfields = array();
113foreach ($object->fields as $key => $val) {
114 // If $val['visible']==0, then we never show the field
115 if (!empty($val['visible'])) {
116 $visible = (int) dol_eval($val['visible'], 1);
117 $arrayfields['t.'.$key] = array(
118 'label'=>$val['label'],
119 'checked'=>(($visible < 0) ? 0 : 1),
120 'enabled'=>(abs($visible) != 3 && (bool) dol_eval($val['enabled'], 1)),
121 'position'=>$val['position'],
122 'help'=> isset($val['help']) ? $val['help'] : ''
123 );
124 }
125
126 if ($key == 'fk_parent_line') {
127 $visible = (int) dol_eval($val['visible'], 1);
128 $arrayfields['t.'.$key] = array(
129 'label'=>$val['label'],
130 'checked'=>(($visible <= 0) ? 0 : 1),
131 'enabled'=>(abs($visible) != 3 && (bool) dol_eval($val['enabled'], 1)),
132 'position'=>$val['position'],
133 'help'=> isset($val['help']) ? $val['help'] : ''
134 );
135 }
136}
137// Extra fields
138include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
139
140$object->fields = dol_sort_array($object->fields, 'position');
141$arrayfields = dol_sort_array($arrayfields, 'position');
142
143$permissiontoread = $user->hasRight('mrp', 'read');
144$permissiontoadd = $user->hasRight('mrp', 'write');
145$permissiontodelete = $user->hasRight('mrp', 'delete');
146
147// Security check
148if ($user->socid > 0) {
150}
151$result = restrictedArea($user, 'mrp');
152
153
154/*
155 * Actions
156 */
157
158if (GETPOST('cancel', 'alpha')) {
159 $action = 'list';
160 $massaction = '';
161}
162if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
163 $massaction = '';
164}
165
166$parameters = array();
167$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
168if ($reshook < 0) {
169 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
170}
171
172if (empty($reshook)) {
173 // Selection of new fields
174 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
175
176 // Purge search criteria
177 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
178 foreach ($object->fields as $key => $val) {
179 $search[$key] = '';
180 if ($key == 'status') {
181 $search[$key] = -1;
182 }
183 if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
184 $search[$key.'_dtstart'] = '';
185 $search[$key.'_dtend'] = '';
186 }
187 }
188 $search_all = '';
189 $toselect = array();
190 $search_array_options = array();
191 }
192 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
193 || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
194 $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
195 }
196
197 // Mass actions
198 $objectclass = 'Mo';
199 $objectlabel = 'Mo';
200 $uploaddir = $conf->mrp->dir_output;
201 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
202}
203
204
205
206/*
207 * View
208 */
209
210$form = new Form($db);
211
212$now = dol_now();
213
214//$help_url="EN:Module_Mo|FR:Module_Mo_FR|ES:Módulo_Mo";
215$help_url = '';
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');
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 print '</div>';
480}
481
482$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
483$htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields with user setup
484$selectedfields = ($mode != 'kanban' ? $htmlofselectarray : '');
485$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
486
487print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
488print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
489
490
491// Fields title search
492// --------------------------------------------------------------------
493print '<tr class="liste_titre_filter">';
494// Action column
495if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
496 print '<td class="liste_titre center maxwidthsearch">';
497 $searchpicto = $form->showFilterButtons('left');
498 print $searchpicto;
499 print '</td>';
500}
501foreach ($object->fields as $key => $val) {
502 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
503 if ($key == 'status') {
504 $cssforfield .= ($cssforfield ? ' ' : '').'center';
505 } elseif ($key == 'fk_parent_line') {
506 $cssforfield .= ($cssforfield ? ' ' : '').'center';
507 } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
508 $cssforfield .= ($cssforfield ? ' ' : '').'center';
509 } elseif (in_array($val['type'], array('timestamp'))) {
510 $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
511 } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
512 $cssforfield .= ($cssforfield ? ' ' : '').'right';
513 }
514 if (!empty($arrayfields['t.'.$key]['checked'])) {
515 print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
516 if ($key == 'fk_parent_line') {
517 print '<input type="text" class="flat maxwidth75" name="search_fk_parent_line">';
518 print '</td>';
519 continue;
520 }
521 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
522 print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
523 } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
524 print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', 'maxwidth125', 1);
525 } elseif (!preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
526 print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
527 } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
528 print '<div class="nowrap">';
529 print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
530 print '</div>';
531 print '<div class="nowrap">';
532 print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
533 print '</div>';
534 }
535 print '</td>';
536 }
537}
538// Extra fields
539include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
540
541// Fields from hook
542$parameters = array('arrayfields'=>$arrayfields);
543$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
544print $hookmanager->resPrint;
545// Action column
546if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
547 print '<td class="liste_titre center maxwidthsearch">';
548 $searchpicto = $form->showFilterButtons();
549 print $searchpicto;
550 print '</td>';
551}
552print '</tr>'."\n";
553
554$totalarray = array();
555$totalarray['nbfield'] = 0;
556
557
558// Fields title label
559// --------------------------------------------------------------------
560print '<tr class="liste_titre">';
561// Action column
562if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
563 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
564 $totalarray['nbfield']++;
565}
566foreach ($object->fields as $key => $val) {
567 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
568 if ($key == 'status') {
569 $cssforfield .= ($cssforfield ? ' ' : '').'center';
570 } elseif ($key == 'fk_parent_line') {
571 $cssforfield .= ($cssforfield ? ' ' : '').'center';
572 } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
573 $cssforfield .= ($cssforfield ? ' ' : '').'center';
574 } elseif (in_array($val['type'], array('timestamp'))) {
575 $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
576 } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
577 $cssforfield .= ($cssforfield ? ' ' : '').'right';
578 }
579 if (!empty($arrayfields['t.'.$key]['checked'])) {
580 if ($key == "fk_product") {
581 print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 'p.ref', '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
582 } else {
583 print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
584 }
585 $totalarray['nbfield']++;
586 }
587}
588// Extra fields
589include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
590// Hook fields
591$parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
592$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
593print $hookmanager->resPrint;
594// Action column
595if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
596 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
597 $totalarray['nbfield']++;
598}
599print '</tr>'."\n";
600
601
602// Detect if we need a fetch on each output line
603$needToFetchEachLine = 0;
604if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
605 foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
606 if (!is_null($val) && preg_match('/\$object/', $val)) {
607 $needToFetchEachLine++; // There is at least one compute field that use $object
608 }
609 }
610}
611
612
613$bom = new BOM($db);
614$product = new Product($db);
615
616// Loop on record
617// --------------------------------------------------------------------
618$i = 0;
619$savnbfield = $totalarray['nbfield'];
620$totalarray = array();
621$totalarray['nbfield'] = 0;
622$imaxinloop = ($limit ? min($num, $limit) : $num);
623while ($i < $imaxinloop) {
624 $obj = $db->fetch_object($resql);
625 if (empty($obj)) {
626 break; // Should not happen
627 }
628
629 // Store properties in $object
630 $object->setVarsFromFetchObj($obj);
631
632
633 if ($mode == 'kanban') {
634 if ($i == 0) {
635 print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
636 print '<div class="box-flex-container kanban">';
637 }
638 //$object->type_id = $obj->type_id;
639
640 // TODO Use a cache on BOM
641 if ($obj->fk_bom > 0) {
642 $bom->fetch($obj->fk_bom);
643 }
644 if ($obj->fk_product > 0) {
645 $product->fetch($obj->fk_product);
646 }
647
648 // Output Kanban
649 $selected = -1;
650 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
651 $selected = 0;
652 if (in_array($object->id, $arrayofselected)) {
653 $selected = 1;
654 }
655 }
656 print $object->getKanbanView('', array('bom'=>($obj->fk_bom > 0 ? $bom : null), 'product'=>($obj->fk_product > 0 ? $product : null), 'selected' => $selected));
657 if ($i == ($imaxinloop - 1)) {
658 print '</div>';
659 print '</td></tr>';
660 }
661 } else {
662 // Show line of result
663 $j = 0;
664 print '<tr data-rowid="'.$object->id.'" class="oddeven">';
665
666 // Action column
667 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
668 print '<td class="nowrap center">';
669 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
670 $selected = 0;
671 if (in_array($object->id, $arrayofselected)) {
672 $selected = 1;
673 }
674 print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
675 }
676 print '</td>';
677 if (!$i) {
678 $totalarray['nbfield']++;
679 }
680 }
681 // Fields
682 foreach ($object->fields as $key => $val) {
683 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
684 if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
685 $cssforfield .= ($cssforfield ? ' ' : '').'center';
686 } elseif ($key == 'status') {
687 $cssforfield .= ($cssforfield ? ' ' : '').'center';
688 } elseif ($key == 'fk_parent_line') {
689 $cssforfield .= ($cssforfield ? ' ' : '').'center';
690 }
691
692 if (in_array($val['type'], array('timestamp'))) {
693 $cssforfield .= ($cssforfield ? ' ' : '').'nowraponall';
694 } elseif ($key == 'ref') {
695 $cssforfield .= ($cssforfield ? ' ' : '').'nowraponall';
696 }
697
698 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'])) {
699 $cssforfield .= ($cssforfield ? ' ' : '').'right';
700 }
701
702 if (!empty($arrayfields['t.'.$key]['checked'])) {
703 print '<td'.($cssforfield ? ' class="'.$cssforfield.((preg_match('/tdoverflow/', $cssforfield) && !in_array($val['type'], array('ip', 'url')) && !is_numeric($object->$key)) ? ' classfortooltip' : '').'"' : '');
704 if (preg_match('/tdoverflow/', $cssforfield) && !in_array($val['type'], array('ip', 'url')) && !is_numeric($object->$key)) {
705 print ' title="'.dol_escape_htmltag($object->$key).'"';
706 }
707 print '>';
708 if ($key == 'status') {
709 print $object->getLibStatut(5);
710 } elseif ($key == 'fk_parent_line') {
711 $moparent = $object->getMoParent();
712 if (is_object($moparent)) {
713 print $moparent->getNomUrl(1);
714 }
715 } elseif ($key == 'rowid') {
716 print $object->showOutputField($val, $key, $object->id, '');
717 } else {
718 print $object->showOutputField($val, $key, $object->$key, '');
719 }
720 print '</td>';
721 if (!$i) {
722 $totalarray['nbfield']++;
723 }
724 if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
725 if (!$i) {
726 $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
727 }
728 if (!isset($totalarray['val'])) {
729 $totalarray['val'] = array();
730 }
731 if (!isset($totalarray['val']['t.'.$key])) {
732 $totalarray['val']['t.'.$key] = 0;
733 }
734 $totalarray['val']['t.'.$key] += $object->$key;
735 }
736 }
737 }
738 // Extra fields
739 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
740 // Fields from hook
741 $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
742 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
743 print $hookmanager->resPrint;
744
745 // Action column
746 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
747 print '<td class="nowrap center">';
748 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
749 $selected = 0;
750 if (in_array($object->id, $arrayofselected)) {
751 $selected = 1;
752 }
753 print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
754 }
755 print '</td>';
756 if (!$i) {
757 $totalarray['nbfield']++;
758 }
759 }
760
761 print '</tr>'."\n";
762 }
763 $i++;
764}
765
766// Show total line
767include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
768
769
770// If no record found
771if ($num == 0) {
772 $colspan = 1;
773 foreach ($arrayfields as $key => $val) {
774 if (!empty($val['checked'])) {
775 $colspan++;
776 }
777 }
778 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
779}
780
781
782$db->free($resql);
783
784$parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
785$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
786print $hookmanager->resPrint;
787
788print '</table>'."\n";
789print '</div>'."\n";
790
791print '</form>'."\n";
792
793if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
794 $hidegeneratedfilelistifempty = 1;
795 if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
796 $hidegeneratedfilelistifempty = 0;
797 }
798
799 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
800 $formfile = new FormFile($db);
801
802 // Show list of available documents
803 $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
804 $urlsource .= str_replace('&amp;', '&', $param);
805
806 $filedir = $diroutputmassaction;
807 $genallowed = $permissiontoread;
808 $delallowed = $permissiontoadd;
809
810 print $formfile->showdocuments('massfilesarea_mrp', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
811}
812
813// End of page
814llxFooter();
815$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()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
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.
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.