From 910443eccba3dd85176059bcbc2484c9ddf6abe2 Mon Sep 17 00:00:00 2001 From: ldestailleur Date: Tue, 16 Sep 2025 12:37:39 +0200 Subject: [PATCH] Fix hook doAction in contact tab --- htdocs/societe/consumption.php | 4 +- htdocs/societe/societecontact.php | 77 +++++++++++++++++-------------- 2 files changed, 45 insertions(+), 36 deletions(-) diff --git a/htdocs/societe/consumption.php b/htdocs/societe/consumption.php index c7fe04d80a2..5b339b9a206 100644 --- a/htdocs/societe/consumption.php +++ b/htdocs/societe/consumption.php @@ -48,6 +48,7 @@ $langs->loadLangs(array("companies", "bills", "orders", "suppliers", "propal", " $action = GETPOST('action', 'aZ09'); $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'thirdpartylist'; +$optioncss = GETPOST('optioncss', 'alpha'); // Security check $socid = GETPOSTINT('socid'); @@ -69,11 +70,10 @@ $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit; $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page"); -$optioncss = GETPOST('optioncss', 'alpha'); if (empty($page) || $page == -1) { $page = 0; -} // If $page is not defined, or '' or -1 +} $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; diff --git a/htdocs/societe/societecontact.php b/htdocs/societe/societecontact.php index 84a0aebc13a..4e621976509 100644 --- a/htdocs/societe/societecontact.php +++ b/htdocs/societe/societecontact.php @@ -51,7 +51,9 @@ $langs->loadLangs(array('companies', 'orders')); $id = GETPOSTINT('id') ? GETPOSTINT('id') : GETPOSTINT('socid'); $ref = GETPOST('ref', 'alpha'); $action = GETPOST('action', 'aZ09'); +$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'thirdpartylist'; $massaction = GETPOST('massaction', 'alpha'); +$optioncss = GETPOST('optioncss', 'alpha'); $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit; $sortfield = GETPOST('sortfield', 'aZ09comma'); @@ -88,43 +90,50 @@ $object = new Societe($db); * Actions */ -if ($action == 'addcontact' && $user->hasRight('societe', 'creer')) { - $result = $object->fetch($id); +$parameters = array('id' => $socid); +$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 ($action == 'addcontact' && $user->hasRight('societe', 'creer')) { + $result = $object->fetch($id); - if ($result > 0 && $id > 0) { - $contactid = (GETPOSTINT('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid')); - $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); - $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09')); - } - - if ($result >= 0) { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); - exit; - } else { - if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { - $langs->load("errors"); - $mesg = '
'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'
'; - } else { - $mesg = '
'.$object->error.'
'; + if ($result > 0 && $id > 0) { + $contactid = (GETPOSTINT('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid')); + $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); + $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09')); } - } -} elseif ($action == 'swapstatut' && $user->hasRight('societe', 'creer')) { - // bascule du statut d'un contact - if ($object->fetch($id)) { - $result = $object->swapContactStatus(GETPOSTINT('ligne')); - } else { - dol_print_error($db); - } -} elseif ($action == 'deletecontact' && $user->hasRight('societe', 'creer')) { - // Efface un contact - $object->fetch($id); - $result = $object->delete_contact(GETPOSTINT("lineid")); - if ($result >= 0) { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); - exit; - } else { - dol_print_error($db); + if ($result >= 0) { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } else { + if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { + $langs->load("errors"); + $mesg = '
'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'
'; + } else { + $mesg = '
'.$object->error.'
'; + } + } + } elseif ($action == 'swapstatut' && $user->hasRight('societe', 'creer')) { + // bascule du statut d'un contact + if ($object->fetch($id)) { + $result = $object->swapContactStatus(GETPOSTINT('ligne')); + } else { + dol_print_error($db); + } + } elseif ($action == 'deletecontact' && $user->hasRight('societe', 'creer')) { + // Efface un contact + $object->fetch($id); + $result = $object->delete_contact(GETPOSTINT("lineid")); + + if ($result >= 0) { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } else { + dol_print_error($db); + } } }