-
Notifications
You must be signed in to change notification settings - Fork 4
/
messagesMenu.php
163 lines (116 loc) · 5.29 KB
/
messagesMenu.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
<?php
session_start();
include "menu.php";
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "mydb";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
//wehre Id = $selectedId
//$sql= "SELECT * FROM logs WHERE Id = 1";
$receiverId = $_SESSION['user']['Id'];
if($_SESSION['user']['Role'] == 4)
{
$sql = "SELECT l.content, u.firstName,l.reg_date,l.senderId,l.receiverId,l.seen
FROM `logs` l
JOIN `user` u
ON l.senderId = u.Id
WHERE u.Role !=2
GROUP BY l.senderId,l.receiverId
ORDER BY reg_date";
}
else if ($_SESSION['user']['Role'] == 3)
{
$sql = "SELECT l.content, u.firstName,l.reg_date,l.senderId,l.receiverId,l.seen
FROM `logs` l
JOIN `user` u
ON l.senderId = u.Id
WHERE u.Role !=2 AND l.report = 1
GROUP BY l.senderId,l.receiverId
ORDER BY reg_date";
}
else
{
$sql = "SELECT l2.*, u.firstName, u.lastName
FROM logs l2
JOIN user u
ON l2.senderId = u.Id
WHERE l2.Id IN (SELECT max(l.Id) FROM logs l
WHERE l.receiverId = $receiverId
GROUP BY l.receiverId,l.senderId
ORDER BY reg_date)";
}
//$result = mysqli_query($conn,$sql);
$result = $conn->query($sql);
$allRecords = $result->fetch_all(MYSQLI_ASSOC);
?>
<!DOCTYPE html>
<html>
<head>
<link href="CSS/simple-sidebar.css" rel="stylesheet">
<title></title>
</head>
<body>
<div class = row>
<?php if($_SESSION['user']['Role'] == 4){
echo '<div class="bg-dark border-right" id="sidebar-wrapper">
<div class="list-group list-group-flush bg-dark">
<a href="Auditor_surveys.php" class="list-group-item list-group-item-action bg-secondary text-light show"><span class="text-nowrap"><i class="fa fa-plus-square"></i> surveys</a></span>
<a href="messagesMenu.php" class="list-group-item list-group-item-action bg-dark text-light show"><span class="text-nowrap"><i class="fa fa-profile"></i>Messages</a></span>
</div>
</div>';
}
if($_SESSION['user']['Role'] == 3){
echo '<div class="bg-dark border-right" id="sidebar-wrapper">
<div class="list-group list-group-flush bg-dark">
<a href="Auditor_surveys.php" class="list-group-item list-group-item-action bg-secondary text-light show"><span class="text-nowrap"><i class="fa fa-plus-square"></i> users</a></span>
<a href="messagesMenu.php" class="list-group-item list-group-item-action bg-dark text-light show"><span class="text-nowrap"><i class="fa fa-profile"></i>Reports</a></span>
</div>
</div>';
}
?>
<div class="bg-dark border-right" id="sidebar-wrapper" >
<div class="list-group list-group-flush bg-dark " style= "width:40%;">
<?php
foreach($allRecords as $record){
$senderId = $record['senderId'];
if($_SESSION['user']['Role'] == 3 || $_SESSION['user']['Role'] == 4)
$getRequest = "sender=". $record['receiverId']. "&receiver=".$record['senderId'];
else
$getRequest = "receiver=".$record['senderId'];
if($record['seen'])
{
printf('<a href="chat.php?%s" class="list-group-item list-group-item-action bg-secondary text-light show" style = "font-style:italic;"><span class="text-nowrap"><i class="fa fa-user"></i> %s </a></span>',$getRequest,$record['firstName']);
}
else
{
printf('<a href="chat.php?%s" class="list-group-item list-group-item-action bg-secondary text-light show" style = "font-weight:bold;"><span class="text-nowrap"><i class="fa fa-user"></i> %s </a></span>',$getRequest,$record['firstName']);
}
}
if(count($allRecords) == 0 && $_SESSION['user']['Role'] == 1)
{
$sqlAdmins = "SELECT * FROM user WHERE Role = 2";
$result = $conn->query($sqlAdmins);
$admins = $result->fetch_all(MYSQLI_ASSOC);
echo "<h5 style='margin-left: 20px;color: white;'>you didnt send any message here are some of our available workers</h5> ";
foreach($admins as $admin)
{
//echo $admin['firstName'];
printf('<a href="chat.php?receiver=%s" class="list-group-item list-group-item-action bg-secondary text-light show"><span class="text-nowrap"><i class="fa fa-plus-square"></i> %s </a></span>',$admin['Id'],$admin['firstName']);
}
}
if(isset($_POST['message']))
{
$sender = $_SESSION['user']['Id'];
$message = $_POST['message'];
}
?>
</div>
</div>
</div>
<?php
include 'footer.php'
?>
</body>
</html>