From abd06924d524899c49029504ec3c42a832d31f7c Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex.orluc@maarch.org>
Date: Mon, 29 Oct 2018 19:30:52 +0100
Subject: [PATCH] fix links in validate_mail (contact check)

---
 apps/maarch_entreprise/js/indexing.js |  6 +++++-
 modules/attachments/show_res_id.php   | 27 ++++++++++++++++++++-------
 2 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/apps/maarch_entreprise/js/indexing.js b/apps/maarch_entreprise/js/indexing.js
index 294d06eaaa9..73b909dcefc 100755
--- a/apps/maarch_entreprise/js/indexing.js
+++ b/apps/maarch_entreprise/js/indexing.js
@@ -1598,6 +1598,7 @@ function check_date_exp(path_manage_script, path_link){
         var res_id = $('values').value;
         var e = $("category_id");
         var category = e.options[e.selectedIndex].value;
+        var scriptAddons = '';
         new Ajax.Request(path_manage_script,
         {
             method:'post',
@@ -1613,9 +1614,12 @@ function check_date_exp(path_manage_script, path_link){
                     document.getElementById('contact_check').style.display='none';
                     document.getElementById('contactcheck').value = answer.responseText;
                 } else {
+                    if (document.getElementById('to_link') != null) {
+                        scriptAddons = "document.getElementById('to_link').click();";
+                    }
                     document.getElementById('contact_check').style.display='table-row';
                     document.getElementById("contact_check").innerHTML = "<td colspan=\"3\" style=\"font-size: 9px;text-align: center;color:#ea0000;\">Au moins un courrier enregistré dans les "+check_days_before+" derniers jours est affecté au même contact. "+
-                                                                            "<input type='button' class='button' value='Voir' onclick=\"window.open('"+path_link+"',"+
+                                                                            "<input type='button' class='button' value='Voir' onclick=\""+scriptAddons+"window.open('"+path_link+"',"+
                                                                             " 'search_doc_for_attachment', 'scrollbars=yes,menubar=no,toolbar=no,resizable=yes,status=no,width=1100,height=775');\"/></td>";
                     document.getElementById('contactcheck').value = answer.responseText;
                 }
diff --git a/modules/attachments/show_res_id.php b/modules/attachments/show_res_id.php
index 65ed186699d..e3ca3a7e44f 100755
--- a/modules/attachments/show_res_id.php
+++ b/modules/attachments/show_res_id.php
@@ -1,10 +1,10 @@
 <?php
+/**
+* Copyright Maarch since 2008 under licence GPLv3.
+* See LICENCE.txt file at the root folder for more details.
+* This file is part of Maarch software.
 
-/*
-*   Copyright 2015 Maarch
-*
-*   This file is part of Maarch Framework.
-*
+* @brief   show_res_id
 * @author  dev <dev@maarch.org>
 * @ingroup attachments
 */
@@ -31,8 +31,20 @@ if (_ID_TO_DISPLAY == 'chrono_number') {
     }
 } ?>
 
-//VALIDATE_MAIL
-if (input_res) {
+//VALIDATE_MAIL (contact_check)
+if (window.opener.document.getElementById('to_link') != null) {
+    console.log(window.opener.document.getElementById('to_link'));
+    console.log(window.opener.document.getElementById('iframe_tab').contentWindow.document.getElementById('attach_link'));
+    window.opener.document.getElementById('iframe_tab').contentWindow.document.getElementById('res_id_link').value=<?php echo json_encode($_SESSION['stockCheckbox']); ?>;
+    <?php 
+    if (_ID_TO_DISPLAY == 'chrono_number') {
+        ?>
+        window.opener.document.getElementById('iframe_tab').contentWindow.document.getElementById('input_chrono_id').value==<?php echo json_encode($arrayChrono); ?>;       
+    <?php
+    } ?>
+    window.opener.document.getElementById('iframe_tab').contentWindow.document.getElementById('attach_link').click();
+} else if (input_res) {
+    //VALIDATE_MAIL
 	input_res.value=<?php echo json_encode($_SESSION['stockCheckbox']); ?>;
         <?php 
         if (_ID_TO_DISPLAY == 'chrono_number') {
@@ -51,6 +63,7 @@ if (input_res) {
     <?php
 
     } ?>
+    window.opener.$('attach').click();
 }
 
 self.close();
-- 
GitLab