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.php118
1 files changed, 85 insertions, 33 deletions
diff --git a/modules-available/locations/pages/details.inc.php b/modules-available/locations/pages/details.inc.php
index a55460cf..279eee44 100644
--- a/modules-available/locations/pages/details.inc.php
+++ b/modules-available/locations/pages/details.inc.php
@@ -3,24 +3,25 @@
class SubPage
{
- public static function doPreprocess($action)
+ public static function doPreprocess($action): bool
{
if ($action === 'updatelocation') {
self::updateLocation();
return true;
- } else if ($action === 'updateOpeningtimes') {
+ }
+ if ($action === 'updateOpeningtimes') {
self::updateOpeningTimes();
return true;
}
return false;
}
- public static function doRender($action)
+ public static function doRender($action): bool
{
return false;
}
- public static function doAjax($action)
+ public static function doAjax($action): bool
{
if ($action === 'showlocation') {
self::ajaxShowLocation();
@@ -33,22 +34,31 @@ class SubPage
return false;
}
- private static function updateOpeningTimes() {
- $openingTimes = Request::post('openingtimes', '', 'string');
- $locationid = Request::post('locationid', false, 'int');
+ 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');
+ $wolOffset = Request::post('wol-offset', 0, 'int');
+ $sd = Request::post('sd', false, 'bool');
+ $sdOffset = Request::post('sd-offset', 0, 'int');
+ $raMode = Request::post('ra-mode', 'ALWAYS', 'string');
- User::assertPermission('location.edit', $locationid);
+ 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) {
$entry = $openingTimes[$key];
- if (!isset($entry['days']) || !is_array($entry['days']) || empty($entry['days'])) {
+ if (empty($entry['days']) || !is_array($entry['days'])) {
Message::addError('ignored-line-no-days');
continue;
}
@@ -83,14 +93,28 @@ class SubPage
Database::exec('UPDATE location SET openingtime = :openingtime WHERE locationid = :locationid',
array('locationid' => $locationid, 'openingtime' => $openingTimes));
- return true;
+ if (Module::isAvailable('rebootcontrol')) {
+ // Set options
+ if (!Scheduler::isValidRaMode($raMode)) {
+ $raMode = Scheduler::RA_ALWAYS;
+ }
+ Scheduler::setLocationOptions($locationid, [
+ 'wol' => $wol,
+ 'sd' => $sd,
+ 'wol-offset' => $wolOffset,
+ 'sd-offset' => $sdOffset,
+ 'ra-mode' => $raMode,
+ ]);
+ }
}
private static function getTime($str)
{
$str = explode(':', $str);
- if (count($str) !== 2) return false;
- if ($str[0] < 0 || $str[0] > 23 || $str[1] < 0 || $str[1] > 59) return false;
+ if (count($str) !== 2)
+ return false;
+ if ($str[0] < 0 || $str[0] > 23 || $str[1] < 0 || $str[1] > 59)
+ return false;
return $str[0] * 60 + $str[1];
}
@@ -149,7 +173,7 @@ class SubPage
Util::redirect('?do=Locations');
}
- private static function updateLocationData($location)
+ private static function updateLocationData(array $location): bool
{
$locationId = (int)$location['locationid'];
$newParent = Request::post('parentlocationid', false, 'integer');
@@ -193,14 +217,12 @@ class SubPage
return $newParent != $location['parentlocationid'];
}
- private static function updateLocationSubnets()
+ private static function updateLocationSubnets(): bool
{
$locationId = Request::post('locationid', false, 'integer');
if (!User::hasPermission('location.edit.subnets', $locationId))
return false;
- $change = false;
-
// Deletion first
$dels = Request::post('deletesubnet', false);
$deleteCount = 0;
@@ -219,8 +241,9 @@ class SubPage
$starts = Request::post('startaddr', false);
$ends = Request::post('endaddr', false);
if (!is_array($starts) || !is_array($ends)) {
- return $change;
+ return false;
}
+ $change = false;
$editCount = 0;
$stmt = Database::prepare('UPDATE subnet SET startaddr = :start, endaddr = :end'
. ' WHERE subnetid = :id');
@@ -235,7 +258,7 @@ class SubPage
continue;
}
$range = LocationUtil::rangeToLongVerbose($start, $end);
- if ($range === false)
+ if ($range === null)
continue;
list($startLong, $endLong) = $range;
if ($stmt->execute(array('id' => $subnetid, 'start' => $startLong, 'end' => $endLong))) {
@@ -253,18 +276,18 @@ class SubPage
return $change;
}
- private static function addNewLocationSubnets($location)
+ private static function addNewLocationSubnets(array $location): bool
{
$locationId = (int)$location['locationid'];
if (!User::hasPermission('location.edit.subnets', $locationId))
return false;
- $change = false;
$starts = Request::post('newstartaddr', false);
$ends = Request::post('newendaddr', false);
if (!is_array($starts) || !is_array($ends)) {
- return $change;
+ return false;
}
+ $change = false;
$count = 0;
$stmt = Database::prepare('INSERT INTO subnet SET startaddr = :start, endaddr = :end, locationid = :location');
foreach ($starts as $key => $start) {
@@ -309,7 +332,7 @@ class SubPage
$res = Database::simpleQuery("SELECT subnetid, startaddr, endaddr FROM subnet WHERE locationid = :lid",
array('lid' => $locationId));
$rows = array();
- while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($res as $row) {
$row['startaddr'] = long2ip($row['startaddr']);
$row['endaddr'] = long2ip($row['endaddr']);
$rows[] = $row;
@@ -319,6 +342,7 @@ class SubPage
'locationname' => $loc['locationname'],
'list' => $rows,
'roomplanner' => Module::get('roomplanner') !== false,
+ 'news' => Module::get('news') !== false && User::hasPermission('.news.*', $loc['locationid']),
'parents' => Location::getLocations($loc['parentlocationid'], $locationId, true)
);
@@ -347,7 +371,7 @@ class SubPage
if (Module::get('statistics') !== false) {
$mres = Database::simpleQuery("SELECT state FROM machine"
. " WHERE machine.locationid = :lid", array('lid' => $locationId));
- while ($row = $mres->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($mres as $row) {
$count++;
if ($row['state'] === 'IDLE') {
$online++;
@@ -371,33 +395,61 @@ class SubPage
$data['used_percent'] = $count === 0 ? 0 : round(($used / $count) * 100);
- Permission::addGlobalTags($data['perms'], $locationId, ['location.edit.name', 'location.edit.subnets', 'location.delete', '.roomplanner.edit'], 'save_button');
+ Permission::addGlobalTags($data['perms'], $locationId,
+ ['location.edit.name', 'location.edit.subnets', 'location.delete', 'location.edit.openingtimes', '.roomplanner.edit'],
+ 'save_button');
if (empty($allowedLocs)) {
$data['perms']['location']['edit']['parent']['disabled'] = 'disabled';
} else {
unset($data['perms']['save_button']);
}
+ if (Module::get('rebootcontrol') !== false) {
+ $res = Database::queryFirst("SELECT action, nextexecution FROM `reboot_scheduler`
+ WHERE locationid = :id", ['id' => $locationId]);
+ if ($res !== false && $res['nextexecution'] > 0) {
+ $data['next_action'] = $res['action'];
+ $data['next_time'] = Util::prettyTime($res['nextexecution']);
+ }
+ }
+
echo Render::parse('location-subnets', $data);
}
- private static function ajaxOpeningTimes($id) {
- User::assertPermission('location.edit', $id);
- $openTimes = Database::queryFirst("SELECT openingtime FROM `location` WHERE locationid = :id", array('id' => $id));
- if ($openTimes !== false) {
+ private static function ajaxOpeningTimes($id)
+ {
+ User::assertPermission('location.edit.openingtimes', $id);
+ $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) {
+ $data['scheduler-options'] = Scheduler::getLocationOptions($id);
+ $data['scheduler_' . $data['scheduler-options']['ra-mode'] . '_checked'] = 'checked';
+ }
+
echo Render::parse('ajax-opening-location', $data);
}
- private static function isSimpleMode(&$array) {
+ private static function isSimpleMode(&$array): bool
+ {
if (empty($array))
return true;
// Decompose by day
@@ -485,7 +537,7 @@ class SubPage
// $start must lie before range start, otherwise we'd have hit the case above
$e = $current[1];
unset($array[$day][$key]);
- continue;
+ //continue;
}
}
$array[$day][] = array($s, $e);