dolibarr 20.0.0
customreports.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2024 Laurent Destailleur <eldy@users.sourceforge.net>
3*
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 * or see https://www.gnu.org/
17 */
18
36function fillArrayOfMeasures($object, $tablealias, $labelofobject, &$arrayofmesures, $level = 0, &$count = 0, &$tablepath = '')
37{
38 global $langs, $extrafields, $db;
39
40 if (empty($object)) { // Protection against bad use of method
41 return array();
42 }
43 if ($level > 10) { // Protection against infinite loop
44 return $arrayofmesures;
45 }
46
47 if (empty($tablepath)) {
48 $tablepath = $object->table_element.'='.$tablealias;
49 } else {
50 $tablepath .= ','.$object->table_element.'='.$tablealias;
51 }
52
53 if ($level == 0) {
54 // Add the count of record only for the main/first level object. Parents are necessarily unique for each record.
55 $arrayofmesures[$tablealias.'.count'] = array(
56 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').$labelofobject.': '.$langs->trans("Number"),
57 'labelnohtml' => $labelofobject.': '.$langs->trans("Number"),
58 'position' => 0,
59 'table' => $object->table_element,
60 'tablefromt' => $tablepath
61 );
62 }
63
64 // Note: here $tablealias can be 't' or 't__fk_contract' or 't_fk_contract_fk_soc'
65
66 // Add main fields of object
67 foreach ($object->fields as $key => $val) {
68 if (!empty($val['isameasure']) && (!isset($val['enabled']) || (int) dol_eval($val['enabled'], 1, 1, '1'))) {
69 $position = (empty($val['position']) ? 0 : intval($val['position']));
70 $arrayofmesures[$tablealias.'.'.$key.'-sum'] = array(
71 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$langs->trans("Sum").')</span>',
72 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
73 'position' => ($position + ($count * 100000)).'.1',
74 'table' => $object->table_element,
75 'tablefromt' => $tablepath
76 );
77 $arrayofmesures[$tablealias.'.'.$key.'-average'] = array(
78 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$langs->trans("Average").')</span>',
79 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
80 'position' => ($position + ($count * 100000)).'.2',
81 'table' => $object->table_element,
82 'tablefromt' => $tablepath
83 );
84 $arrayofmesures[$tablealias.'.'.$key.'-min'] = array(
85 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$langs->trans("Minimum").')</span>',
86 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
87 'position' => ($position + ($count * 100000)).'.3',
88 'table' => $object->table_element,
89 'tablefromt' => $tablepath
90 );
91 $arrayofmesures[$tablealias.'.'.$key.'-max'] = array(
92 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$langs->trans("Maximum").')</span>',
93 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
94 'position' => ($position + ($count * 100000)).'.4',
95 'table' => $object->table_element,
96 'tablefromt' => $tablepath
97 );
98 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
99 $arrayofmesures[$tablealias.'.'.$key.'-stddevpop'] = array(
100 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$langs->trans("StandardDeviationPop").')</span>',
101 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
102 'position' => ($position + ($count * 100000)).'.5',
103 'table' => $object->table_element,
104 'tablefromt' => $tablepath
105 );
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($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 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
144 $arrayofmesures[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-stddevpop'] = 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("StandardDeviationPop").')</span>',
146 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
147 'position' => ($position + ($count * 100000)).'.5',
148 'table' => $object->table_element,
149 'tablefromt' => $tablepath
150 );
151 }
152 }
153 }
154 }
155 // Add fields for parent objects
156 foreach ($object->fields as $key => $val) {
157 if (preg_match('/^[^:]+:[^:]+:/', $val['type'])) {
158 $tmptype = explode(':', $val['type'], 4);
159 if ($tmptype[0] == 'integer' && !empty($tmptype[1]) && !empty($tmptype[2])) {
160 $newobject = $tmptype[1];
161 dol_include_once($tmptype[2]);
162 if (class_exists($newobject)) {
163 $tmpobject = new $newobject($db);
164 //var_dump($key); var_dump($tmpobject->element); var_dump($val['label']); var_dump($tmptype); var_dump('t-'.$key);
165 $count++;
166 $arrayofmesures = fillArrayOfMeasures($tmpobject, $tablealias.'__'.$key, $langs->trans($val['label']), $arrayofmesures, $level + 1, $count, $tablepath);
167 } else {
168 print 'For property '.$object->element.'->'.$key.', type="'.$val['type'].'": Failed to find class '.$newobject." in file ".$tmptype[2]."<br>\n";
169 }
170 }
171 }
172 }
173
174 return $arrayofmesures;
175}
176
177
190function fillArrayOfXAxis($object, $tablealias, $labelofobject, &$arrayofxaxis, $level = 0, &$count = 0, &$tablepath = '')
191{
192 global $langs, $extrafields, $db;
193
194 if (empty($object)) { // Protection against bad use of method
195 return array();
196 }
197 if ($level >= 3) { // Limit scan on 2 levels max
198 return $arrayofxaxis;
199 }
200
201 if (empty($tablepath)) {
202 $tablepath = $object->table_element.'='.$tablealias;
203 } else {
204 $tablepath .= ','.$object->table_element.'='.$tablealias;
205 }
206
207 $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);
208 $MM = substr($langs->trans("Month"), 0, 1).substr($langs->trans("Month"), 0, 1);
209 $DD = substr($langs->trans("Day"), 0, 1).substr($langs->trans("Day"), 0, 1);
210 $HH = substr($langs->trans("Hour"), 0, 1).substr($langs->trans("Hour"), 0, 1);
211 $MI = substr($langs->trans("Minute"), 0, 1).substr($langs->trans("Minute"), 0, 1);
212 $SS = substr($langs->trans("Second"), 0, 1).substr($langs->trans("Second"), 0, 1);
213
214 /*if ($level > 0) {
215 var_dump($object->element.' '.$object->isextrafieldmanaged);
216 }*/
217
218 // Note: here $tablealias can be 't' or 't__fk_contract' or 't_fk_contract_fk_soc'
219
220 // Add main fields of object
221 foreach ($object->fields as $key => $val) {
222 if (empty($val['measure'])) {
223 if (in_array($key, array(
224 'id', 'ref_ext', 'rowid', 'entity', 'last_main_doc', 'logo', 'logo_squarred', 'extraparams',
225 'parent', 'photo', 'socialnetworks', 'webservices_url', 'webservices_key'))) {
226 continue;
227 }
228 if (isset($val['enabled']) && ! (int) dol_eval($val['enabled'], 1, 1, '1')) {
229 continue;
230 }
231 if (isset($val['visible']) && ! (int) dol_eval($val['visible'], 1, 1, '1')) {
232 continue;
233 }
234 if (preg_match('/^fk_/', $key) && !preg_match('/^fk_statu/', $key)) {
235 continue;
236 }
237 if (preg_match('/^pass/', $key)) {
238 continue;
239 }
240 if (in_array($val['type'], array('html', 'text'))) {
241 continue;
242 }
243 if (in_array($val['type'], array('timestamp', 'date', 'datetime'))) {
244 $position = (empty($val['position']) ? 0 : intval($val['position']));
245 $arrayofxaxis[$tablealias.'.'.$key.'-year'] = array(
246 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$YYYY.')</span>',
247 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
248 'position' => ($position + ($count * 100000)).'.1',
249 'table' => $object->table_element,
250 'tablefromt' => $tablepath
251 );
252 $arrayofxaxis[$tablealias.'.'.$key.'-month'] = array(
253 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$YYYY.'-'.$MM.')</span>',
254 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
255 'position' => ($position + ($count * 100000)).'.2',
256 'table' => $object->table_element,
257 'tablefromt' => $tablepath
258 );
259 $arrayofxaxis[$tablealias.'.'.$key.'-day'] = array(
260 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$YYYY.'-'.$MM.'-'.$DD.')</span>',
261 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
262 'position' => ($position + ($count * 100000)).'.3',
263 'table' => $object->table_element,
264 'tablefromt' => $tablepath
265 );
266 } else {
267 $position = (empty($val['position']) ? 0 : intval($val['position']));
268 $arrayofxaxis[$tablealias.'.'.$key] = array(
269 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val['label']),
270 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
271 'position' => ($position + ($count * 100000)),
272 'table' => $object->table_element,
273 'tablefromt' => $tablepath
274 );
275 }
276 }
277 }
278
279 // Add extrafields to X-Axis
280 if (!empty($object->isextrafieldmanaged) && isset($extrafields->attributes[$object->table_element]['label'])) {
281 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
282 if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate') {
283 continue;
284 }
285 if (!empty($extrafields->attributes[$object->table_element]['totalizable'][$key])) {
286 continue;
287 }
288
289 if (in_array($extrafields->attributes[$object->table_element]['type'][$key], array('timestamp', 'date', 'datetime'))) {
290 $position = (empty($extrafields->attributes[$object->table_element]['pos'][$key]) ? 0 : intval($extrafields->attributes[$object->table_element]['pos'][$key]));
291 $arrayofxaxis[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-year'] = array(
292 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val).' <span class="opacitymedium">('.$YYYY.')</span>',
293 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
294 'position' => ($position + ($count * 100000)).'.1',
295 'table' => $object->table_element,
296 'tablefromt' => $tablepath
297 );
298 $arrayofxaxis[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-month'] = array(
299 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val).' <span class="opacitymedium">('.$YYYY.'-'.$MM.')</span>',
300 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
301 'position' => ($position + ($count * 100000)).'.2',
302 'table' => $object->table_element,
303 'tablefromt' => $tablepath
304 );
305 $arrayofxaxis[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-day'] = array(
306 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val).' <span class="opacitymedium">('.$YYYY.'-'.$MM.'-'.$DD.')</span>',
307 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
308 'position' => ($position + ($count * 100000)).'.3',
309 'table' => $object->table_element,
310 'tablefromt' => $tablepath
311 );
312 } else {
313 $arrayofxaxis[preg_replace('/^t/', 'te', $tablealias).'.'.$key] = array(
314 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val),
315 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
316 'position' => 1000 + (int) $extrafields->attributes[$object->table_element]['pos'][$key] + ($count * 100000),
317 'table' => $object->table_element,
318 'tablefromt' => $tablepath
319 );
320 }
321 }
322 }
323
324 // Add fields for parent objects
325 foreach ($object->fields as $key => $val) {
326 if (preg_match('/^[^:]+:[^:]+:/', $val['type'])) {
327 $tmptype = explode(':', $val['type'], 4);
328 if ($tmptype[0] == 'integer' && $tmptype[1] && $tmptype[2]) {
329 $newobject = $tmptype[1];
330 dol_include_once($tmptype[2]);
331 if (class_exists($newobject)) {
332 $tmpobject = new $newobject($db);
333 //var_dump($key); var_dump($tmpobject->element); var_dump($val['label']); var_dump($tmptype); var_dump('t-'.$key);
334 $count++;
335 $arrayofxaxis = fillArrayOfXAxis($tmpobject, $tablealias.'__'.$key, $langs->trans($val['label']), $arrayofxaxis, $level + 1, $count, $tablepath);
336 } else {
337 print 'For property '.$object->element.'->'.$key.', type="'.$val['type'].'": Failed to find class '.$newobject." in file ".$tmptype[2]."<br>\n";
338 }
339 }
340 }
341 }
342
343 return $arrayofxaxis;
344}
345
346
359function fillArrayOfGroupBy($object, $tablealias, $labelofobject, &$arrayofgroupby, $level = 0, &$count = 0, &$tablepath = '')
360{
361 global $langs, $extrafields, $db;
362
363 if (empty($object)) { // Protection against bad use of method
364 return array();
365 }
366 if ($level >= 3) {
367 return $arrayofgroupby;
368 }
369
370 if (empty($tablepath)) {
371 $tablepath = $object->table_element.'='.$tablealias;
372 } else {
373 $tablepath .= ','.$object->table_element.'='.$tablealias;
374 }
375
376 $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);
377 $MM = substr($langs->trans("Month"), 0, 1).substr($langs->trans("Month"), 0, 1);
378 $DD = substr($langs->trans("Day"), 0, 1).substr($langs->trans("Day"), 0, 1);
379 $HH = substr($langs->trans("Hour"), 0, 1).substr($langs->trans("Hour"), 0, 1);
380 $MI = substr($langs->trans("Minute"), 0, 1).substr($langs->trans("Minute"), 0, 1);
381 $SS = substr($langs->trans("Second"), 0, 1).substr($langs->trans("Second"), 0, 1);
382
383 // Note: here $tablealias can be 't' or 't__fk_contract' or 't_fk_contract_fk_soc'
384
385 // Add main fields of object
386 foreach ($object->fields as $key => $val) {
387 if (empty($val['isameasure'])) {
388 if (in_array($key, array(
389 'id', 'ref_ext', 'rowid', 'entity', 'last_main_doc', 'logo', 'logo_squarred', 'extraparams',
390 'parent', 'photo', 'socialnetworks', 'webservices_url', 'webservices_key'))) {
391 continue;
392 }
393 if (isset($val['enabled']) && ! (int) dol_eval($val['enabled'], 1, 1, '1')) {
394 continue;
395 }
396 if (isset($val['visible']) && ! (int) dol_eval($val['visible'], 1, 1, '1')) {
397 continue;
398 }
399 if (preg_match('/^fk_/', $key) && !preg_match('/^fk_statu/', $key)) {
400 continue;
401 }
402 if (preg_match('/^pass/', $key)) {
403 continue;
404 }
405 if (in_array($val['type'], array('html', 'text'))) {
406 continue;
407 }
408 if (in_array($val['type'], array('timestamp', 'date', 'datetime'))) {
409 $position = (empty($val['position']) ? 0 : intval($val['position']));
410 $arrayofgroupby[$tablealias.'.'.$key.'-year'] = array(
411 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$YYYY.')</span>',
412 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
413 'position' => ($position + ($count * 100000)).'.1',
414 'table' => $object->table_element,
415 'tablefromt' => $tablepath
416 );
417 $arrayofgroupby[$tablealias.'.'.$key.'-month'] = array(
418 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$YYYY.'-'.$MM.')</span>',
419 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
420 'position' => ($position + ($count * 100000)).'.2',
421 'table' => $object->table_element,
422 'tablefromt' => $tablepath
423 );
424 $arrayofgroupby[$tablealias.'.'.$key.'-day'] = array(
425 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val['label']).' <span class="opacitymedium">('.$YYYY.'-'.$MM.'-'.$DD.')</span>',
426 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
427 'position' => ($position + ($count * 100000)).'.3',
428 'table' => $object->table_element,
429 'tablefromt' => $tablepath
430 );
431 } else {
432 $position = (empty($val['position']) ? 0 : intval($val['position']));
433 $arrayofgroupby[$tablealias.'.'.$key] = array(
434 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val['label']),
435 'labelnohtml' => $labelofobject.': '.$langs->trans($val['label']),
436 'position' => ($position + ($count * 100000)),
437 'table' => $object->table_element,
438 'tablefromt' => $tablepath
439 );
440 }
441 }
442 }
443
444 // Add extrafields to Group by
445 if (!empty($object->isextrafieldmanaged) && isset($extrafields->attributes[$object->table_element]['label'])) {
446 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
447 if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate') {
448 continue;
449 }
450 if (!empty($extrafields->attributes[$object->table_element]['totalizable'][$key])) {
451 continue;
452 }
453
454 if (in_array($extrafields->attributes[$object->table_element]['type'][$key], array('timestamp', 'date', 'datetime'))) {
455 $position = (empty($extrafields->attributes[$object->table_element]['pos'][$key]) ? 0 : intval($extrafields->attributes[$object->table_element]['pos'][$key]));
456 $arrayofgroupby[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-year'] = array(
457 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val).' <span class="opacitymedium">('.$YYYY.')</span>',
458 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
459 'position' => ($position + ($count * 100000)).'.1',
460 'table' => $object->table_element,
461 'tablefromt' => $tablepath
462 );
463 $arrayofgroupby[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-month'] = array(
464 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val).' <span class="opacitymedium">('.$YYYY.'-'.$MM.')</span>',
465 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
466 'position' => ($position + ($count * 100000)).'.2',
467 'table' => $object->table_element,
468 'tablefromt' => $tablepath
469 );
470 $arrayofgroupby[preg_replace('/^t/', 'te', $tablealias).'.'.$key.'-day'] = array(
471 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val).' <span class="opacitymedium">('.$YYYY.'-'.$MM.'-'.$DD.')</span>',
472 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
473 'position' => ($position + ($count * 100000)).'.3',
474 'table' => $object->table_element,
475 'tablefromt' => $tablepath
476 );
477 } else {
478 $arrayofgroupby[preg_replace('/^t/', 'te', $tablealias).'.'.$key] = array(
479 'label' => img_picto('', (empty($object->picto) ? 'generic' : $object->picto), 'class="pictofixedwidth"').' '.$labelofobject.': '.$langs->trans($val),
480 'labelnohtml' => $labelofobject.': '.$langs->trans($val),
481 'position' => 1000 + (int) $extrafields->attributes[$object->table_element]['pos'][$key] + ($count * 100000),
482 'table' => $object->table_element,
483 'tablefromt' => $tablepath
484 );
485 }
486 }
487 }
488
489 // Add fields for parent objects
490 foreach ($object->fields as $key => $val) {
491 if (preg_match('/^[^:]+:[^:]+:/', $val['type'])) {
492 $tmptype = explode(':', $val['type'], 4);
493 if ($tmptype[0] == 'integer' && $tmptype[1] && $tmptype[2]) {
494 $newobject = $tmptype[1];
495 dol_include_once($tmptype[2]);
496 if (class_exists($newobject)) {
497 $tmpobject = new $newobject($db);
498 //var_dump($key); var_dump($tmpobject->element); var_dump($val['label']); var_dump($tmptype); var_dump('t-'.$key);
499 $count++;
500 $arrayofgroupby = fillArrayOfGroupBy($tmpobject, $tablealias.'__'.$key, $langs->trans($val['label']), $arrayofgroupby, $level + 1, $count, $tablepath);
501 } else {
502 print 'For property '.$object->element.'->'.$key.', type="'.$val['type'].'": Failed to find class '.$newobject." in file ".$tmptype[2]."<br>\n";
503 }
504 }
505 }
506 }
507
508 return $arrayofgroupby;
509}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
fillArrayOfGroupBy($object, $tablealias, $labelofobject, &$arrayofgroupby, $level=0, &$count=0, &$tablepath='')
Fill arrayofgrupby 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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.