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

$msg="";$name="";$status="";$caption="Add"; $botton="add";$mcid="";
//echo'<pre>';print_r($_REQUEST);exit;
if(isset($_GET['id']))
{
	$sqlcheck1=mysql_query("select * from tbl_cities where id='".$_GET['id']."'");
	$rescheck1=mysql_fetch_assoc($sqlcheck1);
	
	$mcid=$rescheck1['mcid'];
	$name=$rescheck1['name'];
	$status=$rescheck1['status'];
	
	$caption="Update"; $botton="update";
	
	if(isset($_POST['update']))
	{
		$maincategory=$_POST['maincategory'];
		$category=mysql_real_escape_string(ucwords($_POST['category']));
		
		$update=mysql_query("update tbl_cities set status='".$_POST['status']."',mcid='$maincategory',name='$category' where cid='".$_GET['id']."'");
		
		
		$msg="Country update successfully";
		
		?>
		<script>
        setTimeout(function(){
			window.location="category.php";
			},2000);
        </script>
		<?php
	}
	
}





?>


  <!-- Page -->
  <div class="page animsition">
    <div class="page-header">
      <h1 class="page-title">Cities</h1>
      <ol class="breadcrumb">
        <li><a href="dashboard.php">Home</a></li>
        <li><a href="countries.php">Cities</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
	}
    
	?>
    
    <div class="page-content">
      <!-- Panel Basic -->
      <div class="panel">
        <header class="panel-heading">
          <div class="panel-actions"></div>
          <h3 class="panel-title">Cities 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>Cities Name</th>
                <th>Status</th>
                <th>Action</th>
               
              </tr>
            </thead>
           
            <tbody>
              
              <?php
			  $i=1;
			  
			  $sqlmaincat=mysql_query("select * from tbl_cities");
			  if(mysql_num_rows($sqlmaincat))
			  {
			  while($resmaincat=mysql_fetch_assoc($sqlmaincat))
			  {?>
              <tr>
                <td><?php echo $i;?></td>
                
                <td><?php echo $resmaincat['cityname']?></td>
                <td id="sttus_<?php echo $resmaincat['city_id']?>"><?php echo $resmaincat['status']?></td>
                <td><a id="<?php echo $resmaincat['city_id']?>" type="button" class="btn btn-sm btn-icon btn-default btn-outline btn-round statuss" data-toggle="tooltip"  data-original-title="Change Status"><i class="icon wb-pencil" aria-hidden="true"></i></a>
               <a id="<?php echo $resmaincat['city_id']?>" 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>
$(".delete").click(function(){
var id=$(this).attr('id');

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

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

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

var st=$('#sttus_'+id).html();

if(st=="Enable")
{
	var changeBy="Disable";
}
else
{
	var changeBy="Enable";
}

$.post("ajax/change_city_status.php",{changeBy:changeBy,id:id},function(data){
	
	$('#sttus_'+id).html(changeBy);
});

});
</script>