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