create_val.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /* Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
  3. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. require '../main.inc.php';
  19. require 'class/ProductAttribute.class.php';
  20. require 'class/ProductAttributeValue.class.php';
  21. $id = GETPOST('id', 'int');
  22. $ref = GETPOST('ref', 'alpha');
  23. $value = GETPOST('value', 'alpha');
  24. $action = GETPOST('action', 'aZ09');
  25. $cancel = GETPOST('cancel', 'alpha');
  26. $backtopage = GETPOST('backtopage', 'alpha');
  27. $object = new ProductAttribute($db);
  28. $objectval = new ProductAttributeValue($db);
  29. if ($object->fetch($id) < 1) {
  30. dol_print_error($db, $langs->trans('ErrorRecordNotFound'));
  31. exit();
  32. }
  33. $permissiontoread = $user->rights->produit->lire || $user->rights->service->lire;
  34. // Security check
  35. if (empty($conf->variants->enabled)) {
  36. accessforbidden('Module not enabled');
  37. }
  38. if ($user->socid > 0) { // Protection if external user
  39. accessforbidden();
  40. }
  41. //$result = restrictedArea($user, 'variant');
  42. if (!$permissiontoread) accessforbidden();
  43. /*
  44. * Actions
  45. */
  46. if ($cancel) {
  47. $action = '';
  48. header('Location: '.DOL_URL_ROOT.'/variants/card.php?id='.$object->id);
  49. exit();
  50. }
  51. // None
  52. /*
  53. * View
  54. */
  55. if ($action == 'add') {
  56. if (empty($ref) || empty($value)) {
  57. setEventMessages($langs->trans('ErrorFieldsRequired'), null, 'errors');
  58. } else {
  59. $objectval->fk_product_attribute = $object->id;
  60. $objectval->ref = $ref;
  61. $objectval->value = $value;
  62. if ($objectval->create($user) > 0) {
  63. setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
  64. header('Location: '.DOL_URL_ROOT.'/variants/card.php?id='.$object->id);
  65. exit();
  66. } else {
  67. setEventMessages($langs->trans('ErrorCreatingProductAttributeValue'), $objectval->errors, 'errors');
  68. }
  69. }
  70. }
  71. $langs->load('products');
  72. $help_url = 'EN:Module_Products#Variants';
  73. $title = $langs->trans('ProductAttributeName', dol_htmlentities($object->label));
  74. llxHeader('', $title, $help_url);
  75. $h = 0;
  76. $head[$h][0] = DOL_URL_ROOT.'/variants/card.php?id='.$object->id;
  77. $head[$h][1] = $langs->trans("ProductAttributeName");
  78. $head[$h][2] = 'variant';
  79. $h++;
  80. print dol_get_fiche_head($head, 'variant', $langs->trans('ProductAttributeName'), -1, 'generic');
  81. print '<div class="fichecenter">';
  82. print '<div class="underbanner clearboth"></div>';
  83. ?>
  84. <table class="border" style="width: 100%">
  85. <tr>
  86. <td class="titlefield fieldrequired"><?php echo $langs->trans('Ref') ?></td>
  87. <td><?php echo dol_htmlentities($object->ref) ?>
  88. </tr>
  89. <tr>
  90. <td class="fieldrequired"><?php echo $langs->trans('Label') ?></td>
  91. <td><?php echo dol_htmlentities($object->label) ?></td>
  92. </tr>
  93. </table>
  94. <?php
  95. print '</div>';
  96. print dol_get_fiche_end();
  97. print '<br>';
  98. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  99. print '<input type="hidden" name="token" value="'.newToken().'">';
  100. print '<input type="hidden" name="action" value="add">';
  101. print '<input type="hidden" name="id" value="'.$object->id.'">';
  102. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  103. print load_fiche_titre($langs->trans('NewProductAttributeValue'));
  104. print dol_get_fiche_head();
  105. ?>
  106. <table class="border" style="width: 100%">
  107. <tr>
  108. <td class="titlefield fieldrequired"><label for="ref"><?php echo $langs->trans('Ref') ?></label></td>
  109. <td><input id="ref" type="text" name="ref" value="<?php echo $ref ?>"></td>
  110. </tr>
  111. <tr>
  112. <td class="fieldrequired"><label for="value"><?php echo $langs->trans('Label') ?></label></td>
  113. <td><input id="value" type="text" name="value" value="<?php echo $value ?>"></td>
  114. </tr>
  115. </table>
  116. <?php
  117. print dol_get_fiche_end();
  118. print '<div class="center">';
  119. print '<input type="submit" class="button" name="create" value="'.$langs->trans("Create").'">';
  120. print ' &nbsp; ';
  121. print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
  122. print '</div>';
  123. print '</form>';
  124. // End of page
  125. llxFooter();
  126. $db->close();