diff --git a/htdocs/includes/triggers/interface_demo.class.php b/htdocs/includes/triggers/interface_demo.class.php index 427b42e97ab..085cf730be3 100644 --- a/htdocs/includes/triggers/interface_demo.class.php +++ b/htdocs/includes/triggers/interface_demo.class.php @@ -104,33 +104,51 @@ class InterfaceDemo // Users if ($action == 'USER_CREATE') { - dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id); + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); } elseif ($action == 'USER_MODIFY') { - dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id); + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); } elseif ($action == 'USER_NEW_PASSWORD') { - dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id); + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); } elseif ($action == 'USER_DISABLE') { - dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id); + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'USER_DELETE') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); } // Companies elseif ($action == 'COMPANY_CREATE') { - dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id); + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); } elseif ($action == 'COMPANY_MODIFY') { - dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id); + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); } elseif ($action == 'COMPANY_DELETE') { - dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id); + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + + // Contacts + elseif ($action == 'CONTACT_CREATE') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'CONTACT_MODIFY') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'CONTACT_DELETE') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); } // Products @@ -283,12 +301,6 @@ class InterfaceDemo dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched"); } - // If not found - else - { - dolibarr_syslog("Trigger '".$this->name."' for action '$action' was ran but no handler found for this action."); - return -1; - } return 0; } diff --git a/htdocs/includes/triggers/interface_ldap.class.php b/htdocs/includes/triggers/interface_ldap.class.php new file mode 100644 index 00000000000..0624c78ae9c --- /dev/null +++ b/htdocs/includes/triggers/interface_ldap.class.php @@ -0,0 +1,208 @@ + + * + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + * $Source$ + */ + +/** + \file htdocs/includes/triggers/interface_ldap.class.php + \ingroup core + \brief Fichier de gestion des triggers LDAP +*/ + +require_once (DOL_DOCUMENT_ROOT."/lib/ldap.class.php"); + + +/** + \class InterfaceLdap + \brief Classe des fonctions triggers des actions de synchro LDAP +*/ + +class InterfaceLdap +{ + var $db; + + /** + * \brief Constructeur. + * \param DB Handler d'accès base + */ + function InterfaceLdap($DB) + { + $this->db = $DB ; + + $this->name = "Ldap"; + $this->family = "ldap"; + $this->description = "Les triggers de ce composant permettent d'effectuer les synchro de Dolibarr vers un annuaire LDAP"; + $this->version = 'dolibarr'; // 'experimental' or 'dolibarr' or version + } + + /** + * \brief Renvoi nom du lot de triggers + * \return string Nom du lot de triggers + */ + function getName() + { + return $this->name; + } + + /** + * \brief Renvoi descriptif du lot de triggers + * \return string Descriptif du lot de triggers + */ + function getDesc() + { + return $this->description; + } + + /** + * \brief Renvoi version du lot de triggers + * \return string Version du lot de triggers + */ + function getVersion() + { + global $langs; + $langs->load("admin"); + + if ($this->version == 'experimental') return $langs->trans("Experimental"); + elseif ($this->version == 'dolibarr') return DOL_VERSION; + elseif ($this->version) return $this->version; + else return $langs->trans("Unknown"); + } + + /** + * \brief Fonction appelée lors du déclenchement d'un évènement Dolibarr. + * D'autres fonctions run_trigger peuvent etre présentes dans includes/triggers + * \param action Code de l'evenement + * \param object Objet concerné + * \param user Objet user + * \param lang Objet lang + * \param conf Objet conf + * \return int <0 si ko, 0 si aucune action faite, >0 si ok + */ + function run_trigger($action,$object,$user,$langs,$conf) + { + // Mettre ici le code à exécuter en réaction de l'action + // Les données de l'action sont stockées dans $object + + if (! $conf->ldap->enabled) return 0; // Module non actif + + // Users + if ($action == 'USER_CREATE') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if ($conf->ldap->enabled && $conf->global->LDAP_SYNCHRO_ACTIVE) + { + $ldap=new Ldap(); + $ldap->connect_bind(); + + $info=$object->_load_ldap_info(); + $dn=$object->_load_ldap_dn($info); + + $ldap->add($dn,$info,$user); + } + } + elseif ($action == 'USER_MODIFY') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if ($conf->ldap->enabled && $conf->global->LDAP_SYNCHRO_ACTIVE) + { + $ldap=new Ldap(); + $ldap->connect_bind(); + + $info=$object->_load_ldap_info(); + $dn=$object->_load_ldap_dn($info); + + $ldap->update($dn,$info,$user); + } + } + elseif ($action == 'USER_NEW_PASSWORD') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'USER_DISABLE') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'USER_DELETE') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if ($conf->ldap->enabled && $conf->global->LDAP_SYNCHRO_ACTIVE) + { + $ldap=new Ldap(); + $ldap->connect_bind(); + + $info=$object->_load_ldap_info(); + $dn=$object->_load_ldap_dn($info); + + $ldap->delete($dn,$info,$user); + } + } + + // Contacts + elseif ($action == 'CONTACT_CREATE') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'CONTACT_MODIFY') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'CONTACT_DELETE') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + + // Members + elseif ($action == 'MEMBER_CREATE') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'MEMBER_VALIDATE') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'MEMBER_SUBSCRIPTION') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'MEMBER_MODIFY') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'MEMBER_RESILIATE') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'MEMBER_DELETE') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + + // If not found +/* + else + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' was ran by ".__FILE__." but no handler found for this action."); + return -1; + } +*/ + return 0; + } + +} +?> diff --git a/htdocs/includes/triggers/interface_notification.class.php b/htdocs/includes/triggers/interface_notification.class.php index e7fd1d7098c..a0519848fff 100644 --- a/htdocs/includes/triggers/interface_notification.class.php +++ b/htdocs/includes/triggers/interface_notification.class.php @@ -94,6 +94,9 @@ class InterfaceNotification */ function run_trigger($action,$object,$user,$langs,$conf) { + // Mettre ici le code à exécuter en réaction de l'action + // Les données de l'action sont stockées dans $object + // Si module notification non actif, on ne fait rien if (! $conf->notification->enabled) return 0; @@ -101,7 +104,7 @@ class InterfaceNotification if ($action == 'BILL_VALIDATE') { - dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id); + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $action_notify = 2; $ref = sanitize_string($object->ref); @@ -112,9 +115,9 @@ class InterfaceNotification $notify->send($action_notify, $object->socid, $mesg, 'facture', $object->id, $filepdf); } - if ($action == 'FICHEINTER_VALIDATE') + elseif ($action == 'FICHEINTER_VALIDATE') { - dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id); + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $action_notify = 1; $ref = sanitize_string($object->ref); @@ -125,9 +128,9 @@ class InterfaceNotification $notify->send($action_notify, $object->socid, $mesg, 'ficheinter', $object->id, $filepdf); } - if ($action == 'ORDER_SUPPLIER_VALIDATE') + elseif ($action == 'ORDER_SUPPLIER_VALIDATE') { - dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id); + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $action_notify = 3; $ref = sanitize_string($object->ref); @@ -138,6 +141,14 @@ class InterfaceNotification $notify->send($action_notify, $object->socid, $mesg, 'order_supplier', $object->id, $filepdf); } + // If not found +/* + else + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' was ran by ".__FILE__." but no handler found for this action."); + return -1; + } +*/ return 0; } diff --git a/htdocs/includes/triggers/interface_webcal.class.php b/htdocs/includes/triggers/interface_webcal.class.php index d572c19feb1..14a301c21df 100644 --- a/htdocs/includes/triggers/interface_webcal.class.php +++ b/htdocs/includes/triggers/interface_webcal.class.php @@ -115,7 +115,7 @@ class InterfaceWebCal // Actions if ($action == 'ACTION_CREATE') { - dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id); + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); // Initialisation donnees (date,duree,texte,desc) @@ -141,9 +141,9 @@ class InterfaceWebCal $this->desc=$libellecal; } - if ($action == 'COMPANY_CREATE') + elseif ($action == 'COMPANY_CREATE') { - dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id); + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); // Initialisation donnees (date,duree,texte,desc) @@ -157,9 +157,9 @@ class InterfaceWebCal $this->desc.="\n".$langs->trans("Author").': '.$user->code; } - if ($action == 'CONTRACT_VALIDATE') + elseif ($action == 'CONTRACT_VALIDATE') { - dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id); + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); // Initialisation donnees (date,duree,texte,desc) @@ -169,9 +169,9 @@ class InterfaceWebCal $this->desc=$langs->trans("ContractValidatedInDolibarr",$object->ref); $this->desc.="\n".$langs->trans("Author").': '.$user->code; } - if ($action == 'CONTRACT_CANCEL') + elseif ($action == 'CONTRACT_CANCEL') { - dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id); + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $this->date=time(); @@ -180,9 +180,9 @@ class InterfaceWebCal $this->desc=$langs->trans("ContractCanceledInDolibarr",$object->ref); $this->desc.="\n".$langs->trans("Author").': '.$user->code; } - if ($action == 'CONTRACT_CLOSE') + elseif ($action == 'CONTRACT_CLOSE') { - dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id); + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $this->date=time(); @@ -191,18 +191,9 @@ class InterfaceWebCal $this->desc=$langs->trans("ContractClosedInDolibarr",$object->ref); $this->desc.="\n".$langs->trans("Author").': '.$user->code; } - - if ($action == 'PROPAL_CREATE') + elseif ($action == 'PROPAL_VALIDATE') { - // Pas interessant - } - if ($action == 'PROPAL_MODIFY') - { - // Etat brouillon pas interessant - } - if ($action == 'PROPAL_VALIDATE') - { - dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id); + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $this->date=time(); @@ -211,7 +202,7 @@ class InterfaceWebCal $this->desc=$langs->trans("PropalValidatedInDolibarr",$object->ref); $this->desc.="\n".$langs->trans("Author").': '.$user->code; } - if ($action == 'PROPAL_CLOSE_SIGNED') + elseif ($action == 'PROPAL_CLOSE_SIGNED') { dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id); $langs->load("other"); @@ -222,7 +213,7 @@ class InterfaceWebCal $this->desc=$langs->trans("PropalClosedSignedInDolibarr",$object->ref); $this->desc.="\n".$langs->trans("Author").': '.$user->code; } - if ($action == 'PROPAL_CLOSE_REFUSED') + elseif ($action == 'PROPAL_CLOSE_REFUSED') { dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id); $langs->load("other"); @@ -234,15 +225,7 @@ class InterfaceWebCal $this->desc.="\n".$langs->trans("Author").': '.$user->code; } - if ($action == 'BILL_CREATE') - { - // Etat brouillon pas interessant - } - if ($action == 'BILL_MODIFY') - { - // Pas interessant - } - if ($action == 'BILL_VALIDATE') + elseif ($action == 'BILL_VALIDATE') { dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id); $langs->load("other"); @@ -253,7 +236,7 @@ class InterfaceWebCal $this->desc=$langs->trans("InvoiceValidatedInDolibarr",$object->ref); $this->desc.="\n".$langs->trans("Author").': '.$user->code; } - if ($action == 'BILL_PAYED') + elseif ($action == 'BILL_PAYED') { dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id); $langs->load("other"); @@ -264,7 +247,7 @@ class InterfaceWebCal $this->desc=$langs->trans("InvoicePayedInDolibarr",$object->ref); $this->desc.="\n".$langs->trans("Author").': '.$user->code; } - if ($action == 'BILL_CANCELED') + elseif ($action == 'BILL_CANCELED') { dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id); $langs->load("other"); @@ -300,6 +283,14 @@ class InterfaceWebCal $this->desc.="\n".$langs->trans("AmountTTC").': '.$object->total; $this->desc.="\n".$langs->trans("Author").': '.$user->code; } + // If not found +/* + else + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' was ran by ".__FILE__." but no handler found for this action."); + return 0; + } +*/ // Ajoute entrée dans webcal if ($this->date) @@ -334,7 +325,7 @@ class InterfaceWebCal return -1; } } - + return 0; } diff --git a/htdocs/lib/ldap.class.php b/htdocs/lib/ldap.class.php index a50017255fa..08db213a5c7 100644 --- a/htdocs/lib/ldap.class.php +++ b/htdocs/lib/ldap.class.php @@ -603,7 +603,7 @@ class Ldap } } - dolibarr_syslog("ldap.class::add dn=".$dn." info=".join(',',$info)); + dolibarr_syslog("Ldap.class::add dn=".$dn." info=".join(',',$info)); //print_r($info); $result=@ldap_add($this->connection, $dn, $info); @@ -627,7 +627,7 @@ class Ldap $dn=utf8_encode($dn); } - dolibarr_syslog("ldap.class::delete Delete LDAP entry dn=".$dn); + dolibarr_syslog("Ldap.class::delete Delete LDAP entry dn=".$dn); $result=@ldap_delete($this->connection, $dn); @@ -791,7 +791,7 @@ class Ldap $checkDn=utf8_decode($checkDn); } - dolibarr_syslog("ldap.class::search checkDn=".$checkDn." filter=".$filter); + dolibarr_syslog("Ldap.class::search checkDn=".$checkDn." filter=".$filter); // if the directory is AD, then bind first with the search user first if ($this->serverType == "activedirectory") { diff --git a/htdocs/user.class.php b/htdocs/user.class.php index 7cacb6840fd..78d8668571d 100644 --- a/htdocs/user.class.php +++ b/htdocs/user.class.php @@ -37,8 +37,6 @@ \version $Revision$ */ -require_once (DOL_DOCUMENT_ROOT."/lib/ldap.class.php"); - /** \class User @@ -587,18 +585,6 @@ class User if ($result < 0) $error++; // Fin appel triggers - // \todo Mettre en trigger - if ($conf->ldap->enabled && $conf->global->LDAP_SYNCHRO_ACTIVE) - { - $ldap=new Ldap(); - $ldap->connect_bind(); - - $info=$this->_load_ldap_info(); - $dn=$this->_load_ldap_dn($info); - - $ldap->delete($dn,$info,$user); - } - $this->db->commit(); return 1; } @@ -670,18 +656,6 @@ class User if ($result < 0) $error++; // Fin appel triggers - // \todo Mettre en trigger - if ($conf->ldap->enabled && $conf->global->LDAP_SYNCHRO_ACTIVE) - { - $ldap=new Ldap(); - $ldap->connect_bind(); - - $info=$this->_load_ldap_info(); - $dn=$this->_load_ldap_dn($info); - - $ldap->add($dn,$info,$user); - } - if (! $error) { $this->db->commit(); @@ -878,18 +852,6 @@ class User $result=$interface->run_triggers('USER_MODIFY',$this,$user,$lang,$conf); if ($result < 0) $error++; // Fin appel triggers - - // \todo Mettre en trigger - if ($conf->ldap->enabled && $conf->global->LDAP_SYNCHRO_ACTIVE) - { - $ldap=new Ldap(); - $ldap->connect_bind(); - - $info=$this->_load_ldap_info(); - $dn=$this->_load_ldap_dn($info); - - $ldap->update($dn,$info,$user); - } } return 1;