/
list_categories.php
58 lines (47 loc) · 1.33 KB
/
list_categories.php
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
<?php
require_once './config.php';
require_once './lib/alert.class.php';
require_once './lib/user.class.php';
require_once './lib/category.class.php';
$db = new MySQLi(
$config['database']['host'],
$config['database']['username'],
$config['database']['password'],
$config['database']['database']
);
if ($db->connect_errno) {
die('Ei tietokantayhteyttä.');
}
$alertClass = new Alert();
$userClass = new User($db);
if (!$userClass->isLoggedIn()) {
$alertClass->addAlert('Sinun täytyy olla kirjautuneen sisään katsellaksesi kategorioita', 'error');
$alertClass->redirect('/login.php');
}
$user = $userClass->getCurrentUser();
$categoryClass = new Category($db);
$categories = $categoryClass->getAllCategories($user['id']);
$active = 'categories';
require_once 'header.php';
?>
<table class="table">
<thead>
<tr>
<th>ID</th>
<th>Nimi</th>
<th>Kokonaissumma</th>
<th></th>
</tr>
</thead>
<tbody>
<?php foreach ($categories as $category): ?>
<tr>
<td><a href="/view_category.php?id=<?= $category['id'] ?>"><?= $category['id'] ?></a></td>
<td><?= $category['name'] ?></td>
<td><?= $category['total_sum'] ?>€</td>
<td><a href="/view_category.php?id=<?= $category['id'] ?>">Katsele</a></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php require_once 'footer.php'; ?>