Skip to content

Commit

Permalink
Adding percent complete to admin view.
Browse files Browse the repository at this point in the history
  • Loading branch information
darthmolly committed Oct 10, 2011
1 parent a3c2088 commit 3366fd1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
14 changes: 14 additions & 0 deletions inc/utils.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,18 @@ function sendAdminConfirmation($user) {
mail($to, $subject, $body, $headers, $extra);
}

function percentageComplete($users) {
$total = count($users);
if ($total == 0) {
return "";
}
$complete = 0;
foreach($users as $user) {
if ($user->complete()) {
$complete ++;
}
}
return round($complete / $total * 100);
}

?>
3 changes: 3 additions & 0 deletions partials/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ h3 {
.excel {
padding-bottom:20px;
}
.percent {
padding-bottom:20px;
}
1 change: 0 additions & 1 deletion partials/users.inc.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<table border="1" cellspacing="0" cellpadding="3">
<tr><th>Computing ID</th><th>Last Name</th><th>First Name</th><th>Completion date</th></tr>
<?php
$users = getUsers();

foreach($users as $user) {

Expand Down
12 changes: 11 additions & 1 deletion users.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php
include_once("inc/configs.inc.php");
include_once("inc/db.inc.php");
include_once("inc/utils.inc.php");
$user = getUser($_SERVER['PHP_AUTH_USER']);
$users = getUsers();
isset($_GET["excel"]) ? $doAsExcel = true : $doAsExcel = false;

if ($doAsExcel) {
Expand All @@ -13,7 +15,15 @@
print "<div class=\"excel\"><a href=\"" . $_SERVER['PHP_SELF'] . "?excel=true\">View in Excel</a></div>";
}

$user->isAdministrator() ? include("partials/users.inc.php") : die("You are not an authorized administrator");
if (!$user->isAdministrator()) {
die("You are not an authorized administrator");
}

if (!$doAsExcel) {
print "<div class=\"percent\">Percent complete: " . percentageComplete($users) . "%</div>";
}

include("partials/users.inc.php");

if (!$doAsExcel) {
include("partials/footer.inc.php");
Expand Down

0 comments on commit 3366fd1

Please sign in to comment.