-
Notifications
You must be signed in to change notification settings - Fork 0
/
threadlist.php
308 lines (212 loc) · 9.55 KB
/
threadlist.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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
<?php session_start(); ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Threads</title>
<!--------- Bootstrap CSS ------------->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="./css/threadlist.css">
</head>
<body>
<?php
/*
Connecting Database
*/
include './partials/_dbconnect.php';
/*
Navbar
*/
include './partials/_header.php';
?>
<?php
$method = $_SERVER['REQUEST_METHOD'];
if($method == 'POST')
{
// Insert thread into db
$th_title = $_POST['title'];
$th_desc = $_POST['desc'];
// convert all html entities to string inside single quote and double quotes
$th_desc = htmlentities($th_desc, ENT_QUOTES);
$th_title = htmlentities($th_title, ENT_QUOTES);
// // protection from attack
// $th_desc = str_replace("<","<",$th_desc);
// $th_desc = str_replace(">",">",$th_desc);
// how to use enter in next line in code
$th_desc = str_replace("\n","<br>",$th_desc);
$th_title = str_replace("\n","<br>",$th_title);
$id = $_GET['catid'];
$userid = $_SESSION['userid'];
if($th_desc != "" || $th_desc != "")
{
$sql = "INSERT INTO `threads`(`thread_subject`,`thread_description`,`thread_cat_id`,`thread_user_id`,`thread_time`) VALUES ('$th_title','$th_desc','$id','$userid',current_timestamp())";
$result = mysqli_query($conn,$sql);
if($result){
$error = false;
$message = "Your question is been addesuccesssfully into forum.";
alertdisplay($message,$error);
}
else
{
$error = true;
$message = "Your question is not added to forubecause of some technical issue.";
alertdisplay($message,$error);
}
}else
{
$error = true;
$message = "Please fill both title and descriptioof your question into the form.";
alertdisplay($message,$error);
}
}
?>
<?php
// Alert message
function alertdisplay($message,$error){
if($error){
echo '
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<strong> Failed! </strong>'.$message.'
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
';
}else{
echo '
<div class="alert alert-success alert-dismissible fade show" role="alert">
<strong> Successfull! </strong> '.$message.'
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
';
}
}
?>
<div class="container main-con">
<?php
// get request from url
$id = $_GET['catid'];
$sql = "SELECT * FROM `categories` WHERE `category_id` = $id";
$result = mysqli_query($conn,$sql);
while($row = mysqli_fetch_assoc($result)){
$catname = $row['category_name'];
$catdesc = $row['category_description'];
}
?>
<div class="jumbotron mt-3 p-3 rounded-3">
<h1 class="display-4 text-muted text-capitalize"><span class="forumName">
<?php
echo "$catname";
?>
</span> Forums</h1>
<p class="lead catdesc">
<?php
echo "$catdesc";
?>
</p>
<hr class="my-4">
<p class="rules-heading">Forum Rules</p>
<ol class="rules">
<li>
No Spam / Advertising / Self-promote in the forums.
</li>
<li>
Do not post copyright-infringing material.
providing or asking for information on how to illegally obtain copyrighted materials is forbidden.
</li>
<li>
Do not post “offensive” posts, links or images
</li>
<li>
Do not cross post questions.
</li>
<li>
Do not send private messages to any users asking for help.
</li>
<li>
Remain respectful of other members at all times.
</li>
</ol>
</div>
<!-------------------------------------------
Discussion form
-------------------------------------------->
<div class="container my-3 discussionform">
<p class="disformheading text-center">Start a Discussion</p>
<?php
if(isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true){
echo '<form action=" '.$_SERVER['REQUEST_URI'] . '" method="post">
<div class="mb-3">
<label for="problemtitle" class="form-label">Problem Title</label>
<input type="text" class="form-control" id="problemtitle" name="title"
placeholder="what do you want to ask ?">
</div>
<div class="mb-3">
<label for="exampleFormControlTextarea1" class="form-label">Problem Description</label>
<textarea class="form-control" name="desc" id="exampleFormControlTextarea1" rows="3"
placeholder="Describe your problem in detail."></textarea>
</div>
<button type="submit" class="btn btn-success">Ask Question</button>
</form>';
}else{
echo '<div class="loginmessage text-center">
<p>You are not logged in. Please <span id="loginmodalopen">login</span> to start the disscussion and post your query</p>
</div>';
// redirect to same page after login and signup
$currpage = $_SERVER['REQUEST_URI'];
$_SESSION['currpageaddress'] = $currpage;
}
?>
</div>
<div class="container my-4">
<p class="quesheading mb-3">Browse Question</p>
<?php
$cat_id = $_GET['catid'];
$sqlques = "SELECT * FROM `threads` WHERE `thread_cat_id` = $cat_id ORDER BY `thread_id` DESC";
$result = mysqli_query($conn,$sqlques);
$numRow = mysqli_num_rows($result);
if($numRow > 0){
while($rowdata = mysqli_fetch_assoc($result)){
$threadID = $rowdata['thread_id'];
$threadSub = $rowdata['thread_subject'];
$threadDesc = $rowdata['thread_description'];
$threadSub = str_replace("<br>","\n",$threadSub);
$threadDesc = str_replace("<br>","\n",$threadDesc);
$threadtime = $rowdata['thread_time'];
$userid = $rowdata['thread_user_id'];
$usersql = "SELECT * FROM `users` WHERE `user_id` = '$userid'";
$userres = mysqli_query($conn,$usersql);
while($userdata = mysqli_fetch_assoc($userres)){
echo '
<div class="media d-flex align-items-center my-3">
<img class="mr-3" src="images/user_default_img.png" alt="Generic placeholder image">
<div class="media-body">
<h5 class="mt-0"><a class="threadhead" href="thread.php?thread_id='.$threadID.'">'.$threadSub.'</a></h5>
<p class="threadDesc">'.substr($threadDesc,0,200).'....<a class="readmore" href="thread.php?thread_id='.$threadID.'">readmore</a>
</p>
<p class="time">Asked by <span class="name">'.$userdata['username'].'</span> on : '.date("l jS \of F Y - h:i:s A",strtotime($threadtime)).'</p>
</div>
</div>';
}
}
}else{
echo '<div class="container no-message">
<p>No thread found. Be the first person to ask.</p>
</div>';
}
?>
</div>
</div>
<!--------footer--------->
<?php
include './partials/_footer.php';
?>
<!-------------- Jquery CDN ----------------->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous">
</script>
<!--------- Bootstrap JS ------------->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script src="./js/threadlist.js"></script>
</body>
</html>