diff options
author | msquare <msquare@notrademark.de> | 2016-08-22 19:11:09 +0200 |
---|---|---|
committer | msquare <msquare@notrademark.de> | 2016-08-22 19:11:09 +0200 |
commit | 54e6f422ceb9b621b8cd405265e7ce3743c5fa15 (patch) | |
tree | 80ece67e23d50306ce8e9b9778f4b2f6d8f412c6 /includes | |
parent | 79588ff2cf68500072285d14f048fadf89eaebf7 (diff) |
cleanup guest stats
Diffstat (limited to 'includes')
-rw-r--r-- | includes/pages/guest_stats.php | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/includes/pages/guest_stats.php b/includes/pages/guest_stats.php index da5a6301..aec2d7d4 100644 --- a/includes/pages/guest_stats.php +++ b/includes/pages/guest_stats.php @@ -2,29 +2,34 @@ function guest_stats() { global $api_key; - - if(isset($_REQUEST['api_key'])) { - if($_REQUEST['api_key'] == $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_seconds = sql_select_single_cell("SELECT SUM(`Shifts`.`end` - `Shifts`.`start`) FROM `ShiftEntry` JOIN `Shifts` USING (`SID`) WHERE `Shifts`.`end` < UNIX_TIMESTAMP()"); - $stats['done_work_hours'] = round($done_shifts_seconds / (60*60), 0); - - $users_in_action_source = sql_select("SELECT `Shifts`.`start`, `Shifts`.`end` FROM `ShiftEntry` JOIN `Shifts` ON `Shifts`.`SID`=`ShiftEntry`.`SID` WHERE UNIX_TIMESTAMP() BETWEEN `Shifts`.`start` AND `Shifts`.`end`"); - $stats['users_in_action'] = count($users_in_action_source); - + $stats['done_work_hours'] = round($done_shifts_seconds / (60 * 60), 0); + + $users_in_action = sql_select("SELECT `Shifts`.`start`, `Shifts`.`end` FROM `ShiftEntry` JOIN `Shifts` ON `Shifts`.`SID`=`ShiftEntry`.`SID` WHERE UNIX_TIMESTAMP() BETWEEN `Shifts`.`start` AND `Shifts`.`end`"); + $stats['users_in_action'] = count($users_in_action); + 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."))); - + raw_output(json_encode($stats)); + return; + } + raw_output(json_encode([ + 'error' => "Wrong api_key." + ])); + } + raw_output(json_encode([ + 'error' => "Missing parameter api_key." + ])); } - ?> |