<?php

ini_set("display_errors", 1);
if (isset($_GET["lab"]) == false) {
    echo "Bad input 1";
    exit;
}
$lab_id = $_GET["lab"];
if (preg_match("/^\\d+\$/", $lab_id) == false) {
    echo "Bad input 2";
    exit;
}
$lab_id = (int) $lab_id;
require_once "../classes/db_connection.php";
require_once "../classes/lab.php";
require_once "../classes/computer.php";
$computers = array();
try {
    DBConnection::Connect();
    $computers = Computer::GetComputersByLab($lab_id);
    DBConnection::Close();
} catch (Exception $ex) {
}
$st = "";
foreach ($computers as $computer) {
    $st .= "{\n\t\t\t\t\"id\": " . $computer->ID . ",\n\t\t\t\t\"ip\": \"" . $computer->IP . "\",\n\t\t\t\t\"name\": \"" . $computer->Name . "\",\n\t\t\t\t\"studentID\": " . ($computer->StudentID == null ? "null" : "\"" . $computer->StudentID . "\"") . ",\n\t\t\t\t\"x1\": " . $computer->X1 . ",\n                                \"y1\": " . $computer->Y1 . ",\n\t\t\t\t\"statusID\": " . $computer->StatusID . "\n\t\t\t},";
}
$st = str_replace("\t", "", substr($st, 0, -1));
header("Content-Type: application/json");
//header("Content-Type: text/plain");
echo "[" . $st . "]";