dolibarr 23.0.3
depreciation_options_view.tpl.php
1<?php
2/* Copyright (C) 2021 Open-Dsi <support@open-dsi.fr>
3 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 *
19 * Show extrafields. It also shows fields from hook formAssetAccountancyCode. Need to have the following variables defined:
20 * $object (asset, assetmodel, ...)
21 * $assetaccountancycodes
22 * $action
23 * $conf
24 * $langs
25 *
26 * $parameters
27 */
28
36'
37@phan-var-force ?Form $form
38@phan-var-force HookManager $hookmanager
39@phan-var-force AssetDepreciationOptions $assetdepreciationoptions
40';
41
42// Protection to avoid direct call of template
43if (empty($object) || !is_object($object)) {
44 print "Error, template page can't be called as URL";
45 exit(1);
46}
47
48
49if (!is_object($form)) {
50 $form = new Form($db);
51}
52
53
54?>
55<!-- BEGIN PHP TEMPLATE depreciation_options_view.tpl.php -->
56<?php
57
58if (!is_array($parameters)) {
59 $parameters = array();
60}
61if (empty($parameters['assetdepreciationoptions'])) {
62 $parameters['assetdepreciationoptions'] = &$assetdepreciationoptions;
63}
64$reshook = $hookmanager->executeHooks('formAssetDeprecationOptions', $parameters, $object, $action);
65print $hookmanager->resPrint;
66if ($reshook < 0) {
67 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
68}
69
70if (empty($reshook)) {
71 $class_type = get_class($object) == 'Asset' ? 0 : 1;
72
73 foreach ($assetdepreciationoptions->deprecation_options_fields as $mode_key => $mode_info) {
74 if (!empty($mode_info['enabled_field'])) {
75 $info = explode(':', $mode_info['enabled_field']);
76 if (empty($assetdepreciationoptions->deprecation_options[$info[0]][$info[1]]) || $assetdepreciationoptions->deprecation_options[$info[0]][$info[1]] != $info[2]) {
77 continue;
78 }
79 }
80
81 $assetdepreciationoptions->setInfosForMode($mode_key, $class_type, true);
82
83 $width = "pull-left";
84 print '<table class="liste centpercent '. $width .'" id="block_' . $mode_key . '">' . "\n";
85 print '<tr class="liste_titre"><td colspan="5">'.$langs->trans($mode_info['label']).'</td></tr>';
86 $mode_info['fields'] = dol_sort_array($mode_info['fields'], 'position');
87 foreach ($mode_info['fields'] as $field_key => $field_info) {
88 if (!empty($field_info['enabled_field'])) {
89 $info = explode(':', $field_info['enabled_field']);
90 if (empty($assetdepreciationoptions->deprecation_options[$info[0]][$info[1]]) || $assetdepreciationoptions->deprecation_options[$info[0]][$info[1]] != $info[2]) {
91 continue;
92 }
93 }
94 // Discard if extrafield is a hidden field on form
95 $isVisibleAbs = array_key_exists('visible', $field_info) ? abs((int) $field_info['visible']) : 0;
96 if (!in_array($isVisibleAbs, array(1, 3, 4, 5))) {
97 continue;
98 }
99 if (array_key_exists('enabled', $field_info) && isset($field_info['enabled']) && !verifCond($field_info['enabled'])) {
100 continue; // We don't want this field
101 }
102 $key = $mode_key . '_' . $field_key;
103 $value = $assetdepreciationoptions->deprecation_options[$mode_key][$field_key] ?? null;
104
105 print '<tr class="field_' . $key . '" id="block_' . $mode_key . '"><td';
106 print ' class="' . (empty($field_info['tdcss']) ? 'titlefieldmiddle' : $field_info['tdcss']) . ' fieldname_' . $key;
107 if ($field_info['type'] == 'text' || $field_info['type'] == 'html') {
108 print ' tdtop';
109 }
110 print '">';
111 if (!empty($field_info['help'])) {
112 print $form->textwithpicto($langs->trans($field_info['label']), $langs->trans($field_info['help']));
113 } else {
114 if (isset($field_info['copytoclipboard']) && $field_info['copytoclipboard'] == 1) { // @phan-suppress-current-line PhanTypeInvalidDimOffset
115 print showValueWithClipboardCPButton($value, 0, $langs->transnoentitiesnoconv($field_info['label']));
116 } else {
117 print $langs->trans($field_info['label']);
118 }
119 }
120 print '</td>';
121 print '<td class="valuefield fieldname_' . $key;
122 if ($field_info['type'] == 'text') {
123 print ' wordbreak';
124 }
125 if (!empty($field_info['cssview'])) {
126 print ' ' . $field_info['cssview'];
127 }
128 print '">';
129 if (in_array($field_info['type'], array('text', 'html'))) {
130 print '<div class="longmessagecut">';
131 }
132 if ($field_key == 'lang') {
133 $langs->load("languages");
134 $labellang = ($value ? $langs->trans('Language_' . $value) : '');
135 print picto_from_langcode($value, 'class="paddingrightonly saturatemedium opacitylow"');
136 print $labellang;
137 } else {
138 if (isset($field_info['copytoclipboard']) && $field_info['copytoclipboard'] == 2) {
139 $out = $assetdepreciationoptions->showOutputField($field_info, $field_key, $value, '', '', $mode_key . '_', 0);
140 print showValueWithClipboardCPButton($out, 0, $out);
141 } else {
142 print $assetdepreciationoptions->showOutputField($field_info, $field_key, $value, '', '', $mode_key . '_', 0);
143 }
144 }
145 if (in_array($field_info['type'], array('text', 'html'))) {
146 print '</div>';
147 }
148 print '</td>';
149 print '</tr>';
150 }
151 print '</table>';
152 print '<div class="clearboth"></div>';
153 print '<br>';
154 }
155}
156
157?>
158<!-- END PHP TEMPLATE depreciation_options_view.tpl.php -->
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
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...