Skip to content

Commit

Permalink
Merge pull request #7 from AbuseIO/master
Browse files Browse the repository at this point in the history
issue #21 - implement ordering and filtering of analytics screen
  • Loading branch information
marknl committed Mar 26, 2015
2 parents 0cd0d8c + 9a7d4a5 commit edba717
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 11 deletions.
9 changes: 6 additions & 3 deletions lib/core/reporting.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,13 @@ function reportGet($id) {
function reportSummary($period) {
$summary = array();

$filter = "";
$query = "SELECT Class, count(*) AS Count FROM Reports GROUP BY Class";
$query = "SELECT Class, count(*) AS Count FROM Reports WHERE 1 AND LastSeen > '".strtotime($period . " days ago")."' GROUP BY Class";

$summary = _mysqli_fetch($query);
$rows = _mysqli_fetch($query);

foreach($rows as $id => $row) {
$summary[$row['Class']] = $row['Count'];
}

return $summary;
}
Expand Down
55 changes: 50 additions & 5 deletions www/admin/analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,67 @@
$title = 'Analytics and statistics';
include('../../lib/core/loader.php');
include('../../lib/frontend/top.php');
$summary = reportSummary("3650");

if(!empty($_GET['Days']) && is_numeric($_GET['Days'])) {
$days = $_GET['Days'];
} else {
$days = 3560;
}

$uri = $_GET;
$summary = reportSummary($days);
$filter = array('All' => 3650, 'Day' => 1, 'Week' => 7, 'Month' => 30, 'Quarter' => 90, 'Year' => 365);

if(!empty($_GET['OrderBy']) && in_array($_GET['OrderBy'],array('Count','Class'))) { $order = mysql_escape_string($_GET['OrderBy']); } else { $order = 'Class'; }
if(!empty($_GET['Direction']) && in_array($_GET['Direction'],array('ASC','DESC'))) { $direction = mysql_escape_string($_GET['Direction']); } else { $direction = 'ASC'; }

if($order == 'Count' && $direction == 'DESC') { arsort($summary); }
if($order == 'Count' && $direction == 'ASC') { asort($summary); }
if($order == 'Class' && $direction == 'DESC') { krsort($summary); }
if($order == 'Class' && $direction == 'ASC') { ksort($summary); }


?>
<div class="row">
<div class="col-md-1">
<form method='GET'>
<input type='hidden' name='OrderBy' value='<?php echo $order; ?>'>
<input type='hidden' name='Direction' value='<?php echo $direction; ?>'>
<select name='Days' class="form-control" style="width: 100px;">
<?php
foreach($filter as $name => $setting) {
if ($setting == $days) {
echo "<option value='{$setting}' SELECTED>{$name}</option>" . PHP_EOL;
} else {
echo "<option value='{$setting}'>{$name}</option>" . PHP_EOL;
}
}
?>
</select>
</div>

<div class="col-md-1">
&nbsp;<button type='submit' class="btn btn-primary">Apply</button>
</div>
</form>
</div>

<br>

<div class="row">
<div class="col-md-6">
<div id="summary">
<table class="table table-striped table-condensed">
<thead>
<tr>
<th>Classification</th>
<th>Count</th>
<th><a href='?<?php echo http_build_query(array_merge($uri,array('OrderBy'=>'Class','Direction'=>($order='Class'&&$direction=='ASC')?'DESC':'ASC'))); ?>'>Classification</a></th>
<th><a href='?<?php echo http_build_query(array_merge($uri,array('OrderBy'=>'Count','Direction'=>($order='Count'&&$direction=='ASC')?'DESC':'ASC'))); ?>'>Count</a></th>
</tr>
</thead>
<tbody>
<?php
foreach($summary as $nr => $element) {
echo "<tr><td><a href='reports.php?Class=${element['Class']}'>${element['Class']}</a></td><td>${element['Count']}</td></tr>";
foreach($summary as $class => $count) {
echo "<tr><td><a href='reports.php?Class=${class}'>${class}</a></td><td>${count}</td></tr>";
}
?>
</tbody>
Expand Down
6 changes: 3 additions & 3 deletions www/admin/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
<select name='Class' class="form-control">
<option value=''>All</option>
<?php
$summary = reportSummary("365");
foreach($summary as $nr => $element) {
echo "<option value='{$element['Class']}'>{$element['Class']}</option>";
$summary = reportSummary(3650);
foreach($summary as $class => $count) {
echo "<option value='{$class}'>{$class}</option>";
}
?>
</select>
Expand Down

0 comments on commit edba717

Please sign in to comment.