diff --git a/htdocs/adherents/adherent.class.php b/htdocs/adherents/adherent.class.php index 2906b1d905b..befef900bb0 100644 --- a/htdocs/adherents/adherent.class.php +++ b/htdocs/adherents/adherent.class.php @@ -47,6 +47,9 @@ class Adherent { var $id; var $db; + var $error; + var $errors=array(); + var $prenom; var $nom; var $fullname; @@ -81,11 +84,13 @@ class Adherent var $type; // Libellé type adherent var $need_subscription; + var $user_id; + var $user_login; + + // var $public; var $array_options; - var $error; - var $errors=array(); /** @@ -687,9 +692,11 @@ class Adherent $sql.= " ".$this->db->pdate("d.datevalid")." as datev,"; $sql.= " d.pays,"; $sql.= " p.rowid as pays_id, p.code as pays_code, p.libelle as pays_lib,"; - $sql.= " t.libelle as type, t.cotisation as cotisation"; + $sql.= " t.libelle as type, t.cotisation as cotisation,"; + $sql.= " u.rowid as user_id, u.login as user_login"; $sql.= " FROM ".MAIN_DB_PREFIX."adherent_type as t, ".MAIN_DB_PREFIX."adherent as d"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_pays as p ON d.pays = p.rowid"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON d.rowid = u.fk_member"; $sql.= " WHERE d.rowid = ".$rowid." AND d.fk_adherent_type = t.rowid"; dolibarr_syslog("Adherent::fetch sql=".$sql); @@ -736,6 +743,9 @@ class Adherent $this->typeid = $obj->fk_adherent_type; $this->type = $obj->type; $this->need_subscription = ($obj->cotisation=='yes'?1:0); + + $this->user_id = $obj->user_id; + $this->user_login = $obj->user_login; } return 1; } diff --git a/htdocs/adherents/fiche.php b/htdocs/adherents/fiche.php index 1a6d2698cef..24f0915cf86 100644 --- a/htdocs/adherents/fiche.php +++ b/htdocs/adherents/fiche.php @@ -58,6 +58,33 @@ $typeid=isset($_GET["typeid"])?$_GET["typeid"]:$_POST["typeid"]; * Actions */ +// Creation utilisateur depuis adherent +if ($user->rights->user->user->creer) +{ + if ($_GET["action"] == 'create_user') + { + // Recuperation contact actuel + $adh = new Adherent($db); + $result = $adh->fetch($_GET["rowid"]); + + if ($result > 0) + { + // Creation user + $nuser = new User($db); + $result=$nuser->create_from_member($adh); + + if ($result < 0) + { + $msg=$nuser->error; + } + } + else + { + $msg=$adh->error; + } + } +} + if ($_POST["action"] == 'confirm_sendinfo' && $_POST["confirm"] == 'yes') { $adh->id = $rowid; @@ -750,6 +777,7 @@ if ($rowid && $action != 'edit') dolibarr_fiche_head($head, 'general', $langs->trans("Member")); + if ($msg) print '
'.$msg.'
'; $result=$adh->load_previous_next_id($adh->next_prev_filter); if ($result < 0) dolibarr_print_error($db,$adh->error); @@ -889,6 +917,19 @@ if ($rowid && $action != 'edit') // Status print ''.$langs->trans("Status").''.$adh->getLibStatut(4).''; + + // Login Dolibarr + print ''.$langs->trans("DolibarrLogin").''; + if ($adh->user_id) + { + $dolibarr_user=new User($db); + $dolibarr_user->id=$adh->user_id; + $result=$dolibarr_user->fetch(); + print $dolibarr_user->getLoginUrl(1); + } + else print $langs->trans("NoDolibarrAccess"); + print ''; + // Autres attributs foreach($adho->attribute_label as $key=>$value){ @@ -933,6 +974,15 @@ if ($rowid && $action != 'edit') { print "".$langs->trans("Resiliate")."\n"; } + + // Barre d'actions + if (! $user->societe_id) + { + if (! $adh->user_id && $user->rights->user->user->creer) + { + print ''.$langs->trans("CreateDolibarrLogin").''; + } + } // Supprimer if ($user->rights->adherent->supprimer) diff --git a/htdocs/admin/security.php b/htdocs/admin/security.php index 350a0600219..2b6f4e88435 100644 --- a/htdocs/admin/security.php +++ b/htdocs/admin/security.php @@ -213,7 +213,7 @@ foreach ($arrayhandler as $key => $module) // Affiche example print ''.$module->getExample().''; - print ''; + print ''; if ($conf->global->USER_PASSWORD_GENERATED == $key) { $title=''; @@ -253,7 +253,7 @@ print ''; $var=!$var; print ""; print ''.$langs->trans("DoNotStoreClearPassword").''; -print ''; +print ''; if($conf->global->DATABASE_PWD_ENCRYPTED == 1) { print img_tick(); @@ -291,7 +291,7 @@ print ''; $var=!$var; print ""; print ''.$langs->trans("MainDbPasswordFileConfEncrypted").''; -print ''; +print ''; if($conf->global->MAIN_DATABASE_PWD_CONFIG_ENCRYPTED == 1) { print img_tick(); @@ -323,7 +323,7 @@ $text = $langs->trans("ProtectAndEncryptPdfFiles"); $desc = $html->textwithwarning($text,$langs->transnoentities("ProtectAndEncryptPdfFilesDesc"),1); print $desc; print ''; -print ''; +print ''; if($conf->global->PDF_SECURITY_ENCRYPTION == 1) { print img_tick(); diff --git a/htdocs/contact.class.php b/htdocs/contact.class.php index 37ea9b0cf59..2a7ddc69ec8 100644 --- a/htdocs/contact.class.php +++ b/htdocs/contact.class.php @@ -65,6 +65,10 @@ class Contact var $ref_commande; // Nb de reference commande pour lequel il est contact var $ref_propal; // Nb de reference propal pour lequel il est contact + var $user_id; + var $user_login; + + /** * \brief Constructeur de l'objet contact * \param DB Habler d'accès base diff --git a/htdocs/contact/fiche.php b/htdocs/contact/fiche.php index 25fd5e6fb09..81c2a5f2ced 100644 --- a/htdocs/contact/fiche.php +++ b/htdocs/contact/fiche.php @@ -81,11 +81,21 @@ if ($user->rights->user->user->creer) $contact = new Contact($db); $result = $contact->fetch($_GET["id"]); - // Creation user - $nuser = new User($db); - $nuser->nom = $contact->name; - $nuser->prenom = $contact->firstname; - $nuser->create_from_contact($contact); + if ($result > 0) + { + // Creation user + $nuser = new User($db); + $result=$nuser->create_from_contact($contact); + + if ($result < 0) + { + $msg=$nuser->error; + } + } + else + { + $msg=$contact->error; + } } } @@ -445,6 +455,7 @@ if ($user->rights->societe->contact->creer) print ''; } + // Login Dolibarr print ''.$langs->trans("DolibarrLogin").''; if ($contact->user_id) { @@ -473,6 +484,7 @@ if ($_GET["id"] && $_GET["action"] != 'edit') * Fiche en mode visualisation * */ + if ($msg) print '
'.$msg.'
'; print ''; @@ -598,7 +610,7 @@ if ($_GET["id"] && $_GET["action"] != 'edit') print ''.$langs->trans('Edit').''; } - if (! $contact->user_id && $user->admin && $contact->socid > 0) + if (! $contact->user_id && $user->rights->user->user->creer && $contact->socid > 0) { print ''.$langs->trans("CreateDolibarrLogin").''; } diff --git a/htdocs/user.class.php b/htdocs/user.class.php index eacede09a0b..a09749d0ed7 100644 --- a/htdocs/user.class.php +++ b/htdocs/user.class.php @@ -653,6 +653,8 @@ class User // Nettoyage parametres $this->login = trim($this->login); + dolibarr_syslog("User::Create login=".$this->login.", user=".$user->id); + $this->db->begin(); $sql = "SELECT login FROM ".MAIN_DB_PREFIX."user"; @@ -744,7 +746,7 @@ class User $this->nom = $contact->nom; $this->prenom = $contact->prenom; - $this->login = strtolower(substr($contact->prenom, 0, 3)) . strtolower(substr($contact->nom, 0, 3)); + $this->login = strtolower(substr($contact->prenom, 0, 4)) . strtolower(substr($contact->nom, 0, 4)); $this->admin = 0; $this->email = $contact->email; @@ -803,10 +805,64 @@ class User } /** - * \brief Affectation des permissions par défaut - * \return si erreur <0, si ok renvoi le nbre de droits par defaut positionnés + * \brief Créé en base un utilisateur depuis l'objet adherent + * \param member Objet adherent source + * \return int Si erreur <0, si ok renvoie id compte créé */ - function set_default_rights() + function create_from_member($member) + { + global $langs; + + // Positionne paramètres + $this->nom = $member->nom; + $this->prenom = $member->prenom; + + $this->login = $member->login; + $this->admin = 0; + + $this->email = $member->email; + + $this->db->begin(); + + // Crée et positionne $this->id + $result=$this->create(); + + if ($result > 0) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."user"; + $sql.= " SET fk_member=".$member->id; + $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_member - 1 - ".$this->error); + + $this->db->rollback(); + return -1; + } + } + else + { + // $this->error deja positionné + dolibarr_syslog("User::create_from_member - 2 - ".$this->error); + + $this->db->rollback(); + return $result; + } + } + + /** + * \brief Affectation des permissions par défaut + * \return Si erreur <0, si ok renvoi le nbre de droits par defaut positionnés + */ + function set_default_rights() { $sql = "SELECT id FROM ".MAIN_DB_PREFIX."rights_def WHERE bydefault = 1"; diff --git a/mysql/migration/2.0.0-2.1.0.sql b/mysql/migration/2.0.0-2.1.0.sql index 8b137b4454d..806b605b076 100644 --- a/mysql/migration/2.0.0-2.1.0.sql +++ b/mysql/migration/2.0.0-2.1.0.sql @@ -732,15 +732,33 @@ alter table llx_user add column office_phone varchar(20); alter table llx_user add column office_fax varchar(20); alter table llx_user add column user_mobile varchar(20); + alter table llx_user modify login varchar(24) NOT NULL; alter table llx_user drop code; -ALTER TABLE llx_user ADD UNIQUE uk_user_login (login); update llx_user set pass_crypted = MD5(pass) where pass IS NOT NULL AND pass_crypted IS NULL and length(pass) < 32; update llx_user set pass_crypted = pass where pass IS NOT NULL AND pass_crypted IS NULL and length(pass) = 32; update llx_user set pass = NULL where length(pass) = 32; +ALTER TABLE llx_user modify fk_societe integer; +ALTER TABLE llx_user modify fk_socpeople integer; +alter table llx_user add column fk_member integer after fk_socpeople; + +update llx_user set fk_societe = NULL where fk_societe = 0; +update llx_user set fk_socpeople = NULL where fk_socpeople = 0; +update llx_user set fk_member = NULL where fk_member = 0; + +ALTER TABLE llx_user DROP INDEX login; + +ALTER TABLE llx_user ADD UNIQUE INDEX uk_user_login (login); + +ALTER TABLE llx_user ADD INDEX uk_user_fk_societe (fk_societe); + +ALTER TABLE llx_user ADD UNIQUE INDEX uk_user_fk_socpeople (fk_socpeople); +ALTER TABLE llx_user ADD UNIQUE INDEX uk_user_fk_member (fk_member); + + alter table llx_boxes add column fk_user integer; alter table llx_commande_fournisseur drop column fk_soc_contact; diff --git a/mysql/tables/llx_user.key.sql b/mysql/tables/llx_user.key.sql index e937ea04a41..bebb93884e8 100644 --- a/mysql/tables/llx_user.key.sql +++ b/mysql/tables/llx_user.key.sql @@ -1,7 +1,7 @@ -- ============================================================================ --- Copyright (C) 2003 Rodolphe Quiedeville --- Copyright (C) 2006 Laurent Destailleur --- Copyright (C) 2007 Regis Houssin +-- Copyright (C) 2003 Rodolphe Quiedeville +-- Copyright (C) 2006-2007 Laurent Destailleur +-- Copyright (C) 2007 Regis Houssin -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by @@ -23,4 +23,9 @@ -- =========================================================================== -ALTER TABLE llx_user ADD UNIQUE uk_user_login (login); \ No newline at end of file +ALTER TABLE llx_user ADD UNIQUE INDEX uk_user_login (login); + +ALTER TABLE llx_user ADD INDEX uk_user_fk_societe (fk_societe); + +ALTER TABLE llx_user ADD UNIQUE INDEX uk_user_fk_socpeople (fk_socpeople); +ALTER TABLE llx_user ADD UNIQUE INDEX uk_user_fk_member (fk_member); diff --git a/mysql/tables/llx_user.sql b/mysql/tables/llx_user.sql index 5bea59abe32..b0768a9f9e4 100644 --- a/mysql/tables/llx_user.sql +++ b/mysql/tables/llx_user.sql @@ -1,6 +1,6 @@ -- ============================================================================ -- Copyright (C) 2001-2003 Rodolphe Quiedeville --- Copyright (C) 2006 Laurent Destailleur +-- Copyright (C) 2006-2007 Laurent Destailleur -- Copyright (C) 2007 Regis Houssin -- -- This program is free software; you can redistribute it and/or modify @@ -40,8 +40,9 @@ create table llx_user webcal_login varchar(25), module_comm smallint DEFAULT 1, module_compta smallint DEFAULT 1, - fk_societe integer DEFAULT 0, - fk_socpeople integer DEFAULT 0, + fk_societe integer, + fk_socpeople integer, + fk_member integer, note text DEFAULT NULL, datelastlogin datetime, datepreviouslogin datetime,