<?php
include"initialize_page.php";
     if(isset($_REQUEST['id'])&&$_REQUEST['id']!="")
	   {
		   $id=$_REQUEST['id'];
		   
?>
<!DOCTYPE html>
<html lang="en">

<head>
  
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

	<title>Chat</title>

	<!-- Bootstrap core CSS -->
	<link rel="stylesheet" href="assets/css/bootstrap/bootstrap.css" /> 

	<!-- datatables Styling  -->
    <link rel="stylesheet" href="assets/css/plugins/datatables/jquery.dataTables.css" />
    
    <!-- Fonts  -->
    <link href='http://fonts.googleapis.com/css?family=Raleway:400,500,600,700,300' rel='stylesheet' type='text/css'>
    
    <!-- Base Styling  -->
    <link rel="stylesheet" href="assets/css/app/app.v1.css" />

	<script type="text/javascript" src="jquery-1.11.1.min.js"></script>
		
	
   <script type="text/javascript">
   
     $(document).ready(function() {
        
		$("#acctioninaccounts").click(
		
		function()
		 {
			  var getmsg=$("#sendmemdgid").val(); 
			  var msgtrim=getmsg.trim();
			  
			     if(msgtrim=="")
				  {
					  alert("Please Write Something...");
					  return false;
				  }
				  else
				  {
					   $.post("controller.php", { q:"send_msgtouser", id:"<?php echo $id;  ?>", msgtrim:msgtrim  }, function(data)
					    {
							 if(data=="empty")
							  {
							alert("Please Write Something...");	  
							  }
							  if(data=="done")
							  {
								alert("Sent Successfully..");
								window.location.href='view_chat?id=<?php echo $id;  ?>&ss=4389681590d73b887f52da9760239a90';  
							  }
						}
					   );
				  }
		 }
		);
    });
   
   
   </script>
   
   
</head>
<body>

 
	
<div class="modal fade" id="modal-form" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
            <h4 class="modal-title" id="myModalLabel">Send Message</h4>
          </div>
          <div class="modal-body">
            
            	 <div class="form-group">
                    <label for="exampleInputEmail1">Message</label>
                  <textarea name="sendmemdgid" class="form-control" id="sendmemdgid"></textarea>
                    
                  </div>
              
            
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            <input type="submit" class="btn btn-primary" value="Send" name="sub" id="acctioninaccounts"> 
          </div>
        </div>
      </div>
    </div>
    

    
    
    
	<?php    include"xleftmenu.php"; ?>
    
    <section class="content">
    	
         <?php  include"xheader.php";  ?>
        <!-- Header Ends -->
        
        
        <div class="warper container-fluid">
        	
            <div class="page-header"><h1>Chat <?php //echo time();  ?></h1></div>
            
       
            
                <div class="panel panel-default">
                  
                       <div align="right">
                    <button type="button" class="btn btn-success btn-circle btn-flat" data-toggle="modal" data-target="#modal-form" >Send Message</button>
                    
                    </div>
                   
                    <div class="row">
                    <div class="col-md-12">
                    <div class="panel-body">
                   
<table class="table table-striped table-bordered" id="basic-datatable" width="100%">
        <thead>
            <tr>
                <th>Sr</th>
                <th>By</th>
               
               
                 <th>Message</th>
              
                 <th>Date</th>
            </tr>
        </thead>
        <tbody>
                            
                             <?php
						  $sr=1;
						 
						  
						      $data_q=mysqli_query($con,"SELECT *
							                       FROM x_chat
												   WHERE x_userid='$id'
												   ORDER by x_id DESC");  
							  
							
							   
			while($data_array=mysqli_fetch_array($data_q))
			{
				 
				  $get_name=user_bankuser($id,"x_fname")." ".user_bankuser($id,"x_lname");
				  
				  //get unread msg of this user
				  
				  $master_id=$data_array['x_id'];
			?>
                <tr class="odd gradeX">
              
                
                
             
                 
                
                    
                      
                      
                  <td><?php echo $sr;  ?></td>
               <td><?php   if($data_array['x_by']=="admin")
			               {
							echo "You";   
						   }
						   else
						   {
							   mysqli_query($con,"UPDATE x_chat SET x_readstatus='R' WHERE x_id='$master_id'");
							   
							   echo $get_name;
						   }
			     ?></td>
                  <td><?php echo $data_array['x_msg'];  ?></td>
                    <td><?php echo $data_array['x_date'];  ?></td>
              
               
                                 
                </tr>
			<?php
            
            $sr++;
            }
            ?>  
</tbody>
</table>

</div></div>
</div></div>
</div>
<!-- Warper Ends Here (working area) -->


<footer class="container-fluid footer">
Copyright &copy; <?php    echo date('Y');  ?>
</footer>


</section>
<!-- Content Block Ends Here (right box)-->



<!-- JQuery v1.9.1 -->
			<script src="assets/js/jquery/jquery-1.9.1.min.js" type="text/javascript"></script>
            
            <!-- Bootstrap -->
            <script src="assets/js/bootstrap/bootstrap.min.js"></script>
            
            <!-- NanoScroll -->
            <script src="assets/js/plugins/nicescroll/jquery.nicescroll.min.js"></script>
            
            
            <!-- Data Table -->
            <script src="assets/js/plugins/datatables/jquery.dataTables.js"></script>
            <script src="assets/js/plugins/datatables/DT_bootstrap.js"></script>
            <script src="assets/js/plugins/datatables/jquery.dataTables-conf.js"></script>
            
            
            <!-- Custom JQuery -->
            <script src="assets/js/app/custom.js" type="text/javascript"></script>
            
            
            
            <script>
            (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
            m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
            })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
            
            ga('create', 'UA-56821827-1', 'auto');
            ga('send', 'pageview');
            
            </script>
</body>
</html>
<?php

	   }
	   else
	   {
		 header("location:index.php");  
		   
	   }
	   ?>