Skip to content

Commit

Permalink
add target filter to the admin bank logs
Browse files Browse the repository at this point in the history
  • Loading branch information
bratkartoffel committed Jan 31, 2023
1 parent b5763f4 commit a84ed9b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 21 deletions.
42 changes: 25 additions & 17 deletions include/database.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,23 +326,6 @@ public function getPlayerCount(): ?int
return $this->executeAndExtractField($this->prepare("SELECT count(1) AS count FROM " . self::TABLE_USERS . " WHERE ID > 0"), 'count');
}

public function getAdminBankLogCount(string $werFilter): ?int
{
$stmt = $this->prepare("SELECT count(1) AS count FROM " . self::TABLE_LOG_BANK . " WHERE playerName LIKE :wer");
$stmt->bindParam("wer", $werFilter);
return $this->executeAndExtractField($stmt, 'count');
}

public function getAdminBankLogEntries(string $werFilter, int $page, int $entriesPerPage): ?array
{
$offset = $page * $entriesPerPage;
$stmt = $this->prepare("SELECT * FROM " . self::TABLE_LOG_BANK . " WHERE log_bank.playerName LIKE :wer ORDER BY created DESC LIMIT :offset, :count");
$stmt->bindParam("wer", $werFilter);
$stmt->bindParam("offset", $offset, PDO::PARAM_INT);
$stmt->bindParam("count", $entriesPerPage, PDO::PARAM_INT);
return $this->executeAndExtractRows($stmt);
}

public function getAllMessagesByAnCount(int $blm_user): ?int
{
$stmt = $this->prepare("SELECT count(1) AS count FROM " . self::TABLE_MESSAGES . " WHERE An = :id ORDER BY Zeit DESC");
Expand Down Expand Up @@ -583,6 +566,31 @@ public function getAdminBioladenLogEntries(?string $werFilter, ?int $wareFilter,
return $this->executeAndExtractRows($stmt);
}

public function getAdminBankLogCount(?string $werFilter, ?string $wohinFilter): ?int
{
$stmt = $this->prepareAndBind("SELECT count(1) AS count FROM " . self::TABLE_LOG_BANK . " WHERE ((1))",
array(
"playerName LIKE :wer" => $werFilter,
"target = :wohin" => $wohinFilter,
)
);
return $this->executeAndExtractField($stmt, 'count');
}

public function getAdminBankLogEntries(?string $werFilter, ?string $wohinFilter, int $page, int $entriesPerPage): ?array
{
$offset = $page * $entriesPerPage;
$stmt = $this->prepareAndBind("SELECT * FROM " . self::TABLE_LOG_BANK . " WHERE ((1)) ORDER BY created DESC LIMIT :offset, :count",
array(
"playerName LIKE :wer" => $werFilter,
"target = :wohin" => $wohinFilter,
)
);
$stmt->bindParam("offset", $offset, PDO::PARAM_INT);
$stmt->bindParam("count", $entriesPerPage, PDO::PARAM_INT);
return $this->executeAndExtractRows($stmt);
}

public function getAdminGroupTreasuryLogCount(?string $werFilter, ?string $wenFilter, ?int $groupFilter): ?int
{
$stmt = $this->prepareAndBind("SELECT count(1) AS count FROM " . self::TABLE_LOG_GROUP_CASH . " WHERE ((1))",
Expand Down
19 changes: 15 additions & 4 deletions pages/admin_log_bank.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

$wer = getOrDefault($_GET, 'wer');
$wohin = getOrDefault($_GET, 'wohin');
$offset = getOrDefault($_GET, 'o', 0);
?>
<div id="SeitenUeberschrift">
Expand All @@ -21,6 +22,13 @@
<input type="hidden" name="p" value="admin_log_bank"/>
<label for="wer">Wer:</label>
<input type="text" name="wer" id="wer" value="<?= escapeForOutput($wer); ?>"/>
<label for="wohin">Wohin:</label>
<select name="wohin" id="wohin">
<option value="">- Alle -</option>
<option value="HAND"<?= ($wohin === 'HAND' ? ' selected="selected"' : '') ?>>Hand</option>
<option value="BANK"<?= ($wohin === 'BANK' ? ' selected="selected"' : '') ?>>Bank</option>
</select>

<input type="submit" value="Abschicken"/>
</form>
</div>
Expand All @@ -33,10 +41,11 @@
<th>Wohin</th>
</tr>
<?php
$filter = empty($wer) ? "%" : $wer;
$entriesCount = Database::getInstance()->getAdminBankLogCount($filter);
$filter_wer = empty($wer) ? null : $wer;
$filter_wohin = empty($wohin) ? null : $wohin;
$entriesCount = Database::getInstance()->getAdminBankLogCount($filter_wer, $filter_wohin);
$offset = verifyOffset($offset, $entriesCount, Config::getInt(Config::SECTION_BASE, 'admin_log_page_size'));
$entries = Database::getInstance()->getAdminBankLogEntries($filter, $offset, Config::getInt(Config::SECTION_BASE, 'admin_log_page_size'));
$entries = Database::getInstance()->getAdminBankLogEntries($filter_wer, $filter_wohin, $offset, Config::getInt(Config::SECTION_BASE, 'admin_log_page_size'));

for ($i = 0; $i < count($entries); $i++) {
$row = $entries[$i];
Expand All @@ -54,7 +63,9 @@
}
?>
</table>
<?= createPaginationTable('/?p=admin_log_bank&amp;wer=' . escapeForOutput($wer), $offset, $entriesCount, Config::getInt(Config::SECTION_BASE, 'admin_log_page_size')); ?>
<?= createPaginationTable('/?p=admin_log_bank&amp;wer=' . escapeForOutput($wer)
. '&amp;wohin=' . escapeForOutput($wohin)
, $offset, $entriesCount, Config::getInt(Config::SECTION_BASE, 'admin_log_page_size')); ?>

<div>
<a href="/?p=admin">&lt;&lt; Zurück</a>
Expand Down

0 comments on commit a84ed9b

Please sign in to comment.