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