summaryrefslogtreecommitdiffstats
path: root/modules-available/statistics_reporting/page.inc.php
blob: 0309be68ecbfbf2761e15e25a7a06a7d1159bc64 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php


class Page_Statistics_Reporting extends Page
{

	private $action = false;

	/**
	 * Called before any page rendering happens - early hook to check parameters etc.
	 */
	protected function doPreprocess()
	{
		User::load();

		if (!User::isLoggedIn()) {
			Message::addError('main.no-permission');
			Util::redirect('?do=Main'); // does not return
		}

		$this->action = Request::any('action', 'show', 'string');
	}

	/**
	 * Menu etc. has already been generated, now it's time to generate page content.
	 */
	protected function doRender()
	{
		if ($this->action === 'show') {
			// timespan you want to see. default = last 7 days
			GetData::$from = strtotime("- " . (Request::get('cutoff', 14, 'int') - 1) . " days 00:00:00");
			GetData::$to = time();
			GetData::$lowerTimeBound = Request::get('lower', 0, 'int');
			GetData::$upperTimeBound = Request::get('upper', 24, 'int');

			$data = array_merge(GetData::total(), array('perLocation' => array(), 'perClient' => array(), 'perUser' => array(), 'perVM' => array()));
			$data['perLocation'] = GetData::perLocation();
			$data['perClient'] = GetData::perClient();
			$data['perUser'] = GetData::perUser();
			$data['perVM'] = GetData::perVM();

			Render::addTemplate('columnChooser');
			Render::addTemplate('_page', $data);
		}
	}

	protected function doAjax()
	{
		$this->action = Request::any('action', false, 'string');
		if ($this->action === 'setReporting') {
			if (!User::isLoggedIn()) {
				die("No.");
			}
			$state = Request::post('reporting', false, 'string');
			if ($state === false) {
				die('Missing setting value.');
			}
			RemoteReport::setReportingEnabled($state);
		} elseif ($this->action === 'getReporting') {
			echo RemoteReport::isReportingEnabled() ? 'on' : '';
		} else {
			echo 'Invalid action.';
		}
	}

}