From 59fab70b7505e8bc1a243c1ed0f3e66006ac346e Mon Sep 17 00:00:00 2001 From: Knah Tsaeb Date: Tue, 7 Jul 2015 17:13:49 +0200 Subject: [PATCH] [add] possibility to sort all columns --- index.php | 24 ++++++++++++++++++++---- page/allBans.php | 22 +++++++++++----------- page/currentBan.php | 22 ++++++++++++---------- page/lastBan.php | 21 ++++++++++++--------- page/recidivist.php | 16 +++++++++------- page/topTen.php | 8 ++++---- 6 files changed, 68 insertions(+), 45 deletions(-) diff --git a/index.php b/index.php index 24ee5a4..c18a76d 100644 --- a/index.php +++ b/index.php @@ -23,13 +23,28 @@ $db_pwd = $config['mysqlpw']; $database = $config['mysqldb']; // Page variable $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 = '') { $aBackTrace = debug_backtrace(); echo '

', $name, '

'; echo '
'; - echo '', basename($aBackTrace[0]['file']), ' ligne => ', $aBackTrace[0]['line'], ''; - echo '
',        htmlentities(print_r($data, 1)), '
'; + echo '', basename($aBackTrace[0]['file']), ' ligne => ', $aBackTrace[0]['line'], ''; + echo '
',   htmlentities(print_r($data, 1)), '
'; echo '

'; } @@ -61,6 +76,7 @@ if (!$totalunbans) { while ($row = mysqli_fetch_array($totalunbans)) { $numunbans = $row['MAX(id)']; } +$currentlybanned = $numbans - $numunbans; if ($currentlybanned != 1) { $grammer = "IPs are"; } else { @@ -132,7 +148,7 @@ $stop = microtime(true); $total = round($stop - $start, 4); echo 'Generate in ', $total, ' secondes
'; echo "\n"; echo "\n"; echo "\n"; diff --git a/page/allBans.php b/page/allBans.php index cfdede5..0df776c 100644 --- a/page/allBans.php +++ b/page/allBans.php @@ -1,7 +1,7 @@
'; echo '
', $value['service'], '
'; echo '
', $value['ip'], '
'; echo '
', $value['ban_date'], '
'; echo '
', $value['ban_time'], '
'; - echo '
', $value['country'].printFlag($value['countryCode']),'
'; + echo '
', $value['country'].printFlag($value['countryCode']), '
'; echo '
'; } ?> diff --git a/page/currentBan.php b/page/currentBan.php index 763c67b..98ae849 100644 --- a/page/currentBan.php +++ b/page/currentBan.php @@ -1,6 +1,6 @@ Currently ',$currentlybanned,' ',$grammer,' banned.'; - +//echo '

Currently ',abs($currentlybanned),' ',$grammer,' banned.

'; ?>

Currently Banned

- Service + Service
- IP + IP
- Date + Date
- Time + Time
- Country + Country
', $value['service'], '
diff --git a/page/lastBan.php b/page/lastBan.php index 5919462..35626ba 100644 --- a/page/lastBan.php +++ b/page/lastBan.php @@ -1,6 +1,6 @@ = now() - INTERVAL 1 DAY ORDER BY id"); +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 $sortBy $order"); while ($rows = mysqli_fetch_assoc($getLast24hBan)) { $lastBan[] = $rows; } @@ -12,22 +12,25 @@ function getLast24hBan($db) { ?>
- Service + Service
- IP + IP
- Date + Date
- Time + Time
- Country + Country
@@ -44,7 +47,7 @@ function getLast24hBan($db) { ', $value['ban_time'], '
-', $value['country'], printFlag($value['countryCode']), ' +', $value['country'], printFlag($value['countryCode']), '
'; } diff --git a/page/recidivist.php b/page/recidivist.php index f885ee3..89a95da 100644 --- a/page/recidivist.php +++ b/page/recidivist.php @@ -1,6 +1,6 @@ 1 ORDER BY count DESC"); +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 $sortBy $order"); if (!$sql) { die("Query failed. 1"); } @@ -13,21 +13,23 @@ function getRecidivist($db) { } return $multiplebans; } - -$multiplebans = getRecidivist($db); +if (empty($sortBy)) { + $sortBy = 'count'; +} +$multiplebans = getRecidivist($db, $sortBy, $order); ?>

Recidivist ()

- IP + IP
- Bans + Bans
- Country + Country
- Country + Bans
- Bans + Country
'; - echo '
', $value['country'].printFlag($value['countryCode']),'
'; echo '
', $value['count'], '
'; + echo '
', $value['country'].printFlag($value['countryCode']), '
'; echo '
'; } - ?> +?> \ No newline at end of file