-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.php
161 lines (137 loc) · 4.75 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
<?php
// This is the index page. Are they actually logged into Facebook?
require_once("../app/fbsdk/secret.php");
require_once("../app/fbsdk/facebook.php");
$facebook = new Facebook(array(
'appId' => FB_APPID,
'secret' => FB_SECRET,
'cookie' => true,
));
$session = $facebook->getSession();
$me = null;
// Session based API call.
if ($session) {
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
}
}
if (!$me) {
include_once("../app/static/notenoughperms.html");exit();
}
require_once('libraries/library.php');
if (!userExists($me['id'])) {
createUser($me['id'], $me['name']);
}
if ($_GET['request_ids']) {
$handler = "landing.php";
$data = $_SERVER['QUERY_STRING'];
} else {
$handler = "landing.php";
$data = '';
}
// Do we still need their phone number?
$_data = new mysqli('localhost', 'hackathon', 'deneve', 'hackathon');
$checksql = $_data->query("select phone from face_users where facebook_id = '".$uid."' limit 0,1");
if ($checksql->num_rows !== 1) die("ERROR: User not in database");
$checkresult = $checksql->fetch_assoc();
if ($checkresult["phone"] == "") {
$handler = "no_phone_number.php";
$data = '';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<link href='http://fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic' rel='stylesheet' type='text/css' />
<link href='../app/static/styles.css' rel='stylesheet' type='text/css' />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>
<script type="text/javascript" src="http://konami-js.googlecode.com/svn/trunk/konami.js"></script>
<script type="text/javascript" src="../app/static/soundmanager.js"></script>
<script type="text/javascript" src="../app/static/scripts.js"></script>
<script src="https://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript">
konami = new Konami()
konami.code = function() {
soundManager.play('loop');
};
konami.load();
var merry = setTimeout('', 2000);
$(function() {
FB.init({
appId:'208549769177114', cookie:true,
status:true, xfbml:true
});
FB.Event.subscribe('auth.login', function(response) {
window.location.reload();
});
});
function navNick(where, passchars, methalt) {
clearTimeout(merry);
$.ajax({
url: './'+where,
data: passchars,
method: ((methalt) ? "GET" : methalt),
error: function() {
return false;
},
success: function(returned) {
$('#booyah').html(returned);
FB.Canvas.setSize();
return true;
}
});
}
function checkGameName() {
var game_name = $('#game_name').val();
$.getJSON('create_game.php?game_name=' + game_name, function(data) {
if (!data || data.exists) {
$('#game_exists').html('<span style="color:#f00;">Game name already exists</span>');
} else {
$('#game_exists').html('<span style="color:green;">Game name OK!</span>');
}
});
}
function addmore(gameid, gamename) {
FB.ui({
method: 'apprequests',
message: 'I\'d like to challenge you in the Fassassin game "' + gamename + '"',
data: gameid
}, function (response) {
navNick('listgames.php');
});
}
function submitNewGame() {
$.post($('#create_form').attr('action'), $('#create_form').serialize(), function(response) {
var data = $.parseJSON(response);
if(data.game_id) {
FB.ui({
method: 'apprequests',
message: 'I\'d like to challenge you in the Fassassin game "' + data.game_name + '"',
data: data.game_id
}, function (response) {
if (!response) {
$.get('./delete_game.php', 'gameid='+data.game_id, function() {
$('#game_name').val('').focus();
$('#game_exists').html('<span style="color:#666;">Game creation cancelled...</span>');
});
} else {
// Game created, invites sent!
navNick('listgames.php');
}
});
} else {
alert('Error');
}
});
}
</script>
</head><?php if ($_errorpage) { echo "<body>"; include_once($_errorpage); echo "</body></html>"; die(); } ?>
<body onload="navNick('<?=$handler; ?>', '<?=$data; ?>', 'GET');">
<div id="fb-root"></div>
<div class="header"><div style="float:left;font-size:1.3em;"><span class="hl ml" onclick="navNick('landing.php');">Fassassin</span> <span style="color:#5e6b83;">(315) ASS-ASSN</span></div><div style="float:right;"><a href="javascript:;" onclick="navNick('landing.php');">Home</a> • <a href="javascript:;" onclick="navNick('faq.php');">FAQ & Instructions</a> • <a href="javascript:;" onclick="navNick('create.php');">Create New Game</a> • <a href="javascript:;" onclick="navNick('listgames.php');">Your Games</a></div></div>
<div class="content"><div style="padding:10px;" id="booyah">Loading app, please be patient...</div></div>
</body>
</html>