commonfields_edit.tpl.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /* Copyright (C) 2017-2019 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. * $form
  23. */
  24. // Protection to avoid direct call of template
  25. if (empty($conf) || !is_object($conf)) {
  26. print "Error, template page can't be called as URL";
  27. exit;
  28. }
  29. if (!is_object($form)) {
  30. $form = new Form($db);
  31. }
  32. ?>
  33. <!-- BEGIN PHP TEMPLATE commonfields_edit.tpl.php -->
  34. <?php
  35. $object->fields = dol_sort_array($object->fields, 'position');
  36. foreach ($object->fields as $key => $val) {
  37. // Discard if extrafield is a hidden field on form
  38. if (abs($val['visible']) != 1 && abs($val['visible']) != 3 && abs($val['visible']) != 4) {
  39. continue;
  40. }
  41. if (array_key_exists('enabled', $val) && isset($val['enabled']) && !verifCond($val['enabled'])) {
  42. continue; // We don't want this field
  43. }
  44. print '<tr class="field_'.$key.'"><td';
  45. print ' class="titlefieldcreate';
  46. if (isset($val['notnull']) && $val['notnull'] > 0) {
  47. print ' fieldrequired';
  48. }
  49. if (preg_match('/^(text|html)/', $val['type'])) {
  50. print ' tdtop';
  51. }
  52. print '">';
  53. if (!empty($val['help'])) {
  54. print $form->textwithpicto($langs->trans($val['label']), $langs->trans($val['help']));
  55. } else {
  56. print $langs->trans($val['label']);
  57. }
  58. print '</td>';
  59. print '<td class="valuefieldcreate">';
  60. if (!empty($val['picto'])) {
  61. print img_picto('', $val['picto'], '', false, 0, 0, '', 'pictofixedwidth');
  62. }
  63. if (in_array($val['type'], array('int', 'integer'))) {
  64. $value = GETPOSTISSET($key) ?GETPOST($key, 'int') : $object->$key;
  65. } elseif ($val['type'] == 'double') {
  66. $value = GETPOSTISSET($key) ? price2num(GETPOST($key, 'alphanohtml')) : $object->$key;
  67. } elseif (preg_match('/^(text|html)/', $val['type'])) {
  68. $tmparray = explode(':', $val['type']);
  69. if (!empty($tmparray[1])) {
  70. $check = $tmparray[1];
  71. } else {
  72. $check = 'restricthtml';
  73. }
  74. $value = GETPOSTISSET($key) ? GETPOST($key, $check) : $object->$key;
  75. } elseif (in_array($val['type'], array('date', 'datetime'))) {
  76. $value = GETPOSTISSET($key) ? dol_mktime(GETPOST($key.'hour', 'int'), GETPOST($key.'min', 'int'), GETPOST($key.'sec', 'int'), GETPOST($key.'month', 'int'), GETPOST($key.'day', 'int'), GETPOST($key.'year', 'int')) : $object->$key;
  77. } elseif ($val['type'] == 'price') {
  78. $value = GETPOSTISSET($key) ? price2num(GETPOST($key)) : price2num($object->$key);
  79. } elseif ($key == 'lang') {
  80. $value = GETPOSTISSET($key) ? GETPOST($key, 'aZ09') : $object->lang;
  81. } else {
  82. $value = GETPOSTISSET($key) ? GETPOST($key, 'alpha') : $object->$key;
  83. }
  84. //var_dump($val.' '.$key.' '.$value);
  85. if (!empty($val['noteditable'])) {
  86. print $object->showOutputField($val, $key, $value, '', '', '', 0);
  87. } else {
  88. if ($key == 'lang') {
  89. print img_picto('', 'language', 'class="pictofixedwidth"');
  90. print $formadmin->select_language($value, $key, 0, null, 1, 0, 0, 'minwidth300', 2);
  91. } else {
  92. print $object->showInputField($val, $key, $value, '', '', '', 0);
  93. }
  94. }
  95. print '</td>';
  96. print '</tr>';
  97. }
  98. ?>
  99. <!-- END PHP TEMPLATE commonfields_edit.tpl.php -->