<?php
require_once "auth.php";
$user = API_AUTH();

$terminal = $_POST['terminal_id'] ?? "";
$acc      = $_POST['account_no'] ?? "";
$symbol   = $_POST['symbol'] ?? "";
$status   = "ONLINE";
$time     = date("Y-m-d H:i:s");

if($terminal == ""){
    echo "MISSING_TERMINAL";
    exit;
}

$q = $conn->prepare("
    INSERT INTO connections (user_id,terminal_id,account_no,default_symbol,last_heartbeat,status)
    VALUES (?,?,?,?,?,?)
    ON DUPLICATE KEY UPDATE
        account_no=VALUES(account_no),
        default_symbol=VALUES(default_symbol),
        last_heartbeat=VALUES(last_heartbeat),
        status='ONLINE'
");
$q->bind_param("isssss", $user['id'], $terminal, $acc, $symbol, $time, $status);
$q->execute();

echo "OK";
?>
