dolibarr 21.0.0-alpha
extrafields_list_print_fields.tpl.php
1<?php
2/* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
3 */
4
5// Protection to avoid direct call of template
6if (empty($conf) || !is_object($conf)) {
7 print "Error, template page can't be called as URL";
8 exit(1);
9}
10
11if (empty($extrafieldsobjectkey) && is_object($object)) {
12 $extrafieldsobjectkey = $object->table_element;
13}
14
15// Loop to show all columns of extrafields from $obj, $extrafields and $db
16if (!empty($extrafieldsobjectkey) && !empty($extrafields->attributes[$extrafieldsobjectkey])) { // $extrafieldsobject is the $object->table_element like 'societe', 'socpeople', ...
17 if (array_key_exists('label', $extrafields->attributes[$extrafieldsobjectkey]) && is_array($extrafields->attributes[$extrafieldsobjectkey]['label']) && count($extrafields->attributes[$extrafieldsobjectkey]['label'])) {
18 if (empty($extrafieldsobjectprefix)) {
19 $extrafieldsobjectprefix = 'ef.';
20 }
21
22 foreach ($extrafields->attributes[$extrafieldsobjectkey]['label'] as $key => $val) {
23 if (!empty($arrayfields[$extrafieldsobjectprefix.$key]['checked'])) {
24 if ($extrafields->attributes[$extrafieldsobjectkey]['type'][$key] == 'separate') {
25 continue;
26 }
27
28 $cssclass = $extrafields->getAlignFlag($key, $extrafieldsobjectkey);
29
30 $tmpkey = 'options_'.$key;
31
32 if (in_array($extrafields->attributes[$extrafieldsobjectkey]['type'][$key], array('date', 'datetime', 'timestamp')) && isset($obj->$tmpkey) && !is_numeric($obj->$tmpkey)) {
33 $datenotinstring = $obj->$tmpkey;
34 if (!is_numeric($obj->$tmpkey)) { // For backward compatibility
35 $datenotinstring = $db->jdate($datenotinstring);
36 }
37 $value = $datenotinstring;
38 } elseif (in_array($extrafields->attributes[$extrafieldsobjectkey]['type'][$key], array('int'))) {
39 $value = (!empty($obj->$tmpkey) || $obj->$tmpkey === '0' ? $obj->$tmpkey : '');
40 } else {
41 // The key may be in $obj->array_options if not in $obj
42 $value = (isset($obj->$tmpkey) ? $obj->$tmpkey :
43 (isset($obj->array_options[$tmpkey]) ? $obj->array_options[$tmpkey] : '') );
44 }
45 // If field is a computed field, we make computation to get value
46 if ($extrafields->attributes[$extrafieldsobjectkey]['computed'][$key]) {
47 $objectoffield = $object; //For compatibility with the computed formula
48 $value = dol_eval((string) $extrafields->attributes[$extrafieldsobjectkey]['computed'][$key], 1, 1, '2');
49 if (is_numeric(price2num($value)) && $extrafields->attributes[$extrafieldsobjectkey]['totalizable'][$key]) {
50 $obj->$tmpkey = price2num($value);
51 }
52 }
53
54 $valuetoshow = $extrafields->showOutputField($key, $value, '', $extrafieldsobjectkey);
55 $title = dol_string_nohtmltag($valuetoshow);
56
57 print '<td'.($cssclass ? ' class="'.$cssclass.'"' : ''); // TODO Add 'css' and 'cssview' and 'csslist' for extrafields and use here 'csslist'
58 print ' data-key="'.$extrafieldsobjectkey.'.'.$key.'"';
59 print($title ? ' title="'.dol_escape_htmltag($title).'"' : '');
60 print '>';
61 print $valuetoshow;
62 print '</td>';
63
64 if (!$i) {
65 if (empty($totalarray)) {
66 $totalarray['nbfield'] = 0;
67 }
68 $totalarray['nbfield']++;
69 }
70
71 if (!empty($extrafields->attributes[$extrafieldsobjectkey]['totalizable'][$key])) {
72 if (!$i) {
73 // we keep position for the first line
74 $totalarray['totalizable'][$key]['pos'] = $totalarray['nbfield'];
75 }
76 if (isset($obj->$tmpkey) && is_numeric($obj->$tmpkey)) {
77 if (!isset($totalarray['totalizable'][$key]['total'])) {
78 $totalarray['totalizable'][$key]['total'] = 0;
79 }
80 $totalarray['totalizable'][$key]['total'] += $obj->$tmpkey;
81 }
82 }
83 // The key 'totalizable' on extrafields, is the same as 'isameasure' into ->fields
84 if (!empty($extrafields->attributes[$extrafieldsobjectkey]['totalizable'][$key]) && $extrafields->attributes[$extrafieldsobjectkey]['totalizable'][$key] == 1) {
85 if (!$i) {
86 $totalarray['pos'][$totalarray['nbfield']] = $extrafieldsobjectprefix.$tmpkey;
87 }
88 if (!isset($totalarray['val'])) {
89 $totalarray['val'] = array();
90 }
91 if (!isset($totalarray['val'][$extrafieldsobjectprefix.$tmpkey])) {
92 $totalarray['val'][$extrafieldsobjectprefix.$tmpkey] = 0;
93 }
94 if (isset($obj->$tmpkey) && is_numeric($obj->$tmpkey)) {
95 if (!isset($totalarray['val'][$extrafieldsobjectprefix.$tmpkey])) {
96 $totalarray['val'][$extrafieldsobjectprefix.$tmpkey] = 0;
97 }
98 $totalarray['val'][$extrafieldsobjectprefix.$tmpkey] += $obj->$tmpkey;
99 }
100 }
101 }
102 }
103 }
104}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...