mirror of
https://github.com/slawkens/myaac.git
synced 2025-05-04 13:19:20 +02:00
Adjustments & fixed to mass actions
This commit is contained in:
parent
938d01eb00
commit
6aa28a3002
@ -22,23 +22,23 @@ function admin_give_points($points)
|
|||||||
global $db, $hasPointsColumn;
|
global $db, $hasPointsColumn;
|
||||||
|
|
||||||
if (!$hasPointsColumn) {
|
if (!$hasPointsColumn) {
|
||||||
error('Points not supported.');
|
displayMessage('Points not supported.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$statement = $db->prepare('UPDATE `accounts` SET `premium_points` = `premium_points` + :points');
|
$statement = $db->prepare('UPDATE `accounts` SET `premium_points` = `premium_points` + :points');
|
||||||
if (!$statement) {
|
if (!$statement) {
|
||||||
error('Failed to prepare query statement.');
|
displayMessage('Failed to prepare query statement.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$statement->execute([
|
if (!$statement->execute([
|
||||||
'points' => $points
|
'points' => $points
|
||||||
])) {
|
])) {
|
||||||
error('Failed to add points.');
|
displayMessage('Failed to add points.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
success($points . ' points added to all accounts.');
|
displayMessage($points . ' points added to all accounts.', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function admin_give_coins($coins)
|
function admin_give_coins($coins)
|
||||||
@ -46,24 +46,24 @@ function admin_give_coins($coins)
|
|||||||
global $db, $hasCoinsColumn;
|
global $db, $hasCoinsColumn;
|
||||||
|
|
||||||
if (!$hasCoinsColumn) {
|
if (!$hasCoinsColumn) {
|
||||||
error('Coins not supported.');
|
displayMessage('Coins not supported.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$statement = $db->prepare('UPDATE `accounts` SET `coins` = `coins` + :coins');
|
$statement = $db->prepare('UPDATE `accounts` SET `coins` = `coins` + :coins');
|
||||||
if (!$statement) {
|
if (!$statement) {
|
||||||
error('Failed to prepare query statement.');
|
displayMessage('Failed to prepare query statement.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$statement->execute([
|
if (!$statement->execute([
|
||||||
'coins' => $coins
|
'coins' => $coins
|
||||||
])) {
|
])) {
|
||||||
error('Failed to add coins.');
|
displayMessage('Failed to add coins.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
success($coins . ' coins added to all accounts.');
|
displayMessage($coins . ' coins added to all accounts.', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function query_add_premium($column, $value_query, $condition_query = '1=1', $params = [])
|
function query_add_premium($column, $value_query, $condition_query = '1=1', $params = [])
|
||||||
@ -72,12 +72,12 @@ function query_add_premium($column, $value_query, $condition_query = '1=1', $par
|
|||||||
|
|
||||||
$statement = $db->prepare("UPDATE `accounts` SET `{$column}` = $value_query WHERE $condition_query");
|
$statement = $db->prepare("UPDATE `accounts` SET `{$column}` = $value_query WHERE $condition_query");
|
||||||
if (!$statement) {
|
if (!$statement) {
|
||||||
error('Failed to prepare query statement.');
|
displayMessage('Failed to prepare query statement.');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$statement->execute($params)) {
|
if (!$statement->execute($params)) {
|
||||||
error('Failed to add premium days.');
|
displayMessage('Failed to add premium days.');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ function admin_give_premdays($days)
|
|||||||
global $db, $freePremium;
|
global $db, $freePremium;
|
||||||
|
|
||||||
if ($freePremium) {
|
if ($freePremium) {
|
||||||
error('Premium days not supported. Free Premium enabled.');
|
displayMessage('Premium days not supported. Free Premium enabled.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,14 +101,14 @@ function admin_give_premdays($days)
|
|||||||
if (query_add_premium('premend', '`premend` + :value', '`premend` > :now', ['value' => $value, 'now' => $now])) {
|
if (query_add_premium('premend', '`premend` + :value', '`premend` > :now', ['value' => $value, 'now' => $now])) {
|
||||||
// set premend
|
// set premend
|
||||||
if (query_add_premium('premend', ':value', '`premend` <= :now', ['value' => $now + $value, 'now' => $now])) {
|
if (query_add_premium('premend', ':value', '`premend` <= :now', ['value' => $now + $value, 'now' => $now])) {
|
||||||
success($days . ' premium days added to all accounts.');
|
displayMessage($days . ' premium days added to all accounts.', true);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
error('Failed to execute set query.');
|
displayMessage('Failed to execute set query.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
error('Failed to execute append query.');
|
displayMessage('Failed to execute append query.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,20 +123,20 @@ function admin_give_premdays($days)
|
|||||||
if (query_add_premium('lastday', '`lastday` + :value', '`lastday` > :now', ['value' => $value, 'now' => $now])) {
|
if (query_add_premium('lastday', '`lastday` + :value', '`lastday` > :now', ['value' => $value, 'now' => $now])) {
|
||||||
// set lastday
|
// set lastday
|
||||||
if (query_add_premium('lastday', ':value', '`lastday` <= :now', ['value' => $now + $value, 'now' => $now])) {
|
if (query_add_premium('lastday', ':value', '`lastday` <= :now', ['value' => $now + $value, 'now' => $now])) {
|
||||||
success($days . ' premium days added to all accounts.');
|
displayMessage($days . ' premium days added to all accounts.', true);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
error('Failed to execute set query.');
|
displayMessage('Failed to execute set query.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
success($days . ' premium days added to all accounts.');
|
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
error('Failed to execute append query.');
|
displayMessage('Failed to execute append query.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
error('Failed to execute set days query.');
|
displayMessage('Failed to execute set days query.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,21 +149,21 @@ function admin_give_premdays($days)
|
|||||||
if (query_add_premium('premium_ends_at', '`premium_ends_at` + :value', '`premium_ends_at` > :now', ['value' => $value, 'now' => $now])) {
|
if (query_add_premium('premium_ends_at', '`premium_ends_at` + :value', '`premium_ends_at` > :now', ['value' => $value, 'now' => $now])) {
|
||||||
// set premium_ends_at
|
// set premium_ends_at
|
||||||
if (query_add_premium('premium_ends_at', ':value', '`premium_ends_at` <= :now', ['value' => $now + $value, 'now' => $now])) {
|
if (query_add_premium('premium_ends_at', ':value', '`premium_ends_at` <= :now', ['value' => $now + $value, 'now' => $now])) {
|
||||||
success($days . ' premium days added to all accounts.');
|
displayMessage($days . ' premium days added to all accounts.', true);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
error('Failed to execute set query.');
|
displayMessage('Failed to execute set query.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
error('Failed to execute append query.');
|
displayMessage('Failed to execute append query.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
error('Premium Days not supported.');
|
displayMessage('Premium Days not supported.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($_POST['action']) && $_POST['action']) {
|
if (isset($_POST['action']) && $_POST['action']) {
|
||||||
@ -171,12 +171,12 @@ if (isset($_POST['action']) && $_POST['action']) {
|
|||||||
$action = $_POST['action'];
|
$action = $_POST['action'];
|
||||||
|
|
||||||
if (preg_match("/[^A-z0-9_\-]/", $action)) {
|
if (preg_match("/[^A-z0-9_\-]/", $action)) {
|
||||||
error('Invalid action.');
|
displayMessage('Invalid action.');
|
||||||
} else {
|
} else {
|
||||||
$value = isset($_POST['value']) ? intval($_POST['value']) : 0;
|
$value = isset($_POST['value']) ? intval($_POST['value']) : 0;
|
||||||
|
|
||||||
if (!$value) {
|
if (!$value) {
|
||||||
error('Please fill all inputs');
|
displayMessage('Please fill all inputs');
|
||||||
} else {
|
} else {
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
case 'give-points':
|
case 'give-points':
|
||||||
@ -189,14 +189,27 @@ if (isset($_POST['action']) && $_POST['action']) {
|
|||||||
admin_give_premdays($value);
|
admin_give_premdays($value);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error('Action ' . $action . 'not found.');
|
displayMessage('Action ' . $action . 'not found.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
$twig->display('admin.tools.account.html.twig', array(
|
||||||
|
'hasCoinsColumn' => $hasCoinsColumn,
|
||||||
|
'hasPointsColumn' => $hasPointsColumn,
|
||||||
|
'freePremium' => $freePremium,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
function displayMessage($message, $success = false) {
|
||||||
|
global $twig, $hasCoinsColumn, $hasPointsColumn, $freePremium;
|
||||||
|
|
||||||
|
$success ? success($message): error($message);
|
||||||
|
|
||||||
$twig->display('admin.tools.account.html.twig', array(
|
$twig->display('admin.tools.account.html.twig', array(
|
||||||
'hasCoinsColumn' => $hasCoinsColumn,
|
'hasCoinsColumn' => $hasCoinsColumn,
|
||||||
'hasPointsColumn' => $hasPointsColumn,
|
'hasPointsColumn' => $hasPointsColumn,
|
||||||
'freePremium' => $freePremium,
|
'freePremium' => $freePremium,
|
||||||
));
|
));
|
||||||
|
}
|
||||||
|
@ -16,36 +16,36 @@ function admin_teleport_position($x, $y, $z) {
|
|||||||
global $db;
|
global $db;
|
||||||
$statement = $db->prepare('UPDATE `players` SET `posx` = :x, `posy` = :y, `posz` = :z');
|
$statement = $db->prepare('UPDATE `players` SET `posx` = :x, `posy` = :y, `posz` = :z');
|
||||||
if (!$statement) {
|
if (!$statement) {
|
||||||
error('Failed to prepare query statement.');
|
displayMessage('Failed to prepare query statement.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$statement->execute([
|
if (!$statement->execute([
|
||||||
'x' => $x, 'y' => $y, 'z' => $z
|
'x' => $x, 'y' => $y, 'z' => $z
|
||||||
])) {
|
])) {
|
||||||
error('Failed to execute query.');
|
displayMessage('Failed to execute query.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
success('Player\'s position updated.');
|
displayMessage('Player\'s position updated.', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function admin_teleport_town($town_id) {
|
function admin_teleport_town($town_id) {
|
||||||
global $db;
|
global $db;
|
||||||
$statement = $db->prepare('UPDATE `players` SET `town_id` = :town_id');
|
$statement = $db->prepare('UPDATE `players` SET `town_id` = :town_id');
|
||||||
if (!$statement) {
|
if (!$statement) {
|
||||||
error('Failed to prepare query statement.');
|
displayMessage('Failed to prepare query statement.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$statement->execute([
|
if (!$statement->execute([
|
||||||
'town_id' => $town_id
|
'town_id' => $town_id
|
||||||
])) {
|
])) {
|
||||||
error('Failed to execute query.');
|
displayMessage('Failed to execute query.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
success('Player\'s town updated.');
|
displayMessage('Player\'s town updated.', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($_POST['action']) && $_POST['action']) {
|
if (isset($_POST['action']) && $_POST['action']) {
|
||||||
@ -53,48 +53,64 @@ if (isset($_POST['action']) && $_POST['action']) {
|
|||||||
$action = $_POST['action'];
|
$action = $_POST['action'];
|
||||||
|
|
||||||
if (preg_match("/[^A-z0-9_\-]/", $action)) {
|
if (preg_match("/[^A-z0-9_\-]/", $action)) {
|
||||||
error('Invalid action.');
|
displayMessage('Invalid action.');
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
$playersOnline = 0;
|
$playersOnline = 0;
|
||||||
if($db->hasTable('players_online')) {// tfs 1.0
|
if($db->hasTable('players_online')) {// tfs 1.0
|
||||||
$playersOnline = $db->query('SELECT count(*) FROM `players_online`');
|
$query = $db->query('SELECT count(*) AS `count` FROM `players_online`');
|
||||||
} else {
|
} else {
|
||||||
$playersOnline = $db->query('SELECT count(*) FROM `players` WHERE `players`.`online` > 0');
|
$query = $db->query('SELECT count(*) AS `count` FROM `players` WHERE `players`.`online` > 0');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($playersOnline > 0) {
|
$playersOnline = $query->fetch(PDO::FETCH_ASSOC);
|
||||||
error('Please, close the server before execute this action otherwise players will not be affected.');
|
if ($playersOnline['count'] > 0) {
|
||||||
|
displayMessage('Please, close the server before execute this action otherwise players will not be affected.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$town_id = isset($_POST['town_id']) ? intval($_POST['town_id']) : 0;
|
$town_id = isset($_POST['town_id']) ? intval($_POST['town_id']) : null;
|
||||||
$posx = isset($_POST['posx']) ? intval($_POST['posx']) : 0;
|
$posx = isset($_POST['posx']) ? intval($_POST['posx']) : null;
|
||||||
$posy = isset($_POST['posy']) ? intval($_POST['posy']) : 0;
|
$posy = isset($_POST['posy']) ? intval($_POST['posy']) : null;
|
||||||
$posz = isset($_POST['posz']) ? intval($_POST['posz']) : 0;
|
$posz = isset($_POST['posz']) ? intval($_POST['posz']) : null;
|
||||||
|
$to_temple = $_POST['to_temple'] ?? null;
|
||||||
|
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
case 'set-town':
|
case 'set-town':
|
||||||
if (!isset($config['towns'][$town_id])) {
|
if (!$town_id) {
|
||||||
error('Please fill all inputs');
|
displayMessage('Please fill all inputs');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
admin_teleport_town($value);
|
if (!isset($config['towns'][$town_id])) {
|
||||||
|
displayMessage('Specified town does not exist');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
admin_teleport_town($town_id);
|
||||||
break;
|
break;
|
||||||
case 'set-position':
|
case 'set-position':
|
||||||
if (!$posx || !$posy || !$posz) {
|
if ((!$posx || !$posy || !$posz) && !$to_temple) {
|
||||||
error('Please fill all inputs');
|
displayMessage('Please fill all inputs');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
admin_teleport_position($posx, $posy, $posz);
|
admin_teleport_position($posx, $posy, $posz);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error('Action ' . $action . 'not found.');
|
displayMessage('Action ' . $action . 'not found.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
$twig->display('admin.tools.teleport.html.twig', array());
|
$twig->display('admin.tools.teleport.html.twig', array());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function displayMessage($message, $success = false) {
|
||||||
|
global $twig;
|
||||||
|
|
||||||
|
$success ? success($message): error($message);
|
||||||
|
$twig->display('admin.tools.teleport.html.twig', array());
|
||||||
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h5 class="m-0">Give Premium Points</h5>
|
<h5 class="m-0">Give Premium Points</h5>
|
||||||
</div>
|
</div>
|
||||||
<form method="post" action="{{ constant('ADMIN_URL') }}?p=tools&tool=account">
|
<form method="post" action="{{ constant('ADMIN_URL') }}?p=mass_account">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Premium Points</label>
|
<label>Premium Points</label>
|
||||||
@ -27,7 +27,7 @@
|
|||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h5 class="m-0">Give Coins</h5>
|
<h5 class="m-0">Give Coins</h5>
|
||||||
</div>
|
</div>
|
||||||
<form method="post" action="{{ constant('ADMIN_URL') }}?p=tools&tool=account">
|
<form method="post" action="{{ constant('ADMIN_URL') }}?p=mass_account">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Coins</label>
|
<label>Coins</label>
|
||||||
@ -49,7 +49,7 @@
|
|||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h5 class="m-0">Give Premium Days</h5>
|
<h5 class="m-0">Give Premium Days</h5>
|
||||||
</div>
|
</div>
|
||||||
<form method="post" action="{{ constant('ADMIN_URL') }}?p=tools&tool=account">
|
<form method="post" action="{{ constant('ADMIN_URL') }}?p=mass_account">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Premium Days</label>
|
<label>Premium Days</label>
|
||||||
|
@ -4,11 +4,11 @@
|
|||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h5 class="m-0">Set Town</h5>
|
<h5 class="m-0">Set Town</h5>
|
||||||
</div>
|
</div>
|
||||||
<form method="post" action="{{ constant('ADMIN_URL') }}?p=tools&tool=teleport">
|
<form method="post" action="{{ constant('ADMIN_URL') }}?p=mass_teleport">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Town</label>
|
<label>Town</label>
|
||||||
<select name="value" class="form-control">
|
<select name="town_id" class="form-control">
|
||||||
{% if config.towns|length > 0 %}
|
{% if config.towns|length > 0 %}
|
||||||
{% for town_id, town_name in config.towns %}
|
{% for town_id, town_name in config.towns %}
|
||||||
<option value="{{ town_id }}">{{ town_name }}</option>
|
<option value="{{ town_id }}">{{ town_name }}</option>
|
||||||
@ -31,7 +31,7 @@
|
|||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h5 class="m-0">Set Position</h5>
|
<h5 class="m-0">Set Position</h5>
|
||||||
</div>
|
</div>
|
||||||
<form method="post" action="{{ constant('ADMIN_URL') }}?p=tools&tool=teleport">
|
<form method="post" action="{{ constant('ADMIN_URL') }}?p=mass_teleport">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
@ -66,12 +66,13 @@
|
|||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h5 class="m-0">Teleport to Temple</h5>
|
<h5 class="m-0">Teleport to Temple</h5>
|
||||||
</div>
|
</div>
|
||||||
<form method="post" action="{{ constant('ADMIN_URL') }}?p=tools&tool=teleport">
|
<form method="post" action="{{ constant('ADMIN_URL') }}?p=mass_teleport">
|
||||||
<div class="card-footer">
|
<div class="card-footer">
|
||||||
<input type="hidden" name="action" value="set-position">
|
<input type="hidden" name="action" value="set-position">
|
||||||
<input type="hidden" name="posx" value="0">
|
<input type="hidden" name="posx" value="0">
|
||||||
<input type="hidden" name="posy" value="0">
|
<input type="hidden" name="posy" value="0">
|
||||||
<input type="hidden" name="posz" value="0">
|
<input type="hidden" name="posz" value="0">
|
||||||
|
<input type="hidden" name="to_temple" value="yes">
|
||||||
<button type="submit" class="btn btn-info">Teleport to Temple</button>
|
<button type="submit" class="btn btn-info">Teleport to Temple</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user