This repository was archived by the owner on Aug 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcategory.php
More file actions
143 lines (138 loc) · 4.33 KB
/
category.php
File metadata and controls
143 lines (138 loc) · 4.33 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
include 'include/header.php';
?>
<div class="container mt-3">
<?php
if ($_GET) {
$forum_id = $_GET['forum'];
$category_id = $_GET['category'];
$forums = $database->prepare("SELECT * FROM forums WHERE id = ?;");
$forums->execute(array($forum_id));
$category = $database->prepare("SELECT * FROM categories WHERE id = ?;");
$category->execute(array($category_id));
$category_row = $category->fetch(PDO::FETCH_OBJ);
$error = '';
if (empty($forum_id) || empty($category_id)) {
$error = 'Podana kategoria lub forum nie istnieje!';
} else if ($forums->rowCount() <= 0) {
$error = 'Podana kategoria lub forum nie istnieje!';
} else if ($category->rowCount() <= 0) {
$error = 'Podana kategoria lub forum nie istnieje!';
}
if (empty($error)) {
if (USER_ID && $category_row->type != 2) {
?>
<div class="mb-3">
<a class="btn btn-primary" href="<?= $config['default']['link'] ?>new-topic.php?forum=<?= $forum_id ?>&category=<?= $category_id ?>">Stwórz temat</a>
</div>
<?php
}
?>
<?php
$topics = $database->prepare("SELECT * FROM topics WHERE forum_id = ? AND category_id = ?;");
$topics->execute(array($forum_id, $category_id));
if ($topics->rowCount() <= 0) {
alert('info', 'Podana kategoria nie zawiera żadnych tematów.<br>Stwórz temat aby być pierwszym!');
} else {
?>
<div class="card mb-3">
<table class="table mb-0">
<thead>
<tr>
<th scope="col" width="54%">
Temat
</th>
<th scope="col" width="10%" class="text-center">
Postów
</th>
<th scope="col" width="10%" class="text-center">
Wyświetleń
</th>
<th scope="col" width="26%">
Ostatni post
</th>
</tr>
</thead>
<tbody>
<?php
while ($topics_row = $topics->fetch(PDO::FETCH_OBJ)) {
?>
<tr>
<td>
<?php if ($topics_row->type == 2) { ?>
<span class="badge badge-dark"><i class="fas fa-lock"></i></span>
<?php } ?>
<a href="<?= $config['default']['link'] ?>topic.php?forum=<?= $forum_id ?>&category=<?= $category_id ?>&topic=<?= $topics_row->id ?>">
<b><?= $topics_row->name ?></b>
</a>
<?php
$author = $database->prepare("SELECT * FROM users WHERE id = ?;");
$author->execute(array($topics_row->user_id));
$author_row = $author->fetch(PDO::FETCH_OBJ);
?>
<br>
Autor: <a href='profile.php?id=<?= $author_row->id ?>'><?= $author_row->username ?></a>
</td>
<td class="text-center">
<?php
$topics_posts = $database->prepare("SELECT * FROM posts WHERE topic_id = ?;");
$topics_posts->execute(array($topics_row->id));
$topics_posts_count = $topics_posts->rowCount();
?>
<div style="font-size: 20px; font-weight: 900;">
<?= $topics_posts_count ?>
</div>
<div class="text-muted" style="font-size: 12px;">Postów</div>
</td>
<td class="text-center">
<div style="font-size: 20px; font-weight: 900;">
<?= $topics_row->views ?>
</div>
<div class="text-muted" style="font-size: 12px;">Wyświetleń</div>
</td>
<td>
<?php
$post = $database->prepare('SELECT * FROM posts WHERE forum_id = ? AND category_id = ? ORDER BY id DESC LIMIT 1;');
$post->execute(array($forum_id, $category_id));
$post_row = $post->fetch(PDO::FETCH_OBJ);
if (empty($post_row)) {
?>
<span class="text-muted">Brak</span>
<?php
} else {
$post_user = $database->prepare('SELECT * FROM users WHERE id = ?;');
$post_user->execute(array($post_row->user_id));
$post_user_row = $post_user->fetch(PDO::FETCH_OBJ);
?>
<div style="display: inline-block;">
<a href="profile.php?id=<?= $post_user_row->id ?>">
<b><?= $post_user_row->username ?></b>
</a>
<br>
<span class="text-muted"><?= $post_row->created ?></span>
</div>
<canvas class="user-icon rounded" data-name="<?= $post_user_row->username ?>" width="42" height="42" style="float: left; display: inline-block; margin-right: 6px;" data-chars="1"></canvas>
<?php
}
?>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<?php
}
} else {
alert('danger', $error);
}
} else {
alert('danger', 'Podana kategoria lub forum nie istnieje!');
}
?>
</div>
<?php
include 'include/footer.php';
?>