summaryrefslogtreecommitdiffstats
path: root/modules-available/statistics_reporting/page.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/statistics_reporting/page.inc.php')
-rw-r--r--modules-available/statistics_reporting/page.inc.php53
1 files changed, 28 insertions, 25 deletions
diff --git a/modules-available/statistics_reporting/page.inc.php b/modules-available/statistics_reporting/page.inc.php
index cc03e4d8..ec4bbf1a 100644
--- a/modules-available/statistics_reporting/page.inc.php
+++ b/modules-available/statistics_reporting/page.inc.php
@@ -11,7 +11,11 @@ class Page_Statistics_Reporting extends Page
/**
* @var int
*/
- private $days;
+ private $from;
+ /**
+ * @var int
+ */
+ private $to;
/**
* @var int
*/
@@ -46,7 +50,11 @@ class Page_Statistics_Reporting extends Page
$this->action = Request::any('action', 'show', 'string');
$this->type = Request::get('type', 'total', 'string');
- $this->days = Request::get('cutoff', 7, 'int');
+
+ // Format: yyyy-mm-dd
+ $fromString = Request::get('from', '-6 days', 'string');
+ $toString = Request::get('to', 'today', 'string');
+
$this->lower = Request::get('lower', 8, 'int');
$this->upper = Request::get('upper', 20, 'int');
@@ -55,9 +63,13 @@ class Page_Statistics_Reporting extends Page
$this->type = 'total';
}
+ // convert from/to dates to unixtime
+ $this->from = min(strtotime($fromString.' 00:00:00'), time());
+ $this->to = min(strtotime($toString.' 23:59:59'), time());
+
// timespan you want to see. default = last 7 days
- GetData::$from = strtotime("-" . ($this->days - 1) . " days 00:00:00");
- GetData::$to = time();
+ GetData::$from = $this->from;
+ GetData::$to = $this->to;
GetData::$lowerTimeBound = $this->lower;
GetData::$upperTimeBound = $this->upper;
/*
@@ -113,26 +125,22 @@ class Page_Statistics_Reporting extends Page
foreach ($this->COLUMNS as $column) {
$data['columns'][] = array(
'id' => 'col_' . $column,
- 'name' => Dictionary::translateFile('template-tags', 'lang_' . $column, true),
+ 'name' => Dictionary::translateFile('template-tags', 'lang_' . $column),
'checked' => ($forceOn || Request::get('col_' . $column, 'off', 'string') !== 'off') ? 'checked' : '',
);
}
foreach ($this->TABLES as $table) {
$data['tables'][] = array(
- 'name' => Dictionary::translate('table_' . $table, true),
+ 'name' => Dictionary::translate('table_' . $table),
'value' => $table,
'allowed' => User::hasPermission("table.view.$table"),
'selected' => ($this->type === $table) ? 'selected' : '',
);
}
- foreach (array(1,2,5,7,14,30,90) as $day) {
- $data['days'][] = array(
- 'days' => $day,
- 'selected' => ($day === $this->days) ? 'selected' : '',
- );
- }
+ $data['from'] = date_format(date_timestamp_set(new DateTime(), $this->from), 'Y-m-d');
+ $data['to'] = date_format(date_timestamp_set(new DateTime(), $this->to), 'Y-m-d');
$data['lower'] = $this->lower;
$data['upper'] = $this->upper;
@@ -177,12 +185,10 @@ class Page_Statistics_Reporting extends Page
}
Header('Content-Type: application/json; charset=utf-8');
die(json_encode($data));
- } else {
- die('No permission.');
}
- } else {
- echo 'Invalid action.';
+ die('No permission.');
}
+ echo 'Invalid action.';
}
private function doExport()
@@ -249,7 +255,6 @@ class Page_Statistics_Reporting extends Page
}
fclose($fh);
exit();
- break;
case 'xml':
$xml_data = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8" ?><data></data>');
$this->array_to_xml($res, $xml_data, 'row');
@@ -265,9 +270,9 @@ class Page_Statistics_Reporting extends Page
/**
* @param $data array Data to encode
- * @param $xml_data \SimpleXMLElement XML Object to append to
+ * @param $xml_data SimpleXMLElement XML Object to append to
*/
- private function array_to_xml($data, $xml_data, $parentName = 'row')
+ private function array_to_xml(array $data, SimpleXMLElement $xml_data, string $parentName = 'row'): void
{
foreach ($data as $key => $value) {
if (is_numeric($key)) {
@@ -282,7 +287,7 @@ class Page_Statistics_Reporting extends Page
}
}
- private function fetchData($flags)
+ private function fetchData(int $flags)
{
// TODO: Make all modes location-aware, filter while querying, not after
switch ($this->type) {
@@ -306,10 +311,9 @@ class Page_Statistics_Reporting extends Page
}
}
// correct indexing of array after deletions
- $data = array_values($data);
- return $data;
+ return array_values($data);
case 'client':
- $data = GetData::perClient($flags, Request::any('new', false, 'string'));
+ $data = GetData::perClient($flags);
// only show clients from locations which you have permission for
$filterLocs = User::getAllowedLocations("table.view.client");
foreach ($data as $key => $row) {
@@ -318,8 +322,7 @@ class Page_Statistics_Reporting extends Page
}
}
// correct indexing of array after deletions
- $data = array_values($data);
- return $data;
+ return array_values($data);
case 'user':
return GetData::perUser($flags);
case 'vm':