dolibarr 24.0.0-beta
commonfields_add.tpl.php
1<?php
2/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2025 Benjamin Falière <benjamin@faliere.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 *
20 * Need to have the following variables defined:
21 * $object (invoice, order, ...)
22 * $action
23 * $conf
24 * $langs
25 * $form
26 */
36'@phan-var-force FormAdmin $formadmin';
37
38// Protection to avoid direct call of template
39if (empty($conf) || !is_object($conf)) {
40 print "Error, template page can't be called as URL";
41 exit(1);
42}
43
44?>
45<!-- BEGIN PHP TEMPLATE commonfields_add.tpl.php -->
46<?php
47
48$object->fields = dol_sort_array($object->fields, 'position');
49
50foreach ($object->fields as $key => $val) {
51 // Discard if field is a hidden field on form
52 // Ensure $val['visible'] is treated as an integer
53 $visible = (int) $val['visible'];
54 if (abs($visible) != 1 && abs($visible) != 3 && abs($visible) != 6) {
55 continue;
56 }
57
58 if (array_key_exists('enabled', $val) && isset($val['enabled']) && !verifCond($val['enabled'])) {
59 continue; // We don't want this field
60 }
61
62 print '<tr class="field_'.$key.'">';
63 print '<td';
64 print ' class="titlefieldcreate';
65 if (isset($val['notnull']) && $val['notnull'] > 0) {
66 print ' fieldrequired';
67 }
68 if ($val['type'] == 'text' || $val['type'] == 'html') {
69 print ' tdtop';
70 }
71 print '"';
72 print '>';
73 print '<label for="'.$key.'" class="block">';
74 if (!empty($val['help'])) {
75 print $form->textwithpicto($langs->trans($val['label']), $langs->trans($val['help']));
76 } else {
77 print $langs->trans($val['label']);
78 }
79 print '</label>';
80 print '</td>';
81 print '<td class="valuefieldcreate">';
82 if (!empty($val['picto'])) {
83 print img_picto('', $val['picto'], '', 0, 0, 0, '', 'pictofixedwidth');
84 }
85 if (in_array($val['type'], array('int', 'integer'))) {
86 $value = GETPOST($key); // We must not use GETPOSTINT in creation form because value can still be ""
87 } elseif ($val['type'] == 'double') {
88 $value = price2num(GETPOST($key, 'alphanohtml'));
89 } elseif (preg_match('/^text/', $val['type'])) {
90 $tmparray = explode(':', $val['type']);
91 if (!empty($tmparray[1])) {
92 $check = $tmparray[1];
93 } else {
94 $check = 'nohtml';
95 }
96 $value = GETPOST($key, $check);
97 } elseif (preg_match('/^html/', $val['type'])) {
98 $tmparray = explode(':', $val['type']);
99 if (!empty($tmparray[1])) {
100 $check = $tmparray[1];
101 } else {
102 $check = 'restricthtml';
103 }
104 $value = GETPOST($key, $check);
105 } elseif ($val['type'] == 'date') {
106 $value = dol_mktime(12, 0, 0, GETPOSTINT($key.'month'), GETPOSTINT($key.'day'), GETPOSTINT($key.'year'));
107 } elseif ($val['type'] == 'datetime') {
108 $value = dol_mktime(GETPOSTINT($key.'hour'), GETPOSTINT($key.'min'), 0, GETPOSTINT($key.'month'), GETPOSTINT($key.'day'), GETPOSTINT($key.'year'));
109 } elseif ($val['type'] == 'boolean') {
110 $value = (GETPOST($key) == 'on' ? 1 : 0);
111 } elseif ($val['type'] == 'price') {
112 $value = price2num(GETPOST($key));
113 } elseif ($key == 'lang') {
114 $value = GETPOST($key, 'aZ09');
115 } else {
116 $value = GETPOST($key, 'alphanohtml');
117 }
118 if (!empty($val['noteditable'])) {
119 print $object->showOutputField($val, $key, $value, '', '', '', 0);
120 } else {
121 if ($key == 'lang') {
122 print img_picto('', 'language', 'class="pictofixedwidth"');
123 print $formadmin->select_language($value, $key, 0, array(), 1, 0, 0, 'minwidth300', 2);
124 } else {
125 if (isset($val['notnull']) && $val['notnull'] > 0 && empty($value)) {
126 // $value = 'ifone'; // TODO Implement this
127 }
128 print $object->showInputField($val, $key, $value, '', '', '', 0);
129 }
130 }
131 print '</td>';
132 print '</tr>';
133}
134
135?>
136<!-- END PHP TEMPLATE commonfields_add.tpl.php -->
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
verifCond($strToEvaluate, $onlysimplestring='1')
Verify if condition in string is ok or not.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.