48 lines
1.1 KiB
PHP
48 lines
1.1 KiB
PHP
<?php
|
|
require("../../../inc/connect.php");
|
|
require("../../../inc/session.php");
|
|
|
|
$name = $_POST['name'];
|
|
$time = $_POST['time'];
|
|
$duration = $_POST['duration'];
|
|
$stream = $_POST['stream'];
|
|
|
|
//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 = "INSERT INTO `schedule` (`dev_id`, `name`, `time`, `duration`, `stream`) VALUES ($deviceid, '$name', '$time', '$duration', $stream)";
|
|
ExecQuery($mysqli, $sql);
|
|
|
|
success("schedules", "The schedule has been added");
|
|
|
|
?>
|