From 4c0862efe57fbdaa51a69c8dc39f6fc4ae45fa20 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 19 Mar 2021 13:54:22 +0100 Subject: [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 --- modules-available/locations/pages/details.inc.php | 55 ++++++++--------------- 1 file changed, 19 insertions(+), 36 deletions(-) (limited to 'modules-available/locations/pages') 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); -- cgit v1.2.3-55-g7522