aboutsummaryrefslogtreecommitdiffstats
path: root/admin/index.php
blob: 1cddb8c9ae4545aa6634c798df58e9e9208952d7 (plain)
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
77
78
79
80
81
82
83
84
85
86
87
88
<?php
#===============================================================================
# DEFINE: Administration
#===============================================================================
define('ADMINISTRATION', TRUE);
define('AUTHENTICATION', TRUE);

#===============================================================================
# INCLUDE: Main configuration
#===============================================================================
require '../core/application.php';

#===============================================================================
# TRY: PDOException
#===============================================================================
try {
	$LastPageStatement = $Database->query(sprintf('SELECT id FROM %s ORDER BY time_insert DESC LIMIT 1', Page\Attribute::TABLE));
	$LastPostStatement = $Database->query(sprintf('SELECT id FROM %s ORDER BY time_insert DESC LIMIT 1', Post\Attribute::TABLE));
	$LastUserStatement = $Database->query(sprintf('SELECT id FROM %s ORDER BY time_insert DESC LIMIT 1', User\Attribute::TABLE));

	$PageCountStatement = $Database->query(sprintf('SELECT COUNT(*) FROM %s', Page\Attribute::TABLE));
	$PostCountStatement = $Database->query(sprintf('SELECT COUNT(*) FROM %s', Post\Attribute::TABLE));
	$UserCountStatement = $Database->query(sprintf('SELECT COUNT(*) FROM %s', User\Attribute::TABLE));
}

#===============================================================================
# CATCH: PDOException
#===============================================================================
catch(PDOException $Exception) {
	exit($Exception->getMessage());
}

#===============================================================================
# TRY: Template\Exception
#===============================================================================
try {
	try {
		$LastPage = Page\Factory::build($LastPageStatement->fetchColumn());
		$LastPageUser = User\Factory::build($LastPage->attr('user'));

		$PageItemTemplate = generatePageItemTemplate($LastPage, $LastPageUser);
	}

	catch(Page\Exception $Exception){}
	catch(User\Exception $Exception){}

	try {
		$LastPost = Post\Factory::build($LastPostStatement->fetchColumn());
		$LastPostUser = User\Factory::build($LastPost->attr('user'));

		$PostItemTemplate = generatePostItemTemplate($LastPost, $LastPostUser);
	}

	catch(Post\Exception $Exception){}
	catch(User\Exception $Exception){}

	try {
		$LastUser = User\Factory::build($LastUserStatement->fetchColumn());
		$UserItemTemplate = generateUserItemTemplate($LastUser);
	} catch(User\Exception $Exception){}

	$HomeTemplate = Template\Factory::build('home');
	$HomeTemplate->set('LAST', [
		'PAGE' => $PageItemTemplate ?? FALSE,
		'POST' => $PostItemTemplate ?? FALSE,
		'USER' => $UserItemTemplate ?? FALSE,

	]);

	$HomeTemplate->set('COUNT', [
		'PAGE' => $PageCountStatement->fetchColumn(),
		'POST' => $PostCountStatement->fetchColumn(),
		'USER' => $UserCountStatement->fetchColumn(),
	]);

	$MainTemplate = Template\Factory::build('main');
	$MainTemplate->set('NAME', 'Dashboard');
	$MainTemplate->set('HTML', $HomeTemplate);
	echo $MainTemplate;
}

#===============================================================================
# CATCH: Template\Exception
#===============================================================================
catch(Template\Exception $Exception) {
	Application::exit($Exception->getMessage());
}
?>