commonfields_edit.tpl.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. if (empty($object->fields['status']['arrayofkeyval'])) {
  37. $object->fields['status']['arrayofkeyval'] = $stasusesObj->getStatusIds($db);
  38. }
  39. foreach ($object->fields as $key => $val) {
  40. // Discard if extrafield is a hidden field on form
  41. if (abs($val['visible']) != 1 && abs($val['visible']) != 3 && abs($val['visible']) != 4) {
  42. continue;
  43. }
  44. if (array_key_exists('enabled', $val) && isset($val['enabled']) && !verifCond($val['enabled'])) {
  45. continue; // We don't want this field
  46. }
  47. print '<tr class="field_' . $key . '"><td';
  48. print ' class="titlefieldcreate';
  49. if (isset($val['notnull']) && $val['notnull'] > 0) {
  50. print ' fieldrequired';
  51. }
  52. if (preg_match('/^(text|html)/', $val['type'])) {
  53. print ' tdtop';
  54. }
  55. print '">';
  56. if (!empty($val['help'])) {
  57. print $form->textwithpicto($langs->trans($val['label']), $langs->trans($val['help']));
  58. } else {
  59. print $langs->trans($val['label']);
  60. }
  61. print '</td>';
  62. print '<td class="valuefieldcreate">';
  63. if (!empty($val['picto'])) {
  64. print img_picto('', $val['picto'], '', false, 0, 0, '', 'pictofixedwidth');
  65. }
  66. if (in_array($val['type'], array('int', 'integer'))) {
  67. $val['arrayofkeyval'] = [110 => 'Raktárban1', 111 => 'Szervízben1', 112 => 'Kiadva1', 113 => 'Szállítás alatt1', 114 => 'Hibás1'];
  68. $value = GETPOSTISSET($key) ? GETPOST($key, 'int') : $object->$key;
  69. } elseif ($val['type'] == 'double') {
  70. $value = GETPOSTISSET($key) ? price2num(GETPOST($key, 'alphanohtml')) : $object->$key;
  71. } elseif (preg_match('/^(text|html)/', $val['type'])) {
  72. $tmparray = explode(':', $val['type']);
  73. if (!empty($tmparray[1])) {
  74. $check = $tmparray[1];
  75. } else {
  76. $check = 'restricthtml';
  77. }
  78. $value = GETPOSTISSET($key) ? GETPOST($key, $check) : $object->$key;
  79. } elseif (in_array($val['type'], array('date', 'datetime'))) {
  80. $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;
  81. } elseif ($val['type'] == 'price') {
  82. $value = GETPOSTISSET($key) ? price2num(GETPOST($key)) : price2num($object->$key);
  83. } elseif ($key == 'lang') {
  84. $value = GETPOSTISSET($key) ? GETPOST($key, 'aZ09') : $object->lang;
  85. } else {
  86. $value = GETPOSTISSET($key) ? GETPOST($key, 'alpha') : $object->$key;
  87. }
  88. //var_dump($val.' '.$key.' '.$value);
  89. if (!empty($val['noteditable'])) {
  90. print $object->showOutputField($val, $key, $value, '', '', '', 0);
  91. } else {
  92. if ($key == 'lang') {
  93. print img_picto('', 'language', 'class="pictofixedwidth"');
  94. print $formadmin->select_language($value, $key, 0, null, 1, 0, 0, 'minwidth300', 2);
  95. } else {
  96. print_r($val[$key]);
  97. print $object->showInputField($val, $key, $value, '', '', '', 0);
  98. }
  99. }
  100. print '</td>';
  101. print '</tr>';
  102. }
  103. ?>
  104. <!-- END PHP TEMPLATE commonfields_edit.tpl.php -->
  105. <script>
  106. var warehouses = ['1', '2', '3'];
  107. var mySelect = document.getElementById('fk_warehouse');
  108. mySelect.onchange = (event) => {
  109. var warehouse_id = event.target.value;
  110. if (warehouses.includes(warehouse_id)) {
  111. $("#status").val("113");
  112. $("#select2-status-container").html("Szállítás alatt");
  113. $('span.select2-selection__rendered').attr('title', 'Szállítás alatt');
  114. } else {
  115. $("#status").val("111");
  116. $("#select2-status-container").html("Szervízben");
  117. $('span.select2-selection__rendered').attr('title', 'Szervízben');
  118. }
  119. }
  120. </script>