diff --git a/admin/pages/accounts.php b/admin/pages/accounts.php
index 377cac39..767b6e7f 100644
--- a/admin/pages/accounts.php
+++ b/admin/pages/accounts.php
@@ -57,37 +57,39 @@ if (isset($_REQUEST['id']))
$id = (int)$_REQUEST['id'];
else if (isset($_REQUEST['search_email'])) {
$search_account_email = $_REQUEST['search_email'];
- $accountModel = AccountModel::where('email', $search_account_email)->get();
- if ($accountModel->count() == 1) {
- $id = (int)$accountModel[0]->id;
- } else if ($accountModel->count() > 10) {
- echo_error('Specified e-mail resulted with too many accounts.');
- }
- else {
+ $accountModel = AccountModel::where('email', $search_account_email)->limit(11)->get(['email', 'id']);
+ if (count($accountModel) == 0) {
echo_error('No entries found.');
+ } else if (count($accountModel) == 1) {
+ $id = $accountModel->first()->getKey();
+ } else if (count($accountModel) > 10) {
+ echo_error('Specified e-mail resulted with too many accounts.');
}
}
else if (isset($_REQUEST['search'])) {
$search_account = $_REQUEST['search'];
- if (strlen($search_account) < 3 && !Validator::number($search_account)) {
- echo_error('Player name is too short.');
+ $min_size = 3;
+ if ($nameOrNumberColumn == 'number') {
+ $min_size = 1;
+ }
+
+ if (strlen($search_account) < $min_size && !Validator::number($search_account)) {
+ echo_error('Account ' . $nameOrNumberColumn . ' is too short.');
} else {
- $query = $db->query('SELECT `id` FROM `accounts` WHERE `' . $nameOrNumberColumn . '` = ' . $db->quote($search_account));
- if ($query->rowCount() == 1) {
- $query = $query->fetch();
- $id = (int)$query['id'];
+ $query = AccountModel::where($nameOrNumberColumn, '=', $search_account)->limit(11)->get(['id', $nameOrNumberColumn]);
+ if (count($query) == 0) {
+ echo_error('No entries found.');
+ } else if (count($query) == 1) {
+ $id = $query->first()->getKey();
+ } else if (count($query) > 10) {
+ echo_error('Specified name resulted with too many accounts.');
} else {
- $query = $db->query('SELECT `id`, `' . $nameOrNumberColumn . '` FROM `accounts` WHERE `' . $nameOrNumberColumn . '` LIKE ' . $db->quote('%' . $search_account . '%'));
- if ($query->rowCount() > 0 && $query->rowCount() <= 10) {
- $str_construct = 'Do you mean?
';
- echo_error($str_construct);
- } else if ($query->rowCount() > 10)
- echo_error('Specified name resulted with too many accounts.');
- else
- echo_error('No entries found.');
+ $str_construct = 'Do you mean?';
+ echo_error($str_construct);
}
}
}
diff --git a/admin/pages/mailer.php b/admin/pages/mailer.php
index d9cf8888..1f8d3188 100644
--- a/admin/pages/mailer.php
+++ b/admin/pages/mailer.php
@@ -7,6 +7,9 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
+
+use MyAAC\Models\Account;
+
defined('MYAAC') or die('Direct access not allowed!');
$title = 'Mailer';
@@ -61,15 +64,15 @@ if (!empty($mail_content) && !empty($mail_subject) && empty($mail_to)) {
$add = ' AND `email_verified` = 1';
}
- $query = $db->query('SELECT `email` FROM `accounts` WHERE `email` != ""' . $add);
+ $query = Account::where('email', '!=', '')->get(['email']);
foreach ($query as $email) {
- if (_mail($email['email'], $mail_subject, $mail_content)) {
+ if (_mail($email->email, $mail_subject, $mail_content)) {
$success++;
}
else {
$failed++;
echo '
';
- error('An error occorred while sending email to ' . $email['email'] . '. For Admin: More info can be found in system/logs/mailer-error.log');
+ error('An error occorred while sending email to ' . $email->email . '. For Admin: More info can be found in system/logs/mailer-error.log');
}
}
diff --git a/admin/pages/mass_account.php b/admin/pages/mass_account.php
index dc921ac5..46c9bc9d 100644
--- a/admin/pages/mass_account.php
+++ b/admin/pages/mass_account.php
@@ -24,20 +24,13 @@ $freePremium = $config['lua']['freePremium'];
function admin_give_points($points)
{
- global $db, $hasPointsColumn;
+ global $hasPointsColumn;
if (!$hasPointsColumn) {
displayMessage('Points not supported.');
return;
}
-
- $statement = $db->prepare('UPDATE `accounts` SET `premium_points` = `premium_points` + :points');
- if (!$statement) {
- displayMessage('Failed to prepare query statement.');
- return;
- }
-
if (!Account::query()->increment('premium_points', $points)) {
displayMessage('Failed to add points.');
return;
@@ -47,7 +40,7 @@ function admin_give_points($points)
function admin_give_coins($coins)
{
- global $db, $hasCoinsColumn;
+ global $hasCoinsColumn;
if (!$hasCoinsColumn) {
displayMessage('Coins not supported.');
@@ -62,24 +55,6 @@ function admin_give_coins($coins)
displayMessage($coins . ' coins added to all accounts.', true);
}
-function query_add_premium($column, $value_query, $condition_query = '1=1', $params = [])
-{
- global $db;
-
- $statement = $db->prepare("UPDATE `accounts` SET `{$column}` = $value_query WHERE $condition_query");
- if (!$statement) {
- displayMessage('Failed to prepare query statement.');
- return false;
- }
-
- if (!$statement->execute($params)) {
- displayMessage('Failed to add premium days.');
- return false;
- }
-
- return true;
-}
-
function admin_give_premdays($days)
{
global $db, $freePremium;
@@ -94,9 +69,9 @@ function admin_give_premdays($days)
// othire
if ($db->hasColumn('accounts', 'premend')) {
// append premend
- if (query_add_premium('premend', '`premend` + :value', '`premend` > :now', ['value' => $value, 'now' => $now])) {
+ if (Account::where('premend', '>', $now)->increment('premend', $value)) {
// set premend
- if (query_add_premium('premend', ':value', '`premend` <= :now', ['value' => $now + $value, 'now' => $now])) {
+ if (Account::where('premend', '<=', $now)->update(['premend' => $now + $value])) {
displayMessage($days . ' premium days added to all accounts.', true);
return;
} else {
@@ -114,11 +89,11 @@ function admin_give_premdays($days)
// tfs 0.x
if ($db->hasColumn('accounts', 'premdays')) {
// append premdays
- if (query_add_premium('premdays', '`premdays` + :value', '1=1', ['value' => $days])) {
+ if (Account::query()->update(['premdays' => $days])) {
// append lastday
- if (query_add_premium('lastday', '`lastday` + :value', '`lastday` > :now', ['value' => $value, 'now' => $now])) {
+ if (Account::where('lastday', '>', $now)->increment('lastday', $value)) {
// set lastday
- if (query_add_premium('lastday', ':value', '`lastday` <= :now', ['value' => $now + $value, 'now' => $now])) {
+ if (Account::where('lastday', '<=', $now)->update(['lastday' => $now + $value])) {
displayMessage($days . ' premium days added to all accounts.', true);
return;
} else {
@@ -142,9 +117,9 @@ function admin_give_premdays($days)
// tfs 1.x
if ($db->hasColumn('accounts', 'premium_ends_at')) {
// append premium_ends_at
- if (query_add_premium('premium_ends_at', '`premium_ends_at` + :value', '`premium_ends_at` > :now', ['value' => $value, 'now' => $now])) {
+ if (Account::where('premium_ends_at', '>', $now)->increment('premium_ends_at', $value)) {
// set premium_ends_at
- if (query_add_premium('premium_ends_at', ':value', '`premium_ends_at` <= :now', ['value' => $now + $value, 'now' => $now])) {
+ if (Account::where('premium_ends_at', '<=', $now)->update(['premium_ends_at' => $now + $value])) {
displayMessage($days . ' premium days added to all accounts.', true);
return;
} else {
diff --git a/admin/pages/players.php b/admin/pages/players.php
index e8084afd..c44bc012 100644
--- a/admin/pages/players.php
+++ b/admin/pages/players.php
@@ -51,22 +51,20 @@ else if (isset($_REQUEST['search'])) {
if (strlen($search_player) < 3 && !Validator::number($search_player)) {
echo_error('Player name is too short.');
} else {
- $query = $db->query('SELECT `id` FROM `players` WHERE `name` = ' . $db->quote($search_player));
- if ($query->rowCount() == 1) {
- $query = $query->fetch();
- $id = (int)$query['id'];
+ $query = Player::where('name', 'like', '%' . $search_player . '%')->orderBy('name')->limit(11)->get(['id', 'name']);
+ if (count($query) == 0) {
+ echo_error('No entries found.');
+ } else if (count($query) == 1) {
+ $id = $query->first()->getKey();
+ } else if (count($query) > 10) {
+ echo_error('Specified name resulted with too many players.');
} else {
- $query = $db->query('SELECT `id`, `name` FROM `players` WHERE `name` LIKE ' . $db->quote('%' . $search_player . '%'));
- if ($query->rowCount() > 0 && $query->rowCount() <= 10) {
- $str_construct = 'Do you mean?';
- echo_error($str_construct);
- } else if ($query->rowCount() > 10)
- echo_error('Specified name resulted with too many players.');
- else
- echo_error('No entries found.');
+ $str_construct = 'Do you mean?';
+ foreach ($query as $row) {
+ $str_construct .= '- ' . $row->name . '
';
+ }
+ $str_construct .= '
';
+ echo_error($str_construct);
}
}
}
@@ -307,7 +305,7 @@ else if (isset($_REQUEST['search'])) {
}
}
} else if ($id == 0) {
- $players_db = $db->query('SELECT `id`, `name`, `level` FROM `players` ORDER BY `id` asc');
+ $players_db = Player::orderBy('id')->get(['id','name', 'level']);
?>
@@ -327,11 +325,11 @@ else if (isset($_REQUEST['search'])) {
- |
- |
- |
+ id; ?> |
+ name; ?> |
+ level; ?> |
-
+ |
|