<?php include("../db_connection.php");

if(isset($_POST['sender']) && $_POST['sender']!=="")
{
	$sql=mysql_query("update tbl_chats set status='read' where sender_id='".$_POST['sender']."' and receiver_id='".$_SESSION['cid']."'");
	
	?><input type="hidden" value="<?php echo $_POST['sender'];?>" id="sender"><?php  
    
}


$sqlad=mysql_query("select * from tbl_chats where ads_id='".$_POST['adid']."' and (sender_id='".$_SESSION['cid']."' or receiver_id='".$_SESSION['cid']."')");

while($resad=mysql_fetch_assoc($sqlad))
{

$sender_id=$resad['sender_id'];

$receiver_id=$resad['receiver_id'];

if($sender_id==$_SESSION['cid'])
{
	$sender=mysql_query("select * from tbl_users where userid='$sender_id'");
	$ressender=mysql_fetch_assoc($sender);
	
	?>
	<div class="row msg_container base_sent">
        <div class="col-md-9 col-xs-9">
            <div class="messages msg_sent">
                <p><?php echo $resad['msg'];?></p>
                <time datetime="2009-11-13T20:00"><?php echo date('d M Y h:i:sa',strtotime($resad['datetime']));?></time>
            </div>
        </div>
        <div class="col-md-3 col-xs-3 avatar">
            <strong><?php echo ucfirst($ressender['fullname']);?></strong>
            <!--<img src="<?php ?>" class=" img-responsive ">-->
        </div>
    </div>
    
    <?php 
	/*$receiver=mysql_query("select * from tbl_users where userid='$receiver_id'");
	$resreceiver=mysql_fetch_assoc($receiver);
	?>
    
    <div class="row msg_container base_receive">
        <div class="col-md-2 col-xs-2 avatar">
            <strong><?php echo $resreceiver['fullname'];?></strong>
            <!--<img src="http://www.bitrebels.com/wp-content/uploads/2011/02/Original-Facebook-Geek-Profile-Avatar-1.jpg" class=" img-responsive ">-->
        </div>
        <div class="col-md-10 col-xs-10">
            <div class="messages msg_receive">
                <p><?php echo $resad['msg'];?></p>
                <time datetime="2009-11-13T20:00"><?php echo date('d M Y h:i:sa',strtotime($resad['datetime']));?></time>
            </div>
        </div>
   </div>*/
    
	//<?php
}
else
{
	$sender=mysql_query("select * from tbl_users where userid='$sender_id'");
	$ressender=mysql_fetch_assoc($sender);
	
	$receiver=mysql_query("select * from tbl_users where userid='$receiver_id'");
	$resreceiver=mysql_fetch_assoc($receiver);
	
	?>
	<?php /*?><div class="row msg_container base_sent">
        <div class="col-md-10 col-xs-10">
            <div class="messages msg_sent">
                <p><?php echo $resad['msg'];?></p>
                <time datetime="2009-11-13T20:00"><?php echo date('d M Y h:i:sa',strtotime($resad['datetime']));?></time>
            </div>
        </div>
        <div class="col-md-2 col-xs-2 avatar">
            <strong><?php echo $resreceiver['fullname'];?></strong>
            <!--<img src="<?php ?>" class=" img-responsive ">-->
        </div>
    </div><?php */?>
    
  
    
    <div class="row msg_container base_receive">
        <div class="col-md-3 col-xs-3 avatar">
            <strong><?php echo ucfirst($ressender['fullname']);?></strong>
            <!--<img src="http://www.bitrebels.com/wp-content/uploads/2011/02/Original-Facebook-Geek-Profile-Avatar-1.jpg" class=" img-responsive ">-->
        </div>
        <div class="col-md-9 col-xs-9">
            <div class="messages msg_receive">
                <p><?php echo $resad['msg'];?></p>
                <time datetime="2009-11-13T20:00"><?php echo date('d M Y h:i:sa',strtotime($resad['datetime']));?></time>
            </div>
        </div>
   </div>
    
	<?php
}

}

?>