* Copyright (C) 2018 Frédéric France * * 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', 'aZ09'); $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(); } $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(); /* * Actions */ if ($cancel) { $action = ''; } if ($action) { if ($action == 'update') { $object->ref = $ref; $object->label = $label; if ($object->update($user) < 1) { setEventMessages($langs->trans('CoreErrorMessage'), $object->errors, 'errors'); } else { setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); header('Location: '.dol_buildpath('/variants/card.php?id='.$id, 2)); exit(); } } elseif ($action == 'update_value') { if ($objectval->fetch($valueid) > 0) { $objectval->ref = $ref; $objectval->value = GETPOST('value', 'alpha'); if (empty($objectval->ref)) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Ref")), null, 'errors'); } if (empty($objectval->value)) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors'); } if (!$error) { if ($objectval->update($user) > 0) { setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); } else { setEventMessage($langs->trans('CoreErrorMessage'), $objectval->errors, '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, $user); if ($res < 1 || ($object->delete($user) < 1)) { $db->rollback(); setEventMessages($langs->trans('CoreErrorMessage'), $object->errors, 'errors'); header('Location: '.dol_buildpath('/variants/card.php?id='.$object->id, 2)); } else { $db->commit(); setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); header('Location: '.dol_buildpath('/variants/list.php', 2)); } exit(); } elseif ($action == 'confirm_deletevalue') { if ($objectval->fetch($valueid) > 0) { if ($objectval->delete($user) < 1) { setEventMessages($langs->trans('CoreErrorMessage'), $objectval->errors, 'errors'); } else { setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); } header('Location: '.dol_buildpath('/variants/card.php?id='.$object->id, 2)); exit(); } } } /* * View */ $langs->load('products'); $help_url = 'EN:Module_Products#Variants'; $title = $langs->trans('ProductAttributeName', dol_htmlentities($object->label)); llxHeader('', $title, $help_url); //print load_fiche_titre($title); $h = 0; $head[$h][0] = DOL_URL_ROOT.'/variants/card.php?id='.$object->id; $head[$h][1] = $langs->trans("ProductAttributeName"); $head[$h][2] = 'variant'; $h++; print dol_get_fiche_head($head, 'variant', $langs->trans('ProductAttributeName'), -1, 'generic'); if ($action == 'edit') { print '
'; print ''; print ''; print ''; print ''; print ''; } if ($action != 'edit') { print '
'; print '
'; } print ''; print ''; print ''; print ''; print ''; print ''; print ''.$langs->trans('Label').''; print ''; print ''; print '
'.$langs->trans('Ref').''; if ($action == 'edit') { print ''; } else { print dol_htmlentities($object->ref); } print '
'; if ($action == 'edit') { print ''; } else { print dol_htmlentities($object->label); } print '
'; if ($action != 'edit') { print '
'; } print dol_get_fiche_end(); if ($action == 'edit') { print '
'; print '
'; print ''; print '   '; print ''; print '
'; print '
'; } else { if ($action == 'delete') { $form = new Form($db); print $form->formconfirm( "card.php?id=".$object->id, $langs->trans('Delete'), $langs->trans('ProductAttributeDeleteDialog'), "confirm_delete", '', 0, 1 ); } elseif ($action == 'delete_value') { if ($objectval->fetch($valueid) > 0) { $form = new Form($db); print $form->formconfirm( "card.php?id=".$object->id."&valueid=".$objectval->id, $langs->trans('Delete'), $langs->trans('ProductAttributeValueDeleteDialog', dol_htmlentities($objectval->value), dol_htmlentities($objectval->ref)), "confirm_deletevalue", '', 0, 1 ); } } ?> trans("PossibleValues")); if ($action == 'edit_value') { print '
'; print ''; print ''; print ''; print ''; print ''; } print ''; print ''; print ''; print ''; print ''; print ''; foreach ($objectval->fetchAllByProductAttribute($object->id) as $attrval) { print ''; if ($action == 'edit_value' && ($valueid == $attrval->id)) { ?> '; } print '
'.$langs->trans('Ref').''.$langs->trans('Value').'
" class="button button-save">     " class="button button-cancel"> ref) ?> value) ?>
'; if ($action == 'edit_value') { print '
'; } print '
'; print '
'; print ''.$langs->trans('Create').''; print '
'; print '
'; } // End of page llxFooter(); $db->close();