rewrite controller for creating shift entries
This commit is contained in:
parent
afd7c59d1d
commit
1289101f6e
|
@ -1,247 +1,283 @@
|
|||
<?php
|
||||
use Engelsystem\ShiftSignupState;
|
||||
|
||||
use Engelsystem\Database\DB;
|
||||
/**
|
||||
* Route shift entry actions.
|
||||
*/
|
||||
function shift_entries_controller()
|
||||
{
|
||||
global $user;
|
||||
|
||||
$action = strip_request_item('action');
|
||||
if ($action == null) {
|
||||
redirect(user_link($user));
|
||||
}
|
||||
|
||||
switch ($action) {
|
||||
case 'create':
|
||||
return shift_entry_create_controller();
|
||||
case 'edit':
|
||||
return shift_entry_edit_controller();
|
||||
case 'delete':
|
||||
return shift_entry_delete_controller();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sign up for a shift.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function shift_entry_add_controller()
|
||||
function shift_entry_create_controller()
|
||||
{
|
||||
global $privileges, $user;
|
||||
|
||||
$request = request();
|
||||
$shift_id = 0;
|
||||
if ($request->has('shift_id') && preg_match('/^\d+$/', $request->input('shift_id'))) {
|
||||
$shift_id = $request->input('shift_id');
|
||||
} else {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
|
||||
if (User_is_freeloader($user)) {
|
||||
redirect(page_link_to('user_myshifts'));
|
||||
}
|
||||
|
||||
// Locations laden
|
||||
$rooms = Rooms();
|
||||
$room_array = [];
|
||||
foreach ($rooms as $room) {
|
||||
$room_array[$room['RID']] = $room['Name'];
|
||||
}
|
||||
|
||||
$shift = Shift($shift_id);
|
||||
$shift = Shift($request->input('shift_id'));
|
||||
if ($shift == null) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
$shift['Name'] = $room_array[$shift['RID']];
|
||||
|
||||
$type_id = null;
|
||||
if ($request->has('type_id') && preg_match('/^\d+$/', $request->input('type_id'))) {
|
||||
$type_id = $request->input('type_id');
|
||||
redirect(user_link($user));
|
||||
}
|
||||
|
||||
if (in_array('user_shifts_admin', $privileges) || in_array('shiftentry_edit_angeltype_supporter', $privileges)) {
|
||||
if($type_id == null) {
|
||||
// If no angeltype id is given, then select first existing angeltype.
|
||||
$needed_angeltypes = NeededAngelTypes_by_shift($shift_id);
|
||||
if(count($needed_angeltypes) > 0) {
|
||||
$type_id = $needed_angeltypes[0]['id'];
|
||||
}
|
||||
}
|
||||
$type = AngelType($type_id);
|
||||
} else {
|
||||
// TODO: Move queries to model
|
||||
$type = DB::selectOne('
|
||||
SELECT *
|
||||
FROM `UserAngelTypes`
|
||||
JOIN `AngelTypes` ON (`UserAngelTypes`.`angeltype_id` = `AngelTypes`.`id`)
|
||||
WHERE `AngelTypes`.`id` = ?
|
||||
AND (
|
||||
`AngelTypes`.`restricted` = 0
|
||||
OR (
|
||||
`UserAngelTypes`.`user_id` = ?
|
||||
AND NOT `UserAngelTypes`.`confirm_user_id` IS NULL
|
||||
)
|
||||
)
|
||||
', [$type_id, $user['UID']]);
|
||||
$angeltype = AngelType($request->input('angeltype_id'));
|
||||
|
||||
if (in_array('user_shifts_admin', $privileges)) {
|
||||
return shift_entry_create_controller_admin($shift, $angeltype);
|
||||
}
|
||||
|
||||
if (empty($type)) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
if ($angeltype == null) {
|
||||
redirect(user_link($user));
|
||||
}
|
||||
|
||||
if (
|
||||
$request->has('user_id')
|
||||
&& preg_match('/^\d+$/', $request->input('user_id'))
|
||||
&& (
|
||||
in_array('user_shifts_admin', $privileges)
|
||||
|| in_array('shiftentry_edit_angeltype_supporter', $privileges)
|
||||
)
|
||||
) {
|
||||
$user_id = $request->input('user_id');
|
||||
} else {
|
||||
$user_id = $user['UID'];
|
||||
if (User_is_AngelType_supporter($user, $angeltype)) {
|
||||
return shift_entry_create_controller_supporter($shift, $angeltype);
|
||||
}
|
||||
|
||||
$needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $type);
|
||||
$shift_entries = ShiftEntries_by_shift_and_angeltype($shift['SID'], $type['id']);
|
||||
return shift_entry_create_controller_user($shift, $angeltype);
|
||||
}
|
||||
|
||||
$shift_signup_allowed = Shift_signup_allowed(
|
||||
User($user_id),
|
||||
$shift,
|
||||
$type,
|
||||
null,
|
||||
null,
|
||||
$needed_angeltype,
|
||||
$shift_entries
|
||||
);
|
||||
if (!$shift_signup_allowed->isSignupAllowed()) {
|
||||
error(_('You are not allowed to sign up for this shift. Maybe shift is full or already running.'));
|
||||
/**
|
||||
* Sign up for a shift.
|
||||
* Case: Admin
|
||||
*
|
||||
* @param array $shift
|
||||
* @param array $angeltype
|
||||
*/
|
||||
function shift_entry_create_controller_admin($shift, $angeltype)
|
||||
{
|
||||
global $user;
|
||||
$request = request();
|
||||
|
||||
$signup_user = $user;
|
||||
if ($request->has('user_id')) {
|
||||
$signup_user = User($request->input('user_id'));
|
||||
}
|
||||
if($signup_user == null) {
|
||||
redirect(shift_link($shift));
|
||||
}
|
||||
|
||||
$angeltypes = AngelTypes();
|
||||
if($request->has('angeltype_id')) {
|
||||
$angeltype = AngelType($request->input('angeltype_id'));
|
||||
}
|
||||
if($angeltype == null) {
|
||||
if(count($angeltypes) == 0) {
|
||||
redirect(shift_link($shift));
|
||||
}
|
||||
$angeltype = $angeltypes[0];
|
||||
}
|
||||
|
||||
if ($request->has('submit')) {
|
||||
ShiftEntry_create([
|
||||
'SID' => $shift['SID'],
|
||||
'TID' => $angeltype['id'],
|
||||
'UID' => $signup_user['UID'],
|
||||
'Comment' => '',
|
||||
'freeloaded' => false,
|
||||
'freeload_comment' => ''
|
||||
]);
|
||||
|
||||
success(sprintf(_('%s has been subscribed to the shift.'), User_Nick_render($signup_user)));
|
||||
redirect(shift_link($shift));
|
||||
}
|
||||
|
||||
$users = Users();
|
||||
$users_select = [];
|
||||
foreach ($users as $u) {
|
||||
$users_select[$u['UID']] = $u['Nick'];
|
||||
}
|
||||
|
||||
$angeltypes_select = [];
|
||||
foreach($angeltypes as $a) {
|
||||
$angeltypes_select[$a['id']] = $a['name'];
|
||||
}
|
||||
|
||||
$room = Room($shift['RID']);
|
||||
return [
|
||||
ShiftEntry_create_title(),
|
||||
ShiftEntry_create_view_admin($shift, $room, $angeltype, $angeltypes_select, $signup_user, $users_select)
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sign up for a shift.
|
||||
* Case: Supporter
|
||||
*
|
||||
* @param array $shift
|
||||
* @param array $angeltype
|
||||
*/
|
||||
function shift_entry_create_controller_supporter($shift, $angeltype)
|
||||
{
|
||||
global $user;
|
||||
$request = request();
|
||||
|
||||
$signup_user = $user;
|
||||
if ($request->has('user_id')) {
|
||||
$signup_user = User($request->input('user_id'));
|
||||
}
|
||||
if (! UserAngelType_exists($signup_user, $angeltype)) {
|
||||
error(_('User is not in angeltype.'));
|
||||
redirect(shift_link($shift));
|
||||
}
|
||||
|
||||
$needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype);
|
||||
$shift_entries = ShiftEntries_by_shift_and_angeltype($shift['SID'], $angeltype['id']);
|
||||
$shift_signup_state = Shift_signup_allowed($signup_user, $shift, $angeltype, null, null, $needed_angeltype, $shift_entries);
|
||||
if (! $shift_signup_state->isSignupAllowed()) {
|
||||
if ($shift_signup_state->getState() == ShiftSignupState::OCCUPIED) {
|
||||
error(_('This shift is already occupied.'));
|
||||
}
|
||||
redirect(shift_link($shift));
|
||||
}
|
||||
|
||||
if ($request->has('submit')) {
|
||||
$selected_type_id = $type_id;
|
||||
if (in_array('user_shifts_admin', $privileges) || in_array('shiftentry_edit_angeltype_supporter',
|
||||
$privileges)
|
||||
) {
|
||||
|
||||
if (count(DB::select('SELECT `UID` FROM `User` WHERE `UID`=? LIMIT 1', [$user_id])) == 0) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
|
||||
if (
|
||||
$request->has('angeltype_id')
|
||||
&& test_request_int('angeltype_id')
|
||||
&& count(DB::select(
|
||||
'SELECT `id` FROM `AngelTypes` WHERE `id`=? LIMIT 1',
|
||||
[$request->input('angeltype_id')]
|
||||
)) > 0
|
||||
) {
|
||||
$selected_type_id = $request->input('angeltype_id');
|
||||
}
|
||||
}
|
||||
|
||||
if (count(DB::select(
|
||||
'SELECT `id` FROM `ShiftEntry` WHERE `SID`= ? AND `UID` = ?',
|
||||
[$shift['SID'], $user_id]))
|
||||
) {
|
||||
return error(_('This angel does already have an entry for this shift.'), true);
|
||||
}
|
||||
|
||||
$freeloaded = isset($shift['freeloaded']) ? $shift['freeloaded'] : false;
|
||||
$freeload_comment = isset($shift['freeload_comment']) ? $shift['freeload_comment'] : '';
|
||||
if (in_array('user_shifts_admin', $privileges)) {
|
||||
$freeloaded = $request->has('freeloaded');
|
||||
$freeload_comment = strip_request_item_nl('freeload_comment');
|
||||
}
|
||||
|
||||
$comment = strip_request_item_nl('comment');
|
||||
ShiftEntry_create([
|
||||
'SID' => $shift_id,
|
||||
'TID' => $selected_type_id,
|
||||
'UID' => $user_id,
|
||||
'Comment' => $comment,
|
||||
'freeloaded' => $freeloaded,
|
||||
'freeload_comment' => $freeload_comment
|
||||
'SID' => $shift['SID'],
|
||||
'TID' => $angeltype['id'],
|
||||
'UID' => $signup_user['UID'],
|
||||
'Comment' => '',
|
||||
'freeloaded' => false,
|
||||
'freeload_comment' => ''
|
||||
]);
|
||||
|
||||
if (
|
||||
$type['restricted'] == 0
|
||||
&& count(DB::select('
|
||||
SELECT `UserAngelTypes`.`id` FROM `UserAngelTypes`
|
||||
INNER JOIN `AngelTypes` ON `AngelTypes`.`id` = `UserAngelTypes`.`angeltype_id`
|
||||
WHERE `angeltype_id` = ?
|
||||
AND `user_id` = ?
|
||||
', [$selected_type_id, $user_id])) == 0
|
||||
) {
|
||||
DB::insert(
|
||||
'INSERT INTO `UserAngelTypes` (`user_id`, `angeltype_id`) VALUES (?, ?)',
|
||||
[$user_id, $selected_type_id]
|
||||
);
|
||||
}
|
||||
|
||||
$user_source = User($user_id);
|
||||
engelsystem_log(
|
||||
'User ' . User_Nick_render($user_source)
|
||||
. ' signed up for shift ' . $shift['name']
|
||||
. ' from ' . date('Y-m-d H:i', $shift['start'])
|
||||
. ' to ' . date('Y-m-d H:i', $shift['end'])
|
||||
);
|
||||
success(_('You are subscribed. Thank you!') . ' <a href="' . page_link_to('user_myshifts') . '">' . _('My shifts') . ' »</a>');
|
||||
success(sprintf(_('%s has been subscribed to the shift.'), User_Nick_render($signup_user)));
|
||||
redirect(shift_link($shift));
|
||||
}
|
||||
|
||||
$angeltype_select = '';
|
||||
if (in_array('user_shifts_admin', $privileges)) {
|
||||
$users = DB::select('
|
||||
SELECT *,
|
||||
(
|
||||
SELECT count(*)
|
||||
FROM `ShiftEntry`
|
||||
WHERE `freeloaded`=1
|
||||
AND `ShiftEntry`.`UID`=`User`.`UID`
|
||||
) AS `freeloaded`
|
||||
FROM `User`
|
||||
ORDER BY `Nick`
|
||||
');
|
||||
$users = Users_by_angeltype($angeltype);
|
||||
$users_select = [];
|
||||
foreach ($users as $usr) {
|
||||
$users_select[$usr['UID']] = $usr['Nick'] . ($usr['freeloaded'] == 0 ? '' : ' (' . _('Freeloader') . ')');
|
||||
}
|
||||
$user_text = html_select_key('user_id', 'user_id', $users_select, $user['UID']);
|
||||
|
||||
$angeltypes_source = DB::select('SELECT `id`, `name` FROM `AngelTypes` ORDER BY `name`');
|
||||
$angeltypes = [];
|
||||
foreach ($angeltypes_source as $angeltype) {
|
||||
$angeltypes[$angeltype['id']] = $angeltype['name'];
|
||||
}
|
||||
$angeltype_select = html_select_key('angeltype_id', 'angeltype_id', $angeltypes, $type['id']);
|
||||
} elseif (in_array('shiftentry_edit_angeltype_supporter', $privileges) && User_is_AngelType_supporter($user, $type)) {
|
||||
$users = Users_by_angeltype($type);
|
||||
$users_select = [];
|
||||
foreach ($users as $usr) {
|
||||
if (!$type['restricted'] || $usr['confirm_user_id'] != null) {
|
||||
$users_select[$usr['UID']] = $usr['Nick'];
|
||||
}
|
||||
}
|
||||
$user_text = html_select_key('user_id', 'user_id', $users_select, $user['UID']);
|
||||
|
||||
$angeltypes_source = User_angeltypes($user);
|
||||
$angeltypes = [];
|
||||
foreach ($angeltypes_source as $angeltype) {
|
||||
if ($angeltype['supporter']) {
|
||||
$angeltypes[$angeltype['id']] = $angeltype['name'];
|
||||
}
|
||||
$angeltype_select = html_select_key('angeltype_id', 'angeltype_id', $angeltypes, $type['id']);
|
||||
}
|
||||
} else {
|
||||
$user_text = User_Nick_render($user);
|
||||
$angeltype_select = $type['name'];
|
||||
foreach ($users as $u) {
|
||||
$users_select[$u['UID']] = $u['Nick'];
|
||||
}
|
||||
|
||||
return ShiftEntry_edit_view(
|
||||
$user_text,
|
||||
date('Y-m-d H:i', $shift['start'])
|
||||
. ' – '
|
||||
. date('Y-m-d H:i', $shift['end'])
|
||||
. ' (' . shift_length($shift) . ')',
|
||||
$shift['Name'],
|
||||
$shift['name'],
|
||||
$angeltype_select, '',
|
||||
false,
|
||||
null,
|
||||
in_array('user_shifts_admin', $privileges)
|
||||
);
|
||||
$room = Room($shift['RID']);
|
||||
return [
|
||||
ShiftEntry_create_title(),
|
||||
ShiftEntry_create_view_supporter($shift, $room, $angeltype, $signup_user, $users_select)
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a shift entry from get parameter entry_id.
|
||||
* Sign up for a shift.
|
||||
* Case: User
|
||||
*
|
||||
* @param array $shift
|
||||
* @param array $angeltype
|
||||
*/
|
||||
function shift_entry_load() {
|
||||
function shift_entry_create_controller_user($shift, $angeltype)
|
||||
{
|
||||
global $user;
|
||||
$request = request();
|
||||
|
||||
if (!$request->has('entry_id') || !test_request_int('entry_id')) {
|
||||
$signup_user = $user;
|
||||
$needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype);
|
||||
$shift_entries = ShiftEntries_by_shift_and_angeltype($shift['SID'], $angeltype['id']);
|
||||
|
||||
$shift_signup_state = Shift_signup_allowed($signup_user, $shift, $angeltype, null, null, $needed_angeltype, $shift_entries);
|
||||
|
||||
if (! $shift_signup_state->isSignupAllowed()) {
|
||||
if ($shift_signup_state->getState() == ShiftSignupState::ANGELTYPE) {
|
||||
error(_('You need be accepted member of the angeltype.'));
|
||||
} elseif ($shift_signup_state->getState() == ShiftSignupState::COLLIDES) {
|
||||
error(_('This shift collides with one of your shifts.'));
|
||||
} elseif ($shift_signup_state->getState() == ShiftSignupState::OCCUPIED) {
|
||||
error(_('This shift is already occupied.'));
|
||||
} elseif ($shift_signup_state->getState() == ShiftSignupState::SHIFT_ENDED) {
|
||||
error(_('This shift ended already.'));
|
||||
} elseif ($shift_signup_state->getState() == ShiftSignupState::SIGNED_UP) {
|
||||
error(_('You are signed up for this shift.'));
|
||||
}
|
||||
redirect(shift_link($shift));
|
||||
}
|
||||
|
||||
$comment = '';
|
||||
if ($request->has('submit')) {
|
||||
$comment = strip_request_item_nl('comment');
|
||||
ShiftEntry_create([
|
||||
'SID' => $shift['SID'],
|
||||
'TID' => $angeltype['id'],
|
||||
'UID' => $signup_user['UID'],
|
||||
'Comment' => $comment,
|
||||
'freeloaded' => false,
|
||||
'freeload_comment' => ''
|
||||
]);
|
||||
|
||||
if ($angeltype['restricted'] == false && ! UserAngelType_exists($signup_user, $angeltype)) {
|
||||
UserAngelType_create($signup_user, $angeltype);
|
||||
}
|
||||
|
||||
success(_('You are subscribed. Thank you!'));
|
||||
redirect(shift_link($shift));
|
||||
}
|
||||
|
||||
$room = Room($shift['RID']);
|
||||
return [
|
||||
ShiftEntry_create_title(),
|
||||
ShiftEntry_create_view_user($shift, $room, $angeltype, $comment)
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Link to create a shift entry.
|
||||
*
|
||||
* @return string URL
|
||||
*/
|
||||
function shift_entry_create_link($shift, $angeltype, $params = [])
|
||||
{
|
||||
$params = array_merge([
|
||||
'action' => 'create',
|
||||
'shift_id' => $shift['SID'],
|
||||
'angeltype_id' => $angeltype['id']
|
||||
], $params);
|
||||
return page_link_to('shift_entries', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Link to create a shift entry as admin.
|
||||
*
|
||||
* @return string URL
|
||||
*/
|
||||
function shift_entry_create_link_admin($shift, $params = [])
|
||||
{
|
||||
$params = array_merge([
|
||||
'action' => 'create',
|
||||
'shift_id' => $shift['SID']
|
||||
], $params);
|
||||
return page_link_to('shift_entries', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a shift entry from get parameter shift_entry_id.
|
||||
*/
|
||||
function shift_entry_load()
|
||||
{
|
||||
$request = request();
|
||||
|
||||
if (! $request->has('shift_entry_id') || ! test_request_int('shift_entry_id')) {
|
||||
redirect(page_link_to('user_shifts'));
|
||||
}
|
||||
$shiftEntry = ShiftEntry($request->input('entry_id'));
|
||||
$shiftEntry = ShiftEntry($request->input('shift_entry_id'));
|
||||
if ($shiftEntry == null) {
|
||||
error(_('Shift entry not found.'));
|
||||
redirect(page_link_to('user_shifts'));
|
||||
|
@ -274,8 +310,30 @@ function shift_entry_delete_controller()
|
|||
}
|
||||
|
||||
if ($user['UID'] == $signout_user['UID']) {
|
||||
return ShiftEntry_delete_view($shiftEntry, $shift, $angeltype, $signout_user);
|
||||
return [
|
||||
ShiftEntry_delete_title(),
|
||||
ShiftEntry_delete_view($shiftEntry, $shift, $angeltype, $signout_user)
|
||||
];
|
||||
}
|
||||
|
||||
return ShiftEntry_delete_view_admin($shiftEntry, $shift, $angeltype, $signout_user);
|
||||
return [
|
||||
ShiftEntry_delete_title(),
|
||||
ShiftEntry_delete_view_admin($shiftEntry, $shift, $angeltype, $signout_user)
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Link to delete a shift entry.
|
||||
*
|
||||
* @param array $shiftEntry
|
||||
*
|
||||
* @return string URL
|
||||
*/
|
||||
function shift_entry_delete_link($shiftEntry, $params = [])
|
||||
{
|
||||
$params = array_merge([
|
||||
'action' => 'delete',
|
||||
'shift_entry_id' => $shiftEntry['id']
|
||||
], $params);
|
||||
return page_link_to('shift_entries', $params);
|
||||
}
|
||||
|
|
|
@ -74,8 +74,10 @@ function ShiftEntries_by_shift($shift_id)
|
|||
*/
|
||||
function ShiftEntry_create($shift_entry)
|
||||
{
|
||||
mail_shift_assign(User($shift_entry['UID']), Shift($shift_entry['SID']));
|
||||
return DB::insert('
|
||||
$user = User($shift_entry['UID']);
|
||||
$shift = Shift($shift_entry['SID']);
|
||||
mail_shift_assign($user, $shift);
|
||||
$result = DB::insert('
|
||||
INSERT INTO `ShiftEntry` (
|
||||
`SID`,
|
||||
`TID`,
|
||||
|
@ -95,6 +97,13 @@ function ShiftEntry_create($shift_entry)
|
|||
(int)$shift_entry['freeloaded'],
|
||||
]
|
||||
);
|
||||
engelsystem_log(
|
||||
'User ' . User_Nick_render($user)
|
||||
. ' signed up for shift ' . $shift['name']
|
||||
. ' from ' . date('Y-m-d H:i', $shift['start'])
|
||||
. ' to ' . date('Y-m-d H:i', $shift['end'])
|
||||
);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -29,15 +29,10 @@ function user_shifts()
|
|||
redirect(page_link_to('user_myshifts'));
|
||||
}
|
||||
|
||||
// Löschen einzelner Schicht-Einträge (Also Belegung einer Schicht von Engeln) durch Admins
|
||||
if ($request->has('entry_id')) {
|
||||
return shift_entry_delete_controller();
|
||||
} elseif ($request->has('edit_shift')) {
|
||||
if ($request->has('edit_shift')) {
|
||||
return shift_edit_controller();
|
||||
} elseif ($request->has('delete_shift')) {
|
||||
return shift_delete_controller();
|
||||
} elseif ($request->has('shift_id')) {
|
||||
return shift_entry_add_controller();
|
||||
}
|
||||
return view_user_shifts();
|
||||
}
|
||||
|
|
|
@ -208,7 +208,7 @@ function form_info($label, $text = '')
|
|||
function form_submit($name, $label)
|
||||
{
|
||||
return form_element(
|
||||
'<input class="btn btn-primary" type="submit" name="' . $name . '" value="' . $label . '" />',
|
||||
'<button class="btn btn-primary" type="submit" name="' . $name . '">' . $label . '</button>',
|
||||
''
|
||||
);
|
||||
}
|
||||
|
|
|
@ -125,8 +125,7 @@ class ShiftCalendarShiftRenderer
|
|||
|
||||
if (in_array('user_shifts_admin', $privileges)) {
|
||||
$html .= '<li class="list-group-item">';
|
||||
$html .= button(
|
||||
page_link_to('user_shifts', ['shift_id' => $shift['SID']]),
|
||||
$html .= button(shift_entry_create_link_admin($shift),
|
||||
glyph('plus') . _('Add more angels'),
|
||||
'btn-xs'
|
||||
);
|
||||
|
@ -172,12 +171,12 @@ class ShiftCalendarShiftRenderer
|
|||
case ShiftSignupState::FREE:
|
||||
// When admin or free display a link + button for sign up
|
||||
$entry_list[] = '<a href="'
|
||||
. page_link_to('user_shifts', ['shift_id' => $shift['SID'], 'type_id' => $angeltype['id']])
|
||||
. shift_entry_create_link($shift, $angeltype)
|
||||
. '">'
|
||||
. $inner_text
|
||||
. '</a> '
|
||||
. button(
|
||||
page_link_to('user_shifts', ['shift_id' => $shift['SID'], 'type_id' => $angeltype['id']]),
|
||||
shift_entry_create_link($shift, $angeltype),
|
||||
_('Sign up'), 'btn-xs btn-primary'
|
||||
);
|
||||
break;
|
||||
|
|
|
@ -10,19 +10,15 @@
|
|||
*
|
||||
* @return string HTML
|
||||
*/
|
||||
function ShiftEntry_delete_view_admin($shiftEntry, $shift, $angeltype, $signoff_user) {
|
||||
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),
|
||||
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), glyph('remove') . _('cancel')),
|
||||
button(ShiftEntry_delete_link($shiftEntry, ['continue' => 1]), glyph('ok') . _('delete'), 'btn-danger')
|
||||
button(shift_entry_delete_link($shiftEntry, [
|
||||
'continue' => 1
|
||||
]), glyph('ok') . _('delete'), 'btn-danger')
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
@ -37,38 +33,97 @@ function ShiftEntry_delete_view_admin($shiftEntry, $shift, $angeltype, $signoff_
|
|||
*
|
||||
* @return string HTML
|
||||
*/
|
||||
function ShiftEntry_delete_view($shiftEntry, $shift, $angeltype, $signoff_user) {
|
||||
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),
|
||||
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), glyph('remove') . _('cancel')),
|
||||
button(ShiftEntry_delete_link($shiftEntry, ['continue' => 1]), glyph('ok') . _('delete'), 'btn-danger')
|
||||
button(shift_entry_delete_link($shiftEntry, [
|
||||
'continue' => 1
|
||||
]), glyph('ok') . _('delete'), 'btn-danger')
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Link to delete a shift entry.
|
||||
* @param array $shiftEntry
|
||||
*
|
||||
* @return string URL
|
||||
* Title for deleting a shift entry.
|
||||
*/
|
||||
function ShiftEntry_delete_link($shiftEntry, $params = []) {
|
||||
$params = array_merge(['entry_id' => $shiftEntry['id']], $params);
|
||||
return page_link_to('user_shifts', $params);
|
||||
function ShiftEntry_delete_title()
|
||||
{
|
||||
return _('Shift sign off');
|
||||
}
|
||||
|
||||
/**
|
||||
* Title for deleting a shift entry.
|
||||
* 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
|
||||
*/
|
||||
function ShiftEntry_delete_title() {
|
||||
return _('Shift sign off');
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -85,17 +140,8 @@ function ShiftEntry_delete_title() {
|
|||
* @param bool $user_admin_shifts
|
||||
* @return string
|
||||
*/
|
||||
function ShiftEntry_edit_view(
|
||||
$angel,
|
||||
$date,
|
||||
$location,
|
||||
$title,
|
||||
$type,
|
||||
$comment,
|
||||
$freeloaded,
|
||||
$freeload_comment,
|
||||
$user_admin_shifts = false
|
||||
) {
|
||||
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 = [
|
||||
|
|
|
@ -2,6 +2,43 @@
|
|||
|
||||
use Engelsystem\ShiftSignupState;
|
||||
|
||||
/**
|
||||
* Renders the basic shift view header.
|
||||
*
|
||||
* @param array $shift
|
||||
* @param array $room
|
||||
*
|
||||
* @return string HTML
|
||||
*/
|
||||
function Shift_view_header($shift, $room) {
|
||||
return div('row', [
|
||||
div('col-sm-3 col-xs-6', [
|
||||
'<h4>' . _('Title') . '</h4>',
|
||||
'<p class="lead">' . ($shift['URL'] != '' ? '<a href="' . $shift['URL'] . '">' . $shift['title'] . '</a>' : $shift['title']) . '</p>'
|
||||
]),
|
||||
div('col-sm-3 col-xs-6', [
|
||||
'<h4>' . _('Start') . '</h4>',
|
||||
'<p class="lead' . (time() >= $shift['start'] ? ' text-success' : '') . '">',
|
||||
glyph('calendar') . date(_('Y-m-d'), $shift['start']),
|
||||
'<br />',
|
||||
glyph('time') . date('H:i', $shift['start']),
|
||||
'</p>'
|
||||
]),
|
||||
div('col-sm-3 col-xs-6', [
|
||||
'<h4>' . _('End') . '</h4>',
|
||||
'<p class="lead' . (time() >= $shift['end'] ? ' text-success' : '') . '">',
|
||||
glyph('calendar') . date(_('Y-m-d'), $shift['end']),
|
||||
'<br />',
|
||||
glyph('time') . date('H:i', $shift['end']),
|
||||
'</p>'
|
||||
]),
|
||||
div('col-sm-3 col-xs-6', [
|
||||
'<h4>' . _('Location') . '</h4>',
|
||||
'<p class="lead">' . Room_name_render($room) . '</p>'
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $shift
|
||||
* @return string
|
||||
|
@ -41,10 +78,7 @@ function Shift_signup_button_render($shift, $angeltype, $user_angeltype = null)
|
|||
}
|
||||
|
||||
if ($angeltype['shift_signup_state']->isSignupAllowed()) {
|
||||
return button(
|
||||
page_link_to('user_shifts', ['shift_id' => $shift['SID'], 'type_id' => $angeltype['id']]),
|
||||
_('Sign up')
|
||||
);
|
||||
return button(shift_entry_create_link($shift, $angeltype), _('Sign up'));
|
||||
} elseif ($user_angeltype == null) {
|
||||
return button(
|
||||
page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']]),
|
||||
|
@ -100,32 +134,7 @@ function Shift_view($shift, $shifttype, $room, $angeltypes_source, ShiftSignupSt
|
|||
$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', [
|
||||
'<h4>' . _('Title') . '</h4>',
|
||||
'<p class="lead">' . ($shift['URL'] != '' ? '<a href="' . $shift['URL'] . '">' . $shift['title'] . '</a>' : $shift['title']) . '</p>'
|
||||
]),
|
||||
div('col-sm-3 col-xs-6', [
|
||||
'<h4>' . _('Start') . '</h4>',
|
||||
'<p class="lead' . (time() >= $shift['start'] ? ' text-success' : '') . '">',
|
||||
glyph('calendar') . date(_('Y-m-d'), $shift['start']),
|
||||
'<br />',
|
||||
glyph('time') . date('H:i', $shift['start']),
|
||||
'</p>'
|
||||
]),
|
||||
div('col-sm-3 col-xs-6', [
|
||||
'<h4>' . _('End') . '</h4>',
|
||||
'<p class="lead' . (time() >= $shift['end'] ? ' text-success' : '') . '">',
|
||||
glyph('calendar') . date(_('Y-m-d'), $shift['end']),
|
||||
'<br />',
|
||||
glyph('time') . date('H:i', $shift['end']),
|
||||
'</p>'
|
||||
]),
|
||||
div('col-sm-3 col-xs-6', [
|
||||
'<h4>' . _('Location') . '</h4>',
|
||||
'<p class="lead">' . Room_name_render($room) . '</p>'
|
||||
])
|
||||
]),
|
||||
Shift_view_header($shift, $room),
|
||||
div('row', [
|
||||
div('col-sm-6', [
|
||||
'<h2>' . _('Needed angels') . '</h2>',
|
||||
|
@ -213,7 +222,7 @@ function Shift_view_render_shift_entry($shift_entry, $user_shift_admin, $angelty
|
|||
'btn-xs'
|
||||
);
|
||||
}
|
||||
$entry .= button_glyph(page_link_to('user_shifts', ['entry_id' => $shift_entry['id']]), 'trash', 'btn-xs');
|
||||
$entry .= button_glyph(shift_entry_delete_link($shift_entry), 'trash', 'btn-xs');
|
||||
$entry .= '</div>';
|
||||
}
|
||||
return $entry;
|
||||
|
|
|
@ -365,7 +365,7 @@ function User_view_myshift($shift, $user_source, $its_me)
|
|||
}
|
||||
if (Shift_signout_allowed($shift, ['id' => $shift['TID']], $user_source)) {
|
||||
$myshift['actions'][] = button(
|
||||
ShiftEntry_delete_link($shift),
|
||||
shift_entry_delete_link($shift),
|
||||
glyph('trash') . _('sign off'),
|
||||
'btn-xs'
|
||||
);
|
||||
|
|
|
@ -14,6 +14,7 @@ $free_pages = [
|
|||
'login',
|
||||
'public_dashboard',
|
||||
'rooms',
|
||||
'shift_entries',
|
||||
'shifts',
|
||||
'shifts_json_export',
|
||||
'shifts_json_export_all',
|
||||
|
@ -84,6 +85,9 @@ if (
|
|||
case 'angeltypes':
|
||||
list($title, $content) = angeltypes_controller();
|
||||
break;
|
||||
case 'shift_entries':
|
||||
list($title, $content) = shift_entries_controller();
|
||||
break;
|
||||
case 'shifts':
|
||||
list($title, $content) = shifts_controller();
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue