-
Notifications
You must be signed in to change notification settings - Fork 0
/
chat-connect.php
265 lines (200 loc) · 6.17 KB
/
chat-connect.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
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
<?php session_start(); ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Freedomchat</title>
<link rel="icon" href="img/eagle.ico" type="image/x-icon"/>
<!-- Bootstrap core CSS -->
<link href="/css/bootstrap.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="/css/custom.css" rel="stylesheet">
<link href="/css/contacts.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<div class="header">
<?php
$user = $_SESSION['user'];
if ($user != "")
{
echo '
<ul class="nav nav-pills pull-right">
<li class="active"><a href="logout.php">Log Out</a></li>
</ul>';
}
include 'CGI-BIN/connect.php';
$sql = "SELECT * FROM users WHERE username = '".$_SESSION['user']."' LIMIT 1";
$result = $dbh->prepare($sql);
$result->execute();
foreach ($result as $row)
{
$curr_user_id = $row['id'];
}
?>
<a href="/"><img class="logo" src="img/logo.png" height="50px" alt="Freedom Chat" /></a>
</div>
<div class="row" style="margin-top:20px">
<div class="col-xs-12">
<div id="myTabContent" class="tab-content">
<?php
$user_1 = $curr_user_id;
if ($_POST['id'])
{
$_SESSION['hs_id'] = $_POST['id'];
}
if ($_SESSION['hs_id'] != "")
{
$user_2 = $_SESSION['hs_id'];
}
$password = $_POST['password'];
$sql = "SELECT * FROM handshake WHERE (user_1 = '".$user_1."' AND user_2 = '".$user_2."') OR (user_1 = '".$user_2."' AND user_2 = '".$user_1."') LIMIT 2";
$result = $dbh->prepare($sql);
$result->execute();
#Check if connection already exists
$count = $result->rowCount();
$sql = "SELECT * FROM handshake WHERE (user_1 = '".$user_1."' AND user_2 = '".$user_2."') LIMIT 1";
$result = $dbh->prepare($sql);
$result->execute();
#Check if connection already exists
$pending = $result->rowCount();
if ($count == 2)
{
$i = 0;
foreach ($result as $row) {
$array[$i] = $row['code_1'];
$i = $i + 1;
}
if ($array[0] == $array[1])
{
echo "Confirmed";
}
}
else if ($pending == 1)
{ ?>
<div class="tab-pane active in" id="login">
<div class="row">
<div class="col-xs-4">
<h2>Waiting For Partner</h2>
</div>
</div>
<div> </div>
<hr class="chatcolours">
<div class="loader-box">
</div>
<script type="text/javascript">
window.onload = setupRefresh;
function setupRefresh() {
setTimeout("refreshPage();", 2000);
}
function refreshPage() {
window.location = location.href;
}
</script>
<hr class="chatcolours">
</div>
<?php }
else if ($_POST['psubmit'])
{
$sql = "SELECT * FROM handshake WHERE (user_1 = '".$user_1."' AND user_2 = '".$user_2."') LIMIT 1";
$result = $dbh->prepare($sql);
$result->execute();
#Check if connection already exists
$count = $result->rowCount();
if ($count == 1)
{ ?>
<div class="tab-pane active in" id="login">
<div class="row">
<div class="col-xs-4">
<h2>Waiting For Partner</h2>
</div>
</div>
<div> </div>
<hr class="chatcolours">
<div class="loader-box">
</div>
<script type="text/javascript">
window.onload = setupRefresh;
function setupRefresh() {
setTimeout("refreshPage();", 2000);
}
function refreshPage() {
window.location = location.href;
}
</script>
<hr class="chatcolours">
</div>
<?php }
else
{
$sql = "INSERT INTO handshake VALUES ('', '".$user_1."', '".$user_2."', '".$password."', '0')";
$result = $dbh->prepare($sql);
$result->execute();
?>
<div class="tab-pane active in" id="login">
<div class="row">
<div class="col-xs-4">
<h2>Waiting For Partner</h2>
</div>
</div>
<div> </div>
<hr class="chatcolours">
<div class="loader-box">
</div>
<script type="text/javascript">
window.onload = setupRefresh;
function setupRefresh() {
setTimeout("refreshPage();", 2000);
}
function refreshPage() {
window.location = location.href;
}
</script>
<hr class="chatcolours">
</div>
<?php }
} else {
?>
<div class="tab-pane active in" id="login">
<div class="row">
<div class="col-xs-4">
<h2>Enter Chat Password</h2>
</div>
</div>
<div> </div>
<hr class="chatcolours">
<div id="message-box">
</div>
<div id="message-form">
<form method="post">
<input type="hidden" name="id" value="<?php echo $_POST['id']; ?>" />
<input type="password" name="password" />
<input name="psubmit" type="submit" value="Send" />
</form>
</div>
<hr class="chatcolours">
</div>
<?php } ?>
</div>
</div>
</div>
<div id="response"></div>
<div class="footer">
<p>A <a href="#" target="_blank">Cardiff University Makespace 2014</a> project by <a href="http://www.timcoysh.co.uk/" target="_blank">Tim Coysh</a>, <a href="http://www.brenz.co.uk/" target="_blank">Brendan Warren</a> and <a href="#" target="_blank">Remi Stevens</a></p>
</div>
</div> <!-- /container -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
<script src="/js/script.js"></script>
</body>
</html>