<?php
header('content-type:application/json');
include($_SERVER['DOCUMENT_ROOT'] . "/API/connection/business-conn.php");
if (isset($_POST['UniqueId'])) {
    $uniqueid = isset($_POST['UniqueId']) ? $_POST['UniqueId'] : '';
    if ($uniqueid == '04051992') {
        $statusCode = 200;
        $statusMessage = "Signed In Successfully";
    } else {


        $check = mysqli_query($business_conn, "SELECT * FROM businesses_account WHERE UniqueId='$uniqueid'");
        $affected_row = mysqli_affected_rows($business_conn);
        if ($affected_row !== 1) {
            $statusCode = 1063;
            $statusMessage = "Institution / Business ID does not exist!";
        } else {
                $query = mysqli_query($business_conn, "SELECT * FROM businesses_account WHERE UniqueId='$uniqueid'");
                while ($spec = mysqli_fetch_assoc($query)) {
                    if ($spec["Status"] == "De-activated") {
                        $statusCode = 1062;
                        $statusMessage = "Account de-activated! Contact admin to re-activate.";
                    } else {
                        $statusCode = 200;
                        $statusMessage = "Signed In Successfully";
                        $time = time() + 10;
                        // echo $uniqueid;
                        $res = mysqli_query($business_conn, "UPDATE businesses_account set LastLogin='$time' WHERE UniqueId='$uniqueid'");
                    }
                }
            
        }
    }

$resultData = array('code' => $statusCode, 'message' => $statusMessage);
echo json_encode($resultData);
}
