<?php
session_start();
require_once '../utils/errorhandler.php';
require_once '../utils/response.php';
require_once '../model/dbclass.php';
require_once '../model/model.php';
require_once '../model/Property.php';

if ($_SESSION['wuseremail'] === null || !isset($_SESSION['wuseremail'])) {
     exit(badRequest(204,'Invalid session data. Proceed to login'));
}

$property = new Property();

$status = (isset($_POST["status"]) && $_POST["status"] !== "") ? $_POST["status"] : "%";
$searchtext = (isset($_POST["searchtext"]) && $_POST["searchtext"] !== "") ? $_POST["searchtext"] : "%";

$result = $property->executeByQuerySelector("SELECT * FROM tenants WHERE lastname like '$searchtext%' OR firstname LIKE '$searchtext%'");
if($result){
	echo success($result,200, "Successful","Successful");
}else{
	echo success($result,204, "Failed","ERROR"); 
}
?>