From 4bde7e9f51a18926713a1c04cb6bd5af70ace820 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur <eldy@destailleur.fr> Date: Thu, 26 Feb 2015 14:25:30 +0100 Subject: [PATCH] Fix: Missing error management --- htdocs/adherents/card.php | 2 ++ htdocs/adherents/type.php | 2 ++ htdocs/categories/card.php | 1 + htdocs/categories/edit.php | 3 ++- htdocs/comm/action/card.php | 2 ++ htdocs/comm/propal.php | 6 ++--- htdocs/commande/card.php | 12 +++++----- htdocs/compta/facture.php | 7 +++--- htdocs/contact/card.php | 2 ++ htdocs/contrat/card.php | 24 +++++++++++--------- htdocs/core/class/extrafields.class.php | 2 +- htdocs/fourn/commande/card.php | 25 +++++++++++++-------- htdocs/fourn/facture/card.php | 5 ++--- htdocs/product/card.php | 9 ++++++-- htdocs/projet/card.php | 6 ++--- htdocs/projet/tasks/task.php | 11 +++++---- htdocs/public/members/new.php | 1 + htdocs/societe/soc.php | 2 +- htdocs/user/card.php | 30 ++++++++++++++----------- htdocs/user/group/card.php | 2 ++ 20 files changed, 91 insertions(+), 63 deletions(-) diff --git a/htdocs/adherents/card.php b/htdocs/adherents/card.php index d8a1a85debf..94f12a61f8b 100644 --- a/htdocs/adherents/card.php +++ b/htdocs/adherents/card.php @@ -302,6 +302,7 @@ if (empty($reshook)) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if ($ret < 0) $error++; // Check if we need to also synchronize user information $nosyncuser=0; @@ -471,6 +472,7 @@ if (empty($reshook)) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if ($ret < 0) $error++; // Check parameters if (empty($morphy) || $morphy == "-1") { diff --git a/htdocs/adherents/type.php b/htdocs/adherents/type.php index 96e13561825..ea39a200c97 100644 --- a/htdocs/adherents/type.php +++ b/htdocs/adherents/type.php @@ -89,6 +89,7 @@ if ($action == 'add' && $user->rights->adherent->configurer) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$adht); + if ($ret < 0) $error++; if ($adht->libelle) { @@ -126,6 +127,7 @@ if ($action == 'update' && $user->rights->adherent->configurer) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$adht); + if ($ret < 0) $error++; $adht->update($user); diff --git a/htdocs/categories/card.php b/htdocs/categories/card.php index 672c92b9508..8a587d7de32 100644 --- a/htdocs/categories/card.php +++ b/htdocs/categories/card.php @@ -127,6 +127,7 @@ if ($action == 'add' && $user->rights->categorie->creer) if ($parent != "-1") $object->fk_parent = $parent; $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if ($ret < 0) $error++; if (! $object->label) { diff --git a/htdocs/categories/edit.php b/htdocs/categories/edit.php index aa82fdb455d..a105d104036 100644 --- a/htdocs/categories/edit.php +++ b/htdocs/categories/edit.php @@ -90,7 +90,8 @@ if ($action == 'update' && $user->rights->categorie->creer) if (empty($categorie->error)) { $ret = $extrafields->setOptionalsFromPost($extralabels,$categorie); - + if ($ret < 0) $error++; + if ($categorie->update($user) > 0) { header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$categorie->id.'&type='.$type); diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index 0a4b255884a..c15b1fe4f32 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -274,6 +274,7 @@ if ($action == 'add') // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if ($ret < 0) $error++; if (! $error) { @@ -429,6 +430,7 @@ if ($action == 'update') // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if ($ret < 0) $error++; if (! $error) { diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 030aff46434..3739b59c338 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -1080,10 +1080,10 @@ if (empty($reshook)) // Fill array 'array_options' with data from update form $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute')); - if ($ret < 0) - $error ++; + if ($ret < 0) $error++; - if (! $error) { + if (! $error) + { // Actions on extra fields (by external module or standard code) // FIXME le hook fait double emploi avec le trigger !! $hookmanager->initHooks(array('propaldao')); diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 5b76dd59323..eb5767b173a 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -271,8 +271,7 @@ if (empty($reshook)) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels, $object); - if ($ret < 0) - $error ++; + if ($ret < 0) $error++; if (! $error) { @@ -365,10 +364,10 @@ if (empty($reshook)) } else { // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels, $object); - if ($ret < 0) - $error ++; + if ($ret < 0) $error++; - if (! $error) { + if (! $error) + { $object_id = $object->create($user); // If some invoice's lines already known @@ -1124,8 +1123,7 @@ if (empty($reshook)) // Fill array 'array_options' with data from update form $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute')); - if ($ret < 0) - $error ++; + if ($ret < 0) $error++; if (! $error) { // Actions on extra fields (by external module or standard code) diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 5f1f3998b5d..3d7a71f8133 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -585,7 +585,7 @@ if (empty($reshook)) $discount->fk_facture_source = $object->id; $error = 0; - + foreach ($amount_ht as $tva_tx => $xxx) { $discount->amount_ht = abs($amount_ht [$tva_tx]); $discount->amount_tva = abs($amount_tva [$tva_tx]); @@ -636,7 +636,7 @@ if (empty($reshook)) // Fill array 'array_options' with data from add form $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $ret = $extrafields->setOptionalsFromPost($extralabels, $object); - if ($ret < 0) $error ++; + if ($ret < 0) $error++; // Replacement invoice if ($_POST['type'] == Facture::TYPE_REPLACEMENT) @@ -1676,8 +1676,7 @@ if (empty($reshook)) // Fill array 'array_options' with data from add form $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute')); - if ($ret < 0) - $error ++; + if ($ret < 0) $error++; if (! $error) { // Actions on extra fields (by external module or standard code) diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php index af07cbb9a62..248352dfee3 100644 --- a/htdocs/contact/card.php +++ b/htdocs/contact/card.php @@ -200,6 +200,7 @@ if (empty($reshook)) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if ($ret < 0) $error++; if (! GETPOST("lastname")) { @@ -303,6 +304,7 @@ if (empty($reshook)) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if ($ret < 0) $error++; $result = $object->update($contactid, $user); diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index fdd0acfec74..6d10442caf7 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -355,6 +355,7 @@ if ($action == 'add' && $user->rights->contrat->creer) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels, $object); + if ($ret < 0) $error++; $result = $object->create($user); if ($result > 0) @@ -702,19 +703,20 @@ else if ($action == 'confirm_move' && $confirm == 'yes' && $user->rights->contra // Fill array 'array_options' with data from update form $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute')); - if ($ret < 0) - $error ++; - - if (! $error) { + if ($ret < 0) $error++; - $result = $object->insertExtraFields(); - if ($result < 0) { - $error ++; - } - } else if ($reshook < 0) - $error ++; + if (! $error) + { + $result = $object->insertExtraFields(); + if ($result < 0) + { + $error++; + } + } + else if ($reshook < 0) $error++; - if ($error) { + if ($error) + { $action = 'edit_extras'; setEventMessage($object->error,'errors'); } diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 008dff0f019..cc602d08ed5 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -1063,7 +1063,7 @@ class ExtraFields * @param array $extralabels $array of extrafields * @param object $object Object * @param string $onlykey Only following key is filled. When we make update of only one extrafield ($action = 'update_extras'), calling page must must set this to avoid to have other extrafields being reset. - * @return int 1 if array_options set / 0 if no value + * @return int 1 if array_options set, 0 if no value, -1 if error (field required missing for example) */ function setOptionalsFromPost($extralabels,&$object,$onlykey='') { diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index 28b492651c0..0257b51c946 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -783,7 +783,7 @@ if ($action == 'update_extras') $ret = $extrafields->setOptionalsFromPost($extralabels,$object,GETPOST('attribute')); if ($ret < 0) $error++; - if (!$error) + if (! $error) { // Actions on extra fields (by external module or standard code) // FIXME le hook fait double emploi avec le trigger !! @@ -842,19 +842,26 @@ if ($action == 'add' && $user->rights->fournisseur->commande->creer) $object->date_livraison = $datelivraison; // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost($extralabels,$object); - - $id = $object->create($user); - if ($id < 0) - { - $error++; - } + if (! $error) + { + $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if ($ret < 0) $error++; + } + + if (! $error) + { + $id = $object->create($user); + if ($id < 0) + { + $error++; + setEventMessage($langs->trans($object->error), 'errors'); + } + } if ($error) { $langs->load("errors"); $db->rollback(); - setEventMessage($langs->trans($object->error), 'errors'); $action='create'; $_GET['socid']=$_POST['socid']; } diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index a10aa89ae65..54ef660f6aa 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -308,7 +308,7 @@ elseif ($action == 'add' && $user->rights->fournisseur->facture->creer) $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $ret = $extrafields->setOptionalsFromPost($extralabels, $object); - if ($ret < 0) $error ++; + if ($ret < 0) $error++; $tmpproject = GETPOST('projectid', 'int'); @@ -1071,8 +1071,7 @@ elseif ($action == 'update_extras') // Fill array 'array_options' with data from add form $extralabels=$extrafields->fetch_name_optionals_label($object->table_element); $ret = $extrafields->setOptionalsFromPost($extralabels,$object,GETPOST('attribute')); - - if($ret < 0) $error++; + if ($ret < 0) $error++; if (!$error) { diff --git a/htdocs/product/card.php b/htdocs/product/card.php index a4c4e4ee92e..b5f34e20a8d 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -262,8 +262,12 @@ if (empty($reshook)) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if ($ret < 0) $error++; - $id = $object->create($user); + if (! $error) + { + $id = $object->create($user); + } if ($id > 0) { @@ -339,8 +343,9 @@ if (empty($reshook)) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if ($ret < 0) $error++; - if ($object->check()) + if (! $error && $object->check()) { if ($object->update($object->id, $user) > 0) { diff --git a/htdocs/projet/card.php b/htdocs/projet/card.php index b376133699b..1c971ef9e35 100644 --- a/htdocs/projet/card.php +++ b/htdocs/projet/card.php @@ -147,6 +147,7 @@ if (empty($reshook)) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if ($ret < 0) $error++; $result = $object->create($user); if ($result > 0) @@ -222,10 +223,7 @@ if (empty($reshook)) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); - if ($ret < 0) - { - $error++; - } + if ($ret < 0) $error++; } if (! $error) diff --git a/htdocs/projet/tasks/task.php b/htdocs/projet/tasks/task.php index 11bc8ffea09..a9cd64e33b5 100644 --- a/htdocs/projet/tasks/task.php +++ b/htdocs/projet/tasks/task.php @@ -91,12 +91,15 @@ if ($action == 'update' && ! $_POST["cancel"] && $user->rights->projet->creer) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if ($ret < 0) $error++; - $result=$object->update($user); - - if ($result < 0) + if (! $error) { - setEventMessages($object->error,$object->errors,'errors'); + $result=$object->update($user); + if ($result < 0) + { + setEventMessages($object->error,$object->errors,'errors'); + } } } else diff --git a/htdocs/public/members/new.php b/htdocs/public/members/new.php index c8628bd26a0..255e7fe9134 100644 --- a/htdocs/public/members/new.php +++ b/htdocs/public/members/new.php @@ -250,6 +250,7 @@ if ($action == 'add') // Fill array 'array_options' with data from add form $extralabels=$extrafields->fetch_name_optionals_label($adh->table_element); $ret = $extrafields->setOptionalsFromPost($extralabels,$adh); + if ($ret < 0) $error++; $result=$adh->create($user); if ($result > 0) diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php index 72e249ce542..065bbbc0ac8 100644 --- a/htdocs/societe/soc.php +++ b/htdocs/societe/soc.php @@ -195,7 +195,7 @@ if (empty($reshook)) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); - + if ($ret < 0) $error++; if (GETPOST('deletephoto')) $object->logo = ''; else if (! empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']); diff --git a/htdocs/user/card.php b/htdocs/user/card.php index ec6b65e534c..7c5caf5254a 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -211,6 +211,7 @@ if ($action == 'add' && $canadduser) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if ($ret < 0) $error++; // If multicompany is off, admin users must all be on entity 0. $entity=GETPOST('entity','int'); @@ -358,6 +359,7 @@ if ($action == 'update' && ! $_POST["cancel"]) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if ($ret < 0) $error++; if (! empty($conf->multicompany->enabled)) { @@ -382,20 +384,22 @@ if ($action == 'update' && ! $_POST["cancel"]) if (GETPOST('deletephoto')) $object->photo=''; if (! empty($_FILES['photo']['name'])) $object->photo = dol_sanitizeFileName($_FILES['photo']['name']); - $ret=$object->update($user); - - if ($ret < 0) + if (! $error) { - $error++; - if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') - { - $langs->load("errors"); - setEventMessage($langs->trans("ErrorLoginAlreadyExists",$object->login), 'errors'); - } - else - { - setEventMessage($object->error, 'errors'); - } + $ret=$object->update($user); + if ($ret < 0) + { + $error++; + if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { + $langs->load("errors"); + setEventMessage($langs->trans("ErrorLoginAlreadyExists",$object->login), 'errors'); + } + else + { + setEventMessage($object->error, 'errors'); + } + } } if (! $error && isset($_POST['contactid'])) diff --git a/htdocs/user/group/card.php b/htdocs/user/group/card.php index a1930f7c027..56cfc5d9ee8 100644 --- a/htdocs/user/group/card.php +++ b/htdocs/user/group/card.php @@ -101,6 +101,7 @@ if ($action == 'add') // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if ($ret < 0) $error++; if (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode)) $object->entity = 0; else $object->entity = $_POST["entity"]; @@ -183,6 +184,7 @@ if ($action == 'update') // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if ($ret < 0) $error++; if (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode)) $object->entity = 0; else $object->entity = $_POST["entity"]; -- GitLab