dolibarr 21.0.0-alpha
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 the 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
27if (empty($conf) || !is_object($conf)) {
28 print "Error, template page can't be called as URL";
29 exit(1);
30}
31if (!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
41foreach ($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 if (array_key_exists('enabled', $val) && isset($val['enabled']) && !verifCond($val['enabled'])) {
51 continue; // We don't want this field
52 }
53
54 if (in_array($key, array('rowid', 'ref', 'status'))) {
55 continue; // rowid, 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']) ? 'titlefieldmiddle' : $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
68 $labeltoshow = '';
69 if (!empty($val['help'])) {
70 $labeltoshow .= $form->textwithpicto($langs->trans($val['label']), $langs->trans($val['help']));
71 } else {
72 if (isset($val['copytoclipboard']) && $val['copytoclipboard'] == 1) {
73 $labeltoshow .= showValueWithClipboardCPButton($value, 0, $langs->transnoentitiesnoconv($val['label']));
74 } else {
75 $labeltoshow .= $langs->trans($val['label']);
76 }
77 }
78 if (empty($val['alwayseditable'])) {
79 print $labeltoshow;
80 } else {
81 print $form->editfieldkey($labeltoshow, $key, $value, $object, 1, $val['type']);
82 }
83
84 print '</td>';
85 print '<td class="valuefield fieldname_'.$key;
86 if ($val['type'] == 'text') {
87 print ' wordbreak';
88 }
89 if (!empty($val['cssview'])) {
90 print ' '.$val['cssview'];
91 }
92 print '">';
93 if (empty($val['alwayseditable'])) {
94 if (preg_match('/^(text|html)/', $val['type'])) {
95 print '<div class="longmessagecut">';
96 }
97 if ($key == 'lang') {
98 $langs->load("languages");
99 $labellang = ($value ? $langs->trans('Language_'.$value) : '');
100 print picto_from_langcode($value, 'class="paddingrightonly saturatemedium opacitylow"');
101 print $labellang;
102 } else {
103 if (isset($val['copytoclipboard']) && $val['copytoclipboard'] == 2) {
104 $out = $object->showOutputField($val, $key, $value, '', '', '', 0);
105 print showValueWithClipboardCPButton($out, 0, $out);
106 } else {
107 print $object->showOutputField($val, $key, $value, '', '', '', 0);
108 }
109 }
110 //print dol_escape_htmltag($object->$key, 1, 1);
111 if (preg_match('/^(text|html)/', $val['type'])) {
112 print '</div>';
113 }
114 } else {
115 print $form->editfieldval($labeltoshow, $key, $value, $object, 1, $val['type']);
116 }
117 print '</td>';
118 print '</tr>';
119}
120
121print '</table>';
122
123// We close div and reopen for second column
124print '</div>';
125
126
127$rightpart = '';
128$alreadyoutput = 1;
129foreach ($object->fields as $key => $val) {
130 if ($alreadyoutput) {
131 if (!empty($keyforbreak) && $key == $keyforbreak) {
132 $alreadyoutput = 0; // key used for break on second column
133 } else {
134 continue;
135 }
136 }
137
138 // Discard if extrafield is a hidden field on form
139 if (abs($val['visible']) != 1 && abs($val['visible']) != 3 && abs($val['visible']) != 4 && abs($val['visible']) != 5) {
140 continue;
141 }
142
143 if (array_key_exists('enabled', $val) && isset($val['enabled']) && !$val['enabled']) {
144 continue; // We don't want this field
145 }
146 if (in_array($key, array('ref', 'status'))) {
147 continue; // Ref and status are already in dol_banner
148 }
149
150 $value = $object->$key;
151
152 $rightpart .= '<tr><td';
153 $rightpart .= ' class="'.(empty($val['tdcss']) ? 'titlefield' : $val['tdcss']).' fieldname_'.$key;
154 //if ($val['notnull'] > 0) $rightpart .= ' fieldrequired'; // No fieldrequired in the view output
155 if ($val['type'] == 'text' || $val['type'] == 'html') {
156 $rightpart .= ' tdtop';
157 }
158 $rightpart.= '">';
159 $labeltoshow = '';
160 if (!empty($val['help'])) {
161 $labeltoshow .= $form->textwithpicto($langs->trans($val['label']), $langs->trans($val['help']));
162 } else {
163 if (isset($val['copytoclipboard']) && $val['copytoclipboard'] == 1) {
164 $labeltoshow .= showValueWithClipboardCPButton($value, 0, $langs->transnoentitiesnoconv($val['label']));
165 } else {
166 $labeltoshow .= $langs->trans($val['label']);
167 }
168 }
169 if (empty($val['alwayseditable'])) {
170 $rightpart .= $labeltoshow;
171 } else {
172 $rightpart .= $form->editfieldkey($labeltoshow, $key, $value, $object, 1, $val['type']);
173 }
174 $rightpart .= '</td>';
175 $rightpart .= '<td class="valuefield fieldname_'.$key;
176 if ($val['type'] == 'text') {
177 $rightpart .= ' wordbreak';
178 }
179 if (!empty($val['cssview'])) {
180 $rightpart .= ' '.$val['cssview'];
181 }
182 $rightpart .= '">';
183
184 if (empty($val['alwayseditable'])) {
185 if (preg_match('/^(text|html)/', $val['type'])) {
186 $rightpart .= '<div class="longmessagecut">';
187 }
188 if ($key == 'lang') {
189 $langs->load("languages");
190 $labellang = ($value ? $langs->trans('Language_'.$value) : '');
191 $rightpart .= picto_from_langcode($value, 'class="paddingrightonly saturatemedium opacitylow"');
192 $rightpart .= $labellang;
193 } else {
194 if (isset($val['copytoclipboard']) && $val['copytoclipboard'] == 2) {
195 $out = $object->showOutputField($val, $key, $value, '', '', '', 0);
196 $rightpart .= showValueWithClipboardCPButton($out, 0, $out);
197 } else {
198 $rightpart.= $object->showOutputField($val, $key, $value, '', '', '', 0);
199 }
200 }
201 if (preg_match('/^(text|html)/', $val['type'])) {
202 $rightpart .= '</div>';
203 }
204 } else {
205 $rightpart .= $form->editfieldval($labeltoshow, $key, $value, $object, 1, $val['type']);
206 }
207
208 $rightpart .= '</td>';
209 $rightpart .= '</tr>';
210}
211
212
213print '<div class="fichehalfright">';
214if (empty($nounderbanner)) {
215 print '<div class="underbanner clearboth"></div>';
216}
217print '<table class="border centpercent tableforfield">';
218
219print $rightpart;
220
221?>
222<!-- END PHP TEMPLATE commonfields_view.tpl.php -->
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
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...