<?php 
    include_once('../header.php');
    if(!isset($_SESSION['user_id'])){
        header("Location: " . WEB_URL . "logout.php");
        die();
    }

    if($_SERVER["REQUEST_METHOD"] == "POST"){
        $current_time = date("y-m-d: H:i:s");
        $sql = "UPDATE  tenant_unit SET date_removed = '{$current_time}' where id = '{$_POST['assignment_id']}'";
        $clean_old_assignments = "UPDATE tenant_unit SET past_assignment = 1, last_action_by = {$_SESSION["user_id"]} where id = {$_POST['assignment_id']}";
        echo $clean_old_assignments;
	    mysqli_query($link,$clean_old_assignments);
        if(mysqli_query($link,$sql)){

            $_SESSION["message"] = "Tenant Ejected Successfully";
        }else{
            $_SESSION["message"] = "Unable to Eject Tenant";
        }
        mysqli_close($link);
    }else{
        $_SESSION["message"] = "Invalid Request";
    }
    $url = WEB_URL . 'tenant/tenantlist.php';
    header("Location: $url");


	
?>

