-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontacts.php
89 lines (74 loc) · 2.85 KB
/
contacts.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>contacts</title>
<?php include_once __DIR__ . '/styles/styles.php'; ?>
<link rel="stylesheet" type="text/css" href="/livechat/styles/general.css">
</head>
<body>
<div class="container">
<?php
include_once __DIR__ . '/layout/sidebar.php';
?>
<section class="main_content">
<header class="main_header">
<div class="username" id="username">Username</div>
<button onclick="dangxuat()">Đăng xuất</button>
</header>
<div>
<section class="all_users" id="all_users">
<div id="list_of_users">
</div>
</section>
</div>
</section>
</div>
<script src="js/clickbox.js"></script>
<script src="js/get_data.js"></script>
<script src="js/dangxuat.js"></script>
<script>
var CURRENT_CHAT_USERID = "";
var CURRENT_CHAT_USERNAME = "";
get_data({}, "user_info");
get_data({}, "contacts");
//get_data({}, "preview_messages"); // display preview messages
function start_chat(e) {
var userid = e.target.getAttribute("data-userid");
var username = e.target.getAttribute("data-username");
if (e.target.id == "") {
userid = e.target.parentNode.getAttribute("data-userid");
username = e.target.parentNode.getAttribute("data-username");
}
// console.log(userid, username);
CURRENT_CHAT_USERID = userid;
CURRENT_CHAT_USERNAME = username;
// collect data
const data = {};
data.userid = userid;
data.username = username;
//console.log(JSON.stringify(data));
send_data(data, 'friend_info');
// 1. Get friends information that the user want to chat
//location.href = 'chat.php';
// 2. redirect to the chat.php to start chatting
}
function send_data(data, type) {
let xml = new XMLHttpRequest();
xml.addEventListener("load", function() {
if (xml.readyState == 4 || xml.status == 200) { // everything good
let message = xml.responseText;
alert(message);
//location.href = 'chat.php';
}
});
// send data
data.type_of_data = type;
let data_string = JSON.stringify(data); // cannot send object so turn the obj to string
xml.open("POST", "chat.php", true);
xml.send(data_string);
}
</script>
</body>
</html>