?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>App Real Estate</title>
</head>

<body>

 <?php 
//$user = new User();
$tenant = new Tenant();
$tenant->setFirstName('New');
$tenant->setLastName("Tenant");
$tenant->setEmail('*****@*****.**');
$tenant->setPhoneNumber('0719 644 479');
$tenant->setNationalIdNumber('29074310');
echo "<tt><pre>" . var_dump($tenant) . "</pre></tt>";
/**$sanitized_props = $user->_sanitizedProperties();
	echo "<tt><pre>".var_dump($sanitized_props)."</pre></tt>";*/
if ($tenant->save()) {
    $msg = "User details created";
} else {
    $msg = "Save failed";
}
echo "User ID: ";
echo $tenant->id;
echo "<br />";
echo "First Name: ";
echo $tenant->getFirstName();
    $joined = $_POST['joined'];
    if (empty($fname) || empty($lname) || empty($phone) || empty($id_num) || empty($joined)) {
        $err = "Form fields marked with an asterix are required";
    } else {
        // Continue with processing
        $prop_id = (int) $session->sessionVar("prop_id");
        $room_id = (int) $session->sessionVar("room_id");
        $tenant = new Tenant();
        $tenant->setPropertyId($prop_id);
        $tenant->setRoomId($room_id);
        $tenant->setFirstName($fname);
        $tenant->setLastName($lname);
        $tenant->setPhoneNumber($phone);
        $tenant->setNationalIdNumber($id_num);
        if (!empty($email)) {
            $tenant->setEmail($email);
        }
        if (!empty($business)) {
            $tenant->setBusinessName($business);
        }
        $tenant->setDateJoined($joined);
        #echo var_dump($tenant);
        if ($tenant->createNewTenant($room_id)) {
            $session->message("Tenant added");
            redirect_to("tenants.php");
        } else {
            $err = "An error occured preventing the tenant from being added. Try again later";
        }
    }
} else {
    // Form not submitted