diff --git a/htdocs/comm/propal/contact.php b/htdocs/comm/propal/contact.php index 26bb7c5818e..e56d383550c 100644 --- a/htdocs/comm/propal/contact.php +++ b/htdocs/comm/propal/contact.php @@ -3,6 +3,7 @@ * Copyright (C) 2005-2016 Destailleur Laurent * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2011-2022 Philippe Grand + * Copyright (C) 2023 Christian Foellmann * * 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 @@ -67,50 +68,58 @@ $socid = ''; if (!empty($user->socid)) { $socid = $user->socid; } -restrictedArea($user, 'propal', $object->id); +$result = restrictedArea($user, 'propal', $object->id); +$hookmanager->initHooks(array('proposalcontactcard', 'globalcard')); $usercancreate = $user->hasRight("propal", "creer"); - /* - * Add a new contact + * Actions */ -if ($action == 'addcontact' && $user->hasRight('propal', 'creer')) { - if ($object->id > 0) { - $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int')); - $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"); - setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors'); - } else { - setEventMessages($object->error, $object->errors, 'errors'); - } - } -} elseif ($action == 'swapstatut' && $user->hasRight('propal', 'creer')) { - // Toggle the status of a contact - if ($object->id > 0) { - $result = $object->swapContactStatus(GETPOST('ligne', 'int')); - } -} elseif ($action == 'deletecontact' && $user->hasRight('propal', 'creer')) { - // Deletes a contact - $result = $object->delete_contact($lineid); - - if ($result >= 0) { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); - exit; - } else { - dol_print_error($db); - } +$parameters = array('id'=>$id); +$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } +if (empty($reshook)) { + // Add new contact + if ($action == 'addcontact' && $user->hasRight('propal', 'creer')) { + if ($object->id > 0) { + $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int')); + $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"); + setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors'); + } else { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + } elseif ($action == 'swapstatut' && $user->hasRight('propal', 'creer')) { + // Toggle the status of a contact + if ($object->id > 0) { + $result = $object->swapContactStatus(GETPOST('ligne', 'int')); + } + } elseif ($action == 'deletecontact' && $user->hasRight('propal', 'creer')) { + // Delete contact + $result = $object->delete_contact($lineid); + + if ($result >= 0) { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } else { + dol_print_error($db); + } + } +} /* * View diff --git a/htdocs/commande/contact.php b/htdocs/commande/contact.php index a5fc715eb38..1d800e1eaca 100644 --- a/htdocs/commande/contact.php +++ b/htdocs/commande/contact.php @@ -46,57 +46,65 @@ if ($user->socid) { $socid = $user->socid; } $result = restrictedArea($user, 'commande', $id, ''); +$hookmanager->initHooks(array('ordercontactcard', 'globalcard')); $usercancreate = $user->hasRight("commande", "creer"); $object = new Commande($db); - /* - * Ajout d'un nouveau contact + * Actions */ -if ($action == 'addcontact' && $user->hasRight('commande', 'creer')) { - $result = $object->fetch($id); +$parameters = array('id'=>$id); +$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} - if ($result > 0 && $id > 0) { - $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int')); - $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); - $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09')); - } +if (empty($reshook)) { + // Add new contact + if ($action == 'addcontact' && $user->hasRight('commande', 'creer')) { + $result = $object->fetch($id); - if ($result >= 0) { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); - exit; - } else { - if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { - $langs->load("errors"); - setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors'); + if ($result > 0 && $id > 0) { + $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int')); + $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"); + setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors'); + } else { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + } elseif ($action == 'swapstatut' && $user->hasRight('commande', 'creer')) { + // Toggle the status of a contact + if ($object->fetch($id)) { + $result = $object->swapContactStatus(GETPOST('ligne', 'int')); + } else { + dol_print_error($db); + } + } elseif ($action == 'deletecontact' && $user->hasRight('commande', 'creer')) { + // Delete contact + $object->fetch($id); + $result = $object->delete_contact(GETPOST("lineid", 'int')); + + if ($result >= 0) { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; } else { setEventMessages($object->error, $object->errors, 'errors'); } } -} elseif ($action == 'swapstatut' && $user->hasRight('commande', 'creer')) { - // bascule du statut d'un contact - if ($object->fetch($id)) { - $result = $object->swapContactStatus(GETPOST('ligne', 'int')); - } else { - dol_print_error($db); - } -} elseif ($action == 'deletecontact' && $user->hasRight('commande', 'creer')) { - // Efface un contact - $object->fetch($id); - $result = $object->delete_contact(GETPOST("lineid", 'int')); - - if ($result >= 0) { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); - exit; - } else { - setEventMessages($object->error, $object->errors, 'errors'); - } } - /* * View */ diff --git a/htdocs/compta/facture/contact.php b/htdocs/compta/facture/contact.php index 7076303057c..6f0ffe3463e 100644 --- a/htdocs/compta/facture/contact.php +++ b/htdocs/compta/facture/contact.php @@ -4,6 +4,7 @@ * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2011-2015 Philippe Grand * Copyright (C) 2017 Ferran Marcet + * Copyright (C) 2023 Christian Foellmann * * 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 @@ -57,47 +58,56 @@ if ($id > 0 || !empty($ref)) { } $result = restrictedArea($user, 'facture', $object->id); +$hookmanager->initHooks(array('invoicecontactcard', 'globalcard')); $usercancreate = $user->hasRight("facture", "creer"); /* - * Add a new contact + * Actions */ -if ($action == 'addcontact' && $user->hasRight('facture', 'creer')) { - if ($result > 0 && $id > 0) { - $contactid = (GETPOST('userid') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int')); - $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"); - setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors'); - } else { - setEventMessages($object->error, $object->errors, 'errors'); - } - } -} elseif ($action == 'swapstatut' && $user->hasRight('facture', 'creer')) { - // Toggle the status of a contact - $result = $object->swapContactStatus(GETPOST('ligne', 'int')); -} elseif ($action == 'deletecontact' && $user->hasRight('facture', 'creer')) { - // Deletes a contact - $result = $object->delete_contact($lineid); - - if ($result >= 0) { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); - exit; - } else { - dol_print_error($db); - } +$parameters = array('id'=>$id); +$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } +if (empty($reshook)) { + // Add new contact + if ($action == 'addcontact' && $user->hasRight('facture', 'creer')) { + if ($result > 0 && $id > 0) { + $contactid = (GETPOST('userid') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int')); + $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"); + setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors'); + } else { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + } elseif ($action == 'swapstatut' && $user->hasRight('facture', 'creer')) { + // Toggle the status of a contact + $result = $object->swapContactStatus(GETPOST('ligne', 'int')); + } elseif ($action == 'deletecontact' && $user->hasRight('facture', 'creer')) { + // Delete contact + $result = $object->delete_contact($lineid); + + if ($result >= 0) { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } else { + dol_print_error($db); + } + } +} /* * View diff --git a/htdocs/contrat/contact.php b/htdocs/contrat/contact.php index 661b316df59..980fa5f29fb 100644 --- a/htdocs/contrat/contact.php +++ b/htdocs/contrat/contact.php @@ -3,6 +3,7 @@ * Copyright (C) 2005-2009 Destailleur Laurent * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2017 Ferran Marcet + * Copyright (C) 2023 Christian Foellmann * * 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 @@ -51,7 +52,7 @@ if ($user->socid) { $object = new Contrat($db); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context -$hookmanager->initHooks(array('contractcard', 'globalcard')); +$hookmanager->initHooks(array('contractcontactcard', 'globalcard')); $permissiontoadd = $user->hasRight('contrat', 'creer'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php @@ -62,51 +63,59 @@ $result = restrictedArea($user, 'contrat', $object->id); * Actions */ -if ($action == 'addcontact' && $user->hasRight('contrat', 'creer')) { - $result = $object->fetch($id); +$parameters = array('id'=>$id); +$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} - if ($result > 0 && $id > 0) { - $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid')); - $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); - $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09')); - } +if (empty($reshook)) { + // Add new contact + if ($action == 'addcontact' && $user->hasRight('contrat', 'creer')) { + $result = $object->fetch($id); - if ($result >= 0) { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); - exit; - } else { - if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { - $langs->load("errors"); - $msg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"); - } else { - $mesg = $object->error; + if ($result > 0 && $id > 0) { + $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid')); + $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); + $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09')); } - setEventMessages($mesg, null, 'errors'); + if ($result >= 0) { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } else { + if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { + $langs->load("errors"); + $msg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"); + } else { + $mesg = $object->error; + } + + setEventMessages($mesg, null, 'errors'); + } + } + + // Toggle the status of a contact + if ($action == 'swapstatut' && $user->hasRight('contrat', 'creer')) { + if ($object->fetch($id)) { + $result = $object->swapContactStatus(GETPOST('ligne', 'int')); + } else { + dol_print_error($db, $object->error); + } + } + + // Delete contact + if ($action == 'deletecontact' && $user->hasRight('contrat', 'creer')) { + $object->fetch($id); + $result = $object->delete_contact(GETPOST("lineid", 'int')); + + if ($result >= 0) { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } } } -// bascule du statut d'un contact -if ($action == 'swapstatut' && $user->hasRight('contrat', 'creer')) { - if ($object->fetch($id)) { - $result = $object->swapContactStatus(GETPOST('ligne', 'int')); - } else { - dol_print_error($db, $object->error); - } -} - -// Delete contact -if ($action == 'deletecontact' && $user->hasRight('contrat', 'creer')) { - $object->fetch($id); - $result = $object->delete_contact(GETPOST("lineid", 'int')); - - if ($result >= 0) { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); - exit; - } -} - - /* * View */ diff --git a/htdocs/expedition/contact.php b/htdocs/expedition/contact.php index 9bd9bba7440..4396bbaebc1 100644 --- a/htdocs/expedition/contact.php +++ b/htdocs/expedition/contact.php @@ -2,6 +2,7 @@ /* Copyright (C) 2005 Patrick Rouillon * Copyright (C) 2005-2011 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2023 Christian Foellmann * * 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 @@ -69,47 +70,54 @@ if ($user->socid) { $socid = $user->socid; } $result = restrictedArea($user, 'expedition', $object->id, ''); - +$hookmanager->initHooks(array('shipmentcontactcard', 'globalcard')); /* * Actions */ -if ($action == 'addcontact' && $user->hasRight('expedition', 'creer')) { - if ($result > 0 && $id > 0) { - $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int')); - $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); - $result = $objectsrc->add_contact($contactid, $typeid, GETPOST("source", 'aZ09')); - } - - if ($result >= 0) { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); - exit; - } else { - if ($objectsrc->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { - $langs->load("errors"); - $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"); - } else { - $mesg = $objectsrc->error; - $mesgs = $objectsrc->errors; - } - setEventMessages($mesg, $mesgs, 'errors'); - } -} elseif ($action == 'swapstatut' && $user->hasRight('expedition', 'creer')) { - // bascule du statut d'un contact - $result = $objectsrc->swapContactStatus(GETPOST('ligne', 'int')); -} elseif ($action == 'deletecontact' && $user->hasRight('expedition', 'creer')) { - // Efface un contact - $result = $objectsrc->delete_contact(GETPOST("lineid", 'int')); - - if ($result >= 0) { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); - exit; - } else { - dol_print_error($db); - } +$parameters = array('id'=>$id); +$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } +if (empty($reshook)) { + if ($action == 'addcontact' && $user->hasRight('expedition', 'creer')) { + if ($result > 0 && $id > 0) { + $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int')); + $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); + $result = $objectsrc->add_contact($contactid, $typeid, GETPOST("source", 'aZ09')); + } + + if ($result >= 0) { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } else { + if ($objectsrc->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { + $langs->load("errors"); + $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"); + } else { + $mesg = $objectsrc->error; + $mesgs = $objectsrc->errors; + } + setEventMessages($mesg, $mesgs, 'errors'); + } + } elseif ($action == 'swapstatut' && $user->hasRight('expedition', 'creer')) { + // bascule du statut d'un contact + $result = $objectsrc->swapContactStatus(GETPOST('ligne', 'int')); + } elseif ($action == 'deletecontact' && $user->hasRight('expedition', 'creer')) { + // Efface un contact + $result = $objectsrc->delete_contact(GETPOST("lineid", 'int')); + + if ($result >= 0) { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } else { + dol_print_error($db); + } + } +} /* * View diff --git a/htdocs/fourn/commande/contact.php b/htdocs/fourn/commande/contact.php index 0315ffc4c5b..e825c0d8dc4 100644 --- a/htdocs/fourn/commande/contact.php +++ b/htdocs/fourn/commande/contact.php @@ -3,6 +3,7 @@ * Copyright (C) 2005-2009 Destailleur Laurent * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2017 Ferran Marcet + * Copyright (C) 2023 Christian Foellmann * * 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 @@ -46,60 +47,70 @@ if ($user->socid) { $socid = $user->socid; } $result = restrictedArea($user, 'fournisseur', $id, 'commande_fournisseur', 'commande'); -$hookmanager->initHooks(array('ordersuppliercardcontact')); +$hookmanager->initHooks(array('ordersuppliercardcontact', 'ordersuppliercontactcard', 'globalcard')); $object = new CommandeFournisseur($db); $usercancreate = ($user->hasRight("fournisseur", "commande", "creer") || $user->hasRight("supplier_order", "creer")); $permissiontoadd = $usercancreate; // Used by the include of actions_addupdatedelete.inc.php - /* * Actions */ -if ($action == 'addcontact' && ($user->hasRight("fournisseur", "commande", "creer") || $user->hasRight("supplier_order", "creer"))) { - $result = $object->fetch($id); +$parameters = array('id'=>$id); +$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} - if ($result > 0 && $id > 0) { - $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid')); - $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); - $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09')); - } +/* + * Add a new contact + */ - if ($result >= 0) { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); - exit; - } else { - if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { - $langs->load("errors"); - setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors'); +if (empty($reshook)) { + if ($action == 'addcontact' && ($user->hasRight("fournisseur", "commande", "creer") || $user->hasRight("supplier_order", "creer"))) { + $result = $object->fetch($id); + + if ($result > 0 && $id > 0) { + $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('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"); + setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors'); + } else { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + } elseif ($action == 'swapstatut' && ($user->hasRight("fournisseur", "commande", "creer") || $user->hasRight("supplier_order", "creer"))) { + // Toggle the status of a contact + if ($object->fetch($id)) { + $result = $object->swapContactStatus(GETPOST('ligne', 'int')); + } else { + setEventMessages($object->error, $object->errors, 'errors'); + } + } elseif ($action == 'deletecontact' && ($user->hasRight("fournisseur", "commande", "creer") || $user->hasRight("supplier_order", "creer"))) { + // Deleting a contact + $object->fetch($id); + $result = $object->delete_contact(GETPOST("lineid", 'int')); + + if ($result >= 0) { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; } else { setEventMessages($object->error, $object->errors, 'errors'); } } -} elseif ($action == 'swapstatut' && ($user->hasRight("fournisseur", "commande", "creer") || $user->hasRight("supplier_order", "creer"))) { - // Toggle the status of a contact - if ($object->fetch($id)) { - $result = $object->swapContactStatus(GETPOST('ligne', 'int')); - } else { - setEventMessages($object->error, $object->errors, 'errors'); - } -} elseif ($action == 'deletecontact' && ($user->hasRight("fournisseur", "commande", "creer") || $user->hasRight("supplier_order", "creer"))) { - // Deleting a contact - $object->fetch($id); - $result = $object->delete_contact(GETPOST("lineid", 'int')); - - if ($result >= 0) { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); - exit; - } else { - setEventMessages($object->error, $object->errors, 'errors'); - } } - /* * View */ diff --git a/htdocs/fourn/facture/contact.php b/htdocs/fourn/facture/contact.php index c5585bdc134..84081c0cb8f 100644 --- a/htdocs/fourn/facture/contact.php +++ b/htdocs/fourn/facture/contact.php @@ -4,6 +4,7 @@ * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2017 Ferran Marcet * Copyright (C) 2021 Frédéric France + * Copyright (C) 2023 Christian Foellmann * * 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 @@ -47,55 +48,66 @@ if ($user->socid) { $socid = $user->socid; } $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture'); -$hookmanager->initHooks(array('invoicesuppliercardcontact')); +$hookmanager->initHooks(array('invoicesuppliercardcontact','invoicesuppliercontactcard', 'globalcard')); $object = new FactureFournisseur($db); $usercancreate = ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer")); $permissiontoadd = $usercancreate; - /* - * Ajout d'un nouveau contact + * Actions */ -if ($action == 'addcontact' && ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"))) { - $result = $object->fetch($id, $ref); +$parameters = array('id'=>$id); +$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} - if ($result > 0 && $id > 0) { - $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid')); - $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); - $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09')); - } +/* + * Add a new contact + */ - if ($result >= 0) { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); - exit; - } else { - if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { - $langs->load("errors"); - setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors'); - } else { - setEventMessages($object->error, $object->errors, 'errors'); +if (empty($reshook)) { + if ($action == 'addcontact' && ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"))) { + $result = $object->fetch($id, $ref); + + if ($result > 0 && $id > 0) { + $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid')); + $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); + $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09')); } - } -} elseif ($action == 'swapstatut' && ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"))) { - // bascule du statut d'un contact - if ($object->fetch($id)) { - $result = $object->swapContactStatus(GETPOST('ligne', 'int')); - } else { - dol_print_error($db); - } -} elseif ($action == 'deletecontact' && ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"))) { - // Efface un contact - $object->fetch($id); - $result = $object->delete_contact(GETPOST("lineid", 'int')); - 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"); + setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors'); + } else { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + } elseif ($action == 'swapstatut' && ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"))) { + // bascule du statut d'un contact + if ($object->fetch($id)) { + $result = $object->swapContactStatus(GETPOST('ligne', 'int')); + } else { + dol_print_error($db); + } + } elseif ($action == 'deletecontact' && ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"))) { + // Efface un contact + $object->fetch($id); + $result = $object->delete_contact(GETPOST("lineid", 'int')); + + if ($result >= 0) { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } else { + dol_print_error($db); + } } } diff --git a/htdocs/supplier_proposal/contact.php b/htdocs/supplier_proposal/contact.php index 9a9fd5686b1..4ff2e5ac4f9 100644 --- a/htdocs/supplier_proposal/contact.php +++ b/htdocs/supplier_proposal/contact.php @@ -3,6 +3,7 @@ * Copyright (C) 2005-2018 Destailleur Laurent * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2017 Ferran Marcet + * Copyright (C) 2023 Christian Foellmann * * 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 @@ -49,55 +50,67 @@ $result = restrictedArea($user, 'supplier_proposal', $id, 'supplier_proposal', ' $object = new SupplierProposal($db); -$permissiontoedit = $user->rights->supplier_proposal->creer; +$permissiontoedit = $user->hasRight('supplier_proposal', 'creer'); + +$hookmanager->initHooks(array('supplier_proposalcontactcard', 'globalcard')); /* - * Add a new contact + * Actions */ -if ($action == 'addcontact' && $permissiontoedit) { - $result = $object->fetch($id); +$parameters = array('id'=>$id); +$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} - if ($result > 0 && $id > 0) { - $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid')); - $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); - $result = $object->add_contact($contactid, $typeid, GETPOST("source")); - } +if (empty($reshook)) { + /* + * Add a new contact + */ + if ($action == 'addcontact' && $permissiontoedit) { + $result = $object->fetch($id); - if ($result >= 0) { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); - exit; - } else { - if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { - $langs->load("errors"); - setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors'); + if ($result > 0 && $id > 0) { + $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid')); + $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); + $result = $object->add_contact($contactid, $typeid, GETPOST("source")); + } + + if ($result >= 0) { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } else { + if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { + $langs->load("errors"); + setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors'); + } else { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + } elseif ($action == 'swapstatut' && $permissiontoedit) { + // Toggle the status of a contact + if ($object->fetch($id)) { + $result = $object->swapContactStatus(GETPOST('ligne', 'int')); + } else { + setEventMessages($object->error, $object->errors, 'errors'); + } + } elseif ($action == 'deletecontact' && $permissiontoedit) { + // Deleting a contact + $object->fetch($id); + $result = $object->delete_contact(GETPOST("lineid", 'int')); + + if ($result >= 0) { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; } else { setEventMessages($object->error, $object->errors, 'errors'); } } -} elseif ($action == 'swapstatut' && $permissiontoedit) { - // Toggle the status of a contact - if ($object->fetch($id)) { - $result = $object->swapContactStatus(GETPOST('ligne', 'int')); - } else { - setEventMessages($object->error, $object->errors, 'errors'); - } -} elseif ($action == 'deletecontact' && $permissiontoedit) { - // Deleting a contact - $object->fetch($id); - $result = $object->delete_contact(GETPOST("lineid", 'int')); - - if ($result >= 0) { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); - exit; - } else { - setEventMessages($object->error, $object->errors, 'errors'); - } } - /* * View */