dolibarr 19.0.3
extrafields_list_print_fields.tpl.php
1<?php
2
3// Protection to avoid direct call of template
4if (empty($conf) || !is_object($conf)) {
5 print "Error, template page can't be called as URL";
6 exit;
7}
8
9if (empty($extrafieldsobjectkey) && is_object($object)) {
10 $extrafieldsobjectkey = $object->table_element;
11}
12
13// Loop to show all columns of extrafields from $obj, $extrafields and $db
14if (!empty($extrafieldsobjectkey) && !empty($extrafields->attributes[$extrafieldsobjectkey])) { // $extrafieldsobject is the $object->table_element like 'societe', 'socpeople', ...
15 if (key_exists('label', $extrafields->attributes[$extrafieldsobjectkey]) && is_array($extrafields->attributes[$extrafieldsobjectkey]['label']) && count($extrafields->attributes[$extrafieldsobjectkey]['label'])) {
16 if (empty($extrafieldsobjectprefix)) {
17 $extrafieldsobjectprefix = 'ef.';
18 }
19
20 foreach ($extrafields->attributes[$extrafieldsobjectkey]['label'] as $key => $val) {
21 if (!empty($arrayfields[$extrafieldsobjectprefix.$key]['checked'])) {
22 $cssclass = $extrafields->getAlignFlag($key, $extrafieldsobjectkey);
23
24 $tmpkey = 'options_'.$key;
25
26 if (in_array($extrafields->attributes[$extrafieldsobjectkey]['type'][$key], array('date', 'datetime', 'timestamp')) && isset($obj->$tmpkey) && !is_numeric($obj->$tmpkey)) {
27 $datenotinstring = $obj->$tmpkey;
28 if (!is_numeric($obj->$tmpkey)) { // For backward compatibility
29 $datenotinstring = $db->jdate($datenotinstring);
30 }
31 $value = $datenotinstring;
32 } elseif (in_array($extrafields->attributes[$extrafieldsobjectkey]['type'][$key], array('int'))) {
33 $value = (!empty($obj->$tmpkey) || $obj->$tmpkey === '0' ? $obj->$tmpkey : '');
34 } else {
35 $value = (!empty($obj->$tmpkey) ? $obj->$tmpkey : '');
36 }
37 // If field is a computed field, we make computation to get value
38 if ($extrafields->attributes[$extrafieldsobjectkey]['computed'][$key]) {
39 $objectoffield = $object; //For compatibily with the computed formula
40 $value = dol_eval($extrafields->attributes[$extrafieldsobjectkey]['computed'][$key], 1, 1, '2');
41 if (is_numeric(price2num($value)) && $extrafields->attributes[$extrafieldsobjectkey]['totalizable'][$key]) {
42 $obj->$tmpkey = price2num($value);
43 }
44 //var_dump($value);
45 }
46
47 $valuetoshow = $extrafields->showOutputField($key, $value, '', $extrafieldsobjectkey);
48 $title = dol_string_nohtmltag($valuetoshow);
49
50 print '<td'.($cssclass ? ' class="'.$cssclass.'"' : ''); // TODO Add 'css' and 'cssview' and 'csslist' for extrafields and use here 'csslist'
51 print ' data-key="'.$extrafieldsobjectkey.'.'.$key.'"';
52 print($title ? ' title="'.dol_escape_htmltag($title).'"' : '');
53 print '>';
54 print $valuetoshow;
55 print '</td>';
56
57 if (!$i) {
58 if (empty($totalarray)) {
59 $totalarray['nbfield'] = 0;
60 }
61 $totalarray['nbfield']++;
62 }
63
64 if ($extrafields->attributes[$extrafieldsobjectkey]['totalizable'][$key]) {
65 if (!$i) {
66 // we keep position for the first line
67 $totalarray['totalizable'][$key]['pos'] = $totalarray['nbfield'];
68 }
69 if (isset($obj->$tmpkey) && is_numeric($obj->$tmpkey)) {
70 if (!isset($totalarray['totalizable'][$key]['total'])) {
71 $totalarray['totalizable'][$key]['total'] = 0;
72 }
73 $totalarray['totalizable'][$key]['total'] += $obj->$tmpkey;
74 }
75 }
76 if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
77 if (!$i) {
78 $totalarray['pos'][$totalarray['nbfield']] = $extrafieldsobjectprefix.$tmpkey;
79 }
80 if (!isset($totalarray['val'])) {
81 $totalarray['val'] = array();
82 }
83 if (!isset($totalarray['val'][$extrafieldsobjectprefix.$tmpkey])) {
84 $totalarray['val'][$extrafieldsobjectprefix.$tmpkey] = 0;
85 }
86 $totalarray['val'][$extrafieldsobjectprefix.$tmpkey] += $obj->$tmpkey;
87 }
88 }
89 }
90 }
91}
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=0, $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...