dolibarr 21.0.0-beta
extrafields_list_print_fields.tpl.php
1<?php
2/* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
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 *
17 */
18
25// Protection to avoid direct call of template
26if (empty($conf) || !is_object($conf)) {
27 print "Error, template page can't be called as URL";
28 exit(1);
29}
30
31if (empty($extrafieldsobjectkey) && is_object($object)) {
32 $extrafieldsobjectkey = $object->table_element;
33}
34
35// Loop to show all columns of extrafields from $obj, $extrafields and $db
36if (!empty($extrafieldsobjectkey) && !empty($extrafields->attributes[$extrafieldsobjectkey])) { // $extrafieldsobject is the $object->table_element like 'societe', 'socpeople', ...
37 if (array_key_exists('label', $extrafields->attributes[$extrafieldsobjectkey]) && is_array($extrafields->attributes[$extrafieldsobjectkey]['label']) && count($extrafields->attributes[$extrafieldsobjectkey]['label'])) {
38 if (empty($extrafieldsobjectprefix)) {
39 $extrafieldsobjectprefix = 'ef.';
40 }
41
42 foreach ($extrafields->attributes[$extrafieldsobjectkey]['label'] as $key => $val) {
43 if (!empty($arrayfields[$extrafieldsobjectprefix.$key]['checked'])) {
44 if ($extrafields->attributes[$extrafieldsobjectkey]['type'][$key] == 'separate') {
45 continue;
46 }
47
48 $cssclass = $extrafields->getAlignFlag($key, $extrafieldsobjectkey);
49
50 $tmpkey = 'options_'.$key;
51
52 if (in_array($extrafields->attributes[$extrafieldsobjectkey]['type'][$key], array('date', 'datetime', 'timestamp')) && isset($obj->$tmpkey) && !is_numeric($obj->$tmpkey)) {
53 $datenotinstring = $obj->$tmpkey;
54 if (!is_numeric($obj->$tmpkey)) { // For backward compatibility
55 $datenotinstring = $db->jdate($datenotinstring);
56 }
57 $value = $datenotinstring;
58 } elseif (in_array($extrafields->attributes[$extrafieldsobjectkey]['type'][$key], array('int'))) {
59 $value = (!empty($obj->$tmpkey) || $obj->$tmpkey === '0' ? $obj->$tmpkey : '');
60 } else {
61 // The key may be in $obj->array_options if not in $obj
62 $value = (isset($obj->$tmpkey) ? $obj->$tmpkey :
63 (isset($obj->array_options[$tmpkey]) ? $obj->array_options[$tmpkey] : '') );
64 }
65 // If field is a computed field, we make computation to get value
66 if ($extrafields->attributes[$extrafieldsobjectkey]['computed'][$key]) {
67 $objectoffield = $object; //For compatibility with the computed formula
68 $value = dol_eval((string) $extrafields->attributes[$extrafieldsobjectkey]['computed'][$key], 1, 1, '2');
69 if (is_numeric(price2num($value)) && $extrafields->attributes[$extrafieldsobjectkey]['totalizable'][$key]) {
70 $obj->$tmpkey = price2num($value);
71 }
72 }
73
74 $valuetoshow = $extrafields->showOutputField($key, $value, '', $extrafieldsobjectkey, null, $object);
75 $title = dol_string_nohtmltag($valuetoshow);
76
77 print '<td'.($cssclass ? ' class="'.$cssclass.'"' : ''); // TODO Add 'css' and 'cssview' and 'csslist' for extrafields and use here 'csslist'
78 print ' data-key="'.$extrafieldsobjectkey.'.'.$key.'"';
79 print($title ? ' title="'.dol_escape_htmltag($title).'"' : '');
80 print '>';
81 print $valuetoshow;
82 print '</td>';
83
84 if (!$i) {
85 if (empty($totalarray)) {
86 $totalarray['nbfield'] = 0;
87 }
88 $totalarray['nbfield']++;
89 }
90
91 if (!empty($extrafields->attributes[$extrafieldsobjectkey]['totalizable'][$key])) {
92 if (!$i) {
93 // we keep position for the first line
94 $totalarray['totalizable'][$key]['pos'] = $totalarray['nbfield'];
95 }
96 if (isset($obj->$tmpkey) && is_numeric($obj->$tmpkey)) {
97 if (!isset($totalarray['totalizable'][$key]['total'])) {
98 $totalarray['totalizable'][$key]['total'] = 0;
99 }
100 $totalarray['totalizable'][$key]['total'] += $obj->$tmpkey;
101 }
102 }
103 // The key 'totalizable' on extrafields, is the same as 'isameasure' into ->fields
104 if (!empty($extrafields->attributes[$extrafieldsobjectkey]['totalizable'][$key]) && $extrafields->attributes[$extrafieldsobjectkey]['totalizable'][$key] == 1) {
105 if (!$i) {
106 $totalarray['pos'][$totalarray['nbfield']] = $extrafieldsobjectprefix.$tmpkey;
107 }
108 if (!isset($totalarray['val'])) {
109 $totalarray['val'] = array();
110 }
111 if (!isset($totalarray['val'][$extrafieldsobjectprefix.$tmpkey])) {
112 $totalarray['val'][$extrafieldsobjectprefix.$tmpkey] = 0;
113 }
114 if (isset($obj->$tmpkey) && is_numeric($obj->$tmpkey)) {
115 if (!isset($totalarray['val'][$extrafieldsobjectprefix.$tmpkey])) {
116 $totalarray['val'][$extrafieldsobjectprefix.$tmpkey] = 0;
117 }
118 $totalarray['val'][$extrafieldsobjectprefix.$tmpkey] += $obj->$tmpkey;
119 }
120 }
121 }
122 }
123 }
124}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79