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