-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddReply.php
More file actions
133 lines (83 loc) · 3.8 KB
/
addReply.php
File metadata and controls
133 lines (83 loc) · 3.8 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
<?php
session_start();
header("Access-Control-Allow-Origin: *");
require_once 'config/appsConfig.php';
require_once 'middleware/Xss.php';
require_once 'middleware/Csrf.php';
$apps = new appsConfig();
appsConfig::loadLibaryClass();
$d = new DBContext();
$comment = $_GET['comment'];
$username = $_GET['username'];
$questionsid = $_GET['questionsid'];
$reply = $_GET['reply'];
$data = ['comment'=>$comment,'username'=>$username,'questionid'=>$questionsid,'reply'=>$reply,'dates'=>date('y-m-d')];
$sql = "insert into comments(comment,username,questionid,reply,dates) values('".$comment."','".$username."',".$questionsid.",".$reply.",".date('y-m-d').")";
if($d->customAdd($sql)){
$sql = "select * from comments where questionid =".$questionsid." order by id desc";
foreach ($d->customGet($sql) as $key => $value) {
?>
<?php
$d = new DBContext();
$sql = "select * from comments where questionid =".$value['id']." and reply is null order by id desc";
foreach ($d->customGet($sql) as $key => $v) {
echo '<div class="cmt-box">
<p style="color:black"><b>'.$v['username'].'</b></p>
<p>'.$v['comment'].'</p>';
echo '<p><a href="javascript:void(0)" onclick="like('.$value['id'].','.$v['id'].')">Like</a>
<a href="javascript:void(0)" onclick="Reply('.$v['id'].')">Reply</a> ';
echo '<a href=""><i class="far fa-thumbs-up"></i> <span id="likeResult'.$v['id'].'">';
//like here
$cmd = "select * from likes where questionsid =".$value['id']." and commentid =".$v['id'];
echo $d->dataCount($cmd);
echo'</span></a>
<a href="" style="font-size: 12px;color:gray;text-decoration: none;">'.date("F j, Y g:i a", strtotime($v['dates'])).'</a>
</p>';
$ccc = "select * from comments where questionid =".$value['id']." and reply = ".$v['id']." order by id desc";
echo '<div class="reply-box">';
//start reply
//reply form
if(isset($_SESSION['username'])){
echo '
<form method="post" action="" class="form-display" id="replyForm'.$v['id'].'">
<p><b>Write your commnet here...</b></p>
<textarea name="comment" id="commentReply'.$v['id'].'">
</textarea>
<input type="hidden" name="username" value="'.$_SESSION['username'].'" id="usernameReply'.$v['id'].'"/>
<input type="hidden" name="questionsid" value="'.$value['id'].'" id="questionsidReply'.$v['id'].'"/>
<button type="button" class="commentSubmitbtn" onclick="addReply('.$v['id'].')">Submit</button>
</form>';
}//end reply form
if($d->dataCount($ccc)){
foreach ($d->customGet($ccc) as $key => $item) {
echo '<div class="cmt-box" style="border-bottom:1px solid #FFFFFF;margin-bottom:10px;padding-top:0px">
<p style="color:black"><b>'.$item['username'].'</b></p>
<p>'.$item['comment'].'</p>';
if(isset($_SESSION['username'])){
echo '<p><a href="javascript:void(0)" onclick="like('.$value['id'].','.$item['id'].')">Like</a>
<a href="javascript:void(0)">Reply</a> ';
}else{
echo '<p><a href="javascript:void(0)">Like</a>
<a href="javascript:void(0)">Reply</a> ';
}
echo '<a href="#"><i class="far fa-thumbs-up"></i> <span id="likeResult'.$item['id'].'">';
//like here
$cmd = "select * from likes where questionsid =".$value['id']." and commentid =".$item['id'];
echo $d->dataCount($cmd);
echo'</span></a>
<a href="" style="font-size: 12px;color:gray;text-decoration: none;">'.date("F j, Y g:i a", strtotime($item['dates'])).'</a>
</p>
</div>';
}
}//end if
//end reply
echo '</div>';
echo '</div>';
}
?>
<?php }
}else{
print_r($d->Error);
echo 'reply not added';
}
?>