summaryrefslogtreecommitdiffstats
path: root/modules-available/statistics/pages/projectors.inc.php
blob: 01be2971a3ef7e54ccf11592b4527b1cd9fb652c (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
<?php

class SubPage
{

	public static function doPreprocess()
	{
		$action = Request::post('action', false, 'string');
		if ($action !== false) {
			self::handleProjector($action);
		}
	}

	private static function handleProjector($action)
	{
		User::assertPermission('hardware.projectors.edit');
		$hwid = Request::post('hwid', false, 'int');
		if ($hwid === false) {
			ErrorHandler::traceError('Param hwid missing');
		}
		if ($action === 'addprojector') {
			Database::exec('INSERT IGNORE INTO statistic_hw_prop (hwid, prop, value)'
				. ' VALUES (:hwid, :prop, :value)', array(
				'hwid' => $hwid,
				'prop' => 'projector',
				'value' => 'true',
			));
		} else {
			Database::exec('DELETE FROM statistic_hw_prop WHERE hwid = :hwid AND prop = :prop', array(
				'hwid' => $hwid,
				'prop' => 'projector',
			));
		}
		if (Module::isAvailable('sysconfig')) {
			ConfigTgz::rebuildAllConfigs();
		}
		Util::redirect('?do=statistics&show=projectors');
	}

	public static function doRender()
	{
		self::showProjectors();
	}

	private static function showProjectors()
	{
		User::assertPermission('hardware.projectors.*');
		$res = Database::simpleQuery('SELECT h.hwname, h.hwid FROM statistic_hw h'
			. " INNER JOIN statistic_hw_prop p ON (h.hwid = p.hwid AND p.prop = :projector)"
			. " WHERE h.hwtype = :screen ORDER BY h.hwname ASC", array(
			'projector' => 'projector',
			'screen' => HardwareInfo::SCREEN,
		));
		$data = array(
			'projectors' => $res->fetchAll()
		);
		Render::addTemplate('projector-list', $data);
	}

}