From 56016a922995370b1ae141d2ccc07ca42a209e96 Mon Sep 17 00:00:00 2001
From: "kevin.dezaphi" <kevin.dezaphi@maarch.org>
Date: Mon, 22 Oct 2018 18:04:44 +0200
Subject: [PATCH] FIX #8698 set correctly postal code and country when town is
 write by autocompletion

---
 .../indexing_searching/ajaxShowCodePostal.php | 23 +++++++++----------
 .../indexing_searching/ajaxShowVille.php      | 23 +++++++++----------
 apps/maarch_entreprise/js/functions.js        |  6 ++---
 3 files changed, 25 insertions(+), 27 deletions(-)

diff --git a/apps/maarch_entreprise/indexing_searching/ajaxShowCodePostal.php b/apps/maarch_entreprise/indexing_searching/ajaxShowCodePostal.php
index 113b82925f8..c60c44661a0 100755
--- a/apps/maarch_entreprise/indexing_searching/ajaxShowCodePostal.php
+++ b/apps/maarch_entreprise/indexing_searching/ajaxShowCodePostal.php
@@ -1,24 +1,23 @@
 <?php
 
-require_once("core".DIRECTORY_SEPARATOR."class".DIRECTORY_SEPARATOR."class_request.php");
+require_once("core" . DIRECTORY_SEPARATOR . "class" . DIRECTORY_SEPARATOR . "class_request.php");
 
 $row = 1;
-$handle = fopen($_SESSION['config']['corepath'] .
-    "apps" . DIRECTORY_SEPARATOR . $_SESSION['config']['app_id']. DIRECTORY_SEPARATOR."tools/referentiel/code_postaux_v201410.csv", "r");
+$handle = fopen($_SESSION['config']['corepath'] . "apps" . DIRECTORY_SEPARATOR . $_SESSION['config']['app_id'] .
+    DIRECTORY_SEPARATOR . "tools/referentiel/code_postaux_v201410.csv", "r");
 
 $request = new request();
 
 echo "<ul>\n";
-while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
+while (($data = fgetcsv($handle, 1000, ";")) !== false) {
     $num = count($data);
-    
-    
-    for ($c=0; $c < $num; $c++) {
-    	$pos = stripos($data[3], $_POST['what']);
-    	if ($pos === 0) {
-    		echo '<li id="'. $data[2].','. $request->show_string(trim($data[3])) .'">'.$data[2].' - '.$request->show_string(trim($data[3])).'</li>';
-   			break;
-		}
+
+    for ($c = 0; $c < $num; $c++) {
+        $pos = stripos($data[3], $_POST['what']);
+        if ($pos === 0) {
+            echo '<li id="' . $data[2] . ',' . $request->show_string(trim($data[3])) . '">' . $data[2] . ' - ' . $request->show_string(trim($data[3])) . '</li>';
+            break;
+        }
     }
     $row++;
 }
diff --git a/apps/maarch_entreprise/indexing_searching/ajaxShowVille.php b/apps/maarch_entreprise/indexing_searching/ajaxShowVille.php
index 19f573ea717..0a4a0a2c619 100755
--- a/apps/maarch_entreprise/indexing_searching/ajaxShowVille.php
+++ b/apps/maarch_entreprise/indexing_searching/ajaxShowVille.php
@@ -1,24 +1,23 @@
 <?php
 
-require_once("core".DIRECTORY_SEPARATOR."class".DIRECTORY_SEPARATOR."class_request.php");
+require_once("core" . DIRECTORY_SEPARATOR . "class" . DIRECTORY_SEPARATOR . "class_request.php");
 
 $row = 1;
-$handle = fopen($_SESSION['config']['corepath'] .
-    "apps" . DIRECTORY_SEPARATOR . $_SESSION['config']['app_id']. DIRECTORY_SEPARATOR."tools/referentiel/code_postaux_v201410.csv", "r");
+$handle = fopen($_SESSION['config']['corepath'] . "apps" . DIRECTORY_SEPARATOR . $_SESSION['config']['app_id'] .
+    DIRECTORY_SEPARATOR . "tools/referentiel/code_postaux_v201410.csv", "r");
 
 $request = new request();
 
 echo "<ul>\n";
-while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
+while (($data = fgetcsv($handle, 1000, ";")) !== false) {
     $num = count($data);
-    
-    
-    for ($c=0; $c < $num; $c++) {
-    	$pos = stripos($data[2], $_POST['what']);
-    	if ($pos === 0) {
-    	    echo '<li id="'. $data[2].','. $request->show_string(trim($data[3])) .'">'.$data[2].' - '.$request->show_string(trim($data[3])).'</li>';
-    	    break;
-		}
+
+    for ($c = 0; $c < $num; $c++) {
+        $pos = stripos($data[2], $_POST['what']);
+        if ($pos === 0) {
+            echo '<li id="' . $data[2] . ',' . $request->show_string(trim($data[3])) . '">' . $data[2] . ' - ' . $request->show_string(trim($data[3])) . '</li>';
+            break;
+        }
     }
     $row++;
 }
diff --git a/apps/maarch_entreprise/js/functions.js b/apps/maarch_entreprise/js/functions.js
index 05ad2d2df83..f870eef6ca5 100755
--- a/apps/maarch_entreprise/js/functions.js
+++ b/apps/maarch_entreprise/js/functions.js
@@ -214,9 +214,9 @@ var initList_hidden_input3 = function (idField, idList, theUrlToListScript, para
             afterUpdateElement: function (text, li) {
                 var str = li.id;
                 var res = str.split(",");
-                $j("#" + new_value).value = res[0];
-                $j("#" + actual_value).value = res[1];
-                $j('#country').value = 'FRANCE';
+                $(new_value).value = res[0];
+                $(actual_value).value = res[1];
+                $('country').value = 'FRANCE';
             }
         });
 };
-- 
GitLab