diff --git a/includes/sys_menu.php b/includes/sys_menu.php index 790ca3b2..56b25a78 100644 --- a/includes/sys_menu.php +++ b/includes/sys_menu.php @@ -19,7 +19,7 @@ function header_toolbar() { $toolbar_items = array(); if (isset($user)) - $toolbar_items[] = toolbar_item_link('#', 'time', User_shift_state_render(User_shift_state($user))); + $toolbar_items[] = toolbar_item_link('#', 'time', User_shift_state_render($user)); $toolbar_items[] = make_langselect(); diff --git a/includes/view/User_view.php b/includes/view/User_view.php index e5405835..734e266e 100644 --- a/includes/view/User_view.php +++ b/includes/view/User_view.php @@ -20,14 +20,25 @@ $tshirt_sizes = array( ); function User_shift_state_render($user) { - if ($shift_mode == 0) + $upcoming_shifts = ShiftEntries_upcoming_for_user($user); + if ($upcoming_shifts === false) + return false; + + if (count($upcoming_shifts) == 0) return '' . _("Free") . ''; - if ($shift_mode > 8 * 3600) - return '' . _("Next shift in") . ''; - if ($shift_mode > 0) - return '' . _("Next shift in") . ''; - if ($shift_mode < 0) - return '' . _("Current shift ends in") . ''; + + if ($upcoming_shifts[0]['start'] > time()) + if ($upcoming_shifts[0]['start'] - time() > 3600) + return '' . _("Next shift in %c") . ''; + else + return '' . _("Next shift in %c") . ''; + + $halfway = ($upcoming_shifts[0]['start'] + $upcoming_shifts[0]['end']) / 2; + + if (time() < $halfway) + return '' . _("Shift startet %c ago") . ''; + else + return '' . _("Shift ends in %c") . ''; } function User_view($user_source, $admin_user_privilege, $freeloader, $user_angeltypes, $user_groups, $shifts, $its_me) {