depreciation_options_view.tpl.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. // Protection to avoid direct call of template
  27. if (empty($object) || !is_object($object)) {
  28. print "Error, template page can't be called as URL";
  29. exit;
  30. }
  31. if (!is_object($form)) {
  32. $form = new Form($db);
  33. }
  34. ?>
  35. <!-- BEGIN PHP TEMPLATE depreciation_options_view.tpl.php -->
  36. <?php
  37. if (!is_array($parameters)) {
  38. $parameters = array();
  39. }
  40. if (empty($parameters['assetdepreciationoptions'])) {
  41. $parameters['assetdepreciationoptions'] = &$assetdepreciationoptions;
  42. }
  43. $reshook = $hookmanager->executeHooks('formAssetDeprecationOptions', $parameters, $object, $action);
  44. print $hookmanager->resPrint;
  45. if ($reshook < 0) {
  46. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  47. }
  48. if (empty($reshook)) {
  49. $class_type = get_class($object) == 'Asset' ? 0 : 1;
  50. foreach ($assetdepreciationoptions->deprecation_options_fields as $mode_key => $mode_info) {
  51. if (!empty($mode_info['enabled_field'])) {
  52. $info = explode(':', $mode_info['enabled_field']);
  53. if ($assetdepreciationoptions->deprecation_options[$info[0]][$info[1]] != $info[2]) {
  54. continue;
  55. }
  56. }
  57. $assetdepreciationoptions->setInfosForMode($mode_key, $class_type, true);
  58. print load_fiche_titre($langs->trans($mode_info['label']), '', '');
  59. print '<div class="fichecenter">';
  60. print '<div class="fichehalfleft">';
  61. print '<div class="underbanner clearboth"></div>';
  62. print '<table class="border centpercent tableforfield">' . "\n";
  63. $mode_info['fields'] = dol_sort_array($mode_info['fields'], 'position');
  64. foreach ($mode_info['fields'] as $field_key => $field_info) {
  65. if (!empty($field_info['enabled_field'])) {
  66. $info = explode(':', $field_info['enabled_field']);
  67. if ($assetdepreciationoptions->deprecation_options[$info[0]][$info[1]] != $info[2]) {
  68. continue;
  69. }
  70. }
  71. // Discard if extrafield is a hidden field on form
  72. if (abs($field_info['visible']) != 1 && abs($field_info['visible']) != 3 && abs($field_info['visible']) != 4 && abs($field_info['visible']) != 5) {
  73. continue;
  74. }
  75. if (array_key_exists('enabled', $field_info) && isset($field_info['enabled']) && !verifCond($field_info['enabled'])) {
  76. continue; // We don't want this field
  77. }
  78. if (!empty($field_info['column_break'])) {
  79. print '</table>';
  80. // We close div and reopen for second column
  81. print '</div>';
  82. print '<div class="fichehalfright">';
  83. print '<div class="underbanner clearboth"></div>';
  84. print '<table class="border centpercent tableforfield">';
  85. }
  86. $key = $mode_key . '_' . $field_key;
  87. $value = $assetdepreciationoptions->deprecation_options[$mode_key][$field_key];
  88. print '<tr class="field_' . $key . '"><td';
  89. print ' class="' . (empty($field_info['tdcss']) ? 'titlefield' : $field_info['tdcss']) . ' fieldname_' . $key;
  90. if ($field_info['type'] == 'text' || $field_info['type'] == 'html') {
  91. print ' tdtop';
  92. }
  93. print '">';
  94. if (!empty($field_info['help'])) {
  95. print $form->textwithpicto($langs->trans($field_info['label']), $langs->trans($field_info['help']));
  96. } else {
  97. if (isset($field_info['copytoclipboard']) && $field_info['copytoclipboard'] == 1) {
  98. print showValueWithClipboardCPButton($value, 0, $langs->transnoentitiesnoconv($field_info['label']));
  99. } else {
  100. print $langs->trans($field_info['label']);
  101. }
  102. }
  103. print '</td>';
  104. print '<td class="valuefield fieldname_' . $key;
  105. if ($field_info['type'] == 'text') {
  106. print ' wordbreak';
  107. }
  108. if (!empty($field_info['cssview'])) {
  109. print ' ' . $field_info['cssview'];
  110. }
  111. print '">';
  112. if (in_array($field_info['type'], array('text', 'html'))) {
  113. print '<div class="longmessagecut">';
  114. }
  115. if ($field_key == 'lang') {
  116. $langs->load("languages");
  117. $labellang = ($value ? $langs->trans('Language_' . $value) : '');
  118. print picto_from_langcode($value, 'class="paddingrightonly saturatemedium opacitylow"');
  119. print $labellang;
  120. } else {
  121. if (isset($field_info['copytoclipboard']) && $field_info['copytoclipboard'] == 2) {
  122. $out = $assetdepreciationoptions->showOutputField($field_info, $field_key, $value, '', '', $mode_key . '_', 0);
  123. print showValueWithClipboardCPButton($out, 0, $out);
  124. } else {
  125. print $assetdepreciationoptions->showOutputField($field_info, $field_key, $value, '', '', $mode_key . '_', 0);
  126. }
  127. }
  128. if (in_array($field_info['type'], array('text', 'html'))) {
  129. print '</div>';
  130. }
  131. print '</td>';
  132. print '</tr>';
  133. }
  134. print '</table>';
  135. print '</div>';
  136. print '</div>';
  137. print '<div class="clearboth"></div>';
  138. }
  139. }
  140. ?>
  141. <!-- END PHP TEMPLATE depreciation_options_view.tpl.php -->