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