diff --git a/admin/pages/accounts.php b/admin/pages/accounts.php index e481c782..554ed60c 100644 --- a/admin/pages/accounts.php +++ b/admin/pages/accounts.php @@ -16,6 +16,11 @@ $use_datatable = true; if ($config['account_country']) require SYSTEM . 'countries.conf.php'; +$nameOrNumberColumn = 'name'; +if (USE_ACCOUNT_NUMBER) { + $nameOrNumberColumn = 'number'; +} + $hasSecretColumn = $db->hasColumn('accounts', 'secret'); $hasCoinsColumn = $db->hasColumn('accounts', 'coins'); $hasPointsColumn = $db->hasColumn('accounts', 'premium_points'); @@ -48,7 +53,7 @@ else if (isset($_REQUEST['search'])) { if (strlen($search_account) < 3 && !Validator::number($search_account)) { echo_error('Player name is too short.'); } else { - $query = $db->query('SELECT `id` FROM `accounts` WHERE `name` = ' . $db->quote($search_account)); + $query = $db->query('SELECT `id` FROM `accounts` WHERE `' . $nameOrNumberColumn . '` = ' . $db->quote($search_account)); if ($query->rowCount() == 1) { $query = $query->fetch(); $id = (int)$query['id']; @@ -203,7 +208,7 @@ else if (isset($_REQUEST['search'])) { } } } else if ($id == 0) { - $accounts_db = $db->query('SELECT `id`, `name`' . ($hasTypeColumn ? ',type' : ($hasGroupColumn ? ',group_id' : '')) . ' FROM `accounts` ORDER BY `id` ASC'); + $accounts_db = $db->query('SELECT `id`, `' . $nameOrNumberColumn . '`' . ($hasTypeColumn ? ',type' : ($hasGroupColumn ? ',group_id' : '')) . ' FROM `accounts` ORDER BY `id` ASC'); ?>
@@ -215,7 +220,7 @@ else if (isset($_REQUEST['search'])) { ID - Name + Position @@ -226,7 +231,7 @@ else if (isset($_REQUEST['search'])) { - + Account Name:
+ +
+ + +
diff --git a/install/steps/7-finish.php b/install/steps/7-finish.php index 81ace38f..75a76f70 100644 --- a/install/steps/7-finish.php +++ b/install/steps/7-finish.php @@ -8,7 +8,7 @@ if(isset($config['installed']) && $config['installed'] && !isset($_SESSION['save else { require SYSTEM . 'init.php'; if(!$error) { - if(USE_ACCOUNT_NAME) + if(USE_ACCOUNT_NAME || USE_ACCOUNT_NUMBER) $account = isset($_SESSION['var_account']) ? $_SESSION['var_account'] : null; else $account_id = isset($_SESSION['var_account_id']) ? $_SESSION['var_account_id'] : null; diff --git a/system/libs/pot/OTS_Account.php b/system/libs/pot/OTS_Account.php index 89db0d16..b511ff29 100644 --- a/system/libs/pot/OTS_Account.php +++ b/system/libs/pot/OTS_Account.php @@ -231,26 +231,22 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable * @param int $id Account number. * @throws PDOException On PDO operation error. */ - public function load($id, $fresh = false, $searchOnlyById = false) + public function load($id, $fresh = false) { if(!$fresh && isset(self::$cache[$id])) { $this->data = self::$cache[$id]; return; } - $numberColumn = 'id'; $nameOrNumber = ''; - if (!$searchOnlyById) { - if (USE_ACCOUNT_NAME) { - $nameOrNumber = '`name`,'; - } else if (USE_ACCOUNT_NUMBER) { - $nameOrNumber = '`number`,'; - $numberColumn = 'number'; - } + if (USE_ACCOUNT_NAME) { + $nameOrNumber = '`name`,'; + } else if (USE_ACCOUNT_NUMBER) { + $nameOrNumber = '`number`,'; } // SELECT query on database - $this->data = $this->db->query('SELECT `id`, ' . $nameOrNumber . '`password`, `email`, `blocked`, `rlname`, `location`, `country`, `web_flags`, ' . ($this->db->hasColumn('accounts', 'premdays') ? '`premdays`, ' : '') . ($this->db->hasColumn('accounts', 'lastday') ? '`lastday`, ' : ($this->db->hasColumn('accounts', 'premend') ? '`premend`,' : ($this->db->hasColumn('accounts', 'premium_ends_at') ? '`premium_ends_at`,' : ''))) . '`created` FROM `accounts` WHERE `' . $numberColumn . '` = ' . (int) $id)->fetch(); + $this->data = $this->db->query('SELECT `id`, ' . $nameOrNumber . '`password`, `email`, `blocked`, `rlname`, `location`, `country`, `web_flags`, ' . ($this->db->hasColumn('accounts', 'premdays') ? '`premdays`, ' : '') . ($this->db->hasColumn('accounts', 'lastday') ? '`lastday`, ' : ($this->db->hasColumn('accounts', 'premend') ? '`premend`,' : ($this->db->hasColumn('accounts', 'premium_ends_at') ? '`premium_ends_at`,' : ''))) . '`created` FROM `accounts` WHERE `id` = ' . (int) $id)->fetch(); self::$cache[$id] = $this->data; } @@ -268,8 +264,13 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable */ public function find($name) { + $nameOrNumberColumn = 'name'; + if (USE_ACCOUNT_NUMBER) { + $nameOrNumberColumn = 'number'; + } + // finds player's ID - $id = $this->db->query('SELECT `id` FROM `accounts` WHERE `name` = ' . $this->db->quote($name) )->fetch(); + $id = $this->db->query('SELECT `id` FROM `accounts` WHERE `' . $nameOrNumberColumn . '` = ' . $this->db->quote($name) )->fetch(); // if anything was found if( isset($id['id']) ) diff --git a/system/libs/pot/OTS_Player.php b/system/libs/pot/OTS_Player.php index b5f48dc6..b111a150 100644 --- a/system/libs/pot/OTS_Player.php +++ b/system/libs/pot/OTS_Player.php @@ -602,7 +602,7 @@ class OTS_Player extends OTS_Row_DAO } $account = new OTS_Account(); - $account->load($this->data['account_id'], false, true); + $account->load($this->data['account_id']); return $account; } diff --git a/system/login.php b/system/login.php index 5d55cd18..e002b0b2 100644 --- a/system/login.php +++ b/system/login.php @@ -16,7 +16,7 @@ $current_session = getSession('account'); if($current_session !== false) { $account_logged = new OTS_Account(); - $account_logged->load($current_session); + $account_logged->find($current_session); if($account_logged->isLoaded() && $account_logged->getPassword() == getSession('password') //&& (!isset($_SESSION['admin']) || admin()) && (getSession('remember_me') !== false || getSession('last_visit') > time() - 15 * 60)) { // login for 15 minutes if "remember me" is not used diff --git a/system/pages/account/login.php b/system/pages/account/login.php index 9cc31503..99c812b7 100644 --- a/system/pages/account/login.php +++ b/system/pages/account/login.php @@ -37,7 +37,7 @@ if(!$logged && isset($_POST['account_login'], $_POST['password_login'])) } if (!config('account_login_by_email') || config('account_login_by_email_fallback')) { - if(USE_ACCOUNT_NAME) { + if(USE_ACCOUNT_NAME || USE_ACCOUNT_NUMBER) { $account_logged->find($login_account); } else { $account_logged->load($login_account, true); diff --git a/tools/validate.php b/tools/validate.php index b0718062..6e80a6e6 100644 --- a/tools/validate.php +++ b/tools/validate.php @@ -27,15 +27,16 @@ if(isset($_GET['account'])) error_(Validator::getLastError()); $_account = new OTS_Account(); - if(USE_ACCOUNT_NAME) + if(USE_ACCOUNT_NAME || USE_ACCOUNT_NUMBER) $_account->find($account); else $_account->load($account); + $accountNameOrNumber = (USE_ACCOUNT_NAME ? ' name' : 'number'); if($_account->isLoaded()) - error_('Account with this name already exist.'); + error_("Account with this $accountNameOrNumber already exist."); - success_('Good account' . (USE_ACCOUNT_NAME ? ' name' : '') . ' ( ' . $account . ' ).'); + success_("Good account $accountNameOrNumber ($account)."); } else if(isset($_GET['email'])) {