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