dolibarr 23.0.3
emailcollector_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) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
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';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/core/class/events.class.php';
39
40require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
43
44require_once DOL_DOCUMENT_ROOT.'/emailcollector/class/emailcollector.class.php';
45
46// Load translation files required by page
47$langs->loadLangs(array("admin", "other"));
48
49$action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
50$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
51$show_files = GETPOSTINT('show_files'); // Show files area generated by bulk actions ?
52$confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
53$cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
54$toselect = GETPOST('toselect', 'array:int'); // Array of ids of elements selected into a list
55$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : getDolDefaultContextPage(__FILE__); // To manage different context of search
56$backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
57$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
58$mode = GETPOST('mode', 'aZ');
59$groupby = GETPOST('mode', 'aZ09');
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') || (empty($toselect) && $massaction === '0')) {
69 // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
70 $page = 0;
71}
72$offset = $limit * $page;
73$pageprev = $page - 1;
74$pagenext = $page + 1;
75//if (! $sortfield) $sortfield="p.date_fin";
76//if (! $sortorder) $sortorder="DESC";
77
78// Initialize a technical objects
79$object = new EmailCollector($db);
80$extrafields = new ExtraFields($db);
81$diroutputmassaction = $conf->emailcollector->dir_output.'/temp/massgeneration/'.$user->id;
82$hookmanager->initHooks(array('emailcollectorlist')); // Note that conf->hooks_modules contains array
83
84// Fetch optionals attributes and labels
85$extrafields->fetch_name_optionals_label($object->table_element);
86
87$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
88
89// Default sort order (if not yet defined by previous GETPOST)
90if (!$sortfield) {
91 $sortfield = "t.ref"; // Set here default search field. By default 1st field in definition.
92}
93if (!$sortorder) {
94 $sortorder = "ASC";
95}
96
97// Security check
98$socid = 0;
99if ($user->socid > 0) { // Protection if external user
100 //$socid = $user->socid;
102}
103//restrictedArea($user, 'emailcollector', $id, '');
104
105// Initialize array of search criteria
106$search_all = trim(GETPOST('search_all', 'alphanohtml'));
107$search = array();
108foreach ($object->fields as $key => $val) {
109 if (GETPOST('search_'.$key, 'alpha') !== '') {
110 $search[$key] = GETPOST('search_'.$key, 'alpha');
111 }
112 if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
113 $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOSTINT('search_'.$key.'_dtstartmonth'), GETPOSTINT('search_'.$key.'_dtstartday'), GETPOSTINT('search_'.$key.'_dtstartyear'));
114 $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOSTINT('search_'.$key.'_dtendmonth'), GETPOSTINT('search_'.$key.'_dtendday'), GETPOSTINT('search_'.$key.'_dtendyear'));
115 }
116}
117
118// List of fields to search into when doing a "search in all"
119$fieldstosearchall = array();
120foreach ($object->fields as $key => $val) {
121 if (!empty($val['searchall'])) {
122 $fieldstosearchall['t.'.$key] = $val['label'];
123 }
124}
125
126// Definition of array of fields for columns
127$tableprefix = 't';
128$arrayfields = array();
129foreach ($object->fields as $key => $val) {
130 // If $val['visible']==0, then we never show the field
131 if (!empty($val['visible'])) {
132 $visible = (int) dol_eval((string) $val['visible'], 1);
133 $arrayfields[$tableprefix.'.'.$key] = array(
134 'label' => $val['label'],
135 'checked' => (($visible < 0) ? '0' : '1'),
136 'enabled' => (string) (int) (abs($visible) != 3 && (bool) dol_eval((string) $val['enabled'], 1)),
137 'position' => $val['position'],
138 'help' => isset($val['help']) ? $val['help'] : ''
139 );
140 }
141}
142
143// Extra fields
144include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
145
146$object->fields = dol_sort_array($object->fields, 'position');
147$arrayfields = dol_sort_array($arrayfields, 'position');
148
149$permissiontoread = $user->admin;
150$permissiontoadd = $user->admin;
151$permissiontodelete = $user->admin;
152
153if (!$user->admin) {
155}
156if (!isModEnabled('emailcollector')) {
157 accessforbidden('Module not enabled');
158}
159
160
161
162
163/*
164 * Actions
165 */
166
167if (GETPOST('cancel', 'alpha')) {
168 $action = 'list';
169 $massaction = '';
170}
171if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
172 $massaction = '';
173}
174
175$parameters = array('arrayfields' => &$arrayfields);
176$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
177if ($reshook < 0) {
178 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
179}
180
181if (empty($reshook)) {
182 // Selection of new fields
183 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
184
185 // Purge search criteria
186 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
187 foreach ($object->fields as $key => $val) {
188 $search[$key] = '';
189 if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
190 $search[$key.'_dtstart'] = '';
191 $search[$key.'_dtend'] = '';
192 }
193 }
194 $search_all = '';
195 $toselect = array();
196 $search_array_options = array();
197 }
198 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
199 || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
200 $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
201 }
202
203 // Mass actions
204 $objectclass = 'EmailCollector';
205 $objectlabel = 'EmailCollector';
206 $uploaddir = $conf->emailcollector->dir_output;
207
208 global $error;
209 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
210}
211
212
213
214/*
215 * View
216 */
217
218$form = new Form($db);
219
220$now = dol_now();
221
222$help_url = "EN:Module_EMail_Collector|FR:Module_Collecteur_de_courrier_électronique|ES:Module_EMail_Collector";
223$title = $langs->trans('EmailCollectors');
224$morejs = array();
225$morecss = array();
226
227
228// Build and execute select
229// --------------------------------------------------------------------
230$sql = "SELECT";
231$sql .= " ".$object->getFieldList('t');
232// Add fields from extrafields
233if (!empty($extrafields->attributes[$object->table_element]['label'])) {
234 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
235 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : "");
236 }
237}
238// Add fields from hooks
239$parameters = array();
240$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
241$sql .= $hookmanager->resPrint;
242$sql = preg_replace('/,\s*$/', '', $sql);
243
244$sqlfields = $sql; // $sql fields to remove for count total
245
246$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
247if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
248 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
249}
250if ($object->ismultientitymanaged == 1) {
251 $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
252} else {
253 $sql .= " WHERE 1 = 1";
254}
255foreach ($search as $key => $val) {
256 if (array_key_exists($key, $object->fields)) {
257 if ($key == 'status' && $search[$key] == -1) {
258 continue;
259 }
260 $field_spec = $object->fields[$key];
261 // @phpstan-ignore-next-line PHPStan thinks that $field_spec is never null
262 if ($field_spec === null) {
263 continue;
264 }
265 $mode_search = (($object->isInt($field_spec) || $object->isFloat($field_spec)) ? 1 : 0);
266 if ((strpos($field_spec['type'], 'integer:') === 0) || (strpos($field_spec['type'], 'sellist:') === 0) || !empty($field_spec['arrayofkeyval'])) {
267 if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($field_spec['arrayofkeyval']) || !array_key_exists('0', $field_spec['arrayofkeyval'])))) {
268 $search[$key] = '';
269 }
270 $mode_search = 2;
271 }
272 if ($field_spec['type'] === 'boolean') {
273 $mode_search = 1;
274 if ($search[$key] == '-1') {
275 $search[$key] = '';
276 }
277 }
278 if (empty($field_spec['searchmulti'])) {
279 if (!is_array($search[$key]) && $search[$key] != '') {
280 $sql .= natural_search("t.".$db->escape($key), $search[$key], (($key == 'status') ? 2 : $mode_search));
281 }
282 } else {
283 if (is_array($search[$key]) && !empty($search[$key])) {
284 $sql .= natural_search("t.".$db->escape($key), implode(',', $search[$key]), (($key == 'status') ? 2 : $mode_search));
285 }
286 }
287 } else {
288 if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
289 $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
290 if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
291 if (preg_match('/_dtstart$/', $key)) {
292 $sql .= " AND t.".$db->sanitize($columnName)." >= '".$db->idate($search[$key])."'";
293 }
294 if (preg_match('/_dtend$/', $key)) {
295 $sql .= " AND t.".$db->sanitize($columnName)." <= '".$db->idate($search[$key])."'";
296 }
297 }
298 }
299 }
300}
301if ($search_all) {
302 $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
303}
304// Add where from extra fields
305include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
306// Add where from hooks
307$parameters = array();
308$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
309$sql .= $hookmanager->resPrint;
310
311// Count total nb of records
312$nbtotalofrecords = '';
313if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
314 /* The fast and low memory method to get and count full list converts the sql into a sql count */
315 $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
316 $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
317
318 $resql = $db->query($sqlforcount);
319 if ($resql) {
320 $objforcount = $db->fetch_object($resql);
321 $nbtotalofrecords = $objforcount->nbtotalofrecords;
322 } else {
323 dol_print_error($db);
324 }
325
326 if (($page * $limit) > (int) $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
327 $page = 0;
328 $offset = 0;
329 }
330
331 $db->free($resql);
332}
333// Complete request and execute it with limit
334$sql .= $db->order($sortfield, $sortorder);
335if ($limit) {
336 $sql .= $db->plimit($limit + 1, $offset);
337}
338
339$resql = $db->query($sql);
340if (!$resql) {
341 dol_print_error($db);
342 exit;
343}
344
345$num = $db->num_rows($resql);
346
347// Direct jump if only one record found
348if ($num == 1 && getDolGlobalInt('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
349 $obj = $db->fetch_object($resql);
350 $id = $obj->rowid;
351 header("Location: ".DOL_URL_ROOT.'/emailcollector/emailcollector_card.php?id='.$id);
352 exit;
353}
354
355
356// Output page
357// --------------------------------------------------------------------
358
359llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'bodyforlist mod-user page-emailcollector_list');
360
361
362$linkback = '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['restore_lastsearch_values' => 1]).'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
363
364print load_fiche_titre($title, $linkback, 'title_setup');
365
366
367$head = array();
368$h = 0;
369$head[$h][0] = DOL_URL_ROOT."/admin/emailcollector_list.php";
370$head[$h][1] = $langs->trans("Setup");
371$head[$h][2] = 'common';
372$h++;
373
374print dol_get_fiche_head($head, 'common', '', -1);
375
376
377
378$arrayofselected = is_array($toselect) ? $toselect : array();
379
380$param = '';
381if (!empty($mode)) {
382 $param .= '&mode='.urlencode($mode);
383}
384if (!empty($contextpage) && $contextpage != getDolDefaultContextPage(__FILE__)) {
385 $param .= '&contextpage='.urlencode($contextpage);
386}
387if ($limit > 0 && $limit != $conf->liste_limit) {
388 $param .= '&limit='.((int) $limit);
389}
390if ($optioncss != '') {
391 $param .= '&optioncss='.urlencode($optioncss);
392}
393if ($groupby != '') {
394 $param .= '&groupby='.urlencode($groupby);
395}
396foreach ($search as $key => $val) {
397 if (is_array($search[$key])) {
398 foreach ($search[$key] as $skey) {
399 if ($skey != '') {
400 $param .= '&search_'.$key.'[]='.urlencode($skey);
401 }
402 }
403 } elseif (preg_match('/(_dtstart|_dtend)$/', $key) && !empty($val)) {
404 $param .= '&search_'.$key.'month='.GETPOSTINT('search_'.$key.'month');
405 $param .= '&search_'.$key.'day='.GETPOSTINT('search_'.$key.'day');
406 $param .= '&search_'.$key.'year='.GETPOSTINT('search_'.$key.'year');
407 } elseif ($search[$key] != '') {
408 $param .= '&search_'.$key.'='.urlencode($search[$key]);
409 }
410}
411// Add $param from extra fields
412include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
413// Add $param from hooks
414$parameters = array('param' => &$param);
415$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
416$param .= $hookmanager->resPrint;
417
418// List of mass actions available
419$arrayofmassactions = array(
420 //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
421 //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
422);
423if (!empty($permissiontodelete)) {
424 $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
425}
426if (GETPOSTINT('nomassaction') || in_array($massaction, array('presend', 'predelete'))) {
427 $arrayofmassactions = array();
428}
429$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
430
431print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
432if ($optioncss != '') {
433 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
434}
435print '<input type="hidden" name="token" value="'.newToken().'">';
436print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
437print '<input type="hidden" name="action" value="list">';
438print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
439print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
440print '<input type="hidden" name="page" value="'.$page.'">';
441print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
442print '<input type="hidden" name="page_y" value="">';
443print '<input type="hidden" name="mode" value="'.$mode.'">';
444
445$newcardbutton = '';
446$newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', 'emailcollector_card.php?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
447
448print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'email', 0, $newcardbutton, '', $limit, 0, 0, 1);
449
450// Add code for pre mass action (confirmation or email presend form)
451/*$topicmail="";
452$modelmail="";
453$objecttmp=new EmailCollector($db);
454$trackid='xxxx'.$object->id;*/
455include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
456
457$moreforfilter = '';
458/*$moreforfilter.='<div class="divsearchfield">';
459$moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
460$moreforfilter.= '</div>';*/
461
462$parameters = array();
463$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
464if (empty($reshook)) {
465 $moreforfilter .= $hookmanager->resPrint;
466} else {
467 $moreforfilter = $hookmanager->resPrint;
468}
469$parameters = array(
470 'arrayfields' => &$arrayfields,
471);
472
473if (!empty($moreforfilter)) {
474 print '<div class="liste_titre liste_titre_bydiv centpercent">';
475 print $moreforfilter;
476 print '</div>';
477}
478
479$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
480$htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields with user setup
481$selectedfields = (($mode != 'kanban' && $mode != 'kanbangroupby') ? $htmlofselectarray : '');
482$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
483
484print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
485print '<table class="tagtable nobottomiftotal noborder liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
486
487
488// Fields title search
489// --------------------------------------------------------------------
490print '<tr class="liste_titre_filter">';
491// Action column
492if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
493 print '<td class="liste_titre center maxwidthsearch">';
494 $searchpicto = $form->showFilterButtons('left');
495 print $searchpicto;
496 print '</td>';
497}
498foreach ($object->fields as $key => $val) {
499 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
500 if ($key == 'status') {
501 $cssforfield .= ($cssforfield ? ' ' : '').'center';
502 } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
503 $cssforfield .= ($cssforfield ? ' ' : '').'center';
504 } elseif (in_array($val['type'], array('timestamp'))) {
505 $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
506 } 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'])) {
507 $cssforfield .= ($cssforfield ? ' ' : '').'right';
508 }
509 if (!empty($arrayfields['t.'.$key]['checked'])) {
510 print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').($key == 'status' ? ' parentonrightofpage' : '').'">';
511 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
512 if (empty($val['searchmulti'])) {
513 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);
514 } else {
515 print $form->multiselectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : array()), 0, 0, 'maxwidth100'.($key == 'status' ? ' search_status width100 onrightofpage' : ''), 1);
516 }
517 } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
518 print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', $cssforfield.' maxwidth125', 1);
519 } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
520 print '<div class="nowrap">';
521 print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
522 print '</div>';
523 print '<div class="nowrap">';
524 print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
525 print '</div>';
526 } elseif ($key == 'lang') {
527 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
528 $formadmin = new FormAdmin($db);
529 print $formadmin->select_language((isset($search[$key]) ? $search[$key] : ''), 'search_lang', 0, array(), 1, 0, 0, 'minwidth100imp maxwidth125', 2);
530 } elseif ($val['type'] === 'boolean') {
531 print $form->selectyesno('search_' . $key, $search[$key] ?? '', 1, false, 1);
532 } else {
533 print '<input type="text" class="flat maxwidth'.(in_array($val['type'], array('integer', 'price')) ? '50' : '75').'" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
534 }
535 print '</td>';
536 }
537}
538// Extra fields
539include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
540
541// Fields from hook
542$parameters = array('arrayfields' => $arrayfields);
543$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
544print $hookmanager->resPrint;
545// Action column
546if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
547 print '<td class="liste_titre center maxwidthsearch">';
548 $searchpicto = $form->showFilterButtons();
549 print $searchpicto;
550 print '</td>';
551}
552print '</tr>'."\n";
553
554$totalarray = array();
555$totalarray['nbfield'] = 0;
556
557// Fields title label
558// --------------------------------------------------------------------
559print '<tr class="liste_titre">';
560// Action column
561if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
562 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
563 $totalarray['nbfield']++;
564}
565foreach ($object->fields as $key => $val) {
566 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
567 if ($key == 'status') {
568 $cssforfield .= ($cssforfield ? ' ' : '').'center';
569 } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
570 $cssforfield .= ($cssforfield ? ' ' : '').'center';
571 } elseif (in_array($val['type'], array('timestamp'))) {
572 $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
573 } 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'])) {
574 $cssforfield .= ($cssforfield ? ' ' : '').'right';
575 }
576 $cssforfield = preg_replace('/small\s*/', '', $cssforfield); // the 'small' css must not be used for the title label
577 if (!empty($arrayfields['t.'.$key]['checked'])) {
578 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";
579 $totalarray['nbfield']++;
580 }
581}
582// Extra fields
583include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
584// Hook fields
585$parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder, 'totalarray' => &$totalarray);
586$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
587print $hookmanager->resPrint;
588// Action column
589if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
590 print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
591 $totalarray['nbfield']++;
592}
593print '</tr>'."\n";
594
595
596// Detect if we need a fetch on each output line
597$needToFetchEachLine = 0;
598if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
599 foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
600 if (!is_null($val) && preg_match('/\$object/', $val)) {
601 $needToFetchEachLine++; // There is at least one compute field that use $object
602 }
603 }
604}
605
606
607// Loop on record
608// --------------------------------------------------------------------
609$i = 0;
610$savnbfield = $totalarray['nbfield'];
611$totalarray = array();
612$totalarray['nbfield'] = 0;
613$imaxinloop = ($limit ? min($num, $limit) : $num);
614while ($i < $imaxinloop) {
615 $obj = $db->fetch_object($resql);
616 if (empty($obj)) {
617 break; // Should not happen
618 }
619
620 // Store properties in $object
621 $object->setVarsFromFetchObj($obj);
622
623 if ($mode == 'kanban' || $mode == 'kanbangroupby') {
624 if ($i == 0) {
625 print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
626 print '<div class="box-flex-container kanban">';
627 }
628 // Output Kanban
629 $selected = -1;
630 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
631 $selected = 0;
632 if (in_array($object->id, $arrayofselected)) {
633 $selected = 1;
634 }
635 }
636 print $object->getKanbanView('', array('selected' => $selected));
637 if ($i == ($imaxinloop - 1)) {
638 print '</div>';
639 print '</td></tr>';
640 }
641 } else {
642 // Show line of result
643 $j = 0;
644 print '<tr data-rowid="'.$object->id.'" class="oddeven">';
645 // Action column
646 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
647 print '<td class="nowrap center">';
648 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
649 $selected = 0;
650 if (in_array($object->id, $arrayofselected)) {
651 $selected = 1;
652 }
653 print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
654 }
655 print '</td>';
656 if (!$i) {
657 $totalarray['nbfield']++;
658 }
659 }
660 // Fields
661 foreach ($object->fields as $key => $val) {
662 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
663 if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
664 $cssforfield .= ($cssforfield ? ' ' : '').'center';
665 } elseif ($key == 'status') {
666 $cssforfield .= ($cssforfield ? ' ' : '').'center';
667 }
668
669 if (in_array($val['type'], array('timestamp'))) {
670 $cssforfield .= ($cssforfield ? ' ' : '').'nowraponall';
671 } elseif ($key == 'ref') {
672 $cssforfield .= ($cssforfield ? ' ' : '').'nowraponall';
673 }
674
675 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'])) {
676 $cssforfield .= ($cssforfield ? ' ' : '').'right';
677 }
678 //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
679
680 if (!empty($arrayfields['t.'.$key]['checked'])) {
681 print '<td'.($cssforfield ? ' class="'.$cssforfield.((preg_match('/tdoverflow/', $cssforfield) && !in_array($val['type'], array('ip', 'url')) && !is_numeric($object->$key)) ? ' classfortooltip' : '').'"' : '');
682 if (preg_match('/tdoverflow/', $cssforfield) && !in_array($val['type'], array('ip', 'url')) && !is_numeric($object->$key) && !in_array($key, array('ref'))) {
683 print ' title="'.dol_escape_htmltag((string) $object->$key).'"';
684 }
685 print '>';
686 if ($key == 'status') {
687 print $object->getLibStatut(5);
688 } elseif ($key == 'rowid') {
689 print $object->showOutputField($val, $key, (string) $object->id, '');
690 } else {
691 if ($val['type'] == 'html' || $key == 'lastresult') {
692 print '<div class="small lineheightsmall twolinesmax-normallineheight">';
693 }
694 print $object->showOutputField($val, $key, (string) $object->$key, '');
695 if ($val['type'] == 'html' || $key == 'lastresult') {
696 print '</div>';
697 }
698 }
699 print '</td>';
700 if (!$i) {
701 $totalarray['nbfield']++;
702 }
703 if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
704 if (!$i) {
705 $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
706 }
707 if (!isset($totalarray['val'])) {
708 $totalarray['val'] = array();
709 }
710 if (!isset($totalarray['val']['t.'.$key])) {
711 $totalarray['val']['t.'.$key] = 0;
712 }
713 $totalarray['val']['t.'.$key] += $object->$key;
714 }
715 }
716 }
717 // Extra fields
718 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
719 // Fields from hook
720 $parameters = array('arrayfields' => $arrayfields, 'object' => $object, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
721 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
722 print $hookmanager->resPrint;
723 // Action column
724 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
725 print '<td class="nowrap center">';
726 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
727 $selected = 0;
728 if (in_array($object->id, $arrayofselected)) {
729 $selected = 1;
730 }
731 print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
732 }
733 print '</td>';
734 if (!$i) {
735 $totalarray['nbfield']++;
736 }
737 }
738
739 print '</tr>'."\n";
740 }
741
742 $i++;
743}
744
745// Show total line
746include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
747
748
749// If no record found
750if ($num == 0) {
751 $colspan = 1;
752 foreach ($arrayfields as $key => $val) {
753 if (!empty($val['checked'])) {
754 $colspan++;
755 }
756 }
757 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
758}
759
760
761$db->free($resql);
762
763$parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
764$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
765print $hookmanager->resPrint;
766
767print '</table>'."\n";
768print '</div>'."\n";
769
770print load_fiche_titre($langs->trans("Other"), '', '');
771
772
773print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
774print '<table class="noborder centpercent">';
775
776print '<tr class="liste_titre">';
777print '<td>'.$langs->trans("Parameter").'</td>';
778print '<td></td>';
779print "</tr>\n";
780
781// MAIN_IMAP_USE_PHPIMAP: Enable use of the PHP Imap library
782print '<tr class="oddeven"><td>';
783//print $form->textwithpicto($langs->trans("MAIN_IMAP_USE_PHPIMAP"), $langs->transnoentitiesnoconv("MAIN_IMAP_USE_PHPIMAPDesc"));
784print $langs->trans("MAIN_IMAP_USE_PHPIMAP");
785print '</td>';
786print '<td class="left">';
787if ($conf->use_javascript_ajax) {
788 print ajax_constantonoff('MAIN_IMAP_USE_PHPIMAP');
789} else {
790 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
791 print $form->selectarray("MAIN_IMAP_USE_PHPIMAP", $arrval, $conf->global->MAIN_IMAP_USE_PHPIMAP);
792}
793print '</td>';
794print '</tr>';
795
796// MAIN_EMAILCOLLECTOR_MAIL_WITHOUT_HEADER: Hide e-mail headers from collected messages
797print '<tr class="oddeven"><td>'.$form->textwithpicto($langs->trans("EmailCollectorHideMailHeaders"), $langs->transnoentitiesnoconv("EmailCollectorHideMailHeadersHelp")).'</td>';
798print '<td class="left">';
799if ($conf->use_javascript_ajax) {
800 print ajax_constantonoff('MAIN_EMAILCOLLECTOR_MAIL_WITHOUT_HEADER');
801} else {
802 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
803 print $form->selectarray("MAIN_EMAILCOLLECTOR_MAIL_WITHOUT_HEADER", $arrval, getDolGlobalString('TICKET_AUTO_READ_WHEN_CREATED_FROM_BACKEND'));
804}
805print '</td>';
806print '</tr>';
807
808print '</table>';
809print '</div>';
810
811print '<br>';
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_emailcollector', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
833}
834
835
837
838
839// End of page
840llxFooter();
841$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$totalarray
Definition export.php:1216
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class for EmailCollector.
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.
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
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_get_fiche_end($notab=0)
Return tab footer of a card.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
getDolDefaultContextPage($s)
Return the default context page string.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.