From d6497ab90ccea5972cea8e58ded2adf8981dd4c8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 17 Mar 2008 14:59:34 +0000 Subject: [PATCH] New: Added USER_LOGIN trigger event --- htdocs/admin/events.php | 12 ++ ...php => interface_all_Demo.class.php-NORUN} | 25 ++++- .../interface_all_Logevents.class.php | 104 +++++++++++++++++- htdocs/main.inc.php | 20 ++++ htdocs/user.class.php | 2 + 5 files changed, 158 insertions(+), 5 deletions(-) rename htdocs/includes/triggers/{interface_all_Demo.class.php => interface_all_Demo.class.php-NORUN} (93%) diff --git a/htdocs/admin/events.php b/htdocs/admin/events.php index ec39d02d6df..2e036410a0b 100644 --- a/htdocs/admin/events.php +++ b/htdocs/admin/events.php @@ -37,7 +37,18 @@ $langs->load("other"); $action=$_POST["action"]; + +// List of all events supported by triggers $eventstolog=array( + array('id'=>'USER_LOGIN', 'test'=>1), + array('id'=>'USER_CREATE', 'test'=>1), + array('id'=>'USER_MODIFY', 'test'=>1), + array('id'=>'USER_NEW_PASSWORD', 'test'=>1), + array('id'=>'USER_DISABLE', 'test'=>1), + array('id'=>'USER_DELETE', 'test'=>1), + array('id'=>'GROUP_CREATE', 'test'=>1), + array('id'=>'GROUP_MODIFY', 'test'=>1), + array('id'=>'GROUP_DELETE', 'test'=>1), array('id'=>'ACTION_CREATE', 'test'=>$conf->societe->enabled), array('id'=>'COMPANY_CREATE', 'test'=>$conf->societe->enabled), array('id'=>'CONTRACT_VALIDATE', 'test'=>$conf->contrat->enabled), @@ -51,6 +62,7 @@ $eventstolog=array( array('id'=>'BILL_CANCELED', 'test'=>$conf->facture->enabled), array('id'=>'PAYMENT_CUSTOMER_CREATE','test'=>$conf->facture->enabled), array('id'=>'PAYMENT_SUPPLIER_CREATE','test'=>$conf->fournisseur->enabled), + array('id'=>'MEMBER_CREATE', 'test'=>$conf->adherent->enabled), array('id'=>'MEMBER_VALIDATE', 'test'=>$conf->adherent->enabled), array('id'=>'MEMBER_SUBSCRIPTION', 'test'=>$conf->adherent->enabled), array('id'=>'MEMBER_MODIFY', 'test'=>$conf->adherent->enabled), diff --git a/htdocs/includes/triggers/interface_all_Demo.class.php b/htdocs/includes/triggers/interface_all_Demo.class.php-NORUN similarity index 93% rename from htdocs/includes/triggers/interface_all_Demo.class.php rename to htdocs/includes/triggers/interface_all_Demo.class.php-NORUN index 321a317ca7d..d537b5ca4c9 100644 --- a/htdocs/includes/triggers/interface_all_Demo.class.php +++ b/htdocs/includes/triggers/interface_all_Demo.class.php-NORUN @@ -1,5 +1,5 @@ +/* Copyright (C) 2005-2008 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 @@ -14,8 +14,6 @@ * 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$ */ /** @@ -29,6 +27,7 @@ - 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 + \version $Id$ */ @@ -104,7 +103,11 @@ class InterfaceDemo // Les données de l'action sont stockées dans $object // Users - if ($action == 'USER_CREATE') + if ($action == 'USER_LOGIN') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'USER_CREATE') { dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); } @@ -125,6 +128,20 @@ class InterfaceDemo dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); } + // Groups + elseif ($action == 'GROUP_CREATE') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'GROUP_MODIFY') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'GROUP_DELETE') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + // Companies elseif ($action == 'COMPANY_CREATE') { diff --git a/htdocs/includes/triggers/interface_all_Logevents.class.php b/htdocs/includes/triggers/interface_all_Logevents.class.php index 89c17043352..18453e0fe7a 100644 --- a/htdocs/includes/triggers/interface_all_Logevents.class.php +++ b/htdocs/includes/triggers/interface_all_Logevents.class.php @@ -105,6 +105,104 @@ class InterfaceLogevents if (empty($conf->global->$key)) return 0; // Log events not enabled for this action // Actions + if ($action == 'USER_LOGIN') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("users"); + + // Initialisation donnees (date,duree,texte,desc) + $this->date=time(); + $this->duree=0; + $this->texte=$langs->transnoentities("UserLogged",$object->nom); + $this->desc=$langs->transnoentities("UserLogged",$object->nom); + } + if ($action == 'USER_CREATE') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("users"); + + // Initialisation donnees (date,duree,texte,desc) + $this->date=time(); + $this->duree=0; + $this->texte=$langs->transnoentities("NewUserCreated",$object->nom); + $this->desc=$langs->transnoentities("NewUserCreated",$object->nom); + } + elseif ($action == 'USER_MODIFY') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("users"); + + // Initialisation donnees (date,duree,texte,desc) + $this->date=time(); + $this->duree=0; + $this->texte=$langs->transnoentities("UserModified",$object->nom); + $this->desc=$langs->transnoentities("UserModified",$object->nom); + } + elseif ($action == 'USER_NEW_PASSWORD') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("users"); + + // Initialisation donnees (date,duree,texte,desc) + $this->date=time(); + $this->duree=0; + $this->texte=$langs->transnoentities("NewUserPassword",$object->nom); + $this->desc=$langs->transnoentities("NewUserPassword",$object->nom); + } + elseif ($action == 'USER_DISABLE') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("users"); + // Initialisation donnees (date,duree,texte,desc) + $this->date=time(); + $this->duree=0; + $this->texte=$langs->transnoentities("UserDisabled",$object->nom); + $this->desc=$langs->transnoentities("UserDisabled",$object->nom); + } + elseif ($action == 'USER_DELETE') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("users"); + // Initialisation donnees (date,duree,texte,desc) + $this->date=time(); + $this->duree=0; + $this->texte=$langs->transnoentities("UserDeleted",$object->nom); + $this->desc=$langs->transnoentities("Userdeleted",$object->nom); + } + + // Groupes + elseif ($action == 'GROUP_CREATE') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("users"); + // Initialisation donnees (date,duree,texte,desc) + $this->date=time(); + $this->duree=0; + $this->texte=$langs->transnoentities("NewGroupCreated",$object->nom); + $this->desc=$langs->transnoentities("NewGroupCreated",$object->nom); + } + elseif ($action == 'GROUP_MODIFY') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("users"); + // Initialisation donnees (date,duree,texte,desc) + $this->date=time(); + $this->duree=0; + $this->texte=$langs->transnoentities("GroupModified",$object->nom); + $this->desc=$langs->transnoentities("GroupModified",$object->nom); + } + elseif ($action == 'GROUP_DELETE') + { + dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("users"); + // Initialisation donnees (date,duree,texte,desc) + $this->date=time(); + $this->duree=0; + $this->texte=$langs->transnoentities("GroupDeleted",$object->nom); + $this->desc=$langs->transnoentities("GroupDeleted",$object->nom); + } + + // Actions if ($action == 'ACTION_CREATE') { dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); @@ -285,6 +383,10 @@ class InterfaceLogevents // Members elseif ($action == 'MEMBER_CREATE') { + $this->date=time(); + $this->duree=0; + $this->texte=$langs->transnoentities("NewMemberCreated",$object->id); + $this->desc=$langs->transnoentities("NewMemberCreated",$object->id); } elseif ($action == 'MEMBER_VALIDATE') { @@ -368,7 +470,7 @@ class InterfaceLogevents } */ - // Ajoute entree dans webcal + // Add entry in event table if ($this->date) { include_once(DOL_DOCUMENT_ROOT.'/core/events.class.php'); diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index f3e96ee2ef4..3a0e517a62b 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -244,7 +244,27 @@ if (! isset($_SESSION["dol_login"])) $_SESSION["dol_login"]=$user->login; $_SESSION["dol_password"]=$user->pass_crypted; dolibarr_syslog("This is a new started user session. _SESSION['dol_login']=".$_SESSION["dol_login"].' Session id='.session_id()); + + $db->begin(); + $user->update_last_login_date(); + + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); + $interface=new Interfaces($db); + $result=$interface->run_triggers('USER_LOGIN',$user,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + + if ($error) + { + dolibarr_print_errors($db,$this->errors); + $db->rollback(); + } + else + { + $db->commit(); + } // Module webcalendar if ($conf->webcal->enabled && $user->webcal_login != "") diff --git a/htdocs/user.class.php b/htdocs/user.class.php index fe68e98fc29..94616364d9d 100644 --- a/htdocs/user.class.php +++ b/htdocs/user.class.php @@ -589,6 +589,8 @@ class User extends CommonObject */ function setstatus($statut) { + global $conf,$langs,$user; + $error=0; $this->db->begin();