dolibarr/htdocs/variants/create_val.php

162 lines
4.5 KiB
PHP
Raw Normal View History

2016-07-23 16:37:21 +02:00
<?php
/* Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
2018-07-25 09:36:34 +02:00
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
2016-07-23 16:37:21 +02:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2016-07-23 16:37:21 +02:00
*/
require '../main.inc.php';
require 'class/ProductAttribute.class.php';
require 'class/ProductAttributeValue.class.php';
$id = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha');
$value = GETPOST('value', 'alpha');
2017-05-10 12:35:05 +02:00
2020-09-16 19:39:50 +02:00
$action = GETPOST('action', 'aZ09');
$cancel = GETPOST('cancel', 'alpha');
$backtopage = GETPOST('backtopage', 'alpha');
2016-07-23 16:37:21 +02:00
2017-05-10 12:35:05 +02:00
$object = new ProductAttribute($db);
$objectval = new ProductAttributeValue($db);
2016-07-23 16:37:21 +02:00
2017-05-10 12:35:05 +02:00
if ($object->fetch($id) < 1) {
2016-07-23 16:37:21 +02:00
dol_print_error($db, $langs->trans('ErrorRecordNotFound'));
2017-02-08 12:52:31 +01:00
exit();
2016-07-23 16:37:21 +02:00
}
2021-03-20 18:58:34 +01:00
$permissiontoread = $user->rights->produit->lire || $user->rights->service->lire;
// Security check
if (empty($conf->variants->enabled)) {
accessforbidden('Module not enabled');
}
if ($user->socid > 0) { // Protection if external user
accessforbidden();
}
//$result = restrictedArea($user, 'variant');
if (!$permissiontoread) accessforbidden();
2016-07-23 16:37:21 +02:00
2017-05-10 12:35:05 +02:00
/*
* Actions
*/
if ($cancel) {
$action = '';
header('Location: '.DOL_URL_ROOT.'/variants/card.php?id='.$object->id);
exit();
2017-05-10 12:35:05 +02:00
}
// None
/*
* View
*/
if ($action == 'add') {
2016-07-23 16:37:21 +02:00
if (empty($ref) || empty($value)) {
2018-07-27 14:49:33 +02:00
setEventMessages($langs->trans('ErrorFieldsRequired'), null, 'errors');
2016-07-23 16:37:21 +02:00
} else {
2017-05-10 12:35:05 +02:00
$objectval->fk_product_attribute = $object->id;
$objectval->ref = $ref;
$objectval->value = $value;
2016-07-23 16:37:21 +02:00
2018-03-10 12:37:44 +01:00
if ($objectval->create($user) > 0) {
2018-07-27 14:49:33 +02:00
setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
2017-05-10 12:35:05 +02:00
header('Location: '.DOL_URL_ROOT.'/variants/card.php?id='.$object->id);
2017-02-08 12:52:31 +01:00
exit();
2016-07-23 16:37:21 +02:00
} else {
2018-07-25 09:36:34 +02:00
setEventMessages($langs->trans('ErrorCreatingProductAttributeValue'), $objectval->errors, 'errors');
2016-07-23 16:37:21 +02:00
}
}
}
$langs->load('products');
$help_url = 'EN:Module_Products#Variants';
2017-05-10 12:35:05 +02:00
$title = $langs->trans('ProductAttributeName', dol_htmlentities($object->label));
2016-07-23 16:37:21 +02:00
llxHeader('', $title, $help_url);
2016-07-23 16:37:21 +02:00
$h = 0;
2017-05-10 12:35:05 +02:00
$head[$h][0] = DOL_URL_ROOT.'/variants/card.php?id='.$object->id;
2020-05-17 13:34:16 +02:00
$head[$h][1] = $langs->trans("ProductAttributeName");
2017-05-10 12:35:05 +02:00
$head[$h][2] = 'variant';
$h++;
2016-07-23 16:37:21 +02:00
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head($head, 'variant', $langs->trans('ProductAttributeName'), -1, 'generic');
2016-07-23 16:37:21 +02:00
2017-05-10 12:35:05 +02:00
print '<div class="fichecenter">';
print '<div class="underbanner clearboth"></div>';
2016-07-23 16:37:21 +02:00
?>
<table class="border" style="width: 100%">
<tr>
2017-05-10 12:35:05 +02:00
<td class="titlefield fieldrequired"><?php echo $langs->trans('Ref') ?></td>
<td><?php echo dol_htmlentities($object->ref) ?>
2016-07-23 16:37:21 +02:00
</tr>
<tr>
2017-05-10 12:35:05 +02:00
<td class="fieldrequired"><?php echo $langs->trans('Label') ?></td>
<td><?php echo dol_htmlentities($object->label) ?></td>
2016-07-23 16:37:21 +02:00
</tr>
</table>
<?php
2017-05-10 12:35:05 +02:00
print '</div>';
2016-07-23 16:37:21 +02:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end();
2016-07-23 16:37:21 +02:00
2017-05-10 12:35:05 +02:00
print '<br>';
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<input type="hidden" name="token" value="'.newToken().'">';
2017-05-10 12:35:05 +02:00
print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
2018-09-09 18:38:48 +02:00
print load_fiche_titre($langs->trans('NewProductAttributeValue'));
2016-07-23 16:37:21 +02:00
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head();
2017-05-10 12:35:05 +02:00
2016-07-23 16:37:21 +02:00
?>
<table class="border" style="width: 100%">
<tr>
2017-05-10 12:35:05 +02:00
<td class="titlefield fieldrequired"><label for="ref"><?php echo $langs->trans('Ref') ?></label></td>
2016-07-23 16:37:21 +02:00
<td><input id="ref" type="text" name="ref" value="<?php echo $ref ?>"></td>
</tr>
<tr>
2017-11-26 10:13:32 +01:00
<td class="fieldrequired"><label for="value"><?php echo $langs->trans('Label') ?></label></td>
2016-07-23 16:37:21 +02:00
<td><input id="value" type="text" name="value" value="<?php echo $value ?>"></td>
</tr>
</table>
<?php
2017-05-10 12:35:05 +02:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end();
2016-07-23 16:37:21 +02:00
2017-05-10 12:35:05 +02:00
print '<div class="center">';
print '<input type="submit" class="button" name="create" value="'.$langs->trans("Create").'">';
print ' &nbsp; ';
print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
2017-05-10 12:35:05 +02:00
print '</div>';
print '</form>';
2016-07-23 16:37:21 +02:00
2018-08-04 15:58:05 +02:00
// End of page
2017-05-10 12:35:05 +02:00
llxFooter();
$db->close();