summaryrefslogtreecommitdiffstats
path: root/modules-available/statistics/inc/filter.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/statistics/inc/filter.inc.php')
-rw-r--r--modules-available/statistics/inc/filter.inc.php51
1 files changed, 37 insertions, 14 deletions
diff --git a/modules-available/statistics/inc/filter.inc.php b/modules-available/statistics/inc/filter.inc.php
index 0afce572..be6df752 100644
--- a/modules-available/statistics/inc/filter.inc.php
+++ b/modules-available/statistics/inc/filter.inc.php
@@ -29,7 +29,7 @@ class Filter
$addendum = '';
/* check if we have to do some parsing*/
- if (Page_Statistics::$columns[$this->column]['type'] == 'date') {
+ if (Page_Statistics::$columns[$this->column]['type'] === 'date') {
$args[$key] = strtotime($this->argument);
} else {
$args[$key] = $this->argument;
@@ -180,21 +180,18 @@ class StateFilter extends Filter
{
public function __construct($operator, $argument)
{
- $this->operator = $operator;
- $this->argument = $argument;
+ parent::__construct(null, $operator, $argument);
}
public function whereClause(&$args, &$joins)
{
+ $map = [ 'on' => ['IDLE', 'OCCUPIED'], 'off' => ['OFFLINE'], 'idle' => ['IDLE'], 'occupied' => ['OCCUPIED'], 'standby' => ['STANDBY'] ];
$neg = $this->operator == '!=' ? 'NOT ' : '';
- if ($this->argument === 'on') {
- return " $neg (lastseen + 600 > UNIX_TIMESTAMP() ) ";
- } elseif ($this->argument === 'off') {
- return " $neg (lastseen + 600 < UNIX_TIMESTAMP() ) ";
- } elseif ($this->argument === 'idle') {
- return " $neg (lastseen + 600 > UNIX_TIMESTAMP() AND logintime = 0 ) ";
- } elseif ($this->argument === 'occupied') {
- return " $neg (lastseen + 600 > UNIX_TIMESTAMP() AND logintime <> 0 ) ";
+ if (array_key_exists($this->argument, $map)) {
+ global $unique_key;
+ $key = $this->column . '_arg' . ($unique_key++);
+ $args[$key] = $map[$this->argument];
+ return " machine.state $neg IN ( :$key ) ";
} else {
Message::addError('invalid-filter-argument', 'state', $this->argument);
return ' 1';
@@ -211,13 +208,22 @@ class LocationFilter extends Filter
public function whereClause(&$args, &$joins)
{
+ $recursive = (substr($this->operator, -1) === '~');
+ $this->operator = str_replace('~', '=', $this->operator);
+
settype($this->argument, 'int');
+ $neg = $this->operator === '=' ? '' : 'NOT';
if ($this->argument === 0) {
- $neg = $this->operator === '=' ? '' : 'NOT';
return "machine.locationid IS $neg NULL";
} else {
- $args['lid'] = $this->argument;
- return "machine.locationid {$this->operator} :lid";
+ global $unique_key;
+ $key = $this->column . '_arg' . ($unique_key++);
+ if ($recursive) {
+ $args[$key] = array_keys(Location::getRecursiveFlat($this->argument));
+ } else {
+ $args[$key] = $this->argument;
+ }
+ return "machine.locationid $neg IN (:$key)";
}
}
}
@@ -236,3 +242,20 @@ class SubnetFilter extends Filter
}
}
+class IsClientFilter extends Filter
+{
+ public function __construct($argument)
+ {
+ parent::__construct(null, null, $argument);
+ }
+
+ public function whereClause(&$args, &$joins)
+ {
+ if ($this->argument) {
+ $joins[] = ' LEFT JOIN runmode USING (machineuuid)';
+ return "(runmode.isclient <> 0 OR runmode.isclient IS NULL)";
+ }
+ $joins[] = ' INNER JOIN runmode USING (machineuuid)';
+ return "runmode.isclient = 0";
+ }
+}