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

66 lines
1.5 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 schedule.id, schedule.name, schedule.time, schedule.duration, stream.ip, stream.port, stream.path FROM schedule, device, stream WHERE schedule.dev_id=device.id AND schedule.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 = '{"schedules": [';
$count = 1;
while ($row = $query->fetch_assoc()) {
$time = $row['time'];
$timea = explode(":", $time);
$hour = $timea[0];
$minute = $timea[1];
$duration = $row['duration'];
$durationa = explode(":", $duration);
$dhour = $durationa[0];
$dminute = $durationa[1];
$str .= '{"id":"' . $row["id"] . '", ';
$str .= '"name":"' . $row["name"] . '", ';
$str .= '"hour":"' . $hour . '", ';
$str .= '"minute":"' . $minute. '", ';
$str .= '"dhour":"' . $dhour . '", ';
$str .= '"dminute":"' . $dminute. '", ';
$str .= '"ip":"' . $row["ip"] . '", ';
$str .= '"port":"' . $row["port"] . '", ';
$str .= '"path":"/' . $row["path"] . '"';
if($count == $query->num_rows)
{
$str .= '}';
}
else
{
$str .= '}, ';
}
$count++;
}
$str .= ']}';
echo $str;
?>