<?php
/*
* $Id: s.php 132 2011-09-28 16:06:09Z stuart $
*
* spbug.com
* Sequel Pro URL Shortening Service
*
* Copyright (c) 2010 Stuart Connolly. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
$title = 'Stats';
// General
$total = DB::get_var('SELECT COUNT(1) FROM redirect_log');
$year = DB::get_var('SELECT COUNT(1) FROM redirect_log WHERE YEAR(redirect_date) = YEAR(CURRENT_DATE())');
$month = DB::get_var('SELECT COUNT(1) FROM redirect_log WHERE MONTH(redirect_date) = MONTH(CURRENT_DATE())');
$day = DB::get_var('SELECT COUNT(1) FROM redirect_log WHERE DATE(redirect_date) = CURRENT_DATE()');
$hour = DB::get_var("SELECT COUNT(1) FROM redirect_log WHERE redirect_date >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR)");
// Rule based
$rule_stats = DB::get_results(
"SELECT u.url_name, COUNT(1) AS 'hit_count'
FROM redirect_log l, redirect_urls u
WHERE l.redirect_url_id = u.url_id
GROUP BY u.url_name"
);
// Build array of stats
$stats = array((object
)array('name' => 'Total Redirects', 'hits' => $total),
(object
)array('name' => 'Redirects This Year', 'hits' => $year),
(object
)array('name' => 'Redirects This Month', 'hits' => $month),
(object
)array('name' => 'Redirects Today', 'hits' => $day),
(object
)array('name' => 'Redirects This Hour', 'hits' => $hour));
require_once('header.php'); ?>
<h1><?php echo $_SERVER['HTTP_HOST']; ?> Stats</h1>
<p>URL redirect statistics.</p>
<h2>General Stats</h2>
<table class="stattable">
<thead>
<tr>
<th>Stat</th>
<th class="center">Hits</th>
</tr>
</thead>
<tbody>
<?php foreach ($stats as $stat) : ?>
<tr>
<td><?php echo $stat->name; ?></td>
<td class="center"><?php echo $stat->hits; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<h2>Rule-Based Stats</h2>
<?php if (count($rule_stats)) : ?>
<table class="stattable">
<thead>
<tr>
<th>Redirect Rule</th>
<th class="center">Hits</th>
</tr>
</thead>
<tbody>
<?php foreach ($rule_stats as $rule) : ?>
<tr>
<td><?php echo $rule->url_name; ?></td>
<td class="center"><?php echo $rule->hit_count; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php else : ?>
<p><em>No rule-based statistics to display.</em></p>
<?php endif; ?>
<?php require_once('footer.php'); ?>