From d02272afd6725d46c37b7ba781c5d40268aa09a6 Mon Sep 17 00:00:00 2001 From: Philip Häusler Date: Fri, 19 Dec 2014 22:41:55 +0100 Subject: add basic shift view --- includes/view/Shifts_view.php | 89 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) (limited to 'includes/view/Shifts_view.php') diff --git a/includes/view/Shifts_view.php b/includes/view/Shifts_view.php index d0e7d809..47f83a9f 100644 --- a/includes/view/Shifts_view.php +++ b/includes/view/Shifts_view.php @@ -1,7 +1,94 @@ = $needed_angeltype['count']) + $class = 'progress-bar-success'; + $needed_angels .= '
'; + $needed_angels .= '
' . button(page_link_to('user_shifts') . '&shift_id=' . $shift['SID'] . '&type_id=' . $needed_angeltype['TID'], _('Sign up')) . '
'; + $needed_angels .= '

' . $angeltypes[$needed_angeltype['TID']]['name'] . '

'; + $needed_angels .= progress_bar(0, $needed_angeltype['count'], $needed_angeltype['taken'], $class, $needed_angeltype['taken'] . ' / ' . $needed_angeltype['count']); + + $angels = []; + foreach ($shift['ShiftEntry'] as $shift_entry) { + if ($shift_entry['TID'] == $needed_angeltype['TID']) { + $entry = User_Nick_render(User($shift_entry['UID'])); + if ($shift_entry['freeloaded']) + $entry = '' . $entry . ''; + if ($user_shift_admin) { + $entry .= '
'; + $entry .= button_glyph(page_link_to('user_myshifts') . '&edit=' . $shift['SID'] . '&id=' . $shift_entry['UID'], 'pencil', 'btn-xs'); + $entry .= button_glyph(page_link_to('user_shifts') . '&entry_id=' . $shift_entry['id'], 'trash', 'btn-xs'); + $entry .= '
'; + } + $angels[] = $entry; + } + } + + $needed_angels .= join(', ', $angels); + + $needed_angels .= '
'; + } + + return page_with_title($shift['name'] . ' %c', [ + msg(), + $shift_admin ? buttons([ + button(shift_edit_link($shift), glyph('pencil') . _('edit')), + button(shift_delete_link($shift), glyph('trash') . _('delete')) + ]) : '', + div('row', [ + div('col-sm-3', [ + '

' . _('Start') . '

', + '

', + date('y-m-d', $shift['start']), + '
', + date('H:i', $shift['start']), + '

' + ]), + div('col-sm-3', [ + '

' . _('End') . '

', + '

', + date('y-m-d', $shift['end']), + '
', + date('H:i', $shift['end']), + '

' + ]), + div('col-sm-3', [ + '

' . _('Location') . '

', + '

' . $room['Name'] . '

' + ]), + div('col-sm-3', [ + '

' . _('More info') . '

', + $shift['URL'] != '' ? '' . $shift['URL'] . '' : '' + ]) + ]), + div('row', [ + div('col-sm-6', [ + '

' . _('Needed angels') . '

', + '
' . $needed_angels . '
' + ]), + div('col-sm-6', [ + '

' . _('Description') . '

', + $parsedown->parse($shifttype['description']) + ]) + ]) + ]); +} + /** * Calc shift length in format 12:23h. - * @param Shift $shift + * + * @param Shift $shift */ function shift_length($shift) { $length = floor(($shift['end'] - $shift['start']) / (60 * 60)) . ":"; -- cgit v1.2.3-54-g00ecf From 038bf97178ec369f693ca1ca8445ab527abc919d Mon Sep 17 00:00:00 2001 From: Philip Häusler Date: Fri, 19 Dec 2014 22:59:18 +0100 Subject: link to next shift in menu --- includes/controller/shifts_controller.php | 23 +++++++++- includes/sys_menu.php | 2 +- includes/view/AngelTypes_view.php | 74 ++++++++++++++++++------------- includes/view/Shifts_view.php | 10 ++--- 4 files changed, 70 insertions(+), 39 deletions(-) (limited to 'includes/view/Shifts_view.php') diff --git a/includes/controller/shifts_controller.php b/includes/controller/shifts_controller.php index 58131d2e..041f21e2 100644 --- a/includes/controller/shifts_controller.php +++ b/includes/controller/shifts_controller.php @@ -16,7 +16,7 @@ function shift_controller() { global $user, $privileges; if (! in_array('user_shifts', $privileges)) - redirect(page_link_to('user_shifts')); + redirect(page_link_to('?')); if (! isset($_REQUEST['shift_id'])) redirect(page_link_to('user_shifts')); @@ -58,9 +58,30 @@ function shifts_controller() { redirect(page_link_to('?')); case 'view': return shift_controller(); + case 'next': + return shift_next_controller(); } } +/** + * Redirects the user to his next shift. + */ +function shift_next_controller() { + global $user, $privileges; + + if (! in_array('user_shifts', $privileges)) + redirect(page_link_to('?')); + + $upcoming_shifts = ShiftEntries_upcoming_for_user($user); + if ($upcoming_shifts === false) + return false; + + if (count($upcoming_shifts) > 0) + redirect(shift_link($upcoming_shifts[0])); + + redirect(page_link_to('user_shifts')); +} + /** * Export all shifts using api-key. */ diff --git a/includes/sys_menu.php b/includes/sys_menu.php index c5cded11..16577cbc 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(page_link_to('users') . '&action=view', 'time', User_shift_state_render($user)); + $toolbar_items[] = toolbar_item_link(page_link_to('shifts') . '&action=next', 'time', User_shift_state_render($user)); if (! isset($user) && in_array('register', $privileges)) $toolbar_items[] = toolbar_item_link(page_link_to('register'), 'plus', register_title(), $p == 'register'); diff --git a/includes/view/AngelTypes_view.php b/includes/view/AngelTypes_view.php index 7b3e162a..78563c0b 100644 --- a/includes/view/AngelTypes_view.php +++ b/includes/view/AngelTypes_view.php @@ -1,8 +1,18 @@ ' . ($angeltype['restricted'] ? glyph('lock') : '') . $angeltype['name'] . ''; +} + /** * Render angeltype membership state * @@ -35,15 +45,15 @@ function AngelType_delete_view($angeltype) { info(sprintf(_("Do you want to delete angeltype %s?"), $angeltype['name']), true), buttons(array( button(page_link_to('angeltypes'), _("cancel"), 'cancel'), - button(page_link_to('angeltypes') . '&action=delete&angeltype_id=' . $angeltype['id'] . '&confirmed', _("delete"), 'ok') - )) + button(page_link_to('angeltypes') . '&action=delete&angeltype_id=' . $angeltype['id'] . '&confirmed', _("delete"), 'ok') + )) )); } function AngelType_edit_view($name, $restricted, $description, $coordinator_mode) { return page_with_title(sprintf(_("Edit %s"), $name), array( buttons(array( - button(page_link_to('angeltypes'), _("Angeltypes"), 'back') + button(page_link_to('angeltypes'), _("Angeltypes"), 'back') )), msg(), form(array( @@ -52,16 +62,16 @@ function AngelType_edit_view($name, $restricted, $description, $coordinator_mode form_info("", _("Restricted angel types can only be used by an angel if enabled by an archangel (double opt-in).")), form_textarea('description', _("Description"), $description), form_info("", _("Please use markdown for the description.")), - form_submit('submit', _("Save")) - )) + form_submit('submit', _("Save")) + )) )); } function AngelType_view($angeltype, $members, $user_angeltype, $admin_user_angeltypes, $admin_angeltypes, $coordinator) { $buttons = array( - button(page_link_to('angeltypes'), _("Angeltypes"), 'back') + button(page_link_to('angeltypes'), _("Angeltypes"), 'back') ); - + if ($user_angeltype == null) $buttons[] = button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], _("join"), 'add'); else { @@ -69,24 +79,24 @@ function AngelType_view($angeltype, $members, $user_angeltype, $admin_user_angel error(sprintf(_("You are unconfirmed for this angeltype. Please go to the introduction for %s to get confirmed."), $angeltype['name'])); $buttons[] = button(page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $user_angeltype['id'], _("leave"), 'cancel'); } - + if ($admin_angeltypes || $coordinator) $buttons[] = button(page_link_to('angeltypes') . '&action=edit&angeltype_id=' . $angeltype['id'], _("edit"), 'edit'); if ($admin_angeltypes) $buttons[] = button(page_link_to('angeltypes') . '&action=delete&angeltype_id=' . $angeltype['id'], _("delete"), 'delete'); - + $page = array( msg(), - buttons($buttons) + buttons($buttons) ); - + $page[] = '

' . _("Description") . '

'; $parsedown = new Parsedown(); if ($angeltype['description'] != "") $page[] = '
' . $parsedown->parse($angeltype['description']) . '
'; - + // Team-Coordinators list missing - + $coordinators = array(); $members_confirmed = array(); $members_unconfirmed = array(); @@ -95,7 +105,7 @@ function AngelType_view($angeltype, $members, $user_angeltype, $admin_user_angel if ($angeltype['restricted'] && $member['confirm_user_id'] == null) { $member['actions'] = join(" ", array( '' . _("confirm") . '', - '' . _("deny") . '' + '' . _("deny") . '' )); $members_unconfirmed[] = $member; } elseif ($member['coordinator']) { @@ -108,7 +118,7 @@ function AngelType_view($angeltype, $members, $user_angeltype, $admin_user_angel if ($admin_user_angeltypes) $member['actions'] = join(" ", array( $admin_angeltypes ? '' . _("Add coordinator rights") . '' : '', - '' . _("remove") . '' + '' . _("remove") . '' )); $members_confirmed[] = $member; } @@ -118,74 +128,74 @@ function AngelType_view($angeltype, $members, $user_angeltype, $admin_user_angel $page[] = table(array( 'Nick' => _("Nick"), 'DECT' => _("DECT"), - 'actions' => "" + 'actions' => "" ), $coordinators); } $page[] = '

' . _("Members") . '

'; if ($admin_user_angeltypes) $page[] = buttons(array( - button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], _("Add"), 'add') + button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], _("Add"), 'add') )); $page[] = table(array( 'Nick' => _("Nick"), 'DECT' => _("DECT"), - 'actions' => "" + 'actions' => "" ), $members_confirmed); - + if ($admin_user_angeltypes && $angeltype['restricted'] && count($members_unconfirmed) > 0) { $page[] = '

' . _("Unconfirmed") . '

'; $page[] = buttons(array( button(page_link_to('user_angeltypes') . '&action=confirm_all&angeltype_id=' . $angeltype['id'], _("confirm all"), 'ok'), - button(page_link_to('user_angeltypes') . '&action=delete_all&angeltype_id=' . $angeltype['id'], _("deny all"), 'cancel') + button(page_link_to('user_angeltypes') . '&action=delete_all&angeltype_id=' . $angeltype['id'], _("deny all"), 'cancel') )); $page[] = table(array( 'Nick' => _("Nick"), 'DECT' => _("DECT"), - 'actions' => "" + 'actions' => "" ), $members_unconfirmed); } - + return page_with_title(sprintf(_("Team %s"), $angeltype['name']), $page); } /** * Display the list of angeltypes. * - * @param array $angeltypes + * @param array $angeltypes */ function AngelTypes_list_view($angeltypes, $admin_angeltypes) { return page_with_title(angeltypes_title(), array( msg(), buttons(array( $admin_angeltypes ? button(page_link_to('angeltypes') . '&action=edit', _("New angeltype"), 'add') : '', - button(page_link_to('angeltypes') . '&action=about', _("Teams/Job description")) + button(page_link_to('angeltypes') . '&action=about', _("Teams/Job description")) )), table(array( 'name' => _("Name"), 'restricted' => glyph('lock') . _("Restricted"), 'membership' => _("Membership"), - 'actions' => "" - ), $angeltypes) + 'actions' => "" + ), $angeltypes) )); } function AngelTypes_about_view($angeltypes, $user_logged_in) { global $faq_url; - + $content = array( buttons(array( ! $user_logged_in ? button(page_link_to('register'), register_title()) : '', ! $user_logged_in ? button(page_link_to('login'), login_title()) : '', $user_logged_in ? button(page_link_to('angeltypes'), angeltypes_title(), 'back') : '', - button($faq_url, _("FAQ"), "btn-primary") + button($faq_url, _("FAQ"), "btn-primary") )), '

' . _("Here is the list of teams and their tasks. If you have questions, read the FAQ.") . '

', - '
' + '
' ); $parsedown = new Parsedown(); foreach ($angeltypes as $angeltype) { $content[] = '

' . $angeltype['name'] . '

'; - + if (isset($angeltype['user_angeltype_id'])) { $buttons = array(); if ($angeltype['user_angeltype_id'] != null) @@ -194,14 +204,14 @@ function AngelTypes_about_view($angeltypes, $user_logged_in) { $buttons[] = button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], _("join"), 'add'); $content[] = buttons($buttons); } - + if ($angeltype['restricted']) $content[] = info(_("This angeltype is restricted by double-opt-in by a team coordinator. Please show up at the according introduction meetings."), true); if ($angeltype['description'] != "") $content[] = '
' . $parsedown->parse($angeltype['description']) . '
'; $content[] = '
'; } - + return page_with_title(_("Teams/Job description"), $content); } diff --git a/includes/view/Shifts_view.php b/includes/view/Shifts_view.php index 47f83a9f..c796b13e 100644 --- a/includes/view/Shifts_view.php +++ b/includes/view/Shifts_view.php @@ -16,7 +16,7 @@ function Shift_view($shift, $shifttype, $room, $shift_admin, $angeltypes_source, $class = 'progress-bar-success'; $needed_angels .= '
'; $needed_angels .= '
' . button(page_link_to('user_shifts') . '&shift_id=' . $shift['SID'] . '&type_id=' . $needed_angeltype['TID'], _('Sign up')) . '
'; - $needed_angels .= '

' . $angeltypes[$needed_angeltype['TID']]['name'] . '

'; + $needed_angels .= '

' . AngelType_name_render($angeltypes[$needed_angeltype['TID']]) . '

'; $needed_angels .= progress_bar(0, $needed_angeltype['count'], $needed_angeltype['taken'], $class, $needed_angeltype['taken'] . ' / ' . $needed_angeltype['count']); $angels = []; @@ -47,7 +47,7 @@ function Shift_view($shift, $shifttype, $room, $shift_admin, $angeltypes_source, button(shift_delete_link($shift), glyph('trash') . _('delete')) ]) : '', div('row', [ - div('col-sm-3', [ + div('col-sm-3 col-xs-6', [ '

' . _('Start') . '

', '

', date('y-m-d', $shift['start']), @@ -55,7 +55,7 @@ function Shift_view($shift, $shifttype, $room, $shift_admin, $angeltypes_source, date('H:i', $shift['start']), '

' ]), - div('col-sm-3', [ + div('col-sm-3 col-xs-6', [ '

' . _('End') . '

', '

', date('y-m-d', $shift['end']), @@ -63,11 +63,11 @@ function Shift_view($shift, $shifttype, $room, $shift_admin, $angeltypes_source, date('H:i', $shift['end']), '

' ]), - div('col-sm-3', [ + div('col-sm-3 col-xs-6', [ '

' . _('Location') . '

', '

' . $room['Name'] . '

' ]), - div('col-sm-3', [ + div('col-sm-3 col-xs-6', [ '

' . _('More info') . '

', $shift['URL'] != '' ? '' . $shift['URL'] . '' : '' ]) -- cgit v1.2.3-54-g00ecf From c12e5336fbe93c4596bd26c2bc4c9ee7390759fc Mon Sep 17 00:00:00 2001 From: Philip Häusler Date: Mon, 22 Dec 2014 18:06:58 +0100 Subject: display shifts with title --- includes/pages/user_shifts.php | 4 ++-- includes/view/Shifts_view.php | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'includes/view/Shifts_view.php') diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php index c8633cc5..70a674fb 100644 --- a/includes/pages/user_shifts.php +++ b/includes/pages/user_shifts.php @@ -551,9 +551,9 @@ function view_user_shifts() { $shifts_row .= " – "; $shifts_row .= date('H:i', $shift['end']); $shifts_row .= "
"; - $shifts_row .= '' . $shift['name'] . ''; + $shifts_row .= '' . ShiftType($shift['shifttype_id'])['name'] . ''; $shifts_row .= "
"; - $shifts_row .= '' . $shift['name'] . ''; + $shifts_row .= '' . $shift['title'] . ''; $shifts_row .= "
"; if (in_array('admin_shifts', $privileges)) $shifts_row .= ' ' . table_buttons(array( diff --git a/includes/view/Shifts_view.php b/includes/view/Shifts_view.php index c796b13e..91a553ec 100644 --- a/includes/view/Shifts_view.php +++ b/includes/view/Shifts_view.php @@ -47,6 +47,10 @@ function Shift_view($shift, $shifttype, $room, $shift_admin, $angeltypes_source, button(shift_delete_link($shift), glyph('trash') . _('delete')) ]) : '', div('row', [ + div('col-sm-3 col-xs-6', [ + '

' . _('Title') . '

', + '

' . ($shift['URL'] != '' ? '' . $shift['title'] . '' : $shift['title']) . '

' + ]), div('col-sm-3 col-xs-6', [ '

' . _('Start') . '

', '

', @@ -66,10 +70,6 @@ function Shift_view($shift, $shifttype, $room, $shift_admin, $angeltypes_source, div('col-sm-3 col-xs-6', [ '

' . _('Location') . '

', '

' . $room['Name'] . '

' - ]), - div('col-sm-3 col-xs-6', [ - '

' . _('More info') . '

', - $shift['URL'] != '' ? '' . $shift['URL'] . '' : '' ]) ]), div('row', [ -- cgit v1.2.3-54-g00ecf From 702047de5391b968137966077103cbb6d0a24dd8 Mon Sep 17 00:00:00 2001 From: Philip Häusler Date: Mon, 22 Dec 2014 18:22:54 +0100 Subject: add more icons for better shift view --- includes/controller/shifts_controller.php | 2 +- includes/pages/user_shifts.php | 7 +++++-- includes/view/Shifts_view.php | 20 +++++++++++--------- 3 files changed, 17 insertions(+), 12 deletions(-) (limited to 'includes/view/Shifts_view.php') diff --git a/includes/controller/shifts_controller.php b/includes/controller/shifts_controller.php index 041f21e2..126678a7 100644 --- a/includes/controller/shifts_controller.php +++ b/includes/controller/shifts_controller.php @@ -45,7 +45,7 @@ function shift_controller() { return [ $shift['name'], - Shift_view($shift, $shifttype, $room, in_array('admin_shifts', $privileges), $angeltypes, in_array('user_shifts_admin', $privileges)) + Shift_view($shift, $shifttype, $room, in_array('admin_shifts', $privileges), $angeltypes, in_array('user_shifts_admin', $privileges), in_array('admin_rooms', $privileges), in_array('shifttypes', $privileges)) ]; } diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php index 70a674fb..9ec79438 100644 --- a/includes/pages/user_shifts.php +++ b/includes/pages/user_shifts.php @@ -676,11 +676,14 @@ function view_user_shifts() { $info[] = date("Y-m-d", $shift['start']); $info[] = date("H:i", $shift['start']) . ' - ' . date("H:i", $shift['end']); if (count($_SESSION['user_shifts']['rooms']) > 1) - $info[] = $shift['room_name']; + $info[] = Room_name_render([ + 'Name' => $shift['room_name'], + 'RID' => $shift['RID'] + ]); $shift_row = array( 'info' => join('
', $info), - 'entries' => $shift['name'] + 'entries' => '' . $shift['name'] . '' . ($shift['title'] ? '
' . $shift['title'] : '') ); if (in_array('admin_shifts', $privileges)) diff --git a/includes/view/Shifts_view.php b/includes/view/Shifts_view.php index 91a553ec..594cb33c 100644 --- a/includes/view/Shifts_view.php +++ b/includes/view/Shifts_view.php @@ -1,6 +1,6 @@ %c', [ msg(), - $shift_admin ? buttons([ - button(shift_edit_link($shift), glyph('pencil') . _('edit')), - button(shift_delete_link($shift), glyph('trash') . _('delete')) + ($shift_admin || $admin_shifttypes || $admin_rooms) ? buttons([ + $shift_admin ? button(shift_edit_link($shift), glyph('pencil') . _('edit')) : '', + $shift_admin ? button(shift_delete_link($shift), glyph('trash') . _('delete')) : '', + $admin_shifttypes ? button(shifttype_link($shifttype), $shifttype['name']) : '', + $admin_rooms ? button(room_link($room), glyph('map-marker') . $room['Name']) : '' ]) : '', div('row', [ div('col-sm-3 col-xs-6', [ @@ -54,22 +56,22 @@ function Shift_view($shift, $shifttype, $room, $shift_admin, $angeltypes_source, div('col-sm-3 col-xs-6', [ '

' . _('Start') . '

', '

', - date('y-m-d', $shift['start']), + glyph('calendar') . date('y-m-d', $shift['start']), '
', - date('H:i', $shift['start']), + glyph('time') . date('H:i', $shift['start']), '

' ]), div('col-sm-3 col-xs-6', [ '

' . _('End') . '

', '

', - date('y-m-d', $shift['end']), + glyph('calendar') . date('y-m-d', $shift['end']), '
', - date('H:i', $shift['end']), + glyph('time') . date('H:i', $shift['end']), '

' ]), div('col-sm-3 col-xs-6', [ '

' . _('Location') . '

', - '

' . $room['Name'] . '

' + '

' . glyph('map-marker') . $room['Name'] . '

' ]) ]), div('row', [ -- cgit v1.2.3-54-g00ecf From 34e2f4987558a887ab3bc66b47306ec70cdfbd17 Mon Sep 17 00:00:00 2001 From: Philip Häusler Date: Thu, 25 Dec 2014 22:23:18 +0100 Subject: shift signup improvements for shift view --- includes/controller/shifts_controller.php | 13 +++++- includes/model/Shifts_model.php | 69 +++++++++++++++++++++++++++++++ includes/pages/user_shifts.php | 18 ++++---- includes/view/Shifts_view.php | 29 +++++++++++-- 4 files changed, 115 insertions(+), 14 deletions(-) (limited to 'includes/view/Shifts_view.php') diff --git a/includes/controller/shifts_controller.php b/includes/controller/shifts_controller.php index 126678a7..90753217 100644 --- a/includes/controller/shifts_controller.php +++ b/includes/controller/shifts_controller.php @@ -41,11 +41,20 @@ function shift_controller() { if ($angeltypes === false) engelsystem_error('Unable to load angeltypes.'); - User_angeltypes($user); + $user_shifts = Shifts_by_user($user); + if ($user_shifts === false) + engelsystem_error('Unable to load users shifts.'); + + $signed_up = false; + foreach ($user_shifts as $user_shift) + if ($user_shift['SID'] == $shift['SID']) { + $signed_up = true; + break; + } return [ $shift['name'], - Shift_view($shift, $shifttype, $room, in_array('admin_shifts', $privileges), $angeltypes, in_array('user_shifts_admin', $privileges), in_array('admin_rooms', $privileges), in_array('shifttypes', $privileges)) + Shift_view($shift, $shifttype, $room, in_array('admin_shifts', $privileges), $angeltypes, in_array('user_shifts_admin', $privileges), in_array('admin_rooms', $privileges), in_array('shifttypes', $privileges), $user_shifts, $signed_up) ]; } diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php index ee9c3773..37c772bf 100644 --- a/includes/model/Shifts_model.php +++ b/includes/model/Shifts_model.php @@ -1,5 +1,74 @@ $shifts + */ +function Shift_collides($shift, $shifts) { + foreach ($shifts as $other_shift) + if ($shift['SID'] != $other_shift['SID']) + if (! ($shift['start'] >= $other_shift['end'] || $shift['end'] <= $other_shift['start'])) + return true; + return false; +} + +/** + * Check if an angel can sign up for given shift. + * + * @param Shift $shift + * @param AngelType $angeltype + * @param array $user_shifts + */ +function Shift_signup_allowed($shift, $angeltype, $user_angeltype = null, $user_shifts = null) { + global $user, $privileges; + + if ($user_shifts == null) { + $user_shifts = Shifts_by_user($user); + if ($user_shifts === false) + engelsystem_error('Unable to load users shifts.'); + } + + $collides = Shift_collides($shift, $user_shifts); + + if ($user_angeltype == null) { + $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype); + if ($user_angeltype === false) + engelsystem_error('Unable to load user angeltype.'); + } + + $signed_up = false; + foreach ($user_shifts as $user_shift) + if ($user_shift['SID'] == $shift['SID']) { + $signed_up = true; + break; + } + + // is the shift still running or alternatively is the user shift admin? + $user_may_join_shift = true; + + // you cannot join if user alread joined a parallel or this shift + $user_may_join_shift &= ! $collides; + + // you cannot join if you already singed up for this shift + $user_may_join_shift &= ! $signed_up; + + // you cannot join if user is not of this angel type + $user_may_join_shift &= $user_angeltype != null; + + // you cannot join if you are not confirmed + if ($angeltype['restricted'] == 1 && $user_angeltype != null) + $user_may_join_shift &= isset($user_angeltype['confirm_user_id']); + + // you can only join if the shift is in future + $user_may_join_shift &= time() < $shift['start']; + + // User shift admins may join anybody in every shift + $user_may_join_shift |= in_array('user_shifts_admin', $privileges); + + return $user_may_join_shift; +} + /** * Delete a shift by its external id. */ diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php index a727bbcb..603ca993 100644 --- a/includes/pages/user_shifts.php +++ b/includes/pages/user_shifts.php @@ -9,8 +9,8 @@ function user_shifts() { if (User_is_freeloader($user)) redirect(page_link_to('user_myshifts')); - - // Locations laden + + // Locations laden $rooms = sql_select("SELECT * FROM `Room` WHERE `show`='Y' ORDER BY `Name`"); $room_array = array(); foreach ($rooms as $room) @@ -62,8 +62,8 @@ function user_shifts() { if (count($shift) == 0) redirect(page_link_to('user_shifts')); $shift = $shift[0]; - - // Engeltypen laden + + // Engeltypen laden $types = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`"); $angel_types = array(); $needed_angel_types = array(); @@ -543,14 +543,16 @@ function view_user_shifts() { // qqqqqq $is_free = false; - $shifts_row = date('d.m. H:i', $shift['start']); + $shifts_row = '' . date('d.m. H:i', $shift['start']); $shifts_row .= " – "; $shifts_row .= date('H:i', $shift['end']); $shifts_row .= "
"; - $shifts_row .= '
' . ShiftType($shift['shifttype_id'])['name'] . ''; + $shifts_row .= ShiftType($shift['shifttype_id'])['name']; $shifts_row .= "
"; - $shifts_row .= '' . $shift['title'] . ''; - $shifts_row .= "
"; + if ($shift['title'] != '') { + $shifts_row .= $shift['title']; + $shifts_row .= "
"; + } if (in_array('admin_shifts', $privileges)) $shifts_row .= ' ' . table_buttons(array( button(page_link_to('user_shifts') . '&edit_shift=' . $shift['SID'], glyph('edit'), 'btn-xs'), diff --git a/includes/view/Shifts_view.php b/includes/view/Shifts_view.php index 594cb33c..00c18572 100644 --- a/includes/view/Shifts_view.php +++ b/includes/view/Shifts_view.php @@ -1,6 +1,23 @@ = $needed_angeltype['count']) $class = 'progress-bar-success'; $needed_angels .= '
'; - $needed_angels .= '
' . button(page_link_to('user_shifts') . '&shift_id=' . $shift['SID'] . '&type_id=' . $needed_angeltype['TID'], _('Sign up')) . '
'; + + $needed_angels .= '
' . Shift_signup_button_render($shift, $angeltypes[$needed_angeltype['TID']]) . '
'; + $needed_angels .= '

' . AngelType_name_render($angeltypes[$needed_angeltype['TID']]) . '

'; $needed_angels .= progress_bar(0, $needed_angeltype['count'], $needed_angeltype['taken'], $class, $needed_angeltype['taken'] . ' / ' . $needed_angeltype['count']); @@ -42,6 +61,8 @@ function Shift_view($shift, $shifttype, $room, $shift_admin, $angeltypes_source, return page_with_title($shift['name'] . ' %c', [ msg(), + Shift_collides($shift, $user_shifts) ? info(_('This shift collides with one of your shifts.'), true) : '', + $signed_up ? info(_('You are signed up for this shift.'), true) : '', ($shift_admin || $admin_shifttypes || $admin_rooms) ? buttons([ $shift_admin ? button(shift_edit_link($shift), glyph('pencil') . _('edit')) : '', $shift_admin ? button(shift_delete_link($shift), glyph('trash') . _('delete')) : '', @@ -55,7 +76,7 @@ function Shift_view($shift, $shifttype, $room, $shift_admin, $angeltypes_source, ]), div('col-sm-3 col-xs-6', [ '

' . _('Start') . '

', - '

', + '

', glyph('calendar') . date('y-m-d', $shift['start']), '
', glyph('time') . date('H:i', $shift['start']), @@ -63,7 +84,7 @@ function Shift_view($shift, $shifttype, $room, $shift_admin, $angeltypes_source, ]), div('col-sm-3 col-xs-6', [ '

' . _('End') . '

', - '

', + '

', glyph('calendar') . date('y-m-d', $shift['end']), '
', glyph('time') . date('H:i', $shift['end']), -- cgit v1.2.3-54-g00ecf