-
Notifications
You must be signed in to change notification settings - Fork 154
/
posts.php
267 lines (212 loc) · 9.64 KB
/
posts.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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<?php
session_start();
require 'includes/dbh.inc.php';
define('TITLE',"Forum | KLiK");
if(!isset($_SESSION['userId']))
{
header("Location: login.php");
exit();
}
if (isset($_GET['topic']))
{
$topic = $_GET['topic'];
}
else
{
header("Location: index.php");
exit();
}
include 'includes/HTML-head.php';
?>
<link href="css/forum-styles.css" rel="stylesheet">
</head>
<body>
<?php
include 'includes/navbar.php';
if (isset($_POST['submit-reply']))
{
$content = $_POST['reply-content'];
if (!empty($content))
{
$sql = "insert into posts(post_content, post_date, post_topic, post_by) "
. "values (?,now(),?,?)";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql))
{
die('sql error');
}
else
{
mysqli_stmt_bind_param($stmt, "sss", $content, $topic, $_SESSION['userId']);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
}
}
}
$sql = "select * from topics, categories where topic_id=? "
. "and topic_cat = cat_id";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql))
{
die('sql error');
}
else
{
mysqli_stmt_bind_param($stmt, "s", $topic);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if (!($forum = mysqli_fetch_assoc($result)))
{
die('sql error');
}
}
?>
<br><Br>
<div class="container">
<div class="col-sm-12">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="#">Forums</a></li>
<li class="breadcrumb-item"><a href="#"><?php echo ucwords($forum['cat_name']); ?></a></li>
</ol>
</nav>
<div class="card post-header text-center">
<h1><?php echo ucwords($forum['topic_subject']); ?></h1>
</div>
</div>
<div class="col-sm-12">
<?php
$sql = "select * from posts p, users u "
. "where p.post_topic=? "
. "and p.post_by=u.idUsers "
. "order by p.post_id;";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql))
{
die('sql error');
}
else
{
mysqli_stmt_bind_param($stmt, "s", $topic);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$i = 1;
while ($row = mysqli_fetch_assoc($result))
{
$voted_u = false;
$voted_d = false;
$sql = "select votePost, voteBy, vote from postvotes "
. "where votePost=? "
. "and voteBy=? "
. "and vote=1";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql))
{
die('sql error');
}
else
{
mysqli_stmt_bind_param($stmt, "ss", $row['post_id'], $_SESSION['userId']);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
$resultCheck = mysqli_stmt_num_rows($stmt);
if ($resultCheck == 0)
{
$voted_u = true;
}
}
$sql = "select votePost, voteBy, vote from postvotes "
. "where votePost=? "
. "and voteBy=? "
. "and vote=-1";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql))
{
die('sql error');
}
else
{
mysqli_stmt_bind_param($stmt, "ss", $row['post_id'], $_SESSION['userId']);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
$resultCheck = mysqli_stmt_num_rows($stmt);
if ($resultCheck == 0)
{
$voted_d = true;
}
}
echo '<div class="card post">
<span class="date">'.date("F jS, Y", strtotime($row['post_date']))
.'<span class="span-post-no">#'.$i.'</span> </span>
<div class="row">
<div class="col-sm-3 user">
<div class="text-center">
<img src="uploads/'.$row['userImg'].'" class="img-fluid center-block user-img">
<h3>'.$row['uidUsers'].'</h3>
<small class="text-muted">'.$row['headline'].'</small><br><br>
<table style="width:100%">
<tr>
<th>Joined:</th>
<td>Sep 27, 2018</td>
</tr>
<tr>
<th>Messages:</th>
<td>3</td>
</tr>
<tr>
<th>Likes:</th>
<td>0</td>
</tr>
</table>
<a href="profile.php?id='.$row['idUsers'].'">
<i class="fa fa-user fa-2x" aria-hidden="true"></i></a>
<a href="message.php?id='.$row['idUsers'].'">
<i class="fa fa-envelope fa-2x" aria-hidden="true"></i></a>
</div>
</div>
<div class="col-sm-9 post-content">
<p>'.$row['post_content'].'</p>
<div class="vote text-center">';
if ( ($row['post_by']==$_SESSION['userId']) || ($_SESSION['userLevel'] == 1))
{
echo '<a href="includes/delete-post.php?topic='.$topic.'&post='.$row['post_id'].'&by='.$row['post_by'].'" >'
. '<i class="fa fa-trash fa-2x" aria-hidden="true"></i></a><br>';
}
if ($voted_u)
{
echo "<a href='includes/post-vote.inc.php?topic=".$topic."&post=".$row['post_id']."&vote=1' >";
}
echo '<i class="fa fa-chevron-up fa-3x" aria-hidden="true"></i></a>';
echo '<br><span class="vote-count">'.$row['post_votes'].'</span><br>';
if ($voted_d)
{
echo "<a href='includes/post-vote.inc.php?topic=".$topic."&post=".$row['post_id']."&vote=-1' >";
}
echo '<i class="fa fa-chevron-down fa-3x" aria-hidden="true"></i></a>';
echo '</div>
</div>
</div>
<span class="likes"><span class="span-post-no"></span> <span class="span-post-no"><a
href="">KLiK Forum</a></span></span>
</div>';
$i++;
}
}
?>
</div>
<div class="col-sm-12">
<form method="post" action="">
<fieldset>
<div class="form-group">
<textarea name="reply-content" class="form-control" id="reply-form" rows="7"></textarea>
</div>
<input type="submit" value="Submit reply" class="btn btn-lg btn-dark" name="submit-reply">
</fieldset>
</form>
</div>
</div>
<?php include 'includes/footer.php'; ?>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js" ></script>
</body>
</html>