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