2
0
forked from Wavyzz/dolibarr

New: Add trigger on enabled and disable user.

This commit is contained in:
Laurent Destailleur
2008-03-20 21:22:35 +00:00
parent cbec6ec2aa
commit d50b3ae380
7 changed files with 33 additions and 15 deletions

View File

@@ -44,7 +44,7 @@ $eventstolog=array(
array('id'=>'USER_CREATE', 'test'=>1), array('id'=>'USER_CREATE', 'test'=>1),
array('id'=>'USER_MODIFY', 'test'=>1), array('id'=>'USER_MODIFY', 'test'=>1),
array('id'=>'USER_NEW_PASSWORD', 'test'=>1), array('id'=>'USER_NEW_PASSWORD', 'test'=>1),
array('id'=>'USER_DISABLE', 'test'=>1), array('id'=>'USER_ENABLEDISABLE', 'test'=>1),
array('id'=>'USER_DELETE', 'test'=>1), array('id'=>'USER_DELETE', 'test'=>1),
array('id'=>'GROUP_CREATE', 'test'=>1), array('id'=>'GROUP_CREATE', 'test'=>1),
array('id'=>'GROUP_MODIFY', 'test'=>1), array('id'=>'GROUP_MODIFY', 'test'=>1),

View File

@@ -149,15 +149,23 @@ class InterfaceLogevents
$this->texte=$langs->transnoentities("NewUserPassword",$object->login); $this->texte=$langs->transnoentities("NewUserPassword",$object->login);
$this->desc=$langs->transnoentities("NewUserPassword",$object->login); $this->desc=$langs->transnoentities("NewUserPassword",$object->login);
} }
elseif ($action == 'USER_DISABLE') elseif ($action == 'USER_ENABLEDISABLE')
{ {
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
$langs->load("users"); $langs->load("users");
// Initialisation donnees (date,duree,texte,desc) // Initialisation donnees (date,duree,texte,desc)
$this->date=time(); $this->date=time();
$this->duree=0; $this->duree=0;
$this->texte=$langs->transnoentities("UserDisabled",$object->login); if ($object->statut == 0)
$this->desc=$langs->transnoentities("UserDisabled",$object->login); {
$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') elseif ($action == 'USER_DELETE')
{ {

View File

@@ -138,7 +138,7 @@ class InterfaceLdapsynchro
{ {
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
} }
elseif ($action == 'USER_DISABLE') elseif ($action == 'USER_ENABLEDISABLE')
{ {
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
} }

View File

@@ -90,6 +90,7 @@ NewUserCreated=User %s created
NewUserPassword=Password change for %s NewUserPassword=Password change for %s
EventUserModified=User %s modified EventUserModified=User %s modified
UserDisabled=User %s disabled UserDisabled=User %s disabled
UserEnabled=User %s activated
UserDeleted=User %s removed UserDeleted=User %s removed
NewGroupCreated=Group %s created NewGroupCreated=Group %s created
GroupModified=Group %s modified GroupModified=Group %s modified

View File

@@ -90,6 +90,7 @@ NewUserCreated=Cr
NewUserPassword=Changement mot de passe de %s NewUserPassword=Changement mot de passe de %s
EventUserModified=Modification utiliateur %s EventUserModified=Modification utiliateur %s
UserDisabled=D<>sactivation utilisateur %s UserDisabled=D<>sactivation utilisateur %s
UserEnabled=Activation utilisateur %s
UserDeleted=Suppression utilisateur %s UserDeleted=Suppression utilisateur %s
NewGroupCreated=Cr<43>ation groupe %s NewGroupCreated=Cr<43>ation groupe %s
GroupModified=Modification groupe %s GroupModified=Modification groupe %s

View File

@@ -585,7 +585,7 @@ class User extends CommonObject
/** /**
* \brief Change statut d'un utilisateur * \brief Change statut d'un utilisateur
* \return int <0 si ko, >0 si ok * \return int <0 si ko, >=0 si ok
*/ */
function setstatus($statut) function setstatus($statut)
{ {
@@ -593,6 +593,12 @@ class User extends CommonObject
$error=0; $error=0;
// Check parameters
if ($this->statut == $statut)
{
return 0;
}
$this->db->begin(); $this->db->begin();
// Desactive utilisateur // Desactive utilisateur
@@ -601,12 +607,13 @@ class User extends CommonObject
$sql.= " WHERE rowid = ".$this->id; $sql.= " WHERE rowid = ".$this->id;
$result = $this->db->query($sql); $result = $this->db->query($sql);
dolibarr_syslog("User::setstatus sql=".$sql);
if ($result) if ($result)
{ {
// Appel des triggers // Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
$interface=new Interfaces($this->db); $interface=new Interfaces($this->db);
$result=$interface->run_triggers('USER_DISABLE',$this,$user,$langs,$conf); $result=$interface->run_triggers('USER_ENABLEDISABLE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; } if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers // Fin appel triggers
} }
@@ -619,6 +626,7 @@ class User extends CommonObject
else else
{ {
$this->db->commit(); $this->db->commit();
$this->statut=$statut;
return 1; return 1;
} }
} }

View File

@@ -19,14 +19,12 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
*/ */
/** /**
\file htdocs/user/fiche.php \file htdocs/user/fiche.php
\brief Onglet user et permissions de la fiche utilisateur \brief Onglet user et permissions de la fiche utilisateur
\version $Revision$ \version $Id$
*/ */
require("./pre.inc.php"); require("./pre.inc.php");
@@ -52,7 +50,7 @@ if ($_GET["id"])
} }
if ($user->id <> $_GET["id"] && ! $canreadperms) if ($user->id <> $_GET["id"] && ! $canreadperms)
{ {
accessforbidden(); accessforbidden();
} }
$langs->load("users"); $langs->load("users");
@@ -84,10 +82,11 @@ if ($_POST["action"] == 'confirm_disable' && $_POST["confirm"] == "yes")
{ {
if ($_GET["id"] <> $user->id) if ($_GET["id"] <> $user->id)
{ {
$edituser = new User($db, $_GET["id"]); $edituser = new User($db);
$edituser->fetch($_GET["id"]); $edituser->id=$_GET["id"];
$edituser->fetch();
$edituser->setstatus(0); $edituser->setstatus(0);
Header("Location: ".DOL_URL_ROOT.'/user/fiche.php?id='.$_GET["id"]); Header("Location: ".DOL_URL_ROOT.'/user/fiche.php?id='.$_GET["id"]);
exit; exit;
} }
} }
@@ -96,7 +95,8 @@ if ($_POST["action"] == 'confirm_enable' && $_POST["confirm"] == "yes")
if ($_GET["id"] <> $user->id) if ($_GET["id"] <> $user->id)
{ {
$edituser = new User($db, $_GET["id"]); $edituser = new User($db, $_GET["id"]);
$edituser->fetch($_GET["id"]); $edituser->id=$_GET["id"];
$edituser->fetch();
$edituser->setstatus(1); $edituser->setstatus(1);
Header("Location: ".DOL_URL_ROOT.'/user/fiche.php?id='.$_GET["id"]); Header("Location: ".DOL_URL_ROOT.'/user/fiche.php?id='.$_GET["id"]);
exit; exit;