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">
    <meta charset="utf-8">