dolibarr 25.0.0-alpha
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) 2018-2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
4 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
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';
39require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/asset/class/assetmodel.class.php';
43
44// Load translation files required by the page
45$langs->loadLangs(array("assets", "other"));
46
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:int'); // Array of ids of elements selected into a list
53$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'assetmodellist'; // 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
57$id = GETPOSTINT('id');
58
59// Load variable for pagination
60$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
61$sortfield = GETPOST('sortfield', 'aZ09comma');
62$sortorder = GETPOST('sortorder', 'aZ09comma');
63$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
64if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) {
65 $page = 0;
66} // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
67$offset = $limit * $page;
68$pageprev = $page - 1;
69$pagenext = $page + 1;
70
71// Initialize a technical objects
73$diroutputmassaction = $conf->asset->dir_output.'/temp/massgeneration/'.$user->id;
74$hookmanager->initHooks(array('assetmodellist')); // Note that conf->hooks_modules contains array
75
76// Fetch optionals attributes and labels
77$extrafields->fetch_name_optionals_label($object->table_element);
78//$extrafields->fetch_name_optionals_label($object->table_element_line);
79
80$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
81
82// Default sort order (if not yet defined by previous GETPOST)
83if (!$sortfield) {
84 reset($object->fields); // Reset is required to avoid key() to return null.
85 $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
86}
87if (!$sortorder) {
88 $sortorder = "ASC";
89}
90
91// Initialize array of search criteria
92$search_all = GETPOST('search_all', 'alphanohtml');
93$search = array();
94foreach ($object->fields as $key => $val) {
95 if ($key == 'fk_pays' && !GETPOSTISSET('search_'.$key)) {
96 $search[$key] = $mysoc->country_id;
97 } elseif (GETPOST('search_'.$key, 'alpha') !== '') {
98 $search[$key] = GETPOST('search_'.$key, 'alpha');
99 }
100 if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
101 $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOSTINT('search_'.$key.'_dtstartmonth'), GETPOSTINT('search_'.$key.'_dtstartday'), GETPOSTINT('search_'.$key.'_dtstartyear'));
102 $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOSTINT('search_'.$key.'_dtendmonth'), GETPOSTINT('search_'.$key.'_dtendday'), GETPOSTINT('search_'.$key.'_dtendyear'));
103 }
104}
105
106// List of fields to search into when doing a "search in all"
107$fieldstosearchall = array();
108foreach ($object->fields as $key => $val) {
109 if (!empty($val['searchall'])) {
110 $fieldstosearchall['t.'.$key] = $val['label'];
111 }
112}
113
114// Definition of array of fields for columns
115$arrayfields = array();
116foreach ($object->fields as $key => $val) {
117 // If $val['visible']==0, then we never show the field
118 if (!empty($val['visible'])) {
119 $visible = (int) dol_eval((string) $val['visible'], 1);
120 $arrayfields['t.'.$key] = array(
121 'label' => $val['label'],
122 'checked' => (($visible < 0) ? 0 : 1),
123 'enabled' => (abs($visible) != 3 && (bool) dol_eval((string) $val['enabled'], 1)),
124 'position' => $val['position'],
125 'help' => isset($val['help']) ? $val['help'] : ''
126 );
127 }
128}
129// Extra fields
130include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
131// Add hook to complete $arrayfield
132$parameters = array('arrayfields' => &$arrayfields);
133$reshook = $hookmanager->executeHooks('completeArrayFields', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
134
135$object->fields = dol_sort_array($object->fields, 'position');
136$arrayfields = dol_sort_array($arrayfields, 'position');
137
138$permissiontoread = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('asset', 'read')) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('asset', 'model_advance', 'read')));
139$permissiontoadd = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('asset', 'write')) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('asset', 'model_advance', 'write')));
140$permissiontodelete = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('asset', 'delete')) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('asset', 'model_advance', 'delete')));
141
142// Security check
143if (!isModEnabled('asset')) {
144 accessforbidden('Module not enabled');
145}
146
147// Security check (enable the most restrictive one)
148if ($user->socid > 0) {
150}
151$socid = 0;
152if ($user->socid > 0) {
153 $socid = $user->socid;
154}
155$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
156restrictedArea($user, 'asset', $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
157if (!isModEnabled('asset')) {
159}
160if (!$permissiontoread) {
162}
163
164/*
165 * Actions
166 */
167
168if (GETPOST('cancel', 'alpha')) {
169 $action = 'list';
170 $massaction = '';
171}
172if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
173 $massaction = '';
174}
175
176$parameters = array();
177$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
178if ($reshook < 0) {
179 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
180}
181
182if (empty($reshook)) {
183 // Selection of new fields
184 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
185
186 // Purge search criteria
187 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
188 foreach ($object->fields as $key => $val) {
189 $search[$key] = '';
190 if ($key == 'fk_pays') {
191 $search[$key] = $mysoc->country_id;
192 }
193 if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
194 $search[$key.'_dtstart'] = '';
195 $search[$key.'_dtend'] = '';
196 }
197 }
198 $toselect = array();
199 $search_array_options = array();
200 }
201 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
202 || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
203 $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
204 }
205
206 // Mass actions
207 $objectclass = 'AssetModel';
208 $objectlabel = 'AssetModel';
209 $uploaddir = $conf->asset->dir_output;
210 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
211}
212
213
214
215/*
216 * View
217 */
218
219$form = new Form($db);
220
221$now = dol_now();
222
223$help_url = '';
224$title = $langs->trans('ListOf', $langs->transnoentitiesnoconv("AssetModels"));
225$morejs = array();
226$morecss = array();
227
228
229// Build and execute select
230// --------------------------------------------------------------------
231$sql = 'SELECT ';
232$sql .= $object->getFieldList('t');
233// Add fields from extrafields
234if (!empty($extrafields->attributes[$object->table_element]['label'])) {
235 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
236 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
237 }
238}
239// Add fields from hooks
240$parameters = array();
241$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
242$sql .= $hookmanager->resPrint;
243$sql = preg_replace('/,\s*$/', '', $sql);
244$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
245if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
246 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
247}
248// Add table from hooks
249$parameters = array();
250$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
251$sql .= $hookmanager->resPrint;
252if ($object->ismultientitymanaged == 1) {
253 $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
254} else {
255 $sql .= " WHERE 1 = 1";
256}
257foreach ($search as $key => $val) {
258 if (array_key_exists($key, $object->fields)) {
259 if ($key == 'status' && $search[$key] == -1) {
260 continue;
261 }
262 $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
263 if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
264 if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
265 $search[$key] = '';
266 }
267 $mode_search = 2;
268 }
269 if ($search[$key] != '') {
270 $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
271 }
272 } else {
273 if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
274 $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
275 if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
276 if (preg_match('/_dtstart$/', $key)) {
277 $sql .= " AND t.".$db->sanitize($columnName)." >= '".$db->idate($search[$key])."'";
278 }
279 if (preg_match('/_dtend$/', $key)) {
280 $sql .= " AND t." . $db->sanitize($columnName) . " <= '" . $db->idate($search[$key]) . "'";
281 }
282 }
283 }
284 }
285}
286if ($search_all) {
287 $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
288}
289//$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
290// Add where from extra fields
291include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
292// Add where from hooks
293$parameters = array();
294$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
295$sql .= $hookmanager->resPrint;
296
297// Count total nb of records
298$nbtotalofrecords = '';
299if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
300 /* This old and fast method to get and count full list returns all record so use a high amount of memory.
301 $result = $db->query($sql);
302 $nbtotalofrecords = $db->num_rows($result);
303 */
304 /* The fast and low memory method to get and count full list converts the sql into a sql count */
305 $sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\‍(\‍),]+FROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql);
306
307 $resql = $db->query($sqlforcount);
308 if ($resql) {
309 $objforcount = $db->fetch_object($resql);
310 $nbtotalofrecords = $objforcount->nbtotalofrecords;
311 } else {
313 }
314
315 if (($page * $limit) > (int) $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
316 $page = 0;
317 $offset = 0;
318 }
319 $db->free($resql);
320}
321
322// Complete request and execute it with limit
323$sql .= $db->order($sortfield, $sortorder);
324if ($limit) {
325 $sql .= $db->plimit($limit + 1, $offset);
326}
327
328$resql = $db->query($sql);
329if (!$resql) {
331 exit;
332}
333
334$num = $db->num_rows($resql);
335
336
337// Direct jump if only one record found
338if ($num == 1 && getDolGlobalString('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
339 $obj = $db->fetch_object($resql);
340 $id = $obj->rowid;
341 header("Location: ".DOL_URL_ROOT.'/asset/model/card.php?id='.$id);
342 exit;
343}
344
345
346// Output page
347// --------------------------------------------------------------------
348
349llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'bodyforlist mod-asset page-model-list');
350
351$arrayofselected = is_array($toselect) ? $toselect : array();
352
353$param = '';
354if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
355 $param .= '&contextpage='.urlencode($contextpage);
356}
357if ($limit > 0 && $limit != $conf->liste_limit) {
358 $param .= '&limit='.((int) $limit);
359}
360foreach ($search as $key => $val) {
361 if (is_array($search[$key]) && count($search[$key])) {
362 foreach ($search[$key] as $skey) {
363 if ($skey != '') {
364 $param .= '&search_'.$key.'[]='.urlencode($skey);
365 }
366 }
367 } elseif ($search[$key] != '') {
368 $param .= '&search_'.$key.'='.urlencode($search[$key]);
369 }
370}
371if ($optioncss != '') {
372 $param .= '&optioncss='.urlencode($optioncss);
373}
374// Add $param from extra fields
375include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
376// Add $param from hooks
377$parameters = array('param' => &$param);
378$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
379$param .= $hookmanager->resPrint;
380
381// List of mass actions available
382$arrayofmassactions = array(
383 //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
384 //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
385 //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
386 //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
387);
388if ($permissiontodelete) {
389 $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
390}
391if (GETPOSTINT('nomassaction') || in_array($massaction, array('presend', 'predelete'))) {
392 $arrayofmassactions = array();
393}
394$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
395
396print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
397if ($optioncss != '') {
398 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
399}
400print '<input type="hidden" name="token" value="'.newToken().'">';
401print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
402print '<input type="hidden" name="action" value="list">';
403print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
404print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
405print '<input type="hidden" name="page" value="'.$page.'">';
406print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
407
408$newcardbutton = '';
409$newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/asset/model/card.php?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', (int) $permissiontoadd);
410
411print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
412
413// Add code for pre mass action (confirmation or email presend form)
414$topicmail = "SendAssetModelRef";
415$modelmail = "assetmodel";
416$objecttmp = new AssetModel($db);
417$trackid = 'assetmodel'.$object->id;
418include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
419
420if ($search_all) {
421 foreach ($fieldstosearchall as $key => $val) {
422 $fieldstosearchall[$key] = $langs->trans($val);
423 }
424 print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).implode(', ', $fieldstosearchall).'</div>';
425}
426
427$moreforfilter = '';
428/*$moreforfilter.='<div class="divsearchfield">';
429$moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
430$moreforfilter.= '</div>';*/
431
432$parameters = array();
433$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
434if (empty($reshook)) {
435 $moreforfilter .= $hookmanager->resPrint;
436} else {
437 $moreforfilter = $hookmanager->resPrint;
438}
439
440if (!empty($moreforfilter)) {
441 print '<div class="liste_titre liste_titre_bydiv centpercent">';
442 print $moreforfilter;
443 print '</div>';
444}
445
446$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
447$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
448$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
449
450print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
451print '<table class="tagtable nobottomiftotal noborder liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
452
453
454// Fields title search
455// --------------------------------------------------------------------
456print '<tr class="liste_titre">';
457foreach ($object->fields as $key => $val) {
458 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
459 if ($key == 'status') {
460 $cssforfield .= ($cssforfield ? ' ' : '').'center';
461 } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
462 $cssforfield .= ($cssforfield ? ' ' : '').'center';
463 } elseif (in_array($val['type'], array('timestamp'))) {
464 $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
465 } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
466 $cssforfield .= ($cssforfield ? ' ' : '').'right';
467 }
468 if (!empty($arrayfields['t.'.$key]['checked'])) {
469 print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
470 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
471 print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
472 } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
473 print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', 'maxwidth125', 1);
474 } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
475 print '<div class="nowrap">';
476 $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
477 print '</div>';
478 print '<div class="nowrap">';
479 print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
480 print '</div>';
481 } elseif ($key == 'lang') {
482 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
483 $formadmin = new FormAdmin($db);
484 print $formadmin->select_language($search[$key], 'search_lang', 0, array(), 1, 0, 0, 'minwidth100imp maxwidth125', 2);
485 } else {
486 print '<input type="text" class="flat maxwidth'.($val['type'] == 'integer' ? '50' : '75').'" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
487 }
488 print '</td>';
489 }
490}
491// Extra fields
492include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
493
494// Fields from hook
495$parameters = array('arrayfields' => $arrayfields);
496$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
497print $hookmanager->resPrint;
498// Action column
499print '<td class="liste_titre maxwidthsearch">';
500$searchpicto = $form->showFilterButtons();
501print $searchpicto;
502print '</td>';
503print '</tr>'."\n";
504
505
506// Fields title label
507// --------------------------------------------------------------------
508print '<tr class="liste_titre">';
509foreach ($object->fields as $key => $val) {
510 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
511 if ($key == 'status') {
512 $cssforfield .= ($cssforfield ? ' ' : '').'center';
513 } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
514 $cssforfield .= ($cssforfield ? ' ' : '').'center';
515 } elseif (in_array($val['type'], array('timestamp'))) {
516 $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
517 } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
518 $cssforfield .= ($cssforfield ? ' ' : '').'right';
519 }
520 if (!empty($arrayfields['t.'.$key]['checked'])) {
521 print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
522 }
523}
524// Extra fields
525include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
526// Hook fields
527$parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
528$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
529print $hookmanager->resPrint;
530// Action column
531print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
532print '</tr>'."\n";
533
534
535// Detect if we need a fetch on each output line
536$needToFetchEachLine = 0;
537if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
538 foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
539 if (!is_null($val) && preg_match('/\$object/', $val)) {
540 $needToFetchEachLine++; // There is at least one compute field that use $object
541 }
542 }
543}
544
545
546// Loop on record
547// --------------------------------------------------------------------
548$i = 0;
549$totalarray = array();
550$totalarray['nbfield'] = 0;
551while ($i < ($limit ? min($num, $limit) : $num)) {
552 $obj = $db->fetch_object($resql);
553 if (empty($obj)) {
554 break; // Should not happen
555 }
556
557 // Store properties in $object
558 $object->setVarsFromFetchObj($obj);
559
560 // Show here line of result
561 print '<tr class="oddeven">';
562 foreach ($object->fields as $key => $val) {
563 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
564 if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
565 $cssforfield .= ($cssforfield ? ' ' : '').'center';
566 } elseif ($key == 'status') {
567 $cssforfield .= ($cssforfield ? ' ' : '').'center';
568 }
569
570 if (in_array($val['type'], array('timestamp'))) {
571 $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
572 } elseif ($key == 'ref') {
573 $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
574 }
575
576 if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
577 $cssforfield .= ($cssforfield ? ' ' : '').'right';
578 }
579 //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
580
581 if (!empty($arrayfields['t.'.$key]['checked'])) {
582 print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '').'>';
583 if ($key == 'status') {
584 print $object->getLibStatut(5);
585 } elseif ($key == 'rowid') {
586 print $object->showOutputField($val, $key, (string) $object->id, '');
587 } else {
588 print $object->showOutputField($val, $key, $object->$key, '');
589 }
590 print '</td>';
591 if (!$i) {
592 $totalarray['nbfield']++;
593 }
594 if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
595 if (!$i) {
596 $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
597 }
598 if (!isset($totalarray['val'])) {
599 $totalarray['val'] = array();
600 }
601 if (!isset($totalarray['val']['t.'.$key])) {
602 $totalarray['val']['t.'.$key] = 0;
603 }
604 $totalarray['val']['t.'.$key] += $object->$key;
605 }
606 }
607 }
608 // Extra fields
609 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
610 // Fields from hook
611 $parameters = array('arrayfields' => $arrayfields, 'object' => $object, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
612 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
613 print $hookmanager->resPrint;
614 // Action column
615 print '<td class="nowrap center">';
616 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
617 $selected = 0;
618 if (in_array($object->id, $arrayofselected)) {
619 $selected = 1;
620 }
621 print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
622 }
623 print '</td>';
624 if (!$i) {
625 $totalarray['nbfield']++;
626 }
627
628 print '</tr>'."\n";
629
630 $i++;
631}
632
633// Show total line
634include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
635
636// If no record found
637if ($num == 0) {
638 $colspan = 1;
639 foreach ($arrayfields as $key => $val) {
640 if (!empty($val['checked'])) {
641 $colspan++;
642 }
643 }
644 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
645}
646
647
648$db->free($resql);
649
650$parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
651$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
652print $hookmanager->resPrint;
653
654print '</table>'."\n";
655print '</div>'."\n";
656
657print '</form>'."\n";
658
659if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
660 $hidegeneratedfilelistifempty = 1;
661 if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
662 $hidegeneratedfilelistifempty = 0;
663 }
664
665 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
666 $formfile = new FormFile($db);
667
668 // Show list of available documents
669 $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
670 $urlsource .= str_replace('&amp;', '&', $param);
671
672 $filedir = $diroutputmassaction;
673 $genallowed = $permissiontoread;
674 $delallowed = $permissiontoadd;
675
676 print $formfile->showdocuments('massfilesarea_asset', '', $filedir, $urlsource, 0, (int) $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
677}
678
679// End of page
680llxFooter();
681$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$totalarray
Definition list.php:501
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
Class for AssetModel.
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.
global $mysoc
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_now($mode='gmt')
Return date for now.
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...
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
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...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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, $allowothertags=array())
Show picto whatever it's its name (generic function)
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.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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...
Definition html.lib.php:172
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.