-
Notifications
You must be signed in to change notification settings - Fork 1
/
message.php
194 lines (172 loc) · 8.4 KB
/
message.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
<?php
@ob_start();
session_start();
date_default_timezone_set('Asia/Singapore');
if (!isset( $_SESSION['NUSEmail'] ) ) {
// Redirect them to the login page
if ($_SERVER['SERVER_PORT'] == '80' || $_SERVER['SERVER_PORT'] =='443'){
header("Location: http://localhost/orbital/signup.php");
}
else{
header("Location: http://localhost:8080/orbital/signup.php");
}
}
?>
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<link rel="icon" href="img\studylah_logo.jpg" type="image/jpg">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300&display=swap" rel="stylesheet">
<link rel="stylesheet" href="css\navbar.css">
<link rel="stylesheet" href="css\message.css">
<title>StudyLah</title>
</head>
<style>
#newmessage:hover{
opacity:0.7;
cursor:pointer;
}
.centertable{
margin:0 auto;
border-collapse:separate;
border-spacing:0;
width:70%;
}
tr, td{
padding:15px;
text-align:left;
border-bottom:1px solid #bfbfbf;
border-collapse:separate;
border-spacing:0;
}
.groupprofilepic{
border-radius:50%;
}
.groupnamefont{
font-size:20px;
}
.thefinalmessage{
color:#adacac;
}
.eachchatrow:hover{
opacity:0.7;
cursor:pointer;
}
.notificationcounts{
border-radius:50%;
background-color:maroon;
color:white;
font-weight:bold;
font-size:12px;
padding:5px 10px;
}
</style>
<body style="font-family: 'Inter', sans-serif;">
<!--navbar-->
<?php include('header.php');?>
<!--message section-->
<section style="background-color:#424240;">
<section id="messagesection">
<div>
<div class="bigtext">Messages </div>
<div>
<?php
if ($_SERVER['SERVER_PORT'] == '80' || $_SERVER['SERVER_PORT'] =='443'){
echo "<a href=\"http://localhost/orbital/createmessage.php\"><img src=\"img/new-email.png\" width=\"50px\" height=\"50px\" alt=\"new message\" id=\"newmessage\"></a>";
}
else{
echo "<a href=\"http://localhost:8080/orbital/createmessage.php\"><img src=\"img/new-email.png\" width=\"50px\" height=\"50px\" alt=\"new message\" id=\"newmessage\"></a>";
}
?>
</div>
<div style="margin-bottom:30px;"></div>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname= "orbital";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$useremail=$_SESSION['NUSEmail'];
$sqlgetgroups = "SELECT * FROM messages WHERE NUSEmail='$useremail' GROUP BY GroupID";//group by is no duplicate
$resultgetgroups = mysqli_query($conn,$sqlgetgroups);
echo "<table class=\"centertable\">";
if(mysqli_num_rows($resultgetgroups) > 0){//got existing messages, groups etc
while($rowgetgroups=mysqli_fetch_array($resultgetgroups)){
//display group details etc
$mygroups = $rowgetgroups['GroupID'];
$sqlgroupdetails = "SELECT * FROM groups WHERE GroupID='$mygroups'";
$resultgroupdetails = mysqli_query($conn,$sqlgroupdetails);
while($rowgroupdetails=mysqli_fetch_array($resultgroupdetails)){
$groupid=$rowgroupdetails['GroupID'];
$grouppic = $rowgroupdetails['GroupPic'];
$groupname = $rowgroupdetails['GroupName'];
if ($_SERVER['SERVER_PORT'] == '80' || $_SERVER['SERVER_PORT'] =='443'){
echo "<tr class=\"eachchatrow\" onclick=\"window.location.href='http://localhost/orbital/seemessage.php?group=$mygroups'\">";
}
else{
echo "<tr class=\"eachchatrow\" onclick=\"window.location.href='http://localhost:8080/orbital/seemessage.php?group=$mygroups'\">";
}
if ($grouppic == "" || $grouppic == NULL) {
echo "<td><img src=\"img/user.png\" width=\"80px\" height=\"80px\" alt=\"groupprofile\" class=\"groupprofilepic\"></td>";
}
else{
echo "<td><img src=\"grouppic/$grouppic\" width=\"80px\" height=\"80px\" alt=\"groupprofile\" class=\"groupprofilepic\"></td>";
}
echo "<td><span class=\"groupnamefont\">$groupname</span><br><br>";
//display last message
$sqlgetlastmessage= "SELECT MAX(MessageID) FROM messages WHERE GroupID='$mygroups'";
$resultgetlastmessage = mysqli_query($conn,$sqlgetlastmessage);
echo "<span class=\"thefinalmessage\">";
//last msg
if(mysqli_num_rows($resultgetlastmessage) > 0){//got last messages
while($rowgetlastmessage=mysqli_fetch_array($resultgetlastmessage)){
$thelastmessageid = $rowgetlastmessage['MAX(MessageID)'];
$sqlfetchfinalmessage = "SELECT * FROM messages WHERE MessageID='$thelastmessageid'";
$resultfetchfinalmessage = mysqli_query($conn,$sqlfetchfinalmessage);
while($rowfetchfinalmessage = mysqli_fetch_array($resultfetchfinalmessage)){
$thereallastmessage = $rowfetchfinalmessage['Message'];
$thelastmessagefullname=$rowfetchfinalmessage['FullName'];
$thelastmessagetiming = $rowfetchfinalmessage['Timing'];
echo "$thelastmessagefullname";
echo ": ";
echo "$thereallastmessage";
echo "<br><br>";
echo "<span style=\"font-size:12px;\">$thelastmessagetiming</span>";
}
}
}
echo "</span></td>";
//display how many notifications for that user - unseen only
$sqlgetnotifications = "SELECT * FROM notifications WHERE GroupID='$groupid' AND NUSEmail='$useremail' AND Status='Unseen'";
$resultgetnotifications = mysqli_query($conn,$sqlgetnotifications);
$notificationcount = 0;
if(mysqli_num_rows($resultgetnotifications) > 0){//got notifications
while($rowgetnotifications = mysqli_fetch_array($resultgetnotifications)){
$notificationcount += 1;
}
echo "<td><span class=\"notificationcounts\">$notificationcount</span></td>";
}
else{
echo "<td></td>";
}
echo "</tr>";
}
}
}
else{
echo "<div>You have no chats/messages!</div>";
}
echo "</table>";
?>
</div>
</section>
</section>
</body>
</html>