Activation des evenements de trigger USER_CREATE, USER_MODIFY et USER_DISABLE lors de la création, modification et désactivation d'un utilisateur Dolibarr.
This commit is contained in:
parent
fc2b946e93
commit
6430fa5238
@ -448,26 +448,39 @@ class Contrat
|
|||||||
// 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);
|
||||||
$interface->run_triggers('CONTRACT_CREATE',$this,$user,$lang,$conf);
|
$result=$interface->run_triggers('CONTRACT_CREATE',$this,$user,$lang,$conf);
|
||||||
|
if ($result < 0) $error++;
|
||||||
// Fin appel triggers
|
// Fin appel triggers
|
||||||
|
|
||||||
$this->db->commit();
|
if (! $error)
|
||||||
|
{
|
||||||
return $this->id;
|
$this->db->commit();
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->error=$interface->error;
|
||||||
|
dolibarr_syslog("Contrat::create - 30 - ".$this->error);
|
||||||
|
|
||||||
|
$this->db->rollback();
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->db->rollback();
|
$this->error="Failed to add contact";
|
||||||
|
dolibarr_syslog("Contrat::create - 20 - ".$this->error);
|
||||||
|
|
||||||
return -1;
|
$this->db->rollback();
|
||||||
|
return -2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->db->rollback();
|
|
||||||
|
|
||||||
dolibarr_syslog("Contrat::create - 10");
|
|
||||||
$this->error=$lang->trans("UnknownError: ".$this->db->error()." - sql=".$sql);
|
$this->error=$lang->trans("UnknownError: ".$this->db->error()." - sql=".$sql);
|
||||||
|
dolibarr_syslog("Contrat::create - 10 - ".$this->error);
|
||||||
|
|
||||||
|
$this->db->rollback();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -98,7 +98,7 @@ class box_bookmarks extends ModeleBoxes {
|
|||||||
{
|
{
|
||||||
if ($num==0 && $i==$num)
|
if ($num==0 && $i==$num)
|
||||||
{
|
{
|
||||||
$this->info_box_contents[$i][0] = array('align' => 'center','text'=>$langs->trans("NoRecordedBookmarks"));
|
$this->info_box_contents[$i][0] = array('align' => 'center','text'=>$langs->trans("NoRecordedBookmarks",DOL_URL_ROOT.'/bookmarks/liste.php'));
|
||||||
$this->info_box_contents[$i][1] = array('text'=>' ');
|
$this->info_box_contents[$i][1] = array('text'=>' ');
|
||||||
} else {
|
} else {
|
||||||
$this->info_box_contents[$i][0] = array('text'=>' ');
|
$this->info_box_contents[$i][0] = array('text'=>' ');
|
||||||
|
|||||||
@ -40,7 +40,7 @@
|
|||||||
|
|
||||||
class MenuLeft {
|
class MenuLeft {
|
||||||
|
|
||||||
var $require_top=array("eldy"); // Si doit etre en phase avec un gestionnaire de menu du haut particulier
|
var $require_top=array("eldy_backoffice"); // Si doit etre en phase avec un gestionnaire de menu du haut particulier
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -40,7 +40,7 @@
|
|||||||
|
|
||||||
class MenuLeft {
|
class MenuLeft {
|
||||||
|
|
||||||
var $require_top=array("eldy"); // Si doit etre en phase avec un gestionnaire de menu du haut particulier
|
var $require_top=array("eldy_frontoffice"); // Si doit etre en phase avec un gestionnaire de menu du haut particulier
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -107,7 +107,10 @@ class MenuLeft {
|
|||||||
/*
|
/*
|
||||||
* Menu HOME
|
* Menu HOME
|
||||||
*/
|
*/
|
||||||
if ($mainmenu == 'home') {
|
if ($mainmenu == 'home')
|
||||||
|
{
|
||||||
|
$newmenu->add(DOL_URL_ROOT.'/user/fiche.php?id='.$user->id.'&leftmenu=home', $langs->trans("MyAccount"));
|
||||||
|
|
||||||
if($user->admin)
|
if($user->admin)
|
||||||
{
|
{
|
||||||
$langs->load("admin");
|
$langs->load("admin");
|
||||||
@ -137,12 +140,6 @@ class MenuLeft {
|
|||||||
if ($leftmenu=="system") $newmenu->add_submenu(DOL_URL_ROOT."/admin/system/database-tables-contraintes.php", $langs->trans("Constraints"),2);
|
if ($leftmenu=="system") $newmenu->add_submenu(DOL_URL_ROOT."/admin/system/database-tables-contraintes.php", $langs->trans("Constraints"),2);
|
||||||
}
|
}
|
||||||
|
|
||||||
$langs->load("users");
|
|
||||||
$newmenu->add(DOL_URL_ROOT."/user/home.php?leftmenu=users", $langs->trans("MenuUsersAndGroups"));
|
|
||||||
if ($leftmenu=="users") $newmenu->add_submenu(DOL_URL_ROOT."/user/index.php", $langs->trans("Users"));
|
|
||||||
if ($leftmenu=="users") $newmenu->add_submenu(DOL_URL_ROOT."/user/fiche.php?action=create", $langs->trans("NewUser"),2);
|
|
||||||
if ($leftmenu=="users") $newmenu->add_submenu(DOL_URL_ROOT."/user/group/index.php", $langs->trans("Groups"));
|
|
||||||
if ($leftmenu=="users") $newmenu->add_submenu(DOL_URL_ROOT."/user/group/fiche.php?action=create", $langs->trans("NewGroup"),2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@ -40,8 +40,8 @@
|
|||||||
|
|
||||||
class MenuTop {
|
class MenuTop {
|
||||||
|
|
||||||
var $require_left=array("eldy"); // Si doit etre en phase avec un gestionnaire de menu gauche particulier
|
var $require_left=array("eldy_backoffice"); // Si doit etre en phase avec un gestionnaire de menu gauche particulier
|
||||||
var $atarget=""; // Valeur du target a utiliser dans les liens
|
var $atarget=""; // Valeur du target a utiliser dans les liens
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -40,8 +40,8 @@
|
|||||||
|
|
||||||
class MenuTop {
|
class MenuTop {
|
||||||
|
|
||||||
var $require_left=array("eldy"); // Si doit etre en phase avec un gestionnaire de menu gauche particulier
|
var $require_left=array("eldy_frontoffice"); // Si doit etre en phase avec un gestionnaire de menu gauche particulier
|
||||||
var $atarget=""; // Valeur du target a utiliser dans les liens
|
var $atarget=""; // Valeur du target a utiliser dans les liens
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -17,7 +17,6 @@
|
|||||||
*
|
*
|
||||||
* $Id$
|
* $Id$
|
||||||
* $Source$
|
* $Source$
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -102,8 +101,21 @@ class InterfaceDemo
|
|||||||
// Mettre ici le code à exécuter en réaction de l'action
|
// Mettre ici le code à exécuter en réaction de l'action
|
||||||
// Les données de l'action sont stockées dans $object
|
// Les données de l'action sont stockées dans $object
|
||||||
|
|
||||||
|
// Users
|
||||||
|
if ($action == 'USER_CREATE')
|
||||||
|
{
|
||||||
|
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id);
|
||||||
|
}
|
||||||
|
elseif ($action == 'USER_MODIFY')
|
||||||
|
{
|
||||||
|
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id);
|
||||||
|
}
|
||||||
|
elseif ($action == 'USER_DISABLE')
|
||||||
|
{
|
||||||
|
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id);
|
||||||
|
}
|
||||||
// Companies
|
// Companies
|
||||||
if ($action == 'COMPANY_CREATE')
|
elseif ($action == 'COMPANY_CREATE')
|
||||||
{
|
{
|
||||||
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id);
|
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched. id=".$object->id);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -70,5 +70,5 @@ MailingNeedCommand=Pour des raisons de s
|
|||||||
TargetsReset=Vider liste
|
TargetsReset=Vider liste
|
||||||
ToClearAllRecipientsClickHere=Pour effacer la liste des destinataires de ce mailing, cliquer ici
|
ToClearAllRecipientsClickHere=Pour effacer la liste des destinataires de ce mailing, cliquer ici
|
||||||
ToAddRecipientsChooseHere=Pour ajouter des destinataires, choisir dans les listes ci-dessous
|
ToAddRecipientsChooseHere=Pour ajouter des destinataires, choisir dans les listes ci-dessous
|
||||||
NbOfEMailingsReceived=Nb de mailings de masse reçus
|
NbOfEMailingsReceived=Mailings de masse reçus
|
||||||
IdRecord=ID enregistrement
|
IdRecord=ID enregistrement
|
||||||
@ -483,24 +483,44 @@ class User
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Désactive un utilisateur
|
* \brief Désactive un utilisateur
|
||||||
*/
|
* \return int <0 si ko, >0 si ok
|
||||||
|
*/
|
||||||
function disable()
|
function disable()
|
||||||
{
|
{
|
||||||
|
$error=0;
|
||||||
|
|
||||||
// Désactive utilisateur
|
// Désactive utilisateur
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."user";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."user";
|
||||||
$sql.= " SET login = NULL";
|
$sql.= " SET login = NULL";
|
||||||
$sql.= " WHERE rowid = ".$this->id;
|
$sql.= " WHERE rowid = ".$this->id;
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
|
|
||||||
|
if ($result)
|
||||||
|
{
|
||||||
|
// Appel des triggers
|
||||||
|
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
|
||||||
|
$interface=new Interfaces($this->db);
|
||||||
|
$result=$interface->run_triggers('USER_DISABLE',$this,$user,$lang,$conf);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// Fin appel triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($error)
|
||||||
|
{
|
||||||
|
return -$error;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Supprime complètement un utilisateur
|
* \brief Supprime complètement un utilisateur
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function delete()
|
function delete()
|
||||||
{
|
{
|
||||||
// Supprime droits
|
// Supprime droits
|
||||||
@ -526,22 +546,23 @@ class User
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Crée un utilisateur en base
|
* \brief Crée un utilisateur en base
|
||||||
* \return si erreur <0, si ok renvoie id compte créé
|
* \return int si erreur <0, si ok renvoie id compte créé
|
||||||
*/
|
*/
|
||||||
|
function create()
|
||||||
function create()
|
|
||||||
{
|
{
|
||||||
global $langs;
|
global $langs;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = "SELECT login FROM ".MAIN_DB_PREFIX."user WHERE login ='".$this->login."';";
|
$sql = "SELECT login FROM ".MAIN_DB_PREFIX."user WHERE login ='".$this->login."';";
|
||||||
$result=$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
if ($result)
|
if ($resql)
|
||||||
{
|
{
|
||||||
$num = $this->db->num_rows($result);
|
$num = $this->db->num_rows($resql);
|
||||||
$this->db->free($result);
|
$this->db->free($resql);
|
||||||
|
|
||||||
if ($num)
|
if ($num)
|
||||||
{
|
{
|
||||||
$this->error = $langs->trans("ErrorLoginAlreadyExists");
|
$this->error = $langs->trans("ErrorLoginAlreadyExists");
|
||||||
@ -549,94 +570,139 @@ class User
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."user (datec,login,email) VALUES(now(),'$this->login','$this->email');";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."user (datec,login) VALUES(now(),'$this->login');";
|
||||||
$result=$this->db->query($sql);
|
$result=$this->db->query($sql);
|
||||||
|
|
||||||
if ($result)
|
if ($result)
|
||||||
{
|
{
|
||||||
$table = "".MAIN_DB_PREFIX."user";
|
$table = "".MAIN_DB_PREFIX."user";
|
||||||
$this->id = $this->db->last_insert_id($table);
|
$this->id = $this->db->last_insert_id($table);
|
||||||
|
|
||||||
if ($this->set_default_rights() < 0) return -4;
|
// Set default rights
|
||||||
|
if ($this->set_default_rights() < 0)
|
||||||
if ($this->update() < 0) return -3;
|
{
|
||||||
|
$this->db->rollback();
|
||||||
return $this->id;
|
|
||||||
|
$this->error=$this->db->error();
|
||||||
|
return -4;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update minor fields
|
||||||
|
if ($this->update() < 0)
|
||||||
|
{
|
||||||
|
$this->db->rollback();
|
||||||
|
|
||||||
|
$this->error=$this->db->error();
|
||||||
|
return -5;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Appel des triggers
|
||||||
|
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
|
||||||
|
$interface=new Interfaces($this->db);
|
||||||
|
$result=$interface->run_triggers('USER_CREATE',$this,$user,$lang,$conf);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// Fin appel triggers
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$this->db->commit();
|
||||||
|
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->db->rollback();
|
||||||
|
|
||||||
|
$this->error=$interface->error;
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dolibarr_print_error($this->db);
|
$this->db->rollback();
|
||||||
|
$this->error=$this->db->error();
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dolibarr_print_error($this->db);
|
$this->db->rollback();
|
||||||
|
$this->error=$this->db->error();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Créé en base un utilisateur depuis l'objetc contact
|
/**
|
||||||
* \param contact Objet du contact source
|
* \brief Créé en base un utilisateur depuis l'objet contact
|
||||||
*
|
* \param contact Objet du contact source
|
||||||
*/
|
* \return int si erreur <0, si ok renvoie id compte créé
|
||||||
|
*/
|
||||||
function create_from_contact($contact)
|
function create_from_contact($contact)
|
||||||
{
|
{
|
||||||
global $langs;
|
global $langs;
|
||||||
|
|
||||||
|
// Positionne paramètres
|
||||||
|
$this->nom = $contact->nom;
|
||||||
|
$this->prenom = $contact->prenom;
|
||||||
|
|
||||||
|
$this->login = strtolower(substr($contact->prenom, 0, 3)) . strtolower(substr($contact->nom, 0, 3));
|
||||||
|
$this->admin = 0;
|
||||||
|
|
||||||
|
$this->email = $contact->email;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
|
// Crée et positionne $this->id
|
||||||
|
$result=$this->create();
|
||||||
|
|
||||||
$this->nom = $contact->nom;
|
if ($result > 0)
|
||||||
$this->prenom = $contact->prenom;
|
{
|
||||||
$this->email = $contact->email;
|
$sql = "UPDATE ".MAIN_DB_PREFIX."user";
|
||||||
|
$sql.= " SET fk_socpeople=".$contact->id.", fk_societe=".$contact->societeid;
|
||||||
|
$sql.= " WHERE rowid=".$this->id;
|
||||||
|
$resql=$this->db->query($sql);
|
||||||
|
|
||||||
$this->login = strtolower(substr($contact->prenom, 0, 3)) . strtolower(substr($contact->nom, 0, 3));
|
if ($resql)
|
||||||
|
{
|
||||||
|
$sql = "UPDATE ".MAIN_DB_PREFIX."socpeople";
|
||||||
|
$sql.= " SET fk_user = ".$this->id;
|
||||||
|
$sql.= " WHERE idp = ".$contact->id;
|
||||||
|
$resql=$this->db->query($sql);
|
||||||
|
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
$this->db->commit();
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->error=$this->db->error()." - $sql";
|
||||||
|
dolibarr_syslog("User::create_from_contact - 20 - ".$this->error);
|
||||||
|
|
||||||
$sql = "SELECT login FROM ".MAIN_DB_PREFIX."user WHERE login ='$this->login'";
|
$this->db->rollback();
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->error=$this->db->error()." - $sql";
|
||||||
|
dolibarr_syslog("User::create_from_contact - 10 - ".$this->error);
|
||||||
|
|
||||||
if ($this->db->query($sql))
|
$this->db->rollback();
|
||||||
{
|
return -1;
|
||||||
$num = $this->db->num_rows();
|
}
|
||||||
$this->db->free();
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// $this->error deja positionné
|
||||||
|
dolibarr_syslog("User::create_from_contact - 0");
|
||||||
|
|
||||||
if ($num)
|
$this->db->rollback();
|
||||||
{
|
return $result;
|
||||||
$this->error = $langs->trans("ErrorLoginAlreadyExists");
|
}
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."user (datec, login, fk_socpeople, fk_societe)";
|
|
||||||
$sql .= " VALUES (now(),'$this->login',$contact->id, $contact->societeid);";
|
|
||||||
if ($this->db->query($sql))
|
|
||||||
{
|
|
||||||
if ($this->db->affected_rows())
|
|
||||||
{
|
|
||||||
$table = "".MAIN_DB_PREFIX."user";
|
|
||||||
$this->id = $this->db->last_insert_id($table);
|
|
||||||
$this->admin = 0;
|
|
||||||
$this->update();
|
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET fk_user = $this->id WHERE idp = $contact->id";
|
|
||||||
$this->db->query($sql);
|
|
||||||
|
|
||||||
$this->set_default_rights();
|
|
||||||
|
|
||||||
return $this->id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dolibarr_print_error($this->db);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dolibarr_print_error($this->db);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -679,12 +745,15 @@ class User
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Mise à jour en base d'un utilisateur
|
* \brief Mise à jour en base d'un utilisateur
|
||||||
* \return <0 si echec, >=0 si ok
|
* \param create 1 si update durant le create, 0 sinon
|
||||||
|
* \return int <0 si echec, >=0 si ok
|
||||||
*/
|
*/
|
||||||
function update()
|
function update($create=0)
|
||||||
{
|
{
|
||||||
global $langs;
|
global $langs;
|
||||||
|
|
||||||
|
$error=0;
|
||||||
|
|
||||||
if (!strlen($this->code)) $this->code = $this->login;
|
if (!strlen($this->code)) $this->code = $this->login;
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."user SET ";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."user SET ";
|
||||||
@ -707,6 +776,16 @@ class User
|
|||||||
{
|
{
|
||||||
if ($this->db->affected_rows())
|
if ($this->db->affected_rows())
|
||||||
{
|
{
|
||||||
|
if (! $create)
|
||||||
|
{
|
||||||
|
// Appel des triggers
|
||||||
|
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
|
||||||
|
$interface=new Interfaces($this->db);
|
||||||
|
$result=$interface->run_triggers('USER_MODIFY',$this,$user,$lang,$conf);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// Fin appel triggers
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user