<?php include("header.php");
$msg="";
if(!isset($_SESSION['cid']))
{
	?>
	<script>
    window.location="<?php echo $actual_link;?>login";
    </script>
	<?php
	
}

$sqlads=mysql_query("select * from tbl_ads where ads_id='".$_GET['adid']."'");
$resads=mysql_fetch_assoc($sqlads);


?>
 
<div class="main-container">
<div class="container">
<div class="row" style="min-height:430px;">



<div class="col-sm-3 page-sidebar">
<aside>
<div class="inner-box">
<div class="user-panel-sidebar">
<div class="collapse-box">
<h5 class="collapse-title no-border"> Items i Want <a class="pull-right" data-toggle="collapse" href="#MyClassified"><i class="fa fa-angle-down"></i></a></h5>
<div id="MyClassified" class="panel-collapse collapse in">
<ul class="acc-list">
<li><a href="<?php echo $actual_link;?>ads_details/<?php echo $_GET['adid'];?>"><div class="col-md-4 col-xs-4"><img src="<?php echo $actual_link."postedfile/".$resads['file1'];?>" width="100%"></div><div class="col-md-8"><h4><?php echo $resads['title'];?></h4></div><span><i class="fa fa-inr"></i>&nbsp;<?php echo $resads['price'];?></span></a></li>
</ul>
</div>
</div>
 
<div class="collapse-box">
<h5 class="collapse-title"> Transaction Type<a class="pull-right" data-toggle="collapse" href="#MyAds"><i class="fa fa-angle-down"></i></a></h5>
<div id="MyAds" class="panel-collapse collapse in">
<ul class="acc-list">
<li><a > <input name="trans" type="radio"  <?php if($resads['exchange_type']=="exchange") { echo "checked";}else { echo "disabled";} ?>> &nbsp;Exchange Only</a></li>
<li><a> <input name="trans"  type="radio" <?php if($resads['exchange_type']=="exchange_cash") { echo "checked";}else { echo "disabled";} ?>> &nbsp; Exchange + Cash  </a></li>
<li><a> <input name="trans"  type="radio" <?php if($resads['exchange_type']=="cash") { echo "checked";}else { echo "disabled";}  ?>> &nbsp; Cash  </a>
</ul>
</div>
</div>
 <?php $postuser=mysql_query("select * from tbl_users where userid='".$resads['posted_userid']."'");
 	   $respostu=mysql_fetch_assoc($postuser);
 ?>
<div class="collapse-box">
<h5 class="collapse-title"> Listed By<a class="pull-right" data-toggle="collapse" href="#TerminateAccount"><i class="fa fa-angle-down"></i></a></h5>
<div id="TerminateAccount" class="panel-collapse collapse in">
<ul class="acc-list">
<li><p><?php echo $respostu['fullname'];?></p>
<p><?php echo $respostu['address'];?></p>
<p><?php 
$postcity=mysql_query("select * from tbl_cities where city_id='".$respostu['city']."'");
$rescity=mysql_fetch_assoc($postcity);
echo $rescity['cityname'];
if($respostu['hidenumber']=="")
{
	echo $respostu['number'];
}
?></p>
</li>
</ul>
</div>
</div>
 
</div>
</div>
 
</aside>
</div>

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

<?php


if(isset($_POST['makequery']))
{
	$adsids=$_POST['adsids'];
	
	$query=$_POST['query'];
	
	$adid=$_GET['adid'];
	
	
	$sqlquery=mysql_query("select * from tbl_queries where for_adid='".$adid."' and querybyid='".$_SESSION['cid']."'");
	$resquery=mysql_num_rows($sqlquery);
	
	
	if($resquery==0)
	{
		


$insert=mysql_query("insert into tbl_queries(for_adid,querybyid,suggested_ads,query,datetime)values('$adid','".$_SESSION['cid']."','$adsids','$query',now())");


		
	

		$dellete=mysql_query("delete from tbl_notification where ads_id='$adid' and user_id='".$_SESSION['cid']."'");
		//mysql_query("insert into tbl_notification(user_id,ads_id,query_id,datetime)values('".$resads['posted_userid']."','$adid','".mysql_insert_id()."',now())");
		
		 $msg="Query sent successfully.";
		
		
	}
	else
	{
		
		 $msg="You have sent query already.";
		
	}
	
	if($msg!=="")
	{?>
	<div class="alert alert-success">
	<a class="pull-right" data-dismiss="alert" aria-label="close">&times;</a>
	<?php echo $msg;?>
	</div>
	<?php }
	
	
}
else
{


	$sqlquery1=mysql_query("select * from tbl_queries where for_adid='".$_GET['adid']."' and querybyid='".$_SESSION['cid']."'");
	$resquery1=mysql_num_rows($sqlquery1);
	
	
	if($resquery1==0)
	{
	
	 
	 if($resads['exchange_type']!=="cash")
	 {
	 ?>
	
	<div class="col-md-12">
	<div class="page-content">
	
	<div class="combo">
		
	</div>
	
	<div class="col-md-6 clicablep">
	<div class="inner-box" align="center" style="height: 390px;">
	<h2>Click on below items to add your product or multiple item for making combo offer.</h2><br>
	<i class="fa fa-plus-square fa-3x"></i>
	
	</div>
	 
	</div>
	</div>
	</div>
	<div class="col-md-12">
	<div class="prddtl">
	
	<?php $sql=mysql_query("select * from tbl_ads where posted_userid='".$_SESSION['cid']."'");
	while($res=mysql_fetch_assoc($sql))
	{
	?>
	<div class="Postads">
		<div class="col-sm-6 page-content">
		<div class="inner-box">
		 <a class="pull-right cross_<?php echo $res['ads_id'];?> cross" id="<?php echo $res['ads_id'];?>" style="display:none;"><i class="fa fa-times"></i></a>
			<h2 class="title-2"><i class="icon-folder-close"></i> <?php echo $res['title'];?> </h2>
			<a  class="clickAds" id="<?php echo $res['ads_id'];?>"><img src="<?php echo $actual_link."postedfile/".$res['file1'];?>" title="Click Here" width="100%" height="100%"></a>
			<span><h2><?php echo $res['description'];?></h2></span>
	
			<?php 
			$user=mysql_query("select * from tbl_users where userid='".$_SESSION['cid']."'");
			$resu=mysql_fetch_assoc($user);
			?>
			<span><?php echo $resu['address'];?></span>
	 
		</div>
		</div>
	</div>
	<?php } ?>
	</div>
	</div>
	<?php } ?>
	<div class="col-md-12">
	<!--<div class="col-md-3 page-sidebar">
	</div>
	<div class="col-md-9">-->
	<form action="" method="post">
	<input type="hidden" name="adsids" id="addds" value="">
	<div class="form-group">
	<textarea class="form-control" name="query" rows="10" cols="5" ></textarea>
	</div>
	<div class="form-group">
	<button name="makequery" class="btn btn-primary">Make Query</button>
	</div>
	</form>
	<!--</div>-->
	</div>
	
	<?php }
	else
	{
		?>
		<div class="alert alert-success">
		<a class="pull-right" data-dismiss="alert" aria-label="close">&times;</a>
		<?php echo "You have sent query already.";?>
		</div>
		<?php
	}
	
}
	
?>
</div>
 
</div>
 
</div>
 
<?php 
//}
 include("footer.php");?>

<script>
var hrefs = new Array();
    
$(".prddtl").on('click',".clickAds",function(){

if($(".Postads").length==1)
{
	$(".clicablep").hide();
}

//if($(".Postads").length>1)
//{

 
    
 hrefs.push($(this).attr('id'));
 
 //console.log(hrefs);
   
$("#addds").val(hrefs);

$(".cross_"+$(this).attr('id')).show();
	
var detail=$(this).closest('.Postads').html();	

if($(".combo").html()=="")
{
	$(".combo").html(detail);
}
else
{
	$(".combo").append(detail);
}

$(this).closest('.Postads').remove();

//}
/*else
{
	$(".clicablep").hide();
	$(".cross_"+$(this).attr('id')).show();
}*/

});

$(".combo").on('click','.cross',function(){


var ads=$("#addds").val();
var clik=','+$(this).attr('id');
var re=ads.search(clik);

if(re=="-1")
{
	$("#addds").val($("#addds").val().replace($(this).attr('id'),''));
}
else
{
	$("#addds").val($("#addds").val().replace(','+$(this).attr('id'),''));
}
$(".clicablep").show();

var detail=$(this).closest('.col-sm-6').html();


if($(".prddtl").html()=="")
{
	$(".prddtl").html(detail);
}
else
{
	$(".prddtl").append('<div class="Postads"><div class="col-sm-6 page-content">'+detail+'</div></div>');
}


$(this).closest('.col-sm-6').remove();
$(".cross_"+$(this).attr('id')).hide();

});
</script>