<?php
require 'db.php';
header('Content-Type: application/json');

$code = $_POST['code'] ?? '';

$stmt = $pdo->prepare("
    SELECT id, org_name, Concat( country,', ', city ) As location
    FROM company 
    WHERE biz_code=? AND last_activity >= NOW() - INTERVAL 24 HOUR;
");
$stmt->execute([$code]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);

if(!$user){
    echo json_encode(["status"=>"error"]);
    exit;
}

echo json_encode([
    "status"  => "success",
    "org_name" => $user['org_name'],
    "address"  => $user['location'],
    "id"     => $user['id']
]);
