diff --git a/htdocs/core/triggers/interface_20_all_Logevents.class.php b/htdocs/core/triggers/interface_20_all_Logevents.class.php new file mode 100755 index 00000000000..508cfa19541 --- /dev/null +++ b/htdocs/core/triggers/interface_20_all_Logevents.class.php @@ -0,0 +1,256 @@ + + * Copyright (C) 2009 Regis Houssin + * + * 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/triggers/interface_20_all_Logevents.class.php + * \ingroup core + * \brief Trigger file for + */ + + +/** + * \class InterfaceLogevents + * \brief Class of triggers for security events + */ +class InterfaceLogevents +{ + var $db; + var $error; + + var $date; + var $duree; + var $texte; + var $desc; + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + function InterfaceLogevents($db) + { + $this->db = $db; + + $this->name = preg_replace('/^Interface/i','',get_class($this)); + $this->family = "core"; + $this->description = "Triggers of this module allows to add security event records inside Dolibarr."; + $this->version = 'dolibarr'; // 'experimental' or 'dolibarr' or version + $this->picto = 'technic'; + } + + /** + * Return name of trigger file + * @return string Name of trigger file + */ + function getName() + { + return $this->name; + } + + /** + * Return description of trigger file + * @return string Description of trigger file + */ + function getDesc() + { + return $this->description; + } + + /** + * Return version of trigger file + * @return string Version of trigger file + */ + 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"); + } + + /** + * Function called when a Dolibarrr business event is done. + * All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers + * @param action Code de l'evenement + * @param object Objet concerne + * @param user Objet user + * @param langs Objet langs + * @param conf Objet conf + * @param entity Value for instance of data (Always 1 except if module MultiCompany is installed) + * @return int <0 if KO, 0 if no triggered ran, >0 if OK + */ + function run_trigger($action,$object,$user,$langs,$conf,$entity=1) + { + if (! empty($conf->global->MAIN_LOGEVENTS_DISABLE_ALL)) return 0; // Log events is disabled (hidden features) + + $key='MAIN_LOGEVENTS_'.$action; + //dol_syslog("xxxxxxxxxxx".$key); + if (empty($conf->global->$key)) return 0; // Log events not enabled for this action + + if (empty($conf->entity)) $conf->entity = $entity; // forcing of the entity if it's not defined (ex: in login form) + + $this->date=gmmktime(); + $this->duree=0; + + // Actions + if ($action == 'USER_LOGIN') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + + // Initialisation donnees (date,duree,texte,desc) + $this->texte="(UserLogged,".$object->login.")"; + $this->desc="(UserLogged,".$object->login.")"; + } + if ($action == 'USER_LOGIN_FAILED') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + + // Initialisation donnees (date,duree,texte,desc) + $this->texte=$object->trigger_mesg; // Message direct + $this->desc=$object->trigger_mesg; // Message direct + } + if ($action == 'USER_LOGOUT') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + + // Initialisation donnees (date,duree,texte,desc) + $this->texte="(UserLogoff,".$object->login.")"; + $this->desc="(UserLogoff,".$object->login.")"; + } + if ($action == 'USER_CREATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("users"); + + // Initialisation donnees (date,duree,texte,desc) + $this->texte=$langs->transnoentities("NewUserCreated",$object->login); + $this->desc=$langs->transnoentities("NewUserCreated",$object->login); + } + elseif ($action == 'USER_MODIFY') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("users"); + + // Initialisation donnees (date,duree,texte,desc) + $this->texte=$langs->transnoentities("EventUserModified",$object->login); + $this->desc=$langs->transnoentities("EventUserModified",$object->login); + } + elseif ($action == 'USER_NEW_PASSWORD') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("users"); + + // Initialisation donnees (date,duree,texte,desc) + $this->texte=$langs->transnoentities("NewUserPassword",$object->login); + $this->desc=$langs->transnoentities("NewUserPassword",$object->login); + } + elseif ($action == 'USER_ENABLEDISABLE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("users"); + // Initialisation donnees (date,duree,texte,desc) + if ($object->statut == 0) + { + $this->texte=$langs->transnoentities("UserEnabled",$object->login); + $this->desc=$langs->transnoentities("UserEnabled",$object->login); + } + if ($object->statut == 1) + { + $this->texte=$langs->transnoentities("UserDisabled",$object->login); + $this->desc=$langs->transnoentities("UserDisabled",$object->login); + } + } + elseif ($action == 'USER_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("users"); + // Initialisation donnees (date,duree,texte,desc) + $this->texte=$langs->transnoentities("UserDeleted",$object->login); + $this->desc=$langs->transnoentities("UserDeleted",$object->login); + } + + // Groupes + elseif ($action == 'GROUP_CREATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("users"); + // Initialisation donnees (date,duree,texte,desc) + $this->texte=$langs->transnoentities("NewGroupCreated",$object->nom); + $this->desc=$langs->transnoentities("NewGroupCreated",$object->nom); + } + elseif ($action == 'GROUP_MODIFY') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("users"); + // Initialisation donnees (date,duree,texte,desc) + $this->texte=$langs->transnoentities("GroupModified",$object->nom); + $this->desc=$langs->transnoentities("GroupModified",$object->nom); + } + elseif ($action == 'GROUP_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("users"); + // Initialisation donnees (date,duree,texte,desc) + $this->texte=$langs->transnoentities("GroupDeleted",$object->nom); + $this->desc=$langs->transnoentities("GroupDeleted",$object->nom); + } + + // If not found +/* + else + { + dol_syslog("Trigger '".$this->name."' for action '$action' was ran by ".__FILE__." but no handler found for this action."); + return 0; + } +*/ + + // Add entry in event table + if ($this->date) + { + include_once(DOL_DOCUMENT_ROOT.'/core/class/events.class.php'); + + $event=new Events($this->db); + $event->type=$action; + $event->dateevent=$this->date; + $event->label=$this->texte; + $event->description=$this->desc; + $event->user_agent=$_SERVER["HTTP_USER_AGENT"]; + + $result=$event->create($user); + if ($result > 0) + { + return 1; + } + else + { + $error ="Failed to insert security event: ".$event->error; + $this->error=$error; + + dol_syslog(get_class($this).": ".$this->error, LOG_ERR); + return -1; + } + } + + return 0; + } + +} +?> diff --git a/htdocs/core/triggers/interface_20_modPaypal_PaypalWorkflow.class.php b/htdocs/core/triggers/interface_20_modPaypal_PaypalWorkflow.class.php new file mode 100755 index 00000000000..219087a0922 --- /dev/null +++ b/htdocs/core/triggers/interface_20_modPaypal_PaypalWorkflow.class.php @@ -0,0 +1,139 @@ + + * + * 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/triggers/interface_20_modPaypal_PaypalWorkflow.class.php + * \ingroup paypal + * \brief Trigger file for paypal workflow + */ + + +/** + * \class InterfacePaypalWorkflow + * \brief Class of triggers for paypal module + */ +class InterfacePaypalWorkflow +{ + var $db; + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + function InterfacePaypalWorkflow($db) + { + $this->db = $db; + + $this->name = preg_replace('/^Interface/i','',get_class($this)); + $this->family = "paypal"; + $this->description = "Triggers of this module allows to manage paypal workflow"; + $this->version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' or version + $this->picto = 'paypal@paypal'; + } + + + /** + * \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 == 'development') return $langs->trans("Development"); + elseif ($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"); + } + + /** + * Fonction appelee lors du declenchement d'un evenement Dolibarr. + * D'autres fonctions run_trigger peuvent etre presentes dans core/triggers + * + * @param string $action Code de l'evenement + * @param CommonObject $object Objet concerne + * @param User $user Objet user + * @param Translate $lang Objet lang + * @param Conf $conf Objet conf + * @return int <0 if fatal error, 0 si nothing done, >0 if ok + */ + function run_trigger($action,$object,$user,$langs,$conf) + { + // Mettre ici le code a executer en reaction de l'action + // Les donnees de l'action sont stockees dans $object + + if ($action == 'PAYPAL_PAYMENT_OK') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". source=".$object->source." ref=".$object->ref); + + require_once(DOL_DOCUMENT_ROOT."/societe/class/societe.class.php"); + + $soc = new Societe($this->db); + + // Parse element/subelement (ex: project_task) + $element = $path = $filename = $object->source; + if (preg_match('/^([^_]+)_([^_]+)/i',$object->source,$regs)) + { + $element = $path = $regs[1]; + $filename = $regs[2]; + } + // For compatibility + if ($element == 'order') { $path = $filename = 'commande'; } + if ($element == 'invoice') { $path = 'compta/facture'; $filename = 'facture'; } + + dol_include_once('/'.$path.'/class/'.$filename.'.class.php'); + + $classname = ucfirst($filename); + $obj = new $classname($this->db); + + $ret = $obj->fetch('',$object->ref); + if ($ret < 0) return -1; + + // Add payer id + $soc->setValueFrom('ref_int', $object->payerID, 'societe', $obj->socid); + + // Add transaction id + $obj->setValueFrom('ref_int',$object->resArray["TRANSACTIONID"]); + + } + + return 0; + } + +} +?> diff --git a/htdocs/core/triggers/interface_20_modWorkflow_WorkflowManager.class.php b/htdocs/core/triggers/interface_20_modWorkflow_WorkflowManager.class.php new file mode 100755 index 00000000000..4d9c5a42ac0 --- /dev/null +++ b/htdocs/core/triggers/interface_20_modWorkflow_WorkflowManager.class.php @@ -0,0 +1,135 @@ + + * Copyright (C) 2011 Laurent Destailleur + * + * 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/triggers/interface_20_modWorkflow_WorkflowManager.class.php + * \ingroup core + * \brief Trigger file for workflows + */ + + +/** + * \class InterfaceWorkflowManager + * \brief Class of triggers for workflow module + */ + +class InterfaceWorkflowManager +{ + var $db; + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + function InterfaceWorkflowManager($db) + { + $this->db = $db; + + $this->name = preg_replace('/^Interface/i','',get_class($this)); + $this->family = "core"; + $this->description = "Triggers of this module allows to manage workflows"; + $this->version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' or version + $this->picto = 'technic'; + } + + + /** + * Return name of trigger file + * @return string Name of trigger file + */ + function getName() + { + return $this->name; + } + + /** + * Return description of trigger file + * @return string Description of trigger file + */ + function getDesc() + { + return $this->description; + } + + /** + * Return version of trigger file + * @return string Version of trigger file + */ + function getVersion() + { + global $langs; + $langs->load("admin"); + + if ($this->version == 'development') return $langs->trans("Development"); + elseif ($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"); + } + + /** + * Function called when a Dolibarrr business event is done. + * All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers + * + * @param action Event code (COMPANY_CREATE, PROPAL_VALIDATE, ...) + * @param object Object action is done on + * @param user Object user + * @param langs Object langs + * @param conf Object conf + * @return int <0 if KO, 0 if no action are done, >0 if OK + */ + function run_trigger($action,$object,$user,$langs,$conf) + { + if (empty($conf->workflow->enabled)) return 0; // Module not active, we do nothing + + // Proposals to order + if ($action == 'PROPAL_CLOSE_SIGNED') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if (! empty($conf->commande->enabled) && ! empty($conf->global->WORKFLOW_PROPAL_AUTOCREATE_ORDER)) + { + include_once(DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'); + $newobject = new Commande($this->db); + + $ret=$newobject->createFromProposal($object); + if ($ret < 0) { $this->error=$newobject->error; $this->errors[]=$newobject->error; } + return $ret; + } + } + + // Order to invoice + if ($action == 'ORDER_CLOSE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if (! empty($conf->facture->enabled) && ! empty($conf->global->WORKFLOW_ORDER_AUTOCREATE_INVOICE)) + { + include_once(DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'); + $newobject = new Facture($this->db); + + $ret=$newobject->createFromOrder($object); + if ($ret < 0) { $this->error=$newobject->error; $this->errors[]=$newobject->error; } + return $ret; + } + } + + return 0; + } + +} +?> diff --git a/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php b/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php new file mode 100755 index 00000000000..77d4755134e --- /dev/null +++ b/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php @@ -0,0 +1,599 @@ + + * Copyright (C) 2009-2011 Regis Houssin + * Copyright (C) 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/triggers/interface_50_modAgenda_ActionsAuto.class.php + * \ingroup agenda + * \brief Trigger file for agenda module + */ + + +/** + * \class InterfaceActionsAuto + * \brief Class of triggered functions for agenda module + */ +class InterfaceActionsAuto +{ + var $db; + var $error; + + var $date; + var $duree; + var $texte; + var $desc; + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + function InterfaceActionsAuto($db) + { + $this->db = $db; + + $this->name = preg_replace('/^Interface/i','',get_class($this)); + $this->family = "agenda"; + $this->description = "Triggers of this module add actions in agenda according to setup made in agenda setup."; + $this->version = 'dolibarr'; // 'experimental' or 'dolibarr' or version + $this->picto = 'action'; + } + + /** + * Return name of trigger file + * @return string Name of trigger file + */ + function getName() + { + return $this->name; + } + + /** + * Return description of trigger file + * @return string Description of trigger file + */ + function getDesc() + { + return $this->description; + } + + /** + * Return version of trigger file + * @return string Version of trigger file + */ + 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"); + } + + /** + * Function called when a Dolibarrr business event is done. + * All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers + * + * Following properties must be filled: + * $object->actiontypecode (translation action code: AC_OTH, ...) + * $object->actionmsg (note, long text) + * $object->actionmsg2 (label, short text) + * $object->sendtoid (id of contact) + * $object->socid + * Optionnal: + * $object->fk_element + * $object->elementtype + * + * @param action Event code (COMPANY_CREATE, PROPAL_VALIDATE, ...) + * @param object Object action is done on + * @param user Object user + * @param langs Object langs + * @param conf Object conf + * @return int <0 if KO, 0 if no action are done, >0 if OK + */ + function run_trigger($action,$object,$user,$langs,$conf) + { + $key='MAIN_AGENDA_ACTIONAUTO_'.$action; + //dol_syslog("xxxxxxxxxxx".$key); + + if (empty($conf->agenda->enabled)) return 0; // Module not active, we do nothing + if (empty($conf->global->$key)) return 0; // Log events not enabled for this action + + $ok=0; + + // Actions + if ($action == 'COMPANY_CREATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("other"); + $langs->load("agenda"); + + $object->actiontypecode='AC_OTH'; + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("NewCompanyToDolibarr",$object->nom); + $object->actionmsg=$langs->transnoentities("NewCompanyToDolibarr",$object->nom); + if ($object->prefix) $object->actionmsg.=" (".$object->prefix.")"; + //$this->desc.="\n".$langs->transnoentities("Customer").': '.yn($object->client); + //$this->desc.="\n".$langs->transnoentities("Supplier").': '.yn($object->fournisseur); + $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; + + $object->sendtoid=0; + $object->socid=$object->id; + $ok=1; + } + elseif ($action == 'CONTRACT_VALIDATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("other"); + $langs->load("contracts"); + $langs->load("agenda"); + + $object->actiontypecode='AC_OTH'; + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ContractValidatedInDolibarr",$object->ref); + $object->actionmsg=$langs->transnoentities("ContractValidatedInDolibarr",$object->ref); + $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; + + $object->sendtoid=0; + $ok=1; + } + elseif ($action == 'PROPAL_VALIDATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("propal"); + $langs->load("agenda"); + + $object->actiontypecode='AC_OTH'; + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalValidatedInDolibarr",$object->ref); + $object->actionmsg=$langs->transnoentities("PropalValidatedInDolibarr",$object->ref); + $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; + + $object->sendtoid=0; + $ok=1; + } + elseif ($action == 'PROPAL_SENTBYMAIL') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("propal"); + $langs->load("agenda"); + + $object->actiontypecode='AC_EMAIL'; + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ProposalSentByEMail",$object->ref); + if (empty($object->actionmsg)) + { + $object->actionmsg=$langs->transnoentities("ProposalSentByEMail",$object->ref); + $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; + } + + // Parameters $object->sendtoid defined by caller + //$object->sendtoid=0; + $ok=1; + } + elseif ($action == 'PROPAL_CLOSE_SIGNED') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("propal"); + $langs->load("agenda"); + + $object->actiontypecode='AC_OTH'; + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalClosedSignedInDolibarr",$object->ref); + $object->actionmsg=$langs->transnoentities("PropalClosedSignedInDolibarr",$object->ref); + $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; + + $object->sendtoid=0; + $ok=1; + } + elseif ($action == 'PROPAL_CLOSE_REFUSED') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("propal"); + $langs->load("agenda"); + + $object->actiontypecode='AC_OTH'; + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalClosedRefusedInDolibarr",$object->ref); + $object->actionmsg=$langs->transnoentities("PropalClosedRefusedInDolibarr",$object->ref); + $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; + + $object->sendtoid=0; + $ok=1; + } + elseif ($action == 'ORDER_VALIDATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("orders"); + $langs->load("agenda"); + + $object->actiontypecode='AC_OTH'; + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderValidatedInDolibarr",$object->ref); + $object->actionmsg=$langs->transnoentities("OrderValidatedInDolibarr",$object->ref); + $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; + + $object->sendtoid=0; + $ok=1; + } + elseif ($action == 'ORDER_SENTBYMAIL') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("orders"); + $langs->load("agenda"); + + $object->actiontypecode='AC_EMAIL'; + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderSentByEMail",$object->ref); + if (empty($object->actionmsg)) + { + $object->actionmsg=$langs->transnoentities("OrderSentByEMail",$object->ref); + $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; + } + + // Parameters $object->sendtoid defined by caller + //$object->sendtoid=0; + $ok=1; + } + elseif ($action == 'BILL_VALIDATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("other"); + $langs->load("bills"); + $langs->load("agenda"); + + $object->actiontypecode='AC_OTH'; + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceValidatedInDolibarr",$object->ref); + $object->actionmsg=$langs->transnoentities("InvoiceValidatedInDolibarr",$object->ref); + $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; + + $object->sendtoid=0; + $ok=1; + } + elseif ($action == 'BILL_SENTBYMAIL') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("other"); + $langs->load("bills"); + $langs->load("agenda"); + + $object->actiontypecode='AC_EMAIL'; + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceSentByEMail",$object->ref); + if (empty($object->actionmsg)) + { + $object->actionmsg=$langs->transnoentities("InvoiceSentByEMail",$object->ref); + $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; + } + + // Parameters $object->sendtoid defined by caller + //$object->sendtoid=0; + $ok=1; + } + elseif ($action == 'BILL_PAYED') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("other"); + $langs->load("bills"); + $langs->load("agenda"); + + $object->actiontypecode='AC_OTH'; + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoicePaidInDolibarr",$object->ref); + $object->actionmsg=$langs->transnoentities("InvoicePaidInDolibarr",$object->ref); + $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; + + $object->sendtoid=0; + $ok=1; + } + elseif ($action == 'BILL_CANCEL') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("other"); + $langs->load("bills"); + $langs->load("agenda"); + + $object->actiontypecode='AC_OTH'; + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref); + $object->actionmsg=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref); + $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; + + $object->sendtoid=0; + $ok=1; + } + elseif ($action == 'FICHEINTER_VALIDATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("other"); + $langs->load("interventions"); + $langs->load("agenda"); + + $object->actiontypecode='AC_OTH'; + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionValidatedInDolibarr",$object->ref); + $object->actionmsg=$langs->transnoentities("InterventionValidatedInDolibarr",$object->ref); + $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; + + $object->sendtoid=0; + $object->fk_element=0; + $object->elementtype=''; + $ok=1; + } + elseif ($action == 'FICHEINTER_SENTBYMAIL') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("other"); + $langs->load("interventions"); + $langs->load("agenda"); + + $object->actiontypecode='AC_EMAIL'; + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionSentByEMail",$object->ref); + $object->actionmsg=$langs->transnoentities("InterventionSentByEMail",$object->ref); + $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; + + // Parameters $object->sendotid defined by caller + //$object->sendtoid=0; + $ok=1; + } + elseif ($action == 'SHIPPING_SENTBYMAIL') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("other"); + $langs->load("sendings"); + $langs->load("agenda"); + + $object->actiontypecode='AC_SHIP'; + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ShippingSentByEMail",$object->ref); + if (empty($object->actionmsg)) + { + $object->actionmsg=$langs->transnoentities("ShippingSentByEMail",$object->ref); + $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; + } + + // Parameters $object->sendtoid defined by caller + //$object->sendtoid=0; + $ok=1; + } + elseif ($action == 'ORDER_SUPPLIER_VALIDATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("orders"); + $langs->load("agenda"); + + $object->actiontypecode='AC_OTH'; + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderValidatedInDolibarr",$object->ref); + $object->actionmsg=$langs->transnoentities("OrderValidatedInDolibarr",$object->ref); + $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; + + $object->sendtoid=0; + $ok=1; + } + elseif ($action == 'ORDER_SUPPLIER_SENTBYMAIL') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("other"); + $langs->load("bills"); + $langs->load("agenda"); + $langs->load("orders"); + + $object->actiontypecode='AC_EMAIL'; + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("SupplierOrderSentByEMail",$object->ref); + if (empty($object->actionmsg)) + { + $object->actionmsg=$langs->transnoentities("SupplierOrderSentByEMail",$object->ref); + $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; + } + + // Parameters $object->sendotid defined by caller + //$object->sendtoid=0; + $ok=1; + } + elseif ($action == 'BILL_SUPPLIER_VALIDATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("other"); + $langs->load("bills"); + $langs->load("agenda"); + + $object->actiontypecode='AC_OTH'; + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceValidatedInDolibarr",$object->ref); + $object->actionmsg=$langs->transnoentities("InvoiceValidatedInDolibarr",$object->ref); + $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; + + $object->sendtoid=0; + $ok=1; + } + elseif ($action == 'BILL_SUPPLIER_SENTBYMAIL') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("other"); + $langs->load("bills"); + $langs->load("agenda"); + $langs->load("orders"); + + $object->actiontypecode='AC_EMAIL'; + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("SupplierInvoiceSentByEMail",$object->ref); + if (empty($object->actionmsg)) + { + $object->actionmsg=$langs->transnoentities("SupplierInvoiceSentByEMail",$object->ref); + $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; + } + + // Parameters $object->sendtoid defined by caller + //$object->sendtoid=0; + $ok=1; + } + elseif ($action == 'BILL_SUPPLIER_PAYED') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("other"); + $langs->load("bills"); + $langs->load("agenda"); + + $object->actiontypecode='AC_OTH'; + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoicePaidInDolibarr",$object->ref); + $object->actionmsg=$langs->transnoentities("InvoicePaidInDolibarr",$object->ref); + $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; + + $object->sendtoid=0; + $ok=1; + } + elseif ($action == 'BILL_SUPPLIER_CANCELED') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("other"); + $langs->load("bills"); + $langs->load("agenda"); + + $object->actiontypecode='AC_OTH'; + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref); + $object->actionmsg=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref); + $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; + + $object->sendtoid=0; + $ok=1; + } + + // Members + elseif ($action == 'MEMBER_VALIDATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("other"); + $langs->load("members"); + $langs->load("agenda"); + + $object->actiontypecode='AC_OTH'; + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberValidatedInDolibarr",$object->ref); + $object->actionmsg=$langs->transnoentities("MemberValidatedInDolibarr",$object->ref); + $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs); + $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type; + $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; + + $object->sendtoid=0; + $ok=1; + } + elseif ($action == 'MEMBER_SUBSCRIPTION') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("other"); + $langs->load("members"); + $langs->load("agenda"); + + $object->actiontypecode='AC_OTH'; + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberSubscriptionAddedInDolibarr",$object->ref); + $object->actionmsg=$langs->transnoentities("MemberSubscriptionAddedInDolibarr",$object->ref); + $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs); + $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type; + $object->actionmsg.="\n".$langs->transnoentities("Amount").': '.$object->last_subscription_amount; + $object->actionmsg.="\n".$langs->transnoentities("Period").': '.dol_print_date($object->last_subscription_date_start,'day').' - '.dol_print_date($object->last_subscription_date_end,'day'); + $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; + + $object->sendtoid=0; + $ok=1; + } + elseif ($action == 'MEMBER_MODIFY') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'MEMBER_RESILIATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("other"); + $langs->load("members"); + $langs->load("agenda"); + + $object->actiontypecode='AC_OTH'; + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberResiliatedInDolibarr",$object->ref); + $object->actionmsg=$langs->transnoentities("MemberResiliatedInDolibarr",$object->ref); + $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs); + $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type; + $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; + + $object->sendtoid=0; + $ok=1; + } + elseif ($action == 'MEMBER_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("other"); + $langs->load("members"); + $langs->load("agenda"); + + $object->actiontypecode='AC_OTH'; + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberDeletedInDolibarr",$object->ref); + $object->actionmsg=$langs->transnoentities("MemberDeletedInDolibarr",$object->ref); + $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs); + $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type; + $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; + + $object->sendtoid=0; + $ok=1; + } + + // If not found + /* + else + { + dol_syslog("Trigger '".$this->name."' for action '$action' was ran by ".__FILE__." but no handler found for this action."); + return 0; + } + */ + + // Add entry in event table + if ($ok) + { + $now=dol_now(); + + require_once(DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'); + require_once(DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'); + $contactforaction=new Contact($this->db); + $societeforaction=new Societe($this->db); + if ($object->sendtoid > 0) $contactforaction->fetch($object->sendtoid); + if ($object->socid > 0) $societeforaction->fetch($object->socid); + + // Insertion action + require_once(DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'); + $actioncomm = new ActionComm($this->db); + $actioncomm->type_code = $object->actiontypecode; + $actioncomm->label = $object->actionmsg2; + $actioncomm->note = $object->actionmsg; + $actioncomm->datep = $now; + $actioncomm->datef = $now; + $actioncomm->durationp = 0; + $actioncomm->punctual = 1; + $actioncomm->percentage = -1; // Not applicable + $actioncomm->contact = $contactforaction; + $actioncomm->societe = $societeforaction; + $actioncomm->author = $user; // User saving action + //$actioncomm->usertodo = $user; // User affected to action + $actioncomm->userdone = $user; // User doing action + + $actioncomm->fk_element = $object->id; + $actioncomm->elementtype = $object->element; + + $ret=$actioncomm->add($user); // User qui saisit l'action + if ($ret > 0) + { + return 1; + } + else + { + $error ="Failed to insert : ".$actioncomm->error." "; + $this->error=$error; + + dol_syslog("interface_modAgenda_ActionsAuto.class.php: ".$this->error, LOG_ERR); + return -1; + } + } + + return 0; + } + +} +?> diff --git a/htdocs/core/triggers/interface_50_modLdap_Ldapsynchro.class.php b/htdocs/core/triggers/interface_50_modLdap_Ldapsynchro.class.php new file mode 100755 index 00000000000..89595d96169 --- /dev/null +++ b/htdocs/core/triggers/interface_50_modLdap_Ldapsynchro.class.php @@ -0,0 +1,537 @@ + + * + * 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/triggers/interface_50_modLdap_Ldapsynchro.class.php + * \ingroup core + * \brief Fichier de gestion des triggers LDAP + */ +require_once (DOL_DOCUMENT_ROOT."/core/class/ldap.class.php"); + + +/** + * \class InterfaceLdapsynchro + * \brief Class of triggers for ldap module + */ +class InterfaceLdapsynchro +{ + var $db; + var $error; + + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + function InterfaceLdapsynchro($db) + { + $this->db = $db; + + $this->name = preg_replace('/^Interface/i','',get_class($this)); + $this->family = "ldap"; + $this->description = "Triggers of this module allows to synchronize Dolibarr toward a LDAP database."; + $this->version = 'dolibarr'; // 'experimental' or 'dolibarr' or version + $this->picto = 'technic'; + } + + /** + * Return name of trigger file + * @return string Name of trigger file + */ + function getName() + { + return $this->name; + } + + /** + * Return description of trigger file + * @return string Description of trigger file + */ + function getDesc() + { + return $this->description; + } + + /** + * Return version of trigger file + * @return string Version of trigger file + */ + 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"); + } + + /** + * Function called when a Dolibarrr business event is done. + * All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers + * @param action Event code (COMPANY_CREATE, PROPAL_VALIDATE, ...) + * @param object Object action is done on + * @param user Object user + * @param langs Object langs + * @param conf Object conf + * @return int <0 if KO, 0 if no action are done, >0 if OK + */ + function run_trigger($action,$object,$user,$langs,$conf) + { + if (empty($conf->ldap->enabled)) return 0; // Module not active, we do nothing + + if (! function_exists('ldap_connect')) + { + dol_syslog("Warning, module LDAP is enabled but LDAP functions not available in this PHP", LOG_WARNING); + return 0; + } + + // Users + if ($action == 'USER_CREATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if ($conf->ldap->enabled && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap') + { + $ldap=new Ldap(); + $ldap->connect_bind(); + + $info=$object->_load_ldap_info(); + $dn=$object->_load_ldap_dn($info); + + $result=$ldap->add($dn,$info,$user); + if ($result < 0) + { + $this->error="ErrorLDAP"." ".$ldap->error; + } + return $result; + } + } + elseif ($action == 'USER_MODIFY') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if ($conf->ldap->enabled && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap') + { + $ldap=new Ldap(); + $ldap->connect_bind(); + + $oldinfo=$object->oldcopy->_load_ldap_info(); + $olddn=$object->oldcopy->_load_ldap_dn($oldinfo); + + // Verify if entry exist + $container=$object->oldcopy->_load_ldap_dn($oldinfo,1); + $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")"; + $records=$ldap->search($container,$search); + if (count($records) && $records['count'] == 0) + { + $olddn = ''; + } + + $info=$object->_load_ldap_info(); + $dn=$object->_load_ldap_dn($info); + + $result=$ldap->update($dn,$info,$user,$olddn); + if ($result < 0) + { + $this->error="ErrorLDAP"." ".$ldap->error; + } + return $result; + } + } + elseif ($action == 'USER_NEW_PASSWORD') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if ($conf->ldap->enabled && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap') + { + $ldap=new Ldap(); + $ldap->connect_bind(); + + $oldinfo=$object->oldcopy->_load_ldap_info(); + $olddn=$object->oldcopy->_load_ldap_dn($oldinfo); + + // Verify if entry exist + $container=$object->oldcopy->_load_ldap_dn($oldinfo,1); + $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")"; + $records=$ldap->search($container,$search); + if (count($records) && $records['count'] == 0) + { + $olddn = ''; + } + + $info=$object->_load_ldap_info(); + $dn=$object->_load_ldap_dn($info); + + $result=$ldap->update($dn,$info,$user,$olddn); + if ($result < 0) + { + $this->error="ErrorLDAP"." ".$ldap->error; + } + return $result; + } + } + elseif ($action == 'USER_ENABLEDISABLE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'USER_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if ($conf->ldap->enabled && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap') + { + $ldap=new Ldap(); + $ldap->connect_bind(); + + $info=$object->_load_ldap_info(); + $dn=$object->_load_ldap_dn($info); + + $result=$ldap->delete($dn,$info,$user); + if ($result < 0) + { + $this->error="ErrorLDAP"." ".$ldap->error; + } + return $result; + } + } + + // Groupes + elseif ($action == 'GROUP_CREATE') + { + if ($conf->ldap->enabled && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap') + { + $ldap=new Ldap(); + $ldap->connect_bind(); + + $info=$object->_load_ldap_info(); + $dn=$object->_load_ldap_dn($info); + + // Get a gid number for objectclass PosixGroup + if(in_array('posixGroup',$info['objectclass'])) + $info['gidNumber'] = $ldap->getNextGroupGid(); + + $result=$ldap->add($dn,$info,$user); + if ($result < 0) + { + $this->error="ErrorLDAP"." ".$ldap->error; + } + return $result; + } + } + elseif ($action == 'GROUP_MODIFY') + { + if ($conf->ldap->enabled && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap') + { + $ldap=new Ldap(); + $ldap->connect_bind(); + + $oldinfo=$object->oldcopy->_load_ldap_info(); + $olddn=$object->oldcopy->_load_ldap_dn($oldinfo); + + // Verify if entry exist + $container=$object->oldcopy->_load_ldap_dn($oldinfo,1); + $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")"; + $records=$ldap->search($container,$search); + if (count($records) && $records['count'] == 0) + { + $olddn = ''; + } + + $info=$object->_load_ldap_info(); + $dn=$object->_load_ldap_dn($info); + + $result=$ldap->update($dn,$info,$user,$olddn); + if ($result < 0) + { + $this->error="ErrorLDAP"." ".$ldap->error; + } + return $result; + } + } + elseif ($action == 'GROUP_DELETE') + { + if ($conf->ldap->enabled && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap') + { + $ldap=new Ldap(); + $ldap->connect_bind(); + + $info=$object->_load_ldap_info(); + $dn=$object->_load_ldap_dn($info); + + $result=$ldap->delete($dn,$info,$user); + if ($result < 0) + { + $this->error="ErrorLDAP"." ".$ldap->error; + } + return $result; + } + } + + // Contacts + elseif ($action == 'CONTACT_CREATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if ($conf->ldap->enabled && $conf->global->LDAP_CONTACT_ACTIVE) + { + $ldap=new Ldap(); + $ldap->connect_bind(); + + $info=$object->_load_ldap_info(); + $dn=$object->_load_ldap_dn($info); + + $result=$ldap->add($dn,$info,$user); + if ($result < 0) + { + $this->error="ErrorLDAP"." ".$ldap->error; + } + return $result; + } + } + elseif ($action == 'CONTACT_MODIFY') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if ($conf->ldap->enabled && $conf->global->LDAP_CONTACT_ACTIVE) + { + $ldap=new Ldap(); + $ldap->connect_bind(); + + $oldinfo=$object->oldcopy->_load_ldap_info(); + $olddn=$object->oldcopy->_load_ldap_dn($oldinfo); + + // Verify if entry exist + $container=$object->oldcopy->_load_ldap_dn($oldinfo,1); + $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")"; + $records=$ldap->search($container,$search); + if (count($records) && $records['count'] == 0) + { + $olddn = ''; + } + + $info=$object->_load_ldap_info(); + $dn=$object->_load_ldap_dn($info); + + $result=$ldap->update($dn,$info,$user,$olddn); + if ($result < 0) + { + $this->error="ErrorLDAP"." ".$ldap->error; + } + return $result; + } + } + elseif ($action == 'CONTACT_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if ($conf->ldap->enabled && $conf->global->LDAP_CONTACT_ACTIVE) + { + $ldap=new Ldap(); + $ldap->connect_bind(); + + $info=$object->_load_ldap_info(); + $dn=$object->_load_ldap_dn($info); + + $result=$ldap->delete($dn,$info,$user); + if ($result < 0) + { + $this->error="ErrorLDAP"." ".$ldap->error; + } + return $result; + } + } + + // Members + elseif ($action == 'MEMBER_CREATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if ($conf->ldap->enabled && $conf->global->LDAP_MEMBER_ACTIVE) + { + $ldap=new Ldap(); + $ldap->connect_bind(); + + $info=$object->_load_ldap_info(); + $dn=$object->_load_ldap_dn($info); + + $result=$ldap->add($dn,$info,$user); + if ($result < 0) + { + $this->error="ErrorLDAP"." ".$ldap->error; + } + return $result; + } + } + elseif ($action == 'MEMBER_VALIDATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if ($conf->ldap->enabled && $conf->global->LDAP_MEMBER_ACTIVE) + { + // If status field is setup to be synchronized + if ($conf->global->LDAP_FIELD_MEMBER_STATUS) + { + $ldap=new Ldap(); + $ldap->connect_bind(); + + $info=$object->_load_ldap_info(); + $dn=$object->_load_ldap_dn($info); + $olddn=$dn; // We know olddn=dn as we change only status + + $result=$ldap->update($dn,$info,$user,$olddn); + if ($result < 0) + { + $this->error="ErrorLDAP"." ".$ldap->error; + } + return $result; + } + } + } + elseif ($action == 'MEMBER_SUBSCRIPTION') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if ($conf->ldap->enabled && $conf->global->LDAP_MEMBER_ACTIVE) + { + // If subscriptions fields are setup to be synchronized + if ($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE + || $conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT + || $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE + || $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT + || $conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION) + { + $ldap=new Ldap(); + $ldap->connect_bind(); + + $info=$object->_load_ldap_info(); + $dn=$object->_load_ldap_dn($info); + $olddn=$dn; // We know olddn=dn as we change only subscriptions + + $result=$ldap->update($dn,$info,$user,$olddn); + if ($result < 0) + { + $this->error="ErrorLDAP"." ".$ldap->error; + } + return $result; + } + } + } + elseif ($action == 'MEMBER_MODIFY') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if ($conf->ldap->enabled && $conf->global->LDAP_MEMBER_ACTIVE) + { + $ldap=new Ldap(); + $ldap->connect_bind(); + + $oldinfo=$object->oldcopy->_load_ldap_info(); + $olddn=$object->oldcopy->_load_ldap_dn($oldinfo); + + // Verify if entry exist + $container=$object->oldcopy->_load_ldap_dn($oldinfo,1); + $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")"; + $records=$ldap->search($container,$search); + if (count($records) && $records['count'] == 0) + { + $olddn = ''; + } + + $info=$object->_load_ldap_info(); + $dn=$object->_load_ldap_dn($info); + + $result=$ldap->update($dn,$info,$user,$olddn); + if ($result < 0) + { + $this->error="ErrorLDAP"." ".$ldap->error; + } + return $result; + } + } + elseif ($action == 'MEMBER_NEW_PASSWORD') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if ($conf->ldap->enabled && $conf->global->LDAP_MEMBER_ACTIVE) + { + // If password field is setup to be synchronized + if ($conf->global->LDAP_FIELD_PASSWORD || $conf->global->LDAP_FIELD_PASSWORD_CRYPTED) + { + $ldap=new Ldap(); + $ldap->connect_bind(); + + $info=$object->_load_ldap_info(); + $dn=$object->_load_ldap_dn($info); + $olddn=$dn; // We know olddn=dn as we change only password + + $result=$ldap->update($dn,$info,$user,$olddn); + if ($result < 0) + { + $this->error="ErrorLDAP"." ".$ldap->error; + } + return $result; + } + } + } + elseif ($action == 'MEMBER_RESILIATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if ($conf->ldap->enabled && $conf->global->LDAP_MEMBER_ACTIVE) + { + // If status field is setup to be synchronized + if ($conf->global->LDAP_FIELD_MEMBER_STATUS) + { + $ldap=new Ldap(); + $ldap->connect_bind(); + + $info=$object->_load_ldap_info(); + $dn=$object->_load_ldap_dn($info); + $olddn=$dn; // We know olddn=dn as we change only status + + $result=$ldap->update($dn,$info,$user,$olddn); + if ($result < 0) + { + $this->error="ErrorLDAP"." ".$ldap->error; + } + return $result; + } + } + } + elseif ($action == 'MEMBER_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + if ($conf->ldap->enabled && $conf->global->LDAP_MEMBER_ACTIVE) + { + $ldap=new Ldap(); + $ldap->connect_bind(); + + $info=$object->_load_ldap_info(); + $dn=$object->_load_ldap_dn($info); + + $result=$ldap->delete($dn,$info,$user); + if ($result < 0) + { + $this->error="ErrorLDAP"." ".$ldap->error; + } + return $result; + } + } + + // If not found +/* + else + { + dol_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/core/triggers/interface_50_modNotification_Notification.class.php b/htdocs/core/triggers/interface_50_modNotification_Notification.class.php new file mode 100755 index 00000000000..d98c1ec0b93 --- /dev/null +++ b/htdocs/core/triggers/interface_50_modNotification_Notification.class.php @@ -0,0 +1,257 @@ + + * Copyright (C) 2011 Regis Houssin + * + * 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/triggers/interface_50_modNotification_Notification.class.php + * \ingroup notification + * \brief File of class of triggers for notification module + */ + + +/** + * \class InterfaceNotification + * \brief Class of triggers for notification module + */ +class InterfaceNotification +{ + var $db; + var $listofmanagedevents=array('BILL_VALIDATE','ORDER_VALIDATE','PROPAL_VALIDATE', + 'FICHEINTER_VALIDATE','ORDER_SUPPLIER_APPROVE','ORDER_SUPPLIER_REFUSE'); + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + function InterfaceNotification($db) + { + $this->db = $db; + + $this->name = preg_replace('/^Interface/i','',get_class($this)); + $this->family = "notification"; + $this->description = "Triggers of this module send email notifications according to Notification module setup."; + $this->version = 'dolibarr'; // 'experimental' or 'dolibarr' or version + $this->picto = 'email'; + } + + /** + * Return name of trigger file + * @return string Name of trigger file + */ + function getName() + { + return $this->name; + } + + /** + * Return description of trigger file + * @return string Description of trigger file + */ + function getDesc() + { + return $this->description; + } + + /** + * Return version of trigger file + * @return string Version of trigger file + */ + 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"); + } + + /** + * Function called when a Dolibarrr business event is done. + * All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers + * @param action Event code (COMPANY_CREATE, PROPAL_VALIDATE, ...) + * @param object Object action is done on + * @param user Object user + * @param langs Object langs + * @param conf Object conf + * @return int <0 if KO, 0 if no action are done, >0 if OK + */ + function run_trigger($action,$object,$user,$langs,$conf) + { + if (empty($conf->notification->enabled)) return 0; // Module not active, we do nothing + + require_once(DOL_DOCUMENT_ROOT .'/core/class/notify.class.php'); + + if ($action == 'BILL_VALIDATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + + $ref = dol_sanitizeFileName($object->ref); + $filepdf = $conf->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf'; + if (! file_exists($filepdf)) $filepdf=''; + $filepdf=''; // We can't add PDF as it is not generated yet. + $langs->load("other"); + $mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated",$object->ref); + + $notify = new Notify($this->db); + $notify->send($action, $object->socid, $mesg, 'facture', $object->id, $filepdf); + } + + elseif ($action == 'ORDER_VALIDATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + + $ref = dol_sanitizeFileName($object->ref); + $filepdf = $conf->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf'; + if (! file_exists($filepdf)) $filepdf=''; + $filepdf=''; // We can't add PDF as it is not generated yet. + $langs->load("other"); + $mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated",$object->ref); + + $notify = new Notify($this->db); + $notify->send($action, $object->socid, $mesg, 'order', $object->id, $filepdf); + } + + elseif ($action == 'PROPAL_VALIDATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + + $ref = dol_sanitizeFileName($object->ref); + $filepdf = $conf->propale->dir_output . '/' . $ref . '/' . $ref . '.pdf'; + if (! file_exists($filepdf)) $filepdf=''; + $filepdf=''; // We can't add PDF as it is not generated yet. + $langs->load("other"); + $mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated",$object->ref); + + $notify = new Notify($this->db); + $notify->send($action, $object->socid, $mesg, 'propal', $object->id, $filepdf); + } + + elseif ($action == 'FICHEINTER_VALIDATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + + $ref = dol_sanitizeFileName($object->ref); + $filepdf = $conf->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf'; + if (! file_exists($filepdf)) $filepdf=''; + $filepdf=''; // We can't add PDF as it is not generated yet. + $langs->load("other"); + $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated",$object->ref); + + $notify = new Notify($this->db); + $notify->send($action, $object->socid, $mesg, 'ficheinter', $object->id, $filepdf); + } + + elseif ($action == 'ORDER_SUPPLIER_APPROVE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + + $ref = dol_sanitizeFileName($object->ref); + $filepdf = $conf->fournisseur->dir_output . '/commande/' . $ref . '/' . $ref . '.pdf'; + if (! file_exists($filepdf)) $filepdf=''; + $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; + $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$object->ref,$user->getFullName($langs)); + $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; + + $notify = new Notify($this->db); + $notify->send($action, $object->socid, $mesg, 'order_supplier', $object->id, $filepdf); + } + + elseif ($action == 'ORDER_SUPPLIER_REFUSE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + + $ref = dol_sanitizeFileName($object->ref); + $filepdf = $conf->fournisseur->dir_output . '/commande/' . $ref . '/' . $ref . '.pdf'; + if (! file_exists($filepdf)) $filepdf=''; + $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; + $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy",$object->ref,$user->getFullName($langs)); + $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; + + $notify = new Notify($this->db); + $notify->send($action, $object->socid, $mesg, 'order_supplier', $object->id, $filepdf); + } + + // If not found +/* + else + { + dol_syslog("Trigger '".$this->name."' for action '$action' was ran by ".__FILE__." but no handler found for this action."); + return -1; + } +*/ + return 0; + } + + + /** + * Return list of events managed by notification module + * @return array Array of events managed by notification module + */ + function getListOfManagedEvents() + { + global $conf,$langs; + + $ret=array(); + + $sql = "SELECT rowid, code, label, description, elementtype"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_action_trigger"; + $sql.= $this->db->order("elementtype, code"); + dol_syslog("Get list of notifications sql=".$sql); + $resql=$this->db->query($sql); + if ($resql) + { + $num=$this->db->num_rows($resql); + $i=0; + while ($i < $num) + { + $obj=$this->db->fetch_object($resql); + + $qualified=0; + // Check is this event is supported by notification module + if (in_array($obj->code,$this->listofmanagedevents)) $qualified=1; + // Check if module for this event is active + if ($qualified) + { + //print 'xx'.$obj->code; + $element=$obj->elementtype; + if ($element == 'order_supplier' && empty($conf->fournisseur->enabled)) $qualified=0; + elseif ($element == 'invoice_supplier' && empty($conf->fournisseur->enabled)) $qualified=0; + elseif ($element == 'withdraw' && empty($conf->prelevement->enabled)) $qualified=0; + elseif ($element == 'shipping' && empty($conf->expedition->enabled)) $qualified=0; + elseif ($element == 'member' && empty($conf->adherent->enabled)) $qualified=0; + elseif (! in_array($element,array('order_supplier','invoice_supplier','withdraw','shipping','member')) + && empty($conf->$element->enabled)) $qualified=0; + } + + if ($qualified) + { + $ret[]=array('rowid'=>$obj->rowid,'code'=>$obj->code,'label'=>$obj->label,'description'=>$obj->description,'elementtype'=>$obj->elementtype); + } + + $i++; + } + } + else dol_print_error($this->db); + + return $ret; + } + +} +?> diff --git a/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN b/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN new file mode 100755 index 00000000000..7d28d98760f --- /dev/null +++ b/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN @@ -0,0 +1,527 @@ + + * Copyright (C) 2005-2011 Regis Houssin + * + * 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/triggers/interface_90_all_Demo.class.php + * \ingroup core + * \brief Fichier de demo de personalisation des actions du workflow + * \remarks Son propre fichier d'actions peut etre cree par recopie de celui-ci: + * - Le nom du fichier doit etre: interface_99_modMymodule_Mytrigger.class.php + * ou: interface_99_all_Mytrigger.class.php + * - Le fichier doit rester stocke dans core/triggers + * - Le nom de la classe doit etre InterfaceMytrigger + * - Le nom de la methode constructeur doit etre InterfaceMytrigger + * - Le nom de la propriete name doit etre Mytrigger + */ + + +/** + * \class InterfaceDemo + * \brief Class of triggers for demo module + */ +class InterfaceDemo +{ + var $db; + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + function InterfaceDemo($db) + { + $this->db = $db; + + $this->name = preg_replace('/^Interface/i','',get_class($this)); + $this->family = "demo"; + $this->description = "Triggers of this module are empty functions. They have no effect. They are provided for tutorial purpose only."; + $this->version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' or version + $this->picto = 'technic'; + } + + + /** + * Return name of trigger file + * @return string Name of trigger file + */ + function getName() + { + return $this->name; + } + + /** + * Return description of trigger file + * @return string Description of trigger file + */ + function getDesc() + { + return $this->description; + } + + /** + * Return version of trigger file + * @return string Version of trigger file + */ + function getVersion() + { + global $langs; + $langs->load("admin"); + + if ($this->version == 'development') return $langs->trans("Development"); + elseif ($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"); + } + + /** + * Function called when a Dolibarrr business event is done. + * All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers + * @param action Code de l'evenement + * @param object Objet concerne + * @param user Objet user + * @param langs Objet langs + * @param conf Objet conf + * @return int <0 if KO, 0 if no triggered ran, >0 if OK + */ + function run_trigger($action,$object,$user,$langs,$conf) + { + // Put here code you want to execute when a Dolibarr business events occurs. + // Data and type of action are stored into $object and $action + + // Users + if ($action == 'USER_LOGIN') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'USER_UPDATE_SESSION') + { + // Warning: To increase performances, this action is triggered only if + // constant MAIN_ACTIVATE_UPDATESESSIONTRIGGER is set to 1. + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'USER_CREATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'USER_CREATE_FROM_CONTACT') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'USER_MODIFY') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'USER_NEW_PASSWORD') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'USER_ENABLEDISABLE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'USER_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'USER_LOGOUT') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'USER_SETINGROUP') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'USER_REMOVEFROMGROUP') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + + // Groups + elseif ($action == 'GROUP_CREATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'GROUP_MODIFY') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'GROUP_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + + // Companies + elseif ($action == 'COMPANY_CREATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'COMPANY_MODIFY') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'COMPANY_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + + // Contacts + elseif ($action == 'CONTACT_CREATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'CONTACT_MODIFY') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'CONTACT_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + + // Products + elseif ($action == 'PRODUCT_CREATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'PRODUCT_MODIFY') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'PRODUCT_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + + // Customer orders + elseif ($action == 'ORDER_CREATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'ORDER_CLONE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'ORDER_VALIDATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'ORDER_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'ORDER_BUILDDOC') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'ORDER_SENTBYMAIL') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'LINEORDER_INSERT') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'LINEORDER_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + + // Supplier orders + elseif ($action == 'ORDER_SUPPLIER_CREATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'ORDER_SUPPLIER_VALIDATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'ORDER_SUPPLIER_SENTBYMAIL') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + + // Proposals + elseif ($action == 'PROPAL_CREATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'PROPAL_CLONE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'PROPAL_MODIFY') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'PROPAL_VALIDATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'PROPAL_BUILDDOC') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'PROPAL_SENTBYMAIL') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'PROPAL_CLOSE_SIGNED') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'PROPAL_CLOSE_REFUSED') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'PROPAL_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'LINEPROPAL_INSERT') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'LINEPROPAL_MODIFY') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'LINEPROPAL_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + + // Contracts + elseif ($action == 'CONTRACT_CREATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'CONTRACT_MODIFY') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'CONTRACT_ACTIVATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'CONTRACT_CANCEL') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'CONTRACT_CLOSE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'CONTRACT_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + + // Bills + elseif ($action == 'BILL_CREATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'BILL_CLONE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'BILL_MODIFY') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'BILL_VALIDATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'BILL_BUILDDOC') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'BILL_SENTBYMAIL') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'BILL_CANCEL') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'BILL_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'LINEBILL_INSERT') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'LINEBILL_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + + // Payments + elseif ($action == 'PAYMENT_CUSTOMER_CREATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'PAYMENT_SUPPLIER_CREATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'PAYMENT_ADD_TO_BANK') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'PAYMENT_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + + // Interventions + elseif ($action == 'FICHEINTER_VALIDATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + + // Members + elseif ($action == 'MEMBER_CREATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'MEMBER_VALIDATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'MEMBER_SUBSCRIPTION') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'MEMBER_MODIFY') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'MEMBER_NEW_PASSWORD') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'MEMBER_RESILIATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'MEMBER_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + + // Categories + elseif ($action == 'CATEGORY_CREATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'CATEGORY_MODIFY') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'CATEGORY_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + + // Projects + elseif ($action == 'PROJECT_CREATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'PROJECT_MODIFY') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'PROJECT_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + + // Project tasks + elseif ($action == 'TASK_CREATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'TASK_MODIFY') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'TASK_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + + // Task time spent + elseif ($action == 'TASK_TIMESPENT_CREATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'TASK_TIMESPENT_MODIFY') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'TASK_TIMESPENT_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + + // Shipping + elseif ($action == 'SHIPPING_CREATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'SHIPPING_MODIFY') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'SHIPPING_VALIDATE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'SHIPPING_SENTBYMAIL') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'SHIPPING_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'SHIPPING_BUILDDOC') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + + // File + elseif ($action == 'FILE_UPLOAD') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'FILE_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + + return 0; + } + +} +?>