dolibarr  16.0.5
commonfields_view.tpl.php
1 <?php
2 /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
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  * Need to have following variables defined:
18  * $object (invoice, order, ...)
19  * $action
20  * $conf
21  * $langs
22  *
23  * $keyforbreak may be defined to key to switch on second column
24  */
25 
26 // Protection to avoid direct call of template
27 if (empty($conf) || !is_object($conf)) {
28  print "Error, template page can't be called as URL";
29  exit;
30 }
31 if (!is_object($form)) {
32  $form = new Form($db);
33 }
34 
35 ?>
36 <!-- BEGIN PHP TEMPLATE commonfields_view.tpl.php -->
37 <?php
38 
39 $object->fields = dol_sort_array($object->fields, 'position');
40 
41 foreach ($object->fields as $key => $val) {
42  if (!empty($keyforbreak) && $key == $keyforbreak) {
43  break; // key used for break on second column
44  }
45 
46  // Discard if extrafield is a hidden field on form
47  if (abs($val['visible']) != 1 && abs($val['visible']) != 3 && abs($val['visible']) != 4 && abs($val['visible']) != 5) {
48  continue;
49  }
50 
51  if (array_key_exists('enabled', $val) && isset($val['enabled']) && !verifCond($val['enabled'])) {
52  continue; // We don't want this field
53  }
54  if (in_array($key, array('ref', 'status'))) {
55  continue; // Ref and status are already in dol_banner
56  }
57 
58  $value = $object->$key;
59 
60  print '<tr class="field_'.$key.'"><td';
61  print ' class="'.(empty($val['tdcss']) ? 'titlefield' : $val['tdcss']).' fieldname_'.$key;
62  //if ($val['notnull'] > 0) print ' fieldrequired'; // No fieldrequired on the view output
63  if ($val['type'] == 'text' || $val['type'] == 'html') {
64  print ' tdtop';
65  }
66  print '">';
67  if (!empty($val['help'])) {
68  print $form->textwithpicto($langs->trans($val['label']), $langs->trans($val['help']));
69  } else {
70  if (isset($val['copytoclipboard']) && $val['copytoclipboard'] == 1) {
71  print showValueWithClipboardCPButton($value, 0, $langs->transnoentitiesnoconv($val['label']));
72  } else {
73  print $langs->trans($val['label']);
74  }
75  }
76  print '</td>';
77  print '<td class="valuefield fieldname_'.$key;
78  if ($val['type'] == 'text') {
79  print ' wordbreak';
80  }
81  if (!empty($val['cssview'])) {
82  print ' '.$val['cssview'];
83  }
84  print '">';
85  if (in_array($val['type'], array('text', 'html'))) {
86  print '<div class="longmessagecut">';
87  }
88  if ($key == 'lang') {
89  $langs->load("languages");
90  $labellang = ($value ? $langs->trans('Language_'.$value) : '');
91  print picto_from_langcode($value, 'class="paddingrightonly saturatemedium opacitylow"');
92  print $labellang;
93  } else {
94  if (isset($val['copytoclipboard']) && $val['copytoclipboard'] == 2) {
95  $out = $object->showOutputField($val, $key, $value, '', '', '', 0);
96  print showValueWithClipboardCPButton($out, 0, $out);
97  } else {
98  print $object->showOutputField($val, $key, $value, '', '', '', 0);
99  }
100  }
101  //print dol_escape_htmltag($object->$key, 1, 1);
102  if (in_array($val['type'], array('text', 'html'))) {
103  print '</div>';
104  }
105  print '</td>';
106  print '</tr>';
107 }
108 
109 print '</table>';
110 
111 // We close div and reopen for second column
112 print '</div>';
113 
114 
115 $rightpart = '';
116 $alreadyoutput = 1;
117 foreach ($object->fields as $key => $val) {
118  if ($alreadyoutput) {
119  if (!empty($keyforbreak) && $key == $keyforbreak) {
120  $alreadyoutput = 0; // key used for break on second column
121  } else {
122  continue;
123  }
124  }
125 
126  // Discard if extrafield is a hidden field on form
127  if (abs($val['visible']) != 1 && abs($val['visible']) != 3 && abs($val['visible']) != 4 && abs($val['visible']) != 5) {
128  continue;
129  }
130 
131  if (array_key_exists('enabled', $val) && isset($val['enabled']) && !$val['enabled']) {
132  continue; // We don't want this field
133  }
134  if (in_array($key, array('ref', 'status'))) {
135  continue; // Ref and status are already in dol_banner
136  }
137 
138  $value = $object->$key;
139 
140  $rightpart .= '<tr><td';
141  $rightpart .= ' class="'.(empty($val['tdcss']) ? 'titlefield' : $val['tdcss']).' fieldname_'.$key;
142  //if ($val['notnull'] > 0) $rightpart .= ' fieldrequired'; // No fieldrequired inthe view output
143  if ($val['type'] == 'text' || $val['type'] == 'html') {
144  $rightpart .= ' tdtop';
145  }
146  $rightpart.= '">';
147  if (!empty($val['help'])) {
148  $rightpart .= $form->textwithpicto($langs->trans($val['label']), $langs->trans($val['help']));
149  } else {
150  $rightpart .= $langs->trans($val['label']);
151  }
152  $rightpart .= '</td>';
153  $rightpart .= '<td class="valuefield fieldname_'.$key;
154  if ($val['type'] == 'text') {
155  $rightpart .= ' wordbreak';
156  }
157  if (!empty($val['cssview'])) {
158  $rightpart .= ' '.$val['cssview'];
159  }
160  $rightpart .= '">';
161  if (in_array($val['type'], array('text', 'html'))) {
162  $rightpart .= '<div class="longmessagecut">';
163  }
164  $rightpart .= $object->showOutputField($val, $key, $value, '', '', '', 0);
165  //$rightpart .= dol_escape_htmltag($object->$key, 1, 1);
166  if (in_array($val['type'], array('text', 'html'))) {
167  $rightpart .= '</div>';
168  }
169  $rightpart .= '</td>';
170  $rightpart .= '</tr>';
171 }
172 
173 
174 print '<div class="fichehalfright">';
175 print '<div class="underbanner clearboth"></div>';
176 
177 print '<table class="border centpercent tableforfield">';
178 
179 print $rightpart;
180 
181 ?>
182 <!-- END PHP TEMPLATE commonfields_view.tpl.php -->
dol_sort_array
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
Definition: functions.lib.php:8385
verifCond
verifCond($strToEvaluate)
Verify if condition in string is ok or not.
Definition: functions.lib.php:8582
picto_from_langcode
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
Definition: functions.lib.php:8742
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
showValueWithClipboardCPButton
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
Definition: functions.lib.php:11087
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52