summaryrefslogtreecommitdiffstats
path: root/modules-available/roomplanner/page.inc.php
diff options
context:
space:
mode:
authorChristian Klinger2016-08-08 14:30:18 +0200
committerChristian Klinger2016-08-08 14:30:18 +0200
commit19eec4188d6d871d980deee2255507ac7d265b6c (patch)
tree0ed082703c39033eafbaa79861b53487fa857014 /modules-available/roomplanner/page.inc.php
parentfixed bug. (diff)
downloadslx-admin-19eec4188d6d871d980deee2255507ac7d265b6c.tar.gz
slx-admin-19eec4188d6d871d980deee2255507ac7d265b6c.tar.xz
slx-admin-19eec4188d6d871d980deee2255507ac7d265b6c.zip
subnet select.
Diffstat (limited to 'modules-available/roomplanner/page.inc.php')
-rw-r--r--modules-available/roomplanner/page.inc.php91
1 files changed, 57 insertions, 34 deletions
diff --git a/modules-available/roomplanner/page.inc.php b/modules-available/roomplanner/page.inc.php
index b533cf2f..222192c1 100644
--- a/modules-available/roomplanner/page.inc.php
+++ b/modules-available/roomplanner/page.inc.php
@@ -2,30 +2,38 @@
class Page_Roomplanner extends Page
{
- protected function doPreprocess()
- {
- User::load();
+ protected function doPreprocess()
+ {
+ User::load();
- if (!User::hasPermission('superadmin')) {
- Message::addError('main.no-permission');
- Util::redirect('?do=Main');
- }
+ if (!User::hasPermission('superadmin')) {
+ Message::addError('main.no-permission');
+ Util::redirect('?do=Main');
+ }
+ }
- }
+ protected function doRender()
+ {
+ $locationid = Request::get('locationid', null, 'integer');
- protected function doRender()
- {
- Render::addTemplate('page', []);
- }
+ if ($locationid === null) {
+ die('please specify locationid');
+ }
- protected function doAjax()
- {
- $action = Request::get('action', null, 'string');
+ $subnetMachines = $this->getPotentialMachines($locationid);
- if ($action === 'getmachines') {
- $query = Request::get('query', null, 'string');
+ Render::addTemplate('page', ['subnetMachines' => json_encode($subnetMachines),
+ ]);
+ }
- /* the query could be anything: UUID, IP or macaddr */
+ protected function doAjax()
+ {
+ $action = Request::get('action', null, 'string');
+
+ if ($action === 'getmachines') {
+ $query = Request::get('query', null, 'string');
+
+ /* the query could be anything: UUID, IP or macaddr */
// $result = Database::simpleQuery('SELECT machineuuid, macaddr, clientip, hostname '
// . ', MATCH (machineuuid, macaddr, clientip, hostname) AGAINST (:query) AS relevance '
// . 'FROM machine '
@@ -34,20 +42,35 @@ class Page_Roomplanner extends Page
// . 'LIMIT 5'
// , ['query' => $query]);
//
- $result = Database::simpleQuery('SELECT machineuuid, macaddr, clientip, hostname '
- . 'FROM machine '
- . "WHERE machineuuid LIKE :query "
- . " OR macaddr LIKE :query "
- . " OR clientip LIKE :query "
- . " OR hostname LIKE :query ", ['query' => "%$query%"]);
-
- $returnObject = ['machines' => []];
-
- while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
- $returnObject['machines'][] = $row;
- }
- echo json_encode($returnObject, JSON_PRETTY_PRINT);
-
- }
- }
+ $result = Database::simpleQuery('SELECT machineuuid, macaddr, clientip, hostname '
+ .'FROM machine '
+ .'WHERE machineuuid LIKE :query '
+ .' OR macaddr LIKE :query '
+ .' OR clientip LIKE :query '
+ .' OR hostname LIKE :query ', ['query' => "%$query%"]);
+
+ $returnObject = ['machines' => []];
+
+ while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
+ $returnObject['machines'][] = $row;
+ }
+ echo json_encode($returnObject, JSON_PRETTY_PRINT);
+ }
+ }
+
+ protected function getPotentialMachines($locationid)
+ {
+ $result = Database::simpleQuery('SELECT machineuuid, macaddr, clientip, hostname '
+ .'FROM machine INNER JOIN subnet ON (INET_ATON(clientip) BETWEEN startaddr AND endaddr) '
+ .'WHERE subnet.locationid = :locationid', ['locationid' => $locationid]);
+
+ $machines = [];
+
+ while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
+ $row['combined'] = implode(' ', array_values($row));
+ $machines[] = $row;
+ }
+
+ return $machines;
+ }
}