From 901d5e235a1cba96deee3f4e1beecdf1963a206a Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@users.sourceforge.net>
Date: Wed, 5 Jan 2011 17:43:58 +0000
Subject: [PATCH] Fix: User creation must use same rule if from contact and
 from member.

---
 htdocs/adherents/fiche.php    |  6 ++++++
 htdocs/contact/fiche.php      | 11 +++++------
 htdocs/lib/functions2.lib.php | 17 +++++++++++++++--
 3 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/htdocs/adherents/fiche.php b/htdocs/adherents/fiche.php
index 312c4d8b9b0..f817615ce99 100644
--- a/htdocs/adherents/fiche.php
+++ b/htdocs/adherents/fiche.php
@@ -1020,6 +1020,12 @@ if ($rowid && $action != 'edit')
 	if ($_GET["action"] == 'create_user')
 	{
 		$login=$adh->login;
+		if (empty($login)) 
+		{
+			// Full firstname and name separated with a dot : firstname.name
+			include_once(DOL_DOCUMENT_ROOT.'/lib/functions2.lib.php');
+			$login=dol_buildlogin($adh->nom,$adh->prenom);
+		}
 		if (empty($login)) $login=strtolower(substr($adh->prenom, 0, 4)) . strtolower(substr($adh->nom, 0, 4));
 
 		// Create a form array
diff --git a/htdocs/contact/fiche.php b/htdocs/contact/fiche.php
index 08202b1a0c7..2919521e33a 100644
--- a/htdocs/contact/fiche.php
+++ b/htdocs/contact/fiche.php
@@ -23,7 +23,7 @@
 /**
  *       \file       htdocs/contact/fiche.php
  *       \ingroup    societe
- *       \brief      Onglet general d'un contact
+ *       \brief      Card of a contact
  *       \version    $Id$
  */
 
@@ -757,11 +757,10 @@ else
 
 		if ($_GET["action"] == 'create_user')
 		{
-			// Full firstname and name separated with a dot : firstname.name 
-			// TODO add function
-			$login=strtolower(dol_string_unaccent($object->prenom)) .'.'. strtolower(dol_string_unaccent($object->nom));
-			$login=dol_string_nospecial($login,''); // For special names
-
+			// Full firstname and name separated with a dot : firstname.name
+			include_once(DOL_DOCUMENT_ROOT.'/lib/functions2.lib.php');
+			$login=dol_buildlogin($object->nom,$object->prenom);
+			
 			// Create a form array
 			$formquestion=array(array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login));
 
diff --git a/htdocs/lib/functions2.lib.php b/htdocs/lib/functions2.lib.php
index 9b331a22b87..c821fbb7ecf 100644
--- a/htdocs/lib/functions2.lib.php
+++ b/htdocs/lib/functions2.lib.php
@@ -1099,8 +1099,8 @@ function getListOfModels($db,$type)
 }
 
 /**
- * \brief	This function evaluates a string that should be a valid IPv4
- * \return	It returns 0 if $ip is not a valid IPv4
+ * This function evaluates a string that should be a valid IPv4
+ * @return	It returns 0 if $ip is not a valid IPv4
  * 			It returns 1 if $ip is a valid IPv4 and is a public IP
  * 			It returns 2 if $ip is a valid IPv4 and is a private lan IP
  */
@@ -1115,3 +1115,16 @@ function is_ip($ip)
     return 1;
 }
 
+
+/**
+ *  Build a login from lastname, firstname
+ *  @param      lastname		Lastname
+ *  @param      firstname		Firstname
+ *	@return		string
+ */
+function dol_buildlogin($lastname,$firstname)
+{
+	$login=strtolower(dol_string_unaccent($firstname)) .'.'. strtolower(dol_string_unaccent($lastname));
+	$login=dol_string_nospecial($login,''); // For special names
+	return $login;
+}
\ No newline at end of file
-- 
GitLab