-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathadmin.php
241 lines (194 loc) · 6.75 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
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
<?php
require_once 'includes/inc.global.php';
// make sure we are an admin
if ( ! isset($GLOBALS['Player']) || (true !== $GLOBALS['Player']->is_admin)) {
Flash::store('Nice try');
}
if (isset($_POST['player_action'])) {
test_token( );
try {
switch ($_POST['player_action']) {
case 'approve' :
$GLOBALS['Player']->admin_approve($_POST['ids']);
break;
case 'reset' :
$GLOBALS['Player']->admin_reset_pass($_POST['ids']);
break;
case 'admin' :
$GLOBALS['Player']->admin_add_admin($_POST['ids']);
break;
case 'unadmin' :
$GLOBALS['Player']->admin_remove_admin($_POST['ids']);
break;
case 'delete' :
$player_ids = Player::clean_deleted($_POST['ids']);
$GLOBALS['Player']->admin_delete($player_ids);
Game::player_deleted($player_ids);
Message::player_deleted($player_ids);
break;
default :
break;
}
Flash::store('Admin Update Successful', true); // redirect kills form resubmission
}
catch (MyException $e) {
Flash::store('Admin Update FAILED !', true); // redirect kills form resubmission
}
}
if (isset($_POST['game_action'])) {
test_token( );
try {
switch ($_POST['game_action']) {
case 'pause' :
Game::pause($_POST['ids']);
break;
case 'unpause' :
Game::pause($_POST['ids'], false);
break;
case 'delete' :
Game::delete($_POST['ids']);
break;
default :
break;
}
Flash::store('Admin Update Successful', true); // redirect kills form resubmission
}
catch (MyException $e) {
Flash::store('Admin Update FAILED !', true); // redirect kills form resubmission
}
}
if (isset($_POST['submit'])) {
test_token( );
try {
// clear the submit and token fields
$POST = $_POST;
unset($POST['submit']);
unset($POST['token']);
Settings::write_all($POST);
Flash::store('Admin Update Successful', true); // redirect kills form resubmission
}
catch (MyException $e) {
Flash::store('Admin Update FAILED !', true); // redirect kills form resubmission
}
}
$meta['title'] = GAME_NAME.' Administration';
$meta['head_data'] = '
<script type="text/javascript" src="scripts/admin.js"></script>
';
$hints = array(
'Here you can administrate your '.GAME_NAME.' installation.' ,
'Click anywhere on a row to mark that row for action.' ,
);
$contents = '';
// get the players
$player_list = GamePlayer::get_list( );
// go through the player list and remove the root admin and ourselves
foreach ($player_list as $key => $player) {
if ($GLOBALS['_ROOT_ADMIN'] == $player['username']) {
unset($player_list[$key]);
continue;
}
if ($_SESSION['player_id'] == $player['player_id']) {
unset($player_list[$key]);
continue;
}
list($player['games'], $player['turn']) = Game::get_my_count($player['player_id']);
$player['played'] = $player['wins'] + $player['losses'];
$player_list[$key] = $player;
}
$table_meta = array(
'sortable' => true ,
'no_data' => '<p>There are no players to show</p><!-- NO_PLAYERS -->' ,
'caption' => 'Players' ,
);
$table_format = array(
array('ID', 'player_id') ,
array('Player', 'username') ,
array('First Name', 'first_name') ,
array('Last Name', 'last_name') ,
array('Email', 'email') ,
array('Color', 'color') ,
array(array('Games', '(Total | Current | Turn)'), '[[[played]]] | [[[games]]] | [[[turn]]]') ,
array('Admin', '###(([[[full_admin]]] | [[[half_admin]]]) ? \'<span class="notice">Yes</span>\' : \'No\')') ,
array('Approved', '###(([[[is_approved]]]) ? \'Yes\' : \'<span class="notice">No</span>\')') ,
array('Last Online', '###date(Settings::read(\'long_date\'), strtotime(\'[[[last_online]]]\'))', null, ' class="date"') ,
array('<input type="checkbox" id="player_all" />', '<input type="checkbox" name="ids[]" value="[[[player_id]]]" class="player_box" />', 'false', 'class="edit"') ,
);
$table = get_table($table_format, $player_list, $table_meta);
if (false === strpos($table, 'NO_PLAYERS')) {
$contents .= '
<form method="post" action="'.$_SERVER['REQUEST_URI'].'"><div class="action">
<input type="hidden" name="token" value="'.$_SESSION['token'].'" />
'.$table.'
<select name="player_action" id="player_action">
<option value="">With Selected:</option>
<option value="approve">Approve</option>
<option value="reset">Reset Pass</option>
<option value="admin">Make Admin</option>
<option value="unadmin">Remove Admin</option>
<option value="delete">Delete</option>
</select>
</div></form>';
}
else {
$contents = $table;
}
// get the games
$game_list = Game::get_list( );
$table_meta = array(
'sortable' => true ,
'no_data' => '<p>There are no games to show</p><!-- NO_GAMES -->' ,
'caption' => 'Games' ,
);
$table_format = array(
array('SPECIAL_CLASS', '(in_array(\'[[[state]]]\', array(\'Finished\',\'Draw\')))', 'lowlight') ,
array('ID', 'game_id') ,
array('Player #1', 'white') ,
array('Player #2', 'black') ,
array('State', '###(([[[paused]]]) ? \'<span class="notice">Paused</span>\' : \'[[[state]]]\')') ,
array('Created', '###date(Settings::read(\'long_date\'), strtotime(\'[[[create_date]]]\'))', null, ' class="date"') ,
array('Last Move', '###date(Settings::read(\'long_date\'), strtotime(\'[[[last_move]]]\'))', null, ' class="date"') ,
array('<input type="checkbox" id="game_all" />', '<input type="checkbox" name="ids[]" value="[[[game_id]]]" class="game_box" />', 'false', 'class="edit"') ,
);
$table = get_table($table_format, $game_list, $table_meta);
if (false === strpos($table, 'NO_GAMES')) {
$contents .= '
<form method="post" action="'.$_SERVER['REQUEST_URI'].'"><div class="action">
<input type="hidden" name="token" value="'.$_SESSION['token'].'" />
'.$table.'
<select name="game_action" id="game_action">
<option value="">With Selected:</option>
<option value="pause">Pause</option>
<option value="unpause">Unpause</option>
<option value="delete">Delete</option>
</select>
</div></form>';
}
else {
$contents .= $table;
}
// make the settings form
$settings = Settings::read_all( );
$notes = Settings::read_setting_notes( );
$form = <<< EOF
<form method="post" action="{$_SERVER['REQUEST_URI']}"><div class="action" style="clear:both;">
<input type="hidden" name="token" value="{$_SESSION['token']}" />
<ul class="settings">
EOF;
foreach ($settings as $setting => $value) {
$human_setting = humanize($setting);
$value = htmlentities($value, ENT_QUOTES);
$form .= <<< EOF
<li><label for="{$setting}">{$human_setting}</label><input type="text" id="{$setting}" name="{$setting}" maxlength="255" value="{$value}" /> <span class="note">{$notes[$setting]}</span></li>
EOF;
}
$form .= <<< EOF
<li><input type="submit" id="submit" name="submit" value="Update Settings" /></li>
</ul>
</div></form>
EOF;
$contents .= $form;
echo get_header($meta);
echo get_item($contents, $hints, $meta['title']);
call($GLOBALS);
echo get_footer( );