-
Notifications
You must be signed in to change notification settings - Fork 0
/
notifications.php
173 lines (150 loc) · 7.31 KB
/
notifications.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
<?php
session_start();
include "connectDb.php";
if(isset($_REQUEST['slash']))
$slashes = $_REQUEST['slash'];
if(isset($_REQUEST['notify_typ']))
$notify_typ = $_REQUEST['notify_typ'];
if(strcmp($notify_typ,"DISPLAY") == 0) {
try {
$sql_get_notifications = "select notify_id,notify_confg,view_flag from notifications where user_id = '".$_SESSION['user']."' order by created_ts desc";
$stmt_get_notify = $conn->prepare($sql_get_notifications);
$stmt_get_notify->execute();
if($stmt_get_notify->rowCount() > 0) {
while($row_notify = $stmt_get_notify->fetch()) {
$user_notify_text = $row_notify['notify_confg'];
$user_notify_id = $row_notify['notify_id'];
$user_view_flag = $row_notify['view_flag'];
$user_notify_array=json_decode($user_notify_text,true);
/*
JSON format
commentsJSON -
{
"post_type":"C",
"user_id":null,
"ans_config":
{
"ans_id":0,
"ans_posted_by":null
},
"qstn_config":
{
"qstn_id":0,
"qstn_posted_by":null
}
}
answersJSON -
{
"post_type":"A",
"user_id":null,
"ans_config":
{
"ans_id":0,
"ans_posted_by":null
},
"qstn_config":
{
"qstn_id":0,
"qstn_posted_by":null
}
}
*/
try {
$qid=$user_notify_array['qstn_config']['qstn_id'];
$qstn_posted_by=$user_notify_array['qstn_config']['qstn_posted_by'];
$sql_fetch_qstn_titl="select qstn_titl from questions where qstn_id=".$qid;
foreach($conn->query($sql_fetch_qstn_titl) as $row_qstn)
$qstn_titl_notify=$row_qstn['qstn_titl'];
$ans_posted_by=$user_notify_array['ans_config']['ans_posted_by'];
if($user_notify_array['post_type'] == 'A') {
$a_link = $slashes."qstn_ans.php?qid=".$qid;
if($_SESSION['user'] == $qstn_posted_by) {
$notify_text = '<strong>'.$user_notify_array['user_id'].'</strong> answered your question on <strong>'.$qstn_titl_notify.'</strong>';
}
else if($user_notify_array['user_id'] != $qstn_posted_by) {
$notify_text = '<strong>'.$user_notify_array['user_id'].'</strong> answered <strong>'.$qstn_posted_by.'\'s</strong> question on <strong>'.$qstn_titl_notify.'</strong>';
}
else {
$notify_text = '<strong>'.$user_notify_array['user_id'].'</strong> answered a question on <strong>'.$qstn_titl_notify.'</strong>';
}
}
else if($user_notify_array['post_type'] == 'C') {
$ansid=$user_notify_array['ans_config']['ans_id'];
$a_link = $slashes."qstn_ans.php?qid=".$qid."#user-answer-".$ansid;
if($_SESSION['user'] == $qstn_posted_by and $_SESSION['user'] == $ans_posted_by) {
$notify_text = '<strong>'.$user_notify_array['user_id'].'</strong> commented on your answer to your question on <strong>'.$qstn_titl_notify.'</strong>';
}
else if($_SESSION['user'] != $qstn_posted_by and $_SESSION['user'] == $ans_posted_by){
if($user_notify_array['user_id'] != $qstn_posted_by)
$notify_text = '<strong>'.$user_notify_array['user_id'].'</strong> commented on your answer to <strong>'.$qstn_posted_by.'\'s</strong> question on <strong>'.$qstn_titl_notify.'</strong>';
else
$notify_text = '<strong>'.$user_notify_array['user_id'].'</strong> commented on your answer to question on <strong>'.$qstn_titl_notify.'</strong>';
}
else if($_SESSION['user'] == $qstn_posted_by and $_SESSION['user'] != $ans_posted_by){
if($user_notify_array['user_id'] != $ans_posted_by)
$notify_text = '<strong>'.$user_notify_array['user_id'].'</strong> commented on '.$ans_posted_by.'\'s answer to your question on <strong>'.$qstn_titl_notify.'</strong>';
else
$notify_text = '<strong>'.$user_notify_array['user_id'].'</strong> commented on an answer to your question on <strong>'.$qstn_titl_notify.'</strong>';
}
else {
if($qstn_posted_by == $ans_posted_by) {
if($user_notify_array['user_id'] != $qstn_posted_by)
$notify_text = '<strong>'.$user_notify_array['user_id'].'</strong> commented on an answer to <strong>'.$qstn_posted_by.'\'s</strong> question on <strong>'.$qstn_titl_notify.'</strong>';
else
$notify_text = '<strong>'.$user_notify_array['user_id'].'</strong> commented on an answer to the question on <strong>'.$qstn_titl_notify.'</strong>';
}
else {
if($user_notify_array['user_id'] != $qstn_posted_by and $user_notify_array['user_id'] != $ans_posted_by)
$notify_text = '<strong>'.$user_notify_array['user_id'].'</strong> commented on '.$ans_posted_by.'\'s answer to <strong>'.$qstn_posted_by.'\'s</strong> question on <strong>'.$qstn_titl_notify.'</strong>';
else if($user_notify_array['user_id'] != $qstn_posted_by and $user_notify_array['user_id'] == $ans_posted_by)
$notify_text = '<strong>'.$user_notify_array['user_id'].'</strong> commented on an answer to <strong>'.$qstn_posted_by.'\'s</strong> question on <strong>'.$qstn_titl_notify.'</strong>';
else if($user_notify_array['user_id'] == $qstn_posted_by and $user_notify_array['user_id'] != $ans_posted_by)
$notify_text = '<strong>'.$user_notify_array['user_id'].'</strong> commented on '.$ans_posted_by.'\'s answer to a question on <strong>'.$qstn_titl_notify.'</strong>';
}
}
}
}
catch(Exception $e) {
}
if($user_view_flag == 'Y')
$notify_div_class = "<a data-id='".$user_notify_id."' id='notify-message-".$user_notify_id."' class='list-group-item' href='".$a_link."' style='min-height:50px;' onclick='updateNotify(this.getAttribute(\"data-id\"))' >";
else
$notify_div_class = "<a data-id='".$user_notify_id."' id='notify-message-".$user_notify_id."' class='list-group-item list-view-on' href='".$a_link."' style='min-height:50px;' onclick='updateNotify(this.getAttribute(\"data-id\"))' >";
try {
$sql_get_user_pic = "select pro_img_url from users where user_id='".$user_notify_array['user_id']."'";
foreach($conn->query($sql_get_user_pic) as $row_pic)
$user_notify_pic = $slashes.$row_pic['pro_img_url'];
}
catch(PDOException $e) {
}
echo $notify_div_class.'<div class="notify-user-pic" style="background-image:url(\''.$user_notify_pic.'\'); background-size:cover;"></div>
<div class="notify-text-section">'.$notify_text.'</div></a>';
}
}
else
echo "You don't have any new notifications";
}
catch(PDOException $e) {
echo "Some error occured in fetching notifications. Please try again after some time";
}
}
else if(strcmp($notify_typ,"UPDATE") == 0) {
if(isset($_REQUEST["notify_id"]))
$notify_id = $_REQUEST["notify_id"];
try {
if($notify_id != -1)
$sql_updt_notifications = "update notifications set view_flag = 'Y' ,view_ts=CURRENT_TIMESTAMP where notify_id=".$notify_id;
else
$sql_updt_notifications = "update notifications set view_flag = 'Y' ,view_ts=CURRENT_TIMESTAMP where user_id='".$_SESSION['user']."'";
$stmt_updt_notification = $conn->prepare($sql_updt_notifications);
$stmt_updt_notification->execute();
if($stmt_updt_notification->rowCount() > 0)
echo 1;
else
echo 0;
}
catch(PDOException $e) {
echo -1;
}
}
?>