Snippets
Created by
Bear Jordan
last modified
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 | <?php
/*
Written and released by Magictallguy under the DBAD License - http://www.dbad-license.org
DON'T BE A DICK PUBLIC LICENSE
Version 1, December 2009
Copyright (C) 2009 Philip Sturgeon me@philsturgeon.uk
Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed.
DON'T BE A DICK PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
Do whatever you like with the original work, just don't be a dick.
Being a dick includes - but is not limited to - the following instances:
1a. Outright copyright infringement - Don't just copy this and change the name.
1b. Selling the unmodified original with no work done what-so-ever, that's REALLY being a dick.
1c. Modifying the original work to contain hidden harmful content. That would make you a PROPER dick.
If you become rich through modifications, related works/services, or supporting the original work, share the love. Only a dick would make loads off this work and not buy the original works creator(s) a pint.
Code is provided with no warranty. Using somebody else's code and bitching when it goes wrong makes you a DONKEY dick. Fix the problem yourself. A non-dick would submit the fix back.
*/
require_once __DIR__ . '/sglobals.php';
if(!function_exists('error')) {
function error($msg) {
global $h;
echo '<div class="error"><strong>ERROR</strong><br />',$msg,'</div>';
exit($h->endpage());
}
}
if(!function_exists('format')) {
function format($str, $dec = 0) {
$ret = is_numeric($str) ? number_format($str, $dec) : stripslashes(strip_tags($str));
if(!is_numeric($str) && $dec)
$ret = nl2br($ret);
return $ret;
}
}
if(!function_exists('username')) {
function username($id = 0, $showID = false) {
global $db, $ir;
if(!$id || !ctype_digit($id))
return 'SYSTEM';
if($id == $ir['userid'])
return '<a href="viewuser.php?u='.$id.'">'.format($ir['username']).'</a>'.($showID ? ' ['.$id.']' : '');
$select = $db->query('SELECT `username` FROM `users` WHERE `userid` = '.$id);
if(!$db->num_rows($select))
return 'SYSTEM';
return '<a href="viewuser.php?u='.$id.'">'.format($db->fetch_single($select)).'</a>'.($showID ? ' ['.$id.']' : '');
}
}
if($ir['user_level'] != 2)
error('You don\'t have access');
$_GET['action'] = array_key_exists('action', $_GET) && ctype_alpha($_GET['action']) ? strtolower(trim($_GET['action'])) : null;
switch($_GET['action']) {
case 'ban':
banUser();
break;
case 'unban':
unbanUser();
break;
case 'add':
addRoom();
break;
case 'edit':
editRoom();
break;
case 'del':
deleteRoom();
break;
default:
staffChatIndex();
break;
}
function staffChatIndex() {
?><table class="table" width="75%">
<tr>
<th width="50%">Rooms</th>
<th width="50%">Bans</th>
</tr>
<tr>
<td>
<a href="staff_chat.php?action=add">Add Room</a><br />
<a href="staff_chat.php?action=edit">Edit Room</a><br />
<a href="staff_chat.php?action=del">Delete Room</a>
</td>
<td>
<a href="staff_chat.php?action=ban">Ban Player (temp/perm)</a><br />
<a href="staff_chat.php?action=unban">Unban Player</a>
</td>
</tr>
</table><?php
}
function banUser() {
global $db;
$types = [
'temp' => 'Temporary',
'perm' => 'Permanent'
];
if(array_key_exists('submit', $_POST)) {
$_POST['user1'] = array_key_exists('user1', $_POST) && ctype_digit($_POST['user1']) ? $_POST['user1'] : null;
$_POST['user2'] = array_key_exists('user2', $_POST) && ctype_digit($_POST['user2']) ? $_POST['user2'] : null;
if((empty($_POST['user1']) && empty($_POST['user2'])) || (!empty($_POST['user1']) && !empty($_POST['user2'])))
error('You must use only one of the options available');
$who = empty($_POST['user1']) ? $_POST['user2'] : $_POST['user1'];
$selectUser = $db->query('SELECT `userid` FROM `users` WHERE `userid` = '.$who);
if(!$db->num_rows($selectUser))
error('That player doesn\'t exist');
$name = $db->fetch_single($selectUser);
$selectBan = $db->query('SELECT `ban_type`, `ban_until`, `banned_by` FROM `pusher_chat_bans` WHERE `userid` = '.$who);
if($db->num_rows($selectBan)) {
$row = $db->fetch_row($selectBan);
error(username($who).' has already been '.$types2[$row['ban_type']].' banned from the chat by '.username($row['banned_by']).'. The ban will lift on '.date('H:i:s d/m/Y', $row['ban_until']));
}
$_POST['type'] = array_key_exists('type', $_POST) && in_array($_POST['type'], ['temp', 'perm']) ? $_POST['type'] : null;
if(empty($_POST['type']))
error("You didn't select a valid ban type");
$db->query('INSERT INTO `pusher_chat_bans` (`userid`, `ban_type`, `ban_until`, `banned_by`) VALUES ('.$who.', '.$_POST['type'].', '.(time() + 60).', '.$ir['userid'].')');
stafflog_add('Imposed a '.strtolower($types[$_POST['type']]).' chat ban on '.username($who));
?>You've imposed a <?php echo strtolower($types[$_POST['type']]);?> ban on <?php echo username($who);
}
?><form action="staff_chat.php?action=ban" method="post">
<table class="table" width="75%">
<tr>
<th width="25%">Select a player</th>
<td width="75%"><select name="user1">
<option value="0">--- SELECT ---</option><?php
$selectUsers = $db->query('SELECT `userid`, `username` FROM `users` ORDER BY `username` ASC');
while($row = $db->fetch_row($selectUsers))
printf('<option value="%u">%s [%u]</option>', $row['userid'], format($row['username']), $row['userid']);
?></select></td>
</tr>
<tr>
<th><strong style="text-decoration:underline;">OR</strong> enter their ID</th>
<td><input type="number" name="user2" /></td>
</tr>
<tr>
<th>Type of ban</th>
<td><select name="type"><?php
foreach($types as $type => $disp)
printf('<option value="%s">%s</option>', $type, $disp);
?></select></td>
</tr>
<tr>
<td colspan="2" class="center"><input type="submit" name="submit" value="Impose ban" /></td>
</tr>
</table>
</form><?php
}
function unbanUser() {
global $db;
if(array_key_exists('submit', $_POST)) {
$_POST['user1'] = array_key_exists('user1', $_POST) && ctype_digit($_POST['user1']) ? $_POST['user1'] : null;
$_POST['user2'] = array_key_exists('user2', $_POST) && ctype_digit($_POST['user2']) ? $_POST['user2'] : null;
if((empty($_POST['user1']) && empty($_POST['user2'])) || (!empty($_POST['user1']) && !empty($_POST['user2'])))
error("You must use only one of the options available");
$who = empty($_POST['user1']) ? $_POST['user2'] : $_POST['user1'];
$selectUser = $db->query('SELECT `userid` FROM `users` WHERE `userid` = '.$who);
if(!$db->num_rows($selectUser))
error('That player doesn\'t exist');
$name = $db->fetch_single($selectUser);
$selectBan = $db->query('SELECT `ban_type`, `ban_until`, `banned_by` FROM `pusher_chat_bans` WHERE `userid` = '.$who);
if(!$db->num_rows($selectBan))
error(username($who).' isn\'t banned from the chat');
$db->query('DELETE FROM `pusher_chat_bans` WHERE `userid` = '.$who);
stafflog_add('Revoked the chat ban on '.username($who));
?>You've revoked the ban on <?php echo username($who);
}
?><form action="staff_chat.php?action=unban" method="post">
<table class="table" width="75%">
<tr>
<th width="25%">Select a player</th>
<td width="75%"><select name="user1">
<option value="0">--- SELECT ---</option><?php
$selectUsers = $db->query('SELECT `userid`, `username` FROM `users` ORDER BY `username` ASC');
while($row = $db->fetch_row($selectUsers))
printf('<option value="%u">%s [%u]</option>', $row['userid'], format($row['username']), $row['userid']);
?></select></td>
</tr>
<tr>
<th><strong style="text-decoration:underline;">OR</strong> enter their ID</th>
<td><input type="number" name="user2" /></td>
</tr>
<tr>
<td colspan="2" class="center"><input type="submit" name="submit" value="Revoke ban" /></td>
</tr>
</table>
</form><?php
}
function addRoom() {
global $db;
$status = [
0 => 'open',
1 => 'closed'
];
if(array_key_exists('submit', $_POST)) {
$_POST['name'] = array_key_exists('name', $_POST) && is_string($_POST['name']) ? $db->escape(trim($_POST['name'])) : null;
if(empty($_POST['name']))
error('You didn\'t enter a valid name');
$select = $db->query('SELECT `id` FROM `pusher_chat_rooms` WHERE `chat_name` = "'.$_POST['name'].'"');
if($db->num_rows($select))
error('That room already exists');
$_POST['status'] = array_key_exists('status', $_POST) && in_array($_POST['status'], [0, 1]) ? $_POST['status'] : null;
if(empty($_POST['status']))
error('You didn\'t select a valid room status');
$db->query('INSERT INTO `pusher_chat_rooms` (`chat_name`, `closed`) VALUES ("'.$_POST['name'].'", '.$_POST['status'].')');
stafflog_add('Added chat room: '.stripslashes($_POST['name']));
?>You've added the new chat room: <?php echo stripslashes($_POST['name']);?><br /><?php
}
?><form action="staff_chat.php?action=add" method="post">
<table class="table" width="75%">
<tr>
<th width="25%">Name</th>
<td width="75%"><input type="text" name="name" /></td>
</tr>
<tr>
<th>Status</th>
<td><select name="status"><?php
foreach($status as $val => $disp)
printf('<option value="%u">%s</option>', $val, ucfirst($disp));
?></select></td>
</tr>
<tr>
<td colspan="2" class="center"><input type="submit" name="submit" value="Add Room" /></td>
</tr>
</table>
</form><?php
}
function editRoom() {
global $db;
$_GET['step'] = array_key_exists('step', $_GET) && ctype_digit($_GET['step']) ? $_GET['step'] : null;
switch($_GET['step']) {
case 2:
$_POST['id'] = array_key_exists('id', $_POST) && ctype_digit($_POST['id']) ? $_POST['id'] : null;
if(empty($_POST['id']))
error('You didn\'t select a valid room');
$select = $db->query('SELECT `chat_name` FROM `pusher_chat_rooms` WHERE `id` = '.$_POST['id']);
if(!$db->num_rows($select))
error('That room doesn\'t exist');
$_POST['name'] = array_key_exists('name', $_POST) && is_string($_POST['name']) ? $db->escape(trim($_POST['name'])) : null;
if(empty($_POST['name']))
$mtg->error('You didn\'t enter a valid name');
$select = $db->query('SELECT `id` FROM `pusher_chat_rooms` WHERE `chat_name` = "'.$_POST['name'].'" AND `id` != '.$_POST['id']);
if($db->num_rows($select))
error('Another room with that name already exists');
$_POST['status'] = array_key_exists('status', $_POST) && in_array($_POST['status'], [0, 1]) ? $_POST['status'] : null;
if(empty($_POST['status']))
error('You didn\'t select a valid room status');
$db->query('REPLACE INTO `pusher_chat_rooms` (`id`, `chat_name`, `closed`) VALUES ('.$_POST['id'].', "'.$_POST['name'].'", '.$_POST['status'].')');
stafflog_add('Edited chat room: '.stripslashes($_POST['name']));
?>You've edited the chat room: <?php echo stripslashes($_POST['name']);?><br /><?php
break;
case 1:
$status = [
0 => 'open',
1 => 'closed'
];
$_POST['id'] = array_key_exists('id', $_POST) && ctype_digit($_POST['id']) ? $_POST['id'] : null;
if(empty($_POST['id']))
error('You didn\'t select a valid room');
$select = $db->query('SELECT `chat_name`, `closed` FROM `pusher_chat_rooms` WHERE `id` = '.$_POST['id']);
if(!$db->num_rows($select))
error('That room doesn\'t exist');
$row = $db->fetch_row($select);
?><form action="staff_chat.php?action=edit&step=2" method="post">
<input type="hidden" name="id" value="<?php echo $_POST['id'];?>" />
<table class="table" width="75%">
<tr>
<th width="25%">Name</th>
<td width="75%"><input type="text" name="name" value="<?php echo $row['chat_name'];?>" /></td>
</tr>
<tr>
<th>Status</th>
<td><select name="status"><?php
foreach($status as $val => $disp)
printf('<option value="%u"%s>%s</option>', $val, $val == $row['closed'] ? ' selected="selected"' : '', ucfirst($disp));
?></select></td>
</tr>
<tr>
<td colspan="2" class="center"><input type="submit" name="submit" value="Edit Room" /></td>
</tr>
</table>
</form><?php
break;
default:
?><form action="staff_chat.php?action=edit&step=1" method="post">
<table class="table" width="75%">
<tr>
<th width="25%">Room to delete</th>
<td width="75%"><select name="id"><?php
$select = $db->query('SELECT `id`, `chat_name` FROM `pusher_chat_rooms` ORDER BY `id` ASC');
if(!$db->num_rows($select))
echo '<option value="0">There are no rooms</option>';
else
while($row = $db->fetch_row($select))
printf('<option value="%u">%s</option>', $row['id'], $row['chat_name']);
?></select></td>
</tr>
<tr>
<td colspan="2" class="center"><input type="submit" name="submit" value="Edit room" /></td>
</tr>
</table>
</form><?php
break;
}
}
function deleteRoom() {
global $db;
if(array_key_exists('submit', $_POST)) {
$_POST['id'] = array_key_exists('id', $_POST) && ctype_digit($_POST['id']) ? $_POST['id'] : null;
if(empty($_POST['id']))
error('You didn\'t select a valid room');
$select = $db->query('SELECT `chat_name` FROM `pusher_chat_rooms` WHERE `id` = '.$_POST['id']);
if(!$db->num_rows($select))
error('That room doesn\'t exist');
$name = $db->fetch_single($select);
if(!array_key_exists('ans', $_POST)) {
?>Are you sure you want to delete the Chat Room: “<?php echo $name;?>”?<br />
<form action="staff_chat.php?action=del" method="post">
<input type="hidden" name="id" value="<?php echo $_POST['id'];?>" />
<input type="hidden" name="submit" value="1" />
<input type="submit" name="ans" value="Yes, delete that room!" />
</form><?php
} else {
$db->query('DELETE FROM `pusher_chat_rooms` WHERE `id` = '.$_POST['id']);
stafflog_add('Deleted chat room: '.$name);
?>You've deleted the Chat Room: “<?php echo $name;?>”<?php
}
} else {
?><form action="staff_chat.php?action=del" method="post">
<table class="table" width="75%">
<tr>
<th width="25%">Room to delete</th>
<td width="75%"><select name="id"><?php
$select = $db->query('SELECT `id`, `chat_name` FROM `pusher_chat_rooms` ORDER BY `id` ASC');
if(!$db->num_rows($select))
echo '<option value="0">There are no rooms</option>';
else
while($row = $db->fetch_row($select))
printf('<option value="%u">%s</option>', $row['id'], $row['chat_name']);
?></select></td>
</tr>
<tr>
<td colspan="2" class="center"><input type="submit" name="submit" value="Delete room" /></td>
</tr>
</table>
</form><?php
}
}
$h->endpage();
|
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.