From 76bee575536bd3729b5f180408e809fa36560180 Mon Sep 17 00:00:00 2001 From: John <john.botella@atm-consulting.fr> Date: Mon, 7 Aug 2017 15:49:17 +0200 Subject: [PATCH] Fix Add doaction hook --- htdocs/resource/add.php | 118 +++++++++++++++++++++------------------- 1 file changed, 63 insertions(+), 55 deletions(-) diff --git a/htdocs/resource/add.php b/htdocs/resource/add.php index a294dfb94db..a6cd75cccf8 100644 --- a/htdocs/resource/add.php +++ b/htdocs/resource/add.php @@ -66,63 +66,71 @@ $extrafields = new ExtraFields($db); // fetch optionals attributes and labels $extralabels=$extrafields->fetch_name_optionals_label($object->table_element); -if ($action == 'confirm_add_resource') +$hookmanager->initHooks(array('resource_card_add','globalcard')); +$parameters=array(); +$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks +if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + +if (empty($reshook)) { - if (! $cancel) - { - $error=''; - - $ref=GETPOST('ref','alpha'); - $description=GETPOST('description','alpha'); - $fk_code_type_resource=GETPOST('fk_code_type_resource','alpha'); - - if (empty($ref)) - { - $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref")); - setEventMessages($mesg, null, 'errors'); - $error++; - } - - if (! $error) - { - $object=new Dolresource($db); - $object->ref=$ref; - $object->description=$description; - $object->fk_code_type_resource=$fk_code_type_resource; - - // 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) - { - // Creation OK - $db->commit(); - setEventMessages($langs->trans('ResourceCreatedWithSuccess'), null, 'mesgs'); - Header("Location: card.php?id=" . $object->id); - return; - } - else - { - // Creation KO - setEventMessages($object->error, $object->errors, 'errors'); - $action = ''; - } - } - else - { - $action = ''; - } - } - else - { - Header("Location: list.php"); - } -} + if ($action == 'confirm_add_resource') + { + if (! $cancel) + { + $error=''; + + $ref=GETPOST('ref','alpha'); + $description=GETPOST('description','alpha'); + $fk_code_type_resource=GETPOST('fk_code_type_resource','alpha'); + + if (empty($ref)) + { + $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref")); + setEventMessages($mesg, null, 'errors'); + $error++; + } + + if (! $error) + { + $object=new Dolresource($db); + $object->ref=$ref; + $object->description=$description; + $object->fk_code_type_resource=$fk_code_type_resource; + + // 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) + { + // Creation OK + $db->commit(); + setEventMessages($langs->trans('ResourceCreatedWithSuccess'), null, 'mesgs'); + Header("Location: card.php?id=" . $object->id); + return; + } + else + { + // Creation KO + setEventMessages($object->error, $object->errors, 'errors'); + $action = ''; + } + } + else + { + $action = ''; + } + } + else + { + Header("Location: list.php"); + } + } +} /* * View -- GitLab