[add] possibility to sort all columns

This commit is contained in:
Knah Tsaeb 2015-07-07 17:13:49 +02:00
parent 860344923c
commit 59fab70b75
6 changed files with 68 additions and 45 deletions

View File

@ -23,13 +23,28 @@ $db_pwd = $config['mysqlpw'];
$database = $config['mysqldb']; $database = $config['mysqldb'];
// Page variable // Page variable
$page = htmlspecialchars($_GET["page"]); $page = htmlspecialchars($_GET["page"]);
$orderby = htmlspecialchars($_GET["orderby"]); $sortBy = htmlspecialchars($_GET["sortBy"]);
$order = htmlspecialchars($_GET["order"]);
$newOrder = testOrder($order);
if ($order == 'a') {
$order = 'asc';
} else {
$order = 'desc';
}
function testOrder($order) {
if ($order == 'd') {
return 'a';
} else {
return 'd';
}
}
function n_print($data, $name = '') { function n_print($data, $name = '') {
$aBackTrace = debug_backtrace(); $aBackTrace = debug_backtrace();
echo '<h2>', $name, '</h2>'; echo '<h2>', $name, '</h2>';
echo '<fieldset style="border: 1px solid orange; padding: 5px;color: #333; background-color: #fff;">'; echo '<fieldset style="border: 1px solid orange; padding: 5px;color: #333; background-color: #fff;">';
echo '<legend style="border:1px solid orange;padding: 1px;background-color:#eee;color:orange;">', basename($aBackTrace[0]['file']), ' ligne => ', $aBackTrace[0]['line'], '</legend>'; echo '<legend style="border:1px solid orange;padding: 1px;background-color:#eee;color:orange;">', basename($aBackTrace[0]['file']), ' ligne => ', $aBackTrace[0]['line'], '</legend>';
echo '<pre>', htmlentities(print_r($data, 1)), '</pre>'; echo '<pre>', htmlentities(print_r($data, 1)), '</pre>';
echo '</fieldset><br />'; echo '</fieldset><br />';
} }
@ -61,6 +76,7 @@ if (!$totalunbans) {
while ($row = mysqli_fetch_array($totalunbans)) { while ($row = mysqli_fetch_array($totalunbans)) {
$numunbans = $row['MAX(id)']; $numunbans = $row['MAX(id)'];
} }
$currentlybanned = $numbans - $numunbans;
if ($currentlybanned != 1) { if ($currentlybanned != 1) {
$grammer = "IPs are"; $grammer = "IPs are";
} else { } else {
@ -132,7 +148,7 @@ $stop = microtime(true);
$total = round($stop - $start, 4); $total = round($stop - $start, 4);
echo 'Generate in ', $total, ' secondes</br>'; echo 'Generate in ', $total, ' secondes</br>';
echo "<div id='footer'>\n"; echo "<div id='footer'>\n";
echo "\t&#169;", date("Y"), " released under GNU GPL base on <a href='http://kylefberry.net'>k6b</a> work this version are made by Knah Tsaeb\n"; echo "\t&#169;", date("Y"), " released under GNU GPL base on <a href='http://kylefberry.net'>k6b</a> work this version are made by Knah Tsaeb\n";
echo "</div>\n"; echo "</div>\n";
echo "</body>\n"; echo "</body>\n";
echo "</html>\n"; echo "</html>\n";

View File

@ -1,7 +1,7 @@
<?php <?php
// Order by ID // Order by ID
function getAllBan($db, $order = 'id') { function getAllBan($db, $sortBy = 'ban_date, ban_time', $order = 'DESC') {
$sql = "SELECT id,service,ip,ban_date,ban_time,country,countryCode FROM bans ORDER BY $order"; $sql = "SELECT id,service,ip,ban_date,ban_time,country,countryCode FROM bans ORDER BY $sortBy $order";
$res = mysqli_query($db, $sql); $res = mysqli_query($db, $sql);
while ($rows = mysqli_fetch_assoc($res)) { while ($rows = mysqli_fetch_assoc($res)) {
$allBan[] = $rows; $allBan[] = $rows;
@ -14,24 +14,24 @@ function getAllBan($db, $order = 'id') {
?> ?>
<div class='table'> <div class='table'>
<div class='row'> <div class='row'>
<a href='?page=allBans&amp;orderby=service' class='cell-header'><u>Service</u></a> <a href="?page=allBans&amp;sortBy=service&amp;order=<?php echo $newOrder?>" class='cell-header'>Service</a>
<a href='?page=allBans&amp;orderby=ip' class='cell-header'><u>IP</u></a> <a href="?page=allBans&amp;sortBy=ip&amp;order=<?php echo $newOrder?>" class='cell-header'>IP</a>
<a href='?page=allBans&amp;orderby=ban_date' class='cell-header'><u>Ban Date</u></a> <a href="?page=allBans&amp;sortBy=ban_date&amp;order=<?php echo $newOrder?>" class='cell-header'>Ban Date</a>
<a href='?page=allBans&amp;orderby=ban_time' class='cell-header'><u>Ban Time</u></a> <a href="?page=allBans&amp;sortBy=ban_time&amp;order=<?php echo $newOrder?>" class='cell-header'>Ban Time</a>
<a href='?page=allBans&amp;orderby=country' class='cell-header'><u>Country</u></a> <a href="?page=allBans&amp;sortBy=country&amp;order=<?php echo $newOrder?>" class='cell-header'>Country</a>
</div> </div>
<?php <?php
if (empty($orderby)) { if (empty($sortBy)) {
$orderby = 'id'; $sortBy = 'ban_date';
} }
$allBan = getAllBan($db, $orderby); $allBan = getAllBan($db, $sortBy, $order);
foreach ($allBan as $value) { foreach ($allBan as $value) {
echo '<div class="row">'; echo '<div class="row">';
echo '<div class="cell">', $value['service'], '</div>'; echo '<div class="cell">', $value['service'], '</div>';
echo '<div class="cell">', $value['ip'], '</div>'; echo '<div class="cell">', $value['ip'], '</div>';
echo '<div class="cell">', $value['ban_date'], '</div>'; echo '<div class="cell">', $value['ban_date'], '</div>';
echo '<div class="cell">', $value['ban_time'], '</div>'; echo '<div class="cell">', $value['ban_time'], '</div>';
echo '<div class="cell">', $value['country'].printFlag($value['countryCode']),'</div>'; echo '<div class="cell">', $value['country'].printFlag($value['countryCode']), '</div>';
echo '</div>'; echo '</div>';
} }
?> ?>

View File

@ -1,6 +1,6 @@
<?php <?php
function getCurrentBan($db) { function getCurrentBan($db, $sortBy = 'ban_date, ban_time', $order = 'DESC') {
$sql = mysqli_query($db, "SELECT service,ip,ban_date,ban_time,country,countryCode FROM bans WHERE bans.id NOT IN ( SELECT unbans.id FROM unbans WHERE bans.id=unbans.id)"); $sql = mysqli_query($db, "SELECT id,service,ip,ban_date,ban_time,country,countryCode FROM bans WHERE bans.ip NOT IN ( SELECT unbans.ip FROM unbans WHERE bans.ip=unbans.ip) ORDER BY $sortBy $order");
while ($rows = mysqli_fetch_assoc($sql)) { while ($rows = mysqli_fetch_assoc($sql)) {
$currentBan[] = $rows; $currentBan[] = $rows;
} }
@ -11,30 +11,32 @@ function getCurrentBan($db) {
return $currentBan; return $currentBan;
} }
echo '<h3>Currently ',$currentlybanned,' ',$grammer,' banned.</h3>'; //echo '<h3>Currently ',abs($currentlybanned),' ',$grammer,' banned.</h3>';
?> ?>
<h2>Currently Banned</h2> <h2>Currently Banned</h2>
<div class='table'> <div class='table'>
<div class='row'> <div class='row'>
<div class='cell-header'> <div class='cell-header'>
Service <a href="?page=currentBan&amp;sortBy=service&amp;order=<?php echo $newOrder?>">Service</a>
</div> </div>
<div class='cell-header'> <div class='cell-header'>
IP <a href="?page=currentBan&amp;sortBy=ip&amp;order=<?php echo $newOrder?>">IP</a>
</div> </div>
<div class='cell-header'> <div class='cell-header'>
Date <a href="?page=currentBan&amp;sortBy=ban_date&amp;order=<?php echo $newOrder?>">Date</a>
</div> </div>
<div class='cell-header'> <div class='cell-header'>
Time <a href="?page=currentBan&amp;sortBy=ban_time&amp;order=<?php echo $newOrder?>">Time</a>
</div> </div>
<div class='cell-header'> <div class='cell-header'>
Country <a href="?page=currentBan&amp;sortBy=country&amp;order=<?php echo $newOrder?>">Country</a>
</div> </div>
</div> </div>
<?php <?php
$currentBan = getCurrentBan($db); if (empty($sortBy)) {
$sortBy = 'ban_date';
}
$currentBan = getCurrentBan($db, $sortBy, $order);
foreach ($currentBan as $value) { foreach ($currentBan as $value) {
echo '<div class="row"> echo '<div class="row">
<div class="cell">', $value['service'], '</div> <div class="cell">', $value['service'], '</div>

View File

@ -1,6 +1,6 @@
<?php <?php
function getLast24hBan($db) { function getLast24hBan($db, $sortBy = 'ban_date, ban_time', $order = 'DESC') {
$getLast24hBan = mysqli_query($db, "SELECT service,ip,ban_date,ban_time,country, countryCode FROM bans WHERE concat_ws(' ',ban_date, ban_time) >= now() - INTERVAL 1 DAY ORDER BY id"); $getLast24hBan = mysqli_query($db, "SELECT service,ip,ban_date,ban_time,country, countryCode FROM bans WHERE concat_ws(' ',ban_date, ban_time) >= now() - INTERVAL 1 DAY ORDER BY $sortBy $order");
while ($rows = mysqli_fetch_assoc($getLast24hBan)) { while ($rows = mysqli_fetch_assoc($getLast24hBan)) {
$lastBan[] = $rows; $lastBan[] = $rows;
} }
@ -12,22 +12,25 @@ function getLast24hBan($db) {
?> ?>
<div class='table'> <div class='table'>
<div class='cell-header'> <div class='cell-header'>
Service <a href="?page=lastBan&amp;sortBy=service&amp;order=<?php echo $newOrder?>">Service</a>
</div> </div>
<div class='cell-header'> <div class='cell-header'>
IP <a href="?page=lastBan&amp;sortBy=ip&amp;order=<?php echo $newOrder?>">IP</a>
</div> </div>
<div class='cell-header'> <div class='cell-header'>
Date <a href="?page=lastBan&amp;sortBy=ban_date&amp;order=<?php echo $newOrder?>">Date</a>
</div> </div>
<div class='cell-header'> <div class='cell-header'>
Time <a href="?page=lastBan&amp;sortBy=ban_time&amp;order=<?php echo $newOrder?>">Time</a>
</div> </div>
<div class='cell-header'> <div class='cell-header'>
Country <a href="?page=lastBan&amp;sortBy=country&amp;order=<?php echo $newOrder?>">Country</a>
</div> </div>
<?php <?php
$getLast24hBan = getLast24hBan($db); if (empty($sortBy)) {
$sortBy = 'ban_date';
}
$getLast24hBan = getLast24hBan($db, $sortBy, $order);
foreach ($getLast24hBan as $value) { foreach ($getLast24hBan as $value) {
echo ' echo '
<div class="row"> <div class="row">
@ -44,7 +47,7 @@ function getLast24hBan($db) {
', $value['ban_time'], ' ', $value['ban_time'], '
</div> </div>
<div class="cell"> <div class="cell">
', $value['country'], printFlag($value['countryCode']), ' ', $value['country'], printFlag($value['countryCode']), '
</div> </div>
</div>'; </div>';
} }

View File

@ -1,6 +1,6 @@
<?php <?php
function getRecidivist($db) { function getRecidivist($db, $sortBy = 'count', $order = 'ASC') {
$sql = mysqli_query($db, "SELECT ip, COUNT(*) count,country, countryCode FROM bans GROUP BY ip HAVING count > 1 ORDER BY count DESC"); $sql = mysqli_query($db, "SELECT ip, COUNT(*) count,country, countryCode FROM bans GROUP BY ip HAVING count > 1 ORDER BY $sortBy $order");
if (!$sql) { if (!$sql) {
die("Query failed. 1"); die("Query failed. 1");
} }
@ -13,21 +13,23 @@ function getRecidivist($db) {
} }
return $multiplebans; return $multiplebans;
} }
if (empty($sortBy)) {
$multiplebans = getRecidivist($db); $sortBy = 'count';
}
$multiplebans = getRecidivist($db, $sortBy, $order);
?> ?>
<h2>Recidivist (<?php echo count($multiplebans); ?>) <h2>Recidivist (<?php echo count($multiplebans); ?>)
</h2> </h2>
<div class='table'> <div class='table'>
<div class='row'> <div class='row'>
<div class='cell-header'> <div class='cell-header'>
IP <a href="?page=recidivist&amp;sortBy=count&amp;order=<?php echo $newOrder?>">IP</a>
</div> </div>
<div class='cell-header'> <div class='cell-header'>
Bans <a href="?page=recidivist&amp;sortBy=count&amp;order=<?php echo $newOrder?>">Bans</a>
</div> </div>
<div class='cell-header'> <div class='cell-header'>
Country <a href="?page=recidivist&amp;sortBy=country&amp;order=<?php echo $newOrder?>">Country</a>
</div> </div>
</div> </div>
<?php <?php

View File

@ -16,19 +16,19 @@ function topTen($db) {
<div class='table'> <div class='table'>
<div class='row'> <div class='row'>
<div class='cell-header'> <div class='cell-header'>
Country Bans
</div> </div>
<div class='cell-header'> <div class='cell-header'>
Bans Country
</div> </div>
</div> </div>
<?php <?php
$topTen = topTen($db); $topTen = topTen($db);
foreach ($topTen as $value) { foreach ($topTen as $value) {
echo '<div class="row">'; echo '<div class="row">';
echo '<div class="cell">', $value['country'].printFlag($value['countryCode']),'</div>';
echo '<div class="cell">', $value['count'], '</div>'; echo '<div class="cell">', $value['count'], '</div>';
echo '<div class="cell">', $value['country'].printFlag($value['countryCode']), '</div>';
echo '</div>'; echo '</div>';
} }
?> ?>
</div> </div>