dolibarr 21.0.0-beta
customreports.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2024 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5*
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 * or see https://www.gnu.org/
19 */
20
38function fillArrayOfMeasures($object, $tablealias, $labelofobject, &$arrayofmesures, $level = 0, &$count = 0, &$tablepath = '')
39{
40 global $langs, $extrafields, $db;
41
42 if (empty($object)) { // Protection against bad use of method
43 return array();
44 }
45 if ($level > 10) { // Protection against infinite loop
46 return $arrayofmesures;
47 }
48
49 if (empty($tablepath)) {
50 $tablepath = $object->table_element.'='.$tablealias;
51 } else {
52 $tablepath .= ','.$object->table_element.'='.$tablealias;
53 }
54
55 if ($level == 0) {
56 // Add the count of record only for the main/first level object. Parents are necessarily unique for each record.
57 $arrayofmesures[$tablealias.'.count'] = array(
58 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').$labelofobject.': '.$langs->trans("Number"),
59 'labelnohtml' => $labelofobject.': '.$langs->trans("Number"),
60 'position' => 0,
61 'table' => $object->table_element,
62 'tablefromt' => $tablepath
63 );
64 }
65
66 // Note: here $tablealias can be 't' or 't__fk_contract' or 't_fk_contract_fk_soc'
67
68 // Add main fields of object
69 foreach ($object->fields as $key => $val) {
70 if (!empty($val['isameasure']) && (!isset($val['enabled']) || (int) dol_eval($val['enabled'], 1, 1, '1'))) {
71 $position = (empty($val['position']) ? 0 : intval($val['position']));
72 $arrayofmesures[$tablealias.'.'.$key.'-sum'] = array(
73 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$langs->trans("Sum").')</span>',
74 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
75 'position' => ($position + ($count * 100000)).'.1',
76 'table' => $object->table_element,
77 'tablefromt' => $tablepath
78 );
79 $arrayofmesures[$tablealias.'.'.$key.'-average'] = array(
80 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$langs->trans("Average").')</span>',
81 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
82 'position' => ($position + ($count * 100000)).'.2',
83 'table' => $object->table_element,
84 'tablefromt' => $tablepath
85 );
86 $arrayofmesures[$tablealias.'.'.$key.'-min'] = array(
87 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$langs->trans("Minimum").')</span>',
88 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
89 'position' => ($position + ($count * 100000)).'.3',
90 'table' => $object->table_element,
91 'tablefromt' => $tablepath
92 );
93 $arrayofmesures[$tablealias.'.'.$key.'-max'] = array(
94 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$langs->trans("Maximum").')</span>',
95 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
96 'position' => ($position + ($count * 100000)).'.4',
97 'table' => $object->table_element,
98 'tablefromt' => $tablepath
99 );
100 $arrayofmesures[$tablealias.'.'.$key.'-stddevpop'] = array(
101 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$langs->trans("StandardDeviationPop").')</span>',
102 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
103 'position' => ($position + ($count * 100000)).'.5',
104 'table' => $object->table_element,
105 'tablefromt' => $tablepath
106 );
107 }
108 }
109 // Add extrafields to Measures
110 if (!empty($object->isextrafieldmanaged) && isset($extrafields->attributes[$object->table_element]['label'])) {
111 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
112 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'))) {
113 // @phan-suppress-next-line PhanTypeMismatchDimAssignment
114 $position = (!empty($val['position']) ? $val['position'] : 0);
115 $arrayofmesures[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-sum'] = array(
116 '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>',
117 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
118 'position' => ($position + ($count * 100000)).'.1',
119 'table' => $object->table_element,
120 'tablefromt' => $tablepath
121 );
122 $arrayofmesures[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-average'] = array(
123 '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>',
124 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
125 'position' => ($position + ($count * 100000)).'.2',
126 'table' => $object->table_element,
127 'tablefromt' => $tablepath
128 );
129 $arrayofmesures[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-min'] = array(
130 '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>',
131 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
132 'position' => ($position + ($count * 100000)).'.3',
133 'table' => $object->table_element,
134 'tablefromt' => $tablepath
135 );
136 $arrayofmesures[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-max'] = array(
137 '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>',
138 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
139 'position' => ($position + ($count * 100000)).'.4',
140 'table' => $object->table_element,
141 'tablefromt' => $tablepath
142 );
143 $arrayofmesures[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-stddevpop'] = array(
144 '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>',
145 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
146 'position' => ($position + ($count * 100000)).'.5',
147 'table' => $object->table_element,
148 'tablefromt' => $tablepath
149 );
150 }
151 }
152 }
153 // Add fields for parent objects
154 foreach ($object->fields as $key => $val) {
155 if (preg_match('/^[^:]+:[^:]+:/', $val['type'])) {
156 $tmptype = explode(':', $val['type'], 4);
157 if ($tmptype[0] == 'integer' && !empty($tmptype[1]) && !empty($tmptype[2])) {
158 $newobject = $tmptype[1];
159 dol_include_once($tmptype[2]);
160 if (class_exists($newobject)) {
161 $tmpobject = new $newobject($db);
162 //var_dump($key); var_dump($tmpobject->element); var_dump($val['label']); var_dump($tmptype); var_dump('t-'.$key);
163 $count++;
164 $arrayofmesures = fillArrayOfMeasures($tmpobject, $tablealias.'__'.$key, $langs->trans($val['label']), $arrayofmesures, $level + 1, $count, $tablepath);
165 } else {
166 print 'For property '.$object->element.'->'.$key.', type="'.$val['type'].'": Failed to find class '.$newobject." in file ".$tmptype[2]."<br>\n";
167 }
168 }
169 }
170 }
171
172 return $arrayofmesures;
173}
174
175
188function fillArrayOfXAxis($object, $tablealias, $labelofobject, &$arrayofxaxis, $level = 0, &$count = 0, &$tablepath = '')
189{
190 global $langs, $extrafields, $db;
191
192 if (empty($object)) { // Protection against bad use of method
193 return array();
194 }
195 if ($level >= 3) { // Limit scan on 2 levels max
196 return $arrayofxaxis;
197 }
198
199 if (empty($tablepath)) {
200 $tablepath = $object->table_element.'='.$tablealias;
201 } else {
202 $tablepath .= ','.$object->table_element.'='.$tablealias;
203 }
204
205 $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);
206 $MM = substr($langs->trans("Month"), 0, 1).substr($langs->trans("Month"), 0, 1);
207 $DD = substr($langs->trans("Day"), 0, 1).substr($langs->trans("Day"), 0, 1);
208 $HH = substr($langs->trans("Hour"), 0, 1).substr($langs->trans("Hour"), 0, 1);
209 $MI = substr($langs->trans("Minute"), 0, 1).substr($langs->trans("Minute"), 0, 1);
210 $SS = substr($langs->trans("Second"), 0, 1).substr($langs->trans("Second"), 0, 1);
211
212 /*if ($level > 0) {
213 var_dump($object->element.' '.$object->isextrafieldmanaged);
214 }*/
215
216 // Note: here $tablealias can be 't' or 't__fk_contract' or 't_fk_contract_fk_soc'
217
218 // Add main fields of object
219 foreach ($object->fields as $key => $val) {
220 if (empty($val['measure'])) {
221 if (in_array($key, array(
222 'id', 'ref_ext', 'rowid', 'entity', 'last_main_doc', 'logo', 'logo_squarred', 'extraparams',
223 'parent', 'photo', 'socialnetworks', 'webservices_url', 'webservices_key'))) {
224 continue;
225 }
226 if (isset($val['enabled']) && ! (int) dol_eval($val['enabled'], 1, 1, '1')) {
227 continue;
228 }
229 if (isset($val['visible']) && ! (int) dol_eval($val['visible'], 1, 1, '1')) {
230 continue;
231 }
232 if (preg_match('/^fk_/', $key) && !preg_match('/^fk_statu/', $key)) {
233 continue;
234 }
235 if (preg_match('/^pass/', $key)) {
236 continue;
237 }
238 if (in_array($val['type'], array('html', 'text'))) {
239 continue;
240 }
241 if (in_array($val['type'], array('timestamp', 'date', 'datetime'))) {
242 $position = (empty($val['position']) ? 0 : intval($val['position']));
243 $arrayofxaxis[$tablealias.'.'.$key.'-year'] = array(
244 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$YYYY.')</span>',
245 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
246 'position' => ($position + ($count * 100000)).'.1',
247 'table' => $object->table_element,
248 'tablefromt' => $tablepath
249 );
250 $arrayofxaxis[$tablealias.'.'.$key.'-month'] = array(
251 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$YYYY.'-'.$MM.')</span>',
252 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
253 'position' => ($position + ($count * 100000)).'.2',
254 'table' => $object->table_element,
255 'tablefromt' => $tablepath
256 );
257 $arrayofxaxis[$tablealias.'.'.$key.'-day'] = array(
258 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$YYYY.'-'.$MM.'-'.$DD.')</span>',
259 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
260 'position' => ($position + ($count * 100000)).'.3',
261 'table' => $object->table_element,
262 'tablefromt' => $tablepath
263 );
264 } else {
265 $position = (empty($val['position']) ? 0 : intval($val['position']));
266 $arrayofxaxis[$tablealias.'.'.$key] = array(
267 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val['label']),
268 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
269 'position' => ($position + ($count * 100000)),
270 'table' => $object->table_element,
271 'tablefromt' => $tablepath
272 );
273 }
274 }
275 }
276
277 // Add extrafields to X-Axis
278 if (!empty($object->isextrafieldmanaged) && isset($extrafields->attributes[$object->table_element]['label'])) {
279 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
280 if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate') {
281 continue;
282 }
283 if (!empty($extrafields->attributes[$object->table_element]['totalizable'][$key])) {
284 continue;
285 }
286
287 if (in_array($extrafields->attributes[$object->table_element]['type'][$key], array('timestamp', 'date', 'datetime'))) {
288 $position = (empty($extrafields->attributes[$object->table_element]['pos'][$key]) ? 0 : intval($extrafields->attributes[$object->table_element]['pos'][$key]));
289 $arrayofxaxis[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-year'] = array(
290 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val).' <span class="opacitymedium">('.$YYYY.')</span>',
291 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
292 'position' => ($position + ($count * 100000)).'.1',
293 'table' => $object->table_element,
294 'tablefromt' => $tablepath
295 );
296 $arrayofxaxis[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-month'] = array(
297 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val).' <span class="opacitymedium">('.$YYYY.'-'.$MM.')</span>',
298 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
299 'position' => ($position + ($count * 100000)).'.2',
300 'table' => $object->table_element,
301 'tablefromt' => $tablepath
302 );
303 $arrayofxaxis[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-day'] = array(
304 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val).' <span class="opacitymedium">('.$YYYY.'-'.$MM.'-'.$DD.')</span>',
305 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
306 'position' => ($position + ($count * 100000)).'.3',
307 'table' => $object->table_element,
308 'tablefromt' => $tablepath
309 );
310 } else {
311 $arrayofxaxis[preg_replace('/^t/', 'te', $tablealias).'.'.$key] = array(
312 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val),
313 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
314 'position' => 1000 + (int) $extrafields->attributes[$object->table_element]['pos'][$key] + ($count * 100000),
315 'table' => $object->table_element,
316 'tablefromt' => $tablepath
317 );
318 }
319 }
320 }
321
322 // Add fields for parent objects
323 foreach ($object->fields as $key => $val) {
324 if (preg_match('/^[^:]+:[^:]+:/', $val['type'])) {
325 $tmptype = explode(':', $val['type'], 4);
326 if ($tmptype[0] == 'integer' && $tmptype[1] && $tmptype[2]) {
327 $newobject = $tmptype[1];
328 dol_include_once($tmptype[2]);
329 if (class_exists($newobject)) {
330 $tmpobject = new $newobject($db);
331 //var_dump($key); var_dump($tmpobject->element); var_dump($val['label']); var_dump($tmptype); var_dump('t-'.$key);
332 $count++;
333 $arrayofxaxis = fillArrayOfXAxis($tmpobject, $tablealias.'__'.$key, $langs->trans($val['label']), $arrayofxaxis, $level + 1, $count, $tablepath);
334 } else {
335 print 'For property '.$object->element.'->'.$key.', type="'.$val['type'].'": Failed to find class '.$newobject." in file ".$tmptype[2]."<br>\n";
336 }
337 }
338 }
339 }
340
341 return $arrayofxaxis;
342}
343
344
357function fillArrayOfGroupBy($object, $tablealias, $labelofobject, &$arrayofgroupby, $level = 0, &$count = 0, &$tablepath = '')
358{
359 global $langs, $extrafields, $db;
360
361 if (empty($object)) { // Protection against bad use of method
362 return array();
363 }
364 if ($level >= 3) {
365 return $arrayofgroupby;
366 }
367
368 if (empty($tablepath)) {
369 $tablepath = $object->table_element.'='.$tablealias;
370 } else {
371 $tablepath .= ','.$object->table_element.'='.$tablealias;
372 }
373
374 $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);
375 $MM = substr($langs->trans("Month"), 0, 1).substr($langs->trans("Month"), 0, 1);
376 $DD = substr($langs->trans("Day"), 0, 1).substr($langs->trans("Day"), 0, 1);
377 $HH = substr($langs->trans("Hour"), 0, 1).substr($langs->trans("Hour"), 0, 1);
378 $MI = substr($langs->trans("Minute"), 0, 1).substr($langs->trans("Minute"), 0, 1);
379 $SS = substr($langs->trans("Second"), 0, 1).substr($langs->trans("Second"), 0, 1);
380
381 // Note: here $tablealias can be 't' or 't__fk_contract' or 't_fk_contract_fk_soc'
382
383 // Add main fields of object
384 foreach ($object->fields as $key => $val) {
385 if (empty($val['isameasure'])) {
386 if (in_array($key, array(
387 'id', 'ref_ext', 'rowid', 'entity', 'last_main_doc', 'logo', 'logo_squarred', 'extraparams',
388 'parent', 'photo', 'socialnetworks', 'webservices_url', 'webservices_key'))) {
389 continue;
390 }
391 if (isset($val['enabled']) && ! (int) dol_eval($val['enabled'], 1, 1, '1')) {
392 continue;
393 }
394 if (isset($val['visible']) && ! (int) dol_eval($val['visible'], 1, 1, '1')) {
395 continue;
396 }
397 if (preg_match('/^fk_/', $key) && !preg_match('/^fk_statu/', $key)) {
398 continue;
399 }
400 if (preg_match('/^pass/', $key)) {
401 continue;
402 }
403 if (in_array($val['type'], array('html', 'text'))) {
404 continue;
405 }
406 if (in_array($val['type'], array('timestamp', 'date', 'datetime'))) {
407 $position = (empty($val['position']) ? 0 : intval($val['position']));
408 $arrayofgroupby[$tablealias.'.'.$key.'-year'] = array(
409 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$YYYY.')</span>',
410 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
411 'position' => ($position + ($count * 100000)).'.1',
412 'table' => $object->table_element,
413 'tablefromt' => $tablepath
414 );
415 $arrayofgroupby[$tablealias.'.'.$key.'-month'] = array(
416 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$YYYY.'-'.$MM.')</span>',
417 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
418 'position' => ($position + ($count * 100000)).'.2',
419 'table' => $object->table_element,
420 'tablefromt' => $tablepath
421 );
422 $arrayofgroupby[$tablealias.'.'.$key.'-day'] = array(
423 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$YYYY.'-'.$MM.'-'.$DD.')</span>',
424 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
425 'position' => ($position + ($count * 100000)).'.3',
426 'table' => $object->table_element,
427 'tablefromt' => $tablepath
428 );
429 } else {
430 $position = (empty($val['position']) ? 0 : intval($val['position']));
431 $arrayofgroupby[$tablealias.'.'.$key] = array(
432 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val['label']),
433 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
434 'position' => ($position + ($count * 100000)),
435 'table' => $object->table_element,
436 'tablefromt' => $tablepath
437 );
438 }
439 }
440 }
441
442 // Add extrafields to Group by
443 if (!empty($object->isextrafieldmanaged) && isset($extrafields->attributes[$object->table_element]['label'])) {
444 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
445 if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate') {
446 continue;
447 }
448 if (!empty($extrafields->attributes[$object->table_element]['totalizable'][$key])) {
449 continue;
450 }
451
452 if (in_array($extrafields->attributes[$object->table_element]['type'][$key], array('timestamp', 'date', 'datetime'))) {
453 $position = (empty($extrafields->attributes[$object->table_element]['pos'][$key]) ? 0 : intval($extrafields->attributes[$object->table_element]['pos'][$key]));
454 $arrayofgroupby[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-year'] = array(
455 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val).' <span class="opacitymedium">('.$YYYY.')</span>',
456 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
457 'position' => ($position + ($count * 100000)).'.1',
458 'table' => $object->table_element,
459 'tablefromt' => $tablepath
460 );
461 $arrayofgroupby[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-month'] = array(
462 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val).' <span class="opacitymedium">('.$YYYY.'-'.$MM.')</span>',
463 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
464 'position' => ($position + ($count * 100000)).'.2',
465 'table' => $object->table_element,
466 'tablefromt' => $tablepath
467 );
468 $arrayofgroupby[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-day'] = array(
469 '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
470 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
471 'position' => ($position + ($count * 100000)).'.3',
472 'table' => $object->table_element,
473 'tablefromt' => $tablepath
474 );
475 } else {
476 $arrayofgroupby[preg_replace('/^t/', 'te', $tablealias).'.'.$key] = array(
477 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val), // @phan-suppress-current-line PhanUndeclaredProperty
478 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
479 'position' => 1000 + (int) $extrafields->attributes[$object->table_element]['pos'][$key] + ($count * 100000),
480 'table' => $object->table_element,
481 'tablefromt' => $tablepath
482 );
483 }
484 }
485 }
486
487 // Add fields for parent objects
488 foreach ($object->fields as $key => $val) {
489 if (preg_match('/^[^:]+:[^:]+:/', $val['type'])) {
490 $tmptype = explode(':', $val['type'], 4);
491 if ($tmptype[0] == 'integer' && $tmptype[1] && $tmptype[2]) {
492 $newobject = $tmptype[1];
493 dol_include_once($tmptype[2]);
494 if (class_exists($newobject)) {
495 $tmpobject = new $newobject($db);
496 //var_dump($key); var_dump($tmpobject->element); var_dump($val['label']); var_dump($tmptype); var_dump('t-'.$key);
497 $count++;
498 $arrayofgroupby = fillArrayOfGroupBy($tmpobject, $tablealias.'__'.$key, $langs->trans($val['label']), $arrayofgroupby, $level + 1, $count, $tablepath);
499 } else {
500 print 'For property '.$object->element.'->'.$key.', type="'.$val['type'].'": Failed to find class '.$newobject." in file ".$tmptype[2]."<br>\n";
501 }
502 }
503 }
504 }
505
506 return $arrayofgroupby;
507}
508
509
522function fillArrayOfFilterFields($object, $tablealias, $labelofobject, &$arrayoffields, $level = 0, &$count = 0, &$tablepath = '')
523{
524 global $langs, $extrafields, $db;
525
526 if (empty($object)) { // Protection against bad use of method
527 return array();
528 }
529 if ($level >= 3) { // Limit scan on 2 levels max
530 return $arrayoffields;
531 }
532
533 if (empty($tablepath)) {
534 $tablepath = $object->table_element.'='.$tablealias;
535 } else {
536 $tablepath .= ','.$object->table_element.'='.$tablealias;
537 }
538
539 // Note: here $tablealias can be 't' or 't__fk_contract' or 't_fk_contract_fk_soc'
540
541 // Add main fields of object
542 foreach ($object->fields as $key => $val) {
543 if (empty($val['measure'])) {
544 // Exclude some fields
545 if (in_array($key, array(
546 'id', 'ref_ext', 'rowid', 'entity', 'last_main_doc', 'logo', 'logo_squarred', 'extraparams',
547 'parent', 'photo', 'socialnetworks', 'webservices_url', 'webservices_key'))) {
548 continue;
549 }
550 if (isset($val['enabled']) && ! (int) dol_eval($val['enabled'], 1, 1, '1')) {
551 continue;
552 }
553 if (isset($val['visible']) && ! (int) dol_eval($val['visible'], 1, 1, '1')) {
554 continue;
555 }
556 if (preg_match('/^fk_/', $key) && !preg_match('/^fk_statu/', $key)) {
557 continue;
558 }
559 if (preg_match('/^pass/', $key)) {
560 continue;
561 }
562 if (in_array($val['type'], array('html', 'text'))) {
563 continue;
564 }
565
566 $position = (empty($val['position']) ? 0 : intval($val['position']));
567 $arrayoffields[$tablealias.'.'.$key] = array(
568 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val['label']),
569 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
570 'position' => ($position + ($count * 100000)),
571 'table' => $object->table_element,
572 'tablefromt' => $tablepath,
573 'type' => $val['type']
574 );
575 }
576 }
577
578 // Add extrafields to fields
579 if (!empty($object->isextrafieldmanaged) && isset($extrafields->attributes[$object->table_element]['label'])) {
580 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
581 if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate') {
582 continue;
583 }
584 if (!empty($extrafields->attributes[$object->table_element]['totalizable'][$key])) {
585 continue;
586 }
587
588 $arrayoffields[preg_replace('/^t/', 'te', $tablealias).'.'.$key] = array(
589 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val), // @phan-suppress-current-line PhanUndeclaredProperty
590 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
591 'position' => 1000 + (int) $extrafields->attributes[$object->table_element]['pos'][$key] + ($count * 100000),
592 'table' => $object->table_element,
593 'tablefromt' => $tablepath,
594 'type' => $extrafields->attributes[$object->table_element]['type'][$key],
595 );
596 }
597 }
598
599 // Add fields for parent objects
600 foreach ($object->fields as $key => $val) {
601 if (preg_match('/^[^:]+:[^:]+:/', $val['type'])) {
602 $tmptype = explode(':', $val['type'], 4);
603 if ($tmptype[0] == 'integer' && $tmptype[1] && $tmptype[2]) {
604 $newobject = $tmptype[1];
605 dol_include_once($tmptype[2]);
606 if (class_exists($newobject)) {
607 $tmpobject = new $newobject($db);
608 $count++;
609 $arrayoffields = fillArrayOfFilterFields($tmpobject, $tablealias.'__'.$key, $langs->trans($val['label']), $arrayoffields, $level + 1, $count, $tablepath);
610 } else {
611 print 'For property '.$object->element.'->'.$key.', type="'.$val['type'].'": Failed to find class '.$newobject." in file ".$tmptype[2]."<br>\n";
612 }
613 }
614 }
615 }
616
617 return $arrayoffields;
618}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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)
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.