Files
InternetRadio-Website/android/alarm/add.php
T
2026-06-17 15:46:26 +02:00

67 lines
1.3 KiB
PHP

<?php
header('Content-Type: application/json');
require("../../inc/connect.php");
require("../session.php");
$session = $_GET['session'];
if($session == "")
{
JError("session not set");
}
$name = $_GET['name'];
$time = $_GET['time'];
$stream = $_GET['stream'];
if($name == "")
{
JError("name not set");
}
if($time == "")
{
JError("time not set");
}
if($stream == "")
{
JError("stream not set");
}
//check session
verify_session($mysqli, $session);
//check if not too many alarms
$sql = "SELECT `id` FROM `alarm` WHERE `dev_id`=$deviceid";
$query = ExecQuery($mysqli, $sql);
if($query->num_rows >= 2)
{
JError("you cannot have more than 2 alarms");
}
//Check if stream is allowed
$sql = "SELECT `name` FROM `stream` WHERE `dev_id`=$deviceid AND `id`=$stream";
$query = ExecQuery($mysqli, $sql);
if($query->num_rows < 1)
{
JError("you cannot use that stream");
}
//Remove seconds
$time = substr($time, 0, 5);
//Check time
if(!preg_match("/(2[0-3]|[01][0-9]):([0-5][0-9])/", $time))
{
JError("invalid time");
}
$time .= ":00";
//update
$sql = "INSERT INTO `alarm` (`name`, `time`, `stream`, `dev_id`) VALUES ('$name', '$time', $stream, $deviceid)";
ExecQuery($mysqli, $sql);
JSuccess("true");
?>