summaryrefslogtreecommitdiffstats
path: root/modules-available/passthrough/page.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2021-12-07 16:14:19 +0100
committerSimon Rettberg2022-03-09 15:06:54 +0100
commit9399fab2c22582c2d9dc7127bc7bf85b0ed86210 (patch)
tree4bcd4f6ee4875ad9b52e6a467badbc50d038c0ea /modules-available/passthrough/page.inc.php
parent[statistics/passthrough] Consider group<->location mapping for KCL (diff)
downloadslx-admin-9399fab2c22582c2d9dc7127bc7bf85b0ed86210.tar.gz
slx-admin-9399fab2c22582c2d9dc7127bc7bf85b0ed86210.tar.xz
slx-admin-9399fab2c22582c2d9dc7127bc7bf85b0ed86210.zip
[passthrough] Add location assignment page
Diffstat (limited to 'modules-available/passthrough/page.inc.php')
-rw-r--r--modules-available/passthrough/page.inc.php49
1 files changed, 49 insertions, 0 deletions
diff --git a/modules-available/passthrough/page.inc.php b/modules-available/passthrough/page.inc.php
index 7dcc8215..b36b45ac 100644
--- a/modules-available/passthrough/page.inc.php
+++ b/modules-available/passthrough/page.inc.php
@@ -10,6 +10,8 @@ class Page_Passthrough extends Page
$action = Request::post('action');
if ($action === 'save-hwlist') {
$this->saveHwList();
+ } elseif ($action === 'save-location') {
+ $this->saveLocation();
}
if (Request::isPost()) {
Util::redirect('?do=passthrough');
@@ -18,6 +20,7 @@ class Page_Passthrough extends Page
private function saveHwList()
{
+ User::assertPermission('edit.group');
$newgroups = Request::post('newgroup', [], 'array');
foreach ($newgroups as $id => $title) {
$id = strtoupper(preg_replace('/[^a-z0-9_\-]/i', '', $id));
@@ -49,6 +52,30 @@ class Page_Passthrough extends Page
Util::redirect('?do=passthrough&show=hwlist');
}
+ private function saveLocation()
+ {
+ $locationId = Request::post('locationid', Request::REQUIRED, 'int');
+ User::assertPermission('edit.location', $locationId);
+ $list = [];
+ $groups = [];
+ foreach (Request::post('enabled', [], 'array') as $groupId) {
+ $groupId = (string)$groupId;
+ $list[] = [$groupId, $locationId];
+ $groups[] = $groupId;
+ }
+ if (!empty($list)) {
+ Database::exec("INSERT IGNORE INTO passthrough_group_x_location (groupid, locationid)
+ VALUES :list", ['list' => $list]);
+ Database::exec("DELETE FROM passthrough_group_x_location
+ WHERE locationid = :lid AND groupid NOT IN (:groups)", ['lid' => $locationId, 'groups' => $groups]);
+ } else {
+ Database::exec("DELETE FROM passthrough_group_x_location
+ WHERE locationid = :lid", ['lid' => $locationId]);
+ }
+ Message::addSuccess('location-updated', Location::getName($locationId));
+ Util::redirect('?do=passthrough&show=assignlocation&locationid=' . $locationId);
+ }
+
/*
*
*/
@@ -58,11 +85,16 @@ class Page_Passthrough extends Page
$show = Request::get('show');
if ($show === 'hwlist') {
$this->showHardwareList();
+ } elseif ($show === 'assignlocation') {
+ $this->showLocationMapping();
} else {
Util::redirect('?do=passthrough&show=hwlist');
}
}
+ /**
+ * Show all the hardware that is known. Start with video adapters.
+ */
private function showHardwareList()
{
$q = new HardwareQuery(HardwareInfo::PCI_DEVICE, null, false);
@@ -118,6 +150,23 @@ class Page_Passthrough extends Page
}
}
+ /**
+ * Show mapping between specific location and passthrough groups.
+ * @return void
+ */
+ private function showLocationMapping()
+ {
+ $locationId = Request::get('locationid', Request::REQUIRED, 'int');
+ $res = Database::queryAll("SELECT g.groupid, g.title, gxl.locationid AS enabled FROM passthrough_group g
+ LEFT JOIN passthrough_group_x_location gxl ON (g.groupid = gxl.groupid AND gxl.locationid = :locationid)
+ ORDER BY gxl.locationid ASC",
+ ['locationid' => $locationId]);
+ Render::addTemplate('location-assign', [
+ 'list' => array_reverse($res),
+ 'locationid' => $locationId,
+ ]);
+ }
+
/*
*
*/