dolibarr 24.0.0-beta
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.
21 */
22
36'
37@phan-var-force Conf $conf
38@phan-var-force DoliDB $db
39@phan-var-force ?Form $form
40@phan-var-force HookManager $hookmanager
41@phan-var-force AssetDepreciationOptions $assetdepreciationoptions
42@phan-var-force Translate $langs
43@phan-var-force ?array<array{mode_key:string,field_key:string,value:string,target:string}> $enabled_field_info
44';
45
46// Protection to avoid direct call of template
47if (empty($object) || !is_object($object)) {
48 print "Error, template page can't be called as URL";
49 exit(1);
50}
51
52if (!is_object($form)) {
53 $form = new Form($db);
54}
55
56if (!isset($formadmin) || !is_object($formadmin)) {
57 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formadmin.class.php';
58 $formadmin = new FormAdmin($db);
59}
60
61
62?>
63<!-- BEGIN PHP TEMPLATE depreciation_options_edit.tpl.php -->
64<?php
65
66if (!is_array($parameters)) {
67 $parameters = array();
68}
69$enabled_field_info = array();
70if (empty($parameters['enabled_field_info'])) {
71 $parameters['enabled_field_info'] = &$enabled_field_info;
72}
73if (empty($parameters['assetdepreciationoptions'])) {
74 $parameters['assetdepreciationoptions'] = &$assetdepreciationoptions;
75}
76$reshook = $hookmanager->executeHooks('formAssetDeprecationOptions', $parameters, $object, $action);
77print $hookmanager->resPrint;
78if ($reshook < 0) {
79 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
80}
81
82if (empty($reshook)) {
83 $class_type = get_class($object) == 'Asset' ? 0 : 1;
84 foreach ($assetdepreciationoptions->deprecation_options_fields as $mode_key => $mode_info) {
85 if (!empty($mode_info['enabled_field'])) {
86 $info = explode(':', $mode_info['enabled_field']);
87 $enabled_field_info[] = array(
88 'mode_key' => $info[0],
89 'field_key' => $info[1],
90 'value' => $info[2],
91 'target' => 'block_' . $mode_key,
92 );
93 }
94
95 $assetdepreciationoptions->setInfosForMode($mode_key, $class_type, true);
96 $prefix_html_name = $mode_key . '_';
97 $width = ($mode_key == "economic") ? "width50p pull-left" : "width50p";
98 print '<table class="border '. $width .'" id="block_' . $mode_key . '">' . "\n";
99 print '<tr><td class="info-box-title">'.$langs->trans($mode_info['label']).'</td></tr>';
100 if ($mode_key == "economic") {
101 print '<hr>';
102 }
103 $mode_info['fields'] = dol_sort_array($mode_info['fields'], 'position');
104 foreach ($mode_info['fields'] as $field_key => $field_info) {
105 // Discard if extrafield is a hidden field on form
106 if (abs($field_info['visible']) != 1 && abs($field_info['visible']) != 3 && abs($field_info['visible']) != 4) {
107 continue;
108 }
109 if (array_key_exists('enabled', $field_info) && isset($field_info['enabled']) && !verifCond($field_info['enabled'])) {
110 continue; // We don't want this field
111 }
112
113
114 $html_name = $prefix_html_name . $field_key;
115 if (!empty($field_info['enabled_field'])) {
116 $info = explode(':', $field_info['enabled_field']);
117 $enabled_field_info[] = array(
118 'mode_key' => $info[0],
119 'field_key' => $info[1],
120 'value' => $info[2],
121 'target' => 'field_' . $html_name,
122 );
123 }
124
125 $more_class = '';
126 if (!empty($field_info['required'])) {
127 $more_class .= 'width40p fieldrequired';
128 }
129 if (isset($val['type']) && preg_match('/^(text|html)/', $val['type'])) {
130 $more_class .= ' tdtop';
131 }
132
133 print '<tr class="field_' . $html_name . '" id="field_' . $html_name . '"><td';
134 print ' class="' . $more_class . '">';
135 if (!empty($field_info['help'])) {
136 print $form->textwithpicto($langs->trans($field_info['label']), $langs->trans($field_info['help']));
137 } else {
138 print $langs->trans($field_info['label']);
139 }
140 print '</td>';
141 print '<td class="valuefieldcreate">';
142 if (!empty($field_info['picto'])) {
143 print img_picto('', $field_info['picto'], '', 0, 0, 0, '', 'pictofixedwidth');
144 }
145 if (in_array($field_info['type'], array('int', 'integer'))) {
146 $value = GETPOSTISSET($html_name) ? GETPOSTINT($html_name) : $assetdepreciationoptions->$field_key;
147 } elseif ($field_info['type'] == 'double') {
148 $value = GETPOSTISSET($html_name) ? price2num(GETPOST($html_name, 'alphanohtml')) : $assetdepreciationoptions->$field_key;
149 } elseif (preg_match('/^(text|html)/', $field_info['type'])) {
150 $tmparray = explode(':', $field_info['type']);
151 if (!empty($tmparray[1])) {
152 $check = $tmparray[1];
153 } else {
154 $check = 'restricthtml';
155 }
156 $value = GETPOSTISSET($html_name) ? GETPOST($html_name, $check) : $assetdepreciationoptions->$field_key;
157 } elseif ($field_info['type'] == 'price') {
158 $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));
159 } else {
160 $value = GETPOSTISSET($html_name) ? GETPOST($html_name, 'alpha') : $assetdepreciationoptions->$field_key;
161 }
162 if (!empty($field_info['noteditable'])) {
163 print $assetdepreciationoptions->showOutputField($field_info, $field_key, $value, '', '', $prefix_html_name, 0);
164 } else {
165 if ($field_key == 'lang') {
166 print img_picto('', 'language', 'class="pictofixedwidth"');
167 print $formadmin->select_language($value, $html_name, 0, array(), 1, 0, 0, 'minwidth300', 2);
168 } else {
169 print $assetdepreciationoptions->showInputField($field_info, $field_key, $value, '', '', $prefix_html_name, 0);
170 }
171 }
172 print '</td>';
173 print '</tr>';
174 }
175 print '</table>';
176 }
177 print '<div class="clearboth"></div>';
178}
179
180if (!empty($enabled_field_info)) {
181 $enabled_field_info = json_encode($enabled_field_info);
182 print <<<SCRIPT
183<script type="text/javascript">
184 jQuery(document).ready(function () {
185 var enabled_field_info = $enabled_field_info;
186
187 // Init fields
188 enabled_field_info.map(function(info) {
189 var html_name = info.mode_key + '_' + info.field_key;
190 var source = $('#' + html_name);
191 if (!(source.length > 0)) source = $('[name="' + html_name + '"]');
192 if (source.length > 0) {
193 source.attr('data-asset-enabled-field-value', info.value);
194 source.attr('data-asset-enabled-field-target', info.target);
195 updateEnabledField(source);
196 source.on('change click', function() {
197 updateEnabledField(jQuery(this));
198 });
199 }
200 });
201
202 function updateEnabledField(_this) {
203 var value = _this.attr('data-asset-enabled-field-value');
204 var target_name = _this.attr('data-asset-enabled-field-target');
205
206 // for block mode
207 var target = $('table#' + target_name);
208
209 // for field
210 if (!(target.length > 0)) {
211 target = $('#' + target_name);
212 if (!(target.length > 0)) target = $('[name="' + target_name + '"]');
213 if (target.length > 0) target = target.closest('tr');
214 }
215
216 if (target.length > 0) {
217 var source_value = _this.attr('type') == 'checkbox' ? (_this.is(':checked') ? 1 : 0) : _this.val();
218
219 if (source_value != value) {
220 target.hide();
221 } else {
222 target.show();
223 }
224 }
225 }
226 });
227</script>
228SCRIPT;
229}
230
231?>
232<!-- 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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
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:130