diff --git a/htdocs/actioncomm.class.php b/htdocs/actioncomm.class.php index 21cdfcd0bed..569fa169c04 100644 --- a/htdocs/actioncomm.class.php +++ b/htdocs/actioncomm.class.php @@ -88,7 +88,7 @@ class ActionComm * \brief Ajout d'une action en base * \param user auteur de la creation de l'action * \param notrigger 1 ne declenche pas les triggers, 0 sinon - * \return int id de l'action cr��e, < 0 si erreur + * \return int id de l'action creee, < 0 si erreur */ function add($user,$notrigger=0) { @@ -159,7 +159,7 @@ class ActionComm $sql.= ($this->durationa >= 0?"'".$this->durationa."'":"null").","; $sql.= "'".$this->type_id."', '".$this->societe->id."' ,'".addslashes($this->note)."',"; $sql.= ($this->contact->id > 0?"'".$this->contact->id."'":"null").","; - $sql.= "'".$user->id."',"; + $sql.= ($user->id > 0 ? "'".$user->id."'":"null").","; $sql.= ($this->usertodo->id > 0?"'".$this->usertodo->id."'":"null").","; $sql.= ($this->userdone->id > 0?"'".$this->userdone->id."'":"null").","; $sql.= "'".addslashes($this->label)."','".$this->percentage."','".$this->priority."','".$this->punctual."',"; diff --git a/htdocs/comm/action/fiche.php b/htdocs/comm/action/fiche.php index 6db1a2711fc..1d4abc63dc5 100644 --- a/htdocs/comm/action/fiche.php +++ b/htdocs/comm/action/fiche.php @@ -741,7 +741,8 @@ if ($_GET["id"]) // Input by print ''.$langs->trans("ActionAskedBy").''; - print $act->author->getNomUrl(1); + if ($act->author->id > 0) print $act->author->getNomUrl(1); + else print ' '; print ''; // Affecte a diff --git a/htdocs/contact.class.php b/htdocs/contact.class.php index 8c8b6225dd2..0af9830ebec 100644 --- a/htdocs/contact.class.php +++ b/htdocs/contact.class.php @@ -80,9 +80,9 @@ class Contact extends CommonObject } /** - * \brief Ajout d'un contact en base - * \param user Utilisateur qui effectue l'ajout - * \return int <0 si ko, >0 si ok + * \brief Add a contact in database + * \param user Object user that create + * \return int <0 if KO, >0 if OK */ function create($user) { @@ -98,7 +98,7 @@ class Contact extends CommonObject if ($this->socid > 0) $sql.= " ".$this->socid.","; else $sql.= "null,"; $sql.= "'".addslashes($this->name)."',"; - $sql.= $user->id.","; + $sql.= " ".($user->id > 0 ? "'".$user->id."'":"null").","; $sql.= $this->priv; $sql.= ")"; @@ -178,7 +178,7 @@ class Contact extends CommonObject $sql .= ", phone_mobile = '".addslashes($this->phone_mobile)."'"; $sql .= ", jabberid = '".addslashes($this->jabberid)."'"; $sql .= ", priv = '".$this->priv."'"; - if ($user) $sql .= ", fk_user_modif=".$user->id; + $sql .= ", fk_user_modif=".($user->id > 0 ? "'".$user->id."'":"null"); $sql .= " WHERE rowid=".$id; dolibarr_syslog("Contact::update sql=".$sql,LOG_DEBUG); diff --git a/htdocs/societe.class.php b/htdocs/societe.class.php index 3ca88c482e4..6ab911cbf24 100644 --- a/htdocs/societe.class.php +++ b/htdocs/societe.class.php @@ -22,25 +22,25 @@ */ /** - \file htdocs/societe.class.php - \ingroup societe - \brief Fichier de la classe des societes - \version $Id$ -*/ + \file htdocs/societe.class.php + \ingroup societe + \brief Fichier de la classe des societes + \version $Id$ + */ require_once(DOL_DOCUMENT_ROOT."/commonobject.class.php"); /** - \class Societe - \brief Classe permettant la gestion des societes -*/ + \class Societe + \brief Classe permettant la gestion des societes + */ class Societe extends CommonObject { var $db; var $error; var $errors=array(); - var $table_element = 'societe'; + var $table_element = 'societe'; var $id; var $nom; @@ -63,171 +63,174 @@ class Societe extends CommonObject var $siret; // IdProf2 var $ape; // IdProf3 var $idprof4; // IdProf4 - + var $prefix_comm; - + var $tva_assuj; var $tva_intra; - + var $capital; var $typent_id; var $effectif_id; var $forme_juridique_code; var $forme_juridique; - + var $remise_client; var $mode_reglement; var $cond_reglement; - + var $client; var $prospect; var $fournisseur; - + var $prefixCustomerIsRequired; var $prefixSupplierIsRequired; var $code_client; var $code_fournisseur; var $code_compta; var $code_compta_fournisseur; - + var $note; - //! code statut prospect - var $stcomm_id; - var $statut_commercial; - - var $price_level; - - var $commercial_id; //Id du commercial affecte + //! code statut prospect + var $stcomm_id; + var $statut_commercial; + + var $price_level; + + var $commercial_id; //Id du commercial affecte - /** - * \brief Constructeur de la classe - * \param DB handler acc�s base de donn�es - * \param id id societe (0 par defaut) - */ - function Societe($DB, $id=0) - { - global $conf; - - $this->db = $DB; + /** + * \brief Constructeur de la classe + * \param DB handler acc�s base de donn�es + * \param id id societe (0 par defaut) + */ + function Societe($DB, $id=0) + { + global $conf; - $this->id = $id; - $this->client = 0; - $this->prospect = 0; - $this->fournisseur = 0; - $this->typent_id = 0; - $this->effectif_id = 0; - $this->forme_juridique_code = 0; - $this->prefixCustomerIsRequired = 0; - $this->prefixSupplierIsRequired = 0; - $this->tva_assuj = 1; + $this->db = $DB; - return 1; - } + $this->id = $id; + $this->client = 0; + $this->prospect = 0; + $this->fournisseur = 0; + $this->typent_id = 0; + $this->effectif_id = 0; + $this->forme_juridique_code = 0; + $this->prefixCustomerIsRequired = 0; + $this->prefixSupplierIsRequired = 0; + $this->tva_assuj = 1; - /** - * \brief Cree la societe en base - * \param user Objet utilisateur qui demande la cr�ation - * \return int 0 si ok, < 0 si erreur - */ + return 1; + } - function create($user='') - { - global $langs,$conf; - // Nettoyage param�tres - $this->nom=trim($this->nom); + /** + * \brief Create third party in database + * \param user Object of user that ask creation + * \return int >= 0 if OK, < 0 if KO + */ + function create($user='') + { + global $langs,$conf; + + // clean parameters + $this->nom=trim($this->nom); - dolibarr_syslog("Societe::create ".$this->nom); + dolibarr_syslog("Societe::create ".$this->nom); - $this->db->begin(); - - // Pour code automatique - if ($this->code_client == -1) $this->get_codeclient($this->prefix_comm,0); - if ($this->code_fournisseur == -1) $this->get_codefournisseur($this->prefix_comm,1); + $this->db->begin(); - $result = $this->verify(); + // Pour code automatique + if ($this->code_client == -1) $this->get_codeclient($this->prefix_comm,0); + if ($this->code_fournisseur == -1) $this->get_codefournisseur($this->prefix_comm,1); - if ($result >= 0) - { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe (nom, datec, datea, fk_user_creat) "; - $sql .= " VALUES ('".addslashes($this->nom)."', now(), now(), '".$user->id."')"; + $result = $this->verify(); - $result=$this->db->query($sql); - if ($result) - { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe"); + if ($result >= 0) + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe (nom, datec, datea, fk_user_creat)"; + $sql.= " VALUES ('".addslashes($this->nom)."', now(), now(),"; + $sql.= " ".($user->id > 0 ? "'".$user->id."'":"null"); + $sql.= ")"; - $ret = $this->update($this->id,$user,0,1,1); - - // si un commercial cree un client il lui est affecte automatiquement - if (!$user->rights->societe->client->voir) - { - $this->add_commercial($user, $user->id); - } - // Ajout du commercial affecte - else if ($this->commercial_id != '' && $this->commercial_id != -1) - { - $this->add_commercial($user, $this->commercial_id); - } + dolibarr_syslog("Societe::create sql=".$sql); + $result=$this->db->query($sql); + if ($result) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe"); + + $ret = $this->update($this->id,$user,0,1,1); + + // si un commercial cree un client il lui est affecte automatiquement + if (!$user->rights->societe->client->voir) + { + $this->add_commercial($user, $user->id); + } + // Ajout du commercial affecte + else if ($this->commercial_id != '' && $this->commercial_id != -1) + { + $this->add_commercial($user, $this->commercial_id); + } // si le fournisseur est classe on l'ajoute $this->AddFournisseurInCategory($this->fournisseur_categorie); - if ($ret >= 0) - { - $this->use_webcal=($conf->global->PHPWEBCALENDAR_COMPANYCREATE=='always'?1:0); + if ($ret >= 0) + { + $this->use_webcal=($conf->global->PHPWEBCALENDAR_COMPANYCREATE=='always'?1:0); - // Appel des triggers - include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('COMPANY_CREATE',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('COMPANY_CREATE',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers - dolibarr_syslog("Societe::Create success id=".$this->id); - $this->db->commit(); - return 0; - } - else - { - dolibarr_syslog("Societe::Create echec update"); - $this->db->rollback(); - return -3; - } - } - else - { - if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') - { + dolibarr_syslog("Societe::Create success id=".$this->id); + $this->db->commit(); + return 0; + } + else + { + dolibarr_syslog("Societe::Create echec update"); + $this->db->rollback(); + return -3; + } + } + else + { + if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { - $this->error=$langs->trans("ErrorCompanyNameAlreadyExists",$this->nom); - } - else - { - dolibarr_syslog("Societe::Create echec insert sql=".$sql); - } - $this->db->rollback(); - return -2; - } + $this->error=$langs->trans("ErrorCompanyNameAlreadyExists",$this->nom); + } + else + { + dolibarr_syslog("Societe::Create echec insert sql=".$sql); + } + $this->db->rollback(); + return -2; + } - } - else - { - $this->db->rollback(); - dolibarr_syslog("Societe::Create echec verify sql=".$sql); - return -1; - } - } + } + else + { + $this->db->rollback(); + dolibarr_syslog("Societe::Create echec verify sql=".$sql); + return -1; + } + } /** - * \brief Verification lors de la modification - * \return int 0 si OK, <0 si KO - */ + * \brief Verification lors de la modification + * \return int 0 si OK, <0 si KO + */ function verify() { $this->errors=array(); - + $result = 0; $this->nom=trim($this->nom); @@ -287,188 +290,188 @@ class Societe extends CommonObject } $result = -3; } - } + } return $result; } - /** - * \brief Update parameters of third party - * \param id id societe - * \param user Utilisateur qui demande la mise � jour - * \param call_trigger 0=non, 1=oui + /** + * \brief Update parameters of third party + * \param id id societe + * \param user Utilisateur qui demande la mise a jour + * \param call_trigger 0=non, 1=oui * \param allowmodcodeclient Autorise modif code client * \param allowmodcodefournisseur Autorise modif code fournisseur - * \return int <0 si ko, >=0 si ok - */ - function update($id, $user='', $call_trigger=1, $allowmodcodeclient=0, $allowmodcodefournisseur=0) - { - global $langs,$conf; + * \return int <0 si ko, >=0 si ok + */ + function update($id, $user='', $call_trigger=1, $allowmodcodeclient=0, $allowmodcodefournisseur=0) + { + global $langs,$conf; - dolibarr_syslog("Societe::Update id=".$id." call_trigger=".$call_triger." allowmodcodeclient=".$allowmodcodeclient." allowmodcodefournisseur=".$allowmodcodefournisseur); + dolibarr_syslog("Societe::Update id=".$id." call_trigger=".$call_triger." allowmodcodeclient=".$allowmodcodeclient." allowmodcodefournisseur=".$allowmodcodefournisseur); - // Nettoyage des param�tres - $this->id=$id; - $this->capital=trim($this->capital); - $this->nom=trim($this->nom); - $this->adresse=trim($this->adresse); - $this->cp=trim($this->cp); - $this->ville=trim($this->ville); - $this->departement_id=trim($this->departement_id); - $this->pays_id=trim($this->pays_id); - $this->tel=trim($this->tel); - $this->fax=trim($this->fax); - $this->tel = ereg_replace(" ","",$this->tel); - $this->tel = ereg_replace("\.","",$this->tel); - $this->fax = ereg_replace(" ","",$this->fax); - $this->fax = ereg_replace("\.","",$this->fax); - $this->email=trim($this->email); - $this->url=$this->url?clean_url($this->url,0):''; - $this->siren=trim($this->siren); - $this->siret=trim($this->siret); - $this->ape=trim($this->ape); - $this->idprof4=trim($this->idprof4); - $this->prefix_comm=trim($this->prefix_comm); + // Clean parameters + $this->id=$id; + $this->capital=trim($this->capital); + $this->nom=trim($this->nom); + $this->adresse=trim($this->adresse); + $this->cp=trim($this->cp); + $this->ville=trim($this->ville); + $this->departement_id=trim($this->departement_id); + $this->pays_id=trim($this->pays_id); + $this->tel=trim($this->tel); + $this->fax=trim($this->fax); + $this->tel = ereg_replace(" ","",$this->tel); + $this->tel = ereg_replace("\.","",$this->tel); + $this->fax = ereg_replace(" ","",$this->fax); + $this->fax = ereg_replace("\.","",$this->fax); + $this->email=trim($this->email); + $this->url=$this->url?clean_url($this->url,0):''; + $this->siren=trim($this->siren); + $this->siret=trim($this->siret); + $this->ape=trim($this->ape); + $this->idprof4=trim($this->idprof4); + $this->prefix_comm=trim($this->prefix_comm); - $this->tva_assuj=trim($this->tva_assuj); - $this->tva_intra=trim($this->tva_intra); + $this->tva_assuj=trim($this->tva_assuj); + $this->tva_intra=trim($this->tva_intra); - $this->capital=trim($this->capital); - if (strlen($this->capital) == 0) $this->capital = 0; + $this->capital=trim($this->capital); + if (strlen($this->capital) == 0) $this->capital = 0; - $this->effectif_id=trim($this->effectif_id); - $this->forme_juridique_code=trim($this->forme_juridique_code); - - // Pour code client/fournisseur automatique - if ($this->code_client == -1) $this->get_codeclient($this->prefix_comm,0); - if ($this->code_fournisseur == -1) $this->get_codefournisseur($this->prefix_comm,1); + $this->effectif_id=trim($this->effectif_id); + $this->forme_juridique_code=trim($this->forme_juridique_code); - // Check name is required and codes are ok or unique. + // Pour code client/fournisseur automatique + if ($this->code_client == -1) $this->get_codeclient($this->prefix_comm,0); + if ($this->code_fournisseur == -1) $this->get_codefournisseur($this->prefix_comm,1); + + // Check name is required and codes are ok or unique. // If error, this->errors[] is filled $result = $this->verify(); - if ($result >= 0) - { - dolibarr_syslog("Societe::Update verify ok"); - - $sql = "UPDATE ".MAIN_DB_PREFIX."societe"; - $sql.= " SET nom = '" . addslashes($this->nom) ."'"; // Champ obligatoire - $sql.= ",datea = now()"; - $sql.= ",address = '" . addslashes($this->adresse) ."'"; - - $sql.= ",cp = ".($this->cp?"'".$this->cp."'":"null"); - $sql.= ",ville = ".($this->ville?"'".addslashes($this->ville)."'":"null"); - - $sql .= ",fk_departement = '" . ($this->departement_id?$this->departement_id:'0') ."'"; - $sql .= ",fk_pays = '" . ($this->pays_id?$this->pays_id:'0') ."'"; - - $sql .= ",tel = ".($this->tel?"'".addslashes($this->tel)."'":"null"); - $sql .= ",fax = ".($this->fax?"'".addslashes($this->fax)."'":"null"); - $sql .= ",email = ".($this->email?"'".addslashes($this->email)."'":"null"); - $sql .= ",url = ".($this->url?"'".addslashes($this->url)."'":"null"); - - $sql .= ",siren = '". addslashes($this->siren) ."'"; - $sql .= ",siret = '". addslashes($this->siret) ."'"; - $sql .= ",ape = '". addslashes($this->ape) ."'"; - $sql .= ",idprof4 = '". addslashes($this->idprof4) ."'"; - + if ($result >= 0) + { + dolibarr_syslog("Societe::Update verify ok"); + + $sql = "UPDATE ".MAIN_DB_PREFIX."societe"; + $sql.= " SET nom = '" . addslashes($this->nom) ."'"; // Champ obligatoire + $sql.= ",datea = now()"; + $sql.= ",address = '" . addslashes($this->adresse) ."'"; + + $sql.= ",cp = ".($this->cp?"'".$this->cp."'":"null"); + $sql.= ",ville = ".($this->ville?"'".addslashes($this->ville)."'":"null"); + + $sql .= ",fk_departement = '" . ($this->departement_id?$this->departement_id:'0') ."'"; + $sql .= ",fk_pays = '" . ($this->pays_id?$this->pays_id:'0') ."'"; + + $sql .= ",tel = ".($this->tel?"'".addslashes($this->tel)."'":"null"); + $sql .= ",fax = ".($this->fax?"'".addslashes($this->fax)."'":"null"); + $sql .= ",email = ".($this->email?"'".addslashes($this->email)."'":"null"); + $sql .= ",url = ".($this->url?"'".addslashes($this->url)."'":"null"); + + $sql .= ",siren = '". addslashes($this->siren) ."'"; + $sql .= ",siret = '". addslashes($this->siret) ."'"; + $sql .= ",ape = '". addslashes($this->ape) ."'"; + $sql .= ",idprof4 = '". addslashes($this->idprof4) ."'"; + $sql .= ",tva_assuj = ".($this->tva_assuj>=0?"'".$this->tva_assuj."'":"null"); - $sql .= ",tva_intra = '" . addslashes($this->tva_intra) ."'"; + $sql .= ",tva_intra = '" . addslashes($this->tva_intra) ."'"; - $sql .= ",capital = '" . addslashes($this->capital) ."'"; - - $sql .= ",prefix_comm = ".($this->prefix_comm?"'".addslashes($this->prefix_comm)."'":"null"); - - $sql .= ",fk_effectif = ".($this->effectif_id?"'".$this->effectif_id."'":"null"); - - $sql .= ",fk_typent = ".($this->typent_id?"'".$this->typent_id."'":"0"); - - $sql .= ",fk_forme_juridique = ".($this->forme_juridique_code?"'".$this->forme_juridique_code."'":"null"); - - $sql .= ",client = " . $this->client; - $sql .= ",fournisseur = " . $this->fournisseur; - - if ($allowmodcodeclient) - { - // Attention check_codeclient peut modifier le code suivant le module utilise - $this->check_codeclient(); - - $sql .= ", code_client = ".($this->code_client?"'".addslashes($this->code_client)."'":"null"); - - // Attention get_codecompta peut modifier le code suivant le module utilise - $this->get_codecompta('customer'); - - $sql .= ", code_compta = ".($this->code_compta?"'".addslashes($this->code_compta)."'":"null"); - } - - if ($allowmodcodefournisseur) - { - // Attention check_codefournisseur peut modifier le code suivant le module utilise - $this->check_codefournisseur(); - - $sql .= ", code_fournisseur = ".($this->code_fournisseur?"'".addslashes($this->code_fournisseur)."'":"null"); - - // Attention get_codecompta peut modifier le code suivant le module utilise - $this->get_codecompta('supplier'); - - $sql .= ", code_compta_fournisseur = ".($this->code_compta_fournisseur?"'".addslashes($this->code_compta_fournisseur)."'":"null"); - } - if ($user) $sql .= ",fk_user_modif = '".$user->id."'"; - $sql .= " WHERE rowid = '" . $id ."'"; + $sql .= ",capital = '" . addslashes($this->capital) ."'"; + + $sql .= ",prefix_comm = ".($this->prefix_comm?"'".addslashes($this->prefix_comm)."'":"null"); - + $sql .= ",fk_effectif = ".($this->effectif_id?"'".$this->effectif_id."'":"null"); + + $sql .= ",fk_typent = ".($this->typent_id?"'".$this->typent_id."'":"0"); + + $sql .= ",fk_forme_juridique = ".($this->forme_juridique_code?"'".$this->forme_juridique_code."'":"null"); + + $sql .= ",client = " . $this->client; + $sql .= ",fournisseur = " . $this->fournisseur; + + if ($allowmodcodeclient) + { + // Attention check_codeclient peut modifier le code suivant le module utilise + $this->check_codeclient(); + + $sql .= ", code_client = ".($this->code_client?"'".addslashes($this->code_client)."'":"null"); + + // Attention get_codecompta peut modifier le code suivant le module utilise + $this->get_codecompta('customer'); + + $sql .= ", code_compta = ".($this->code_compta?"'".addslashes($this->code_compta)."'":"null"); + } + + if ($allowmodcodefournisseur) + { + // Attention check_codefournisseur peut modifier le code suivant le module utilise + $this->check_codefournisseur(); + + $sql .= ", code_fournisseur = ".($this->code_fournisseur?"'".addslashes($this->code_fournisseur)."'":"null"); + + // Attention get_codecompta peut modifier le code suivant le module utilise + $this->get_codecompta('supplier'); + + $sql .= ", code_compta_fournisseur = ".($this->code_compta_fournisseur?"'".addslashes($this->code_compta_fournisseur)."'":"null"); + } + $sql .= ", fk_user_modif = ".($user->id > 0 ? "'".$user->id."'":"null"); + $sql .= " WHERE rowid = '" . $id ."'"; + + dolibarr_syslog("Societe::update sql=".$sql); - $resql=$this->db->query($sql); - if ($resql) - { + $resql=$this->db->query($sql); + if ($resql) + { // Si le fournisseur est classe on l'ajoute $this->AddFournisseurInCategory($this->fournisseur_categorie); - if ($call_trigger) - { - // Appel des triggers - include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('COMPANY_MODIFY',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers - } - - $result = 1; - } - else - { - if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') - { - // Doublon - $this->error = $langs->trans("ErrorDuplicateField"); - $result = -1; - } - else - { - - $this->error = $langs->trans("Error sql=".$sql); - dolibarr_syslog("Societe::Update echec sql=".$sql); - $result = -2; - } - } - } + if ($call_trigger) + { + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('COMPANY_MODIFY',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + } - return $result; + $result = 1; + } + else + { + if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { + // Doublon + $this->error = $langs->trans("ErrorDuplicateField"); + $result = -1; + } + else + { - } + $this->error = $langs->trans("Error sql=".$sql); + dolibarr_syslog("Societe::Update echec sql=".$sql); + $result = -2; + } + } + } - /** - * \brief Load a third party from database into memory - * \param socid Id third party to load - * \param user User object (\deprecated) - * \return int >0 si ok, <0 si ko - */ - function fetch($socid, $user=0) - { + return $result; + + } + + /** + * \brief Load a third party from database into memory + * \param socid Id third party to load + * \param user User object (\deprecated) + * \return int >0 si ok, <0 si ko + */ + function fetch($socid, $user=0) + { global $langs; global $conf; - + // Init data for telephonie module if ($conf->telephonie->enabled && $user && $user->id) { @@ -572,7 +575,7 @@ class Societe extends CommonObject $this->typent_id = $obj->typent_id; $this->typent_code = $obj->typent_code; - + $this->effectif_id = $obj->effectif_id; $this->effectif = $obj->effectif_id?$obj->effectif:''; @@ -593,7 +596,7 @@ class Societe extends CommonObject $this->note = $obj->note; // multiprix if($conf->global->PRODUIT_MULTIPRICES == 1) - $this->price_level = $obj->price_level; + $this->price_level = $obj->price_level; $result = 1; } @@ -616,178 +619,178 @@ class Societe extends CommonObject return $result; } - - /** - * - * Lit une adresse de livraison - * - */ - function fetch_adresse_livraison($id) - { - global $conf,$langs; - $sql = "SELECT l.rowid, l.label, l.fk_societe, l.nom, l.address, l.cp"; - $sql .= ", ".$this->db->pdate("l.tms")."as dm, ".$this->db->pdate("l.datec")."as dc"; - $sql .= ", l.ville, l.fk_pays, l.note, l.tel, l.fax"; - $sql .= ", p.libelle as pays, p.code as pays_code, s.nom as socname"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe_adresse_livraison as l"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_pays as p ON l.fk_pays = p.rowid"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON l.fk_societe = s.rowid"; - $sql .= " WHERE l.rowid = ".$id; + /** + * + * Lit une adresse de livraison + * + */ + function fetch_adresse_livraison($id) + { + global $conf,$langs; - $result = $this->db->query($sql) ; - - if ( $result ) - { - $obj = $this->db->fetch_object($result); - - $this->id = $obj->rowid; - $this->datec = $obj->dc; - $this->datem = $obj->dm; - $this->label = $obj->label; - $this->socid = $obj->fk_societe; - $this->societe = $obj->socname; - $this->nom = $obj->nom; - $this->address = $obj->address; - $this->adresse = $obj->address; //Todo: uniformiser le nom des champs - $this->cp = $obj->cp; - $this->ville = $obj->ville; - $this->pays_id = $obj->fk_pays; - $this->pays_code = $obj->fk_pays?$obj->pays_code:''; - $this->pays = $obj->fk_pays?($langs->trans('Country'.$obj->pays_code)!='Country'.$obj->pays_code?strtoupper(clean_html($langs->trans('Country'.$obj->pays_code))):$obj->pays):''; - $this->tel = $obj->tel; - $this->fax = $obj->fax; - $this->note = $obj->note; + $sql = "SELECT l.rowid, l.label, l.fk_societe, l.nom, l.address, l.cp"; + $sql .= ", ".$this->db->pdate("l.tms")."as dm, ".$this->db->pdate("l.datec")."as dc"; + $sql .= ", l.ville, l.fk_pays, l.note, l.tel, l.fax"; + $sql .= ", p.libelle as pays, p.code as pays_code, s.nom as socname"; + $sql .= " FROM ".MAIN_DB_PREFIX."societe_adresse_livraison as l"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_pays as p ON l.fk_pays = p.rowid"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON l.fk_societe = s.rowid"; + $sql .= " WHERE l.rowid = ".$id; + + $result = $this->db->query($sql) ; + + if ( $result ) + { + $obj = $this->db->fetch_object($result); + + $this->id = $obj->rowid; + $this->datec = $obj->dc; + $this->datem = $obj->dm; + $this->label = $obj->label; + $this->socid = $obj->fk_societe; + $this->societe = $obj->socname; + $this->nom = $obj->nom; + $this->address = $obj->address; + $this->adresse = $obj->address; //Todo: uniformiser le nom des champs + $this->cp = $obj->cp; + $this->ville = $obj->ville; + $this->pays_id = $obj->fk_pays; + $this->pays_code = $obj->fk_pays?$obj->pays_code:''; + $this->pays = $obj->fk_pays?($langs->trans('Country'.$obj->pays_code)!='Country'.$obj->pays_code?strtoupper(clean_html($langs->trans('Country'.$obj->pays_code))):$obj->pays):''; + $this->tel = $obj->tel; + $this->fax = $obj->fax; + $this->note = $obj->note; - $this->db->free($result); - - return 1; - } - else - { - $this->error=$this->db->error(); - return -1; - } - } + $this->db->free($result); - /** - * \brief Suppression d'une societe de la base avec ses d�pendances (contacts, rib...) - * \param id id de la societe � supprimer - */ - function delete($id) - { + return 1; + } + else + { + $this->error=$this->db->error(); + return -1; + } + } + + /** + * \brief Suppression d'une societe de la base avec ses d�pendances (contacts, rib...) + * \param id id de la societe � supprimer + */ + function delete($id) + { global $user,$langs,$conf; - - dolibarr_syslog("Societe::Delete"); - $sqr = 0; + + dolibarr_syslog("Societe::Delete"); + $sqr = 0; // \Todo // Check if third party can be deleted - - - - - if ( $this->db->begin()) - { - $sql = "DELETE from ".MAIN_DB_PREFIX."socpeople"; - $sql.= " WHERE fk_soc = " . $id; - if ($this->db->query($sql)) - { - $sqr++; - } - else - { - $this->error .= $this->db->lasterror(); - dolibarr_syslog("Societe::Delete erreur -1 ".$this->error); - } - - $sql = "DELETE from ".MAIN_DB_PREFIX."societe_rib"; - $sql.= " WHERE fk_soc = " . $id; - if ($this->db->query($sql)) - { - $sqr++; - } - else - { - $this->error = $this->db->lasterror(); - dolibarr_syslog("Societe::Delete erreur -2 ".$this->error); - } - - $sql = "DELETE from ".MAIN_DB_PREFIX."societe"; - $sql.= " WHERE rowid = " . $id; - if ($this->db->query($sql)) - { - $sqr++; - } - else - { - $this->error = $this->db->lasterror(); - dolibarr_syslog("Societe::Delete erreur -3 ".$this->error); - } - - if ($sqr == 3) - { - // Appel des triggers - include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('COMPANY_DELETE',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers - - $this->db->commit(); - - // Suppression du r�pertoire document - $docdir = $conf->societe->dir_output . "/" . $id; - if (file_exists ($docdir)) - { - dol_delete_dir_recursive($docdir); - } - - return 0; - } - else - { - $this->db->rollback(); - return -1; - } - } - - } - /** - * \brief Retournes les factures impay�es de la soci�t� - * \return array tableau des id de factures impay�es - * - */ - function factures_impayes() - { - $facimp = array(); - /* - * Lignes - */ - $sql = "SELECT f.rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."facture as f WHERE f.fk_soc = '".$this->id . "'"; - $sql .= " AND f.fk_statut = '1' AND f.paye = '0'"; - if ($this->db->query($sql)) - { - $num = $this->db->num_rows(); - $i = 0; - while ($i < $num) + if ( $this->db->begin()) + { + $sql = "DELETE from ".MAIN_DB_PREFIX."socpeople"; + $sql.= " WHERE fk_soc = " . $id; + if ($this->db->query($sql)) + { + $sqr++; + } + else + { + $this->error .= $this->db->lasterror(); + dolibarr_syslog("Societe::Delete erreur -1 ".$this->error); + } + + $sql = "DELETE from ".MAIN_DB_PREFIX."societe_rib"; + $sql.= " WHERE fk_soc = " . $id; + if ($this->db->query($sql)) + { + $sqr++; + } + else + { + $this->error = $this->db->lasterror(); + dolibarr_syslog("Societe::Delete erreur -2 ".$this->error); + } + + $sql = "DELETE from ".MAIN_DB_PREFIX."societe"; + $sql.= " WHERE rowid = " . $id; + if ($this->db->query($sql)) + { + $sqr++; + } + else + { + $this->error = $this->db->lasterror(); + dolibarr_syslog("Societe::Delete erreur -3 ".$this->error); + } + + if ($sqr == 3) + { + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('COMPANY_DELETE',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + + $this->db->commit(); + + // Suppression du r�pertoire document + $docdir = $conf->societe->dir_output . "/" . $id; + if (file_exists ($docdir)) + { + dol_delete_dir_recursive($docdir); + } + + return 0; + } + else + { + $this->db->rollback(); + return -1; + } + } + + } + + + /** + * \brief Retournes les factures impay�es de la soci�t� + * \return array tableau des id de factures impay�es + * + */ + function factures_impayes() + { + $facimp = array(); + /* + * Lignes + */ + $sql = "SELECT f.rowid"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture as f WHERE f.fk_soc = '".$this->id . "'"; + $sql .= " AND f.fk_statut = '1' AND f.paye = '0'"; + + if ($this->db->query($sql)) + { + $num = $this->db->num_rows(); + $i = 0; + + while ($i < $num) { - $objp = $this->db->fetch_object(); - $array_push($facimp, $objp->rowid); - $i++; - print $i; + $objp = $this->db->fetch_object(); + $array_push($facimp, $objp->rowid); + $i++; + print $i; } - $this->db->free(); - } - return $facimp; - } + $this->db->free(); + } + return $facimp; + } /** * \brief Attribut le prefix de la soci�t� en base @@ -804,9 +807,9 @@ class Societe extends CommonObject $obj=$this->db->fetch_object($resql); $nom = preg_replace("/[[:punct:]]/","",$obj->nom); $this->db->free(); - + $prefix = $this->genprefix($nom,4); - + $sql = "SELECT count(*) as nb FROM ".MAIN_DB_PREFIX."societe WHERE prefix_comm = '$prefix'"; $resql=$this->db->query($sql); if ($resql) @@ -816,10 +819,10 @@ class Societe extends CommonObject if (! $obj->nb) { $sql = "UPDATE ".MAIN_DB_PREFIX."societe set prefix_comm='".$prefix."' WHERE rowid='".$this->id."'"; - + if ( $this->db->query( $sql) ) { - + } else { @@ -874,21 +877,21 @@ class Societe extends CommonObject return $retour; } - /** - * \brief D�finit la soci�t� comme un client - * - */ - function set_as_client() - { - if ($this->id) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."societe "; - $sql .= " SET client = 1"; - $sql .= " WHERE rowid = " . $this->id .";"; + /** + * \brief D�finit la soci�t� comme un client + * + */ + function set_as_client() + { + if ($this->id) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."societe "; + $sql .= " SET client = 1"; + $sql .= " WHERE rowid = " . $this->id .";"; - return $this->db->query($sql); - } - } + return $this->db->query($sql); + } + } /** * \brief D�finit la soci�t� comme un client @@ -900,7 +903,7 @@ class Societe extends CommonObject function set_remise_client($remise, $note, $user) { global $langs; - + // Nettoyage parametres $note=trim($note); if (! $note) @@ -914,7 +917,7 @@ class Societe extends CommonObject if ($this->id) { $this->db->begin(); - + // Positionne remise courante $sql = "UPDATE ".MAIN_DB_PREFIX."societe "; $sql.= " SET remise_client = '".$remise."'"; @@ -926,7 +929,7 @@ class Societe extends CommonObject $this->error=$this->db->error(); return -1; } - + // Ecrit trace dans historique des remises $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise "; $sql.= " (datec, fk_soc, remise_client, note, fk_user_author)"; @@ -942,7 +945,7 @@ class Societe extends CommonObject $this->error=$this->db->error(); return -1; } - + $this->db->commit(); return 1; } @@ -958,11 +961,11 @@ class Societe extends CommonObject function set_remise_except($remise, $user, $desc, $tva_tx=0) { global $langs; - + // Nettoyage des parametres $remise = price2num($remise); $desc = trim($desc); - + // Check parameters if (! $remise > 0) { @@ -974,7 +977,7 @@ class Societe extends CommonObject $this->error=$langs->trans("ErrorWrongValueForParameter","3"); return -2; } - + if ($this->id) { require_once(DOL_DOCUMENT_ROOT.'/discount.class.php'); @@ -1010,7 +1013,7 @@ class Societe extends CommonObject if ($this->id) { require_once(DOL_DOCUMENT_ROOT.'/discount.class.php'); - + $discount = new DiscountAbsolute($this->db); $result=$discount->fetch($id); $result=$discount->delete(); @@ -1030,7 +1033,7 @@ class Societe extends CommonObject { require_once(DOL_DOCUMENT_ROOT.'/discount.class.php'); - $discountstatic=new DiscountAbsolute($this->db); + $discountstatic=new DiscountAbsolute($this->db); $result=$discountstatic->getAvailableDiscounts($this,$user,$filter); if ($result >= 0) { @@ -1045,70 +1048,70 @@ class Societe extends CommonObject function set_price_level($price_level, $user) { - if ($this->id) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."societe "; - $sql .= " SET price_level = '".$price_level."'"; - $sql .= " WHERE rowid = " . $this->id .";"; + if ($this->id) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."societe "; + $sql .= " SET price_level = '".$price_level."'"; + $sql .= " WHERE rowid = " . $this->id .";"; - $this->db->query($sql); + $this->db->query($sql); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_prices "; - $sql .= " ( datec, fk_soc, price_level, fk_user_author )"; - $sql .= " VALUES (now(),".$this->id.",'".$price_level."',".$user->id.")"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_prices "; + $sql .= " ( datec, fk_soc, price_level, fk_user_author )"; + $sql .= " VALUES (now(),".$this->id.",'".$price_level."',".$user->id.")"; - if (! $this->db->query($sql) ) + if (! $this->db->query($sql) ) { - dolibarr_print_error($this->db); + dolibarr_print_error($this->db); } - } - } + } + } - /** - * - * - */ - function add_commercial($user, $commid) - { - if ($this->id > 0 && $commid > 0) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_commerciaux "; - $sql .= " WHERE fk_soc = " . $this->id ." AND fk_user =".$commid; + /** + * + * + */ + function add_commercial($user, $commid) + { + if ($this->id > 0 && $commid > 0) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_commerciaux "; + $sql .= " WHERE fk_soc = " . $this->id ." AND fk_user =".$commid; - $this->db->query($sql); + $this->db->query($sql); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_commerciaux "; - $sql .= " ( fk_soc, fk_user )"; - $sql .= " VALUES (".$this->id.",".$commid.")"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_commerciaux "; + $sql .= " ( fk_soc, fk_user )"; + $sql .= " VALUES (".$this->id.",".$commid.")"; - if (! $this->db->query($sql) ) + if (! $this->db->query($sql) ) { - dolibarr_syslog("Societe::add_commercial Erreur"); + dolibarr_syslog("Societe::add_commercial Erreur"); } - } - } + } + } - /** - * - * - * - */ - function del_commercial($user, $commid) - { - if ($this->id > 0 && $commid > 0) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_commerciaux "; - $sql .= " WHERE fk_soc = " . $this->id ." AND fk_user =".$commid; + /** + * + * + * + */ + function del_commercial($user, $commid) + { + if ($this->id > 0 && $commid > 0) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_commerciaux "; + $sql .= " WHERE fk_soc = " . $this->id ." AND fk_user =".$commid; - if (! $this->db->query($sql) ) + if (! $this->db->query($sql) ) { - dolibarr_syslog("Societe::del_commercial Erreur"); + dolibarr_syslog("Societe::del_commercial Erreur"); } - } - } + } + } /** @@ -1121,9 +1124,9 @@ class Societe extends CommonObject function getNomUrl($withpicto=0,$option='',$maxlen=0) { global $langs; - + $result=''; - + if ($this->client == 1) { $lien = ''; @@ -1152,42 +1155,42 @@ class Societe extends CommonObject } - /** - * \brief Renvoie le nom d'une societe a partir d'un id - * \param id id company we search for name - * \return string Third party name - */ - function get_nom($id) - { + /** + * \brief Renvoie le nom d'une societe a partir d'un id + * \param id id company we search for name + * \return string Third party name + */ + function get_nom($id) + { - $sql = "SELECT nom FROM ".MAIN_DB_PREFIX."societe WHERE rowid='".$id."';"; + $sql = "SELECT nom FROM ".MAIN_DB_PREFIX."societe WHERE rowid='".$id."';"; - $result = $this->db->query($sql); + $result = $this->db->query($sql); - if ($result) - { - if ($this->db->num_rows()) - { - $obj = $this->db->fetch_object($result); - return $obj->nom; - } - $this->db->free(); - } - else { - dolibarr_print_error($this->db); - } + if ($result) + { + if ($this->db->num_rows()) + { + $obj = $this->db->fetch_object($result); + return $obj->nom; + } + $this->db->free(); + } + else { + dolibarr_print_error($this->db); + } - } + } /** - * \brief Renvoie la liste des contacts emails existant pour la soci�t� - * \return array tableau des contacts emails - */ + * \brief Renvoie la liste des contacts emails existant pour la soci�t� + * \return array tableau des contacts emails + */ function thirdparty_and_contact_email_array() { global $langs; - + $contact_email = $this->contact_email_array(); if ($this->email) { @@ -1196,15 +1199,15 @@ class Societe extends CommonObject } return $contact_email; } - + /** - * \brief Renvoie la liste des contacts emails existant pour la soci�t� - * \return array tableau des contacts emails - */ + * \brief Renvoie la liste des contacts emails existant pour la soci�t� + * \return array tableau des contacts emails + */ function contact_email_array() { $contact_email = array(); - + $sql = "SELECT rowid, email, name, firstname"; $sql.= " FROM ".MAIN_DB_PREFIX."socpeople"; $sql.= " WHERE fk_soc = '".$this->id."'"; @@ -1229,16 +1232,16 @@ class Societe extends CommonObject } return $contact_email; } - - + + /** - * \brief Renvoie la liste des contacts de cette soci�t� - * \return array tableau des contacts - */ + * \brief Renvoie la liste des contacts de cette soci�t� + * \return array tableau des contacts + */ function contact_array() { $contacts = array(); - + $sql = "SELECT rowid, name, firstname FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = '".$this->id."'"; $resql=$this->db->query($sql); if ($resql) @@ -1262,41 +1265,41 @@ class Societe extends CommonObject return $contacts; } - /** - * \brief Renvoie l'email d'un contact depuis son id - * \param rowid id du contact - * \return string email du contact - */ - function contact_get_email($rowid) - { + /** + * \brief Renvoie l'email d'un contact depuis son id + * \param rowid id du contact + * \return string email du contact + */ + function contact_get_email($rowid) + { - $sql = "SELECT rowid, email, name, firstname FROM ".MAIN_DB_PREFIX."socpeople WHERE rowid = '".$rowid."'"; + $sql = "SELECT rowid, email, name, firstname FROM ".MAIN_DB_PREFIX."socpeople WHERE rowid = '".$rowid."'"; - if ($this->db->query($sql) ) - { - $nump = $this->db->num_rows(); + if ($this->db->query($sql) ) + { + $nump = $this->db->num_rows(); - if ($nump) - { + if ($nump) + { - $obj = $this->db->fetch_object(); + $obj = $this->db->fetch_object(); - $contact_email = "$obj->firstname $obj->name <$obj->email>"; + $contact_email = "$obj->firstname $obj->name <$obj->email>"; - } - return $contact_email; - } - else - { - dolibarr_print_error($this->db); - } + } + return $contact_email; + } + else + { + dolibarr_print_error($this->db); + } - } + } /** - * \brief Affiche le rib - */ + * \brief Affiche le rib + */ function display_rib() { global $langs; @@ -1337,7 +1340,7 @@ class Societe extends CommonObject return $this->bank_account->verif(); } - /** + /** * \brief Attribut un code client � partir du module de controle des codes. * \return code_client Code client automatique */ @@ -1349,14 +1352,14 @@ class Societe extends CommonObject require_once DOL_DOCUMENT_ROOT.'/includes/modules/societe/'.$conf->global->SOCIETE_CODECLIENT_ADDON.'.php'; $var = $conf->global->SOCIETE_CODECLIENT_ADDON; $mod = new $var; - + $this->code_client = $mod->getNextValue($objsoc,$type); $this->prefixCustomerIsRequired = $mod->prefixIsRequired; dolibarr_syslog("Societe::get_codeclient code_client=".$this->code_client." module=".$var); } } - + /** * \brief Attribut un code fournisseur � partir du module de controle des codes. * \return code_fournisseur Code fournisseur automatique @@ -1369,10 +1372,10 @@ class Societe extends CommonObject require_once DOL_DOCUMENT_ROOT.'/includes/modules/societe/'.$conf->global->SOCIETE_CODEFOURNISSEUR_ADDON.'.php'; $var = $conf->global->SOCIETE_CODEFOURNISSEUR_ADDON; $mod = new $var; - + $this->code_fournisseur = $mod->getNextValue($objsoc,$type); $this->prefixSupplierIsRequired = $mod->prefixIsRequired; - + dolibarr_syslog("Societe::get_codefournisseur code_fournisseur=".$this->code_fournisseur." module=".$var); } } @@ -1388,13 +1391,13 @@ class Societe extends CommonObject if ($conf->global->SOCIETE_CODECLIENT_ADDON) { require_once DOL_DOCUMENT_ROOT.'/includes/modules/societe/'.$conf->global->SOCIETE_CODECLIENT_ADDON.'.php'; - + $var = $conf->global->SOCIETE_CODECLIENT_ADDON; - + $mod = new $var; - + dolibarr_syslog("Societe::codeclient_modifiable code_client=".$this->code_client." module=".$var); - if ($mod->code_modifiable_null && ! $this->code_client) return 1; + if ($mod->code_modifiable_null && ! $this->code_client) return 1; if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) return 1; if ($mod->code_modifiable) return 1; // A mettre en dernier return 0; @@ -1416,13 +1419,13 @@ class Societe extends CommonObject if ($conf->global->SOCIETE_CODEFOURNISSEUR_ADDON) { require_once DOL_DOCUMENT_ROOT.'/includes/modules/societe/'.$conf->global->SOCIETE_CODEFOURNISSEUR_ADDON.'.php'; - + $var = $conf->global->SOCIETE_CODEFOURNISSEUR_ADDON; - + $mod = new $var; - + dolibarr_syslog("Societe::codefournisseur_modifiable code_founisseur=".$this->code_fournisseur." module=".$var); - if ($mod->code_modifiable_null && ! $this->code_fournisseur) return 1; + if ($mod->code_modifiable_null && ! $this->code_fournisseur) return 1; if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) return 1; if ($mod->code_modifiable) return 1; // A mettre en dernier return 0; @@ -1444,11 +1447,11 @@ class Societe extends CommonObject if ($conf->global->SOCIETE_CODECLIENT_ADDON) { require_once DOL_DOCUMENT_ROOT.'/includes/modules/societe/'.$conf->global->SOCIETE_CODECLIENT_ADDON.'.php'; - + $var = $conf->global->SOCIETE_CODECLIENT_ADDON; - + $mod = new $var; - + dolibarr_syslog("Societe::check_codeclient code_client=".$this->code_client." module=".$var); $result = $mod->verif($this->db, $this->code_client, $this, 0); return $result; @@ -1458,7 +1461,7 @@ class Societe extends CommonObject return 0; } } - + /** * \brief Verifie code fournisseur * \return int <0 si KO, 0 si OK, peut modifier le code client suivant le module utilis� @@ -1469,9 +1472,9 @@ class Societe extends CommonObject if ($conf->global->SOCIETE_CODEFOURNISSEUR_ADDON) { require_once DOL_DOCUMENT_ROOT.'/includes/modules/societe/'.$conf->global->SOCIETE_CODEFOURNISSEUR_ADDON.'.php'; - + $var = $conf->global->SOCIETE_CODEFOURNISSEUR_ADDON; - + $mod = new $var; dolibarr_syslog("Societe::check_codefournisseur code_fournisseur=".$this->code_fournisseur." module=".$var); @@ -1494,21 +1497,21 @@ class Societe extends CommonObject function get_codecompta($type) { global $conf; - + if ($conf->global->SOCIETE_CODECOMPTA_ADDON) { require_once DOL_DOCUMENT_ROOT.'/includes/modules/societe/'.$conf->global->SOCIETE_CODECOMPTA_ADDON.'.php'; - + $var = $conf->global->SOCIETE_CODECOMPTA_ADDON; - + $mod = new $var; - + // Defini code compta dans $mod->code $result = $mod->get_code($this->db, $this, $type); - + if ($type == 'customer') $this->code_compta = $mod->code; if ($type == 'supplier') $this->code_compta_fournisseur = $mod->code; - + return $result; } else @@ -1519,213 +1522,213 @@ class Societe extends CommonObject return 0; } } - - /** - * \brief D�fini la soci�t� m�re pour les filiales - * \param id id compagnie m�re � positionner - * \return int <0 si ko, >0 si ok - */ - function set_parent($id) - { - if ($this->id) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."societe "; - $sql .= " SET parent = ".$id; - $sql .= " WHERE rowid = " . $this->id .";"; - - if ( $this->db->query($sql) ) - { - return 1; - } - else - { - return -1; - } - } - } - - /** - * \brief Supprime la soci�t� m�re - * \param id id compagnie m�re � effacer - * \return int <0 si ko, >0 si ok - */ - function remove_parent($id) - { - if ($this->id) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."societe "; - $sql .= " SET parent = null"; - $sql .= " WHERE rowid = " . $this->id .";"; - - if ( $this->db->query($sql) ) - { - return 1; - } - else - { - return -1; - } - } - } - - /** - * \brief Verifie la validite d'un identifiant professionnel en - * fonction du pays de la societe (siren, siret, ...) - * \param idprof 1,2,3,4 (Exemple: 1=siren,2=siret,3=naf,4=rcs/rm) - * \param soc Objet societe - * \return int <0 si ko, >0 si ok - */ - function id_prof_check($idprof,$soc) - { - $ok=1; - - // Verifie SIREN si pays FR - if ($idprof == 1 && $soc->pays_code == 'FR') - { - $chaine=trim($this->siren); - $chaine=eregi_replace(' ','',$chaine); - - if (strlen($chaine) != 9) return -1; - - $sum = 0; - - for ($i = 0 ; $i < 10 ; $i = $i+2) - { - $sum = $sum + substr($this->siren, (8 - $i), 1); - } - - for ($i = 1 ; $i < 9 ; $i = $i+2) - { - $ps = 2 * substr($this->siren, (8 - $i), 1); - - if ($ps > 9) - { - $ps = substr($ps, 0,1) + substr($ps, 1 ,1); - } - $sum = $sum + $ps; - } - - if (substr($sum, -1) != 0) return -1; - } - - // Verifie SIRET si pays FR - if ($idprof == 2 && $soc->pays_code == 'FR') - { - $chaine=trim($this->siret); - $chaine=eregi_replace(' ','',$chaine); - - if (strlen($chaine) != 14) return -1; - } - - return $ok; - } - - /** - * \brief Renvoi url de v�rification d'un identifiant professionnal - * \param idprof 1,2,3,4 (Exemple: 1=siren,2=siret,3=naf,4=rcs/rm) - * \param soc Objet societe - * \return string url ou chaine vide si aucune url connue - */ - function id_prof_url($idprof,$soc) - { - global $langs; - - $url=''; - if ($idprof == 1 && $soc->pays_code == 'FR') $url='http://www.societe.com/cgi-bin/recherche?rncs='.$soc->siren; - if ($idprof == 1 && $soc->pays_code == 'GB') $url='http://www.companieshouse.gov.uk/WebCHeck/findinfolink/'; - - if ($url) return '['.$langs->trans("Check").']'; - return ''; - } - - /** - * \brief Indique si la soci�t� a des projets - * \return bool true si la soci�t� a des projets, false sinon - */ - function has_projects() - { - $sql = 'SELECT COUNT(*) as numproj FROM '.MAIN_DB_PREFIX.'projet WHERE fk_soc = ' . $this->id; - $resql = $this->db->query($sql); - if ($resql) - { - $nump = $this->db->num_rows($resql); - $obj = $this->db->fetch_object(); - $count = $obj->numproj; - } - else - { - $count = 0; - print $this->db->error(); - } - $this->db->free($resql); - return ($count > 0); - } - - - function AddPerms($user_id, $read, $write, $perms) - { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_perms"; - $sql .= " (fk_soc, fk_user, pread, pwrite, pperms) "; - $sql .= " VALUES (".$this->id.",".$user_id.",".$read.",".$write.",".$perms.");"; - - $resql=$this->db->query($sql); - if ($resql) - { - - } - } /** - * \brief Charge les informations d'ordre info dans l'objet societe - * \param id id de la societe a charger - */ - function info($id) - { - $sql = "SELECT s.rowid, s.nom, ".$this->db->pdate("datec")." as datec, ".$this->db->pdate("datea")." as datea,"; - $sql.= " fk_user_creat, fk_user_modif"; - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; - $sql.= " WHERE s.rowid = ".$id; + * \brief D�fini la soci�t� m�re pour les filiales + * \param id id compagnie m�re � positionner + * \return int <0 si ko, >0 si ok + */ + function set_parent($id) + { + if ($this->id) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."societe "; + $sql .= " SET parent = ".$id; + $sql .= " WHERE rowid = " . $this->id .";"; - $result=$this->db->query($sql); - if ($result) - { - if ($this->db->num_rows($result)) - { - $obj = $this->db->fetch_object($result); - - $this->id = $obj->rowid; - - if ($obj->fk_user_creat) { - $cuser = new User($this->db, $obj->fk_user_creat); - $cuser->fetch(); - $this->user_creation = $cuser; - } - - if ($obj->fk_user_modif) { - $muser = new User($this->db, $obj->fk_user_modif); - $muser->fetch(); - $this->user_modification = $muser; - } - $this->ref = $obj->nom; - $this->date_creation = $obj->datec; - $this->date_modification = $obj->datea; - } - - $this->db->free($result); - - } - else - { - dolibarr_print_error($this->db); - } - } + if ( $this->db->query($sql) ) + { + return 1; + } + else + { + return -1; + } + } + } /** - * \brief Renvoi si pays appartient � CEE - * \param boolean true = pays dans CEE, false= pays hors CEE - */ - function isInEEC() - { + * \brief Supprime la soci�t� m�re + * \param id id compagnie m�re � effacer + * \return int <0 si ko, >0 si ok + */ + function remove_parent($id) + { + if ($this->id) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."societe "; + $sql .= " SET parent = null"; + $sql .= " WHERE rowid = " . $this->id .";"; + + if ( $this->db->query($sql) ) + { + return 1; + } + else + { + return -1; + } + } + } + + /** + * \brief Verifie la validite d'un identifiant professionnel en + * fonction du pays de la societe (siren, siret, ...) + * \param idprof 1,2,3,4 (Exemple: 1=siren,2=siret,3=naf,4=rcs/rm) + * \param soc Objet societe + * \return int <0 si ko, >0 si ok + */ + function id_prof_check($idprof,$soc) + { + $ok=1; + + // Verifie SIREN si pays FR + if ($idprof == 1 && $soc->pays_code == 'FR') + { + $chaine=trim($this->siren); + $chaine=eregi_replace(' ','',$chaine); + + if (strlen($chaine) != 9) return -1; + + $sum = 0; + + for ($i = 0 ; $i < 10 ; $i = $i+2) + { + $sum = $sum + substr($this->siren, (8 - $i), 1); + } + + for ($i = 1 ; $i < 9 ; $i = $i+2) + { + $ps = 2 * substr($this->siren, (8 - $i), 1); + + if ($ps > 9) + { + $ps = substr($ps, 0,1) + substr($ps, 1 ,1); + } + $sum = $sum + $ps; + } + + if (substr($sum, -1) != 0) return -1; + } + + // Verifie SIRET si pays FR + if ($idprof == 2 && $soc->pays_code == 'FR') + { + $chaine=trim($this->siret); + $chaine=eregi_replace(' ','',$chaine); + + if (strlen($chaine) != 14) return -1; + } + + return $ok; + } + + /** + * \brief Renvoi url de v�rification d'un identifiant professionnal + * \param idprof 1,2,3,4 (Exemple: 1=siren,2=siret,3=naf,4=rcs/rm) + * \param soc Objet societe + * \return string url ou chaine vide si aucune url connue + */ + function id_prof_url($idprof,$soc) + { + global $langs; + + $url=''; + if ($idprof == 1 && $soc->pays_code == 'FR') $url='http://www.societe.com/cgi-bin/recherche?rncs='.$soc->siren; + if ($idprof == 1 && $soc->pays_code == 'GB') $url='http://www.companieshouse.gov.uk/WebCHeck/findinfolink/'; + + if ($url) return '['.$langs->trans("Check").']'; + return ''; + } + + /** + * \brief Indique si la soci�t� a des projets + * \return bool true si la soci�t� a des projets, false sinon + */ + function has_projects() + { + $sql = 'SELECT COUNT(*) as numproj FROM '.MAIN_DB_PREFIX.'projet WHERE fk_soc = ' . $this->id; + $resql = $this->db->query($sql); + if ($resql) + { + $nump = $this->db->num_rows($resql); + $obj = $this->db->fetch_object(); + $count = $obj->numproj; + } + else + { + $count = 0; + print $this->db->error(); + } + $this->db->free($resql); + return ($count > 0); + } + + + function AddPerms($user_id, $read, $write, $perms) + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_perms"; + $sql .= " (fk_soc, fk_user, pread, pwrite, pperms) "; + $sql .= " VALUES (".$this->id.",".$user_id.",".$read.",".$write.",".$perms.");"; + + $resql=$this->db->query($sql); + if ($resql) + { + + } + } + + /** + * \brief Charge les informations d'ordre info dans l'objet societe + * \param id id de la societe a charger + */ + function info($id) + { + $sql = "SELECT s.rowid, s.nom, ".$this->db->pdate("datec")." as datec, ".$this->db->pdate("datea")." as datea,"; + $sql.= " fk_user_creat, fk_user_modif"; + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; + $sql.= " WHERE s.rowid = ".$id; + + $result=$this->db->query($sql); + if ($result) + { + if ($this->db->num_rows($result)) + { + $obj = $this->db->fetch_object($result); + + $this->id = $obj->rowid; + + if ($obj->fk_user_creat) { + $cuser = new User($this->db, $obj->fk_user_creat); + $cuser->fetch(); + $this->user_creation = $cuser; + } + + if ($obj->fk_user_modif) { + $muser = new User($this->db, $obj->fk_user_modif); + $muser->fetch(); + $this->user_modification = $muser; + } + $this->ref = $obj->nom; + $this->date_creation = $obj->datec; + $this->date_modification = $obj->datea; + } + + $this->db->free($result); + + } + else + { + dolibarr_print_error($this->db); + } + } + + /** + * \brief Renvoi si pays appartient � CEE + * \param boolean true = pays dans CEE, false= pays hors CEE + */ + function isInEEC() + { // List of all country codes that are in europe for european vat rules $country_code_in_EEC=array( 'AT', // Austria @@ -1757,92 +1760,92 @@ class Societe extends CommonObject 'ES', // Spain 'SE', // Sweden 'CH', // Switzerland - ); + ); //print "dd".$this->pays_code; return in_array($this->pays_code,$country_code_in_EEC); - } - + } + /** - * \brief Charge la liste des categories fournisseurs - * \return 0 in success, <> 0 in error - */ - function LoadSupplierCateg() - { - $this->SupplierCategories = array(); - $sql = "SELECT rowid, label"; - $sql.= " FROM ".MAIN_DB_PREFIX."categorie"; - $sql.= " WHERE type = 1"; - - $resql=$this->db->query($sql); - if ($resql) - { - while ($obj = $this->db->fetch_object($resql) ) - { - $this->SupplierCategories[$obj->rowid] = $obj->label; - } - return 0; - } - else + * \brief Charge la liste des categories fournisseurs + * \return 0 in success, <> 0 in error + */ + function LoadSupplierCateg() { - return -1; - } - } - - /* - * \brief Charge la liste des categories fournisseurs - * \return 0 in success, <> 0 in error - */ - function AddFournisseurInCategory($categorie_id) - { - if ($categorie_id > 0) - { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_fournisseur (fk_categorie, fk_societe) "; - $sql.= " VALUES ('".$categorie_id."','".$this->id."');"; - - if ($resql=$this->db->query($sql)) + $this->SupplierCategories = array(); + $sql = "SELECT rowid, label"; + $sql.= " FROM ".MAIN_DB_PREFIX."categorie"; + $sql.= " WHERE type = 1"; + + $resql=$this->db->query($sql); + if ($resql) + { + while ($obj = $this->db->fetch_object($resql) ) + { + $this->SupplierCategories[$obj->rowid] = $obj->label; + } return 0; - } - else - { - return 0; - } - return -1; - } - + } + else + { + return -1; + } + } + + /* + * \brief Charge la liste des categories fournisseurs + * \return 0 in success, <> 0 in error + */ + function AddFournisseurInCategory($categorie_id) + { + if ($categorie_id > 0) + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_fournisseur (fk_categorie, fk_societe) "; + $sql.= " VALUES ('".$categorie_id."','".$this->id."');"; + + if ($resql=$this->db->query($sql)) + return 0; + } + else + { + return 0; + } + return -1; + } + function set_status($id_status) - { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_log (datel, fk_soc, fk_statut, fk_user, author, label)"; - $sql.= " VALUES ('$dateaction', $socid, $id_status,"; + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_log (datel, fk_soc, fk_statut, fk_user, author, label)"; + $sql.= " VALUES ('$dateaction', $socid, $id_status,"; $sql.= "'".$user->id."',"; $sql.= "'".addslashes($user->login)."',"; $sql.= "'Change statut from $oldstcomm to $stcommid'"; $sql.= ")"; - $result = $db->query($sql); - if ($result) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=$stcommid WHERE rowid=".$socid; - $result = $db->query($sql); - } - else - { + $result = $db->query($sql); + if ($result) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=$stcommid WHERE rowid=".$socid; + $result = $db->query($sql); + } + else + { $errmesg = $db->error; - } + } } - + /** - * \brief Retourne le formulaire de saisie d'un identifiant professionnel (siren, siret, etc...) - * \param idprof 1,2,3,4 (Exemple: 1=siren,2=siret,3=naf,4=rcs/rm) - * \param htmlname Nom de la zone input - * \param preselected Default value to show - */ - function show_input_id_prof($idprof,$htmlname,$preselected) - { - global $langs; - - $formlength=16; - if ($this->pays_code == 'FR') + * \brief Retourne le formulaire de saisie d'un identifiant professionnel (siren, siret, etc...) + * \param idprof 1,2,3,4 (Exemple: 1=siren,2=siret,3=naf,4=rcs/rm) + * \param htmlname Nom de la zone input + * \param preselected Default value to show + */ + function show_input_id_prof($idprof,$htmlname,$preselected) + { + global $langs; + + $formlength=16; + if ($this->pays_code == 'FR') { if ($idprof==1) $formlength=9; if ($idprof==2) $formlength=14; @@ -1850,13 +1853,13 @@ class Societe extends CommonObject if ($idprof==4) $formlength=12; } $selected=$preselected; - if (! $selected && $idprof==1) $selected=$this->siren; - if (! $selected && $idprof==2) $selected=$this->siret; - if (! $selected && $idprof==3) $selected=$this->ape; - if (! $selected && $idprof==4) $selected=$this->idprof4; + if (! $selected && $idprof==1) $selected=$this->siren; + if (! $selected && $idprof==2) $selected=$this->siret; + if (! $selected && $idprof==3) $selected=$this->ape; + if (! $selected && $idprof==4) $selected=$this->idprof4; - print ''; - } + print ''; + } } ?> diff --git a/htdocs/user.class.php b/htdocs/user.class.php index e6d9758d4dc..18ddbc10c53 100644 --- a/htdocs/user.class.php +++ b/htdocs/user.class.php @@ -23,33 +23,33 @@ */ /** - \file htdocs/user.class.php - \brief Fichier de la classe utilisateur - \author Rodolphe Quiedeville - \author Jean-Louis Bergamo - \author Laurent Destailleur - \author Sebastien Di Cintio - \author Benoit Mortier - \author Regis Houssin - \author Lionel Cousteix - \version $Id$ -*/ + \file htdocs/user.class.php + \brief Fichier de la classe utilisateur + \author Rodolphe Quiedeville + \author Jean-Louis Bergamo + \author Laurent Destailleur + \author Sebastien Di Cintio + \author Benoit Mortier + \author Regis Houssin + \author Lionel Cousteix + \version $Id$ + */ require_once(DOL_DOCUMENT_ROOT ."/commonobject.class.php"); /** - \class User - \brief Classe permettant la gestion d'un utilisateur -*/ + \class User + \brief Classe permettant la gestion d'un utilisateur + */ class User extends CommonObject { - var $db; - var $error; - var $element='user'; - var $table_element='user'; + var $db; + var $error; + var $element='user'; + var $table_element='user'; - var $id; + var $id=0; var $ldap_sid; var $search_sid; var $fullname; @@ -65,9 +65,9 @@ class User extends CommonObject //! Mot de passe en clair en memoire var $pass; - //! Mot de passe en clair en base (renseign� si DATABASE_PWD_ENCRYPTED=0) + //! Mot de passe en clair en base (renseigne si DATABASE_PWD_ENCRYPTED=0) var $pass_indatabase; - //! Mot de passe crypte en base (toujours renseign�) + //! Mot de passe crypte en base (toujours renseigne) var $pass_indatabase_crypted; var $datec; @@ -91,45 +91,45 @@ class User extends CommonObject var $rights; var $all_permissions_are_loaded; /**< \private all_permissions_are_loaded */ - var $tab_loaded=array(); // Tableau pour signaler les permissions deja charg�es + var $tab_loaded=array(); // Tableau pour signaler les permissions deja chargees + - - /** - * \brief Constructeur de la classe - * \param DB Handler acces base de donnees - * \param id Id de l'utilisateur (0 par defaut) - */ - function User($DB, $id=0) - { - $this->db = $DB; - $this->id = $id; - - // Preference utilisateur - $this->liste_limit = 0; - $this->clicktodial_enabled = 0; - - $this->all_permissions_are_loaded = 0; - $this->admin=0; - - return 1; - } - - /** - * \brief Charge un objet user avec toutes ces caracteristiques depuis un id ou login - * \param login Si defini, login a utiliser pour recherche - * \param sid Si defini, sid a utiliser pour recherche - * \return int <0 if KO, 0 not found, >0 if OK - */ + * \brief Constructeur de la classe + * \param DB Handler acces base de donnees + * \param id Id de l'utilisateur (0 par defaut) + */ + function User($DB, $id=0) + { + $this->db = $DB; + $this->id = $id; + + // Preference utilisateur + $this->liste_limit = 0; + $this->clicktodial_enabled = 0; + + $this->all_permissions_are_loaded = 0; + $this->admin=0; + + return 1; + } + + + /** + * \brief Charge un objet user avec toutes ces caracteristiques depuis un id ou login + * \param login Si defini, login a utiliser pour recherche + * \param sid Si defini, sid a utiliser pour recherche + * \return int <0 if KO, 0 not found, >0 if OK + */ function fetch($login='',$sid='') { global $conf; // Nettoyage parametres $login=trim($login); - + // Recupere utilisateur $sql = "SELECT u.rowid, u.name, u.firstname, u.email, u.office_phone, u.office_fax, u.user_mobile,"; $sql.= " u.admin, u.login, u.webcal_login, u.phenix_login, u.phenix_pass, u.note,"; @@ -154,7 +154,7 @@ class User extends CommonObject { $sql .= " WHERE u.rowid = ".$this->id; } - + dolibarr_syslog("User::Fetch sql=".$sql, LOG_DEBUG); $result = $this->db->query($sql); if ($result) @@ -168,7 +168,7 @@ class User extends CommonObject $this->ldap_sid = $obj->ldap_sid; $this->nom = $obj->name; $this->prenom = $obj->firstname; - + $this->fullname = trim($this->prenom . ' ' . $this->nom); $this->login = $obj->login; $this->pass_indatabase = $obj->pass; @@ -183,19 +183,19 @@ class User extends CommonObject $this->note = $obj->note; $this->statut = $obj->statut; $this->lang = $obj->lang; - + $this->datec = $obj->datec; $this->datem = $obj->datem; $this->datelastlogin = $obj->datel; $this->datepreviouslogin = $obj->datep; - + $this->webcal_login = $obj->webcal_login; $this->phenix_login = $obj->phenix_login; $this->phenix_pass_crypted = $obj->phenix_pass; $this->societe_id = $obj->fk_societe; $this->contact_id = $obj->fk_socpeople; $this->fk_member = $obj->fk_member; - + if (! $this->lang) $this->lang='fr_FR'; $this->db->free($result); @@ -207,7 +207,7 @@ class User extends CommonObject $this->db->free($result); return 0; - } + } } else { @@ -215,7 +215,7 @@ class User extends CommonObject dolibarr_syslog("User::fetch Error -1, fails to get user - ".$this->error." - sql=".$sql, LOG_ERR); return -1; } - + // Recupere parametrage global propre a l'utilisateur // \todo a stocker/recuperer en session pour eviter ce select a chaque page $sql = "SELECT param, value FROM ".MAIN_DB_PREFIX."user_param"; @@ -241,7 +241,7 @@ class User extends CommonObject dolibarr_syslog("User::fetch Error -2, fails to get setup user - ".$this->error." - sql=".$sql, LOG_ERR); return -2; } - + // Recupere parametrage propre a la page et a l'utilisateur // \todo SCRIPT_URL non defini sur tous serveurs // Parametrage par page desactive pour l'instant @@ -273,201 +273,201 @@ class User extends CommonObject return -1; } } - + return 1; } - - /** - * \brief Ajoute un droit a l'utilisateur - * \param rid id du droit a ajouter - * \param allmodule Ajouter tous les droits du module allmodule - * \param allperms Ajouter tous les droits du module allmodule, perms allperms - * \return int > 0 si ok, < 0 si erreur - */ - function addrights($rid,$allmodule='',$allperms='') - { - dolibarr_syslog("User::addrights $rid, $allmodule, $allperms"); - $err=0; - $whereforadd=''; - $this->db->begin(); + /** + * \brief Ajoute un droit a l'utilisateur + * \param rid id du droit a ajouter + * \param allmodule Ajouter tous les droits du module allmodule + * \param allperms Ajouter tous les droits du module allmodule, perms allperms + * \return int > 0 si ok, < 0 si erreur + */ + function addrights($rid,$allmodule='',$allperms='') + { + dolibarr_syslog("User::addrights $rid, $allmodule, $allperms"); + $err=0; + $whereforadd=''; - if ($rid) - { - // Si on a demande ajout d'un droit en particulier, on recupere - // les caracteristiques (module, perms et subperms) de ce droit. - $sql = "SELECT module, perms, subperms"; - $sql.= " FROM ".MAIN_DB_PREFIX."rights_def"; - $sql.= " WHERE "; - $sql.=" id = '".$rid."'"; + $this->db->begin(); - $result=$this->db->query($sql); - if ($result) { - $obj = $this->db->fetch_object($result); - $module=$obj->module; - $perms=$obj->perms; - $subperms=$obj->subperms; - } - else { - $err++; - dolibarr_print_error($this->db); - } + if ($rid) + { + // Si on a demande ajout d'un droit en particulier, on recupere + // les caracteristiques (module, perms et subperms) de ce droit. + $sql = "SELECT module, perms, subperms"; + $sql.= " FROM ".MAIN_DB_PREFIX."rights_def"; + $sql.= " WHERE "; + $sql.=" id = '".$rid."'"; - // Where pour la liste des droits a ajouter - $whereforadd="id=".$rid; - // Ajout des droits induits - if ($subperms) $whereforadd.=" OR (module='$module' AND perms='$perms' AND (subperms='lire' OR subperms='read'))"; - else if ($perms) $whereforadd.=" OR (module='$module' AND (perms='lire' OR perms='read') AND subperms IS NULL)"; - } - else { - // On a pas demande un droit en particulier mais une liste de droits - // sur la base d'un nom de module de de perms - // Where pour la liste des droits a ajouter - if ($allmodule) $whereforadd="module='$allmodule'"; - if ($allperms) $whereforadd=" AND perms='$allperms'"; - } + $result=$this->db->query($sql); + if ($result) { + $obj = $this->db->fetch_object($result); + $module=$obj->module; + $perms=$obj->perms; + $subperms=$obj->subperms; + } + else { + $err++; + dolibarr_print_error($this->db); + } - // Ajout des droits trouves grace au critere whereforadd - if ($whereforadd) - { - //print "$module-$perms-$subperms"; - $sql = "SELECT id"; - $sql.= " FROM ".MAIN_DB_PREFIX."rights_def"; - $sql.= " WHERE ".$whereforadd; + // Where pour la liste des droits a ajouter + $whereforadd="id=".$rid; + // Ajout des droits induits + if ($subperms) $whereforadd.=" OR (module='$module' AND perms='$perms' AND (subperms='lire' OR subperms='read'))"; + else if ($perms) $whereforadd.=" OR (module='$module' AND (perms='lire' OR perms='read') AND subperms IS NULL)"; + } + else { + // On a pas demande un droit en particulier mais une liste de droits + // sur la base d'un nom de module de de perms + // Where pour la liste des droits a ajouter + if ($allmodule) $whereforadd="module='$allmodule'"; + if ($allperms) $whereforadd=" AND perms='$allperms'"; + } - $result=$this->db->query($sql); - if ($result) - { - $num = $this->db->num_rows($result); - $i = 0; - while ($i < $num) - { - $obj = $this->db->fetch_object($result); - $nid = $obj->id; + // Ajout des droits trouves grace au critere whereforadd + if ($whereforadd) + { + //print "$module-$perms-$subperms"; + $sql = "SELECT id"; + $sql.= " FROM ".MAIN_DB_PREFIX."rights_def"; + $sql.= " WHERE ".$whereforadd; - $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++; + $result=$this->db->query($sql); + if ($result) + { + $num = $this->db->num_rows($result); + $i = 0; + while ($i < $num) + { + $obj = $this->db->fetch_object($result); + $nid = $obj->id; - $i++; - } - } - else - { - $err++; - dolibarr_print_error($this->db); - } - } + $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++; - if ($err) { - $this->db->rollback(); - return -$err; - } - else { - $this->db->commit(); - return 1; - } + $i++; + } + } + else + { + $err++; + dolibarr_print_error($this->db); + } + } - } + if ($err) { + $this->db->rollback(); + return -$err; + } + else { + $this->db->commit(); + return 1; + } - - /** - * \brief Retire un droit a l'utilisateur - * \param rid id du droit a retirer - * \param allmodule Retirer tous les droits du module allmodule - * \param allperms Retirer tous les droits du module allmodule, perms allperms - * \return int > 0 si ok, < 0 si erreur - */ - function delrights($rid,$allmodule='',$allperms='') - { - $err=0; - $wherefordel=''; - - $this->db->begin(); - - if ($rid) - { - // Si on a demande supression d'un droit en particulier, on recupere - // les caracteristiques 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; - } - else { - $err++; - dolibarr_print_error($this->db); - } - - // Where pour la liste des droits a supprimer - $wherefordel="id=".$rid; - // Suppression des droits induits - if ($subperms=='lire' || $subperms=='read') $wherefordel.=" OR (module='$module' AND perms='$perms' AND subperms IS NOT NULL)"; - if ($perms=='lire' || $perms=='read') $wherefordel.=" OR (module='$module')"; - } - else { - // On a demande suppression d'un droit sur la base d'un nom de module ou perms - // Where pour la liste des droits a supprimer - if ($allmodule) $wherefordel="module='$allmodule'"; - if ($allperms) $wherefordel=" AND perms='$allperms'"; - } - - // Suppression des droits selon critere defini dans wherefordel - if ($wherefordel) - { - //print "$module-$perms-$subperms"; - $sql = "SELECT id"; - $sql.= " FROM ".MAIN_DB_PREFIX."rights_def"; - $sql.= " WHERE $wherefordel"; - - $result=$this->db->query($sql); - if ($result) - { - $num = $this->db->num_rows($result); - $i = 0; - while ($i < $num) - { - $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++; - - $i++; - } - } - else - { - $err++; - dolibarr_print_error($this->db); - } - } - - if ($err) { - $this->db->rollback(); - return -$err; - } - else { - $this->db->commit(); - return 1; - } - - } + } /** - * \brief Vide la tableau des droits de l'utilisateur - */ + * \brief Retire un droit a l'utilisateur + * \param rid id du droit a retirer + * \param allmodule Retirer tous les droits du module allmodule + * \param allperms Retirer tous les droits du module allmodule, perms allperms + * \return int > 0 si ok, < 0 si erreur + */ + function delrights($rid,$allmodule='',$allperms='') + { + $err=0; + $wherefordel=''; + + $this->db->begin(); + + if ($rid) + { + // Si on a demande supression d'un droit en particulier, on recupere + // les caracteristiques 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; + } + else { + $err++; + dolibarr_print_error($this->db); + } + + // Where pour la liste des droits a supprimer + $wherefordel="id=".$rid; + // Suppression des droits induits + if ($subperms=='lire' || $subperms=='read') $wherefordel.=" OR (module='$module' AND perms='$perms' AND subperms IS NOT NULL)"; + if ($perms=='lire' || $perms=='read') $wherefordel.=" OR (module='$module')"; + } + else { + // On a demande suppression d'un droit sur la base d'un nom de module ou perms + // Where pour la liste des droits a supprimer + if ($allmodule) $wherefordel="module='$allmodule'"; + if ($allperms) $wherefordel=" AND perms='$allperms'"; + } + + // Suppression des droits selon critere defini dans wherefordel + if ($wherefordel) + { + //print "$module-$perms-$subperms"; + $sql = "SELECT id"; + $sql.= " FROM ".MAIN_DB_PREFIX."rights_def"; + $sql.= " WHERE $wherefordel"; + + $result=$this->db->query($sql); + if ($result) + { + $num = $this->db->num_rows($result); + $i = 0; + while ($i < $num) + { + $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++; + + $i++; + } + } + else + { + $err++; + dolibarr_print_error($this->db); + } + } + + if ($err) { + $this->db->rollback(); + return -$err; + } + else { + $this->db->commit(); + return 1; + } + + } + + + /** + * \brief Vide la tableau des droits de l'utilisateur + */ function clearrights() - { + { $this->rights=''; $this->all_permissions_are_loaded=false; $this->tab_loaded=array(); @@ -477,11 +477,11 @@ class User extends CommonObject /** \brief Charge dans l'objet user, la liste des permissions auxquelles l'utilisateur a droit \param moduletag nom du module dont il faut recuperer les droits ('' par defaut signifie tous les droits) - */ + */ function getrights($moduletag='') { if ($moduletag && isset($this->tab_loaded[$moduletag]) && $this->tab_loaded[$moduletag]) - { + { // Le fichier de ce module est deja charge return; } @@ -491,15 +491,15 @@ class User extends CommonObject // Si les permissions ont deja ete charge pour ce user, on quitte return; } - + // Recuperation des droits utilisateurs + recuperation des droits groupes - + // D'abord les droits utilisateurs $sql = "SELECT r.module, r.perms, r.subperms"; $sql.= " FROM ".MAIN_DB_PREFIX."user_rights as ur, ".MAIN_DB_PREFIX."rights_def as r"; $sql.= " WHERE r.id = ur.fk_id AND ur.fk_user= ".$this->id." AND r.perms IS NOT NULL"; if ($moduletag) $sql.= " AND r.module = '".addslashes($moduletag)."'"; - + dolibarr_syslog('User::getRights sql='.$sql, LOG_DEBUG); $result = $this->db->query($sql); if ($result) @@ -519,8 +519,8 @@ class User extends CommonObject if ($subperms) { if (! isset($this->rights->$module) || - (is_object($this->rights->$module) && ! isset($this->rights->$module->$perms)) || - (is_object($this->rights->$module->$perms)) ) + (is_object($this->rights->$module) && ! isset($this->rights->$module->$perms)) || + (is_object($this->rights->$module->$perms)) ) { $this->rights->$module->$perms->$subperms = 1; } @@ -583,30 +583,30 @@ class User extends CommonObject } } - /** - * \brief Change statut d'un utilisateur - * \return int <0 si ko, >=0 si ok - */ + /** + * \brief Change statut d'un utilisateur + * \return int <0 si ko, >=0 si ok + */ function setstatus($statut) { global $conf,$langs,$user; - + $error=0; - + // Check parameters if ($this->statut == $statut) { return 0; } - + $this->db->begin(); - + // Desactive utilisateur $sql = "UPDATE ".MAIN_DB_PREFIX."user"; $sql.= " SET statut = ".$statut; $sql.= " WHERE rowid = ".$this->id; $result = $this->db->query($sql); - + dolibarr_syslog("User::setstatus sql=".$sql); if ($result) { @@ -614,10 +614,10 @@ class User extends CommonObject include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); $interface=new Interfaces($this->db); $result=$interface->run_triggers('USER_ENABLEDISABLE',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } + if ($result < 0) { $error++; $this->errors=$interface->errors; } // Fin appel triggers } - + if ($error) { $this->db->rollback(); @@ -630,77 +630,77 @@ class User extends CommonObject return 1; } } - - - /** - * \brief Supprime completement un utilisateur - */ - function delete() - { - global $user,$conf,$langs; - - $this->db->begin(); - - $this->fetch(); - - // 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_creat = null WHERE rowid = ".$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); - - if ($result) - { - // Appel des triggers - include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('USER_DELETE',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers - - $this->db->commit(); - return 1; - } - else - { - $this->db->rollback(); - return -1; - } - } - - /** - * \brief Cree l'utilisateur en base - * \param user Objet user qui demande la creation - * \param notrigger 1 ne declenche pas les triggers, 0 sinon - * \return int <0 si KO, id compte cree si OK - */ + + + /** + * \brief Supprime completement un utilisateur + */ + function delete() + { + global $user,$conf,$langs; + + $this->db->begin(); + + $this->fetch(); + + // 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_creat = null WHERE rowid = ".$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); + + if ($result) + { + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('USER_DELETE',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + return -1; + } + } + + /** + * \brief Cree l'utilisateur en base + * \param user Objet user qui demande la creation + * \param notrigger 1 ne declenche pas les triggers, 0 sinon + * \return int <0 si KO, id compte cree 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=".(is_object($user)?$user->id:'')); - + $error=0; $this->db->begin(); - + $sql = "SELECT login FROM ".MAIN_DB_PREFIX."user"; $sql.= " WHERE login ='".addslashes($this->login)."'"; $resql=$this->db->query($sql); @@ -708,7 +708,7 @@ class User extends CommonObject { $num = $this->db->num_rows($resql); $this->db->free($resql); - + if ($num) { $this->error = 'ErrorLoginAlreadyExists'; @@ -719,13 +719,13 @@ class User extends CommonObject { $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) { @@ -733,7 +733,7 @@ class User extends CommonObject $this->db->rollback(); return -5; } - + // Update minor fields $result = $this->update($user,1,1); if ($result < 0) @@ -761,7 +761,7 @@ class User extends CommonObject if ($result < 0) { $error++; $this->errors=$interface->errors; } // Fin appel triggers } - + if (! $error) { $this->db->commit(); @@ -792,235 +792,235 @@ class User extends CommonObject /** - * \brief Cree en base un utilisateur depuis l'objet contact - * \param contact Objet du contact source - * \return int si erreur <0, si ok renvoie id compte cree - */ + * \brief Cree en base un utilisateur depuis l'objet contact + * \param contact Objet du contact source + * \return int si erreur <0, si ok renvoie id compte cree + */ function create_from_contact($contact) { - global $user,$langs; + global $user,$langs; - // Positionne parametres - $this->nom = $contact->nom; - $this->prenom = $contact->prenom; + // Positionne parametres + $this->nom = $contact->nom; + $this->prenom = $contact->prenom; - $this->login = strtolower(substr($contact->prenom, 0, 4)) . strtolower(substr($contact->nom, 0, 4)); - $this->admin = 0; + $this->login = strtolower(substr($contact->prenom, 0, 4)) . strtolower(substr($contact->nom, 0, 4)); + $this->admin = 0; - $this->email = $contact->email; + $this->email = $contact->email; - $this->db->begin(); + $this->db->begin(); - // Cree et positionne $this->id - $result=$this->create($user); + // Cree et positionne $this->id + $result=$this->create($user); - 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 ($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) - { - $this->db->commit(); - return $this->id; - } - else - { - $this->error=$this->db->error()." - $sql"; - dolibarr_syslog("User::create_from_contact - 10 - ".$this->error); + if ($resql) + { + $this->db->commit(); + return $this->id; + } + 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 positionne - dolibarr_syslog("User::create_from_contact - 0"); + $this->db->rollback(); + return -1; + } + } + else + { + // $this->error deja positionne + dolibarr_syslog("User::create_from_contact - 0"); - $this->db->rollback(); - return $result; - } + $this->db->rollback(); + return $result; + } - } + } - /** - * \brief Cree en base un utilisateur depuis l'objet adherent - * \param member Objet adherent source - * \return int Si erreur <0, si ok renvoie id compte cree - */ - function create_from_member($member) - { - global $conf,$user,$langs; + /** + * \brief Cree en base un utilisateur depuis l'objet adherent + * \param member Objet adherent source + * \return int Si erreur <0, si ok renvoie id compte cree + */ + function create_from_member($member) + { + global $conf,$user,$langs; - // Positionne parametres - $this->nom = $member->nom; - $this->prenom = $member->prenom; + // Positionne parametres + $this->nom = $member->nom; + $this->prenom = $member->prenom; - $this->login = $member->login; + $this->login = $member->login; $this->pass = $member->pass; - $this->admin = 0; + $this->admin = 0; - $this->email = $member->email; + $this->email = $member->email; - $this->db->begin(); + $this->db->begin(); - // Cree et positionne $this->id - $result=$this->create($user); - if ($result > 0) - { + // Cree et positionne $this->id + $result=$this->create($user); + if ($result > 0) + { $result=$this->setPassword($user,$this->pass); $sql = "UPDATE ".MAIN_DB_PREFIX."user"; - $sql.= " SET fk_member=".$member->id; - $sql.= " WHERE rowid=".$this->id; - $resql=$this->db->query($sql); + $sql.= " SET fk_member=".$member->id; + $sql.= " WHERE rowid=".$this->id; + $resql=$this->db->query($sql); - if ($resql) - { + if ($resql) + { $this->db->commit(); return $this->id; - } - else - { - $this->error=$this->db->error()." - ".$sql; - dolibarr_syslog("User::create_from_member - 1 - ".$this->error); + } + else + { + $this->error=$this->db->error()." - ".$sql; + dolibarr_syslog("User::create_from_member - 1 - ".$this->error); - $this->db->rollback(); - return -1; - } + $this->db->rollback(); + return -1; + } } - else - { - // $this->error deja positionne - dolibarr_syslog("User::create_from_member - 2 - ".$this->error); + else + { + // $this->error deja positionne + dolibarr_syslog("User::create_from_member - 2 - ".$this->error); - $this->db->rollback(); - return $result; - } - } + $this->db->rollback(); + return $result; + } + } /** - * \brief Affectation des permissions par defaut - * \return Si erreur <0, si ok renvoi le nbre de droits par defaut positionnes - */ + * \brief Affectation des permissions par defaut + * \return Si erreur <0, si ok renvoi le nbre de droits par defaut positionnes + */ function set_default_rights() - { - $sql = "SELECT id FROM ".MAIN_DB_PREFIX."rights_def WHERE bydefault = 1"; + { + $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) - { + 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 = "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++; - } + $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; - } + return $i; + } + + /** + * \brief Mise e jour en base d'un utilisateur (sauf info mot de passe) + * \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($user,$notrigger=0,$nosyncmember=0) + { + global $conf, $langs; - /** - * \brief Mise e jour en base d'un utilisateur (sauf info mot de passe) - * \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($user,$notrigger=0,$nosyncmember=0) - { - global $conf, $langs; - $nbrowsaffected=0; $error=0; - dolibarr_syslog("User::update notrigger=".$notrigger.", nosyncmember=".$nosyncmember); + dolibarr_syslog("User::update notrigger=".$notrigger.", nosyncmember=".$nosyncmember); - // Nettoyage parametres - $this->nom = trim($this->nom); - $this->prenom = trim($this->prenom); - $this->fullname = $this->prenom." ".$this->nom; - $this->login = trim($this->login); - $this->pass = trim($this->pass); - $this->office_phone = trim($this->office_phone); - $this->office_fax = trim($this->office_fax); - $this->user_mobile = trim($this->user_mobile); - $this->email = trim($this->email); - $this->note = trim($this->note); - $this->webcal_login = trim($this->webcal_login); - $this->phenix_login = trim($this->phenix_login); - if ($this->phenix_pass != $this->phenix_pass_crypted) - { - $this->phenix_pass = md5(trim($this->phenix_pass)); - } - $this->admin = $this->admin?$this->admin:0; - - $this->db->begin(); - - // 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 = '".addslashes($this->office_phone)."'"; - $sql.= ", office_fax = '".addslashes($this->office_fax)."'"; - $sql.= ", user_mobile = '".addslashes($this->user_mobile)."'"; - $sql.= ", email = '".addslashes($this->email)."'"; - $sql.= ", webcal_login = '".addslashes($this->webcal_login)."'"; - $sql.= ", phenix_login = '".addslashes($this->phenix_login)."'"; - $sql.= ", phenix_pass = '".addslashes($this->phenix_pass)."'"; - $sql.= ", note = '".addslashes($this->note)."'"; - $sql.= " WHERE rowid = ".$this->id; + // Nettoyage parametres + $this->nom = trim($this->nom); + $this->prenom = trim($this->prenom); + $this->fullname = $this->prenom." ".$this->nom; + $this->login = trim($this->login); + $this->pass = trim($this->pass); + $this->office_phone = trim($this->office_phone); + $this->office_fax = trim($this->office_fax); + $this->user_mobile = trim($this->user_mobile); + $this->email = trim($this->email); + $this->note = trim($this->note); + $this->webcal_login = trim($this->webcal_login); + $this->phenix_login = trim($this->phenix_login); + if ($this->phenix_pass != $this->phenix_pass_crypted) + { + $this->phenix_pass = md5(trim($this->phenix_pass)); + } + $this->admin = $this->admin?$this->admin:0; - dolibarr_syslog("User::update sql=".$sql); - $resql = $this->db->query($sql); - if ($resql) - { - $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 different de celui en base - $result=$this->setPassword($user,$this->pass,0,$notrigger); - - if (! $nbrowsaffected) $nbrowsaffected++; - } - } - - if ($nbrowsaffected) + $this->db->begin(); + + // 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 = '".addslashes($this->office_phone)."'"; + $sql.= ", office_fax = '".addslashes($this->office_fax)."'"; + $sql.= ", user_mobile = '".addslashes($this->user_mobile)."'"; + $sql.= ", email = '".addslashes($this->email)."'"; + $sql.= ", webcal_login = '".addslashes($this->webcal_login)."'"; + $sql.= ", phenix_login = '".addslashes($this->phenix_login)."'"; + $sql.= ", phenix_pass = '".addslashes($this->phenix_pass)."'"; + $sql.= ", note = '".addslashes($this->note)."'"; + $sql.= " WHERE rowid = ".$this->id; + + dolibarr_syslog("User::update sql=".$sql); + $resql = $this->db->query($sql); + if ($resql) + { + $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 different de celui en base + $result=$this->setPassword($user,$this->pass,0,$notrigger); + + if (! $nbrowsaffected) $nbrowsaffected++; + } + } + + if ($nbrowsaffected) { if ($this->fk_member && ! $nosyncmember) { require_once(DOL_DOCUMENT_ROOT."/adherents/adherent.class.php"); - + // This user is linked with a member, so we also update members informations // if this is an update. $adh=new Adherent($this->db); $result=$adh->fetch($this->fk_member); - + if ($result >= 0) { $adh->prenom=$this->prenom; @@ -1032,7 +1032,7 @@ class User extends CommonObject $adh->email=$this->email; $adh->phone=$this->office_phone; $adh->phone_mobile=$this->user_mobile; - + $adh->note=$this->note; $adh->user_id=$this->id; @@ -1053,16 +1053,16 @@ class User extends CommonObject } } - if (! $error && ! $notrigger) - { - // Appel des triggers - include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('USER_MODIFY',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers - } - } + if (! $error && ! $notrigger) + { + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('USER_MODIFY',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + } + } if (! $error) { @@ -1074,81 +1074,81 @@ class User extends CommonObject } return $nbrowsaffected; - } - else - { + } + else + { $this->db->rollback(); - $this->error=$this->db->lasterror(); + $this->error=$this->db->lasterror(); dolibarr_syslog("User::update ".$this->error,LOG_ERROR); - return -1; - } + return -1; + } } /** - * \brief Mise e jour en base de la date de deniere connexion d'un utilisateur - * Fonction appelee lors d'une nouvelle connexion - * \return <0 si echec, >=0 si ok - */ + * \brief Mise e jour en base de la date de deniere connexion d'un utilisateur + * Fonction appelee lors d'une nouvelle connexion + * \return <0 si echec, >=0 si ok + */ function update_last_login_date() - { - dolibarr_syslog ("Mise a jour date derniere connexion pour user->id=".$this->id); + { + dolibarr_syslog ("Mise a jour date derniere connexion pour user->id=".$this->id); - $now=time(); + $now=time(); - $sql = "UPDATE ".MAIN_DB_PREFIX."user SET"; - $sql.= " datepreviouslogin = datelastlogin,"; - $sql.= " datelastlogin = ".$this->db->idate($now).","; - $sql.= " tms = tms"; // La date de derniere modif doit changer sauf pour la mise a jour de date de derniere connexion - $sql.= " WHERE rowid = ".$this->id; - $resql = $this->db->query($sql); - if ($resql) - { - $this->datepreviouslogin=$this->datelastlogin; - $this->datelastlogin=$now; - return 1; - } - else - { - $this->error=$this->db->error().' sql='.$sql; - return -1; - } - } + $sql = "UPDATE ".MAIN_DB_PREFIX."user SET"; + $sql.= " datepreviouslogin = datelastlogin,"; + $sql.= " datelastlogin = ".$this->db->idate($now).","; + $sql.= " tms = tms"; // La date de derniere modif doit changer sauf pour la mise a jour de date de derniere connexion + $sql.= " WHERE rowid = ".$this->id; + $resql = $this->db->query($sql); + if ($resql) + { + $this->datepreviouslogin=$this->datelastlogin; + $this->datelastlogin=$now; + return 1; + } + else + { + $this->error=$this->db->error().' sql='.$sql; + return -1; + } + } /** - * \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 en clair (a generer si non communique) - * \param changelater 1=Change password only after clicking on confirm email - * \param notrigger 1=Ne declenche pas les triggers - * \param nosyncmember Do not synchronize linked member - * \return string If OK return clear password, 0 if no change, < 0 if error - */ - function setPassword($user, $password='', $changelater=0, $notrigger=0, $nosyncmember=0) - { - global $conf, $langs; - + * \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 en clair (a generer si non communique) + * \param changelater 1=Change password only after clicking on confirm email + * \param notrigger 1=Ne declenche pas les triggers + * \param nosyncmember Do not synchronize linked member + * \return string If OK return clear password, 0 if no change, < 0 if error + */ + function setPassword($user, $password='', $changelater=0, $notrigger=0, $nosyncmember=0) + { + global $conf, $langs; + $error=0; - - dolibarr_syslog("User::Password user=".$user->id." password=".eregi_replace('.','*',$password)." changelater=".$changelater." notrigger=".$notrigger); - // Si nouveau mot de passe non communique, on genere par module - if (! $password) - { - // TODO Mettre appel au module de generation de mot de passe - $password=creer_pass_aleatoire_1(''); - //$password=creer_pass_aleatoire_2(''); - } + dolibarr_syslog("User::Password user=".$user->id." password=".eregi_replace('.','*',$password)." changelater=".$changelater." notrigger=".$notrigger); - // Crypte avec md5 - $password_crypted = md5($password); + // Si nouveau mot de passe non communique, on genere par module + if (! $password) + { + // TODO Mettre appel au module de generation de mot de passe + $password=creer_pass_aleatoire_1(''); + //$password=creer_pass_aleatoire_2(''); + } + + // Crypte avec md5 + $password_crypted = md5($password); // Mise a jour if (! $changelater) { - $sql = "UPDATE ".MAIN_DB_PREFIX."user"; + $sql = "UPDATE ".MAIN_DB_PREFIX."user"; $sql.= " SET pass_crypted = '".addslashes($password_crypted)."',"; $sql.= " pass_temp = null"; if (! empty($conf->global->DATABASE_PWD_ENCRYPTED)) @@ -1159,28 +1159,28 @@ class User extends CommonObject { $sql.= ", pass = '".addslashes($password)."'"; } - $sql.= " WHERE rowid = ".$this->id; + $sql.= " WHERE rowid = ".$this->id; //dolibarr_syslog("User::Password sql=hidden"); dolibarr_syslog("User::Password sql=".$sql); - $result = $this->db->query($sql); - if ($result) - { + $result = $this->db->query($sql); + if ($result) + { if ($this->db->affected_rows($result)) - { - $this->pass=$password; - $this->pass_indatabase=$password; - $this->pass_indatabase_crypted=$password_crypted; + { + $this->pass=$password; + $this->pass_indatabase=$password; + $this->pass_indatabase_crypted=$password_crypted; if ($this->fk_member && ! $nosyncmember) { require_once(DOL_DOCUMENT_ROOT."/adherents/adherent.class.php"); - + // This user is linked with a member, so we also update members informations // if this is an update. $adh=new Adherent($this->db); $result=$adh->fetch($this->fk_member); - + if ($result >= 0) { $result=$adh->setPassword($user,$this->pass,0,1); // Cryptage non gere dans module adherent @@ -1200,26 +1200,26 @@ class User extends CommonObject if (! $error && ! $notrigger) { - // Appel des triggers + // 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,$langs,$conf); - if ($result < 0) $this->errors=$interface->errors; - // Fin appel triggers + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('USER_NEW_PASSWORD',$this,$user,$langs,$conf); + if ($result < 0) $this->errors=$interface->errors; + // Fin appel triggers } - - return $this->pass; - } - else + + return $this->pass; + } + else { - return 0; - } - } - else - { - dolibarr_print_error($this->db); - return -1; - } + return 0; + } + } + else + { + dolibarr_print_error($this->db); + return -1; + } } else { @@ -1227,194 +1227,194 @@ class User extends CommonObject // After receiving confirmation link, we will crypt it and store it in pass_crypted $sql = "UPDATE ".MAIN_DB_PREFIX."user"; $sql.= " SET pass_temp = '".addslashes($password)."'"; - $sql.= " WHERE rowid = ".$this->id; + $sql.= " WHERE rowid = ".$this->id; // dolibarr_syslog("User::update sql=".$sql); Pas de trace - $result = $this->db->query($sql); - if ($result) + $result = $this->db->query($sql); + if ($result) { - return $password; + return $password; } else { - dolibarr_print_error($this->db); - return -3; - } + dolibarr_print_error($this->db); + return -3; + } } - } + } /** - * \brief Envoie mot de passe par mail - * \param user Object user de l'utilisateur qui fait l'envoi - * \param password Nouveau mot de passe - * \param changelater 1=Change password only after clicking on confirm email - * \return int < 0 si erreur, > 0 si ok - */ - function send_password($user, $password='', $changelater=0) - { - global $conf,$langs; + * \brief Envoie mot de passe par mail + * \param user Object user de l'utilisateur qui fait l'envoi + * \param password Nouveau mot de passe + * \param changelater 1=Change password only after clicking on confirm email + * \return int < 0 si erreur, > 0 si ok + */ + function send_password($user, $password='', $changelater=0) + { + global $conf,$langs; - require_once DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php"; + require_once DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php"; - $subject = $langs->trans("SubjectNewPassword"); - $msgishtml=0; + $subject = $langs->trans("SubjectNewPassword"); + $msgishtml=0; // Define $msg - $mesg = ''; + $mesg = ''; if (! $changelater) { $mesg.= "A request to change your Dolibarr password has been received.\n"; - $mesg.= "This is your new keys to login:\n\n"; - $mesg.= $langs->trans("Login")." : $this->login\n"; - $mesg.= $langs->trans("Password")." : $password\n\n"; + $mesg.= "This is your new keys to login:\n\n"; + $mesg.= $langs->trans("Login")." : $this->login\n"; + $mesg.= $langs->trans("Password")." : $password\n\n"; $mesg.= "\n"; - $url = "http://".$_SERVER["HTTP_HOST"].DOL_URL_ROOT; + $url = "http://".$_SERVER["HTTP_HOST"].DOL_URL_ROOT; $mesg.= 'Go to Dolibarr'."\n\n"; - $mesg.= "--\n"; - $mesg.= $user->fullname; // Username that make then sending + $mesg.= "--\n"; + $mesg.= $user->fullname; // Username that make then sending } else { $mesg.= "A request to change your Dolibarr password has been received.\n"; - $mesg.= "Your new key to login will be:\n\n"; - $mesg.= $langs->trans("Login")." : $this->login\n"; + $mesg.= "Your new key to login will be:\n\n"; + $mesg.= $langs->trans("Login")." : $this->login\n"; $mesg.= $langs->trans("Password")." : $password\n\n"; $mesg.= "\n"; $mesg.= "You must click on the folowing link to validate its change.\n"; - $url = "http://".$_SERVER["HTTP_HOST"].DOL_URL_ROOT.'/user/passwordforgotten.php?action=validatenewpassword&username='.$this->login."&passwordmd5=".md5($password); - $mesg.= $url."\n\n"; + $url = "http://".$_SERVER["HTTP_HOST"].DOL_URL_ROOT.'/user/passwordforgotten.php?action=validatenewpassword&username='.$this->login."&passwordmd5=".md5($password); + $mesg.= $url."\n\n"; $mesg.= "If you didn't ask anything, just forget this email\n\n"; dolibarr_syslog("User::send_password url=".$url); } - $mailfile = new CMailFile($subject,$this->email,$conf->notification->email_from,$mesg, - array(),array(),array(), + $mailfile = new CMailFile($subject,$this->email,$conf->notification->email_from,$mesg, + array(),array(),array(), '', '', 0, $msgishtml); - if ($mailfile->sendfile()) - { - return 1; - } - else - { - $this->error=$langs->trans("ErrorFailedToSendPassword").' '.$mailfile->error; + if ($mailfile->sendfile()) + { + return 1; + } + else + { + $this->error=$langs->trans("ErrorFailedToSendPassword").' '.$mailfile->error; //print nl2br($mesg); - return -1; - } - } + return -1; + } + } - /** - * \brief Renvoie la derniere erreur fonctionnelle de manipulation de l'objet - * \return string chaine erreur - */ + /** + * \brief Renvoie la derniere erreur fonctionnelle de manipulation de l'objet + * \return string chaine erreur + */ function error() - { - return $this->error; - } - - - /** - * \brief Lecture des infos de click to dial - */ - function fetch_clicktodial() - { - - $sql = "SELECT login, pass, poste "; - $sql.= " FROM ".MAIN_DB_PREFIX."user_clicktodial as u"; - $sql.= " WHERE u.fk_user = ".$this->id; - - $result = $this->db->query($sql); - - if ($result) { + return $this->error; + } + + + /** + * \brief Lecture des infos de click to dial + */ + function fetch_clicktodial() + { + + $sql = "SELECT login, pass, poste "; + $sql.= " 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(); + { + $obj = $this->db->fetch_object(); - $this->clicktodial_login = $obj->login; - $this->clicktodial_password = $obj->pass; - $this->clicktodial_poste = $obj->poste; + $this->clicktodial_login = $obj->login; + $this->clicktodial_password = $obj->pass; + $this->clicktodial_poste = $obj->poste; - if (strlen(trim($this->clicktodial_login)) && + if (strlen(trim($this->clicktodial_login)) && strlen(trim($this->clicktodial_password)) && strlen(trim($this->clicktodial_poste))) - { - $this->clicktodial_enabled = 1; - } + { + $this->clicktodial_enabled = 1; + } - } + } $this->db->free(); - } - else - { + } + else + { print $this->db->error(); + } } - } - /** - * \brief Mise e jour des infos de click to dial - */ - function update_clicktodial() - { - - $sql = "DELETE FROM ".MAIN_DB_PREFIX."user_clicktodial"; - $sql .= " WHERE fk_user = ".$this->id; - - $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) + /** + * \brief Mise e jour des infos de click to dial + */ + function update_clicktodial() { + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."user_clicktodial"; + $sql .= " WHERE fk_user = ".$this->id; + + $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 - { + } + else + { print $this->db->error(); + } } - } - /** - * \brief Ajoute l'utilisateur dans un groupe - * \param group id du groupe - */ - function SetInGroup($group) - { + /** + * \brief Ajoute l'utilisateur dans un groupe + * \param group id du groupe + */ + function SetInGroup($group) + { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."usergroup_user"; - $sql .= " WHERE fk_user = ".$this->id; - $sql .= " AND fk_usergroup = ".$group; + $sql = "DELETE FROM ".MAIN_DB_PREFIX."usergroup_user"; + $sql .= " WHERE fk_user = ".$this->id; + $sql .= " AND fk_usergroup = ".$group; - $result = $this->db->query($sql); + $result = $this->db->query($sql); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."usergroup_user (fk_user, fk_usergroup)"; - $sql .= " VALUES (".$this->id.",".$group.")"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."usergroup_user (fk_user, fk_usergroup)"; + $sql .= " VALUES (".$this->id.",".$group.")"; - $result = $this->db->query($sql); - } + $result = $this->db->query($sql); + } /** * \brief Retire l'utilisateur d'un groupe * \param group id du groupe */ function RemoveFromGroup($group) - { + { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."usergroup_user"; - $sql .= " WHERE fk_user = ".$this->id; - $sql .= " AND fk_usergroup = ".$group; + $sql = "DELETE FROM ".MAIN_DB_PREFIX."usergroup_user"; + $sql .= " WHERE fk_user = ".$this->id; + $sql .= " AND fk_usergroup = ".$group; - $result = $this->db->query($sql); - } + $result = $this->db->query($sql); + } /** * \brief Renvoie nom clicable (avec eventuellement le picto) @@ -1524,13 +1524,13 @@ class User extends CommonObject /* - * \brief Retourne chaine DN complete dans l'annuaire LDAP pour l'objet - * \param info Info string loaded by _load_ldap_info - * \param mode 0=Return DN without key inside (ou=xxx,dc=aaa,dc=bbb) - 1=Return full DN (uid=qqq,ou=xxx,dc=aaa,dc=bbb) - 2=Return key only (uid=qqq) - * \return string DN - */ + * \brief Retourne chaine DN complete dans l'annuaire LDAP pour l'objet + * \param info Info string loaded by _load_ldap_info + * \param mode 0=Return DN without key inside (ou=xxx,dc=aaa,dc=bbb) + 1=Return full DN (uid=qqq,ou=xxx,dc=aaa,dc=bbb) + 2=Return key only (uid=qqq) + * \return string DN + */ function _load_ldap_dn($info,$mode=0) { global $conf; @@ -1543,9 +1543,9 @@ class User extends CommonObject /* - * \brief Initialise tableau info (tableau des attributs LDAP) - * \return array Tableau info des attributs - */ + * \brief Initialise tableau info (tableau des attributs LDAP) + * \return array Tableau info des attributs + */ function _load_ldap_info() { global $conf,$langs; @@ -1554,7 +1554,7 @@ class User extends CommonObject // Object classes $info["objectclass"]=split(',',$conf->global->LDAP_USER_OBJECT_CLASS); - + // Champs if ($this->fullname && $conf->global->LDAP_FIELD_FULLNAME) $info[$conf->global->LDAP_FIELD_FULLNAME] = $this->fullname; if ($this->nom && $conf->global->LDAP_FIELD_NAME) $info[$conf->global->LDAP_FIELD_NAME] = $this->nom; @@ -1609,7 +1609,7 @@ class User extends CommonObject return $info; } - + /** * \brief Initialise le user avec valeurs fictives aleatoire @@ -1663,123 +1663,123 @@ class User extends CommonObject $this->societe_id = $socids[$socid]; } - /** - * \brief Charge la liste des entrepots pour l'utilisateur - * \return int 0 si ok, <> 0 si erreur - */ - function load_entrepots() - { - $err=0; - $this->entrepots = array(); - $sql = "SELECT e.rowid,ue.consult,ue.send,e.label"; - $sql.= " FROM ".MAIN_DB_PREFIX."user_entrepot as ue,".MAIN_DB_PREFIX."entrepot as e"; - $sql.= " WHERE fk_user = '".$this->id."'"; - $sql .= " AND e.statut = 1"; - $sql .= " AND e.rowid = ue.fk_entrepot"; - - if ( $this->db->query($sql) ) - { - $i=0; - while ($obj = $this->db->fetch_object($result) ) + /** + * \brief Charge la liste des entrepots pour l'utilisateur + * \return int 0 si ok, <> 0 si erreur + */ + function load_entrepots() + { + $err=0; + $this->entrepots = array(); + $sql = "SELECT e.rowid,ue.consult,ue.send,e.label"; + $sql.= " FROM ".MAIN_DB_PREFIX."user_entrepot as ue,".MAIN_DB_PREFIX."entrepot as e"; + $sql.= " WHERE fk_user = '".$this->id."'"; + $sql .= " AND e.statut = 1"; + $sql .= " AND e.rowid = ue.fk_entrepot"; + + if ( $this->db->query($sql) ) + { + $i=0; + while ($obj = $this->db->fetch_object($result) ) { - $this->entrepots[$i]['id'] = $obj->consult; - $this->entrepots[$i]['consult'] = $obj->consult; - $this->entrepots[$i]['send'] = $obj->send; - $this->entrepots[$i]['label'] = $obj->label; - $i++; + $this->entrepots[$i]['id'] = $obj->consult; + $this->entrepots[$i]['consult'] = $obj->consult; + $this->entrepots[$i]['send'] = $obj->send; + $this->entrepots[$i]['label'] = $obj->label; + $i++; } - } - else - { - $err++; - dolibarr_print_error($this->db); - } - return $err; - } + } + else + { + $err++; + dolibarr_print_error($this->db); + } + return $err; + } - - /* - * \brief Charge les informations d'ordre info dans l'objet user - * \param id id du user a charger - */ - function info($id) - { - $sql = "SELECT u.rowid, u.login as ref, ".$this->db->pdate("datec")." as datec,"; - $sql.= $this->db->pdate("u.tms")." as date_modification"; - $sql.= " FROM ".MAIN_DB_PREFIX."user as u"; - $sql.= " WHERE u.rowid = ".$id; - $result=$this->db->query($sql); - if ($result) - { - if ($this->db->num_rows($result)) - { - $obj = $this->db->fetch_object($result); + /* + * \brief Charge les informations d'ordre info dans l'objet user + * \param id id du user a charger + */ + function info($id) + { + $sql = "SELECT u.rowid, u.login as ref, ".$this->db->pdate("datec")." as datec,"; + $sql.= $this->db->pdate("u.tms")." as date_modification"; + $sql.= " FROM ".MAIN_DB_PREFIX."user as u"; + $sql.= " WHERE u.rowid = ".$id; - $this->id = $obj->rowid; + $result=$this->db->query($sql); + if ($result) + { + if ($this->db->num_rows($result)) + { + $obj = $this->db->fetch_object($result); - $this->ref = (! $obj->ref) ? $obj->rowid : $obj->ref; - $this->date_creation = $obj->datec; - $this->date_modification = $obj->date_modification; - } + $this->id = $obj->rowid; - $this->db->free($result); + $this->ref = (! $obj->ref) ? $obj->rowid : $obj->ref; + $this->date_creation = $obj->datec; + $this->date_modification = $obj->date_modification; + } - } - else - { - dolibarr_print_error($this->db); - } - } + $this->db->free($result); + + } + else + { + dolibarr_print_error($this->db); + } + } } /** - \brief Fonction pour creer un mot de passe aleatoire en minuscule - \param sel Donnee aleatoire - \return string Mot de passe -*/ + \brief Fonction pour creer un mot de passe aleatoire en minuscule + \param sel Donnee aleatoire + \return string Mot de passe + */ function creer_pass_aleatoire_1($sel = "") { - $longueur = 8; - - return strtolower(substr(md5(uniqid(rand())),0,$longueur)); + $longueur = 8; + + return strtolower(substr(md5(uniqid(rand())),0,$longueur)); } /** - \brief Fonction pour creer un mot de passe aleatoire melangeant majuscule, - minuscule, chiffre et alpha et caracteres speciaux - \remarks La fonction a ete prise sur http://www.uzine.net/spip - \param sel Donnee aleatoire - \return string Mot de passe -*/ + \brief Fonction pour creer un mot de passe aleatoire melangeant majuscule, + minuscule, chiffre et alpha et caracteres speciaux + \remarks La fonction a ete prise sur http://www.uzine.net/spip + \param sel Donnee aleatoire + \return string Mot de passe + */ function creer_pass_aleatoire_2($sel = "") { - $longueur=8; - - $seed = (double) (microtime() + 1) * time(); - srand($seed); - - for ($i = 0; $i < $longueur; $i++) - { - if (!$s) + $longueur=8; + + $seed = (double) (microtime() + 1) * time(); + srand($seed); + + for ($i = 0; $i < $longueur; $i++) { + if (!$s) + { if (!$s) $s = rand(); $s = substr(md5(uniqid($s).$sel), 0, 16); + } + $r = unpack("Cr", pack("H2", $s.$s)); + $x = $r['r'] & 63; + if ($x < 10) $x = chr($x + 48); + else if ($x < 36) $x = chr($x + 55); + else if ($x < 62) $x = chr($x + 61); + else if ($x == 63) $x = '/'; + else $x = '.'; + $pass .= $x; + $s = substr($s, 2); } - $r = unpack("Cr", pack("H2", $s.$s)); - $x = $r['r'] & 63; - if ($x < 10) $x = chr($x + 48); - else if ($x < 36) $x = chr($x + 55); - else if ($x < 62) $x = chr($x + 61); - else if ($x == 63) $x = '/'; - else $x = '.'; - $pass .= $x; - $s = substr($s, 2); - } - return $pass; + return $pass; }