dolibarr  20.0.0-beta
availabilities_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) 2022 Alice Adminson <aadminson@example.com>
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/date.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
30 
31 // load module libraries
32 require_once __DIR__.'/class/availabilities.class.php';
33 
34 // for other modules
35 //dol_include_once('/othermodule/class/otherobject.class.php');
36 
37 // Load translation files required by the page
38 $langs->loadLangs(array("agenda", "other"));
39 
40 $id = GETPOSTINT('id');
41 $ref = GETPOST('ref', 'alpha');
42 
43 $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
44 $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
45 $show_files = GETPOSTINT('show_files'); // Show files area generated by bulk actions ?
46 $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
47 $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
48 $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
49 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)).basename(__FILE__, '.php')); // To manage different context of search
50 $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
51 $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
52 $mode = GETPOST('mode', 'aZ'); // The output mode ('list', 'kanban', 'hierarchy', 'calendar', ...)
53 
54 // Load variable for pagination
55 $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
56 $sortfield = GETPOST('sortfield', 'aZ09comma');
57 $sortorder = GETPOST('sortorder', 'aZ09comma');
58 $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
59 if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
60  // If $page is not defined, or '' or -1 or if we click on clear filters
61  $page = 0;
62 }
63 $offset = $limit * $page;
64 $pageprev = $page - 1;
65 $pagenext = $page + 1;
66 
67 // Initialize technical objects
68 $object = new Availabilities($db);
69 $extrafields = new ExtraFields($db);
70 $diroutputmassaction = $conf->bookcal->dir_output.'/temp/massgeneration/'.$user->id;
71 $hookmanager->initHooks(array($contextpage)); // Note that conf->hooks_modules contains array
72 
73 // Fetch optionals attributes and labels
74 $extrafields->fetch_name_optionals_label($object->table_element);
75 //$extrafields->fetch_name_optionals_label($object->table_element_line);
76 
77 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
78 
79 // Default sort order (if not yet defined by previous GETPOST)
80 if (!$sortfield) {
81  reset($object->fields); // Reset is required to avoid key() to return null.
82  $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
83 }
84 if (!$sortorder) {
85  $sortorder = "ASC";
86 }
87 
88 // Initialize array of search criteria
89 $search_all = GETPOST('search_all', 'alphanohtml');
90 $search = array();
91 foreach ($object->fields as $key => $val) {
92  if (GETPOST('search_'.$key, 'alpha') !== '') {
93  $search[$key] = GETPOST('search_'.$key, 'alpha');
94  }
95  if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
96  $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOSTINT('search_'.$key.'_dtstartmonth'), GETPOSTINT('search_'.$key.'_dtstartday'), GETPOSTINT('search_'.$key.'_dtstartyear'));
97  $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOSTINT('search_'.$key.'_dtendmonth'), GETPOSTINT('search_'.$key.'_dtendday'), GETPOSTINT('search_'.$key.'_dtendyear'));
98  }
99 }
100 
101 // List of fields to search into when doing a "search in all"
102 // $fieldstosearchall = array();
103 // foreach ($object->fields as $key => $val) {
104 // if (!empty($val['searchall'])) {
105 // $fieldstosearchall['t.'.$key] = $val['label'];
106 // }
107 // }
108 // $parameters = array('fieldstosearchall'=>$fieldstosearchall);
109 // $reshook = $hookmanager->executeHooks('completeFieldsToSearchAll', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
110 // if ($reshook > 0) {
111 // $fieldstosearchall = empty($hookmanager->resArray['fieldstosearchall']) ? array() : $hookmanager->resArray['fieldstosearchall'];
112 // } elseif ($reshook == 0) {
113 // $fieldstosearchall = array_merge($fieldstosearchall, empty($hookmanager->resArray['fieldstosearchall']) ? array() : $hookmanager->resArray['fieldstosearchall']);
114 // }
115 
116 
117 // $fieldstosearchall is supposedly defined further below, ensure that it is.
118 if (!isset($fieldstosearchall) || !is_array($fieldstosearchall)) {
119  $fieldstosearchall = array();
120 }
121 '
122  @phan-var-force array<string,string> $fieldstosearchall
123 ';
124 
125 
126 // Definition of array of fields for columns
127 $arrayfields = array();
128 foreach ($object->fields as $key => $val) {
129  // If $val['visible']==0, then we never show the field
130  if (!empty($val['visible'])) {
131  $visible = (int) dol_eval($val['visible'], 1);
132  $arrayfields['t.'.$key] = array(
133  'label' => $val['label'],
134  'checked' => (($visible < 0) ? 0 : 1),
135  'enabled' => (abs($visible) != 3 && (int) dol_eval($val['enabled'], 1)),
136  'position' => $val['position'],
137  'help' => isset($val['help']) ? $val['help'] : ''
138  );
139  }
140 }
141 // Extra fields
142 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
143 
144 $object->fields = dol_sort_array($object->fields, 'position');
145 //$arrayfields['anotherfield'] = array('type'=>'integer', 'label'=>'AnotherField', 'checked'=>1, 'enabled'=>1, 'position'=>90, 'csslist'=>'right');
146 $arrayfields = dol_sort_array($arrayfields, 'position');
147 
148 // There is several ways to check permission.
149 // Set $enablepermissioncheck to 1 to enable a minimum low level of checks
150 $enablepermissioncheck = 0;
151 if ($enablepermissioncheck) {
152  $permissiontoread = $user->hasRight('bookcal', 'availabilities', 'read');
153  $permissiontoadd = $user->hasRight('bookcal', 'availabilities', 'write');
154  $permissiontodelete = $user->hasRight('bookcal', 'availabilities', 'delete');
155 } else {
156  $permissiontoread = 1;
157  $permissiontoadd = 1;
158  $permissiontodelete = 1;
159 }
160 
161 // Security check (enable the most restrictive one)
162 if ($user->socid > 0) {
163  accessforbidden();
164 }
165 //if ($user->socid > 0) accessforbidden();
166 //$socid = 0; if ($user->socid > 0) $socid = $user->socid;
167 //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
168 //restrictedArea($user, $object->element, 0, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
169 if (!isModEnabled('bookcal')) {
170  accessforbidden('Module bookcal not enabled');
171 }
172 if (!$permissiontoread) {
173  accessforbidden();
174 }
175 
176 
177 /*
178  * Actions
179  */
180 
181 if (GETPOST('cancel', 'alpha')) {
182  $action = 'list';
183  $massaction = '';
184 }
185 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
186  $massaction = '';
187 }
188 
189 $parameters = array();
190 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
191 if ($reshook < 0) {
192  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
193 }
194 
195 if (empty($reshook)) {
196  // Selection of new fields
197  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
198 
199  // Purge search criteria
200  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
201  foreach ($object->fields as $key => $val) {
202  $search[$key] = '';
203  if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
204  $search[$key.'_dtstart'] = '';
205  $search[$key.'_dtend'] = '';
206  }
207  }
208  $toselect = array();
209  $search_array_options = array();
210  }
211  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
212  || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
213  $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
214  }
215 
216  // Mass actions
217  $objectclass = 'Availabilities';
218  $objectlabel = 'Availabilities';
219  $uploaddir = $conf->bookcal->dir_output;
220  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
221 
222  // You can add more action here
223  // if ($action == 'xxx' && $permissiontoxxx) ...
224 }
225 
226 
227 
228 /*
229  * View
230  */
231 
232 $form = new Form($db);
233 
234 $now = dol_now();
235 
236 $title = $langs->trans("Availabilities");
237 //$help_url = "EN:Module_Availabilities|FR:Module_Availabilities_FR|ES:Módulo_Availabilities";
238 $help_url = '';
239 $morejs = array();
240 $morecss = array();
241 
242 
243 // Build and execute select
244 // --------------------------------------------------------------------
245 $sql = 'SELECT ';
246 $sql .= $object->getFieldList('t');
247 // Add fields from extrafields
248 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
249  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
250  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
251  }
252 }
253 // Add fields from hooks
254 $parameters = array();
255 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
256 $sql .= $hookmanager->resPrint;
257 $sql = preg_replace('/,\s*$/', '', $sql);
258 //$sql .= ", COUNT(rc.rowid) as anotherfield";
259 
260 $sqlfields = $sql; // $sql fields to remove for count total
261 
262 $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
263 //$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."anothertable as rc ON rc.parent = t.rowid";
264 if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
265  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
266 }
267 // Add table from hooks
268 $parameters = array();
269 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
270 $sql .= $hookmanager->resPrint;
271 if ($object->ismultientitymanaged == 1) {
272  $sql .= " WHERE t.entity IN (".getEntity($object->element, (GETPOSTINT('search_current_entity') ? 0 : 1)).")";
273 } else {
274  $sql .= " WHERE 1 = 1";
275 }
276 foreach ($search as $key => $val) {
277  if (array_key_exists($key, $object->fields)) {
278  if ($key == 'status' && $search[$key] == -1) {
279  continue;
280  }
281  $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
282  if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
283  if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
284  $search[$key] = '';
285  }
286  $mode_search = 2;
287  }
288  if ($search[$key] != '') {
289  $sql .= natural_search("t.".$db->escape($key), $search[$key], (($key == 'status') ? 2 : $mode_search));
290  }
291  } else {
292  if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
293  $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
294  if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
295  if (preg_match('/_dtstart$/', $key)) {
296  $sql .= " AND t.".$db->escape($columnName)." >= '".$db->idate($search[$key])."'";
297  }
298  if (preg_match('/_dtend$/', $key)) {
299  $sql .= " AND t.".$db->escape($columnName)." <= '".$db->idate($search[$key])."'";
300  }
301  }
302  }
303  }
304 }
305 if ($search_all) {
306  $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
307 }
308 //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
309 // Add where from extra fields
310 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
311 // Add where from hooks
312 $parameters = array();
313 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
314 $sql .= $hookmanager->resPrint;
315 
316 /* If a group by is required
317 $sql .= " GROUP BY ";
318 foreach($object->fields as $key => $val) {
319  $sql .= "t.".$db->escape($key).", ";
320 }
321 // Add fields from extrafields
322 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
323  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
324  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
325  }
326 }
327 // Add groupby from hooks
328 $parameters = array();
329 $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
330 $sql .= $hookmanager->resPrint;
331 $sql = preg_replace('/,\s*$/', '', $sql);
332 */
333 
334 // Add HAVING from hooks
335 /*
336 $parameters = array();
337 $reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
338 $sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint;
339 */
340 
341 // Count total nb of records
342 $nbtotalofrecords = '';
343 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
344  /* The fast and low memory method to get and count full list converts the sql into a sql count */
345  $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
346  $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
347  $resql = $db->query($sqlforcount);
348  if ($resql) {
349  $objforcount = $db->fetch_object($resql);
350  $nbtotalofrecords = $objforcount->nbtotalofrecords;
351  } else {
352  dol_print_error($db);
353  }
354 
355  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
356  $page = 0;
357  $offset = 0;
358  }
359  $db->free($resql);
360 }
361 
362 // Complete request and execute it with limit
363 $sql .= $db->order($sortfield, $sortorder);
364 if ($limit) {
365  $sql .= $db->plimit($limit + 1, $offset);
366 }
367 
368 $resql = $db->query($sql);
369 if (!$resql) {
370  dol_print_error($db);
371  exit;
372 }
373 
374 $num = $db->num_rows($resql);
375 
376 
377 // Direct jump if only one record found
378 if ($num == 1 && getDolGlobalInt('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
379  $obj = $db->fetch_object($resql);
380  $id = $obj->rowid;
381  header("Location: ".dol_buildpath('/bookcal/availabilities_card.php', 1).'?id='.$id);
382  exit;
383 }
384 
385 
386 // Output page
387 // --------------------------------------------------------------------
388 
389 llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'bodyforlist'); // Can use also classforhorizontalscrolloftabs instead of bodyforlist for no horizontal scroll
390 
391 // Example : Adding jquery code
392 // print '<script type="text/javascript">
393 // jQuery(document).ready(function() {
394 // function init_myfunc()
395 // {
396 // jQuery("#myid").removeAttr(\'disabled\');
397 // jQuery("#myid").attr(\'disabled\',\'disabled\');
398 // }
399 // init_myfunc();
400 // jQuery("#mybutton").click(function() {
401 // init_myfunc();
402 // });
403 // });
404 // </script>';
405 
406 $arrayofselected = is_array($toselect) ? $toselect : array();
407 
408 $param = '';
409 if (!empty($mode)) {
410  $param .= '&mode='.urlencode($mode);
411 }
412 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
413  $param .= '&contextpage='.urlencode($contextpage);
414 }
415 if ($limit > 0 && $limit != $conf->liste_limit) {
416  $param .= '&limit='.((int) $limit);
417 }
418 if ($optioncss != '') {
419  $param .= '&optioncss='.urlencode($optioncss);
420 }
421 foreach ($search as $key => $val) {
422  if (is_array($search[$key])) {
423  foreach ($search[$key] as $skey) {
424  if ($skey != '') {
425  $param .= '&search_'.$key.'[]='.urlencode($skey);
426  }
427  }
428  } elseif (preg_match('/(_dtstart|_dtend)$/', $key) && !empty($val)) {
429  $param .= '&search_'.$key.'month='.(GETPOSTINT('search_'.$key.'month'));
430  $param .= '&search_'.$key.'day='.(GETPOSTINT('search_'.$key.'day'));
431  $param .= '&search_'.$key.'year='.(GETPOSTINT('search_'.$key.'year'));
432  } elseif ($search[$key] != '') {
433  $param .= '&search_'.$key.'='.urlencode($search[$key]);
434  }
435 }
436 // Add $param from extra fields
437 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
438 // Add $param from hooks
439 $parameters = array('param' => &$param);
440 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
441 $param .= $hookmanager->resPrint;
442 
443 // List of mass actions available
444 $arrayofmassactions = array(
445  //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
446  //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
447  //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
448  //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
449 );
450 if (!empty($permissiontodelete)) {
451  $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
452 }
453 if (GETPOSTINT('nomassaction') || in_array($massaction, array('presend', 'predelete'))) {
454  $arrayofmassactions = array();
455 }
456 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
457 
458 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
459 if ($optioncss != '') {
460  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
461 }
462 print '<input type="hidden" name="token" value="'.newToken().'">';
463 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
464 print '<input type="hidden" name="action" value="list">';
465 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
466 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
467 print '<input type="hidden" name="page" value="'.$page.'">';
468 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
469 print '<input type="hidden" name="mode" value="'.$mode.'">';
470 
471 
472 $newcardbutton = '';
473 $newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss' => 'reposition'));
474 $newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss' => 'reposition'));
475 $newcardbutton .= dolGetButtonTitleSeparator();
476 $newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/bookcal/availabilities_card.php', 1).'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
477 
478 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
479 
480 // Add code for pre mass action (confirmation or email presend form)
481 $topicmail = "SendAvailabilitiesRef";
482 $modelmail = "availabilities";
483 $objecttmp = new Availabilities($db);
484 $trackid = 'xxxx'.$object->id;
485 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
486 
487 if ($search_all) {
488  $setupstring = '';
489  foreach ($fieldstosearchall as $key => $val) {
490  $fieldstosearchall[$key] = $langs->trans($val);
491  $setupstring .= $key."=".$val.";";
492  }
493  print '<!-- Search done like if BOOKCAL_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
494  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).implode(', ', $fieldstosearchall).'</div>'."\n";
495 }
496 
497 $moreforfilter = '';
498 /*$moreforfilter.='<div class="divsearchfield">';
499 $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
500 $moreforfilter.= '</div>';*/
501 
502 $parameters = array();
503 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
504 if (empty($reshook)) {
505  $moreforfilter .= $hookmanager->resPrint;
506 } else {
507  $moreforfilter = $hookmanager->resPrint;
508 }
509 
510 if (!empty($moreforfilter)) {
511  print '<div class="liste_titre liste_titre_bydiv centpercent">';
512  print $moreforfilter;
513  $parameters = array();
514  $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
515  print $hookmanager->resPrint;
516  print '</div>';
517 }
518 
519 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
520 $htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields with user setup
521 $selectedfields = ($mode != 'kanban' ? $htmlofselectarray : '');
522 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
523 
524 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
525 print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
526 
527 
528 // Fields title search
529 // --------------------------------------------------------------------
530 print '<tr class="liste_titre_filter">';
531 // Action column
532 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
533  print '<td class="liste_titre center maxwidthsearch">';
534  $searchpicto = $form->showFilterButtons('left');
535  print $searchpicto;
536  print '</td>';
537 }
538 foreach ($object->fields as $key => $val) {
539  $searchkey = empty($search[$key]) ? '' : $search[$key];
540  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
541  if ($key == 'status') {
542  $cssforfield .= ($cssforfield ? ' ' : '').'center';
543  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
544  $cssforfield .= ($cssforfield ? ' ' : '').'center';
545  } elseif (in_array($val['type'], array('timestamp'))) {
546  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
547  } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $key != 'rowid' && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
548  $cssforfield .= ($cssforfield ? ' ' : '').'right';
549  }
550  if (!empty($arrayfields['t.'.$key]['checked'])) {
551  print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').($key == 'status' ? ' parentonrightofpage' : '').'">';
552  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
553  print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100'.($key == 'status' ? ' search_status width100 onrightofpage' : ''), 1);
554  } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
555  print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', $cssforfield.' maxwidth250', 1);
556  } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
557  print '<div class="nowrap">';
558  print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
559  print '</div>';
560  print '<div class="nowrap">';
561  print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
562  print '</div>';
563  } elseif ($key == 'lang') {
564  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
565  $formadmin = new FormAdmin($db);
566  print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth100imp maxwidth125', 2);
567  } else {
568  print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
569  }
570  print '</td>';
571  }
572 }
573 // Extra fields
574 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
575 
576 // Fields from hook
577 $parameters = array('arrayfields' => $arrayfields);
578 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
579 print $hookmanager->resPrint;
580 /*if (!empty($arrayfields['anotherfield']['checked'])) {
581  print '<td class="liste_titre"></td>';
582 }*/
583 // Action column
584 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
585  print '<td class="liste_titre center maxwidthsearch">';
586  $searchpicto = $form->showFilterButtons();
587  print $searchpicto;
588  print '</td>';
589 }
590 print '</tr>'."\n";
591 
592 $totalarray = array();
593 $totalarray['nbfield'] = 0;
594 
595 // Fields title label
596 // --------------------------------------------------------------------
597 print '<tr class="liste_titre">';
598 // Action column
599 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
600  print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
601  $totalarray['nbfield']++;
602 }
603 foreach ($object->fields as $key => $val) {
604  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
605  if ($key == 'status') {
606  $cssforfield .= ($cssforfield ? ' ' : '').'center';
607  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
608  $cssforfield .= ($cssforfield ? ' ' : '').'center';
609  } elseif (in_array($val['type'], array('timestamp'))) {
610  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
611  } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $key != 'rowid' && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
612  $cssforfield .= ($cssforfield ? ' ' : '').'right';
613  }
614  $cssforfield = preg_replace('/small\s*/', '', $cssforfield); // the 'small' css must not be used for the title label
615  if (!empty($arrayfields['t.'.$key]['checked'])) {
616  print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''), 0, (empty($val['helplist']) ? '' : $val['helplist']))."\n";
617  $totalarray['nbfield']++;
618  }
619 }
620 // Extra fields
621 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
622 // Hook fields
623 $parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder, 'totalarray' => &$totalarray);
624 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
625 print $hookmanager->resPrint;
626 /*if (!empty($arrayfields['anotherfield']['checked'])) {
627  print '<th class="liste_titre right">'.$langs->trans("AnotherField").'</th>';
628  $totalarray['nbfield']++;
629 }*/
630 // Action column
631 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
632  print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
633  $totalarray['nbfield']++;
634 }
635 print '</tr>'."\n";
636 
637 
638 // Detect if we need a fetch on each output line
639 $needToFetchEachLine = 0;
640 if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
641  foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
642  if (!is_null($val) && preg_match('/\$object/', $val)) {
643  $needToFetchEachLine++; // There is at least one compute field that use $object
644  }
645  }
646 }
647 
648 
649 // Loop on record
650 // --------------------------------------------------------------------
651 $i = 0;
652 $savnbfield = $totalarray['nbfield'];
653 $totalarray = array();
654 $totalarray['nbfield'] = 0;
655 $imaxinloop = ($limit ? min($num, $limit) : $num);
656 while ($i < $imaxinloop) {
657  $obj = $db->fetch_object($resql);
658  if (empty($obj)) {
659  break; // Should not happen
660  }
661 
662  // Store properties in $object
663  $object->setVarsFromFetchObj($obj);
664 
665  if ($mode == 'kanban') {
666  if ($i == 0) {
667  print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
668  print '<div class="box-flex-container kanban">';
669  }
670  // Output Kanban
671  $selected = -1;
672  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
673  $selected = 0;
674  if (in_array($object->id, $arrayofselected)) {
675  $selected = 1;
676  }
677  }
678  print $object->getKanbanView('', array('selected' => $selected));
679  if ($i == ($imaxinloop - 1)) {
680  print '</div>';
681  print '</td></tr>';
682  }
683  } else {
684  // Show line of result
685  $j = 0;
686  print '<tr data-rowid="'.$object->id.'" class="oddeven">';
687  // Action column
688  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
689  print '<td class="nowrap center">';
690  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
691  $selected = 0;
692  if (in_array($object->id, $arrayofselected)) {
693  $selected = 1;
694  }
695  print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
696  }
697  print '</td>';
698  if (!$i) {
699  $totalarray['nbfield']++;
700  }
701  }
702  foreach ($object->fields as $key => $val) {
703  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
704  if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
705  $cssforfield .= ($cssforfield ? ' ' : '').'center';
706  } elseif ($key == 'status') {
707  $cssforfield .= ($cssforfield ? ' ' : '').'center';
708  }
709 
710  if (in_array($val['type'], array('timestamp'))) {
711  $cssforfield .= ($cssforfield ? ' ' : '').'nowraponall';
712  } elseif ($key == 'ref') {
713  $cssforfield .= ($cssforfield ? ' ' : '').'nowraponall';
714  }
715 
716  if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
717  $cssforfield .= ($cssforfield ? ' ' : '').'right';
718  }
719  //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
720 
721  if (!empty($arrayfields['t.'.$key]['checked'])) {
722  print '<td'.($cssforfield ? ' class="'.$cssforfield.(preg_match('/tdoverflow/', $cssforfield) ? ' classfortooltip' : '').'"' : '');
723  if (preg_match('/tdoverflow/', $cssforfield) && !is_numeric($object->$key)) {
724  print ' title="'.dol_escape_htmltag($object->$key).'"';
725  }
726  print '>';
727  if ($key == 'status') {
728  print $object->getLibStatut(5);
729  } elseif ($key == 'rowid') {
730  print $object->showOutputField($val, $key, $object->id, '');
731  } else {
732  print $object->showOutputField($val, $key, $object->$key, '');
733  }
734  print '</td>';
735  if (!$i) {
736  $totalarray['nbfield']++;
737  }
738  if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
739  if (!$i) {
740  $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
741  }
742  if (!isset($totalarray['val'])) {
743  $totalarray['val'] = array();
744  }
745  if (!isset($totalarray['val']['t.'.$key])) {
746  $totalarray['val']['t.'.$key] = 0;
747  }
748  $totalarray['val']['t.'.$key] += $object->$key;
749  }
750  }
751  }
752  // Extra fields
753  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
754  // Fields from hook
755  $parameters = array('arrayfields' => $arrayfields, 'object' => $object, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
756  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
757  print $hookmanager->resPrint;
758  /*if (!empty($arrayfields['anotherfield']['checked'])) {
759  print '<td class="right">'.$obj->anotherfield.'</td>';
760  }*/
761  // Action column
762  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
763  print '<td class="nowrap center">';
764  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
765  $selected = 0;
766  if (in_array($object->id, $arrayofselected)) {
767  $selected = 1;
768  }
769  print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
770  }
771  print '</td>';
772  if (!$i) {
773  $totalarray['nbfield']++;
774  }
775  }
776 
777  print '</tr>'."\n";
778  }
779 
780  $i++;
781 }
782 
783 // Show total line
784 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
785 
786 // If no record found
787 if ($num == 0) {
788  $colspan = 1;
789  foreach ($arrayfields as $key => $val) {
790  if (!empty($val['checked'])) {
791  $colspan++;
792  }
793  }
794  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
795 }
796 
797 
798 $db->free($resql);
799 
800 $parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
801 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
802 print $hookmanager->resPrint;
803 
804 print '</table>'."\n";
805 print '</div>'."\n";
806 
807 print '</form>'."\n";
808 
809 if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
810  $hidegeneratedfilelistifempty = 1;
811  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
812  $hidegeneratedfilelistifempty = 0;
813  }
814 
815  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
816  $formfile = new FormFile($db);
817 
818  // Show list of available documents
819  $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
820  $urlsource .= str_replace('&amp;', '&', $param);
821 
822  $filedir = $diroutputmassaction;
823  $genallowed = $permissiontoread;
824  $delallowed = $permissiontoadd;
825 
826  print $formfile->showdocuments('massfilesarea_'.$object->module, '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
827 }
828 
829 // End of page
830 llxFooter();
831 $db->close();
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:55
llxFooter()
Empty footer.
Definition: wrapper.php:69
Class for Availabilities.
Class to manage standard extra fields.
Class to generate html code for admin pages.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('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') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:745
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
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 a Dolibarr global constant int value.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
dolGetButtonTitleSeparator($moreClass="")
Add space between dolGetButtonTitle.
print_barre_liste($title, $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.
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.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.