summaryrefslogtreecommitdiff
path: root/includes/controller
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2017-12-19 20:58:01 +0100
committermsquare <msquare@notrademark.de>2017-12-19 20:58:01 +0100
commitfd85034e7f2277730f4ea4de49dade6d125832dd (patch)
tree54017bb754302b578838479d8f4d68f4a92010dd /includes/controller
parent567ed9ebd2603a5deb9c171b4d969f7188414794 (diff)
redo shift signoff and icons for delete/confirm/acknowledgment questions
Diffstat (limited to 'includes/controller')
-rw-r--r--includes/controller/angeltypes_controller.php6
-rw-r--r--includes/controller/shift_entries_controller.php79
-rw-r--r--includes/controller/user_angeltypes_controller.php8
3 files changed, 40 insertions, 53 deletions
diff --git a/includes/controller/angeltypes_controller.php b/includes/controller/angeltypes_controller.php
index a47c1340..621b5cbd 100644
--- a/includes/controller/angeltypes_controller.php
+++ b/includes/controller/angeltypes_controller.php
@@ -40,11 +40,13 @@ function angeltypes_controller()
* Path to angeltype view.
*
* @param int $angeltype_id AngelType id
+ * @param array $params additional params
* @return string
*/
-function angeltype_link($angeltype_id)
+function angeltype_link($angeltype_id, $params = [])
{
- return page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype_id]);
+ $params = array_merge(['action' => 'view', 'angeltype_id' => $angeltype_id], $params);
+ return page_link_to('angeltypes', $params);
}
/**
diff --git a/includes/controller/shift_entries_controller.php b/includes/controller/shift_entries_controller.php
index c28a3e9c..0b37be6c 100644
--- a/includes/controller/shift_entries_controller.php
+++ b/includes/controller/shift_entries_controller.php
@@ -233,58 +233,49 @@ function shift_entry_add_controller()
}
/**
- * Remove somebody from a shift.
+ * Load a shift entry from get parameter entry_id.
*/
-function shift_entry_delete_controller()
-{
- global $privileges, $user;
+function shift_entry_load() {
$request = request();
if (!$request->has('entry_id') || !test_request_int('entry_id')) {
redirect(page_link_to('user_shifts'));
}
- $entry_id = $request->input('entry_id');
-
- $shift_entry_source = DB::selectOne('
- SELECT
- `User`.`Nick`,
- `User`.`Gekommen`,
- `ShiftEntry`.`Comment`,
- `ShiftEntry`.`UID`,
- `ShiftTypes`.`name`,
- `Shifts`.*,
- `Room`.`Name`,
- `AngelTypes`.`name` AS `angel_type`,
- `AngelTypes`.`id` AS `angeltype_id`
- FROM `ShiftEntry`
- JOIN `User` ON (`User`.`UID`=`ShiftEntry`.`UID`)
- JOIN `AngelTypes` ON (`ShiftEntry`.`TID` = `AngelTypes`.`id`)
- JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID`)
- JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`)
- JOIN `Room` ON (`Shifts`.`RID` = `Room`.`RID`)
- WHERE `ShiftEntry`.`id`=?',
- [$entry_id]
- );
- if (!empty($shift_entry_source)) {
- if (!in_array('user_shifts_admin', $privileges) && (!in_array('shiftentry_edit_angeltype_supporter',
- $privileges) || !User_is_AngelType_supporter($user, AngelType($shift_entry_source['angeltype_id'])))
- ) {
- redirect(page_link_to('user_shifts'));
- }
+ $shiftEntry = ShiftEntry($request->input('entry_id'));
+ if($shiftEntry == null) {
+ error(_('Shift entry not found.'));
+ redirect(page_link_to('user_shifts'));
+ }
+
+ return $shiftEntry;
+}
- ShiftEntry_delete($entry_id);
+/**
+ * Remove somebody from a shift.
+ */
+function shift_entry_delete_controller()
+{
+ global $privileges, $user;
+ $request = request();
+ $shiftEntry = shift_entry_load();
- engelsystem_log(
- 'Deleted ' . User_Nick_render($shift_entry_source) . '\'s shift: ' . $shift_entry_source['name']
- . ' at ' . $shift_entry_source['Name']
- . ' from ' . date('Y-m-d H:i', $shift_entry_source['start'])
- . ' to ' . date('Y-m-d H:i', $shift_entry_source['end'])
- . ' as ' . $shift_entry_source['angel_type']
- );
- success(_('Shift entry deleted.'));
- } else {
- error(_('Entry not found.'));
+ $shift = Shift($shiftEntry['SID']);
+ $angeltype = AngelType($shiftEntry['TID']);
+ $signout_user = User($shiftEntry['UID']);
+ if(!Shift_signout_allowed($shift, $angeltype, $signout_user)) {
+ error(_('You are not allowed to remove this shift entry. If neccessary, ask your supporter or heaven to do so.'));
+ redirect(user_link($signout_user));
+ }
+
+ if($request->has('continue')) {
+ ShiftEntry_delete($shiftEntry);
+ success(_('Shift entry removed.'));
+ redirect(shift_link($shift));
}
- redirect(shift_link($shift_entry_source));
+ if($user['UID'] == $signout_user['UID']) {
+ return ShiftEntry_delete_view($shiftEntry, $shift, $angeltype, $signout_user);
+ }
+
+ return ShiftEntry_delete_view_admin($shiftEntry, $shift, $angeltype, $signout_user);
}
diff --git a/includes/controller/user_angeltypes_controller.php b/includes/controller/user_angeltypes_controller.php
index 8f21fa32..543ba150 100644
--- a/includes/controller/user_angeltypes_controller.php
+++ b/includes/controller/user_angeltypes_controller.php
@@ -90,13 +90,7 @@ function user_angeltypes_confirm_all_controller()
redirect(page_link_to('angeltypes'));
}
- $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
- if ($user_angeltype == null) {
- error(_('User angeltype doesn\'t exist.'));
- redirect(page_link_to('angeltypes'));
- }
-
- if (!in_array('admin_user_angeltypes', $privileges) && !$user_angeltype['supporter']) {
+ if (!in_array('admin_user_angeltypes', $privileges) && !User_is_AngelType_supporter($user, $angeltype)) {
error(_('You are not allowed to confirm all users for this angeltype.'));
redirect(page_link_to('angeltypes'));
}