stats for infobeamer/monitor

This commit is contained in:
Philip Häusler 2012-12-28 22:53:05 +01:00
parent 7044c07c00
commit 263edf58f2
3 changed files with 39 additions and 1 deletions

View File

@ -0,0 +1,30 @@
<?php
function guest_stats() {
global $api_key;
if(isset($_REQUEST['api_key'])) {
if($_REQUEST['api_key'] == $api_key) {
$stats = array();
list($user_count) = sql_select("SELECT count(*) as `user_count` FROM `User`");
$stats['user_count'] = $user_count['user_count'];
list($arrived_user_count) = sql_select("SELECT count(*) as `user_count` FROM `User` WHERE `Gekommen`=1");
$stats['arrived_user_count'] = $arrived_user_count['user_count'];
$done_shifts_source = sql_select("SELECT `Shifts`.`start`, `Shifts`.`end` FROM `ShiftEntry` JOIN `Shifts` ON `Shifts`.`SID`=`ShiftEntry`.`SID` WHERE `Shifts`.`end` < " . time());
$done_shifts_seconds = 0;
foreach($done_shifts_source as $done_shift)
$done_shifts_seconds += $done_shift['end'] - $done_shift['start'];
$stats['done_work_hours'] = round($done_shifts_seconds / (60*60), 0);
header("Content-Type: application/json");
die(json_encode($stats));
} else die(json_encode(array('error' => "Wrong api_key.")));
} else die(json_encode(array('error' => "Missing parameter api_key.")));
}
?>

View File

@ -68,4 +68,8 @@ $shift_sum_formula = "SUM(
// weigh every shift the same // weigh every shift the same
//$shift_sum_formula = "SUM(`end` - `start`)"; //$shift_sum_formula = "SUM(`end` - `start`)";
// For accessing stats
$api_key = "";
?> ?>

View File

@ -33,7 +33,7 @@ if (isset ($_REQUEST['auth']))
// Gewünschte Seite/Funktion // Gewünschte Seite/Funktion
$p = isset ($user) ? "news" : "login"; $p = isset ($user) ? "news" : "login";
if (isset ($_REQUEST['p']) && preg_match("/^[a-z0-9_]*$/i", $_REQUEST['p']) && sql_num_query("SELECT * FROM `Privileges` WHERE `name`='" . sql_escape($_REQUEST['p']) . "' LIMIT 1") > 0) if (isset ($_REQUEST['p']) && preg_match("/^[a-z0-9_]*$/i", $_REQUEST['p']) && ($_REQUEST['p'] == 'stats' || (sql_num_query("SELECT * FROM `Privileges` WHERE `name`='" . sql_escape($_REQUEST['p']) . "' LIMIT 1") > 0)))
$p = $_REQUEST['p']; $p = $_REQUEST['p'];
$title = Get_Text($p); $title = Get_Text($p);
@ -47,6 +47,10 @@ elseif ($p == "atom") {
require_once ('includes/pages/user_atom.php'); require_once ('includes/pages/user_atom.php');
user_atom(); user_atom();
} }
elseif ($p == "stats") {
require_once ('includes/pages/guest_stats.php');
guest_stats();
}
// Recht dafür vorhanden? // Recht dafür vorhanden?
elseif (in_array($p, $privileges)) { elseif (in_array($p, $privileges)) {
if ($p == "news") { if ($p == "news") {