dolibarr 18.0.6
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;
31}
32
33if (!is_object($form)) {
34 $form = new Form($db);
35}
36
37if (!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
79 print '<div id="block_' . $mode_key . '">';
80 print load_fiche_titre($langs->trans($mode_info['label']), '', '');
81 print '<div class="fichecenter">';
82 print '<div class="fichehalfleft">';
83 print '<div class="underbanner clearboth"></div>';
84 print '<table class="border centpercent tableforfield">' . "\n";
85 $mode_info['fields'] = dol_sort_array($mode_info['fields'], 'position');
86 foreach ($mode_info['fields'] as $field_key => $field_info) {
87 // Discard if extrafield is a hidden field on form
88 if (abs($field_info['visible']) != 1 && abs($field_info['visible']) != 3 && abs($field_info['visible']) != 4) {
89 continue;
90 }
91 if (array_key_exists('enabled', $field_info) && isset($field_info['enabled']) && !verifCond($field_info['enabled'])) {
92 continue; // We don't want this field
93 }
94 if (!empty($field_info['column_break'])) {
95 print '</table>';
96
97 // We close div and reopen for second column
98 print '</div>';
99 print '<div class="fichehalfright">';
100
101 print '<div class="underbanner clearboth"></div>';
102 print '<table class="border centpercent tableforfield">';
103 }
104
105 $html_name = $prefix_html_name . $field_key;
106 if (!empty($field_info['enabled_field'])) {
107 $info = explode(':', $field_info['enabled_field']);
108 $enabled_field_info[] = array(
109 'mode_key' => $info[0],
110 'field_key' => $info[1],
111 'value' => $info[2],
112 'target' => 'field_' . $html_name,
113 );
114 }
115
116 $more_class = '';
117 if (!empty($field_info['required']) || (isset($field_info['notnull']) && $field_info['notnull'] > 0)) {
118 $more_class .= ' fieldrequired';
119 }
120 if (preg_match('/^(text|html)/', $val['type'])) {
121 $more_class .= ' tdtop';
122 }
123
124 print '<tr class="field_' . $html_name . '" id="field_' . $html_name . '"><td';
125 print ' class="titlefieldcreate' . $more_class . '">';
126 if (!empty($field_info['help'])) {
127 print $form->textwithpicto($langs->trans($field_info['label']), $langs->trans($field_info['help']));
128 } else {
129 print $langs->trans($field_info['label']);
130 }
131 print '</td>';
132 print '<td class="valuefieldcreate">';
133 if (!empty($field_info['picto'])) {
134 print img_picto('', $field_info['picto'], '', false, 0, 0, '', 'pictofixedwidth');
135 }
136 if (in_array($field_info['type'], array('int', 'integer'))) {
137 $value = GETPOSTISSET($html_name) ?GETPOST($html_name, 'int') : $assetdepreciationoptions->$field_key;
138 } elseif ($field_info['type'] == 'double') {
139 $value = GETPOSTISSET($html_name) ? price2num(GETPOST($html_name, 'alphanohtml')) : $assetdepreciationoptions->$field_key;
140 } elseif (preg_match('/^(text|html)/', $field_info['type'])) {
141 $tmparray = explode(':', $field_info['type']);
142 if (!empty($tmparray[1])) {
143 $check = $tmparray[1];
144 } else {
145 $check = 'restricthtml';
146 }
147 $value = GETPOSTISSET($html_name) ? GETPOST($html_name, $check) : $assetdepreciationoptions->$field_key;
148 } elseif ($field_info['type'] == 'price') {
149 $value = GETPOSTISSET($html_name) ? price2num(GETPOST($html_name)) : ($assetdepreciationoptions->$field_key ? price2num($assetdepreciationoptions->$field_key) : (!empty($field_info['default']) ? dol_eval($field_info['default'], 1) : 0));
150 } elseif ($field_key == 'lang') {
151 $value = GETPOSTISSET($html_name) ? GETPOST($html_name, 'aZ09') : $assetdepreciationoptions->lang;
152 } else {
153 $value = GETPOSTISSET($html_name) ? GETPOST($html_name, 'alpha') : $assetdepreciationoptions->$field_key;
154 }
155 if (!empty($field_info['noteditable'])) {
156 print $assetdepreciationoptions->showOutputField($field_info, $field_key, $value, '', '', $prefix_html_name, 0);
157 } else {
158 if ($field_key == 'lang') {
159 print img_picto('', 'language', 'class="pictofixedwidth"');
160 print $formadmin->select_language($value, $html_name, 0, null, 1, 0, 0, 'minwidth300', 2);
161 } else {
162 print $assetdepreciationoptions->showInputField($field_info, $field_key, $value, '', '', $prefix_html_name, 0);
163 }
164 }
165 print '</td>';
166 print '</tr>';
167 }
168 print '</table>';
169 print '</div>';
170 print '</div>';
171 print '<div class="clearboth"></div>';
172 print '</div>';
173 }
174}
175
176if (!empty($enabled_field_info)) {
177 $enabled_field_info = json_encode($enabled_field_info);
178 print <<<SCRIPT
179<script type="text/javascript">
180 jQuery(document).ready(function () {
181 var enabled_field_info = $enabled_field_info;
182
183 // Init fields
184 enabled_field_info.map(function(info) {
185 var html_name = info.mode_key + '_' + info.field_key;
186 var source = $('#' + html_name);
187 if (!(source.length > 0)) source = $('[name="' + html_name + '"]');
188 if (source.length > 0) {
189 source.attr('data-asset-enabled-field-value', info.value);
190 source.attr('data-asset-enabled-field-target', info.target);
191 updateEnabledField(source);
192 source.on('change click', function() {
193 updateEnabledField(jQuery(this));
194 });
195 }
196 });
197
198 function updateEnabledField(_this) {
199 var value = _this.attr('data-asset-enabled-field-value');
200 var target_name = _this.attr('data-asset-enabled-field-target');
201
202 // for block mode
203 var target = $('div#' + target_name);
204
205 // for field
206 if (!(target.length > 0)) {
207 target = $('#' + target_name);
208 if (!(target.length > 0)) target = $('[name="' + target_name + '"]');
209 if (target.length > 0) target = target.closest('tr');
210 }
211
212 if (target.length > 0) {
213 var source_value = _this.attr('type') == 'checkbox' ? (_this.is(':checked') ? 1 : 0) : _this.val();
214
215 if (source_value != value) {
216 target.hide();
217 } else {
218 target.show();
219 }
220 }
221 }
222 });
223</script>
224SCRIPT;
225}
226
227?>
228<!-- END PHP TEMPLATE depreciation_options_edit.tpl.php -->
Class to generate html code for admin pages.
Class to manage generation of HTML components Only common components must be here.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
dol_eval($s, $returnvalue=0, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
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.
verifCond($strToEvaluate)
Verify if condition in string is ok or not.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:120