Files
2026-06-17 15:46:26 +02:00

58 lines
1.4 KiB
PHP

<?php
require("../../../inc/connect.php");
require("../../../inc/session.php");
$schedule = $_POST['id'];
$name = $_POST['name'];
$time = $_POST['time'];
$duration = $_POST['duration'];
$stream = $_POST['stream'];
//Check if alarms editing is allowed
$sql = "SELECT `name` FROM `schedule` WHERE `dev_id`=$deviceid AND `id`=$schedule";
$query = ExecQuery($mysqli, $sql);
if($query->num_rows < 1)
{
error("schedules", "You are not allowed to edit that schedule");
}
//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)
{
error("schedules", "You are not allowed to 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))
{
error("schedules", "Invalid time");
}
$time .= ":00";
//Remove seconds
$duration = substr($duration, 0, 5);
//Check duration
if(!preg_match("/(2[0-3]|[01][0-9]):([0-5][0-9])/", $duration))
{
error("schedules", "Invalid duration");
}
$duration .= ":00";
//Add alarm
$sql = "UPDATE `schedule` SET `name`='$name', `time`='$time', `duration`='$duration', `stream`=$stream WHERE `id`=$schedule";
ExecQuery($mysqli, $sql);
success("schedules", "The schedule has been updated");
?>