-
Notifications
You must be signed in to change notification settings - Fork 0
/
search_buddy_chat.php
124 lines (104 loc) · 6.38 KB
/
search_buddy_chat.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
<?php
include "db_conn.php";
if (isset($_POST['user']) && isset($_POST['action'])) {
$user = $_POST["user"];
$action = $_POST["action"];
// Get the fullname of the online user
$sql1 = "SELECT * FROM `account` WHERE `username` = '$user'";
$result1 = mysqli_query($conn, $sql1);
if (mysqli_num_rows($result1) > 0) {
while ($row = mysqli_fetch_assoc($result1)) {
$fullname = $row['fullname'];
// Get the match id of the online user in search_queue_con
$sql2 = "SELECT * FROM `search_queue_con` WHERE `fullname` = '$fullname' LIMIT 1";
$result2 = mysqli_query($conn, $sql2);
if ((mysqli_num_rows($result2) > 0)){
while ($row = mysqli_fetch_assoc($result2)) {
$matchId = $row['matchId'];
// Get the buddy's fullname
$sql3 = "SELECT * FROM `search_queue_con` WHERE `matchId` = '$matchId' AND `fullname` != '$fullname' LIMIT 1";
$result3 = mysqli_query($conn, $sql3);
if ((mysqli_num_rows($result3) > 0)){
while ($row = mysqli_fetch_assoc($result3)) {
$matched_fullname = $row['fullname'];
// Remove the online users queue on search_queue
$sql4 = "DELETE FROM `search_queue` WHERE `fullname` = '$fullname'";
$result4 = mysqli_query($conn, $sql4);
if ($result4) {
// Remove the online users queue and its buddy in search_queue_con
$sql5 = "DELETE FROM `search_queue_con` WHERE 1";
$result5 = mysqli_query($conn, $sql5);
if ($result5) {
// Get the user id of the online user
$sql5 = "SELECT * FROM `account` WHERE `fullname` = '$fullname'";
$result5 = mysqli_query($conn, $sql5);
if ((mysqli_num_rows($result5) > 0)){
while ($row = mysqli_fetch_assoc($result5)) {
$userid = $row['userid'];
// Get the user id of the other user
$sql6 = "SELECT * FROM `account` WHERE `fullname` = '$matched_fullname'";
$result6 = mysqli_query($conn, $sql6);
if ((mysqli_num_rows($result6) > 0)){
while ($row = mysqli_fetch_assoc($result6)) {
$matched_userid = $row['userid'];
// Add the group into message_groups
$sql7 = "INSERT INTO `message_groups`(`groupid`, `groupname`)
VALUES ('$matchId','Buddy')";
$result7 = mysqli_query($conn, $sql7);
if ($result7) {
// Insert the online user into the group
$sql8 = "INSERT INTO `message_members`(`groupid`, `userid`)
VALUES ('$matchId','$userid')";
$result8 = mysqli_query($conn, $sql8);
if ($result8) {
// Insert the buddy into the group as well
$sql9 = "INSERT INTO `message_members`(`groupid`, `userid`)
VALUES ('$matchId','$matched_userid')";
$result9 = mysqli_query($conn, $sql9);
if ($result9) {
// Insert both user to the relationship table
$sql10 = "INSERT INTO `relationship`(`id`, `user`, `buddy`, `relation`)
VALUES ('$matchId','$userid','$matched_userid','buddy')";
$result10 = mysqli_query($conn, $sql10);
if ($result10){
echo "Success";
}
} else {
echo "Upload";
}
} else {
echo "Upload";
}
} else {
echo "Upload";
}
}
} else {
echo "Username";
}
}
} else {
echo "Username";
}
} else {
echo "Failed";
}
} else {
echo "Failed";
}
}
} else {
echo "MatchID";
}
}
} else {
echo "Queue";
}
}
} else {
echo "Username";
}
} else {
echo "Unknown";
}
?>