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

    <div class="row ">


        <div class="col-sm-12 " style="padding: 0">
            <div class="col-sm-12" >

              
                <h3 class="pull-right">&nbsp;

                    <a href="<?php echo base_url() ?>send-message"> <span style="font-size: 18px;padding: 10px"><i class="fa fa-envelope" title=" New Message"></i></span></a>

                    <a href="javascript:;" onclick="DeleteDraft();"> <span style="font-size: 18px;padding: 10px"><i class="fa fa-trash-o" title="Delete "></i></span></a>
                </h3>

            </div>

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


                <div class="col-sm-12 gray_ttc text-left" style="border-bottom: 2px solid #8CC73F;font-weight: bold">
                    <div class="col-sm-4" style="padding:10px 0">
                        <div class="checkbox checkbox-success">
                            <input  id="checkbox1" name="checkbox1"class="styled" type="checkbox" ><label for="checkbox1" > <strong>Sender</strong></label>
                        </div>
                    </div>
                    <div class="col-sm-8" style="padding:23px 0">Type/Subject</div>
                </div>


<?php foreach($draft_message as $val){?>

                <div class="col-sm-12 gray_ttc text-left" >

                    <div class="col-sm-4" style="padding:10px 0">
                        <div class="checkbox checkbox-success">
                              <input class="checkbox2"  name="checkbox2[]" class="styled "  type="checkbox"  value="<?php echo $val->message_id ;?>"><label for="checkbox2" >   
                                <a href="#">
                                    Me (<?php $recieve_id =$val->receiver_id; 
                                        $recieve_id_array=explode(",", $recieve_id);
                                        echo $count=  count($recieve_id_array);
                                
                                
                                ?>)
                                </a></label>
                        </div>
                    </div>
                   
                    <div class="col-sm-8" style="padding:23px 0">
                        <p class="text-left col-sm-12">
                            <?php 
                            $mess= $val->message_body; 
                                                        
                               //$words = preg_split('/\s+/', $mess);

                              // $words = array_slice($words, 0, 10);
                               echo substr($mess, 0,40)."...";
                              //$words = str_word_count($mess, 1);
                               //$first50Words = array_slice($words, 0, 50);
                              // $first_20_word=implode(" ", $words);
                             // echo $first_20_word;                                //print_r($words) ;
                           
                            ?>
                             <?php 
                                  foreach($draft_message_attachment[$val->message_id] as $value)
                                  {
                                      $exist_attach=$value->message_sender_attachment;
                                  
                                      if($exist_attach){
                                      
                                     
                                  
                            ?>
                            <i class="fa fa-paperclip" style="color: #80c12c;"></i>
                                  <?php } 
                                       break;
                                      } ?>
                            <a href="<?php echo base_url() ?>view-draft/<?php $message_id= $this->encrypt->encode($val->message_id);echo str_replace("/","%F2", $message_id); ?>">
                                View
                            </a>
                        </p>


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


                


<!--                <nav class="course-pagination">
                    <ul class="pagination">
                        <li>
                            <a href="#" aria-label="Previous">
                                <span aria-hidden="true" title="First Page">&laquo;&laquo;</span>
                            </a>
                        </li>
                        <li>
                            <a href="#" aria-label="Previous">
                                <span aria-hidden="true" title="Previous Page">&laquo;</span>
                            </a>
                        </li>
                        <li><a href="#">1</a></li>
                        <li><a href="#">2</a></li>
                        <li><a href="#">3</a></li>
                        <li><a href="#">4</a></li>
                        <li><a href="#">5</a></li>
                        <li>
                            <a href="#" aria-label="Next">
                                <span aria-hidden="true" title="Next Page">&raquo;</span>
                            </a>
                        </li>
                        <li>
                            <a href="#" aria-label="Next">
                                <span aria-hidden="true" title="Last Page">&raquo;&raquo;</span>
                            </a>
                        </li>
                    </ul>
                </nav>-->

            </div>


        </div><!-- /.row gray -->


    </div>

</div>
<script>
    $(document).ready(function() {
    $('#checkbox1').click(function(event) {  //on click
        if(this.checked) { // check select status
            $('.checkbox2').each(function() { //loop through each checkbox
                this.checked = true;  //select all checkboxes with class "checkbox1"              
            });
        }else{
            $('.checkbox2').each(function() { //loop through each checkbox
                this.checked = false; //deselect all checkboxes with class "checkbox1"                      
            });        
        }
    });
   
});
function DeleteDraft(){
    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-draft-selected-msg';
       
       
    var vals = [];
$(document).ready(function(){
$('input:checkbox[name="checkbox2[]"]').each(function() {
    if (this.checked) {
        vals.push(this.value);
    }
});

 
});

 var message_id=vals;
 //alert( message_id);
        var formdata = new FormData();
        formdata.append("message_id",message_id);
      
        
        xmlhttp5.addEventListener("load", function () {
         //alert(xmlhttp5.responseText);
       
             location.href = '<?php echo base_url();?>'+'draft-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>