From acd63d1b88bf8605b3ef0f05ce9a2e25e10abcd0 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 8 Dec 2022 15:46:50 +0100 Subject: [remoteaccess] Add list of active locations to overview page References #3767 --- modules-available/remoteaccess/page.inc.php | 54 ++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 9 deletions(-) (limited to 'modules-available/remoteaccess/page.inc.php') diff --git a/modules-available/remoteaccess/page.inc.php b/modules-available/remoteaccess/page.inc.php index fa94e193..ee9305dc 100644 --- a/modules-available/remoteaccess/page.inc.php +++ b/modules-available/remoteaccess/page.inc.php @@ -105,6 +105,36 @@ class Page_RemoteAccess extends Page ]; $data['plugin_version'] = Property::get(RemoteAccess::PROP_PLUGIN_VERSION); Permission::addGlobalTags($data['perms'], null, ['group.locations', 'group.add', 'group.edit', 'set-proxy-ip']); + // List of locations used in at least one group + $res = Database::simpleQuery("SELECT l.locationid, l.locationname, g.groupid, g.groupname, g.active + FROM location l + INNER JOIN remoteaccess_x_location rxl USING (locationid) + INNER JOIN remoteaccess_group g USING (groupid) + ORDER BY locationname, locationid"); + $data['locations'] = []; + $last = null; + foreach ($res as $row) { + if ($last === null || $last['locationid'] !== $row['locationid']) { + unset($last); + $last = [ + 'locationid' => $row['locationid'], + 'locationname' => $row['locationname'], + 'lclass' => 'slx-strike', + 'groups' => [], + ]; + $data['locations'][] =& $last; + } + $last['groups'][] = [ + 'groupid' => $row['groupid'], + 'groupname' => $row['groupname'], + 'gclass' => $row['active'] ?: 'slx-strike', + ]; + if ($row['active']) { + $last['lclass'] = ''; + } + } + unset($last); + $this->addSchedulerTags($data['locations']); Render::addTemplate('edit-settings', $data); } else { // Edit locations for group @@ -117,19 +147,11 @@ class Page_RemoteAccess extends Page $locationList[$lid]['checked'] = 'checked'; } } - $scheduler = Module::isAvailable('rebootcontrol'); + $this->addSchedulerTags($locationList); foreach ($locationList as $lid => &$loc) { if (!in_array($lid, $allowed)) { $loc['disabled'] = 'disabled'; } - if ($scheduler) { - $options = Scheduler::getLocationOptions($lid); - if ($options['ra-mode'] === Scheduler::RA_SELECTIVE) { - $loc['ra_selective'] = true; - } elseif ($options['ra-mode'] === Scheduler::RA_NEVER) { - $loc['ra_never'] = true; - } - } } $data = [ 'groupid' => $groupid, @@ -157,4 +179,18 @@ class Page_RemoteAccess extends Page return empty($diff); } + private function addSchedulerTags(array &$locationList) + { + if (!Module::isAvailable('rebootcontrol')) + return; + foreach ($locationList as $lid => &$loc) { + $options = Scheduler::getLocationOptions($loc['locationid'] ?? $lid); + if ($options['ra-mode'] === Scheduler::RA_SELECTIVE) { + $loc['ra_selective'] = true; + } elseif ($options['ra-mode'] === Scheduler::RA_NEVER) { + $loc['ra_never'] = true; + } + } + } + } -- cgit v1.2.3-55-g7522