dolibarr  17.0.4
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 foreach ($object->fields as $key => $val) {
230  $sql .= "t.".$key.", ";
231 }
232 // Add fields from extrafields
233 if (!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); // Note that $action and $object may have been modified by hook
241 $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
242 $sql = preg_replace('/,\s*$/', '', $sql);
243 $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
244 if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
245  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
246 }
247 if ($object->ismultientitymanaged == 1) {
248  $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
249 } else {
250  $sql .= " WHERE 1 = 1";
251 }
252 foreach ($search as $key => $val) {
253  if ($key == 'status' && $search[$key] == -1) {
254  continue;
255  }
256  $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
257  if (strpos($object->fields[$key]['type'], 'integer:') === 0 || $key == 'active') {
258  if ($search[$key] == '-1') {
259  $search[$key] = '';
260  }
261  $mode_search = 2;
262  }
263  if ($search[$key] != '') {
264  $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
265  }
266 }
267 if ($search_all) {
268  $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
269 }
270 // If non admin, restrict list to itself
271 if (empty($user->admin)) {
272  $sql .= " AND private = ".((int) $user->id);
273 }
274 //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
275 // Add where from extra fields
276 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
277 // Add where from hooks
278 $parameters = array();
279 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
280 $sql .= $hookmanager->resPrint;
281 
282 /* If a group by is required
283 $sql.= " GROUP BY "
284 foreach($object->fields as $key => $val)
285 {
286  $sql .= "t.".$key.", ";
287 }
288 // Add fields from extrafields
289 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
290  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
291 }
292 // Add where from hooks
293 $parameters=array();
294 $reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters); // Note that $action and $object may have been modified by hook
295 $sql.=$hookmanager->resPrint;
296 $sql=preg_replace('/,\s*$/','', $sql);
297 */
298 
299 $sql .= $db->order($sortfield, $sortorder);
300 
301 // Count total nb of records
302 $nbtotalofrecords = '';
303 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
304  $resql = $db->query($sql);
305  $nbtotalofrecords = $db->num_rows($resql);
306  if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
307  $page = 0;
308  $offset = 0;
309  }
310 }
311 // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
312 if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
313  $num = $nbtotalofrecords;
314 } else {
315  if ($limit) {
316  $sql .= $db->plimit($limit + 1, $offset);
317  }
318 
319  $resql = $db->query($sql);
320  if (!$resql) {
321  dol_print_error($db);
322  exit;
323  }
324 
325  $num = $db->num_rows($resql);
326 }
327 
328 
329 // Output page
330 // --------------------------------------------------------------------
331 
332 $arrayofselected = is_array($toselect) ? $toselect : array();
333 
334 $param = '';
335 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
336  $param .= '&contextpage='.urlencode($contextpage);
337 }
338 if ($limit > 0 && $limit != $conf->liste_limit) {
339  $param .= '&limit='.urlencode($limit);
340 }
341 foreach ($search as $key => $val) {
342  if (is_array($search[$key]) && count($search[$key])) {
343  foreach ($search[$key] as $skey) {
344  $param .= '&search_'.$key.'[]='.urlencode($skey);
345  }
346  } else {
347  $param .= '&search_'.$key.'='.urlencode($search[$key]);
348  }
349 }
350 if ($optioncss != '') {
351  $param .= '&optioncss='.urlencode($optioncss);
352 }
353 // Add $param from extra fields
354 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
355 
356 // List of mass actions available
357 $arrayofmassactions = array(
358  //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
359  //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
360 );
361 //if ($permissiontodelete) $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
362 //if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array();
363 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
364 
365 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
366 if ($optioncss != '') {
367  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
368 }
369 print '<input type="hidden" name="token" value="'.newToken().'">';
370 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
371 print '<input type="hidden" name="action" value="'.($action == 'create' ? 'add' : ($action == 'edit' ? 'update' : 'list')).'">';
372 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
373 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
374 print '<input type="hidden" name="page" value="'.$page.'">';
375 print '<input type="hidden" name="id" value="'.$id.'">';
376 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
377 
378 $newcardbutton = '';
379 if ($action != 'create') {
380  $newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', $_SERVER['PHP_SELF'].'?action=create', '', $permissiontoadd);
381 
382  if ($action == 'edit') {
383  print '<table class="border centpercent tableforfield">';
384  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>';
385  print '<tr><td>'.$langs->trans("Email").'</td><td>';
386  print img_picto('', 'email', 'class="pictofixedwidth"');
387  print '<input type="text" name="email" value="'.(GETPOSTISSET('email') ? GETPOST('email', 'alphanohtml') : $object->email).'"></td></tr>';
388  print '<tr><td>'.$langs->trans("Signature").'</td><td>';
389  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
390  $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%');
391  print $doleditor->Create(1);
392  print '</td></tr>';
393  print '<tr><td>'.$langs->trans("User").'</td><td>';
394  print img_picto('', 'user', 'class="pictofixedwidth"');
395  print $form->select_dolusers((GETPOSTISSET('private') ? GETPOST('private', 'int') : $object->private), 'private', 1, null, 0, ($user->admin ? '' : $user->id));
396  print '</td></tr>';
397  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>';
398  print '<tr><td>'.$langs->trans("Status").'</td><td>';
399  print $form->selectarray('active', $object->fields['active']['arrayofkeyval'], (GETPOSTISSET('active') ? GETPOST('active', 'int') : $object->active), 0, 0, 0, '', 1);
400  print '</td></tr>';
401  print '</table>';
402 
403  print $form->buttonsSaveCancel();
404  }
405 } else {
406  /*print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
407  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
408  print '<input type="hidden" name="token" value="'.newToken().'">';
409  print '<input type="hidden" name="action" value="add">';
410  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
411  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
412  print '<input type="hidden" name="page" value="'.$page.'">';
413  print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
414  */
415  print '<table class="border centpercent tableforfield">';
416  print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input type="text" name="label" class="width300" value="'.GETPOST('label', 'alphanohtml').'" autofocus></td></tr>';
417  print '<tr><td class="fieldrequired">'.$langs->trans("Email").'</td><td>';
418  print img_picto('', 'email', 'class="pictofixedwidth"');
419  print '<input type="text" name="email" class="width300" value="'.GETPOST('email', 'alphanohtml').'"></td></tr>';
420  print '<tr><td>'.$langs->trans("Signature").'</td><td>';
421  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
422  $doleditor = new DolEditor('signature', GETPOST('signature'), '', 138, 'dolibarr_notes', 'In', true, true, empty($conf->global->FCKEDITOR_ENABLE_USERSIGN) ? 0 : 1, ROWS_4, '90%');
423  print $doleditor->Create(1);
424  print '</td></tr>';
425  print '<tr><td>'.$langs->trans("User").'</td><td>';
426  print img_picto('', 'user', 'class="pictofixedwidth"');
427  print $form->select_dolusers((GETPOSTISSET('private') ? GETPOST('private', 'int') : -1), 'private', 1, null, 0, ($user->admin ? '' : $user->id));
428  print '</td></tr>';
429  print '<tr><td>'.$langs->trans("Position").'</td><td><input type="text" name="position" class="maxwidth50" value="'.GETPOST('position', 'int').'"></td></tr>';
430  print '<tr><td>'.$langs->trans("Status").'</td><td>';
431  print $form->selectarray('active', $object->fields['active']['arrayofkeyval'], GETPOST('active', 'int'), 0);
432  print '</td></tr>';
433  print '</table>';
434 
435  print $form->buttonsSaveCancel();
436  //print '</form>';
437 }
438 
439 print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_companies', 0, $newcardbutton, '', $limit);
440 //print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_companies', 0, '', '', $limit);
441 
442 $topicmail = "Information";
443 //$modelmail="subscription";
444 $objecttmp = new EmailSenderProfile($db);
445 //$trackid = (($action == 'testhtml') ? "testhtml" : "test");
446 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
447 
448 if ($search_all) {
449  foreach ($fieldstosearchall as $key => $val) {
450  $fieldstosearchall[$key] = $langs->trans($val);
451  }
452  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
453 }
454 
455 $moreforfilter = '';
456 /*$moreforfilter.='<div class="divsearchfield">';
457 $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
458 $moreforfilter.= '</div>';*/
459 
460 $parameters = array();
461 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
462 if (empty($reshook)) {
463  $moreforfilter .= $hookmanager->resPrint;
464 } else {
465  $moreforfilter = $hookmanager->resPrint;
466 }
467 
468 if (!empty($moreforfilter)) {
469  print '<div class="liste_titre liste_titre_bydiv centpercent">';
470  print $moreforfilter;
471  print '</div>';
472 }
473 
474 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
475 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
476 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
477 
478 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
479 print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
480 
481 
482 // Fields title search
483 // --------------------------------------------------------------------
484 print '<tr class="liste_titre">';
485 foreach ($object->fields as $key => $val) {
486  $cssforfield = (empty($val['css']) ? '' : $val['css']);
487  if ($key == 'status') {
488  $cssforfield .= ($cssforfield ? ' ' : '').'center';
489  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
490  $cssforfield .= ($cssforfield ? ' ' : '').'center';
491  } elseif (in_array($val['type'], array('timestamp'))) {
492  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
493  } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') {
494  $cssforfield .= ($cssforfield ? ' ' : '').'right';
495  }
496  if (!empty($arrayfields['t.'.$key]['checked'])) {
497  print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
498  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
499  print $form->selectarray('search_'.$key, $val['arrayofkeyval'], empty($search[$key]) ? '' : $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
500  } elseif (strpos($val['type'], 'integer:') === 0) {
501  print $object->showInputField($val, $key, empty($search[$key]) ? '' : $search[$key], '', '', 'search_', 'maxwidth150', 1);
502  } elseif (!preg_match('/^(date|timestamp)/', $val['type'])) {
503  print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(empty($search[$key]) ? '' : $search[$key]).'">';
504  }
505  print '</td>';
506  }
507 }
508 // Extra fields
509 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
510 // Fields from hook
511 $parameters = array('arrayfields'=>$arrayfields);
512 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
513 print $hookmanager->resPrint;
514 // Action column
515 print '<td class="liste_titre maxwidthsearch">';
516 $searchpicto = $form->showFilterButtons();
517 print $searchpicto;
518 print '</td>';
519 print '</tr>'."\n";
520 
521 
522 // Fields title label
523 // --------------------------------------------------------------------
524 print '<tr class="liste_titre">';
525 foreach ($object->fields as $key => $val) {
526  $cssforfield = (empty($val['css']) ? '' : $val['css']);
527  if ($key == 'status') {
528  $cssforfield .= ($cssforfield ? ' ' : '').'center';
529  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
530  $cssforfield .= ($cssforfield ? ' ' : '').'center';
531  } elseif (in_array($val['type'], array('timestamp'))) {
532  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
533  } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') {
534  $cssforfield .= ($cssforfield ? ' ' : '').'right';
535  }
536  if (!empty($arrayfields['t.'.$key]['checked'])) {
537  print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
538  }
539 }
540 // Extra fields
541 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
542 
543 // Hook fields
544 $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
545 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
546 print $hookmanager->resPrint;
547 // Action column
548 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
549 print '</tr>'."\n";
550 
551 
552 // Detect if we need a fetch on each output line
553 $needToFetchEachLine = 0;
554 if (!empty($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
555  foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
556  if (preg_match('/\$object/', $val)) {
557  $needToFetchEachLine++; // There is at least one compute field that use $object
558  }
559  }
560 }
561 
562 
563 // Loop on record
564 // --------------------------------------------------------------------
565 $i = 0;
566 $totalarray = array();
567 $totalarray['nbfield'] = 0;
568 while ($i < ($limit ? min($num, $limit) : $num)) {
569  $obj = $db->fetch_object($resql);
570  if (empty($obj)) {
571  break; // Should not happen
572  }
573 
574  // Store properties in $object
575  $object->setVarsFromFetchObj($obj);
576 
577  // Show here line of result
578  print '<tr class="oddeven">';
579  foreach ($object->fields as $key => $val) {
580  $cssforfield = (empty($val['css']) ? '' : $val['css']);
581  if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
582  $cssforfield .= ($cssforfield ? ' ' : '').'center';
583  } elseif ($key == 'status') {
584  $cssforfield .= ($cssforfield ? ' ' : '').'center';
585  }
586 
587  if (in_array($val['type'], array('timestamp'))) {
588  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
589  } elseif ($key == 'ref') {
590  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
591  }
592 
593  if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $key != 'status') {
594  $cssforfield .= ($cssforfield ? ' ' : '').'right';
595  }
596 
597  if (!empty($arrayfields['t.'.$key]['checked'])) {
598  print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '').'>';
599  if ($key == 'status' || $key == 'active') {
600  print $object->getLibStatut(5);
601  } else {
602  print $object->showOutputField($val, $key, $object->$key, '');
603  }
604  print '</td>';
605  if (!$i) {
606  $totalarray['nbfield']++;
607  }
608  if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
609  if (!$i) {
610  $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
611  }
612  if (!isset($totalarray['val'])) {
613  $totalarray['val'] = array();
614  }
615  if (!isset($totalarray['val']['t.'.$key])) {
616  $totalarray['val']['t.'.$key] = 0;
617  }
618  $totalarray['val']['t.'.$key] += $object->$key;
619  }
620  }
621  }
622  // Extra fields
623  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
624  // Fields from hook
625  $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
626  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
627  print $hookmanager->resPrint;
628  // Action column
629  print '<td class="nowrap center">';
630  $url = $_SERVER["PHP_SELF"].'?id='.$obj->rowid;
631  if ($limit) {
632  $url .= '&limit='.urlencode($limit);
633  }
634  if ($page) {
635  $url .= '&page='.urlencode($page);
636  }
637  if ($sortfield) {
638  $url .= '&sortfield='.urlencode($sortfield);
639  }
640  if ($sortorder) {
641  $url .= '&page='.urlencode($sortorder);
642  }
643  print '<a class="editfielda reposition marginrightonly marginleftonly" href="'.$url.'&action=edit&token='.newToken().'&rowid='.$obj->rowid.'">'.img_edit().'</a>';
644  //print ' &nbsp; ';
645  print '<a class=" marginrightonly marginleftonly" href="'.$url.'&action=delete&token='.newToken().'">'.img_delete().'</a> &nbsp; ';
646  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
647  $selected = 0;
648  if (in_array($object->id, $arrayofselected)) {
649  $selected = 1;
650  }
651  print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
652  }
653  print '</td>';
654  if (!$i) {
655  $totalarray['nbfield']++;
656  }
657 
658  print '</tr>'."\n";
659 
660  $i++;
661 }
662 
663 // Show total line
664 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
665 
666 
667 // If no record found
668 if ($num == 0) {
669  $colspan = 1;
670  foreach ($arrayfields as $key => $val) {
671  if (!empty($val['checked'])) {
672  $colspan++;
673  }
674  }
675  print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
676 }
677 
678 
679 $db->free($resql);
680 
681 $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
682 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
683 print $hookmanager->resPrint;
684 
685 print '</table>'."\n";
686 print '</div>'."\n";
687 
688 print '</form>'."\n";
689 
690 if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
691  $hidegeneratedfilelistifempty = 1;
692  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
693  $hidegeneratedfilelistifempty = 0;
694  }
695 
696  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
697  $formfile = new FormFile($db);
698 
699  // Show list of available documents
700  $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
701  $urlsource .= str_replace('&amp;', '&', $param);
702 
703  $filedir = $diroutputmassaction;
704  $genallowed = $permissiontoread;
705  $delallowed = $permissiontoadd;
706 
707  print $formfile->showdocuments('massfilesarea_emailsenderprofile', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
708 }
709 
710 print dol_get_fiche_end();
711 
712 // End of page
713 llxFooter();
714 $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:2016
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') &&!empty($user->rights->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') &&!empty($user->rights->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)) $resql
Social contributions to pay.
Definition: index.php:745
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.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
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...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
dol_now($mode='auto')
Return date for now.
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.
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.
$nbtotalofrecords
Count total nb of records.
Definition: list.php:329
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.