dolibarr 25.0.0-alpha
customreports.lib.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (C) 2024 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024-2025 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 * or see https://www.gnu.org/
20 */
21
39function fillArrayOfMeasures($object, $tablealias, $labelofobject, &$arrayofmesures, $level = 0, &$count = 0, &$tablepath = '')
40{
41 global $langs, $extrafields, $db;
42
43 if (empty($object)) { // Protection against bad use of method
44 return array();
45 }
46 if ($level >= 3) { // Limit scan on 2 levels max
47 return $arrayofmesures;
48 }
49
50 if (empty($tablepath)) {
51 $tablepath = $object->table_element.'='.$tablealias;
52 } else {
53 $tablepath .= ','.$object->table_element.'='.$tablealias;
54 }
55
56 if ($level == 0) {
57 // Add the count of record only for the main/first level object. Parents are necessarily unique for each record.
58 $arrayofmesures[$tablealias.'.count'] = array(
59 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').$labelofobject.': '.$langs->trans("Number"),
60 'labelnohtml' => $labelofobject.': '.$langs->trans("Number"),
61 'position' => 0,
62 'table' => $object->table_element,
63 'tablefromt' => $tablepath
64 );
65 }
66
67 // Note: here $tablealias can be 't' or 't__fk_contract' or 't_fk_contract_fk_soc'
68
69 // Add main fields of object
70 foreach ($object->fields as $key => $val) {
71 // Discard the fields declared with attribute 'bi' set to 0 (field hidden on BI tool)
72 if (isset($val['bi']) && (int) $val['bi'] == 0) {
73 continue;
74 }
75 if (!empty($val['isameasure']) && (!isset($val['enabled']) || (int) dol_eval((string) $val['enabled'], 1, 1, '1'))) {
76 $position = (empty($val['position']) ? 0 : intval($val['position']));
77 $arrayofmesures[$tablealias.'.'.$key.'-sum'] = array(
78 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$langs->trans("Sum").')</span>',
79 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
80 'position' => ($position + ($count * 100000)).'.1',
81 'table' => $object->table_element,
82 'tablefromt' => $tablepath
83 );
84 $arrayofmesures[$tablealias.'.'.$key.'-average'] = array(
85 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$langs->trans("Average").')</span>',
86 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
87 'position' => ($position + ($count * 100000)).'.2',
88 'table' => $object->table_element,
89 'tablefromt' => $tablepath
90 );
91 $arrayofmesures[$tablealias.'.'.$key.'-min'] = array(
92 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$langs->trans("Minimum").')</span>',
93 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
94 'position' => ($position + ($count * 100000)).'.3',
95 'table' => $object->table_element,
96 'tablefromt' => $tablepath
97 );
98 $arrayofmesures[$tablealias.'.'.$key.'-max'] = array(
99 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$langs->trans("Maximum").')</span>',
100 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
101 'position' => ($position + ($count * 100000)).'.4',
102 'table' => $object->table_element,
103 'tablefromt' => $tablepath
104 );
105 $arrayofmesures[$tablealias.'.'.$key.'-stddevpop'] = array(
106 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$langs->trans("StandardDeviationPop").')</span>',
107 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
108 'position' => ($position + ($count * 100000)).'.5',
109 'table' => $object->table_element,
110 'tablefromt' => $tablepath
111 );
112 }
113 }
114 // Add extrafields to Measures
115 if (!empty($object->isextrafieldmanaged) && isset($extrafields->attributes[$object->table_element]['label'])) {
116 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
117 if (!empty($extrafields->attributes[$object->table_element]['totalizable'][$key]) && (!isset($extrafields->attributes[$object->table_element]['enabled'][$key]) || (int) dol_eval((string) $extrafields->attributes[$object->table_element]['enabled'][$key], 1, 1, '1'))) {
118 if (isset($extrafields->attributes[$object->table_element]['pos'][$key])) {
119 $position = $extrafields->attributes[$object->table_element]['pos'][$key];
120 } else {
121 $position = 0;
122 }
123 $arrayofmesures[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-sum'] = array(
124 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').$labelofobject.': '.$langs->trans($extrafields->attributes[$object->table_element]['label'][$key]).' <span class="opacitymedium">('.$langs->trans("Sum").')</span>',
125 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
126 'position' => ($position + ($count * 100000)).'.1',
127 'table' => $object->table_element,
128 'tablefromt' => $tablepath
129 );
130 $arrayofmesures[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-average'] = array(
131 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').$labelofobject.': '.$langs->trans($extrafields->attributes[$object->table_element]['label'][$key]).' <span class="opacitymedium">('.$langs->trans("Average").')</span>',
132 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
133 'position' => ($position + ($count * 100000)).'.2',
134 'table' => $object->table_element,
135 'tablefromt' => $tablepath
136 );
137 $arrayofmesures[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-min'] = array(
138 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').$labelofobject.': '.$langs->trans($extrafields->attributes[$object->table_element]['label'][$key]).' <span class="opacitymedium">('.$langs->trans("Minimum").')</span>',
139 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
140 'position' => ($position + ($count * 100000)).'.3',
141 'table' => $object->table_element,
142 'tablefromt' => $tablepath
143 );
144 $arrayofmesures[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-max'] = array(
145 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').$labelofobject.': '.$langs->trans($extrafields->attributes[$object->table_element]['label'][$key]).' <span class="opacitymedium">('.$langs->trans("Maximum").')</span>',
146 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
147 'position' => ($position + ($count * 100000)).'.4',
148 'table' => $object->table_element,
149 'tablefromt' => $tablepath
150 );
151 $arrayofmesures[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-stddevpop'] = array(
152 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').$labelofobject.': '.$langs->trans($extrafields->attributes[$object->table_element]['label'][$key]).' <span class="opacitymedium">('.$langs->trans("StandardDeviationPop").')</span>',
153 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
154 'position' => ($position + ($count * 100000)).'.5',
155 'table' => $object->table_element,
156 'tablefromt' => $tablepath
157 );
158 }
159 }
160 }
161 // Add fields for parent objects
162 foreach ($object->fields as $key => $val) {
163 // Discard the linked objects of fields declared with attribute 'bi' set to 0 (field hidden on BI tool),
164 // so the sub element (the linked table) and all its sub fields are not added into the list
165 if (isset($val['bi']) && (int) $val['bi'] == 0) {
166 continue;
167 }
168 if (preg_match('/^[^:]+:[^:]+:/', $val['type'])) {
169 $tmptype = explode(':', $val['type'], 4);
170 if ($tmptype[0] == 'integer' && !empty($tmptype[1]) && !empty($tmptype[2])) {
171 $newobject = $tmptype[1];
172 dol_include_once($tmptype[2]);
173 if (class_exists($newobject)) {
174 $tmpobject = new $newobject($db);
175 //var_dump($key); var_dump($tmpobject->element); var_dump($val['label']); var_dump($tmptype); var_dump('t-'.$key);
176 $count++;
177 $tmptablepath = $tablepath; // Use a copy so the path of a sibling link is not appended to the path of the next one
178 $arrayofmesures = fillArrayOfMeasures($tmpobject, $tablealias.'__'.$key, ($level >= 1 ? $labelofobject.' - ' : '').$langs->trans($val['label']), $arrayofmesures, $level + 1, $count, $tmptablepath);
179 } else {
180 print 'For property '.$object->element.'->'.$key.', type="'.$val['type'].'": Failed to find class '.$newobject." in file ".$tmptype[2]."<br>\n";
181 }
182 }
183 }
184 }
185
186 return $arrayofmesures;
187}
188
189
202function fillArrayOfXAxis($object, $tablealias, $labelofobject, &$arrayofxaxis, $level = 0, &$count = 0, &$tablepath = '')
203{
204 global $langs, $extrafields, $db;
205
206 if (empty($object)) { // Protection against bad use of method
207 return array();
208 }
209 if ($level >= 3) { // Limit scan on 2 levels max
210 return $arrayofxaxis;
211 }
212
213 if (empty($tablepath)) {
214 $tablepath = $object->table_element.'='.$tablealias;
215 } else {
216 $tablepath .= ','.$object->table_element.'='.$tablealias;
217 }
218
219 $YYYY = substr($langs->trans("Year"), 0, 1).substr($langs->trans("Year"), 0, 1).substr($langs->trans("Year"), 0, 1).substr($langs->trans("Year"), 0, 1);
220 $MM = substr($langs->trans("Month"), 0, 1).substr($langs->trans("Month"), 0, 1);
221 $DD = substr($langs->trans("Day"), 0, 1).substr($langs->trans("Day"), 0, 1);
222 $HH = substr($langs->trans("Hour"), 0, 1).substr($langs->trans("Hour"), 0, 1);
223 $MI = substr($langs->trans("Minute"), 0, 1).substr($langs->trans("Minute"), 0, 1);
224 $SS = substr($langs->trans("Second"), 0, 1).substr($langs->trans("Second"), 0, 1);
225
226 /*if ($level > 0) {
227 var_dump($object->element.' '.$object->isextrafieldmanaged);
228 }*/
229
230 // Note: here $tablealias can be 't' or 't__fk_contract' or 't_fk_contract_fk_soc'
231
232 // Add main fields of object
233 foreach ($object->fields as $key => $val) {
234 // Discard the fields declared with attribute 'bi' set to 0 (field hidden on BI tool)
235 if (isset($val['bi']) && (int) $val['bi'] == 0) {
236 continue;
237 }
238 if (empty($val['measure'])) {
239 if (in_array($key, array(
240 'id', 'ref_ext', 'rowid', 'entity', 'last_main_doc', 'logo', 'logo_squarred', 'extraparams',
241 'parent', 'photo', 'socialnetworks', 'webservices_url', 'webservices_key'))) {
242 continue;
243 }
244 if (isset($val['enabled']) && ! (int) dol_eval((string) $val['enabled'], 1, 1, '1')) {
245 continue;
246 }
247 if (isset($val['visible']) && ! (int) dol_eval((string) $val['visible'], 1, 1, '1')) {
248 continue;
249 }
250 if (preg_match('/^fk_/', $key) && !preg_match('/^fk_statu/', $key)) {
251 continue;
252 }
253 if (preg_match('/^pass/', $key)) {
254 continue;
255 }
256 if (in_array($val['type'], array('html', 'text'))) {
257 continue;
258 }
259 if (in_array($val['type'], array('timestamp', 'date', 'datetime'))) {
260 $position = (empty($val['position']) ? 0 : intval($val['position']));
261 $arrayofxaxis[$tablealias.'.'.$key.'-year'] = array(
262 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$YYYY.')</span>',
263 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
264 'position' => ($position + ($count * 100000)).'.1',
265 'table' => $object->table_element,
266 'tablefromt' => $tablepath
267 );
268 $arrayofxaxis[$tablealias.'.'.$key.'-month'] = array(
269 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$YYYY.'-'.$MM.')</span>',
270 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
271 'position' => ($position + ($count * 100000)).'.2',
272 'table' => $object->table_element,
273 'tablefromt' => $tablepath
274 );
275 $arrayofxaxis[$tablealias.'.'.$key.'-day'] = array(
276 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$YYYY.'-'.$MM.'-'.$DD.')</span>',
277 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
278 'position' => ($position + ($count * 100000)).'.3',
279 'table' => $object->table_element,
280 'tablefromt' => $tablepath
281 );
282 } else {
283 $position = (empty($val['position']) ? 0 : intval($val['position']));
284 $arrayofxaxis[$tablealias.'.'.$key] = array(
285 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val['label']),
286 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
287 'position' => ($position + ($count * 100000)),
288 'table' => $object->table_element,
289 'tablefromt' => $tablepath
290 );
291 }
292 }
293 }
294
295 // Add extrafields to X-Axis
296 if (!empty($object->isextrafieldmanaged) && isset($extrafields->attributes[$object->table_element]['label'])) {
297 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
298 if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate') {
299 continue;
300 }
301 if (!empty($extrafields->attributes[$object->table_element]['totalizable'][$key])) {
302 continue;
303 }
304
305 if (in_array($extrafields->attributes[$object->table_element]['type'][$key], array('timestamp', 'date', 'datetime'))) {
306 $position = (empty($extrafields->attributes[$object->table_element]['pos'][$key]) ? 0 : intval($extrafields->attributes[$object->table_element]['pos'][$key]));
307 $arrayofxaxis[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-year'] = array(
308 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val).' <span class="opacitymedium">('.$YYYY.')</span>',
309 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
310 'position' => ($position + ($count * 100000)).'.1',
311 'table' => $object->table_element,
312 'tablefromt' => $tablepath
313 );
314 $arrayofxaxis[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-month'] = array(
315 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val).' <span class="opacitymedium">('.$YYYY.'-'.$MM.')</span>',
316 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
317 'position' => ($position + ($count * 100000)).'.2',
318 'table' => $object->table_element,
319 'tablefromt' => $tablepath
320 );
321 $arrayofxaxis[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-day'] = array(
322 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val).' <span class="opacitymedium">('.$YYYY.'-'.$MM.'-'.$DD.')</span>',
323 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
324 'position' => ($position + ($count * 100000)).'.3',
325 'table' => $object->table_element,
326 'tablefromt' => $tablepath
327 );
328 } else {
329 $arrayofxaxis[preg_replace('/^t/', 'te', $tablealias).'.'.$key] = array(
330 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val),
331 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
332 'position' => 1000 + (int) $extrafields->attributes[$object->table_element]['pos'][$key] + ($count * 100000),
333 'table' => $object->table_element,
334 'tablefromt' => $tablepath
335 );
336 }
337 }
338 }
339
340 // Add fields for parent objects
341 foreach ($object->fields as $key => $val) {
342 // Discard the linked objects of fields declared with attribute 'bi' set to 0 (field hidden on BI tool),
343 // so the sub element (the linked table) and all its sub fields are not added into the list
344 if (isset($val['bi']) && (int) $val['bi'] == 0) {
345 continue;
346 }
347 if (preg_match('/^[^:]+:[^:]+:/', $val['type'])) {
348 $tmptype = explode(':', $val['type'], 4);
349 if ($tmptype[0] == 'integer' && $tmptype[1] && $tmptype[2]) {
350 $newobject = $tmptype[1];
351 dol_include_once($tmptype[2]);
352 if (class_exists($newobject)) {
353 $tmpobject = new $newobject($db);
354 //var_dump($key); var_dump($tmpobject->element); var_dump($val['label']); var_dump($tmptype); var_dump('t-'.$key);
355 $count++;
356 $tmptablepath = $tablepath; // Use a copy so the path of a sibling link is not appended to the path of the next one
357 $arrayofxaxis = fillArrayOfXAxis($tmpobject, $tablealias.'__'.$key, ($level >= 1 ? $labelofobject.' - ' : '').$langs->trans($val['label']), $arrayofxaxis, $level + 1, $count, $tmptablepath);
358 } else {
359 print 'For property '.$object->element.'->'.$key.', type="'.$val['type'].'": Failed to find class '.$newobject." in file ".$tmptype[2]."<br>\n";
360 }
361 }
362 }
363 }
364
365 return $arrayofxaxis;
366}
367
368
381function fillArrayOfGroupBy($object, $tablealias, $labelofobject, &$arrayofgroupby, $level = 0, &$count = 0, &$tablepath = '')
382{
383 global $langs, $extrafields, $db;
384
385 if (empty($object)) { // Protection against bad use of method
386 return array();
387 }
388 if ($level >= 3) {
389 return $arrayofgroupby;
390 }
391
392 if (empty($tablepath)) {
393 $tablepath = $object->table_element.'='.$tablealias;
394 } else {
395 $tablepath .= ','.$object->table_element.'='.$tablealias;
396 }
397
398 $YYYY = substr($langs->trans("Year"), 0, 1).substr($langs->trans("Year"), 0, 1).substr($langs->trans("Year"), 0, 1).substr($langs->trans("Year"), 0, 1);
399 $MM = substr($langs->trans("Month"), 0, 1).substr($langs->trans("Month"), 0, 1);
400 $DD = substr($langs->trans("Day"), 0, 1).substr($langs->trans("Day"), 0, 1);
401 $HH = substr($langs->trans("Hour"), 0, 1).substr($langs->trans("Hour"), 0, 1);
402 $MI = substr($langs->trans("Minute"), 0, 1).substr($langs->trans("Minute"), 0, 1);
403 $SS = substr($langs->trans("Second"), 0, 1).substr($langs->trans("Second"), 0, 1);
404
405 // Note: here $tablealias can be 't' or 't__fk_contract' or 't_fk_contract_fk_soc'
406
407 // Add main fields of object
408 foreach ($object->fields as $key => $val) {
409 // Discard the fields declared with attribute 'bi' set to 0 (field hidden on BI tool)
410 if (isset($val['bi']) && (int) $val['bi'] == 0) {
411 continue;
412 }
413 if (empty($val['isameasure'])) {
414 if (in_array($key, array(
415 'id', 'ref_ext', 'rowid', 'entity', 'last_main_doc', 'logo', 'logo_squarred', 'extraparams',
416 'parent', 'photo', 'socialnetworks', 'webservices_url', 'webservices_key'))) {
417 continue;
418 }
419 if (isset($val['enabled']) && ! (int) dol_eval((string) $val['enabled'], 1, 1, '1')) {
420 continue;
421 }
422 if (isset($val['visible']) && ! (int) dol_eval((string) $val['visible'], 1, 1, '1')) {
423 continue;
424 }
425 if (preg_match('/^fk_/', $key) && !preg_match('/^fk_statu/', $key)) {
426 continue;
427 }
428 if (preg_match('/^pass/', $key)) {
429 continue;
430 }
431 if (in_array($val['type'], array('html', 'text'))) {
432 continue;
433 }
434 if (in_array($val['type'], array('timestamp', 'date', 'datetime'))) {
435 $position = (empty($val['position']) ? 0 : intval($val['position']));
436 $arrayofgroupby[$tablealias.'.'.$key.'-year'] = array(
437 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$YYYY.')</span>', // @phan-suppress-current-line PhanUndeclaredProperty
438 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
439 'position' => ($position + ($count * 100000)).'.1',
440 'table' => $object->table_element,
441 'tablefromt' => $tablepath
442 );
443 $arrayofgroupby[$tablealias.'.'.$key.'-month'] = array(
444 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$YYYY.'-'.$MM.')</span>', // @phan-suppress-current-line PhanUndeclaredProperty
445 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
446 'position' => ($position + ($count * 100000)).'.2',
447 'table' => $object->table_element,
448 'tablefromt' => $tablepath
449 );
450 $arrayofgroupby[$tablealias.'.'.$key.'-day'] = array(
451 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$YYYY.'-'.$MM.'-'.$DD.')</span>', // @phan-suppress-current-line PhanUndeclaredProperty
452 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
453 'position' => ($position + ($count * 100000)).'.3',
454 'table' => $object->table_element,
455 'tablefromt' => $tablepath
456 );
457 } else {
458 $position = (empty($val['position']) ? 0 : intval($val['position']));
459 $arrayofgroupby[$tablealias.'.'.$key] = array(
460 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val['label']), // @phan-suppress-current-line PhanUndeclaredProperty
461 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
462 'position' => ($position + ($count * 100000)),
463 'table' => $object->table_element,
464 'tablefromt' => $tablepath
465 );
466 }
467 }
468 }
469
470 // Add extrafields to Group by
471 if (!empty($object->isextrafieldmanaged) && isset($extrafields->attributes[$object->table_element]['label'])) {
472 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
473 if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate') {
474 continue;
475 }
476 if (!empty($extrafields->attributes[$object->table_element]['totalizable'][$key])) {
477 continue;
478 }
479
480 if (in_array($extrafields->attributes[$object->table_element]['type'][$key], array('timestamp', 'date', 'datetime'))) {
481 $position = (empty($extrafields->attributes[$object->table_element]['pos'][$key]) ? 0 : intval($extrafields->attributes[$object->table_element]['pos'][$key]));
482 $arrayofgroupby[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-year'] = array(
483 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val).' <span class="opacitymedium">('.$YYYY.')</span>', // @phan-suppress-current-line PhanUndeclaredProperty
484 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
485 'position' => ($position + ($count * 100000)).'.1',
486 'table' => $object->table_element,
487 'tablefromt' => $tablepath
488 );
489 $arrayofgroupby[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-month'] = array(
490 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val).' <span class="opacitymedium">('.$YYYY.'-'.$MM.')</span>', // @phan-suppress-current-line PhanUndeclaredProperty
491 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
492 'position' => ($position + ($count * 100000)).'.2',
493 'table' => $object->table_element,
494 'tablefromt' => $tablepath
495 );
496 $arrayofgroupby[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-day'] = array(
497 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val).' <span class="opacitymedium">('.$YYYY.'-'.$MM.'-'.$DD.')</span>', // @phan-suppress-current-line PhanUndeclaredProperty
498 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
499 'position' => ($position + ($count * 100000)).'.3',
500 'table' => $object->table_element,
501 'tablefromt' => $tablepath
502 );
503 } else {
504 $arrayofgroupby[preg_replace('/^t/', 'te', $tablealias).'.'.$key] = array(
505 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val), // @phan-suppress-current-line PhanUndeclaredProperty
506 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
507 'position' => 1000 + (int) $extrafields->attributes[$object->table_element]['pos'][$key] + ($count * 100000),
508 'table' => $object->table_element,
509 'tablefromt' => $tablepath
510 );
511 }
512 }
513 }
514
515 // Add fields for parent objects
516 foreach ($object->fields as $key => $val) {
517 // Discard the linked objects of fields declared with attribute 'bi' set to 0 (field hidden on BI tool),
518 // so the sub element (the linked table) and all its sub fields are not added into the list
519 if (isset($val['bi']) && (int) $val['bi'] == 0) {
520 continue;
521 }
522 if (preg_match('/^[^:]+:[^:]+:/', $val['type'])) {
523 $tmptype = explode(':', $val['type'], 4);
524 if ($tmptype[0] == 'integer' && $tmptype[1] && $tmptype[2]) {
525 $newobject = $tmptype[1];
526 dol_include_once($tmptype[2]);
527 if (class_exists($newobject)) {
528 $tmpobject = new $newobject($db);
529 //var_dump($key); var_dump($tmpobject->element); var_dump($val['label']); var_dump($tmptype); var_dump('t-'.$key);
530 $count++;
531 $tmptablepath = $tablepath; // Use a copy so the path of a sibling link is not appended to the path of the next one
532 $arrayofgroupby = fillArrayOfGroupBy($tmpobject, $tablealias.'__'.$key, ($level >= 1 ? $labelofobject.' - ' : '').$langs->trans($val['label']), $arrayofgroupby, $level + 1, $count, $tmptablepath);
533 } else {
534 print 'For property '.$object->element.'->'.$key.', type="'.$val['type'].'": Failed to find class '.$newobject." in file ".$tmptype[2]."<br>\n";
535 }
536 }
537 }
538 }
539
540 return $arrayofgroupby;
541}
542
543
556function fillArrayOfFilterFields($object, $tablealias, $labelofobject, &$arrayoffields, $level = 0, &$count = 0, &$tablepath = '')
557{
558 global $langs, $extrafields, $db;
559
560 $MAXLEVEL = 2;
561
562 if (empty($object)) { // Protection against bad use of method
563 return array();
564 }
565 if ($level > $MAXLEVEL) { // Limit scan on 2 levels max
566 return $arrayoffields;
567 }
568
569 if (empty($tablepath)) {
570 $tablepath = $object->table_element.'='.$tablealias;
571 } else {
572 $tablepath .= ','.$object->table_element.'='.$tablealias;
573 }
574
575 // Note: here $tablealias can be 't' or 't__fk_contract' or 't_fk_contract_fk_soc'
576
577 // Add main fields of object
578 foreach ($object->fields as $key => $val) {
579 if (empty($val['measure'])) {
580 // Exclude some fields
581 if (in_array($key, array(
582 'id', 'ref_ext', 'rowid', 'entity', 'last_main_doc', 'logo', 'logo_squarred', 'extraparams',
583 'parent', 'pass', 'pass_crypted', 'pass_temp', 'photo', 'socialnetworks', 'webservices_url', 'webservices_key'))) {
584 continue;
585 }
586 if (isset($val['enabled']) && ! (int) dol_eval((string) $val['enabled'], 1, 1, '1')) {
587 continue;
588 }
589 if (isset($val['visible']) && ! (int) dol_eval((string) $val['visible'], 1, 1, '1')) {
590 continue;
591 }
592 if (preg_match('/^fk_/', $key) && !preg_match('/^fk_statu/', $key)) {
593 continue;
594 }
595 if (preg_match('/^pass/', $key)) {
596 continue;
597 }
598 if (in_array($val['type'], array('html', 'text'))) {
599 continue;
600 }
601
602 $position = (empty($val['position']) ? 0 : intval($val['position']));
603 $arrayoffields[$tablealias.'.'.$key] = array(
604 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val['label']), // @phan-suppress-current-line PhanUndeclaredProperty
605 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
606 'position' => ($position + ($count * 100000)),
607 'table' => $object->table_element,
608 'tablefromt' => $tablepath,
609 'type' => $val['type']
610 );
611 if (!empty($val['arrayofkeyval'])) {
612 $arrayoffields[$tablealias.'.'.$key]['arrayofkeyval'] = $val['arrayofkeyval'];
613 }
614 if ((!isset($val['isamesaure']) || $val['isamesaure'] != 1) && (!isset($val['notnull']) || $val['notnull'] != '1')) {
615 $arrayoffields[$tablealias.'.'.$key]['maybenull'] = 1;
616 }
617 // Keep the attribute 'bi' of the field so the search component can discard the fields hidden on BI tool
618 if (isset($val['bi'])) {
619 $arrayoffields[$tablealias.'.'.$key]['bi'] = (int) $val['bi'];
620 }
621 }
622 }
623
624 // Add extrafields to fields
625 if (!empty($object->isextrafieldmanaged) && isset($extrafields->attributes[$object->table_element]['label'])) {
626 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
627 if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate') {
628 continue;
629 }
630 if (!empty($extrafields->attributes[$object->table_element]['totalizable'][$key])) {
631 continue;
632 }
633
634 $arrayoffields[preg_replace('/^t/', 'te', $tablealias).'.'.$key] = array(
635 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val), // @phan-suppress-current-line PhanUndeclaredProperty
636 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
637 'position' => 1000 + (int) $extrafields->attributes[$object->table_element]['pos'][$key] + ($count * 100000),
638 'table' => $object->table_element,
639 'tablefromt' => $tablepath,
640 'type' => $extrafields->attributes[$object->table_element]['type'][$key],
641 );
642 }
643 }
644
645 // Add fields for parent objects
646 foreach ($object->fields as $key => $val) {
647 // Discard the linked objects of fields declared with attribute 'bi' set to 0 (field hidden on BI tool),
648 // so the sub element (the linked table) and all its sub fields are not added into the list
649 if (isset($val['bi']) && (int) $val['bi'] == 0) {
650 continue;
651 }
652 if (preg_match('/^[^:]+:[^:]+:/', $val['type'])) {
653 $tmptype = explode(':', $val['type'], 4);
654 if ($tmptype[0] == 'integer' && $tmptype[1] && $tmptype[2]) {
655 $newobject = $tmptype[1];
656 dol_include_once($tmptype[2]);
657 if (class_exists($newobject)) {
658 $tmpobject = new $newobject($db);
659 $count++;
660 if (!empty($val['nodepth'])) {
661 $tmptablepath = $tablepath; // Use a copy so the path of a sibling link is not appended to the path of the next one
662 $arrayoffields = fillArrayOfFilterFields($tmpobject, $tablealias.'__'.$key, ($level >= 1 ? $labelofobject.' - ' : '').$langs->trans($val['label']), $arrayoffields, $MAXLEVEL, $count, $tmptablepath);
663 } else {
664 $tmptablepath = $tablepath; // Use a copy so the path of a sibling link is not appended to the path of the next one
665 $arrayoffields = fillArrayOfFilterFields($tmpobject, $tablealias.'__'.$key, ($level >= 1 ? $labelofobject.' - ' : '').$langs->trans($val['label']), $arrayoffields, $level + 1, $count, $tmptablepath);
666 }
667 } else {
668 print 'For property '.$object->element.'->'.$key.', type="'.$val['type'].'": Failed to find class '.$newobject." in file ".$tmptype[2]."<br>\n";
669 }
670 }
671 }
672 }
673
674 return $arrayoffields;
675}
676
677
689function customReportsSelectMeasures($htmlname, $arrayofmesures, $selected, $placeholder = '')
690{
691 global $conf, $langs;
692
693 $variantlabels = array(
694 'sum' => $langs->trans("Sum"),
695 'average' => $langs->trans("Average"),
696 'min' => $langs->trans("Minimum"),
697 'max' => $langs->trans("Maximum"),
698 'stddevpop' => $langs->trans("StandardDeviationPop"),
699 );
700
701 // Group measures by field. Keys of variants are 'alias.field-variant'.
702 $groups = array();
703 foreach ($arrayofmesures as $key => $val) {
704 $reg = array();
705 if (preg_match('/^(.+)-(sum|average|min|max|stddevpop)$/', $key, $reg)) {
706 $groupkey = $reg[1];
707 $variant = $reg[2];
708 } else {
709 $groupkey = $key;
710 $variant = '';
711 }
712 if (!isset($groups[$groupkey])) {
713 // The label is the picto of the object followed by the labelnohtml (and the variant suffix), so we extract the picto
714 $picto = '';
715 $pos = strpos($val['label'], $val['labelnohtml']);
716 if ($pos !== false) {
717 $picto = substr($val['label'], 0, $pos);
718 }
719 $groups[$groupkey] = array(
720 'picto' => $picto,
721 'labelnohtml' => $val['labelnohtml'],
722 'variants' => array()
723 );
724 }
725 $groups[$groupkey]['variants'][$key] = ($variant ? $variantlabels[$variant] : '');
726 }
727
728 $out = '<div class="customreportsmeasures divadvancedsearchfieldcompinput inline-block minwidth300 maxwidth500" id="'.dol_escape_htmltag($htmlname).'_component" data-htmlname="'.dol_escape_htmltag($htmlname).'">';
729
730 // Hidden select used to post values
731 $out .= '<select id="'.dol_escape_htmltag($htmlname).'" name="'.dol_escape_htmltag($htmlname).'[]" multiple class="hideobject">';
732 foreach ($arrayofmesures as $key => $val) {
733 $out .= '<option value="'.dol_escape_htmltag($key).'"'.(in_array($key, $selected) ? ' selected' : '').'>'.dol_escape_htmltag($val['labelnohtml']).'</option>';
734 }
735 $out .= '</select>';
736
737 // Visible area with tags of selected measures
738 $out .= '<div class="customreportsmeasures-control noborderbottom search_component_params inline-block" tabindex="0" role="combobox" aria-expanded="false" aria-haspopup="listbox">';
739 $out .= '<span class="customreportsmeasures-tags"></span>';
740 $out .= '<span class="customreportsmeasures-placeholder opacitymedium">'.dol_escape_htmltag($placeholder).'</span>';
741 $out .= '<span class="fas fa-caret-down customreportsmeasures-caret"></span>';
742 $out .= '</div>';
743
744 // Dropdown with list of fields then variants
745 $out .= '<div class="customreportsmeasures-dropdown hidden">';
746 $out .= '<div class="liinputsearch"><input type="text" class="customreportsmeasures-search noborderfocus" placeholder="'.dol_escape_htmltag($langs->trans("Search")).'" autocomplete="off"></div>';
747 $out .= '<ul class="customreportsmeasures-list" role="listbox">';
748 foreach ($groups as $groupkey => $group) {
749 $hasvariants = (count($group['variants']) > 1 || key($group['variants']) != $groupkey);
750 $out .= '<li class="customreportsmeasures-field'.($hasvariants ? ' customreportsmeasures-hasvariants' : '').'" data-search="'.dol_escape_htmltag(dol_strtolower($group['labelnohtml'])).'">';
751 if ($hasvariants) {
752 $out .= '<div class="customreportsmeasures-fieldlabel">';
753 $out .= '<span class="customreportsmeasures-text">'.$group['picto'].dol_escape_htmltag($group['labelnohtml']).'</span>';
754 $out .= '<span class="customreportsmeasures-count badge badge-secondary hidden"></span>';
755 $out .= '<span class="fas fa-caret-right customreportsmeasures-expand"></span>';
756 $out .= '</div>';
757 $out .= '<ul class="customreportsmeasures-variants hidden">';
758 foreach ($group['variants'] as $key => $variantlabel) {
759 $out .= '<li class="customreportsmeasures-item" role="option" data-value="'.dol_escape_htmltag($key).'" data-tag="'.dol_escape_htmltag($group['labelnohtml'].' ('.$variantlabel.')').'">';
760 $out .= '<span class="customreportsmeasures-text">'.dol_escape_htmltag($variantlabel).'</span>';
761 $out .= '<span class="fas fa-check customreportsmeasures-check"></span>';
762 $out .= '</li>';
763 }
764 $out .= '</ul>';
765 } else {
766 $out .= '<div class="customreportsmeasures-fieldlabel customreportsmeasures-item" role="option" data-value="'.dol_escape_htmltag($groupkey).'" data-tag="'.dol_escape_htmltag($group['labelnohtml']).'">';
767 $out .= '<span class="customreportsmeasures-text">'.$group['picto'].dol_escape_htmltag($group['labelnohtml']).'</span>';
768 $out .= '<span class="fas fa-check customreportsmeasures-check"></span>';
769 $out .= '</div>';
770 }
771 $out .= '</li>';
772 }
773 $out .= '</ul>';
774 $out .= '</div>';
775
776 $out .= '</div>';
777
778 if (empty($conf->cache['customreportsjsloaded'])) {
779 $out .= '<script nonce="'.getNonce().'" src="'.DOL_URL_ROOT.'/core/js/customreports.js"></script>';
780 $conf->cache['customreportsjsloaded'] = 1;
781 }
782 $out .= '<script nonce="'.getNonce().'">jQuery(document).ready(function() { initCustomReportsMeasures(\''.dol_escape_js($htmlname).'_component\'); });</script>';
783
784 return $out;
785}
786
787
800function customReportsSelectFieldCombo($htmlname, $arrayoffields, $selected, $placeholder = '', $allowclear = 0)
801{
802 global $conf, $langs;
803
804 $selectedkey = (is_array($selected) && count($selected)) ? (string) reset($selected) : '';
805 $selectedlabel = '';
806 $variantlabels = array('year' => $langs->trans("Year"), 'month' => $langs->trans("Year").' - '.$langs->trans("Month"), 'day' => $langs->trans("Year").' - '.$langs->trans("Month").' - '.$langs->trans("Day"));
807 $selectedtitle = ''; // Full label of the selected field, shown as a tooltip because the label may be truncated
808
809 // Group fields by element. The element is the part of the key before the last dot ('t.ref' -> 't'), extrafields 'te...' are mapped onto 't...'.
810 $elements = array();
811 foreach ($arrayoffields as $key => $val) {
812 $elementkey = preg_replace('/^te(__|$)/', 't$1', preg_replace('/\.[^.]*$/', '', $key));
813 // The labelnohtml is 'LabelOfElement: LabelOfField' and the label is 'picto LabelOfElement: LabelOfField <span>(variant)</span>'
814 $elementlabel = $elementkey;
815 $reg = array();
816 if (preg_match('/^(.+?): /', $val['labelnohtml'], $reg)) {
817 $elementlabel = $reg[1];
818 }
819 $picto = '';
820 $fieldlabel = $val['labelnohtml'];
821 $pos = strpos($val['label'], $val['labelnohtml']);
822 if ($pos !== false) {
823 $picto = trim(substr($val['label'], 0, $pos));
824 $fieldlabel = trim(dol_string_nohtmltag(substr($val['label'], $pos + ($elementlabel != $elementkey ? strlen($elementlabel) + 2 : 0))));
825 }
826 if (!isset($elements[$elementkey])) {
827 $elements[$elementkey] = array('picto' => $picto, 'label' => $elementlabel, 'fields' => array(), 'datefields' => array());
828 }
829 $elements[$elementkey]['fields'][$key] = $fieldlabel;
830 // Variants of a date field ('alias.field-year', '-month', '-day') are grouped under one row of the date field
831 if (preg_match('/^(.+)-(year|month|day)$/', $key, $reg)) {
832 $regformat = array();
833 $format = (preg_match('/(\‍([^()]*\‍))\s*<\/span>\s*$/', $val['label'], $regformat) ? ' '.$regformat[1] : '');
834 $elements[$elementkey]['datefields'][$reg[1]]['label'] = ($elementlabel != $elementkey ? substr($val['labelnohtml'], strlen($elementlabel) + 2) : $val['labelnohtml']);
835 $elements[$elementkey]['datefields'][$reg[1]]['variants'][$key] = $variantlabels[$reg[2]].$format;
836 }
837 if ($key === $selectedkey) {
838 $selectedlabel = $picto.' '.dol_escape_htmltag($elementlabel.': '.$fieldlabel);
839 $selectedtitle = $elementlabel.': '.$fieldlabel;
840 }
841 }
842
843 $out = '<div class="customreportscombo divadvancedsearchfieldcompinput" id="'.dol_escape_htmltag($htmlname).'_component">';
844 $out .= '<input type="hidden" id="'.dol_escape_htmltag($htmlname).'" name="'.dol_escape_htmltag($htmlname).'" value="'.dol_escape_htmltag($selectedlabel ? $selectedkey : '').'">';
845 $out .= '<button type="button" class="customreportscombo-toggle noborderbottom search_component_params minwidth300">';
846 $out .= '<span class="customreportscombo-label'.($selectedlabel ? '' : ' opacitymedium').'"'.($selectedtitle ? ' title="'.dolPrintHTMLForAttribute($selectedtitle).'"' : '').' data-placeholder="'.dol_escape_htmltag($placeholder).'">'.($selectedlabel ? $selectedlabel : dol_escape_htmltag($placeholder)).'</span>';
847 if ($allowclear) {
848 $out .= '<span class="fas fa-times customreportscombo-clear'.($selectedlabel ? '' : ' hideobject').'" title="'.dol_escape_htmltag($langs->trans('Reset')).'"></span>';
849 }
850 $out .= '<span class="fas fa-caret-down customreportscombo-caret"></span>';
851 $out .= '</button>';
852 $out .= '<div class="customreportscombo-panel" style="display:none">';
853 $out .= '<div class="liinputsearch"><input type="text" class="customreportscombo-search noborderfocus" placeholder="'.dol_escape_htmltag($langs->trans('Search')).'" autocomplete="off"></div>';
854 $out .= '<div class="customreportscombo-list">';
855
856 // Recursive rendering of an element: its fields first, then its sub-elements (a direct sub-element of 't' is 't__xxx' without other '__' after)
861 $renderElement = function (string $elementkey) use ($elements, $selectedkey, &$renderElement): string {
862 $element = $elements[$elementkey];
863 $out = '<div class="customreportscombo-element" data-element="'.dol_escape_htmltag($elementkey).'">';
864 $out .= '<div class="customreportscombo-elementheader" tabindex="0"><span class="customreportscombo-elementlabel">'.$element['picto'].' '.dol_escape_htmltag($element['label']).'</span><span class="fas fa-caret-right customreportscombo-elementcaret"></span></div>';
865 $out .= '<div class="customreportscombo-fields" style="display:none">';
866 foreach ($element['fields'] as $fieldkey => $fieldlabel) {
867 $reg = array();
868 if (preg_match('/^(.+)-(year|month|day)$/', $fieldkey, $reg) && isset($element['datefields'][$reg[1]])) {
869 // A date field is shown once, with a caret to expand its variants (by year, by month, by day)
870 if (empty($element['datefields'][$reg[1]]['variants'])) {
871 continue; // Already rendered with the first variant
872 }
873 $out .= '<div class="customreportscombo-datefield">';
874 $out .= '<div class="customreportscombo-datefieldheader" tabindex="0"><span>'.dol_escape_htmltag($element['datefields'][$reg[1]]['label']).'</span><span class="fas fa-caret-right customreportscombo-datefieldcaret"></span></div>';
875 $out .= '<div class="customreportscombo-variants" style="display:none">';
876 foreach ($element['datefields'][$reg[1]]['variants'] as $variantkey => $variantlabel) {
877 $out .= '<div class="customreportscombo-field'.($variantkey === $selectedkey ? ' selected' : '').'" tabindex="0" data-field="'.dol_escape_htmltag($variantkey).'" data-label="'.dol_escape_htmltag($element['fields'][$variantkey]).'">'.dol_escape_htmltag($variantlabel).'</div>';
878 }
879 $out .= '</div>';
880 $out .= '</div>';
881 $element['datefields'][$reg[1]]['variants'] = array();
882 continue;
883 }
884 $out .= '<div class="customreportscombo-field'.($fieldkey === $selectedkey ? ' selected' : '').'" tabindex="0" data-field="'.dol_escape_htmltag($fieldkey).'">'.dol_escape_htmltag($fieldlabel).'</div>';
885 }
886 $out .= '</div>';
887 $children = '';
888 foreach (array_keys($elements) as $childkey) {
889 if (strpos($childkey, $elementkey.'__') === 0 && strpos(substr($childkey, strlen($elementkey) + 2), '__') === false) {
890 $children .= $renderElement($childkey);
891 }
892 }
893 if ($children) {
894 $out .= '<div class="customreportscombo-children" style="display:none">'.$children.'</div>';
895 }
896 $out .= '</div>';
897 return $out;
898 };
899 // At root level, we render only the elements without parent element (or with a parent not found)
900 foreach (array_keys($elements) as $elementkey) {
901 $parentkey = (strpos($elementkey, '__') !== false) ? substr($elementkey, 0, strrpos($elementkey, '__')) : '';
902 if ($parentkey == '' || !isset($elements[$parentkey])) {
903 $out .= $renderElement($elementkey);
904 }
905 }
906
907 $out .= '</div>';
908 $out .= '</div>';
909 $out .= '</div>';
910
911 if (empty($conf->cache['customreportsjsloaded'])) {
912 $out .= '<script nonce="'.getNonce().'" src="'.DOL_URL_ROOT.'/core/js/customreports.js"></script>';
913 $conf->cache['customreportsjsloaded'] = 1;
914 }
915 $out .= '<script nonce="'.getNonce().'">jQuery(document).ready(function() { initCustomReportsCombo(\''.dol_escape_js($htmlname).'_component\'); });</script>';
916
917 return $out;
918}
919
920
930function customReportsSelectXAxis($htmlname, $arrayofxaxis, $selected, $placeholder = '')
931{
932 return customReportsSelectFieldCombo($htmlname, $arrayofxaxis, $selected, $placeholder, 0);
933}
934
935
945function customReportsSelectGroupBy($htmlname, $arrayofgroupby, $selected, $placeholder = '')
946{
947 return customReportsSelectFieldCombo($htmlname, $arrayofgroupby, $selected, $placeholder, 1);
948}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
fillArrayOfGroupBy($object, $tablealias, $labelofobject, &$arrayofgroupby, $level=0, &$count=0, &$tablepath='')
Fill arrayofgroupby for an object.
fillArrayOfFilterFields($object, $tablealias, $labelofobject, &$arrayoffields, $level=0, &$count=0, &$tablepath='')
Fill array of possible filter fields for an object.
customReportsSelectGroupBy($htmlname, $arrayofgroupby, $selected, $placeholder='')
Return HTML of the combo to select the group by field (see customReportsSelectFieldCombo()).
customReportsSelectMeasures($htmlname, $arrayofmesures, $selected, $placeholder='')
Return HTML of the component to select measures.
fillArrayOfMeasures($object, $tablealias, $labelofobject, &$arrayofmesures, $level=0, &$count=0, &$tablepath='')
Fill arrayofmesures for an object.
customReportsSelectXAxis($htmlname, $arrayofxaxis, $selected, $placeholder='')
Return HTML of the combo to select the X axis (see customReportsSelectFieldCombo())
customReportsSelectFieldCombo($htmlname, $arrayoffields, $selected, $placeholder='', $allowclear=0)
Return HTML of a combo to select one field (X axis, group by...).
fillArrayOfXAxis($object, $tablealias, $labelofobject, &$arrayofxaxis, $level=0, &$count=0, &$tablepath='')
Fill arrayofmesures for an object.
dol_strtolower($string, $encoding="UTF-8")
Convert a string to lower.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into JavaScript code.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183