dolibarr 23.0.4
depreciation_options_edit.tpl.php
1<?php
2/* Copyright (C) 2021 Open-Dsi <support@open-dsi.fr>
3 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024 José <jose.martinez@pichinov.com>
5 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.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 * Show extrafields. It also shows fields from hook formAssetAccountancyCode. Need to have the following variables defined:
21 * $object (asset, assetmodel, ...)
22 * $assetaccountancycodes
23 * $action
24 * $conf
25 * $langs
26 *
27 * $parameters
28 */
29
41'
42@phan-var-force Conf $conf
43@phan-var-force DoliDB $db
44@phan-var-force ?Form $form
45@phan-var-force HookManager $hookmanager
46@phan-var-force AssetDepreciationOptions $assetdepreciationoptions
47@phan-var-force Translate $langs
48@phan-var-force ?array<array{mode_key:string,field_key:string,value:string,target:string}> $enabled_field_info
49';
50
51// Protection to avoid direct call of template
52if (empty($object) || !is_object($object)) {
53 print "Error, template page can't be called as URL";
54 exit(1);
55}
56
57if (!is_object($form)) {
58 $form = new Form($db);
59}
60
61if (!isset($formadmin) || !is_object($formadmin)) {
62 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formadmin.class.php';
63 $formadmin = new FormAdmin($db);
64}
65
66
67?>
68<!-- BEGIN PHP TEMPLATE depreciation_options_edit.tpl.php -->
69<?php
70
71if (!is_array($parameters)) {
72 $parameters = array();
73}
74$enabled_field_info = array();
75if (empty($parameters['enabled_field_info'])) {
76 $parameters['enabled_field_info'] = &$enabled_field_info;
77}
78if (empty($parameters['assetdepreciationoptions'])) {
79 $parameters['assetdepreciationoptions'] = &$assetdepreciationoptions;
80}
81$reshook = $hookmanager->executeHooks('formAssetDeprecationOptions', $parameters, $object, $action);
82print $hookmanager->resPrint;
83if ($reshook < 0) {
84 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
85}
86
87if (empty($reshook)) {
88 $class_type = get_class($object) == 'Asset' ? 0 : 1;
89 foreach ($assetdepreciationoptions->deprecation_options_fields as $mode_key => $mode_info) {
90 if (!empty($mode_info['enabled_field'])) {
91 $info = explode(':', $mode_info['enabled_field']);
92 $enabled_field_info[] = array(
93 'mode_key' => $info[0],
94 'field_key' => $info[1],
95 'value' => $info[2],
96 'target' => 'block_' . $mode_key,
97 );
98 }
99
100 $assetdepreciationoptions->setInfosForMode($mode_key, $class_type, true);
101 $prefix_html_name = $mode_key . '_';
102 $width = ($mode_key == "economic") ? "width50p pull-left" : "width50p";
103 print '<table class="border '. $width .'" id="block_' . $mode_key . '">' . "\n";
104 print '<tr><td class="info-box-title">'.$langs->trans($mode_info['label']).'</td></tr>';
105 if ($mode_key == "economic") {
106 print '<hr>';
107 }
108 $mode_info['fields'] = dol_sort_array($mode_info['fields'], 'position');
109 foreach ($mode_info['fields'] as $field_key => $field_info) {
110 // Discard if extrafield is a hidden field on form
111 if (abs($field_info['visible']) != 1 && abs($field_info['visible']) != 3 && abs($field_info['visible']) != 4) {
112 continue;
113 }
114 if (array_key_exists('enabled', $field_info) && isset($field_info['enabled']) && !verifCond($field_info['enabled'])) {
115 continue; // We don't want this field
116 }
117 // This loop walks the raw definition of the fields, not the one filtered by
118 // setInfosForMode(), so the fields reserved to an asset must be discarded here too
119 if (!empty($field_info['only_on_asset']) && !empty($class_type)) {
120 continue;
121 }
122
123
124 $html_name = $prefix_html_name . $field_key;
125 if (!empty($field_info['enabled_field'])) {
126 $info = explode(':', $field_info['enabled_field']);
127 $enabled_field_info[] = array(
128 'mode_key' => $info[0],
129 'field_key' => $info[1],
130 'value' => $info[2],
131 'target' => 'field_' . $html_name,
132 );
133 }
134
135 $more_class = '';
136 if (!empty($field_info['required'])) {
137 $more_class .= 'width40p fieldrequired';
138 }
139 if (isset($val['type']) && preg_match('/^(text|html)/', $val['type'])) {
140 $more_class .= ' tdtop';
141 }
142
143 print '<tr class="field_' . $html_name . '" id="field_' . $html_name . '"><td';
144 print ' class="' . $more_class . '">';
145 if (!empty($field_info['help'])) {
146 print $form->textwithpicto($langs->trans($field_info['label']), $langs->trans($field_info['help']));
147 } else {
148 print $langs->trans($field_info['label']);
149 }
150 print '</td>';
151 print '<td class="valuefieldcreate">';
152 if (!empty($field_info['picto'])) {
153 print img_picto('', $field_info['picto'], '', 0, 0, 0, '', 'pictofixedwidth');
154 }
155 if (in_array($field_info['type'], array('int', 'integer'))) {
156 $value = GETPOSTISSET($html_name) ? GETPOSTINT($html_name) : $assetdepreciationoptions->$field_key;
157 } elseif ($field_info['type'] == 'double') {
158 $value = GETPOSTISSET($html_name) ? price2num(GETPOST($html_name, 'alphanohtml')) : $assetdepreciationoptions->$field_key;
159 } elseif (preg_match('/^(text|html)/', $field_info['type'])) {
160 $tmparray = explode(':', $field_info['type']);
161 if (!empty($tmparray[1])) {
162 $check = $tmparray[1];
163 } else {
164 $check = 'restricthtml';
165 }
166 $value = GETPOSTISSET($html_name) ? GETPOST($html_name, $check) : $assetdepreciationoptions->$field_key;
167 } elseif ($field_info['type'] == 'price') {
168 $value = GETPOSTISSET($html_name) ? price2num(GETPOST($html_name)) : ($assetdepreciationoptions->$field_key ? price2num($assetdepreciationoptions->$field_key) : (!empty($field_info['default']) ? dol_eval((string) $field_info['default'], 1) : 0));
169 } else {
170 $value = GETPOSTISSET($html_name) ? GETPOST($html_name, 'alpha') : $assetdepreciationoptions->$field_key;
171 }
172 if (!empty($field_info['noteditable'])) {
173 print $assetdepreciationoptions->showOutputField($field_info, $field_key, $value, '', '', $prefix_html_name, 0);
174 } else {
175 if ($field_key == 'lang') {
176 print img_picto('', 'language', 'class="pictofixedwidth"');
177 print $formadmin->select_language($value, $html_name, 0, array(), 1, 0, 0, 'minwidth300', 2);
178 } else {
179 print $assetdepreciationoptions->showInputField($field_info, $field_key, $value, '', '', $prefix_html_name, 0);
180 }
181 }
182 print '</td>';
183 print '</tr>';
184 }
185 print '</table>';
186 }
187 print '<div class="clearboth"></div>';
188}
189
190if (!empty($enabled_field_info)) {
191 $enabled_field_info = json_encode($enabled_field_info);
192 print <<<SCRIPT
193<script type="text/javascript">
194 jQuery(document).ready(function () {
195 var enabled_field_info = $enabled_field_info;
196
197 // Init fields
198 enabled_field_info.map(function(info) {
199 var html_name = info.mode_key + '_' + info.field_key;
200 var source = $('#' + html_name);
201 if (!(source.length > 0)) source = $('[name="' + html_name + '"]');
202 if (source.length > 0) {
203 source.attr('data-asset-enabled-field-value', info.value);
204 source.attr('data-asset-enabled-field-target', info.target);
205 updateEnabledField(source);
206 source.on('change click', function() {
207 updateEnabledField(jQuery(this));
208 });
209 }
210 });
211
212 function updateEnabledField(_this) {
213 var value = _this.attr('data-asset-enabled-field-value');
214 var target_name = _this.attr('data-asset-enabled-field-target');
215
216 // for block mode
217 var target = $('table#' + target_name);
218
219 // for field
220 if (!(target.length > 0)) {
221 target = $('#' + target_name);
222 if (!(target.length > 0)) target = $('[name="' + target_name + '"]');
223 if (target.length > 0) target = target.closest('tr');
224 }
225
226 if (target.length > 0) {
227 var source_value = _this.attr('type') == 'checkbox' ? (_this.is(':checked') ? 1 : 0) : _this.val();
228
229 if (source_value != value) {
230 target.hide();
231 } else {
232 target.show();
233 }
234 }
235 }
236 });
237</script>
238SCRIPT;
239}
240
241?>
242<!-- END PHP TEMPLATE depreciation_options_edit.tpl.php -->
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Class to generate html code for admin pages.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
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.
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition repair.php:132