-
Notifications
You must be signed in to change notification settings - Fork 1
/
admin.php
176 lines (153 loc) · 5.54 KB
/
admin.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
<?php
// Could include some db functions in later release
include_once('session.php');
session_start();
$me = $_SESSION['user']->getName();
if( !$_SESSION['user']->isLoggedIn() ){
header('location: index.php');
}
elseif( !$_SESSION['user']->query("select isAdmin('$me');",'boolean' ))
{
header('location: index.php');
}
$conn = new Database();
if( ((isset($_POST['newconsole']) && trim($_POST['newconsole'])) || (isset($_POST['oldconsole']) && trim($_POST['oldconsole']))) && isset($_POST['newgame']) && trim($_POST['newgame']) ){
$newconsole = pg_escape_string($_POST['newconsole']);
if( !trim($newconsole) ){
$newconsole = pg_escape_string($_POST['oldconsole']);
}
$newgame = pg_escape_string($_POST['newgame']);
$newdesc = pg_escape_string($_POST['newdesc']);
if( !$conn->queryTrueFalse("select insertGame( '$newgame', '$newconsole', '$newdesc' );" )){
echo "Error: Game $newgame could not be added for console: $newconsole";
}
}
if( isset($_POST['qtext']) && trim($_POST['qtext']) && isset($_POST['ans1']) && trim($_POST['ans1']) && isset($_POST['ans2']) && trim($_POST['ans2']) ){
$console = pg_escape_string($_POST['console']);
$game = pg_escape_string($_POST['game']);
$qtext = pg_escape_string($_POST['qtext']);
$ans1 = pg_escape_string($_POST['ans1']);
$ans2 = pg_escape_string($_POST['ans2']);
$ans3 = pg_escape_string($_POST['ans3']);
$ans4 = pg_escape_string($_POST['ans4']);
$ans5 = pg_escape_string($_POST['ans5']);
if( !$conn->queryTrueFalse("select insertQuestion('$game','$console','$qtext','$ans1','$ans2','$ans3','$ans4','$ans5');")){
echo "Error: Game $game does not exist for Console $console";
}
}
if( isset($_POST['addAdmin']) && trim($_POST['addAdmin']) ){
$admin = pg_escape_string($_POST['addAdmin']);
if( !$conn->queryTrueFalse("select addAdmin('$admin');") ){
echo "Error: Failed to add admin: $admin";
}
}
if( isset($_POST['rmAdmin']) && trim($_POST['rmAdmin']) ){
$admin = pg_escape_string($_POST['rmAdmin']);
if( !$conn->queryTrueFalse("select rmAdmin('$admin');") ){
echo "Error: Failed to remove admin: $admin";
}
}
$resultCon = $conn->queryTable('select DISTINCT gameConsole FROM games ORDER BY gameConsole ASC');
$consoles = Array();
foreach( $resultCon as $row ){
array_push($consoles,$row['gameconsole']);
}
$games = Array();
$resultGame = $conn->queryTable('select DISTINCT gamename FROM games ORDER BY gamename ASC');
foreach( $resultGame as $row ){
array_push($games, $row['gamename']);
}
$users = Array();
$admins = Array();
$resultUser = $conn->queryTable("select username,isadmin from users where username!='$me' and username!='brian'");
foreach( $resultUser as $row ){
if( $row['isadmin'] == 'f') {array_push($users,$row['username']); }
else{ array_push($admins,$row['username']); }
}
if( isset($_POST['rematch']) && $_POST['rematch'] == 'rematch' ){
exec('./matchusers.exe', $output, $exit);
if( $exit != '0' ){
echo "Rematch failed!";
}
}
if( isset($_POST['rmuser']) && trim($_POST['rmuser'])){
$rmuser = pg_escape_string($_POST['rmuser']);
if( $conn->queryTrueFalse("select rmUser('$rmuser');")){
header('refresh:0');
} else{
echo "Failed to remove user: $rmuser";
}
}
?>
<html>
<h1>Add a question</h1>
<form method='post'>
Select Console:<font color='red'>*</font>
<select name='console'><option>--Select--</option><?php foreach( $consoles as $console){ echo "<option value='$console'>$console</option>";}?></select>
<br/>
Select Game:<font color='red'>*</font>
<select name='game'><option>--Select--</option><?php foreach( $games as $game){ echo "<option value='$game'>$game</option>";} ?></select>
<br/>
Question text:<font color='red'>*</font>
<input type='textbox' name='qtext'>
<br/>
Answer 1:<font color='red'>*</font>
<input type='text' name='ans1'>
<br/>
Answer 2:<font color='red'>*</font>
<input type='text' name='ans2'>
<br/>
Answer 3:
<input type='text' name='ans3'>
<br/>
Answer 4:
<input type='text' name='ans4'>
<br/>
Answer 5:
<input type='text' name='ans5'>
<br/>
<input type='submit'>
</form>
<br/>
<h1>Add a game</h1>
<form method='post'>
GameConsole:<font color='red'>*</font><br/>
Select an existing console or add a new one!
<br/>
<select name='oldconsole'><option>--Select--</option><?php foreach( $consoles as $console){ echo "<option value='$console'>$console</option>";}?></select>
or
<input type='text' name='newconsole'>
<br/>
GameName:<font color='red'>*</font>
<input type='text' name='newgame'>
<br/>
Game Description:
<input type='textbox' name='newdesc'>
<br/>
<input type='submit'>
</form>
<h1>Add an admin</h1>
<form method='post'>
Select user:<font color='red'>*</font><select name='addAdmin'><option>--Select--</option><?php foreach( $users as $user ){ echo "<option value='$user'>$user</option>";} ?></select>
<br/>
<input type='submit'>
</form>
<h1>Remove an admin</h1>
<form method='post'>
Select admin:<font color='red'>*</font><select name='rmAdmin'><option>--Select--</option><?php foreach( $admins as $user ){ echo "<option value='$user'>$user</option>";} ?></select>
<br/>
<input type='submit'>
</form>
<h1>Remove a user</h1>
<form method='post'>
Select user:<font color='red'>*</font><select name='rmuser'><option>--Select--</option><?php foreach( $users as $user ){ echo "<option value='$user'>$user</option>";} ?></select>
<br/>
<input type='submit'>
</form>
<h1>Rematch all</h1>
<form method='post'>
<input type='hidden' name='rematch' value='rematch'>
<input type='submit'>
</form>
<footer><?php include('footer.html');?></footer>
</html>