-
Notifications
You must be signed in to change notification settings - Fork 1
/
leaderboard.php
436 lines (394 loc) · 16.4 KB
/
leaderboard.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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
<!DOCTYPE html>
<html lang="en">
<head>
<title>PuzzlePedia</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="style.css">
<link rel="icon" href="puz.png">
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Lobster|Righteous|Yellowtail" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Lobster|Pontano+Sans|Righteous|Yellowtail" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Lobster|Pontano+Sans|Quattrocento|Righteous|Yellowtail" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style type="text/css">
.bg-4 {
background-color: #2f2f2f;
color: #fff;
}
.b{
background-color: #e6e6e6;
color: #000000;
}
h2{
font-family: 'Lobster', cursive;
}
body
{
font-family: 'Quattrocento', serif;
}
</style>
</head>
<body>
<?php
require 'connect.inc.php';
require 'core.inc.php';
?>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.php">PuzzlePedia</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li ><a href="index.php">Home</a></li>
<li><a href="puzzlemine.php">Puzzle Mine</a></li>
<li class="active"><a href="leaderboard.php">Leaderboard</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<?php if(!loggedin())
{?>
<li><a data-toggle="modal" data-target="#login"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
<li><a data-toggle="modal" data-target="#register"><span class="glyphicon glyphicon-edit"></span> Register</a></li>
<?php
}
else
{?>
<li><a href="profile.php?id=<?php echo $_SESSION['id'];?>"><span class="glyphicon glyphicon-user"></span> My Profile</a></li>
<li style="padding:5px"><button class="btn btn-primary" type="button">Score <span class="badge">
<?php
$query="select * from userinfo where id = '".$_SESSION['id']."' ";
if( $query_run = mysqli_query($con,$query) )
{
$result = $con->query($query);
if ($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
echo $row['score'];?></span></button>
</li>
<li><a href="logout.php"><span class="glyphicon glyphicon-off"></span>Logout</a></li>
<?php
}
}
}
}
?>
</ul>
</div>
</div>
</nav>
<div class="panel panel-default">
<div class="panel-heading">
<h2>
<center>Leaderboard</center>
</h2>
</div>
<table class="table">
<thead>
<tr>
<th>Rank</th>
<th>Name</th>
<th></th>
<th>Score</th>
</tr>
</thead>
<tbody>
<?php
$query="select * from userinfo order by score desc";
$rank=0;
$prevscore=0;
if( $query_run = mysqli_query($con,$query) )
{
$result = $con->query($query);
if ($result->num_rows > 0)
{
$i=1;
while($row = $result->fetch_assoc())
{
?>
<tr>
<td><?php if($prevscore!=$row['score'])
$rank=$rank+1;
echo $rank;
?>
</td>
<td><a href="profile.php?id=<?php echo $row[id];?>"> <img src="img/profile/<?php echo $row[img];?>" alt="profilepic" style="width: 3rem; height: 3rem;"class="img-circle" /><?php echo $row['name'];?></a></td>
<td>
<?php if($rank==1)
{
?> <img src="img/gold-medal.png" alt="badge"/> <?php
}
else if($rank==2)
{
?><img src="img/silver-medal.png" alt="badge"/> <?php
}
else if($rank==3)
{
?><img src="img/bronze-medal.png" alt="badge"/> <?php
}
?>
</td>
<td><?php echo $row['score'];
$prevscore=$row['score'];
?></td>
</tr>
<?php
$i=$i+1;
}
?>
<?php
}
}
?>
</tbody>
</table>
</div>
<div class=" bg-4">
<hr>
<div class="text-center center-block">
<h3>PuzzlePedia</h3>
<h5>Think, Solve, Compete</h5>
<h5>-Designed & Developed by <a href="https://in.linkedin.com/in/rahul-bagad-b7810bb0"><strong>Rahul Bagad</strong></a></h5>
<a href="https://www.facebook.com/PuzzlePedia-933560270109874"><i id="social-fb" class="fa fa-facebook-square fa-3x social"></i></a>
<a href=""><i id="social-tw" class="fa fa-github fa-3x social"></i></a>
<a href="https://plus.google.com/u/0/114174056107999198883"><i id="social-gp" class="fa fa-google-plus-square fa-3x social"></i></a>
<a href="mailto:itspuzzlepedia@gmail.com"><i id="social-em" class="fa fa-envelope-square fa-3x social"></i></a>
</div>
<center>
<script type="text/javascript" src="http://widget.supercounters.com/hit.js"></script><script type="text/javascript">sc_hit(1353537,2,5);</script>
</center>
</div>
<div class="modal fade" id="login" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<center>
<h4 class="modal-title">Login</h4>
</center>
</div>
<div class="modal-body">
<form class="form" method="post" action="index.php">
<div class="form-group">
<label for="email">Email address:</label>
<input type="email" class="form-control" name="lemail">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" name="lpwd">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
<div class="modal-footer">
<a href="fp.php"><button class="btn btn-danger">Forgot Passsword</button></a>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="register" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<center>
<h4 class="modal-title">Register</h4>
</center>
</div>
<div class="modal-body">
<form class="form" method="post" action="index.php" enctype="multipart/form-data">
<div class="form-group">
<label for="name">Name:</label>
<input type="text" class="form-control" name="name">
</div>
<div class="form-group">
<label for="contact">Contact No:</label>
<input type="text" class="form-control" name="contact">
</div>
<div class="form-group">
<label for="contact">Institute/Work Place:</label>
<input type="text" class="form-control" name="institute">
</div>
<div class="form-group">
<label for="email">Email address:</label>
<input type="email" class="form-control" name="email">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" name="pwd">
</div>
<div class="form-group">
<label class="control-label col-sm-2" >Profile Pic(Optional)</label>
<div class="col-sm-10">
<input class='form-control' type="file" name="img" ><br><br>
</div>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<?php
if(!loggedin())
{
if(isset($_POST['lemail'])&&isset($_POST['lpwd']))
{
$eid = trim($_POST['lemail']); $pwd=trim($_POST['lpwd']);
if(!empty($eid) && !empty($pwd))
{
$pwdhash=md5($pwd);
$query = "SELECT * FROM `userinfo` WHERE trim(`email`) = '$eid' AND trim(`password`) = '$pwdhash' ";
if( $query_run = mysqli_query($con,$query) )
{
$result = $con->query($query);
if ($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
$_SESSION['id']=$row['id'];
$_SESSION['eid']=$row['email'];
$_SESSION['name']=$row['name'];
$_SESSION['contact']=$row['contact'];
$_SESSION['score']=$row['score'];
echo mysqli_error($con);
?>
<script type="text/javascript">
alert("Successfully Logged In..");
</script>
<?php
header("Refresh:0.2 url=level1.php");
}
}
else
{
?>
<script type="text/javascript">
alert("invalid Login Id or Password");
</script>
<?php
}
}
else
{
?>
<script type="text/javascript">
alert("Sorry an error Ocurred . Try again later");
</script>
<?php
}
}
else
{
?>
<script type="text/javascript">
alert("Please fill in all fields");
</script>
<?php
}
}
}
?>
<?php
if(!loggedin())
{
if(isset($_POST['email'])&&isset($_POST['pwd'])&&isset($_POST['name'])&&isset($_POST['institute']))
{
$eid = $_POST['email']; $pwd=$_POST['pwd']; $name=$_POST['name'];$institute=$_POST['institute'];
$pwdhash=md5($pwd);
if(isset($_FILES['img']))
{
echo "i2";
$fname = $_FILES['img']['name'];
$ext = @strtolower( end ( explode( '.', $fname) ) );
$ftmp = $_FILES['img']['tmp_name'];
echo $fname;
}
if( !empty($eid) && !empty($pwd) && !empty($name)&&!empty($institute))
{
$query1= "SELECT email FROM userinfo WHERE trim(email)='".$eid."';";
$res=mysqli_query($con,$query1);
if(mysqli_num_rows($res)>0)
{
?>
<script type="text/javascript">
alert("Already registered.");
</script>
<?php
}
else
{
if(!empty($fname))
{
$tim = time();
$iname = $tim.".".$ext;
if(!empty($_POST['contact']))
{
$mob=$_POST['contact'];
$query="INSERT INTO `userinfo`( `email`, `password`, `name`, `contact`,`img`,`institute`) VALUES ( ' ". $eid." ', '$pwdhash', ' ".$name." ','".$mob."','".$iname."','".$institute."') ";
}
else
$query = "INSERT INTO `userinfo`( `email`, `password`, `name`,`img`,`institute`) VALUES ( ' ". $eid." ', '$pwdhash', ' ".$name." ','".$iname."','".$institute."') ";
$path="img/profile/".$iname;
if(move_uploaded_file($ftmp,$path));
}
else
{
echo "i4";
$tim = time();
if(!empty($_POST['contact']))
{
$mob=$_POST['contact'];
$query = "INSERT INTO `userinfo`( `email`, `password`, `name`, `contact`,`img`,`institute`) VALUES ( ' ". $eid." ', '$pwdhash', ' ".$name." ','".$mob."','ni.jpg','".$institute."') ";
}
else
$query = "INSERT INTO `userinfo`( `email`, `password`, `name`,`img`,`institute`) VALUES ( ' ". $eid." ', '$pwdhash', ' ".$name." ','ni.jpg','".$institute."') ";
}
if( $query_run = mysqli_query($con,$query) )
{
$subject="link for email verification";
$message = "Successfully registered";
mail($eid,$subject,$message,$headers);
?>
<script type="text/javascript">
alert("Registered Successfully..");
</script>
<?php
header("Refresh:0");
}
else
{
?>
<script type="text/javascript">
alert("Sorry an error Ocurred . Try again later");
</script>
<?php
}
}
}
else
{
?>
<script type="text/javascript">
alert("Please fill in all fields");
</script>
<?php
}
}
}
?>
</body>
</html>