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