commonfields_view.tpl.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
  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. * Need to have following variables defined:
  18. * $object (invoice, order, ...)
  19. * $action
  20. * $conf
  21. * $langs
  22. *
  23. * $keyforbreak may be defined to key to switch on second column
  24. */
  25. // Protection to avoid direct call of template
  26. if (empty($conf) || !is_object($conf)) {
  27. print "Error, template page can't be called as URL";
  28. exit;
  29. }
  30. if (!is_object($form)) {
  31. $form = new Form($db);
  32. }
  33. ?>
  34. <!-- BEGIN PHP TEMPLATE commonfields_view.tpl.php -->
  35. <?php
  36. //$warehouses = $settlementsGroup->getWarehouses();
  37. //$entities = $settlementsGroup->getEntites();
  38. $entities = $helper->getAllEntities();
  39. $object->fields = dol_sort_array($object->fields, 'position');
  40. foreach ($object->fields as $key => $val) {
  41. if (!empty($keyforbreak) && $key == $keyforbreak) {
  42. break; // key used for break on second column
  43. }
  44. // Discard if extrafield is a hidden field on form
  45. if (abs($val['visible']) != 1 && abs($val['visible']) != 3 && abs($val['visible']) != 4 && abs($val['visible']) != 5) {
  46. continue;
  47. }
  48. if (array_key_exists('enabled', $val) && isset($val['enabled']) && !verifCond($val['enabled'])) {
  49. continue; // We don't want this field
  50. }
  51. if (in_array($key, array('ref', 'status'))) {
  52. continue; // Ref and status are already in dol_banner
  53. }
  54. $value = $object->$key;
  55. print '<tr class="field_' . $key . '"><td';
  56. print ' class="' . (empty($val['tdcss']) ? 'titlefield' : $val['tdcss']) . ' fieldname_' . $key;
  57. //if ($val['notnull'] > 0) print ' fieldrequired'; // No fieldrequired on the view output
  58. if ($val['type'] == 'text' || $val['type'] == 'html') {
  59. print ' tdtop';
  60. }
  61. print '">';
  62. if (!empty($val['help'])) {
  63. print $form->textwithpicto($langs->trans($val['label']), $langs->trans($val['help']));
  64. } else {
  65. if (isset($val['copytoclipboard']) && $val['copytoclipboard'] == 1) {
  66. print showValueWithClipboardCPButton($value, 0, $langs->transnoentitiesnoconv($val['label']));
  67. } else {
  68. print $langs->trans($val['label']);
  69. }
  70. }
  71. print '</td>';
  72. print '<td class="valuefield fieldname_' . $key;
  73. if ($val['type'] == 'text') {
  74. print ' wordbreak';
  75. }
  76. if (!empty($val['cssview'])) {
  77. print ' ' . $val['cssview'];
  78. }
  79. print '">';
  80. if (in_array($val['type'], array('text', 'html'))) {
  81. print '<div class="longmessagecut">';
  82. }
  83. if ($key == 'lang') {
  84. $langs->load("languages");
  85. $labellang = ($value ? $langs->trans('Language_' . $value) : '');
  86. print picto_from_langcode($value, 'class="paddingrightonly saturatemedium opacitylow"');
  87. print $labellang;
  88. } else {
  89. if (isset($val['copytoclipboard']) && $val['copytoclipboard'] == 2) {
  90. $out = $object->showOutputField($val, $key, $value, '', '', '', 0);
  91. print showValueWithClipboardCPButton($out, 0, $out);
  92. } else {
  93. if ($key == 'fk_entity') {
  94. print $entities[$value];
  95. } else {
  96. print $object->showOutputField($val, $key, $value, '', '', '', 0);
  97. }
  98. }
  99. }
  100. //print dol_escape_htmltag($object->$key, 1, 1);
  101. if (in_array($val['type'], array('text', 'html'))) {
  102. print '</div>';
  103. }
  104. print '</td>';
  105. print '</tr>';
  106. if ($key == 'single_user_group') {
  107. if ($value == 't') {
  108. $name = $helper->getUserName($id);
  109. print '<tr class="field_single_user_name"><td class="titlefield fieldname_single_user_name">' . $langs->trans('User') . '</td><td class="valuefield fieldname_single_user_name">' . $name . '</td></tr>';
  110. }
  111. }
  112. if ($key == 'hotelgroup') {
  113. if ($value == 't') {
  114. $name = $helper->getHotelName($id);
  115. print '<tr class="field_single_user_name"><td class="titlefield fieldname_single_user_name">' . $langs->trans('Hotel') . '</td><td class="valuefield fieldname_single_user_name">' . $name . '</td></tr>';
  116. }
  117. }
  118. }
  119. print '</table>';
  120. // We close div and reopen for second column
  121. print '</div>';
  122. $rightpart = '';
  123. $alreadyoutput = 1;
  124. foreach ($object->fields as $key => $val) {
  125. if ($alreadyoutput) {
  126. if (!empty($keyforbreak) && $key == $keyforbreak) {
  127. $alreadyoutput = 0; // key used for break on second column
  128. } else {
  129. continue;
  130. }
  131. }
  132. // Discard if extrafield is a hidden field on form
  133. if (abs($val['visible']) != 1 && abs($val['visible']) != 3 && abs($val['visible']) != 4 && abs($val['visible']) != 5) {
  134. continue;
  135. }
  136. if (array_key_exists('enabled', $val) && isset($val['enabled']) && !$val['enabled']) {
  137. continue; // We don't want this field
  138. }
  139. if (in_array($key, array('ref', 'status'))) {
  140. continue; // Ref and status are already in dol_banner
  141. }
  142. $value = $object->$key;
  143. $rightpart .= '<tr><td';
  144. $rightpart .= ' class="' . (empty($val['tdcss']) ? 'titlefield' : $val['tdcss']) . ' fieldname_' . $key;
  145. //if ($val['notnull'] > 0) $rightpart .= ' fieldrequired'; // No fieldrequired inthe view output
  146. if ($val['type'] == 'text' || $val['type'] == 'html') {
  147. $rightpart .= ' tdtop';
  148. }
  149. $rightpart .= '">';
  150. if (!empty($val['help'])) {
  151. $rightpart .= $form->textwithpicto($langs->trans($val['label']), $langs->trans($val['help']));
  152. } else {
  153. $rightpart .= $langs->trans($val['label']);
  154. }
  155. $rightpart .= '</td>';
  156. $rightpart .= '<td class="valuefield fieldname_' . $key;
  157. if ($val['type'] == 'text') {
  158. $rightpart .= ' wordbreak';
  159. }
  160. if (!empty($val['cssview'])) {
  161. $rightpart .= ' ' . $val['cssview'];
  162. }
  163. $rightpart .= '">';
  164. if (in_array($val['type'], array('text', 'html'))) {
  165. $rightpart .= '<div class="longmessagecut">';
  166. }
  167. $rightpart .= $object->showOutputField($val, $key, $value, '', '', '', 0);
  168. //$rightpart .= dol_escape_htmltag($object->$key, 1, 1);
  169. if (in_array($val['type'], array('text', 'html'))) {
  170. $rightpart .= '</div>';
  171. }
  172. $rightpart .= '</td>';
  173. $rightpart .= '</tr>';
  174. }
  175. print '<div class="fichehalfright">';
  176. print '<div class="underbanner clearboth"></div>';
  177. print '<table class="border centpercent tableforfield">';
  178. print $rightpart;
  179. ?>
  180. <!-- END PHP TEMPLATE commonfields_view.tpl.php -->