This repository has been archived on 2020-03-25. You can view files and clone it, but cannot push or open issues or pull requests.
lightscontrol-server/index.php

128 lines
4.4 KiB
PHP
Raw Normal View History

2017-07-23 23:34:53 +00:00
<?php
// -------------------------------------------
// outdoor lights control -- server
// copyright: Jannik Beyerstedt | https://jannikbeyerstedt.de
// license: http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 License
// -------------------------------------------
include "functions.php";
$light = new LightStatus();
$light->update();
$error_string = "";
// route actions
if (isset($_GET['action'])) {
if ($_GET['action'] == 'enlighten') {
// set off time to now + 15 minutes
$light->times['instant-on'] = time() + (15*60);
if ($light->saveTimes() === true) {
header('Location: index.php?success=true');
} else {
$error_string = "Error saving config file";
}
} else if ($_GET['action'] == 'update') {
if (isset($_POST) && !empty($_POST)) {
// parse form data
$parse_state = checkTimesInput($_POST);
if ($parse_state === true) {
// change values of $times arrays
$light->times['time1']['on'] = $_POST['time1-start'];
$light->times['time1']['off'] = $_POST['time1-stop'];
$light->times['time2']['on'] = $_POST['time2-start'];
$light->times['time2']['off'] = $_POST['time2-stop'];
$light->times['time3']['on'] = $_POST['time3-start'];
$light->times['time3']['off'] = $_POST['time3-stop'];
// save new $times array
$light->saveTimes();
header('Location: index.php?success=true');
} else {
$error_string = $parse_state;
}
} else {
$error_string = "ERROR: no form data received";
}
} else {
echo "invalid action\n";
}
}
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<meta name="format-detection" content="telephone=no">
<title>Lightscontrol Control Interface</title>
<meta name="robots" content="noindex, nofollow">
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="style.css">
</head>
<body class="container-fluid">
<h1>Außenbeleuchtung</h1>
<?php if ($error_string != '') : ?>
<div class="alert alert-danger" role="alert"><?php echo $error_string ?></div>
<?php endif; ?>
<h2>Aktueller Status</h2>
<p>
<?php if ($light->state) : ?>
Licht: <span class="label label-success">AN</span><br>
<?php else : ?>
Licht: <span class="label label-default">AUS</span><br>
<?php endif; ?>
Zeit bis nächste Änderung: <span class="label label-default"><?php echo ($light->changeTime === 1) ? $light->changeTime." Minute" : $light->changeTime." Minuten" ?></span>
</p>
<a class="btn btn-success" href="index.php?action=enlighten">Licht temporär an (15 Min)</a>
<h5>weitere Informationen:</h5>
<p>
Sonnenaufgang: <?php echo $light->sunrise ?><br>
Sonnenuntergang: <?php echo $light->sunset ?><br>
Aktuelle Zeit: <?php echo date("Y-m-d H:i",time()) ?><br>
</p>
<h2>Einstellungen</h2>
<form class="form-horizontal" action="index.php?action=update" method="post">
<div class="form-group">
<label for="time1-start" class="col-xs-3 col-sm-2 control-label">Zeit 1</label>
<div class="col-xs-9 col-sm-10">
<input type="time" class="form-control" name="time1-start" value="<?php echo $light->times['time1']['on'] ?>">
<input type="time" class="form-control" name="time1-stop" value="<?php echo $light->times['time1']['off'] ?>">
</div>
</div>
<div class="form-group">
<label for="time2-start" class="col-xs-3 col-sm-2 control-label">Zeit 2</label>
<div class="col-xs-9 col-sm-10">
<input type="time" class="form-control" name="time2-start" value="<?php echo $light->times['time2']['on'] ?>">
<input type="time" class="form-control" name="time2-stop" value="<?php echo $light->times['time2']['off'] ?>">
</div>
</div>
<div class="form-group">
<label for="time3-start" class="col-xs-3 col-sm-2 control-label">Zeit 3</label>
<div class="col-xs-9 col-sm-10">
<input type="time" class="form-control" name="time3-start" value="<?php echo $light->times['time3']['on'] ?>">
<input type="time" class="form-control" name="time3-stop" value="<?php echo $light->times['time3']['off'] ?>">
</div>
</div>
<button type="submit" class="btn btn-warning">Zeiten ändern</button>
</form>
</body>
</html>
<script src="bootstrap/jquery-2.2.4.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>