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