create.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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_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. $action = GETPOST('action', 'alpha');
  24. $permissiontoread = $user->rights->produit->lire || $user->rights->service->lire;
  25. // Security check
  26. if (empty($conf->variants->enabled)) {
  27. accessforbidden('Module not enabled');
  28. }
  29. if ($user->socid > 0) { // Protection if external user
  30. accessforbidden();
  31. }
  32. //$result = restrictedArea($user, 'variant');
  33. if (!$permissiontoread) accessforbidden();
  34. /*
  35. * Actions
  36. */
  37. if ($action == 'add') {
  38. if (empty($ref) || empty($label)) {
  39. setEventMessages($langs->trans('ErrorFieldsRequired'), null, 'errors');
  40. } else {
  41. $prodattr = new ProductAttribute($db);
  42. $prodattr->label = $label;
  43. $prodattr->ref = $ref;
  44. $resid = $prodattr->create($user);
  45. if ($resid > 0) {
  46. setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
  47. if ($backtopage) {
  48. header('Location: '.$backtopage);
  49. } else {
  50. header('Location: '.DOL_URL_ROOT.'/variants/card.php?id='.$resid.'&backtopage='.urlencode($backtopage));
  51. }
  52. exit;
  53. } else {
  54. setEventMessages($langs->trans('ErrorRecordAlreadyExists'), $prodattr->errors, 'errors');
  55. }
  56. }
  57. }
  58. $langs->load('products');
  59. /*
  60. * View
  61. */
  62. $help_url = 'EN:Module_Products#Variants';
  63. $title = $langs->trans('NewProductAttribute');
  64. llxHeader('', $title, $help_url);
  65. print load_fiche_titre($title);
  66. print dol_get_fiche_head();
  67. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  68. print '<input type="hidden" name="token" value="'.newToken().'">';
  69. print '<input type="hidden" name="action" value="add">';
  70. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  71. ?>
  72. <table class="border centpercent">
  73. <tr>
  74. <td class="titlefield fieldrequired"><label for="ref"><?php echo $langs->trans('Ref') ?></label></td>
  75. <td><input type="text" id="ref" name="ref" value="<?php echo $ref ?>"></td>
  76. <td><?php echo $langs->trans("VariantRefExample"); ?>
  77. </tr>
  78. <tr>
  79. <td class="fieldrequired"><label for="label"><?php echo $langs->trans('Label') ?></label></td>
  80. <td><input type="text" id="label" name="label" value="<?php echo $label ?>"></td>
  81. <td><?php echo $langs->trans("VariantLabelExample"); ?>
  82. </tr>
  83. </table>
  84. <?php
  85. print dol_get_fiche_end();
  86. print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Create").'"></div>';
  87. print '</form>';
  88. // End of page
  89. llxFooter();
  90. $db->close();