<?php 
include("header.php");
include("sidebar.php");

$msg="";$fullname="";$number="";$hidenumber="";$gender="";$address="";$postcode="";$city="";$locality="";$caption="Add"; $botton="add";$image="";
//echo'<pre>';print_r($_POST);
if(isset($_GET['id']))
{
	if(isset($_GET['action']))
	{
		$sql=mysql_query("delete from tbl_users where userid='".$_GET['id']."'");
		
		 $msg="User details delete successfully";
			
			?>
			<script>
			setTimeout(function(){
				window.location="paid_users.php";
				},2000);
			</script>
			<?php
		
	}
	else
	{
	
		$sqlcheck1=mysql_query("select * from tbl_users where userid='".$_GET['id']."'");
		$rescheck1=mysql_fetch_assoc($sqlcheck1);
		
		$fullname=$rescheck1['fullname'];
		$number=$rescheck1['number'];
		$hidenumber=$rescheck1['hidenumber'];
		$gender=$rescheck1['gender'];
		$email=$rescheck1['email'];
		$address=$rescheck1['address'];
		$postcode=$rescheck1['postcode'];
		$city=$rescheck1['city'];
		$locality=$rescheck1['locality'];
		
		
		$caption="Update"; $botton="update";
		if(isset($_POST['update']))
		{
			
			$hidenumber="";
			    if(isset($_POST['hidenumber']))
				{
					$hidenumber=$_POST['hidenumber'];
				}
				
				if($_FILES['file']['name']=="")
				{
					$update=mysql_query("update tbl_users set fullname='".$_POST['fullname']."',number='".$_POST['number']."',hidenumber='".$hidenumber."',gender='".$_POST['gender']."',email='".$_POST['email']."',address='".$_POST['address']."',postcode='".$_POST['postcode']."',city='".$_POST['city']."',locality='".$_POST['locality']."' where userid='".$_GET['id']."'");
				}
				else
				{
					
					move_uploaded_file($_FILES['file']['tmp_name'],"../userimage/".time().$_FILES['file']['name']);
					
					$update=mysql_query("update tbl_users set fullname='".$_POST['fullname']."',number='".$_POST['number']."',hidenumber='".$hidenumber."',gender='".$_POST['gender']."',email='".$_POST['email']."',address='".$_POST['address']."',postcode='".$_POST['postcode']."', image='".time().$_FILES['file']['name']."', city='".$_POST['city']."',locality='".$_POST['locality']."' where userid='".$_GET['id']."'");
				
				}
			
			
			
			
			
			$msg="User details update successfully";
			
			?>
			<script>
			setTimeout(function(){
				window.location="paid_users.php";
				},2000);
			</script>
			<?php
		}
	}
	
}



?>


  <!-- Page -->
  <div class="page animsition">
    <div class="page-header">
      <h1 class="page-title">Paid Users</h1>
      <ol class="breadcrumb">
        <li><a href="dashboard.php">Home</a></li>
        <li><a href="paid_users.php">Paid Users</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">Add Main Category</h3>
            </div>
            <div class="panel-body container-fluid">
              <form method="post" enctype="multipart/form-data">
                <div class="form-group form-material">
                  <label class="control-label" for="inputText">Full Name</label>
                  <input type="text" class="form-control" id="inputText" required name="fullname" value="<?php echo $fullname;?>" placeholder="Enter Full Name"
                  />
                </div>
                
                <div class="form-group form-material">
                  <label class="control-label" for="inputText">Contact Number</label>
                  <input type="text" class="form-control" id="inputText" required name="number" value="<?php echo $number;?>" placeholder="Enter Contact Name"
                  />
                </div>
                
                <div class="form-group form-material">
                  <label class="control-label" for="inputText">Number Hide</label>
                  <input type="checkbox" class="form-control"  name="hidenumber" value="<?php echo $number;?>" <?php if($hidenumber=="on") { echo "checked";} ?> />
                </div>
                
                <div class="form-group form-material">
                  <label class="control-label" for="inputText">Gender</label>
                    <select name="gender" class="form-control" required>
                        <option value="">Please Select</option>
                        <option <?php if($gender=="male") { echo "selected";}?> value="male">Male</option>
                        <option <?php if($gender=="female") { echo "selected";}?> value="female">Female</option>
                    
                    </select>
                </div>
                
                <div class="form-group form-material">
                  <label class="control-label" for="inputText">Email</label>
                  <input type="email" class="form-control" id="inputText" required name="email" value="<?php echo $email;?>" placeholder="Enter Email"
                  />
                </div>
                
                <div class="form-group form-material">
                  <label class="control-label" for="inputText">Address</label>
                  <textarea class="form-control" name="address" required value="<?php echo $address;?>" placeholder="Enter Address"
                  /></textarea>
                </div>
                
                
                
                
                
             
               
					
                <div class="form-group form-material">
                  <label class="control-label" for="inputText">City</label>
                    <select name="city" class="form-control" id="citis" required>
                        <option value="">Please Select</option>
                        <?php $sqlc=mysql_query("select * from tbl_cities");
							  while($resc=mysql_fetch_assoc($sqlc))
							  {
								  ?>
								  <option <?php  if($city==$resc['city_id']) { echo "selected";} ?> value="<?php echo $resc['city_id'];?>"><?php echo $resc['cityname'];?></option>
								  <?php
							  }
						?>
                    
                    </select>
                </div>
                <div id="local">
                <div class="form-group form-material">
                  <label class="control-label" for="inputText">Locality</label>
                    <select name="locality" class="form-control" required>
	    
                        <option value="<?php echo $locality;?>" selected="selected"><?php echo $locality;?></option>
                    
                    </select>
                </div>
                </div>
                
                
                <div class="form-group form-material">
                  <label class="control-label" for="inputText">Postcode</label>
                  <input type="text" class="form-control" id="postcode" required  name="postcode" value="<?php echo $postcode;?>" placeholder="Enter Postcode"
                  />
                  <p  id="posC"></p>
                </div>
                
                <div class="form-group">
                 <label class="control-label" for="inputText">Picture</label>
                 <input type="file" name="file">
                 <?php if($image!=="")
					{?>
					<img class="userImg" src="../userimage/<?php echo $image;?>" alt="user" height="70" width="70">
					<?php }
					else
					{
						?>
							<img class="userImg" src="../images/user.jpg" alt="user" >
						<?php
					}
					 ?>
                 
                </div>
                
                <div class="form-group form-material row">
                  <div class="col-xs-12 col-sm-4 col-lg-2">
                  <button type="submit" name="<?php echo $botton?>" class="btn btn-block btn-primary"><?php echo $caption?></button>
                  </div>
                </div>
              </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">Paid Users Details</h3>
        </header>
        <div class="panel-body">
          <table class="table table-hover dataTable table-striped width-full" data-plugin="dataTable">
            <thead>
              <tr>
                <th>Image</th>
                <th>Fullname</th>
                <th>Number</th>
                <th>Hidenumber</th>
                <th>Gender</th>
                <th>Email</th>
                <th>Address</th>
                <th>Postcode</th>
                <th>City</th>
                <th>Locality</th>
                <th>Date</th>
                <th>Action</th>
               
              </tr>
            </thead>
           
            <tbody>
              
              <?php
			  
			  $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']."' group by posted_userid");
			  
			  while($resads=mysql_fetch_assoc($sqlads))
			  {
			  
			  
			  $sqlmaincat=mysql_query("select * from tbl_users where userid='".$resads['posted_userid']."'");
			  
			  
			  if(mysql_num_rows($sqlmaincat))
			  {
				  
				 $resmaincat=mysql_fetch_assoc($sqlmaincat); 
			  ?>
              <tr>
                <td><?php if($resmaincat['image']!=="")
					{?>
					<img class="userImg" src="../userimage/<?php echo $resmaincat['image'];?>" alt="user" height="70" width="70">
					<?php }
					else
					{
						?>
							<img class="userImg" src="../images/user.jpg" alt="user" >
						<?php
					}
					 ?></td>
                <td><?php echo $resmaincat['fullname']?></td>
                <td><?php echo $resmaincat['number']?></td>
                <td><?php echo $resmaincat['hidenumber']?></td>
                <td><?php echo $resmaincat['gender']?></td>
                <td><?php echo $resmaincat['email']?></td>
                <td><?php echo $resmaincat['address']?></td>
                <td><?php echo $resmaincat['postcode']?></td>
                <td><?php 
				$sqlct=mysql_query("select * from tbl_cities where city_id='".$resmaincat['city']."'");
				$rescity=mysql_fetch_assoc($sqlct);
				echo $rescity['cityname']?></td>
                <td><?php echo $resmaincat['locality']?></td>
                <td><?php echo $resmaincat['date']?></td>
                
                <td><a href="paid_users.php?id=<?php echo $resmaincat['userid']?>" 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['userid']?>" type="button" class="btn btn-sm btn-icon btn-default btn-outline btn-round" data-toggle="tooltip" href="paid_users.php?id=<?php echo $resmaincat['userid']?>&action=delete"  data-original-title="Delete"><i class="icon wb-trash" aria-hidden="true"></i></a></td>
              </tr>
              <?php } }?>
            
             
            </tbody>
          </table>
        </div>
      </div>
    
    </div>
    
    
  </div>
  
 
  <!-- End Page -->


  <!-- Footer -->
<?php 
include("footer.php");
?>
<script>
$(".delete").click(function(){
var id=$(this).attr('id');

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

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



$("#postcode").keyup(function(){
	
	var c=$("select[name='city']").val();
	
	var l=$("select[name='locality']").val();
	if(c=="")
	{
		alert("please select city");
		return false();
	}
	else
	{
		if(l=="")
		{
			alert("please select locality");
			return false();
		}
		else
		{
			
			var z=$(this).val();
			if(z=="")
			{
				$("#posC").html("Please Enter Postcode");
				$("#posC").css("color","red");
			}
			else
			{
			
					$.post("<?php echo $actual_link;?>ajax/zipcheck.php",{c:c,l:l,z:z},function(data){
					//alert(data);
					$("#posC").html(data);
					if(data=="Postcode does not match")
					{
						$("button[name='update']").attr('disabled',true);
						$("#posC").css("color","red");
					}
					else
					{
						$("button[name='update']").attr('disabled',false);
						$("#posC").css("color","green");
					}
				});
			}
			
		}
	}
	
	
});


$("#citis").change(function(){

$.post("<?php echo $actual_link;?>ajax/ajax_locality.php",{city:$(this).val()},function(data){

	$("#local").html(data);
});
});

$(".icon_closes").click(function(){
$(".chatBox").hide();
});
</script>