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']));
    $itm->zipcode = trim(strip_tags($_POST['zipcode']));
    $controller->insertRealEstate($itm);
$controllerCategory = new ControllerCategory();
$categories = $controllerCategory->getCategories();
$extras = new Extras();
$store_id = $extras->decryptQuery1(KEY_SALT, $_SERVER['QUERY_STRING']);
if ($store_id != null) {
    $store = $controller->getStoreByStoreId($store_id);
    if (isset($_POST['submit'])) {
        $itm = $store;
        $itm->store_name = htmlspecialchars(trim(strip_tags($_POST['store_name'])), ENT_QUOTES);
        $itm->store_address = htmlspecialchars(trim(strip_tags($_POST['store_address'])), ENT_QUOTES);
        $store_desc = preg_replace('~[\\r\\n]+~', '', $_POST['store_desc']);
        $itm->store_desc = htmlspecialchars(trim(strip_tags($store_desc)));
        $itm->lat = trim(strip_tags($_POST['lat']));
        $itm->lon = htmlspecialchars(trim(strip_tags($_POST['lon'])), ENT_QUOTES);
        $itm->created_at = time();
        $itm->website = $extras->removeHttp(htmlspecialchars(trim(strip_tags($_POST['website'])), ENT_QUOTES));
        $itm->phone_no = htmlspecialchars(trim(strip_tags($_POST['phone_no'])), ENT_QUOTES);
        $itm->email = trim(strip_tags($_POST['email']));
        $itm->sms_no = trim(strip_tags($_POST['sms_no']));
        $itm->category_id = trim(strip_tags($_POST['category_id']));
        $itm->updated_at = time();
        $itm->featured = trim(strip_tags($_POST['featured']));
        $controller->updateStore($itm);
        echo "<script type='text/javascript'>location.href='stores.php';</script>";
    }
} else {
    echo "<script type='text/javascript'>location.href='403.php';</script>";
}
?>