dolibarr 23.0.3
list.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2015 ATM Consulting <support@atm-consulting.fr>
3 * Copyright (C) 2019-2020 Open-DSI <support@open-dsi.fr>
4 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/intracommreport/class/intracommreport.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
32
41// Load translation files required by the page
42$langs->loadLangs(array('intracommreport'));
43
44// Get parameters
45$action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'create'/'add', 'edit'/'update', 'view', ...
46$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
47$show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
48$confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
49$cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
50$toselect = GETPOST('toselect', 'array:int'); // Array of ids of elements selected into a list
51$optioncss = GETPOST('optioncss', 'alpha');
52$mode = GETPOST('mode', 'aZ');
53
54$search_all = trim(GETPOST('search_all', 'alphanohtml'));
55$search_ref = GETPOST("search_ref", 'alpha');
56$search_type = GETPOST("search_type", 'int');
57
58// Initialize context for list
59$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'intracommreportlist';
60if ((string) $type == '1') {
61 $contextpage = 'DESlist';
62 if ($search_type == '') {
63 $search_type = '1';
64 }
65}
66if ((string) $type == '0') {
67 $contextpage = 'DEBlist';
68 if ($search_type == '') {
69 $search_type = '0';
70 }
71}
72
73$diroutputmassaction = $conf->product->dir_output.'/temp/massgeneration/'.$user->id;
74
75// Load variable for pagination
76$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
77$sortfield = GETPOST('sortfield', 'aZ09comma');
78$sortorder = GETPOST('sortorder', 'aZ09comma');
79$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT('page');
80if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
81 // If $page is not defined, or '' or -1 or if we click on clear filters
82 $page = 0;
83}
84$offset = $limit * $page;
85$pageprev = $page - 1;
86$pagenext = $page + 1;
87
88
89// Initialize a technical objects
90$object = new IntracommReport($db);
91$extrafields = new ExtraFields($db);
92$diroutputmassaction = $conf->mymodule->dir_output.'/temp/massgeneration/'.$user->id;
93$hookmanager->initHooks(array($contextpage)); // Note that conf->hooks_modules contains array of activated contexes
94
95// Fetch optionals attributes and labels
96$extrafields->fetch_name_optionals_label($object->table_element);
97//$extrafields->fetch_name_optionals_label($object->table_element_line);
98
99$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
100
101// Default sort order (if not yet defined by previous GETPOST)
102if (!$sortfield) {
103 reset($object->fields); // Reset is required to avoid key() to return null.
104 $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
105}
106if (!$sortorder) {
107 $sortorder = "ASC";
108}
109
110// Initialize array of search criteria
111$search_all = trim(GETPOST('search_all', 'alphanohtml'));
112$search = array();
113foreach ($object->fields as $key => $val) {
114 if (GETPOST('search_'.$key, 'alpha') !== '') {
115 $search[$key] = GETPOST('search_'.$key, 'alpha');
116 }
117 if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
118 $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOSTINT('search_'.$key.'_dtstartmonth'), GETPOSTINT('search_'.$key.'_dtstartday'), GETPOSTINT('search_'.$key.'_dtstartyear'));
119 $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOSTINT('search_'.$key.'_dtendmonth'), GETPOSTINT('search_'.$key.'_dtendday'), GETPOSTINT('search_'.$key.'_dtendyear'));
120 }
121}
122
123$fieldstosearchall = array(
124 't.ref' => "Ref",
125);
126
127// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array of hooks
128$object = new IntracommReport($db);
129$hookmanager->initHooks(array('intracommreportlist'));
130$extrafields = new ExtraFields($db);
131$form = new Form($db);
132
133/*
134// fetch optionals attributes and labels
135$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
136$search_array_options=$extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
137*/
138
139if (empty($action)) {
140 $action = 'list';
141}
142
143
144
145// Definition of array of fields for columns
146$arrayfields = array();
147foreach ($object->fields as $key => $val) {
148 // If $val['visible']==0, then we never show the field
149 if (!empty($val['visible'])) {
150 $visible = (int) dol_eval((string) $val['visible'], 1);
151 $arrayfields['t.'.$key] = array(
152 'label' => $val['label'],
153 'checked' => (($visible < 0) ? 0 : 1),
154 'enabled' => (abs($visible) != 3 && (bool) dol_eval((string) $val['enabled'], 1)),
155 'position' => $val['position'],
156 'help' => isset($val['help']) ? $val['help'] : ''
157 );
158 }
159}
160// Extra fields
161include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
162
163$object->fields = dol_sort_array($object->fields, 'position');
164//$arrayfields['anotherfield'] = array('type'=>'integer', 'label'=>'AnotherField', 'checked'=>1, 'enabled'=>1, 'position'=>90, 'csslist'=>'right');
165$arrayfields = dol_sort_array($arrayfields, 'position');
166
167
168//$isInEEC = isInEEC($mysoc);
169
170
171$permissiontoread = $user->hasRight('intracommreport', 'read');
172$permissiontoadd = $user->hasRight('intracommreport', 'write');
173$permissiontodelete = $user->hasRight('intracommreport', 'delete');
174
175// Security check
176if ($search_type == '0') {
177 $result = restrictedArea($user, 'produit', '', '', '', '', '', 0);
178} elseif ($search_type == '1') {
179 $result = restrictedArea($user, 'service', '', '', '', '', '', 0);
180} else {
181 $result = restrictedArea($user, 'produit|service', '', '', '', '', '', 0);
182}
183
184if (!isModEnabled("intracommreport")) {
185 accessforbidden('Module intracommreport not enabled');
186}
187
188
189
190/*
191 * Actions
192 */
193
194if (GETPOST('cancel', 'alpha')) {
195 $action = 'list';
196 $massaction = '';
197}
198if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
199 $massaction = '';
200}
201
202$parameters = array();
203$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
204if ($reshook < 0) {
205 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
206}
207
208if (empty($reshook)) {
209 // Selection of new fields
210 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
211
212 // Purge search criteria
213 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
214 $search_all = "";
215 $search_ref = "";
216 //$search_label = "";
217 //$search_type=''; // There is 2 types of list: a list of product and a list of services. No list with both. So when we clear search criteria, we must keep the filter on type.
218
219 //$show_childproducts = '';
220 $search_array_options = array();
221 }
222
223 // Mass actions
224 $objectclass = 'Product';
225 if ((string) $search_type == '1') {
226 $objectlabel = 'Services';
227 }
228 if ((string) $search_type == '0') {
229 $objectlabel = 'Products';
230 }
231
232 $uploaddir = $conf->product->dir_output;
233 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
234}
235
236
237/*
238 * View
239 */
240
241$form = new Form($db);
242
243$now = dol_now();
244
245$title = $langs->trans("IntraCommReports");
246//$help_url = "EN:Module_IntraCommReport|FR:Module_IntraCommReport_FR|ES:Módulo_IntraCommReport";
247$help_url = '';
248$morejs = array();
249$morecss = array();
250
251
252// Build and execute select
253// --------------------------------------------------------------------
254$sql = 'SELECT ';
255$sql .= $object->getFieldList('t');
256// Add fields from extrafields
257if (!empty($extrafields->attributes[$object->table_element]['label'])) {
258 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
259 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : "");
260 }
261}
262// Add fields from hooks
263$parameters = array();
264$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
265$sql .= $hookmanager->resPrint;
266$sql = preg_replace('/,\s*$/', '', $sql);
267
268$sqlfields = $sql; // $sql fields to remove for count total
269
270$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
271//$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."anothertable as rc ON rc.parent = t.rowid";
272if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
273 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
274}
275// Add table from hooks
276$parameters = array();
277$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
278$sql .= $hookmanager->resPrint;
279if ($object->ismultientitymanaged == 1) {
280 $sql .= " WHERE t.entity IN (".getEntity($object->element, (GETPOSTINT('search_current_entity') ? 0 : 1)).")";
281} else {
282 $sql .= " WHERE 1 = 1";
283}
284foreach ($search as $key => $val) {
285 if (array_key_exists($key, $object->fields)) {
286 if ($key == 'status' && $search[$key] == -1) {
287 continue;
288 }
289 $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
290 if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
291 if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
292 $search[$key] = '';
293 }
294 $mode_search = 2;
295 }
296 if ($search[$key] != '') {
297 $sql .= natural_search("t.".$db->sanitize($key), $search[$key], (($key == 'status') ? 2 : $mode_search));
298 }
299 } else {
300 if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
301 $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
302 if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
303 if (preg_match('/_dtstart$/', $key)) {
304 $sql .= " AND t.".$db->sanitize($columnName)." >= '".$db->idate($search[$key])."'";
305 }
306 if (preg_match('/_dtend$/', $key)) {
307 $sql .= " AND t.".$db->sanitize($columnName)." <= '".$db->idate($search[$key])."'";
308 }
309 }
310 }
311 }
312}
313if ($search_all) {
314 $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
315}
316/*
317 // If the internal user must only see his customers, force searching by him
318 $search_sale = 0;
319 if (!$user->hasRight('societe', 'client', 'voir')) {
320 $search_sale = $user->id;
321 }
322 // Search on sale representative
323 if ($search_sale && $search_sale != '-1') {
324 if ($search_sale == -2) {
325 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc)";
326 } elseif ($search_sale > 0) {
327 $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc AND sc.fk_user = ".((int) $search_sale).")";
328 }
329 }
330 // Search on socid
331 if ($socid) {
332 $sql .= " AND t.fk_soc = ".((int) $socid);
333 }
334 */
335//$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
336// Add where from extra fields
337include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
338// Add where from hooks
339$parameters = array();
340$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
341$sql .= $hookmanager->resPrint;
342
343// Count total nb of records
344$nbtotalofrecords = '';
345if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
346 /* The fast and low memory method to get and count full list converts the sql into a sql count */
347 $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
348 $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
349
350 $resql = $db->query($sqlforcount);
351 if ($resql) {
352 $objforcount = $db->fetch_object($resql);
353 $nbtotalofrecords = $objforcount->nbtotalofrecords;
354 } else {
355 dol_print_error($db);
356 }
357
358 if (($page * $limit) > (int) $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
359 $page = 0;
360 $offset = 0;
361 }
362 $db->free($resql);
363}
364
365// Complete request and execute it with limit
366$sql .= $db->order($sortfield, $sortorder);
367if ($limit) {
368 $sql .= $db->plimit($limit + 1, $offset);
369}
370
371$resql = $db->query($sql);
372if (!$resql) {
373 dol_print_error($db);
374 exit;
375}
376
377$num = $db->num_rows($resql);
378
379
380// Direct jump if only one record found
381if ($num == 1 && getDolGlobalInt('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
382 $obj = $db->fetch_object($resql);
383 $id = $obj->rowid;
384 header("Location: ".dol_buildpath('/intracommreport/card.php', 1).'?id='.((int) $id));
385 exit;
386}
387
388
389// Output page
390// --------------------------------------------------------------------
391
392llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'mod-mymodule page-list bodyforlist'); // Can use also classforhorizontalscrolloftabs instead of bodyforlist for no horizontal scroll
393
394// Example : Adding jquery code
395// print '<script type="text/javascript">
396// jQuery(document).ready(function() {
397// function init_myfunc()
398// {
399// jQuery("#myid").removeAttr(\'disabled\');
400// jQuery("#myid").attr(\'disabled\',\'disabled\');
401// }
402// init_myfunc();
403// jQuery("#mybutton").click(function() {
404// init_myfunc();
405// });
406// });
407// </script>';
408
409$arrayofselected = is_array($toselect) ? $toselect : array();
410
411$param = '';
412if (!empty($mode)) {
413 $param .= '&mode='.urlencode($mode);
414}
415if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
416 $param .= '&contextpage='.urlencode($contextpage);
417}
418if ($limit > 0 && $limit != $conf->liste_limit) {
419 $param .= '&limit='.((int) $limit);
420}
421if ($optioncss != '') {
422 $param .= '&optioncss='.urlencode($optioncss);
423}
424if ($groupby != '') {
425 $param .= '&groupby='.urlencode($groupby);
426}
427foreach ($search as $key => $val) {
428 if (is_array($search[$key])) {
429 foreach ($search[$key] as $skey) {
430 if ($skey != '') {
431 $param .= '&search_'.$key.'[]='.urlencode($skey);
432 }
433 }
434 } elseif (preg_match('/(_dtstart|_dtend)$/', $key) && !empty($val)) {
435 $param .= '&search_'.$key.'month='.((int) GETPOST('search_'.$key.'month', 'int'));
436 $param .= '&search_'.$key.'day='.((int) GETPOST('search_'.$key.'day', 'int'));
437 $param .= '&search_'.$key.'year='.((int) GETPOST('search_'.$key.'year', 'int'));
438 } elseif ($search[$key] != '') {
439 $param .= '&search_'.$key.'='.urlencode($search[$key]);
440 }
441}
442// Add $param from extra fields
443include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
444// Add $param from hooks
445$parameters = array('param' => &$param);
446$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
447$param .= $hookmanager->resPrint;
448
449// List of mass actions available
450$arrayofmassactions = array(
451 //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
452 //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
453 //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
454 //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
455);
456if (!empty($permissiontodelete)) {
457 $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
458}
459if (GETPOSTINT('nomassaction') || in_array($massaction, array('presend', 'predelete'))) {
460 $arrayofmassactions = array();
461}
462$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
463
464print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
465if ($optioncss != '') {
466 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
467}
468print '<input type="hidden" name="token" value="'.newToken().'">';
469print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
470print '<input type="hidden" name="action" value="list">';
471print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
472print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
473print '<input type="hidden" name="page" value="'.$page.'">';
474print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
475print '<input type="hidden" name="page_y" value="">';
476print '<input type="hidden" name="mode" value="'.$mode.'">';
477
478
479$newcardbutton = '';
480$newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss' => 'reposition'));
481$newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss' => 'reposition'));
482$newcardbutton .= dolGetButtonTitleSeparator();
483$newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/intracommreport/card.php', 1).'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
484
485print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
486
487// Add code for pre mass action (confirmation or email presend form)
488$topicmail = "SendIntraCommReportRef";
489$modelmail = "intracommreport";
490$objecttmp = new IntracommReport($db);
491$trackid = 'xxxx'.$object->id;
492include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
493
494if ($search_all) {
495 $setupstring = '';
496 foreach ($fieldstosearchall as $key => $val) {
497 $fieldstosearchall[$key] = $langs->trans($val);
498 $setupstring .= $key."=".$val.";";
499 }
500 print '<!-- Search done like if INTRACOMMREPORT_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
501 print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).implode(', ', $fieldstosearchall).'</div>'."\n";
502}
503
504$moreforfilter = '';
505/*$moreforfilter.='<div class="divsearchfield">';
506 $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
507 $moreforfilter.= '</div>';*/
508
509$parameters = array();
510$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
511if (empty($reshook)) {
512 $moreforfilter .= $hookmanager->resPrint;
513} else {
514 $moreforfilter = $hookmanager->resPrint;
515}
516
517if (!empty($moreforfilter)) {
518 print '<div class="liste_titre liste_titre_bydiv centpercent">';
519 print $moreforfilter;
520 print '</div>';
521}
522
523$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
524$htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, (string) $conf->main_checkbox_left_column ? 'left' : ''); // This also change content of $arrayfields with user setup
525$selectedfields = ($mode != 'kanban' ? $htmlofselectarray : '');
526$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
527
528print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
529print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
530
531// Fields title search
532// --------------------------------------------------------------------
533print '<tr class="liste_titre_filter">';
534// Action column
535if ($conf->main_checkbox_left_column) {
536 print '<td class="liste_titre center maxwidthsearch">';
537 $searchpicto = $form->showFilterButtons('left');
538 print $searchpicto;
539 print '</td>';
540}
541foreach ($object->fields as $key => $val) {
542 //$searchkey = empty($search[$key]) ? '' : $search[$key];
543 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
544 if ($key == 'status') {
545 $cssforfield .= ($cssforfield ? ' ' : '').'center';
546 } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
547 $cssforfield .= ($cssforfield ? ' ' : '').'center';
548 } elseif (in_array($val['type'], array('timestamp'))) {
549 $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
550 } 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'])) {
551 $cssforfield .= ($cssforfield ? ' ' : '').'right';
552 }
553 if (!empty($arrayfields['t.'.$key]['checked'])) {
554 print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').($key == 'status' ? ' parentonrightofpage' : '').'">';
555 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
556 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);
557 } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
558 print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', $cssforfield.' maxwidth250', 1);
559 } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
560 print '<div class="nowrap">';
561 print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
562 print '</div>';
563 print '<div class="nowrap">';
564 print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
565 print '</div>';
566 } elseif ($key == 'lang') {
567 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
568 $formadmin = new FormAdmin($db);
569 print $formadmin->select_language((isset($search[$key]) ? $search[$key] : ''), 'search_lang', 0, array(), 1, 0, 0, 'minwidth100imp maxwidth125', 2);
570 } else {
571 print '<input type="text" class="flat maxwidth'.($val['type'] == 'integer' ? '50' : '75').'" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
572 }
573 print '</td>';
574 }
575}
576// Extra fields
577include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
578
579// Fields from hook
580$parameters = array('arrayfields' => $arrayfields);
581$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
582print $hookmanager->resPrint;
583/*if (!empty($arrayfields['anotherfield']['checked'])) {
584 print '<td class="liste_titre"></td>';
585 }*/
586// Action column
587if (!$conf->main_checkbox_left_column) {
588 print '<td class="liste_titre center maxwidthsearch">';
589 $searchpicto = $form->showFilterButtons();
590 print $searchpicto;
591 print '</td>';
592}
593print '</tr>'."\n";
594
595$totalarray = array();
596$totalarray['nbfield'] = 0;
597
598// Fields title label
599// --------------------------------------------------------------------
600print '<tr class="liste_titre">';
601// Action column
602if ($conf->main_checkbox_left_column) {
603 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
604 $totalarray['nbfield']++;
605}
606foreach ($object->fields as $key => $val) {
607 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
608 if ($key == 'status') {
609 $cssforfield .= ($cssforfield ? ' ' : '').'center';
610 } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
611 $cssforfield .= ($cssforfield ? ' ' : '').'center';
612 } elseif (in_array($val['type'], array('timestamp'))) {
613 $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
614 } 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'])) {
615 $cssforfield .= ($cssforfield ? ' ' : '').'right';
616 }
617 $cssforfield = preg_replace('/small\s*/', '', $cssforfield); // the 'small' css must not be used for the title label
618 if (!empty($arrayfields['t.'.$key]['checked'])) {
619 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";
620 $totalarray['nbfield']++;
621 }
622}
623// Extra fields
624include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
625// Hook fields
626$parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder, 'totalarray' => &$totalarray);
627$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
628print $hookmanager->resPrint;
629/*if (!empty($arrayfields['anotherfield']['checked'])) {
630 print '<th class="liste_titre right">'.$langs->trans("AnotherField").'</th>';
631 $totalarray['nbfield']++;
632 }*/
633// Action column
634if (!$conf->main_checkbox_left_column) {
635 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
636 $totalarray['nbfield']++;
637}
638print '</tr>'."\n";
639
640// Detect if we need a fetch on each output line
641$needToFetchEachLine = 0;
642if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
643 foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
644 if (!is_null($val) && preg_match('/\$object/', $val)) {
645 $needToFetchEachLine++; // There is at least one compute field that use $object
646 }
647 }
648}
649
650
651// Loop on record
652// --------------------------------------------------------------------
653$i = 0;
654$savnbfield = $totalarray['nbfield'];
655$totalarray = array();
656$totalarray['nbfield'] = 0;
657$imaxinloop = ($limit ? min($num, $limit) : $num);
658while ($i < $imaxinloop) {
659 $obj = $db->fetch_object($resql);
660 if (empty($obj)) {
661 break; // Should not happen
662 }
663
664 // Store properties in $object
665 $object->setVarsFromFetchObj($obj);
666
667 /*
668 $object->thirdparty = null;
669 if ($obj->fk_soc > 0) {
670 if (!empty($conf->cache['thirdparty'][$obj->fk_soc])) {
671 $companyobj = $conf->cache['thirdparty'][$obj->fk_soc];
672 } else {
673 $companyobj = new Societe($db);
674 $companyobj->fetch($obj->fk_soc);
675 $conf->cache['thirdparty'][$obj->fk_soc] = $companyobj;
676 }
677
678 $object->thirdparty = $companyobj;
679 }*/
680
681 if ($mode == 'kanban') {
682 if ($i == 0) {
683 print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
684 print '<div class="box-flex-container kanban">';
685 }
686 // Output Kanban
687 $selected = -1;
688 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
689 $selected = 0;
690 if (in_array($object->id, $arrayofselected)) {
691 $selected = 1;
692 }
693 }
694 //print $object->getKanbanView('', array('thirdparty'=>$object->thirdparty, 'selected' => $selected));
695 print $object->getKanbanView('', array('selected' => $selected));
696 if ($i == ($imaxinloop - 1)) {
697 print '</div>';
698 print '</td></tr>';
699 }
700 } else {
701 // Show line of result
702 $j = 0;
703 print '<tr data-rowid="'.$object->id.'" class="oddeven">';
704
705 // Action column
706 if ($conf->main_checkbox_left_column) {
707 print '<td class="nowrap center">';
708 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
709 $selected = 0;
710 if (in_array($object->id, $arrayofselected)) {
711 $selected = 1;
712 }
713 print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
714 }
715 print '</td>';
716 if (!$i) {
717 $totalarray['nbfield']++;
718 }
719 }
720 // Fields
721 foreach ($object->fields as $key => $val) {
722 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
723 if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
724 $cssforfield .= ($cssforfield ? ' ' : '').'center';
725 } elseif ($key == 'status') {
726 $cssforfield .= ($cssforfield ? ' ' : '').'center';
727 }
728
729 if (in_array($val['type'], array('timestamp'))) {
730 $cssforfield .= ($cssforfield ? ' ' : '').'nowraponall';
731 } elseif ($key == 'ref') {
732 $cssforfield .= ($cssforfield ? ' ' : '').'nowraponall';
733 }
734
735 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'])) {
736 $cssforfield .= ($cssforfield ? ' ' : '').'right';
737 }
738 //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
739
740 if (!empty($arrayfields['t.'.$key]['checked'])) {
741 print '<td'.($cssforfield ? ' class="'.$cssforfield.((preg_match('/tdoverflow/', $cssforfield) && !in_array($val['type'], array('ip', 'url')) && !is_numeric($object->$key)) ? ' classfortooltip' : '').'"' : '');
742 if (preg_match('/tdoverflow/', $cssforfield) && !in_array($val['type'], array('ip', 'url')) && !is_numeric($object->$key)) {
743 print ' title="'.dol_escape_htmltag((string) $object->$key).'"';
744 }
745 print '>';
746 if ($key == 'status') {
747 print $object->getLibStatut(5);
748 } elseif ($key == 'rowid') {
749 print $object->showOutputField($val, $key, (string) $object->id, '');
750 } else {
751 print $object->showOutputField($val, $key, $object->$key, '');
752 }
753 print '</td>';
754 if (!$i) {
755 $totalarray['nbfield']++;
756 }
757 if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
758 if (!$i) {
759 $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
760 }
761 if (!isset($totalarray['val'])) {
762 $totalarray['val'] = array();
763 }
764 if (!isset($totalarray['val']['t.'.$key])) {
765 $totalarray['val']['t.'.$key] = 0;
766 }
767 $totalarray['val']['t.'.$key] += $object->$key;
768 }
769 }
770 }
771 // Extra fields
772 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
773 // Fields from hook
774 $parameters = array('arrayfields' => $arrayfields, 'object' => $object, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
775 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
776 print $hookmanager->resPrint;
777
778 /*if (!empty($arrayfields['anotherfield']['checked'])) {
779 print '<td class="right">'.$obj->anotherfield.'</td>';
780 }*/
781
782 // Action column
783 if (empty($conf->main_checkbox_left_column)) {
784 print '<td class="nowrap center">';
785 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
786 $selected = 0;
787 if (in_array($object->id, $arrayofselected)) {
788 $selected = 1;
789 }
790 print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
791 }
792 print '</td>';
793 if (!$i) {
794 $totalarray['nbfield']++;
795 }
796 }
797
798 print '</tr>'."\n";
799 }
800
801 $i++;
802}
803
804// Show total line
805include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
806
807// If no record found
808if ($num == 0) {
809 $colspan = 1;
810 foreach ($arrayfields as $key => $val) {
811 if (!empty($val['checked'])) {
812 $colspan++;
813 }
814 }
815 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
816}
817
818
819$db->free($resql);
820
821$parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
822$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
823print $hookmanager->resPrint;
824
825print '</table>'."\n";
826print '</div>'."\n";
827
828print '</form>'."\n";
829
830if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
831 $hidegeneratedfilelistifempty = 1;
832 if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
833 $hidegeneratedfilelistifempty = 0;
834 }
835
836 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
837 $formfile = new FormFile($db);
838
839 // Show list of available documents
840 $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
841 $urlsource .= str_replace('&amp;', '&', $param);
842
843 $filedir = $diroutputmassaction;
844 $genallowed = $permissiontoread;
845 $delallowed = $permissiontoadd;
846
847 print $formfile->showdocuments('massfilesarea_'.$object->module, '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
848}
849
850// End of page
851llxFooter();
852$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$totalarray
Definition export.php:1216
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class 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 to manage intracomm report.
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...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
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...
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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.