-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview_forum.php
363 lines (341 loc) · 12.3 KB
/
view_forum.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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
<?php include 'conn_db.php' ?>
<?php
if(isset($_GET['id'])){
$qry = $conn->query("SELECT t.*,m.name FROM topics t inner join member m on m.id = t.user_id where t.id= ".$_GET['id']);
foreach($qry->fetch_array() as $k => $val){
$$k=$val;
}
$comments = $conn->query("SELECT c.*,m.name,m.matric_no FROM comments c inner join member m on m.id = c.user_id where c.topic_id= ".$_GET['id']." order by unix_timestamp(c.date_created) asc");
$com_arr= array();
while($row= $comments->fetch_assoc()){
$com_arr[] = $row;
}
$replies = $conn->query("SELECT r.*,m.name,m.matric_no FROM replies r inner join member m on m.id = r.user_id where r.comment_id in (SELECT id FROM comments where topic_id= ".$_GET['id'].") order by unix_timestamp(r.date_created) asc");
$rep_arr= array();
while($row= $replies->fetch_assoc()){
$rep_arr[$row['comment_id']][] = $row;
}
if($user_id != $_SESSION['id']){
$chk = $conn->query("SELECT * FROM forum_views where topic_id=$id and user_id='{$_SESSION['id']}' ")->num_rows;
if($chk <= 0){
$conn->query("INSERT INTO forum_views set topic_id=$id , user_id='{$_SESSION['id']}' ");
}
}
$view = $conn->query("SELECT * FROM forum_views where topic_id=$id")->num_rows;
$tags = array();
if(!empty($category_ids)){
$tag = $conn->query("SELECT * FROM categories where id in ($category_ids) order by name asc");
while($row= $tag->fetch_assoc()):
$tags[$row['id']] = $row['name'];
endwhile;
}
}
?>
<style type="text/css">
.avatar {
display: flex;
border-radius: 100%;
width: 100px;
height: 100px;
align-items: center;
justify-content: center;
border: 3px solid;
padding: 5px;
}
.avatar img {
max-width: calc(100%);
max-height: calc(100%);
border-radius: 100%;
}
p{
margin:unset;
}
#content{
max-height: 60vh;
overflow: auto;
}
#content pre {
background: #80808091;
padding:5px;
}
</style>
<div class="container-field">
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<span class="float-right mr-4"><small><i><?php echo date('M d, Y h:i A',strtotime($date_created)) ?></i></small></span>
<span class="float-right mr-4 text-primary"><small><i>Posted By: <?php echo ucwords($name) ?></i></small></span>
<div class="col-md-8">
<h4><b><?php echo $title ?></b></h4>
</div>
<?php if(count($tags) > 0): ?>
<div>
<span class="badge badge-default"><i class="fa fa-tags"></i> Tags: </span>
<?php foreach(explode(',',$category_ids) as $t): ?>
<span class="badge badge-info text-white"><?php echo $tags[$t] ?></span>
<?php endforeach; ?>
</div>
<?php endif; ?>
<hr>
<div class="w-100">
<span class="badge badge-secondary text-white"><?php echo number_format($view) ?> view/s</span>
<span class="badge btn_pink text-white ml-2"><i class="fa fa-comments"></i> <?php echo number_format(count($com_arr)) ?> comment/s</span>
</div>
<div id="content" class="w-100 mt-4">
<?php echo html_entity_decode($content) ?>
</div>
</div>
</div>
<div class="card">
<div class="card-body">
<div class="col-lg-12">
<div class="row">
<h3><b> <i class="fa fa-comments"></i> Comment/s</b></h3>
</div>
<hr class="divider" style="max-width: 100%">
<?php
foreach($com_arr as $row):
?>
<div class="form-group comment">
<?php if($_SESSION['id'] == $row['user_id']): ?>
<div class="dropleft float-right">
<a class="text-dark" href="javascript:void(0)" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="fa fa-ellipsis-v"></span>
</a>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item edit_comment" data-id="<?php echo $row['id'] ?>" href="javascript:void(0)">Edit</a>
<a class="dropdown-item delete_comment" data-id="<?php echo $row['id'] ?>" href="javascript:void(0)">Delete</a>
</div>
</div>
<?php endif; ?>
<span class="float-right mr-4"><small><i>Created: <?php echo date('M d, Y h:i A',strtotime($row['date_created'])) ?></i></small></span>
<p class="mb-0"><large><b><?php echo $row['name'] ?></b></large> <span class="text-primary"><small class="mb-0"><i><?php echo $row['matric_no'] ?></i></small></span></p>
<br>
<?php echo html_entity_decode($row['comment']) ?>
<div>
<span><button class="btn btn-default btn-sm c_reply" data-id='<?php echo $row['id'] ?>'><i class="fa fa-reply"></i></button></span>
<span class="text-primary ml-4"><?php echo isset($rep_arr[$row['id']]) ? count($rep_arr[$row['id']]).(count($rep_arr[$row['id']]) > 1? ' Replies':' Replied') : '' ?></span>
<?php if(isset($rep_arr[$row['id']])): ?>
<hr>
<div class="col-lg-8 offset-lg-2 replies">
<a href="javascript:void(0)" class="show_all" style="display: none">Show all replies</a>
<?php
foreach($rep_arr[$row['id']] as $rep):
?>
<div class="form-group ty-compact-list">
<?php if($_SESSION['id'] == $rep['user_id']): ?>
<div class="dropleft float-right">
<a class="text-dark" href="javascript:void(0)" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="fa fa-ellipsis-v"></span>
</a>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item edit_reply" data-id="<?php echo $rep['id'] ?>" href="javascript:void(0)">Edit</a>
<a class="dropdown-item delete_reply" data-id="<?php echo $rep['id'] ?>" href="javascript:void(0)">Delete</a>
</div>
</div>
<?php endif; ?>
<span class="float-right mr-4"><small><i>Created: <?php echo date('M d, Y h:i A',strtotime($rep['date_created'])) ?></i></small></span>
<p class="mb-0"><large><b><?php echo $rep['name'] ?></b></large> <span class="text-primary"><small class="mb-0"><i><?php echo $rep['matric_no'] ?></i></small></span></p>
<br>
<?php echo html_entity_decode($rep['reply']) ?>
<hr>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<hr>
</div>
<?php endforeach; ?>
</div>
<hr class="divider" style="max-width: 100%">
<div class="col-lg-12">
<form action="" id="manage-comment">
<div class="form-group">
<input type="hidden" name="id" value="">
<input type="hidden" name="topic_id" value="<?php echo isset($id) ? $id : '' ?>">
<textarea class="form-control jqte" id="comment-txt" name="comment" cols="30" rows="5" placeholder="New Comment"></textarea>
</div>
<button class="btn btn_pink">Save Comment</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="reply_clone" style="display: none;">
<div class="col-lg-8 offset-lg-2 reply-field">
<hr>
<form action="" id="">
<div class="form-group">
<input type="hidden" name="id" value="">
<input type="hidden" name="comment_id" value="">
<textarea class="form-control" name="" cols="30" rows="5" placeholder="New Reply"></textarea>
</div>
<button class="btn btn-primary">Reply</button>
</form>
</div>
</div>
<script>
$('.jqte').jqte()
$('.edit_topic').click(function(){
uni_modal("Edit Topic","manage_topic.php?id="+$(this).attr('data-id'),'mid-large')
})
$('.edit_comment').click(function(){
uni_modal("Edit Comment","manage_comment.php?id="+$(this).attr('data-id'),'mid-large')
})
$('.edit_reply').click(function(){
uni_modal("Edit Reply","manage_reply.php?id="+$(this).attr('data-id'),'mid-large')
})
// function _compact(){
$('.replies').each(function(){
if ($(this).find('.ty-compact-list').length > 4) {
var i = $(this).find('.ty-compact-list').length - 5;
for(i; i >= 0 ; i--){
$(this).find('.ty-compact-list:nth("'+i+'")').hide()
}
$(this).find('.show_all').show();
}
})
$('.replies .show_all').click(function(){
var i = $(this).siblings('.ty-compact-list').length - 5;
for(i; i >= 0 ; i--){
$(this).siblings('.ty-compact-list:nth("'+i+'")').toggle()
}
if($(this).text() == 'Show all replies')
$(this).text('Show less')
else
$(this).text('Show all replies')
})
// }
$('.c_reply').click(function(){
if($('.reply-field[data-id="'+$(this).attr('data-id')+'"]').length >0){
return false;
}else{
$('.comment .reply-field').remove()
}
var rtf= $('#reply_clone .reply-field').clone()
rtf.find('form').attr('id','manage-reply')
rtf.find('[name="comment_id"]').val($(this).attr('data-id'))
rtf.find('textarea').attr({'name':"reply",'id':"reply-txt"}).jqte()
rtf.attr('data-id',$(this).attr('data-id'))
if($(this).parent().parent().find('.replies').length > 0)
$(this).parent().parent().find('.replies').parent().after(rtf)
else
$(this).parent().append(rtf)
submit_reply_func()
})
$('.delete_topic').click(function(){
_conf("Are you sure to delete this topic?","delete_topic",[$(this).attr('data-id')],'mid-large')
})
function delete_topic($id){
start_load()
$.ajax({
url:'ajax.php?action=delete_topic',
method:'POST',
data:{id:$id},
success:function(resp){
if(resp==1){
alert_toast("Data successfully deleted",'success')
setTimeout(function(){
location.reload()
},1500)
}
}
})
}
function submit_reply_func(){
$('#manage-reply').submit(function(e){
e.preventDefault()
start_load()
$.ajax({
url:'ajax.php?action=save_reply',
method:'POST',
data:$(this).serialize(),
success:function(resp){
if(resp == 1){
alert_toast("Data successfully saved.",'success')
setTimeout(function(){
location.reload()
},1000)
}
}
})
})
}
$('#manage-comment').submit(function(e){
e.preventDefault()
start_load()
$.ajax({
url:'ajax.php?action=save_comment',
method:'POST',
data:$(this).serialize(),
success:function(resp){
if(resp == 1){
alert_toast("Data successfully saved.",'success')
setTimeout(function(){
location.reload()
},1000)
}
}
})
})
$('.delete_comment').click(function(){
_conf("Are you sure to delete this comment?","delete_comment",[$(this).attr('data-id')],'mid-large')
})
function delete_comment($id){
start_load()
$.ajax({
url:'ajax.php?action=delete_comment',
method:'POST',
data:{id:$id},
success:function(resp){
if(resp==1){
alert_toast("Data successfully deleted",'success')
setTimeout(function(){
location.reload()
},1500)
}
}
})
}
$('.delete_topic').click(function(){
_conf("Are you sure to delete this topic?","delete_topic",[$(this).attr('data-id')],'mid-large')
})
function delete_topic($id){
start_load()
$.ajax({
url:'ajax.php?action=delete_topic',
method:'POST',
data:{id:$id},
success:function(resp){
if(resp==1){
alert_toast("Data successfully deleted",'success')
setTimeout(function(){
location.reload()
},1500)
}
}
})
}
$('.delete_reply').click(function(){
_conf("Are you sure to delete this reply?","delete_reply",[$(this).attr('data-id')],'mid-large')
})
function delete_reply($id){
start_load()
$.ajax({
url:'ajax.php?action=delete_reply',
method:'POST',
data:{id:$id},
success:function(resp){
if(resp==1){
alert_toast("Data successfully deleted",'success')
setTimeout(function(){
location.reload()
},1500)
}
}
})
}
</script>