create.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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_once DOL_DOCUMENT_ROOT.'/variants/class/ProductAttribute.class.php';
  20. $ref = GETPOST('ref', 'alpha');
  21. $label = GETPOST('label', 'alpha');
  22. $backtopage = GETPOST('backtopage', 'alpha');
  23. /*
  24. * Actions
  25. */
  26. if ($_POST) {
  27. if (empty($ref) || empty($label)) {
  28. setEventMessages($langs->trans('ErrorFieldsRequired'), null, 'errors');
  29. } else {
  30. $prodattr = new ProductAttribute($db);
  31. $prodattr->label = $label;
  32. $prodattr->ref = $ref;
  33. $resid = $prodattr->create($user);
  34. if ($resid > 0) {
  35. setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
  36. if ($backtopage)
  37. {
  38. header('Location: '.$backtopage);
  39. }
  40. else
  41. {
  42. header('Location: '.DOL_URL_ROOT.'/variants/card.php?id='.$resid.'&backtopage='.urlencode($backtopage));
  43. }
  44. exit;
  45. } else {
  46. setEventMessages($langs->trans('ErrorRecordAlreadyExists'), $prodattr->errors, 'errors');
  47. }
  48. }
  49. }
  50. $langs->load('products');
  51. /*
  52. * View
  53. */
  54. $title = $langs->trans('NewProductAttribute');
  55. llxHeader('', $title);
  56. print load_fiche_titre($title);
  57. dol_fiche_head();
  58. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  59. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  60. print '<input type="hidden" name="action" value="add">';
  61. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  62. ?>
  63. <table class="border" style="width: 100%">
  64. <tr>
  65. <td class="titlefield fieldrequired"><label for="ref"><?php echo $langs->trans('Ref') ?></label></td>
  66. <td><input type="text" id="ref" name="ref" value="<?php echo $ref ?>"></td>
  67. <td><?php echo $langs->trans("VariantRefExample"); ?>
  68. </tr>
  69. <tr>
  70. <td class="fieldrequired"><label for="label"><?php echo $langs->trans('Label') ?></label></td>
  71. <td><input type="text" id="label" name="label" value="<?php echo $label ?>"></td>
  72. <td><?php echo $langs->trans("VariantLabelExample"); ?>
  73. </tr>
  74. </table>
  75. <?php
  76. dol_fiche_end();
  77. print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Create").'"></div>';
  78. print '</form>';
  79. // End of page
  80. llxFooter();
  81. $db->close();