dolibarr  19.0.0-dev
mails_senderprofile_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) 2018 Ferran Marcet <fmarcet@2byte.es>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
25 // Load Dolibarr environment
26 require '../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/emailsenderprofile.class.php';
32 
33 // Load translation files required by the page
34 $langs->loadLangs(array("errors", "admin", "mails", "languages"));
35 
36 $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
37 $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
38 $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
39 $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
40 $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
41 $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
42 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'emailsenderprofilelist'; // To manage different context of search
43 $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
44 $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
45 
46 $id = GETPOST('id', 'int');
47 $rowid = GETPOST('rowid', 'alpha');
48 
49 // Load variable for pagination
50 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
51 $sortfield = GETPOST('sortfield', 'aZ09comma');
52 $sortorder = GETPOST('sortorder', 'aZ09comma');
53 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
54 if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) {
55  $page = 0;
56 } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
57 $offset = $limit * $page;
58 $pageprev = $page - 1;
59 $pagenext = $page + 1;
60 
61 // Initialize technical objects
62 $object = new EmailSenderProfile($db);
63 $extrafields = new ExtraFields($db);
64 $diroutputmassaction = $conf->admin->dir_output.'/temp/massgeneration/'.$user->id;
65 $hookmanager->initHooks(array('emailsenderprofilelist')); // Note that conf->hooks_modules contains array
66 
67 // Fetch optionals attributes and labels
68 $extrafields->fetch_name_optionals_label($object->table_element);
69 
70 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
71 
72 // Default sort order (if not yet defined by previous GETPOST)
73 if (!$sortfield) {
74  $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
75 }
76 if (!$sortorder) {
77  $sortorder = "ASC";
78 }
79 
80 // Initialize array of search criterias
81 $search_all = GETPOST("search_all", 'alpha');
82 $search = array();
83 foreach ($object->fields as $key => $val) {
84  if (GETPOST('search_'.$key, 'alpha')) {
85  $search[$key] = GETPOST('search_'.$key, 'alpha');
86  }
87 }
88 
89 // List of fields to search into when doing a "search in all"
90 $fieldstosearchall = array();
91 foreach ($object->fields as $key => $val) {
92  if (!empty($val['searchall'])) {
93  $fieldstosearchall['t.'.$key] = $val['label'];
94  }
95 }
96 
97 // Definition of fields for list
98 $arrayfields = array();
99 foreach ($object->fields as $key => $val) {
100  // If $val['visible']==0, then we never show the field
101  if (!empty($val['visible'])) {
102  $arrayfields['t.'.$key] = array('label'=>$val['label'], 'checked'=>(($val['visible'] < 0) ? 0 : 1), 'enabled'=>($val['enabled'] && ($val['visible'] != 3)), 'position'=>$val['position']);
103  }
104 }
105 // Extra fields
106 if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0) {
107  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
108  if (!empty($extrafields->attributes[$object->table_element]['list'][$key])) {
109  $arrayfields["ef.".$key] = array(
110  'label'=>$extrafields->attributes[$object->table_element]['label'][$key],
111  'checked'=>(($extrafields->attributes[$object->table_element]['list'][$key] < 0) ? 0 : 1),
112  'position'=>$extrafields->attributes[$object->table_element]['pos'][$key],
113  'enabled'=>(abs($extrafields->attributes[$object->table_element]['list'][$key]) != 3 && $extrafields->attributes[$object->table_element]['perms'][$key])
114  );
115  }
116  }
117 }
118 $object->fields = dol_sort_array($object->fields, 'position');
119 $arrayfields = dol_sort_array($arrayfields, 'position');
120 
121 $permissiontoread = $user->admin;
122 $permissiontoadd = $user->admin;
123 $permissiontodelete = $user->admin;
124 
125 if ($id > 0) {
126  $object->fetch($id);
127 }
128 
129 // Security check
130 $socid = 0;
131 if ($user->socid > 0) { // Protection if external user
132  //$socid = $user->socid;
133  accessforbidden();
134 }
135 // A non admin user can see profiles but limited to its own user
136 if (!$user->admin) {
137  if ($object->id > 0 && $object->private != $user->id) {
138  accessforbidden();
139  }
140 }
141 
142 
143 /*
144  * Actions
145  */
146 
147 if (GETPOST('cancel', 'alpha')) {
148  $action = 'list'; $massaction = '';
149 }
150 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
151  $massaction = '';
152 }
153 
154 $parameters = array();
155 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
156 if ($reshook < 0) {
157  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
158 }
159 
160 if (empty($reshook)) {
161  // Actions cancel, add, update, delete or clone
162  $backurlforlist = $_SERVER["PHP_SELF"].'?action=list';
163  include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
164 
165  // Selection of new fields
166  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
167 
168  // Purge search criteria
169  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
170  foreach ($object->fields as $key => $val) {
171  $search[$key] = '';
172  }
173  $toselect = array();
174  $search_array_options = array();
175  }
176  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
177  || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
178  $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
179  }
180 
181  // Mass actions
182  $objectclass = 'EmailSenderProfile';
183  $objectlabel = 'EmailSenderProfile';
184  $uploaddir = $conf->admin->dir_output.'/senderprofiles';
185  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
186 
187  if ($action == 'delete') {
188  $sql = "DELETE FROM ".MAIN_DB_PREFIX."c_email_senderprofile WHERE rowid = ".GETPOST('id', 'int');
189  $resql = $db->query($sql);
190  if ($resql) {
191  setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
192  } else {
193  setEventMessages($langs->trans("Error").' '.$db->lasterror(), null, 'errors');
194  }
195  }
196 }
197 
198 
199 
200 /*
201  * View
202  */
203 
204 $form = new Form($db);
205 
206 $now = dol_now();
207 
208 //$help_url="EN:Module_EmailSenderProfile|FR:Module_EmailSenderProfile_FR|ES:Módulo_EmailSenderProfile";
209 $help_url = '';
210 $title = $langs->trans("EMailsSetup");
211 
212 llxHeader('', $title);
213 
214 $linkback = '';
215 $titlepicto = 'title_setup';
216 
217 print load_fiche_titre($title, $linkback, $titlepicto);
218 
219 $head = email_admin_prepare_head();
220 
221 print dol_get_fiche_head($head, 'senderprofiles', '', -1);
222 
223 print '<span class="opacitymedium">'.$langs->trans("EMailsSenderProfileDesc")."</span><br>\n";
224 print "<br>\n";
225 
226 // Build and execute select
227 // --------------------------------------------------------------------
228 $sql = 'SELECT ';
229 $sql .= $object->getFieldList('t');
230 // Add fields from extrafields
231 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
232  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
233  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
234  }
235 }
236 // Add fields from hooks
237 $parameters = array();
238 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
239 $sql .= $hookmanager->resPrint;
240 $sql = preg_replace('/,\s*$/', '', $sql);
241 $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
242 if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
243  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
244 }
245 if ($object->ismultientitymanaged == 1) {
246  $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
247 } else {
248  $sql .= " WHERE 1 = 1";
249 }
250 foreach ($search as $key => $val) {
251  if ($key == 'status' && $search[$key] == -1) {
252  continue;
253  }
254  $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
255  if (strpos($object->fields[$key]['type'], 'integer:') === 0 || $key == 'active') {
256  if ($search[$key] == '-1') {
257  $search[$key] = '';
258  }
259  $mode_search = 2;
260  }
261  if ($search[$key] != '') {
262  $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
263  }
264 }
265 if ($search_all) {
266  $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
267 }
268 // If non admin, restrict list to itself
269 if (empty($user->admin)) {
270  $sql .= " AND private = ".((int) $user->id);
271 }
272 //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
273 // Add where from extra fields
274 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
275 // Add where from hooks
276 $parameters = array();
277 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
278 $sql .= $hookmanager->resPrint;
279 
280 /* If a group by is required
281 $sql.= " GROUP BY "
282 foreach($object->fields as $key => $val)
283 {
284  $sql .= "t.".$key.", ";
285 }
286 // Add fields from extrafields
287 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
288  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
289 }
290 // Add where from hooks
291 $parameters=array();
292 $reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters); // Note that $action and $object may have been modified by hook
293 $sql.=$hookmanager->resPrint;
294 $sql=preg_replace('/,\s*$/','', $sql);
295 */
296 
297 $sql .= $db->order($sortfield, $sortorder);
298 
299 // Count total nb of records
300 $nbtotalofrecords = '';
301 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
302  $resql = $db->query($sql);
303  $nbtotalofrecords = $db->num_rows($resql);
304  if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
305  $page = 0;
306  $offset = 0;
307  }
308 }
309 // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
310 if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
311  $num = $nbtotalofrecords;
312 } else {
313  if ($limit) {
314  $sql .= $db->plimit($limit + 1, $offset);
315  }
316 
317  $resql = $db->query($sql);
318  if (!$resql) {
319  dol_print_error($db);
320  exit;
321  }
322 
323  $num = $db->num_rows($resql);
324 }
325 
326 
327 // Output page
328 // --------------------------------------------------------------------
329 
330 $arrayofselected = is_array($toselect) ? $toselect : array();
331 
332 $param = '';
333 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
334  $param .= '&contextpage='.urlencode($contextpage);
335 }
336 if ($limit > 0 && $limit != $conf->liste_limit) {
337  $param .= '&limit='.((int) $limit);
338 }
339 foreach ($search as $key => $val) {
340  if (is_array($search[$key]) && count($search[$key])) {
341  foreach ($search[$key] as $skey) {
342  $param .= '&search_'.$key.'[]='.urlencode($skey);
343  }
344  } else {
345  $param .= '&search_'.$key.'='.urlencode($search[$key]);
346  }
347 }
348 if ($optioncss != '') {
349  $param .= '&optioncss='.urlencode($optioncss);
350 }
351 // Add $param from extra fields
352 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
353 
354 // List of mass actions available
355 $arrayofmassactions = array(
356  //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
357  //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
358 );
359 //if ($permissiontodelete) $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
360 //if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array();
361 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
362 
363 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
364 if ($optioncss != '') {
365  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
366 }
367 print '<input type="hidden" name="token" value="'.newToken().'">';
368 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
369 print '<input type="hidden" name="action" value="'.($action == 'create' ? 'add' : ($action == 'edit' ? 'update' : 'list')).'">';
370 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
371 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
372 print '<input type="hidden" name="page" value="'.$page.'">';
373 print '<input type="hidden" name="id" value="'.$id.'">';
374 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
375 
376 $newcardbutton = '';
377 if ($action != 'create') {
378  $newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', $_SERVER['PHP_SELF'].'?action=create', '', $permissiontoadd);
379 
380  if ($action == 'edit') {
381  print '<table class="border centpercent tableforfield">';
382  print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input type="text" name="label" class="width300" value="'.(GETPOSTISSET('label') ? GETPOST('label', 'alphanohtml') : $object->label).'"></td></tr>';
383  print '<tr><td>'.$langs->trans("Email").'</td><td>';
384  print img_picto('', 'email', 'class="pictofixedwidth"');
385  print '<input type="text" name="email" value="'.(GETPOSTISSET('email') ? GETPOST('email', 'alphanohtml') : $object->email).'"></td></tr>';
386  print '<tr><td>'.$langs->trans("Signature").'</td><td>';
387  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
388  $doleditor = new DolEditor('signature', (GETPOSTISSET('signature') ? GETPOST('signature', 'restricthtml') : $object->signature), '', 138, 'dolibarr_notes', 'In', true, true, empty($conf->global->FCKEDITOR_ENABLE_USERSIGN) ? 0 : 1, ROWS_4, '90%');
389  print $doleditor->Create(1);
390  print '</td></tr>';
391  print '<tr><td>'.$langs->trans("User").'</td><td>';
392  print img_picto('', 'user', 'class="pictofixedwidth"');
393  print $form->select_dolusers((GETPOSTISSET('private') ? GETPOST('private', 'int') : $object->private), 'private', 1, null, 0, ($user->admin ? '' : $user->id));
394  print '</td></tr>';
395  print '<tr><td>'.$langs->trans("Position").'</td><td><input type="text" name="position" class="maxwidth50" value="'.(GETPOSTISSET('position') ? GETPOST('position', 'int') : $object->position).'"></td></tr>';
396  print '<tr><td>'.$langs->trans("Status").'</td><td>';
397  print $form->selectarray('active', $object->fields['active']['arrayofkeyval'], (GETPOSTISSET('active') ? GETPOST('active', 'int') : $object->active), 0, 0, 0, '', 1);
398  print '</td></tr>';
399  print '</table>';
400 
401  print $form->buttonsSaveCancel();
402  }
403 } else {
404  /*print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
405  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
406  print '<input type="hidden" name="token" value="'.newToken().'">';
407  print '<input type="hidden" name="action" value="add">';
408  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
409  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
410  print '<input type="hidden" name="page" value="'.$page.'">';
411  print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
412  */
413  print '<table class="border centpercent tableforfield">';
414  print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input type="text" name="label" class="width300" value="'.GETPOST('label', 'alphanohtml').'" autofocus></td></tr>';
415  print '<tr><td class="fieldrequired">'.$langs->trans("Email").'</td><td>';
416  print img_picto('', 'email', 'class="pictofixedwidth"');
417  print '<input type="text" name="email" class="width300" value="'.GETPOST('email', 'alphanohtml').'"></td></tr>';
418  print '<tr><td>'.$langs->trans("Signature").'</td><td>';
419  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
420  $doleditor = new DolEditor('signature', GETPOST('signature'), '', 138, 'dolibarr_notes', 'In', true, true, empty($conf->global->FCKEDITOR_ENABLE_USERSIGN) ? 0 : 1, ROWS_4, '90%');
421  print $doleditor->Create(1);
422  print '</td></tr>';
423  print '<tr><td>'.$langs->trans("User").'</td><td>';
424  print img_picto('', 'user', 'class="pictofixedwidth"');
425  print $form->select_dolusers((GETPOSTISSET('private') ? GETPOST('private', 'int') : -1), 'private', 1, null, 0, ($user->admin ? '' : $user->id));
426  print '</td></tr>';
427  print '<tr><td>'.$langs->trans("Position").'</td><td><input type="text" name="position" class="maxwidth50" value="'.GETPOST('position', 'int').'"></td></tr>';
428  print '<tr><td>'.$langs->trans("Status").'</td><td>';
429  print $form->selectarray('active', $object->fields['active']['arrayofkeyval'], GETPOST('active', 'int'), 0);
430  print '</td></tr>';
431  print '</table>';
432 
433  print $form->buttonsSaveCancel();
434  //print '</form>';
435 }
436 
437 print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_companies', 0, $newcardbutton, '', $limit);
438 //print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_companies', 0, '', '', $limit);
439 
440 $topicmail = "Information";
441 //$modelmail="subscription";
442 $objecttmp = new EmailSenderProfile($db);
443 //$trackid = (($action == 'testhtml') ? "testhtml" : "test");
444 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
445 
446 if ($search_all) {
447  foreach ($fieldstosearchall as $key => $val) {
448  $fieldstosearchall[$key] = $langs->trans($val);
449  }
450  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
451 }
452 
453 $moreforfilter = '';
454 /*$moreforfilter.='<div class="divsearchfield">';
455 $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
456 $moreforfilter.= '</div>';*/
457 
458 $parameters = array();
459 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
460 if (empty($reshook)) {
461  $moreforfilter .= $hookmanager->resPrint;
462 } else {
463  $moreforfilter = $hookmanager->resPrint;
464 }
465 
466 if (!empty($moreforfilter)) {
467  print '<div class="liste_titre liste_titre_bydiv centpercent">';
468  print $moreforfilter;
469  print '</div>';
470 }
471 
472 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
473 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
474 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
475 
476 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
477 print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
478 
479 
480 // Fields title search
481 // --------------------------------------------------------------------
482 print '<tr class="liste_titre">';
483 foreach ($object->fields as $key => $val) {
484  $cssforfield = (empty($val['css']) ? '' : $val['css']);
485  if ($key == 'status') {
486  $cssforfield .= ($cssforfield ? ' ' : '').'center';
487  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
488  $cssforfield .= ($cssforfield ? ' ' : '').'center';
489  } elseif (in_array($val['type'], array('timestamp'))) {
490  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
491  } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') {
492  $cssforfield .= ($cssforfield ? ' ' : '').'right';
493  }
494  if (!empty($arrayfields['t.'.$key]['checked'])) {
495  print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
496  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
497  print $form->selectarray('search_'.$key, $val['arrayofkeyval'], empty($search[$key]) ? '' : $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
498  } elseif (strpos($val['type'], 'integer:') === 0) {
499  print $object->showInputField($val, $key, empty($search[$key]) ? '' : $search[$key], '', '', 'search_', 'maxwidth150', 1);
500  } elseif (!preg_match('/^(date|timestamp)/', $val['type'])) {
501  print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(empty($search[$key]) ? '' : $search[$key]).'">';
502  }
503  print '</td>';
504  }
505 }
506 // Extra fields
507 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
508 // Fields from hook
509 $parameters = array('arrayfields'=>$arrayfields);
510 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
511 print $hookmanager->resPrint;
512 // Action column
513 print '<td class="liste_titre maxwidthsearch">';
514 $searchpicto = $form->showFilterButtons();
515 print $searchpicto;
516 print '</td>';
517 print '</tr>'."\n";
518 
519 
520 // Fields title label
521 // --------------------------------------------------------------------
522 print '<tr class="liste_titre">';
523 foreach ($object->fields as $key => $val) {
524  $cssforfield = (empty($val['css']) ? '' : $val['css']);
525  if ($key == 'status') {
526  $cssforfield .= ($cssforfield ? ' ' : '').'center';
527  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
528  $cssforfield .= ($cssforfield ? ' ' : '').'center';
529  } elseif (in_array($val['type'], array('timestamp'))) {
530  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
531  } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') {
532  $cssforfield .= ($cssforfield ? ' ' : '').'right';
533  }
534  if (!empty($arrayfields['t.'.$key]['checked'])) {
535  print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
536  }
537 }
538 // Extra fields
539 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
540 
541 // Hook fields
542 $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
543 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
544 print $hookmanager->resPrint;
545 // Action column
546 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
547 print '</tr>'."\n";
548 
549 
550 // Detect if we need a fetch on each output line
551 $needToFetchEachLine = 0;
552 if (!empty($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
553  foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
554  if (!is_null($val) && preg_match('/\$object/', $val)) {
555  $needToFetchEachLine++; // There is at least one compute field that use $object
556  }
557  }
558 }
559 
560 
561 // Loop on record
562 // --------------------------------------------------------------------
563 $i = 0;
564 $totalarray = array();
565 $totalarray['nbfield'] = 0;
566 while ($i < ($limit ? min($num, $limit) : $num)) {
567  $obj = $db->fetch_object($resql);
568  if (empty($obj)) {
569  break; // Should not happen
570  }
571 
572  // Store properties in $object
573  $object->setVarsFromFetchObj($obj);
574 
575  // Show here line of result
576  print '<tr class="oddeven">';
577  foreach ($object->fields as $key => $val) {
578  $cssforfield = (empty($val['css']) ? '' : $val['css']);
579  if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
580  $cssforfield .= ($cssforfield ? ' ' : '').'center';
581  } elseif ($key == 'status') {
582  $cssforfield .= ($cssforfield ? ' ' : '').'center';
583  }
584 
585  if (in_array($val['type'], array('timestamp'))) {
586  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
587  } elseif ($key == 'ref') {
588  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
589  }
590 
591  if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $key != 'status') {
592  $cssforfield .= ($cssforfield ? ' ' : '').'right';
593  }
594 
595  if (!empty($arrayfields['t.'.$key]['checked'])) {
596  print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '').'>';
597  if ($key == 'status' || $key == 'active') {
598  print $object->getLibStatut(5);
599  } else {
600  print $object->showOutputField($val, $key, $object->$key, '');
601  }
602  print '</td>';
603  if (!$i) {
604  $totalarray['nbfield']++;
605  }
606  if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
607  if (!$i) {
608  $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
609  }
610  if (!isset($totalarray['val'])) {
611  $totalarray['val'] = array();
612  }
613  if (!isset($totalarray['val']['t.'.$key])) {
614  $totalarray['val']['t.'.$key] = 0;
615  }
616  $totalarray['val']['t.'.$key] += $object->$key;
617  }
618  }
619  }
620  // Extra fields
621  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
622  // Fields from hook
623  $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
624  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
625  print $hookmanager->resPrint;
626  // Action column
627  print '<td class="nowrap center">';
628  $url = $_SERVER["PHP_SELF"].'?id='.$obj->rowid;
629  if ($limit) {
630  $url .= '&limit='.((int) $limit);
631  }
632  if ($page) {
633  $url .= '&page='.urlencode($page);
634  }
635  if ($sortfield) {
636  $url .= '&sortfield='.urlencode($sortfield);
637  }
638  if ($sortorder) {
639  $url .= '&page='.urlencode($sortorder);
640  }
641  print '<a class="editfielda reposition marginrightonly marginleftonly" href="'.$url.'&action=edit&token='.newToken().'&rowid='.$obj->rowid.'">'.img_edit().'</a>';
642  //print ' &nbsp; ';
643  print '<a class=" marginrightonly marginleftonly" href="'.$url.'&action=delete&token='.newToken().'">'.img_delete().'</a> &nbsp; ';
644  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
645  $selected = 0;
646  if (in_array($object->id, $arrayofselected)) {
647  $selected = 1;
648  }
649  print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
650  }
651  print '</td>';
652  if (!$i) {
653  $totalarray['nbfield']++;
654  }
655 
656  print '</tr>'."\n";
657 
658  $i++;
659 }
660 
661 // Show total line
662 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
663 
664 
665 // If no record found
666 if ($num == 0) {
667  $colspan = 1;
668  foreach ($arrayfields as $key => $val) {
669  if (!empty($val['checked'])) {
670  $colspan++;
671  }
672  }
673  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
674 }
675 
676 
677 $db->free($resql);
678 
679 $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
680 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
681 print $hookmanager->resPrint;
682 
683 print '</table>'."\n";
684 print '</div>'."\n";
685 
686 print '</form>'."\n";
687 
688 if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
689  $hidegeneratedfilelistifempty = 1;
690  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
691  $hidegeneratedfilelistifempty = 0;
692  }
693 
694  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
695  $formfile = new FormFile($db);
696 
697  // Show list of available documents
698  $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
699  $urlsource .= str_replace('&amp;', '&', $param);
700 
701  $filedir = $diroutputmassaction;
702  $genallowed = $permissiontoread;
703  $delallowed = $permissiontoadd;
704 
705  print $formfile->showdocuments('massfilesarea_emailsenderprofile', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
706 }
707 
708 print dol_get_fiche_end();
709 
710 // End of page
711 llxFooter();
712 $db->close();
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
email_admin_prepare_head()
Return array head with list of tabs to view object informations.
Definition: admin.lib.php:2046
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage a WYSIWYG editor.
Class for EmailSenderProfile.
Class to manage standard extra fields.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
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.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
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 dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
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...
rtl background position
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.