summaryrefslogtreecommitdiffstats
path: root/modules-available/locations/pages
diff options
context:
space:
mode:
authorSimon Rettberg2021-03-19 13:54:22 +0100
committerSimon Rettberg2021-03-19 13:54:22 +0100
commit4c0862efe57fbdaa51a69c8dc39f6fc4ae45fa20 (patch)
treecf5d472d2bea7a4ba43339bf892db6dad710e51c /modules-available/locations/pages
parent[locations] Add permission for openingtimes (diff)
downloadslx-admin-4c0862efe57fbdaa51a69c8dc39f6fc4ae45fa20.tar.gz
slx-admin-4c0862efe57fbdaa51a69c8dc39f6fc4ae45fa20.tar.xz
slx-admin-4c0862efe57fbdaa51a69c8dc39f6fc4ae45fa20.zip
[locations/rebootcontrol] Inherit openingtimes for WOL/shutdown
The opening times schedule is now inherited to child locations, so it's easy to toggle WOL or shutdown for individual rooms in a building, where you only have to set the opening times once for the entire building. As of now, WOL and shutdown settings are *not* inherited to child locations, as I'm not sure if you always want to inherit those by default. Closes #3710
Diffstat (limited to 'modules-available/locations/pages')
-rw-r--r--modules-available/locations/pages/details.inc.php55
1 files changed, 19 insertions, 36 deletions
diff --git a/modules-available/locations/pages/details.inc.php b/modules-available/locations/pages/details.inc.php
index 19a89c88..356620d3 100644
--- a/modules-available/locations/pages/details.inc.php
+++ b/modules-available/locations/pages/details.inc.php
@@ -35,6 +35,7 @@ class SubPage
private static function updateOpeningTimes()
{
+ $otInherited = Request::post('openingtimes-inherited', false, 'bool');
$openingTimes = Request::post('openingtimes', Request::REQUIRED, 'string');
$locationid = Request::post('locationid', Request::REQUIRED, 'int');
$wol = Request::post('wol', false, 'bool');
@@ -45,10 +46,12 @@ class SubPage
User::assertPermission('location.edit.openingtimes', $locationid);
// Construct opening-times for database
- if ($openingTimes !== '') {
+ if ($otInherited || $openingTimes === '') {
+ $openingTimes = null;
+ } else {
$openingTimes = json_decode($openingTimes, true);
if (!is_array($openingTimes)) {
- $openingTimes = '';
+ $openingTimes = null;
} else {
$mangled = array();
foreach (array_keys($openingTimes) as $key) {
@@ -89,32 +92,8 @@ class SubPage
array('locationid' => $locationid, 'openingtime' => $openingTimes));
if (Module::isAvailable('rebootcontrol')) {
- if ($wol || $sd) {
- $options = array();
-
- // Sanity checks
- if ($woloffset > 15) {
- $woloffset = 15;
- } elseif ($woloffset < 0) {
- $woloffset = 0;
- }
- if ($sdoffset > 15) {
- $sdoffset = 15;
- } elseif ($sdoffset < 0) {
- $sdoffset = 0;
- }
-
- // Set options
- $options['wol'] = $wol;
- $options['wol-offset'] = $woloffset;
- $options['sd'] = $sd;
- $options['sd-offset'] = $sdoffset;
-
- Scheduler::updateSchedule($locationid, $options, $openingTimes);
-
- } else {
- Scheduler::deleteSchedule($locationid);
- }
+ // Set options
+ Scheduler::setLocationOptions($locationid, $wol, $sd, $woloffset, $sdoffset);
}
}
@@ -429,25 +408,29 @@ class SubPage
private static function ajaxOpeningTimes($id)
{
User::assertPermission('location.edit.openingtimes', $id);
- $openTimes = Database::queryFirst("SELECT openingtime FROM `location` WHERE locationid = :id", array('id' => $id));
- if ($openTimes !== false) {
+ $data = ['id' => $id];
+ $openTimes = Database::queryFirst("SELECT openingtime FROM `location`
+ WHERE locationid = :id", array('id' => $id));
+ if ($openTimes === false) {
+ Message::addError('invalid-location-id', $id);
+ return;
+ }
+ if ($openTimes['openingtime'] !== null) {
$openingTimes = json_decode($openTimes['openingtime'], true);
+ } else {
+ $openingTimes = OpeningTimes::forLocation($id);
+ $data['openingtimes_inherited'] = 'checked';
}
if (!isset($openingTimes) || !is_array($openingTimes)) {
$openingTimes = array();
}
- $data = array('id' => $id);
$data['expertMode'] = !self::isSimpleMode($openingTimes);
$data['schedule_data'] = json_encode($openingTimes);
$rebootcontrol = Module::isAvailable('rebootcontrol');
$data['rebootcontrol'] = $rebootcontrol;
if ($rebootcontrol) {
- $res = Database::queryFirst("SELECT action, nextexecution, options FROM `reboot_scheduler`
- WHERE locationid = :id", ['id' => $id]);
- if ($res !== false) {
- $data['scheduler-options'] = json_decode($res['options'], true);
- }
+ $data['scheduler-options'] = Scheduler::getLocationOptions($id);
}
echo Render::parse('ajax-opening-location', $data);