diff --git a/htdocs/companybankaccount.class.php b/htdocs/companybankaccount.class.php
index 7a587a30a59d49855001514daf725969d68962dc..a4280ed8476219deff4dbcad1ba6a078b3bef7b6 100644
--- a/htdocs/companybankaccount.class.php
+++ b/htdocs/companybankaccount.class.php
@@ -14,16 +14,21 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * $Id$
- * $Source$
  */
 
+/*
+ * 	\version	$Id$
+ */
+
+/**
+ * 	\brief	Class
+ *
+ */
 class CompanyBankAccount
 {
 	var $rowid;
 	var $socid;
-		
+
 	var $bank;
 	var $courant;
 	var $clos;
@@ -32,209 +37,194 @@ class CompanyBankAccount
 	var $number;
 	var $cle_rib;
 	var $bic;
-	var $iban_prefix;
+	var $iban;
+	var $iban_prefix;		// deprecated
 	var $proprio;
 	var $adresse_proprio;
-	
-	function CompanyBankAccount($DB, $socid)
+
+	/**
+	 * 	Constructor
+	 */
+	function CompanyBankAccount($DB)
 	{
-    global $config;
-    
-    $this->db = $DB;
-    $this->socid = $socid;
-
-    $this->clos = 0;
-    $this->solde = 0;
-    $this->error_number = 0;
-    return 1;
-  }
-
-
-  /*
-   * Creation du compte bancaire
-   *
-   */
-  function create()
-    {
-      $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_rib (fk_soc, datec) values ($this->socid, ".$this->db->idate(mktime()).")";
-      if ($this->db->query($sql))
+		$this->db = $DB;
+
+		$this->socid = 0;
+		$this->clos = 0;
+		$this->solde = 0;
+		$this->error_number = 0;
+		return 1;
+	}
+
+
+	/*
+	 * Creation du compte bancaire
+	 *
+	 */
+	function create()
 	{
-	  if ($this->db->affected_rows()) 
-	    {
-	      return 1;
-	    }
+		$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_rib (fk_soc, datec) values ($this->socid, ".$this->db->idate(mktime()).")";
+		if ($this->db->query($sql))
+		{
+			if ($this->db->affected_rows())
+			{
+				return 1;
+			}
+		}
+		else
+		{
+			print $this->db->error();
+			return 0;
+		}
 	}
-      else
+
+	/*
+	 *
+	 *
+	 */
+	function update($user='')
 	{
-	  print $this->db->error();
-	  return 0;
 
+		$sql = "SELECT fk_soc FROM ".MAIN_DB_PREFIX."societe_rib";
+		$sql .= " WHERE fk_soc = ".$this->socid;
+
+		$result = $this->db->query($sql);
+
+		if ($result)
+		{
+			if ($this->db->num_rows() == 0)
+			{
+				$this->create();
+			}
+		}
+		else
+		{
+			print $this->db->error();
+			return 0;
+		}
+
+		$sql = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET ";
+
+		$sql .= " bank = '" .addslashes($this->bank)."'";
+		$sql .= ",code_banque='".$this->code_banque."'";
+		$sql .= ",code_guichet='".$this->code_guichet."'";
+		$sql .= ",number='".$this->number."'";
+		$sql .= ",cle_rib='".$this->cle_rib."'";
+		$sql .= ",bic='".$this->bic."'";
+		$sql .= ",iban_prefix = '".$this->iban_prefix."'";
+		$sql .= ",domiciliation='".addslashes($this->domiciliation)."'";
+		$sql .= ",proprio = '".addslashes($this->proprio)."'";
+		$sql .= ",adresse_proprio = '".addslashes($this->adresse_proprio)."'";
+
+		$sql .= " WHERE fk_soc = ".$this->socid;
+
+		$result = $this->db->query($sql);
+
+		if ($result)
+		{
+			return 1;
+		}
+		else
+		{
+			dolibarr_print_error($this->db);
+			return 0;
+		}
 	}
-    }  
-  /*
-   *
-   *
-   */
-  function update($user='')
-  {      
-    
-    $sql = "SELECT fk_soc FROM ".MAIN_DB_PREFIX."societe_rib ";
-    $sql .= " WHERE fk_soc = ".$this->socid;
-
-    $result = $this->db->query($sql);
-
-    if ($result)
-      {
-	if ($this->db->num_rows() == 0)
-	  {
-	    $this->create();
-	  }
-      }
-    else
-      {
-	print $this->db->error();
-	return 0;	
-      }
-
-    if (strlen(trim($this->iban_prefix)) == 0)
-      {
-	// Indispensable de la positionner pour v�rifier le RIB
-	$this->iban_prefix = 'FR';
-      }
-
-
-    $sql = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET ";
-    
-    $sql .= " bank = '" .addslashes($this->bank)."'";    
-    $sql .= ",code_banque='".$this->code_banque."'";
-    $sql .= ",code_guichet='".$this->code_guichet."'";
-    $sql .= ",number='".$this->number."'";
-    $sql .= ",cle_rib='".$this->cle_rib."'";
-    $sql .= ",bic='".$this->bic."'";
-    $sql .= ",iban_prefix = '".$this->iban_prefix."'";
-    $sql .= ",domiciliation='".addslashes($this->domiciliation)."'";
-    $sql .= ",proprio = '".addslashes($this->proprio)."'";
-    $sql .= ",adresse_proprio = '".addslashes($this->adresse_proprio)."'";
-    
-    $sql .= " WHERE fk_soc = ".$this->socid;
-    
-    $result = $this->db->query($sql);
-    
-    if ($result) 
-      {
-	return 1;		      
-      }
-    else
-      {
-	dolibarr_print_error($this->db);
-	return 0;
-      }
-  }
-  
-  /*
-   *
-   *
-   */
-  function fetch()
-  {
-
-    $sql = "SELECT rowid, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix, domiciliation, proprio, adresse_proprio FROM ".MAIN_DB_PREFIX."societe_rib";
-    $sql .= " WHERE fk_soc  = ".$this->socid;
-
-    $result = $this->db->query($sql);
-
-    if ($result)
-      {
-	if ($this->db->num_rows())
-	  {
-	    $obj = $this->db->fetch_object($result);
-	    
-	    $this->bank            = $obj->bank;
-	    $this->courant         = $obj->courant;
-	    $this->clos            = $obj->clos;
-	    $this->code_banque     = $obj->code_banque;
-	    $this->code_guichet    = $obj->code_guichet;
-	    $this->number          = $obj->number;
-	    $this->cle_rib         = $obj->cle_rib;
-	    $this->bic             = $obj->bic;
-	    $this->iban_prefix     = $obj->iban_prefix;
-	    $this->domiciliation   = $obj->domiciliation;
-	    $this->proprio         = $obj->proprio;
-	    $this->adresse_proprio = $obj->adresse_proprio;
-	  }
-	$this->db->free();
-      }
-    else
-      {
-	dolibarr_print_error($this->db);
-      }
-  }
-
-  /*
-   *
-   *
-   */
-  function error()
-    {      
-      return $this->error;
-    }
-
-  /*
-   *
-   *
-   */
-  function verif()
-  {
-    require_once DOL_DOCUMENT_ROOT . '/lib/bank.lib.php';
-
-
-    if (strlen(trim($this->code_banque)) == 0)
-      {
-	$this->error_number = 32;
-	$this->error_message = "Le code banque n'est pas renseign�";
-      }
-
-    if (strlen(trim($this->code_guichet)) == 0)
-      {
-	$this->error_number = 33;
-	$this->error_message = "Le code guichet n'est pas renseign�";
-      }
-
-
-    if (strlen(trim($this->number)) == 0)
-      {
-	$this->error_number = 34;
-	$this->error_message = "Le num�ro de compte n'est pas renseign�";
-      }
-
-    if (strlen(trim($this->cle_rib)) == 0)
-      {
-	$this->error_number = 35;
-	$this->error_message = "La cl� n'est pas renseign�e";
-      }
-
-    if (strlen(trim($this->iban_prefix)) == 0)
-      {
-	$this->error_number = 36;
-	$this->error_message = "La cle IBAN n'est pas renseign�e";
-      }
-
-
-    if (! verif_rib($this->code_banque, $this->code_guichet, $this->number, $this->cle_rib, $this->iban_prefix))
-      {
-	$this->error_number = 12;
-	$this->error_message = "Le RIB n'est pas valide";
-      }
-    
-    if ($this->error_number == 0)
-      {
-	return 1;
-      }
-    else
-      {
-	return 0;
-      }
-  }
+
+	/*
+	 *
+	 *
+	 */
+	function fetch()
+	{
+
+		$sql = "SELECT rowid, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio, adresse_proprio FROM ".MAIN_DB_PREFIX."societe_rib";
+		$sql.= " WHERE fk_soc  = ".$this->socid;
+
+		$result = $this->db->query($sql);
+
+		if ($result)
+		{
+			if ($this->db->num_rows())
+			{
+				$obj = $this->db->fetch_object($result);
+
+				$this->bank            = $obj->bank;
+				$this->courant         = $obj->courant;
+				$this->clos            = $obj->clos;
+				$this->code_banque     = $obj->code_banque;
+				$this->code_guichet    = $obj->code_guichet;
+				$this->number          = $obj->number;
+				$this->cle_rib         = $obj->cle_rib;
+				$this->bic             = $obj->bic;
+				$this->iban		       = $obj->iban;
+				$this->iban_prefix     = $obj->iban;	// deprecated
+				$this->domiciliation   = $obj->domiciliation;
+				$this->proprio         = $obj->proprio;
+				$this->adresse_proprio = $obj->adresse_proprio;
+			}
+			$this->db->free();
+		}
+		else
+		{
+			dolibarr_print_error($this->db);
+		}
+	}
+
+	/*
+	 *
+	 *
+	 */
+	function error()
+	{
+		return $this->error;
+	}
+
+	
+	/**
+	 *
+	 *
+	 */
+	function verif()
+	{
+		require_once DOL_DOCUMENT_ROOT . '/lib/bank.lib.php';
+
+		// Call function to check BAN
+		if (! verif_rib($this))
+		{
+			$this->error_number = 12;
+			$this->error_message = 'RIBControlError';
+		}
+
+		if ($this->error_number == 0)
+		{
+			return 1;
+		}
+		else
+		{
+			return 0;
+		}
+	}
+	
+	/**
+	 * 	\brief		Return account country code
+	 *	\return		String		country code
+	 */
+	function getCountryCode()
+	{
+		if (! empty($this->iban))
+		{
+			// If IBAN defined, we can know country of account from it
+			if (eregi("^([a-zA-Z][a-zA-Z])",$this->iban,$reg)) return $reg[1];
+		}
+		
+		// We return country code
+		$company=new Societe($this->db);
+		$result=$company->fetch($this->socid);
+		if (! empty($company->pays_code)) return $company->pays_code;
+
+		return '';
+	}	
 }
 
 ?>
diff --git a/htdocs/compta/bank/account.class.php b/htdocs/compta/bank/account.class.php
index 59bf7074a0a93a2430e1f6ef819c103d4467eb1c..10f1bcc8ad63ad32fc7c5fba54f36f741961b355 100644
--- a/htdocs/compta/bank/account.class.php
+++ b/htdocs/compta/bank/account.class.php
@@ -48,17 +48,17 @@ class Account extends CommonObject
 	var $clos;
 	var $rappro;
 	var $url;
-	//! Code banque dans le RIB
+	//! BBAN field for French Code banque
 	var $code_banque;
-	//! Code guichet dans le RIB
+	//! BBAN field for French Code guichet
 	var $code_guichet;
-	//! Numero du compte dans le RIB
+	//! BBAN main account number
 	var $number;
-	//! Cle de controle du RIB
+	//! BBAN field for French Cle de controle
 	var $cle_rib;
-	//! Numero BIC/SWIFT du compte
+	//! BIC/SWIFT number
 	var $bic;
-	//! Prefix IBAN a utiliser pour creer la cle IBAN International Bank Account Number
+	//! IBAN number (International Bank Account Number)
 	var $iban_prefix;
 	var $proprio;
 	var $adresse_proprio;
@@ -277,9 +277,10 @@ class Account extends CommonObject
 		// Chargement librairie pour acces fonction controle RIB
 		require_once DOL_DOCUMENT_ROOT.'/lib/bank.lib.php';
 
-		if (! verif_rib($this->code_banque,$this->code_guichet,$this->number,$this->cle_rib,$this->iban_prefix)) {
-			$this->error="Le controle de la cle indique que les informations de votre compte bancaire sont incorrectes.";
-			return 0;
+		if (! verif_rib($this)) 
+		{
+			$this->error='RIBControlError';
+			return -1;
 		}
 
 		if (! $this->ref)
@@ -345,6 +346,7 @@ class Account extends CommonObject
 		if (! $this->ref)
 		{
 			$this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Ref"));
+			dolibarr_syslog("Account::update ".$this->error);
 			return -1;
 		}
 		if (! $this->label) $this->label = "???";
@@ -368,7 +370,7 @@ class Account extends CommonObject
 
 		$sql .= " WHERE rowid = ".$this->id;
 
-		dolibarr_syslog("Account::update sql=$sql");
+		dolibarr_syslog("Account::update sql=".$sql);
 		$result = $this->db->query($sql);
 		if ($result)
 		{
@@ -384,29 +386,24 @@ class Account extends CommonObject
 
 
 	/*
-	 *    	\brief      Mise a jour compte, partie RIB
+	 *    	\brief      Update BBAN (RIB) account fields
 	 *    	\param      user        Object utilisateur qui modifie
 	 *		\return		int			<0 si ko, >0 si ok
 	 */
-	function update_rib($user='')
+	function update_bban($user='')
 	{
 		global $langs;
 
 		// Chargement librairie pour acces fonction controle RIB
 		require_once(DOL_DOCUMENT_ROOT.'/lib/bank.lib.php');
 
-		dolibarr_syslog("Account::update $this->code_banque,$this->code_guichet,$this->number,$this->cle_rib,$this->iban_prefix");
-
-		// Verification parametres
-		if (! verif_rib($this->code_banque,$this->code_guichet,$this->number,$this->cle_rib,$this->iban_prefix)) {
-			$this->error="Le contr�le de la cl� indique que les informations de votre compte bancaire sont incorrectes.";
-			return 0;
-		}
+		dolibarr_syslog("Account::update_bban $this->code_banque,$this->code_guichet,$this->number,$this->cle_rib,$this->iban");
 
+		// Check parameters
 		if (! $this->ref)
 		{
 			$this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Ref"));
-			return -1;
+			return -2;
 		}
 
 		$sql = "UPDATE ".MAIN_DB_PREFIX."bank_account SET ";
@@ -416,13 +413,13 @@ class Account extends CommonObject
 		$sql .= ",number='".$this->number."'";
 		$sql .= ",cle_rib='".$this->cle_rib."'";
 		$sql .= ",bic='".$this->bic."'";
-		$sql .= ",iban_prefix = '".$this->iban_prefix."'";
+		$sql .= ",iban_prefix = '".$this->iban."'";
 		$sql .= ",domiciliation='".addslashes($this->domiciliation)."'";
 		$sql .= ",proprio = '".addslashes($this->proprio)."'";
 		$sql .= ",adresse_proprio = '".addslashes($this->adresse_proprio)."'";
 		$sql .= " WHERE rowid = ".$this->id;
 
-		dolibarr_syslog("Account::update_rib sql=$sql");
+		dolibarr_syslog("Account::update_bban sql=$sql");
 
 		$result = $this->db->query($sql);
 		if ($result)
@@ -446,7 +443,7 @@ class Account extends CommonObject
 	function fetch($id,$ref='')
 	{
 		$sql = "SELECT rowid, ref, label, bank, number, courant, clos, rappro, url,";
-		$sql.= " code_banque, code_guichet, cle_rib, bic, iban_prefix,";
+		$sql.= " code_banque, code_guichet, cle_rib, bic, iban_prefix as iban,";
 		$sql.= " domiciliation, proprio, adresse_proprio,";
 		$sql.= " account_number, currency_code,";
 		$sql.= " min_allowed, min_desired, comment";
@@ -478,7 +475,8 @@ class Account extends CommonObject
 				$this->number        = $obj->number;
 				$this->cle_rib       = $obj->cle_rib;
 				$this->bic           = $obj->bic;
-				$this->iban_prefix   = $obj->iban_prefix;
+				$this->iban          = $obj->iban;
+				$this->iban_prefix   = $obj->iban;	// deprecated
 				$this->domiciliation = $obj->domiciliation;
 				$this->proprio       = $obj->proprio;
 				$this->adresse_proprio = $obj->adresse_proprio;
@@ -747,12 +745,32 @@ class Account extends CommonObject
 		return $result;
 	}
 
+	/**
+	 * 	\brief		Return account country code
+	 *	\return		String		country code
+	 */
+	function getCountryCode()
+	{
+		global $mysoc;
+		
+		if (! empty($this->iban))
+		{
+			// If IBAN defined, we can know country of account from it
+			if (eregi("^([a-zA-Z][a-zA-Z])",$this->iban,$reg)) return $reg[1];
+		}
+		
+		// We return country code
+		if (! empty($mysoc->pays_code)) return $mysoc->pays_code;
+
+		return '';
+	}	
+	
 }
 
 
 /**
- \class      AccountLine
- \brief      Classe permettant la gestion des lignes de transactions bancaires
+ *	\class      AccountLine
+ *	\brief      Classe permettant la gestion des lignes de transactions bancaires
  */
 class AccountLine
 {
@@ -997,6 +1015,7 @@ class AccountLine
 		
 		return $result;
 	}
+	
 }
 
 ?>
diff --git a/htdocs/compta/bank/bankid_fr.php b/htdocs/compta/bank/bankid_fr.php
index faaee1564dae511cf664ed172b8d4fb620448934..e4dbf63f415aaaedb2fe1209952a0eb8aaecd343 100644
--- a/htdocs/compta/bank/bankid_fr.php
+++ b/htdocs/compta/bank/bankid_fr.php
@@ -48,14 +48,15 @@ if ($_POST["action"] == 'update' && ! $_POST["cancel"])
 	$account->number          = trim($_POST["number"]);
 	$account->cle_rib         = trim($_POST["cle_rib"]);
 	$account->bic             = trim($_POST["bic"]);
-	$account->iban_prefix     = trim($_POST["iban_prefix"]);
+	$account->iban            = trim($_POST["iban_prefix"]);	
+	$account->iban_prefix     = trim($_POST["iban_prefix"]);	// deprecated
 	$account->domiciliation   = trim($_POST["domiciliation"]);
 	$account->proprio 	      = trim($_POST["proprio"]);
 	$account->adresse_proprio = trim($_POST["adresse_proprio"]);
 
 	if ($account->id)
 	{
-		$result = $account->update_rib($user);
+		$result = $account->update_bban($user);
 		if ($result >= 0)
 		{
 			$_GET["id"]=$_POST["id"];   // Force chargement page en mode visu
@@ -122,6 +123,13 @@ if (($_GET["id"] || $_GET["ref"]) && $_GET["action"] != 'edit')
 		print '<br />';
 	}
 
+	// Check BBAN
+	if (! checkBanForAccount($account)) 
+	{
+		print '<div class="warning">'.$langs->trans("RIBControlError").'</div><br>';
+	}
+	
+	
 	print '<table class="border" width="100%">';
 
 	// Ref
@@ -144,22 +152,28 @@ if (($_GET["id"] || $_GET["ref"]) && $_GET["action"] != 'edit')
 		print '<tr><td valign="top">'.$langs->trans("BankName").'</td>';
 		print '<td colspan="3">'.$account->bank.'</td></tr>';
 
-		print '<tr><td>'.$langs->trans("BankCode").'</td>';
-		print '<td colspan="3">'.$account->code_banque.'</td>';
-		print '</tr>';
-
-		print '<tr><td>'.$langs->trans("DeskCode").'</td>';
-		print '<td colspan="3">'.$account->code_guichet.'</td>';
-		print '</tr>';
-			
+		if ($account->getCountryCode() == 'FR')
+		{
+			print '<tr><td>'.$langs->trans("BankCode").'</td>';
+			print '<td colspan="3">'.$account->code_banque.'</td>';
+			print '</tr>';
+	
+			print '<tr><td>'.$langs->trans("DeskCode").'</td>';
+			print '<td colspan="3">'.$account->code_guichet.'</td>';
+			print '</tr>';
+		}
+	
 		print '<tr><td>'.$langs->trans("BankAccountNumber").'</td>';
 		print '<td colspan="3">'.$account->number.'</td>';
 		print '</tr>';
 			
-		print '<tr><td>'.$langs->trans("BankAccountNumberKey").'</td>';
-		print '<td colspan="3">'.$account->cle_rib.'</td>';
-		print '</tr>';
-
+		if ($account->getCountryCode() == 'FR')
+		{
+			print '<tr><td>'.$langs->trans("BankAccountNumberKey").'</td>';
+			print '<td colspan="3">'.$account->cle_rib.'</td>';
+			print '</tr>';
+		}
+		
 		print '<tr><td valign="top">'.$langs->trans("IBAN").'</td>';
 		print '<td colspan="3">'.$account->iban_prefix.'</td></tr>';
 
@@ -245,22 +259,30 @@ if ($_GET["id"] && $_GET["action"] == 'edit' && $user->rights->banque->configure
 		print '<td colspan="3"><input size="30" type="text" class="flat" name="bank" value="'.$account->bank.'"></td>';
 		print '</tr>';
 
-		print '<tr><td>'.$langs->trans("BankCode").'</td>';
-		print '<td><input size="8" type="text" class="flat" name="code_banque" value="'.$account->code_banque.'"></td>';
-		print '</tr>';
-
-		print '<tr><td>'.$langs->trans("DeskCode").'</td>';
-		print '<td><input size="8" type="text" class="flat" name="code_guichet" value="'.$account->code_guichet.'"></td>';
-		print '</tr>';
-
+		// BBAN
+		if ($account->getCountryCode() == 'FR')
+		{
+			print '<tr><td>'.$langs->trans("BankCode").'</td>';
+			print '<td><input size="8" type="text" class="flat" name="code_banque" value="'.$account->code_banque.'"></td>';
+			print '</tr>';
+	
+			print '<tr><td>'.$langs->trans("DeskCode").'</td>';
+			print '<td><input size="8" type="text" class="flat" name="code_guichet" value="'.$account->code_guichet.'"></td>';
+			print '</tr>';
+		}
+		
 		print '<td>'.$langs->trans("BankAccountNumber").'</td>';
 		print '<td><input size="15" type="text" class="flat" name="number" value="'.$account->number.'"></td>';
 		print '</tr>';
 
-		print '<td>'.$langs->trans("BankAccountNumberKey").'</td>';
-		print '<td><input size="3" type="text" class="flat" name="cle_rib" value="'.$account->cle_rib.'"></td>';
-		print '</tr>';
+		if ($account->getCountryCode() == 'FR')
+		{
+			print '<td>'.$langs->trans("BankAccountNumberKey").'</td>';
+			print '<td><input size="3" type="text" class="flat" name="cle_rib" value="'.$account->cle_rib.'"></td>';
+			print '</tr>';
+		}
 
+		// IBAN
 		print '<tr><td valign="top">'.$langs->trans("IBAN").'</td>';
 		print '<td colspan="3"><input size="24" type="text" class="flat" name="iban_prefix" value="'.$account->iban_prefix.'"></td></tr>';
 
diff --git a/htdocs/compta/prelevement/bon-prelevement.class.php b/htdocs/compta/prelevement/bon-prelevement.class.php
index 3940a0035de255c91eee24bfd1cc974f024dbf72..949688d23e80bf1a9cdb728909775340038238fd 100644
--- a/htdocs/compta/prelevement/bon-prelevement.class.php
+++ b/htdocs/compta/prelevement/bon-prelevement.class.php
@@ -1152,22 +1152,6 @@ class BonPrelevement extends CommonObject
         {
             $result = -2;
         }
-        /*
-        $nbfactures = sizeof($this->factures);
-        for ($i = 0 ; $i < $nbfactures ; $i++)
-        {
-        $fac = new Facture($this->db);
-        $fac->fetch($this->factures[$i]);
-        $fac->fetch_client();
-        $fac->client->rib();
-        if ($fac->client->bank_account->verif()) {
-        $this->total = $this->total + $fac->total_ttc;
-        $this->EnregDestinataire($fac);
-        }else{
-        print $fac->client->bank_account->error_message;
-        print $fac->client->nom; }
-        }
-        */
 
         /*
         * Pied de page total
diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php
index 9319897cdd52d512a18dd97076ffdf8ed2ad65af..1e38fbbc92f757651a9a0256a4f1e46fc22d38e3 100644
--- a/htdocs/facture.class.php
+++ b/htdocs/facture.class.php
@@ -2422,7 +2422,8 @@ class Facture extends CommonObject
 
 		$soc = new Societe($this->db);
 		$soc->id = $this->socid;
-		$soc->rib();
+		$soc->load_ban();
+		
 		if ($this->statut > 0 && $this->paye == 0 && $this->mode_reglement_id == 3)
 		{
 			$sql = 'SELECT count(*) FROM '.MAIN_DB_PREFIX.'prelevement_facture_demande';
diff --git a/htdocs/langs/en_US/banks.lang b/htdocs/langs/en_US/banks.lang
index 155fbd1307fbd5c0117b1e185237eafef0744eb4..5c149def12383ea32fc017705b5aba38738bf5cf 100644
--- a/htdocs/langs/en_US/banks.lang
+++ b/htdocs/langs/en_US/banks.lang
@@ -27,7 +27,7 @@ CurrentBalance=Current balance
 FutureBalance=Future balance
 ShowAllTimeBalance=Show balance from start
 Reconciliation=Reconciliation
-RIB=RIB
+RIB=Bank Account Number
 IBAN=IBAN number
 BIC=BIC/SWIFT number
 StandingOrders=Standing orders
@@ -43,7 +43,7 @@ IOMonthlyReporting=Monthly reporting
 BankAccountDomiciliation=Account address
 BankAccountOwner=Account owner name
 BankAccountOwnerAddress=Account owner address
-RIBControlError=Control of key says informations for this account number are not complete or wrong.
+RIBControlError=Inetgrity checks of values fails. This means information for this account number are not complete or wrong (check country, numbers and IBAN).
 CreateAccount=Create account
 StandingOrderToProcess=To process
 StandingOrderProcessed=Processed
diff --git a/htdocs/langs/en_US/companies.lang b/htdocs/langs/en_US/companies.lang
index 4e4a823d465950827f76da0d3352c3a672b96010..123224c55d61cb6e0a66d71602d4719149c4cdf0 100644
--- a/htdocs/langs/en_US/companies.lang
+++ b/htdocs/langs/en_US/companies.lang
@@ -106,7 +106,7 @@ ProfId4PT=Prof Id 4 (Conservatory)
 ProfId1TN=Prof Id 1 (RC)
 ProfId2TN=Prof Id 2 (Fiscal matricule)
 ProfId3TN=Prof Id 3 (Douane code)
-ProfId4TN=Prof Id 4 (RIB)
+ProfId4TN=Prof Id 4 (BAN)
 VATIntra=VAT number
 VATIntraShort=VAT number
 VATIntraVeryShort=VAT
@@ -226,7 +226,7 @@ ProspectsByStatus=Prospects by status
 BillingContact=Billing contact
 NbOfAttachedFiles=Number of attached files
 AttachANewFile=Attach a new file
-NoRIB=No RIB defined
+NoRIB=No BAN defined
 NoParentCompany=None
 ExportImport=Import-Export
 ExportCardToFormat=Export card to format
diff --git a/htdocs/langs/en_US/withdrawals.lang b/htdocs/langs/en_US/withdrawals.lang
index 7b9a2afe7eaa23e75e7b1d0032d774cb7431efb8..0a84ba83bb29e47138a267d1f35f96d74664784b 100755
--- a/htdocs/langs/en_US/withdrawals.lang
+++ b/htdocs/langs/en_US/withdrawals.lang
@@ -29,5 +29,5 @@ LastWithdrawalReceipt=Last %s withdrawing receipts
 MakeWithdrawRequest=Make a withdraw request
 ThirdPartyBankCode=Third party bank code
 ThirdPartyDeskCode=Third party desk code
-NoInvoiceCouldBeWithdrawed=No invoice withdrawed with success. Check that invoice are on companies with a valid RIB.
+NoInvoiceCouldBeWithdrawed=No invoice withdrawed with success. Check that invoice are on companies with a valid BAN.
 ClassCredited=Classer cr�dit�
\ No newline at end of file
diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang
index c4552d5f523622652e9eb3d0552a4328bd557479..64456e2d96d2e9759458dbecaab181b97e44cdbe 100644
--- a/htdocs/langs/fr_FR/admin.lang
+++ b/htdocs/langs/fr_FR/admin.lang
@@ -663,7 +663,7 @@ ForceInvoiceDate=Forcer la date de facture 
 DisableRepeatable=D�sactiver les factures r�currentes
 SuggestedPaymentModesIfNotDefinedInInvoice=Modes de paiements sugg�r�s par d�faut si non d�fini au niveau de la facture
 EnableEditDeleteValidInvoice=Activer la possibilit� de r��diter/supprimer une facture valid�e sans paiement
-SuggestPaymentByRIBOnAccount=Proposer paiement par RIB sur le compte
+SuggestPaymentByRIBOnAccount=Proposer paiement par virement sur le compte
 SuggestPaymentByChequeToAddress=Proposer paiement par ch�que � l'ordre et adresse de
 FreeLegalTextOnInvoices=Mention compl�mentaire sur les factures
 WatermarkOnDraftInvoices=Filigrane sur les brouillons de factures (aucun si vide)
diff --git a/htdocs/langs/fr_FR/banks.lang b/htdocs/langs/fr_FR/banks.lang
index d0d01b9431e79d981ca1ea4c0b5658058c7ea385..9c58d485ce16ecd1e5ae4e3d3ef1d6d99d67851c 100644
--- a/htdocs/langs/fr_FR/banks.lang
+++ b/htdocs/langs/fr_FR/banks.lang
@@ -27,7 +27,7 @@ CurrentBalance=Solde actuel
 FutureBalance=Solde futur
 ShowAllTimeBalance=Afficher solde depuis d�but
 Reconciliation=Rapprochement
-RIB=RIB
+RIB=Num�ro compte
 IBAN=Identifiant IBAN
 BIC=Identifiant BIC/SWIFT
 StandingOrders=Pr�l�vements
@@ -43,7 +43,7 @@ IOMonthlyReporting=Rapport mensuel E/S
 BankAccountDomiciliation=Domiciliation du compte
 BankAccountOwner=Nom du propri�taire du compte
 BankAccountOwnerAddress=Adresse du propri�taire du compte
-RIBControlError=Le contr�le de la cl� indique que les informations de ce compte bancaire sont incompl�tes ou incorrectes.
+RIBControlError=Les contr�les indiquent que les informations de ce compte bancaire sont incompl�tes ou incorrectes (v�rifier le pays, les num�ros de compte ou IBAN).
 CreateAccount=Cr�er compte
 StandingOrderToProcess=� traiter
 StandingOrderProcessed=Trait�s
diff --git a/htdocs/langs/fr_FR/companies.lang b/htdocs/langs/fr_FR/companies.lang
index 69f73af0c0295c923565356a5e13a588b942513a..7f709bb3927e46cf834906cb9ab7ffbab46d2c27 100644
--- a/htdocs/langs/fr_FR/companies.lang
+++ b/htdocs/langs/fr_FR/companies.lang
@@ -106,7 +106,7 @@ ProfId4PT=Id prof. 4 (Conservatory)
 ProfId1TN=Id prof. 1 (RC)
 ProfId2TN=Id prof. 2 (Matricule fiscale)
 ProfId3TN=Id prof. 3 (Code en douane)
-ProfId4TN=Id prof. 4 (RIB)
+ProfId4TN=Id prof. 4 (BAN)
 VATIntra=Num�ro de TVA
 VATIntraShort=Num TVA
 VATIntraVeryShort=N� TVA
@@ -226,7 +226,7 @@ ProspectsByStatus=Prospects par 
 BillingContact=Contact facturation
 NbOfAttachedFiles=Nombre de fichiers joints
 AttachANewFile=Joindre un nouveau fichier
-NoRIB=Aucun RIB d�fini
+NoRIB=Aucun BAN (RIB) d�fini
 NoParentCompany=Aucune
 ExportImport=Import-Export
 ExportCardToFormat=Exporter fiche au format
diff --git a/htdocs/langs/fr_FR/withdrawals.lang b/htdocs/langs/fr_FR/withdrawals.lang
index a4b12aea10c844d94f0871677525d4c4530bd6a7..b045c21110582682bf32b8063ff47884e191b1c4 100755
--- a/htdocs/langs/fr_FR/withdrawals.lang
+++ b/htdocs/langs/fr_FR/withdrawals.lang
@@ -29,5 +29,5 @@ LastWithdrawalReceipt=Les %s derniers bons de pr
 MakeWithdrawRequest=Faire une demande de pr�l�vement
 ThirdPartyBankCode=Code banque du tiers
 ThirdPartyDeskCode=Code guichet du tiers
-NoInvoiceCouldBeWithdrawed=Aucune facture pr�levable, pr�lev� avec succ�s. V�rifiez que les factures sont sur des soci�t�s dont le RIB est correctement renseign�.
+NoInvoiceCouldBeWithdrawed=Aucune facture pr�levable, pr�lev� avec succ�s. V�rifiez que les factures sont sur des soci�t�s dont le BAN(RIB) est correctement renseign�.
 ClassCredited=Classer cr�dit�
\ No newline at end of file
diff --git a/htdocs/lib/bank.lib.php b/htdocs/lib/bank.lib.php
index b3de1af521d8a2f196c6f4996f7d9f246d788dbf..a284232090455e284b180d288485e3b7db030754 100644
--- a/htdocs/lib/bank.lib.php
+++ b/htdocs/lib/bank.lib.php
@@ -81,29 +81,32 @@ function bank_prepare_head($obj)
 
 
 /**
-		\brief    Verifie le RIB d'un compte bancaire grace � sa cl�
-		\param    code_banque     code banque
-		\param    code_guichet    code guichet
-		\param    num_compte      numero de compte
-		\param    cle             cle
-		\param    iban            Ne sert pas pour le calcul de cle mais sert pour determiner le pays
-		\return   int             true si les infos sont bonnes, false si la cl� ne correspond pas
-*/
-function verif_rib($code_banque , $code_guichet , $num_compte , $cle, $iban)
+ *		\brief    Check account number informations for a bank account
+ *		\param    code_banque     code banque
+ *		\param    code_guichet    code guichet
+ *		\param    num_compte      numero de compte
+ *		\param    cle             cle
+ *		\param    iban            Ne sert pas pour le calcul de cle mais sert pour determiner le pays
+ *		\return   int             true si les infos sont bonnes, false si erreur
+ */
+function checkBanForAccount($account)
 {
-	if (eregi("^FR",$iban))
+	$country_code=$account->getCountryCode();
+	
+	dolibarr_syslog("Bank.lib::checkBanForAccount account->iban=".$account->iban." country_code=".$country_code, LOG_DEBUG);
+	
+	
+	if ($country_code == 'FR')
 	{    // Cas de la France
 
 		$coef = array(62, 34, 3) ;
 
 		// Concatenation des differents codes.
-		$rib = strtolower(trim($code_banque).trim($code_guichet).trim($num_compte).trim($cle));
+		$rib = strtolower(trim($account->code_banque).trim($account->code_guichet).trim($account->num_compte).trim($account->cle));
 
 		// On remplace les eventuelles lettres par des chiffres.
 
-		//Ne marche pas
-		//$rib = strtr($rib, "abcdefghijklmnopqrstuvwxyz","12345678912345678912345678");
-
+		//$rib = strtr($rib, "abcdefghijklmnopqrstuvwxyz","12345678912345678912345678");	//Ne marche pas
 		$rib = strtr($rib, "abcdefghijklmnopqrstuvwxyz","12345678912345678923456789");
 
 		// Separation du rib en 3 groupes de 7 + 1 groupe de 2.
@@ -124,7 +127,19 @@ function verif_rib($code_banque , $code_guichet , $num_compte , $cle, $iban)
 
 		return false;
 	}
+	
+	if ($country_code == 'BE')	// Belgium rules
+	{
+	}
 
+	// No particular rule
+	// If account is CompanyBankAccount class, we use number
+	// If account is Account class, we use num_compte
+	if (empty($account->num_compte) && empty($account->number))
+	{
+		return false;
+	}
+	
 	return true;
 }
 
diff --git a/htdocs/soc.php b/htdocs/soc.php
index 5a53fd81d6c2fced251ee353352c24424487f37f..07896165cfefa2379975e1c43e217022384392b4 100644
--- a/htdocs/soc.php
+++ b/htdocs/soc.php
@@ -36,6 +36,7 @@ require_once(DOL_DOCUMENT_ROOT."/contact.class.php");
 $langs->load("companies");
 $langs->load("commercial");
 $langs->load("bills");
+$langs->load("banks");
 
 // Security check
 $socid = isset($_GET["socid"])?$_GET["socid"]:'';
@@ -1154,7 +1155,7 @@ else
 	$soc->typent= $arr[$soc->typent_code];
 	print '<tr><td>'.$langs->trans("Type").'</td><td>'.$soc->typent.'</td><td>'.$langs->trans("Staff").'</td><td>'.$soc->effectif.'</td></tr>';
 
-	// RIB
+	// Ban
 	print '<tr><td>';
 	print '<table width="100%" class="nobordernopadding"><tr><td>';
 	print $langs->trans('RIB');
@@ -1169,7 +1170,7 @@ else
 	print $soc->display_rib();
 	print '</td></tr>';
 
-	// Maison m�re
+	// Parent company
 	print '<tr><td>';
 	print '<table width="100%" class="nobordernopadding"><tr><td>';
 	print $langs->trans('ParentCompany');
@@ -1185,7 +1186,8 @@ else
 	{
 		$socm = new Societe($db);
 		$socm->fetch($soc->parent);
-		print '<a href="'.DOL_URL_ROOT.'/soc.php?socid='.$socm->id.'">'.img_object($langs->trans("ShowCompany"),'company').' '.$socm->nom.'</a>'.($socm->code_client?"(".$socm->code_client.")":"").' - '.$socm->ville;
+		print $socm->getNomUrl(1).' '.($socm->code_client?"(".$socm->code_client.")":"");
+		print $socm->ville?' - '.$socm->ville:'';
 	}
 	else {
 		print $langs->trans("NoParentCompany");
diff --git a/htdocs/societe.class.php b/htdocs/societe.class.php
index 6a6e8632f6f452da0d63422755a254c7773ef0b6..35d1e5042c5c15bd055ff58f48f1dac831395c4d 100644
--- a/htdocs/societe.class.php
+++ b/htdocs/societe.class.php
@@ -1361,12 +1361,14 @@ class Societe extends CommonObject
 
 		require_once DOL_DOCUMENT_ROOT . "/companybankaccount.class.php";
 
-		$bac = new CompanyBankAccount($this->db, $this->id);
-		$bac->fetch();
+		$bac = new CompanyBankAccount($this->db);
+		$bac->socid = $this->id;
+		$bac->fetch($this->id);
 
 		if ($bac->code_banque || $bac->code_guichet || $bac->number || $bac->cle_rib)
 		{
-			$rib = $bac->code_banque." ".$bac->code_guichet." ".$bac->number." (".$bac->cle_rib.")";
+			$rib = $bac->code_banque." ".$bac->code_guichet." ".$bac->number;
+			$rib.=($bac->cle_rib?" (".$bac->cle_rib.")":"");
 		}
 		else
 		{
@@ -1375,23 +1377,24 @@ class Societe extends CommonObject
 		return $rib;
 	}
 
-
-	function rib()
+	/**
+	 * Load this->bank_account attribut
+	 */
+	function load_ban()
 	{
 		require_once DOL_DOCUMENT_ROOT . "/companybankaccount.class.php";
 
 		$bac = new CompanyBankAccount($this->db, $this->id);
-		$bac->fetch();
+		$bac->fetch($this->id);
 
 		$this->bank_account = $bac;
-
 		return 1;
 	}
 
 
 	function verif_rib()
 	{
-		$this->rib();
+		$this->load_ban();
 		return $this->bank_account->verif();
 	}
 
diff --git a/htdocs/societe/lien.php b/htdocs/societe/lien.php
index 802f548a567c58c7a7af64226ef7c60c59130b08..d4ce271794323ded38b7044951a219c4d384ae0c 100644
--- a/htdocs/societe/lien.php
+++ b/htdocs/societe/lien.php
@@ -185,12 +185,10 @@ if($_GET["socid"])
             $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,";
             $sql.= " ".MAIN_DB_PREFIX."c_typent as te";
             $sql.= " WHERE s.fk_typent = te.id";
-    
             if (strlen(trim($_GET["search_nom"])))
             {
                 $sql .= " AND s.nom LIKE '%".$_GET["search_nom"]."%'";
             }
-    
             $sql .= " ORDER BY s.nom ASC " . $db->plimit($conf->liste_limit+1, $offset);
     
             $resql = $db->query($sql);
@@ -201,7 +199,7 @@ if($_GET["socid"])
     
                 $params = "&amp;socid=".$_GET["socid"];
     
-                print_barre_liste($title, $page, "lien.php",$params,$sortfield,$sortorder,'',$num);
+                print_barre_liste($title, $page, "lien.php",$params,$sortfield,$sortorder,'',$num,0,'');
     
                 // Lignes des titres
                 print '<table class="noborder" width="100%">';
diff --git a/htdocs/societe/rib.php b/htdocs/societe/rib.php
index b0f9aec24fd3d13eade5eae416f827a776b46655..cb8f180048ef8d4c5cb8f42f5dbf8efe7735e236 100644
--- a/htdocs/societe/rib.php
+++ b/htdocs/societe/rib.php
@@ -19,18 +19,20 @@
  */
 
 /**
-	    \file       htdocs/societe/rib.php
-        \ingroup    societe
-		\brief      Onglet rib de societe
-		\version    $Id$
-*/
- 
+ *	    \file       htdocs/societe/rib.php
+ *      \ingroup    societe
+ *		\brief      BAN tab for companies
+ *		\version    $Id$
+ */
+
 require("./pre.inc.php");
 require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php");
+require_once(DOL_DOCUMENT_ROOT."/lib/bank.lib.php");
 require_once DOL_DOCUMENT_ROOT."/companybankaccount.class.php";
 
 $langs->load("companies");
 $langs->load("banks");
+$langs->load("bills");
 
 // Security check
 $socid = isset($_GET["socid"])?$_GET["socid"]:'';
@@ -43,52 +45,57 @@ $soc->fetch($_GET["socid"]);
 
 
 /*
-*	Actions
-*/
+ *	Actions
+ */
 
 if ($_POST["action"] == 'update' && ! $_POST["cancel"])
 {
-  // Modification
-  $account = new CompanyBankAccount($db, $soc->id);
-
-  $account->bank            = $_POST["bank"];
-  $account->label           = $_POST["label"];
-  $account->courant         = $_POST["courant"];
-  $account->clos            = $_POST["clos"];
-  $account->code_banque     = $_POST["code_banque"];
-  $account->code_guichet    = $_POST["code_guichet"];
-  $account->number          = $_POST["number"];
-  $account->cle_rib         = $_POST["cle_rib"];
-  $account->bic             = $_POST["bic"];
-  $account->iban_prefix     = $_POST["iban_prefix"];
-  $account->domiciliation   = $_POST["domiciliation"];
-  $account->proprio 	    = $_POST["proprio"];
-  $account->adresse_proprio = $_POST["adresse_proprio"];
-
-  $result = $account->update($user);
-  if (! $result)
-    {
-      $message=$account->error(); 
-      $_GET["action"]='edit';     // Force chargement page edition
-    }
-  else
-    {
-      $_GET["id"]=$_POST["id"];   // Force chargement page en mode visu
-    }  
+	// Modification
+	$account = new CompanyBankAccount($db);
+
+	$account->socid           = $soc->id;
+
+	$account->bank            = $_POST["bank"];
+	$account->label           = $_POST["label"];
+	$account->courant         = $_POST["courant"];
+	$account->clos            = $_POST["clos"];
+	$account->code_banque     = $_POST["code_banque"];
+	$account->code_guichet    = $_POST["code_guichet"];
+	$account->number          = $_POST["number"];
+	$account->cle_rib         = $_POST["cle_rib"];
+	$account->bic             = $_POST["bic"];
+	$account->iban_prefix     = $_POST["iban_prefix"];
+	$account->domiciliation   = $_POST["domiciliation"];
+	$account->proprio 	    = $_POST["proprio"];
+	$account->adresse_proprio = $_POST["adresse_proprio"];
+
+	$result = $account->update($user);
+	if (! $result)
+	{
+		$message=$account->error();
+		$_GET["action"]='edit';     // Force chargement page edition
+	}
+	else
+	{
+		$_GET["id"]=$_POST["id"];   // Force chargement page en mode visu
+	}
 }
 
 
+
 /*
-*	View
-*/
+ *	View
+ */
+
 llxHeader();
 
 $head=societe_prepare_head2($soc);
-    
+
 dolibarr_fiche_head($head, 'rib', $langs->trans("ThirdParty"));
 
-$account = new CompanyBankAccount($db, $soc->id);
-$account->fetch();
+$account = new CompanyBankAccount($db);
+$account->socid=$soc->id;
+$account->fetch($soc->id);
 
 
 /* ************************************************************************** */
@@ -99,64 +106,75 @@ $account->fetch();
 
 if ($_GET["socid"] && $_GET["action"] != 'edit')
 {
-    if (!$account->verif())
-    {
-        print '<div class="error">'.$langs->trans("RIBControlError").'</div><br>';
-    }
+	// Check BBAN
+	if (! checkBanForAccount($account)) 
+	{
+		print '<div class="warning">'.$langs->trans("RIBControlError").'</div><br>';
+	}
+
+	print '<table class="border" width="100%">';
+
+	print '<tr><td valign="top">'.$langs->trans("Bank").'</td>';
+	print '<td colspan="4">'.$account->bank.'</td></tr>';
 
-    print '<table class="border" width="100%">';
+	if ($account->getCountryCode() == 'FR')
+	{
+		print '<tr><td>'.$langs->trans("BankCode").'</td>';
+		print '<td colspan="3">'.$account->code_banque.'</td>';
+		print '</tr>';
 
-    print '<tr><td valign="top">'.$langs->trans("Bank").'</td>';
-    print '<td colspan="4">'.$account->bank.'</td></tr>';
+		print '<tr><td>'.$langs->trans("DeskCode").'</td>';
+		print '<td colspan="3">'.$account->code_guichet.'</td>';
+		print '</tr>';
+	}
 
-    print '<tr><td>'.$langs->trans("RIB").'</td>';
-    print '<td align="center">'.$langs->trans("BankCode").'</td>';
-    print '<td align="center">'.$langs->trans("DeskCode").'</td>';
-    print '<td align="center">'.$langs->trans("BankAccountNumber").'</td>';
-    print '<td align="center">'.$langs->trans("BankAccountNumberKey").'</td>';
-    print '</tr>';
-    
-    print '<tr><td>&nbsp;</td><td align="center">'.$account->code_banque.'</td>';
-    print '<td align="center">'.$account->code_guichet.'</td>';
-    print '<td align="center">'.$account->number.'</td>';
-    print '<td align="center">'.$account->cle_rib.'</td></tr>';
+	print '<tr><td>'.$langs->trans("BankAccountNumber").'</td>';
+	print '<td colspan="3">'.$account->number.'</td>';
+	print '</tr>';
+		
+	if ($account->getCountryCode() == 'FR')
+	{
+		print '<tr><td>'.$langs->trans("BankAccountNumberKey").'</td>';
+		print '<td colspan="3">'.$account->cle_rib.'</td>';
+		print '</tr>';
+	}
 
-    print '<tr><td valign="top">'.$langs->trans("IBAN").'</td>';
-    print '<td colspan="4">'.$account->iban_prefix.'</td></tr>';
+	print '<tr><td valign="top">'.$langs->trans("IBAN").'</td>';
+	print '<td colspan="4">'.$account->iban_prefix.'</td></tr>';
 
-    print '<tr><td valign="top">'.$langs->trans("BIC").'</td>';
-    print '<td colspan="4">'.$account->bic.'</td></tr>';
+	print '<tr><td valign="top">'.$langs->trans("BIC").'</td>';
+	print '<td colspan="4">'.$account->bic.'</td></tr>';
 
-    print '<tr><td valign="top">'.$langs->trans("BankAccountDomiciliation").'</td><td colspan="4">';
-    print $account->domiciliation;
-    print "</td></tr>\n";
+	print '<tr><td valign="top">'.$langs->trans("BankAccountDomiciliation").'</td><td colspan="4">';
+	print $account->domiciliation;
+	print "</td></tr>\n";
 
-    print '<tr><td valign="top">'.$langs->trans("BankAccountOwner").'</td><td colspan="4">';
-    print $account->proprio;
-    print "</td></tr>\n";
+	print '<tr><td valign="top">'.$langs->trans("BankAccountOwner").'</td><td colspan="4">';
+	print $account->proprio;
+	print "</td></tr>\n";
 
-    print '<tr><td valign="top">'.$langs->trans("BankAccountOwnerAddress").'</td><td colspan="4">';
-    print $account->adresse_proprio;
-    print "</td></tr>\n";
+	print '<tr><td valign="top">'.$langs->trans("BankAccountOwnerAddress").'</td><td colspan="4">';
+	print $account->adresse_proprio;
+	print "</td></tr>\n";
 
-    print '</table>';
+	print '</table>';
 
-    print '</div>';
+	print '</div>';
 
 
 
-    /*
-    * Barre d'actions
-    *
-    */
-    print '<div class="tabsAction">';
+	/*
+	 * Barre d'actions
+	 *
+	 */
+	print '<div class="tabsAction">';
 
-    if ($user->rights->societe->creer)
-    {
-        print '<a class="butAction" href="rib.php?socid='.$soc->id.'&amp;action=edit">'.$langs->trans("Modify").'</a>';
-    }
+	if ($user->rights->societe->creer)
+	{
+		print '<a class="butAction" href="rib.php?socid='.$soc->id.'&amp;action=edit">'.$langs->trans("Modify").'</a>';
+	}
 
-    print '</div>';
+	print '</div>';
 
 }
 
@@ -169,54 +187,69 @@ if ($_GET["socid"] && $_GET["action"] != 'edit')
 if ($_GET["socid"] && $_GET["action"] == 'edit' && $user->rights->societe->creer)
 {
 
-    $form = new Form($db);
-
-    if ($message) { print "$message<br><br>\n"; }
-
-    print '<form action="rib.php?socid='.$soc->id.'" method="post">';
-    print '<input type="hidden" name="action" value="update">';
-    print '<input type="hidden" name="id" value="'.$_GET["id"].'">';
-
-    print '<table class="border" width="100%">';
-
-    print '<tr><td valign="top">'.$langs->trans("Bank").'</td>';
-    print '<td colspan="4"><input size="30" type="text" name="bank" value="'.$account->bank.'"></td></tr>';
-
-    print '<tr><td>'.$langs->trans("RIB").'</td><td>'.$langs->trans("BankCode").'</td>';
-    print '<td>'.$langs->trans("DeskCode").'</td>';
-    print '<td>'.$langs->trans("BankAccountNumber").'</td>';
-    print '<td>'.$langs->trans("BankAccountNumberKey").'</td></tr>';
-    print '<tr><td>&nbsp;</td><td><input size="8" type="text" name="code_banque" value="'.$account->code_banque.'"></td>';
-    print '<td><input size="8" type="text" name="code_guichet" value="'.$account->code_guichet.'"></td>';
-    print '<td><input size="15" type="text" name="number" value="'.$account->number.'"></td>';
-    print '<td><input size="3" type="text" name="cle_rib" value="'.$account->cle_rib.'"></td></tr>';
-
-    print '<tr><td valign="top">'.$langs->trans("IBAN").'</td>';
-    print '<td colspan="4"><input size="30" type="text" name="iban_prefix" value="'.$account->iban_prefix.'"></td></tr>';
-
-    print '<tr><td valign="top">'.$langs->trans("BIC").'</td>';
-    print '<td colspan="4"><input size="12" type="text" name="bic" value="'.$account->bic.'"></td></tr>';
-
-    print '<tr><td valign="top">'.$langs->trans("BankAccountDomiciliation").'</td><td colspan="4">';
-    print "<textarea name=\"domiciliation\" rows=\"4\" cols=\"40\">";
-    print $account->domiciliation;
-    print "</textarea></td></tr>";
-
-    print '<tr><td valign="top">'.$langs->trans("BankAccountOwner").'</td>';
-    print '<td colspan="4"><input size="30" type="text" name="proprio" value="'.$account->proprio.'"></td></tr>';
-    print "</td></tr>\n";
-
-    print '<tr><td valign="top">'.$langs->trans("BankAccountOwnerAddress").'</td><td colspan="4">';
-    print "<textarea name=\"adresse_proprio\" rows=\"4\" cols=\"40\">";
-    print $account->adresse_proprio;
-    print "</textarea></td></tr>";
-
-    print '<tr><td align="center" colspan="5"><input class="button" value="'.$langs->trans("Modify").'" type="submit">';
-    print ' &nbsp; <input name="cancel" class="button" value="'.$langs->trans("Cancel").'" type="submit">';
-    print '</td></tr>';
-
-    print '</form>';
-    print '</table>';
+	$form = new Form($db);
+
+	if ($message) { print "$message<br><br>\n"; }
+
+	print '<form action="rib.php?socid='.$soc->id.'" method="post">';
+	print '<input type="hidden" name="action" value="update">';
+	print '<input type="hidden" name="id" value="'.$_GET["id"].'">';
+
+	print '<table class="border" width="100%">';
+
+	print '<tr><td valign="top">'.$langs->trans("Bank").'</td>';
+	print '<td colspan="4"><input size="30" type="text" name="bank" value="'.$account->bank.'"></td></tr>';
+
+	// BBAN
+	if ($account->getCountryCode() == 'FR')
+	{
+		print '<tr><td>'.$langs->trans("BankCode").'</td>';
+		print '<td><input size="8" type="text" class="flat" name="code_banque" value="'.$account->code_banque.'"></td>';
+		print '</tr>';
+
+		print '<tr><td>'.$langs->trans("DeskCode").'</td>';
+		print '<td><input size="8" type="text" class="flat" name="code_guichet" value="'.$account->code_guichet.'"></td>';
+		print '</tr>';
+	}
+	
+	print '<td>'.$langs->trans("BankAccountNumber").'</td>';
+	print '<td><input size="15" type="text" class="flat" name="number" value="'.$account->number.'"></td>';
+	print '</tr>';
+
+	if ($account->getCountryCode() == 'FR')
+	{
+		print '<td>'.$langs->trans("BankAccountNumberKey").'</td>';
+		print '<td><input size="3" type="text" class="flat" name="cle_rib" value="'.$account->cle_rib.'"></td>';
+		print '</tr>';
+	}	
+
+	// IBAN
+	print '<tr><td valign="top">'.$langs->trans("IBAN").'</td>';
+	print '<td colspan="4"><input size="30" type="text" name="iban_prefix" value="'.$account->iban_prefix.'"></td></tr>';
+
+	print '<tr><td valign="top">'.$langs->trans("BIC").'</td>';
+	print '<td colspan="4"><input size="12" type="text" name="bic" value="'.$account->bic.'"></td></tr>';
+
+	print '<tr><td valign="top">'.$langs->trans("BankAccountDomiciliation").'</td><td colspan="4">';
+	print "<textarea name=\"domiciliation\" rows=\"4\" cols=\"40\">";
+	print $account->domiciliation;
+	print "</textarea></td></tr>";
+
+	print '<tr><td valign="top">'.$langs->trans("BankAccountOwner").'</td>';
+	print '<td colspan="4"><input size="30" type="text" name="proprio" value="'.$account->proprio.'"></td></tr>';
+	print "</td></tr>\n";
+
+	print '<tr><td valign="top">'.$langs->trans("BankAccountOwnerAddress").'</td><td colspan="4">';
+	print "<textarea name=\"adresse_proprio\" rows=\"4\" cols=\"40\">";
+	print $account->adresse_proprio;
+	print "</textarea></td></tr>";
+
+	print '<tr><td align="center" colspan="5"><input class="button" value="'.$langs->trans("Modify").'" type="submit">';
+	print ' &nbsp; <input name="cancel" class="button" value="'.$langs->trans("Cancel").'" type="submit">';
+	print '</td></tr>';
+
+	print '</form>';
+	print '</table>';
 }
 
 
diff --git a/htdocs/telephonie/client/new.php b/htdocs/telephonie/client/new.php
index 02c5989cf705ff942380fdc9636fe9a93e488434..ccba9dfb8d4d4cf7b368bd00a37851af315d1e3a 100644
--- a/htdocs/telephonie/client/new.php
+++ b/htdocs/telephonie/client/new.php
@@ -24,11 +24,11 @@
  */
 
 /**
-   \file       htdocs/telephonie/client/new.php
-   \ingroup    telephonie
-   \brief      Creation d'un nouveau client
-   \version    $Revision$
-*/
+ \file       htdocs/telephonie/client/new.php
+ \ingroup    telephonie
+ \brief      Creation d'un nouveau client
+ \version    $Revision$
+ */
 
 require("pre.inc.php");
 
@@ -44,7 +44,8 @@ $langs->load("companies");
 
 $soc = new Societe($db);
 $contact = new Contact($db);
-$rib = new CompanyBankAccount($db, 0);
+$rib = new CompanyBankAccount($db);
+
 
 /*
  * Actions
@@ -52,558 +53,558 @@ $rib = new CompanyBankAccount($db, 0);
 
 if ($_POST["action"] == 'add')
 {
-  $error = 0;
-  $verif = "ok";
-  $mesg = '';
+	$error = 0;
+	$verif = "ok";
+	$mesg = '';
 
 
-  $contact->name         = $_POST["cnom"];
-  $contact->firstname    = $_POST["cprenom"];
-  $contact->email        = strtolower($_POST["cmail"]);
+	$contact->name         = $_POST["cnom"];
+	$contact->firstname    = $_POST["cprenom"];
+	$contact->email        = strtolower($_POST["cmail"]);
+
+	if (strlen(trim($_POST["nom"])) == 0)
+	{
+		$mesg = "Nom de soci�t� incorrect";
+		$verif = "nok";
+	}
 
-  if (strlen(trim($_POST["nom"])) == 0)
-    {
-      $mesg = "Nom de soci�t� incorrect";
-      $verif = "nok";
-    }
+	if (strlen(trim($_POST["code_client"])) <> 6 && $verif == 'ok')
+	{
+		$mesg = "Code client incorrect";
+		$verif = "nok";
+	}
 
-  if (strlen(trim($_POST["code_client"])) <> 6 && $verif == 'ok')
-    {
-      $mesg = "Code client incorrect";
-      $verif = "nok";
-    }
+	if (strlen(trim($_POST["adresse"])) == 0 && $verif == 'ok')
+	{
+		$mesg = "Adresse de soci�t� manquante";
+		$verif = "nok";
+	}
 
-  if (strlen(trim($_POST["adresse"])) == 0 && $verif == 'ok')
-    {
-      $mesg = "Adresse de soci�t� manquante";
-      $verif = "nok";
-    }
+	if (strlen(trim($_POST["cp"])) == 0 && $verif == 'ok')
+	{
+		$mesg = "Code postal manquant";
+		$verif = "nok";
+	}
 
-  if (strlen(trim($_POST["cp"])) == 0 && $verif == 'ok')
-    {
-      $mesg = "Code postal manquant";
-      $verif = "nok";
-    }
+	if (strlen(trim($_POST["ville"])) == 0 && $verif == 'ok')
+	{
+		$mesg = "Ville manquante";
+		$verif = "nok";
+	}
 
-  if (strlen(trim($_POST["ville"])) == 0 && $verif == 'ok')
-    {
-      $mesg = "Ville manquante";
-      $verif = "nok";
-    }
+	$rib->code_banque  = $_POST["rib_banque"];
+	$rib->code_guichet = $_POST["rib_guichet"];
+	$rib->number       = $_POST["rib_compte"];
+	$rib->cle_rib      = $_POST["rib_cle"];
+	$rib->iban_prefix  = $_POST["rib_iban"];
+	$rib->iban         = $_POST["rib_iban"];
+	$rib->proprio      = $_POST["titulaire"];
 
-  $rib->code_banque  = $_POST["rib_banque"];
-  $rib->code_guichet = $_POST["rib_guichet"];
-  $rib->number       = $_POST["rib_compte"];
-  $rib->cle_rib      = $_POST["rib_cle"];
-  $rib->iban_prefix  = $_POST["rib_iban"];
-  $rib->proprio      = $_POST["titulaire"];
 
-  
-  if ((strlen(trim($_POST["rib_banque"])) + strlen(trim($_POST["rib_guichet"])) + strlen(trim($_POST["rib_compte"])) + strlen(trim($_POST["rib_cle"])))<> 0 && $verif == 'ok')
-    {
-      if (strlen(trim($_POST["rib_banque"])) <> 5 && $verif == 'ok')
+	if ((strlen(trim($_POST["rib_banque"])) + strlen(trim($_POST["rib_guichet"])) + strlen(trim($_POST["rib_compte"])) + strlen(trim($_POST["rib_cle"])))<> 0 && $verif == 'ok')
 	{
-	  $mesg = "Rib code banque incomplet";
-	  $verif = "nok";
+		if (strlen(trim($_POST["rib_banque"])) <> 5 && $verif == 'ok')
+		{
+			$mesg = "Rib code banque incomplet";
+			$verif = "nok";
+		}
+
+		if (strlen(trim($_POST["rib_guichet"])) <> 5 && $verif == 'ok')
+		{
+			$mesg = "Rib code agence incomplet";
+			$verif = "nok";
+		}
+
+		if (strlen(trim($_POST["titulaire"])) == 0 && $verif == 'ok')
+		{
+			$mesg = "Vous devez indiquer le titulaire du compte";
+			$verif = "nok";
+		}
+
+		if ($rib->verif() <> 1 && $verif == 'ok')
+		{
+			$mesg = "Rib incorrect ".$rib->error_message;
+			$verif = "nok";
+		}
 	}
 
-      if (strlen(trim($_POST["rib_guichet"])) <> 5 && $verif == 'ok')
+	if (strlen(trim($_POST["cmail"])) > 0 && $verif == 'ok')
 	{
-	  $mesg = "Rib code agence incomplet";
-	  $verif = "nok";
+
+		if (strlen(trim($_POST["cnom"])) == 0 && $verif == 'ok')
+		{
+			$mesg = "Nom de contact manquant";
+			$verif = "nok";
+		}
+
+		if (!ValidEmail(trim($contact->email))  && $verif == 'ok')
+		{
+			$mesg = "Email invalide";
+			$verif = "nok";
+		}
+
+		if (!check_mail(trim($contact->email))  && $verif == 'ok')
+		{
+			$mesg = "Email invalide (domaine invalide)";
+			$verif = "nok";
+		}
 	}
 
-      if (strlen(trim($_POST["titulaire"])) == 0 && $verif == 'ok')
+
+	if (strlen(trim($_POST["cli"])) <> 9 && $verif == 'ok')
 	{
-	  $mesg = "Vous devez indiquer le titulaire du compte";
-	  $verif = "nok";
+		$mesg = "Num�ro de ligne #1 (0".$_POST["cli"].") incorrect";
+		$verif = "nok";
 	}
 
-      if ($rib->verif() <> 1 && $verif == 'ok')
+	if (strlen(trim($_POST["cliend"])) > 0 && strlen(trim($_POST["cliend"])) <> 9 && $verif == 'ok')
 	{
-	  $mesg = "Rib incorrect ".$rib->error_message;
-	  $verif = "nok";
+		$mesg = "Num�ro de ligne dernier SDA (0".$_POST["cliend"].") incorrect";
+		$verif = "nok";
 	}
-    }
 
-  if (strlen(trim($_POST["cmail"])) > 0 && $verif == 'ok')
-    {
+	$p = array("1","2","3","4","5");
 
-      if (strlen(trim($_POST["cnom"])) == 0 && $verif == 'ok')
+	if (!in_array(substr(trim($_POST["cli"]),0,1), $p) && $verif == 'ok')
 	{
-	  $mesg = "Nom de contact manquant";
-	  $verif = "nok";
+		$mesg = "Num�ro de ligne #1 (0".$_POST["cli"].") incorrect";
+		$verif = "nok";
 	}
 
-      if (!ValidEmail(trim($contact->email))  && $verif == 'ok')
+	$ligne = new LigneTel($db);
+	$ligne->fetch("0".trim($_POST["cli"]));
+	if ($ligne->id > 0 && $verif == 'ok')
 	{
-	  $mesg = "Email invalide";
-	  $verif = "nok";
+		$mesg = "La ligne #1 : 0".$_POST["cli"]." existe d�j� !";
+		$verif = "nok";
 	}
 
-      if (!check_mail(trim($contact->email))  && $verif == 'ok')
-	{
-	  $mesg = "Email invalide (domaine invalide)";
-	  $verif = "nok";
-	}
-    }
 
+	/* Ligne #2 */
 
-  if (strlen(trim($_POST["cli"])) <> 9 && $verif == 'ok')
-    {
-      $mesg = "Num�ro de ligne #1 (0".$_POST["cli"].") incorrect";
-      $verif = "nok";
-    }
-  
-  if (strlen(trim($_POST["cliend"])) > 0 && strlen(trim($_POST["cliend"])) <> 9 && $verif == 'ok')
-    {
-      $mesg = "Num�ro de ligne dernier SDA (0".$_POST["cliend"].") incorrect";
-      $verif = "nok";
-    }
+	if (strlen(trim($_POST["cli2"])) > 0 && $verif == 'ok')
+	{
+		if (strlen(trim($_POST["cli2"])) <> 9 && $verif == 'ok')
+		{
+			$mesg = "Num�ro de ligne #2 (0".$_POST["cli2"].") incorrect";
+			$verif = "nok";
+		}
 
-  $p = array("1","2","3","4","5");
+		if (!in_array(substr(trim($_POST["cli2"]),0,1), $p) && $verif == 'ok')
+		{
+			$mesg = "Num�ro de ligne #2 (0".$_POST["cli2"].") incorrect";
+			$verif = "nok";
+		}
 
-  if (!in_array(substr(trim($_POST["cli"]),0,1), $p) && $verif == 'ok')
-    {
-      $mesg = "Num�ro de ligne #1 (0".$_POST["cli"].") incorrect";
-      $verif = "nok";
-    }
+		$ligne = new LigneTel($db);
+		$ligne->fetch("0".trim($_POST["cli2"]));
+		if ($ligne->id > 0 && $verif == 'ok')
+		{
+			$mesg = "La ligne #2 : 0".$_POST["cli2"]." existe d�j� !";
+			$verif = "nok";
+		}
+	}
+	/* Ligne #3 */
 
-  $ligne = new LigneTel($db);
-  $ligne->fetch("0".trim($_POST["cli"]));
-  if ($ligne->id > 0 && $verif == 'ok')
-    {
-      $mesg = "La ligne #1 : 0".$_POST["cli"]." existe d�j� !";
-      $verif = "nok";
-    }
+	if (strlen(trim($_POST["cli3"])) > 0 && $verif == 'ok')
+	{
+		if (strlen(trim($_POST["cli3"])) <> 9 && $verif == 'ok')
+		{
+			$mesg = "Num�ro de ligne #3 (0".$_POST["cli3"].") incorrect";
+			$verif = "nok";
+		}
 
+		if (!in_array(substr(trim($_POST["cli3"]),0,1), $p) && $verif == 'ok')
+		{
+			$mesg = "Num�ro de ligne #3 (0".$_POST["cli3"].") incorrect";
+			$verif = "nok";
+		}
 
-  /* Ligne #2 */
+		$ligne = new LigneTel($db);
+		$ligne->fetch("0".trim($_POST["cli3"]));
+		if ($ligne->id > 0 && $verif == 'ok')
+		{
+			$mesg = "La ligne #3 : 0".$_POST["cli3"]." existe d�j� !";
+			$verif = "nok";
+		}
+	}
 
-  if (strlen(trim($_POST["cli2"])) > 0 && $verif == 'ok')
-    {
-      if (strlen(trim($_POST["cli2"])) <> 9 && $verif == 'ok')
+	/* Verif Tarif */
+	if (strlen(trim($_POST["france"])) > 0 && $verif == "ok")
 	{
-	  $mesg = "Num�ro de ligne #2 (0".$_POST["cli2"].") incorrect";
-	  $verif = "nok";
+		$temporel = ereg_replace(",",".",trim($_POST["france"]));
+
+		if(! is_numeric($temporel))
+		{
+			$error = 1030;
+			$verif = "nok";
+			$mesg .= "Tarif France Invalide";
+		}
+		else
+		{
+			if ($temporel > 0.04 )
+			{
+				$error = 1031;
+				$verif = "nok";
+				$mesg .= "Tarif France Invalide : $temporel > 0.04 !";
+			}
+			 
+			if ($temporel < 0.016 )
+			{
+				$error = 1031;
+				$verif = "nok";
+				$mesg .= "Tarif France Invalide : $temporel <  0.016 !";
+			}
+		}
 	}
-      
-      if (!in_array(substr(trim($_POST["cli2"]),0,1), $p) && $verif == 'ok')
+	if (strlen(trim($_POST["mobil"])) > 0 && $verif == "ok")
 	{
-	  $mesg = "Num�ro de ligne #2 (0".$_POST["cli2"].") incorrect";
-	  $verif = "nok";
+		$temporel = ereg_replace(",",".",trim($_POST["mobil"]));
+
+		if(! is_numeric($temporel))
+		{
+			$error++;
+			$verif = "nok";
+			$mesg .= "Tarif Mobile Invalide";
+		}
+		else
+		{
+			if ($temporel > 0.40 )
+			{
+				$error = 1033;
+				$verif = "nok";
+				$mesg .= "Tarif Mobile Invalide : $temporel > 0.40 !";
+			}
+			if ($temporel <  0.14 )
+			{
+				$error = 1034;
+				$verif = "nok";
+				$mesg .= "Tarif Mobile Invalide : $temporel <  0.14 !";
+			}
+		}
 	}
 
-      $ligne = new LigneTel($db);
-      $ligne->fetch("0".trim($_POST["cli2"]));
-      if ($ligne->id > 0 && $verif == 'ok')
+	/* Fin Verif Tarif */
+
+	$soc->nom                   = $_POST["nom"];
+	$soc->adresse               = $_POST["adresse"];
+	$soc->cp                    = $_POST["cp"];
+	$soc->ville                 = $_POST["ville"];
+	$soc->pays_id               = $_POST["pays_id"];
+	$soc->tel                   = $_POST["tel"];
+	$soc->fax                   = $_POST["fax"];
+	$soc->url                   = ereg_replace( "http://", "", $_POST["url"] );
+	$soc->code_client           = $_POST["code_client"];
+	$soc->code_fournisseur      = $_POST["code_fournisseur"];
+	$soc->codeclient_modifiable = $_POST["codeclient_modifiable"];
+	$soc->codefournisseur_modifiable = $_POST["codefournisseur_modifiable"];
+	$soc->client                = 1;
+	$soc->fournisseur           = 0;
+
+	if (!$error && $verif == "ok")
 	{
-	  $mesg = "La ligne #2 : 0".$_POST["cli2"]." existe d�j� !";
-	  $verif = "nok";
+		$soc->code_client = $_POST["code_client"]."00";
+		$result = $soc->create($user);
+
+		if ($result == 0)
+		{
+			$soc->AddPerms(1,1,1,1);
+			$soc->AddPerms(5,1,1,1);
+			$soc->AddPerms(9,1,1,1);
+			$soc->AddPerms($user->id,1,1,1);
+			$soc->AddPerms($_POST["commercial_sign"],1,0,0);
+		}
+		else
+		{
+			$mesg = nl2br($soc->error) . " (result $result)\n";
+			$error = 1035;
+		}
 	}
-    }
-  /* Ligne #3 */
 
-  if (strlen(trim($_POST["cli3"])) > 0 && $verif == 'ok')
-    {
-      if (strlen(trim($_POST["cli3"])) <> 9 && $verif == 'ok')
+	if (!$error && $verif == "ok")
 	{
-	  $mesg = "Num�ro de ligne #3 (0".$_POST["cli3"].") incorrect";
-	  $verif = "nok";
+		$contact->socid = $soc->id;
+
+		if ( $contact->create($user) > 0)
+		{
+
+		}
+		else
+		{
+			$error = 1024;
+		}
 	}
-      
-      if (!in_array(substr(trim($_POST["cli3"]),0,1), $p) && $verif == 'ok')
+
+
+	if ((strlen(trim($_POST["rib_banque"])) + strlen(trim($_POST["rib_guichet"])) + strlen(trim($_POST["rib_compte"])) + strlen(trim($_POST["rib_cle"])))<> 0 && $verif == 'ok' && !$error)
 	{
-	  $mesg = "Num�ro de ligne #3 (0".$_POST["cli3"].") incorrect";
-	  $verif = "nok";
+		$rib->socid = $soc->id;
+		if ( $rib->update($user) > 0)
+		{
+
+		}
+		else
+		{
+			$error = 1025;
+		}
 	}
 
-      $ligne = new LigneTel($db);
-      $ligne->fetch("0".trim($_POST["cli3"]));
-      if ($ligne->id > 0 && $verif == 'ok')
-	{
-	  $mesg = "La ligne #3 : 0".$_POST["cli3"]." existe d�j� !";
-	  $verif = "nok";
-	}
-    }
-
-  /* Verif Tarif */
-  if (strlen(trim($_POST["france"])) > 0 && $verif == "ok")
-    {      
-      $temporel = ereg_replace(",",".",trim($_POST["france"]));
-  
-      if(! is_numeric($temporel))
+	if (!$error && $verif == "ok")
 	{
-	  $error = 1030;
-	  $verif = "nok";
-	  $mesg .= "Tarif France Invalide";
-	}
-      else
-	{
-	  if ($temporel > 0.04 )
-	    {
-	      $error = 1031;
-	      $verif = "nok";
-	      $mesg .= "Tarif France Invalide : $temporel > 0.04 !";
-	    }
-	  
-	  if ($temporel < 0.016 )
-	    {
-	      $error = 1031;
-	      $verif = "nok";
-	      $mesg .= "Tarif France Invalide : $temporel <  0.016 !";
-	    }
-	}
-    }      
-  if (strlen(trim($_POST["mobil"])) > 0 && $verif == "ok")
-    {      
-      $temporel = ereg_replace(",",".",trim($_POST["mobil"]));
-  
-      if(! is_numeric($temporel))
+		$contrat = new TelephonieContrat($db);
+
+		$contrat->client_comm     = $soc->id;
+		$contrat->client          = $soc->id;
+		$contrat->client_facture  = $soc->id;
+		$contrat->commercial_sign = $_POST["commercial_sign"];
+
+		if ( $contrat->create($user,'oui',$_POST["mode_paiement"]) == 0)
+		{
+			$contrat->add_contact_facture($contact->id);
+		}
+		else
+		{
+			$error = 1026;
+		}
+	}
+
+	if(!$error && $verif == "ok")
 	{
-	  $error++;
-	  $verif = "nok";
-	  $mesg .= "Tarif Mobile Invalide";
+		$contrat->commercial_sign_id = $_POST["commercial_sign"];
+		$contrat->addpo($_POST["montantpo"], $user);
 	}
-      else
-	{      
-	  if ($temporel > 0.40 )
-	    {
-	      $error = 1033;
-	      $verif = "nok";
-	      $mesg .= "Tarif Mobile Invalide : $temporel > 0.40 !";
-	    }
-	  if ($temporel <  0.14 )
-	    {
-	      $error = 1034;
-	      $verif = "nok";
-	      $mesg .= "Tarif Mobile Invalide : $temporel <  0.14 !";
-	    }
-	}
-    }      
-
-  /* Fin Verif Tarif */
-
-  $soc->nom                   = $_POST["nom"];
-  $soc->adresse               = $_POST["adresse"];
-  $soc->cp                    = $_POST["cp"];
-  $soc->ville                 = $_POST["ville"];
-  $soc->pays_id               = $_POST["pays_id"];
-  $soc->tel                   = $_POST["tel"];
-  $soc->fax                   = $_POST["fax"];
-  $soc->url                   = ereg_replace( "http://", "", $_POST["url"] );
-  $soc->code_client           = $_POST["code_client"];
-  $soc->code_fournisseur      = $_POST["code_fournisseur"];
-  $soc->codeclient_modifiable = $_POST["codeclient_modifiable"];
-  $soc->codefournisseur_modifiable = $_POST["codefournisseur_modifiable"];
-  $soc->client                = 1;
-  $soc->fournisseur           = 0;
-
-  if (!$error && $verif == "ok")
-    {     
-      $soc->code_client = $_POST["code_client"]."00";
-      $result = $soc->create($user);
-      
-      if ($result == 0)
-	{
-	  $soc->AddPerms(1,1,1,1);
-	  $soc->AddPerms(5,1,1,1);
-	  $soc->AddPerms(9,1,1,1);
-	  $soc->AddPerms($user->id,1,1,1);
-	  $soc->AddPerms($_POST["commercial_sign"],1,0,0);
-	}
-      else
-	{
-	  $mesg = nl2br($soc->error) . " (result $result)\n";
-	  $error = 1035;
-	}
-    }
-  
-  if (!$error && $verif == "ok")
-    {
-      $contact->socid = $soc->id;
-      
-      if ( $contact->create($user) > 0)
-	{
-	  
-	}
-      else
-	{
-	  $error = 1024;
-	}
-    }
-
-
-  if ((strlen(trim($_POST["rib_banque"])) + strlen(trim($_POST["rib_guichet"])) + strlen(trim($_POST["rib_compte"])) + strlen(trim($_POST["rib_cle"])))<> 0 && $verif == 'ok' && !$error)
-    {
-      $rib->socid = $soc->id;
-
-      if ( $rib->update($user) > 0)
-	{
-	  
-	}
-      else
-	{
-	  $error = 1025;
-	}
-    }
-
-  if (!$error && $verif == "ok")
-    {
-      $contrat = new TelephonieContrat($db);
-      
-      $contrat->client_comm     = $soc->id;
-      $contrat->client          = $soc->id;
-      $contrat->client_facture  = $soc->id;
-      $contrat->commercial_sign = $_POST["commercial_sign"];
-      
-      if ( $contrat->create($user,'oui',$_POST["mode_paiement"]) == 0)
-	{
-	  $contrat->add_contact_facture($contact->id);
-	}
-      else
-	{
-	  $error = 1026;
-	}
-    }
-  
-  if(!$error && $verif == "ok")
-    {
-      $contrat->commercial_sign_id = $_POST["commercial_sign"];
-      $contrat->addpo($_POST["montantpo"], $user);
-    }
-
-  /* Ligne 1 */
-
-  $ligne = new LigneTel($db);
-  $ligne->contrat         = $contrat->id;
-  $ligne->numero          = "0".$_POST["cli"];
-  $ligne->client_comm     = $soc->id;
-  $ligne->client          = $soc->id;
-  $ligne->client_facture  = $soc->id;
-  $ligne->fournisseur     = $_POST["fournisseur"];
-  $ligne->commercial_sign = $_POST["commercial_sign"];
-  $ligne->commercial_suiv = $_POST["commercial_sign"];
-  $ligne->concurrent      = $_POST["concurrent"];
-  $ligne->remise          = "0";
-  $ligne->note            = $_POST["note"];
-  
-  if(!$error && $verif == "ok")
-    {
-      if (strlen(trim($_POST["cli"])) == 9)
-	{
-	  
+
+	/* Ligne 1 */
+
+	$ligne = new LigneTel($db);
+	$ligne->contrat         = $contrat->id;
+	$ligne->numero          = "0".$_POST["cli"];
+	$ligne->client_comm     = $soc->id;
+	$ligne->client          = $soc->id;
+	$ligne->client_facture  = $soc->id;
+	$ligne->fournisseur     = $_POST["fournisseur"];
+	$ligne->commercial_sign = $_POST["commercial_sign"];
+	$ligne->commercial_suiv = $_POST["commercial_sign"];
+	$ligne->concurrent      = $_POST["concurrent"];
+	$ligne->remise          = "0";
+	$ligne->note            = $_POST["note"];
+
+	if(!$error && $verif == "ok")
+	{
+		if (strlen(trim($_POST["cli"])) == 9)
+		{
+
 	  if ( $ligne->create($user, $_POST["mode_paiement"]) == 0)
-	    {
-	      
-	    }
+	  {
+	  	 
+	  }
 	  else
-	    {
-	      $error = 1027;
-	      $mesg.= "Impossible de cr�er la ligne #1 0".$_POST["cli"];
-	    }
+	  {
+	  	$error = 1027;
+	  	$mesg.= "Impossible de cr�er la ligne #1 0".$_POST["cli"];
+	  }
+		}
 	}
-    }
-  
-  /* SDA */
 
-  if(!$error && $verif == "ok")
-    {
-      if (strlen(trim($_POST["cli"])) == 9 && strlen(trim($_POST["cliend"])) == 9)
+	/* SDA */
+
+	if(!$error && $verif == "ok")
 	{
+		if (strlen(trim($_POST["cli"])) == 9 && strlen(trim($_POST["cliend"])) == 9)
+		{
 	  $cbegin = trim($_POST["cli"]) + 1;
 	  $cend = trim($_POST["cliend"]);
 
 	  $cli = $cbegin;
 
 	  while ($cli <= $cend)
-	    {
-	      $ligne = new LigneTel($db);
-	      $ligne->contrat         = $contrat->id;
-	      $ligne->numero          = "0".$cli;
-	      $ligne->client_comm     = $soc->id;
-	      $ligne->client          = $soc->id;
-	      $ligne->client_facture  = $soc->id;
-	      $ligne->fournisseur     = $_POST["fournisseur"];
-	      $ligne->commercial_sign = $_POST["commercial_sign"];
-	      $ligne->commercial_suiv = $_POST["commercial_sign"];
-	      $ligne->concurrent      = $_POST["concurrent"];
-	      $ligne->remise          = "0";
-	      $ligne->note            = $_POST["note"];
-	      
-	      if ( $ligne->create($user, $_POST["mode_paiement"]) == 0)
-		{
-		  
-		}
-	      else
-		{
-		  $error = 1027;
-		  $mesg.= "Impossible de cr�er la ligne 0$cli";
-		}
-
-	      $cli++;
-	    }
-	}
-    }
-  
-  /* Ligne 2 */
-
-  $ligne = new LigneTel($db);
-  $ligne->contrat         = $contrat->id;
-  $ligne->numero          = "0".$_POST["cli2"];
-  $ligne->client_comm     = $soc->id;
-  $ligne->client          = $soc->id;
-  $ligne->client_facture  = $soc->id;
-  $ligne->fournisseur     = $_POST["fournisseur"];
-  $ligne->commercial_sign = $_POST["commercial_sign"];
-  $ligne->commercial_suiv = $_POST["commercial_sign"];
-  $ligne->concurrent      = $_POST["concurrent"];
-  $ligne->remise          = "0";
-  $ligne->note            = $_POST["note"];
-  
-  if(!$error && $verif == "ok")
-    {
-      if (strlen(trim($_POST["cli2"])) == 9)
-	{
-	  
+	  {
+	  	$ligne = new LigneTel($db);
+	  	$ligne->contrat         = $contrat->id;
+	  	$ligne->numero          = "0".$cli;
+	  	$ligne->client_comm     = $soc->id;
+	  	$ligne->client          = $soc->id;
+	  	$ligne->client_facture  = $soc->id;
+	  	$ligne->fournisseur     = $_POST["fournisseur"];
+	  	$ligne->commercial_sign = $_POST["commercial_sign"];
+	  	$ligne->commercial_suiv = $_POST["commercial_sign"];
+	  	$ligne->concurrent      = $_POST["concurrent"];
+	  	$ligne->remise          = "0";
+	  	$ligne->note            = $_POST["note"];
+	  	 
+	  	if ( $ligne->create($user, $_POST["mode_paiement"]) == 0)
+	  	{
+
+	  	}
+	  	else
+	  	{
+	  		$error = 1027;
+	  		$mesg.= "Impossible de cr�er la ligne 0$cli";
+	  	}
+
+	  	$cli++;
+	  }
+		}
+	}
+
+	/* Ligne 2 */
+
+	$ligne = new LigneTel($db);
+	$ligne->contrat         = $contrat->id;
+	$ligne->numero          = "0".$_POST["cli2"];
+	$ligne->client_comm     = $soc->id;
+	$ligne->client          = $soc->id;
+	$ligne->client_facture  = $soc->id;
+	$ligne->fournisseur     = $_POST["fournisseur"];
+	$ligne->commercial_sign = $_POST["commercial_sign"];
+	$ligne->commercial_suiv = $_POST["commercial_sign"];
+	$ligne->concurrent      = $_POST["concurrent"];
+	$ligne->remise          = "0";
+	$ligne->note            = $_POST["note"];
+
+	if(!$error && $verif == "ok")
+	{
+		if (strlen(trim($_POST["cli2"])) == 9)
+		{
+
 	  if ( $ligne->create($user, $_POST["mode_paiement"]) == 0)
-	    {
-	      
-	    }
+	  {
+	  	 
+	  }
 	  else
-	    {
-	      //$error++;
-	      $error = 1028;
-	      $mesg.= "Impossible de cr�er la ligne #2 0".$_POST["cli2"];
-	    }
-	}
-    }
-
-  /* Ligne 3 */
-  $ligne = new LigneTel($db);
-  $ligne->contrat         = $contrat->id;
-  $ligne->numero          = "0".$_POST["cli3"];
-  $ligne->client_comm     = $soc->id;
-  $ligne->client          = $soc->id;
-  $ligne->client_facture  = $soc->id;
-  $ligne->fournisseur     = $_POST["fournisseur"];
-  $ligne->commercial_sign = $_POST["commercial_sign"];
-  $ligne->commercial_suiv = $_POST["commercial_sign"];
-  $ligne->concurrent      = $_POST["concurrent"];
-  $ligne->remise          = "0";
-  $ligne->note            = $_POST["note"];
-  
-  if(!$error && $verif == "ok")
-    {
-      if (strlen(trim($_POST["cli3"])) == 9)
-	{
-	  
+	  {
+	  	//$error++;
+	  	$error = 1028;
+	  	$mesg.= "Impossible de cr�er la ligne #2 0".$_POST["cli2"];
+	  }
+		}
+	}
+
+	/* Ligne 3 */
+	$ligne = new LigneTel($db);
+	$ligne->contrat         = $contrat->id;
+	$ligne->numero          = "0".$_POST["cli3"];
+	$ligne->client_comm     = $soc->id;
+	$ligne->client          = $soc->id;
+	$ligne->client_facture  = $soc->id;
+	$ligne->fournisseur     = $_POST["fournisseur"];
+	$ligne->commercial_sign = $_POST["commercial_sign"];
+	$ligne->commercial_suiv = $_POST["commercial_sign"];
+	$ligne->concurrent      = $_POST["concurrent"];
+	$ligne->remise          = "0";
+	$ligne->note            = $_POST["note"];
+
+	if(!$error && $verif == "ok")
+	{
+		if (strlen(trim($_POST["cli3"])) == 9)
+		{
+
 	  if ( $ligne->create($user, $_POST["mode_paiement"]) == 0)
-	    {
-	      
-	    }
+	  {
+	  	 
+	  }
 	  else
-	    {
-	      //$error++;
-	      $error = 1029;
-	      $mesg.= "Impossible de cr�er la ligne #3 0".$_POST["cli3"];
-	    }
+	  {
+	  	//$error++;
+	  	$error = 1029;
+	  	$mesg.= "Impossible de cr�er la ligne #3 0".$_POST["cli3"];
+	  }
+		}
 	}
-    }
 
-  /* DEBUT TARIFS */
-  if (strlen(trim($_POST["france"])) > 0 && $verif == "ok")
-    {      
-      $temporel = ereg_replace(",",".",trim($_POST["france"]));
-  
-      if (!$error)
+	/* DEBUT TARIFS */
+	if (strlen(trim($_POST["france"])) > 0 && $verif == "ok")
 	{
+		$temporel = ereg_replace(",",".",trim($_POST["france"]));
+
+		if (!$error)
+		{
 	  $db->begin();
-	  
+
 	  $sql = "REPLACE INTO ".MAIN_DB_PREFIX."telephonie_tarif_client";
 	  $sql .= " (fk_tarif, fk_client, temporel, fixe, fk_user) VALUES ";
 	  $sql .= " (1293,".$soc->id.",'".$temporel."','0',".$user->id.")";
-	  
+
 	  if (! $db->query($sql) )
-	    {
-	      $error++;
-	    }
-	  
+	  {
+	  	$error++;
+	  }
+
 	  $sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_tarif_client_log";
 	  $sql .= " (fk_tarif, fk_client, temporel, fixe, fk_user, datec) VALUES ";
 	  $sql .= " (1293,".$soc->id.",'".$temporel."','0',".$user->id.",now())";
-	  
+
 	  if (! $db->query($sql) )
-	    {
-	      $error++;
-	    }
-	  
+	  {
+	  	$error++;
+	  }
+
 	  if ( $error == 0 )
-	    {
-	      $db->commit();
-	    }
+	  {
+	  	$db->commit();
+	  }
 	  else
-	    {
-	      $db->rollback();
-	      $mesg = "Erreur tarifs !";
-	    }
+	  {
+	  	$db->rollback();
+	  	$mesg = "Erreur tarifs !";
+	  }
+		}
 	}
-    }
 
-  /* mobiles */
-  if (strlen(trim($_POST["mobil"])) > 0 && $verif == "ok")
-    {      
-      $mobil_ids = array(1289,1290,1291,1292);
-      foreach ($mobil_ids as $mobil_id)
+	/* mobiles */
+	if (strlen(trim($_POST["mobil"])) > 0 && $verif == "ok")
 	{
+		$mobil_ids = array(1289,1290,1291,1292);
+		foreach ($mobil_ids as $mobil_id)
+		{
 	  $temporel = ereg_replace(",",".",trim($_POST["mobil"]));
-	  
+
 	  if (!$error)
-	    {
-	      $db->begin();
-	      
-	      $sql = "REPLACE INTO ".MAIN_DB_PREFIX."telephonie_tarif_client";
-	      $sql .= " (fk_tarif, fk_client, temporel, fixe, fk_user) VALUES ";
-	      $sql .= " (".$mobil_id.",".$soc->id.",'".$temporel."','0',".$user->id.")";
-	  
-	      if (! $db->query($sql) )
-		{
-		  $error++;
-		}
-	      
-	      $sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_tarif_client_log";
-	      $sql .= " (fk_tarif, fk_client, temporel, fixe, fk_user, datec) VALUES ";
-	      $sql .= " (".$mobil_id.",".$soc->id.",'".$temporel."','0',".$user->id.",now())";
-	  
-	      if (! $db->query($sql) )
-		{
-		  $error++;
-		}
-	      
-	      if ( $error == 0 )
-		{
-		  $db->commit();
-		}
-	      else
-		{
-		  $db->rollback();
-		  $mesg = "Erreur tarifs !";
+	  {
+	  	$db->begin();
+	  	 
+	  	$sql = "REPLACE INTO ".MAIN_DB_PREFIX."telephonie_tarif_client";
+	  	$sql .= " (fk_tarif, fk_client, temporel, fixe, fk_user) VALUES ";
+	  	$sql .= " (".$mobil_id.",".$soc->id.",'".$temporel."','0',".$user->id.")";
+	  	 
+	  	if (! $db->query($sql) )
+	  	{
+	  		$error++;
+	  	}
+	  	 
+	  	$sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_tarif_client_log";
+	  	$sql .= " (fk_tarif, fk_client, temporel, fixe, fk_user, datec) VALUES ";
+	  	$sql .= " (".$mobil_id.",".$soc->id.",'".$temporel."','0',".$user->id.",now())";
+	  	 
+	  	if (! $db->query($sql) )
+	  	{
+	  		$error++;
+	  	}
+	  	 
+	  	if ( $error == 0 )
+	  	{
+	  		$db->commit();
+	  	}
+	  	else
+	  	{
+	  		$db->rollback();
+	  		$mesg = "Erreur tarifs !";
+	  	}
+	  }
 		}
-	    }
 	}
-    }
 
-  /* FIN TARIFS */
+	/* FIN TARIFS */
+
+	if (!$error && $verif == "ok")
+	{
+		Header("Location: ".DOL_URL_ROOT."/telephonie/contrat/fiche.php?id=".$contrat->id);
+	}
+	else
+	{
+		$mesg .= " (num�ro erreur : $error)";
+	}
 
-  if (!$error && $verif == "ok")
-    {
-      Header("Location: ".DOL_URL_ROOT."/telephonie/contrat/fiche.php?id=".$contrat->id);
-    }
-  else
-    {
-      $mesg .= " (num�ro erreur : $error)";
-    }
-  
 }
 
 /**
@@ -618,243 +619,243 @@ $form = new Form($db);
 if ($user->rights->telephonie->ligne->creer)
 {
 
-  dolibarr_fiche_head($head, $hselected, 'Nouveau client');
-  /*
+	dolibarr_fiche_head($head, $hselected, 'Nouveau client');
+	/*
+
+	*/
 
-   */
+	if ($mesg)
+	{
+		print '<div class="error">';
+		print $mesg;
+		print '</div>';
+	}
+	else
+	{
+
+	}
 
-  if ($mesg)
-    {
-      print '<div class="error">';
-      print $mesg;
-      print '</div>';
-    }
-  else
-    {
+	$focus = " onfocus=\"this.className='focus';\" onblur=\"this.className='normal';\" ";
 
-    }
 
-  $focus = " onfocus=\"this.className='focus';\" onblur=\"this.className='normal';\" ";   
+	print '<FORM NAME="formClient" action="new.php" method="post">';
+	print '<input type="hidden" name="codeclient_modifiable" value="1">';
+	print '<input type="hidden" name="codefournisseur_modifiable" value="1">';
+	print '<input type="hidden" name="action" value="add">';
 
+	print '<div id="corpForm">';
+	print '<fieldset id="societe">';
+	print "<legend>Soci�t�</legend>\n";
 
-  print '<FORM NAME="formClient" action="new.php" method="post">';
-  print '<input type="hidden" name="codeclient_modifiable" value="1">';
-  print '<input type="hidden" name="codefournisseur_modifiable" value="1">';
-  print '<input type="hidden" name="action" value="add">';
+	print '<table class="noborder" width="100%">';
 
-  print '<div id="corpForm">';
-  print '<fieldset id="societe">';
-  print "<legend>Soci�t�</legend>\n";
+	print '<tr><td width="20%">'.$langs->trans('Name').'</td><td>';
+	print '<input type="text" size="30" name="nom" ';
+	print $focus .' value="'.$soc->nom.'"></td><td>';
 
-  print '<table class="noborder" width="100%">';
-  
-  print '<tr><td width="20%">'.$langs->trans('Name').'</td><td>';
-  print '<input type="text" size="30" name="nom" ';
-  print $focus .' value="'.$soc->nom.'"></td><td>';
+	print "Attention ce formulaire n'est a utiliser uniquement pour les nouveaux clients.</td></tr>";
 
-  print "Attention ce formulaire n'est a utiliser uniquement pour les nouveaux clients.</td></tr>";
-  
-  // On positionne pays_id, pays_code et libelle du pays choisi
-  $soc->pays_id=$_POST["pays_id"]?$_POST["pays_id"]:(defined(MAIN_INFO_SOCIETE_PAYS)?MAIN_INFO_SOCIETE_PAYS:'');
-  if ($soc->pays_id)
-    {
-      $sql = "SELECT code, libelle from ".MAIN_DB_PREFIX."c_pays where rowid = ".$soc->pays_id;
-      $resql=$db->query($sql);
-      if ($resql)
+	// On positionne pays_id, pays_code et libelle du pays choisi
+	$soc->pays_id=$_POST["pays_id"]?$_POST["pays_id"]:(defined(MAIN_INFO_SOCIETE_PAYS)?MAIN_INFO_SOCIETE_PAYS:'');
+	if ($soc->pays_id)
 	{
+		$sql = "SELECT code, libelle from ".MAIN_DB_PREFIX."c_pays where rowid = ".$soc->pays_id;
+		$resql=$db->query($sql);
+		if ($resql)
+		{
 	  $obj = $db->fetch_object($resql);
+		}
+		else
+		{
+	  dolibarr_print_error($db);
+		}
+		$soc->pays_code=$obj->code;
+		$soc->pays=$obj->libelle;
 	}
-      else
+
+	print '<tr><td width="20%">'.$langs->trans('CustomerCode').'</td><td colspan="3">';
+
+	print '<input size="7" type="text" name="code_client" maxlength="6"';
+	print " onfocus=\"this.className='focus';\" onblur=\"this.className='normal';\" ";
+	print ' value="'.$soc->code_client.'">00</td>';
+
+	print '<tr><td>'.$langs->trans('Address').'</td><td colspan="3"><textarea '.$focus.' name="adresse" cols="40" rows="2" wrap="soft">';
+	print $soc->adresse;
+	print '</textarea></td></tr>';
+
+	print '<tr><td>'.$langs->trans('Zip').'</td><td colspan="3">';
+	print '<input size="7" maxlength="6" type="text" name="cp" ';
+	print " onfocus=\"this.className='focus';\" onblur=\"this.className='normal';\" ";
+	print ' value="'.$soc->cp.'">&nbsp;';
+
+	print $langs->trans('Town').'&nbsp;<input type="text" '.$focus.' name="ville" value="'.$soc->ville.'"></td></tr>';
+
+	print '<tr><td>'.$langs->trans('Phone').'</td><td><input type="text" size="11" maxlength="10" '.$focus.' name="tel" value="'.$soc->tel.'"></td>';
+	print '<td>'.$langs->trans('Fax').'</td><td><input type="text" '.$focus.' name="fax" size="11" maxlength="10" value="'.$soc->fax.'"></td></tr>';
+
+	print "</table>\n";
+	print "</fieldset><br />\n";
+	print '<fieldset id="contact">';
+	print "<legend>Coordonn�es bancaires</legend>\n";
+	print '<table class="noborder" width="100%">';
+
+	print '<tr><td width="20%">Titulaire du compte</td><td><input type="text" size="30" '.$focus.' name="titulaire" value="'.$_POST["titulaire"].'"></td></tr>';
+
+	print '<tr><td width="20%">RIB</td><td colspan="3">';
+	print '<input type="text" size="6" maxlength="5" '.$focus.' name="rib_banque" value="'.$_POST["rib_banque"].'">';
+	print '<input type="text" size="6" maxlength="5" '.$focus.' name="rib_guichet" value="'.$_POST["rib_guichet"].'">';
+	print '<input type="text" size="12" maxlength="11" '.$focus.' name="rib_compte" value="'.$_POST["rib_compte"].'">';
+	print '<input type="text" size="3" maxlength="2" '.$focus.' name="rib_cle" value="'.$_POST["rib_cle"].'">';
+	print '&nbsp;&nbsp;IBAN&nbsp;&nbsp;';
+	print '<input type="text" size="4" maxlength="4" '.$focus.' name="rib_iban" value="'.$_POST["rib_iban"].'">';
+	print '</td></tr>';
+
+	print '<tr><td width="20%">R�glement</td><td colspan="3">';
+	print '<select name="mode_paiement">';
+	if ($_POST["mode_paiement"] == 'vir')
 	{
-	  dolibarr_print_error($db);
+		print '<option value="pre">Pr�l�vement</option>';
+		print '<option value="vir" SELECTED>Virement</option>';
 	}
-      $soc->pays_code=$obj->code;
-      $soc->pays=$obj->libelle;
-    }  
-    
-  print '<tr><td width="20%">'.$langs->trans('CustomerCode').'</td><td colspan="3">';
-
-  print '<input size="7" type="text" name="code_client" maxlength="6"';
-  print " onfocus=\"this.className='focus';\" onblur=\"this.className='normal';\" "; 
-  print ' value="'.$soc->code_client.'">00</td>';
-
-  print '<tr><td>'.$langs->trans('Address').'</td><td colspan="3"><textarea '.$focus.' name="adresse" cols="40" rows="2" wrap="soft">';
-  print $soc->adresse;
-  print '</textarea></td></tr>';
-  
-  print '<tr><td>'.$langs->trans('Zip').'</td><td colspan="3">';
-  print '<input size="7" maxlength="6" type="text" name="cp" ';
-  print " onfocus=\"this.className='focus';\" onblur=\"this.className='normal';\" "; 
-  print ' value="'.$soc->cp.'">&nbsp;';
-
-  print $langs->trans('Town').'&nbsp;<input type="text" '.$focus.' name="ville" value="'.$soc->ville.'"></td></tr>';
-  
-  print '<tr><td>'.$langs->trans('Phone').'</td><td><input type="text" size="11" maxlength="10" '.$focus.' name="tel" value="'.$soc->tel.'"></td>';
-  print '<td>'.$langs->trans('Fax').'</td><td><input type="text" '.$focus.' name="fax" size="11" maxlength="10" value="'.$soc->fax.'"></td></tr>';
-  
-  print "</table>\n";
-  print "</fieldset><br />\n";
-  print '<fieldset id="contact">';
-  print "<legend>Coordonn�es bancaires</legend>\n";
-  print '<table class="noborder" width="100%">';
-
-  print '<tr><td width="20%">Titulaire du compte</td><td><input type="text" size="30" '.$focus.' name="titulaire" value="'.$_POST["titulaire"].'"></td></tr>';
-
-  print '<tr><td width="20%">RIB</td><td colspan="3">';
-  print '<input type="text" size="6" maxlength="5" '.$focus.' name="rib_banque" value="'.$_POST["rib_banque"].'">';
-  print '<input type="text" size="6" maxlength="5" '.$focus.' name="rib_guichet" value="'.$_POST["rib_guichet"].'">';
-  print '<input type="text" size="12" maxlength="11" '.$focus.' name="rib_compte" value="'.$_POST["rib_compte"].'">';
-  print '<input type="text" size="3" maxlength="2" '.$focus.' name="rib_cle" value="'.$_POST["rib_cle"].'">';
-  print '&nbsp;&nbsp;IBAN&nbsp;&nbsp;';
-  print '<input type="text" size="4" maxlength="4" '.$focus.' name="rib_iban" value="'.$_POST["rib_iban"].'">';
-  print '</td></tr>';
-  
-  print '<tr><td width="20%">R�glement</td><td colspan="3">';
-  print '<select name="mode_paiement">';
-  if ($_POST["mode_paiement"] == 'vir')
-    {
-      print '<option value="pre">Pr�l�vement</option>';
-      print '<option value="vir" SELECTED>Virement</option>';
-    }
-  else
-    {
-      print '<option value="pre" SELECTED>Pr�l�vement</option>';
-      print '<option value="vir">Virement</option>';
-    }
-  print '</select>';
-  print '</td></tr>';
-
-  print "</table>\n";
-  print "</fieldset><br />\n";
-  
-  print '<fieldset id="contact">';
-  print "<legend>Contact</legend>\n";
-  print '<table class="noborder" width="100%">';
-  
-  print '<tr><td width="20%">'.$langs->trans('Name').'</td><td><input type="text" size="30" '.$focus.' name="cnom" value="'.$contact->name.'"></td>';
-  print '<td width="20%">'.$langs->trans('Firstname').'</td><td><input type="text" size="20" '.$focus.' name="cprenom" value="'.$contact->firstname.'"></td></tr>';
-  print '<tr><td>'.$langs->trans('Mail').'</td><td><input type="text" size="40" '.$focus.' name="cmail" value="'.$contact->email.'"></td></tr>';
-  
-  print "</table>\n";
-  print "</fieldset><br />\n";
-  
-  print '<fieldset id="contact">';
-  print "<legend>Commercial</legend>\n";
-  print '<table class="noborder" width="100%">';
-  print '<tr><td width="20%">Commercial Signature</td><td >';
-  $ff = array();
-  $sql = "SELECT u.rowid, u.firstname, u.name";
-  $sql .= " FROM ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."usergroup_user as ug";
-  $sql .= " WHERE u.rowid = ug.fk_user";
-  $sql .= " AND ug.fk_usergroup = '".TELEPHONIE_GROUPE_COMMERCIAUX_ID."'";
-    $sql .= " ORDER BY name ";
-    if ( $db->query( $sql) )
-      {
-	$num = $db->num_rows();
-	if ( $num > 0 )
-	  {
-	    while ($row = $db->fetch_row($resql))
-	      {
-		$ff[$row[0]] = $row[1] . " " . $row[2];
-	      }
-	  }
-	$db->free();
-	
-      }
-    
-    $form->select_array("commercial_sign",$ff,$ligne->commercial_sign);
-    
-    print '</td>';
-    
-    print '<td width="20%">PO mensuelle</td><td valign="top" colspan="2">';
-    print '<input '.$focus.' name="montantpo" size="8" value="'.$_POST["montantpo"].'"> euros HT</td></tr>';	  
-    print '</td></tr>';	  	  
-    
-    print "</table>\n";
-    print "</fieldset><br />\n";
-
-    print '<fieldset id="ligne">';
-    print "<legend>Lignes t�l�phoniques � pr�s�lectionner</legend>\n";
-  
-    print '<table class="noborder" width="100%">';
-    
-    print '<tr><td width="20%">Ligne t�l�phonique #1</td><td>0<input type="text" size="10" maxlength="9" '.$focus.' name="cli" value="'.$_POST["cli"].'"></td>';
-
-    print '<td>Derniere SDA</td><td>0<input type="text" size="10" maxlength="9" '.$focus.' name="cliend" value="'.$_POST["cliend"].'"></td></tr>';
-
-
-    
-    print '<tr><td width="20%">Ligne t�l�phonique #2</td><td>0<input type="text" size="10" maxlength="9" '.$focus.' name="cli2" value="'.$_POST["cli2"].'"></td></tr>';
-
-    print '<tr><td width="20%">Ligne t�l�phonique #3</td><td>0<input type="text" size="10" maxlength="9" '.$focus.' name="cli3" value="'.$_POST["cli3"].'"></td></tr>';
-
-    print '<tr><td width="20%">Fournisseur</td><td>';
-    $ff = array();
-    $sql = "SELECT rowid, nom FROM ".MAIN_DB_PREFIX."telephonie_fournisseur WHERE commande_active = 1 ORDER BY nom ";
-    $resql = $db->query($sql);
-    if ($resql)
-      {
-	while ($row = $db->fetch_row($resql))
-	  {
-	    $ff[$row[0]] = $row[1];
-	  }
-	$db->free($resql);	
-      }
-
-    $def =$ligne->fournisseur?$ligne->fournisseur:TELEPHONIE_FOURNISSEUR_DEFAUT_ID;
-
-    $form->select_array("fournisseur",$ff,$def);
-    print '</td>';
-    
-    print '<td width="20%">Fournisseur pr�c�dent</td><td>';
-    $ff = array();
-    $sql = "SELECT rowid, nom FROM ".MAIN_DB_PREFIX."telephonie_concurrents ORDER BY rowid ";
-    $resql =  $db->query( $sql) ;
-    if ($resql)
-      {
-	$num = $db->num_rows($resql);
-	if ( $num > 0 )
-	  {
-	    while ($row = $db->fetch_row($resql))
-	      {
-		$ff[$row[0]] = $row[1];
-	      }
-	  }
-	$db->free();
-	
-      }
-    $form->select_array("concurrent",$ff,$ligne->concurrent);
-    print '</td></tr>';
-    
-    print "</table>\n";
-    print "</fieldset><br />\n";
-        
-    /* DEBUT TARIFS */
-
-    print '<fieldset id="ligne">';
-    print "<legend>Tarifs</legend>\n";
-    if ($user->rights->telephonie->tarif->client_modifier)
-      {
+	else
+	{
+		print '<option value="pre" SELECTED>Pr�l�vement</option>';
+		print '<option value="vir">Virement</option>';
+	}
+	print '</select>';
+	print '</td></tr>';
+
+	print "</table>\n";
+	print "</fieldset><br />\n";
+
+	print '<fieldset id="contact">';
+	print "<legend>Contact</legend>\n";
 	print '<table class="noborder" width="100%">';
-    
-	print '<tr><td width="20%">France</td><td><input type="text" size="10" maxlength="9" '.$focus.' name="france" value="'.$_POST["france"].'"></td><td>Laissez vide si tarifs par d�faut</tr>';
-	
-	print '<tr><td width="20%">Mobiles</td><td><input type="text" size="10" maxlength="9" '.$focus.' name="mobil" value="'.$_POST["mobil"].'"></td><td>Tous r�seaux confondus</td></tr>';
-	
+
+	print '<tr><td width="20%">'.$langs->trans('Name').'</td><td><input type="text" size="30" '.$focus.' name="cnom" value="'.$contact->name.'"></td>';
+	print '<td width="20%">'.$langs->trans('Firstname').'</td><td><input type="text" size="20" '.$focus.' name="cprenom" value="'.$contact->firstname.'"></td></tr>';
+	print '<tr><td>'.$langs->trans('Mail').'</td><td><input type="text" size="40" '.$focus.' name="cmail" value="'.$contact->email.'"></td></tr>';
+
 	print "</table>\n";
-      }
-    else
-      {
-	print "Vous n'avez pas les droits pour modifier les tarifs";
-      }
-    print "</fieldset><br />\n";
-
-    /* FIN TARIFS */
-
-    print '<input type="submit" value="'.$langs->trans('Save').'">'."\n";
-    
-    print '</form>'."\n";
-    print "</div>\n";
+	print "</fieldset><br />\n";
+
+	print '<fieldset id="contact">';
+	print "<legend>Commercial</legend>\n";
+	print '<table class="noborder" width="100%">';
+	print '<tr><td width="20%">Commercial Signature</td><td >';
+	$ff = array();
+	$sql = "SELECT u.rowid, u.firstname, u.name";
+	$sql .= " FROM ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."usergroup_user as ug";
+	$sql .= " WHERE u.rowid = ug.fk_user";
+	$sql .= " AND ug.fk_usergroup = '".TELEPHONIE_GROUPE_COMMERCIAUX_ID."'";
+	$sql .= " ORDER BY name ";
+	if ( $db->query( $sql) )
+	{
+		$num = $db->num_rows();
+		if ( $num > 0 )
+		{
+			while ($row = $db->fetch_row($resql))
+			{
+				$ff[$row[0]] = $row[1] . " " . $row[2];
+			}
+		}
+		$db->free();
+
+	}
+
+	$form->select_array("commercial_sign",$ff,$ligne->commercial_sign);
+
+	print '</td>';
+
+	print '<td width="20%">PO mensuelle</td><td valign="top" colspan="2">';
+	print '<input '.$focus.' name="montantpo" size="8" value="'.$_POST["montantpo"].'"> euros HT</td></tr>';
+	print '</td></tr>';
+
+	print "</table>\n";
+	print "</fieldset><br />\n";
+
+	print '<fieldset id="ligne">';
+	print "<legend>Lignes t�l�phoniques � pr�s�lectionner</legend>\n";
+
+	print '<table class="noborder" width="100%">';
+
+	print '<tr><td width="20%">Ligne t�l�phonique #1</td><td>0<input type="text" size="10" maxlength="9" '.$focus.' name="cli" value="'.$_POST["cli"].'"></td>';
+
+	print '<td>Derniere SDA</td><td>0<input type="text" size="10" maxlength="9" '.$focus.' name="cliend" value="'.$_POST["cliend"].'"></td></tr>';
+
+
+
+	print '<tr><td width="20%">Ligne t�l�phonique #2</td><td>0<input type="text" size="10" maxlength="9" '.$focus.' name="cli2" value="'.$_POST["cli2"].'"></td></tr>';
+
+	print '<tr><td width="20%">Ligne t�l�phonique #3</td><td>0<input type="text" size="10" maxlength="9" '.$focus.' name="cli3" value="'.$_POST["cli3"].'"></td></tr>';
+
+	print '<tr><td width="20%">Fournisseur</td><td>';
+	$ff = array();
+	$sql = "SELECT rowid, nom FROM ".MAIN_DB_PREFIX."telephonie_fournisseur WHERE commande_active = 1 ORDER BY nom ";
+	$resql = $db->query($sql);
+	if ($resql)
+	{
+		while ($row = $db->fetch_row($resql))
+		{
+			$ff[$row[0]] = $row[1];
+		}
+		$db->free($resql);
+	}
+
+	$def =$ligne->fournisseur?$ligne->fournisseur:TELEPHONIE_FOURNISSEUR_DEFAUT_ID;
+
+	$form->select_array("fournisseur",$ff,$def);
+	print '</td>';
+
+	print '<td width="20%">Fournisseur pr�c�dent</td><td>';
+	$ff = array();
+	$sql = "SELECT rowid, nom FROM ".MAIN_DB_PREFIX."telephonie_concurrents ORDER BY rowid ";
+	$resql =  $db->query( $sql) ;
+	if ($resql)
+	{
+		$num = $db->num_rows($resql);
+		if ( $num > 0 )
+		{
+			while ($row = $db->fetch_row($resql))
+			{
+				$ff[$row[0]] = $row[1];
+			}
+		}
+		$db->free();
+
+	}
+	$form->select_array("concurrent",$ff,$ligne->concurrent);
+	print '</td></tr>';
+
+	print "</table>\n";
+	print "</fieldset><br />\n";
+
+	/* DEBUT TARIFS */
+
+	print '<fieldset id="ligne">';
+	print "<legend>Tarifs</legend>\n";
+	if ($user->rights->telephonie->tarif->client_modifier)
+	{
+		print '<table class="noborder" width="100%">';
+
+		print '<tr><td width="20%">France</td><td><input type="text" size="10" maxlength="9" '.$focus.' name="france" value="'.$_POST["france"].'"></td><td>Laissez vide si tarifs par d�faut</tr>';
+
+		print '<tr><td width="20%">Mobiles</td><td><input type="text" size="10" maxlength="9" '.$focus.' name="mobil" value="'.$_POST["mobil"].'"></td><td>Tous r�seaux confondus</td></tr>';
+
+		print "</table>\n";
+	}
+	else
+	{
+		print "Vous n'avez pas les droits pour modifier les tarifs";
+	}
+	print "</fieldset><br />\n";
+
+	/* FIN TARIFS */
+
+	print '<input type="submit" value="'.$langs->trans('Save').'">'."\n";
+
+	print '</form>'."\n";
+	print "</div>\n";
 }
 
 
diff --git a/htdocs/telephonie/facturation/FacturationEmission.class.php b/htdocs/telephonie/facturation/FacturationEmission.class.php
index e6a9e996ceaa342129343d903864e8729a62807d..4206b50259773c1f25980f886d14dbba6592daac 100644
--- a/htdocs/telephonie/facturation/FacturationEmission.class.php
+++ b/htdocs/telephonie/facturation/FacturationEmission.class.php
@@ -802,7 +802,7 @@ class FacturationEmission {
       
 	$fac->fetch($facid);
 	$fac->fetch_client();
-	$fac->client->rib();
+	$fac->client->load_ban();
       
 	$message = "";
       
diff --git a/htdocs/telephonie/ligne/commande.php b/htdocs/telephonie/ligne/commande.php
index 8e88ecd9a4bab6c9dbcdfe74d37a99c4c29cfd62..4f5a569fdbe478c809c6e8d723a4e6df4594ee6b 100644
--- a/htdocs/telephonie/ligne/commande.php
+++ b/htdocs/telephonie/ligne/commande.php
@@ -105,11 +105,11 @@ if ($_GET["id"] or $_GET["numero"])
 	}
 
       print '<table>';
-      print "<tr><td>Num�ro correct </td><td> ".$ok_commande .'</td></tr>';
-      print "<tr><td>Commandes ouvertes aupr�s du fournisseur </td><td> ".$ftx->commande_enable .'</td></tr>';
+      print "<tr><td>Numero correct </td><td> ".$ok_commande .'</td></tr>';
+      print "<tr><td>Commandes ouvertes aupres du fournisseur </td><td> ".$ftx->commande_enable .'</td></tr>';
       print "<tr><td>Permission pour l'utilisateur de commander des lignes </td><td> ".$user->rights->telephonie->ligne_commander.'</td></tr>';
       print "<tr><td>Statut de la ligne compatible </td><td> ".($ligne->statut == 1 or $ligne->statut == -1) .'</td></tr>';
-      print "<tr><td>Rib ok ou mode de r�glement par virement </td><td> ".($client_facture->verif_rib() or $ligne->mode_paiement == 'vir').'</td></tr>';
+      print "<tr><td>Rib ok ou mode de reglement par virement </td><td> ".($client_facture->verif_rib() or $ligne->mode_paiement == 'vir').'</td></tr>';
       print '</table>';
 
     }
@@ -121,5 +121,5 @@ else
 
 $db->close();
 
-llxFooter("<em>Derni&egrave;re modification $Date$ r&eacute;vision $Revision$</em>");
+llxFooter('$Date$ - $Revision$');
 ?>
diff --git a/htdocs/telephonie/script/facturation-emission.php b/htdocs/telephonie/script/facturation-emission.php
index a0b10ce6853caa157a77edff53226e6bc14516b8..b6ba051290a691db60ec141f71cdf66e7950ae63 100644
--- a/htdocs/telephonie/script/facturation-emission.php
+++ b/htdocs/telephonie/script/facturation-emission.php
@@ -788,7 +788,7 @@ function facture_contrat($db, $user, $contrat_id, $factel_ids, $datetime, &$fact
       
       $fac->fetch($facid);
       $fac->fetch_client();
-      $fac->client->rib();
+      $fac->client->load_ban();
       
       $message = "";
       
@@ -809,7 +809,8 @@ function facture_contrat($db, $user, $contrat_id, $factel_ids, $datetime, &$fact
   
   if (!$error && !$cancel_facture)
     {
-      $db->query("COMMIT");      
+      $db->commit();
+
       /* $soc
        * $ligne
        */
@@ -832,8 +833,7 @@ function facture_contrat($db, $user, $contrat_id, $factel_ids, $datetime, &$fact
     }
   else
     {
-      $db->query("ROLLBACK");
-      dolibarr_syslog("ROLLBACK de la transaction $error");
+      $db->rollback();
     }    
 }