
<div class="col-sm-8">

    <div class="row gray_ttc">
        <br>

        <div class="col-sm-5 col-sm-offset-1 text-left" style="padding: 10px">
            <strong>Message</strong>
        </div>
 <?php foreach($preview_message as $val) { ?>
        <div class="col-sm-5  text-right" >
            <a href="<?php echo base_url() ?>reply-received-message/<?php $message_id= $this->encrypt->encode($val->message_id);echo str_replace("/","%F2", $message_id); ?>"> <i class="fa fa-reply" title="Reply"> </i></a>&nbsp;&nbsp;
          
            <a href="javascript:;" onclick="dustbin(<?php echo $val->message_id?>);" > <i class="fa fa-trash-o" title="Remove"></i></a>&nbsp;&nbsp;
           <?php } ?>
                <?php foreach($preview_message as $val) { 
      
               
             $message_view=$val->message_viewer_id;
             $message_view_array=  explode(",",$message_view);
            // print_r($message_view_array);
               ?>
            <a href="#"><i class="fa fa-envelope" title="<?php
            
             if ($message_view==''){
                echo 'No';
            }
 else {
                echo count($message_view_array);
       }
            ?>&nbsp;peron read this"> </i><sup class="badge"><?php 
            
            if ($message_view==''){
                echo '0';
            }
 else {
                echo count($message_view_array);
       }
            
                ;?></sup></a>&nbsp;&nbsp;
           <?php } ?>
           
        </div>

        <div class="col-sm-10 col-sm-offset-1 ">
            <hr><br>
        </div>
               <?php if($preview_reply_message) {
                   foreach ($sent_reply as $val){
          for($i=0;$i<count($val);$i++){
                   //foreach ($preview_message as $val) { ?>

            <div class="col-sm-10 col-sm-offset-1 text-left" style="padding: 0">
                <div class="col-sm-12 " style="padding: 0">

                    <div class="col-sm-2">Form</div>
                    <div class="col-sm-1">:</div>
                    <?php foreach ($message_sender_info [$val[$i]->message_id] as $sender) { ?>
                        <div class="col-sm-9"><?php echo $sender->person_first_name . "&nbsp;" . $sender->person_last_name ?></div>
                    <?php } ?>

                </div>
                <div class="col-sm-12 " style="padding: 0">
                    <div class="col-sm-2">Date</div>
                    <div class="col-sm-1">:</div>
                    <div class="col-sm-9"><?php
                        echo date('h:i a', strtotime($val[$i]->message_datetime)) . "," . "&nbsp;";
                        echo date('d F y', strtotime($val[$i]->message_datetime)) . ".";
                        ?></div>

                </div>
                <div class="col-sm-12 " style="padding: 0">
                    <div class="col-sm-2">To</div>
                    <div class="col-sm-1">:</div>

                 <div class="col-sm-9">
                        

                        <span id="fewContent2<?php echo $val[$i]->message_id;?>">
                          <?php  foreach ($message_receiver_single_info [$val[$i]->message_id]  as $single_receiver){
                              
                           
                             echo $single_receiver->person_email;
                        }
                        ?>
                        
                        </span>
                     <span id="moreContent2<?php echo $val[$i]->message_id;?>" style="display: none">
                          <?php  foreach ($message_receiver_info [$val[$i]->message_id]  as $receiver)
                          {
                           
                          echo $receiver->person_email."<br>";
                          
                          }
                        
                        ?>
                     </span>
                     <?php 
                     $receiver_id_view=$val[$i]->receiver_id;
                     $receiver_id_view_array=  explode(",",  $receiver_id_view);
                     if(count($receiver_id_view_array)>1)
                     {
                     
                     
                     ?>
                        <a id="more2<?php echo $val[$i]->message_id?>" class="text-right" href="#" onclick="ViewMoreContent2(<?php echo $val[$i]->message_id;?>)">More..</a>
                        <a id="less2<?php echo $val[$i]->message_id?>" style="display: none" class="text-right" href="#" onclick="LessMoreContent2('<?php echo $val[$i]->message_id;?>')">Less..</a>
                     <?php } ?>   
                 </div>
                </div>

            </div>
          
            <div class="col-sm-10 col-sm-offset-1 ">
                <hr> <br>
            </div>
            <div class="form-group  col-sm-10 col-sm-offset-1 ">
                <div class="input-group">

                    <div class="message_show text-justify "><?php echo $val[$i]->message_body;?></div> 

                   
                        
                        
                        
                        
                        
                        
                        
                        <?php  foreach($preview_message_attachment[$val[$i]->message_id] as $attach)
                      {
              $message_encrypt_id= $this->encrypt->encode($val[$i]->message_id.'talha');
               
              $message_attach_encrypt_id=$this->encrypt->encode($attach->message_attachmen_id.'talha');
                    
                            ?>
                    <p class="text-justify">
                        
                 
                        <a href="javascript:;" onclick="DownloadSend('<?php echo str_replace("/","%F2", $message_encrypt_id); ?>' , '<?php echo str_replace("/","%F2", $message_attach_encrypt_id);?>');return false;" >
                         <i class="fa fa-download"></i>
                           
                            <?php  
          
              echo $attach->message_attachment_original_name;
              
            }
            ?>
                        </a>
                
                    </p>

                </div>
            </div>
                   <?php } ?>
                 
                   <?php   }} else {?>
            
 
     
        <?php  foreach ($preview_message as $val) { ?>

            <div class="col-sm-10 col-sm-offset-1 text-left" style="padding: 0">
                <div class="col-sm-12 " style="padding: 0">

                    <div class="col-sm-2">Form</div>
                    <div class="col-sm-1">:</div>
                    <?php foreach ($message_sender_info as $sender) { ?>
                        <div class="col-sm-9"><?php echo $sender->person_first_name . "&nbsp;" . $sender->person_last_name ?></div>
                    <?php } ?>

                </div>
                <div class="col-sm-12 " style="padding: 0">
                    <div class="col-sm-2">Date</div>
                    <div class="col-sm-1">:</div>
                    <div class="col-sm-9"><?php
                        echo date('h:i a', strtotime($val->message_datetime)) . "," . "&nbsp;";
                        echo date('d F y', strtotime($val->message_datetime)) . ".";
                        ?></div>

                </div>
                <div class="col-sm-12 " style="padding: 0">
                    <div class="col-sm-2">To</div>
                    <div class="col-sm-1">:</div>

                 <div class="col-sm-9">
                        

                        <span id="fewContent">
                          <?php  foreach ($message_receiver_single_info as $single_receiver){
                              
                           
                             echo $single_receiver->person_email;
                        }
                        ?>
                        
                        </span>
                     <span id="moreContent" style="display: none">
                          <?php  foreach ($message_receiver_info as $receiver)
                          {
                           
                          echo $receiver->person_email."<br>";
                          
                          }
                        
                        ?>
                     </span>
                     <?php 
                     $receiver_id_view=$val->receiver_id;
                     $receiver_id_view_array=  explode(",",  $receiver_id_view);
                     if(count($receiver_id_view_array)>1)
                     {
                     
                     
                     ?>
                        <a id="more" class="text-right" href="#" onclick="ViewMoreContent()">More..</a>
                        <a id="less" style="display: none" class="text-right" href="#" onclick="LessMoreContent()">Less..</a>
                     <?php } ?>   
                 </div>
                </div>

            </div>
           
            <div class="col-sm-10 col-sm-offset-1 ">
                <hr> <br>
            </div>
            <div class="form-group  col-sm-10 col-sm-offset-1 ">
                <div class="input-group">

                    <div class="message_show text-justify "><?php echo $val->message_body;?></div> 

                   
                        
                        
                        
                        
                        
                        
                        
                        <?php  foreach($preview_message_attachment[$val->message_id] as $attach)
                      {
              $message_encrypt_id= $this->encrypt->encode($val->message_id.'talha');
               
              $message_attach_encrypt_id=$this->encrypt->encode($attach->message_attachmen_id.'talha');
                    
                            ?>
                    <p class="text-justify">
                        
                 
                        <a href="javascript:;" onclick="DownloadSend('<?php echo str_replace("/","%F2", $message_encrypt_id); ?>' , '<?php echo str_replace("/","%F2", $message_attach_encrypt_id);?>');return false;" >
                         <i class="fa fa-download"></i>
                           
                            <?php  
          
                           echo $attach->message_attachment_original_name;
              
                              }
                             ?>
                        </a>
                
                    </p>

                </div>
            </div>
        <?php }?>
     
                <?php }?>
        <div class="col-sm-12"><br><br></div>
    </div>

</div>
         <script>
                function ViewMoreContent(){
                  
                    var less = document.getElementById('less');
                    var more = document.getElementById('more');
                    var fewContent = document.getElementById('fewContent');
                    var moreContent = document.getElementById('moreContent');
                    moreContent.setAttribute('style','display:block');
                    fewContent.setAttribute('style','display:none');
                    more.setAttribute('style','display:none');
                    less.setAttribute('style','display:inline');
                    
                }
                   function LessMoreContent(){
                    
                    var less = document.getElementById('less');
                    var more = document.getElementById('more');
                    var moreContent = document.getElementById('moreContent');
                    var fewContent = document.getElementById('fewContent');
                    moreContent.setAttribute('style','display:none');
                    fewContent.setAttribute('style','display:block');
                    more.setAttribute('style','display:inline');
                    less.setAttribute('style','display:none');
                    
                }
                 function ViewMoreContent2(message_id){
                  
                    var less2 = document.getElementById('less2'+message_id);
                    var more2 = document.getElementById('more2'+message_id);
                    var fewContent2 = document.getElementById('fewContent2'+message_id);
                    var moreContent2 = document.getElementById('moreContent2'+message_id);
                    moreContent2.setAttribute('style','display:block');
                    fewContent2.setAttribute('style','display:none');
                    more2.setAttribute('style','display:none');
                    less2.setAttribute('style','display:inline');
                    
                }
                   function LessMoreContent2(message_id){
                    
                    var less2 = document.getElementsByClassName('less2'+message_id);
                    var more2= document.getElementsByClassName('more2'+message_id);
                    var moreContent2 = document.getElementsByClassName('moreContent2'+message_id);
                    var fewContent2 = document.getElementsByClassName('fewContent2'+message_id);
                    moreContent2.setAttribute('style','display:none');
                    fewContent2.setAttribute('style','display:block');
                    more2.setAttribute('style','display:inline');
                    less2.setAttribute('style','display:none');
                    
                }
              
            </script>
<script>
function DownloadSend( messageId , messageAttachid )
{
    var xmlhttp = false;
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (E) {
                xmlhttp = false;
            }
        }
        if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
            xmlhttp = new XMLHttpRequest();
        }
        var url= '<?php echo base_url();?>'+'send-download-authenticate';
        var message_id=messageId;
     //   alert(message_id);
        
        var formdata = new FormData();
        formdata.append("message_id",message_id);
        formdata.append("message_attachmen_id",messageAttachid);
        
        xmlhttp.addEventListener("load", function () {
           // alert(xmlhttp.responseText);
            var downloadUrl= '<?php echo base_url();?>'+'action-download-send/'+message_id+'/'+messageAttachid; 
           
          if( xmlhttp.responseText == 'allow'){
               window.location.replace(downloadUrl);
           }
           else if(xmlhttp.responseText == 'f'){
               alert("Your file is not found or Empty file.");
           }
           else
           {
               alert("Download is canceled");
           }
              
            }, false);
            xmlhttp.addEventListener("error", function () {
                alert("not sent");
            }, false);
            xmlhttp.addEventListener("abort", function () {
                alert("Aborted");
            }, false);

            xmlhttp.open("POST", url);
            xmlhttp.send(formdata);

        
    return true;
}
function dustbin(m_id){


swal({
                title: "", text: "Do you really want to delete the entire conversation??",
                showCancelButton: true,
                confirmButtonColor: '#DD6B55',
                confirmButtonText: 'Yes!',
                cancelButtonText: "No", closeOnConfirm: true,
                closeOnCancel: true
            },
            function (isConfirm) {
                if (isConfirm) {
                 
                 var xmlhttp5 = false;
        try {
            xmlhttp5 = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlhttp5 = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (E) {
                xmlhttp5 = false;
            }
        }
        if (!xmlhttp5 && typeof XMLHttpRequest != 'undefined') {
            xmlhttp5 = new XMLHttpRequest();
        }
        var url= '<?php echo base_url();?>'+'remove-send-msg';
        var message_id=m_id;
     // alert(message_id);
        
        var formdata = new FormData();
        formdata.append("message_id",message_id);
       // formdata.append("message_attachmen_id",messageAttachid);
        
        xmlhttp5.addEventListener("load", function () {
          // alert(xmlhttp5.responseText);
           if(xmlhttp5.responseText==='redirect'){
               location.href = "sent-message";
           }
            
              
            }, false);
            xmlhttp5.addEventListener("error", function () {
                alert("not sent");
            }, false);
            xmlhttp5.addEventListener("abort", function () {
                alert("Aborted");
            }, false);

            xmlhttp5.open("POST", url);
            xmlhttp5.send(formdata);

        
                }
            });

}
</script>