Skip to content

Commit

Permalink
Added stats page
Browse files Browse the repository at this point in the history
  • Loading branch information
vjosset committed Nov 26, 2022
1 parent 3bb46e6 commit ddd8711
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 2 deletions.
2 changes: 1 addition & 1 deletion classes/weapon.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function loadWeaponProfiles() {
$params[] =& $this->opid;
$params[] =& $this->wepid;

// Load the operative
// Load the profiles
call_user_func_array(array($cmd, "bind_param"), $params);
$cmd->execute();

Expand Down
122 changes: 122 additions & 0 deletions stats.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?php
if ($_SERVER['REQUEST_METHOD'] != "GET") {
header('HTTP/1.0 400 Invalid Request');
die();
}

$root = $_SERVER['DOCUMENT_ROOT'];
require_once $root . '/include.php';
global $dbcon;
$me = Session::CurrentUser();
if ($me == null || $me->userid != 'vince') {
// They shouldn't be here
header('HTTP/1.0 403 Not Authorized');
header("Location: https://ktdash.app/rosters.php");
die();
}
?>
<!DOCTYPE html>
<html>
<head>
<?php
include "header.shtml";
$pagetitle = "Stats";
$pagedesc = "Stats";
$pageimg = "";
$pageurl = "https://ktdash.app/stats.php";
include "og.php";
?>
</head>
<body ng-app="kt" ng-controller="ktCtrl">
<?php
include "topnav.shtml";
?>

<div class="orange container-fluid">
<div class="row">
<h1 class="col-6 m-0 p-1">
<a class="navloader" onclick="window.location.reload();">Stats</a>
</h1>
<h1 class="col-6 m-0 p-1 text-end h2">
<!-- Activity -->
<?php
$sql = "SELECT COUNT(DISTINCT userid, userip) AS UserCount30Minute, COUNT(*) AS EventCount30Minute FROM Event WHERE userip != '68.80.166.102' AND datestamp > DATE_ADD(CURRENT_TIMESTAMP, INTERVAL -30 minute);";
$cmd = $dbcon->prepare($sql);

// Load the stats
$cmd->execute();

if ($result = $cmd->get_result()) {
while ($row = $result->fetch_object()) {
// Got a result
?>
<i class="fas fa-users"></i> <?php echo $row->UserCount30Minute ?>
<i class="fas fa-bolt"></i> <?php echo $row->EventCount30Minute ?>
<?php
}
}
?>
</h1>
</div>
</div>

<div class="p-2">
<div style="columns: 2;">
<!-- Signups -->
<div>
<h2>Signups</h2>
<?php
$sql = "SELECT CAST(datestamp AS Date) AS Date, COUNT(*) AS SignupCount FROM Event WHERE datestamp > DATE_ADD(CURRENT_DATE, INTERVAL -6 day) AND eventtype = 'session' AND action = 'signup' AND userip != '68.80.166.102' GROUP BY CAST(datestamp AS Date) ORDER BY 1 DESC";
$cmd = $dbcon->prepare($sql);

// Load the stats
$cmd->execute();

echo "<table style=\"width: 100%;\">";

if ($result = $cmd->get_result()) {
while ($row = $result->fetch_object()) {
// Got a result
?>
<tr><th><?php echo $row->Date ?></th><td style="text-align: right;">&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $row->SignupCount ?></td></tr>
<?php
}
}

echo "</table>";
?>
</div>

<!-- Totals -->
<div>
<h2>Totals</h2>
<?php
$sql =
"SELECT 'Users' AS CountType, COUNT(*) AS Count FROM User WHERE userid NOT IN ('prebuilt', 'vince') UNION
SELECT 'Rosters', COUNT(*) AS RosterCount FROM Roster WHERE userid NOT IN ('prebuilt', 'vince') UNION
SELECT 'RosterOps', COUNT(*) AS RosterOpCount FROM RosterOperative WHERE userid NOT IN ('prebuilt', 'vince')";
$cmd = $dbcon->prepare($sql);

// Load the stats
$cmd->execute();

echo "<table style=\"width: 100%;\">";

if ($result = $cmd->get_result()) {
while ($row = $result->fetch_object()) {
// Got a result
?>
<tr><th><?php echo $row->CountType ?></th><td style="text-align: right;">&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $row->Count ?></td></tr>
<?php
}
}

echo "</table>";
?>
</div>
</div>
</div>

<?php include "footer.shtml" ?>
</body>
</html>
3 changes: 2 additions & 1 deletion topnav.shtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
</button>

<div class="navbar-collapse collapse" id="navbarNav" data-toggle="collapse" data-target="#navbarNav">
<ul class="navbar-nav ms-auto">
<ul class="navbar-nav ms-auto ng-cloak">
<li class="nav-item"><a class="nav-link navloader" href="/compendium.php"><span class="fas fa-book-dead fa-fw"></span>&nbsp;Compendium</a></li>
<li class="nav-item" ng-show="currentuser == null"><a class="nav-link navloader" href="/signup.htm"><span class="fas fa-user fa-fw"></span>&nbsp;Sign Up</a></li>
<li class="nav-item" ng-show="currentuser == null"><a class="nav-link navloader" href="/login.htm"><span class="fas fa-lock fa-fw"></span>&nbsp;Log In</a></li>
<li class="nav-item" ng-show="currentuser != null"><a class="nav-link navloader" href="/dashboard.php"><span class="fas fa-dice fa-fw"></span>&nbsp;Dashboard</a></li>
<li class="nav-item" ng-show="currentuser != null"><a class="nav-link navloader" href="/rosters.php?uid={{currentuser.userid}}"><span class="fas fa-users fa-fw"></span>&nbsp;My Rosters</a></li>
<li class="nav-item" ng-show="currentuser != null"><a class="nav-link navloader" href="/settings.php"><span class="fas fa-cogs fa-fw"></span>&nbsp;Settings</a></li>
<li class="nav-item" ng-show="currentuser.userid == 'vince'"><a class="nav-link navloader" href="/stats.php"><span class="fas fa-chart-line fa-fw"></span>&nbsp;Stats</a></li>
<li class="nav-item" ng-show="currentuser != null"><a class="nav-link navloader" href="#" ng-click="logOut();"><span class="fas fa-lock fa-fw"></span>&nbsp;Log Out</a></li>
</ul>
</div>
Expand Down

0 comments on commit ddd8711

Please sign in to comment.