dolibarr 20.0.0
depreciation_options_edit.tpl.php
1<?php
2/* Copyright (C) 2021 Open-Dsi <support@open-dsi.fr>
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 * Show extrafields. It also show fields from hook formAssetAccountancyCode. Need to have following variables defined:
18 * $object (asset, assetmodel, ...)
19 * $assetaccountancycodes
20 * $action
21 * $conf
22 * $langs
23 *
24 * $parameters
25 */
26
27// Protection to avoid direct call of template
28if (empty($object) || !is_object($object)) {
29 print "Error, template page can't be called as URL";
30 exit(1);
31}
32
33if (!is_object($form)) {
34 $form = new Form($db);
35}
36
37if (!isset($formadmin) || !is_object($formadmin)) {
38 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formadmin.class.php';
39 $formadmin = new FormAdmin($db);
40}
41
42
43?>
44<!-- BEGIN PHP TEMPLATE depreciation_options_edit.tpl.php -->
45<?php
46
47if (!is_array($parameters)) {
48 $parameters = array();
49}
50$enabled_field_info = array();
51if (empty($parameters['enabled_field_info'])) {
52 $parameters['enabled_field_info'] = &$enabled_field_info;
53}
54if (empty($parameters['assetdepreciationoptions'])) {
55 $parameters['assetdepreciationoptions'] = &$assetdepreciationoptions;
56}
57$reshook = $hookmanager->executeHooks('formAssetDeprecationOptions', $parameters, $object, $action);
58print $hookmanager->resPrint;
59if ($reshook < 0) {
60 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
61}
62
63if (empty($reshook)) {
64 $class_type = get_class($object) == 'Asset' ? 0 : 1;
65 foreach ($assetdepreciationoptions->deprecation_options_fields as $mode_key => $mode_info) {
66 if (!empty($mode_info['enabled_field'])) {
67 $info = explode(':', $mode_info['enabled_field']);
68 $enabled_field_info[] = array(
69 'mode_key' => $info[0],
70 'field_key' => $info[1],
71 'value' => $info[2],
72 'target' => 'block_' . $mode_key,
73 );
74 }
75
76 $assetdepreciationoptions->setInfosForMode($mode_key, $class_type, true);
77 $prefix_html_name = $mode_key . '_';
78 $width = ($mode_key == "economic")? "width50p pull-left" : "width50p";
79 print '<table class="border '. $width .'" id="block_' . $mode_key . '">' . "\n";
80 print '<tr><td class="info-box-title">'.$langs->trans($mode_info['label']).'</td></tr>';
81 if ($mode_key == "economic") {
82 print '<hr>';
83 }
84 $mode_info['fields'] = dol_sort_array($mode_info['fields'], 'position');
85 foreach ($mode_info['fields'] as $field_key => $field_info) {
86 // Discard if extrafield is a hidden field on form
87 if (abs($field_info['visible']) != 1 && abs($field_info['visible']) != 3 && abs($field_info['visible']) != 4) {
88 continue;
89 }
90 if (array_key_exists('enabled', $field_info) && isset($field_info['enabled']) && !verifCond($field_info['enabled'])) {
91 continue; // We don't want this field
92 }
93
94
95 $html_name = $prefix_html_name . $field_key;
96 if (!empty($field_info['enabled_field'])) {
97 $info = explode(':', $field_info['enabled_field']);
98 $enabled_field_info[] = array(
99 'mode_key' => $info[0],
100 'field_key' => $info[1],
101 'value' => $info[2],
102 'target' => 'field_' . $html_name,
103 );
104 }
105
106 $more_class = '';
107 if (!empty($field_info['required'])) {
108 $more_class .= 'width40p fieldrequired';
109 }
110 if (isset($val['type']) && preg_match('/^(text|html)/', $val['type'])) {
111 $more_class .= ' tdtop';
112 }
113
114 print '<tr class="field_' . $html_name . '" id="field_' . $html_name . '"><td';
115 print ' class="' . $more_class . '">';
116 if (!empty($field_info['help'])) {
117 print $form->textwithpicto($langs->trans($field_info['label']), $langs->trans($field_info['help']));
118 } else {
119 print $langs->trans($field_info['label']);
120 }
121 print '</td>';
122 print '<td class="valuefieldcreate">';
123 if (!empty($field_info['picto'])) {
124 print img_picto('', $field_info['picto'], '', false, 0, 0, '', 'pictofixedwidth');
125 }
126 if (in_array($field_info['type'], array('int', 'integer'))) {
127 $value = GETPOSTISSET($html_name) ? GETPOSTINT($html_name) : $assetdepreciationoptions->$field_key;
128 } elseif ($field_info['type'] == 'double') {
129 $value = GETPOSTISSET($html_name) ? price2num(GETPOST($html_name, 'alphanohtml')) : $assetdepreciationoptions->$field_key;
130 } elseif (preg_match('/^(text|html)/', $field_info['type'])) {
131 $tmparray = explode(':', $field_info['type']);
132 if (!empty($tmparray[1])) {
133 $check = $tmparray[1];
134 } else {
135 $check = 'restricthtml';
136 }
137 $value = GETPOSTISSET($html_name) ? GETPOST($html_name, $check) : $assetdepreciationoptions->$field_key;
138 } elseif ($field_info['type'] == 'price') {
139 $value = GETPOSTISSET($html_name) ? price2num(GETPOST($html_name)) : ($assetdepreciationoptions->$field_key ? price2num($assetdepreciationoptions->$field_key) : (!empty($field_info['default']) ? $field_info['default'] : 0));
140 } elseif ($field_key == 'lang') {
141 $value = GETPOSTISSET($html_name) ? GETPOST($html_name, 'aZ09') : $assetdepreciationoptions->lang;
142 } else {
143 $value = GETPOSTISSET($html_name) ? GETPOST($html_name, 'alpha') : $assetdepreciationoptions->$field_key;
144 }
145 if (!empty($field_info['noteditable'])) {
146 print $assetdepreciationoptions->showOutputField($field_info, $field_key, $value, '', '', $prefix_html_name, 0);
147 } else {
148 if ($field_key == 'lang') {
149 print img_picto('', 'language', 'class="pictofixedwidth"');
150 print $formadmin->select_language($value, $html_name, 0, null, 1, 0, 0, 'minwidth300', 2);
151 } else {
152 print $assetdepreciationoptions->showInputField($field_info, $field_key, $value, '', '', $prefix_html_name, 0);
153 }
154 }
155 print '</td>';
156 print '</tr>';
157 }
158 print '</table>';
159 }
160 print '<div class="clearboth"></div>';
161}
162
163if (!empty($enabled_field_info)) {
164 $enabled_field_info = json_encode($enabled_field_info);
165 print <<<SCRIPT
166<script type="text/javascript">
167 jQuery(document).ready(function () {
168 var enabled_field_info = $enabled_field_info;
169
170 // Init fields
171 enabled_field_info.map(function(info) {
172 var html_name = info.mode_key + '_' + info.field_key;
173 var source = $('#' + html_name);
174 if (!(source.length > 0)) source = $('[name="' + html_name + '"]');
175 if (source.length > 0) {
176 source.attr('data-asset-enabled-field-value', info.value);
177 source.attr('data-asset-enabled-field-target', info.target);
178 updateEnabledField(source);
179 source.on('change click', function() {
180 updateEnabledField(jQuery(this));
181 });
182 }
183 });
184
185 function updateEnabledField(_this) {
186 var value = _this.attr('data-asset-enabled-field-value');
187 var target_name = _this.attr('data-asset-enabled-field-target');
188
189 // for block mode
190 var target = $('table#' + target_name);
191
192 // for field
193 if (!(target.length > 0)) {
194 target = $('#' + target_name);
195 if (!(target.length > 0)) target = $('[name="' + target_name + '"]');
196 if (target.length > 0) target = target.closest('tr');
197 }
198
199 if (target.length > 0) {
200 var source_value = _this.attr('type') == 'checkbox' ? (_this.is(':checked') ? 1 : 0) : _this.val();
201
202 if (source_value != value) {
203 target.hide();
204 } else {
205 target.show();
206 }
207 }
208 }
209 });
210</script>
211SCRIPT;
212}
213
214?>
215<!-- END PHP TEMPLATE depreciation_options_edit.tpl.php -->
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:139