<?php
include"initialize_page.php";
include"systemfunctions.php";
?>
<?php include('resources/header.php') ?>
	<title>Chat</title>
	<meta name="keywords" content="" />
	<meta name="description" content="" />
<?php include('resources/css-file.php') ?>
<?php include('resources/navigation.php') ?> 
<!-- Dashboard wrapper starts -->
<div class="dashboard-wrapper">
	<div class="main-container">				
		<div class="row">
			<div class="col-sm-12 ac-summ">
				<h2>Chat</h2>
			</div>
			
		</div>
		<div class="row gutter">
			<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
				<div class="panel">
					<div class="panel-heading">
						<h4>Messages</h4>
					</div>
					<div class="panel-body">
						<ul class="chat-list">
 <?php
    $statement_q=mysqli_query($con,"SELECT * FROM x_chat WHERE x_userid='$user_id' ORDER by x_id ASC ");
	while($statement_array=mysqli_fetch_array($statement_q))
	   {
	       $get_idxx=$statement_array['x_id'];
  
  ?>                                           
										  
											<!----->
											<?php  if($statement_array['x_by']=="user") {  
												?>
											<li class="in">
											<?php }
												else {
												mysqli_query($con,"UPDATE x_chat SET x_readstatus='R' WHERE x_id='$get_idxx'"); ?>
											</li>	
                                            <li class="out">
												<?php } ?>
											<?php  if($statement_array['x_by']=="user") {  
												?>	
												<div class="chat-img">
													<img alt="Avtar" src="pics/<?php echo user_details($user_id,'x_pic');  ?>">
												</div>
											
											
											<?php }
												else {
												mysqli_query($con,"UPDATE x_chat SET x_readstatus='R' WHERE x_id='$get_idxx'"); ?>
												<div class="chat-img">			
												<img src="img/bank.png" class="avatar" alt="">
												</div>
												<?php 
												}  ?>
												<div class="chat-body">
													<div class="chat-message">
                                                   <h5><?php  if($statement_array['x_by']=="user") {  echo "You"; } else { 
mysqli_query($con,"UPDATE x_chat SET x_readstatus='R' WHERE x_id='$get_idxx'");
echo "Admin"; }  ?> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span>at <?php echo $statement_array['x_date'];  ?></span></h5>
                                                    <p> <?php echo $statement_array['x_msg'];  ?></p>
													</div>
												</div>
                                            </li>
                                            
                                        <?php }  ?>  
										
                                        </ul>
						
						<form action="#" method="post">
						                  <div class="form-group">
						                    <textarea type="text" name="message" placeholder="Enter Chat" class="form-control" id="datainmsgboxid"></textarea>
											</div>
						                    <button type="button" class="btn btn-info" id="msgbuttonsendid" >Send <i class="fa fa-paper-plane-o"></i></button>
						                     </div>
						                </form>
					</div>
				</div>
			</div>
		</div>	
		</br>
		</div>
	<!-- Main container ends -->
</div>
<!-- Dashboard wrapper ends -->
<?php include('resources/footer.php') ?>
<?php include('resources/js-file.php') ?>
<script type="text/javascript">
   $(document).ready(function() {
    
	$("#msgbuttonsendid").click(
	   function()
	     {
		   var getmsg=$("#datainmsgboxid").val();
		   var trimmsg=getmsg.trim(); 
		      if(trimmsg=="")
			   {
				alert("Please Write Something..");  
				return false; 
			   }
			   else
			   {
				   $.post("controller.php", { q:"send_chatmsg", trimmsg:trimmsg }, function(data)
				    {
					          if(data==0)
							   {
								alert("Please Write Something..");   
							   }
							   if(data==1)
							   {
								alert("Sent Successfully..");
								window.location.href='<?php  echo website_settingdata('x_weburl'); ?>user/chat.php';  
							   }
					}
				   );
			   }
			 
		 }
	);
	
});

</script>











