<?php 
include("header.php");
include("sidebar.php");
/*echo'<pre>';print_r($_POST);
echo'<pre>';print_r($_FILES);
exit;*/

$idcategory="";
if(isset($_POST['post']))
{
	//echo'<pre>';print_r($_POST);exit;
	
	$name=$_POST['name'];
	$email=$_POST['email'];
	$number=$_POST['number'];
	$city=$_POST['city'];
	$locality=$_POST['locality'];
	$hidenumber="";
	if(isset($_POST['hidenumber']) && $_POST['hidenumber']!=="")
	{
		$hidenumber=$_POST['hidenumber'];
	}
	
    $sqluser=mysql_query("select * from tbl_users where email='$email'");
	$resuser=mysql_fetch_assoc($sqluser);
	
		
	$insert=mysql_query("update tbl_users set fullname='$name',hidenumber='$hidenumber',number='$number',city='$city',locality='$locality' where email='$email'");
	
	$postid=$resuser['userid'];
		
	$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="";
	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;
	}
	
	
		
		//echo'<pre>';print_r($_FILES);

		//echo'<pre>';print_r($_POST);exit;
		
		if($filename1=="")
		{
			
			$upadtead=mysql_query("update tbl_ads set maincategory='".$_POST['maincategory']."',category='".$_POST['category']."',subcategory='".$_POST['subcategory']."',title='".$_POST['Adtitle']."',description='".$_POST['Ad_description']."',type='".$_POST['Adtype']."',price='".$_POST['price']."',negotiable='".$_POST['negotiable']."',conditions='".$_POST['condition']."',exchange_type='".$_POST['exchangeType']."',desire_products='".$ndesp."',des_maincat='".$ndesmainc."',des_cat='".$ndescat."',des_subcat='".$ndessubcat."',package='".$_POST['package']."' where ads_id='".$_GET['id']."'");
			
		}
		else
		{
			
			if($filename2=="")
			{
				
				$upadtead=mysql_query("update tbl_ads set maincategory='".$_POST['maincategory']."',category='".$_POST['category']."',subcategory='".$_POST['subcategory']."',title='".$_POST['Adtitle']."',description='".$_POST['Ad_description']."',type='".$_POST['Adtype']."',price='".$_POST['price']."',negotiable='".$_POST['negotiable']."',conditions='".$_POST['condition']."',exchange_type='".$_POST['exchangeType']."',file1='".$filename1."',desire_products='".$ndesp."',des_maincat='".$ndesmainc."',des_cat='".$ndescat."',des_subcat='".$ndessubcat."',package='".$_POST['package']."' where ads_id='".$_GET['id']."'");
				
				
			}
			else
			{
				if($filename3=="")
				{
					
					$upadtead=mysql_query("update tbl_ads set maincategory='".$_POST['maincategory']."',category='".$_POST['category']."',subcategory='".$_POST['subcategory']."',title='".$_POST['Adtitle']."',description='".$_POST['Ad_description']."',type='".$_POST['Adtype']."',price='".$_POST['price']."',negotiable='".$_POST['negotiable']."',conditions='".$_POST['condition']."',exchange_type='".$_POST['exchangeType']."',file1='".$filename1."',file2='".$filename2."',desire_products='".$ndesp."',des_maincat='".$ndesmainc."',des_cat='".$ndescat."',des_subcat='".$ndessubcat."',package='".$_POST['package']."' where ads_id='".$_GET['id']."'");
					
				}
				else
				{
					if($filename4=="")
					{
						
						$upadtead=mysql_query("update tbl_ads set maincategory='".$_POST['maincategory']."',category='".$_POST['category']."',subcategory='".$_POST['subcategory']."',title='".$_POST['Adtitle']."',description='".$_POST['Ad_description']."',type='".$_POST['Adtype']."',price='".$_POST['price']."',negotiable='".$_POST['negotiable']."',conditions='".$_POST['condition']."',exchange_type='".$_POST['exchangeType']."',file1='".$filename1."',file2='".$filename2."',file3='".$filename3."',desire_products='".$ndesp."',des_maincat='".$ndesmainc."',des_cat='".$ndescat."',des_subcat='".$ndessubcat."',package='".$_POST['package']."',admin_status='' where ads_id='".$_GET['id']."'");
						
						
					}
					else
					{
						if($filename5=="")
						{
							$upadtead=mysql_query("update tbl_ads set maincategory='".$_POST['maincategory']."',category='".$_POST['category']."',subcategory='".$_POST['subcategory']."',title='".$_POST['Adtitle']."',description='".$_POST['Ad_description']."',type='".$_POST['Adtype']."',price='".$_POST['price']."',negotiable='".$_POST['negotiable']."',conditions='".$_POST['condition']."',exchange_type='".$_POST['exchangeType']."',file1='".$filename1."',file2='".$filename2."',file3='".$filename3."',file4='".$filename4."',desire_products='".$ndesp."',des_maincat='".$ndesmainc."',des_cat='".$ndescat."',des_subcat='".$ndessubcat."',package='".$_POST['package']."' where ads_id='".$_GET['id']."'");
						}
						else
						{
							$upadtead=mysql_query("update tbl_ads set maincategory='".$_POST['maincategory']."',category='".$_POST['category']."',subcategory='".$_POST['subcategory']."',title='".$_POST['Adtitle']."',description='".$_POST['Ad_description']."',type='".$_POST['Adtype']."',price='".$_POST['price']."',negotiable='".$_POST['negotiable']."',conditions='".$_POST['condition']."',exchange_type='".$_POST['exchangeType']."',file1='".$filename1."',file2='".$filename2."',file3='".$filename3."',file4='".$filename4."',file5='".$filename5."',desire_products='".$ndesp."',des_maincat='".$ndesmainc."',des_cat='".$ndescat."',des_subcat='".$ndessubcat."',package='".$_POST['package']."' where ads_id='".$_GET['id']."'");
						}
					}
				}
			}
		}
	
	
	//$sqlpost=mysql_query("update  tbl_ads set (posted_userid='$postid',maincategory='".$_POST['maincategory']."',category='".$_POST['category']."',subcategory='".$_POST['subcategory']."',title='".$_POST['Adtitle']."',description='".$_POST['Ad_description']."',type='".$_POST['Adtype']."',price='".$_POST['price']."',negotiable='".$_POST['negotiable']."',conditions='".$_POST['condition']."',exchange_type='".$_POST['exchangeType']."',file1='".$filename1."',file2='".$filename2."',file3='".$filename3."',file4='".$filename4."',file5='".$filename5."',desire_products='$ndesp',des_maincat='$ndesmainc',des_cat='$ndescat',des_subcat='$ndessubcat',package='".$_POST['package']."' where ads_id='".$_GET['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())");
	}
	*/
	
}



  



$msg="";$caption="Update"; $botton="update";$posted_userid="";$maincategory="";$postdate="";$packname="";$desire_products="";$des_maincat="";$des_cat="";$des_subcat="";$file5="";$file4="";$file3="";$file2="";$file1="";$exchange_type="";$conditions="";$negotiable="";$price="";$type="";$description="";$title="";$category="";$subcategory="";$derireps=array();
//echo'<pre>';print_r($_REQUEST);exit;
if(isset($_GET['id']))
{
	if(isset($_GET['action']))
	{
		
		
		$delete=mysql_query("delete from tbl_ads where ads_id='".$_GET['id']."'");
		
		 $msg="Ads details delete successfully";
			
			?>
			<script>
			
			window.location="nonpaid_ads.php";
			/*setTimeout(function(){
				window.location="ads.php";
				},2000);*/
			</script>
			<?php
		
	}
	else
	{
	
	$sqlcheck1=mysql_query("select * from tbl_ads where ads_id='".$_GET['id']."'");
	$rescheck1=mysql_fetch_assoc($sqlcheck1);
	
	$posted_userid=$rescheck1['posted_userid'];
	
	
	$sqlmaincat=mysql_query("select * from tbl_maincategory where mcid='".$rescheck1['maincategory']."'");
	$resmaincat=mysql_fetch_assoc($sqlmaincat);
	
	$maincategory=$resmaincat['name'];
	
	$sqlcat=mysql_query("select * from tbl_category where cid='".$rescheck1['category']."'");
	$rescat=mysql_fetch_assoc($sqlcat);
	
	
	$category=$rescat['name'];

	
	
	$sqlsubcat=mysql_query("select * from tbl_subcategory where sid='".$rescheck1['subcategory']."'");
	$ressubcat=mysql_fetch_assoc($sqlsubcat);
	
	
	$subcategory=$ressubcat['name'];
	
	
	$title=$rescheck1['title'];
	
	
	$description=$rescheck1['description'];
	
	$type=$rescheck1['type'];
	
	$price=$rescheck1['price'];
	
	
	$negotiable=$rescheck1['negotiable'];
	
	$conditions=$rescheck1['conditions'];
	
	$exchange_type=$rescheck1['exchange_type'];
	
	$file1=$rescheck1['file1'];
	
	$file2=$rescheck1['file2'];
	
	$file3=$rescheck1['file3'];
	
	$file4=$rescheck1['file4'];
	
	$file5=$rescheck1['file5'];
	
	$file5=$rescheck1['file5'];
		
	$derireps=explode(",",$rescheck1['desire_products']);
	
	$package=$rescheck1['package'];
	
	$sqlpackage=mysql_query("select * from tbl_package where pid='".$package."'");
	$respackage=mysql_fetch_assoc($sqlpackage);
	
	$packname=$respackage['name'];
	
	$postdate=$rescheck1['postdate'];
	
	
	$sqlgcat=mysql_query("select * from tbl_category where cid='".$rescheck1['category']."'");
	$resgcat=mysql_fetch_assoc($sqlgcat);
	
	$idcategory=$rescheck1['category'];
	
	$sqlgsubcat=mysql_query("select * from tbl_subcategory where sid='".$rescheck1['subcategory']."'");
	$resgsubcat=mysql_fetch_assoc($sqlgsubcat);
	
	$idsubcategory=$rescheck1['subcategory'];
	
	$Gcategory=$resgcat['name'];
	
	$Gsubcategory=$resgsubcat['name'];
	}

	
	
	
}

?>


  <!-- Page -->
  <div class="page animsition">
    <div class="page-header">
      <h1 class="page-title">Non-Paid Ads</h1>
      <ol class="breadcrumb">
        <li><a href="dashboard.php">Home</a></li>
        <li><a href="nonpaid_ads.php">Non-Paid Ads</a></li>
      </ol>
     <!-- <div class="page-header-actions">
        
        <button type="button" class="btn btn-sm btn-icon btn-default btn-outline btn-round"
        data-toggle="tooltip" data-original-title="Refresh">
          <i class="icon wb-refresh" aria-hidden="true"></i>
        </button>
        <button type="button" class="btn btn-sm btn-icon btn-default btn-outline btn-round"
        data-toggle="tooltip" data-original-title="Setting">
          <i class="icon wb-settings" aria-hidden="true"></i>
        </button>
      </div>-->
    </div>
    <?php if($msg==!"")
	{
		
		?>
			<div class="alert alert-info alert-dismissible" role="alert">
                  <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                  </button>
                  <?php echo $msg;?>
                </div>
		<?php
	}
    
	
	if(isset($_GET['id']))
	{
	?>
    
    
    <div class="page-content container-fluid">
      <div class="row">
        <div class="col-sm-12">
          <!-- Panel Static Lables -->
          <div class="panel">
            <div class="panel-heading">
              <h3 class="panel-title">Non-Paid Ads</h3>
            </div>
            <div class="panel-body container-fluid">
              <form class="form-horizontal" method="post" enctype="multipart/form-data">
                <fieldset>
                 
                <div class="form-group">
                <label class="col-md-2 control-label">Main Category</label>
                <div class="col-md-10">
                
                <select name="maincategory" id="maincategory" class="form-control" required>
                <option value="0" 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($rescheck1['maincategory']==$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-2 control-label">Category</label>
                <div class="col-md-10">
                <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-2 control-label">Sub Category</label>
                <div class="col-md-10">
                <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-2 control-label" for="Adtitle">Ad title</label>
                <div class="col-md-10">
                <input id="Adtitle"  name="Adtitle" placeholder="Ad title" class="form-control input-md" value="<?php echo $title;?>" required="" 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-2 control-label" for="textarea">Describe ad </label>
                <div class="col-md-10">
                <textarea class="form-control" id="textarea" value="<?php echo $description;?>" name="Ad_description">Describe what makes your ad unique</textarea>
                </div>
                </div>
                
                
                <div class="form-group">
                <label class="col-md-2 control-label">Add Type</label>
                <div class="col-md-10">
                <label class="radio-inline" for="radios-0">
                <input name="Adtype" required id="radios-0" value="used" type="radio" <?php if($type=="used") { echo "checked='checked'";} ?>>
                Used </label>
                <label class="radio-inline" for="radios-1">
                <input name="Adtype" required id="radios-1" value="new" type="radio" <?php if($type=="new") { echo "checked='checked'";} ?>>
                New </label>
                </div>
                </div>
                 
                <div class="form-group">
                <label class="col-md-2 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" name="price" class="form-control" value="<?php echo $price;?>" placeholder="placeholder" required="" type="text">
                </div>
                </div>
                <div class="col-md-4">
                <div class="checkbox">
                <label>
                <input type="checkbox" <?php if($negotiable=="on") { echo "checked='checked'";} ?> name="negotiable">Negotiable </label>
                </div>
                </div>
                </div>
                
                <div class="form-group">
                <label class="col-md-2 control-label" for="condition">Condition</label>
                <div class="col-md-10">
                
                <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($conditions=="Not Working") { echo "selected='selected'";} ?> value="Not Working">Not Working</option>
                    <option <?php if($conditions=="Functional") { echo "selected='selected'";} ?> value="Functional">Functional</option>
                    <option <?php if($conditions=="Good") { echo "selected='selected'";} ?> value="Good">Good</option>
                    <option <?php if($conditions=="Very Good") { echo "selected='selected'";} ?> value="Very Good">Very Good</option>
                    <option <?php if($conditions=="Excellent") { echo "selected='selected'";} ?> value="Excellent">Excellent</option>
                </select>
                </div>
                </div>
                
                <div class="form-group">
                <label class="col-md-2 control-label" for="transaction">Transaction</label>
                <div class="col-sm-8">
                    <label class="radio-inline selected">
                        <input <?php if($exchange_type=="exchange") { echo "checked='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($exchange_type=="exchange_cash") { echo "checked='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($exchange_type=="cash") { echo "checked='checked'";} ?> name="exchangeType" value="cash" type="radio" required><span class="transaction-type">Cash only</span>
                    </label>
                </div>
                </div>
                 
                <div class="form-group">
                <label class="col-md-2 control-label" for="textarea"> Picture </label>
                <div class="col-md-10">
                 <div class="col-md-12">
               		<div class="mb10">
                
               
                <div class="col-md-3">
				<?php if($file1!=="")
				{?>
                	<img src="../postedfile/<?php echo $file1;?>" width="70" height="70">
                <?php } ?>
                </div>
                <div class="col-md-9">
                   <div class="form-group form-material floating">
                      <input type="text" class="form-control" readonly="" />
                      <input id="input-upload-img1" type="file" name="file1" value="<?php echo $file1;?>">
                      <label class="floating-label">Browse..</label>
                    </div>
                    </div>
                </div>
                </div>
                 
                 <div class="col-md-12">
                	<div class="mb10">
                    	<div class="col-md-3">
							 <?php if($file2!=="")
                            {?>
                             <img src="../postedfile/<?php echo $file2;?>" width="70" height="70">
                             <?php } ?>
                       </div>
                       <div class="col-md-9"> 
                			<div class="form-group form-material floating">
                      <input type="text" class="form-control" readonly="" />
                      <input id="input-upload-img2" type="file" name="file2" class="file" value="<?php echo $file2;?>" data-preview-file-type="text" <?php if($file1!=="") { }else{?> disabled="disabled" <?php } ?>>
                      <label class="floating-label">Browse..</label>
                    </div>
                            
                            
                       </div>     
                </div>
                 </div>
                
                 
                 <div class="col-md-12">
                	<div class="mb10">
                    	<div class="col-md-3">
							 <?php if($file3!=="")
                            {?>
                             <img src="../postedfile/<?php echo $file3;?>" width="70" height="70">
                             <?php } ?>
                       </div>
                       <div class="col-md-9"> 
                			<div class="form-group form-material floating">
                              <input type="text" class="form-control" readonly="" />
                              <input id="input-upload-img2" type="file" name="file3" class="file" value="<?php echo $file3;?>" data-preview-file-type="text" <?php if($file2!=="") { }else{?> disabled="disabled" <?php } ?>>
                              <label class="floating-label">Browse..</label>
                            </div>
                       </div>     
                </div>
                 </div>
                 
                 
                 <div class="col-md-12">
                	<div class="mb10">
                    	<div class="col-md-3">
							 <?php if($file4!=="")
                            {?>
                             <img src="../postedfile/<?php echo $file4;?>" width="70" height="70">
                             <?php } ?>
                       </div>
                       <div class="col-md-9"> 
                			<div class="form-group form-material floating">
                              <input type="text" class="form-control" readonly="" />
                              <input id="input-upload-img2" type="file" name="file4" class="file" value="<?php echo $file4;?>" data-preview-file-type="text" <?php if($file3!=="") { }else{?> disabled="disabled" <?php } ?>>
                              <label class="floating-label">Browse..</label>
                            </div>
                            
                            
                       </div>     
                </div>
                 </div>
                 <br>
                
                 
                 <div class="col-md-12">
                	<div class="mb10">
                    	<div class="col-md-3">
							 <?php if($file5!=="")
                            {?>
                             <img src="../postedfile/<?php echo $file5;?>" width="70" height="70">
                             <?php } ?>
                       </div>
                       <div class="col-md-9"> 
                            <div class="form-group form-material floating">
                              <input type="text" class="form-control" readonly="" />
                               <input id="input-upload-img2" type="file" name="file5" class="file" value="<?php echo $file5;?>" data-preview-file-type="text" <?php if($file4!=="") { }else{?> disabled="disabled" <?php } ?>>
                              <label class="floating-label">Browse..</label>
                            </div>
                       </div>     
                </div>
                 </div>
                 
                
                	<p class="help-block">Add up to 5 photos. Use a real image of your product, not catalogs.</p>
                </div>
                </div>
                <div class="content-subheading"> <i class="icon-user fa"></i> <strong>Seller information</strong> </div>
                 
                <?php 
                $nameS="";$emailS="";$hidenumberS="";$numberS="";$cityS="";$localityS="";
                
				$sqluserS=mysql_query("select * from tbl_users where userid='".$posted_userid."'");
				$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-2 control-label" for="textinput-name">Name</label>
                <div class="col-md-10">
                <input id="textinput-name" name="name" placeholder="Seller Name" readonly="readonly" class="form-control input-md" required="" type="text" value="<?php echo $nameS;?>">
                </div>
                </div>
                 
                <div class="form-group">
                <label class="col-md-2 control-label" for="seller-email"> Email</label>
                <div class="col-md-10">
                <input id="seller-email" name="email" class="form-control" readonly="readonly" placeholder="Email" required="" type="text" value="<?php echo $emailS;?>">
                <div class="checkbox">
                <label>
                <input type="checkbox" <?php if($hidenumberS=="on") { echo "checked"; } ?> readonly="readonly" onclick="return false"  name="hidenumber">
                <small> Hide the phone number on this ads.</small> </label>
                </div>
                </div>
                </div>
                 
                <div class="form-group">
                <label class="col-md-2 control-label" for="seller-Number">Phone Number</label>
                <div class="col-md-10">
                <input id="seller-Number" name="number" readonly="readonly" 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-2 control-label" for="seller-area">City</label>
                <div class="col-md-10">
                <select id="citis" name="city" class="form-control" readonly="readonly">
                <?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-2 control-label" for="seller-Location">Locality</label>
                <div class="col-md-10">
                <select id="seller-Location" name="locality" class="form-control" readonly="readonly">
                <option selected value="<?php echo $localityS;?>"><?php echo $localityS;?></option>
                </select>
                </div>
                </div>
                </div>
                
                
                
                <div class="form-group" id="extrap">
                <label class="col-md-2 control-label" for="seller-Location">Want In Return</label>
                
                <div class="col-md-10">
                    <div class="panel panel-default">
                        <div class="panel-body">
                           
                           	<?php 
							$Edes_maincat=explode(",",$rescheck1['des_maincat']);
							$Edes_cat=explode(",",$rescheck1['des_cat']);
							$Edes_subcat=explode(",",$rescheck1['des_subcat']);
							
							foreach($derireps as $key=>$desp)
							{
								
								
								$sqlmain1=mysql_query("select * from tbl_maincategory where mcid='".$Edes_maincat[$key]."'");
								$resmain1=mysql_fetch_assoc($sqlmain1);
								
								
								
								$sqlcat1=mysql_query("select * from tbl_category where cid='".$Edes_cat[$key]."'");
								$rescat1=mysql_fetch_assoc($sqlcat1);
								
								
								
								$sqlsubcat1=mysql_query("select * from tbl_subcategory where sid='".$Edes_subcat[$key]."'");
								$ressubcat1=mysql_fetch_assoc($sqlsubcat1);
								
								
								$desire_products=$desp;
								
								$des_maincat=$resmain1['name'];
								
								$des_cat=$rescat1['name'];
								
								$des_subcat=$ressubcat1['name'];
								
								
								?>
                                <div id="crossAction">
								 <div class="col-md-5">
                                    <input type="text"  name="desire_product[]" value="<?php echo $desire_products;?>" class="form-control desprod" id="fdep" required>
                                </div>
                                 <div class="col-md-5 ms">
                                <select name="desire_maincat[]" class="form-control maincategory1" id="fmainc" required>
                                    <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($Edes_maincat[$key]==$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" required>
                                    <option value="">Select Category</option>
                                    <option  selected='selected' value="<?php echo $Edes_cat[$key]?>"><?php echo $des_cat;?></option>
                                </select>
                              </div>  
                              
                              <div class="nearsubcat">
                                
                                 <select name="desire_subcat[]" class="form-control more1" required>
                                    <option value="">Please Select</option>
                                 
                                    
                                    <option  selected='selected' value="<?php echo $Edes_subcat[$key];?>"><?php echo $des_subcat;?></option>
                                   
                                </select>
                              
                             </div>   
                              <!-- <div class="nearcat">
                               </div>
                                <div class="nearsubcat">
                                </div>-->
                            </div>
                               </div>
                               
                               <?php if($key>0)
							   {
							   ?>
                                <div class="col-md-2"> 
								
                               <a class="Cross pull-right" style="color:#89bceb; font-weight:bold; font-size:20px;">&times;</a>
                               </div>    
                               
									<?php
							   }
								
								
							}
							
							?>
                           
                            
                             <div class="add_desire_p" style="margin-top:30px;">
                             </div>
                            <div class="col-md-10">
                            <a class="btn btn-success pull-left more" id="addMore">Add More</a>
                            </div>
                        </div>
                    </div>
                </div>                 
                </div>
                
                <div class="well">
                <h3><i class=" icon-certificate icon-color-1"></i> Ad Premium </h3>
                
                <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))
                      {
                ?>
                
                <tr>
                    <td>
                        <div class="radio">
                            <label>
                                <input readonly="readonly" type="radio" <?php if($package==$respackage['pid']) { echo "checked='checked'"; } ?> required name="package" class="package" value="<?php echo $respackage['pid'];?>">
                                <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-10">
                <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>-->
                
                </tr>
                </table>
                </div>
                </div>
                 
                <!--<div class="form-group">
                <label class="col-md-2 control-label">Terms</label>
                <div class="col-md-10">
                <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-2 control-label"></label>
                <div class="col-md-10"> <button  id="button1id" name="post" type="submit" class="btn btn-success btn-lg">Submit</button> </div>
                </div>
                </fieldset>
              </form>
              
            </div>
          </div>
          <!-- End Panel Static Lables -->
        </div>

        
      </div>
    </div>
    
    <?php } ?>
    
    <div class="page-content">
      <!-- Panel Basic -->
      <div class="panel">
        <header class="panel-heading">
          <div class="panel-actions"></div>
          <h3 class="panel-title">Non-Paid Ads Details</h3>
        </header>
        <div class="panel-body">
          <table class="table table-hover dataTable table-striped width-full" data-plugin="dataTable">
            <thead>
              <tr>
                <th>Sr</th>
                
                <th>Image</th>
                
                <th>Customer</th>
                <th>Main Category</th>
                <th>Category</th>
                <th>Subcategory</th>
                <th>Title</th>
                
                <th>Description</th>
                
                <th>Price</th> 
              
                <th>Type</th>
                
                
                <th>Negotiable</th>
               
               
                
                <th>Exchange Type</th>
                
                 
                
                <!--<th>File1</th>
                
                <th>File2</th>
                
                <th>File3</th>
                
                <th>File4</th>
                
                <th>File5</th>-->
                
                <th>Desire Products/Maincategory/Category/Subcategory</th>
                
                <th>Package</th>
               
                <th>Postdate</th>
                 <th>Action</th>
             <!--   <th>Admin_status</th>-->
                
              
               
              </tr>
            </thead>
           
            <tbody>
              
              <?php
			  $i=1;
			  
			  $SQL=mysql_query("select * from tbl_package where amount<1 and status='Enable'");
			  $RES=mysql_fetch_assoc($SQL);
			  
			  $sqlads=mysql_query("select * from tbl_ads where admin_status='Approved' and package='".$RES['pid']."'");
			  if(mysql_num_rows($sqlads))
			  {
			  while($resads=mysql_fetch_assoc($sqlads))
			  {?>
              <tr>
                <td><?php echo $i;?></td>
                
                <td><img src="../postedfile/<?php echo $resads['file1'];?>" height="70" width="70"></td>
                
                <td><?php 
				$sqlmain=mysql_query("select * from tbl_users where userid='".$resads['posted_userid']."'");
				$resmain=mysql_fetch_assoc($sqlmain);
				 echo $resmain['fullname']?></td>
                 
                <td><?php $sqlmaincat=mysql_query("select * from tbl_maincategory where mcid='".$resads['maincategory']."'");
				$resmaincat=mysql_fetch_assoc($sqlmaincat);
				 echo $resmaincat['name']?></td>
                 
                <td><?php $sqlcat=mysql_query("select * from tbl_category where cid='".$resads['category']."'");
				$rescat=mysql_fetch_assoc($sqlcat);
				 echo $rescat['name']?></td>
                 
                 
                 <td><?php $sqlsubcat=mysql_query("select * from tbl_subcategory where sid='".$resads['subcategory']."'");
				   $ressubcat=mysql_fetch_assoc($sqlsubcat);
				 echo $ressubcat['name']?></td>
                 
                 
                <td><?php echo $resads['title'];?></td>
                
                
                
                <td><?php echo $resads['description'];?></td>
                
                <td><?php echo $resads['price'];?></td>
                
                
               <td><?php echo $resads['type'];?></td>
                
                
                
                <td><?php echo $resads['negotiable'];?></td>
                
                
                
                
                <td><?php echo $resads['exchange_type'];?></td>
                
                
                
                <!--<td><?php echo $resads['file1'];?></td>
                
                <td><?php echo $resads['file2'];?></td>
                
                <td><?php echo $resads['file3'];?></td>
                
                <td><?php echo $resads['file4'];?></td>
                
                <td><?php echo $resads['file5'];?></td>-->
                
                <td><?php  $resads['desire_products'];
				
				$derireps=explode(",",$resads['desire_products']);
				$Edes_maincat=explode(",",$resads['des_maincat']);
				$Edes_cat=explode(",",$resads['des_cat']);
				$Edes_subcat=explode(",",$resads['des_subcat']);
				
				foreach($derireps as $key=>$desp)
				{
					
					
					$sqlmain1=mysql_query("select * from tbl_maincategory where mcid='".$Edes_maincat[$key]."'");
					$resmain1=mysql_fetch_assoc($sqlmain1);
					
					
					
					$sqlcat1=mysql_query("select * from tbl_category where cid='".$Edes_cat[$key]."'");
					$rescat1=mysql_fetch_assoc($sqlcat1);
					
					
					
					$sqlsubcat1=mysql_query("select * from tbl_subcategory where sid='".$Edes_subcat[$key]."'");
				    $ressubcat1=mysql_fetch_assoc($sqlsubcat1);
					
					echo "<br>".$desp."/".$resmain1['name']."/".$rescat1['name']."/".$ressubcat1['name']."<br>";
				}
				
				
				?></td>
                
                <td><?php 
				$sqlpackage=mysql_query("select * from tbl_package where pid='".$resads['package']."'");
				$respackage=mysql_fetch_assoc($sqlpackage);
				
				echo $respackage['name'];?></td>
                
                <td><?php echo $resads['postdate'];?></td>
                
                <td>
               
                    <a type="button" class="btn btn-sm btn-icon btn-default btn-outline btn-round" data-toggle="tooltip"  data-original-title="Edit" href="nonpaid_ads.php?id=<?php echo $resads['ads_id'];?>" ><i class="icon wb-pencil" aria-hidden="true"></i></a>
                    <a type="button" class="btn btn-sm btn-icon btn-default btn-outline btn-round" data-toggle="tooltip"  data-original-title="Delete" href="nonpaid_ads.php?id=<?php echo $resads['ads_id']?>&action=delete" id="<?php echo $resads['ads_id'];?>"><i class="icon wb-trash" aria-hidden="true"></i></a>
				<?php //echo $resads['admin_status'];?></td>
                
                
                
                
                
                
                <!--<td><a href="pending_nonpaid_ads.php?id=<?php echo $resmaincat['cid']?>" type="button" class="btn btn-sm btn-icon btn-default btn-outline btn-round" data-toggle="tooltip"  data-original-title="Edit"><i class="icon wb-pencil" aria-hidden="true"></i></a>
               <a id="<?php echo $resmaincat['cid']?>" type="button" class="btn btn-sm btn-icon btn-default btn-outline btn-round delete" data-toggle="tooltip"  data-original-title="Delete"><i class="icon wb-trash" aria-hidden="true"></i></a></td>-->
              </tr>
              <?php 
			  $i++;
			  } }?>
            
             
            </tbody>
          </table>
        </div>
      </div>
    
    </div>
    
    
  </div>
  
 
  <!-- End Page -->


  <!-- Footer -->
<?php 
include("footer.php");
?>

<script>
$("#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);
	});

});


$(".delete").click(function(){
var id=$(this).attr('id');

$(this).closest('tr').fadeOut();

$.post("ajax/ajax_delete_ads.php",{id:id},function(data){
	//alert(data);
	
	});
});


$(".Approve").click(function(){
	
	var vals=$(this).attr('value');
	
	if(vals=="approve")
	{
		$(this).attr('value','unapprove');
		$(this).html('Unapprove');
		$("#td_"+$(this).attr('id')).html('Approved');
	}
	else
	{
		$(this).attr('value','approve');
		$(this).html('Approve');
		$("#td_"+$(this).attr('id')).html('Unapproved');
	}
	
	
	
$.post("ajax/change_status.php",{id:$(this).attr('id'),value:vals},function(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);	
}

});


$('input[name="file1"]').change(function(){
	
	//$(this).closest(".col-md-3").html("");
	
	$('#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");
	
});


</script>



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

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

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