dolibarr  16.0.5
depreciation_options_view.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
28 if (empty($object) || !is_object($object)) {
29  print "Error, template page can't be called as URL";
30  exit;
31 }
32 
33 if (!is_object($form)) {
34  $form = new Form($db);
35 }
36 
37 
38 ?>
39 <!-- BEGIN PHP TEMPLATE depreciation_options_view.tpl.php -->
40 <?php
41 
42 if (!is_array($parameters)) {
43  $parameters = array();
44 }
45 if (empty($parameters['assetdepreciationoptions'])) {
46  $parameters['assetdepreciationoptions'] = &$assetdepreciationoptions;
47 }
48 $reshook = $hookmanager->executeHooks('formAssetDeprecationOptions', $parameters, $object, $action);
49 print $hookmanager->resPrint;
50 if ($reshook < 0) {
51  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
52 }
53 
54 if (empty($reshook)) {
55  $class_type = get_class($object) == 'Asset' ? 0 : 1;
56  foreach ($assetdepreciationoptions->deprecation_options_fields as $mode_key => $mode_info) {
57  if (!empty($mode_info['enabled_field'])) {
58  $info = explode(':', $mode_info['enabled_field']);
59  if ($assetdepreciationoptions->deprecation_options[$info[0]][$info[1]] != $info[2]) {
60  continue;
61  }
62  }
63 
64  $assetdepreciationoptions->setInfosForMode($mode_key, $class_type, true);
65 
66  print load_fiche_titre($langs->trans($mode_info['label']), '', '');
67  print '<div class="fichecenter">';
68  print '<div class="fichehalfleft">';
69  print '<div class="underbanner clearboth"></div>';
70  print '<table class="border centpercent tableforfield">' . "\n";
71  $mode_info['fields'] = dol_sort_array($mode_info['fields'], 'position');
72  foreach ($mode_info['fields'] as $field_key => $field_info) {
73  if (!empty($field_info['enabled_field'])) {
74  $info = explode(':', $field_info['enabled_field']);
75  if ($assetdepreciationoptions->deprecation_options[$info[0]][$info[1]] != $info[2]) {
76  continue;
77  }
78  }
79  // Discard if extrafield is a hidden field on form
80  if (abs($field_info['visible']) != 1 && abs($field_info['visible']) != 3 && abs($field_info['visible']) != 4 && abs($field_info['visible']) != 5) {
81  continue;
82  }
83  if (array_key_exists('enabled', $field_info) && isset($field_info['enabled']) && !verifCond($field_info['enabled'])) {
84  continue; // We don't want this field
85  }
86  if (!empty($field_info['column_break'])) {
87  print '</table>';
88 
89  // We close div and reopen for second column
90  print '</div>';
91  print '<div class="fichehalfright">';
92 
93  print '<div class="underbanner clearboth"></div>';
94  print '<table class="border centpercent tableforfield">';
95  }
96 
97  $key = $mode_key . '_' . $field_key;
98  $value = $assetdepreciationoptions->deprecation_options[$mode_key][$field_key];
99 
100  print '<tr class="field_' . $key . '"><td';
101  print ' class="' . (empty($field_info['tdcss']) ? 'titlefield' : $field_info['tdcss']) . ' fieldname_' . $key;
102  if ($field_info['type'] == 'text' || $field_info['type'] == 'html') {
103  print ' tdtop';
104  }
105  print '">';
106  if (!empty($field_info['help'])) {
107  print $form->textwithpicto($langs->trans($field_info['label']), $langs->trans($field_info['help']));
108  } else {
109  if (isset($field_info['copytoclipboard']) && $field_info['copytoclipboard'] == 1) {
110  print showValueWithClipboardCPButton($value, 0, $langs->transnoentitiesnoconv($field_info['label']));
111  } else {
112  print $langs->trans($field_info['label']);
113  }
114  }
115  print '</td>';
116  print '<td class="valuefield fieldname_' . $key;
117  if ($field_info['type'] == 'text') {
118  print ' wordbreak';
119  }
120  if (!empty($field_info['cssview'])) {
121  print ' ' . $field_info['cssview'];
122  }
123  print '">';
124  if (in_array($field_info['type'], array('text', 'html'))) {
125  print '<div class="longmessagecut">';
126  }
127  if ($field_key == 'lang') {
128  $langs->load("languages");
129  $labellang = ($value ? $langs->trans('Language_' . $value) : '');
130  print picto_from_langcode($value, 'class="paddingrightonly saturatemedium opacitylow"');
131  print $labellang;
132  } else {
133  if (isset($field_info['copytoclipboard']) && $field_info['copytoclipboard'] == 2) {
134  $out = $assetdepreciationoptions->showOutputField($field_info, $field_key, $value, '', '', $mode_key . '_', 0);
135  print showValueWithClipboardCPButton($out, 0, $out);
136  } else {
137  print $assetdepreciationoptions->showOutputField($field_info, $field_key, $value, '', '', $mode_key . '_', 0);
138  }
139  }
140  if (in_array($field_info['type'], array('text', 'html'))) {
141  print '</div>';
142  }
143  print '</td>';
144  print '</tr>';
145  }
146  print '</table>';
147  print '</div>';
148  print '</div>';
149  print '<div class="clearboth"></div>';
150  }
151 }
152 
153 ?>
154 <!-- END PHP TEMPLATE depreciation_options_view.tpl.php -->
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
dol_sort_array
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...
Definition: functions.lib.php:8385
verifCond
verifCond($strToEvaluate)
Verify if condition in string is ok or not.
Definition: functions.lib.php:8582
picto_from_langcode
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
Definition: functions.lib.php:8742
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
showValueWithClipboardCPButton
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
Definition: functions.lib.php:11087
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137