dolibarr 21.0.0-beta
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 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($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($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/* If a group by is required
344 $sql .= " GROUP BY ";
345 foreach($object->fields as $key => $val) {
346 $sql .= "t.".$db->sanitize($key).", ";
347 }
348 // Add fields from extrafields
349 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
350 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
351 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
352 }
353 }
354 // Add groupby from hooks
355 $parameters = array();
356 $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
357 $sql .= $hookmanager->resPrint;
358 $sql = preg_replace('/,\s*$/', '', $sql);
359 */
360
361// Add HAVING from hooks
362/*
363 $parameters = array();
364 $reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
365 $sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint;
366 */
367
368// Count total nb of records
369$nbtotalofrecords = '';
370if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
371 /* The fast and low memory method to get and count full list converts the sql into a sql count */
372 $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
373 $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
374
375 $resql = $db->query($sqlforcount);
376 if ($resql) {
377 $objforcount = $db->fetch_object($resql);
378 $nbtotalofrecords = $objforcount->nbtotalofrecords;
379 } else {
380 dol_print_error($db);
381 }
382
383 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
384 $page = 0;
385 $offset = 0;
386 }
387 $db->free($resql);
388}
389
390// Complete request and execute it with limit
391$sql .= $db->order($sortfield, $sortorder);
392if ($limit) {
393 $sql .= $db->plimit($limit + 1, $offset);
394}
395
396$resql = $db->query($sql);
397if (!$resql) {
398 dol_print_error($db);
399 exit;
400}
401
402$num = $db->num_rows($resql);
403
404
405// Direct jump if only one record found
406if ($num == 1 && getDolGlobalInt('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
407 $obj = $db->fetch_object($resql);
408 $id = $obj->rowid;
409 header("Location: ".dol_buildpath('/intracommreport/card.php', 1).'?id='.((int) $id));
410 exit;
411}
412
413
414// Output page
415// --------------------------------------------------------------------
416
417llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'mod-mymodule page-list bodyforlist'); // Can use also classforhorizontalscrolloftabs instead of bodyforlist for no horizontal scroll
418
419// Example : Adding jquery code
420// print '<script type="text/javascript">
421// jQuery(document).ready(function() {
422// function init_myfunc()
423// {
424// jQuery("#myid").removeAttr(\'disabled\');
425// jQuery("#myid").attr(\'disabled\',\'disabled\');
426// }
427// init_myfunc();
428// jQuery("#mybutton").click(function() {
429// init_myfunc();
430// });
431// });
432// </script>';
433
434$arrayofselected = is_array($toselect) ? $toselect : array();
435
436$param = '';
437if (!empty($mode)) {
438 $param .= '&mode='.urlencode($mode);
439}
440if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
441 $param .= '&contextpage='.urlencode($contextpage);
442}
443if ($limit > 0 && $limit != $conf->liste_limit) {
444 $param .= '&limit='.((int) $limit);
445}
446if ($optioncss != '') {
447 $param .= '&optioncss='.urlencode($optioncss);
448}
449if ($groupby != '') {
450 $param .= '&groupby='.urlencode($groupby);
451}
452foreach ($search as $key => $val) {
453 if (is_array($search[$key])) {
454 foreach ($search[$key] as $skey) {
455 if ($skey != '') {
456 $param .= '&search_'.$key.'[]='.urlencode($skey);
457 }
458 }
459 } elseif (preg_match('/(_dtstart|_dtend)$/', $key) && !empty($val)) {
460 $param .= '&search_'.$key.'month='.((int) GETPOST('search_'.$key.'month', 'int'));
461 $param .= '&search_'.$key.'day='.((int) GETPOST('search_'.$key.'day', 'int'));
462 $param .= '&search_'.$key.'year='.((int) GETPOST('search_'.$key.'year', 'int'));
463 } elseif ($search[$key] != '') {
464 $param .= '&search_'.$key.'='.urlencode($search[$key]);
465 }
466}
467// Add $param from extra fields
468include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
469// Add $param from hooks
470$parameters = array('param' => &$param);
471$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
472$param .= $hookmanager->resPrint;
473
474// List of mass actions available
475$arrayofmassactions = array(
476 //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
477 //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
478 //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
479 //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
480);
481if (!empty($permissiontodelete)) {
482 $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
483}
484if (GETPOSTINT('nomassaction') || in_array($massaction, array('presend', 'predelete'))) {
485 $arrayofmassactions = array();
486}
487$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
488
489print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
490if ($optioncss != '') {
491 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
492}
493print '<input type="hidden" name="token" value="'.newToken().'">';
494print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
495print '<input type="hidden" name="action" value="list">';
496print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
497print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
498print '<input type="hidden" name="page" value="'.$page.'">';
499print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
500print '<input type="hidden" name="page_y" value="">';
501print '<input type="hidden" name="mode" value="'.$mode.'">';
502
503
504$newcardbutton = '';
505$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'));
506$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'));
507$newcardbutton .= dolGetButtonTitleSeparator();
508$newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/intracommreport/card.php', 1).'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
509
510print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
511
512// Add code for pre mass action (confirmation or email presend form)
513$topicmail = "SendIntraCommReportRef";
514$modelmail = "intracommreport";
515$objecttmp = new IntracommReport($db);
516$trackid = 'xxxx'.$object->id;
517include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
518
519if ($search_all) {
520 $setupstring = '';
521 foreach ($fieldstosearchall as $key => $val) {
522 $fieldstosearchall[$key] = $langs->trans($val);
523 $setupstring .= $key."=".$val.";";
524 }
525 print '<!-- Search done like if INTRACOMMREPORT_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
526 print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).implode(', ', $fieldstosearchall).'</div>'."\n";
527}
528
529$moreforfilter = '';
530/*$moreforfilter.='<div class="divsearchfield">';
531 $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
532 $moreforfilter.= '</div>';*/
533
534$parameters = array();
535$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
536if (empty($reshook)) {
537 $moreforfilter .= $hookmanager->resPrint;
538} else {
539 $moreforfilter = $hookmanager->resPrint;
540}
541
542if (!empty($moreforfilter)) {
543 print '<div class="liste_titre liste_titre_bydiv centpercent">';
544 print $moreforfilter;
545 print '</div>';
546}
547
548$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
549$htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, $conf->main_checkbox_left_column); // This also change content of $arrayfields with user setup
550$selectedfields = ($mode != 'kanban' ? $htmlofselectarray : '');
551$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
552
553print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
554print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
555
556// Fields title search
557// --------------------------------------------------------------------
558print '<tr class="liste_titre_filter">';
559// Action column
560if ($conf->main_checkbox_left_column) {
561 print '<td class="liste_titre center maxwidthsearch">';
562 $searchpicto = $form->showFilterButtons('left');
563 print $searchpicto;
564 print '</td>';
565}
566foreach ($object->fields as $key => $val) {
567 //$searchkey = empty($search[$key]) ? '' : $search[$key];
568 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
569 if ($key == 'status') {
570 $cssforfield .= ($cssforfield ? ' ' : '').'center';
571 } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
572 $cssforfield .= ($cssforfield ? ' ' : '').'center';
573 } elseif (in_array($val['type'], array('timestamp'))) {
574 $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
575 } 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'])) {
576 $cssforfield .= ($cssforfield ? ' ' : '').'right';
577 }
578 if (!empty($arrayfields['t.'.$key]['checked'])) {
579 print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').($key == 'status' ? ' parentonrightofpage' : '').'">';
580 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
581 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);
582 } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
583 print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', $cssforfield.' maxwidth250', 1);
584 } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
585 print '<div class="nowrap">';
586 print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
587 print '</div>';
588 print '<div class="nowrap">';
589 print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
590 print '</div>';
591 } elseif ($key == 'lang') {
592 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
593 $formadmin = new FormAdmin($db);
594 print $formadmin->select_language((isset($search[$key]) ? $search[$key] : ''), 'search_lang', 0, array(), 1, 0, 0, 'minwidth100imp maxwidth125', 2);
595 } else {
596 print '<input type="text" class="flat maxwidth'.($val['type'] == 'integer' ? '50' : '75').'" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
597 }
598 print '</td>';
599 }
600}
601// Extra fields
602include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
603
604// Fields from hook
605$parameters = array('arrayfields' => $arrayfields);
606$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
607print $hookmanager->resPrint;
608/*if (!empty($arrayfields['anotherfield']['checked'])) {
609 print '<td class="liste_titre"></td>';
610 }*/
611// Action column
612if (!$conf->main_checkbox_left_column) {
613 print '<td class="liste_titre center maxwidthsearch">';
614 $searchpicto = $form->showFilterButtons();
615 print $searchpicto;
616 print '</td>';
617}
618print '</tr>'."\n";
619
620$totalarray = array();
621$totalarray['nbfield'] = 0;
622
623// Fields title label
624// --------------------------------------------------------------------
625print '<tr class="liste_titre">';
626// Action column
627if ($conf->main_checkbox_left_column) {
628 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
629 $totalarray['nbfield']++;
630}
631foreach ($object->fields as $key => $val) {
632 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
633 if ($key == 'status') {
634 $cssforfield .= ($cssforfield ? ' ' : '').'center';
635 } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
636 $cssforfield .= ($cssforfield ? ' ' : '').'center';
637 } elseif (in_array($val['type'], array('timestamp'))) {
638 $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
639 } 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'])) {
640 $cssforfield .= ($cssforfield ? ' ' : '').'right';
641 }
642 $cssforfield = preg_replace('/small\s*/', '', $cssforfield); // the 'small' css must not be used for the title label
643 if (!empty($arrayfields['t.'.$key]['checked'])) {
644 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";
645 $totalarray['nbfield']++;
646 }
647}
648// Extra fields
649include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
650// Hook fields
651$parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder, 'totalarray' => &$totalarray);
652$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
653print $hookmanager->resPrint;
654/*if (!empty($arrayfields['anotherfield']['checked'])) {
655 print '<th class="liste_titre right">'.$langs->trans("AnotherField").'</th>';
656 $totalarray['nbfield']++;
657 }*/
658// Action column
659if (!$conf->main_checkbox_left_column) {
660 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
661 $totalarray['nbfield']++;
662}
663print '</tr>'."\n";
664
665// Detect if we need a fetch on each output line
666$needToFetchEachLine = 0;
667if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
668 foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
669 if (!is_null($val) && preg_match('/\$object/', $val)) {
670 $needToFetchEachLine++; // There is at least one compute field that use $object
671 }
672 }
673}
674
675
676// Loop on record
677// --------------------------------------------------------------------
678$i = 0;
679$savnbfield = $totalarray['nbfield'];
680$totalarray = array();
681$totalarray['nbfield'] = 0;
682$imaxinloop = ($limit ? min($num, $limit) : $num);
683while ($i < $imaxinloop) {
684 $obj = $db->fetch_object($resql);
685 if (empty($obj)) {
686 break; // Should not happen
687 }
688
689 // Store properties in $object
690 $object->setVarsFromFetchObj($obj);
691
692 /*
693 $object->thirdparty = null;
694 if ($obj->fk_soc > 0) {
695 if (!empty($conf->cache['thirdparty'][$obj->fk_soc])) {
696 $companyobj = $conf->cache['thirdparty'][$obj->fk_soc];
697 } else {
698 $companyobj = new Societe($db);
699 $companyobj->fetch($obj->fk_soc);
700 $conf->cache['thirdparty'][$obj->fk_soc] = $companyobj;
701 }
702
703 $object->thirdparty = $companyobj;
704 }*/
705
706 if ($mode == 'kanban') {
707 if ($i == 0) {
708 print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
709 print '<div class="box-flex-container kanban">';
710 }
711 // Output Kanban
712 $selected = -1;
713 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
714 $selected = 0;
715 if (in_array($object->id, $arrayofselected)) {
716 $selected = 1;
717 }
718 }
719 //print $object->getKanbanView('', array('thirdparty'=>$object->thirdparty, 'selected' => $selected));
720 print $object->getKanbanView('', array('selected' => $selected));
721 if ($i == ($imaxinloop - 1)) {
722 print '</div>';
723 print '</td></tr>';
724 }
725 } else {
726 // Show line of result
727 $j = 0;
728 print '<tr data-rowid="'.$object->id.'" class="oddeven">';
729
730 // Action column
731 if ($conf->main_checkbox_left_column) {
732 print '<td class="nowrap center">';
733 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
734 $selected = 0;
735 if (in_array($object->id, $arrayofselected)) {
736 $selected = 1;
737 }
738 print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
739 }
740 print '</td>';
741 if (!$i) {
742 $totalarray['nbfield']++;
743 }
744 }
745 // Fields
746 foreach ($object->fields as $key => $val) {
747 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
748 if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
749 $cssforfield .= ($cssforfield ? ' ' : '').'center';
750 } elseif ($key == 'status') {
751 $cssforfield .= ($cssforfield ? ' ' : '').'center';
752 }
753
754 if (in_array($val['type'], array('timestamp'))) {
755 $cssforfield .= ($cssforfield ? ' ' : '').'nowraponall';
756 } elseif ($key == 'ref') {
757 $cssforfield .= ($cssforfield ? ' ' : '').'nowraponall';
758 }
759
760 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'])) {
761 $cssforfield .= ($cssforfield ? ' ' : '').'right';
762 }
763 //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
764
765 if (!empty($arrayfields['t.'.$key]['checked'])) {
766 print '<td'.($cssforfield ? ' class="'.$cssforfield.((preg_match('/tdoverflow/', $cssforfield) && !in_array($val['type'], array('ip', 'url')) && !is_numeric($object->$key)) ? ' classfortooltip' : '').'"' : '');
767 if (preg_match('/tdoverflow/', $cssforfield) && !in_array($val['type'], array('ip', 'url')) && !is_numeric($object->$key)) {
768 print ' title="'.dol_escape_htmltag($object->$key).'"';
769 }
770 print '>';
771 if ($key == 'status') {
772 print $object->getLibStatut(5);
773 } elseif ($key == 'rowid') {
774 print $object->showOutputField($val, $key, $object->id, '');
775 } else {
776 print $object->showOutputField($val, $key, $object->$key, '');
777 }
778 print '</td>';
779 if (!$i) {
780 $totalarray['nbfield']++;
781 }
782 if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
783 if (!$i) {
784 $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
785 }
786 if (!isset($totalarray['val'])) {
787 $totalarray['val'] = array();
788 }
789 if (!isset($totalarray['val']['t.'.$key])) {
790 $totalarray['val']['t.'.$key] = 0;
791 }
792 $totalarray['val']['t.'.$key] += $object->$key;
793 }
794 }
795 }
796 // Extra fields
797 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
798 // Fields from hook
799 $parameters = array('arrayfields' => $arrayfields, 'object' => $object, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
800 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
801 print $hookmanager->resPrint;
802
803 /*if (!empty($arrayfields['anotherfield']['checked'])) {
804 print '<td class="right">'.$obj->anotherfield.'</td>';
805 }*/
806
807 // Action column
808 if (empty($conf->main_checkbox_left_column)) {
809 print '<td class="nowrap center">';
810 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
811 $selected = 0;
812 if (in_array($object->id, $arrayofselected)) {
813 $selected = 1;
814 }
815 print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
816 }
817 print '</td>';
818 if (!$i) {
819 $totalarray['nbfield']++;
820 }
821 }
822
823 print '</tr>'."\n";
824 }
825
826 $i++;
827}
828
829// Show total line
830include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
831
832// If no record found
833if ($num == 0) {
834 $colspan = 1;
835 foreach ($arrayfields as $key => $val) {
836 if (!empty($val['checked'])) {
837 $colspan++;
838 }
839 }
840 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
841}
842
843
844$db->free($resql);
845
846$parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
847$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
848print $hookmanager->resPrint;
849
850print '</table>'."\n";
851print '</div>'."\n";
852
853print '</form>'."\n";
854
855if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
856 $hidegeneratedfilelistifempty = 1;
857 if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
858 $hidegeneratedfilelistifempty = 0;
859 }
860
861 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
862 $formfile = new FormFile($db);
863
864 // Show list of available documents
865 $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
866 $urlsource .= str_replace('&amp;', '&', $param);
867
868 $filedir = $diroutputmassaction;
869 $genallowed = $permissiontoread;
870 $delallowed = $permissiontoadd;
871
872 print $formfile->showdocuments('massfilesarea_'.$object->module, '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
873}
874
875// End of page
876llxFooter();
877$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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:71
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.
llxFooter()
Footer empty.
Definition document.php:107
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)
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)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return 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...
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.