New: Added USER_LOGIN trigger event

This commit is contained in:
Laurent Destailleur 2008-03-17 14:59:34 +00:00
parent e4db6dc21d
commit d6497ab90c
5 changed files with 158 additions and 5 deletions

View File

@ -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),

View File

@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2005-2007 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2005-2008 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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')
{

View File

@ -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');

View File

@ -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 != "")

View File

@ -589,6 +589,8 @@ class User extends CommonObject
*/
function setstatus($statut)
{
global $conf,$langs,$user;
$error=0;
$this->db->begin();