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