Update accounts.php

-Bans table error
-Fix for #114
This commit is contained in:
Lee 2020-04-02 14:52:38 +01:00
parent 7c208b38ed
commit a0afeb2a7a

View File

@ -47,26 +47,22 @@ else if (isset($_REQUEST['search'])) {
if (strlen($search_account) < 3 && !Validator::number($search_account)) { if (strlen($search_account) < 3 && !Validator::number($search_account)) {
echo_error('Player name is too short.'); echo_error('Player name is too short.');
} else { } else {
if (Validator::number($search_account)) $query = $db->query('SELECT `id` FROM `accounts` WHERE `name` = ' . $db->quote($search_account));
$id = (int)$search_account; if ($query->rowCount() == 1) {
else { $query = $query->fetch();
$query = $db->query('SELECT `id` FROM `accounts` WHERE `name` = ' . $db->quote($search_account)); $id = (int)$query['id'];
if ($query->rowCount() == 1) { } else {
$query = $query->fetch(); $query = $db->query('SELECT `id`, `name` FROM `accounts` WHERE `name` LIKE ' . $db->quote('%' . $search_account . '%'));
$id = (int)$query['id']; if ($query->rowCount() > 0 && $query->rowCount() <= 10) {
} else { $str_construct = 'Do you mean?<ul class="mb-0">';
$query = $db->query('SELECT `id`, `name` FROM `accounts` WHERE `name` LIKE ' . $db->quote('%' . $search_account . '%')); foreach ($query as $row)
if ($query->rowCount() > 0 && $query->rowCount() <= 10) { $str_construct .= '<li><a href="' . $admin_base . '&id=' . $row['id'] . '">' . $row['name'] . '</a></li>';
$str_construct = 'Do you mean?<ul class="mb-0">'; $str_construct .= '</ul>';
foreach ($query as $row) echo_error($str_construct);
$str_construct .= '<li><a href="' . $admin_base . '&id=' . $row['id'] . '">' . $row['name'] . '</a></li>'; } else if ($query->rowCount() > 10)
$str_construct .= '</ul>'; echo_error('Specified name resulted with too many accounts.');
echo_error($str_construct); else
} else if ($query->rowCount() > 10) echo_error('No entries found.');
echo_error('Specified name resulted with too many accounts.');
else
echo_error('No entries found.');
}
} }
} }
} }
@ -255,18 +251,17 @@ else if (isset($_REQUEST['search'])) {
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" id="accounts-chars-tab" data-toggle="pill" href="#accounts-chars">Characters</a> <a class="nav-link" id="accounts-chars-tab" data-toggle="pill" href="#accounts-chars">Characters</a>
</li> </li>
<?php <?php if ($db->hasTable('bans')) : ?>
if (!$config['otserv_version'] != TFS_02) { ?>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" id="accounts-bans-tab" data-toggle="pill" href="#accounts-bans">Bans</a> <a class="nav-link" id="accounts-bans-tab" data-toggle="pill" href="#accounts-bans">Bans</a>
</li> </li>
<?php } <?php endif;
if ($db->hasTable('store_history')) { ?> if ($db->hasTable('store_history')) : ?>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" id="accounts-store-tab" data-toggle="pill" href="#accounts-store">Store History</a> <a class="nav-link" id="accounts-store-tab" data-toggle="pill" href="#accounts-store">Store History</a>
</li> </li>
<?php } ?> <?php endif; ?>
</ul> </ul>
</div> </div>
<div class="card-body"> <div class="card-body">
@ -449,8 +444,7 @@ else if (isset($_REQUEST['search'])) {
} ?> } ?>
</div> </div>
</div> </div>
<?php <?php if ($db->hasTable('bans')) : ?>
if (!$config['otserv_version'] != TFS_02) { ?>
<div class="tab-pane fade" id="accounts-bans"> <div class="tab-pane fade" id="accounts-bans">
<?php <?php
$bans = $db->query('SELECT * FROM ' . $db->tableName('bans') . ' WHERE ' . $db->fieldName('active') . ' = 1 AND ' . $db->fieldName('id') . ' = ' . $account->getId() . ' ORDER BY ' . $db->fieldName('added') . ' DESC'); $bans = $db->query('SELECT * FROM ' . $db->tableName('bans') . ' WHERE ' . $db->fieldName('active') . ' = 1 AND ' . $db->fieldName('id') . ' = ' . $account->getId() . ' ORDER BY ' . $db->fieldName('added') . ' DESC');
@ -510,7 +504,7 @@ else if (isset($_REQUEST['search'])) {
echo 'No Account bans.'; echo 'No Account bans.';
} ?> } ?>
</div> </div>
<?php } <?php endif;
if ($db->hasTable('store_history')) { ?> if ($db->hasTable('store_history')) { ?>
<div class="tab-pane fade" id="accounts-store"> <div class="tab-pane fade" id="accounts-store">
<?php $store_history = $db->query('SELECT * FROM `store_history` WHERE `account_id` = "' . $account->getId() . '" ORDER BY `time` DESC')->fetchAll(); ?> <?php $store_history = $db->query('SELECT * FROM `store_history` WHERE `account_id` = "' . $account->getId() . '" ORDER BY `time` DESC')->fetchAll(); ?>
@ -546,12 +540,26 @@ else if (isset($_REQUEST['search'])) {
<h5 class="m-0">Search Accounts</h5> <h5 class="m-0">Search Accounts</h5>
</div> </div>
<div class="card-body"> <div class="card-body">
<form action="<?php echo $admin_base; ?>" method="post"> <div class="row">
<div class="input-group input-group-sm"> <div class="col-6 col-lg-12">
<input type="text" class="form-control" name="search" value="<?php echo $search_account; ?>" maxlength="32" size="32"> <form action="<?php echo $admin_base; ?>" method="post">
<span class="input-group-append"><button type="submit" class="btn btn-info btn-flat">Search</button></span> <label for="name">Account Name:</label>
<div class="input-group input-group-sm">
<input type="text" class="form-control" name="search" value="<?php echo $search_account; ?>" maxlength="32" size="32">
<span class="input-group-append"><button type="submit" class="btn btn-info btn-flat">Search</button></span>
</div>
</form>
</div> </div>
</form> <div class="col-6 col-lg-12">
<form action="<?php echo $admin_base; ?>" method="post">
<label for="name">Account ID:</label>
<div class="input-group input-group-sm">
<input type="text" class="form-control" name="id" value="" maxlength="32" size="32">
<span class="input-group-append"><button type="submit" class="btn btn-info btn-flat">Search</button></span>
</div>
</form>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>