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