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