From 83097db5279b319cd7b6631aad52c7ab43d0d11b Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 13 Nov 2017 23:38:56 +0100 Subject: [statistics] Show client details if filter has exactly one result --- modules-available/statistics/page.inc.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'modules-available/statistics/page.inc.php') diff --git a/modules-available/statistics/page.inc.php b/modules-available/statistics/page.inc.php index 2b12c69f..479f3089 100644 --- a/modules-available/statistics/page.inc.php +++ b/modules-available/statistics/page.inc.php @@ -308,6 +308,14 @@ class Page_Statistics extends Page } } + private function redirectFirst($where, $join, $args) + { + $res = Database::queryFirst("SELECT machineuuid FROM machine $join WHERE ($where) LIMIT 1", $args); + if ($res !== false) { + Util::redirect('?do=statistics&uuid=' . $res['machineuuid']); + } + } + /** * @param \FilterSet $filterSet */ @@ -316,6 +324,10 @@ class Page_Statistics extends Page $filterSet->makeFragments($where, $join, $sort, $args); $known = Database::queryFirst("SELECT Count(*) AS val FROM machine $join WHERE ($where)", $args); + // If we only have one machine, redirect to machine details + if ($known['val'] == 1) { + $this->redirectFirst($where, $join, $args); + } $on = Database::queryFirst("SELECT Count(*) AS val FROM machine $join WHERE lastboot <> 0 AND ($where)", $args); $used = Database::queryFirst("SELECT Count(*) AS val FROM machine $join WHERE lastboot <> 0 AND logintime <> 0 AND ($where)", $args); $hdd = Database::queryFirst("SELECT Count(*) AS val FROM machine $join WHERE badsectors >= 10 AND ($where)", $args); @@ -565,7 +577,13 @@ class Page_Statistics extends Page . " $join WHERE $where $sort", $args); $rows = array(); $NOW = time(); + $singleMachine = 'none'; while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + if ($singleMachine === 'none') { + $singleMachine = $row['machineuuid']; + } else { + $singleMachine = false; + } if ($row['lastboot'] == 0) { $row['state_off'] = true; } elseif ($row['logintime'] == 0) { @@ -596,6 +614,9 @@ class Page_Statistics extends Page } $rows[] = $row; } + if ($singleMachine !== false && $singleMachine !== 'none') { + Util::redirect('?do=statistics&uuid=' . $singleMachine); + } Render::addTemplate('clientlist', array( 'rowCount' => count($rows), 'rows' => $rows, -- cgit v1.2.3-55-g7522