<?php
include('../helpers/init.php');

if(isset($_POST['addCity'])){
	$error = "";
    $title = $_POST['name'];
    $name = str_replace("'","",$_POST['name']);
	$name = str_replace('"','\"',$name);
	$slug = slug($name);
	$clients = mysqli_query($con,"select * from tbl_city where slug='$slug'");
	if(num_rows($clients)){
			header('Location:../pages/city.php?&result=duplicate'); 
	}
    else
    {
    $sql = "insert into tbl_city(city_name,slug) values('$title','$slug')";
		if(query($sql)){
			header('Location:../pages/city.php?result=success');
		}else{
			$error = error();
			header('Location:../pages/city.php?result=failuer');
		}
    }	
	
}
//----------- Add City Ends Here --------------


if(isset($_GET['action']) && $_GET['action']=="delCity"){
	$id=$_GET['city_id'];
	$data = getWhere("clients","city",$id);
    if(num_rows($data)){
		$error = " City Cannot be deleted because ".num_rows($data)." clients are added in this product.";
		header("Location:../pages/city.php?result=failer&message=".$error);
	}
    else
    {
   
		$sql = "delete from tbl_city where city_id=$id";
        
		if(query($sql)){  
			header('Location:../pages/city.php?result=dsuccess');
		}else{
			header('Location:../pages/city.php?result=failure');
		}
	}
}

?>