Files
InternetRadio-Website/api/alarms.php
T
2026-06-17 15:46:26 +02:00

60 lines
1.2 KiB
PHP

<?php
header('Content-Type: application/json');
require('../inc/connect.php');
$device_id = $_GET["id"];
if($device_id == "")
{
echo '{"error":"device-id not set"}';
exit;
}
// Get all the details for the ID
$sql = "SELECT alarm.id, alarm.name, alarm.time, stream.ip, stream.port, stream.path FROM alarm, device, stream WHERE alarm.dev_id=device.id AND alarm.stream=stream.id AND device.dev_id='" . $device_id . "'";
$query = ExecQuery($mysqli, $sql);
if ($query->num_rows === 0) {
echo '{"error":"device-id not found", "device-id":"' . $device_id . '"}';
exit;
}
$size = $query->num_rows;
$str = '{"alarms": [';
$count = 1;
while ($row = $query->fetch_assoc()) {
$time = $row['time'];
$timea = explode(":", $time);
$hour = $timea[0];
$minute = $timea[1];
$str .= '{"id":"' . $row["id"] . '", ';
$str .= '"name":"' . $row["name"] . '", ';
$str .= '"hour":"' . $hour . '", ';
$str .= '"minute":"' . $minute. '", ';
$str .= '"ip":"' . $row["ip"] . '", ';
$str .= '"port":"' . $row["port"] . '", ';
$str .= '"path":"/' . $row["path"] . '"';
if($count == $query->num_rows)
{
$str .= '}';
}
else
{
$str .= '}, ';
}
$count++;
}
$str .= ']}';
echo $str;
?>