From becd40a8251436b51b21e93602c7b6165c1c97cd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marcos=20Garci=CC=81a?= <marcosgdf@gmail.com>
Date: Fri, 19 Apr 2013 15:38:24 +0200
Subject: [PATCH] Fixed bug #828: Error when code_region is not a number in
 llx_c_regions (with postgres)

---
 ChangeLog             |  3 ++-
 htdocs/admin/dict.php | 26 ++++++++++++++++++--------
 2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 945bf875bfd..e605a1f3cfb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -19,11 +19,12 @@ English Dolibarr ChangeLog
 - Fix: [ bug #806 ] Margins module with orders2invoice does not respect cost price
 - Fix: Orderstoinvoice didn't act as expected when no order was checked
 - Fix: Bad link to all proposals into Third party card if customer is prospect
+- Fix: [ bug #774 ] Bug on creating event with box "all day" crossed
 - Fix: [ bug #789 ] VAT not being calculated in POS
 - Fix: [ bug #794 ] Lost filter on zipcode in prospect list
-- Fix: [ bug #774 ] Bug on creating event with box "all day" crossed
 - Fix: [ bug #810 ] Cannot update ODT template path
 - Fix: [ bug #824 ] MAIN_DB_PREFIX not use into dictionnary
+- Fix: [ bug #828 ] Error when code_region is not a number in llx_c_regions (with postgres)
 
 
 ***** ChangeLog for 3.3.1 compared to 3.3 *****
diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php
index 2e49d0f2859..281ae05a65b 100644
--- a/htdocs/admin/dict.php
+++ b/htdocs/admin/dict.php
@@ -383,7 +383,7 @@ if ($id == 11)
 
 // Define localtax_typeList (used for dictionnary "c_tva")
 $localtax_typeList = array();
-if (GETPOST("id") == 10)
+if ($id == 10)
 {
 	$localtax_typeList = array(
 			"0" => $langs->trans("No"),
@@ -433,7 +433,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify'))
             if ($fieldnamekey == 'position') $fieldnamekey = 'Position';
             if ($fieldnamekey == 'unicode') $fieldnamekey = 'Unicode';
 
-            $msg.=$langs->trans("ErrorFieldRequired",$langs->transnoentities($fieldnamekey)).'<br>';
+            $msg.=$langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)).'<br>';
         }
     }
     // Other checks
@@ -441,14 +441,24 @@ if (GETPOST('actionadd') || GETPOST('actionmodify'))
         $ok=0;
         $msg.="Value 'system' and 'systemauto' for type is reserved. You can use 'user' as value to add your own record.<br>";
     }
-    if (isset($_POST["code"]) && $_POST["code"]=='0') {
-        $ok=0;
-        $msg.="Code can't contains value 0<br>";
+    if (isset($_POST["code"])
+    {
+    	if ($_POST["code"]=='0')
+    	{
+        	$ok=0;
+        	$msg.="Code can't contains value 0<br>";
+        }
+        if (!is_numeric($_POST['code']))
+    	{
+	    	$ok = 0;
+	    	$msg .= $langs->transnoentities('ErrorFieldFormat', $langs->transnoentities('Code')).'<br />';
+	    }
     }
     if (isset($_POST["pays"]) && $_POST["pays"]=='0') {
         $ok=0;
-        $msg.=$langs->trans("ErrorFieldRequired",$langs->trans("Country")).'<br>';
+        $msg.=$langs->transnoentities("ErrorFieldRequired",$langs->transnoentities("Country")).'<br>';
     }
+
 	// Clean some parameters
     if (isset($_POST["localtax1"]) && empty($_POST["localtax1"])) $_POST["localtax1"]='0';	// If empty, we force to 0
     if (isset($_POST["localtax2"]) && empty($_POST["localtax2"])) $_POST["localtax2"]='0';	// If empty, we force to 0
@@ -510,7 +520,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify'))
         else
         {
             if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
-                $msg=$langs->trans("ErrorRecordAlreadyExists").'<br>';
+                $msg=$langs->transnoentities("ErrorRecordAlreadyExists").'<br>';
             }
             else {
                 dol_print_error($db);
@@ -580,7 +590,7 @@ if ($action == 'confirm_delete' && $confirm == 'yes')       // delete
     {
         if ($db->errno() == 'DB_ERROR_CHILD_EXISTS')
         {
-            $msg='<div class="error">'.$langs->trans("ErrorRecordIsUsedByChild").'</div>';
+            $msg='<div class="error">'.$langs->transnoentities("ErrorRecordIsUsedByChild").'</div>';
         }
         else
         {
-- 
GitLab