From 2d49c621abeff1909b7f4c90d5273157a4f70286 Mon Sep 17 00:00:00 2001 From: Christian Hofmaier Date: Thu, 3 Dec 2020 12:58:52 +0100 Subject: [locations] Add scheduler to openingtimes modal - only load/safe without further functionality - add backend to rebootcontrol --- modules-available/locations/pages/details.inc.php | 42 +++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'modules-available/locations/pages/details.inc.php') diff --git a/modules-available/locations/pages/details.inc.php b/modules-available/locations/pages/details.inc.php index a55460cf..81c2f2fa 100644 --- a/modules-available/locations/pages/details.inc.php +++ b/modules-available/locations/pages/details.inc.php @@ -36,6 +36,10 @@ class SubPage private static function updateOpeningTimes() { $openingTimes = Request::post('openingtimes', '', 'string'); $locationid = Request::post('locationid', false, 'int'); + $wol = Request::post('wol', false, 'bool'); + $woloffset = Request::post('wol-offset', 0, 'int'); + $sd = Request::post('sd', false, 'bool'); + $sdoffset = Request::post('sd-offset', 0, 'int'); User::assertPermission('location.edit', $locationid); @@ -83,6 +87,29 @@ class SubPage Database::exec('UPDATE location SET openingtime = :openingtime WHERE locationid = :locationid', array('locationid' => $locationid, 'openingtime' => $openingTimes)); + if (Module::isAvailable('rebootcontrol')) { + if ($wol) { + $options = array(); + // Sanity checks + if ($woloffset > 15) $woloffset = 15; + else if ($woloffset < 0) $woloffset = 0; + $options['wol-offset'] = $woloffset; + Scheduler::updateSchedule($locationid, 'wol', $options, $openingTimes); + } else { + Scheduler::deleteSchedule($locationid, 'wol'); + } + if ($sd) { + $options = array(); + // Sanity checks + if ($sdoffset > 15) $sdoffset = 15; + else if ($sdoffset < 0) $sdoffset = 0; + $options['sd-offset'] = $sdoffset; + Scheduler::updateSchedule($locationid, 'sd', $options, $openingTimes); + } else { + Scheduler::deleteSchedule($locationid, 'sd'); + } + } + return true; } @@ -394,6 +421,21 @@ class SubPage $data['expertMode'] = !self::isSimpleMode($openingTimes); $data['schedule_data'] = json_encode($openingTimes); + $rebootcontrol = Module::isAvailable('rebootcontrol'); + $data['rebootcontrol'] = $rebootcontrol; + if ($rebootcontrol) { + $wol = Database::queryFirst("SELECT options FROM `scheduler` WHERE locationid = :id AND action = 'wol'", array('id' => $id)); + if ($wol !== false) { + $data['wol'] = true; + $data['wol-options'] = json_decode($wol['options']); + } + $sd = Database::queryFirst("SELECT options FROM `scheduler` WHERE locationid = :id AND action = 'sd'", array('id' => $id)); + if ($sd !== false) { + $data['sd'] = true; + $data['sd-options'] = json_decode($sd['options']); + } + } + echo Render::parse('ajax-opening-location', $data); } -- cgit v1.2.3-55-g7522