From 2d3642331070d725adea140362399e664629f723 Mon Sep 17 00:00:00 2001 From: Alexis Algoud Date: Fri, 1 Mar 2013 10:42:05 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Ajout=20de=20la=20gestion=20des=20Hooks=20(?= =?UTF-8?q?doActions=20&=20=20sur=20la=20page=20d'ajout=20des=20commerciau?= =?UTF-8?q?x=20=C3=A0=20une=20soci=C3=A9t=C3=A9,=20/societe/commerciaux.ph?= =?UTF-8?q?p?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/societe/commerciaux.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/htdocs/societe/commerciaux.php b/htdocs/societe/commerciaux.php index 141e76a892b..43d01d4c662 100644 --- a/htdocs/societe/commerciaux.php +++ b/htdocs/societe/commerciaux.php @@ -37,6 +37,7 @@ $socid = isset($_GET["socid"])?$_GET["socid"]:''; if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'societe','',''); +$hookmanager->initHooks(array('salesrepresentativescard')); /* * Actions @@ -44,11 +45,21 @@ $result = restrictedArea($user, 'societe','',''); if($_GET["socid"] && $_GET["commid"]) { + $action = 'add'; + if ($user->rights->societe->creer) { + $soc = new Societe($db); $soc->id = $_GET["socid"]; $soc->fetch($_GET["socid"]); + + + $parameters=array('id'=>$_GET["commid"]); + $reshook=$hookmanager->executeHooks('doActions',$parameters,$soc,$action); // Note that $action and $object may have been modified by some hooks + $error=$hookmanager->error; $errors=array_merge($errors, (array) $hookmanager->errors); + + $soc->add_commercial($user, $_GET["commid"]); header("Location: commerciaux.php?socid=".$soc->id); @@ -63,11 +74,19 @@ if($_GET["socid"] && $_GET["commid"]) if($_GET["socid"] && $_GET["delcommid"]) { + $action = 'delete'; + if ($user->rights->societe->creer) { $soc = new Societe($db); $soc->id = $_GET["socid"]; $soc->fetch($_GET["socid"]); + + $parameters=array('id'=>$_GET["delcommid"]); + $reshook=$hookmanager->executeHooks('doActions',$parameters,$soc,$action); // Note that $action and $object may have been modified by some hooks + $error=$hookmanager->error; $errors=array_merge($errors, (array) $hookmanager->errors); + + $soc->del_commercial($user, $_GET["delcommid"]); header("Location: commerciaux.php?socid=".$soc->id); @@ -96,6 +115,8 @@ if ($_GET["socid"]) $soc->id = $_GET["socid"]; $result=$soc->fetch($_GET["socid"]); + $action='view'; + $head=societe_prepare_head2($soc); dol_fiche_head($head, 'salesrepresentative', $langs->trans("ThirdParty"),0,'company'); @@ -158,6 +179,10 @@ if ($_GET["socid"]) { $obj = $db->fetch_object($resql); + $parameters=array('socid'=>$soc->id); + $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$obj,$action); // Note that $action and $object may have been modified by hook + + print ''; print img_object($langs->trans("ShowUser"),"user").' '; print $obj->firstname." " .$obj->name."\n"; From 49f712546fdd73346002307372f7a86ad1d57541 Mon Sep 17 00:00:00 2001 From: Alexis Algoud Date: Fri, 1 Mar 2013 11:38:24 +0100 Subject: [PATCH 2/2] Add condition for normal traitment on empty hook result. Note : The normal case on 'formObjectOptions' is currently nothing more (no extrafields,...). --- htdocs/societe/commerciaux.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/htdocs/societe/commerciaux.php b/htdocs/societe/commerciaux.php index 43d01d4c662..5f0f7af2410 100644 --- a/htdocs/societe/commerciaux.php +++ b/htdocs/societe/commerciaux.php @@ -60,7 +60,7 @@ if($_GET["socid"] && $_GET["commid"]) $error=$hookmanager->error; $errors=array_merge($errors, (array) $hookmanager->errors); - $soc->add_commercial($user, $_GET["commid"]); + if (empty($reshook)) $soc->add_commercial($user, $_GET["commid"]); header("Location: commerciaux.php?socid=".$soc->id); exit; @@ -87,7 +87,7 @@ if($_GET["socid"] && $_GET["delcommid"]) $error=$hookmanager->error; $errors=array_merge($errors, (array) $hookmanager->errors); - $soc->del_commercial($user, $_GET["delcommid"]); + if (empty($reshook)) $soc->del_commercial($user, $_GET["delcommid"]); header("Location: commerciaux.php?socid=".$soc->id); exit; @@ -181,7 +181,10 @@ if ($_GET["socid"]) $parameters=array('socid'=>$soc->id); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$obj,$action); // Note that $action and $object may have been modified by hook - + if (empty($reshook)) { + + null; // actions in normal case + } print ''; print img_object($langs->trans("ShowUser"),"user").' ';