'.ADMIN_STATUS.' |
';
if (isset($_POST['planets'])) {
// delete planets > 15 and = 0
echo ''.ADMIN_PLANETS." : \n";
$query = "DELETE FROM $dbtablename WHERE planet = 0 OR planet > 15";
$res = mysql_query($query) or die(mysql_error());
$results = mysql_affected_rows();
if ($results > 0) {
echo "".ADMIN_DONE." ($results)";
} else {
echo "".ADMIN_NOTBD."";
}
echo " | \n";
}
if (isset($_POST['galaxies']) && isset($_POST['galaxies_p1'])) {
// delete galaxies > x
$parameter = intval($_POST['galaxies_p1']);
if ($parameter < 0) $parameter = 0;
echo ''.str_replace("&1",$parameter,ADMIN_GALAXIES)." : \n";
$query = "DELETE FROM $dbtablename WHERE galaxy = 0 OR galaxy > $parameter";
$res = mysql_query($query) or die(mysql_error());
$results = mysql_affected_rows();
if ($results > 0) {
echo "".ADMIN_DONE." ($results)";
} else {
echo "".ADMIN_NOTBD."";
}
echo " | \n";
}
if (isset($_POST['players'])) {
// delete players without playerid
echo ''.ADMIN_PLAYERS." : \n";
$query = "DELETE FROM $playertable WHERE ogame_playerid IS NULL or ogame_playerid=0"; // = 0 was a bug in a previous version
$res = mysql_query($query) or die(mysql_error());
$results = mysql_affected_rows();
if ($results > 0) {
echo "".ADMIN_DONE." ($results)";
} else {
echo "".ADMIN_NOTBD."";
}
echo " | \n";
}
if (isset($_POST['reports'])) {
// delete reports that have no planet
echo ''.str_replace("&1",$parameter,ADMIN_REPORTS)." : \n";
$query = "select r.id FROM $reporttable r LEFT JOIN $dbtablename g ON (r.galaxy = g.galaxy AND r.system = g.system AND r.planet = g.planet) WHERE r.moon = 'false' AND ( g.player_id = 0 OR g.player_id IS NULL )";
$res = mysql_query($query) or die(mysql_error());
$ids = array();
while ($line = mysql_fetch_object($res)) {
array_push($ids,$line->id);
}
// find moon reports without a moon
$query = "select r.id FROM $reporttable r LEFT JOIN $dbtablename g ON (r.galaxy = g.galaxy AND r.system = g.system AND r.planet = g.planet) WHERE r.moon = 'true' AND ( g.player_id = 0 OR g.player_id IS NULL OR g.moon IS NULL )";
$res = mysql_query($query) or die(mysql_error());
while ($line = mysql_fetch_object($res)) {
array_push($ids,$line->id);
}
if (count($ids) > 0) {
$query = "DELETE FROM $reporttable WHERE id IN (".implode(",",$ids).")";
mysql_query($query) or die(mysql_error());
$results = mysql_affected_rows();
} else {
$results = 0;
}
if ($results > 0) {
echo "".ADMIN_DONE." ($results)";
} else {
echo "".ADMIN_NOTBD."";
}
echo " | \n";
}
if (isset($_POST['reset'])) {
// reset Galaxytool
echo ''.ADMIN_RESET." : \n";
$query = "TRUNCATE $dbtablename";
mysql_query($query) or die(mysql_error());
$query = "TRUNCATE $playertable";
mysql_query($query) or die(mysql_error());
$query = "TRUNCATE $allytable";
mysql_query($query) or die(mysql_error());
$query = "TRUNCATE $noticetable";
mysql_query($query) or die(mysql_error());
$query = "TRUNCATE $reporttable";
mysql_query($query) or die(mysql_error());
$query = "TRUNCATE $shouttable";
mysql_query($query) or die(mysql_error());
$query = "TRUNCATE $allyhistory";
mysql_query($query) or die(mysql_error());
$query = "TRUNCATE $playerhistory";
mysql_query($query) or die(mysql_error());
echo "done";
echo " | \n";
}
if (isset($_POST['old_players']) && isset($_POST['old_players_p1'])) {
// delete player entries older than x days
$parameter = intval($_POST['old_players_p1']);
if ($parameter < 0) $parameter = 0;
echo ''.str_replace("&1",$parameter,ADMIN_OLD_PLAYERS)." : \n";
$timezone = explode(":",$_SESSION['s_timezone_offset']);
if ($timezone[0] > 0) {
$timezone = $timezone[0] * 3600 + $timezone[1] * 60;
} else {
$timezone = $timezone[0] * 3600 - $timezone[1] * 60;
}
$time = date("Y-m-d H:i:s",time() - 86400 * $parameter + $timezone);
$query = "SELECT id FROM $playertable WHERE last_stats_update != '0000-00-00 00:00:00' AND last_stats_update < '$time'";
$res = mysql_query($query) or die(mysql_error());
$ids = array();
while ($line = mysql_fetch_object($res)) {
array_push($ids,$line->id);
}
if (count($ids) > 0) {
$query = "DELETE FROM $playertable WHERE id IN (".implode(",",$ids).")";
mysql_query($query) or die(mysql_error());
$results = mysql_affected_rows();
echo "".ADMIN_DONE." ($results)";
// delete referenced information
$query = "DELETE FROM $playerhistory WHERE player_id IN (".implode(",",$ids).")";
mysql_query($query) or die(mysql_error());
$query = "DELETE FROM $noticetable WHERE player_id IN (".implode(",",$ids).")";
mysql_query($query) or die(mysql_error());
$query = "UPDATE $dbtablename SET player_id = 0, moon = 'false', planetname = '', moonsize = 0 WHERE player_id IN (".implode(",",$ids).")";
mysql_query($query) or die(mysql_error());
} else {
echo "".ADMIN_NOTBD."";
}
echo " | \n";
}
if (isset($_POST['unused_players'])) {
// delete players which are not used in any galaxy view
echo ''.ADMIN_UNUSED_PLAYERS." : \n";
// select all players which are not used at galaxy views
$query = "SELECT p.id FROM $playertable p LEFT JOIN $dbtablename g ON p.id = g.player_id WHERE g.player_id IS NULL";
$res = mysql_query($query) or die(mysql_error());
$ids = array();
while ($line = mysql_fetch_object($res)) {
array_push($ids,$line->id);
}
if (count($ids) > 0) {
$query = "DELETE FROM $playertable WHERE id IN (".implode(",",$ids).")";
mysql_query($query) or die(mysql_error());
$results = mysql_affected_rows();
echo "".ADMIN_DONE." ($results)";
// delete referenced information
$query = "DELETE FROM $playerhistory WHERE player_id IN (".implode(",",$ids).")";
mysql_query($query) or die(mysql_error());
$query = "DELETE FROM $noticetable WHERE player_id IN (".implode(",",$ids).")";
mysql_query($query) or die(mysql_error());
} else {
echo "".ADMIN_NOTBD."";
}
echo " | \n";
}
if (isset($_POST['old_reports']) && isset($_POST['old_reports_p1'])) {
// delete reports older than x days
$parameter = intval($_POST['old_reports_p1']);
if ($parameter < 0) $parameter = 0;
echo ''.str_replace("&1",$parameter,ADMIN_OLD_REPORTS)." : \n";
$timezone = explode(":",$_SESSION['s_timezone_offset']);
if ($timezone[0] > 0) {
$timezone = $timezone[0] * 3600 + $timezone[1] * 60;
} else {
$timezone = $timezone[0] * 3600 - $timezone[1] * 60;
}
$time = date("m-d",time() - 86400 * $parameter + $timezone);
$query = "DELETE FROM $reporttable WHERE scantime < '$time' AND scantime != ''";
mysql_query($query) or die(mysql_error());
$results = mysql_affected_rows();
if ($results > 0) {
echo "".ADMIN_DONE." (".floor($results / 15).")";
} else {
echo "".ADMIN_NOTBD."";
}
echo " | \n";
}
if (isset($_POST['old_galaxies']) && isset($_POST['old_galaxies_p1'])) {
// delete galaxyviews older than x days
$parameter = intval($_POST['old_galaxies_p1']);
if ($parameter < 0) $parameter = 0;
echo ''.str_replace("&1",$parameter,ADMIN_OLD_GALAXIES)." : \n";
$timezone = explode(":",$_SESSION['s_timezone_offset']);
if ($timezone[0] > 0) {
$timezone = $timezone[0] * 3600 + $timezone[1] * 60;
} else {
$timezone = $timezone[0] * 3600 - $timezone[1] * 60;
}
$time = date("y-m-d H:i:s",time() - 86400 * $parameter + $timezone);
$query = "DELETE FROM $dbtablename WHERE last_update < '$time'";
mysql_query($query) or die(mysql_error());
$results = mysql_affected_rows();
if ($results > 0) {
echo "".ADMIN_DONE." ($results)";
} else {
echo "".ADMIN_NOTBD."";
}
echo " | \n";
}
echo " \n";
echo " |
\n";
} else {
$query = "SELECT count(*) as anzahl FROM $playertable WHERE ogame_playerid IS NULL";
$res = mysql_query($query) or die(mysql_error());
$line = mysql_fetch_object($res);
$null_players = $line->anzahl;
$query = "SELECT count(*) as anzahl FROM $playertable";
$res = mysql_query($query) or die(mysql_error());
$line = mysql_fetch_object($res);
$all_players = $line->anzahl;
?>