From ec98799c1421174bfb89eedd0bd5f002ac53fdb3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 17 Dec 2008 18:34:47 +0000 Subject: [PATCH] New: Can choose login of dolibarr account created when create from contact --- ChangeLog | 1 + htdocs/contact/fiche.php | 158 +++++++++++++++++----------------- htdocs/html.form.class.php | 3 + htdocs/langs/en_US/users.lang | 4 +- htdocs/langs/fr_FR/users.lang | 2 + htdocs/user.class.php | 13 +-- 6 files changed, 97 insertions(+), 84 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6e28faee427..70b14ebc579 100644 --- a/ChangeLog +++ b/ChangeLog @@ -38,6 +38,7 @@ For users: - Show greyed lines for not allowed export filters. - Add nature in product fields (manufactured product or not). - Add export filters for category module. +- Can choose login of dolibarr account created when create from contact For translators: - The errors language file contains only error or warning messages with diff --git a/htdocs/contact/fiche.php b/htdocs/contact/fiche.php index b0c564b242f..ba1961d6840 100644 --- a/htdocs/contact/fiche.php +++ b/htdocs/contact/fiche.php @@ -51,37 +51,32 @@ $result = restrictedArea($user, 'contact', $contactid, 'socpeople'); */ // Creation utilisateur depuis contact -if ($user->rights->user->user->creer) +if ($_POST["action"] == 'confirm_create_user' && $_POST["confirm"] == 'yes' && $user->rights->user->user->creer) { - if ($_GET["action"] == 'create_user') + // Recuperation contact actuel + $contact = new Contact($db); + $result = $contact->fetch($_GET["id"]); + + if ($result > 0) { - // Recuperation contact actuel - $contact = new Contact($db); - $result = $contact->fetch($_GET["id"]); + // Creation user + $nuser = new User($db); + $result=$nuser->create_from_contact($contact,$_POST["login"]); - if ($result > 0) + 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; + $msg=$nuser->error; } } + else + { + $msg=$contact->error; + } } // Creation contact -if ($user->rights->societe->contact->creer) +if ($_POST["action"] == 'add' && $user->rights->societe->contact->creer) { - if ($_POST["action"] == 'add') - { $contact = new Contact($db); $contact->socid = $_POST["socid"]; @@ -124,67 +119,60 @@ if ($user->rights->societe->contact->creer) $_GET["action"] = 'create'; } } - } } -if ($user->rights->societe->contact->supprimer) +if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes' && $user->rights->societe->contact->supprimer) { - if ($_POST["action"] == 'confirm_delete' AND $_POST["confirm"] == 'yes') + $contact = new Contact($db); + $result=$contact->fetch($_GET["id"]); + + $contact->old_name = $_POST["old_name"]; + $contact->old_firstname = $_POST["old_firstname"]; + + $result = $contact->delete(); + + Header("Location: index.php"); + exit; +} + +if ($_POST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->societe->contact->creer) +{ + $contact = new Contact($db); + + $contact->old_name = $_POST["old_name"]; + $contact->old_firstname = $_POST["old_firstname"]; + + $contact->socid = $_POST["socid"]; + $contact->name = $_POST["name"]; + $contact->firstname = $_POST["firstname"]; + $contact->civilite_id = $_POST["civilite_id"]; + $contact->poste = $_POST["poste"]; + + $contact->address = $_POST["address"]; + $contact->cp = $_POST["cp"]; + $contact->ville = $_POST["ville"]; + $contact->fk_pays = $_POST["pays_id"]; + + $contact->email = $_POST["email"]; + $contact->phone_pro = $_POST["phone_pro"]; + $contact->phone_perso = $_POST["phone_perso"]; + $contact->phone_mobile = $_POST["phone_mobile"]; + $contact->fax = $_POST["fax"]; + $contact->jabberid = $_POST["jabberid"]; + $contact->priv = $_POST["priv"]; + + $contact->note = $_POST["note"]; + + $result = $contact->update($_POST["contactid"], $user); + + if ($result > 0) { - $contact = new Contact($db); - $result=$contact->fetch($_GET["id"]); - - $contact->old_name = $_POST["old_name"]; - $contact->old_firstname = $_POST["old_firstname"]; - - $result = $contact->delete(); - - Header("Location: index.php"); - exit; + $contact->old_name=''; + $contact->old_firstname=''; } -} - -if ($user->rights->societe->contact->creer) -{ - if ($_POST["action"] == 'update' && ! $_POST["cancel"]) + else { - $contact = new Contact($db); - - $contact->old_name = $_POST["old_name"]; - $contact->old_firstname = $_POST["old_firstname"]; - - $contact->socid = $_POST["socid"]; - $contact->name = $_POST["name"]; - $contact->firstname = $_POST["firstname"]; - $contact->civilite_id = $_POST["civilite_id"]; - $contact->poste = $_POST["poste"]; - - $contact->address = $_POST["address"]; - $contact->cp = $_POST["cp"]; - $contact->ville = $_POST["ville"]; - $contact->fk_pays = $_POST["pays_id"]; - - $contact->email = $_POST["email"]; - $contact->phone_pro = $_POST["phone_pro"]; - $contact->phone_perso = $_POST["phone_perso"]; - $contact->phone_mobile = $_POST["phone_mobile"]; - $contact->fax = $_POST["fax"]; - $contact->jabberid = $_POST["jabberid"]; - $contact->priv = $_POST["priv"]; - - $contact->note = $_POST["note"]; - - $result = $contact->update($_POST["contactid"], $user); - - if ($result > 0) - { - $contact->old_name=''; - $contact->old_firstname=''; - } - else - { - $error = $contact->error; - } + $error = $contact->error; } } @@ -484,8 +472,24 @@ if ($_GET["id"] && $_GET["action"] != 'edit') * Fiche en mode visualisation * */ - if ($msg) print '
'.$msg.'
'; + if ($msg) + { + $langs->load("errors"); + print '
'.$langs->trans($msg).'
'; + } + if ($_GET["action"] == 'create_user') + { + $login=strtolower(substr($contact->prenom, 0, 4)) . strtolower(substr($contact->nom, 0, 4)); + + // Crée un tableau formulaire + $formquestion=array( + array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login)); + + $form->form_confirm($_SERVER["PHP_SELF"]."?id=".$contact->id,$langs->trans("CreateDolibarrLogin"),$langs->trans("ConfirmCreateContact"),"confirm_create_user",$formquestion); + print '
'; + } + print ''; // Ref diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index 5e9e898e11b..4d1c77ab045 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -1491,6 +1491,7 @@ class Form { global $langs; + print "\n\n"; print ''; print ''; @@ -1574,6 +1575,8 @@ class Form } print "\n"; + + print "\n\n"; } diff --git a/htdocs/langs/en_US/users.lang b/htdocs/langs/en_US/users.lang index 8f534d97206..5d1916cfdc3 100755 --- a/htdocs/langs/en_US/users.lang +++ b/htdocs/langs/en_US/users.lang @@ -92,4 +92,6 @@ UserEnabled=User %s activated UserDeleted=User %s removed NewGroupCreated=Group %s created GroupModified=Group %s modified -GroupDeleted=Group %s removed \ No newline at end of file +GroupDeleted=Group %s removed +ConfirmCreateContact=Are you sure yu want to create a Dolibarr account for this contact ? +LoginToCreate=Login to create \ No newline at end of file diff --git a/htdocs/langs/fr_FR/users.lang b/htdocs/langs/fr_FR/users.lang index 332a1803bb6..1b396adf63b 100755 --- a/htdocs/langs/fr_FR/users.lang +++ b/htdocs/langs/fr_FR/users.lang @@ -93,3 +93,5 @@ UserDeleted=Suppression utilisateur %s NewGroupCreated=Création groupe %s GroupModified=Modification groupe %s GroupDeleted=Suppression groupe %s +ConfirmCreateContact=Etes vous sur de vouloir créer un compte Dolibarr pour ce contact ? +LoginToCreate=Login à créer \ No newline at end of file diff --git a/htdocs/user.class.php b/htdocs/user.class.php index 624b53f20cb..2fddf5348e0 100644 --- a/htdocs/user.class.php +++ b/htdocs/user.class.php @@ -781,26 +781,27 @@ class User extends CommonObject /** * \brief Cree en base un utilisateur depuis l'objet contact * \param contact Objet du contact source + * \param login Login to force * \return int si erreur <0, si ok renvoie id compte cree */ - function create_from_contact($contact) + function create_from_contact($contact,$login='') { global $user,$langs; // Positionne parametres + $this->admin = 0; $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->email = $contact->email; + + if (empty($login)) $login=strtolower(substr($contact->prenom, 0, 4)) . strtolower(substr($contact->nom, 0, 4)); + $this->login = $login; + $this->db->begin(); // Cree et positionne $this->id $result=$this->create($user); - if ($result > 0) { $sql = "UPDATE ".MAIN_DB_PREFIX."user";