2002-04-30 12:51:35 +02:00
|
|
|
|
<?PHP
|
2003-01-15 00:50:55 +01:00
|
|
|
|
/* Copyright (c) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
2003-02-20 18:40:42 +01:00
|
|
|
|
* Copyright (c) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
|
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
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
class User {
|
|
|
|
|
|
var $db;
|
|
|
|
|
|
|
|
|
|
|
|
var $id;
|
|
|
|
|
|
var $fullname;
|
|
|
|
|
|
var $nom;
|
|
|
|
|
|
var $prenom;
|
2003-01-15 00:50:55 +01:00
|
|
|
|
var $note;
|
2002-04-30 12:51:35 +02:00
|
|
|
|
var $code;
|
|
|
|
|
|
var $email;
|
2002-05-04 23:28:42 +02:00
|
|
|
|
var $admin;
|
2002-05-06 21:10:48 +02:00
|
|
|
|
var $login;
|
2003-02-20 18:40:42 +01:00
|
|
|
|
var $pass;
|
2002-04-30 12:51:35 +02:00
|
|
|
|
var $comm;
|
|
|
|
|
|
var $compta;
|
2002-05-06 21:10:48 +02:00
|
|
|
|
var $webcal_login;
|
2002-12-18 19:02:06 +01:00
|
|
|
|
var $errorstr;
|
2002-07-29 12:26:12 +02:00
|
|
|
|
var $limite_liste;
|
|
|
|
|
|
|
2002-12-18 19:02:06 +01:00
|
|
|
|
Function User($DB, $id=0)
|
|
|
|
|
|
{
|
2002-04-30 12:51:35 +02:00
|
|
|
|
|
2002-12-18 19:02:06 +01:00
|
|
|
|
$this->db = $DB;
|
|
|
|
|
|
$this->id = $id;
|
2002-04-30 12:51:35 +02:00
|
|
|
|
|
2002-12-18 19:02:06 +01:00
|
|
|
|
$this->limite_liste = 20;
|
2002-07-29 12:26:12 +02:00
|
|
|
|
|
2002-12-18 19:02:06 +01:00
|
|
|
|
return 1;
|
2002-04-30 12:51:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2002-12-18 19:02:06 +01:00
|
|
|
|
Function fetch($login='')
|
|
|
|
|
|
{
|
2002-04-30 12:51:35 +02:00
|
|
|
|
|
2003-02-20 18:40:42 +01:00
|
|
|
|
//$sql = "SELECT u.rowid, u.name, u.firstname, u.email, u.code, u.admin, u.module_comm, u.module_compta, u.login, u.pass, u.webcal_login, u.note";
|
|
|
|
|
|
//$sql .= " FROM llx_user as u";
|
|
|
|
|
|
$sql = "SELECT * FROM llx_user as u";
|
2002-05-01 02:22:13 +02:00
|
|
|
|
if ($this->id) {
|
|
|
|
|
|
$sql .= " WHERE u.rowid = $this->id";
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$sql .= " WHERE u.login = '$login'";
|
|
|
|
|
|
}
|
2002-04-30 12:51:35 +02:00
|
|
|
|
|
|
|
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
|
|
2002-12-18 19:02:06 +01:00
|
|
|
|
if ($result)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($this->db->num_rows())
|
|
|
|
|
|
{
|
|
|
|
|
|
$obj = $this->db->fetch_object($result , 0);
|
|
|
|
|
|
|
|
|
|
|
|
$this->id = $obj->rowid;
|
2003-01-15 00:50:55 +01:00
|
|
|
|
$this->nom = stripslashes($obj->name);
|
|
|
|
|
|
$this->prenom = stripslashes($obj->firstname);
|
2002-12-18 19:02:06 +01:00
|
|
|
|
|
2003-01-15 00:50:55 +01:00
|
|
|
|
$this->note = stripslashes($obj->note);
|
|
|
|
|
|
|
2002-12-18 19:02:06 +01:00
|
|
|
|
$this->fullname = $this->prenom . ' ' . $this->nom;
|
|
|
|
|
|
$this->admin = $obj->admin;
|
|
|
|
|
|
$this->webcal_login = $obj->webcal_login;
|
|
|
|
|
|
$this->code = $obj->code;
|
|
|
|
|
|
$this->email = $obj->email;
|
|
|
|
|
|
|
|
|
|
|
|
$this->comm = $obj->module_comm;
|
|
|
|
|
|
$this->compta = $obj->module_compta;
|
|
|
|
|
|
|
|
|
|
|
|
$this->login = $obj->login;
|
|
|
|
|
|
$this->pass = $obj->pass;
|
|
|
|
|
|
$this->webcal_login = $obj->webcal_login;
|
|
|
|
|
|
|
2003-03-23 15:47:25 +01:00
|
|
|
|
$this->societe_id = $obj->fk_societe;
|
2002-12-18 19:02:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
$this->db->free();
|
2002-05-06 21:10:48 +02:00
|
|
|
|
|
2002-04-30 12:51:35 +02:00
|
|
|
|
}
|
2002-12-18 19:02:06 +01:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
print $this->db->error();
|
|
|
|
|
|
}
|
2002-04-30 12:51:35 +02:00
|
|
|
|
}
|
2002-12-18 19:02:06 +01:00
|
|
|
|
/*
|
|
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
2002-12-19 21:26:51 +01:00
|
|
|
|
Function create()
|
|
|
|
|
|
{
|
|
|
|
|
|
$sql = "SELECT login FROM llx_user WHERE login ='$this->login'";
|
|
|
|
|
|
|
|
|
|
|
|
if ($this->db->query($sql))
|
|
|
|
|
|
{
|
|
|
|
|
|
$num = $this->db->num_rows();
|
|
|
|
|
|
$this->db->free();
|
|
|
|
|
|
|
|
|
|
|
|
if ($num)
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->errorstr = "Ce login existe d<>j<EFBFBD>";
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2002-12-21 19:00:53 +01:00
|
|
|
|
$sql = "INSERT INTO llx_user (datec, login) values (now(),'$this->login');";
|
2002-12-19 21:26:51 +01:00
|
|
|
|
if ($this->db->query($sql))
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($this->db->affected_rows())
|
|
|
|
|
|
{
|
2002-12-21 18:35:17 +01:00
|
|
|
|
$this->id = $this->db->last_insert_id();
|
|
|
|
|
|
$this->update();
|
2002-12-23 00:22:56 +01:00
|
|
|
|
return $this->id;
|
2002-12-19 21:26:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2002-12-23 00:22:56 +01:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
print $this->db->error();
|
|
|
|
|
|
}
|
2002-12-19 21:26:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2002-12-23 00:22:56 +01:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
print $this->db->error();
|
|
|
|
|
|
}
|
2002-12-19 21:26:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2002-12-18 19:02:06 +01:00
|
|
|
|
Function update()
|
|
|
|
|
|
{
|
2002-12-19 23:43:36 +01:00
|
|
|
|
$sql = "SELECT login FROM llx_user WHERE login ='$this->login' AND rowid <> $this->id";
|
2002-12-18 19:02:06 +01:00
|
|
|
|
|
|
|
|
|
|
if ($this->db->query($sql))
|
|
|
|
|
|
{
|
|
|
|
|
|
$num = $this->db->num_rows();
|
|
|
|
|
|
$this->db->free();
|
|
|
|
|
|
|
|
|
|
|
|
if ($num)
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->errorstr = "Ce login existe d<>j<EFBFBD>";
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
$sql = "UPDATE llx_user SET ";
|
|
|
|
|
|
$sql .= " name = '$this->nom'";
|
|
|
|
|
|
$sql .= ", firstname = '$this->prenom'";
|
|
|
|
|
|
$sql .= ", login = '$this->login'";
|
|
|
|
|
|
$sql .= ", email = '$this->email'";
|
2002-12-21 19:00:53 +01:00
|
|
|
|
$sql .= ", admin = $this->admin";
|
2003-02-20 18:40:42 +01:00
|
|
|
|
$sql .= ", webcal_login = '$this->webcal_login'";
|
|
|
|
|
|
$sql .= ", module_comm = $this->comm";
|
|
|
|
|
|
$sql .= ", module_compta = $this->compta";
|
2003-01-15 00:50:55 +01:00
|
|
|
|
$sql .= ", note = '$this->note'";
|
2002-12-18 19:02:06 +01:00
|
|
|
|
$sql .= " WHERE rowid = $this->id";
|
|
|
|
|
|
|
|
|
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
|
|
|
|
|
|
|
if ($result)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($this->db->affected_rows())
|
|
|
|
|
|
{
|
|
|
|
|
|
return 1;
|
2002-12-21 18:59:37 +01:00
|
|
|
|
}
|
2002-12-18 19:02:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
print $this->db->error();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Change le mot de passe et l'envoie par mail
|
|
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
2002-12-23 00:22:56 +01:00
|
|
|
|
Function password($password='',$password_encrypted=0)
|
2002-12-18 19:02:06 +01:00
|
|
|
|
{
|
2002-12-19 21:26:51 +01:00
|
|
|
|
if (! $password)
|
|
|
|
|
|
{
|
|
|
|
|
|
$password = substr(crypt(uniqid("")),0,8);
|
|
|
|
|
|
}
|
2002-12-18 19:02:06 +01:00
|
|
|
|
|
2002-12-23 00:22:56 +01:00
|
|
|
|
if ($password_encrypted)
|
2002-12-21 18:55:23 +01:00
|
|
|
|
{
|
|
|
|
|
|
$sqlpass = crypt($password, "CRYPT_STD_DES");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
$sqlpass = $password;
|
|
|
|
|
|
}
|
2003-02-20 18:40:42 +01:00
|
|
|
|
$this->pass=$password;
|
2002-12-21 18:55:23 +01:00
|
|
|
|
$sql = "UPDATE llx_user SET pass = '".$sqlpass."'";
|
2002-12-18 19:02:06 +01:00
|
|
|
|
$sql .= " WHERE rowid = $this->id";
|
|
|
|
|
|
|
|
|
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
|
|
|
|
|
|
|
if ($result)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($this->db->affected_rows())
|
|
|
|
|
|
{
|
2002-12-30 16:02:46 +01:00
|
|
|
|
$mesg = "Login : $this->login\nMot de passe : $password\n";
|
2003-03-27 16:49:33 +01:00
|
|
|
|
$mesg .= "URL : http://". $GLOBALS["HTTP_HOST"];
|
2002-12-18 19:02:06 +01:00
|
|
|
|
if (mail($this->email, "Mot de passe Dolibarr", $mesg))
|
|
|
|
|
|
{
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
print $this->db->error();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/*
|
2002-12-18 19:03:28 +01:00
|
|
|
|
* Renvoie la cha<EFBFBD>ne de caract<EFBFBD>re d<EFBFBD>crivant l'erreur
|
2002-12-18 19:02:06 +01:00
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
2002-12-18 19:03:28 +01:00
|
|
|
|
Function error()
|
|
|
|
|
|
{
|
|
|
|
|
|
return $this->errorstr;
|
|
|
|
|
|
}
|
2002-12-18 19:02:06 +01: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
|
|
|
|
?>
|