2002-04-30 12:51:35 +02:00
|
|
|
|
<?PHP
|
2004-05-05 11:38:03 +02:00
|
|
|
|
/* Copyright (c) 2002-2004 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
|
|
|
|
*/
|
|
|
|
|
|
|
2003-08-11 20:56:42 +02:00
|
|
|
|
class User
|
|
|
|
|
|
{
|
2002-04-30 12:51:35 +02:00
|
|
|
|
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;
|
2003-08-11 21:31:20 +02:00
|
|
|
|
$this->comm = 1;
|
|
|
|
|
|
$this->compta = 1;
|
2003-07-10 14:59:59 +02:00
|
|
|
|
$this->limite_liste = 0;
|
2002-07-29 12:26:12 +02:00
|
|
|
|
|
2004-06-27 20:16:53 +02:00
|
|
|
|
$this->all_permissions_are_loaded = 0;
|
2004-06-27 19:51:30 +02:00
|
|
|
|
|
2002-12-18 19:02:06 +01:00
|
|
|
|
return 1;
|
2002-04-30 12:51:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
2003-08-11 20:56:42 +02:00
|
|
|
|
Function addrights($rid)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (strlen($rid) == 2)
|
|
|
|
|
|
{
|
|
|
|
|
|
$topid = substr($rid,0,1);
|
|
|
|
|
|
$lowid = substr($rid,1,1);
|
2003-11-10 14:09:59 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (strlen($rid) == 3)
|
|
|
|
|
|
{
|
|
|
|
|
|
$topid = substr($rid,0,2);
|
|
|
|
|
|
$lowid = substr($rid,2,1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($lowid == 1)
|
|
|
|
|
|
{
|
2004-02-01 02:50:21 +01:00
|
|
|
|
$sql = "REPLACE INTO ".MAIN_DB_PREFIX."user_rights (fk_user, fk_id) VALUES ($this->id, $rid)";
|
2003-11-10 14:09:59 +01:00
|
|
|
|
if ($this->db->query($sql))
|
2003-08-11 20:56:42 +02:00
|
|
|
|
{
|
|
|
|
|
|
}
|
2003-11-10 14:09:59 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($lowid > 1)
|
|
|
|
|
|
{
|
2004-02-01 02:50:21 +01:00
|
|
|
|
$sql = "REPLACE INTO ".MAIN_DB_PREFIX."user_rights (fk_user, fk_id) VALUES ($this->id, $rid)";
|
2003-11-10 14:09:59 +01:00
|
|
|
|
if ($this->db->query($sql))
|
2003-08-11 20:56:42 +02:00
|
|
|
|
{
|
2003-11-10 14:09:59 +01:00
|
|
|
|
}
|
|
|
|
|
|
$nid = $topid . "1";
|
2004-02-01 02:50:21 +01:00
|
|
|
|
$sql = "REPLACE INTO ".MAIN_DB_PREFIX."user_rights (fk_user, fk_id) VALUES ($this->id, $nid)";
|
2003-11-10 14:09:59 +01:00
|
|
|
|
if ($this->db->query($sql))
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
print $sql;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($lowid == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
for ($i = 1 ; $i < 10 ; $i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
$nid = $topid . "$i";
|
2004-02-01 02:50:21 +01:00
|
|
|
|
$sql = "REPLACE INTO ".MAIN_DB_PREFIX."user_rights (fk_user, fk_id) VALUES ($this->id, $nid)";
|
2003-08-11 20:56:42 +02:00
|
|
|
|
if ($this->db->query($sql))
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
print $sql;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2003-11-10 14:09:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
2003-08-11 20:56:42 +02:00
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
Function delrights($rid)
|
|
|
|
|
|
{
|
2003-11-21 13:47:34 +01:00
|
|
|
|
|
2003-08-11 20:56:42 +02:00
|
|
|
|
if (strlen($rid) == 2)
|
|
|
|
|
|
{
|
|
|
|
|
|
$topid = substr($rid,0,1);
|
|
|
|
|
|
$lowid = substr($rid,1,1);
|
2003-11-21 13:47:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (strlen($rid) == 3)
|
|
|
|
|
|
{
|
|
|
|
|
|
$topid = substr($rid,0,2);
|
|
|
|
|
|
$lowid = substr($rid,2,1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($lowid > 1)
|
|
|
|
|
|
{
|
2004-02-01 02:50:21 +01:00
|
|
|
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."user_rights WHERE fk_user = $this->id AND fk_id=$rid";
|
2003-11-21 13:47:34 +01:00
|
|
|
|
if ($this->db->query($sql))
|
2003-08-11 20:56:42 +02:00
|
|
|
|
{
|
|
|
|
|
|
}
|
2003-11-21 13:47:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($lowid == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
$fid = $topid . "0";
|
|
|
|
|
|
$lid = $topid . "9";
|
2004-02-01 02:50:21 +01:00
|
|
|
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."user_rights WHERE fk_user = $this->id AND fk_id >= $fid AND fk_id <= $lid";
|
2003-11-21 13:47:34 +01:00
|
|
|
|
if ($this->db->query($sql))
|
2003-08-11 20:56:42 +02:00
|
|
|
|
{
|
2003-11-21 13:47:34 +01:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
print $sql;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($lowid == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
for ($i = 1 ; $i < 10 ; $i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
$nid = $topid . "$i";
|
2004-02-01 02:50:21 +01:00
|
|
|
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."user_rights WHERE fk_user = $this->id AND fk_id=$nid";
|
2003-08-11 20:56:42 +02:00
|
|
|
|
if ($this->db->query($sql))
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
print $sql;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2003-11-21 13:47:34 +01:00
|
|
|
|
|
2003-08-11 20:56:42 +02:00
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
Function getrights($module='')
|
|
|
|
|
|
{
|
2004-06-27 20:16:53 +02:00
|
|
|
|
if ($this->all_permissions_are_loaded) {
|
2004-06-27 19:51:30 +02:00
|
|
|
|
// Si les permissions ont d<>ja <20>t<EFBFBD> charg<72> pour ce user, on quitte
|
|
|
|
|
|
// Cela <20>vite de faire n fois le select quand la fonction est appel<65>e plusieurs fois
|
|
|
|
|
|
// pour charger les droits de diff<66>rents modules. On les charges tous la
|
|
|
|
|
|
// premi<6D>re fois, puis on ne fait plus rien.
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-02-01 02:50:21 +01:00
|
|
|
|
$sql = "SELECT fk_user, fk_id FROM ".MAIN_DB_PREFIX."user_rights WHERE fk_user= $this->id";
|
2003-08-12 15:27:08 +02:00
|
|
|
|
if ($this->db->query($sql))
|
|
|
|
|
|
{
|
|
|
|
|
|
$num = $this->db->num_rows();
|
|
|
|
|
|
$i = 0;
|
|
|
|
|
|
while ($i < $num)
|
|
|
|
|
|
{
|
2004-06-27 20:16:53 +02:00
|
|
|
|
$obj = $this->db->fetch_object();
|
2003-08-12 15:27:08 +02:00
|
|
|
|
|
|
|
|
|
|
if ($module == 'facture' or $module == '')
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($obj->fk_id == 11)
|
|
|
|
|
|
$this->rights->facture->lire = 1;
|
|
|
|
|
|
|
|
|
|
|
|
if ($obj->fk_id == 12)
|
|
|
|
|
|
$this->rights->facture->creer = 1;
|
|
|
|
|
|
|
|
|
|
|
|
if ($obj->fk_id == 13)
|
|
|
|
|
|
$this->rights->facture->modifier = 1;
|
|
|
|
|
|
|
|
|
|
|
|
if ($obj->fk_id == 14)
|
|
|
|
|
|
$this->rights->facture->valider = 1;
|
2003-08-11 20:56:42 +02:00
|
|
|
|
|
2003-08-12 15:27:08 +02:00
|
|
|
|
if ($obj->fk_id == 15)
|
|
|
|
|
|
$this->rights->facture->envoyer = 1;
|
2003-08-11 20:56:42 +02:00
|
|
|
|
|
2003-08-12 15:27:08 +02:00
|
|
|
|
if ($obj->fk_id == 16)
|
|
|
|
|
|
$this->rights->facture->paiement = 1;
|
2003-08-11 20:56:42 +02:00
|
|
|
|
|
2003-08-12 15:27:08 +02:00
|
|
|
|
if ($obj->fk_id == 19)
|
|
|
|
|
|
$this->rights->facture->supprimer = 1;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($module == 'propale' or $module == '')
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($obj->fk_id == 21)
|
|
|
|
|
|
$this->rights->propale->lire = 1;
|
|
|
|
|
|
|
|
|
|
|
|
if ($obj->fk_id == 22)
|
|
|
|
|
|
$this->rights->propale->creer = 1;
|
|
|
|
|
|
|
|
|
|
|
|
if ($obj->fk_id == 23)
|
|
|
|
|
|
$this->rights->propale->modifier = 1;
|
|
|
|
|
|
|
|
|
|
|
|
if ($obj->fk_id == 24)
|
|
|
|
|
|
$this->rights->propale->valider = 1;
|
|
|
|
|
|
|
|
|
|
|
|
if ($obj->fk_id == 25)
|
|
|
|
|
|
$this->rights->propale->envoyer = 1;
|
|
|
|
|
|
|
|
|
|
|
|
if ($obj->fk_id == 26)
|
|
|
|
|
|
$this->rights->propale->cloturer = 1;
|
|
|
|
|
|
|
|
|
|
|
|
if ($obj->fk_id == 27)
|
|
|
|
|
|
$this->rights->propale->supprimer = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($module == 'produit' or $module == '')
|
|
|
|
|
|
{
|
2003-08-11 20:56:42 +02:00
|
|
|
|
|
2003-08-12 15:27:08 +02:00
|
|
|
|
if ($obj->fk_id == 31)
|
|
|
|
|
|
$this->rights->produit->lire = 1;
|
2003-08-11 20:56:42 +02:00
|
|
|
|
|
2003-08-12 15:27:08 +02:00
|
|
|
|
if ($obj->fk_id == 32)
|
|
|
|
|
|
$this->rights->produit->creer = 1;
|
2003-08-11 20:56:42 +02:00
|
|
|
|
|
2003-08-12 15:27:08 +02:00
|
|
|
|
if ($obj->fk_id == 33)
|
|
|
|
|
|
$this->rights->produit->modifier = 1;
|
2003-08-11 20:56:42 +02:00
|
|
|
|
|
2003-08-12 15:27:08 +02:00
|
|
|
|
if ($obj->fk_id == 34)
|
|
|
|
|
|
$this->rights->produit->supprimer = 1;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($module == 'projet' or $module == '')
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
if ($obj->fk_id == 41)
|
|
|
|
|
|
$this->rights->projet->lire = 1;
|
2003-08-11 20:56:42 +02:00
|
|
|
|
|
2003-08-12 15:27:08 +02:00
|
|
|
|
if ($obj->fk_id == 42)
|
|
|
|
|
|
$this->rights->projet->creer = 1;
|
2003-08-11 20:56:42 +02:00
|
|
|
|
|
2003-08-12 15:27:08 +02:00
|
|
|
|
if ($obj->fk_id == 43)
|
|
|
|
|
|
$this->rights->projet->modifier = 1;
|
2003-08-11 20:56:42 +02:00
|
|
|
|
|
2003-08-12 15:27:08 +02:00
|
|
|
|
if ($obj->fk_id == 44)
|
|
|
|
|
|
$this->rights->projet->supprimer = 1;
|
2003-11-03 10:47:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($module == 'commande' or $module == '')
|
|
|
|
|
|
{
|
2003-08-12 15:27:08 +02:00
|
|
|
|
|
2003-11-03 10:47:23 +01:00
|
|
|
|
if ($obj->fk_id == 81)
|
|
|
|
|
|
$this->rights->commande->lire = 1;
|
|
|
|
|
|
|
|
|
|
|
|
if ($obj->fk_id == 82)
|
|
|
|
|
|
$this->rights->commande->creer = 1;
|
|
|
|
|
|
|
2003-11-03 11:37:26 +01:00
|
|
|
|
if ($obj->fk_id == 84)
|
|
|
|
|
|
$this->rights->commande->valider = 1;
|
|
|
|
|
|
|
2003-11-03 10:47:23 +01:00
|
|
|
|
if ($obj->fk_id == 89)
|
|
|
|
|
|
$this->rights->commande->supprimer = 1;
|
2003-09-15 17:31:26 +02:00
|
|
|
|
}
|
2003-11-03 10:47:23 +01:00
|
|
|
|
|
2003-11-10 11:50:14 +01:00
|
|
|
|
if ($module == 'expedition' or $module == '')
|
|
|
|
|
|
{
|
|
|
|
|
|
|
2003-11-19 15:40:44 +01:00
|
|
|
|
if ($obj->fk_id == 101)
|
2003-11-10 11:50:14 +01:00
|
|
|
|
$this->rights->expedition->lire = 1;
|
|
|
|
|
|
|
2003-11-19 15:40:44 +01:00
|
|
|
|
if ($obj->fk_id == 102)
|
2003-11-10 11:50:14 +01:00
|
|
|
|
$this->rights->expedition->creer = 1;
|
|
|
|
|
|
|
2003-11-19 15:40:44 +01:00
|
|
|
|
if ($obj->fk_id == 104)
|
2003-11-10 11:50:14 +01:00
|
|
|
|
$this->rights->expedition->valider = 1;
|
|
|
|
|
|
|
2003-11-19 15:40:44 +01:00
|
|
|
|
if ($obj->fk_id == 109)
|
2003-11-10 11:50:14 +01:00
|
|
|
|
$this->rights->expedition->supprimer = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-09-15 17:31:26 +02:00
|
|
|
|
if ($module == 'adherent' or $module == '')
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
if ($obj->fk_id == 71)
|
|
|
|
|
|
$this->rights->adherent->lire = 1;
|
|
|
|
|
|
|
|
|
|
|
|
if ($obj->fk_id == 72)
|
|
|
|
|
|
$this->rights->adherent->creer = 1;
|
|
|
|
|
|
|
|
|
|
|
|
if ($obj->fk_id == 73)
|
|
|
|
|
|
$this->rights->adherent->modifier = 1;
|
|
|
|
|
|
|
|
|
|
|
|
if ($obj->fk_id == 74)
|
|
|
|
|
|
$this->rights->adherent->supprimer = 1;
|
|
|
|
|
|
|
2003-08-12 15:27:08 +02:00
|
|
|
|
}
|
2003-11-05 10:59:16 +01:00
|
|
|
|
|
|
|
|
|
|
if ($module == 'compta' or $module == '')
|
|
|
|
|
|
{
|
2004-06-27 19:51:30 +02:00
|
|
|
|
if ($obj->fk_id == 91)
|
|
|
|
|
|
$this->rights->compta->charges->lire = 1;
|
|
|
|
|
|
|
2003-11-08 20:05:47 +01:00
|
|
|
|
if ($obj->fk_id == 92)
|
2004-06-27 19:51:30 +02:00
|
|
|
|
$this->rights->compta->charges->creer = 1;
|
2004-06-27 20:16:53 +02:00
|
|
|
|
|
2003-11-08 20:05:47 +01:00
|
|
|
|
if ($obj->fk_id == 93)
|
2004-06-27 19:51:30 +02:00
|
|
|
|
$this->rights->compta->charges->supprimer = 1;
|
|
|
|
|
|
|
|
|
|
|
|
if ($obj->fk_id == 95)
|
|
|
|
|
|
$this->rights->compta->resultat->lire = 1;
|
|
|
|
|
|
|
2003-11-21 13:47:34 +01:00
|
|
|
|
}
|
2004-06-27 19:51:30 +02:00
|
|
|
|
|
2003-11-21 13:47:34 +01:00
|
|
|
|
if ($module == 'banque' or $module == '')
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($obj->fk_id == 111)
|
|
|
|
|
|
$this->rights->banque->lire = 1;
|
|
|
|
|
|
|
|
|
|
|
|
if ($obj->fk_id == 112)
|
|
|
|
|
|
$this->rights->banque->modifier = 1;
|
|
|
|
|
|
|
|
|
|
|
|
if ($obj->fk_id == 113)
|
|
|
|
|
|
$this->rights->banque->configurer = 1;
|
2004-07-13 18:10:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($module == 'societe' or $module == '')
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($obj->fk_id == 121)
|
|
|
|
|
|
$this->rights->societe->lire = 1;
|
2003-11-08 20:05:47 +01:00
|
|
|
|
|
2004-07-13 18:10:32 +02:00
|
|
|
|
if ($obj->fk_id == 122)
|
|
|
|
|
|
$this->rights->societe->creer = 1;
|
|
|
|
|
|
|
|
|
|
|
|
if ($obj->fk_id == 129)
|
|
|
|
|
|
$this->rights->societe->supprimer = 1;
|
2003-11-05 10:59:16 +01:00
|
|
|
|
}
|
2004-07-13 18:10:32 +02:00
|
|
|
|
|
2003-08-12 15:27:08 +02:00
|
|
|
|
$i++;
|
2004-06-27 20:16:53 +02:00
|
|
|
|
}
|
2004-06-27 19:51:30 +02:00
|
|
|
|
$this->db->free();
|
|
|
|
|
|
|
2004-06-27 20:16:53 +02:00
|
|
|
|
if ($module == '') {
|
|
|
|
|
|
// Si module etait non defini, alors on a tout charg<72>, on peut donc consid<69>rer
|
|
|
|
|
|
// que les droits sont cach<63>s (car tous charg<72>s) pour cet instance de user
|
|
|
|
|
|
$this->all_permissions_are_loaded=1;
|
|
|
|
|
|
}
|
2003-08-11 20:56:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
print $this->db->error();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
2002-12-18 19:02:06 +01:00
|
|
|
|
Function fetch($login='')
|
|
|
|
|
|
{
|
2004-02-27 15:24:42 +01: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";
|
2004-02-01 02:50:21 +01:00
|
|
|
|
//$sql .= " FROM ".MAIN_DB_PREFIX."user as u";
|
|
|
|
|
|
$sql = "SELECT * FROM ".MAIN_DB_PREFIX."user as u";
|
2003-08-11 20:56:42 +02:00
|
|
|
|
if ($this->id)
|
|
|
|
|
|
{
|
|
|
|
|
|
$sql .= " WHERE u.rowid = $this->id";
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
$sql .= " WHERE u.login = '$login'";
|
|
|
|
|
|
}
|
2004-02-27 15:24:42 +01:00
|
|
|
|
|
|
|
|
|
|
$result = $this->db->query($sql);
|
2002-04-30 12:51:35 +02:00
|
|
|
|
|
2004-02-27 15:24:42 +01:00
|
|
|
|
if ($result)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($this->db->num_rows())
|
|
|
|
|
|
{
|
|
|
|
|
|
$obj = $this->db->fetch_object($result , 0);
|
|
|
|
|
|
|
|
|
|
|
|
$this->id = $obj->rowid;
|
|
|
|
|
|
$this->nom = stripslashes($obj->name);
|
|
|
|
|
|
$this->prenom = stripslashes($obj->firstname);
|
|
|
|
|
|
|
|
|
|
|
|
$this->note = stripslashes($obj->note);
|
|
|
|
|
|
|
|
|
|
|
|
$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->contact_id = $obj->fk_socpeople;
|
|
|
|
|
|
|
|
|
|
|
|
$this->login = $obj->login;
|
|
|
|
|
|
$this->pass = $obj->pass;
|
|
|
|
|
|
$this->webcal_login = $obj->webcal_login;
|
|
|
|
|
|
|
|
|
|
|
|
$this->societe_id = $obj->fk_societe;
|
2004-05-05 11:38:03 +02:00
|
|
|
|
$this->egroupware_id = $obj->egroupware_id;
|
2004-02-27 15:24:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
$this->db->free();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
print $this->db->error();
|
|
|
|
|
|
}
|
2002-12-18 19:02:06 +01:00
|
|
|
|
|
2004-02-27 15:24:42 +01:00
|
|
|
|
$sql = "SELECT param, value FROM ".MAIN_DB_PREFIX."user_param";
|
|
|
|
|
|
$sql .= " WHERE fk_user = ".$this->id;
|
2004-03-28 20:57:11 +02:00
|
|
|
|
$sql .= " AND page = '".$_SERVER["SCRIPT_URL"]."'";
|
2003-01-15 00:50:55 +01:00
|
|
|
|
|
2004-02-27 15:24:42 +01:00
|
|
|
|
if ( $this->db->query($sql) );
|
|
|
|
|
|
{
|
|
|
|
|
|
$num = $this->db->num_rows();
|
|
|
|
|
|
$i = 0;
|
|
|
|
|
|
$page_param_url = '';
|
|
|
|
|
|
$this->page_param = array();
|
|
|
|
|
|
while ($i < $num)
|
|
|
|
|
|
{
|
|
|
|
|
|
$obj = $this->db->fetch_object($i);
|
|
|
|
|
|
$this->page_param[$obj->param] = $obj->value;
|
|
|
|
|
|
$page_param_url .= $obj->param . "=".$obj->value."&";
|
|
|
|
|
|
$i++;
|
|
|
|
|
|
}
|
|
|
|
|
|
$this->page_param_url = $page_param_url;
|
|
|
|
|
|
}
|
2003-08-11 20:56:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
2002-04-30 12:51:35 +02:00
|
|
|
|
}
|
2002-12-18 19:02:06 +01:00
|
|
|
|
/*
|
|
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
2003-08-11 20:56:42 +02:00
|
|
|
|
Function delete()
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($this->contact_id)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
2004-02-01 02:50:21 +01:00
|
|
|
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."user WHERE rowid = $this->id";
|
2003-08-11 20:56:42 +02:00
|
|
|
|
|
|
|
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
|
|
2004-02-01 02:50:21 +01:00
|
|
|
|
$sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET fk_user = 0 WHERE idp = $this->contact_id";
|
2003-08-11 20:56:42 +02:00
|
|
|
|
|
|
|
|
|
|
if ($this->db->query($sql))
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2004-02-01 02:50:21 +01:00
|
|
|
|
$sql = "UPDATE ".MAIN_DB_PREFIX."user SET login = '' WHERE rowid = $this->id";
|
2003-08-11 20:56:42 +02:00
|
|
|
|
|
|
|
|
|
|
$result = $this->db->query($sql);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-02-01 02:50:21 +01:00
|
|
|
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."user_rights WHERE fk_user = $this->id";
|
2003-08-11 20:56:42 +02:00
|
|
|
|
|
|
|
|
|
|
if ($this->db->query($sql))
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2003-11-19 15:40:44 +01:00
|
|
|
|
/**
|
|
|
|
|
|
* Cr<EFBFBD><EFBFBD> l'utilisateur
|
2003-08-11 20:56:42 +02:00
|
|
|
|
*
|
|
|
|
|
|
*/
|
2002-12-19 21:26:51 +01:00
|
|
|
|
Function create()
|
|
|
|
|
|
{
|
2004-02-01 02:50:21 +01:00
|
|
|
|
$sql = "SELECT login FROM ".MAIN_DB_PREFIX."user WHERE login ='$this->login'";
|
2002-12-19 21:26:51 +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
|
|
|
|
|
|
{
|
2004-02-01 02:50:21 +01:00
|
|
|
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."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();
|
2003-08-11 20:56:42 +02:00
|
|
|
|
$this->set_default_rights();
|
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
|
|
|
|
}
|
2003-11-19 15:40:44 +01:00
|
|
|
|
/**
|
2002-12-19 21:26:51 +01:00
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
2003-08-11 20:56:42 +02:00
|
|
|
|
Function create_from_contact($contact)
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->nom = $contact->nom;
|
|
|
|
|
|
$this->prenom = $contact->prenom;
|
|
|
|
|
|
$this->email = $contact->email;
|
|
|
|
|
|
|
|
|
|
|
|
$this->login = strtolower(substr($contact->prenom, 0, 3)) . strtolower(substr($contact->nom, 0, 3));
|
|
|
|
|
|
|
2004-02-01 02:50:21 +01:00
|
|
|
|
$sql = "SELECT login FROM ".MAIN_DB_PREFIX."user WHERE login ='$this->login'";
|
2003-08-11 20:56:42 +02: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
|
|
|
|
|
|
{
|
2004-02-01 02:50:21 +01:00
|
|
|
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."user (datec, login, fk_socpeople, fk_societe)";
|
2003-08-11 20:56:42 +02:00
|
|
|
|
$sql .= " VALUES (now(),'$this->login',$contact->id, $contact->societeid);";
|
|
|
|
|
|
if ($this->db->query($sql))
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($this->db->affected_rows())
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->id = $this->db->last_insert_id();
|
|
|
|
|
|
$this->admin = 0;
|
|
|
|
|
|
$this->update();
|
|
|
|
|
|
|
2004-02-01 02:50:21 +01:00
|
|
|
|
$sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET fk_user = $this->id WHERE idp = $contact->id";
|
2003-08-11 20:56:42 +02:00
|
|
|
|
$this->db->query($sql);
|
|
|
|
|
|
|
|
|
|
|
|
$this->set_default_rights();
|
|
|
|
|
|
|
|
|
|
|
|
return $this->id;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
print $this->db->error();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
print $this->db->error();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2003-11-19 15:40:44 +01:00
|
|
|
|
/**
|
|
|
|
|
|
* Affectation des permissions par d<EFBFBD>faut
|
2003-08-11 20:56:42 +02:00
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
Function set_default_rights()
|
|
|
|
|
|
{
|
2004-02-01 02:50:21 +01:00
|
|
|
|
$sql = "SELECT id FROM ".MAIN_DB_PREFIX."rights_def WHERE bydefault = 1";
|
2003-08-11 20:56:42 +02:00
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
{
|
2004-02-01 02:50:21 +01:00
|
|
|
|
$sql = "REPLACE INTO ".MAIN_DB_PREFIX."user_rights (fk_user, fk_id) VALUES ($this->id, $rd[$i])";
|
2003-08-11 20:56:42 +02:00
|
|
|
|
if ($this->db->query($sql))
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
$i++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2003-11-19 15:40:44 +01:00
|
|
|
|
/**
|
|
|
|
|
|
* Mise <EFBFBD> jour
|
2003-08-11 20:56:42 +02:00
|
|
|
|
*
|
|
|
|
|
|
*/
|
2002-12-18 19:02:06 +01:00
|
|
|
|
Function update()
|
|
|
|
|
|
{
|
2004-02-01 02:50:21 +01:00
|
|
|
|
$sql = "SELECT login FROM ".MAIN_DB_PREFIX."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
|
|
|
|
|
|
{
|
2003-08-11 20:56:42 +02:00
|
|
|
|
if (!strlen($this->code))
|
|
|
|
|
|
$this->code = $this->login;
|
2002-12-18 19:02:06 +01:00
|
|
|
|
|
2004-02-01 02:50:21 +01:00
|
|
|
|
$sql = "UPDATE ".MAIN_DB_PREFIX."user SET ";
|
2002-12-18 19:02:06 +01:00
|
|
|
|
$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'";
|
2003-08-11 21:31:20 +02:00
|
|
|
|
$sql .= ", module_comm = 1";
|
|
|
|
|
|
$sql .= ", module_compta = 1";
|
2003-08-11 20:56:42 +02:00
|
|
|
|
$sql .= ", code = '$this->code'";
|
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
|
|
|
|
|
|
{
|
2003-08-11 20:56:42 +02:00
|
|
|
|
print $this->db->error() ."<br>$sql";
|
2002-12-18 19:02:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Change le mot de passe et l'envoie par mail
|
|
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
2003-06-20 16:30:08 +02: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)
|
|
|
|
|
|
{
|
2003-06-20 16:30:08 +02:00
|
|
|
|
$password = strtolower(substr(md5(uniqid(rand())),0,6));
|
2002-12-19 21:26:51 +01:00
|
|
|
|
}
|
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;
|
2004-02-01 02:50:21 +01:00
|
|
|
|
$sql = "UPDATE ".MAIN_DB_PREFIX."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())
|
|
|
|
|
|
{
|
2004-02-08 14:03:18 +01:00
|
|
|
|
$mesg = "Votre mot de passe pour acc<63>der <20> Dolibarr a <20>t<EFBFBD> chang<6E> :\n\n";
|
|
|
|
|
|
$mesg .= "Login : $this->login\n";
|
|
|
|
|
|
$mesg .= "Mot de passe : $password\n\n";
|
2004-03-28 20:57:11 +02:00
|
|
|
|
$mesg .= "Adresse : ".substr($_SERVER["SCRIPT_URI"],0,strlen($_SERVER["SCRIPT_URI"]) - 14);
|
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
|
|
|
|
?>
|