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