dolibarr 21.0.0-alpha
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../../../main.inc.php';
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.'/core/lib/functions.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/product/stock/stocktransfer/class/stocktransfer.class.php';
34
35// Load translation files required by the page
36$langs->loadLangs(array("stocks", "other"));
37
38// Get parameters
39$action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
40$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
41$show_files = GETPOSTINT('show_files'); // Show files area generated by bulk actions ?
42$confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
43$cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
44$toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
45$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'stocktransferlist'; // To manage different context of search
46$backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
47$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
48$mode = GETPOST('mode', 'aZ'); // The output mode ('list', 'kanban', 'hierarchy', 'calendar', ...)
49
50$id = GETPOSTINT('id');
51
52// Load variable for pagination
53$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
54$sortfield = GETPOST('sortfield', 'aZ09comma');
55$sortorder = GETPOST('sortorder', 'aZ09comma');
56$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
57if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
58 // If $page is not defined, or '' or -1 or if we click on clear filters
59 $page = 0;
60}
61$offset = $limit * $page;
62$pageprev = $page - 1;
63$pagenext = $page + 1;
64
65// Initialize a technical objects
66$object = new StockTransfer($db);
67$extrafields = new ExtraFields($db);
68$diroutputmassaction = getMultidirOutput($object).'/temp/massgeneration/'.$user->id;
69$hookmanager->initHooks(array('stocktransferlist')); // Note that conf->hooks_modules contains array
70
71// Fetch optionals attributes and labels
72$extrafields->fetch_name_optionals_label($object->table_element);
73//$extrafields->fetch_name_optionals_label($object->table_element_line);
74
75$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
76
77// Default sort order (if not yet defined by previous GETPOST)
78if (!$sortfield) {
79 reset($object->fields); // Reset is required to avoid key() to return null.
80 $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
81}
82if (!$sortorder) {
83 $sortorder = "ASC";
84}
85
86// Initialize array of search criteria
87$search_all = trim(GETPOST('search_all', 'alphanohtml'));
88$search = array();
89foreach ($object->fields as $key => $val) {
90 if (GETPOST('search_'.$key, 'alpha') !== '') {
91 $search[$key] = GETPOST('search_'.$key, 'alpha');
92 }
93 if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
94 $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOSTINT('search_'.$key.'_dtstartmonth'), GETPOSTINT('search_'.$key.'_dtstartday'), GETPOSTINT('search_'.$key.'_dtstartyear'));
95 $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOSTINT('search_'.$key.'_dtendmonth'), GETPOSTINT('search_'.$key.'_dtendday'), GETPOSTINT('search_'.$key.'_dtendyear'));
96 }
97}
98
99// List of fields to search into when doing a "search in all"
100$fieldstosearchall = array();
101foreach ($object->fields as $key => $val) {
102 if (!empty($val['searchall'])) {
103 $fieldstosearchall['t.'.$key] = $val['label'];
104 }
105}
106
107// Definition of array of fields for columns
108$arrayfields = array();
109foreach ($object->fields as $key => $val) {
110 // If $val['visible']==0, then we never show the field
111 if (!empty($val['visible'])) {
112 $visible = (int) dol_eval((string) $val['visible'], 1);
113 $arrayfields['t.'.$key] = array(
114 'label' => $val['label'],
115 'checked' => (($visible < 0) ? 0 : 1),
116 'enabled' => (abs($visible) != 3 && (bool) dol_eval($val['enabled'], 1)),
117 'position' => $val['position'],
118 'help' => isset($val['help']) ? $val['help'] : ''
119 );
120 }
121}
122// Extra fields
123include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
124
125$object->fields = dol_sort_array($object->fields, 'position');
126$arrayfields = dol_sort_array($arrayfields, 'position');
127
128$permissiontoread = $user->hasRight('stocktransfer', 'stocktransfer', 'read');
129$permissiontoadd = $user->hasRight('stocktransfer', 'stocktransfer', 'write');
130$permissiontodelete = $user->hasRight('stocktransfer', 'stocktransfer', 'delete');
131
132// Security check
133if (empty($conf->stocktransfer->enabled)) {
134 accessforbidden('Module not enabled');
135}
136
137// Security check (enable the most restrictive one)
138if ($user->socid > 0) {
140}
141//$result = restrictedArea($user, 'stocktransfer', $id, '');
142if (!$permissiontoread) {
144}
145
146
147
148/*
149 * Actions
150 */
151
152if (GETPOST('cancel', 'alpha')) {
153 $action = 'list';
154 $massaction = '';
155}
156if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
157 $massaction = '';
158}
159
160$parameters = array();
161$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
162if ($reshook < 0) {
163 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
164}
165
166if (empty($reshook)) {
167 // Selection of new fields
168 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
169
170 // Purge search criteria
171 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
172 foreach ($object->fields as $key => $val) {
173 $search[$key] = '';
174 if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
175 $search[$key.'_dtstart'] = '';
176 $search[$key.'_dtend'] = '';
177 }
178 }
179 $toselect = array();
180 $search_array_options = array();
181 }
182 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
183 || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
184 $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
185 }
186
187 // Mass actions
188 $objectclass = 'StockTransfer';
189 $objectlabel = 'StockTransfer';
190 $uploaddir = $conf->stocktransfer->dir_output;
191 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
192}
193
194
195
196/*
197 * View
198 */
199
200$form = new Form($db);
201
202$now = dol_now();
203
204$title = $langs->trans('StockTransferList');
205//$help_url="EN:Module_StockTransfer|FR:Module_StockTransfer_FR|ES:Módulo_StockTransfer";
206$help_url = '';
207$morejs = array();
208$morecss = array();
209
210
211// Build and execute select
212// --------------------------------------------------------------------
213$sql = 'SELECT ';
214$sql .= $object->getFieldList('t');
215// Add fields from extrafields
216if (!empty($extrafields->attributes[$object->table_element]['label'])) {
217 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
218 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
219 }
220}
221// Add fields from hooks
222$parameters = array();
223$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
224$sql .= $hookmanager->resPrint;
225$sql = preg_replace('/,\s*$/', '', $sql);
226
227$sqlfields = $sql; // $sql fields to remove for count total
228
229$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
230if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
231 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
232}
233// Add table from hooks
234$parameters = array();
235$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
236$sql .= $hookmanager->resPrint;
237if ($object->ismultientitymanaged == 1) {
238 $sql .= " WHERE t.entity IN (".getEntity($object->element, (GETPOSTINT('search_current_entity') ? 0 : 1)).")";
239} else {
240 $sql .= " WHERE 1 = 1";
241}
242foreach ($search as $key => $val) {
243 if (array_key_exists($key, $object->fields)) {
244 if ($key == 'status' && $search[$key] == -1) {
245 continue;
246 }
247 $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
248 if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
249 if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
250 $search[$key] = '';
251 }
252 $mode_search = 2;
253 }
254 if ($search[$key] != '') {
255 $sql .= natural_search("t.".$db->escape($key), $search[$key], (($key == 'status') ? 2 : $mode_search));
256 }
257 } else {
258 if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
259 $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
260 if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
261 if (preg_match('/_dtstart$/', $key)) {
262 $sql .= " AND t.".$db->escape($columnName)." >= '".$db->idate($search[$key])."'";
263 }
264 if (preg_match('/_dtend$/', $key)) {
265 $sql .= " AND t.".$db->escape($columnName)." <= '".$db->idate($search[$key])."'";
266 }
267 }
268 }
269 }
270}
271if ($search_all) {
272 $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
273}
274//$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
275// Add where from extra fields
276include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
277// Add where from hooks
278$parameters = array();
279$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
280$sql .= $hookmanager->resPrint;
281
282/* If a group by is required
283$sql.= " GROUP BY ";
284foreach($object->fields as $key => $val) {
285 $sql .= "t.".$db->escape($key).", ";
286}
287// Add fields from extrafields
288if (!empty($extrafields->attributes[$object->table_element]['label'])) {
289 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
290 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
291 }
292}
293// Add groupby from hooks
294$parameters=array();
295$reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
296$sql.=$hookmanager->resPrint;
297$sql=preg_replace('/,\s*$/','', $sql);
298*/
299
300// Count total nb of records
301$nbtotalofrecords = '';
302if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
303 /* The fast and low memory method to get and count full list converts the sql into a sql count */
304 $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
305 $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
306 $resql = $db->query($sqlforcount);
307 if ($resql) {
308 $objforcount = $db->fetch_object($resql);
309 $nbtotalofrecords = $objforcount->nbtotalofrecords;
310 } else {
311 dol_print_error($db);
312 }
313
314 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
315 $page = 0;
316 $offset = 0;
317 }
318 $db->free($resql);
319}
320
321// Complete request and execute it with limit
322$sql .= $db->order($sortfield, $sortorder);
323if ($limit) {
324 $sql .= $db->plimit($limit + 1, $offset);
325}
326
327$resql = $db->query($sql);
328if (!$resql) {
329 dol_print_error($db);
330 exit;
331}
332
333$num = $db->num_rows($resql);
334
335// Direct jump if only one record found
336if ($num == 1 && getDolGlobalInt('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
337 $obj = $db->fetch_object($resql);
338 $id = $obj->rowid;
339 header("Location: ".dol_buildpath('/product/stock/stocktransfer/stocktransfer_card.php', 1).'?id='.$id);
340 exit;
341}
342
343
344// Output page
345// --------------------------------------------------------------------
346
347llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'bodyforlist mod-product page-stock-stocktransfer_stocktransfer_list'); // Can use also classforhorizontalscrolloftabs instead of bodyforlist for no horizontal scroll
348
349// Example : Adding jquery code
350// print '<script type="text/javascript">
351// jQuery(document).ready(function() {
352// function init_myfunc()
353// {
354// jQuery("#myid").removeAttr(\'disabled\');
355// jQuery("#myid").attr(\'disabled\',\'disabled\');
356// }
357// init_myfunc();
358// jQuery("#mybutton").click(function() {
359// init_myfunc();
360// });
361// });
362// </script>';
363
364$arrayofselected = is_array($toselect) ? $toselect : array();
365
366$param = '';
367if (!empty($mode)) {
368 $param .= '&mode='.urlencode($mode);
369}
370if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
371 $param .= '&contextpage='.urlencode($contextpage);
372}
373if ($limit > 0 && $limit != $conf->liste_limit) {
374 $param .= '&limit='.((int) $limit);
375}
376if ($optioncss != '') {
377 $param .= '&optioncss='.urlencode($optioncss);
378}
379foreach ($search as $key => $val) {
380 if (is_array($search[$key])) {
381 foreach ($search[$key] as $skey) {
382 if ($skey != '') {
383 $param .= '&search_'.$key.'[]='.urlencode($skey);
384 }
385 }
386 } elseif (preg_match('/(_dtstart|_dtend)$/', $key) && !empty($val)) {
387 $param .= '&search_'.$key.'month='.(GETPOSTINT('search_'.$key.'month'));
388 $param .= '&search_'.$key.'day='.(GETPOSTINT('search_'.$key.'day'));
389 $param .= '&search_'.$key.'year='.(GETPOSTINT('search_'.$key.'year'));
390 } elseif ($search[$key] != '') {
391 $param .= '&search_'.$key.'='.urlencode($search[$key]);
392 }
393}
394// Add $param from extra fields
395include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
396// Add $param from hooks
397$parameters = array('param' => &$param);
398$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
399$param .= $hookmanager->resPrint;
400
401// List of mass actions available
402$arrayofmassactions = array(
403 //'validate'=>$langs->trans("Validate"),
404 //'generate_doc'=>$langs->trans("ReGeneratePDF"),
405 //'builddoc'=>$langs->trans("PDFMerge"),
406 //'presend'=>$langs->trans("SendByMail"),
407);
408if (!empty($permissiontodelete)) {
409 $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
410}
411if (GETPOSTINT('nomassaction') || in_array($massaction, array('presend', 'predelete'))) {
412 $arrayofmassactions = array();
413}
414$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
415
416print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
417if ($optioncss != '') {
418 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
419}
420print '<input type="hidden" name="token" value="'.newToken().'">';
421print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
422print '<input type="hidden" name="action" value="list">';
423print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
424print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
425print '<input type="hidden" name="page" value="'.$page.'">';
426print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
427print '<input type="hidden" name="page_y" value="">';
428print '<input type="hidden" name="mode" value="'.$mode.'">';
429
430$newcardbutton = '';
431$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);
432
433print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
434
435// Add code for pre mass action (confirmation or email presend form)
436$topicmail = "SendStockTransferRef";
437$modelmail = "stocktransfer";
438$objecttmp = new StockTransfer($db);
439$trackid = 'xxxx'.$object->id;
440include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
441
442if ($search_all) {
443 $setupstring = '';
444 foreach ($fieldstosearchall as $key => $val) {
445 $fieldstosearchall[$key] = $langs->trans($val);
446 $setupstring .= $key."=".$val.";";
447 }
448 print '<!-- Search done like if STOCKTRANSFER_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
449 print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).implode(', ', $fieldstosearchall).'</div>';
450}
451
452$moreforfilter = '';
453/*$moreforfilter.='<div class="divsearchfield">';
454$moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
455$moreforfilter.= '</div>';*/
456
457$parameters = array();
458$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
459if (empty($reshook)) {
460 $moreforfilter .= $hookmanager->resPrint;
461} else {
462 $moreforfilter = $hookmanager->resPrint;
463}
464
465if (!empty($moreforfilter)) {
466 print '<div class="liste_titre liste_titre_bydiv centpercent">';
467 print $moreforfilter;
468 print '</div>';
469}
470
471$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
472$htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields with user setup
473$selectedfields = ($mode != 'kanban' ? $htmlofselectarray : '');
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 don't 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, 'minwidth100imp maxwidth125', 2);
519 } else {
520 print '<input type="text" class="flat maxwidth'.($val['type'] == 'integer' ? '50' : '75').'" 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();
$id
Definition account.php:39
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:70
Class 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.
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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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='', $forobject=0, $mode='output')
Return the full path of the directory where a module (or an object of a module) stores its files,...
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...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.