dolibarr 18.0.6
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 } else {
33 $value = (!empty($obj->$tmpkey) ? $obj->$tmpkey : '');
34 }
35 // If field is a computed field, we make computation to get value
36 if ($extrafields->attributes[$extrafieldsobjectkey]['computed'][$key]) {
37 //global $obj, $object;
38 //var_dump($extrafields->attributes[$extrafieldsobjectkey]['computed'][$key]);
39 //var_dump($obj);
40 //var_dump($extrafields->attributes[$extrafieldsobjectkey]['computed'][$key]);
41 $value = dol_eval($extrafields->attributes[$extrafieldsobjectkey]['computed'][$key], 1, 1, '0');
42 if (is_numeric(price2num($value)) && $extrafields->attributes[$extrafieldsobjectkey]['totalizable'][$key]) {
43 $obj->$tmpkey = price2num($value);
44 }
45 //var_dump($value);
46 }
47
48 $valuetoshow = $extrafields->showOutputField($key, $value, '', $extrafieldsobjectkey);
49 $title = dol_string_nohtmltag($valuetoshow);
50
51 print '<td'.($cssclass ? ' class="'.$cssclass.'"' : ''); // TODO Add 'css' and 'cssview' and 'csslist' for extrafields and use here 'csslist'
52 print ' data-key="'.$extrafieldsobjectkey.'.'.$key.'"';
53 print ($title ? ' title="'.dol_escape_htmltag($title).'"' : '');
54 print '>';
55 print $valuetoshow;
56 print '</td>';
57
58 if (!$i) {
59 if (empty($totalarray)) {
60 $totalarray['nbfield'] = 0;
61 }
62 $totalarray['nbfield']++;
63 }
64
65 if ($extrafields->attributes[$extrafieldsobjectkey]['totalizable'][$key]) {
66 if (!$i) {
67 // we keep position for the first line
68 $totalarray['totalizable'][$key]['pos'] = $totalarray['nbfield'];
69 }
70 if (isset($obj->$tmpkey) && is_numeric($obj->$tmpkey)) {
71 if (!isset($totalarray['totalizable'][$key]['total'])) {
72 $totalarray['totalizable'][$key]['total'] = 0;
73 }
74 $totalarray['totalizable'][$key]['total'] += $obj->$tmpkey;
75 }
76 }
77 if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
78 if (!$i) {
79 $totalarray['pos'][$totalarray['nbfield']] = $extrafieldsobjectprefix.$tmpkey;
80 }
81 if (!isset($totalarray['val'])) {
82 $totalarray['val'] = array();
83 }
84 if (!isset($totalarray['val'][$extrafieldsobjectprefix.$tmpkey])) {
85 $totalarray['val'][$extrafieldsobjectprefix.$tmpkey] = 0;
86 }
87 $totalarray['val'][$extrafieldsobjectprefix.$tmpkey] += $obj->$tmpkey;
88 }
89 }
90 }
91 }
92}
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...