From 528d93bc1880bf467287bb3d4fc9b387f48d7252 Mon Sep 17 00:00:00 2001
From: "florian.azizian" <florian.azizian@maarch.org>
Date: Wed, 8 Nov 2017 23:45:16 +0100
Subject: [PATCH] FEAT #6118 attachment preview was display in attachment tab
 and document tab

---
 .../indexing_searching/view_resource_controler.php | 14 ++++++++++++++
 modules/attachments/attachments_content.php        |  2 +-
 modules/attachments/view_attachment.php            |  2 +-
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/apps/maarch_entreprise/indexing_searching/view_resource_controler.php b/apps/maarch_entreprise/indexing_searching/view_resource_controler.php
index 153870105b1..7a9686041a7 100755
--- a/apps/maarch_entreprise/indexing_searching/view_resource_controler.php
+++ b/apps/maarch_entreprise/indexing_searching/view_resource_controler.php
@@ -117,6 +117,19 @@ if ($s_id == '') {
         $res_outgoing = $stmt->fetchObject(); 
 
         if ($res_outgoing->category_id == 'outgoing' && $res_outgoing->source == 'with_empty_file') {
+            if(!empty($_REQUEST['editingMode'])){
+                $stmt = $db->query("SELECT res_id FROM res_view_attachments WHERE status <> 'DEL' and status <> 'OBS' "
+                    . "and res_id_master = ? and coll_id = ? "
+                    . "and attachment_type = 'outgoing_mail' order by res_id desc", 
+                    array($s_id, $_SESSION['collection_id_choice']));
+                $res_att = $stmt->fetchObject();
+                if ($stmt->rowCount() > 0) { ?>
+                    <script type="text/javascript">
+                    window.location.href = 'index.php?display=true&editingMode=true&module=attachments&page=view_attachment&res_id_master=<?php echo $s_id;?>&id=<?php echo $res_att->res_id;?>'
+                    </script>
+                    <?php exit();
+                }
+            } else {
             $stmt = $db->query("SELECT res_id FROM res_view_attachments WHERE status <> 'DEL' and status <> 'OBS' "
                 . "and res_id_master = ? and coll_id = ? and ((attachment_type = 'converted_pdf' and type_id = 1) "
                 . "OR (attachment_type = 'outgoing_mail' and format = 'pdf')"
@@ -151,6 +164,7 @@ if ($s_id == '') {
 	            exit();
 	        }
             }
+            }
         }
     }
 
diff --git a/modules/attachments/attachments_content.php b/modules/attachments/attachments_content.php
index 6d4c9395c5a..a77a597d59c 100755
--- a/modules/attachments/attachments_content.php
+++ b/modules/attachments/attachments_content.php
@@ -2075,7 +2075,7 @@ if(empty($_REQUEST['id'])){
 $content .= '<iframe src="'.$srcAttachment.'" name="viewframevalid_attachment" id="viewframevalid_attachment" scrolling="auto" frameborder="0" style="width:100% !important;height:90vh;display:none" onmouseover="this.focus()"></iframe>';
 
 // DOCUMENT PRINCIPAL //
-$content .= '<iframe src="index.php?display=true&dir=indexing_searching&page=view_resource_controler&id='. functions::xssafe($_SESSION['doc_id']).'" name="viewframevalid_main" id="viewframevalid_main" scrolling="auto" frameborder="0" style="width:100% !important;height:90vh;display:none" onmouseover="this.focus()"></iframe>';
+$content .= '<iframe src="index.php?display=true&editingMode=true&dir=indexing_searching&page=view_resource_controler&id='. functions::xssafe($_SESSION['doc_id']).'" name="viewframevalid_main" id="viewframevalid_main" scrolling="auto" frameborder="0" style="width:100% !important;height:90vh;display:none" onmouseover="this.focus()"></iframe>';
     
 $content .= '</div>';
 
diff --git a/modules/attachments/view_attachment.php b/modules/attachments/view_attachment.php
index a05c039a8c7..b66f9e06baf 100755
--- a/modules/attachments/view_attachment.php
+++ b/modules/attachments/view_attachment.php
@@ -130,7 +130,7 @@ if (! empty($_SESSION['error'])) {
                 $stmtPdf = $db->query(
                     "SELECT docserver_id, path, filename, format, title
                      FROM res_view_attachments
-                     WHERE filename=? AND status = 'TRA'", array(substr($line->filename, 0, strrpos($line->filename, ".")).'.pdf')
+                     WHERE filename=? AND (status = 'TRA' or status = 'A_TRA')", array(substr($line->filename, 0, strrpos($line->filename, ".")).'.pdf')
                 );
                 $linePdf = $stmtPdf->fetchObject();
                 if(!empty($linePdf)){
-- 
GitLab