<?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 Post
$hotel_id = $_POST['hotel_id'];
$hotel_name = $_POST['hotel_name'];
//$expidia_id = $_POST['expidia_id'];
$hotel_desc = $_POST['hotel_description'];
$hotel_information = $_POST['hotel_information'];
$hotel_price = $_POST['hotel_price'];
$hotel_country = $_POST['hotel_country'];
$hotel_state = $_POST['hotel_state'];
$hotel_city = $_POST['hotel_city'];
$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'];
$hotel_tax = $_POST['hotel_tax'];
$cancel = $_POST['hotel_policy_cancel'];

$policy_cancel = mysqli_escape_string ($conn, $cancel);
$hotel_description = mysqli_escape_string ($conn, $hotel_desc);
$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, "UPDATE hotels SET hotel_name = '$hotel_name', hotel_short_description = '$hotel_description', hotel_information = '$hotel_info', hotel_low_price = '$hotel_price', hotel_country = '$hotel_country', hotel_state = '$hotel_state', hotel_city = '$hotel_city', hotel_address = '$hotel_address', hotel_zipcode = '$hotel_zipcode', longitud = '$longitud', latitud = '$latitud', hotel_stars = '$stars', max_adults = '$max_adults', max_children = '$max_children', max_guests = '$max_guests', max_rooms = '$max_rooms', policy_cancel = '$policy_cancel', hotel_tax = '$hotel_tax', hotel_image_path = '$file_name' WHERE hotel_id = $hotel_id");
			
			header("Location: ../../manage-hotel.php?hotelid=".$hotel_id."&hotelname=".$hotel_name."hotelmsn=update");
		} else {
			header("Location: ../../manage-hotel.php?hotelid=".$hotel_id."&hotelname=".$hotel_name."&hotelmsn=error2&errormsn=".implode($errors));
		}
	} 
} else {

mysqli_query($conn, "UPDATE hotels SET hotel_name = '$hotel_name', hotel_short_description = '$hotel_description', hotel_information = '$hotel_info', hotel_low_price = '$hotel_price', hotel_country = '$hotel_country', hotel_state = '$hotel_state', hotel_city = '$hotel_city', hotel_address = '$hotel_address', hotel_zipcode = '$hotel_zipcode', longitud = '$longitud', latitud = '$latitud', hotel_stars = '$stars', max_adults = '$max_adults', max_children = '$max_children', max_guests = '$max_guests', max_rooms = '$max_rooms', policy_cancel = '$policy_cancel', hotel_tax = '$hotel_tax' WHERE hotel_id = $hotel_id");

header("Location: ../../manage-hotel.php?hotelid=".$hotel_id."&hotelname=".$hotel_name."hotelmsn=update");
}
?>