-
Notifications
You must be signed in to change notification settings - Fork 1
/
level3.php
465 lines (418 loc) · 18.7 KB
/
level3.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
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
<!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|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; /* Black Gray */
color: #fff;
}
.b{
background-color: #e6e6e6; /* light grey */
color: #000000;
}
body {
background-color: #c2d6d6;
font-family: 'Quattrocento', serif;
}
h2{
font-family: 'Lobster', cursive;
}
</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 class="active"><a href="puzzlemine.php">Puzzle Mine</a></li>
<li><a href="practise.php">Practice</a></li>
<li><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="container">
<div class="row">
<?php
$query="select * from puzzle where level='Expert'";
if( $query_run = mysqli_query($con,$query) )
{
$result = $con->query($query);
if ($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
$query3="select * from solved where trim(uid)='".$_SESSION['id']."' and pid=' ".$row['id']."'";
$result3 = mysqli_query($con,$query3);
$row3=mysqli_fetch_assoc($result3);
$queryc="select count(status) as cnt from solved where pid=' ".$row['id']."' and status=1";
$resultc = mysqli_query($con,$queryc);
$rowc=mysqli_fetch_assoc($resultc);
$corr=$rowc['cnt'];
$queryw="select count(status) as cnt from solved where pid=' ".$row['id']."' and status=3";
$resultw = mysqli_query($con,$queryw);
$roww=mysqli_fetch_assoc($resultw);
$wrong=$roww['cnt'];
if($corr+$wrong!=0)
$sr=($corr/($corr+$wrong))*100;
else
$sr=0;
?>
<div class="col-sm-6">
<div class="panel panel-success">
<div class="panel-heading">
<h4><?php echo $row['title'];?><button type="button" class="btn btn-info" style="float:right">Score <span class="badge"><?php echo $row['score'];?></span></button></h4>
</div>
<div class="panel-footer">
<div class="progress">
<div class="progress-bar progress-bar-success progress-bar-striped active" role="progressbar" aria-valuenow="<?php echo ceil($sr); ?>" aria-valuemin="0" aria-valuemax="100" style="width: <?php echo round($sr,2);?>%">
<span><?php echo round($sr,2); ?>% (Success Rate)</span>
</div>
<div class="progress-bar progress-bar-danger progress-bar-striped active" style="width: <?php echo 100-round($sr,2);?>%">
<span> <?php $sr=100-round($sr,2); echo $sr;?>%</span>
</div>
</div>
</div>
<?php
if(loggedin())
{
if($row3['status']==1){ ?>
<div class="panel-footer"><button type="button" class="btn btn-success">Solved Successfully</button></div>
<?php
}
else if($row3['status']==2){ ?>
<div class="panel-footer"><button type="button" class="btn btn-warning">Pending</button></div>
<?php
}
else if($row3['status']==0)
{
?>
<div class="panel-footer"><button type="button" class="btn btn-danger">Unsolved</button></div>
<?php
}
else if($row3['status']==3)
{
?>
<a href="showpuzzle.php?id= <?php echo $row["id"]; ?>&status=<?php echo $row3['status'];?>&level=level3">
<div class="panel-footer"><button type="button" class="btn btn-info">Retry</button></div>
</a>
<?php
}
}
if($row3['status']!=1)
{
?>
<div class="panel-footer"><a href="showpuzzle.php?id= <?php echo $row["id"]; ?>&status=<?php echo $row3['status'];?>&level=level3"><button type="button" class="btn btn-primary btn-md" >Try Now</button></a></div>
<?php
}
else
{
?>
<div class="panel-footer"><a href="showpuzzle.php?id= <?php echo $row["id"]; ?>&status=<?php echo $row3['status'];?>&level=level3"><button type="button" class="btn btn-primary btn-md" >Show Puzzle</button></a></div>
<?php
}
?>
</div>
</div>
<?php }
}
}
?>
</div>
</div>
<br>
<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-warning" 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-primary">Submit</button>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-warning" 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('Location:level3.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="Registration Confirmed";
$message = "Successfully registered";
$headers="From: itspuzzlepedia@gmail.com";
mail($eid,$subject,$message,$headers);
?>
<script type="text/javascript">
alert("Registered Successfully..");
</script>
<?php
header('Location:level3.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
}
}
}
?>
<div class=" bg-4" id="bottom">
<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>
</body>
</html>