<html>
<head>
<title>
Inactive Players Removal
</title>
<style>
body { background-color: black; color: goldenrod }
</style>
<body>
<form action="player_removal.php?action=delete" method="POST" autocomplete="off">
Delete players that didnt login in
<input type="text" size="1" maxlength="3" name="days" /> day(s).<br />
Clear empty accounts?
<input type="checkbox" name="accounts" value="1" checked="checked"/><br />
<input type="submit" value="Delete" />
</form>
<?
$action = $_GET['action'];
$days = $_POST['days'];
$accounts = $_POST['accounts'];
$p = array();
$time = time() - ($days * 24 * 60 * 60);
$error = false;
if($action == 'delete'):
if(!is_numeric($days) || empty($days) || $days < 1):
echo 'Days field is either empty, numeric or lower than 1.';
$error = true;
endif;
if(!$error):
mysql_connect('localhost', 'root', '');
mysql_select_db('');
$players = mysql_query("SELECT id, name, account_id, lastlogin, level FROM players WHERE lastlogin < $time");
while($player = mysql_fetch_array($players))
$p[$player[0]] = array('name' => $player[1], 'acc' => $player[2], 'login' => $player[3], 'level' => $player[4]);
mysql_query("DELETE FROM players WHERE lastlogin < $time");
if(count($p))
echo 'Deleted players that didnt login after '.date('jS F Y G:i', $time).':<br />';
else
echo 'No players have been deleted ('.date('jS F Y G:i', $time).').';
foreach($p as $player):
echo $player['name'].' (Level: '.$player['level'].'), lastlogin: '.date('jS F Y G:i', $player['login']);
if($accounts):
$accs = mysql_query("SELECT * FROM players WHERE account_id = $player[acc]");
if(!mysql_num_rows($accs)):
mysql_query("DELETE FROM accounts WHERE id = $player[acc]");
echo ', also deleted account id# '.$player['acc'];
endif;
endif;
echo '<br />';
endforeach;
mysql_close();
endif;
endif;
?>
</body>
</html>