diff --git a/htdocs/adherents/class/actions_adherent.class.php b/htdocs/adherents/class/actions_adherent.class.php
deleted file mode 100644
index 529e836b83e..00000000000
--- a/htdocs/adherents/class/actions_adherent.class.php
+++ /dev/null
@@ -1,37 +0,0 @@
-
- *
- * 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
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-/**
- * \file htdocs/adherents/class/actions_adherent.class.php
- * \ingroup member
- * \brief File for member class
- * \version $Id: actions_adherent.class.php,v 1.1 2011/08/09 17:59:48 hregis Exp $
- */
-require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php");
-
-
-/**
- * \class ActionsAdherent
- * \brief Class to manage members objects
- */
-class ActionsAdherent extends Adherent
-{
-
-}
-
-
-?>
\ No newline at end of file
diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php
index 1f1c0d295fd..5e5b83301cc 100644
--- a/htdocs/adherents/class/adherent.class.php
+++ b/htdocs/adherents/class/adherent.class.php
@@ -24,7 +24,7 @@
* \file htdocs/adherents/class/adherent.class.php
* \ingroup member
* \brief File of class to manage members of a foundation
- * \version $Id: adherent.class.php,v 1.46 2011/08/09 17:59:46 hregis Exp $
+ * \version $Id: adherent.class.php,v 1.47 2011/08/10 00:50:17 eldy Exp $
*/
require_once(DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php");
@@ -420,33 +420,21 @@ class Adherent extends CommonObject
if ($resql)
{
$nbrowsaffected+=$this->db->affected_rows($resql);
-
- /*
- $result=$this->insertExtraFields();
- if ($result < 0)
+
+ // Actions on extra fields (by external module or standard code)
+ include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
+ $hookmanager=new HookManager($db);
+ $hookmanager->callHooks(array('member_extrafields'));
+ $reshook=$hookmanager->executeHooks('insertExtraFields',$action,$this,$socid); // Note that $action and $object may have been modified by some hooks
+ if (empty($reshook))
{
- $error++;
+ $result=$this->insertExtraFields();
+ if ($result < 0)
+ {
+ $error++;
+ }
}
- */
-
- // Hook for external modules
- if (! empty($this->hooks))
- {
- foreach($this->hooks as $hook)
- {
- if ($hook['type'] == 'member_extrafields' && ! empty($hook['modules']))
- {
- foreach($hook['modules'] as $module)
- {
- if (method_exists($module,'insertExtraFields'))
- {
- $result=$module->insertExtraFields($this);
- if ($result < 0) $error++;
- }
- }
- }
- }
- }
+ else if ($reshook < 0) $error++;
// Update password
if (! $error && $this->pass)
diff --git a/htdocs/adherents/fiche.php b/htdocs/adherents/fiche.php
index 7804204f0fa..ecad7b97951 100644
--- a/htdocs/adherents/fiche.php
+++ b/htdocs/adherents/fiche.php
@@ -22,7 +22,7 @@
* \file htdocs/adherents/fiche.php
* \ingroup member
* \brief Page of member
- * \version $Id: fiche.php,v 1.239 2011/08/09 17:59:52 hregis Exp $
+ * \version $Id: fiche.php,v 1.240 2011/08/10 00:50:19 eldy Exp $
*/
require("../main.inc.php");
@@ -32,7 +32,7 @@ require_once(DOL_DOCUMENT_ROOT."/lib/images.lib.php");
require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php");
require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php");
require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent_type.class.php");
-//require_once(DOL_DOCUMENT_ROOT."/core/class/extrafields.class.php");
+require_once(DOL_DOCUMENT_ROOT."/core/class/extrafields.class.php");
require_once(DOL_DOCUMENT_ROOT."/adherents/class/cotisation.class.php");
require_once(DOL_DOCUMENT_ROOT."/compta/bank/class/account.class.php");
require_once(DOL_DOCUMENT_ROOT."/core/class/html.formcompany.class.php");
@@ -46,7 +46,7 @@ $langs->load("users");
if (! $user->rights->adherent->lire) accessforbidden();
$object = new Adherent($db);
-//$extrafields = new ExtraFields($db);
+$extrafields = new ExtraFields($db);
$errmsg=''; $errmsgs=array();
@@ -80,17 +80,19 @@ if ($rowid)
$caneditfieldmember=$user->rights->adherent->creer;
}
-// Instantiate hooks of thirdparty module. Note that conf->hooks_modules contains array array
-if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules))
-{
- $object->callHooks('member_extrafields');
-}
+// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
+include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
+$hookmanager=new HookManager($db);
+$hookmanager->callHooks(array('member_extrafields'));
/*
* Actions
*/
+$reshook=$hookmanager->executeHooks('doActions',$action,$object,$socid); // Note that $action and $object may have been modified by some hooks
+
+
if ($_POST['action'] == 'setuserid' && ($user->rights->user->self->creer || $user->rights->user->user->creer))
{
$error=0;
@@ -599,7 +601,7 @@ if ($user->rights->adherent->creer && $_POST["action"] == 'confirm_add_spip' &&
*/
// fetch optionals attributes and labels
-//$extralabels=$extrafields->fetch_name_optionals_label('member');
+$extralabels=$extrafields->fetch_name_optionals_label('member');
$help_url='EN:Module_Foundations|FR:Module_Adhérents|ES:Módulo_Miembros';
llxHeader('',$langs->trans("Member"),$help_url);
@@ -770,34 +772,18 @@ if ($action == 'create')
print $html->selectyesno("public",$object->public,1);
print "\n";
- // Attribut optionnels
- /*
- foreach($extrafields->attribute_label as $key=>$label)
+ // Other attributes
+ $reshook=$hookmanager->executeHooks('showInputFields',$action,$object); // Note that $action and $object may have been modified by hook
+ if (empty($reshook))
{
- $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:'');
- print "
| ".$label.' | ';
- print $extrafields->showInputField($key,$value);
- print ' |
'."\n";
+ foreach($extrafields->attribute_label as $key=>$label)
+ {
+ $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:'');
+ print "| ".$label.' | ';
+ print $extrafields->showInputField($key,$value);
+ print ' |
'."\n";
+ }
}
- */
-
- // Hook for external modules
- if (! empty($object->hooks))
- {
- foreach($object->hooks as $hook)
- {
- if ($hook['type'] == 'member_extrafields' && ! empty($hook['modules']))
- {
- foreach($hook['modules'] as $module)
- {
- if (method_exists($module,'showInputFields'))
- {
- $module->showInputFields($object,$_POST);
- }
- }
- }
- }
- }
/*
// Third party Dolibarr
@@ -1004,33 +990,17 @@ if ($action == 'edit')
print "\n";
// Other attributes
- /*
- foreach($extrafields->attribute_label as $key=>$label)
- {
- $value=(isset($_POST["options_$key"])?$_POST["options_$key"]:$object->array_options["options_$key"]);
- print "| ".$label." | ";
- print $extrafields->showInputField($key,$value);
- print " |
\n";
- }
- */
-
- // Hook for external modules
- if (! empty($object->hooks))
- {
- foreach($object->hooks as $hook)
- {
- if ($hook['type'] == 'member_extrafields' && ! empty($hook['modules']))
- {
- foreach($hook['modules'] as $module)
- {
- if (method_exists($module,'showInputFields'))
- {
- $module->showInputFields($object,$_POST,$rowid);
- }
- }
- }
- }
- }
+ $reshook=$hookmanager->executeHooks('showInputFields',$action,$object); // Note that $action and $object may have been modified by hook
+ if (empty($reshook))
+ {
+ foreach($extrafields->attribute_label as $key=>$label)
+ {
+ $value=(isset($_POST["options_$key"])?$_POST["options_$key"]:$object->array_options["options_$key"]);
+ print "| ".$label." | ";
+ print $extrafields->showInputField($key,$value);
+ print " |
\n";
+ }
+ }
// Third party Dolibarr
if ($conf->societe->enabled)
@@ -1332,33 +1302,17 @@ if ($rowid && $action != 'edit')
print '| '.$langs->trans("Status").' | '.$object->getLibStatut(4).' |
';
// Other attributes
- /*
- foreach($extrafields->attribute_label as $key=>$label)
+ $reshook=$hookmanager->executeHooks('showOutputField',$action,$object,$socid); // Note that $action and $object may have been modified by hook
+ if (empty($reshook))
{
- $value=$object->array_options["options_$key"];
- print "| ".$label." | ";
- print $extrafields->showOutputField($key,$value);
- print " |
\n";
- }
- */
-
- // Hook for external modules
- if (! empty($object->hooks))
- {
- foreach($object->hooks as $hook)
+ foreach($extrafields->attribute_label as $key=>$label)
{
- if ($hook['type'] == 'member_extrafields' && ! empty($hook['modules']))
- {
- foreach($hook['modules'] as $module)
- {
- if (method_exists($module,'showOutputFields'))
- {
- $module->showOutputFields($object,$rowid);
- }
- }
- }
- }
- }
+ $value=$object->array_options["options_$key"];
+ print "| ".$label." | ";
+ print $extrafields->showOutputField($key,$value);
+ print " |
\n";
+ }
+ }
// Third party Dolibarr
if ($conf->societe->enabled)
@@ -1568,5 +1522,5 @@ if ($rowid && $action != 'edit')
$db->close();
-llxFooter('$Date: 2011/08/09 17:59:52 $ - $Revision: 1.239 $');
+llxFooter('$Date: 2011/08/10 00:50:19 $ - $Revision: 1.240 $');
?>
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index 4eeb7d603b9..45820894f8b 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -21,7 +21,7 @@
* \file htdocs/core/class/commonobject.class.php
* \ingroup core
* \brief File of parent class of all other business classes (invoices, contracts, proposals, orders, ...)
- * \version $Id: commonobject.class.php,v 1.150 2011/08/09 17:59:45 hregis Exp $
+ * \version $Id: commonobject.class.php,v 1.151 2011/08/10 00:50:17 eldy Exp $
*/
@@ -1436,66 +1436,6 @@ class CommonObject
}
- /**
- * Init array this->hooks with instantiated controler and/or dao
- * @param arraytype Array list of hooked tab/features. For example: thirdpartytab, ...
- */
- function callHooks($arraytype)
- {
- global $conf;
-
- if (! is_array($arraytype)) $arraytype=array($arraytype);
-
- $i=0;
-
- foreach($conf->hooks_modules as $module => $hooks)
- {
- if ($conf->$module->enabled)
- {
- foreach($arraytype as $type)
- {
- if (in_array($type,$hooks))
- {
- $path = $module;
- if ($module == 'adherent') $path = 'adherents';
- $path = '/'.$path.'/class/';
- $actionfile = 'actions_'.$module.'.class.php';
- $daofile = 'dao_'.$module.'.class.php';
- $pathroot = '';
-
- $this->hooks[$i]['type']=$type;
-
- // Include actions class (controller)
- //print 'include '.$path.$actionfile."\n";
- $resaction=dol_include_once($path.$actionfile);
-
- // Include dataservice class (model)
- //print 'include '.$path.$daofile."\n";
- $resdao=dol_include_once($path.$daofile);
-
- // Instantiate actions class (controller)
- if ($resaction)
- {
- $controlclassname = 'Actions'.ucfirst($module);
- $objModule = new $controlclassname($this->db);
- $this->hooks[$i]['modules'][$objModule->module_number] = $objModule;
- }
-
- // TODO storing dao is useless here. It's goal of controller to known which dao to manage
- if ($resdao)
- {
- // Instantiate dataservice class (model)
- $modelclassname = 'Dao'.ucfirst($module);
- $this->hooks[$i]['modules'][$objModule->module_number]->object = new $modelclassname($this->db);
- }
-
- $i++;
- }
- }
- }
- }
- }
-
/**
* Get special code of line
* @param lineid Id of line
@@ -1989,72 +1929,14 @@ class CommonObject
include(DOL_DOCUMENT_ROOT.'/core/tpl/originproductline.tpl.php');
}
- /**
- *
- */
- function showInputFields($object,$post='',$id=0)
- {
- global $conf;
-
- require_once(DOL_DOCUMENT_ROOT."/core/class/extrafields.class.php");
-
- $extrafields = new ExtraFields($this->db);
-
- $elementtype = $object->element;
- if ($object->element == 'societe') $elementtype = 'company';
-
- $extralabels=$extrafields->fetch_name_optionals_label($elementtype);
-
- if ($id)
- {
- $res=$object->fetch_optionals($id,$extralabels);
- if ($res < 0) { dol_print_error($db); exit; }
- }
- foreach($extrafields->attribute_label as $key=>$label)
- {
- $value=(isset($post["options_$key"])?$post["options_$key"]:($id?$object->array_options["options_$key"]:''));
- print "| ".$label.' | ';
- print $extrafields->showInputField($key,$value);
- print ' |
'."\n";
- }
- }
-
- /**
- *
- */
- function showOutputFields($object,$id)
- {
- global $conf;
-
- require_once(DOL_DOCUMENT_ROOT."/core/class/extrafields.class.php");
-
- $extrafields = new ExtraFields($this->db);
-
- $elementtype = $object->element;
- if ($object->element == 'societe') $elementtype = 'company';
-
- $extralabels=$extrafields->fetch_name_optionals_label($elementtype);
-
- $res=$object->fetch_optionals($id,$extralabels);
- if ($res < 0) { dol_print_error($db); exit; }
-
- foreach($extrafields->attribute_label as $key=>$label)
- {
- $value=$object->array_options["options_$key"];
- print "| ".$label.' | ';
- print $extrafields->showOutputField($key,$value);
- print " |
\n";
- }
- }
-
/**
* Add/Update extra fields
* TODO Use also type of field to do manage date fields
*/
function insertExtraFields($object)
{
- if (sizeof($object->array_options) > 0)
+ if (sizeof($object->array_options) > 0)
{
$this->db->begin();
diff --git a/htdocs/core/class/hookmanager.class.php b/htdocs/core/class/hookmanager.class.php
new file mode 100755
index 00000000000..028bfea891f
--- /dev/null
+++ b/htdocs/core/class/hookmanager.class.php
@@ -0,0 +1,187 @@
+
+ * Copyright (C) 2005-2011 Regis Houssin
+ * Copyright (C) 2010-2011 Juanjo Menent
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+/**
+ * \file htdocs/core/class/hookmanager.class.php
+ * \ingroup core
+ * \brief File of class to manage hooks
+ * \version $Id: hookmanager.class.php,v 1.1 2011/08/10 00:50:16 eldy Exp $
+ */
+
+
+/**
+ * \class HookManager
+ * \brief Class to manage hooks
+ */
+
+class HookManager
+{
+ var $db;
+
+ var $linkedObjectBlock;
+ var $objectid;
+
+ // Array with instantiated classes
+ var $hooks=array();
+
+ /**
+ * Constructeur de la classe
+ * @param DB Handler acces base de donnees
+ */
+ function HookManager($DB)
+ {
+ $this->db = $DB;
+ }
+
+
+ /**
+ * Init array this->hooks with instantiated controler and/or dao
+ * @param arraytype Array list of hooked tab/features. For example: thirdpartytab, ...
+ * @return int Always 1
+ */
+ function callHooks($arraytype)
+ {
+ global $conf;
+
+ // Test if ther is hooks to manage
+ if (! is_array($conf->hooks_modules) || empty($conf->hooks_modules)) return;
+
+ // For backward compatibility
+ if (! is_array($arraytype)) $arraytype=array($arraytype);
+
+ $i=0;
+ foreach($conf->hooks_modules as $module => $hooks)
+ {
+ if ($conf->$module->enabled)
+ {
+ foreach($arraytype as $type)
+ {
+ if (in_array($type,$hooks))
+ {
+ $path = $module;
+ if ($module == 'adherent') $path = 'adherents';
+ $path = '/'.$path.'/class/';
+ $actionfile = 'actions_'.$module.'.class.php';
+ //$daofile = 'dao_'.$module.'.class.php';
+ $pathroot = '';
+
+ $this->hooks[$i]['type']=$type;
+
+ // Include actions class overwriting hooks
+ $resaction=dol_include_once($path.$actionfile);
+ if ($resaction)
+ {
+ $controlclassname = 'Actions'.ucfirst($module);
+ $objModule = new $controlclassname($this->db);
+ $this->hooks[$i]['modules'][$objModule->module_number] = $objModule;
+ }
+
+ $i++;
+ }
+ }
+ }
+ }
+ return 1;
+ }
+
+ /**
+ * Execute hooks (if the were initialized) for the given method
+ * @param method Method name to hook ('doActions', 'printSearchForm', ...)
+ * @param action Action code ('create', 'edit', 'view', 'add', 'update', 'delete'...)
+ * @param object Object to use hooks on
+ * @param socid Soc Id.
+ * @param string For doActions,showInputField,showOutputField: Return 0 if we want to keep doing standard actions, >0 if if want to stop standard actions, >0 means KO.
+ * For printSearchForm,printLeftBlock: Return HTML string.
+ * $this->error or this->errors are also defined with hooks errors.
+ */
+ function executeHooks($method, &$action='', &$object='', $id='')
+ {
+ if (! is_array($this->hooks) || empty($this->hooks)) return '';
+
+ // Loop on each hook
+ $resaction=0; $resprint='';
+ foreach($this->hooks as $hook)
+ {
+ if (! empty($this->hook['modules']))
+ {
+ foreach($this->hook['modules'] as $module)
+ {
+ // Hooks that return int
+ if ($method == 'doActions' && method_exists($module,$method))
+ {
+ $restmp+=$module->doActions($object, $action, $id); // action can be changed by method (to go back to other action for example), socid can be changed/set by method (during creation for example)
+ if ($restmp < 0 || ! empty($module->error) || (! empty($module->errors) && sizeof($module->errors) > 0))
+ {
+ $this->error=$module->error; $this->errors=$module->errors;
+ if ($action=='add') $action='create'; // TODO this change must be inside the doActions
+ if ($action=='update') $action='edit'; // TODO this change must be inside the doActions
+ }
+ else
+ {
+ $resaction+=$restmp;
+ }
+ }
+ if ($method == 'showInputFields' && method_exists($module,$method))
+ {
+ $restmp+=$module->showInputFields($object, $action, $id); // action can be changed by method (to go back to other action for example), socid can be changed/set by method (during creation for example)
+ if ($restmp < 0 || ! empty($module->error) || (! empty($module->errors) && sizeof($module->errors) > 0))
+ {
+ $this->error=$module->error; $this->errors=$module->errors;
+ }
+ else
+ {
+ $resaction+=$restmp;
+ }
+ }
+ if ($method == 'showOutputFields' && method_exists($module,$method))
+ {
+ $restmp+=$module->showOutputFields($object, $id); // action can be changed by method (to go back to other action for example), socid can be changed/set by method (during creation for example)
+ if ($restmp < 0 || ! empty($module->error) || (! empty($module->errors) && sizeof($module->errors) > 0))
+ {
+ $this->error=$module->error; $this->errors=$module->errors;
+ }
+ else
+ {
+ $resaction+=$restmp;
+ }
+ }
+ // Hooks that return a string
+ if ($method == 'printSearchForm' && method_exists($module,$method))
+ {
+ $resprint.=''."\n";
+ $resprint.=$module->printSearchForm($object, $action, $id); // action can be changed by method (to go back to other action for example), socid can be changed/set by method (during creation for example)
+ $resprint.="\n".''."\n";
+ }
+ if ($method == 'printLeftBlock' && method_exists($module,$method))
+ {
+ $resprint.=''."\n";
+ $resprint.=$module->printLeftBlock($object, $action, $id); // action can be changed by method (to go back to other action for example), socid can be changed/set by method (during creation for example)
+ $resprint.="\n".''."\n";
+ }
+ }
+ }
+ }
+
+ if ($method == 'doActions' || $method == 'showInputField' || $method == 'showOutputFields') return $resaction;
+ return $resprint;
+ }
+
+}
+
+?>
diff --git a/htdocs/includes/modules/modAdherent.class.php b/htdocs/includes/modules/modAdherent.class.php
index df3e5508da3..c24e3a42fb2 100644
--- a/htdocs/includes/modules/modAdherent.class.php
+++ b/htdocs/includes/modules/modAdherent.class.php
@@ -28,7 +28,7 @@
* \file htdocs/includes/modules/modAdherent.class.php
* \ingroup member
* \brief File descriptor or module Member
- * \version $Id: modAdherent.class.php,v 1.88 2011/08/09 17:59:51 hregis Exp $
+ * \version $Id: modAdherent.class.php,v 1.89 2011/08/10 00:50:18 eldy Exp $
*/
include_once(DOL_DOCUMENT_ROOT ."/includes/modules/DolibarrModules.class.php");
@@ -74,7 +74,6 @@ class modAdherent extends DolibarrModules
// Constantes
//-----------
$this->const = array();
- $this->const[0] = array("MAIN_MODULE_ADHERENT_HOOKS","chaine",'member_extrafields','',0);
$this->const[2] = array("MAIN_SEARCHFORM_ADHERENT","yesno","1","Show form for quick member search");
$this->const[3] = array("ADHERENT_MAIL_RESIL","texte","Votre adhésion vient d'être résiliée.\r\nNous espérons vous revoir très bientôt","Mail de résiliation");
$this->const[4] = array("ADHERENT_MAIL_VALID","texte","Votre adhésion vient d'être validée. \r\nVoici le rappel de vos coordonnées (toute information erronée entrainera la non validation de votre inscription) :\r\n\r\n%INFOS%\r\n\r\n","Mail de validation");
diff --git a/htdocs/includes/modules/modSociete.class.php b/htdocs/includes/modules/modSociete.class.php
index beed750649a..97f7a504f08 100644
--- a/htdocs/includes/modules/modSociete.class.php
+++ b/htdocs/includes/modules/modSociete.class.php
@@ -22,7 +22,7 @@
/**
* \defgroup societe Module societe
* \brief Module to manage third parties (customers, prospects)
- * \version $Id: modSociete.class.php,v 1.121 2011/08/09 17:59:50 hregis Exp $
+ * \version $Id: modSociete.class.php,v 1.122 2011/08/10 00:50:18 eldy Exp $
*/
/**
@@ -106,15 +106,6 @@ class modSociete extends DolibarrModules
$this->const[$r][4] = 0;
$r++;
- $this->const[$r][0] = "MAIN_MODULE_SOCIETE_HOOKS";
- $this->const[$r][1] = "chaine";
- $this->const[$r][2] = "thirdparty_extrafields";
- $this->const[$r][3] = "";
- $this->const[$r][4] = 0;
- $this->const[$r][4] = 'current';
- $this->const[$r][4] = 1;
- $r++;
-
// Boxes
$this->boxes = array();
$r=0;
diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php
index 1bdeb9562e6..1f2d1f4bf44 100644
--- a/htdocs/main.inc.php
+++ b/htdocs/main.inc.php
@@ -25,7 +25,7 @@
* \file htdocs/main.inc.php
* \ingroup core
* \brief File that defines environment for Dolibarr pages only (variables not required by scripts)
- * \version $Id: main.inc.php,v 1.756 2011/07/31 23:19:05 eldy Exp $
+ * \version $Id: main.inc.php,v 1.757 2011/08/10 00:50:19 eldy Exp $
*/
@ini_set('memory_limit', '64M'); // This may be useless if memory is hard limited by your PHP
@@ -1311,12 +1311,9 @@ function left_menu($menu_array_before, $helppagename='', $moresearchform='', $me
print "\n";
// Instantiate hooks of thirdparty module
- if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules))
- {
- require_once(DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php');
- $object = new CommonObject($db);
- $object->callHooks(array('searchform','leftblock'));
- }
+ include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
+ $hookmanager=new HookManager($db);
+ $hookmanager->callHooks(array('printSearchform','leftblock'));
// Define $searchform
if ($conf->societe->enabled && $conf->global->MAIN_SEARCHFORM_SOCIETE && $user->rights->societe->lire)
@@ -1348,24 +1345,8 @@ function left_menu($menu_array_before, $helppagename='', $moresearchform='', $me
img_object('','user').' '.$langs->trans("Members"), 'member', 'sall');
}
- // Search form hook for external modules
- if (! empty($object->hooks))
- {
- $searchform.=''."\n";
-
- foreach($object->hooks as $hook)
- {
- if ($hook['type'] == 'searchform' && ! empty($hook['modules']))
- {
- foreach($hook['modules'] as $module)
- {
- if (method_exists($module,'printSearchForm')) $searchform.=$module->printSearchForm();
- }
- }
- }
-
- $searchform.="\n".''."\n";
- }
+ // Execute hook printSearchForm
+ $searchform.=$hookmanager->executeHooks('printSearchForm'); // Note that $action and $object may have been modified by some hooks
// Define $bookmarks
if ($conf->bookmark->enabled && $user->rights->bookmark->lire)
@@ -1475,24 +1456,9 @@ function left_menu($menu_array_before, $helppagename='', $moresearchform='', $me
print "\n";
- // Left block hook for external modules
- if (! empty($object->hooks))
- {
- print ''."\n";
-
- foreach($object->hooks as $hook)
- {
- if ($hook['type'] == 'leftblock' && ! empty($hook['modules']))
- {
- foreach($hook['modules'] as $module)
- {
- if (method_exists($module,'printLeftBlock')) $module->printLeftBlock();
- }
- }
- }
-
- print "\n".''."\n";
- }
+ // Execute hook printLeftBlock
+ $leftblock.=$hookmanager->executeHooks('printLeftBlock'); // Note that $action and $object may have been modified by some hooks
+ print $leftblock;
if ($conf->use_javascript_ajax && $conf->global->MAIN_MENU_USE_JQUERY_LAYOUT) print ' '."\n";
else print '';
diff --git a/htdocs/societe/class/actions_societe.class.php b/htdocs/societe/class/actions_societe.class.php
deleted file mode 100644
index 00cd1b3b3ee..00000000000
--- a/htdocs/societe/class/actions_societe.class.php
+++ /dev/null
@@ -1,37 +0,0 @@
-
- *
- * 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
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-/**
- * \file htdocs/societe/class/actions_societe.class.php
- * \ingroup societe
- * \brief File for third party class
- * \version $Id: actions_societe.class.php,v 1.1 2011/08/09 09:13:08 hregis Exp $
- */
-require_once(DOL_DOCUMENT_ROOT."/societe/class/societe.class.php");
-
-
-/**
- * \class ActionsSociete
- * \brief Class to manage third parties objects (customers, suppliers, prospects...)
- */
-class ActionsSociete extends Societe
-{
-
-}
-
-
-?>
\ No newline at end of file
diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php
index 6816a0ed23b..3aa32189562 100644
--- a/htdocs/societe/class/societe.class.php
+++ b/htdocs/societe/class/societe.class.php
@@ -26,7 +26,7 @@
* \file htdocs/societe/class/societe.class.php
* \ingroup societe
* \brief File for third party class
- * \version $Id: societe.class.php,v 1.93 2011/08/09 17:59:50 hregis Exp $
+ * \version $Id: societe.class.php,v 1.94 2011/08/10 00:50:16 eldy Exp $
*/
require_once(DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php");
@@ -533,32 +533,20 @@ class Societe extends CommonObject
// Si le fournisseur est classe on l'ajoute
$this->AddFournisseurInCategory($this->fournisseur_categorie);
- /*
- $result=$this->insertExtraFields();
- if ($result < 0)
+ // Actions on extra fields (by external module or standard code)
+ include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
+ $hookmanager=new HookManager($db);
+ $hookmanager->callHooks(array('thirdparty_extrafields'));
+ $reshook=$hookmanager->executeHooks('insertExtraFields',$action,$this,$socid); // Note that $action and $object may have been modified by some hooks
+ if (empty($reshook))
{
- $error++;
+ $result=$this->insertExtraFields($this);
+ if ($result < 0)
+ {
+ $error++;
+ }
}
- */
-
- // Hook for external modules
- if (! empty($this->hooks))
- {
- foreach($this->hooks as $hook)
- {
- if ($hook['type'] == 'thirdparty_extrafields' && ! empty($hook['modules']))
- {
- foreach($hook['modules'] as $module)
- {
- if (method_exists($module,'insertExtraFields'))
- {
- $result=$module->insertExtraFields($this);
- if ($result < 0) $error++;
- }
- }
- }
- }
- }
+ else if ($reshook < 0) $error++;
if (! $error && $call_trigger)
{
diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php
index f6372674671..ba891f65944 100644
--- a/htdocs/societe/soc.php
+++ b/htdocs/societe/soc.php
@@ -25,7 +25,7 @@
* \file htdocs/societe/soc.php
* \ingroup societe
* \brief Third party card page
- * \version $Id: soc.php,v 1.129 2011/08/09 17:59:52 hregis Exp $
+ * \version $Id: soc.php,v 1.130 2011/08/10 00:50:19 eldy Exp $
*/
require("../main.inc.php");
@@ -35,7 +35,7 @@ require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
require_once(DOL_DOCUMENT_ROOT."/core/class/html.formadmin.class.php");
require_once(DOL_DOCUMENT_ROOT."/core/class/html.formcompany.class.php");
require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php");
-//require_once(DOL_DOCUMENT_ROOT."/core/class/extrafields.class.php");
+require_once(DOL_DOCUMENT_ROOT."/core/class/extrafields.class.php");
require_once(DOL_DOCUMENT_ROOT."/contact/class/contact.class.php");
if ($conf->adherent->enabled) require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php");
@@ -52,7 +52,7 @@ $action = GETPOST('action');
$confirm = GETPOST('confirm');
$object = new Societe($db);
-//$extrafields = new ExtraFields($db);
+$extrafields = new ExtraFields($db);
// Security check
$socid = GETPOST("socid");
@@ -75,11 +75,10 @@ else
$result = restrictedArea($user, 'societe', $socid);
}
-// Instantiate hooks of thirdparty module. Note that conf->hooks_modules contains array array
-if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules))
-{
- $object->callHooks(array('thirdpartycard','thirdparty_extrafields'));
-}
+// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
+include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
+$hookmanager=new HookManager($db);
+$hookmanager->callHooks(array('thirdpartycard','thirdparty_extrafields'));
@@ -87,35 +86,8 @@ if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules))
* Actions
*/
-$reshook=0;
+$reshook=$hookmanager->executeHooks('doActions',$action,$object,$socid); // Note that $action and $object may have been modified by some hooks
-// Hook of actions. After that, reshook is 0 if we need to process standard actions, >0 otherwise.
-if (! empty($object->hooks))
-{
- foreach($object->hooks as $hook)
- {
- if (! empty($hook['modules']))
- {
- foreach($hook['modules'] as $module)
- {
- if (method_exists($module,'doActions'))
- {
- $resaction+=$module->doActions($object,$action,$socid); // object is deprecated, action can be changed by method (to go back to other action for example), socid can be changed/set by method (during creation for example)
- if ($resaction < 0 || ! empty($module->error) || (! empty($module->errors) && sizeof($module->errors) > 0))
- {
- $error=$module->error; $errors=$module->errors;
- if ($action=='add') $action='create'; // TODO this chnage must be inside the doActions
- if ($action=='update') $action='edit'; // TODO this chnage must be inside the doActions
- }
- else
- {
- $reshook+=$resaction;
- }
- }
- }
- }
- }
-}
// ---------- start deprecated. Use hook to hook actions.
// If canvas actions are defined, because on url, or because contact was created with canvas feature on, we use the canvas feature.
@@ -133,6 +105,7 @@ if (method_exists($objcanvas->control,'doActions'))
}
// ---------- end deprecated.
+
if (empty($reshook))
{
if ($_POST["getcustomercode"])
@@ -502,7 +475,7 @@ if (empty($reshook))
*/
// fetch optionals attributes and labels
-//$extralabels=$extrafields->fetch_name_optionals_label('company');
+$extralabels=$extrafields->fetch_name_optionals_label('company');
$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
llxHeader('',$langs->trans("ThirdParty"),$help_url);
@@ -1025,33 +998,17 @@ else
}
// Other attributes
- /*
- foreach($extrafields->attribute_label as $key=>$label)
+ $reshook=$hookmanager->executeHooks('showInputFields',$action,$object); // Note that $action and $object may have been modified by hook
+ if (empty($reshook))
{
- $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:'');
- print "| ".$label.' | ';
- print $extrafields->showInputField($key,$value);
- print ' |
'."\n";
+ foreach($extrafields->attribute_label as $key=>$label)
+ {
+ $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:'');
+ print "| ".$label.' | ';
+ print $extrafields->showInputField($key,$value);
+ print ' |
'."\n";
+ }
}
- */
-
- // Hook for external modules
- if (! empty($object->hooks))
- {
- foreach($object->hooks as $hook)
- {
- if ($hook['type'] == 'thirdparty_extrafields' && ! empty($hook['modules']))
- {
- foreach($hook['modules'] as $module)
- {
- if (method_exists($module,'showInputFields'))
- {
- $module->showInputFields($object,$_POST);
- }
- }
- }
- }
- }
// Ajout du logo
print '';
@@ -1077,10 +1034,10 @@ else
if ($socid)
{
- //$object = new Societe($db);
+ $object = new Societe($db);
$res=$object->fetch($socid);
if ($res < 0) { dol_print_error($db,$object->error); exit; }
- //$res=$object->fetch_optionals($socid,$extralabels);
+ $res=$object->fetch_optionals($socid,$extralabels);
//if ($res < 0) { dol_print_error($db); exit; }
// Load object modCodeTiers
@@ -1468,33 +1425,17 @@ else
}
// Other attributes
- /*
- foreach($extrafields->attribute_label as $key=>$label)
+ $reshook=$hookmanager->executeHooks('showInputFields',$action,$object); // Note that $action and $object may have been modified by hook
+ if (empty($reshook))
{
- $value=(isset($_POST["options_$key"])?$_POST["options_$key"]:$object->array_options["options_$key"]);
- print "
| ".$label." | ";
- print $extrafields->showInputField($key,$value);
- print " |
\n";
+ foreach($extrafields->attribute_label as $key=>$label)
+ {
+ $value=(isset($_POST["options_$key"])?$_POST["options_$key"]:$object->array_options["options_$key"]);
+ print "| ".$label." | ";
+ print $extrafields->showInputField($key,$value);
+ print " |
\n";
+ }
}
- */
-
- // Hook for external modules
- if (! empty($object->hooks))
- {
- foreach($object->hooks as $hook)
- {
- if ($hook['type'] == 'thirdparty_extrafields' && ! empty($hook['modules']))
- {
- foreach($hook['modules'] as $module)
- {
- if (method_exists($module,'showInputFields'))
- {
- $module->showInputFields($object,$_POST,$socid);
- }
- }
- }
- }
- }
// Logo
print '';
@@ -1531,10 +1472,10 @@ else
/*
* View
*/
- //$object = new Societe($db);
+ $object = new Societe($db);
$res=$object->fetch($socid);
if ($res < 0) { dol_print_error($db,$object->error); exit; }
- //$res=$object->fetch_optionals($socid,$extralabels);
+ $res=$object->fetch_optionals($socid,$extralabels);
//if ($res < 0) { dol_print_error($db); exit; }
@@ -1824,33 +1765,17 @@ else
}
// Other attributes
- /*
- foreach($extrafields->attribute_label as $key=>$label)
+ $reshook=$hookmanager->executeHooks('showOutputFields',$action,$object,$socid); // Note that $action and $object may have been modified by hook
+ if (empty($reshook))
{
- $value=$object->array_options["options_$key"];
- print "
| ".$label.' | ';
- print $extrafields->showOutputField($key,$value);
- print " |
\n";
+ foreach($extrafields->attribute_label as $key=>$label)
+ {
+ $value=$object->array_options["options_$key"];
+ print "| ".$label.' | ';
+ print $extrafields->showOutputField($key,$value);
+ print " |
\n";
+ }
}
- */
-
- // Hook for external modules
- if (! empty($object->hooks))
- {
- foreach($object->hooks as $hook)
- {
- if ($hook['type'] == 'thirdparty_extrafields' && ! empty($hook['modules']))
- {
- foreach($hook['modules'] as $module)
- {
- if (method_exists($module,'showOutputFields'))
- {
- $module->showOutputFields($object,$socid);
- }
- }
- }
- }
- }
// Ban
if (empty($conf->global->SOCIETE_DISABLE_BANKACCOUNT))
@@ -2029,5 +1954,5 @@ else
$db->close();
-llxFooter('$Date: 2011/08/09 17:59:52 $ - $Revision: 1.129 $');
+llxFooter('$Date: 2011/08/10 00:50:19 $ - $Revision: 1.130 $');
?>
\ No newline at end of file