create_val.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 <http://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','alpha');
  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. /*
  34. * Actions
  35. */
  36. if ($cancel)
  37. {
  38. $action='';
  39. header('Location: '.DOL_URL_ROOT.'/variants/card.php?id='.$object->id);
  40. exit();
  41. }
  42. // None
  43. /*
  44. * View
  45. */
  46. if ($action == 'add')
  47. {
  48. if (empty($ref) || empty($value)) {
  49. setEventMessages($langs->trans('ErrorFieldsRequired'), null, 'errors');
  50. } else {
  51. $objectval->fk_product_attribute = $object->id;
  52. $objectval->ref = $ref;
  53. $objectval->value = $value;
  54. if ($objectval->create($user) > 0) {
  55. setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
  56. header('Location: '.DOL_URL_ROOT.'/variants/card.php?id='.$object->id);
  57. exit();
  58. } else {
  59. setEventMessages($langs->trans('ErrorCreatingProductAttributeValue'), $objectval->errors, 'errors');
  60. }
  61. }
  62. }
  63. $langs->load('products');
  64. $title = $langs->trans('ProductAttributeName', dol_htmlentities($object->label));
  65. llxHeader('', $title);
  66. $h=0;
  67. $head[$h][0] = DOL_URL_ROOT.'/variants/card.php?id='.$object->id;
  68. $head[$h][1] = $langs->trans("Card");
  69. $head[$h][2] = 'variant';
  70. $h++;
  71. dol_fiche_head($head, 'variant', $langs->trans('ProductAttributeName'), -1, 'generic');
  72. print '<div class="fichecenter">';
  73. print '<div class="underbanner clearboth"></div>';
  74. ?>
  75. <table class="border" style="width: 100%">
  76. <tr>
  77. <td class="titlefield fieldrequired"><?php echo $langs->trans('Ref') ?></td>
  78. <td><?php echo dol_htmlentities($object->ref) ?>
  79. </tr>
  80. <tr>
  81. <td class="fieldrequired"><?php echo $langs->trans('Label') ?></td>
  82. <td><?php echo dol_htmlentities($object->label) ?></td>
  83. </tr>
  84. </table>
  85. <?php
  86. print '</div>';
  87. dol_fiche_end();
  88. print '<br>';
  89. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  90. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  91. print '<input type="hidden" name="action" value="add">';
  92. print '<input type="hidden" name="id" value="'.$object->id.'">';
  93. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  94. print load_fiche_titre($langs->trans('NewProductAttributeValue'));
  95. dol_fiche_head();
  96. ?>
  97. <table class="border" style="width: 100%">
  98. <tr>
  99. <td class="titlefield fieldrequired"><label for="ref"><?php echo $langs->trans('Ref') ?></label></td>
  100. <td><input id="ref" type="text" name="ref" value="<?php echo $ref ?>"></td>
  101. </tr>
  102. <tr>
  103. <td class="fieldrequired"><label for="value"><?php echo $langs->trans('Label') ?></label></td>
  104. <td><input id="value" type="text" name="value" value="<?php echo $value ?>"></td>
  105. </tr>
  106. </table>
  107. <?php
  108. dol_fiche_end();
  109. print '<div class="center">';
  110. print '<input type="submit" class="button" name="create" value="'.$langs->trans("Create").'">';
  111. print ' &nbsp; ';
  112. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  113. print '</div>';
  114. print '</form>';
  115. // End of page
  116. llxFooter();
  117. $db->close();