summaryrefslogtreecommitdiffstats
path: root/modules-available/eventlog/page.inc.php
blob: 320c3b0739623f0c2707950a3a72aa9dbfde484c (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
67
68
69
70
71
72
73
74
75
76
<?php

class Page_EventLog extends Page
{

	protected function doPreprocess()
	{
		User::load();
		if (!User::isLoggedIn()) {
			Message::addError('main.no-permission');
			Util::redirect('?do=Main');
		}
		if (User::hasPermission("view")) {
			User::setLastSeenEvent(Property::getLastWarningId());
		}
	}

	protected function doRender()
	{
		Render::addTemplate("heading");
		if (User::hasPermission("view")) {
			$today = date('d.m.Y');
			$yesterday = date('d.m.Y', time() - 86400);
			$lines = array();
			$paginate = new Paginate("SELECT logid, dateline, logtypeid, description, extra FROM eventlog ORDER BY logid DESC", 50);
			$res = $paginate->exec();
			while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
				$day = date('d.m.Y', $row['dateline']);
				if ($day === $today) {
					$day = Dictionary::translate('lang_today');
				} elseif ($day === $yesterday) {
					$day = Dictionary::translate('lang_yesterday');
				}
				$row['date'] = $day . date(' H:i', $row['dateline']);
				$row['icon'] = $this->typeToIcon($row['logtypeid']);
				$row['color'] = $this->typeToColor($row['logtypeid']);
				$lines[] = $row;
			}

			$paginate->render('_page', array(
				'list' => $lines
			));
		} else {
			Message::addError('main.no-permission');
		}
	}

	private function typeToIcon($type)
	{
		switch ($type) {
			case 'info':
				return 'ok';
			case 'warning':
				return 'exclamation-sign';
			case 'failure':
				return 'remove';
			default:
				return 'question-sign';
		}
	}

	private function typeToColor($type)
	{
		switch ($type) {
			case 'info':
				return '';
			case 'warning':
				return 'orange';
			case 'failure':
				return 'red';
			default:
				return '';
		}
	}

}