dolibarr 23.0.3
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 > 10) { // Protection against infinite loop
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 if (!empty($val['isameasure']) && (!isset($val['enabled']) || (int) dol_eval((string) $val['enabled'], 1, 1, '1'))) {
72 $position = (empty($val['position']) ? 0 : intval($val['position']));
73 $arrayofmesures[$tablealias.'.'.$key.'-sum'] = array(
74 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$langs->trans("Sum").')</span>',
75 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
76 'position' => ($position + ($count * 100000)).'.1',
77 'table' => $object->table_element,
78 'tablefromt' => $tablepath
79 );
80 $arrayofmesures[$tablealias.'.'.$key.'-average'] = array(
81 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$langs->trans("Average").')</span>',
82 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
83 'position' => ($position + ($count * 100000)).'.2',
84 'table' => $object->table_element,
85 'tablefromt' => $tablepath
86 );
87 $arrayofmesures[$tablealias.'.'.$key.'-min'] = array(
88 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$langs->trans("Minimum").')</span>',
89 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
90 'position' => ($position + ($count * 100000)).'.3',
91 'table' => $object->table_element,
92 'tablefromt' => $tablepath
93 );
94 $arrayofmesures[$tablealias.'.'.$key.'-max'] = array(
95 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$langs->trans("Maximum").')</span>',
96 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
97 'position' => ($position + ($count * 100000)).'.4',
98 'table' => $object->table_element,
99 'tablefromt' => $tablepath
100 );
101 $arrayofmesures[$tablealias.'.'.$key.'-stddevpop'] = array(
102 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$langs->trans("StandardDeviationPop").')</span>',
103 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
104 'position' => ($position + ($count * 100000)).'.5',
105 'table' => $object->table_element,
106 'tablefromt' => $tablepath
107 );
108 }
109 }
110 // Add extrafields to Measures
111 if (!empty($object->isextrafieldmanaged) && isset($extrafields->attributes[$object->table_element]['label'])) {
112 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
113 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'))) {
114 if (isset($extrafields->attributes[$object->table_element]['pos'][$key])) {
115 $position = $extrafields->attributes[$object->table_element]['pos'][$key];
116 } else {
117 $position = 0;
118 }
119 $arrayofmesures[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-sum'] = array(
120 '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>',
121 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
122 'position' => ($position + ($count * 100000)).'.1',
123 'table' => $object->table_element,
124 'tablefromt' => $tablepath
125 );
126 $arrayofmesures[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-average'] = array(
127 '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>',
128 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
129 'position' => ($position + ($count * 100000)).'.2',
130 'table' => $object->table_element,
131 'tablefromt' => $tablepath
132 );
133 $arrayofmesures[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-min'] = array(
134 '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>',
135 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
136 'position' => ($position + ($count * 100000)).'.3',
137 'table' => $object->table_element,
138 'tablefromt' => $tablepath
139 );
140 $arrayofmesures[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-max'] = array(
141 '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>',
142 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
143 'position' => ($position + ($count * 100000)).'.4',
144 'table' => $object->table_element,
145 'tablefromt' => $tablepath
146 );
147 $arrayofmesures[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-stddevpop'] = array(
148 '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>',
149 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
150 'position' => ($position + ($count * 100000)).'.5',
151 'table' => $object->table_element,
152 'tablefromt' => $tablepath
153 );
154 }
155 }
156 }
157 // Add fields for parent objects
158 foreach ($object->fields as $key => $val) {
159 if (preg_match('/^[^:]+:[^:]+:/', $val['type'])) {
160 $tmptype = explode(':', $val['type'], 4);
161 if ($tmptype[0] == 'integer' && !empty($tmptype[1]) && !empty($tmptype[2])) {
162 $newobject = $tmptype[1];
163 dol_include_once($tmptype[2]);
164 if (class_exists($newobject)) {
165 $tmpobject = new $newobject($db);
166 //var_dump($key); var_dump($tmpobject->element); var_dump($val['label']); var_dump($tmptype); var_dump('t-'.$key);
167 $count++;
168 $arrayofmesures = fillArrayOfMeasures($tmpobject, $tablealias.'__'.$key, $langs->trans($val['label']), $arrayofmesures, $level + 1, $count, $tablepath);
169 } else {
170 print 'For property '.$object->element.'->'.$key.', type="'.$val['type'].'": Failed to find class '.$newobject." in file ".$tmptype[2]."<br>\n";
171 }
172 }
173 }
174 }
175
176 return $arrayofmesures;
177}
178
179
192function fillArrayOfXAxis($object, $tablealias, $labelofobject, &$arrayofxaxis, $level = 0, &$count = 0, &$tablepath = '')
193{
194 global $langs, $extrafields, $db;
195
196 if (empty($object)) { // Protection against bad use of method
197 return array();
198 }
199 if ($level >= 3) { // Limit scan on 2 levels max
200 return $arrayofxaxis;
201 }
202
203 if (empty($tablepath)) {
204 $tablepath = $object->table_element.'='.$tablealias;
205 } else {
206 $tablepath .= ','.$object->table_element.'='.$tablealias;
207 }
208
209 $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);
210 $MM = substr($langs->trans("Month"), 0, 1).substr($langs->trans("Month"), 0, 1);
211 $DD = substr($langs->trans("Day"), 0, 1).substr($langs->trans("Day"), 0, 1);
212 $HH = substr($langs->trans("Hour"), 0, 1).substr($langs->trans("Hour"), 0, 1);
213 $MI = substr($langs->trans("Minute"), 0, 1).substr($langs->trans("Minute"), 0, 1);
214 $SS = substr($langs->trans("Second"), 0, 1).substr($langs->trans("Second"), 0, 1);
215
216 /*if ($level > 0) {
217 var_dump($object->element.' '.$object->isextrafieldmanaged);
218 }*/
219
220 // Note: here $tablealias can be 't' or 't__fk_contract' or 't_fk_contract_fk_soc'
221
222 // Add main fields of object
223 foreach ($object->fields as $key => $val) {
224 if (empty($val['measure'])) {
225 if (in_array($key, array(
226 'id', 'ref_ext', 'rowid', 'entity', 'last_main_doc', 'logo', 'logo_squarred', 'extraparams',
227 'parent', 'photo', 'socialnetworks', 'webservices_url', 'webservices_key'))) {
228 continue;
229 }
230 if (isset($val['enabled']) && ! (int) dol_eval((string) $val['enabled'], 1, 1, '1')) {
231 continue;
232 }
233 if (isset($val['visible']) && ! (int) dol_eval((string) $val['visible'], 1, 1, '1')) {
234 continue;
235 }
236 if (preg_match('/^fk_/', $key) && !preg_match('/^fk_statu/', $key)) {
237 continue;
238 }
239 if (preg_match('/^pass/', $key)) {
240 continue;
241 }
242 if (in_array($val['type'], array('html', 'text'))) {
243 continue;
244 }
245 if (in_array($val['type'], array('timestamp', 'date', 'datetime'))) {
246 $position = (empty($val['position']) ? 0 : intval($val['position']));
247 $arrayofxaxis[$tablealias.'.'.$key.'-year'] = array(
248 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$YYYY.')</span>',
249 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
250 'position' => ($position + ($count * 100000)).'.1',
251 'table' => $object->table_element,
252 'tablefromt' => $tablepath
253 );
254 $arrayofxaxis[$tablealias.'.'.$key.'-month'] = array(
255 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$YYYY.'-'.$MM.')</span>',
256 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
257 'position' => ($position + ($count * 100000)).'.2',
258 'table' => $object->table_element,
259 'tablefromt' => $tablepath
260 );
261 $arrayofxaxis[$tablealias.'.'.$key.'-day'] = array(
262 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$YYYY.'-'.$MM.'-'.$DD.')</span>',
263 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
264 'position' => ($position + ($count * 100000)).'.3',
265 'table' => $object->table_element,
266 'tablefromt' => $tablepath
267 );
268 } else {
269 $position = (empty($val['position']) ? 0 : intval($val['position']));
270 $arrayofxaxis[$tablealias.'.'.$key] = array(
271 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val['label']),
272 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
273 'position' => ($position + ($count * 100000)),
274 'table' => $object->table_element,
275 'tablefromt' => $tablepath
276 );
277 }
278 }
279 }
280
281 // Add extrafields to X-Axis
282 if (!empty($object->isextrafieldmanaged) && isset($extrafields->attributes[$object->table_element]['label'])) {
283 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
284 if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate') {
285 continue;
286 }
287 if (!empty($extrafields->attributes[$object->table_element]['totalizable'][$key])) {
288 continue;
289 }
290
291 if (in_array($extrafields->attributes[$object->table_element]['type'][$key], array('timestamp', 'date', 'datetime'))) {
292 $position = (empty($extrafields->attributes[$object->table_element]['pos'][$key]) ? 0 : intval($extrafields->attributes[$object->table_element]['pos'][$key]));
293 $arrayofxaxis[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-year'] = array(
294 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val).' <span class="opacitymedium">('.$YYYY.')</span>',
295 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
296 'position' => ($position + ($count * 100000)).'.1',
297 'table' => $object->table_element,
298 'tablefromt' => $tablepath
299 );
300 $arrayofxaxis[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-month'] = array(
301 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val).' <span class="opacitymedium">('.$YYYY.'-'.$MM.')</span>',
302 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
303 'position' => ($position + ($count * 100000)).'.2',
304 'table' => $object->table_element,
305 'tablefromt' => $tablepath
306 );
307 $arrayofxaxis[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-day'] = array(
308 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val).' <span class="opacitymedium">('.$YYYY.'-'.$MM.'-'.$DD.')</span>',
309 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
310 'position' => ($position + ($count * 100000)).'.3',
311 'table' => $object->table_element,
312 'tablefromt' => $tablepath
313 );
314 } else {
315 $arrayofxaxis[preg_replace('/^t/', 'te', $tablealias).'.'.$key] = array(
316 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val),
317 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
318 'position' => 1000 + (int) $extrafields->attributes[$object->table_element]['pos'][$key] + ($count * 100000),
319 'table' => $object->table_element,
320 'tablefromt' => $tablepath
321 );
322 }
323 }
324 }
325
326 // Add fields for parent objects
327 foreach ($object->fields as $key => $val) {
328 if (preg_match('/^[^:]+:[^:]+:/', $val['type'])) {
329 $tmptype = explode(':', $val['type'], 4);
330 if ($tmptype[0] == 'integer' && $tmptype[1] && $tmptype[2]) {
331 $newobject = $tmptype[1];
332 dol_include_once($tmptype[2]);
333 if (class_exists($newobject)) {
334 $tmpobject = new $newobject($db);
335 //var_dump($key); var_dump($tmpobject->element); var_dump($val['label']); var_dump($tmptype); var_dump('t-'.$key);
336 $count++;
337 $arrayofxaxis = fillArrayOfXAxis($tmpobject, $tablealias.'__'.$key, $langs->trans($val['label']), $arrayofxaxis, $level + 1, $count, $tablepath);
338 } else {
339 print 'For property '.$object->element.'->'.$key.', type="'.$val['type'].'": Failed to find class '.$newobject." in file ".$tmptype[2]."<br>\n";
340 }
341 }
342 }
343 }
344
345 return $arrayofxaxis;
346}
347
348
361function fillArrayOfGroupBy($object, $tablealias, $labelofobject, &$arrayofgroupby, $level = 0, &$count = 0, &$tablepath = '')
362{
363 global $langs, $extrafields, $db;
364
365 if (empty($object)) { // Protection against bad use of method
366 return array();
367 }
368 if ($level >= 3) {
369 return $arrayofgroupby;
370 }
371
372 if (empty($tablepath)) {
373 $tablepath = $object->table_element.'='.$tablealias;
374 } else {
375 $tablepath .= ','.$object->table_element.'='.$tablealias;
376 }
377
378 $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);
379 $MM = substr($langs->trans("Month"), 0, 1).substr($langs->trans("Month"), 0, 1);
380 $DD = substr($langs->trans("Day"), 0, 1).substr($langs->trans("Day"), 0, 1);
381 $HH = substr($langs->trans("Hour"), 0, 1).substr($langs->trans("Hour"), 0, 1);
382 $MI = substr($langs->trans("Minute"), 0, 1).substr($langs->trans("Minute"), 0, 1);
383 $SS = substr($langs->trans("Second"), 0, 1).substr($langs->trans("Second"), 0, 1);
384
385 // Note: here $tablealias can be 't' or 't__fk_contract' or 't_fk_contract_fk_soc'
386
387 // Add main fields of object
388 foreach ($object->fields as $key => $val) {
389 if (empty($val['isameasure'])) {
390 if (in_array($key, array(
391 'id', 'ref_ext', 'rowid', 'entity', 'last_main_doc', 'logo', 'logo_squarred', 'extraparams',
392 'parent', 'photo', 'socialnetworks', 'webservices_url', 'webservices_key'))) {
393 continue;
394 }
395 if (isset($val['enabled']) && ! (int) dol_eval((string) $val['enabled'], 1, 1, '1')) {
396 continue;
397 }
398 if (isset($val['visible']) && ! (int) dol_eval((string) $val['visible'], 1, 1, '1')) {
399 continue;
400 }
401 if (preg_match('/^fk_/', $key) && !preg_match('/^fk_statu/', $key)) {
402 continue;
403 }
404 if (preg_match('/^pass/', $key)) {
405 continue;
406 }
407 if (in_array($val['type'], array('html', 'text'))) {
408 continue;
409 }
410 if (in_array($val['type'], array('timestamp', 'date', 'datetime'))) {
411 $position = (empty($val['position']) ? 0 : intval($val['position']));
412 $arrayofgroupby[$tablealias.'.'.$key.'-year'] = array(
413 '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
414 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
415 'position' => ($position + ($count * 100000)).'.1',
416 'table' => $object->table_element,
417 'tablefromt' => $tablepath
418 );
419 $arrayofgroupby[$tablealias.'.'.$key.'-month'] = array(
420 '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
421 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
422 'position' => ($position + ($count * 100000)).'.2',
423 'table' => $object->table_element,
424 'tablefromt' => $tablepath
425 );
426 $arrayofgroupby[$tablealias.'.'.$key.'-day'] = array(
427 '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
428 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
429 'position' => ($position + ($count * 100000)).'.3',
430 'table' => $object->table_element,
431 'tablefromt' => $tablepath
432 );
433 } else {
434 $position = (empty($val['position']) ? 0 : intval($val['position']));
435 $arrayofgroupby[$tablealias.'.'.$key] = array(
436 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val['label']), // @phan-suppress-current-line PhanUndeclaredProperty
437 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
438 'position' => ($position + ($count * 100000)),
439 'table' => $object->table_element,
440 'tablefromt' => $tablepath
441 );
442 }
443 }
444 }
445
446 // Add extrafields to Group by
447 if (!empty($object->isextrafieldmanaged) && isset($extrafields->attributes[$object->table_element]['label'])) {
448 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
449 if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate') {
450 continue;
451 }
452 if (!empty($extrafields->attributes[$object->table_element]['totalizable'][$key])) {
453 continue;
454 }
455
456 if (in_array($extrafields->attributes[$object->table_element]['type'][$key], array('timestamp', 'date', 'datetime'))) {
457 $position = (empty($extrafields->attributes[$object->table_element]['pos'][$key]) ? 0 : intval($extrafields->attributes[$object->table_element]['pos'][$key]));
458 $arrayofgroupby[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-year'] = array(
459 '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
460 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
461 'position' => ($position + ($count * 100000)).'.1',
462 'table' => $object->table_element,
463 'tablefromt' => $tablepath
464 );
465 $arrayofgroupby[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-month'] = array(
466 '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
467 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
468 'position' => ($position + ($count * 100000)).'.2',
469 'table' => $object->table_element,
470 'tablefromt' => $tablepath
471 );
472 $arrayofgroupby[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-day'] = array(
473 '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
474 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
475 'position' => ($position + ($count * 100000)).'.3',
476 'table' => $object->table_element,
477 'tablefromt' => $tablepath
478 );
479 } else {
480 $arrayofgroupby[preg_replace('/^t/', 'te', $tablealias).'.'.$key] = array(
481 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val), // @phan-suppress-current-line PhanUndeclaredProperty
482 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
483 'position' => 1000 + (int) $extrafields->attributes[$object->table_element]['pos'][$key] + ($count * 100000),
484 'table' => $object->table_element,
485 'tablefromt' => $tablepath
486 );
487 }
488 }
489 }
490
491 // Add fields for parent objects
492 foreach ($object->fields as $key => $val) {
493 if (preg_match('/^[^:]+:[^:]+:/', $val['type'])) {
494 $tmptype = explode(':', $val['type'], 4);
495 if ($tmptype[0] == 'integer' && $tmptype[1] && $tmptype[2]) {
496 $newobject = $tmptype[1];
497 dol_include_once($tmptype[2]);
498 if (class_exists($newobject)) {
499 $tmpobject = new $newobject($db);
500 //var_dump($key); var_dump($tmpobject->element); var_dump($val['label']); var_dump($tmptype); var_dump('t-'.$key);
501 $count++;
502 $arrayofgroupby = fillArrayOfGroupBy($tmpobject, $tablealias.'__'.$key, $langs->trans($val['label']), $arrayofgroupby, $level + 1, $count, $tablepath);
503 } else {
504 print 'For property '.$object->element.'->'.$key.', type="'.$val['type'].'": Failed to find class '.$newobject." in file ".$tmptype[2]."<br>\n";
505 }
506 }
507 }
508 }
509
510 return $arrayofgroupby;
511}
512
513
526function fillArrayOfFilterFields($object, $tablealias, $labelofobject, &$arrayoffields, $level = 0, &$count = 0, &$tablepath = '')
527{
528 global $langs, $extrafields, $db;
529
530 $MAXLEVEL = 2;
531
532 if (empty($object)) { // Protection against bad use of method
533 return array();
534 }
535 if ($level > $MAXLEVEL) { // Limit scan on 2 levels max
536 return $arrayoffields;
537 }
538
539 if (empty($tablepath)) {
540 $tablepath = $object->table_element.'='.$tablealias;
541 } else {
542 $tablepath .= ','.$object->table_element.'='.$tablealias;
543 }
544
545 // Note: here $tablealias can be 't' or 't__fk_contract' or 't_fk_contract_fk_soc'
546
547 // Add main fields of object
548 foreach ($object->fields as $key => $val) {
549 if (empty($val['measure'])) {
550 // Exclude some fields
551 if (in_array($key, array(
552 'id', 'ref_ext', 'rowid', 'entity', 'last_main_doc', 'logo', 'logo_squarred', 'extraparams',
553 'parent', 'pass', 'pass_crypted', 'pass_temp', 'photo', 'socialnetworks', 'webservices_url', 'webservices_key'))) {
554 continue;
555 }
556 if (isset($val['enabled']) && ! (int) dol_eval((string) $val['enabled'], 1, 1, '1')) {
557 continue;
558 }
559 if (isset($val['visible']) && ! (int) dol_eval((string) $val['visible'], 1, 1, '1')) {
560 continue;
561 }
562 if (preg_match('/^fk_/', $key) && !preg_match('/^fk_statu/', $key)) {
563 continue;
564 }
565 if (preg_match('/^pass/', $key)) {
566 continue;
567 }
568 if (in_array($val['type'], array('html', 'text'))) {
569 continue;
570 }
571
572 $position = (empty($val['position']) ? 0 : intval($val['position']));
573 $arrayoffields[$tablealias.'.'.$key] = array(
574 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val['label']), // @phan-suppress-current-line PhanUndeclaredProperty
575 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
576 'position' => ($position + ($count * 100000)),
577 'table' => $object->table_element,
578 'tablefromt' => $tablepath,
579 'type' => $val['type']
580 );
581 if (!empty($val['arrayofkeyval'])) {
582 $arrayoffields[$tablealias.'.'.$key]['arrayofkeyval'] = $val['arrayofkeyval'];
583 }
584 if ((!isset($val['isamesaure']) || $val['isamesaure'] != 1) && (!isset($val['notnull']) || $val['notnull'] != '1')) {
585 $arrayoffields[$tablealias.'.'.$key]['maybenull'] = 1;
586 }
587 }
588 }
589
590 // Add extrafields to fields
591 if (!empty($object->isextrafieldmanaged) && isset($extrafields->attributes[$object->table_element]['label'])) {
592 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
593 if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate') {
594 continue;
595 }
596 if (!empty($extrafields->attributes[$object->table_element]['totalizable'][$key])) {
597 continue;
598 }
599
600 $arrayoffields[preg_replace('/^t/', 'te', $tablealias).'.'.$key] = array(
601 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val), // @phan-suppress-current-line PhanUndeclaredProperty
602 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
603 'position' => 1000 + (int) $extrafields->attributes[$object->table_element]['pos'][$key] + ($count * 100000),
604 'table' => $object->table_element,
605 'tablefromt' => $tablepath,
606 'type' => $extrafields->attributes[$object->table_element]['type'][$key],
607 );
608 }
609 }
610
611 // Add fields for parent objects
612 foreach ($object->fields as $key => $val) {
613 if (preg_match('/^[^:]+:[^:]+:/', $val['type'])) {
614 $tmptype = explode(':', $val['type'], 4);
615 if ($tmptype[0] == 'integer' && $tmptype[1] && $tmptype[2]) {
616 $newobject = $tmptype[1];
617 dol_include_once($tmptype[2]);
618 if (class_exists($newobject)) {
619 $tmpobject = new $newobject($db);
620 $count++;
621 if (!empty($val['nodepth'])) {
622 $arrayoffields = fillArrayOfFilterFields($tmpobject, $tablealias.'__'.$key, $langs->trans($val['label']), $arrayoffields, $MAXLEVEL, $count, $tablepath);
623 } else {
624 $arrayoffields = fillArrayOfFilterFields($tmpobject, $tablealias.'__'.$key, $langs->trans($val['label']), $arrayoffields, $level + 1, $count, $tablepath);
625 }
626 } else {
627 print 'For property '.$object->element.'->'.$key.', type="'.$val['type'].'": Failed to find class '.$newobject." in file ".$tmptype[2]."<br>\n";
628 }
629 }
630 }
631 }
632
633 return $arrayoffields;
634}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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.
fillArrayOfMeasures($object, $tablealias, $labelofobject, &$arrayofmesures, $level=0, &$count=0, &$tablepath='')
Fill arrayofmesures for an object.
fillArrayOfXAxis($object, $tablealias, $labelofobject, &$arrayofxaxis, $level=0, &$count=0, &$tablepath='')
Fill arrayofmesures for an object.
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)
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.