2012-12-28 22:53:05 +01:00
|
|
|
<?php
|
|
|
|
|
2017-01-21 13:58:53 +01:00
|
|
|
use Engelsystem\Database\DB;
|
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
function guest_stats()
|
|
|
|
{
|
|
|
|
global $api_key;
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-02 03:57:23 +01:00
|
|
|
if (isset($_REQUEST['api_key'])) {
|
|
|
|
if ($_REQUEST['api_key'] == $api_key) {
|
|
|
|
$stats = [];
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-21 13:58:53 +01:00
|
|
|
list($user_count) = DB::select('SELECT count(*) AS `user_count` FROM `User`');
|
2017-01-02 03:57:23 +01:00
|
|
|
$stats['user_count'] = $user_count['user_count'];
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-21 13:58:53 +01:00
|
|
|
list($arrived_user_count) = DB::select('SELECT count(*) AS `user_count` FROM `User` WHERE `Gekommen`=1');
|
2017-01-02 03:57:23 +01:00
|
|
|
$stats['arrived_user_count'] = $arrived_user_count['user_count'];
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-21 13:58:53 +01:00
|
|
|
$done_shifts_seconds = DB::select('
|
2017-01-03 14:12:17 +01:00
|
|
|
SELECT SUM(`Shifts`.`end` - `Shifts`.`start`)
|
|
|
|
FROM `ShiftEntry`
|
|
|
|
JOIN `Shifts` USING (`SID`)
|
|
|
|
WHERE `Shifts`.`end` < UNIX_TIMESTAMP()
|
|
|
|
');
|
2017-01-21 13:58:53 +01:00
|
|
|
$done_shifts_seconds = array_shift($done_shifts_seconds);
|
|
|
|
$done_shifts_seconds = (int)array_shift($done_shifts_seconds);
|
2017-01-02 03:57:23 +01:00
|
|
|
$stats['done_work_hours'] = round($done_shifts_seconds / (60 * 60), 0);
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-21 13:58:53 +01:00
|
|
|
$users_in_action = DB::select('
|
2017-01-03 14:12:17 +01:00
|
|
|
SELECT `Shifts`.`start`, `Shifts`.`end`
|
|
|
|
FROM `ShiftEntry`
|
|
|
|
JOIN `Shifts` ON `Shifts`.`SID`=`ShiftEntry`.`SID`
|
|
|
|
WHERE UNIX_TIMESTAMP() BETWEEN `Shifts`.`start` AND `Shifts`.`end`
|
|
|
|
');
|
2017-01-02 03:57:23 +01:00
|
|
|
$stats['users_in_action'] = count($users_in_action);
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2017-01-03 14:12:17 +01:00
|
|
|
header('Content-Type: application/json');
|
2017-01-02 03:57:23 +01:00
|
|
|
raw_output(json_encode($stats));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
raw_output(json_encode([
|
2017-01-03 14:12:17 +01:00
|
|
|
'error' => 'Wrong api_key.'
|
2017-01-02 15:43:36 +01:00
|
|
|
]));
|
2016-08-22 19:11:09 +02:00
|
|
|
}
|
|
|
|
raw_output(json_encode([
|
2017-01-03 14:12:17 +01:00
|
|
|
'error' => 'Missing parameter api_key.'
|
2017-01-02 15:43:36 +01:00
|
|
|
]));
|
2012-12-28 22:53:05 +01:00
|
|
|
}
|