summaryrefslogtreecommitdiffstats
path: root/modules-available/locations/pages/details.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/locations/pages/details.inc.php')
-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);