Feature: Synchro user depuis fiche adherent

Qual: Deplacement fonction trigger dans core.
This commit is contained in:
Laurent Destailleur 2007-09-09 20:10:20 +00:00
parent ba5c56f6db
commit 1331b29a29
10 changed files with 209 additions and 258 deletions

View File

@ -370,7 +370,7 @@ class Adherent
$this->id=$id;
// Mise a jour
$result=$this->update($user,1);
$result=$this->update($user,1,1);
if ($result < 0)
{
$this->db->rollback();
@ -445,13 +445,15 @@ class Adherent
\brief Fonction qui met à jour l'adhérent
\param user Utilisateur qui réalise la mise a jour
\param notrigger 1=désactive le trigger UPDATE (quand appelé par creation)
\param nosyncuser Do not synchronize linked user
\return int <0 si KO, >0 si OK
*/
function update($user,$notrigger=0)
function update($user,$notrigger=0,$nosyncuser=0)
{
global $conf,$langs;
dolibarr_syslog("Adherent::update user->id=".$user->id.", notrigger=".$notrigger);
$error=0;
dolibarr_syslog("Adherent::update notrigger=".$notrigger.", nosyncuser=".$nosyncuser);
// Verification parametres
if ($conf->global->ADHERENT_MAIL_REQUIRED && ! ValidEMail($this->email))
@ -463,36 +465,37 @@ class Adherent
$this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
$sql .= " prenom = ".($this->prenom?"'".addslashes($this->prenom)."'":"null");
$sql .= ",nom=" .($this->nom?"'".addslashes($this->nom)."'":"null");
$sql .= ",login=" .($this->login?"'".addslashes($this->login)."'":"null");
$sql .= ",pass=" .($this->pass?"'".addslashes($this->pass)."'":"null");
$sql .= ",societe=" .($this->societe?"'".addslashes($this->societe)."'":"null");
$sql .= ",adresse=" .($this->adresse?"'".addslashes($this->adresse)."'":"null");
$sql .= ",cp=" .($this->cp?"'".addslashes($this->cp)."'":"null");
$sql .= ",ville=" .($this->ville?"'".addslashes($this->ville)."'":"null");
$sql .= ",pays=" ."'".$this->pays_id."'";
$sql .= ",email=" ."'".$this->email."'";
$sql .= ",phone=" .($this->phone?"'".addslashes($this->phone)."'":"null");
$sql .= ",phone_perso=" .($this->phone_perso?"'".addslashes($this->phone_perso)."'":"null");
$sql .= ",phone_mobile=" .($this->phone_mobile?"'".addslashes($this->phone_mobile)."'":"null");
$sql .= ",note=" .($this->commentaire?"'".addslashes($this->commentaire)."'":"null");
$sql .= ",photo=" .($this->photo?"'".$this->photo."'":"null");
$sql .= ",public=" ."'".$this->public."'";
$sql .= ",statut=" .$this->statut;
$sql .= ",fk_adherent_type=".$this->typeid;
$sql .= ",morphy=" ."'".$this->morphy."'";
$sql .= ",naiss=" .($this->naiss?"'".$this->db->idate($this->naiss)."'":"null");
if ($this->datefin) $sql .= ",datefin='".$this->db->idate($this->datefin)."'"; // Ne doit etre modifié que par effacement cotisation
if ($this->datevalid) $sql .= ",datevalid='".$this->db->idate($this->datevalid)."'"; // Ne doit etre modifié que par validation adherent
$sql.= " prenom = ".($this->prenom?"'".addslashes($this->prenom)."'":"null");
$sql.= ",nom=" .($this->nom?"'".addslashes($this->nom)."'":"null");
$sql.= ",login=" .($this->login?"'".addslashes($this->login)."'":"null");
$sql.= ",pass=" .($this->pass?"'".addslashes($this->pass)."'":"null");
$sql.= ",societe=" .($this->societe?"'".addslashes($this->societe)."'":"null");
$sql.= ",adresse=" .($this->adresse?"'".addslashes($this->adresse)."'":"null");
$sql.= ",cp=" .($this->cp?"'".addslashes($this->cp)."'":"null");
$sql.= ",ville=" .($this->ville?"'".addslashes($this->ville)."'":"null");
$sql.= ",pays=" ."'".$this->pays_id."'";
$sql.= ",email=" ."'".$this->email."'";
$sql.= ",phone=" .($this->phone?"'".addslashes($this->phone)."'":"null");
$sql.= ",phone_perso=" .($this->phone_perso?"'".addslashes($this->phone_perso)."'":"null");
$sql.= ",phone_mobile=" .($this->phone_mobile?"'".addslashes($this->phone_mobile)."'":"null");
$sql.= ",note=" .($this->commentaire?"'".addslashes($this->commentaire)."'":"null");
$sql.= ",photo=" .($this->photo?"'".$this->photo."'":"null");
$sql.= ",public=" ."'".$this->public."'";
$sql.= ",statut=" .$this->statut;
$sql.= ",fk_adherent_type=".$this->typeid;
$sql.= ",morphy=" ."'".$this->morphy."'";
$sql.= ",naiss=" .($this->naiss?"'".$this->db->idate($this->naiss)."'":"null");
if ($this->datefin) $sql.= ",datefin='".$this->db->idate($this->datefin)."'"; // Ne doit etre modifié que par effacement cotisation
if ($this->datevalid) $sql.= ",datevalid='".$this->db->idate($this->datevalid)."'"; // Ne doit etre modifié que par validation adherent
$sql .= " WHERE rowid = ".$this->id;
$sql.= " WHERE rowid = ".$this->id;
dolibarr_syslog("Adherent::update sql=".$sql);
$result = $this->db->query($sql);
if (! $result)
{
$this->error=$this->db->error();
dolibarr_syslog("Adherent::update ".$this->error,LOG_ERROR);
$this->db->rollback();
return -1;
}
@ -500,6 +503,7 @@ class Adherent
if (sizeof($this->array_options) > 0)
{
$sql_del = "DELETE FROM ".MAIN_DB_PREFIX."adherent_options WHERE adhid = ".$this->id;
dolibarr_syslog("Adherent::update sql=".$sql_del);
$this->db->query($sql_del);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent_options (adhid";
@ -516,19 +520,59 @@ class Adherent
}
$sql.=")";
dolibarr_syslog("Adherent::update sql=".$sql);
$result = $this->db->query($sql);
if (! $result)
{
$this->error=$this->db->error();
dolibarr_syslog("Adherent::update ".$this->error);
dolibarr_syslog("Adherent::update ".$this->error,LOG_ERROR);
$this->db->rollback();
return -2;
}
}
if ($this->user_id && ! $nosyncuser)
{
// This member is linked with a user, so we also update users informations
// if this is an update.
$luser=new User($this->db);
$luser->id=$this->user_id;
$result=$luser->fetch();
if ($result >= 0)
{
$luser->prenom=$this->prenom;
$luser->nom=$this->nom;
$luser->login=$this->user_login;
$luser->pass=$this->pass;
$luser->societe_id=$this->societe;
$luser->email=$this->email;
$luser->office_phone=$this->phone;
$luser->user_mobile=$this->phone_mobile;
$luser->note=$this->commentaire;
$luser->fk_member=$this->id;
$result=$luser->update($user,0,1);
if ($result < 0)
{
$this->error=$luser->error;
dolibarr_syslog("Adherent::update ".$this->error,LOG_ERROR);
$error++;
}
}
else
{
$this->error=$luser->error;
$error++;
}
}
$this->fullname=trim($this->nom.' '.$this->prenom);
if (! $notrigger)
if (! $error && ! $notrigger)
{
$this->use_webcal=($conf->global->PHPWEBCALENDAR_MEMBERSTATUS=='always'?1:0);
@ -540,7 +584,14 @@ class Adherent
// Fin appel triggers
}
$this->db->commit();
if (! $error)
{
$this->db->commit();
}
else
{
$this->db->rollback();
}
return 1;
}

View File

@ -506,7 +506,7 @@ class Fichinter extends CommonObject
}
}
dolibarr_syslog("Suppression de la fiche intervention $this->id par $user->fullname ($user->id)");
dolibarr_syslog("Suppression de la fiche intervention $this->id par $user->id");
return 1;
}
else

View File

@ -1,122 +0,0 @@
<?php
/* Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*/
/**
\file htdocs/includes/triggers/interface_user.class.php
\ingroup stock
\brief Fichier des actions du workflow de stock utilisateurs
\remarks Son propre fichier d'actions peut etre créé par recopie de celui-ci:
- Le nom du fichier doit etre interface_xxx.class.php
- Le fichier doit rester stocké dans includes/triggers
- Le nom de la classe doit etre InterfaceXxx
*/
/**
\class InterfaceUser
\brief Classe des fonctions triggers des actions personalisées du workflow
*/
class InterfaceUser
{
var $db;
var $error;
/**
* \brief Constructeur.
* \param DB Handler d'accès base
*/
function InterfaceUser($DB)
{
$this->db = $DB ;
$this->name = "User";
$this->family = "user";
$this->description = "Les triggers de ce composant s'appliquent sur les utilisateurs gérant des stocks.";
$this->revision = explode(' ','$Revision$');
$this->version = $this->revision[1];
}
/**
* \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 == 'experimental') return $langs->trans("Experimental");
elseif ($this->version == 'dolibarr') return DOL_VERSION;
elseif ($this->version) return $this->version;
else return $langs->trans("Unknown");
}
/**
* \brief Fonction appelée lors du déclenchement d'un évènement Dolibarr.
* D'autres fonctions run_trigger peuvent etre présentes dans includes/triggers
* \param action Code de l'evenement
* \param object Objet concern
* \param user Objet user
* \param lang Objet lang
* \param conf Objet conf
* \return int <0 si ko, 0 si aucune action faite, >0 si ok
*/
function run_trigger($action,$object,$user,$langs,$conf)
{
// Users
if ($action == 'USER_CREATE')
{
dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
if ($conf->global->STOCK_USERSTOCK == 1 && $conf->global->STOCK_USERSTOCK_AUTOCREATE == 1)
{
require_once(DOL_DOCUMENT_ROOT."/product/stock/entrepot.class.php");
$entrepot = new Entrepot($this->db);
$entrepot->libelle = 'Stock Personnel '.$object->nom;
$entrepot->description = 'Cet entrepot représente le stock personnel de '.$object->prenom.' '.$object->nom;
$entrepot->statut = 1;
$entrepot->create($user);
}
}
return 0;
}
}
?>

View File

@ -388,7 +388,7 @@ if (! session_id() || ! isset($_SESSION["dol_login"]))
if ($user->login != $ldap->login && $ldap->login)
{
$user->login = $ldap->login;
$user->update();
$user->update($user);
}
//$resultUpdate = $user->update_ldap2dolibarr();
}

View File

@ -1562,7 +1562,7 @@ class Propal extends CommonObject
}
}
dolibarr_syslog("Suppression de la proposition $this->id par $user->fullname ($user->id)");
dolibarr_syslog("Suppression de la proposition $this->id par $user->id");
return 1;
}
else

View File

@ -656,59 +656,69 @@ class User
* \param notrigger 1 ne declenche pas les triggers, 0 sinon
* \return int <0 si KO, id compte créé si OK
*/
function create($user='',$notrigger=0)
{
global $conf,$langs;
// Nettoyage parametres
$this->login = trim($this->login);
dolibarr_syslog("User::Create login=".$this->login.", user=".$user->id);
$this->db->begin();
$sql = "SELECT login FROM ".MAIN_DB_PREFIX."user";
$sql.= " WHERE login ='".addslashes($this->login)."'";
$resql=$this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$this->db->free($resql);
if ($num)
{
$this->error = $langs->trans("ErrorLoginAlreadyExists");
return -6;
}
else
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."user (datec,login,ldap_sid) VALUES(now(),'".addslashes($this->login)."','".$this->ldap_sid."')";
$result=$this->db->query($sql);
dolibarr_syslog("User::Create sql=".$sql, LOG_DEBUG);
if ($result)
{
$table = "".MAIN_DB_PREFIX."user";
$this->id = $this->db->last_insert_id($table);
function create($user='',$notrigger=0)
{
global $conf,$langs;
// Set default rights
if ($this->set_default_rights() < 0)
{
$this->error=$this->db->error();
$this->db->rollback();
return -5;
}
// Nettoyage parametres
$this->login = trim($this->login);
// Update minor fields
if ($this->update(1) < 0)
{
$this->error=$this->db->error();
dolibarr_syslog("User::Create login=".$this->login.", user=".$user->id);
$this->db->begin();
$sql = "SELECT login FROM ".MAIN_DB_PREFIX."user";
$sql.= " WHERE login ='".addslashes($this->login)."'";
$resql=$this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$this->db->free($resql);
if ($num)
{
$this->error = $langs->trans("ErrorLoginAlreadyExists");
return -6;
}
else
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."user (datec,login,ldap_sid) VALUES(now(),'".addslashes($this->login)."','".$this->ldap_sid."')";
$result=$this->db->query($sql);
dolibarr_syslog("User::Create sql=".$sql, LOG_DEBUG);
if ($result)
{
$table = "".MAIN_DB_PREFIX."user";
$this->id = $this->db->last_insert_id($table);
// Set default rights
if ($this->set_default_rights() < 0)
{
$this->error=$this->db->error();
$this->db->rollback();
return -5;
}
// Update minor fields
if ($this->update($user,1,1) < 0)
{
$this->error=$this->db->error();
$this->db->rollback();
return -4;
}
if (! $notrigger)
{
if ($conf->global->STOCK_USERSTOCK == 1 && $conf->global->STOCK_USERSTOCK_AUTOCREATE == 1)
{
require_once(DOL_DOCUMENT_ROOT."/product/stock/entrepot.class.php");
$entrepot = new Entrepot($this->db);
$entrepot->libelle = 'Stock Personnel '.$this->nom;
$entrepot->description = 'Cet entrepot représente le stock personnel de '.$this->prenom.' '.$this->nom;
$entrepot->statut = 1;
$entrepot->create($user);
}
if (! $notrigger)
{
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
$interface = new Interfaces($this->db);
@ -746,13 +756,13 @@ class User
}
/**
* \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)
{
/**
* \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)
{
global $langs;
// Positionne paramètres
@ -896,12 +906,17 @@ class User
/**
* \brief Mise à jour en base d'un utilisateur
* \param user User qui fait la mise a jour
* \param notrigger 1 ne declenche pas les triggers, 0 sinon
* \param nosyncmember Do not synchronize linked member
* \return int <0 si KO, >=0 si OK
*/
function update($notrigger=0)
function update($user,$notrigger=0,$nosyncmember=0)
{
global $conf,$langs,$user;
$error=0;
dolibarr_syslog("User::update notrigger=".$notrigger.", nosyncmember=".$nosyncmember);
// Nettoyage parametres
$this->nom=trim($this->nom);
@ -913,35 +928,21 @@ class User
$this->note=trim($this->note);
$this->admin=$this->admin?$this->admin:0;
dolibarr_syslog("User::update notrigger=".$notrigger." nom=".$this->nom.", prenom=".$this->prenom);
$error=0;
$this->db->begin();
// Mise a jour mot de passe
if ($this->pass)
{
if ($this->pass != $this->pass_indatabase &&
$this->pass != $this->pass_indatabase_crypted)
{
// Si mot de passe saisi et différent de celui en base
$this->password($user,$this->pass,$conf->password_encrypted);
}
}
// Mise a jour autres infos
$sql = "UPDATE ".MAIN_DB_PREFIX."user SET ";
$sql .= " name = '".addslashes($this->nom)."'";
$sql .= ", firstname = '".addslashes($this->prenom)."'";
$sql .= ", login = '".addslashes($this->login)."'";
$sql .= ", admin = ".$this->admin;
$sql .= ", office_phone = '$this->office_phone'";
$sql .= ", office_fax = '$this->office_fax'";
$sql .= ", user_mobile = '$this->user_mobile'";
$sql .= ", email = '".addslashes($this->email)."'";
$sql .= ", webcal_login = '$this->webcal_login'";
$sql .= ", note = '".addslashes($this->note)."'";
$sql .= " WHERE rowid = ".$this->id;
$sql = "UPDATE ".MAIN_DB_PREFIX."user SET";
$sql.= " name = '".addslashes($this->nom)."'";
$sql.= ", firstname = '".addslashes($this->prenom)."'";
$sql.= ", login = '".addslashes($this->login)."'";
$sql.= ", admin = ".$this->admin;
$sql.= ", office_phone = '$this->office_phone'";
$sql.= ", office_fax = '$this->office_fax'";
$sql.= ", user_mobile = '$this->user_mobile'";
$sql.= ", email = '".addslashes($this->email)."'";
$sql.= ", webcal_login = '$this->webcal_login'";
$sql.= ", note = '".addslashes($this->note)."'";
$sql.= " WHERE rowid = ".$this->id;
dolibarr_syslog("User::update sql=".$sql);
$resql = $this->db->query($sql);
@ -949,33 +950,53 @@ class User
{
$nbrowsaffected=$this->db->affected_rows($resql);
// Mise a jour mot de passe
if ($this->pass)
{
if ($this->pass != $this->pass_indatabase &&
$this->pass != $this->pass_indatabase_crypted)
{
// Si mot de passe saisi et différent de celui en base
$this->password($user,$this->pass,$conf->password_encrypted);
if (! $nbrowsaffected) $nbrowsaffected++;
}
}
if ($nbrowsaffected)
{
if ($this->fk_member && ! $notrigger)
if ($this->fk_member && ! $nosyncmember)
{
// This user is linked with a member, so we also update members informations
// if this is an update (notrigger = 0).
// if this is an update.
$adh=new Adherent($this->db);
$result=$adh->fetch($this->fk_member);
$adh->prenom=$this->prenom;
$adh->nom=$this->nom;
$adh->login=$this->login;
$adh->pass=$this->pass;
$adh->societe=$this->societe_id;
$adh->email=$this->email;
$adh->phone=$this->office_phone;
$adh->phone_perso=$this->office_fax;
$adh->phone_mobile=$this->user_mobile;
$adh->commentaire=$user->note;
if ($result >= 0)
{
$adh->prenom=$this->prenom;
$adh->nom=$this->nom;
$adh->login=$this->login;
$adh->pass=$this->pass;
$adh->societe=$this->societe_id;
$adh->user_id=$this->id;
$adh->user_login=$this->login;
$adh->email=$this->email;
$adh->phone=$this->office_phone;
$adh->phone_mobile=$this->user_mobile;
$adh->commentaire=$this->note;
$result=$adh->update($user,0);
if ($result < 0)
$adh->user_id=$this->id;
$adh->user_login=$this->login;
$result=$adh->update($user,0,1);
if ($result < 0)
{
$this->error=$adh->error;
$error++;
}
}
else
{
$this->error=$adh->error;
$error++;

View File

@ -78,7 +78,7 @@ if ($_GET["id"])
*/
$head = user_prepare_head($fuser);
dolibarr_fiche_head($head, 'bookmark4u', $langs->trans("User").": ".$fuser->fullname);
dolibarr_fiche_head($head, 'bookmark4u', $langs->trans("User"));
/*

View File

@ -70,7 +70,7 @@ if ($_GET["id"])
*/
$head = user_prepare_head($fuser);
dolibarr_fiche_head($head, 'clicktodial', $langs->trans("User").": ".$fuser->fullname);
dolibarr_fiche_head($head, 'clicktodial', $langs->trans("User"));
/*
* Fiche en mode visu

View File

@ -243,7 +243,7 @@ if ($_POST["action"] == 'update' && ! $_POST["cancel"] && $caneditfield)
$edituser->email = trim($_POST["email"]);
$edituser->webcal_login = trim($_POST["webcal_login"]);
$ret=$edituser->update();
$ret=$edituser->update($user);
if ($ret < 0)
{
if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')

View File

@ -566,6 +566,7 @@ ALTER TABLE `llx_socpeople` CHANGE `fk_user_create` `fk_user_creat` INT(11) NULL
-- V4 ALTER TABLE llx_socpeople ADD CONSTRAINT fk_socpeople_user_creat_user_rowid FOREIGN KEY (fk_user_creat) REFERENCES llx_user (rowid);
ALTER TABLE llx_user add pass_temp VARCHAR(32) NULL after pass_crypted;
update llx_user set pass = null where pass = pass_crypted and length(pass) = 32;
drop table if exists llx_soc_events;
drop table if exists llx_todocomm;