-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
327 lines (286 loc) · 14 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
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<?php
// Start the session
session_start();
// Execute scripts when the user is logged in. Mainly to display information and add behaviour for items.
if($_SESSION['loggedin']){
// Display balance
include('balance.php');
// Get all of the bought items
include('getinfo_index.php');
// Get various information of an user
include('getinfo.php');
}
// Validate an user's cookie and keep him logged in, if a cookie is set
if ($_SESSION['loggedin'] !== TRUE){
// Check if a cookie is set
$cookie = isset($_COOKIE['rememberme']) ? $_COOKIE['rememberme'] : '';
if ($cookie) {
// Separate the cookie into user id, token and mac
list ($user_id, $token, $mac) = explode(':', $cookie);
// Check if the cookie was manipulated by hashing it with the secret key again
if (!hash_equals(hash_hmac('sha256', $user_id . ':' . $token, 'secret'), $mac)) {
return false;
}
// Connect to the database
include('db_connect.php');
// Prepare MySQL code and check if the user exists or not
if ($stmt = $connect->prepare('SELECT token FROM User WHERE user_id = ?')) {
$stmt->bind_param('i', $user_id);
$stmt->execute();
// Stores the token in the variable $token_db
$stmt->store_result();
$stmt->bind_result($token_db);
$stmt->fetch();
// Compare both tokens and log the user in if they match
if ($token_db == $token) {
$_SESSION['loggedin'] = TRUE;
$_SESSION['user_id'] = $user_id;
// Reload the page
header('Location: index.php');
die();
}
}
}
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Torture some plants. It's up to you how.</title>
<link rel="stylesheet" type="text/css" href="styles/index.css">
<script type="text/javascript" src="javascripts/login.js"></script>
<script type="text/javascript" src="javascripts/timer.js"></script>
<script type="text/javascript" src="javascripts/torture_and_tools.js"></script>
<script type="text/javascript" src="javascripts/daily_bonus.js"></script>
<script type="text/javascript" src="javascripts/slideshow.js"></script>
</head>
<body>
<!-- Black navigation bar -->
<div id="navbar"></div>
<nav>
<!-- Navigation bar content -->
<ul>
<div id="homebutton">
<li><a href=""><img id="homeicon" src="img/planticon.png"></a></li>
<li><a id="frontpagetext" href="">Torture My Plant</a></li>
</div>
<?php if($_SESSION['loggedin'] === TRUE){ ?>
<li><img id="coins" src="img/coins2.png"></li>
<li><p id="balance" class="cointext"><?php echo number_format($coins, 0, ".", "."); ?></p></li>
<li><a href="profile.php">
<?php if($row['profile_picture'] !== NULL){
?>
<figure>
<?php echo "<img src=\"$path\">"; ?>
</figure>
<?php } else{ ?>
<img id="profilepic" src="img/profilepic.png" >
<?php } ?></a>
</li>
<div id="rectangle" style="cursor: pointer;" onclick="window.location='shop.php'"></div>
<li><a href ="shop.php"><img id="cart" src="img/carticon2.png"><p id="shoptext">Shop</p></a></li>
<?php } else{ ?>
<div id="fixedlinks">
<li class="right"><a class="links" href="#" onclick="showlogin()">Login</a></li>
<li class="right"><a class="links" href="signup.php">Create Account</a></li>
</div>
<?php } ?>
</ul>
</nav>
<!-- Slideshow, arrows and Torture Me button -->
<div id="content-wrapper">
<!-- Images of plants -->
<img class="plant animation_slide" src="img/plant1.jpg" width="100%">
<img class="plant animation_slide" src="img/plant2.jpg" width="100%">
<!-- Display locked/unlocked plants -->
<?php if($_SESSION['loggedin'] === TRUE && (!in_array(1, $array_orders))){ ?>
<img class="plant animation_slide" src="img/plant3_lock.jpg" width="100%">
<?php } else { ?>
<img class="plant animation_slide" src="img/plant3.jpg" width="100%">
<?php }
if($_SESSION['loggedin'] === TRUE && !in_array(2, $array_orders)){ ?>
<img class="plant animation_slide" src="img/plant4_lock.jpg" width="100%">
<?php } else { ?>
<img class="plant animation_slide" src="img/plant4.jpg" width="100%">
<?php } ?>
<!-- Arrow left -->
<a onclick="plusDivs(-1)">
<img id="leftarrow" src="img/linkerpfeil.png" width=10%>
</a>
<!-- Arrow right -->
<a onclick="plusDivs(1)">
<img id="rightarrow" src="img/rechterpfeil.png" width=10%>
</a>
<!-- 4 buttons for plant selection, either send message to arduino or open login window -->
<?php if($_SESSION['loggedin'] === TRUE){ ?>
<button class="button" onclick="startTorture(1)">Torture Me!</button>
<?php } else{ ?>
<button class="button" onclick="document.getElementById('loginbackground').style.display='block'">Torture Me!</button>
<?php } ?>
<?php if($_SESSION['loggedin'] === TRUE){ ?>
<button class="button" onclick="startTorture(2)">Torture Me!</button>
<?php } else{ ?>
<button class="button" onclick="document.getElementById('loginbackground').style.display='block'">Torture Me!</button>
<?php } ?>
<?php if($_SESSION['loggedin'] === TRUE){
if(in_array(1, $array_orders)){ ?>
<button class="button" onclick="startTorture(3)">Torture Me!</button>
<?php } else { ?>
<a class="buttonlink" href="shop.php"><button class="button unavailable">Buy In Store</button></a>
<?php }
} else{ ?>
<button class="button" onclick="document.getElementById('loginbackground').style.display='block'">Torture Me!</button>
<?php } ?>
<?php if($_SESSION['loggedin'] === TRUE){
if(in_array(2, $array_orders)){ ?>
<button class="button" onclick="startTorture(4)">Torture Me!</button>
<?php } else { ?>
<a class="buttonlink" href="shop.php"><button class="button unavailable">Buy In Store</button></a>
<?php }
} else{ ?>
<button class="button" onclick="document.getElementById('loginbackground').style.display='block'">Torture Me!</button>
<?php } ?>
</div>
<!--Loginscreen-->
<div id="loginbackground" class="modal">
<span onclick="document.getElementById('loginbackground').style.display='none'"
class="close animate">×</span>
<!-- Login screen content -->
<form class="modal-content animate" method="POST" action="">
<p class="logintext">Login</p>
<div id="container">
<div id="error"></div>
<label for="username"><b>Username</b></label>
<input type="text" placeholder="Username..." name="username" id="username" required>
<label for="password"><b>Password</b></label>
<input type="password" placeholder="Password..." name="password" id="password" required>
<label>
<input type="checkbox" id="remember" checked="checked" name="remember"> Keep me logged in
</label><br><br>
New here? <a href="signup.php">Create an account here</a><br>
<input name="submit" type="button" class="button loginbutton enter" id="submitform" value="Login" onclick="validate()" >
</div>
</form>
</div>
<!-- Torture Screen -->
<div id="torturebackground" class="Torture">
<span onclick="quitTorture(); liveshow();" class="closetorture" title="Close Modal">×</span>
<!-- Torture screen content -->
<div id="torturecontent" class="animate">
<div id="torturecontainer">
<iframe class="stream" id="stream" src="http://10.90.1.173:8081" ></iframe>
<button class="Quittorture" onclick="quitTorture()">Quit Torture</button>
<ul class="tortureul">
<div id="cooldown_fire" class="cooldown_fire"></div>
<div id="cooldown_bolt" class="cooldown_bolt"></div>
<div id="cooldown_drill" class="cooldown_drill"></div>
<div id="cooldown_acid" class="cooldown_acid"></div>
<div id="cooldown_wind" class="cooldown_wind"></div>
<!-- php checking orders for bought upgrades -->
<?php
// php variable for cooldown upgrade
$upcoold = 0;
// check if user bought upgrades
if(in_array(11, $array_orders)){
$upcoold = 1;
}
// drill uprade
$drillup = 0;
if(in_array(10, $array_orders)){
$drillup = 1;
}
// acid uprade
$acidup = 0;
if(in_array(9, $array_orders)){
$acidup = 1;
}
// bolt uprade
$boltup = 0;
if(in_array(8, $array_orders)){
$boltup = 1;
}
// wind uprade
$windup = 0;
if(in_array(7, $array_orders)){
$windup = 1;
}
// fire uprade
$fireup = 0;
if(in_array(6, $array_orders)){
$fireup = 1;
}
?>
<!-- List for torture tool buttons. Check if tools are bought -->
<?php if(in_array(5, $array_orders)){ ?>
<!-- Start timer with click on icons, pass information: selected tool, if tool is upgraded, if cooldown is upgraded -->
<li><img class="drill" src="img/drill.png" onclick="startTimer(5,<?php echo $drillup ?>,<?php echo $upcoold ?>)"></li>
<?php } else { ?>
<li><a href="shop.php" onclick="quitTorture()"><img class="drill" src="img/drill_lock.png"></a></li>
<?php } if(in_array(4, $array_orders)){ ?>
<li><img class="acid" src="img/acid.png" onclick="startTimer(3,<?php echo $acidup ?>,<?php echo $upcoold ?>)"></li>
<?php } else { ?>
<li><a href="shop.php" onclick="quitTorture()"><img class="acid" src="img/acid_lock.png"></a></li>
<?php } if(in_array(3, $array_orders)){ ?>
<li><img class="bolt" src="img/bolt.png" onclick="startTimer(2,<?php echo $boltup ?>,<?php echo $upcoold ?>)"></li>
<?php } else{ ?>
<li><a href="shop.php" onclick="quitTorture()"><img class="bolt" src="img/bolt_lock.png"></a></li>
<?php } ?>
<!-- Wind and fire are always available -->
<li><img class="wind" src="img/wind.png" onclick="startTimer(4,<?php echo $windup ?>,<?php echo $upcoold ?>);"></li>
<li><img class="fire" src="img/fire.png" onclick="startTimer(1,<?php echo $fireup ?>,<?php echo $upcoold ?>)"></li>
</ul>
<!-- Icon and container for timer -->
<img id="timericon" src="img/timer.png">
<div id="timerbox"><p class ="right" id="Countdown"></p></div>
</div>
</div>
</div>
<!--Bonus screen -->
<?php
// Set the timezone to Europe Berlin
date_default_timezone_set("Europe/Berlin");
// Get the current date (year-month-day)
$current_date = date('Y-m-d');
// Display bonus screen when more than one day has passed since the last login
if((($current_date > $last_login) || is_null($last_login)) && $_SESSION['loggedin']){ ?>
<div id="bonus_screen">
<div class="bonus_content">
<img src="img/bonusscreen.jpg" id="img_bonus">
<h1>Grab your daily bonus!</h1>
<img class="bonus_coins" src="img/coins.png">
<h2><?php if (in_array(12, $array_orders)){
echo 1500;
} else {
echo 1000;
} ?>
</h2>
<button class="button bonus_button" onclick="daily_bonus(); document.getElementById('bonus_screen').style.display='none';">Thanks!</button>
</div>
</div>
<?php }
?>
<!--Screen for notifying a user that another user is already playing-->
<div id="notify_screen">
<div class="notify_content animate">
<h1>Another user is playing right now. Please wait a few minutes.</h1>
<button class="button notifybutton" onclick="document.getElementById('notify_screen').style.visibility='hidden'">OK</button>
</div>
</div>
</body>
<!-- slidescript -->
<script>
var slideIndex = 1;
showDivs(slideIndex);
// Get the torture screen modal
var modal2 = document.getElementById('torturebackground');
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal2) {
quitTorture();
modal2.style.display = "none";
}
}
</script>
</html>