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