<?php include("header.php");
//error_reporting(0);

$msg="";
$Gtitle="";$Gdescription="";$Gtype="";$Gnegotiable="";$Gconditions="";$Gexchange_type="";$Gfile1="";$Gfile2="";$Gfile3="";$Gfile4="";$Gfile5="";$derireP=array();$derireMcid=array();$derireCid=array();$derireSubid=array();$Gpackage="";$Gmaincategory="";$Gcategory="";$Gsubcategory="";$Gprice="";$Gdesire_products="";$Gdes_maincat="";$lastas="";
if(isset($_GET['adid']))
{
	
	if(!isset($_SESSION['cid']))
	{
		?>
		<script>
        window.location="<?php echo $actual_link;?>login";
        </script>
		<?php
	}
	
	$sqlgetadd=mysql_query("select * from tbl_ads where ads_id='".$_GET['adid']."'");
	$resgetadd=mysql_fetch_assoc($sqlgetadd);
	

	
	if($resgetadd['posted_userid']==$_SESSION['cid'])
	{
		$Gtitle=$resgetadd['title'];
		$Gdescription=$resgetadd['description'];
		$Gtype=$resgetadd['type'];
		$Gprice=$resgetadd['price'];
		$Gnegotiable=$resgetadd['negotiable'];
		$Gconditions=$resgetadd['conditions'];
		$Gexchange_type =$resgetadd['exchange_type'];
		$Gfile1=$resgetadd['file1'];
		$Gfile2=$resgetadd['file2'];
		$Gfile3=$resgetadd['file3'];
		$Gfile4=$resgetadd['file4'];
		$Gfile5=$resgetadd['file5'];
		
		$derireP=$resgetadd['desire_products'];
		
		$derireMcid=explode(",",$resgetadd['des_maincat']);
		
		$derireCid=explode(",",$resgetadd['des_cat']);
		
		$derireSubid=explode(",",$resgetadd['des_subcat']);
		
		
		//$Gpackage=$resgetadd['package'];
		
		$sqlgmcat=mysql_query("select * from tbl_maincategory where mcid='".$resgetadd['maincategory']."' and status='Enable'");
		$resgmcat=mysql_fetch_assoc($sqlgmcat);
		
		$sqlgcat=mysql_query("select * from tbl_category where cid='".$resgetadd['category']."' and status='Enable' order by name asc");
		$resgcat=mysql_fetch_assoc($sqlgcat);
		
		$idcategory=$resgetadd['category'];
		
		$sqlgsubcat=mysql_query("select * from tbl_subcategory where sid='".$resgetadd['subcategory']."' and status='Enable' order by name asc");
		$resgsubcat=mysql_fetch_assoc($sqlgsubcat);
		
		$idsubcategory=$resgetadd['subcategory'];
		
		$Gmaincategory=$resgetadd['maincategory'];

		$Gcategory=$resgcat['name'];
		
		$Gsubcategory=$resgsubcat['name'];
		
		
		
		
		
	}
	else
	{
		?>
			<script>
				window.location="<?php echo $actual_link?>index";
			</script>
		<?php 
	}
	
	
}

$sqlpost="";
if(isset($_POST['post']))
{
	
	
      
	$city="";$locality="";$number="";$email="";$name="";
	if(isset($_POST['name']))
	{
		$name=$_POST['name'];
	}
	if(isset($_POST['email']))
	{
		$email=$_POST['email'];
	}
	if(isset($_POST['number']))
	{
		$number=$_POST['number'];
	}
	
	if(isset($_POST['city']))
	{
		$city=$_POST['city'];
	}
	
	if(isset($_POST['locality']))
	{
		$locality=$_POST['locality'];
	}
	
	
    $sqluser=mysql_query("select * from tbl_users where email='$email'");
	$resuser=mysql_fetch_assoc($sqluser);
	
	$hidenumber="";
	if(isset($_POST['hidenumber']) && $_POST['hidenumber']!=="")
	{
		$hidenumber=$_POST['hidenumber'];
	}
	
	
	
	
	if(isset($resuser['email']) && $resuser['email']!=="")
	{
		
		if(isset($_SESSION['cid']))
		{
			
			$postid=$resuser['userid'];
			//$insert=mysql_query("update tbl_users set fullname='$name',number='$number',hidenumber='$hidenumber',city='$city',locality='$locality' where email='$email'");
			
		}
		else
		{
			?><script>
            alert('Email register already');
			window.location="<?php echo $actual_link?>login";
            </script><?php
		}
		
		
		
		
	
	}
	else
	{
		if(isset($_SESSION['cid']))
		{
			$postid=$_SESSION['cid'];
		}
		else
		{
			
		
		
		if(isset($_POST['password']))
		{
			$passw=md5($_POST['password']);
		}
		
		
		
		$insert=mysql_query("insert into tbl_users(fullname,email,number,hidenumber,password,city,locality)values('$name','$email','$number','$hidenumber','$passw','$city','$locality')");
		
		$postid=mysql_insert_id();
		
		
		$_SESSION['cname']=$name;
		$_SESSION['cid']=$postid;
		$_SESSION['cemail']=$email;
		
		

		$message='<div id=":nm" class="ii gt m152202c763663e6d adP adO"><div id=":nl" class="a3s" style="overflow: hidden;"><div marginwidth="0" marginheight="0"><div class="adM">
	   </div><div dir="ltr" style="background-color:#f5f5f5;margin:0;padding:70px 0 70px 0;width:100%"><div class="adM">
		  </div><table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%">
			 <tbody>
				<tr>
				   <td align="center" valign="top">
					  <div>
					  </div>
					  <table style="background-color:#fdfdfd;border:1px solid #dcdcdc;border-radius:3px!important" border="0" cellpadding="0" cellspacing="0" width="600">
						 <tbody>  
						 <tr>
							   <td align="center" valign="top">
								  <table style="margin-top:20px" border="0" cellpadding="0" cellspacing="0" width="600">
									 <tbody>
										<tr>
										   <td align="center" style="text-align: center;
font-family: Open Sans Condensed,Helvetica Neue,sans-serif;
font-size: 28px;
font-weight: bold;
text-transform: uppercase;">
											  
												
												<a href="'.$actual_link.'index" style="color:#5e5e5e;">
 
												<span class="logo-icon"><i class="icon icon-search-1 ln-shadow-logo shape-0"></i> </span> Exchangekarde.com </a> 
												
											   				
											  </div>
											  
										   </td>
										   
										</tr>
									 </tbody>
								  </table>
							   </td>
							</tr>                      
							<tr>
							   <td align="center" valign="top">
								  <table border="0" cellpadding="0" cellspacing="0" width="600">
									 <tbody>
										<tr>
										   <td style="background-color:#fdfdfd" valign="top">
											  <table border="0" cellpadding="20" cellspacing="0" width="100%">
												 <tbody>
													<tr>
													   <td style="padding:48px" valign="top">
														  <div style="color:#000;font-family:&quot;Helvetica Neue&quot;,Helvetica,Roboto,Arial,sans-serif;font-size:14px;line-height:150%;text-align:left">
															 
															 <p style="margin:0 0 16px">Dear '.$name.',<br><br>  Welcome to exchangekrdede.com. Please checkout your account detail.<br>
															 
															 <p>Fullname: '.$name.'</p>
															 <p>Contact No: '.$number.'</p>
															 <p>Username: '.$email.'</p>
															 <p>Password: '.$_POST['password'].'</p>
															 
															 </p>                                                         
														  </div>
													   </td>
													</tr>
												 </tbody>
											  </table>
										   </td>
										</tr>
									 </tbody>
								  </table>
							   </td>
							</tr>
							<tr>
							   <td align="center" valign="top">
								  <table border="0" cellpadding="10" cellspacing="0" width="600">
									 <tbody>
										<tr>
										   <td style="padding:0" valign="top">
											  <table border="0" cellpadding="10" cellspacing="0" width="100%">
												 <tbody>
													<tr>
													   <td colspan="2" style="border:0;color:#000;font-family:Arial;font-size:12px;line-height:125%;text-align:center" valign="middle">
														  <p>Powered by Exchange Kar DE</p>
													   </td>
													</tr>
												 </tbody>
											  </table>
										   </td>
										</tr>
									 </tbody>
								  </table>
							   </td>
							</tr>
						 </tbody>
					  </table>
				   </td>
				</tr>
			 </tbody>
		  </table></div></div></div></div>';
		  
			
			
			$subject="Account Information";
			$to   = $email;
			$from = 'info@exchangekarde.com';
			
			$headers = "From: " . strip_tags($from) . "\r\n";
			$headers .= "Reply-To: ". strip_tags($from) . "\r\n";
			
			$headers .= "MIME-Version: 1.0\r\n";
			$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
			
			mail($to, $subject, $message, $headers);
		
		
	
	    }
		
	}
	
	
	$filename1="";
	if(isset($_FILES['file1']['name']))
	{
		$filename1=$_FILES['file1']['name'];
	}
	$filename2="";
	if(isset($_FILES['file2']['name']))
	{
		$filename2=$_FILES['file2']['name'];
	}
	$filename3="";
	if(isset($_FILES['file3']['name']))
	{
		$filename3=$_FILES['file3']['name'];
	}
	$filename4="";
	if(isset($_FILES['file4']['name']))
	{
		$filename4=$_FILES['file4']['name'];
	}
	$filename5="";
	if(isset($_FILES['file5']['name']))
	{
		$filename5=$_FILES['file5']['name'];
	}
	
	if($filename1!=="")
	{
		$move1=move_uploaded_file($_FILES['file1']['tmp_name'],"postedfile/".$filename1);
	}
	if($filename2!=="")
	{
		$move2=move_uploaded_file($_FILES['file2']['tmp_name'],"postedfile/".$filename2);
	}
	if($filename3!=="")
	{
		$move3=move_uploaded_file($_FILES['file3']['tmp_name'],"postedfile/".$filename3);
	}
	if($filename4!=="")
	{
		$move4=move_uploaded_file($_FILES['file4']['tmp_name'],"postedfile/".$filename4);
	}
	if($filename5!=="")
	{
		$move5=move_uploaded_file($_FILES['file5']['tmp_name'],"postedfile/".$filename5);
	}
	
	
	$desire_product=$_POST['desire_product'];
	
	
	
     
	
	$desire_maincat=$_POST['desire_maincat'];
	
	$desire_cat=array("0");
	if(isset($_POST['desire_cat']))
	{
		$desire_cat=$_POST['desire_cat'];
	}
	
	$desire_subcat=array("0");
	if(isset($_POST['desire_subcat']))
	{
		$desire_subcat=$_POST['desire_subcat'];
	}
	
	$desp="";$dessubcat="";$descat="";$desmainc="";
	
   
	if($desire_product[0]!=="")
	{
	
	foreach($desire_product as $key=>$desirep)
	{
		
		$desp.=$desirep.",";
		
		$desmainc.=$desire_maincat[$key].",";
		
		$descat.=$desire_cat[$key].",";
		
		$dessubcat.=$desire_subcat[$key].",";
		
	}
		
		
		
		$ndesp=rtrim($desp,",");
		
		$ndesmainc=rtrim($desmainc,",");
		if($ndesmainc=="0")
		{
			$ndesmainc="";
		}
		else
		{
			$ndesmainc=$ndesmainc;
		}
		
		$ndescat=rtrim($descat,",");
		
		if($ndescat=="0")
		{
			$ndescat="";
		}
		else
		{
			$ndescat=$ndescat;
		}
		
		$ndessubcat=rtrim($dessubcat,",");
		
		
		
		
		if($ndessubcat==0)
		{
			$ndessubcat="";
			
		}
		else
		{
			$ndessubcat=$ndessubcat;
		}
	}
	else
	{
		$ndessubcat="";$ndescat="";$ndesp="";$ndesmainc="";
			
	}
	
	
	
		$negotiable="";
		if(isset($_POST['negotiable']))
		{
			$negotiable=$_POST['negotiable'];
		}
	
	
	if(isset($_GET['adid']))
	{
		
		
		
		if($filename1!=="")
		{
			
			$upadtead=mysql_query("update tbl_ads set maincategory='".$_POST['maincategory']."',category='".$_POST['category']."',subcategory='".$_POST['subcategory']."',title='".$_POST['Adtitle']."',description='".mysql_real_escape_string($_POST['Ad_description'])."',type='".$_POST['Adtype']."',price='".$_POST['price']."',negotiable='".$negotiable."',conditions='".$_POST['condition']."',exchange_type='".$_POST['exchangeType']."',file1='".$filename1."',desire_products='".$ndesp."',des_maincat='".$ndesmainc."',des_cat='".$ndescat."',des_subcat='".$ndessubcat."' where ads_id='".$_GET['adid']."'");
			
		}
		
			
		if($filename2!=="")
		{
			
			$upadtead=mysql_query("update tbl_ads set maincategory='".$_POST['maincategory']."',category='".$_POST['category']."',subcategory='".$_POST['subcategory']."',title='".$_POST['Adtitle']."',description='".mysql_real_escape_string($_POST['Ad_description'])."',type='".$_POST['Adtype']."',price='".$_POST['price']."',negotiable='".$negotiable."',conditions='".$_POST['condition']."',exchange_type='".$_POST['exchangeType']."',file2='".$filename2."',desire_products='".$ndesp."',des_maincat='".$ndesmainc."',des_cat='".$ndescat."',des_subcat='".$ndessubcat."' where ads_id='".$_GET['adid']."'");
			
			
		}
			
		if($filename3!=="")
		{
			
			$upadtead=mysql_query("update tbl_ads set maincategory='".$_POST['maincategory']."',category='".$_POST['category']."',subcategory='".$_POST['subcategory']."',title='".$_POST['Adtitle']."',description='".mysql_real_escape_string($_POST['Ad_description'])."',type='".$_POST['Adtype']."',price='".$_POST['price']."',negotiable='".$negotiable."',conditions='".$_POST['condition']."',exchange_type='".$_POST['exchangeType']."',file3='".$filename3."',desire_products='".$ndesp."',des_maincat='".$ndesmainc."',des_cat='".$ndescat."',des_subcat='".$ndessubcat."' where ads_id='".$_GET['adid']."'");
			
		}
				
		if($filename4!=="")
		{
			
			$upadtead=mysql_query("update tbl_ads set maincategory='".$_POST['maincategory']."',category='".$_POST['category']."',subcategory='".$_POST['subcategory']."',title='".$_POST['Adtitle']."',description='".mysql_real_escape_string($_POST['Ad_description'])."',type='".$_POST['Adtype']."',price='".$_POST['price']."',negotiable='".$negotiable."',conditions='".$_POST['condition']."',exchange_type='".$_POST['exchangeType']."',file4='".$filename4."',desire_products='".$ndesp."',des_maincat='".$ndesmainc."',des_cat='".$ndescat."',des_subcat='".$ndessubcat."' where ads_id='".$_GET['adid']."'");
			
			
		}
					
		if($filename5!=="")
		{
			$upadtead=mysql_query("update tbl_ads set maincategory='".$_POST['maincategory']."',category='".$_POST['category']."',subcategory='".$_POST['subcategory']."',title='".$_POST['Adtitle']."',description='".mysql_real_escape_string($_POST['Ad_description'])."',type='".$_POST['Adtype']."',price='".$_POST['price']."',negotiable='".$negotiable."',conditions='".$_POST['condition']."',exchange_type='".$_POST['exchangeType']."',file5='".$filename5."',desire_products='".$ndesp."',des_maincat='".$ndesmainc."',des_cat='".$ndescat."',des_subcat='".$ndessubcat."' where ads_id='".$_GET['adid']."'");
		}
						
		if($filename1=="" && $filename2=="" && $filename3=="" && $filename4=="" && $filename5=="")
		{
		
		$upadtead=mysql_query("update tbl_ads set maincategory='".$_POST['maincategory']."',category='".$_POST['category']."',subcategory='".$_POST['subcategory']."',title='".$_POST['Adtitle']."',description='".mysql_real_escape_string($_POST['Ad_description'])."',type='".$_POST['Adtype']."',price='".$_POST['price']."',negotiable='".$negotiable."',conditions='".$_POST['condition']."',exchange_type='".$_POST['exchangeType']."',desire_products='".$ndesp."',des_maincat='".$ndesmainc."',des_cat='".$ndescat."',des_subcat='".$ndessubcat."' where ads_id='".$_GET['adid']."'");
		}
						
				
		//echo'<pre>';print_r($filename1);exit;
		
		if($upadtead==true)
		{
			$msg="Ads details update successfully";
		}
		
		?><script>
		
		setTimeout(function()
			{
			window.location.href=window.location.href;
			},1500);
		</script><?php
	}
	else
	{
		
	
	$sqlpost=mysql_query("insert into tbl_ads(posted_userid,maincategory,category,subcategory,title,description,type,price,negotiable,conditions,exchange_type,file1,file2,file3,file4,file5,desire_products,des_maincat,des_cat,des_subcat,admin_status,postdate)values('$postid','".$_POST['maincategory']."','".$_POST['category']."','".$_POST['subcategory']."','".$_POST['Adtitle']."','".mysql_real_escape_string($_POST['Ad_description'])."','".$_POST['Adtype']."','".$_POST['price']."','".$negotiable."','".$_POST['condition']."','".$_POST['exchangeType']."','".$filename1."','".$filename2."','".$filename3."','".$filename4."','".$filename5."','$ndesp','$ndesmainc','$ndescat','$ndessubcat','Approved',now())");
	
	$lastas=mysql_insert_id();
	
	/*$lastas=mysql_insert_id();
	
	$sqlallu=mysql_query("select * from tbl_users where userid!='".$_SESSION['cid']."'");
	while($resallu=mysql_fetch_assoc($sqlallu))
	{
		mysql_query("insert into tbl_notification(user_id,ads_id,datetime) values('".$resallu['userid']."','".$lastas."',now())");
	}*/
	}
	
	
	
	
	
}
?>

<div class="main-container">
<div class="container">
<div class="row">
<div class="col-md-9 page-content">
<?php 
if($msg!=="")
{
	?><div class="alert alert-success">
<strong>
	<?php echo $msg; ?>
    </strong>
</div>
<?php
}
?>

<div class="inner-box category-content">

<h2 class="title-2 uppercase"><strong> <i class="icon-docs"></i> Post a Free Classified Ad</strong> </h2>
<div class="row">
<div class="col-sm-12">
<form class="form-horizontal" method="post" enctype="multipart/form-data">
<fieldset>
 
<div class="form-group">
<label class="col-md-3 control-label">Main Category</label>
<div class="col-md-8">
<select name="maincategory" id="maincategory" class="form-control" required="">
<option value="" selected="selected"> Select a category... </option>
<?php 
$sqlmaincat=mysql_query("select * from tbl_maincategory where status='Enable' order by name asc");
while($resmaincat=mysql_fetch_assoc($sqlmaincat))
{
	?>
    	<option <?php if($Gmaincategory==$resmaincat['mcid']) { echo "selected='selected'"; } ?> value=<?php echo $resmaincat['mcid']; ?>><?php echo $resmaincat['name'] ?></option>
    <?php
}
?>
</select>
</div>
</div>

<div id="cat">
<?php if($Gcategory!=="")
{?>
<div class="form-group">
<label class="col-md-3 control-label">Category</label>
<div class="col-md-8">
<select name="category" id="category" class="form-control" required="">
<option value="<?php echo $idcategory; ?>" selected="selected"> <?php echo $Gcategory; ?> </option>

</select>
</div>
</div>
<?php } ?>
</div>
<div id="sub">
<?php if($Gsubcategory!=="")
{?>
<div class="form-group">
<label class="col-md-3 control-label">Sub Category</label>
<div class="col-md-8">
<select name="subcategory" id="subcategory" class="form-control" required="">
<option value="<?php echo $idsubcategory; ?>" selected="selected"> <?php echo $Gsubcategory; ?> </option>
</select>
</div>
</div>
<?php } ?>
</div>
 

 
<div class="form-group">
<label class="col-md-3 control-label" for="Adtitle">Ad title</label>
<div class="col-md-8">
<input id="Adtitle" name="Adtitle" placeholder="Ad title" class="form-control input-md" required="" value="<?php echo $Gtitle;?>" type="text">
<span class="help-block">A great title needs at least 60 characters. </span> </div>
</div>

 
<div class="form-group">
<label class="col-md-3 control-label" for="textarea">Describe ad </label>
<div class="col-md-8">
<textarea required="" class="form-control" id="textarea" name="Ad_description"><?php echo $Gdescription;?></textarea>
</div>
</div>


<div class="form-group">
<label class="col-md-3 control-label">Add Type</label>
<div class="col-md-8">
<label class="radio-inline" for="radios-0">
<input name="Adtype" id="radios-0" <?php if($Gtype=="used") { echo "checked";} ?> value="used" type="radio" required="">
Used </label>
<label class="radio-inline" for="radios-1">
<input name="Adtype" id="radios-1" <?php if($Gtype=="new") { echo "checked";} ?> value="new" type="radio" required="">
New </label>
</div>
</div>
 
<div class="form-group">
<label class="col-md-3 control-label" for="Price">Price</label>
<div class="col-md-4">
<div class="input-group"> <span class="input-group-addon"><i class="fa fa-inr"></i></span>
<input id="Price" pattern="[0-9.]+" name="price" value="<?php echo $Gprice;?>"  class="form-control" placeholder="placeholder" required="" type="text">
</div>
</div>
<div class="col-md-4">
<div class="checkbox">
<label>
<input type="checkbox" <?php if($Gnegotiable=="on") { echo "checked"; } ?> name="negotiable">Negotiable </label>
</div>
</div>
</div>

<div class="form-group">
<label class="col-md-3 control-label" for="condition">Condition</label>
<div class="col-md-8">

<select class="form-control" data-categoriesindex="0" data-html="true" name="condition" data-placement="right" required="">
    <option class="default-select" value="" disabled="" selected=""> Select item condition </option>
    <option <?php if($Gconditions=='Not Working') { echo "selected";} ?> value="Not Working">Not Working</option>
    <option <?php if($Gconditions=='Functional') { echo "selected";} ?> value="Functional">Functional</option>
    <option <?php if($Gconditions=='Good') { echo "selected";} ?> value="Good">Good</option>
    <option <?php if($Gconditions=='Very Good') { echo "selected";} ?> value="Very Good">Very Good</option>
    <option <?php if($Gconditions=='Excellent') { echo "selected";} ?> value="Excellent">Excellent</option>
</select>
</div>
</div>

<div class="form-group">
<label class="col-md-3 control-label" for="transaction">Transaction</label>
<div class="col-sm-8">
    <label class="radio-inline selected">
        <input <?php if($Gexchange_type=="exchange") { echo "checked";} ?> name="exchangeType" value="exchange" type="radio" required="">
        <span class="transaction-type">Exchange only</span>
    </label>
    <label class="radio-inline second-radio">
        <input <?php if($Gexchange_type=="exchange_cash") { echo "checked";} ?> name="exchangeType" value="exchange_cash" type="radio" required=""><span class="transaction-type">Exchange + Cash</span>
    </label>
    <label class="radio-inline second-radio">
        <input  <?php if($Gexchange_type=="cash") { echo "checked";} ?> name="exchangeType" value="cash" type="radio" required=""><span class="transaction-type">Cash only</span>
    </label>
</div>
</div>


<div class="form-group" id="extrap" <?php if($Gexchange_type=="exchange" || $Gexchange_type=="exchange_cash") { ?>style="display:block;" <?php } else
{ ?>style="display:none;" <?php } ?>>
<label class="col-md-3 control-label" for="seller-Location"></label>

<div class="col-md-8">
	<div class="panel panel-default">
        <div class="panel-body">
           
            <?php 
			    
				if(!empty($derireP))
				{
					
					
					$exppro=explode(',',$derireP);
					foreach($exppro as $k=>$desrp)
					{
						$Gdesire_products=$desrp;
				
						$Gdes_maincat=$derireMcid[$k];
						
						$Gdes_cat=$derireCid[$k];
						
						
						
						$Gdes_subcat=$derireSubid[$k];
						
						
						
						?>
						<div id="crossAction">
						 <div class="col-md-5">
							<input type="text"  name="desire_product[]" value="<?php echo $Gdesire_products;?>" class="form-control desprod" id="fdep" <?php if($Gexchange_type=="exchange" || $Gexchange_type=="exchange_cash") { ?> required="" <?php } ?>>
						</div>
						 <div class="col-md-5 ms">
							<select name="desire_maincat[]" class="form-control maincategory1" id="fmainc" <?php if($Gexchange_type=="exchange" || $Gexchange_type=="exchange_cash") { ?>required="" <?php } ?>>
								<option value="0" selected="selected"> Select Maincategory </option>
								<?php 
								$sqlmaincat=mysql_query("select * from tbl_maincategory where status='Enable' order by name asc");
								while($resmaincat=mysql_fetch_assoc($sqlmaincat))
								{
									?><option <?php if($Gdes_maincat==$resmaincat['mcid']) { echo"selected='selected'"; } ?> value="<?php echo $resmaincat['mcid'] ?>"><?php echo $resmaincat['name'];?></option>
								 <?php   
								}
								?>
							</select>
							
							   <div class="nearcat"> 
								
								 <select name="desire_cat[]"  class="form-control category1 more1">
								   
									 <?php $sqlcasts=mysql_query("select * from tbl_category where cid='$Gdes_cat'");
											  $rescasts=mysql_fetch_assoc($sqlcasts);
										?>
										<option  value="<?php echo $Gdes_cat;?>"><?php echo $rescasts['name'];?></option>
								</select>
							  </div>  
							  
							  <div class="nearsubcat">
								
								 <select name="desire_subcat[]" class="form-control more1">
									<?php $sqlcastss=mysql_query("select * from tbl_subcategory where sid='$Gdes_subcat'");
											  $rescastss=mysql_fetch_assoc($sqlcastss);
										?>
									<option  value="<?php echo $Gdes_subcat;?>"><?php echo $rescastss['name'];?></option>
								   
								</select>
							  
							 </div>   
					  
						 </div>
					   </div>
					   
					   <?php if($k>0)
					   {
					   ?>
						<div class="col-md-2"> 
						
					   <a class="Cross pull-right"><i class="fa fa-times"></i></a>
					   </div>    
					   
							<?php
					   }
						
						
					}
				}
			
				else
				{
					?>
						<div id="crossAction">
                         <div class="col-md-5">
                            <input type="text"  name="desire_product[]" value="<?php echo $Gdesire_products;?>" class="form-control desprod" id="fdep">
                        </div>
                         <div class="col-md-5 ms">
                            <select name="desire_maincat[]" class="form-control maincategory1" id="fmainc">
                                <option value="0" selected="selected"> Select Maincategory </option>
                                <?php 
                                $sqlmaincat=mysql_query("select * from tbl_maincategory where status='Enable' order by name asc");
                                while($resmaincat=mysql_fetch_assoc($sqlmaincat))
                                {
                                    ?><option <?php if($Gdes_maincat==$resmaincat['mcid']) { echo"selected='selected'"; } ?> value="<?php echo $resmaincat['mcid'] ?>"><?php echo $resmaincat['name'];?></option>
                                 <?php   
                                }
                                ?>
                            </select>
                            
                               <div class="nearcat"> 
                              </div>  
                              
                              <div class="nearsubcat">
                             </div>   
                      
                         </div>
                       </div>
					<?php
				}
			
			
			?>
            
            
             <div class="add_desire_p" style="margin-top:30px;">
             </div>
            <div class="col-md-8">
            <a class="btn btn-success pull-left more" id="addMore">Add More</a>
        	</div>   
        </div>
	</div>
</div>                 
</div>
 
<div class="form-group">
<label class="col-md-3 control-label" for="textarea"> Picture </label>
<div class="col-md-8">
<div class="mb10">
<?php if($Gfile1!=="")
{
?>

<div class="file-preview">
   <div class="close fileinput-remove text-right removefile">×</div>
   <div class="file-preview-thumbnails">
   		<div class="file-preview-frame" id="preview-1460106475958-0">
   			<img src="<?php echo $actual_link."postedfile/".$Gfile1?>" class="file-preview-image" title="Penguins.jpg" alt="Penguins.jpg" style="width:auto;height:160px;">
		</div>
   </div>
   <div class="clearfix"></div>   <div class="file-preview-status text-center text-success"></div>
   
</div>

<input required="" id="input-upload-img1" type="file" name="file1" class="file" data-preview-file-type="text" value="<?php echo $Gfile1 ?>" disabled="disabled">
<?php }
else
{
	?>
	<input required="" id="input-upload-img1" type="file" name="file1" class="file" data-preview-file-type="text" value="<?php echo $Gfile1 ?>">
	<?php
}
 ?>



</div>
<div class="mb10">
<?php if($Gfile2!=="")
{
?>

<div class="file-preview">
   <div class="close fileinput-remove text-right removefile">×</div>
   <div class="file-preview-thumbnails">
   		<div class="file-preview-frame" id="preview-1460106475958-0">
   			<img src="<?php echo $actual_link."postedfile/".$Gfile2?>" class="file-preview-image" title="Penguins.jpg" alt="Penguins.jpg" style="width:auto;height:160px;">
		</div>
   </div>
   <div class="clearfix"></div>   <div class="file-preview-status text-center text-success"></div>
   
</div>
<?php } ?>

<input id="input-upload-img2" type="file" name="file2" class="file" data-preview-file-type="text" disabled="disabled">
</div>
<div class="mb10">
<?php if($Gfile3!=="")
{
?>

<div class="file-preview">
  <div class="close fileinput-remove text-right removefile">×</div>
   <div class="file-preview-thumbnails">
   		<div class="file-preview-frame" id="preview-1460106475958-0">
   			<img src="<?php echo $actual_link."postedfile/".$Gfile3?>" class="file-preview-image" title="Penguins.jpg" alt="Penguins.jpg" style="width:auto;height:160px;">
		</div>
   </div>
   <div class="clearfix"></div>   <div class="file-preview-status text-center text-success"></div>
   
</div>
<?php } ?>

<input id="input-upload-img3" type="file" name="file3" class="file" data-preview-file-type="text" disabled="disabled">
</div>
<div class="mb10">
<?php if($Gfile4!=="")
{
?>

<div class="file-preview">
   <div class="close fileinput-remove text-right removefile">×</div>
   <div class="file-preview-thumbnails">
   		<div class="file-preview-frame" id="preview-1460106475958-0">
   			<img src="<?php echo $actual_link."postedfile/".$Gfile4?>" class="file-preview-image" title="Penguins.jpg" alt="Penguins.jpg" style="width:auto;height:160px;">
		</div>
   </div>
   <div class="clearfix"></div>   <div class="file-preview-status text-center text-success"></div>
   
</div>
<?php } ?>

<input id="input-upload-img4" type="file" name="file4" class="file" data-preview-file-type="text" disabled="disabled">
</div>
<div class="mb10">

<?php if($Gfile5!=="")
{
?>

<div class="file-preview">
   <div class="close fileinput-remove text-right removefile">×</div>
   <div class="file-preview-thumbnails">
   		<div class="file-preview-frame" id="preview-1460106475958-0">
   			<img src="<?php echo $actual_link."postedfile/".$Gfile5?>" class="file-preview-image" title="Penguins.jpg" alt="Penguins.jpg" style="width:auto;height:160px;">
		</div>
   </div>
   <div class="clearfix"></div>   <div class="file-preview-status text-center text-success"></div>
   
</div>
<?php } ?>

<input id="input-upload-img5" type="file" name="file5" class="file" data-preview-file-type="text" disabled="disabled">
</div>
<p class="help-block">Add up to 5 photos. Use a real image of your product, not catalogs.</p>
</div>
</div>

<?php if(!isset($_SESSION['cid']))
{
?>
<div class="content-subheading"> <i class="icon-user fa"></i> <strong>Seller information</strong> </div>
 
<?php 
$nameS="";$emailS="";$hidenumberS="";$numberS="";$cityS="";$localityS="";
if(isset($_SESSION['cid']))
{
	$sqluserS=mysql_query("select * from tbl_users where userid='".$_SESSION['cid']."'");
	$resuserS=mysql_fetch_assoc($sqluserS);
	
	$nameS=$resuserS['fullname'];
	
	$emailS=$resuserS['email'];
	
	$hidenumberS=$resuserS['hidenumber'];
	
	
	$numberS=$resuserS['number'];
	
	$cityS=$resuserS['city'];
	
	$localityS=$resuserS['locality'];
	
}
?> 
 
<div class="form-group">
<label class="col-md-3 control-label" for="textinput-name">Name</label>
<div class="col-md-8">
<input id="textinput-name" name="name"  placeholder="Seller Name" class="form-control input-md" required="" type="text" value="<?php echo $nameS;?>">
</div>
</div>
 
<div class="form-group">
<label class="col-md-3 control-label" for="seller-email"> Email</label>
<div class="col-md-8">
<input id="seller-email" <?php if($emailS!=="") {  echo "readonly='readonly'";} ?> name="email" class="form-control" placeholder="Email" required="" type="text" value="<?php echo $emailS;?>">
<div class="checkbox">
<label>
<input type="checkbox" <?php if($hidenumberS=="on") { echo "checked"; } ?> name="hidenumber">
<small> Hide the phone number on this ads.</small> </label>
</div>
</div>
</div>


<div class="form-group">
<label class="col-md-3 control-label" for="seller-Number">Password</label>
<div class="col-md-8">
<input id="seller-Number" required="" name="password" placeholder="Enter Password" class="form-control input-md" type="password">
</div>
</div>


 
<div class="form-group">
<label class="col-md-3 control-label" for="seller-Number">Phone Number</label>
<div class="col-md-8">
<input id="seller-Number" pattern="[0-9.]+" name="number"  placeholder="Phone Number" class="form-control input-md" required="" value="<?php echo $numberS;?>" type="text">
</div>
</div>
 

 
<div class="form-group">
<label class="col-md-3 control-label" for="seller-area">City</label>
<div class="col-md-8">
<select id="citis" name="city" class="form-control" required="">
<option value="">Select City</option>
<?php $sqlcity=mysql_query("select * from tbl_cities where status='Enable' order by cityname asc");
      while($rescity=mysql_fetch_assoc($sqlcity))
	  {
?>
	<option <?php if($cityS==$rescity['city_id']) { echo "selected";} ?> value="<?php echo $rescity['city_id'];?>"><?php echo $rescity['cityname'];?></option>

<?php } ?>
</select>
</div>
</div>

<div id="local">
<div class="form-group">
<label class="col-md-3 control-label" for="seller-Location">Locality</label>
<div class="col-md-8"> 
<select id="seller-Location" name="locality" class="form-control" required="">
<option selected value="<?php echo $localityS;?>"><?php echo $localityS;?></option>
</select>
</div>
</div>
</div>


<?php } ?>




<?php /*?><div class="well">
<h3><i class=" icon-certificate icon-color-1"></i> Make your Ad Premium </h3>
<p>Premium ads help sellers promote their product or service by getting their ads more visibility with more
buyers and sell what they want faster.</p>
<div class="form-group">
<table class="table table-hover checkboxtable">
<?php $sqlpackage=mysql_query("select * from tbl_package where status='Enable' order by amount asc");
      while($respackage=mysql_fetch_assoc($sqlpackage))
	  {
		  
		  if($respackage['amount']>1)
		  {
?>

<tr>
	<td>
    	<div class="radio">
			<label>
				<input type="radio" <?php if($Gpackage==$respackage['pid']) { echo "checked";} ?> name="package" class="package" value="<?php echo $respackage['pid'];?>" required="">
				<strong><?php echo $respackage['name'];?></strong> 
            </label>
		</div>
    </td>
	<td>
    	<p><i class="fa fa-inr"></i> <b id="pack<?php echo $respackage['pid'];?>"><?php echo $respackage['amount'];?></b> for <?php echo $respackage['dnumber']." ".$respackage['duration'];?>	
        </p>
    </td>
</tr>

<?php 
		  }
} ?>



<tr>
<!--<td><div class="form-group">
<div class="col-md-8">
<select class="form-control" name="Method" id="PaymentMethod">
<option value="2">Select Payment Method</option>
<option value="3">Credit / Debit Card </option>
<option value="5">Paypal</option>
</select>
</div>
</div></td>-->
<?php 

	  $sqlspack=mysql_query("select * from tbl_package where pid='".$Gpackage."'");
	  $resspack=mysql_fetch_assoc($sqlspack);
      
	  
?>	  

<td id="pay"><p> <strong>Payable Amount : <i class='fa fa-inr'></i> <?php echo $resspack['amount'];?></strong></p></td>
</tr>
</table>
</div>
</div><?php */?>
 
<!--<div class="form-group">
<label class="col-md-3 control-label">Terms</label>
<div class="col-md-8">
<label class="checkbox-inline" for="checkboxes-0">
<input name="checkboxes" id="checkboxes-0" value="Remember above contact information." type="checkbox">
Remember above contact information. </label>
</div>
</div>-->
 
<div class="form-group">
<label class="col-md-3 control-label"></label>
<div class="col-md-8"> <button  id="button1id" name="post" type="submit" class="btn btn-success btn-lg">Submit</button> </div>
</div>
</fieldset>
</form>
</div>
</div>
</div>
</div>
 
<div class="col-md-3 reg-sidebar">
<div class="reg-sidebar-inner text-center">
<div class="promo-text-box"> <i class=" icon-picture fa fa-4x icon-color-1"></i>
<h3><strong>Post a Free Classified</strong></h3>
<p> Post your free online classified ads with us. Lorem ipsum dolor sit amet, consectetur adipiscing elit. </p>
</div>
<div class="panel sidebar-panel">
<div class="panel-heading uppercase"><small><strong>How to sell quickly?</strong></small></div>
<div class="panel-content">
<div class="panel-body text-left">
<ul class="list-check">
<li> Use a brief title and description of the item </li>
<li> Make sure you post in the correct category</li>
<li> Add nice photos to your ad</li>
<li> Put a reasonable price</li>
<li> Check the item before publish</li>
</ul>
</div>
</div>
</div>
</div>
</div> 
</div>
 
</div>
 
</div>

<?php include("footer.php");?>
<script src="<?php echo $actual_link;?>jquery.min.js" type="text/javascript"></script>
<script src="<?php echo $actual_link;?>assets/js/fileinput.min.js" type="text/javascript"></script>

<?php 
if($sqlpost==true)
	{
		
		
		?>
		<script>
        window.location="<?php echo $actual_link;?>package_select/<?php echo $lastas;?>";
        </script>
		<?php
	}
?>

<script>

$('input[name="file1"]').change(function(){
	
	
	
	$('#input-upload-img2').removeAttr("disabled");
	
});

$('input[name="file2"]').change(function(){
	
	$('#input-upload-img3').removeAttr("disabled");
	
});

$('input[name="file3"]').change(function(){
	
	$('#input-upload-img4').removeAttr("disabled");
	
});

$('input[name="file4"]').change(function(){
	
	$('#input-upload-img5').removeAttr("disabled");
	
});


/*$('input[name="file3"]').click(function(){
	$('input[name="file1"]').attr('required=""',true);
	$('input[name="file2"]').attr('required=""',true);
});
$('input[name="file4"]').click(function(){
	$('input[name="file1"]').attr('required=""',true);
	$('input[name="file2"]').attr('required=""',true);
	$('input[name="file3"]').attr('required=""',true);
});
$('input[name="file5"]').click(function(){
	$('input[name="file1"]').attr('required=""',true);
	$('input[name="file2"]').attr('required=""',true);
	$('input[name="file3"]').attr('required=""',true);
	$('input[name="file4"]').attr('required=""',true);
});
*/

// initialize with defaults
$("#input-upload-img1").fileinput();
$("#input-upload-img2").fileinput();
$("#input-upload-img3").fileinput();
$("#input-upload-img4").fileinput();
$("#input-upload-img5").fileinput();



$(".package").change(function(){
	
	var val=$(this).val();
	
	var amnt=$("#pack"+val).html();
	$("#pay").html("<p> <strong>Payable Amount : <i class='fa fa-inr'></i> "+amnt+"</strong></p>");

});

$("#maincategory").change(function(){
	
	var val=$(this).val();
	
	
	$.post("<?php echo $actual_link;?>ajax/category.php",{val:val},function(data){
		$("#cat").html(data);
	});

});

$("#cat").on('change','#category',function(){
	
	var val=$(this).val();
	$.post("<?php echo $actual_link;?>ajax/subcategory.php",{val:val},function(data){
		$("#sub").html(data);
	});

});


$(".panel-body").on("change",".maincategory1",function(){
	
	var val=$(this).val();
	
	var len=$(".desprod").length;
	
	var sm=val.concat(len); 
	
	
	$(this).siblings('.nearcat').addClass('cat_'+sm);
	$.post("<?php echo $actual_link;?>ajax/desirecat.php",{val:val,len:$(".desprod").length},function(data){
		$('.cat_'+sm).html(data);
	});

});

$(".nearcat").on('change','.category1',function(){
	
	var val=$(this).val();
	
	
	var len=$(".desprod").length;
	
	var sm=val.concat(len); 
	
	$(this).parent().siblings('.nearsubcat').addClass('subcat_'+sm);
	
	
	$.post("<?php echo $actual_link;?>ajax/desiresubcat.php",{val:val,len:$(".desprod").length},function(data){
		$('.subcat_'+sm).html(data);
		
	});

});

$("#addMore").click(function(){
var len=$(".desprod").length;

var newlen=parseInt(len)+parseInt(1);

	
	$.post("<?php echo $actual_link?>ajax/desireprod.php",{newlen:newlen},function(data){
	
	if($(".add_desire_p").html()=="")
	{
	$(".add_desire_p").html(data);
	}
	else
	{
		$(".add_desire_p").append(data);
	}
	});
});



$("input[name='exchangeType']").change(function(){

if($(this).val()=="exchange" || $(this).val()=="exchange_cash")
{
	$("#extrap").show();
	$("#fdep,#fmainc").attr('required',true);

}
else
{
	$("#extrap").hide();
	
	$("#fdep,#fmainc").attr('required',false);	
}

});



</script>

 <style>
 @media only screen and (max-width: 920px) {
	  .more
 {
	 margin-top:2%;
 }
  .more1
 {
	 margin-top:1%;
 }
 .ms
 {
	 margin-top:5%;
 }
	 
 }
 
 
 .more1
 {
	 margin-top:1%;
 }
 .more
 {
	 margin-top:5%;
 }
 
 </style>
 
 <script>
 $(".removefile").click(function(){
 
 $(this).parent().parent('.mb10').find('.file').removeAttr("disabled");
 $(this).parent().parent('.mb10').find('.file').css("background-color", "#16A085;")
 
 $(this).closest(".file-preview").remove();
 });
 </script>

<script>
$(".Cross").click(function(){

$(this).parent().prev('#crossAction').remove();

$(this).fadeOut();
});
</script>


