*
* 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
* along with this program. If not, see .
*/
require '../main.inc.php';
require 'class/ProductAttribute.class.php';
require 'class/ProductAttributeValue.class.php';
$id = GETPOST('id','int');
$valueid = GETPOST('valueid','alpha');
$action = GETPOST('action','alpha');
$label = GETPOST('label','alpha');
$ref = GETPOST('ref','alpha');
$confirm = GETPOST('confirm','alpha');
$cancel = GETPOST('cancel','alpha');
$object = new ProductAttribute($db);
$objectval = new ProductAttributeValue($db);
if ($object->fetch($id) < 1) {
dol_print_error($db, $langs->trans('ErrorRecordNotFound'));
exit();
}
/*
* Actions
*/
if ($cancel) $action='';
if ($_POST) {
if ($action == 'edit') {
$object->label = $label;
$object->ref = $ref;
if ($object->update() < 1) {
setEventMessage($langs->trans('CoreErrorMessage'), 'errors');
} else {
setEventMessage($langs->trans('RecordSaved'));
header('Location: '.dol_buildpath('/variants/card.php?id='.$id, 2));
exit();
}
} elseif ($action == 'edit_value') {
if ($objectval->fetch($valueid) > 0) {
$objectval->ref = $ref;
$objectval->value = GETPOST('value');
if ($objectval->update() > 0) {
setEventMessage($langs->trans('RecordSaved'));
} else {
setEventMessage($langs->trans('CoreErrorMessage'), 'errors');
}
}
header('Location: '.dol_buildpath('/variants/card.php?id='.$object->id, 2));
exit();
}
}
if ($confirm == 'yes') {
if ($action == 'confirm_delete') {
$db->begin();
$res = $objectval->deleteByFkAttribute($object->id);
if ($res < 1 || ($object->delete() < 1)) {
$db->rollback();
setEventMessage($langs->trans('CoreErrorMessage'), 'errors');
header('Location: '.dol_buildpath('/variants/card.php?id='.$object->id, 2));
} else {
$db->commit();
setEventMessage($langs->trans('RecordSaved'));
header('Location: '.dol_buildpath('/variants/list.php', 2));
}
exit();
}
elseif ($action == 'confirm_deletevalue')
{
if ($objectval->fetch($valueid) > 0) {
if ($objectval->delete() < 1) {
setEventMessage($langs->trans('CoreErrorMessage'), 'errors');
} else {
setEventMessage($langs->trans('RecordSaved'));
}
header('Location: '.dol_buildpath('/variants/card.php?id='.$object->id, 2));
exit();
}
}
}
/*
* View
*/
$langs->load('products');
$title = $langs->trans('ProductAttributeName', dol_htmlentities($object->label));
$var = false;
llxHeader('', $title);
//print_fiche_titre($title);
$h=0;
$head[$h][0] = DOL_URL_ROOT.'/variants/card.php?id='.$object->id;
$head[$h][1] = $langs->trans("Card");
$head[$h][2] = 'variant';
$h++;
dol_fiche_head($head, 'variant', $langs->trans('ProductAttributeName'), -1, 'generic');
if ($action == 'edit') {
print '