dolibarr 21.0.0-beta
commonfields_view.tpl.php
1<?php
2/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 *
18 * Need to have the following variables defined:
19 * $object (invoice, order, ...)
20 * $action
21 * $conf
22 * $langs
23 *
24 * $keyforbreak may be defined to key to switch on second column
25 */
26
37// Protection to avoid direct call of template
38if (empty($conf) || !is_object($conf)) {
39 print "Error, template page can't be called as URL";
40 exit(1);
41}
42if (!is_object($form)) {
43 $form = new Form($db);
44}
45
46?>
47<!-- BEGIN PHP TEMPLATE commonfields_view.tpl.php -->
48<?php
49
50$object->fields = dol_sort_array($object->fields, 'position');
51
52foreach ($object->fields as $key => $val) {
53 if (!empty($keyforbreak) && $key == $keyforbreak) {
54 break; // key used for break on second column
55 }
56
57 // Discard if extrafield is a hidden field on form
58 if (abs($val['visible']) != 1 && abs($val['visible']) != 3 && abs($val['visible']) != 4 && abs($val['visible']) != 5) {
59 continue;
60 }
61 if (array_key_exists('enabled', $val) && isset($val['enabled']) && !verifCond($val['enabled'])) {
62 continue; // We don't want this field
63 }
64
65 if (in_array($key, array('rowid', 'ref', 'status'))) {
66 continue; // rowid, ref and status are already in dol_banner
67 }
68
69 $value = $object->$key;
70
71 print '<tr class="field_'.$key.'"><td';
72 print ' class="'.(empty($val['tdcss']) ? 'titlefieldmiddle' : $val['tdcss']).' fieldname_'.$key;
73 //if ($val['notnull'] > 0) print ' fieldrequired'; // No fieldrequired on the view output
74 if ($val['type'] == 'text' || $val['type'] == 'html') {
75 print ' tdtop';
76 }
77 print '">';
78
79 $labeltoshow = '';
80 if (!empty($val['help'])) {
81 $labeltoshow .= $form->textwithpicto($langs->trans($val['label']), $langs->trans($val['help']));
82 } else {
83 if (isset($val['copytoclipboard']) && $val['copytoclipboard'] == 1) {
84 $labeltoshow .= showValueWithClipboardCPButton($value, 0, $langs->transnoentitiesnoconv($val['label']));
85 } else {
86 $labeltoshow .= $langs->trans($val['label']);
87 }
88 }
89 if (empty($val['alwayseditable'])) {
90 print $labeltoshow;
91 } else {
92 print $form->editfieldkey($labeltoshow, $key, $value, $object, 1, $val['type']);
93 }
94
95 print '</td>';
96 print '<td class="valuefield fieldname_'.$key;
97 if ($val['type'] == 'text') {
98 print ' wordbreak';
99 }
100 if (!empty($val['cssview'])) {
101 print ' '.$val['cssview'];
102 }
103 print '">';
104 if (empty($val['alwayseditable'])) {
105 if (preg_match('/^(text|html)/', $val['type'])) {
106 print '<div class="longmessagecut">';
107 }
108 if ($key == 'lang') {
109 $langs->load("languages");
110 $labellang = ($value ? $langs->trans('Language_'.$value) : '');
111 print picto_from_langcode($value, 'class="paddingrightonly saturatemedium opacitylow"');
112 print $labellang;
113 } else {
114 if (isset($val['copytoclipboard']) && $val['copytoclipboard'] == 2) {
115 $out = $object->showOutputField($val, $key, $value, '', '', '', 0);
116 print showValueWithClipboardCPButton($out, 0, $out);
117 } else {
118 print $object->showOutputField($val, $key, $value, '', '', '', 0);
119 }
120 }
121 //print dol_escape_htmltag($object->$key, 1, 1);
122 if (preg_match('/^(text|html)/', $val['type'])) {
123 print '</div>';
124 }
125 } else {
126 print $form->editfieldval($labeltoshow, $key, $value, $object, 1, $val['type']);
127 }
128 print '</td>';
129 print '</tr>';
130}
131
132print '</table>';
133
134// We close div and reopen for second column
135print '</div>';
136
137
138$rightpart = '';
139$alreadyoutput = 1;
140foreach ($object->fields as $key => $val) {
141 if ($alreadyoutput) {
142 if (!empty($keyforbreak) && $key == $keyforbreak) {
143 $alreadyoutput = 0; // key used for break on second column
144 } else {
145 continue;
146 }
147 }
148
149 // Discard if extrafield is a hidden field on form
150 if (abs($val['visible']) != 1 && abs($val['visible']) != 3 && abs($val['visible']) != 4 && abs($val['visible']) != 5) {
151 continue;
152 }
153
154 if (array_key_exists('enabled', $val) && isset($val['enabled']) && !$val['enabled']) {
155 continue; // We don't want this field
156 }
157 if (in_array($key, array('ref', 'status'))) {
158 continue; // Ref and status are already in dol_banner
159 }
160
161 $value = $object->$key;
162
163 $rightpart .= '<tr><td';
164 $rightpart .= ' class="'.(empty($val['tdcss']) ? 'titlefield' : $val['tdcss']).' fieldname_'.$key;
165 //if ($val['notnull'] > 0) $rightpart .= ' fieldrequired'; // No fieldrequired in the view output
166 if ($val['type'] == 'text' || $val['type'] == 'html') {
167 $rightpart .= ' tdtop';
168 }
169 $rightpart.= '">';
170 $labeltoshow = '';
171 if (!empty($val['help'])) {
172 $labeltoshow .= $form->textwithpicto($langs->trans($val['label']), $langs->trans($val['help']));
173 } else {
174 if (isset($val['copytoclipboard']) && $val['copytoclipboard'] == 1) {
175 $labeltoshow .= showValueWithClipboardCPButton($value, 0, $langs->transnoentitiesnoconv($val['label']));
176 } else {
177 $labeltoshow .= $langs->trans($val['label']);
178 }
179 }
180 if (empty($val['alwayseditable'])) {
181 $rightpart .= $labeltoshow;
182 } else {
183 $rightpart .= $form->editfieldkey($labeltoshow, $key, $value, $object, 1, $val['type']);
184 }
185 $rightpart .= '</td>';
186 $rightpart .= '<td class="valuefield fieldname_'.$key;
187 if ($val['type'] == 'text') {
188 $rightpart .= ' wordbreak';
189 }
190 if (!empty($val['cssview'])) {
191 $rightpart .= ' '.$val['cssview'];
192 }
193 $rightpart .= '">';
194
195 if (empty($val['alwayseditable'])) {
196 if (preg_match('/^(text|html)/', $val['type'])) {
197 $rightpart .= '<div class="longmessagecut">';
198 }
199 if ($key == 'lang') {
200 $langs->load("languages");
201 $labellang = ($value ? $langs->trans('Language_'.$value) : '');
202 $rightpart .= picto_from_langcode($value, 'class="paddingrightonly saturatemedium opacitylow"');
203 $rightpart .= $labellang;
204 } else {
205 if (isset($val['copytoclipboard']) && $val['copytoclipboard'] == 2) {
206 $out = $object->showOutputField($val, $key, $value, '', '', '', 0);
207 $rightpart .= showValueWithClipboardCPButton($out, 0, $out);
208 } else {
209 $rightpart.= $object->showOutputField($val, $key, $value, '', '', '', 0);
210 }
211 }
212 if (preg_match('/^(text|html)/', $val['type'])) {
213 $rightpart .= '</div>';
214 }
215 } else {
216 $rightpart .= $form->editfieldval($labeltoshow, $key, $value, $object, 1, $val['type']);
217 }
218
219 $rightpart .= '</td>';
220 $rightpart .= '</tr>';
221}
222
223
224print '<div class="fichehalfright">';
225if (empty($nounderbanner)) {
226 print '<div class="underbanner clearboth"></div>';
227}
228print '<table class="border centpercent tableforfield">';
229
230print $rightpart;
231
232?>
233<!-- END PHP TEMPLATE commonfields_view.tpl.php -->
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
Class to manage generation of HTML components Only common components must be here.
verifCond($strToEvaluate, $onlysimplestring='1')
Verify if condition in string is ok or not.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79