-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatFriend.php
More file actions
307 lines (279 loc) · 12.8 KB
/
Copy pathChatFriend.php
File metadata and controls
307 lines (279 loc) · 12.8 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
<?php
session_start();
include_once "./assets/php/config.php";
if (!isset($_SESSION['user_id'])) {
header("location: login.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flirt Zone - Chat Friend</title>
<!-- Reset -->
<link rel="stylesheet" href="./assets/css/reset.css">
<!-- fonts -->
<link rel="stylesheet" href="./assets/fonts/stylesheet.css">
<!-- chat friend page -->
<link rel="stylesheet" href="./assets/css/ChatFriend.css">
<!-- Favicon -->
<link rel="apple-touch-icon" sizes="57x57" href="./assets/favicon/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="./assets/favicon/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="./assets/favicon/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="./assets/favicon/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="./assets/favicon/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="./assets/favicon/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="./assets/favicon/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="./assets/favicon/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="./assets/favicon/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="./assets/favicon/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="./assets/favicon/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="./assets/favicon/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="./assets/favicon/favicon-16x16.png">
<link rel="manifest" href="./assets/favicon/manifest.json">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-TileImage" content="./assets/favicon/ms-icon-144x144.png">
<meta name="theme-color" content="#ffffff">
</head>
<body>
<div class="box_textchatpage">
<header class="header fixed-header">
<div class="body">
<!-- logo -->
<div class="logo">
<img style="margin-bottom: 7px;" src="./assets/img/logo.svg" alt="Flirt Zone">
<div class="logo-desc" style="margin-bottom: 1px;">
<img src="./assets/img/logo-desc1.svg" alt="Flirt Zone">
<img src="./assets/img/logo-desc2.svg" alt="Flirt Zone">
</div>
</div>
<!-- nav -->
<ul>
<li>
<a href="index.php">Home</a>
</li>
<li>
<a href="#!">About</a>
</li>
<li>
<a href="support.php">Support</a>
</li>
<li>
<a href="SwipeProfile.php" style="color: red;">Swipe</a>
</li>
</ul>
<!-- action to call -->
<div class="action">
<a href="#!" class="button avatar" style="background-image: url(./assets/img/avt.jpg);"></a>
<div class="menu-nav-avt" id="userMenu">
<a href="Profileuser.php" class="dropdown-item">Xem trang cá nhân</a>
<a href="#!" class="dropdown-item">Đăng xuất</a>
</div>
</div>
</div>
</header>
<div class="textchat_container">
<!-- Chat side no friend -->
<div class="chat-side">
<div class="chat-friend">
<a href="swipeProfile.php" style="margin-left: 24px;">
<button class="chat-friend__filter ">
<img src="./assets/img/filter.svg" alt="" class="chat-img">
<span class="chat-friend__filter-text">Filter</span>
</button>
</a>
<button class="chat-friend__friend chat-friend--active" style="margin-left: -24px">
<img src="./assets/img/users.svg" alt="" class="friend-img">
<span class="chat-friend__friend-text">Friends</span>
</button>
</div>
<!-- Friend -->
<div class="wrapper">
<section class="users">
<header>
<div class="content">
<?php
$sql = mysqli_query($conn, "SELECT * FROM userinformation WHERE ID = {$_SESSION['user_id']}");
if (mysqli_num_rows($sql) > 0) {
$row = mysqli_fetch_assoc($sql);
}
?>
</div>
</header>
<!-- danh sach friend chat -->
<div class="users-list">
<?php
// Lấy ID user hiện tại
$currentUserId = $_SESSION['user_id'];
// Lấy danh sách matches
$sql_matches = mysqli_query($conn, "
SELECT
m.ID as MatchID,
IF(m.User1ID = $currentUserId, m.User2ID, m.User1ID) as FriendID,
u.UserName,
u.Avt,
u.IsActive
FROM matches m
JOIN userinformation u ON u.ID = IF(m.User1ID = $currentUserId, m.User2ID, m.User1ID)
WHERE m.User1ID = $currentUserId OR m.User2ID = $currentUserId
");
if (mysqli_num_rows($sql_matches) > 0) {
while ($friend = mysqli_fetch_assoc($sql_matches)) {
?>
<div class="user" data-friend-id="<?php $friend['FriendID']; ?>"
onclick="window.location.href='chat.php?user_id=<?php echo $friend['FriendID']; ?>'">
<div class="avatar"
style="background-image: url('./assets/img/<?php echo htmlspecialchars($friend['Avt']); ?>');">
</div>
<div class="details">
<span>
<?php echo htmlspecialchars($friend['UserName']); ?>
</span>
<p>
<?php
$ol = $row['IsActive'] ? "Online" : "Offline";
if ($ol == "Online") {
echo "<span class='online' style='color:green'>".$ol."</span>";
} else {
echo "<span class='offline' style='color:red'>".$ol."</span>";
}
?>
</p>
</div>
</div>
<?php
}
} else {
echo "<div class='no-friends'>Bạn chưa có bạn nào.</div>";
}
?>
</div>
</section>
</div>
</div>
</div>
</div>
<script>
// Script choose friend to chat
const chat_side__content_friends = document.querySelectorAll('.chat-side__content-friends');
const main_content = document.querySelector('.main-content');
chat_side__content_friends.forEach(button => {
button.addEventListener('click', () => {
chat_side__content_friends.forEach(btn => btn.classList.remove(
'chat-side__content-friends--active'));
button.classList.add('chat-side__content-friends--active');
});
});
// Script report
const reportBtn = document.querySelector('.textchat__func');
const report_modal = document.querySelector('.textchat__func-report');
reportBtn.addEventListener('click', () => {
report_modal.classList.toggle('textchat__func-report--show');
});
// Script choose chat-friend
const chat = document.querySelector('.chat-friend__filter');
const friend = document.querySelector('.chat-friend__friend');
const chat_side_content = document.querySelector('.chat-side__content');
const chat_side__content_friend = document.querySelector('.chat-side__content-friend');
chat.addEventListener('click', () => {
chat.classList.add('chat-friend--active');
friend.classList.remove('chat-friend--active');
chat_side_content.classList.remove('chat-side__content--hide');
chat_side__content_friend.classList.remove('chat-side__content-friend--show');
});
friend.addEventListener('click', () => {
friend.classList.add('chat-friend--active');
chat.classList.remove('chat-friend--active');
chat_side__content_friend.classList.add('chat-side__content-friend--show');
chat_side_content.classList.add('chat-side__content--hide');
});
// Add functionality to send messages
const textInput = document.querySelector('.friendchat__input');
const sendButton = document.querySelector('.textchat__send');
const chatBox = document.querySelector('.friendchat-box');
sendButton.addEventListener('click', () => {
if (textInput.value.trim() !== '') {
const message = document.createElement('div');
message.classList.add('mess', 'my-mess');
message.textContent = textInput.value;
chatBox.appendChild(message);
textInput.value = '';
chatBox.scrollTop = chatBox.scrollHeight;
}
});
textInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter' && textInput.value.trim() !== '') {
const message = document.createElement('div');
message.classList.add('mess', 'my-mess');
message.textContent = textInput.value;
chatBox.appendChild(message);
textInput.value = '';
chatBox.scrollTop = chatBox.scrollHeight;
}
});
</script>
<!-- Script Filter -->
<script>
const filterAgeMinInput = document.getElementById('filterAgeMin');
const filterAgeMaxInput = document.getElementById('filterAgeMax');
const ageMinDisplay = document.querySelector('.chat-side__content-filter__age-first-value');
const ageMaxDisplay = document.querySelector('.chat-side__content-filter__age-second-value');
function applyFilters() {
const ageMin = parseInt(filterAgeMinInput.value);
const ageMax = parseInt(filterAgeMaxInput.value);
filteredUsers = allUsers.filter(user => {
let passes = true;
if (user.age < ageMin || user.age > ageMax) passes = false;
return passes;
});
}
// Update display for range sliders
if (filterAgeMinInput && ageMinDisplay) {
filterAgeMinInput.addEventListener('input', (e) => {
ageMinDisplay.textContent = e.target.value;
if (parseInt(filterAgeMaxInput.value) < parseInt(e.target.value)) {
filterAgeMaxInput.value = e.target.value;
ageMaxDisplay.textContent = e.target.value;
}
});
}
if (filterAgeMaxInput && ageMaxDisplay) {
filterAgeMaxInput.addEventListener('input', (e) => {
ageMaxDisplay.textContent = e.target.value;
if (parseInt(filterAgeMinInput.value) > parseInt(e.target.value)) {
filterAgeMinInput.value = e.target.value;
ageMinDisplay.textContent = e.target.value;
}
});
}
if (filterDistanceInput && distanceDisplay) {
filterDistanceInput.addEventListener('input', (e) => {
distanceDisplay.textContent = `${e.target.value} km`;
});
}
</script>
<script>
//nut avt
const avatar = document.querySelector('.avatar');
const menu = document.getElementById('userMenu');
const items = document.querySelectorAll('.dropdown-item');
avatar.addEventListener('click', (e) => {
e.stopPropagation();
menu.style.display = (menu.style.display === 'flex') ? 'none' : 'flex';
});
document.addEventListener('click', () => {
menu.style.display = 'none';
});
menu.addEventListener('click', (e) => {
e.stopPropagation();
});
items.forEach(item => {
item.addEventListener('click', () => {
menu.style.display = 'none';
});
});
</script>
<script type="text/javascript" src="./js/users.js"></script>
</body>
</html>