summaryrefslogtreecommitdiff
path: root/includes/view/ShiftEntry_view.php
blob: 1d6ba3a33af165e35fd00e783c42b334e66f78f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<?php

/**
 * Sign off from an user from a shift with admin permissions, asking for ack.
 *
 * @param array $shiftEntry
 * @param array $shift
 * @param array $angeltype
 * @param array $signoff_user
 *
 * @return string HTML
 */
function ShiftEntry_delete_view_admin($shiftEntry, $shift, $angeltype, $signoff_user)
{
    return page_with_title(ShiftEntry_delete_title(), [
        info(sprintf(
            __('Do you want to sign off %s from shift %s from %s to %s as %s?'),
            User_Nick_render($signoff_user),
            $shift['name'],
            date('Y-m-d H:i', $shift['start']),
            date('Y-m-d H:i', $shift['end']),
            $angeltype['name']
        ), true),
        buttons([
            button(user_link($signoff_user['UID']), glyph('remove') . __('cancel')),
            button(shift_entry_delete_link($shiftEntry, [
                'continue' => 1
            ]), glyph('ok') . __('delete'), 'btn-danger')
        ])
    ]);
}

/**
 * Sign off from a shift, asking for ack.
 *
 * @param array $shiftEntry
 * @param array $shift
 * @param array $angeltype
 * @param array $signoff_user
 *
 * @return string HTML
 */
function ShiftEntry_delete_view($shiftEntry, $shift, $angeltype, $signoff_user)
{
    return page_with_title(ShiftEntry_delete_title(), [
        info(sprintf(
            __('Do you want to sign off from your shift %s from %s to %s as %s?'),
            $shift['name'],
            date('Y-m-d H:i', $shift['start']),
            date('Y-m-d H:i', $shift['end']),
            $angeltype['name']
        ), true),
        buttons([
            button(user_link($signoff_user['UID']), glyph('remove') . __('cancel')),
            button(shift_entry_delete_link($shiftEntry, [
                'continue' => 1
            ]), glyph('ok') . __('delete'), 'btn-danger')
        ])
    ]);
}

/**
 * Title for deleting a shift entry.
 */
function ShiftEntry_delete_title()
{
    return __('Shift sign off');
}

/**
 * Admin puts user into shift.
 *
 * @param array $shift
 * @param array $room
 * @param array $angeltype
 * @param array $angeltypes_select
 * @param array $signup_user
 * @param array $users_select
 * @return string
 */
function ShiftEntry_create_view_admin($shift, $room, $angeltype, $angeltypes_select, $signup_user, $users_select)
{
    return page_with_title(
        ShiftEntry_create_title() . ': ' . $shift['name']
        . ' <small class="moment-countdown" data-timestamp="' . $shift['start'] . '">%c</small>',
        [
            Shift_view_header($shift, $room),
            info(__('Do you want to sign up the following user for this shift?'), true),
            form([
                form_select('angeltype_id', __('Angeltype'), $angeltypes_select, $angeltype['id']),
                form_select('user_id', __('User'), $users_select, $signup_user['UID']),
                form_submit('submit', glyph('ok') . __('Save'))
            ])
        ]);
}

/**
 * Supporter puts user into shift.
 *
 * @param array $shift
 * @param array $room
 * @param array $angeltype
 * @param array $signup_user
 * @param array $users_select
 * @return string
 */
function ShiftEntry_create_view_supporter($shift, $room, $angeltype, $signup_user, $users_select)
{
    return page_with_title(ShiftEntry_create_title() . ': ' . $shift['name']
        . ' <small class="moment-countdown" data-timestamp="' . $shift['start'] . '">%c</small>',
        [
            Shift_view_header($shift, $room),
            info(sprintf(__('Do you want to sign up the following user for this shift as %s?'),
                AngelType_name_render($angeltype)), true),
            form([
                form_select('user_id', __('User'), $users_select, $signup_user['UID']),
                form_submit('submit', glyph('ok') . __('Save'))
            ])
        ]);
}

/**
 * User joining a shift.
 *
 * @param array  $shift
 * @param array  $room
 * @param array  $angeltype
 * @param string $comment
 * @return string
 */
function ShiftEntry_create_view_user($shift, $room, $angeltype, $comment)
{
    return page_with_title(ShiftEntry_create_title() . ': ' . $shift['name']
        . ' <small class="moment-countdown" data-timestamp="' . $shift['start'] . '">%c</small>',
        [
            Shift_view_header($shift, $room),
            info(sprintf(__('Do you want to sign up for this shift as %s?'), AngelType_name_render($angeltype)), true),
            form([
                form_textarea('comment', __('Comment (for your eyes only):'), $comment),
                form_submit('submit', glyph('ok') . __('Save'))
            ])
        ]);
}

/**
 * Title for creating a shift entry.
 */
function ShiftEntry_create_title()
{
    return __('Shift signup');
}

/**
 * Display form for adding/editing a shift entry.
 *
 * @param string $angel
 * @param string $date
 * @param string $location
 * @param string $title
 * @param string $type
 * @param string $comment
 * @param bool   $freeloaded
 * @param string $freeload_comment
 * @param bool   $user_admin_shifts
 * @return string
 */
function ShiftEntry_edit_view(
    $angel,
    $date,
    $location,
    $title,
    $type,
    $comment,
    $freeloaded,
    $freeload_comment,
    $user_admin_shifts = false
) {
    $freeload_form = [];
    if ($user_admin_shifts) {
        $freeload_form = [
            form_checkbox('freeloaded', __('Freeloaded'), $freeloaded),
            form_textarea(
                'freeload_comment',
                __('Freeload comment (Only for shift coordination):'),
                $freeload_comment
            )
        ];
    }
    return page_with_title(__('Edit shift entry'), [
        msg(),
        form([
            form_info(__('Angel:'), $angel),
            form_info(__('Date, Duration:'), $date),
            form_info(__('Location:'), $location),
            form_info(__('Title:'), $title),
            form_info(__('Type:'), $type),
            form_textarea('comment', __('Comment (for your eyes only):'), $comment),
            join('', $freeload_form),
            form_submit('submit', __('Save'))
        ])
    ]);
}