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