commonfields_view.tpl.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. $object->fields = dol_sort_array($object->fields, 'position');
  37. foreach ($object->fields as $key => $val) {
  38. if (!empty($keyforbreak) && $key == $keyforbreak) {
  39. break; // key used for break on second column
  40. }
  41. // Discard if extrafield is a hidden field on form
  42. if (abs($val['visible']) != 1 && abs($val['visible']) != 3 && abs($val['visible']) != 4 && abs($val['visible']) != 5) {
  43. continue;
  44. }
  45. if (array_key_exists('enabled', $val) && isset($val['enabled']) && !verifCond($val['enabled'])) {
  46. continue; // We don't want this field
  47. }
  48. if (in_array($key, array('ref'/*, 'status'*/))) {
  49. continue; // Ref and status are already in dol_banner
  50. }
  51. $value = $object->$key;
  52. print '<tr class="field_'.$key.'"><td';
  53. print ' class="'.(empty($val['tdcss']) ? 'titlefield' : $val['tdcss']).' fieldname_'.$key;
  54. //if ($val['notnull'] > 0) print ' fieldrequired'; // No fieldrequired on the view output
  55. if ($val['type'] == 'text' || $val['type'] == 'html') {
  56. print ' tdtop';
  57. }
  58. print '">';
  59. $labeltoshow = '';
  60. if (!empty($val['help'])) {
  61. $labeltoshow .= $form->textwithpicto($langs->trans($val['label']), $langs->trans($val['help']));
  62. } else {
  63. if (isset($val['copytoclipboard']) && $val['copytoclipboard'] == 1) {
  64. $labeltoshow .= showValueWithClipboardCPButton($value, 0, $langs->transnoentitiesnoconv($val['label']));
  65. } else {
  66. $labeltoshow .= $langs->trans($val['label']);
  67. }
  68. }
  69. if (empty($val['alwayseditable'])) {
  70. print $labeltoshow;
  71. } else {
  72. print $form->editfieldkey($labeltoshow, $key, $value, $object, 1, $val['type']);
  73. }
  74. print '</td>';
  75. print '<td class="valuefield fieldname_'.$key;
  76. if ($val['type'] == 'text') {
  77. print ' wordbreak';
  78. }
  79. if (!empty($val['cssview'])) {
  80. print ' '.$val['cssview'];
  81. }
  82. print '">';
  83. if (empty($val['alwayseditable'])) {
  84. if (preg_match('/^(text|html)/', $val['type'])) {
  85. print '<div class="longmessagecut">';
  86. }
  87. if ($key == 'lang') {
  88. $langs->load("languages");
  89. $labellang = ($value ? $langs->trans('Language_'.$value) : '');
  90. print picto_from_langcode($value, 'class="paddingrightonly saturatemedium opacitylow"');
  91. print $labellang;
  92. } else {
  93. if (isset($val['copytoclipboard']) && $val['copytoclipboard'] == 2) {
  94. $out = $object->showOutputField($val, $key, $value, '', '', '', 0);
  95. print showValueWithClipboardCPButton($out, 0, $out);
  96. } else {
  97. print $object->showOutputField($val, $key, $value, '', '', '', 0);
  98. }
  99. }
  100. //print dol_escape_htmltag($object->$key, 1, 1);
  101. if (preg_match('/^(text|html)/', $val['type'])) {
  102. print '</div>';
  103. }
  104. } else {
  105. print $form->editfieldval($labeltoshow, $key, $value, $object, 1, $val['type']);
  106. }
  107. print '</td>';
  108. print '</tr>';
  109. }
  110. print '</table>';
  111. // We close div and reopen for second column
  112. print '</div>';
  113. $rightpart = '';
  114. $alreadyoutput = 1;
  115. foreach ($object->fields as $key => $val) {
  116. if ($alreadyoutput) {
  117. if (!empty($keyforbreak) && $key == $keyforbreak) {
  118. $alreadyoutput = 0; // key used for break on second column
  119. } else {
  120. continue;
  121. }
  122. }
  123. // Discard if extrafield is a hidden field on form
  124. if (abs($val['visible']) != 1 && abs($val['visible']) != 3 && abs($val['visible']) != 4 && abs($val['visible']) != 5) {
  125. continue;
  126. }
  127. if (array_key_exists('enabled', $val) && isset($val['enabled']) && !$val['enabled']) {
  128. continue; // We don't want this field
  129. }
  130. if (in_array($key, array('ref'/*, 'status'*/))) {
  131. continue; // Ref and status are already in dol_banner
  132. }
  133. $value = $object->$key;
  134. $rightpart .= '<tr><td';
  135. $rightpart .= ' class="'.(empty($val['tdcss']) ? 'titlefield' : $val['tdcss']).' fieldname_'.$key;
  136. //if ($val['notnull'] > 0) $rightpart .= ' fieldrequired'; // No fieldrequired inthe view output
  137. if ($val['type'] == 'text' || $val['type'] == 'html') {
  138. $rightpart .= ' tdtop';
  139. }
  140. $rightpart.= '">';
  141. $labeltoshow = '';
  142. if (!empty($val['help'])) {
  143. $labeltoshow .= $form->textwithpicto($langs->trans($val['label']), $langs->trans($val['help']));
  144. } else {
  145. if (isset($val['copytoclipboard']) && $val['copytoclipboard'] == 1) {
  146. $labeltoshow .= showValueWithClipboardCPButton($value, 0, $langs->transnoentitiesnoconv($val['label']));
  147. } else {
  148. $labeltoshow .= $langs->trans($val['label']);
  149. }
  150. }
  151. if (empty($val['alwayseditable'])) {
  152. $rightpart .= $labeltoshow;
  153. } else {
  154. $rightpart .= $form->editfieldkey($labeltoshow, $key, $value, $object, 1, $val['type']);
  155. }
  156. $rightpart .= '</td>';
  157. $rightpart .= '<td class="valuefield fieldname_'.$key;
  158. if ($val['type'] == 'text') {
  159. $rightpart .= ' wordbreak';
  160. }
  161. if (!empty($val['cssview'])) {
  162. $rightpart .= ' '.$val['cssview'];
  163. }
  164. $rightpart .= '">';
  165. if (empty($val['alwayseditable'])) {
  166. if (preg_match('/^(text|html)/', $val['type'])) {
  167. $rightpart .= '<div class="longmessagecut">';
  168. }
  169. if ($key == 'lang') {
  170. $langs->load("languages");
  171. $labellang = ($value ? $langs->trans('Language_'.$value) : '');
  172. $rightpart .= picto_from_langcode($value, 'class="paddingrightonly saturatemedium opacitylow"');
  173. $rightpart .= $labellang;
  174. } else {
  175. if (isset($val['copytoclipboard']) && $val['copytoclipboard'] == 2) {
  176. $out = $object->showOutputField($val, $key, $value, '', '', '', 0);
  177. $rightpart .= showValueWithClipboardCPButton($out, 0, $out);
  178. } else {
  179. $rightpart.= $object->showOutputField($val, $key, $value, '', '', '', 0);
  180. }
  181. }
  182. if (preg_match('/^(text|html)/', $val['type'])) {
  183. $rightpart .= '</div>';
  184. }
  185. } else {
  186. $rightpart .= $form->editfieldval($labeltoshow, $key, $value, $object, 1, $val['type']);
  187. }
  188. $rightpart .= '</td>';
  189. $rightpart .= '</tr>';
  190. }
  191. print '<div class="fichehalfright">';
  192. print '<div class="underbanner clearboth"></div>';
  193. print '<table class="border centpercent tableforfield">';
  194. print $rightpart;
  195. ?>
  196. <!-- END PHP TEMPLATE commonfields_view.tpl.php -->