diff --git a/includes/pages/guest_stats.php b/includes/pages/guest_stats.php index 80df246b..da5a6301 100644 --- a/includes/pages/guest_stats.php +++ b/includes/pages/guest_stats.php @@ -13,13 +13,10 @@ function guest_stats() { 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']; + $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 `Shifts`.`start` < " . time() . " AND `Shifts`.`end` > " . time()); + $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); header("Content-Type: application/json"); @@ -30,4 +27,4 @@ function guest_stats() { } -?> \ No newline at end of file +?>