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