2012-12-28 22:53:05 +01:00
< ? php
function guest_stats () {
global $api_key ;
2016-08-22 19:11:09 +02:00
if ( isset ( $_REQUEST [ 'api_key' ])) {
if ( $_REQUEST [ 'api_key' ] == $api_key ) {
2016-09-30 17:08:20 +02:00
$stats = [];
2016-08-22 19:11:09 +02:00
2012-12-28 22:53:05 +01:00
list ( $user_count ) = sql_select ( " SELECT count(*) as `user_count` FROM `User` " );
$stats [ 'user_count' ] = $user_count [ 'user_count' ];
2016-08-22 19:11:09 +02:00
2012-12-28 22:53:05 +01:00
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' ];
2016-08-22 19:11:09 +02:00
2012-12-30 13:59:07 +01:00
$done_shifts_seconds = sql_select_single_cell ( " SELECT SUM(`Shifts`.`end` - `Shifts`.`start`) FROM `ShiftEntry` JOIN `Shifts` USING (`SID`) WHERE `Shifts`.`end` < UNIX_TIMESTAMP() " );
2016-08-22 19:11:09 +02:00
$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 );
2012-12-28 22:53:05 +01:00
header ( " Content-Type: application/json " );
2016-08-22 19:11:09 +02:00
raw_output ( json_encode ( $stats ));
return ;
}
raw_output ( json_encode ([
'error' => " Wrong api_key. "
]));
}
raw_output ( json_encode ([
'error' => " Missing parameter api_key. "
]));
2012-12-28 22:53:05 +01:00
}
2012-12-30 13:59:07 +01:00
?>