aboutsummaryrefslogtreecommitdiffstats
path: root/admin/index.php
blob: 788cee457b9b4ef754cbfe8ef2d22b3e3fe55177 (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
<?php
#===============================================================================
# DEFINE: Administration
#===============================================================================
define('ADMINISTRATION', TRUE);
define('AUTHENTICATION', TRUE);

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

#===============================================================================
# Fetch last items and item count
#===============================================================================
$execute = 'SELECT id FROM %s ORDER BY time_insert DESC LIMIT 1';
$LastPageStatement = $Database->query(sprintf($execute, Page\Attribute::TABLE));
$LastPostStatement = $Database->query(sprintf($execute, Post\Attribute::TABLE));
$LastUserStatement = $Database->query(sprintf($execute, User\Attribute::TABLE));

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

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){}

#===============================================================================
# Build document
#===============================================================================
$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;