dolibarr 25.0.0-alpha
myobject_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) 2024-2026 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) ---Replace with your own copyright and developer email---
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// General defined Options
27//if (! defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET
28//if (! defined('MAIN_AUTHENTICATION_MODE')) define('MAIN_AUTHENTICATION_MODE', 'aloginmodule'); // Force authentication handler
29//if (! defined('MAIN_LANG_DEFAULT')) define('MAIN_LANG_DEFAULT', 'auto'); // Force LANG (language) to a particular value
30//if (! defined('MAIN_SECURITY_FORCECSP')) define('MAIN_SECURITY_FORCECSP', 'none'); // Disable all Content Security Policies
31//if (! defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', '1'); // Disable browser notification
32//if (! defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
33//if (! defined('NOLOGIN')) define('NOLOGIN', '1'); // Do not use login - if this page is public (can be called outside logged session). This includes the NOIPCHECK too.
34//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library
35//if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Do not create database handler $db
36//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // Do not load html.form.class.php
37//if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // Do not load and show top and left menu
38//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); // Do not load object $mysoc
39//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); // Do not load object $langs
40//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Do not load object $user
41//if (! defined('NOSCANGETFORINJECTION')) define('NOSCANGETFORINJECTION', '1'); // Do not check injection attack on GET parameters
42//if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION', '1'); // Do not check injection attack on POST parameters
43//if (! defined('NOSESSION')) define('NOSESSION', '1'); // On CLI mode, no need to use web sessions
44//if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK', '1'); // Do not check style html tag into posted data
45//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
46
47
48// Load Dolibarr environment
49$res = 0;
50// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
51if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
52 $res = @include str_replace("..", "", $_SERVER["CONTEXT_DOCUMENT_ROOT"])."/main.inc.php";
53}
54// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
55$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
56$tmp2 = realpath(__FILE__);
57$i = strlen($tmp) - 1; // @phan-suppress-current-line DolibarrForbiddenFunctionPlugin
58$j = strlen($tmp2) - 1; // @phan-suppress-current-line DolibarrForbiddenFunctionPlugin
59while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
60 $i--;
61 $j--;
62}
63if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
64 $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
65}
66if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
67 $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
68}
69// Try main.inc.php using relative path
70if (!$res && file_exists("../main.inc.php")) {
71 $res = @include "../main.inc.php";
72}
73if (!$res && file_exists("../../main.inc.php")) {
74 $res = @include "../../main.inc.php";
75}
76if (!$res && file_exists("../../../main.inc.php")) {
77 $res = @include "../../../main.inc.php";
78}
79if (!$res) {
80 die("Include of main fails");
81}
90require_once DOL_DOCUMENT_ROOT . '/core/lib/functions.lib.php';
91include_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
92include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
93include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
94// load module libraries
95include_once __DIR__.'/class/myobject.class.php';
96// for other modules
97//dol_include_once('/othermodule/class/otherobject.class.php');
98
99// Load translation files required by the page
100$langs->loadLangs(array("mymodule@mymodule", "other"));
101
102// Get parameters
103$action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'create'/'add', 'edit'/'update', 'view', ...
104$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
105$show_files = GETPOSTINT('show_files'); // Show files area generated by bulk actions ?
106$confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
107$cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
108$toselect = GETPOST('toselect', 'array:int'); // Array of ids of elements selected into a list
109$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : getDolDefaultContextPage(__FILE__); // To manage different context of search
110$backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
111$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
112$mode = GETPOST('mode', 'aZ'); // The display mode ('list', 'kanban', 'hierarchy', 'calendar', 'gantt', ...)
113$groupby = GETPOST('groupby', 'aZ09'); // Example: $groupby = 'p.fk_opp_status' or $groupby = 'p.fk_statut'
114
115$id = GETPOSTINT('id');
116$ref = GETPOST('ref', 'alpha');
117
118// Load variable for pagination
119$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
120$sortfield = GETPOST('sortfield', 'aZ09comma');
121$sortorder = GETPOST('sortorder', 'aZ09comma');
122$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT('page');
123if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
124 // If $page is not defined, or '' or -1 or if we click on clear filters
125 $page = 0;
126}
127$offset = $limit * $page;
128$pageprev = $page - 1;
129$pagenext = $page + 1;
130
131// Initialize technical objects
132$object = new MyObject($db);
133$extrafields = new ExtraFields($db);
134$diroutputmassaction = $conf->mymodule->dir_output.'/temp/massgeneration/'.$user->id;
135$hookmanager->initHooks(array($contextpage)); // Note that conf->hooks_modules contains array of activated contexes
136
137// Fetch optionals attributes and labels
138$extrafields->fetch_name_optionals_label($object->table_element);
139//$extrafields->fetch_name_optionals_label($object->table_element_line);
140
141$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
142
143// Default sort order (if not yet defined by previous GETPOST)
144if (!$sortfield) {
145 reset($object->fields); // Reset is required to avoid key() to return null.
146 $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
147}
148if (!$sortorder) {
149 $sortorder = "ASC";
150}
151
152// Initialize array of search criteria
153$search_all = trim(GETPOST('search_all', 'alphanohtml'));
154$search = array();
155foreach ($object->fields as $key => $val) {
156 if (GETPOST('search_'.$key, 'alpha') !== '') {
157 $search[$key] = GETPOST('search_'.$key, 'alpha');
158 }
159 if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
160 $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOSTINT('search_'.$key.'_dtstartmonth'), GETPOSTINT('search_'.$key.'_dtstartday'), GETPOSTINT('search_'.$key.'_dtstartyear'));
161 $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOSTINT('search_'.$key.'_dtendmonth'), GETPOSTINT('search_'.$key.'_dtendday'), GETPOSTINT('search_'.$key.'_dtendyear'));
162 }
163}
164
165// List of fields to search into when doing a "search in all"
166$fieldstosearchall = array();
167// foreach ($object->fields as $key => $val) {
168// if (!empty($val['searchall'])) {
169// $fieldstosearchall['t.'.$key] = $val['label'];
170// }
171// }
172// $parameters = array('fieldstosearchall'=>$fieldstosearchall);
173// $reshook = $hookmanager->executeHooks('completeFieldsToSearchAll', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
174// if ($reshook > 0) {
175// $fieldstosearchall = empty($hookmanager->resArray['fieldstosearchall']) ? array() : $hookmanager->resArray['fieldstosearchall'];
176// } elseif ($reshook == 0) {
177// $fieldstosearchall = array_merge($fieldstosearchall, empty($hookmanager->resArray['fieldstosearchall']) ? array() : $hookmanager->resArray['fieldstosearchall']);
178// }
179
180// Definition of array of fields for columns from ->fields
181$tableprefix = 't';
182$arrayfields = array();
183foreach ($object->fields as $key => $val) {
184 // If $val['visible']==0, then we never show the field
185 if (!empty($val['visible'])) {
186 $visible = (int) dol_eval((string) $val['visible'], 1);
187 $arrayfields[$tableprefix.'.'.$key] = array(
188 'label' => $val['label'],
189 'checked' => (($visible < 0) ? '0' : '1'),
190 'enabled' => (string) (int) (abs($visible) != 3 && (bool) dol_eval((string) $val['enabled'], 1)),
191 'position' => $val['position'],
192 'help' => isset($val['help']) ? $val['help'] : ''
193 );
194 }
195}
196// Definition of array of fields with hardcoded columns
197/*
198$arrayfields = array_merge($arrayfields, array(
199 't.anotherfield' => array('type'=>'integer', 'label'=>'AnotherField', 'checked'=>'1', 'enabled'=>'1', 'position'=>'90', 'csslist'=>'right'),
200));
201*/
202
203// Extra fields
204include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
205// Add hook to complete $arrayfield
206$parameters = array('arrayfields' => &$arrayfields);
207$reshook = $hookmanager->executeHooks('completeArrayFields', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
208
209// Complete arrayfields with special fields
210/*$arrayfields = array_merge($arrayfields, array(
211 'anotherfield' => array('type'=>'integer', 'label'=>'AnotherField', 'checked'=>'1', 'enabled'=>'1', 'position'=>'90', 'csslist'=>'right'),
212));*/
213
214// Change position of fields in arrayfield and object
215include DOL_DOCUMENT_ROOT.'/core/tpl/arrayfield_object_position_fields.tpl.php';
216
217$object->fields = dol_sort_array($object->fields, 'position');
218$arrayfields = dol_sort_array($arrayfields, 'position');
219
220// There is several ways to check permission.
221// Set $enablepermissioncheck to 1 to enable a minimum low level of checks
222$enablepermissioncheck = getDolGlobalInt('MYMODULE_ENABLE_PERMISSION_CHECK');
223if ($enablepermissioncheck) {
224 $permissiontoread = $user->hasRight('mymodule', 'myobject', 'read');
225 $permissiontoadd = $user->hasRight('mymodule', 'myobject', 'write');
226 $permissiontodelete = $user->hasRight('mymodule', 'myobject', 'delete');
227} else {
228 $permissiontoread = 1;
229 $permissiontoadd = 1;
230 $permissiontodelete = 1;
231}
232
233// Security check (enable the most restrictive one)
234if ($user->socid > 0) {
236}
237// BEGIN MODULEBUILDER ACCESSPOLICY
238//if ($user->socid > 0) accessforbidden();
239//$socid = 0; if ($user->socid > 0) $socid = $user->socid;
240//$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
241//restrictedArea($user, $object->module, 0, $object->table_element, $object->element, 'fk_soc', 'rowid', $isdraft);
242// END MODULEBUILDER ACCESSPOLICY
243if (!isModEnabled("mymodule")) {
244 accessforbidden('Module mymodule not enabled');
245}
246if (!$permissiontoread) {
248}
249
250
251/*
252 * Actions
253 */
254
255if (GETPOST('cancel', 'alpha')) {
256 $action = 'list';
257 $massaction = '';
258}
259if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
260 $massaction = '';
261}
262
263$parameters = array('arrayfields' => &$arrayfields);
264$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
265if ($reshook < 0) {
266 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
267}
268
269if (empty($reshook)) {
270 // Selection of new fields
271 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
272
273 // Purge search criteria
274 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
275 foreach ($object->fields as $key => $val) {
276 $search[$key] = '';
277 if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
278 $search[$key.'_dtstart'] = '';
279 $search[$key.'_dtend'] = '';
280 }
281 }
282 $search_all = '';
283 $toselect = array();
284 $search_array_options = array();
285 }
286 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
287 || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
288 $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
289 }
290
291 // Mass actions
292 $objectclass = 'MyObject';
293 $objectlabel = 'MyObject';
294 $uploaddir = $conf->mymodule->dir_output;
295
296 global $error;
297 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
298
299 // You can add more action here
300 // if ($action == 'xxx' && $permissiontoxxx) ...
301}
302
303
304
305/*
306 * View
307 */
308
309$form = new Form($db);
310
311$now = dol_now();
312
313$title = $langs->trans("MyObjects");
314//$help_url = "EN:Module_MyObject|FR:Module_MyObject_FR|ES:Módulo_MyObject";
315$help_url = '';
316$morejs = array();
317$morecss = array();
318
319
320// Build and execute select
321// --------------------------------------------------------------------
322$sql = "SELECT";
323$sql .= " ".$object->getFieldList('t');
324// Add fields from extrafields
325if (!empty($extrafields->attributes[$object->table_element]['label'])) {
326 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
327 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : "");
328 }
329}
330// Add fields from hooks
331$parameters = array();
332$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
333$sql .= $hookmanager->resPrint;
334$sql = preg_replace('/,\s*$/', '', $sql);
335
336$sqlfields = $sql; // $sql fields to remove for count total
337
338$sql .= " FROM ".$db->prefix().$object->table_element." as t";
339//$sql .= " LEFT JOIN ".$db->prefix()."anothertable as rc ON rc.parent = t.rowid";
340if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
341 $sql .= " LEFT JOIN ".$db->prefix().$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
342}
343// Add table from hooks
344$parameters = array();
345$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
346$sql .= $hookmanager->resPrint;
347
348if (!empty($object->ismultientitymanaged) && (int) $object->ismultientitymanaged == 1) {
349 $sql .= " WHERE t.entity IN (".getEntity($object->element, (GETPOSTINT('search_current_entity') ? 0 : 1)).")";
350} elseif (preg_match('/^\w+@\w+$/', (string) $object->ismultientitymanaged)) {
351 $tmparray = explode('@', (string) $object->ismultientitymanaged);
352 $sql .= " LEFT JOIN ".$object->db->prefix().$db->sanitize($tmparray[1])." as pt ON t.".$db->sanitize($tmparray[0])." = pt.rowid";
353 $sql .= " WHERE pt.entity IN (".getEntity($object->element, (GETPOSTINT('search_current_entity') ? 0 : 1)).")";
354} else {
355 $sql .= " WHERE 1 = 1";
356}
357foreach ($search as $key => $val) {
358 if (array_key_exists($key, $object->fields)) {
359 if ($key == 'status' && $search[$key] == -1) {
360 continue;
361 }
362 $field_spec = $object->fields[$key];
363 // Ignore false positive @phan-suppress-next-line PhanTypeMismatchArgumentNullable
364 $mode_search = (($object->isInt($field_spec) || $object->isFloat($field_spec)) ? 1 : 0);
365 if ((strpos($field_spec['type'], 'integer:') === 0) || (strpos($field_spec['type'], 'sellist:') === 0) || !empty($field_spec['arrayofkeyval'])) {
366 if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($field_spec['arrayofkeyval']) || !array_key_exists('0', $field_spec['arrayofkeyval'])))) {
367 $search[$key] = '';
368 }
369 $mode_search = 2;
370 }
371 if ($field_spec['type'] === 'boolean') {
372 $mode_search = 1;
373 if ($search[$key] == '-1') {
374 $search[$key] = '';
375 }
376 }
377 if (empty($field_spec['searchmulti'])) {
378 if (!is_array($search[$key]) && $search[$key] != '') {
379 $sql .= natural_search("t.".$db->escape($key), $search[$key], (($key == 'status') ? 2 : $mode_search));
380 }
381 } else {
382 if (is_array($search[$key]) && !empty($search[$key])) {
383 $sql .= natural_search("t.".$db->escape($key), implode(',', $search[$key]), (($key == 'status') ? 2 : $mode_search));
384 }
385 }
386 } else {
387 if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
388 $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
389 if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
390 if (preg_match('/_dtstart$/', $key)) {
391 $sql .= " AND t.".$db->sanitize($columnName)." >= '".$db->idate($search[$key])."'";
392 }
393 if (preg_match('/_dtend$/', $key)) {
394 $sql .= " AND t.".$db->sanitize($columnName)." <= '".$db->idate($search[$key])."'";
395 }
396 }
397 }
398 }
399}
400if ($search_all) {
401 $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
402}
403/*
404// If the internal user must only see his customers, force searching by him
405$search_sale = 0;
406if (!$user->hasRight('societe', 'client', 'voir')) {
407 $search_sale = $user->id;
408}
409// Search on sale representative
410if ($search_sale && $search_sale != '-1') {
411 if ($search_sale == -2) {
412 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".$db->prefix()."societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc)";
413 } elseif ($search_sale > 0) {
414 $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".$db->prefix()."societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc AND sc.fk_user = ".((int) $search_sale).")";
415 }
416}
417// Search on socid
418if ($socid) {
419 $sql .= " AND t.fk_soc = ".((int) $socid);
420}
421*/
422//$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
423// Add where from extra fields
424include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
425// Add where from hooks
426$parameters = array();
427$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
428$sql .= $hookmanager->resPrint;
429
430/* If a group by is required
431$sql .= " GROUP BY ";
432foreach($object->fields as $key => $val) {
433 $sql .= "t.".$db->sanitize($key).", ";
434}
435// Add fields from extrafields
436if (!empty($extrafields->attributes[$object->table_element]['label'])) {
437 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
438 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
439 }
440}
441// Add groupby from hooks
442$parameters = array();
443$reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
444if (empty($reshook)) {
445 $sql .= $hookmanager->resPrint;
446} else {
447 $sql = $hookmanager->resPrint;
448}
449
450$sql = preg_replace('/,\s*$/', '', $sql);
451*/
452
453// Add HAVING from hooks
454/*
455$parameters = array();
456$reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
457if (empty($reshook)) {
458 $sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint;
459} else {
460 $sql = $hookmanager->resPrint;
461}
462*/
463
464// Count total nb of records
465$nbtotalofrecords = '';
466if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
467 /* The fast and low memory method to get and count full list converts the sql into a sql count */
468 $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
469 $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
470
471 $resql = $db->query($sqlforcount);
472 if ($resql) {
473 $objforcount = $db->fetch_object($resql);
474 $nbtotalofrecords = $objforcount->nbtotalofrecords;
475 } else {
476 dol_print_error($db);
477 }
478
479 if (($page * $limit) > (int) $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
480 $page = 0;
481 $offset = 0;
482 }
483 $db->free($resql);
484}
485
486// Complete request and execute it with limit
487$sql .= $db->order($sortfield, $sortorder);
488if ($limit) {
489 $sql .= $db->plimit($limit + 1, $offset);
490}
491
492$resql = $db->query($sql);
493if (!$resql) {
494 dol_print_error($db);
495 exit;
496}
497
498$num = $db->num_rows($resql);
499
500
501// Direct jump if only one record found
502if ($num == 1 && getDolGlobalInt('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
503 $obj = $db->fetch_object($resql);
504 $id = $obj->rowid;
505 header("Location: ".dol_buildpath('/mymodule/myobject_card.php', 1).'?id='.((int) $id));
506 exit;
507}
508
509
510// Example : Adding jquery code
511// print '<script type="text/javascript">
512// jQuery(document).ready(function() {
513// function init_myfunc()
514// {
515// jQuery("#myid").removeAttr(\'disabled\');
516// jQuery("#myid").attr(\'disabled\',\'disabled\');
517// }
518// init_myfunc();
519// jQuery("#mybutton").click(function() {
520// init_myfunc();
521// });
522// });
523// </script>';
524
525$arrayofselected = is_array($toselect) ? $toselect : array();
526
527$param = '';
528if (!empty($mode)) {
529 $param .= '&mode='.urlencode($mode);
530}
531if (!empty($contextpage) && $contextpage != getDolDefaultContextPage(__FILE__)) {
532 $param .= '&contextpage='.urlencode($contextpage);
533}
534if ($limit > 0 && $limit != $conf->liste_limit) {
535 $param .= '&limit='.((int) $limit);
536}
537if ($optioncss != '') {
538 $param .= '&optioncss='.urlencode($optioncss);
539}
540if ($groupby != '') {
541 $param .= '&groupby='.urlencode($groupby);
542}
543if ($search_all != '') {
544 $param .= '&search_all='.urlencode($search_all);
545}
546foreach ($search as $key => $val) {
547 if (is_array($search[$key])) {
548 foreach ($search[$key] as $skey) {
549 if ($skey != '') {
550 $param .= '&search_'.$key.'[]='.urlencode($skey);
551 }
552 }
553 } elseif (preg_match('/(_dtstart|_dtend)$/', $key) && !empty($val)) {
554 $param .= '&search_'.$key.'month='.GETPOSTINT('search_'.$key.'month');
555 $param .= '&search_'.$key.'day='.GETPOSTINT('search_'.$key.'day');
556 $param .= '&search_'.$key.'year='.GETPOSTINT('search_'.$key.'year');
557 } elseif ($search[$key] != '') {
558 $param .= '&search_'.$key.'='.urlencode((string) $search[$key]);
559 }
560}
561// Add $param from extra fields
562include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
563// Add $param from hooks
564$parameters = array('param' => &$param);
565$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
566$param .= $hookmanager->resPrint;
567
568// Use Post/Redirect/Get for filter submissions so browser history contains a
569// reconstructible GET request instead of a POST that requires confirmation.
570$filterSearchSubmitted = GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha');
571$filterResetSubmitted = GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha');
572if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($filterSearchSubmitted || $filterResetSubmitted)) {
573 $redirectUrl = dolBuildUrl($_SERVER['PHP_SELF'], array(
574 'formfilteraction' => 'list',
575 'sortfield' => $sortfield,
576 'sortorder' => $sortorder,
577 ));
578 $redirectUrl .= $param;
579 header('Location: '.$redirectUrl, true, 303);
580 exit;
581}
582
583// Output page
584// --------------------------------------------------------------------
585
586llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'mod-mymodule page-list bodyforlist'); // Can use also classforhorizontalscrolloftabs instead of bodyforlist for a horizontal scroll in the table instead of page
587
588// List of mass actions available
589$arrayofmassactions = array(
590 //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
591 //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
592 //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
593 //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
594);
595if (!empty($permissiontodelete)) {
596 $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
597}
598if (GETPOSTINT('nomassaction') || in_array($massaction, array('presend', 'predelete'))) {
599 $arrayofmassactions = array();
600}
601$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
602
603print '<form method="POST" id="searchFormList" spellcheck="false" action="'.$_SERVER["PHP_SELF"].'">'."\n";
604if ($optioncss != '') {
605 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
606}
607print '<input type="hidden" name="token" value="'.newToken().'">';
608print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
609print '<input type="hidden" name="action" value="list">';
610print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
611print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
612print '<input type="hidden" name="page" value="'.$page.'">';
613print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
614print '<input type="hidden" name="page_y" value="">';
615print '<input type="hidden" name="mode" value="'.$mode.'">';
616
617
618$newcardbutton = '';
619$newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*(mode|groupby)=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss' => 'reposition'));
620$newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*(mode|groupby)=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss' => 'reposition'));
621//$newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanbanGroupBy'), '', 'fa fa-grip-vertical imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanbangroupby&groupby=p.fk_opp_status'.preg_replace('/(&|\?)*(mode|groupby)=[^&]+/', '', $param), '', ($mode == 'kanbangroupby' ? 2 : 1), array('morecss' => 'reposition'));
622//$newcardbutton .= dolGetButtonTitle($langs->trans('HierarchicView'), '', 'fa fa-stream paddingleft imgforviewmode', $_SERVER["PHP_SELF"].'?mode=hierarchy'.preg_replace('/(&|\?)*(mode|groupby)=[^&]+/', '', $param), '', (($mode == 'hierarchy') ? 2 : 1), array('morecss' => 'reposition'));
623$newcardbutton .= dolGetButtonTitle($langs->trans('Statistics'), '', 'fa fa-chart-bar imgforviewmode', dol_buildpath('/mymodule/stats/myobject_index.php', 1).'?mode=statistics&objecttype=myobject@mymodule'.preg_replace('/(&|\?)*(mode|groupby)=[^&]+/', '', $param), '', ($mode == 'statistics' ? 2 : 1), array('morecss' => 'reposition'));
624$newcardbutton .= dolGetButtonTitleSeparator();
625$newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/mymodule/myobject_card.php', 1).'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
626
627print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
628
629// Add code for pre mass action (confirmation or email presend form)
630$topicmail = "SendMyObjectRef";
631$modelmail = "myobject";
632$objecttmp = new MyObject($db);
633$trackid = 'myobject'.$object->id;
634include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
635
636if ($search_all) {
637 $setupstring = '';
638 // @phan-suppress-next-line PhanEmptyForeach
639 foreach ($fieldstosearchall as $key => $val) {
640 $fieldstosearchall[$key] = $langs->trans($val);
641 $setupstring .= $key."=".$val.";";
642 }
643 print '<!-- Search done like if MYOBJECT_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
644 print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).implode(', ', $fieldstosearchall).'</div>'."\n";
645}
646
647$moreforfilter = '';
648/*$moreforfilter.='<div class="divsearchfield">';
649$moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
650$moreforfilter.= '</div>';*/
651
652$parameters = array();
653$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
654if (empty($reshook)) {
655 $moreforfilter .= $hookmanager->resPrint;
656} else {
657 $moreforfilter = $hookmanager->resPrint;
658}
659$parameters = array(
660 'arrayfields' => &$arrayfields,
661);
662
663if (!empty($moreforfilter)) {
664 print '<div class="liste_titre liste_titre_bydiv centpercent">';
665 print $moreforfilter;
666 print '</div>';
667}
668
669$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
670$htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, $conf->main_checkbox_left_column, 1); // This also change content of $arrayfields with user setup
671$selectedfields = (($mode != 'kanban' && $mode != 'kanbangroupby') ? $htmlofselectarray : '');
672$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
673
674print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
675print '<table class="tagtable nobottomiftotal noborder liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
676
677// Fields title search
678// --------------------------------------------------------------------
679print '<tr class="liste_titre_filter">';
680// Action column
681if ($conf->main_checkbox_left_column) {
682 print '<td class="liste_titre center maxwidthsearch">';
683 $searchpicto = $form->showFilterButtons('left');
684 print $searchpicto;
685 print '</td>';
686}
687foreach ($object->fields as $key => $val) {
688 //$searchkey = empty($search[$key]) ? '' : $search[$key];
689 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
690 if ($key == 'status') {
691 $cssforfield .= ($cssforfield ? ' ' : '').'center';
692 } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
693 $cssforfield .= ($cssforfield ? ' ' : '').'center';
694 } elseif (in_array($val['type'], array('timestamp'))) {
695 $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
696 } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('id', 'rowid', 'ref', 'status')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
697 $cssforfield .= ($cssforfield ? ' ' : '').'right';
698 }
699 if (!empty($arrayfields['t.'.$key]['checked'])) {
700 print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').($key == 'status' ? ' parentonrightofpage' : '').'">';
701 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
702 if (empty($val['searchmulti'])) {
703 print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), 1, 0, 0, '', 1, 0, 0, '', 'maxwidth100'.($key == 'status' ? ' search_status width100 onrightofpage' : ''), 1);
704 } else {
705 print $form->multiselectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), 0, 0, 'maxwidth100'.($key == 'status' ? ' search_status width100 onrightofpage' : ''), 1);
706 }
707 } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
708 print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', $cssforfield.' maxwidth250', 1);
709 } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
710 print '<div class="nowrap">';
711 print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
712 print '</div>';
713 print '<div class="nowrap">';
714 print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
715 print '</div>';
716 } elseif ($key == 'lang') {
717 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
718 $formadmin = new FormAdmin($db);
719 print $formadmin->select_language((isset($search[$key]) ? $search[$key] : ''), 'search_lang', 0, array(), 1, 0, 0, 'minwidth100imp maxwidth125', 2);
720 } elseif ($val['type'] === 'boolean') {
721 print $form->selectyesno('search_' . $key, $search[$key] ?? '', 1, false, 1);
722 } else {
723 print '<input type="text" class="flat maxwidth'.(in_array($val['type'], array('integer', 'price')) ? '50' : '75').'" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
724 }
725 print '</td>';
726 }
727}
728// Extra fields
729include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
730
731// Fields from hook
732$parameters = array('arrayfields' => $arrayfields);
733$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
734print $hookmanager->resPrint;
735/*if (!empty($arrayfields['anotherfield']['checked'])) {
736 print '<td class="liste_titre"></td>';
737}*/
738// Action column
739if (!$conf->main_checkbox_left_column) {
740 print '<td class="liste_titre center maxwidthsearch">';
741 $searchpicto = $form->showFilterButtons();
742 print $searchpicto;
743 print '</td>';
744}
745print '</tr>'."\n";
746
747$totalarray = array();
748$totalarray['nbfield'] = 0;
749
750// Fields title label
751// --------------------------------------------------------------------
752print '<tr class="liste_titre">';
753// Action column
754if ($conf->main_checkbox_left_column) {
755 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
756 $totalarray['nbfield']++;
757}
758foreach ($object->fields as $key => $val) {
759 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
760 if ($key == 'status') {
761 $cssforfield .= ($cssforfield ? ' ' : '').'center';
762 } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
763 $cssforfield .= ($cssforfield ? ' ' : '').'center';
764 } elseif (in_array($val['type'], array('timestamp'))) {
765 $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
766 } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('id', 'rowid', 'ref', 'status')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
767 $cssforfield .= ($cssforfield ? ' ' : '').'right';
768 }
769 $cssforfield = preg_replace('/small\s*/', '', $cssforfield); // the 'small' css must not be used for the title label
770 if (!empty($arrayfields['t.'.$key]['checked'])) {
771 print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''), 0, (empty($val['helplist']) ? '' : $val['helplist']))."\n";
772 $totalarray['nbfield']++;
773 }
774}
775// Extra fields
776include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
777// Hook fields
778$parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder, 'totalarray' => &$totalarray);
779$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
780print $hookmanager->resPrint;
781/*if (!empty($arrayfields['anotherfield']['checked'])) {
782 print '<th class="liste_titre">'.$langs->trans("AnotherField").'</th>';
783 $totalarray['nbfield']++;
784}*/
785// Action column
786if (!$conf->main_checkbox_left_column) {
787 print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
788 $totalarray['nbfield']++;
789}
790print '</tr>'."\n";
791
792// Detect if we need a fetch on each output line
793$needToFetchEachLine = 0;
794if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
795 foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
796 if (!is_null($val) && preg_match('/\$object/', $val)) {
797 $needToFetchEachLine++; // There is at least one compute field that use $object
798 }
799 }
800}
801
802
803// Loop on record
804// --------------------------------------------------------------------
805$i = 0;
806$savnbfield = $totalarray['nbfield'];
807$totalarray = array();
808$totalarray['nbfield'] = 0;
809$imaxinloop = ($limit ? min($num, $limit) : $num);
810while ($i < $imaxinloop) {
811 $obj = $db->fetch_object($resql);
812 if (empty($obj)) {
813 break; // Should not happen
814 }
815
816 // Store properties in $object
817 $object->setVarsFromFetchObj($obj);
818
819 /*
820 $object->thirdparty = null;
821 if ($obj->fk_soc > 0) {
822 if (!empty($conf->cache['thirdparty'][$obj->fk_soc])) {
823 $companyobj = $conf->cache['thirdparty'][$obj->fk_soc];
824 } else {
825 $companyobj = new Societe($db);
826 $companyobj->fetch($obj->fk_soc);
827 $conf->cache['thirdparty'][$obj->fk_soc] = $companyobj;
828 }
829
830 $object->thirdparty = $companyobj;
831 }*/
832
833 if ($mode == 'kanban' || $mode == 'kanbangroupby') {
834 if ($i == 0) {
835 print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
836 print '<div class="box-flex-container kanban">';
837 }
838 // Output Kanban
839 $selected = -1;
840 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
841 $selected = 0;
842 if (in_array($object->id, $arrayofselected)) {
843 $selected = 1;
844 }
845 }
846 //print $object->getKanbanView('', array('thirdparty'=>$object->thirdparty, 'selected' => $selected));
847 print $object->getKanbanView('', array('selected' => $selected));
848 if ($i == ($imaxinloop - 1)) {
849 print '</div>';
850 print '</td></tr>';
851 }
852 } else {
853 // Show line of result
854 $j = 0;
855 print '<tr data-rowid="'.$object->id.'" class="oddeven row-with-select">';
856
857 // Action column
858 if ($conf->main_checkbox_left_column) {
859 print '<td class="nowrap center">';
860 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
861 $selected = 0;
862 if (in_array($object->id, $arrayofselected)) {
863 $selected = 1;
864 }
865 print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
866 }
867 print '</td>';
868 if (!$i) {
869 $totalarray['nbfield']++;
870 }
871 }
872 // Fields
873 foreach ($object->fields as $key => $val) {
874 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
875 if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
876 $cssforfield .= ($cssforfield ? ' ' : '').'center';
877 } elseif ($key == 'status') {
878 $cssforfield .= ($cssforfield ? ' ' : '').'center';
879 }
880
881 if (in_array($val['type'], array('timestamp'))) {
882 $cssforfield .= ($cssforfield ? ' ' : '').'nowraponall';
883 } elseif ($key == 'ref') {
884 $cssforfield .= ($cssforfield ? ' ' : '').'nowraponall';
885 }
886
887 if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('id', 'rowid', 'ref', 'status')) && empty($val['arrayofkeyval'])) {
888 $cssforfield .= ($cssforfield ? ' ' : '').'right';
889 }
890 //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
891
892 if (!empty($arrayfields['t.'.$key]['checked'])) {
893 print '<td'.($cssforfield ? ' class="'.$cssforfield.((preg_match('/tdoverflow/', $cssforfield) && !in_array($val['type'], array('ip', 'url')) && !is_numeric($object->$key)) ? ' classfortooltip' : '').'"' : '');
894 if (preg_match('/tdoverflow/', $cssforfield) && !in_array($val['type'], array('ip', 'url')) && !is_numeric($object->$key) && !in_array($key, array('ref'))) {
895 print ' title="'.dol_escape_htmltag((string) $object->$key).'"';
896 }
897 print '>';
898 if ($key == 'status') {
899 print $object->getLibStatut(5);
900 } elseif ($key == 'rowid') {
901 print $object->showOutputField($val, $key, (string) $object->id, '');
902 } else {
903 if ($val['type'] == 'html') {
904 print '<div class="small lineheightsmall twolinesmax-normallineheight">';
905 }
906 print $object->showOutputField($val, $key, (string) $object->$key, '');
907 if ($val['type'] == 'html') {
908 print '</div>';
909 }
910 }
911 print '</td>';
912 if (!$i) {
913 $totalarray['nbfield']++;
914 }
915 if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
916 if (!$i) {
917 $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
918 }
919 if (!isset($totalarray['val'])) {
920 $totalarray['val'] = array();
921 }
922 if (!isset($totalarray['val']['t.'.$key])) {
923 $totalarray['val']['t.'.$key] = 0;
924 }
925 $totalarray['val']['t.'.$key] += $object->$key;
926 }
927 }
928 }
929 // Extra fields
930 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
931 // Fields from hook
932 $parameters = array('arrayfields' => $arrayfields, 'object' => $object, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
933 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
934 print $hookmanager->resPrint;
935
936 /*if (!empty($arrayfields['anotherfield']['checked'])) {
937 print '<td class="right">'.$obj->anotherfield.'</td>';
938 }*/
939
940 // Action column
941 if (empty($conf->main_checkbox_left_column)) {
942 print '<td class="nowrap center">';
943 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
944 $selected = 0;
945 if (in_array($object->id, $arrayofselected)) {
946 $selected = 1;
947 }
948 print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
949 }
950 print '</td>';
951 if (!$i) {
952 $totalarray['nbfield']++;
953 }
954 }
955
956 print '</tr>'."\n";
957 }
958
959 $i++;
960}
961
962// Show total line
963include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
964
965// If no record found
966if ($num == 0) {
967 $colspan = 1;
968 foreach ($arrayfields as $key => $val) {
969 if (!empty($val['checked'])) {
970 $colspan++;
971 }
972 }
973 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
974}
975
976
977$db->free($resql);
978
979$parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
980$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
981print $hookmanager->resPrint;
982
983print '</table>'."\n";
984print '</div>'."\n";
985
986print '</form>'."\n";
987
988if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
989 $hidegeneratedfilelistifempty = 1;
990 if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
991 $hidegeneratedfilelistifempty = 0;
992 }
993
994 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
995 $formfile = new FormFile($db);
996
997 // Show list of available documents
998 $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
999 $urlsource .= str_replace('&amp;', '&', $param);
1000
1001 $filedir = $diroutputmassaction;
1002 $genallowed = $permissiontoread;
1003 $delallowed = $permissiontoadd;
1004
1005 print $formfile->showdocuments('massfilesarea_'.$object->module, '', $filedir, $urlsource, $genallowed, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
1006}
1007
1008// End of page
1009llxFooter();
1010$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage standard extra fields.
Class to generate html code for admin pages.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class for MyObject.
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
getDolDefaultContextPage($s)
Return the default context page string.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
dolGetButtonTitleSeparator($moreClass="")
Add space between dolGetButtonTitle.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.