<?php

require_once 'header.php';
$controller = new ControllerRealEstate();
$controllerAgent = new ControllerAgent();
$controllerPropertyType = new ControllerPropertyType();
$agents = $controllerAgent->getAgents();
$propertytypes = $controllerPropertyType->getPropertyTypes();
$extras = new Extras();
if (isset($_POST['submit'])) {
    $itm = new RealEstate();
    $itm->address = htmlspecialchars(trim(strip_tags($_POST['address'])), ENT_QUOTES);
    $itm->baths = htmlspecialchars(trim(strip_tags($_POST['baths'])), ENT_QUOTES);
    $itm->beds = trim(strip_tags($_POST['beds']));
    $itm->built_in = trim(strip_tags($_POST['built_in']));
    $itm->country = htmlspecialchars(trim(strip_tags($_POST['country'])), ENT_QUOTES);
    $itm->created_at = time();
    $itm->desc1 = $extras->removeHttp(htmlspecialchars(trim(strip_tags($_POST['desc1'])), ENT_QUOTES));
    $itm->featured = htmlspecialchars(trim(strip_tags($_POST['featured'])), ENT_QUOTES);
    $itm->lat = trim(strip_tags($_POST['lat']));
    $itm->lon = trim(strip_tags($_POST['lon']));
    $itm->lot_size = trim(strip_tags($_POST['lot_size']));
    $itm->price = htmlspecialchars(trim(strip_tags($_POST['price'])), ENT_QUOTES);
    $itm->price_per_sqft = htmlspecialchars(trim(strip_tags($_POST['price_per_sqft'])), ENT_QUOTES);
    $itm->property_type = trim(strip_tags($_POST['property_type']));
    $itm->rooms = trim(strip_tags($_POST['rooms']));
    $itm->sqft = trim(strip_tags($_POST['sqft']));
    $itm->status = trim(strip_tags($_POST['status']));
    $itm->updated_at = time();
    $itm->is_deleted = 0;
    $itm->agent_id = trim(strip_tags($_POST['agent_id']));
<?php

require_once 'header.php';
$controller = new ControllerPropertyType();
$propertytypes = $controller->getPropertyTypes();
if (!empty($_SERVER['QUERY_STRING'])) {
    $extras = new Extras();
    $propertytype_id = $extras->decryptQuery1(KEY_SALT, $_SERVER['QUERY_STRING']);
    if ($propertytype_id != null) {
        $controller->deletePropertyType($propertytype_id, 1);
        echo "<script type='text/javascript'>location.href='propertytypes.php';</script>";
    } else {
        echo "<script type='text/javascript'>location.href='403.php';</script>";
    }
}
$search_criteria = "";
if (isset($_POST['button_search'])) {
    $search_criteria = trim(strip_tags($_POST['search']));
    $propertytypes = $controller->getPropertyTypesBySearching($search_criteria);
}
?>


<!DOCTYPE html>
<html lang="en"><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
<?php

require_once 'header.php';
$controller = new ControllerPropertyType();
if (isset($_POST['submit'])) {
    $propertytype_found = $controller->getPropertyTypeByPropertyType(trim($_POST['property_type']));
    if ($propertytype_found == null) {
        $itm = new PropertyType();
        $itm->property_type = htmlspecialchars(trim(strip_tags($_POST['property_type'])), ENT_QUOTES);
        $itm->created_at = time();
        $itm->updated_at = time();
        $controller->insertPropertyType($itm);
        echo "<script type='text/javascript'>location.href='propertytypes.php';</script>";
    } else {
        echo "<script>alert('Property Type exist already.');</script>";
    }
}
?>


<!DOCTYPE html>
<html lang="en"><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="shortcut icon" href="http://getbootstrap.com/assets/ico/favicon.ico">

    <title>RealEstate Finder</title>
<?php

require_once 'header.php';
$controller = new ControllerPropertyType();
$extras = new Extras();
$propertytype_id = $extras->decryptQuery1(KEY_SALT, $_SERVER['QUERY_STRING']);
if ($propertytype_id != null) {
    $propertytype = $controller->getPropertyTypeByPropertyTypeId($propertytype_id);
    if (isset($_POST['submit'])) {
        $propertytype_found = $controller->getPropertyTypeByPropertyType(trim($_POST['property_type']));
        if ($propertytype_found == null) {
            $itm = new PropertyType();
            $itm->property_type = htmlspecialchars(trim(strip_tags($_POST['property_type'])), ENT_QUOTES);
            $itm->created_at = time();
            $itm->updated_at = time();
            $itm->propertytype_id = $propertytype_id;
            $controller->updatePropertyType($itm);
            echo "<script type='text/javascript'>location.href='propertytypes.php';</script>";
        } else {
            echo "<script>alert('Cannot update because property type exist already.');</script>";
        }
    }
} else {
    echo "<script type='text/javascript'>location.href='403.php';</script>";
}
?>


<!DOCTYPE html>
<html lang="en"><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">