<?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
$hotel_name = $_POST['hotel_name'];
$hotel_des = $_POST['hotel_description'];
$hotel_information = $_POST['hotel_information'];
$hotel_price = $_POST['hotel_price'];
$hotel_tax = $_POST['hotel_tax'];
$hotel_country = $_POST['hotel_country'];
$hotel_city = $_POST['hotel_city'];
$hotel_state = $_POST['city_state'];
$hotel_address = $_POST['hotel_address'];
$hotel_zipcode = $_POST['hotel_zipcode'];
$longitud = $_POST['longitud'];
$latitud = $_POST['latitud'];
$stars = $_POST['stars'];
$max_adults = $_POST['max_adults'];
$max_children = $_POST['max_children'];
$max_guests = $_POST['max_guests'];
$max_rooms = $_POST['max_rooms'];
$cancel = $_POST['hotel_policy_cancel'];

$policy_cancel = mysqli_escape_string ($conn, $cancel);

$hotel_description = mysqli_escape_string($conn, $hotel_des);
$hotel_info = mysqli_escape_string($conn, $hotel_information);

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,"../../hotelimages/".$file_name);
			
			mysqli_query($conn, "INSERT INTO hotels (account_id, ota_default, hotel_name, hotel_short_description, hotel_information, hotel_low_price, hotel_country, hotel_state, hotel_city, hotel_address, hotel_beach, hotel_zipcode, longitud, latitud, hotel_stars, max_adults, max_children, max_guests, max_rooms, policy_cancel, hotel_tax,hotel_image_path) VALUES('1', 'BK',  '$hotel_name', '$hotel_description', '$hotel_info', '$hotel_price', '$hotel_country', '$hotel_state', '$hotel_city', '$hotel_address', '0', '$hotel_zipcode', '$longitud', '$latitud', '$stars', '$max_adults', '$max_children', '$max_guests', '$max_rooms', '$policy_cancel', '$hotel_tax', '$file_name')");
			
			mysqli_close($conn);
			
			header("Location: ../../hotels.php?hotelmsn=added&tab=2");
		} else {
			header("Location: ../../hotels.php?hotelmsn=error&errormsn=".implode($errors)."&tab=2");
		}
	} 
} else {
mysqli_query($conn, "INSERT INTO hotels (account_id, ota_default, hotel_name, hotel_short_description, hotel_information, hotel_low_price, hotel_country, hotel_state, hotel_city, hotel_address, hotel_beach, hotel_zipcode, longitud, latitud, hotel_stars, max_adults, max_children, max_guests, max_rooms, policy_cancel, hotel_tax, hotel_image_path) VALUES('1', 'BK', '$hotel_name', '$hotel_description', '$hotel_info', '$hotel_price', '$hotel_country', '$hotel_state', '$hotel_city', '$hotel_address', '0', '$hotel_zipcode', '$longitud', '$latitud', '$stars', '$max_adults', '$max_children', '$max_guests', '$max_rooms', '$policy_cancel', '$hotel_tax', 'city_hotel_icon70x70.png')");

mysqli_close($conn);

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