-
Notifications
You must be signed in to change notification settings - Fork 0
/
patmessages.php
146 lines (136 loc) · 5.23 KB
/
patmessages.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
<?php
session_start();
$sender_id = $_SESSION['user_id'];
$conn = mysqli_connect("localhost", "root", 12345, "healthcare");
if (mysqli_connect_errno()) {
die("Connection failed: " . mysqli_connect_error());
}
$sql1 = "select user_id,username,user_type from users";
$result1 = mysqli_query($conn, $sql1);
$name = $_SESSION['name'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>P-Messages</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
var conn = new WebSocket('ws://localhost:5001');
conn.onopen = function(e) {
console.log("Connection established!");
};
conn.onmessage = function(e) {
var message = JSON.parse(e.data);
$('.messages').append('<p><strong>' + message.sender_id + ': </strong>' + message.message + '</p>');
};
});
</script>
<style>
@import url("https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap");
nav {
padding: 2rem 1rem;
display: flex;
align-items: center;
justify-content: space-between;
gap: 1rem;
}
.nav__logo {
font-size: 1.5rem;
font-weight: 600;
color: var(--primary-color);
}
.nav__links {
list-style: none;
display: flex;
align-items: center;
gap: 2rem;
}
.link a {
text-decoration: none;
color: var(--text-light);
cursor: pointer;
transition: 0.3s;
}
:root {
--primary-color: #28bf96;
--primary-color-dark: #209677;
--text-dark: #111827;
--text-light: #6b7280;
--white: #ffffff;
}
.link a:hover {
color: var(--primary-color);
}
.card{
max-width: 400px;
height: 500px !important;
margin: 5px;
padding: 5px;
}
.card-body{
overflow-y: scroll;
}
</style>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<nav>
<div class="nav__logo"><img src="Images/logo.png" alt=""></div>
<ul class="nav__links">
<li class="link"><a href="patprofile.php">Profile</a></li>
<li class="link"><a href="patappointment.php">Request an Appointment</a></li>
<li class="link"><a href="patmessages.php">Messages</a></li>
<li class="link"><a href="makepayment.php">Billing and Invoice</a></li>
<li class="link"><a href="feedback.php">Feedback</a></li>
</ul>
</nav>
<div class="container">
<table class="table table-striped">
<thead>
<tr>
<th>User Id</th>
<th>User Name</th>
<th>User Type</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
if(mysqli_num_rows($result1) > 0){
while($row = $result1->fetch_assoc()){
echo "<tr>";
echo "<td>".$row['user_id']."</td>";
echo "<td>".$row['username']."</td>";
echo "<td>".$row['user_type']."</td>";
echo "<td><button class='btn btn-success' data-bs-toggle='collapse' data-bs-target='#collapseexample" . $row['user_id'] . "'>Message</button>";
echo "<div class='collapse' id='collapseexample" . $row['user_id'] . "'>";
echo "<div class='card'>";
echo "<div class='card-header'>Welcome $name</div>";
echo "<div class='card-body messages'>";
echo "</div>";
echo "<div class='card-footer'>";
echo"<form id='message_form'>
<input type='hidden' id='sender_id' value=1>
<input type='hidden' id='receiver_id'>
<input type='text' id='message' placeholder='Type your message...'>
<button type='button' class='btn btn-success'>Send</button>
</form>
";
echo "</div></div></div>";
echo "</td>";
echo "</tr>";
}
}
?>
</tbody>
</table>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>