-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtemp-notifications.php
More file actions
208 lines (174 loc) · 7.87 KB
/
temp-notifications.php
File metadata and controls
208 lines (174 loc) · 7.87 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
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
<?php
include_once('./parts/entryCheck.php');
include_once('./server/db_connection.php');
include_once('./server/validation.php');
include_once('./server/functions.php');
$aboutSite = $connection->query('SELECT * FROM `system_data`');
$aboutSite = $aboutSite->fetch_array(MYSQLI_ASSOC);
include_once("./server/auto-routes.php");
?>
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<link rel='stylesheet' href='style.css'>
<link rel="stylesheet" href="./assets/css/all.min.css">
<link rel="stylesheet" href="./assets/css/fontawesome.css">
<link rel='preconnect' href='https://fonts.googleapis.com'>
<link rel='preconnect' href='https://fonts.gstatic.com' crossorigin>
<link href='https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap' rel='stylesheet'>
<link rel="shortcut icon" href="./assets/images/favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="./assets/css/navbar.css">
<link rel="stylesheet" href="./assets/css/boxicons/css/boxicons.min.css">
<title>Notifications -
<?php echo $aboutSite['system_name']; ?>
</title>
<style>
#share-btn {
border: none;
background-color: white;
cursor: pointer;
}
#share-btn:hover {
background-color: rgba(0, 0, 0, 0.2);
}
.right-nav-item {
width: 60%;
justify-content: space-between;
}
.notification-right-part {
width: 100%;
}
.section-heading {
width: 70%;
}
</style>
<?php include_once("../MitraPark/assets/css/dynamicColor.php"); ?>
<?php echo "<script>localStorage.setItem('mp-uid','" . $_SESSION['user']['uid'] . "')</script>"; ?>
</head>
<body>
<?php
include_once("./parts/navbar.php");
include_once("./parts/leftSidebar.php");
?>
<div class="mid-body">
<div class="left-inner-heading section-heading">
<span class="dim-label">
Notifications
</span>
<hr class="label-underline">
</div>
<?php
$uid = $_SESSION['user']['uid'];
// Query for request-related notifications
$requestQuery = "SELECT CONCAT(fname, ' ',lname) as uname,
profile_picture,
type,
created_date_time,
component_id,
triggered_by
FROM notifications n
INNER JOIN users u ON triggered_by = u.uid
WHERE triggered_by <> '$uid' AND component_id = '$uid'
ORDER BY created_Date_time DESC";
$result = mysqli_query($connection, $requestQuery);
$requestNotification = mysqli_affected_rows($connection);
while ($row = mysqli_fetch_assoc($result)) {
if ($row['type'] == 'request_received') {
displayRequestNotification($row);
} elseif ($row['type'] == 'request_accepted') {
displayAcceptedNotification($row);
}
}
// Query for other notifications (likes, comments)
$otherQuery = "SELECT CONCAT(fname, ' ',lname) AS uname,
profile_picture,
type,
created_date_time,
component_id
FROM notifications n
INNER JOIN users u ON triggered_by = u.uid
WHERE triggered_by <> '$uid' AND component_id IN (SELECT post_id FROM posts WHERE author_id = '$uid')
ORDER BY created_date_time DESC";
$result = mysqli_query($connection, $otherQuery);
$otherNotification = mysqli_affected_rows($connection);
while ($row = mysqli_fetch_assoc($result)) {
if ($row['type'] == 'like') {
displayLikeNotification($row);
} elseif ($row['type'] == 'comment') {
displayCommentNotification($row);
} elseif ($row['type'] == 'request_received') {
displayRequestNotification($row);
}
}
if($otherNotification + $requestNotification == 0)
{
echo "<p>No notifications found.</p>";
}
// Function to display a request notification
function displayRequestNotification($row)
{
echo '
<a class="right-nav-item" href="./user.php?id=' . $row['triggered_by'] . '">
<img class="right-nav-item-img" src="./' . $row['profile_picture'] . '">
<div class="notification-right-part" style="display:flex; flex-direction:column;">
<span><b>' . $row['uname'] . '</b> sent you Mitra request.</span>
<span style="font-size: small; color: #373737;">' . timeAgo($row['created_date_time']) . ' </span>
</div>
</a>
';
}
// Function to display an accepted notification
function displayAcceptedNotification($row)
{
echo '
<a class="right-nav-item" href="./user.php?id=' . $row['triggered_by'] . '">
<img class="right-nav-item-img" src="./' . $row['profile_picture'] . '">
<div class="notification-right-part" style="display:flex; flex-direction:column;">
<span><b>' . $row['uname'] . '</b> accepted your Mitra request.</span>
<span style="font-size: small; color: #373737;">' . timeAgo($row['created_date_time']) . ' </span>
</div>
</a>
';
}
// Function to display a like notification
function displayLikeNotification($row)
{
echo '
<a class="right-nav-item" href="./post.php?postId=' . $row['component_id'] . '">
<img class="right-nav-item-img" src="./' . $row['profile_picture'] . '">
<div class="notification-right-part" style="display:flex; flex-direction:column;">
<span><b>' . $row['uname'] . '</b> liked your post.</span>
<span style="font-size: small; color: #373737;">' . timeAgo($row['created_date_time']) . ' </span>
</div>
</a>
';
}
// Function to display a comment notification
function displayCommentNotification($row)
{
echo '
<a class="right-nav-item" href="./post.php?postId=' . $row['component_id'] . '">
<img class="right-nav-item-img" src="./' . $row['profile_picture'] . '">
<div class="notification-right-part" style="display:flex; flex-direction:column;">
<span><b>' . $row['uname'] . '</b> commented in your post.</span>
<span style="font-size: small; color: #373737;">' . timeAgo($row['created_date_time']) . ' </span>
</div>
</a>
';
}
?>
</div>
<?php
$setSeenNotifications = "UPDATE `notifications` SET `seen_status`=1 WHERE `author_id`='$uid'";
$result = mysqli_query($connection, $setSeenNotifications);
?>
<?php
include_once("./parts/rightSidebar.php");
?>
<script src='./assets/scripts/jquery.js'></script>
<?php include_once("./parts/js-script-files/js-script.php");?>
<?php include_once("./parts/js-script-files/strict-and-activity-update.php"); ?>
</body>
</html>