Skip to content

Commit

Permalink
Fix error management
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Feb 23, 2018
1 parent d8f8e76 commit 829de06
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
39 changes: 32 additions & 7 deletions htdocs/societe/card.php
Expand Up @@ -511,6 +511,8 @@
{
if ($action == 'add')
{
$error = 0;

$db->begin();

if (empty($object->client)) $object->code_client='';
Expand All @@ -533,11 +535,21 @@

// Customer categories association
$custcats = GETPOST('custcats', 'array');
$object->setCategories($custcats, 'customer');
$result = $object->setCategories($custcats, 'customer');
if ($result < 0)
{
$error++;
setEventMessages($object->error, $object->errors, 'errors');
}

// Supplier categories association
$suppcats = GETPOST('suppcats', 'array');
$object->setCategories($suppcats, 'supplier');
$result = $object->setCategories($suppcats, 'supplier');
if ($result < 0)
{
$error++;
setEventMessages($object->error, $object->errors, 'errors');
}

// Logo/Photo save
$dir = $conf->societe->multidir_output[$conf->entity]."/".$object->id."/logos/";
Expand Down Expand Up @@ -566,7 +578,7 @@
}
}
else
{
{
switch($_FILES['photo']['error'])
{
case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
Expand All @@ -593,7 +605,7 @@
$error++;
}

if ($result >= 0)
if ($result >= 0 && ! $error)
{
$db->commit();

Expand Down Expand Up @@ -622,6 +634,8 @@

if ($action == 'update')
{
$error = 0;

if (GETPOST('cancel','alpha'))
{
if (! empty($backtopage))
Expand All @@ -647,16 +661,27 @@
setEventMessages($object->error, $object->errors, 'errors');
$error++;
}

// Prevent thirdparty's emptying if a user hasn't rights $user->rights->categorie->lire (in such a case, post of 'custcats' is not defined)
if (!empty($user->rights->categorie->lire))
if (! $error && !empty($user->rights->categorie->lire))
{
// Customer categories association
$categories = GETPOST( 'custcats', 'array' );
$object->setCategories($categories, 'customer');
$result = $object->setCategories($categories, 'customer');
if ($result < 0)
{
$error++;
setEventMessages($object->error, $object->errors, 'errors');
}

// Supplier categories association
$categories = GETPOST('suppcats', 'array');
$object->setCategories($categories, 'supplier');
$result = $object->setCategories($categories, 'supplier');
if ($result < 0)
{
$error++;
setEventMessages($object->error, $object->errors, 'errors');
}
}

// Logo/Photo save
Expand Down
16 changes: 13 additions & 3 deletions htdocs/societe/class/societe.class.php
Expand Up @@ -3767,19 +3767,29 @@ public function setCategories($categories, $type)
$to_add = $categories;
}

$error = 0;

// Process
foreach ($to_del as $del) {
if ($c->fetch($del) > 0) {
$c->del_type($this, $type_text);
}
}
foreach ($to_add as $add) {
if ($c->fetch($add) > 0) {
$c->add_type($this, $type_text);
if ($c->fetch($add) > 0)
{
$result = $c->add_type($this, $type_text);
if ($result < 0)
{
$error++;
$this->error = $c->error;
$this->errors = $c->errors;
break;
}
}
}

return 1;
return $error ? -1 : 1;
}


Expand Down

0 comments on commit 829de06

Please sign in to comment.