code cleaning

This commit is contained in:
Frédéric FRANCE 2018-07-25 09:36:34 +02:00
parent 0c0c9269d5
commit b87c3b80af
No known key found for this signature in database
GPG Key ID: 06809324E4B2ABC1
6 changed files with 43 additions and 41 deletions

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2016 Marcos García <marcosgdf@gmail.com> /* Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -31,15 +31,15 @@ if ($_POST) {
$value = GETPOST('PRODUIT_ATTRIBUTES_HIDECHILD'); $value = GETPOST('PRODUIT_ATTRIBUTES_HIDECHILD');
if (dolibarr_set_const($db, 'PRODUIT_ATTRIBUTES_HIDECHILD', $value, 'chaine', 0, '', $conf->entity)) { if (dolibarr_set_const($db, 'PRODUIT_ATTRIBUTES_HIDECHILD', $value, 'chaine', 0, '', $conf->entity)) {
setEventMessage($langs->trans('RecordSaved')); setEventMessages($langs->trans('RecordSaved'), null);
} else { } else {
setEventMessage($langs->trans('CoreErrorMessage'), 'errors'); setEventMessages($langs->trans('CoreErrorMessage'), null, 'errors');
} }
if (dolibarr_set_const($db, 'PRODUIT_ATTRIBUTES_SEPARATOR', GETPOST('PRODUIT_ATTRIBUTES_SEPARATOR'), 'chaine', 0, '', $conf->entity)) { if (dolibarr_set_const($db, 'PRODUIT_ATTRIBUTES_SEPARATOR', GETPOST('PRODUIT_ATTRIBUTES_SEPARATOR'), 'chaine', 0, '', $conf->entity)) {
setEventMessage($langs->trans('RecordSaved')); setEventMessages($langs->trans('RecordSaved'), null);
} else { } else {
setEventMessage($langs->trans('CoreErrorMessage'), 'errors'); setEventMessages($langs->trans('CoreErrorMessage'), null, 'errors');
} }
} }
@ -72,6 +72,4 @@ print '<br><div style="text-align: center"><input type="submit" value="'.$langs-
print '</form>'; print '</form>';
llxFooter(); llxFooter();
$db->close(); $db->close();

View File

@ -1,5 +1,6 @@
<?php <?php
/* Copyright (C) 2016 Marcos García <marcosgdf@gmail.com> /* Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -50,9 +51,9 @@ if ($_POST) {
$object->label = $label; $object->label = $label;
if ($object->update($user) < 1) { if ($object->update($user) < 1) {
setEventMessage($langs->trans('CoreErrorMessage'), 'errors'); setEventMessages($langs->trans('CoreErrorMessage'), $object->errors, 'errors');
} else { } else {
setEventMessage($langs->trans('RecordSaved')); setEventMessages($langs->trans('RecordSaved'), null);
header('Location: '.dol_buildpath('/variants/card.php?id='.$id, 2)); header('Location: '.dol_buildpath('/variants/card.php?id='.$id, 2));
exit(); exit();
} }
@ -77,9 +78,9 @@ if ($_POST) {
if (! $error) if (! $error)
{ {
if ($objectval->update($user) > 0) { if ($objectval->update($user) > 0) {
setEventMessage($langs->trans('RecordSaved')); setEventMessages($langs->trans('RecordSaved'), null);
} else { } else {
setEventMessage($langs->trans('CoreErrorMessage'), 'errors'); setEventMessages($langs->trans('CoreErrorMessage'), $objectval->errors, 'errors');
} }
} }
} }
@ -99,11 +100,11 @@ if ($confirm == 'yes') {
if ($res < 1 || ($object->delete() < 1)) { if ($res < 1 || ($object->delete() < 1)) {
$db->rollback(); $db->rollback();
setEventMessage($langs->trans('CoreErrorMessage'), 'errors'); setEventMessages($langs->trans('CoreErrorMessage'), $object->errors, 'errors');
header('Location: '.dol_buildpath('/variants/card.php?id='.$object->id, 2)); header('Location: '.dol_buildpath('/variants/card.php?id='.$object->id, 2));
} else { } else {
$db->commit(); $db->commit();
setEventMessage($langs->trans('RecordSaved')); setEventMessages($langs->trans('RecordSaved'), null);
header('Location: '.dol_buildpath('/variants/list.php', 2)); header('Location: '.dol_buildpath('/variants/list.php', 2));
} }
exit(); exit();
@ -113,9 +114,9 @@ if ($confirm == 'yes') {
if ($objectval->fetch($valueid) > 0) { if ($objectval->fetch($valueid) > 0) {
if ($objectval->delete() < 1) { if ($objectval->delete() < 1) {
setEventMessage($langs->trans('CoreErrorMessage'), 'errors'); setEventMessages($langs->trans('CoreErrorMessage'), $objectval->errors, 'errors');
} else { } else {
setEventMessage($langs->trans('RecordSaved')); setEventMessages($langs->trans('RecordSaved'), null);
} }
header('Location: '.dol_buildpath('/variants/card.php?id='.$object->id, 2)); header('Location: '.dol_buildpath('/variants/card.php?id='.$object->id, 2));

View File

@ -1,6 +1,7 @@
<?php <?php
/* Copyright (C) 2016 Marcos García <marcosgdf@gmail.com> /* Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -104,7 +105,7 @@ if ($_POST) {
$features = $_SESSION['addvariant_'.$object->id]; $features = $_SESSION['addvariant_'.$object->id];
if (!$features) { if (!$features) {
setEventMessage($langs->trans('ErrorFieldsRequired'), 'errors'); setEventMessages($langs->trans('ErrorFieldsRequired'), null, 'errors');
} }
else else
{ {
@ -147,7 +148,7 @@ if ($_POST) {
$result = $prodcomb->createProductCombination($object, $sanit_features, array(), $price_impact_percent, $price_impact, $weight_impact); $result = $prodcomb->createProductCombination($object, $sanit_features, array(), $price_impact_percent, $price_impact, $weight_impact);
if ($result > 0) if ($result > 0)
{ {
setEventMessage($langs->trans('RecordSaved')); setEventMessages($langs->trans('RecordSaved'), null);
unset($_SESSION['addvariant_'.$object->id]); unset($_SESSION['addvariant_'.$object->id]);
$db->commit(); $db->commit();
@ -214,7 +215,7 @@ if ($_POST) {
} else { } else {
$db->commit(); $db->commit();
setEventMessage($langs->trans('RecordSaved')); setEventMessages($langs->trans('RecordSaved'), null);
} }
} }
@ -230,7 +231,7 @@ if ($_POST) {
$prodcomb->variation_weight = $weight_impact; $prodcomb->variation_weight = $weight_impact;
if ($prodcomb->update($user) > 0) { if ($prodcomb->update($user) > 0) {
setEventMessage($langs->trans('RecordSaved')); setEventMessages($langs->trans('RecordSaved'), null);
header('Location: '.dol_buildpath('/variants/combinations.php?id='.$id, 2)); header('Location: '.dol_buildpath('/variants/combinations.php?id='.$id, 2));
exit(); exit();
} else { } else {
@ -250,13 +251,13 @@ if ($action === 'confirm_deletecombination') {
if ($prodcomb->delete($user) > 0 && $prodstatic->fetch($prodcomb->fk_product_child) > 0 && $prodstatic->delete($user) > 0) { if ($prodcomb->delete($user) > 0 && $prodstatic->fetch($prodcomb->fk_product_child) > 0 && $prodstatic->delete($user) > 0) {
$db->commit(); $db->commit();
setEventMessage($langs->trans('RecordSaved')); setEventMessages($langs->trans('RecordSaved'), null);
header('Location: '.dol_buildpath('/variants/combinations.php?id='.$object->id, 2)); header('Location: '.dol_buildpath('/variants/combinations.php?id='.$object->id, 2));
exit(); exit();
} }
$db->rollback(); $db->rollback();
setEventMessage($langs->trans('ProductCombinationAlreadyUsed'), 'errors'); setEventMessages($langs->trans('ProductCombinationAlreadyUsed'), null, 'errors');
$action = ''; $action = '';
} }
} elseif ($action === 'edit') { } elseif ($action === 'edit') {
@ -284,12 +285,12 @@ if ($action === 'confirm_deletecombination') {
header('Location: '.dol_buildpath('/variants/combinations.php?id='.$prodstatic->id, 2)); header('Location: '.dol_buildpath('/variants/combinations.php?id='.$prodstatic->id, 2));
exit(); exit();
} else { } else {
setEventMessage($langs->trans('ErrorCopyProductCombinations'), 'errors'); setEventMessages($langs->trans('ErrorCopyProductCombinations'), null, 'errors');
} }
} }
} else { } else {
setEventMessage($langs->trans('ErrorDestinationProductNotFound'), 'errors'); setEventMessages($langs->trans('ErrorDestinationProductNotFound'), null, 'errors');
} }
} }

View File

@ -1,5 +1,6 @@
<?php <?php
/* Copyright (C) 2016 Marcos García <marcosgdf@gmail.com> /* Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -29,7 +30,7 @@ $backtopage = GETPOST('backtopage', 'alpha');
if ($_POST) { if ($_POST) {
if (empty($ref) || empty($label)) { if (empty($ref) || empty($label)) {
setEventMessage($langs->trans('ErrorFieldsRequired'), 'errors'); setEventMessages($langs->trans('ErrorFieldsRequired'), null, 'errors');
} else { } else {
$prodattr = new ProductAttribute($db); $prodattr = new ProductAttribute($db);
@ -38,7 +39,7 @@ if ($_POST) {
$resid = $prodattr->create($user); $resid = $prodattr->create($user);
if ($resid > 0) { if ($resid > 0) {
setEventMessage($langs->trans('RecordSaved')); setEventMessages($langs->trans('RecordSaved'), null);
if ($backtopage) if ($backtopage)
{ {
header('Location: '.$backtopage); header('Location: '.$backtopage);
@ -49,7 +50,7 @@ if ($_POST) {
} }
exit; exit;
} else { } else {
setEventMessage($langs->trans('ErrorRecordAlreadyExists'), 'errors'); setEventMessages($langs->trans('ErrorRecordAlreadyExists'), $prodattr->errors, 'errors');
} }
} }
} }

View File

@ -1,5 +1,6 @@
<?php <?php
/* Copyright (C) 2016 Marcos García <marcosgdf@gmail.com> /* Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -58,7 +59,7 @@ if ($cancel)
if ($action == 'add') if ($action == 'add')
{ {
if (empty($ref) || empty($value)) { if (empty($ref) || empty($value)) {
setEventMessage($langs->trans('ErrorFieldsRequired'), 'errors'); setEventMessages($langs->trans('ErrorFieldsRequired'), null, 'errors');
} else { } else {
$objectval->fk_product_attribute = $object->id; $objectval->fk_product_attribute = $object->id;
@ -66,11 +67,11 @@ if ($action == 'add')
$objectval->value = $value; $objectval->value = $value;
if ($objectval->create($user) > 0) { if ($objectval->create($user) > 0) {
setEventMessage($langs->trans('RecordSaved')); setEventMessages($langs->trans('RecordSaved'), null);
header('Location: '.DOL_URL_ROOT.'/variants/card.php?id='.$object->id); header('Location: '.DOL_URL_ROOT.'/variants/card.php?id='.$object->id);
exit(); exit();
} else { } else {
setEventMessage($langs->trans('ErrorCreatingProductAttributeValue'), 'errors'); setEventMessages($langs->trans('ErrorCreatingProductAttributeValue'), $objectval->errors, 'errors');
} }
} }
} }

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2016 Marcos García <marcosgdf@gmail.com> /* Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -115,18 +115,18 @@ if ($_POST) {
if ($res > 0) { if ($res > 0) {
$db->commit(); $db->commit();
setEventMessage($langs->trans('RecordSaved')); setEventMessages($langs->trans('RecordSaved'), null);
header('Location: '.dol_buildpath('/variants/combinations.php?id='.$id, 2)); header('Location: '.dol_buildpath('/variants/combinations.php?id='.$id, 2));
exit; exit;
} }
} else { } else {
setEventMessage($langs->trans('ErrorDeletingGeneratedProducts'), 'errors'); setEventMessages($langs->trans('ErrorDeletingGeneratedProducts'), null, 'errors');
} }
$db->rollback(); $db->rollback();
} else { } else {
setEventMessage($langs->trans('ErrorFieldsRequired'), 'errors'); setEventMessages($langs->trans('ErrorFieldsRequired'), null, 'errors');
} }
} }