2004-10-20 23:15:17 +02:00
|
|
|
|
<?php
|
2005-02-04 12:08:01 +01:00
|
|
|
|
/* Copyright (c) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
2004-08-07 20:47:54 +02:00
|
|
|
|
* Copyright (c) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
|
2006-06-07 00:54:23 +02:00
|
|
|
|
* Copyright (c) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net>
|
2004-09-01 23:23:20 +02:00
|
|
|
|
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
|
2004-10-01 15:25:02 +02:00
|
|
|
|
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
|
2005-07-25 17:41:50 +02:00
|
|
|
|
* Copyright (C) 2005 Regis Houssin <regis.houssin@cap-networks.com>
|
2005-09-13 10:05:47 +02:00
|
|
|
|
* Copyright (C) 2005 Lionel COUSTEIX <etm_ltd@tiscali.co.uk>
|
2002-04-30 12:51:35 +02:00
|
|
|
|
*
|
|
|
|
|
|
* 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.
|
|
|
|
|
|
*
|
2002-12-18 19:03:28 +01:00
|
|
|
|
* $Id$
|
|
|
|
|
|
* $Source$
|
2002-04-30 12:51:35 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
2005-03-15 18:17:58 +01:00
|
|
|
|
/**
|
|
|
|
|
|
\file htdocs/user.class.php
|
2005-01-08 22:47:37 +01:00
|
|
|
|
\brief Fichier de la classe utilisateur
|
|
|
|
|
|
\author Rodolphe Qiedeville
|
|
|
|
|
|
\author Jean-Louis Bergamo
|
|
|
|
|
|
\author Laurent Destailleur
|
|
|
|
|
|
\author Sebastien Di Cintio
|
|
|
|
|
|
\author Benoit Mortier
|
2005-07-25 17:41:50 +02:00
|
|
|
|
\author Regis Houssin
|
2005-01-08 22:47:37 +01:00
|
|
|
|
\version $Revision$
|
2004-08-07 20:47:54 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-03-15 18:17:58 +01:00
|
|
|
|
/**
|
|
|
|
|
|
\class User
|
2005-01-08 22:47:37 +01:00
|
|
|
|
\brief Classe permettant la gestion d'un utilisateur
|
2004-08-07 20:47:54 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
2003-08-11 20:56:42 +02:00
|
|
|
|
class User
|
|
|
|
|
|
{
|
2006-03-18 20:58:33 +01:00
|
|
|
|
var $db;
|
2004-09-07 22:45:25 +02:00
|
|
|
|
|
2006-03-18 20:58:33 +01:00
|
|
|
|
var $id;
|
2006-06-24 17:13:29 +02:00
|
|
|
|
var $ldap_sid;
|
2006-03-18 20:58:33 +01:00
|
|
|
|
var $fullname;
|
|
|
|
|
|
var $nom;
|
|
|
|
|
|
var $prenom;
|
|
|
|
|
|
var $note;
|
|
|
|
|
|
var $code;
|
|
|
|
|
|
var $email;
|
|
|
|
|
|
var $office_tel;
|
|
|
|
|
|
var $office_fax;
|
|
|
|
|
|
var $user_mobile;
|
|
|
|
|
|
var $admin;
|
|
|
|
|
|
var $login;
|
|
|
|
|
|
var $pass;
|
|
|
|
|
|
var $lang;
|
|
|
|
|
|
var $datec;
|
|
|
|
|
|
var $datem;
|
|
|
|
|
|
var $societe_id;
|
|
|
|
|
|
var $webcal_login;
|
|
|
|
|
|
var $datelastaccess;
|
|
|
|
|
|
|
|
|
|
|
|
var $error;
|
|
|
|
|
|
var $userpref_limite_liste;
|
|
|
|
|
|
var $all_permissions_are_loaded; /**< \private all_permissions_are_loaded */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* \brief Constructeur de la classe
|
2006-06-07 00:54:23 +02:00
|
|
|
|
* \param DB Handler acc<EFBFBD>s base de donn<EFBFBD>es
|
|
|
|
|
|
* \param id Id de l'utilisateur (0 par d<EFBFBD>faut)
|
2006-03-18 20:58:33 +01:00
|
|
|
|
*/
|
|
|
|
|
|
function User($DB, $id=0)
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->db = $DB;
|
|
|
|
|
|
$this->id = $id;
|
|
|
|
|
|
|
|
|
|
|
|
// Preference utilisateur
|
|
|
|
|
|
$this->liste_limit = 0;
|
|
|
|
|
|
$this->clicktodial_enabled = 0;
|
2005-01-14 15:18:45 +01:00
|
|
|
|
|
2006-03-18 20:58:33 +01:00
|
|
|
|
$this->all_permissions_are_loaded = 0;
|
|
|
|
|
|
$this->admin=0;
|
2004-06-27 19:51:30 +02:00
|
|
|
|
|
2006-03-18 20:58:33 +01:00
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
2004-08-07 20:47:54 +02:00
|
|
|
|
|
2005-02-26 19:34:14 +01:00
|
|
|
|
|
2004-08-07 20:47:54 +02:00
|
|
|
|
/**
|
2005-02-26 19:34:14 +01:00
|
|
|
|
* \brief Charge un objet user avec toutes ces caract<EFBFBD>ristiques depuis un id ou login
|
2005-08-11 20:50:40 +02:00
|
|
|
|
* \param login Si d<EFBFBD>fini, login a utiliser pour recherche
|
2002-04-30 12:51:35 +02:00
|
|
|
|
*/
|
2006-06-07 00:54:23 +02:00
|
|
|
|
function fetch($login='')
|
2003-08-11 20:56:42 +02:00
|
|
|
|
{
|
2005-08-11 20:50:40 +02:00
|
|
|
|
// Recupere utilisateur
|
2005-09-13 10:05:47 +02:00
|
|
|
|
$sql = "SELECT u.rowid, u.name, u.firstname, u.email, u.office_phone, u.office_fax, u.user_mobile, u.code, u.admin, u.login, u.pass, u.webcal_login, u.note,";
|
2006-06-24 17:13:29 +02:00
|
|
|
|
$sql.= " u.fk_societe, u.fk_socpeople, u.ldap_sid,";
|
2005-07-14 19:17:31 +02:00
|
|
|
|
$sql.= " ".$this->db->pdate("u.datec")." as datec, ".$this->db->pdate("u.tms")." as datem,";
|
|
|
|
|
|
$sql.= " ".$this->db->pdate("u.datelastaccess")." as datel";
|
|
|
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."user as u";
|
2005-08-11 20:50:40 +02:00
|
|
|
|
if ($login)
|
2005-07-14 19:17:31 +02:00
|
|
|
|
{
|
2005-08-11 20:50:40 +02:00
|
|
|
|
$sql .= " WHERE u.login = '$login'";
|
2005-07-14 19:17:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2005-11-02 01:12:49 +01:00
|
|
|
|
$sql .= " WHERE u.rowid = ".$this->id;
|
2005-07-14 19:17:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
|
if ($result)
|
|
|
|
|
|
{
|
2005-11-02 01:12:49 +01:00
|
|
|
|
$obj = $this->db->fetch_object($result);
|
|
|
|
|
|
if ($obj)
|
2005-07-14 19:17:31 +02:00
|
|
|
|
{
|
|
|
|
|
|
$this->id = $obj->rowid;
|
2006-06-24 17:13:29 +02:00
|
|
|
|
$this->ldap_sid = $obj->ldap_sid;
|
2005-07-14 19:17:31 +02:00
|
|
|
|
$this->nom = stripslashes($obj->name);
|
|
|
|
|
|
$this->prenom = stripslashes($obj->firstname);
|
|
|
|
|
|
|
|
|
|
|
|
$this->fullname = $this->prenom . ' ' . $this->nom;
|
|
|
|
|
|
$this->code = $obj->code;
|
|
|
|
|
|
$this->login = $obj->login;
|
|
|
|
|
|
$this->pass = $obj->pass;
|
2006-06-24 17:13:29 +02:00
|
|
|
|
$this->office_phone = $obj->office_phone;
|
|
|
|
|
|
$this->office_fax = $obj->office_fax;
|
|
|
|
|
|
$this->user_mobile = $obj->user_mobile;
|
2005-07-14 19:17:31 +02:00
|
|
|
|
$this->email = $obj->email;
|
|
|
|
|
|
$this->admin = $obj->admin;
|
|
|
|
|
|
$this->contact_id = $obj->fk_socpeople;
|
|
|
|
|
|
$this->note = stripslashes($obj->note);
|
|
|
|
|
|
$this->lang = 'fr_FR'; // \todo G<>rer la langue par d<>faut d'un utilisateur Dolibarr
|
2005-07-25 17:41:50 +02:00
|
|
|
|
|
2005-07-14 19:17:31 +02:00
|
|
|
|
$this->datec = $obj->datec;
|
|
|
|
|
|
$this->datem = $obj->datem;
|
|
|
|
|
|
$this->datelastaccess = $obj->datel;
|
|
|
|
|
|
|
|
|
|
|
|
$this->webcal_login = $obj->webcal_login;
|
|
|
|
|
|
$this->societe_id = $obj->fk_societe;
|
|
|
|
|
|
}
|
|
|
|
|
|
$this->db->free($result);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
dolibarr_print_error($this->db);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2005-08-11 20:50:40 +02:00
|
|
|
|
// Recupere parametrage global propre <20> l'utilisateur
|
|
|
|
|
|
// \todo a stocker/recup<75>rer en session pour eviter ce select a chaque page
|
|
|
|
|
|
$sql = "SELECT param, value FROM ".MAIN_DB_PREFIX."user_param";
|
|
|
|
|
|
$sql.= " WHERE fk_user = ".$this->id;
|
|
|
|
|
|
$sql.= " AND page = ''";
|
|
|
|
|
|
$result=$this->db->query($sql);
|
|
|
|
|
|
if ($result)
|
|
|
|
|
|
{
|
|
|
|
|
|
$num = $this->db->num_rows($result);
|
|
|
|
|
|
$i = 0;
|
|
|
|
|
|
while ($i < $num)
|
|
|
|
|
|
{
|
|
|
|
|
|
$obj = $this->db->fetch_object($result);
|
|
|
|
|
|
$p=$obj->param;
|
|
|
|
|
|
$this->conf->$p = $obj->value;
|
|
|
|
|
|
$i++;
|
|
|
|
|
|
}
|
|
|
|
|
|
$this->db->free($result);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
dolibarr_print_error($this->db);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Recupere parametrage propre <20> la page et <20> l'utilisateur
|
|
|
|
|
|
// \todo SCRIPT_URL non defini sur tous serveurs
|
|
|
|
|
|
// Param<61>trage par page desactiv<69> pour l'instant
|
|
|
|
|
|
if (1==2 && isset($_SERVER['SCRIPT_URL']))
|
|
|
|
|
|
{
|
2005-07-14 19:17:31 +02:00
|
|
|
|
$sql = "SELECT param, value FROM ".MAIN_DB_PREFIX."user_param";
|
2005-08-11 20:50:40 +02:00
|
|
|
|
$sql.= " WHERE fk_user = ".$this->id;
|
|
|
|
|
|
$sql.= " AND page='".$_SERVER['SCRIPT_URL']."'";
|
2005-07-14 19:17:31 +02:00
|
|
|
|
$result=$this->db->query($sql);
|
2005-08-11 20:50:40 +02:00
|
|
|
|
if ($result)
|
2005-07-14 19:17:31 +02:00
|
|
|
|
{
|
|
|
|
|
|
$num = $this->db->num_rows($result);
|
|
|
|
|
|
$i = 0;
|
|
|
|
|
|
$page_param_url = '';
|
|
|
|
|
|
$this->page_param = array();
|
|
|
|
|
|
while ($i < $num)
|
|
|
|
|
|
{
|
|
|
|
|
|
$obj = $this->db->fetch_object($result);
|
|
|
|
|
|
$this->page_param[$obj->param] = $obj->value;
|
2005-08-11 20:50:40 +02:00
|
|
|
|
$page_param_url .= $obj->param."=".$obj->value."&";
|
2005-07-14 19:17:31 +02:00
|
|
|
|
$i++;
|
|
|
|
|
|
}
|
|
|
|
|
|
$this->page_param_url = $page_param_url;
|
|
|
|
|
|
$this->db->free($result);
|
|
|
|
|
|
}
|
2005-08-11 20:50:40 +02:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
dolibarr_print_error($this->db);
|
|
|
|
|
|
}
|
2005-07-14 19:17:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2005-02-26 19:34:14 +01:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* \brief Ajoute un droit a l'utilisateur
|
|
|
|
|
|
* \param rid id du droit <EFBFBD> ajouter
|
2005-03-28 18:56:04 +02:00
|
|
|
|
* \param allmodule Ajouter tous les droits du module allmodule
|
|
|
|
|
|
* \param allperms Ajouter tous les droits du module allmodule, perms allperms
|
2005-02-26 19:34:14 +01:00
|
|
|
|
* \return int > 0 si ok, < 0 si erreur
|
|
|
|
|
|
*/
|
2005-03-28 18:56:04 +02:00
|
|
|
|
function addrights($rid,$allmodule='',$allperms='')
|
2005-02-26 19:34:14 +01:00
|
|
|
|
{
|
2005-10-22 19:30:44 +02:00
|
|
|
|
dolibarr_syslog("User::addrights $rid, $allmodule, $allperms");
|
2005-03-28 18:56:04 +02:00
|
|
|
|
$err=0;
|
|
|
|
|
|
$whereforadd='';
|
|
|
|
|
|
|
|
|
|
|
|
$this->db->begin();
|
|
|
|
|
|
|
|
|
|
|
|
if ($rid)
|
2005-02-26 19:34:14 +01:00
|
|
|
|
{
|
2005-03-28 18:56:04 +02:00
|
|
|
|
// Si on a demand<6E> ajout d'un droit en particulier, on r<>cup<75>re
|
|
|
|
|
|
// les caract<63>ristiques (module, perms et subperms) de ce droit.
|
|
|
|
|
|
$sql = "SELECT module, perms, subperms";
|
|
|
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."rights_def";
|
|
|
|
|
|
$sql.= " WHERE ";
|
|
|
|
|
|
$sql.=" id = '".$rid."'";
|
|
|
|
|
|
|
|
|
|
|
|
$result=$this->db->query($sql);
|
|
|
|
|
|
if ($result) {
|
|
|
|
|
|
$obj = $this->db->fetch_object($result);
|
|
|
|
|
|
$module=$obj->module;
|
|
|
|
|
|
$perms=$obj->perms;
|
|
|
|
|
|
$subperms=$obj->subperms;
|
2005-02-26 19:34:14 +01:00
|
|
|
|
}
|
2005-03-28 18:56:04 +02:00
|
|
|
|
else {
|
|
|
|
|
|
$err++;
|
2005-02-26 19:34:14 +01:00
|
|
|
|
dolibarr_print_error($this->db);
|
|
|
|
|
|
}
|
2005-03-28 18:56:04 +02:00
|
|
|
|
|
|
|
|
|
|
// Where pour la liste des droits <20> ajouter
|
|
|
|
|
|
$whereforadd="id=".$rid;
|
|
|
|
|
|
// Ajout des droits induits
|
|
|
|
|
|
if ($subperms) $whereforadd.=" OR (module='$module' AND perms='$perms' AND subperms='lire')";
|
|
|
|
|
|
if ($perms) $whereforadd.=" OR (module='$module' AND perms='lire' AND subperms IS NULL)";
|
2005-02-26 19:34:14 +01:00
|
|
|
|
}
|
2005-03-28 18:56:04 +02:00
|
|
|
|
else {
|
|
|
|
|
|
// Where pour la liste des droits <20> ajouter
|
|
|
|
|
|
if ($allmodule) $whereforadd="module='$allmodule'";
|
|
|
|
|
|
if ($allperms) $whereforadd=" AND perms='$allperms'";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Ajout des droits de la liste whereforadd
|
|
|
|
|
|
if ($whereforadd)
|
2005-02-26 19:34:14 +01:00
|
|
|
|
{
|
2005-03-28 18:56:04 +02:00
|
|
|
|
//print "$module-$perms-$subperms";
|
|
|
|
|
|
$sql = "SELECT id";
|
|
|
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."rights_def";
|
|
|
|
|
|
$sql.= " WHERE $whereforadd";
|
|
|
|
|
|
|
|
|
|
|
|
$result=$this->db->query($sql);
|
|
|
|
|
|
if ($result)
|
2005-02-26 19:34:14 +01:00
|
|
|
|
{
|
2005-03-28 18:56:04 +02:00
|
|
|
|
$num = $this->db->num_rows($result);
|
|
|
|
|
|
$i = 0;
|
|
|
|
|
|
while ($i < $num)
|
2005-02-26 19:34:14 +01:00
|
|
|
|
{
|
2005-03-28 18:56:04 +02:00
|
|
|
|
$obj = $this->db->fetch_object($result);
|
|
|
|
|
|
$nid = $obj->id;
|
|
|
|
|
|
|
|
|
|
|
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."user_rights WHERE fk_user = $this->id AND fk_id=$nid";
|
|
|
|
|
|
if (! $this->db->query($sql)) $err++;
|
|
|
|
|
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."user_rights (fk_user, fk_id) VALUES ($this->id, $nid)";
|
|
|
|
|
|
if (! $this->db->query($sql)) $err++;
|
2005-02-26 19:34:14 +01:00
|
|
|
|
|
2005-03-28 18:56:04 +02:00
|
|
|
|
$i++;
|
2005-02-26 19:34:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2005-03-28 18:56:04 +02:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
$err++;
|
|
|
|
|
|
dolibarr_print_error($this->db);
|
|
|
|
|
|
}
|
2005-02-26 19:34:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2005-03-28 18:56:04 +02:00
|
|
|
|
if ($err) {
|
|
|
|
|
|
$this->db->rollback();
|
|
|
|
|
|
return -$err;
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
$this->db->commit();
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-08-11 20:56:42 +02:00
|
|
|
|
}
|
2004-08-07 20:47:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* \brief Retire un droit a l'utilisateur
|
2005-03-28 18:56:04 +02:00
|
|
|
|
* \param rid id du droit <EFBFBD> retirer
|
|
|
|
|
|
* \param allmodule Retirer tous les droits du module allmodule
|
|
|
|
|
|
* \param allperms Retirer tous les droits du module allmodule, perms allperms
|
2005-02-26 19:34:14 +01:00
|
|
|
|
* \return int > 0 si ok, < 0 si erreur
|
2003-08-11 20:56:42 +02:00
|
|
|
|
*/
|
2005-03-28 18:56:04 +02:00
|
|
|
|
function delrights($rid,$allmodule='',$allperms='')
|
2003-08-11 20:56:42 +02:00
|
|
|
|
{
|
2005-03-28 18:56:04 +02:00
|
|
|
|
$err=0;
|
|
|
|
|
|
$wherefordel='';
|
|
|
|
|
|
|
|
|
|
|
|
$this->db->begin();
|
|
|
|
|
|
|
|
|
|
|
|
if ($rid)
|
2005-02-26 19:34:14 +01:00
|
|
|
|
{
|
2005-03-28 18:56:04 +02:00
|
|
|
|
// Si on a demand<6E> supression d'un droit en particulier, on r<>cup<75>re
|
|
|
|
|
|
// les caract<63>ristiques module, perms et subperms de ce droit.
|
|
|
|
|
|
$sql = "SELECT module, perms, subperms";
|
|
|
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."rights_def";
|
|
|
|
|
|
$sql.= " WHERE ";
|
|
|
|
|
|
$sql.=" id = '".$rid."'";
|
|
|
|
|
|
|
|
|
|
|
|
$result=$this->db->query($sql);
|
|
|
|
|
|
if ($result) {
|
|
|
|
|
|
$obj = $this->db->fetch_object($result);
|
|
|
|
|
|
$module=$obj->module;
|
|
|
|
|
|
$perms=$obj->perms;
|
|
|
|
|
|
$subperms=$obj->subperms;
|
2005-02-26 19:34:14 +01:00
|
|
|
|
}
|
2005-03-28 18:56:04 +02:00
|
|
|
|
else {
|
|
|
|
|
|
$err++;
|
2005-02-26 19:34:14 +01:00
|
|
|
|
dolibarr_print_error($this->db);
|
|
|
|
|
|
}
|
2005-03-28 18:56:04 +02:00
|
|
|
|
|
|
|
|
|
|
// Where pour la liste des droits <20> supprimer
|
|
|
|
|
|
$wherefordel="id=".$rid;
|
|
|
|
|
|
// Suppression des droits induits
|
|
|
|
|
|
if ($subperms=='lire') $wherefordel.=" OR (module='$module' AND perms='$perms' AND subperms IS NOT NULL)";
|
|
|
|
|
|
if ($perms=='lire') $wherefordel.=" OR (module='$module')";
|
2005-02-26 19:34:14 +01:00
|
|
|
|
}
|
2005-03-28 18:56:04 +02:00
|
|
|
|
else {
|
|
|
|
|
|
// Where pour la liste des droits <20> supprimer
|
|
|
|
|
|
if ($allmodule) $wherefordel="module='$allmodule'";
|
|
|
|
|
|
if ($allperms) $wherefordel=" AND perms='$allperms'";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Suppression des droits de la liste wherefordel
|
|
|
|
|
|
if ($wherefordel)
|
2005-02-26 19:34:14 +01:00
|
|
|
|
{
|
2005-03-28 18:56:04 +02:00
|
|
|
|
//print "$module-$perms-$subperms";
|
|
|
|
|
|
$sql = "SELECT id";
|
|
|
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."rights_def";
|
|
|
|
|
|
$sql.= " WHERE $wherefordel";
|
|
|
|
|
|
|
|
|
|
|
|
$result=$this->db->query($sql);
|
|
|
|
|
|
if ($result)
|
2005-02-26 19:34:14 +01:00
|
|
|
|
{
|
2005-03-28 18:56:04 +02:00
|
|
|
|
$num = $this->db->num_rows($result);
|
|
|
|
|
|
$i = 0;
|
|
|
|
|
|
while ($i < $num)
|
2005-02-26 19:34:14 +01:00
|
|
|
|
{
|
2005-03-28 18:56:04 +02:00
|
|
|
|
$obj = $this->db->fetch_object($result);
|
|
|
|
|
|
$nid = $obj->id;
|
|
|
|
|
|
|
|
|
|
|
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."user_rights WHERE fk_user = $this->id AND fk_id=$nid";
|
|
|
|
|
|
if (! $this->db->query($sql)) $err++;
|
2005-02-26 19:34:14 +01:00
|
|
|
|
|
2005-03-28 18:56:04 +02:00
|
|
|
|
$i++;
|
2005-02-26 19:34:14 +01:00
|
|
|
|
}
|
2005-03-28 18:56:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
$err++;
|
|
|
|
|
|
dolibarr_print_error($this->db);
|
2005-02-26 19:34:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2005-03-28 18:56:04 +02:00
|
|
|
|
if ($err) {
|
|
|
|
|
|
$this->db->rollback();
|
|
|
|
|
|
return -$err;
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
$this->db->commit();
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-08-11 20:56:42 +02:00
|
|
|
|
}
|
2004-08-07 20:47:54 +02:00
|
|
|
|
|
|
|
|
|
|
/**
|
2005-03-06 01:55:55 +01:00
|
|
|
|
* \brief Charge dans l'objet user, la liste des permissions auxquelles l'utilisateur a droit
|
2004-08-07 20:47:54 +02:00
|
|
|
|
* \param module nom du module dont il faut r<EFBFBD>cup<EFBFBD>rer les droits ('' par defaut signifie tous les droits)
|
2003-08-11 20:56:42 +02:00
|
|
|
|
*/
|
2006-06-07 00:54:23 +02:00
|
|
|
|
function getrights($module='')
|
2003-08-11 20:56:42 +02:00
|
|
|
|
{
|
2005-03-06 01:55:55 +01:00
|
|
|
|
if ($this->all_permissions_are_loaded)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Si les permissions ont d<>ja <20>t<EFBFBD> charg<72> pour ce user, on quitte
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// R<>cup<75>ration des droits utilisateurs + r<>cup<75>ration des droits groupes
|
2005-03-06 18:16:54 +01:00
|
|
|
|
|
|
|
|
|
|
// D'abord les droits utilisateurs
|
2005-03-06 01:55:55 +01:00
|
|
|
|
$sql = "SELECT r.module, r.perms, r.subperms";
|
|
|
|
|
|
$sql .= " FROM ".MAIN_DB_PREFIX."user_rights as ur, ".MAIN_DB_PREFIX."rights_def as r";
|
2005-03-06 18:16:54 +01:00
|
|
|
|
$sql .= " WHERE r.id = ur.fk_id AND ur.fk_user= ".$this->id." AND r.perms IS NOT NULL";
|
|
|
|
|
|
|
|
|
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
|
if ($result)
|
|
|
|
|
|
{
|
|
|
|
|
|
$num = $this->db->num_rows($result);
|
|
|
|
|
|
$i = 0;
|
|
|
|
|
|
while ($i < $num)
|
|
|
|
|
|
{
|
|
|
|
|
|
$row = $this->db->fetch_row($result);
|
|
|
|
|
|
|
2006-01-22 18:29:38 +01:00
|
|
|
|
if ($row[1])
|
2005-03-06 18:16:54 +01:00
|
|
|
|
{
|
2006-01-22 18:29:38 +01:00
|
|
|
|
if ($row[2])
|
2005-03-06 18:16:54 +01:00
|
|
|
|
{
|
2006-01-22 18:29:38 +01:00
|
|
|
|
if (! $this->rights->$row[0] ||
|
|
|
|
|
|
(is_object($this->rights->$row[0]) && ! $this->rights->$row[0]->$row[1]) ||
|
|
|
|
|
|
(is_object($this->rights->$row[0]->$row[1])) )
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->rights->$row[0]->$row[1]->$row[2] = 1;
|
|
|
|
|
|
}
|
2005-03-06 18:16:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->rights->$row[0]->$row[1] = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
$i++;
|
|
|
|
|
|
}
|
|
|
|
|
|
$this->db->free($result);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Maintenant les droits groupes
|
|
|
|
|
|
$sql = " SELECT r.module, r.perms, r.subperms";
|
2005-03-06 01:55:55 +01:00
|
|
|
|
$sql .= " FROM ".MAIN_DB_PREFIX."usergroup_rights as gr, ".MAIN_DB_PREFIX."usergroup_user as gu, ".MAIN_DB_PREFIX."rights_def as r";
|
2005-03-06 18:16:54 +01:00
|
|
|
|
$sql .= " WHERE r.id = gr.fk_id AND gr.fk_usergroup = gu.fk_usergroup AND gu.fk_user = ".$this->id." AND r.perms IS NOT NULL";
|
2005-03-06 01:55:55 +01:00
|
|
|
|
|
|
|
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
|
if ($result)
|
|
|
|
|
|
{
|
|
|
|
|
|
$num = $this->db->num_rows($result);
|
|
|
|
|
|
$i = 0;
|
|
|
|
|
|
while ($i < $num)
|
|
|
|
|
|
{
|
|
|
|
|
|
$row = $this->db->fetch_row($result);
|
|
|
|
|
|
|
|
|
|
|
|
if (strlen($row[1]) > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
if (strlen($row[2]) > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->rights->$row[0]->$row[1]->$row[2] = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->rights->$row[0]->$row[1] = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
$i++;
|
|
|
|
|
|
}
|
2005-03-06 18:16:54 +01:00
|
|
|
|
$this->db->free($result);
|
2005-03-06 01:55:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2005-01-08 22:47:37 +01:00
|
|
|
|
if ($module == '')
|
|
|
|
|
|
{
|
2005-03-06 01:55:55 +01:00
|
|
|
|
// Si module etait non defini, alors on a tout charg<72>, on peut donc consid<69>rer
|
|
|
|
|
|
// que les droits sont en cache (car tous charg<72>s) pour cet instance de user
|
|
|
|
|
|
$this->all_permissions_are_loaded=1;
|
2005-01-08 22:47:37 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-08-11 20:56:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2005-01-16 21:21:58 +01:00
|
|
|
|
|
2005-09-26 21:37:20 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* \brief D<EFBFBD>sactive un utilisateur
|
|
|
|
|
|
* \return int <0 si ko, >0 si ok
|
|
|
|
|
|
*/
|
2005-02-26 19:34:14 +01:00
|
|
|
|
function disable()
|
2002-12-18 19:02:06 +01:00
|
|
|
|
{
|
2005-09-26 21:37:20 +02:00
|
|
|
|
$error=0;
|
|
|
|
|
|
|
2005-02-26 19:34:14 +01:00
|
|
|
|
// D<>sactive utilisateur
|
2005-07-11 03:10:15 +02:00
|
|
|
|
$sql = "UPDATE ".MAIN_DB_PREFIX."user";
|
|
|
|
|
|
$sql.= " SET login = NULL";
|
|
|
|
|
|
$sql.= " WHERE rowid = ".$this->id;
|
2005-02-26 19:34:14 +01:00
|
|
|
|
$result = $this->db->query($sql);
|
2005-09-26 21:37:20 +02:00
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
2005-02-26 19:34:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-09-26 21:37:20 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* \brief Supprime compl<EFBFBD>tement un utilisateur
|
|
|
|
|
|
*/
|
2005-02-26 19:34:14 +01:00
|
|
|
|
function delete()
|
2003-08-11 20:56:42 +02:00
|
|
|
|
{
|
2005-02-26 19:34:14 +01:00
|
|
|
|
// Supprime droits
|
|
|
|
|
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."user_rights WHERE fk_user = $this->id";
|
|
|
|
|
|
if ($this->db->query($sql))
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Si contact, supprime lien
|
|
|
|
|
|
if ($this->contact_id)
|
|
|
|
|
|
{
|
|
|
|
|
|
$sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET fk_user = null WHERE idp = $this->contact_id";
|
|
|
|
|
|
if ($this->db->query($sql))
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Supprime utilisateur
|
|
|
|
|
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."user WHERE rowid = $this->id";
|
|
|
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
|
}
|
2003-08-11 20:56:42 +02:00
|
|
|
|
|
2004-08-07 20:47:54 +02:00
|
|
|
|
|
2005-09-26 21:37:20 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* \brief Cr<EFBFBD>e un utilisateur en base
|
|
|
|
|
|
* \return int si erreur <0, si ok renvoie id compte cr<EFBFBD><EFBFBD>
|
|
|
|
|
|
*/
|
|
|
|
|
|
function create()
|
2002-12-19 21:26:51 +01:00
|
|
|
|
{
|
2005-02-03 16:04:53 +01:00
|
|
|
|
global $langs;
|
2005-09-26 21:37:20 +02:00
|
|
|
|
|
2005-12-01 00:31:19 +01:00
|
|
|
|
// Nettoyage parametres
|
|
|
|
|
|
$this->login = trim($this->login);
|
|
|
|
|
|
|
2005-09-26 21:37:20 +02:00
|
|
|
|
$this->db->begin();
|
|
|
|
|
|
|
2006-03-18 20:58:33 +01:00
|
|
|
|
$sql = "SELECT login FROM ".MAIN_DB_PREFIX."user";
|
|
|
|
|
|
$sql.= " WHERE login ='".addslashes($this->login)."'";
|
2005-09-26 21:37:20 +02:00
|
|
|
|
$resql=$this->db->query($sql);
|
|
|
|
|
|
if ($resql)
|
2005-02-08 01:18:23 +01:00
|
|
|
|
{
|
2005-09-26 21:37:20 +02:00
|
|
|
|
$num = $this->db->num_rows($resql);
|
|
|
|
|
|
$this->db->free($resql);
|
|
|
|
|
|
|
2005-02-08 01:18:23 +01:00
|
|
|
|
if ($num)
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->error = $langs->trans("ErrorLoginAlreadyExists");
|
2006-03-18 20:58:33 +01:00
|
|
|
|
return -6;
|
2005-02-08 01:18:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2006-06-24 17:13:29 +02:00
|
|
|
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."user (datec,login,ldap_sid) VALUES(now(),'".addslashes($this->login)."','".$this->ldap_sid."')";
|
2005-02-08 01:18:23 +01:00
|
|
|
|
$result=$this->db->query($sql);
|
2005-09-26 21:37:20 +02:00
|
|
|
|
|
2005-02-08 01:18:23 +01:00
|
|
|
|
if ($result)
|
|
|
|
|
|
{
|
|
|
|
|
|
$table = "".MAIN_DB_PREFIX."user";
|
|
|
|
|
|
$this->id = $this->db->last_insert_id($table);
|
2005-09-26 21:37:20 +02:00
|
|
|
|
|
|
|
|
|
|
// Set default rights
|
|
|
|
|
|
if ($this->set_default_rights() < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->error=$this->db->error();
|
2006-03-18 20:58:33 +01:00
|
|
|
|
$this->db->rollback();
|
|
|
|
|
|
return -5;
|
2005-09-26 21:37:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Update minor fields
|
|
|
|
|
|
if ($this->update() < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->error=$this->db->error();
|
2006-03-18 20:58:33 +01:00
|
|
|
|
$this->db->rollback();
|
|
|
|
|
|
return -4;
|
2005-09-26 21:37:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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->error=$interface->error;
|
2006-03-18 20:58:33 +01:00
|
|
|
|
$this->db->rollback();
|
2005-09-26 21:37:20 +02:00
|
|
|
|
return -3;
|
|
|
|
|
|
}
|
2005-02-08 01:18:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2005-09-26 21:37:20 +02:00
|
|
|
|
$this->error=$this->db->error();
|
2006-03-18 20:58:33 +01:00
|
|
|
|
$this->db->rollback();
|
2005-02-08 01:18:23 +01:00
|
|
|
|
return -2;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2005-09-26 21:37:20 +02:00
|
|
|
|
$this->error=$this->db->error();
|
2006-03-18 20:58:33 +01:00
|
|
|
|
$this->db->rollback();
|
2005-02-08 01:18:23 +01:00
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2004-08-07 20:47:54 +02:00
|
|
|
|
|
2005-09-26 21:37:20 +02:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* \brief Cr<EFBFBD><EFBFBD> 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<EFBFBD><EFBFBD>
|
|
|
|
|
|
*/
|
|
|
|
|
|
function create_from_contact($contact)
|
2003-08-11 20:56:42 +02:00
|
|
|
|
{
|
2005-02-03 16:04:53 +01:00
|
|
|
|
global $langs;
|
2005-09-26 21:37:20 +02:00
|
|
|
|
|
|
|
|
|
|
// Positionne param<61>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<43>e et positionne $this->id
|
|
|
|
|
|
$result=$this->create();
|
|
|
|
|
|
|
|
|
|
|
|
if ($result > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
$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);
|
|
|
|
|
|
|
|
|
|
|
|
if ($resql)
|
|
|
|
|
|
{
|
|
|
|
|
|
$sql = "UPDATE ".MAIN_DB_PREFIX."socpeople";
|
|
|
|
|
|
$sql.= " SET fk_user = ".$this->id;
|
|
|
|
|
|
$sql.= " WHERE idp = ".$contact->id;
|
|
|
|
|
|
$resql=$this->db->query($sql);
|
2005-02-03 16:04:53 +01:00
|
|
|
|
|
2005-09-26 21:37:20 +02:00
|
|
|
|
if ($resql)
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->db->commit();
|
|
|
|
|
|
return $this->id;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->error=$this->db->error()." - $sql";
|
|
|
|
|
|
dolibarr_syslog("User::create_from_contact - 20 - ".$this->error);
|
|
|
|
|
|
|
|
|
|
|
|
$this->db->rollback();
|
|
|
|
|
|
return -2;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->error=$this->db->error()." - $sql";
|
|
|
|
|
|
dolibarr_syslog("User::create_from_contact - 10 - ".$this->error);
|
|
|
|
|
|
|
|
|
|
|
|
$this->db->rollback();
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// $this->error deja positionn<6E>
|
|
|
|
|
|
dolibarr_syslog("User::create_from_contact - 0");
|
|
|
|
|
|
|
|
|
|
|
|
$this->db->rollback();
|
|
|
|
|
|
return $result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-08-11 20:56:42 +02:00
|
|
|
|
}
|
2004-08-07 20:47:54 +02:00
|
|
|
|
|
2003-11-19 15:40:44 +01:00
|
|
|
|
/**
|
2005-02-08 01:18:23 +01:00
|
|
|
|
* \brief Affectation des permissions par d<EFBFBD>faut
|
|
|
|
|
|
* \return si erreur <0, si ok renvoi le nbre de droits par defaut positionn<EFBFBD>s
|
2003-08-11 20:56:42 +02:00
|
|
|
|
*/
|
2006-06-07 00:54:23 +02:00
|
|
|
|
function set_default_rights()
|
2003-08-11 20:56:42 +02:00
|
|
|
|
{
|
2005-02-08 01:18:23 +01:00
|
|
|
|
$sql = "SELECT id FROM ".MAIN_DB_PREFIX."rights_def WHERE bydefault = 1";
|
|
|
|
|
|
|
|
|
|
|
|
if ($this->db->query($sql))
|
|
|
|
|
|
{
|
|
|
|
|
|
$num = $this->db->num_rows();
|
|
|
|
|
|
$i = 0;
|
|
|
|
|
|
$rd = array();
|
|
|
|
|
|
while ($i < $num)
|
|
|
|
|
|
{
|
|
|
|
|
|
$row = $this->db->fetch_row($i);
|
|
|
|
|
|
$rd[$i] = $row[0];
|
|
|
|
|
|
$i++;
|
|
|
|
|
|
}
|
|
|
|
|
|
$this->db->free();
|
|
|
|
|
|
}
|
|
|
|
|
|
$i = 0;
|
|
|
|
|
|
while ($i < $num)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."user_rights WHERE fk_user = $this->id AND fk_id=$rd[$i]";
|
|
|
|
|
|
$result=$this->db->query($sql);
|
|
|
|
|
|
|
|
|
|
|
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."user_rights (fk_user, fk_id) VALUES ($this->id, $rd[$i])";
|
|
|
|
|
|
$result=$this->db->query($sql);
|
|
|
|
|
|
if (! $result) return -1;
|
|
|
|
|
|
$i++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $i;
|
2003-08-11 20:56:42 +02:00
|
|
|
|
}
|
2004-08-07 20:47:54 +02:00
|
|
|
|
|
2003-11-19 15:40:44 +01:00
|
|
|
|
/**
|
2005-02-03 16:04:53 +01:00
|
|
|
|
* \brief Mise <EFBFBD> jour en base d'un utilisateur
|
2005-09-26 21:37:20 +02:00
|
|
|
|
* \param create 1 si update durant le create, 0 sinon
|
|
|
|
|
|
* \return int <0 si echec, >=0 si ok
|
2003-08-11 20:56:42 +02:00
|
|
|
|
*/
|
2006-06-07 00:54:23 +02:00
|
|
|
|
function update($create=0)
|
2002-12-18 19:02:06 +01:00
|
|
|
|
{
|
2005-02-03 16:04:53 +01:00
|
|
|
|
global $langs;
|
2005-02-08 01:18:23 +01:00
|
|
|
|
|
2005-12-01 00:31:19 +01:00
|
|
|
|
// Nettoyage parametres
|
|
|
|
|
|
$this->nom=trim($this->nom);
|
|
|
|
|
|
$this->prenom=trim($this->prenom);
|
|
|
|
|
|
$this->login=trim($this->login);
|
|
|
|
|
|
$this->pass=trim($this->pass);
|
|
|
|
|
|
$this->email=trim($this->email);
|
|
|
|
|
|
$this->note=trim($this->note);
|
2006-03-18 20:58:33 +01:00
|
|
|
|
$this->admin=$this->admin?$this->admin:0;
|
2006-06-14 00:26:23 +02:00
|
|
|
|
if (!strlen($this->code)) $this->code = $this->login;
|
2005-12-01 00:31:19 +01:00
|
|
|
|
|
2006-06-14 00:26:23 +02:00
|
|
|
|
dolibarr_syslog("User::update nom=".$this->nom.", prenom=".$this->prenom);
|
2005-09-26 21:37:20 +02:00
|
|
|
|
$error=0;
|
2002-12-18 19:02:06 +01:00
|
|
|
|
|
2005-02-08 01:18:23 +01:00
|
|
|
|
$sql = "UPDATE ".MAIN_DB_PREFIX."user SET ";
|
2005-12-01 00:31:19 +01:00
|
|
|
|
$sql .= " name = '".addslashes($this->nom)."'";
|
|
|
|
|
|
$sql .= ", firstname = '".addslashes($this->prenom)."'";
|
|
|
|
|
|
$sql .= ", login = '".addslashes($this->login)."'";
|
|
|
|
|
|
if ($this->pass) $sql .= ", pass = '".addslashes($this->pass)."'";
|
2006-03-18 20:58:33 +01:00
|
|
|
|
$sql .= ", admin = ".$this->admin;
|
2005-09-13 10:05:47 +02:00
|
|
|
|
$sql .= ", office_phone = '$this->office_phone'";
|
|
|
|
|
|
$sql .= ", office_fax = '$this->office_fax'";
|
|
|
|
|
|
$sql .= ", user_mobile = '$this->user_mobile'";
|
2005-12-01 00:31:19 +01:00
|
|
|
|
$sql .= ", email = '".addslashes($this->email)."'";
|
2005-02-08 01:18:23 +01:00
|
|
|
|
$sql .= ", webcal_login = '$this->webcal_login'";
|
|
|
|
|
|
$sql .= ", code = '$this->code'";
|
2005-12-01 00:31:19 +01:00
|
|
|
|
$sql .= ", note = '".addslashes($this->note)."'";
|
2005-02-08 01:18:23 +01:00
|
|
|
|
$sql .= " WHERE rowid = ".$this->id;
|
2002-12-18 19:02:06 +01:00
|
|
|
|
|
2005-02-08 01:18:23 +01:00
|
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
|
if ($result)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($this->db->affected_rows())
|
|
|
|
|
|
{
|
2005-09-26 21:37:20 +02:00
|
|
|
|
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
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2005-02-08 01:18:23 +01:00
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2005-07-11 01:40:36 +02:00
|
|
|
|
$this->error=$this->db->error();
|
|
|
|
|
|
return -1;
|
2005-02-08 01:18:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2004-08-07 20:47:54 +02:00
|
|
|
|
|
2005-08-11 20:50:40 +02:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* \brief Mise <EFBFBD> jour en base de la date de deniere connexion d'un utilisateur
|
|
|
|
|
|
* \return <0 si echec, >=0 si ok
|
|
|
|
|
|
*/
|
2006-06-07 00:54:23 +02:00
|
|
|
|
function update_last_login_date()
|
2005-08-11 20:50:40 +02:00
|
|
|
|
{
|
|
|
|
|
|
dolibarr_syslog ("Mise a jour date derniere connexion pour user->id=".$this->id);
|
2005-11-01 17:50:31 +01:00
|
|
|
|
|
|
|
|
|
|
$now=time();
|
|
|
|
|
|
|
2005-08-11 20:50:40 +02:00
|
|
|
|
$sql = "UPDATE ".MAIN_DB_PREFIX."user";
|
2006-01-04 20:03:32 +01:00
|
|
|
|
$sql.= " SET datelastaccess = ".$this->db->idate($now).",";
|
2005-12-03 22:20:18 +01:00
|
|
|
|
$sql.= " tms = tms"; // La date de derniere modif doit changer sauf pour la mise a jour de date de derniere connexion
|
2005-08-11 20:50:40 +02:00
|
|
|
|
$sql.= " WHERE rowid = ".$this->id;
|
|
|
|
|
|
$resql = $this->db->query($sql);
|
|
|
|
|
|
if ($resql)
|
|
|
|
|
|
{
|
2005-11-01 17:50:31 +01:00
|
|
|
|
$this->datelastaccess=$now;
|
2005-08-11 20:50:40 +02:00
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->error=$this->db->error();
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-04-24 23:28:24 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* \brief Change le mot de passe d'un utilisateur
|
|
|
|
|
|
* \param user Object user de l'utilisateur qui fait la modification
|
|
|
|
|
|
* \param password Nouveau mot de passe (g<EFBFBD>n<EFBFBD>r<EFBFBD> par defaut si non communiqu<EFBFBD>)
|
|
|
|
|
|
* \param isencrypted 0 ou 1 si il faut crypter le mot de passe en base (0 par d<EFBFBD>faut)
|
|
|
|
|
|
* \return string mot de passe, < 0 si erreur
|
|
|
|
|
|
*/
|
2005-07-02 00:09:12 +02:00
|
|
|
|
function password($user, $password='', $isencrypted = 0)
|
2002-12-18 19:02:06 +01:00
|
|
|
|
{
|
2005-02-03 16:04:53 +01:00
|
|
|
|
global $langs;
|
2005-07-02 00:09:12 +02:00
|
|
|
|
$longueurmotdepasse=8;
|
|
|
|
|
|
|
|
|
|
|
|
if (! $password)
|
|
|
|
|
|
{
|
|
|
|
|
|
$password = strtolower(substr(md5(uniqid(rand())),0,$longueurmotdepasse));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($isencrypted)
|
|
|
|
|
|
{
|
|
|
|
|
|
$sqlpass = crypt($password, "CRYPT_STD_DES");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
$sqlpass = $password;
|
|
|
|
|
|
}
|
2005-12-01 00:31:19 +01:00
|
|
|
|
$sql = "UPDATE ".MAIN_DB_PREFIX."user SET pass = '".addslashes($sqlpass)."'";
|
|
|
|
|
|
$sql.= " WHERE rowid = ".$this->id;
|
2005-07-02 00:09:12 +02:00
|
|
|
|
|
|
|
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
|
if ($result)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($this->db->affected_rows())
|
|
|
|
|
|
{
|
2006-04-24 23:28:24 +02:00
|
|
|
|
$this->pass=$password;
|
|
|
|
|
|
|
|
|
|
|
|
// Appel des triggers
|
|
|
|
|
|
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
|
|
|
|
|
|
$interface=new Interfaces($this->db);
|
|
|
|
|
|
$result=$interface->run_triggers('USER_NEW_PASSWORD',$this,$user,$lang,$conf);
|
|
|
|
|
|
if ($result < 0) $error++;
|
|
|
|
|
|
// Fin appel triggers
|
|
|
|
|
|
|
2005-07-02 00:09:12 +02:00
|
|
|
|
return $this->pass;
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
return -2;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
dolibarr_print_error($this->db);
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2002-12-18 19:02:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
2005-07-02 00:09:12 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* \brief Envoie mot de passe par mail
|
|
|
|
|
|
* \param user Object user de l'utilisateur qui fait l'envoi
|
|
|
|
|
|
* \param password Nouveau mot de passe
|
|
|
|
|
|
* \return int < 0 si erreur, > 0 si ok
|
|
|
|
|
|
*/
|
|
|
|
|
|
function send_password($user, $password='')
|
|
|
|
|
|
{
|
|
|
|
|
|
global $langs;
|
|
|
|
|
|
|
|
|
|
|
|
require_once DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php";
|
2005-02-04 12:08:01 +01:00
|
|
|
|
|
2005-07-02 00:09:12 +02:00
|
|
|
|
$subject = $langs->trans("SubjectNewPassword");
|
|
|
|
|
|
|
|
|
|
|
|
$mesg .= "Bonjour,\n\n";
|
|
|
|
|
|
$mesg .= "Votre mot de passe pour acc<63>der <20> Dolibarr a <20>t<EFBFBD> chang<6E> :\n\n";
|
|
|
|
|
|
$mesg .= $langs->trans("Login")." : $this->login\n";
|
|
|
|
|
|
$mesg .= $langs->trans("Password")." : $password\n\n";
|
|
|
|
|
|
|
|
|
|
|
|
$mesg .= "Adresse : http://".$_SERVER["HTTP_HOST"].DOL_URL_ROOT;
|
|
|
|
|
|
$mesg .= "\n\n";
|
|
|
|
|
|
$mesg .= "--\n";
|
|
|
|
|
|
$mesg.= $user->fullname;
|
2004-08-07 20:47:54 +02:00
|
|
|
|
|
2005-07-02 00:09:12 +02:00
|
|
|
|
$mailfile = new CMailFile($subject,$this->email,$conf->email_from,$mesg,array(),array(),array());
|
|
|
|
|
|
|
|
|
|
|
|
if ($mailfile->sendfile())
|
|
|
|
|
|
{
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2005-07-02 00:23:35 +02:00
|
|
|
|
$this->error=$langs->trans("ErrorFailedToSendPassword");
|
2005-07-02 00:09:12 +02:00
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2005-02-26 19:34:14 +01:00
|
|
|
|
|
2004-08-07 20:47:54 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* \brief Renvoie la derni<EFBFBD>re erreur fonctionnelle de manipulation de l'objet
|
|
|
|
|
|
* \return string chaine erreur
|
2002-12-18 19:02:06 +01:00
|
|
|
|
*/
|
2006-06-07 00:54:23 +02:00
|
|
|
|
function error()
|
2002-12-18 19:03:28 +01:00
|
|
|
|
{
|
2005-02-03 16:04:53 +01:00
|
|
|
|
return $this->error;
|
2002-12-18 19:03:28 +01:00
|
|
|
|
}
|
2005-02-26 19:34:14 +01:00
|
|
|
|
|
2002-12-18 19:02:06 +01:00
|
|
|
|
|
2005-01-14 15:18:45 +01:00
|
|
|
|
/**
|
2005-02-26 19:34:14 +01:00
|
|
|
|
* \brief Lecture des infos de click to dial
|
2005-01-14 15:18:45 +01:00
|
|
|
|
*/
|
2006-06-07 00:54:23 +02:00
|
|
|
|
function fetch_clicktodial()
|
2005-01-14 15:18:45 +01:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT login, pass, poste FROM ".MAIN_DB_PREFIX."user_clicktodial as u";
|
|
|
|
|
|
$sql .= " WHERE u.fk_user = ".$this->id;
|
|
|
|
|
|
|
|
|
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
|
|
|
|
|
|
|
if ($result)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($this->db->num_rows())
|
|
|
|
|
|
{
|
|
|
|
|
|
$obj = $this->db->fetch_object();
|
|
|
|
|
|
|
|
|
|
|
|
$this->clicktodial_login = $obj->login;
|
|
|
|
|
|
$this->clicktodial_password = $obj->pass;
|
|
|
|
|
|
$this->clicktodial_poste = $obj->poste;
|
|
|
|
|
|
|
|
|
|
|
|
if (strlen(trim($this->clicktodial_login)) &&
|
|
|
|
|
|
strlen(trim($this->clicktodial_password)) &&
|
|
|
|
|
|
strlen(trim($this->clicktodial_poste)))
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->clicktodial_enabled = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$this->db->free();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
print $this->db->error();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2005-02-26 19:34:14 +01:00
|
|
|
|
|
2005-01-14 15:18:45 +01:00
|
|
|
|
/**
|
2005-02-26 19:34:14 +01:00
|
|
|
|
* \brief Mise <EFBFBD> jour des infos de click to dial
|
2005-01-14 15:18:45 +01:00
|
|
|
|
*/
|
2006-06-07 00:54:23 +02:00
|
|
|
|
function update_clicktodial()
|
2005-01-14 15:18:45 +01:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."user_clicktodial";
|
|
|
|
|
|
$sql .= " WHERE fk_user = ".$this->id;
|
2002-12-18 19:02:06 +01:00
|
|
|
|
|
2005-01-14 15:18:45 +01:00
|
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
|
|
|
|
|
|
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."user_clicktodial";
|
|
|
|
|
|
$sql .= " (fk_user,login,pass,poste)";
|
|
|
|
|
|
$sql .= " VALUES (".$this->id;
|
|
|
|
|
|
$sql .= ", '". $this->clicktodial_login ."'";
|
|
|
|
|
|
$sql .= ", '". $this->clicktodial_password ."'";
|
|
|
|
|
|
$sql .= ", '". $this->clicktodial_poste."')";
|
|
|
|
|
|
|
|
|
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
|
|
|
|
|
|
|
if ($result)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
print $this->db->error();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2005-01-27 16:56:32 +01:00
|
|
|
|
|
2005-02-26 19:34:14 +01:00
|
|
|
|
|
2005-01-27 16:56:32 +01:00
|
|
|
|
/**
|
2005-02-26 19:34:14 +01:00
|
|
|
|
* \brief Ajoute l'utilisateur dans un groupe
|
|
|
|
|
|
* \param group id du groupe
|
2005-01-27 16:56:32 +01:00
|
|
|
|
*/
|
2006-06-07 00:54:23 +02:00
|
|
|
|
function SetInGroup($group)
|
2005-01-27 16:56:32 +01:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."usergroup_user";
|
|
|
|
|
|
$sql .= " WHERE fk_user = ".$this->id;
|
|
|
|
|
|
$sql .= " AND fk_usergroup = ".$group;
|
|
|
|
|
|
|
|
|
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
|
|
|
|
|
|
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."usergroup_user (fk_user, fk_usergroup)";
|
|
|
|
|
|
$sql .= " VALUES (".$this->id.",".$group.")";
|
|
|
|
|
|
|
|
|
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2005-02-26 19:34:14 +01:00
|
|
|
|
* \brief Retire l'utilisateur d'un groupe
|
|
|
|
|
|
* \param group id du groupe
|
2005-01-27 16:56:32 +01:00
|
|
|
|
*/
|
2006-06-07 00:54:23 +02:00
|
|
|
|
function RemoveFromGroup($group)
|
2005-01-27 16:56:32 +01:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."usergroup_user";
|
|
|
|
|
|
$sql .= " WHERE fk_user = ".$this->id;
|
|
|
|
|
|
$sql .= " AND fk_usergroup = ".$group;
|
|
|
|
|
|
|
|
|
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
|
}
|
2006-06-07 00:54:23 +02:00
|
|
|
|
|
2002-04-30 12:51:35 +02:00
|
|
|
|
}
|
2002-12-18 19:03:28 +01:00
|
|
|
|
|
2002-04-30 12:51:35 +02:00
|
|
|
|
?>
|