From e7cb5e7d6ca7a4e50916074fe4fa1a54c1bad1ab Mon Sep 17 00:00:00 2001
From: "florian.azizian" <florian.azizian@maarch.org>
Date: Thu, 18 Oct 2018 13:24:47 +0100
Subject: [PATCH] FIX #7995 edit contact in detail/process page

---
 .../class/class_contacts_v2_Abstract.php      |  6 ++-
 .../definition_mail_categories.php            |  2 +-
 apps/maarch_entreprise/lang/en.php            |  4 +-
 apps/maarch_entreprise/lang/fr.php            |  2 +-
 .../my_contacts/info_contact_iframe.php       | 54 ++++++++++++++-----
 5 files changed, 50 insertions(+), 18 deletions(-)

diff --git a/apps/maarch_entreprise/class/class_contacts_v2_Abstract.php b/apps/maarch_entreprise/class/class_contacts_v2_Abstract.php
index 0c5cf40ea08..3527be864c5 100755
--- a/apps/maarch_entreprise/class/class_contacts_v2_Abstract.php
+++ b/apps/maarch_entreprise/class/class_contacts_v2_Abstract.php
@@ -1999,9 +1999,11 @@ abstract class contacts_v2_Abstract extends Database
                 $cancel_target = $_SESSION['config']['businessappurl'].'index.php?page=my_contact_up&amp;dir=my_contacts&amp;load';
             }
             if ($iframe == 'iframe') {
-                $cancel_target = $_SESSION['config']['businessappurl'].'index.php?display=false&page=create_contact_iframe&dir=my_contacts';
+                $cancel_target = 'index.php?display=false&page=create_contact_iframe&dir=my_contacts';
             } elseif ($iframe == 'fromContactIframe') {
-                $cancel_target = $_SESSION['config']['businessappurl'].'index.php?display=false&dir=my_contacts&page=info_contact_iframe&seeAllAddresses&contactid='.$_SESSION['contact']['current_contact_id'].'&addressid='.$_SESSION['contact']['current_address_id'];
+                $cancel_target = 'index.php?display=false&dir=my_contacts&page=info_contact_iframe&seeAllAddresses&contactid='.$_SESSION['contact']['current_contact_id'].'&addressid='.$_SESSION['contact']['current_address_id'];
+            } elseif ($iframe == 'editDetail') {
+                $cancel_target = 'index.php?display=false&dir=my_contacts&page=info_contact_iframe&created=cancelDetail';
             }
             if (isset($_SESSION['contact_address']['fromContactAddressesList']) && $_SESSION['contact_address']['fromContactAddressesList'] != '') {
                 $cancel_target = $_SESSION['config']['businessappurl'].'index.php?page=contact_addresses_list';
diff --git a/apps/maarch_entreprise/definition_mail_categories.php b/apps/maarch_entreprise/definition_mail_categories.php
index 7fd990f7d76..81ab6a49788 100644
--- a/apps/maarch_entreprise/definition_mail_categories.php
+++ b/apps/maarch_entreprise/definition_mail_categories.php
@@ -1206,7 +1206,7 @@ function get_general_data($coll_id, $res_id, $mode, $params = array())
                             $data[$arr[$i]]['show_value'] .= ', '.$res->address_num.' '.$res->address_street.' '.$res->address_postal_code.' '.strtoupper($res->address_town);
                         }
                     }
-                    $pathScriptTab = $_SESSION['config']['businessappurl'].'index.php?display=true&dir=my_contacts&page=info_contact_iframe&mode=view&popup&contactid='.$line->{$arr[$i]}.'&addressid='.$addressId;
+                    $pathScriptTab = 'index.php?display=true&dir=my_contacts&page=info_contact_iframe&mode=editDetail&editDetail&popup&contactid='.$line->{$arr[$i]}.'&addressid='.$addressId;
 
                     $preAddon = '<a href="#" id="contact_card" title="'._CONTACT_CARD.'" onclick="';
                     $postAddon = ' ><i class="fa fa-book fa-2x" title="'._CONTACT_CARD.'"></i></a>';
diff --git a/apps/maarch_entreprise/lang/en.php b/apps/maarch_entreprise/lang/en.php
index 508a1f19de4..4b93a626e0f 100755
--- a/apps/maarch_entreprise/lang/en.php
+++ b/apps/maarch_entreprise/lang/en.php
@@ -2389,7 +2389,7 @@ if (!defined('_CONTACT_REAFFECT')) {
     define('_CONTACT_REAFFECT', 'Reallocation of documents and mails');
 }
 if (!defined('_UPDATE_CONTACTS')) {
-    define('_UPDATE_CONTACTS', 'Contact update from indexation/ title');
+    define('_UPDATE_CONTACTS', 'Update contactsc');
 }
 if (!defined('_CONTACT_TYPE')) {
     define('_CONTACT_TYPE', 'Contact type');
@@ -5027,4 +5027,4 @@ if (!defined('_PROCESS_IN_PROGRESS')) {
 }
 if (!defined('_CONTACTS_FILLING')) {
     define('_CONTACTS_FILLING', "Filling contacts informations");
-}
\ No newline at end of file
+}
diff --git a/apps/maarch_entreprise/lang/fr.php b/apps/maarch_entreprise/lang/fr.php
index 2985621883f..d2e3c68e20e 100755
--- a/apps/maarch_entreprise/lang/fr.php
+++ b/apps/maarch_entreprise/lang/fr.php
@@ -2420,7 +2420,7 @@ if (!defined('_CONTACT_REAFFECT')) {
     define('_CONTACT_REAFFECT', 'Réaffectation des documents et des courriers');
 }
 if (!defined('_UPDATE_CONTACTS')) {
-    define('_UPDATE_CONTACTS', 'Mise à jour contact depuis indexation/qualification');
+    define('_UPDATE_CONTACTS', 'Mise à jour des contacts');
 }
 if (!defined('_CONTACT_TYPE')) {
     define('_CONTACT_TYPE', 'Type de contact');
diff --git a/apps/maarch_entreprise/my_contacts/info_contact_iframe.php b/apps/maarch_entreprise/my_contacts/info_contact_iframe.php
index aa38923e381..4df2522439c 100755
--- a/apps/maarch_entreprise/my_contacts/info_contact_iframe.php
+++ b/apps/maarch_entreprise/my_contacts/info_contact_iframe.php
@@ -154,9 +154,10 @@ if ($core_tools2->test_admin('update_contacts', 'apps', false) && $mode <> "view
 <?php
 }
 
-if ($_GET['created'] == "editDetail") {
-    ?>
-    <script type="text/javascript">
+?>
+    <script type="text/javascript"><?php
+    if ($_GET['created'] == "editDetail") {
+        ?>
         new Ajax.Request('index.php?display=false&dir=my_contacts&page=get_last_contact_address&mode=up',
         {
         method:'post',
@@ -164,19 +165,48 @@ if ($_GET['created'] == "editDetail") {
         onSuccess: function(answer){
             eval("response = "+answer.responseText);
 
-            if (response.rateColor != "") {
-                window.opener.$j('#contact').css('background-color', response.rateColor);
+            //Page Detail
+            if(window.opener){
+                if (response.rateColor != "") {
+                    window.opener.$j('#contact').css('background-color', response.rateColor);
+                }
+                window.opener.$j('#contact').html(response.contactName);
+                window.opener.$j('#contactid').val(response.contactId);
+                window.opener.$j('#addressid').val(response.addressId);
+                this.close();
+            //Processing Mail
+            } else {
+                if(parent.$j('#exp_contact_id')){
+                    if (response.rateColor != "") {
+                        parent.$j('#exp_contact_id').css('background-color', response.rateColor);
+                    }
+                    parent.$j('#exp_contact_id').html(response.contactName);
+                }
+
+                if(parent.$j('#dest_contact_id')){
+                    if (response.rateColor != "") {
+                        parent.$j('#dest_contact_id').css('background-color', response.rateColor);
+                    }
+                    parent.$j('#dest_contact_id').html(response.contactName);
+                }
+
+                parent.document.getElementById('show_tab').style.display = 'none';
+                parent.document.getElementById('show_tab').setAttribute('module', '');
             }
-
-            window.opener.$j('#contact').html(response.contactName);
-            window.opener.$j('#contactid').val(response.contactId);
-            window.opener.$j('#addressid').val(response.addressId);
-            this.close();
         }       
-    });
+    });<?php
+    } elseif ($_GET['created'] == "cancelDetail") {
+        ?>
+        if (window.opener) {
+            this.close();
+        } else {
+            parent.document.getElementById('show_tab').style.display = 'none';
+            parent.document.getElementById('show_tab').setAttribute('module', '');
+        }
+   <?php
+    } ?>
     </script><?php
     exit;
-}
 
 ?>
 	<script type="text/javascript">
-- 
GitLab