forked from RITct/Decipher-2016
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
228 lines (198 loc) · 6.54 KB
/
index.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
<?php
session_start();
require_once("database.php");
global $result;
echo "<!DOCTYPE html>
<html>
<head>
<meta charset=\"UTF-8\">
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">
<link rel=\"icon\" href=\"../images/icon.png\" type=\"image/png\" sizes=\"16x16\">
<title>Decipher | 2016</title>
<link rel=\"stylesheet\" href=\"css/style.css\" type=\"text/css\">
<link rel=\"stylesheet\" type=\"text/css\" href=\"css/mobile.css\">
<script src=\"js/mobile.js\" type=\"text/javascript\"></script>
</head>
<body>
<div id=\"page\">
<div id=\"header\">
<div id=\"navigation\">
<span id=\"mobile-navigation\"> </span>
<a href=\"index.php\" class=\"logo\"><img src=\"images/logo.png\"></a>
<ul id=\"menu\">
<li class=\"selected\">
<a href=\"index.php\">Home</a>
</li>
<li>
<a href=\"leader.php\">Leader Board</a>
</li>
<li>
<a href=\"rules.php\">Rules</a>
</li>
<li>
<a href=\"https://www.facebook.com/decipher.ritu\" target=\"_blank\">WATSON</a>
</li>";
if (isset($_SESSION["fbuid"]))
echo "<li>
<a href=\"logout.php\">logout</a>
</li>";
echo "</ul>
</div>
</div>
<div id=\"body\" class=\"home\">
<div class=\"header\">
<div>";
require_once __DIR__ . '/src/Facebook/autoload.php';
$fb = new Facebook\Facebook([
'app_id' => 'yourappid',
'app_secret' => 'appsecret',
'default_graph_version' => 'v2.5',
]);
$helper = $fb->getRedirectLoginHelper();
try {
if (isset($_SESSION['facebook_access_token'])) {
$accessToken = $_SESSION['facebook_access_token'];
} else {
$accessToken = $helper->getAccessToken();
}
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
if (isset($accessToken)) {
if (isset($_SESSION['facebook_access_token'])) {
$fb->setDefaultAccessToken($_SESSION['facebook_access_token']);
} else {
// getting short-lived access token
$_SESSION['facebook_access_token'] = (string) $accessToken;
// OAuth 2.0 client handler
$oAuth2Client = $fb->getOAuth2Client();
// Exchanges a short-lived access token for a long-lived one
$longLivedAccessToken = $oAuth2Client->getLongLivedAccessToken($_SESSION['facebook_access_token']);
$_SESSION['facebook_access_token'] = (string) $longLivedAccessToken;
// setting default access token to be used in script
$fb->setDefaultAccessToken($_SESSION['facebook_access_token']);
}
// redirect the user back to the same page if it has "code" GET variable
if (isset($_GET['code'])) {
header('Location: ./decipher/index.php');
}
// getting basic info about user
try {
$profile_request = $fb->get('/me?fields=name,first_name,last_name');
$profile = $profile_request->getGraphNode()->asArray();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
session_destroy();
// redirecting user back to app login page
header("Location: ./decipher/");
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
// printing $profile array on the screen which holds the basic info about user
//print_r($profile);
$id=$profile['id'];
$_SESSION["fbuid"]=$id;
$name=$profile['name'];
$sql = "SELECT * FROM users WHERE fbuid=".$id;
$ref = $result->query($sql);
$count=mysqli_num_rows($ref);
if ($count==0)
{
$sql= "INSERT INTO `users` (`fbuid`, `name`, `level`,`role`) VALUES ('".$id."', '".$name."', '0', '1')";
$ref = $result->query($sql);
$_SESSION["role"]=1;
$_SESSION["level"]=0;
$output = "<script>
window.location='register.php';
</script>";
echo $output;
}
$sql = "SELECT * FROM users WHERE fbuid=".$id;
$ref = $result->query($sql);
$row = mysqli_fetch_assoc($ref);
$_SESSION["role"]=$row['role'];
$_SESSION["level"]=$row['level'];
$_SESSION["name"]=$row['name'];
if($_SESSION["role"] ==10 )
{
$output = "<script>
window.location='shakthiman.php';
</script>";
echo $output;
}
else if($_SESSION["role"] >=0)
{
$id = $_SESSION["level"];
if($id==25){
$output = "<script>
window.location='winner.html';
</script>";
echo $output;
}
$sql = "SELECT * FROM levels WHERE name = '" . mysqli_real_escape_string($result,$id) . "'" ;
$ref = $result->query($sql);
$rowcount=mysqli_num_rows($ref);
$row = mysqli_fetch_assoc($ref);
$content = "<div id=\"ques\">
<h2 id=\"head\">".$row["title"]."</h2>
<br>".$row['contents']. "</div>";
if(!($rowcount))
{$content = "<p class=\"ack\">SO YOU REACHED ME SHERLOCK...<br>THATS UNBELIEVABLE...<br>JUST WAIT HERE TILL I SET NEW SCENES FOR YOU</p>";
}
else
$content =$content."<br><div id = \"answerbox\"><form action = \"answer.php\" name = \"answer\"><input id=\"ans\" type = \"text\" name = \"answer\" autofocus autocomplete=\"off\"><br><input id=\"sub\" type = \"submit\" value = \"Check\"></form>";
print $content;
$sql= "SELECT count( * ) as rank
FROM `users`
WHERE level > (
SELECT level
FROM users
WHERE fbuid =".$_SESSION["fbuid"]." )
OR (
level = (
SELECT level
FROM users
WHERE fbuid =".$_SESSION["fbuid"]." )
AND passtime < (
SELECT passtime
FROM users
WHERE fbuid =".$_SESSION["fbuid"]." )
) AND role not in (-1,10)";
$ref = $result->query($sql);
$row = mysqli_fetch_assoc($ref);
$rank=$row['rank'];
$rank=$rank+1;
echo "<h2>Your rank ".$rank."</h2>";
echo '<a href="https://goo.gl/IEqrNw" target="_blank"><img src="imgs/decipher-banner.jpg"></a>';
}
else if ($_SESSION["role"]<0)
{
$content = "<p class=\"ack\">You have been banned from playing.<br> Contact the FB page</p>";
print $content;
}
// Now you can redirect to another page and use the access token from $_SESSION['facebook_access_token']
} else {
// if not logged in display
$loginUrl = $helper->getLoginUrl('http://decipher.ritu16.com/');
echo "<div style=\"padding-top:5%;\"><h1> MISS ME?</h1>
<span><a href=\"".$loginUrl ."\" class=\"email\">LOGIN WITH FACEBOOK</a></span></div>
";
echo '<a href="https://goo.gl/IEqrNw" target="_blank"><img id="adv" style="position:fixed;bottom:0px;left:0px;" src="imgs/decipher-banner.jpg"></a>';
}
echo "</div>
</div>
</div>
</div>
</body>
</html>
";