commonfields_add.tpl.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. * $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. ?>
  30. <!-- BEGIN PHP TEMPLATE commonfields_add.tpl.php -->
  31. <?php
  32. $object->fields = dol_sort_array($object->fields, 'position');
  33. if (empty($object->fields['status']['arrayofkeyval'])) {
  34. $object->fields['status']['arrayofkeyval'] = $stasusesObj->getStatusIds($db);
  35. }
  36. foreach ($object->fields as $key => $val) {
  37. // Discard if field is a hidden field on form
  38. if (abs($val['visible']) != 1 && abs($val['visible']) != 3) {
  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.'">';
  45. print '<td';
  46. print ' class="titlefieldcreate';
  47. if (isset($val['notnull']) && $val['notnull'] > 0) {
  48. print ' fieldrequired';
  49. }
  50. if ($val['type'] == 'text' || $val['type'] == 'html') {
  51. print ' tdtop';
  52. }
  53. print '"';
  54. print '>';
  55. if (!empty($val['help'])) {
  56. print $form->textwithpicto($langs->trans($val['label']), $langs->trans($val['help']));
  57. } else {
  58. print $langs->trans($val['label']);
  59. }
  60. print '</td>';
  61. print '<td class="valuefieldcreate">';
  62. if (!empty($val['picto'])) {
  63. print img_picto('', $val['picto'], '', false, 0, 0, '', 'pictofixedwidth');
  64. }
  65. if (in_array($val['type'], array('int', 'integer'))) {
  66. $value = GETPOST($key, 'int');
  67. } elseif ($val['type'] == 'double') {
  68. $value = price2num(GETPOST($key, 'alphanohtml'));
  69. } elseif ($val['type'] == 'text' || $val['type'] == 'html') {
  70. $value = GETPOST($key, 'restricthtml');
  71. } elseif ($val['type'] == 'date') {
  72. $value = dol_mktime(12, 0, 0, GETPOST($key.'month', 'int'), GETPOST($key.'day', 'int'), GETPOST($key.'year', 'int'));
  73. } elseif ($val['type'] == 'datetime') {
  74. $value = dol_mktime(GETPOST($key.'hour', 'int'), GETPOST($key.'min', 'int'), 0, GETPOST($key.'month', 'int'), GETPOST($key.'day', 'int'), GETPOST($key.'year', 'int'));
  75. } elseif ($val['type'] == 'boolean') {
  76. $value = (GETPOST($key) == 'on' ? 1 : 0);
  77. } elseif ($val['type'] == 'price') {
  78. $value = price2num(GETPOST($key));
  79. } elseif ($key == 'lang') {
  80. $value = GETPOST($key, 'aZ09');
  81. } else {
  82. $value = GETPOST($key, 'alphanohtml');
  83. }
  84. if (!empty($val['noteditable'])) {
  85. print $object->showOutputField($val, $key, $value, '', '', '', 0);
  86. } else {
  87. if ($key == 'lang') {
  88. print img_picto('', 'language', 'class="pictofixedwidth"');
  89. print $formadmin->select_language($value, $key, 0, null, 1, 0, 0, 'minwidth300', 2);
  90. } else {
  91. print $object->showInputField($val, $key, $value, '', '', '', 0);
  92. }
  93. }
  94. print '</td>';
  95. print '</tr>';
  96. }
  97. ?>
  98. <!-- END PHP TEMPLATE commonfields_add.tpl.php -->
  99. <script>
  100. var warehouses = ['1', '2', '3'];
  101. var mySelect = document.getElementById('fk_warehouse');
  102. mySelect.onchange = (event) => {
  103. var warehouse_id = event.target.value;
  104. if (warehouses.includes(warehouse_id)) {
  105. $("#status").val("113");
  106. $("#select2-status-container").html("Szállítás alatt");
  107. $('span.select2-selection__rendered').attr('title', 'Szállítás alatt');
  108. } else {
  109. $("#status").val("111");
  110. $("#select2-status-container").html("Szervízben");
  111. $('span.select2-selection__rendered').attr('title', 'Szervízben');
  112. }
  113. }
  114. </script>