-
Notifications
You must be signed in to change notification settings - Fork 0
/
scoreboard.php
199 lines (186 loc) · 5.42 KB
/
scoreboard.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
<?php
session_start();
require('php-bin/db.inc.php');
require('php-bin/global.php');
$logged_in = isset($_SESSION['User']);
if( !$logged_in ){
header('Location: index.php');
exit();
}
function load_user_data( $type ){
$conn = new mysqli( DB_HOST, DB_USER, DB_PASS, 'users' );
$user = $conn -> real_escape_string( $_SESSION['User'] );
$query = "SELECT * FROM `users` WHERE name='$user'";
$res = $conn -> query($query);
if( !$res ){
return '';
}
$data = $res -> fetch_assoc();
if( !$data ){
return '';
}
if( isset( $data[$type] ) ){
return $data[$type];
}
return '';
}
?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo htmlentities(CTF_NAME); ?> -- Scoreboard</title>
<link href="http://fonts.googleapis.com/css?family=Lato&subset=latin,latin-ext" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="style.css" />
<script src="home.js"></script>
<script src="scoreboard.js"></script>
</head>
<body>
<div id="head">
<span class="title">
<?php echo htmlentities(CTF_NAME); ?>
</span>
<ul id="nav">
<?php
if( !$logged_in ){
?>
<li onclick="Data.ShowDialog('Register')"><span class="text">Register</span></li>
<li onclick="Data.ShowDialog('Login')"><span class="text">Log In</span></li>
<?php
}else{
?>
<?php
if( load_user_data('role') === "admin" ){
?>
<li onclick="location.assign('dashboard.php')"><span class="text">Dashboard</span></li>
<?php
}
?>
<li onclick="location.assign('account.php')"><span class="text">Account</span></li>
<li onclick="location.assign('challenges.php')"><span class="text">Challenges</span></li>
<li onclick="location.assign('index.php')"><span class="text">Home</span></li>
<li onclick="Data.SignOut()"><span class="text">Log Out</span></li>
<?php
}
?>
</ul>
</div>
<div id="main">
<div class="table">
<div>
<div class="theader">Team Name</div>
<div class="theader">Points</div>
<div class="theader">Solved</div>
</div>
<hr />
<div id="tbody">
<?php
$conn = new mysqli( DB_HOST, DB_USER, DB_PASS, DB_NAME );
$tquery = "SELECT * FROM `teams` ORDER BY points LIMIT 50";
$res = $conn -> query( $tquery );
if( !$res ){
die('Could not fetch score data.');
}
$row = $res -> fetch_assoc();
if( !$row ){
die('No teams registered yet!');
}
$counter = 1;
do{ //Second effective use of do-while loop!
$name = htmlentities($row['name']);
$points = htmlentities($row['points']);
$asolved = explode(',', $row['solved']);
$solved = 0;
if( !(count($asolved) == 1 && empty($asolved[0])) ){
$solved = htmlentities(count($asolved));
}
echo <<<HTML
<div>
<div class="cell">$counter. $name</div>
<div class="cell">$points</div>
<div class="cell">$solved</div>
</div>
HTML;
$counter += 1;
}while( ($row = $res -> fetch_assoc()) );
?>
</div>
</div>
</div>
<footer>
<?php echo FOOTER; ?>
</footer>
<div id="dialogs" class="modal">
<div class="popup" data-dlg="Login">
<div class="title">
Log In
<img src="x.png" onclick="Data.HideDialog('Login')" alt="" class="closer" />
</div>
<form onsubmit="Data.SignIn(event)" id="login-form">
<table>
<tbody>
<tr>
<td>Username:</td>
<td><input type="text" name="user" placeholder="Username" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="pwd" placeholder="Password123" /></td>
</tr>
</tbody>
</table>
<button type="submit" class="submit">Log In</button>
</form>
</div>
<div class="popup" data-dlg="Register">
<div class="title">
Register
<img src="x.png" onclick="Data.HideDialog('Register')" alt="" class="closer" />
</div>
<form onsubmit="Data.SignUp(event)" id="signup-form">
<table>
<tbody>
<tr>
<td>Username:</td>
<td><input type="text" name="user" placeholder="Username" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="pwd" placeholder="Password123" /></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="email" name="email" placeholder="[email protected]" /></td>
</tr>
<tr>
<td>
Why are you signing up?
</td>
<td>
<select name="role">
<option value="competitor" selected>To compete as a Student</option>
<option value="spectator">To spectate</option>
</select>
</td>
</tr>
</tbody>
</table>
<button type="submit" class="submit">Register</button>
</form>
</div>
<div class="popup" data-dlg="Success">
<div class="title">
Success
</div>
<span id="success-msg">Operation succeeded.</span>
<button onclick="location.reload()" class="submit">OK</button>
</div>
<div class="popup" data-dlg="Failure">
<div class="title">
Failure
</div>
<span id="failure-msg">Operation failed.</span>
<button onclick="location.reload()" class="submit">OK</button>
</div>
</div>
</body>
</html>