<?php
//DB Data
include '../../ASEngine/AS.php';
if(!$login->isLoggedIn())
    header("Location: ../../login.php");
$user = new ASUser(ASSession::get("user_id"));
$userInfo = $user->getInfo();

//basic include files
require_once("../../../db.php");

//variables
$city_name = $_POST['city_name'];
$city_country = $_POST['city_country'];
$city_state = $_POST['city_state'];
$min_amount = $_POST['min_amount'];

if ($_FILES['image']['error'] == UPLOAD_ERR_OK) {	
	if(isset($_FILES['image'])){
		$errors= array();
		$file_name = $_FILES['image']['name'];
		$file_size =$_FILES['image']['size'];
		$file_tmp =$_FILES['image']['tmp_name'];
		$file_type=$_FILES['image']['type'];   
		$file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));
		
		$expensions= array("jpeg","jpg","png"); 		
		if(in_array($file_ext,$expensions)=== false){
			$errors[]="extension not allowed, please choose a JPEG or PNG file.";
		}
		if($file_size > 2097152){
		$errors[]='File size must be excately 2 MB';
		}				
		if(empty($errors)==true){
			move_uploaded_file($file_tmp,"../../images/topdestinations/".$file_name);
			
			mysqli_query($conn, "INSERT INTO cities (city_name, state_id, country_code, min_amount, image_path, city_image) VALUES('$city_name', '$city_state', '$city_country', '$min_amount', '/images/city.jpg', '$file_name')");
			
			mysqli_close($conn);
			
			header("Location: ../../cities.php?citymsn=added&tab=2");
		} else {
			header("Location: ../../cities.php?citymsn=error&errormsn=".implode($errors)."&tab=2");
		}
	} 
} else {
mysqli_query($conn, "INSERT INTO cities (city_name, state_id, country_code, min_amount, image_path, city_image) VALUES('$city_name', '$city_state', '$city_country', '$min_amount', '/images/city.jpg', 'top-destination.jpg')");

mysqli_close($conn);

header("Location: ../../cities.php?citymsn=added&tab=2");
}
?>