summaryrefslogtreecommitdiff
path: root/includes/controller
diff options
context:
space:
mode:
Diffstat (limited to 'includes/controller')
-rw-r--r--includes/controller/angeltypes_controller.php396
-rw-r--r--includes/controller/event_config_controller.php214
-rw-r--r--includes/controller/rooms_controller.php165
-rw-r--r--includes/controller/shift_entries_controller.php422
-rw-r--r--includes/controller/shifts_controller.php621
-rw-r--r--includes/controller/shifttypes_controller.php301
-rw-r--r--includes/controller/user_angeltypes_controller.php693
-rw-r--r--includes/controller/user_driver_licenses_controller.php220
-rw-r--r--includes/controller/users_controller.php688
9 files changed, 2083 insertions, 1637 deletions
diff --git a/includes/controller/angeltypes_controller.php b/includes/controller/angeltypes_controller.php
index cd2aa3e4..daa754eb 100644
--- a/includes/controller/angeltypes_controller.php
+++ b/includes/controller/angeltypes_controller.php
@@ -2,225 +2,275 @@
/**
* Text for Angeltype related links.
+ *
+ * @return string
*/
-function angeltypes_title() {
- return _("Angeltypes");
+function angeltypes_title()
+{
+ return _('Angeltypes');
}
/**
* Route angeltype actions.
+ *
+ * @return array
*/
-function angeltypes_controller() {
- $action = strip_request_item('action', 'list');
-
- switch ($action) {
- default:
- case 'list':
- return angeltypes_list_controller();
- case 'view':
- return angeltype_controller();
- case 'edit':
- return angeltype_edit_controller();
- case 'delete':
- return angeltype_delete_controller();
- case 'about':
- return angeltypes_about_controller();
- }
+function angeltypes_controller()
+{
+ $action = strip_request_item('action', 'list');
+
+ switch ($action) {
+ case 'view':
+ return angeltype_controller();
+ case 'edit':
+ return angeltype_edit_controller();
+ case 'delete':
+ return angeltype_delete_controller();
+ case 'about':
+ return angeltypes_about_controller();
+ case 'list':
+ default:
+ return angeltypes_list_controller();
+ }
}
/**
* Path to angeltype view.
*
- * @param AngelType $angeltype_id
+ * @param int $angeltype_id AngelType id
+ * @return string
*/
-function angeltype_link($angeltype_id) {
- return page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype_id;
+function angeltype_link($angeltype_id)
+{
+ return page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype_id;
}
/**
* Job description for all angeltypes (public to everyone)
+ *
+ * @return array
*/
-function angeltypes_about_controller() {
- global $user;
-
- if (isset($user)) {
- $angeltypes = AngelTypes_with_user($user);
- } else {
- $angeltypes = AngelTypes();
- }
-
- return [
- _("Teams/Job description"),
- AngelTypes_about_view($angeltypes, isset($user))
- ];
+function angeltypes_about_controller()
+{
+ global $user;
+
+ if (isset($user)) {
+ $angeltypes = AngelTypes_with_user($user);
+ } else {
+ $angeltypes = AngelTypes();
+ }
+
+ return [
+ _('Teams/Job description'),
+ AngelTypes_about_view($angeltypes, isset($user))
+ ];
}
/**
* Delete an Angeltype.
+ *
+ * @return array
*/
-function angeltype_delete_controller() {
- global $privileges;
-
- if (! in_array('admin_angel_types', $privileges)) {
- redirect(page_link_to('angeltypes'));
- }
-
- $angeltype = load_angeltype();
-
- if (isset($_REQUEST['confirmed'])) {
- AngelType_delete($angeltype);
- success(sprintf(_("Angeltype %s deleted."), AngelType_name_render($angeltype)));
- redirect(page_link_to('angeltypes'));
- }
-
- return [
- sprintf(_("Delete angeltype %s"), $angeltype['name']),
- AngelType_delete_view($angeltype)
- ];
+function angeltype_delete_controller()
+{
+ global $privileges;
+
+ if (!in_array('admin_angel_types', $privileges)) {
+ redirect(page_link_to('angeltypes'));
+ }
+
+ $angeltype = load_angeltype();
+
+ if (isset($_REQUEST['confirmed'])) {
+ AngelType_delete($angeltype);
+ success(sprintf(_('Angeltype %s deleted.'), AngelType_name_render($angeltype)));
+ redirect(page_link_to('angeltypes'));
+ }
+
+ return [
+ sprintf(_('Delete angeltype %s'), $angeltype['name']),
+ AngelType_delete_view($angeltype)
+ ];
}
/**
* Change an Angeltype.
+ *
+ * @return array
*/
-function angeltype_edit_controller() {
- global $privileges, $user;
-
- // In supporter mode only allow to modify description
- $supporter_mode = ! in_array('admin_angel_types', $privileges);
-
- if (isset($_REQUEST['angeltype_id'])) {
- // Edit existing angeltype
- $angeltype = load_angeltype();
-
- if (! User_is_AngelType_supporter($user, $angeltype)) {
- redirect(page_link_to('angeltypes'));
- }
- } else {
- // New angeltype
- if ($supporter_mode) {
- // Supporters aren't allowed to create new angeltypes.
- redirect(page_link_to('angeltypes'));
+function angeltype_edit_controller()
+{
+ global $privileges, $user;
+
+ // In supporter mode only allow to modify description
+ $supporter_mode = !in_array('admin_angel_types', $privileges);
+
+ if (isset($_REQUEST['angeltype_id'])) {
+ // Edit existing angeltype
+ $angeltype = load_angeltype();
+
+ if (!User_is_AngelType_supporter($user, $angeltype)) {
+ redirect(page_link_to('angeltypes'));
+ }
+ } else {
+ // New angeltype
+ if ($supporter_mode) {
+ // Supporters aren't allowed to create new angeltypes.
+ redirect(page_link_to('angeltypes'));
+ }
+ $angeltype = AngelType_new();
}
- $angeltype = AngelType_new();
- }
-
- if (isset($_REQUEST['submit'])) {
- $valid = true;
-
- if (! $supporter_mode) {
- if (isset($_REQUEST['name'])) {
- $result = AngelType_validate_name($_REQUEST['name'], $angeltype);
- $angeltype['name'] = $result->getValue();
- if (! $result->isValid()) {
- $valid = false;
- error(_("Please check the name. Maybe it already exists."));
+
+ if (isset($_REQUEST['submit'])) {
+ $valid = true;
+
+ if (!$supporter_mode) {
+ if (isset($_REQUEST['name'])) {
+ $result = AngelType_validate_name($_REQUEST['name'], $angeltype);
+ $angeltype['name'] = $result->getValue();
+ if (!$result->isValid()) {
+ $valid = false;
+ error(_('Please check the name. Maybe it already exists.'));
+ }
+ }
+
+ $angeltype['restricted'] = isset($_REQUEST['restricted']);
+ $angeltype['no_self_signup'] = isset($_REQUEST['no_self_signup']);
+
+ $angeltype['requires_driver_license'] = isset($_REQUEST['requires_driver_license']);
}
- }
-
- $angeltype['restricted'] = isset($_REQUEST['restricted']);
- $angeltype['no_self_signup'] = isset($_REQUEST['no_self_signup']);
- $angeltype['requires_driver_license'] = isset($_REQUEST['requires_driver_license']);
- }
-
- $angeltype['description'] = strip_request_item_nl('description', $angeltype['description']);
-
- if ($valid) {
- if ($angeltype['id'] != null) {
- AngelType_update($angeltype);
- } else {
- $angeltype = AngelType_create($angeltype);
- }
-
- success("Angel type saved.");
- redirect(angeltype_link($angeltype['id']));
+ $angeltype['description'] = strip_request_item_nl('description', $angeltype['description']);
+
+ if ($valid) {
+ if ($angeltype['id'] != null) {
+ AngelType_update($angeltype);
+ } else {
+ $angeltype = AngelType_create($angeltype);
+ }
+
+ success('Angel type saved.');
+ redirect(angeltype_link($angeltype['id']));
+ }
}
- }
-
- return [
- sprintf(_("Edit %s"), $angeltype['name']),
- AngelType_edit_view($angeltype, $supporter_mode)
- ];
+
+ return [
+ sprintf(_('Edit %s'), $angeltype['name']),
+ AngelType_edit_view($angeltype, $supporter_mode)
+ ];
}
/**
* View details of a given angeltype.
+ *
+ * @return array
*/
-function angeltype_controller() {
- global $privileges, $user;
-
- if (! in_array('angeltypes', $privileges)) {
- redirect('?');
- }
-
- $angeltype = load_angeltype();
- $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
- $user_driver_license = UserDriverLicense($user['UID']);
- $members = Users_by_angeltype($angeltype);
-
- return [
- sprintf(_("Team %s"), $angeltype['name']),
- AngelType_view($angeltype, $members, $user_angeltype, in_array('admin_user_angeltypes', $privileges) || $user_angeltype['supporter'], in_array('admin_angel_types', $privileges), $user_angeltype['supporter'], $user_driver_license, $user)
- ];
+function angeltype_controller()
+{
+ global $privileges, $user;
+
+ if (!in_array('angeltypes', $privileges)) {
+ redirect('?');
+ }
+
+ $angeltype = load_angeltype();
+ $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
+ $user_driver_license = UserDriverLicense($user['UID']);
+ $members = Users_by_angeltype($angeltype);
+
+ return [
+ sprintf(_('Team %s'), $angeltype['name']),
+ AngelType_view(
+ $angeltype,
+ $members,
+ $user_angeltype,
+ in_array('admin_user_angeltypes', $privileges) || $user_angeltype['supporter'],
+ in_array('admin_angel_types', $privileges),
+ $user_angeltype['supporter'],
+ $user_driver_license,
+ $user
+ )
+ ];
}
/**
* View a list of all angeltypes.
+ *
+ * @return array
*/
-function angeltypes_list_controller() {
- global $privileges, $user;
-
- if (! in_array('angeltypes', $privileges)) {
- redirect('?');
- }
-
- $angeltypes = AngelTypes_with_user($user);
-
- foreach ($angeltypes as &$angeltype) {
- $actions = [
- button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], _("view"), "btn-xs")
- ];
-
- if (in_array('admin_angel_types', $privileges)) {
- $actions[] = button(page_link_to('angeltypes') . '&action=edit&angeltype_id=' . $angeltype['id'], _("edit"), "btn-xs");
- $actions[] = button(page_link_to('angeltypes') . '&action=delete&angeltype_id=' . $angeltype['id'], _("delete"), "btn-xs");
+function angeltypes_list_controller()
+{
+ global $privileges, $user;
+
+ if (!in_array('angeltypes', $privileges)) {
+ redirect('?');
}
-
- $angeltype['membership'] = AngelType_render_membership($angeltype);
- if ($angeltype['user_angeltype_id'] != null) {
- $actions[] = button(page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $angeltype['user_angeltype_id'], _("leave"), "btn-xs");
- } else {
- $actions[] = button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], _("join"), "btn-xs");
+
+ $angeltypes = AngelTypes_with_user($user);
+
+ foreach ($angeltypes as &$angeltype) {
+ $actions = [
+ button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], _('view'), 'btn-xs')
+ ];
+
+ if (in_array('admin_angel_types', $privileges)) {
+ $actions[] = button(
+ page_link_to('angeltypes') . '&action=edit&angeltype_id=' . $angeltype['id'],
+ _('edit'),
+ 'btn-xs'
+ );
+ $actions[] = button(
+ page_link_to('angeltypes') . '&action=delete&angeltype_id=' . $angeltype['id'],
+ _('delete'),
+ 'btn-xs'
+ );
+ }
+
+ $angeltype['membership'] = AngelType_render_membership($angeltype);
+ if ($angeltype['user_angeltype_id'] != null) {
+ $actions[] = button(
+ page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $angeltype['user_angeltype_id'],
+ _('leave'),
+ 'btn-xs'
+ );
+ } else {
+ $actions[] = button(
+ page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'],
+ _('join'),
+ 'btn-xs'
+ );
+ }
+
+ $angeltype['restricted'] = $angeltype['restricted'] ? glyph('lock') : '';
+ $angeltype['no_self_signup'] = $angeltype['no_self_signup'] ? '' : glyph('share');
+
+ $angeltype['name'] = '<a href="' . page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'] . '">' . $angeltype['name'] . '</a>';
+
+ $angeltype['actions'] = table_buttons($actions);
}
-
- $angeltype['restricted'] = $angeltype['restricted'] ? glyph('lock') : '';
- $angeltype['no_self_signup'] = $angeltype['no_self_signup'] ? '' : glyph('share');
-
- $angeltype['name'] = '<a href="' . page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'] . '">' . $angeltype['name'] . '</a>';
-
- $angeltype['actions'] = table_buttons($actions);
- }
-
- return [
- angeltypes_title(),
- AngelTypes_list_view($angeltypes, in_array('admin_angel_types', $privileges))
- ];
+
+ return [
+ angeltypes_title(),
+ AngelTypes_list_view($angeltypes, in_array('admin_angel_types', $privileges))
+ ];
}
/**
* Loads an angeltype from given angeltype_id request param.
+ *
+ * @return array
*/
-function load_angeltype() {
- if (! isset($_REQUEST['angeltype_id'])) {
- redirect(page_link_to('angeltypes'));
- }
-
- $angeltype = AngelType($_REQUEST['angeltype_id']);
- if ($angeltype == null) {
- error(_("Angeltype doesn't exist."));
- redirect(page_link_to('angeltypes'));
- }
-
- return $angeltype;
+function load_angeltype()
+{
+ if (!isset($_REQUEST['angeltype_id'])) {
+ redirect(page_link_to('angeltypes'));
+ }
+
+ $angeltype = AngelType($_REQUEST['angeltype_id']);
+ if ($angeltype == null) {
+ error(_('Angeltype doesn\'t exist . '));
+ redirect(page_link_to('angeltypes'));
+ }
+
+ return $angeltype;
}
-?>
diff --git a/includes/controller/event_config_controller.php b/includes/controller/event_config_controller.php
index 4f07fe4c..06245c47 100644
--- a/includes/controller/event_config_controller.php
+++ b/includes/controller/event_config_controller.php
@@ -1,103 +1,127 @@
<?php
-function event_config_title() {
- return _("Event config");
+/**
+ * @return string
+ */
+function event_config_title()
+{
+ return _('Event config');
}
-function event_config_edit_controller() {
- global $privileges;
-
- if (! in_array('admin_event_config', $privileges)) {
- redirect('?');
- }
-
- $event_name = null;
- $event_welcome_msg = null;
- $buildup_start_date = null;
- $event_start_date = null;
- $event_end_date = null;
- $teardown_end_date = null;
-
- $event_config = EventConfig();
- if ($event_config != null) {
- $event_name = $event_config['event_name'];
- $buildup_start_date = $event_config['buildup_start_date'];
- $event_start_date = $event_config['event_start_date'];
- $event_end_date = $event_config['event_end_date'];
- $teardown_end_date = $event_config['teardown_end_date'];
- $event_welcome_msg = $event_config['event_welcome_msg'];
- }
-
- if (isset($_REQUEST['submit'])) {
- $valid = true;
-
- if (isset($_REQUEST['event_name'])) {
- $event_name = strip_request_item('event_name');
- }
- if ($event_name == '') {
- $event_name = null;
- }
-
- if (isset($_REQUEST['event_welcome_msg'])) {
- $event_welcome_msg = strip_request_item_nl('event_welcome_msg');
- }
- if ($event_welcome_msg == '') {
- $event_welcome_msg = null;
- }
-
- $result = check_request_date('buildup_start_date', _("Please enter buildup start date."), true);
- $buildup_start_date = $result->getValue();
- $valid &= $result->isValid();
-
- $result = check_request_date('event_start_date', _("Please enter event start date."), true);
- $event_start_date = $result->getValue();
- $valid &= $result->isValid();
-
- $result = check_request_date('event_end_date', _("Please enter event end date."), true);
- $event_end_date = $result->getValue();
- $valid &= $result->isValid();
-
- $result = check_request_date('teardown_end_date', _("Please enter teardown end date."), true);
- $teardown_end_date = $result->getValue();
- $valid &= $result->isValid();
-
- if ($buildup_start_date != null && $event_start_date != null && $buildup_start_date > $event_start_date) {
- $valid = false;
- error(_("The buildup start date has to be before the event start date."));
- }
-
- if ($event_start_date != null && $event_end_date != null && $event_start_date > $event_end_date) {
- $valid = false;
- error(_("The event start date has to be before the event end date."));
- }
-
- if ($event_end_date != null && $teardown_end_date != null && $event_end_date > $teardown_end_date) {
- $valid = false;
- error(_("The event end date has to be before the teardown end date."));
+/**
+ * @return array
+ */
+function event_config_edit_controller()
+{
+ global $privileges;
+
+ if (!in_array('admin_event_config', $privileges)) {
+ redirect('?');
}
-
- if ($buildup_start_date != null && $teardown_end_date != null && $buildup_start_date > $teardown_end_date) {
- $valid = false;
- error(_("The buildup start date has to be before the teardown end date."));
+
+ $event_name = null;
+ $event_welcome_msg = null;
+ $buildup_start_date = null;
+ $event_start_date = null;
+ $event_end_date = null;
+ $teardown_end_date = null;
+
+ $event_config = EventConfig();
+ if ($event_config != null) {
+ $event_name = $event_config['event_name'];
+ $buildup_start_date = $event_config['buildup_start_date'];
+ $event_start_date = $event_config['event_start_date'];
+ $event_end_date = $event_config['event_end_date'];
+ $teardown_end_date = $event_config['teardown_end_date'];
+ $event_welcome_msg = $event_config['event_welcome_msg'];
}
-
- if ($valid) {
- $result = EventConfig_update($event_name, $buildup_start_date, $event_start_date, $event_end_date, $teardown_end_date, $event_welcome_msg);
-
- if ($result === false) {
- engelsystem_error("Unable to update event config.");
- }
-
- engelsystem_log("Changed event config: $event_name, $event_welcome_msg, " . date("Y-m-d", $buildup_start_date) . ", " . date("Y-m-d", $event_start_date) . ", " . date("Y-m-d", $event_end_date) . ", " . date("Y-m-d", $teardown_end_date));
- success(_("Settings saved."));
- redirect(page_link_to('admin_event_config'));
+
+ if (isset($_REQUEST['submit'])) {
+ $valid = true;
+
+ if (isset($_REQUEST['event_name'])) {
+ $event_name = strip_request_item('event_name');
+ }
+ if ($event_name == '') {
+ $event_name = null;
+ }
+
+ if (isset($_REQUEST['event_welcome_msg'])) {
+ $event_welcome_msg = strip_request_item_nl('event_welcome_msg');
+ }
+ if ($event_welcome_msg == '') {
+ $event_welcome_msg = null;
+ }
+
+ $result = check_request_date('buildup_start_date', _('Please enter buildup start date.'), true);
+ $buildup_start_date = $result->getValue();
+ $valid &= $result->isValid();
+
+ $result = check_request_date('event_start_date', _('Please enter event start date.'), true);
+ $event_start_date = $result->getValue();
+ $valid &= $result->isValid();
+
+ $result = check_request_date('event_end_date', _('Please enter event end date.'), true);
+ $event_end_date = $result->getValue();
+ $valid &= $result->isValid();
+
+ $result = check_request_date('teardown_end_date', _('Please enter teardown end date.'), true);
+ $teardown_end_date = $result->getValue();
+ $valid &= $result->isValid();
+
+ if ($buildup_start_date != null && $event_start_date != null && $buildup_start_date > $event_start_date) {
+ $valid = false;
+ error(_('The buildup start date has to be before the event start date.'));
+ }
+
+ if ($event_start_date != null && $event_end_date != null && $event_start_date > $event_end_date) {
+ $valid = false;
+ error(_('The event start date has to be before the event end date.'));
+ }
+
+ if ($event_end_date != null && $teardown_end_date != null && $event_end_date > $teardown_end_date) {
+ $valid = false;
+ error(_('The event end date has to be before the teardown end date.'));
+ }
+
+ if ($buildup_start_date != null && $teardown_end_date != null && $buildup_start_date > $teardown_end_date) {
+ $valid = false;
+ error(_('The buildup start date has to be before the teardown end date.'));
+ }
+
+ if ($valid) {
+ $result = EventConfig_update(
+ $event_name,
+ $buildup_start_date,
+ $event_start_date,
+ $event_end_date,
+ $teardown_end_date,
+ $event_welcome_msg
+ );
+
+ if ($result === false) {
+ engelsystem_error('Unable to update event config.');
+ }
+
+ engelsystem_log(
+ 'Changed event config: $event_name, $event_welcome_msg, '
+ . date('Y-m-d', $buildup_start_date) . ', ' . date('Y-m-d', $event_start_date) . ', '
+ . date('Y-m-d', $event_end_date) . ', ' . date('Y-m-d', $teardown_end_date)
+ );
+ success(_('Settings saved.'));
+ redirect(page_link_to('admin_event_config'));
+ }
}
- }
-
- return [
- event_config_title(),
- EventConfig_edit_view($event_name, $event_welcome_msg, $buildup_start_date, $event_start_date, $event_end_date, $teardown_end_date)
- ];
-}
-?> \ No newline at end of file
+ return [
+ event_config_title(),
+ EventConfig_edit_view(
+ $event_name,
+ $event_welcome_msg,
+ $buildup_start_date,
+ $event_start_date,
+ $event_end_date,
+ $teardown_end_date
+ )
+ ];
+}
diff --git a/includes/controller/rooms_controller.php b/includes/controller/rooms_controller.php
index bba38bb5..3f5ff387 100644
--- a/includes/controller/rooms_controller.php
+++ b/includes/controller/rooms_controller.php
@@ -1,7 +1,6 @@
<?php
-use Engelsystem\ShiftsFilterRenderer;
use Engelsystem\ShiftsFilter;
-use Engelsystem\ShiftCalendarRenderer;
+use Engelsystem\ShiftsFilterRenderer;
/**
* Room controllers for managing everything room related.
@@ -9,93 +8,109 @@ use Engelsystem\ShiftCalendarRenderer;
/**
* View a room with its shifts.
+ *
+ * @return array
*/
-function room_controller() {
- global $privileges;
-
- if (! in_array('view_rooms', $privileges)) {
- redirect(page_link_to());
- }
-
-
- $room = load_room();
-
- if($room['show'] != 'Y' && !in_array('admin_rooms', $privileges)) {
- redirect(page_link_to());
- }
-
- $all_shifts = Shifts_by_room($room);
- $days = [];
- foreach ($all_shifts as $shift) {
- $day = date("Y-m-d", $shift['start']);
- if (! in_array($day, $days)) {
- $days[] = $day;
+function room_controller()
+{
+ global $privileges;
+
+ if (!in_array('view_rooms', $privileges)) {
+ redirect(page_link_to());
+ }
+
+ $room = load_room();
+ $all_shifts = Shifts_by_room($room);
+ $days = [];
+ foreach ($all_shifts as $shift) {
+ $day = date('Y-m-d', $shift['start']);
+ if (!in_array($day, $days)) {
+ $days[] = $day;
+ }
+ }
+
+ $shiftsFilter = new ShiftsFilter(
+ true,
+ [$room['RID']],
+ AngelType_ids()
+ );
+ $selected_day = date('Y-m-d');
+ if (!empty($days)) {
+ $selected_day = $days[0];
+ }
+ if (isset($_REQUEST['shifts_filter_day'])) {
+ $selected_day = $_REQUEST['shifts_filter_day'];
}
- }
-
- $shiftsFilter = new ShiftsFilter(true, [
- $room['RID']
- ], AngelType_ids());
- $selected_day = date("Y-m-d");
- if (! empty($days)) {
- $selected_day = $days[0];
- }
- if (isset($_REQUEST['shifts_filter_day'])) {
- $selected_day = $_REQUEST['shifts_filter_day'];
- }
- $shiftsFilter->setStartTime(parse_date("Y-m-d H:i", $selected_day . ' 00:00'));
- $shiftsFilter->setEndTime(parse_date("Y-m-d H:i", $selected_day . ' 23:59'));
-
- $shiftsFilterRenderer = new ShiftsFilterRenderer($shiftsFilter);
- $shiftsFilterRenderer->enableDaySelection($days);
-
- $shiftCalendarRenderer = shiftCalendarRendererByShiftFilter($shiftsFilter);
-
- return [
- $room['Name'],
- Room_view($room, $shiftsFilterRenderer, $shiftCalendarRenderer)
- ];
+ $shiftsFilter->setStartTime(parse_date('Y-m-d H:i', $selected_day . ' 00:00'));
+ $shiftsFilter->setEndTime(parse_date('Y-m-d H:i', $selected_day . ' 23:59'));
+
+ $shiftsFilterRenderer = new ShiftsFilterRenderer($shiftsFilter);
+ $shiftsFilterRenderer->enableDaySelection($days);
+
+ $shiftCalendarRenderer = shiftCalendarRendererByShiftFilter($shiftsFilter);
+
+ return [
+ $room['Name'],
+ Room_view($room, $shiftsFilterRenderer, $shiftCalendarRenderer)
+ ];
}
/**
* Dispatch different room actions.
+ *
+ * @return array
*/
-function rooms_controller() {
- if (! isset($_REQUEST['action'])) {
- $_REQUEST['action'] = 'list';
- }
-
- switch ($_REQUEST['action']) {
- default:
- case 'list':
- redirect(page_link_to('admin_rooms'));
- case 'view':
- return room_controller();
- }
+function rooms_controller()
+{
+ if (!isset($_REQUEST['action'])) {
+ $_REQUEST['action'] = 'list';
+ }
+
+ switch ($_REQUEST['action']) {
+ case 'view':
+ return room_controller();
+ case 'list':
+ default:
+ redirect(page_link_to('admin_rooms'));
+ break;
+ }
+
+ exit;
}
-function room_link($room) {
- return page_link_to('rooms') . '&action=view&room_id=' . $room['RID'];
+/**
+ * @param array $room
+ * @return string
+ */
+function room_link($room)
+{
+ return page_link_to('rooms') . '&action=view&room_id=' . $room['RID'];
}
-function room_edit_link($room) {
- return page_link_to('admin_rooms') . '&show=edit&id=' . $room['RID'];
+/**
+ * @param array $room
+ * @return string
+ */
+function room_edit_link($room)
+{
+ return page_link_to('admin_rooms') . '&show=edit&id=' . $room['RID'];
}
/**
* Loads room by request param room_id
+ *
+ * @return array
*/
-function load_room() {
- if (! test_request_int('room_id')) {
- redirect(page_link_to());
- }
-
- $room = Room($_REQUEST['room_id']);
- if ($room == null) {
- redirect(page_link_to());
- }
-
- return $room;
-}
+function load_room()
+{
+ if (!test_request_int('room_id')) {
+ redirect(page_link_to());
+ }
-?> \ No newline at end of file
+ $room = Room($_REQUEST['room_id']);
+ if ($room == null) {
+ redirect(page_link_to());
+ }
+
+ return $room;
+}
diff --git a/includes/controller/shift_entries_controller.php b/includes/controller/shift_entries_controller.php
index d0a12288..cb2d9bee 100644
--- a/includes/controller/shift_entries_controller.php
+++ b/includes/controller/shift_entries_controller.php
@@ -1,187 +1,291 @@
<?php
+use Engelsystem\Database\DB;
+
/**
* Sign up for a shift.
+ *
+ * @return string
*/
-function shift_entry_add_controller() {
- global $privileges, $user;
-
- if (isset($_REQUEST['shift_id']) && preg_match("/^[0-9]*$/", $_REQUEST['shift_id'])) {
- $shift_id = $_REQUEST['shift_id'];
- } else {
- redirect(page_link_to('user_shifts'));
- }
-
- // Locations laden
- $rooms = sql_select("SELECT * FROM `Room` WHERE `show`='Y' ORDER BY `Name`");
- $room_array = [];
- foreach ($rooms as $room) {
- $room_array[$room['RID']] = $room['Name'];
- }
-
- $shift = Shift($shift_id);
- $shift['Name'] = $room_array[$shift['RID']];
- if ($shift == null) {
- redirect(page_link_to('user_shifts'));
- }
-
- if (isset($_REQUEST['type_id']) && preg_match("/^[0-9]*$/", $_REQUEST['type_id'])) {
- $type_id = $_REQUEST['type_id'];
- } else {
- redirect(page_link_to('user_shifts'));
- }
-
- if (in_array('user_shifts_admin', $privileges) || in_array('shiftentry_edit_angeltype_supporter', $privileges)) {
- $type = AngelType($type_id);
- } else {
- $type = sql_select("SELECT * FROM `UserAngelTypes` JOIN `AngelTypes` ON (`UserAngelTypes`.`angeltype_id` = `AngelTypes`.`id`) WHERE `AngelTypes`.`id` = '" . sql_escape($type_id) . "' AND (`AngelTypes`.`restricted` = 0 OR (`UserAngelTypes`.`user_id` = '" . sql_escape($user['UID']) . "' AND NOT `UserAngelTypes`.`confirm_user_id` IS NULL))");
- $type = $type[0];
- }
-
- if ($type == null) {
- redirect(page_link_to('user_shifts'));
- }
-
- if (isset($_REQUEST['user_id']) && preg_match("/^[0-9]*$/", $_REQUEST['user_id']) && (in_array('user_shifts_admin', $privileges) || in_array('shiftentry_edit_angeltype_supporter', $privileges))) {
- $user_id = $_REQUEST['user_id'];
- } else {
- $user_id = $user['UID'];
- }
-
- $needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $type);
- $shift_entries = ShiftEntries_by_shift_and_angeltype($shift['SID'], $type['id']);
-
- $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."));
- redirect(shift_link($shift));
- }
-
- if (isset($_REQUEST['submit'])) {
- $selected_type_id = $type_id;
- if (in_array('user_shifts_admin', $privileges) || in_array('shiftentry_edit_angeltype_supporter', $privileges)) {
-
- if (sql_num_query("SELECT * FROM `User` WHERE `UID`='" . sql_escape($user_id) . "' LIMIT 1") == 0) {
+function shift_entry_add_controller()
+{
+ global $privileges, $user;
+
+ $shift_id = 0;
+ if (isset($_REQUEST['shift_id']) && preg_match('/^\d*$/', $_REQUEST['shift_id'])) {
+ $shift_id = $_REQUEST['shift_id'];
+ } else {
redirect(page_link_to('user_shifts'));
- }
-
- if (isset($_REQUEST['angeltype_id']) && test_request_int('angeltype_id') && sql_num_query("SELECT * FROM `AngelTypes` WHERE `id`='" . sql_escape($_REQUEST['angeltype_id']) . "' LIMIT 1") > 0) {
- $selected_type_id = $_REQUEST['angeltype_id'];
- }
}
-
- if (sql_num_query("SELECT * FROM `ShiftEntry` WHERE `SID`='" . sql_escape($shift['SID']) . "' AND `UID` = '" . sql_escape($user_id) . "'")) {
- return error("This angel does already have an entry for this shift.", true);
+
+ // Locations laden
+ $rooms = Rooms();
+ $room_array = [];
+ foreach ($rooms as $room) {
+ $room_array[$room['RID']] = $room['Name'];
}
-
- $freeloaded = $shift['freeloaded'];
- $freeload_comment = $shift['freeload_comment'];
- if (in_array("user_shifts_admin", $privileges)) {
- $freeloaded = isset($_REQUEST['freeloaded']);
- $freeload_comment = strip_request_item_nl('freeload_comment');
+
+ $shift = Shift($shift_id);
+ $shift['Name'] = $room_array[$shift['RID']];
+ if ($shift == null) {
+ redirect(page_link_to('user_shifts'));
}
-
- $comment = strip_request_item_nl('comment');
- $result = ShiftEntry_create([
- 'SID' => $shift_id,
- 'TID' => $selected_type_id,
- 'UID' => $user_id,
- 'Comment' => $comment,
- 'freeloaded' => $freeloaded,
- 'freeload_comment' => $freeload_comment
- ]);
- if ($result === false) {
- engelsystem_error('Unable to create shift entry.');
+
+ $type_id = 0;
+ if (isset($_REQUEST['type_id']) && preg_match('/^\d*$/', $_REQUEST['type_id'])) {
+ $type_id = $_REQUEST['type_id'];
+ } else {
+ redirect(page_link_to('user_shifts'));
}
-
- if ($type['restricted'] == 0 && sql_num_query("SELECT * FROM `UserAngelTypes` INNER JOIN `AngelTypes` ON `AngelTypes`.`id` = `UserAngelTypes`.`angeltype_id` WHERE `angeltype_id` = '" . sql_escape($selected_type_id) . "' AND `user_id` = '" . sql_escape($user_id) . "'") == 0) {
- sql_query("INSERT INTO `UserAngelTypes` (`user_id`, `angeltype_id`) VALUES ('" . sql_escape($user_id) . "', '" . sql_escape($selected_type_id) . "')");
+
+ if (in_array('user_shifts_admin', $privileges) || in_array('shiftentry_edit_angeltype_supporter', $privileges)) {
+ $type = AngelType($type_id);
+ } else {
+ // TODO: Move queries to model
+ $type = DB::select('
+ 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']]);
+ $type = array_shift($type);
}
-
- $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") . ' &raquo;</a>');
- redirect(shift_link($shift));
- }
-
- if (in_array('user_shifts_admin', $privileges)) {
- $users = sql_select("SELECT *, (SELECT count(*) FROM `ShiftEntry` WHERE `freeloaded`=1 AND `ShiftEntry`.`UID`=`User`.`UID`) AS `freeloaded` FROM `User` ORDER BY `Nick`");
- $users_select = [];
- foreach ($users as $usr) {
- $users_select[$usr['UID']] = $usr['Nick'] . ($usr['freeloaded'] == 0 ? "" : " (" . _("Freeloader") . ")");
+
+ if (empty($type)) {
+ redirect(page_link_to('user_shifts'));
}
- $user_text = html_select_key('user_id', 'user_id', $users_select, $user['UID']);
-
- $angeltypes_source = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`");
- $angeltypes = [];
- foreach ($angeltypes_source as $angeltype) {
- $angeltypes[$angeltype['id']] = $angeltype['name'];
+
+ if (
+ isset($_REQUEST['user_id'])
+ && preg_match('/^\d*$/', $_REQUEST['user_id'])
+ && (
+ in_array('user_shifts_admin', $privileges)
+ || in_array('shiftentry_edit_angeltype_supporter', $privileges)
+ )
+ ) {
+ $user_id = $_REQUEST['user_id'];
+ } else {
+ $user_id = $user['UID'];
}
- $angeltype_select = html_select_key('angeltype_id', 'angeltype_id', $angeltypes, $type['id']);
- } elseif (in_array('shiftentry_edit_angeltype_supporter', $privileges)) {
- $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'];
- }
+
+ $needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $type);
+ $shift_entries = ShiftEntries_by_shift_and_angeltype($shift['SID'], $type['id']);
+
+ $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.'));
+ redirect(shift_link($shift));
+ }
+
+ if (isset($_REQUEST['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 (
+ isset($_REQUEST['angeltype_id'])
+ && test_request_int('angeltype_id')
+ && count(DB::select(
+ 'SELECT `id` FROM `AngelTypes` WHERE `id`=? LIMIT 1',
+ [$_REQUEST['angeltype_id']]
+ )) > 0
+ ) {
+ $selected_type_id = $_REQUEST['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 = isset($_REQUEST['freeloaded']);
+ $freeload_comment = strip_request_item_nl('freeload_comment');
+ }
+
+ $comment = strip_request_item_nl('comment');
+ $result = ShiftEntry_create([
+ 'SID' => $shift_id,
+ 'TID' => $selected_type_id,
+ 'UID' => $user_id,
+ 'Comment' => $comment,
+ 'freeloaded' => $freeloaded,
+ 'freeload_comment' => $freeload_comment
+ ]);
+ if ($result === false) {
+ engelsystem_error('Unable to create shift entry.');
+ }
+
+ 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') . ' &raquo;</a>');
+ redirect(shift_link($shift));
}
- $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']);
+
+ $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_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)) {
+ $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'];
}
- } else {
- $user_text = User_Nick_render($user);
- $angeltype_select = $type['name'];
- }
-
- return ShiftEntry_edit_view($user_text, date("Y-m-d H:i", $shift['start']) . ' &ndash; ' . 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));
+
+ return ShiftEntry_edit_view(
+ $user_text,
+ date('Y-m-d H:i', $shift['start'])
+ . ' &ndash; '
+ . 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)
+ );
}
/**
* Remove somebody from a shift.
*/
-function shift_entry_delete_controller() {
- global $privileges, $user;
-
- if (! isset($_REQUEST['entry_id']) || ! test_request_int('entry_id')) {
- redirect(page_link_to('user_shifts'));
- }
- $entry_id = $_REQUEST['entry_id'];
-
- $shift_entry_source = sql_select("
- SELECT `User`.`Nick`, `ShiftEntry`.`Comment`, `ShiftEntry`.`UID`, `ShiftTypes`.`name`, `Shifts`.*, `Room`.`Name`, `AngelTypes`.`name` as `angel_type`, `AngelTypes`.`id` as `angeltype_id`
+function shift_entry_delete_controller()
+{
+ global $privileges, $user;
+
+ if (!isset($_REQUEST['entry_id']) || !test_request_int('entry_id')) {
+ redirect(page_link_to('user_shifts'));
+ }
+ $entry_id = $_REQUEST['entry_id'];
+
+ $shift_entry_source = DB::select('
+ SELECT
+ `User`.`Nick`,
+ `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`='" . sql_escape($entry_id) . "'");
- if (count($shift_entry_source) > 0) {
- $shift_entry_source = $shift_entry_source[0];
-
- 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'));
- }
-
- $result = ShiftEntry_delete($entry_id);
- if ($result === false) {
- engelsystem_error('Unable to delete shift entry.');
+ WHERE `ShiftEntry`.`id`=?',
+ [$entry_id]
+ );
+ if (count($shift_entry_source) > 0) {
+ $shift_entry_source = array_shift($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'));
+ }
+
+ $result = ShiftEntry_delete($entry_id);
+ if ($result === false) {
+ engelsystem_error('Unable to delete shift entry.');
+ }
+
+ 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.'));
}
-
- 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."));
- }
- redirect(shift_link($shift_entry_source));
-}
-?> \ No newline at end of file
+ redirect(shift_link($shift_entry_source));
+}
diff --git a/includes/controller/shifts_controller.php b/includes/controller/shifts_controller.php
index 9ac8a766..c8b6932a 100644
--- a/includes/controller/shifts_controller.php
+++ b/includes/controller/shifts_controller.php
@@ -1,324 +1,393 @@
<?php
use Engelsystem\ShiftSignupState;
-function shift_link($shift) {
- return page_link_to('shifts') . '&action=view&shift_id=' . $shift['SID'];
+/**
+ * @param array $shift
+ * @return string
+ */
+function shift_link($shift)
+{
+ $link = page_link_to('shifts') . '&action=view';
+ if (isset($shift['SID'])) {
+ $link .= '&shift_id=' . $shift['SID'];
+ }
+ return $link;
}
-function shift_delete_link($shift) {
- return page_link_to('user_shifts') . '&delete_shift=' . $shift['SID'];
+/**
+ * @param array $shift
+ * @return string
+ */
+function shift_delete_link($shift)
+{
+ return page_link_to('user_shifts') . '&delete_shift=' . $shift['SID'];
}
-function shift_edit_link($shift) {
- return page_link_to('user_shifts') . '&edit_shift=' . $shift['SID'];
+/**
+ * @param array $shift
+ * @return string
+ */
+function shift_edit_link($shift)
+{
+ return page_link_to('user_shifts') . '&edit_shift=' . $shift['SID'];
}
/**
* Edit a single shift.
+ *
+ * @return string
*/
-function shift_edit_controller() {
- global $privileges;
-
- // Schicht bearbeiten
- $msg = "";
- $valid = true;
-
- if (! in_array('admin_shifts', $privileges)) {
- redirect(page_link_to('user_shifts'));
- }
-
- if (! isset($_REQUEST['edit_shift']) || ! test_request_int('edit_shift')) {
- redirect(page_link_to('user_shifts'));
- }
- $shift_id = $_REQUEST['edit_shift'];
-
- $shift = Shift($shift_id);
-
- $room = select_array(Rooms(), 'RID', 'Name');
- $angeltypes = select_array(AngelTypes(), 'id', 'name');
- $shifttypes = select_array(ShiftTypes(), 'id', 'name');
-
- $needed_angel_types = select_array(NeededAngelTypes_by_shift($shift_id), 'id', 'count');
- foreach (array_keys($angeltypes) as $angeltype_id) {
- if (! isset($needed_angel_types[$angeltype_id])) {
- $needed_angel_types[$angeltype_id] = 0;
+function shift_edit_controller()
+{
+ global $privileges;
+
+ // Schicht bearbeiten
+ $msg = '';
+ $valid = true;
+
+ if (!in_array('admin_shifts', $privileges)) {
+ redirect(page_link_to('user_shifts'));
}
- }
-
- $shifttype_id = $shift['shifttype_id'];
- $title = $shift['title'];
- $rid = $shift['RID'];
- $start = $shift['start'];
- $end = $shift['end'];
-
- if (isset($_REQUEST['submit'])) {
- // Name/Bezeichnung der Schicht, darf leer sein
- $title = strip_request_item('title');
-
- // Auswahl der sichtbaren Locations für die Schichten
- if (isset($_REQUEST['rid']) && preg_match("/^[0-9]+$/", $_REQUEST['rid']) && isset($room[$_REQUEST['rid']])) {
- $rid = $_REQUEST['rid'];
- } else {
- $valid = false;
- $msg .= error(_("Please select a room."), true);
+
+ if (!isset($_REQUEST['edit_shift']) || !test_request_int('edit_shift')) {
+ redirect(page_link_to('user_shifts'));
}
-
- if (isset($_REQUEST['shifttype_id']) && isset($shifttypes[$_REQUEST['shifttype_id']])) {
- $shifttype_id = $_REQUEST['shifttype_id'];
- } else {
- $valid = false;
- $msg .= error(_('Please select a shifttype.'), true);
+ $shift_id = $_REQUEST['edit_shift'];
+
+ $shift = Shift($shift_id);
+
+ $room = select_array(Rooms(), 'RID', 'Name');
+ $angeltypes = select_array(AngelTypes(), 'id', 'name');
+ $shifttypes = select_array(ShiftTypes(), 'id', 'name');
+
+ $needed_angel_types = select_array(NeededAngelTypes_by_shift($shift_id), 'id', 'count');
+ foreach (array_keys($angeltypes) as $angeltype_id) {
+ if (!isset($needed_angel_types[$angeltype_id])) {
+ $needed_angel_types[$angeltype_id] = 0;
+ }
}
-
- if (isset($_REQUEST['start']) && $tmp = parse_date("Y-m-d H:i", $_REQUEST['start'])) {
- $start = $tmp;
- } else {
- $valid = false;
- $msg .= error(_("Please enter a valid starting time for the shifts."), true);
+
+ $shifttype_id = $shift['shifttype_id'];
+ $title = $shift['title'];
+ $rid = $shift['RID'];
+ $start = $shift['start'];
+ $end = $shift['end'];
+
+ if (isset($_REQUEST['submit'])) {
+ // Name/Bezeichnung der Schicht, darf leer sein
+ $title = strip_request_item('title');
+
+ // Auswahl der sichtbaren Locations für die Schichten
+ if (isset($_REQUEST['rid']) && preg_match('/^\d+$/', $_REQUEST['rid']) && isset($room[$_REQUEST['rid']])) {
+ $rid = $_REQUEST['rid'];
+ } else {
+ $valid = false;
+ $msg .= error(_('Please select a room.'), true);
+ }
+
+ if (isset($_REQUEST['shifttype_id']) && isset($shifttypes[$_REQUEST['shifttype_id']])) {
+ $shifttype_id = $_REQUEST['shifttype_id'];
+ } else {
+ $valid = false;
+ $msg .= error(_('Please select a shifttype.'), true);
+ }
+
+ if (isset($_REQUEST['start']) && $tmp = parse_date('Y-m-d H:i', $_REQUEST['start'])) {
+ $start = $tmp;
+ } else {
+ $valid = false;
+ $msg .= error(_('Please enter a valid starting time for the shifts.'), true);
+ }
+
+ if (isset($_REQUEST['end']) && $tmp = parse_date('Y-m-d H:i', $_REQUEST['end'])) {
+ $end = $tmp;
+ } else {
+ $valid = false;
+ $msg .= error(_('Please enter a valid ending time for the shifts.'), true);
+ }
+
+ if ($start >= $end) {
+ $valid = false;
+ $msg .= error(_('The ending time has to be after the starting time.'), true);
+ }
+
+ foreach ($needed_angel_types as $needed_angeltype_id => $needed_angeltype_name) {
+ if (isset($_REQUEST['type_' . $needed_angeltype_id]) && test_request_int('type_' . $needed_angeltype_id)) {
+ $needed_angel_types[$needed_angeltype_id] = trim($_REQUEST['type_' . $needed_angeltype_id]);
+ } else {
+ $valid = false;
+ $msg .= error(sprintf(
+ _('Please check your input for needed angels of type %s.'),
+ $needed_angeltype_name
+ ), true);
+ }
+ }
+
+ if ($valid) {
+ $shift['shifttype_id'] = $shifttype_id;
+ $shift['title'] = $title;
+ $shift['RID'] = $rid;
+ $shift['start'] = $start;
+ $shift['end'] = $end;
+
+ $result = Shift_update($shift);
+ if ($result === false) {
+ engelsystem_error('Unable to update shift.');
+ }
+ NeededAngelTypes_delete_by_shift($shift_id);
+ $needed_angel_types_info = [];
+ foreach ($needed_angel_types as $type_id => $count) {
+ NeededAngelType_add($shift_id, $type_id, null, $count);
+ $needed_angel_types_info[] = $angeltypes[$type_id] . ': ' . $count;
+ }
+
+ engelsystem_log(
+ 'Updated shift \'' . $shifttypes[$shifttype_id] . ', ' . $title
+ . '\' from ' . date('Y-m-d H:i', $start)
+ . ' to ' . date('Y-m-d H:i', $end)
+ . ' with angel types ' . join(', ', $needed_angel_types_info)
+ );
+ success(_('Shift updated.'));
+
+ redirect(shift_link([
+ 'SID' => $shift_id
+ ]));
+ }
}
-
- if (isset($_REQUEST['end']) && $tmp = parse_date("Y-m-d H:i", $_REQUEST['end'])) {
- $end = $tmp;
- } else {
- $valid = false;
- $msg .= error(_("Please enter a valid ending time for the shifts."), true);
+
+ $angel_types_spinner = '';
+ foreach ($angeltypes as $angeltype_id => $angeltype_name) {
+ $angel_types_spinner .= form_spinner('type_' . $angeltype_id, $angeltype_name,
+ $needed_angel_types[$angeltype_id]);
}
-
- if ($start >= $end) {
- $valid = false;
- $msg .= error(_("The ending time has to be after the starting time."), true);
+
+ return page_with_title(
+ shifts_title(),
+ [
+ msg(),
+ '<noscript>' . info(_('This page is much more comfortable with javascript.'), true) . '</noscript>',
+ form([
+ form_select('shifttype_id', _('Shifttype'), $shifttypes, $shifttype_id),
+ form_text('title', _('Title'), $title),
+ form_select('rid', _('Room:'), $room, $rid),
+ form_text('start', _('Start:'), date('Y-m-d H:i', $start)),
+ form_text('end', _('End:'), date('Y-m-d H:i', $end)),
+ '<h2>' . _('Needed angels') . '</h2>',
+ $angel_types_spinner,
+ form_submit('submit', _('Save'))
+ ])
+ ]
+ );
+}
+
+/**
+ * @return string
+ */
+function shift_delete_controller()
+{
+ global $privileges;
+
+ if (!in_array('user_shifts_admin', $privileges)) {
+ redirect(page_link_to('user_shifts'));
}
-
- foreach ($needed_angel_types as $needed_angeltype_id => $needed_angeltype_name) {
- if (isset($_REQUEST['type_' . $needed_angeltype_id]) && test_request_int('type_' . $needed_angeltype_id)) {
- $needed_angel_types[$needed_angeltype_id] = trim($_REQUEST['type_' . $needed_angeltype_id]);
- } else {
- $valid = false;
- $msg .= error(sprintf(_("Please check your input for needed angels of type %s."), $needed_angeltype_name), true);
- }
+
+ // Schicht komplett löschen (nur für admins/user mit user_shifts_admin privileg)
+ if (!isset($_REQUEST['delete_shift']) || !preg_match('/^\d*$/', $_REQUEST['delete_shift'])) {
+ redirect(page_link_to('user_shifts'));
}
-
- if ($valid) {
- $shift['shifttype_id'] = $shifttype_id;
- $shift['title'] = $title;
- $shift['RID'] = $rid;
- $shift['start'] = $start;
- $shift['end'] = $end;
-
- $result = Shift_update($shift);
- if ($result === false) {
- engelsystem_error('Unable to update shift.');
- }
- NeededAngelTypes_delete_by_shift($shift_id);
- $needed_angel_types_info = [];
- foreach ($needed_angel_types as $type_id => $count) {
- NeededAngelType_add($shift_id, $type_id, null, $count);
- $needed_angel_types_info[] = $angeltypes[$type_id] . ": " . $count;
- }
-
- engelsystem_log("Updated shift '" . $shifttypes[$shifttype_id] . ", " . $title . "' from " . date("Y-m-d H:i", $start) . " to " . date("Y-m-d H:i", $end) . " with angel types " . join(", ", $needed_angel_types_info));
- success(_("Shift updated."));
-
- redirect(shift_link([
- 'SID' => $shift_id
- ]));
+ $shift_id = $_REQUEST['delete_shift'];
+
+ $shift = Shift($shift_id);
+ if ($shift == null) {
+ redirect(page_link_to('user_shifts'));
}
- }
-
- $angel_types_spinner = "";
- foreach ($angeltypes as $angeltype_id => $angeltype_name) {
- $angel_types_spinner .= form_spinner('type_' . $angeltype_id, $angeltype_name, $needed_angel_types[$angeltype_id]);
- }
-
- return page_with_title(shifts_title(), [
- msg(),
- '<noscript>' . info(_("This page is much more comfortable with javascript."), true) . '</noscript>',
- form([
- form_select('shifttype_id', _('Shifttype'), $shifttypes, $shifttype_id),
- form_text('title', _("Title"), $title),
- form_select('rid', _("Room:"), $room, $rid),
- form_text('start', _("Start:"), date("Y-m-d H:i", $start)),
- form_text('end', _("End:"), date("Y-m-d H:i", $end)),
- '<h2>' . _("Needed angels") . '</h2>',
- $angel_types_spinner,
- form_submit('submit', _("Save"))
- ])
- ]);
-}
-function shift_delete_controller() {
- global $privileges;
-
- if (! in_array('user_shifts_admin', $privileges)) {
- redirect(page_link_to('user_shifts'));
- }
-
- // Schicht komplett löschen (nur für admins/user mit user_shifts_admin privileg)
- if (! isset($_REQUEST['delete_shift']) || ! preg_match("/^[0-9]*$/", $_REQUEST['delete_shift'])) {
- redirect(page_link_to('user_shifts'));
- }
- $shift_id = $_REQUEST['delete_shift'];
-
- $shift = Shift($shift_id);
- if ($shift == null) {
- redirect(page_link_to('user_shifts'));
- }
-
- // Schicht löschen bestätigt
- if (isset($_REQUEST['delete'])) {
- Shift_delete($shift_id);
-
- engelsystem_log("Deleted shift " . $shift['name'] . " from " . date("Y-m-d H:i", $shift['start']) . " to " . date("Y-m-d H:i", $shift['end']));
- success(_("Shift deleted."));
- redirect(page_link_to('user_shifts'));
- }
-
- return page_with_title(shifts_title(), [
- error(sprintf(_("Do you want to delete the shift %s from %s to %s?"), $shift['name'], date("Y-m-d H:i", $shift['start']), date("H:i", $shift['end'])), true),
- '<a class="button" href="?p=user_shifts&delete_shift=' . $shift_id . '&delete">' . _("delete") . '</a>'
- ]);
+ // Schicht löschen bestätigt
+ if (isset($_REQUEST['delete'])) {
+ Shift_delete($shift_id);
+
+ engelsystem_log(
+ 'Deleted shift ' . $shift['name']
+ . ' from ' . date('Y-m-d H:i', $shift['start'])
+ . ' to ' . date('Y-m-d H:i', $shift['end'])
+ );
+ success(_('Shift deleted.'));
+ redirect(page_link_to('user_shifts'));
+ }
+
+ return page_with_title(shifts_title(), [
+ error(sprintf(
+ _('Do you want to delete the shift %s from %s to %s?'),
+ $shift['name'],
+ date('Y-m-d H:i', $shift['start']),
+ date('H:i', $shift['end'])
+ ), true),
+ '<a class="button" href="?p=user_shifts&delete_shift=' . $shift_id . '&delete">' . _('delete') . '</a>'
+ ]);
}
-function shift_controller() {
- global $user, $privileges;
-
- if (! in_array('user_shifts', $privileges)) {
- redirect(page_link_to('?'));
- }
-
- if (! isset($_REQUEST['shift_id'])) {
- redirect(page_link_to('user_shifts'));
- }
-
- $shift = Shift($_REQUEST['shift_id']);
- if ($shift == null) {
- error(_("Shift could not be found."));
- redirect(page_link_to('user_shifts'));
- }
-
- $shifttype = ShiftType($shift['shifttype_id']);
- $room = Room($shift['RID']);
- $angeltypes = AngelTypes();
- $user_shifts = Shifts_by_user($user);
-
- $shift_signup_state = new ShiftSignupState(ShiftSignupState::OCCUPIED, 0);
- foreach ($angeltypes as &$angeltype) {
- $needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype);
- $shift_entries = ShiftEntries_by_shift_and_angeltype($shift['SID'], $angeltype['id']);
-
- $angeltype_signup_state = Shift_signup_allowed($user, $shift, $angeltype, null, $user_shifts, $needed_angeltype, $shift_entries);
- if ($shift_signup_state == null) {
- $shift_signup_state = $angeltype_signup_state;
- } else {
- $shift_signup_state->combineWith($angeltype_signup_state);
+/**
+ * @return array
+ */
+function shift_controller()
+{
+ global $user, $privileges;
+
+ if (!in_array('user_shifts', $privileges)) {
+ redirect(page_link_to('?'));
+ }
+
+ if (!isset($_REQUEST['shift_id'])) {
+ redirect(page_link_to('user_shifts'));
+ }
+
+ $shift = Shift($_REQUEST['shift_id']);
+ if ($shift == null) {
+ error(_('Shift could not be found.'));
+ redirect(page_link_to('user_shifts'));
}
- $angeltype['shift_signup_state'] = $angeltype_signup_state;
- }
-
- return [
- $shift['name'],
- Shift_view($shift, $shifttype, $room, $angeltypes, $shift_signup_state)
- ];
+
+ $shifttype = ShiftType($shift['shifttype_id']);
+ $room = Room($shift['RID']);
+ $angeltypes = AngelTypes();
+ $user_shifts = Shifts_by_user($user);
+
+ $shift_signup_state = new ShiftSignupState(ShiftSignupState::OCCUPIED, 0);
+ foreach ($angeltypes as &$angeltype) {
+ $needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype);
+ $shift_entries = ShiftEntries_by_shift_and_angeltype($shift['SID'], $angeltype['id']);
+
+ $angeltype_signup_state = Shift_signup_allowed(
+ $user,
+ $shift,
+ $angeltype,
+ null,
+ $user_shifts,
+ $needed_angeltype,
+ $shift_entries
+ );
+ if ($shift_signup_state == null) {
+ $shift_signup_state = $angeltype_signup_state;
+ } else {
+ $shift_signup_state->combineWith($angeltype_signup_state);
+ }
+ $angeltype['shift_signup_state'] = $angeltype_signup_state;
+ }
+
+ return [
+ $shift['name'],
+ Shift_view($shift, $shifttype, $room, $angeltypes, $shift_signup_state)
+ ];
}
-function shifts_controller() {
- if (! isset($_REQUEST['action'])) {
- redirect(page_link_to('user_shifts'));
- }
-
- switch ($_REQUEST['action']) {
- default:
- redirect(page_link_to('?'));
- case 'view':
- return shift_controller();
- case 'next':
- return shift_next_controller();
- }
+/**
+ * @return array|false
+ */
+function shifts_controller()
+{
+ if (!isset($_REQUEST['action'])) {
+ redirect(page_link_to('user_shifts'));
+ }
+
+ switch ($_REQUEST['action']) {
+ case 'view':
+ return shift_controller();
+ case 'next':
+ return shift_next_controller();
+ default:
+ redirect(page_link_to('?'));
+ }
+
+ return false;
}
/**
* Redirects the user to his next shift.
+ *
+ * @return false
*/
-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'));
+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 (!empty($upcoming_shifts)) {
+ redirect(shift_link($upcoming_shifts[0]));
+ }
+
+ redirect(page_link_to('user_shifts'));
+ exit;
}
/**
* Export all shifts using api-key.
*/
-function shifts_json_export_all_controller() {
- global $api_key;
-
- if ($api_key == "") {
- engelsystem_error("Config contains empty apikey.");
- }
-
- if (! isset($_REQUEST['api_key'])) {
- engelsystem_error("Missing parameter api_key.");
- }
-
- if ($_REQUEST['api_key'] != $api_key) {
- engelsystem_error("Invalid api_key.");
- }
-
- $shifts_source = Shifts();
- if ($shifts_source === false) {
- engelsystem_error("Unable to load shifts.");
- }
-
- header("Content-Type: application/json; charset=utf-8");
- raw_output(json_encode($shifts_source));
+function shifts_json_export_all_controller()
+{
+ $api_key = config('api_key');
+
+ if (empty($api_key)) {
+ engelsystem_error('Config contains empty apikey.');
+ }
+
+ if (!isset($_REQUEST['api_key'])) {
+ engelsystem_error('Missing parameter api_key.');
+ }
+
+ if ($_REQUEST['api_key'] != $api_key) {
+ engelsystem_error('Invalid api_key.');
+ }
+
+ $shifts_source = Shifts();
+ if ($shifts_source === false) {
+ engelsystem_error('Unable to load shifts.');
+ }
+
+ header('Content-Type: application/json; charset=utf-8');
+ raw_output(json_encode($shifts_source));
}
/**
* Export filtered shifts via JSON.
* (Like iCal Export or shifts view)
*/
-function shifts_json_export_controller() {
- global $user;
-
- if (! isset($_REQUEST['key']) || ! preg_match("/^[0-9a-f]{32}$/", $_REQUEST['key'])) {
- engelsystem_error("Missing key.");
- }
-
- $key = $_REQUEST['key'];
-
- $user = User_by_api_key($key);
- if ($user == null) {
- engelsystem_error("Key invalid.");
- }
- if (! in_array('shifts_json_export', privileges_for_user($user['UID']))) {
- engelsystem_error("No privilege for shifts_json_export.");
- }
-
- $shifts = load_ical_shifts();
-
- header("Content-Type: application/json; charset=utf-8");
- raw_output(json_encode($shifts));
+function shifts_json_export_controller()
+{
+ global $user;
+
+ if (!isset($_REQUEST['key']) || !preg_match('/^[\da-f]{32}$/', $_REQUEST['key'])) {
+ engelsystem_error('Missing key.');
+ }
+
+ $key = $_REQUEST['key'];
+
+ $user = User_by_api_key($key);
+ if ($user == null) {
+ engelsystem_error('Key invalid.');
+ }
+ if (!in_array('shifts_json_export', privileges_for_user($user['UID']))) {
+ engelsystem_error('No privilege for shifts_json_export.');
+ }
+
+ $shifts = load_ical_shifts();
+
+ header('Content-Type: application/json; charset=utf-8');
+ raw_output(json_encode($shifts));
}
/**
* Returns users shifts to export.
+ *
+ * @return array
*/
-function load_ical_shifts() {
- global $user;
-
- return Shifts_by_user($user);
-}
+function load_ical_shifts()
+{
+ global $user;
-?> \ No newline at end of file
+ return Shifts_by_user($user);
+}
diff --git a/includes/controller/shifttypes_controller.php b/includes/controller/shifttypes_controller.php
index 456e39ae..9a470e29 100644
--- a/includes/controller/shifttypes_controller.php
+++ b/includes/controller/shifttypes_controller.php
@@ -1,179 +1,192 @@
<?php
-function shifttype_link($shifttype) {
- return page_link_to('shifttypes') . '&action=view&shifttype_id=' . $shifttype['id'];
+/**
+ * @param array $shifttype
+ * @return string
+ */
+function shifttype_link($shifttype)
+{
+ return page_link_to('shifttypes') . '&action=view&shifttype_id=' . $shifttype['id'];
}
/**
* Delete a shifttype.
+ *
+ * @return array
*/
-function shifttype_delete_controller() {
- if (! isset($_REQUEST['shifttype_id'])) {
- redirect(page_link_to('shifttypes'));
- }
-
- $shifttype = ShiftType($_REQUEST['shifttype_id']);
- if ($shifttype === false) {
- engelsystem_error('Unable to load shifttype.');
- }
-
- if ($shifttype == null) {
- redirect(page_link_to('shifttypes'));
- }
-
- if (isset($_REQUEST['confirmed'])) {
- $result = ShiftType_delete($shifttype['id']);
- if ($result === false) {
- engelsystem_error('Unable to delete shifttype.');
+function shifttype_delete_controller()
+{
+ if (!isset($_REQUEST['shifttype_id'])) {
+ redirect(page_link_to('shifttypes'));
}
-
- engelsystem_log('Deleted shifttype ' . $shifttype['name']);
- success(sprintf(_('Shifttype %s deleted.'), $shifttype['name']));
- redirect(page_link_to('shifttypes'));
- }
-
- return [
- sprintf(_("Delete shifttype %s"), $shifttype['name']),
- ShiftType_delete_view($shifttype)
- ];
-}
-/**
- * Edit or create shift type.
- */
-function shifttype_edit_controller() {
- $shifttype_id = null;
- $name = "";
- $angeltype_id = null;
- $description = "";
-
- $angeltypes = AngelTypes();
-
- if (isset($_REQUEST['shifttype_id'])) {
$shifttype = ShiftType($_REQUEST['shifttype_id']);
- if ($shifttype === false) {
- engelsystem_error('Unable to load shifttype.');
- }
+
if ($shifttype == null) {
- error(_('Shifttype not found.'));
- redirect(page_link_to('shifttypes'));
- }
- $shifttype_id = $shifttype['id'];
- $name = $shifttype['name'];
- $angeltype_id = $shifttype['angeltype_id'];
- $description = $shifttype['description'];
- }
-
- if (isset($_REQUEST['submit'])) {
- $valid = true;
-
- if (isset($_REQUEST['name']) && $_REQUEST['name'] != '') {
- $name = strip_request_item('name');
- } else {
- $valid = false;
- error(_('Please enter a name.'));
+ redirect(page_link_to('shifttypes'));
}
-
- if (isset($_REQUEST['angeltype_id']) && preg_match("/^[0-9]+$/", $_REQUEST['angeltype_id'])) {
- $angeltype_id = $_REQUEST['angeltype_id'];
- } else {
- $angeltype_id = null;
+
+ if (isset($_REQUEST['confirmed'])) {
+ $result = ShiftType_delete($shifttype['id']);
+ if (empty($result)) {
+ engelsystem_error('Unable to delete shifttype.');
+ }
+
+ engelsystem_log('Deleted shifttype ' . $shifttype['name']);
+ success(sprintf(_('Shifttype %s deleted.'), $shifttype['name']));
+ redirect(page_link_to('shifttypes'));
}
-
- if (isset($_REQUEST['description'])) {
- $description = strip_request_item_nl('description');
+
+ return [
+ sprintf(_('Delete shifttype %s'), $shifttype['name']),
+ ShiftType_delete_view($shifttype)
+ ];
+}
+
+/**
+ * Edit or create shift type.
+ *
+ * @return array
+ */
+function shifttype_edit_controller()
+{
+ $shifttype_id = null;
+ $name = '';
+ $angeltype_id = null;
+ $description = '';
+
+ $angeltypes = AngelTypes();
+
+ if (isset($_REQUEST['shifttype_id'])) {
+ $shifttype = ShiftType($_REQUEST['shifttype_id']);
+ if ($shifttype == null) {
+ error(_('Shifttype not found.'));
+ redirect(page_link_to('shifttypes'));
+ }
+ $shifttype_id = $shifttype['id'];
+ $name = $shifttype['name'];
+ $angeltype_id = $shifttype['angeltype_id'];
+ $description = $shifttype['description'];
}
-
- if ($valid) {
- if ($shifttype_id) {
- $result = ShiftType_update($shifttype_id, $name, $angeltype_id, $description);
- if ($result === false) {
- engelsystem_error('Unable to update shifttype.');
+
+ if (isset($_REQUEST['submit'])) {
+ $valid = true;
+
+ if (isset($_REQUEST['name']) && $_REQUEST['name'] != '') {
+ $name = strip_request_item('name');
+ } else {
+ $valid = false;
+ error(_('Please enter a name.'));
+ }
+
+ if (isset($_REQUEST['angeltype_id']) && preg_match('/^\d+$/', $_REQUEST['angeltype_id'])) {
+ $angeltype_id = $_REQUEST['angeltype_id'];
+ } else {
+ $angeltype_id = null;
}
- engelsystem_log('Updated shifttype ' . $name);
- success(_('Updated shifttype.'));
- } else {
- $shifttype_id = ShiftType_create($name, $angeltype_id, $description);
- if ($shifttype_id === false) {
- engelsystem_error('Unable to create shifttype.');
+
+ if (isset($_REQUEST['description'])) {
+ $description = strip_request_item_nl('description');
+ }
+
+ if ($valid) {
+ if ($shifttype_id) {
+ $result = ShiftType_update($shifttype_id, $name, $angeltype_id, $description);
+ if ($result === false) {
+ engelsystem_error('Unable to update shifttype.');
+ }
+ engelsystem_log('Updated shifttype ' . $name);
+ success(_('Updated shifttype.'));
+ } else {
+ $shifttype_id = ShiftType_create($name, $angeltype_id, $description);
+ if ($shifttype_id === false) {
+ engelsystem_error('Unable to create shifttype.');
+ }
+ engelsystem_log('Created shifttype ' . $name);
+ success(_('Created shifttype.'));
+ }
+ redirect(page_link_to('shifttypes') . '&action=view&shifttype_id=' . $shifttype_id);
}
- engelsystem_log('Created shifttype ' . $name);
- success(_('Created shifttype.'));
- }
- redirect(page_link_to('shifttypes') . '&action=view&shifttype_id=' . $shifttype_id);
}
- }
-
- return [
- shifttypes_title(),
- ShiftType_edit_view($name, $angeltype_id, $angeltypes, $description, $shifttype_id)
- ];
+
+ return [
+ shifttypes_title(),
+ ShiftType_edit_view($name, $angeltype_id, $angeltypes, $description, $shifttype_id)
+ ];
}
-function shifttype_controller() {
- if (! isset($_REQUEST['shifttype_id'])) {
- redirect(page_link_to('shifttypes'));
- }
- $shifttype = ShiftType($_REQUEST['shifttype_id']);
- if ($shifttype === false) {
- engelsystem_error('Unable to load shifttype.');
- }
- if ($shifttype == null) {
- redirect(page_link_to('shifttypes'));
- }
-
- $angeltype = null;
- if ($shifttype['angeltype_id'] != null) {
- $angeltype = AngelType($shifttype['angeltype_id']);
- }
-
- return [
- $shifttype['name'],
- ShiftType_view($shifttype, $angeltype)
- ];
+/**
+ * @return array
+ */
+function shifttype_controller()
+{
+ if (!isset($_REQUEST['shifttype_id'])) {
+ redirect(page_link_to('shifttypes'));
+ }
+ $shifttype = ShiftType($_REQUEST['shifttype_id']);
+ if ($shifttype == null) {
+ redirect(page_link_to('shifttypes'));
+ }
+
+ $angeltype = null;
+ if ($shifttype['angeltype_id'] != null) {
+ $angeltype = AngelType($shifttype['angeltype_id']);
+ }
+
+ return [
+ $shifttype['name'],
+ ShiftType_view($shifttype, $angeltype)
+ ];
}
/**
* List all shift types.
+ *
+ * @return array
*/
-function shifttypes_list_controller() {
- $shifttypes = ShiftTypes();
- if ($shifttypes === false) {
- engelsystem_error("Unable to load shifttypes.");
- }
-
- return [
- shifttypes_title(),
- ShiftTypes_list_view($shifttypes)
- ];
+function shifttypes_list_controller()
+{
+ $shifttypes = ShiftTypes();
+ if ($shifttypes === false) {
+ engelsystem_error('Unable to load shifttypes.');
+ }
+
+ return [
+ shifttypes_title(),
+ ShiftTypes_list_view($shifttypes)
+ ];
}
/**
* Text for shift type related links.
+ *
+ * @return string
*/
-function shifttypes_title() {
- return _("Shifttypes");
+function shifttypes_title()
+{
+ return _('Shifttypes');
}
/**
* Route shift type actions
+ *
+ * @return array
*/
-function shifttypes_controller() {
- if (! isset($_REQUEST['action'])) {
- $_REQUEST['action'] = 'list';
- }
-
- switch ($_REQUEST['action']) {
- default:
- case 'list':
- return shifttypes_list_controller();
- case 'view':
- return shifttype_controller();
- case 'edit':
- return shifttype_edit_controller();
- case 'delete':
- return shifttype_delete_controller();
- }
-}
+function shifttypes_controller()
+{
+ if (!isset($_REQUEST['action'])) {
+ $_REQUEST['action'] = 'list';
+ }
-?> \ No newline at end of file
+ switch ($_REQUEST['action']) {
+ case 'view':
+ return shifttype_controller();
+ case 'edit':
+ return shifttype_edit_controller();
+ case 'delete':
+ return shifttype_delete_controller();
+ case 'list':
+ default:
+ return shifttypes_list_controller();
+ }
+}
diff --git a/includes/controller/user_angeltypes_controller.php b/includes/controller/user_angeltypes_controller.php
index 6ef894c7..f31aeecd 100644
--- a/includes/controller/user_angeltypes_controller.php
+++ b/includes/controller/user_angeltypes_controller.php
@@ -2,362 +2,421 @@
/**
* Display a hint for team/angeltype supporters if there are unconfirmed users for his angeltype.
+ *
+ * @return string|null
*/
-function user_angeltypes_unconfirmed_hint() {
- global $user;
-
- $unconfirmed_user_angeltypes = User_unconfirmed_AngelTypes($user);
- if (count($unconfirmed_user_angeltypes) == 0) {
- return null;
- }
-
- $unconfirmed_links = [];
- foreach ($unconfirmed_user_angeltypes as $user_angeltype) {
- $unconfirmed_links[] = '<a href="' . page_link_to('angeltypes') . '&action=view&angeltype_id=' . $user_angeltype['angeltype_id'] . '">' . $user_angeltype['name'] . ' (+' . $user_angeltype['count'] . ')' . '</a>';
- }
-
- return sprintf(ngettext("There is %d unconfirmed angeltype.", "There are %d unconfirmed angeltypes.", count($unconfirmed_user_angeltypes)), count($unconfirmed_user_angeltypes)) . " " . _('Angel types which need approvals:') . ' ' . join(', ', $unconfirmed_links);
+function user_angeltypes_unconfirmed_hint()
+{
+ global $user;
+
+ $unconfirmed_user_angeltypes = User_unconfirmed_AngelTypes($user);
+ if (count($unconfirmed_user_angeltypes) == 0) {
+ return null;
+ }
+
+ $unconfirmed_links = [];
+ foreach ($unconfirmed_user_angeltypes as $user_angeltype) {
+ $unconfirmed_links[] = '<a href="'
+ . page_link_to('angeltypes')
+ . '&action=view&angeltype_id=' . $user_angeltype['angeltype_id']
+ . '">' . $user_angeltype['name']
+ . ' (+' . $user_angeltype['count'] . ')'
+ . '</a>';
+ }
+
+ return sprintf(ngettext('There is %d unconfirmed angeltype.', 'There are %d unconfirmed angeltypes.',
+ count($unconfirmed_user_angeltypes)),
+ count($unconfirmed_user_angeltypes)) . ' ' . _('Angel types which need approvals:') . ' ' . join(', ',
+ $unconfirmed_links);
}
/**
* Remove all unconfirmed users from a specific angeltype.
+ *
+ * @return array
*/
-function user_angeltypes_delete_all_controller() {
- global $user;
-
- if (! isset($_REQUEST['angeltype_id'])) {
- error(_("Angeltype doesn't exist."));
- redirect(page_link_to('angeltypes'));
- }
-
- $angeltype = AngelType($_REQUEST['angeltype_id']);
- if ($angeltype == null) {
- error(_("Angeltype doesn't exist."));
- redirect(page_link_to('angeltypes'));
- }
-
- if (! User_is_AngelType_supporter($user, $angeltype)) {
- error(_("You are not allowed to delete all users for this angeltype."));
- redirect(page_link_to('angeltypes'));
- }
-
- if (isset($_REQUEST['confirmed'])) {
- UserAngelTypes_delete_all($angeltype['id']);
-
- engelsystem_log(sprintf("Denied all users for angeltype %s", AngelType_name_render($angeltype)));
- success(sprintf(_("Denied all users for angeltype %s."), AngelType_name_render($angeltype)));
- redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
- }
-
- return [
- _("Deny all users"),
- UserAngelTypes_delete_all_view($angeltype)
- ];
+function user_angeltypes_delete_all_controller()
+{
+ global $user;
+
+ if (!isset($_REQUEST['angeltype_id'])) {
+ error(_('Angeltype doesn\'t exist.'));
+ redirect(page_link_to('angeltypes'));
+ }
+
+ $angeltype = AngelType($_REQUEST['angeltype_id']);
+ if ($angeltype == null) {
+ error(_('Angeltype doesn\'t exist.'));
+ redirect(page_link_to('angeltypes'));
+ }
+
+ if (!User_is_AngelType_supporter($user, $angeltype)) {
+ error(_('You are not allowed to delete all users for this angeltype.'));
+ redirect(page_link_to('angeltypes'));
+ }
+
+ if (isset($_REQUEST['confirmed'])) {
+ UserAngelTypes_delete_all($angeltype['id']);
+
+ engelsystem_log(sprintf('Denied all users for angeltype %s', AngelType_name_render($angeltype)));
+ success(sprintf(_('Denied all users for angeltype %s.'), AngelType_name_render($angeltype)));
+ redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
+ }
+
+ return [
+ _('Deny all users'),
+ UserAngelTypes_delete_all_view($angeltype)
+ ];
}
/**
* Confirm all unconfirmed users for an angeltype.
+ *
+ * @return array
*/
-function user_angeltypes_confirm_all_controller() {
- global $user, $privileges;
-
- if (! isset($_REQUEST['angeltype_id'])) {
- error(_("Angeltype doesn't exist."));
- redirect(page_link_to('angeltypes'));
- }
-
- $angeltype = AngelType($_REQUEST['angeltype_id']);
- if ($angeltype == null) {
- error(_("Angeltype doesn't exist."));
- 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']) {
- error(_("You are not allowed to confirm all users for this angeltype."));
- redirect(page_link_to('angeltypes'));
- }
-
- if (isset($_REQUEST['confirmed'])) {
- UserAngelTypes_confirm_all($angeltype['id'], $user);
-
- engelsystem_log(sprintf("Confirmed all users for angeltype %s", AngelType_name_render($angeltype)));
- success(sprintf(_("Confirmed all users for angeltype %s."), AngelType_name_render($angeltype)));
- redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
- }
-
- return [
- _("Confirm all users"),
- UserAngelTypes_confirm_all_view($angeltype)
- ];
+function user_angeltypes_confirm_all_controller()
+{
+ global $user, $privileges;
+
+ if (!isset($_REQUEST['angeltype_id'])) {
+ error(_('Angeltype doesn\'t exist.'));
+ redirect(page_link_to('angeltypes'));
+ }
+
+ $angeltype = AngelType($_REQUEST['angeltype_id']);
+ if ($angeltype == null) {
+ error(_('Angeltype doesn\'t exist.'));
+ 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']) {
+ error(_('You are not allowed to confirm all users for this angeltype.'));
+ redirect(page_link_to('angeltypes'));
+ }
+
+ if (isset($_REQUEST['confirmed'])) {
+ UserAngelTypes_confirm_all($angeltype['id'], $user);
+
+ engelsystem_log(sprintf('Confirmed all users for angeltype %s', AngelType_name_render($angeltype)));
+ success(sprintf(_('Confirmed all users for angeltype %s.'), AngelType_name_render($angeltype)));
+ redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
+ }
+
+ return [
+ _('Confirm all users'),
+ UserAngelTypes_confirm_all_view($angeltype)
+ ];
}
/**
* Confirm an user for an angeltype.
+ *
+ * @return array
*/
-function user_angeltype_confirm_controller() {
- global $user;
-
- if (! isset($_REQUEST['user_angeltype_id'])) {
- error(_("User angeltype doesn't exist."));
- redirect(page_link_to('angeltypes'));
- }
-
- $user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']);
- if ($user_angeltype == null) {
- error(_("User angeltype doesn't exist."));
- redirect(page_link_to('angeltypes'));
- }
-
- $angeltype = AngelType($user_angeltype['angeltype_id']);
- if ($angeltype == null) {
- error(_("Angeltype doesn't exist."));
- redirect(page_link_to('angeltypes'));
- }
-
- if (! User_is_AngelType_supporter($user, $angeltype)) {
- error(_("You are not allowed to confirm this users angeltype."));
- redirect(page_link_to('angeltypes'));
- }
-
- $user_source = User($user_angeltype['user_id']);
- if ($user_source == null) {
- error(_("User doesn't exist."));
- redirect(page_link_to('angeltypes'));
- }
-
- if (isset($_REQUEST['confirmed'])) {
- $result = UserAngelType_confirm($user_angeltype['id'], $user);
- if ($result === false) {
- engelsystem_error("Unable to confirm user angeltype.");
- }
-
- engelsystem_log(sprintf("%s confirmed for angeltype %s", User_Nick_render($user_source), AngelType_name_render($angeltype)));
- success(sprintf(_("%s confirmed for angeltype %s."), User_Nick_render($user_source), AngelType_name_render($angeltype)));
- redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
- }
-
- return [
- _("Confirm angeltype for user"),
- UserAngelType_confirm_view($user_angeltype, $user_source, $angeltype)
- ];
+function user_angeltype_confirm_controller()
+{
+ global $user;
+
+ if (!isset($_REQUEST['user_angeltype_id'])) {
+ error(_('User angeltype doesn\'t exist.'));
+ redirect(page_link_to('angeltypes'));
+ }
+
+ $user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']);
+ if ($user_angeltype == null) {
+ error(_('User angeltype doesn\'t exist.'));
+ redirect(page_link_to('angeltypes'));
+ }
+
+ $angeltype = AngelType($user_angeltype['angeltype_id']);
+ if ($angeltype == null) {
+ error(_('Angeltype doesn\'t exist.'));
+ redirect(page_link_to('angeltypes'));
+ }
+
+ if (!User_is_AngelType_supporter($user, $angeltype)) {
+ error(_('You are not allowed to confirm this users angeltype.'));
+ redirect(page_link_to('angeltypes'));
+ }
+
+ $user_source = User($user_angeltype['user_id']);
+ if ($user_source == null) {
+ error(_('User doesn\'t exist.'));
+ redirect(page_link_to('angeltypes'));
+ }
+
+ if (isset($_REQUEST['confirmed'])) {
+ UserAngelType_confirm($user_angeltype['id'], $user);
+
+ engelsystem_log(sprintf(
+ '%s confirmed for angeltype %s',
+ User_Nick_render($user_source),
+ AngelType_name_render($angeltype)
+ ));
+ success(sprintf(
+ _('%s confirmed for angeltype %s.'),
+ User_Nick_render($user_source),
+ AngelType_name_render($angeltype)
+ ));
+ redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
+ }
+
+ return [
+ _('Confirm angeltype for user'),
+ UserAngelType_confirm_view($user_angeltype, $user_source, $angeltype)
+ ];
}
/**
* Remove a user from an Angeltype.
+ *
+ * @return array
*/
-function user_angeltype_delete_controller() {
- global $user;
-
- if (! isset($_REQUEST['user_angeltype_id'])) {
- error(_("User angeltype doesn't exist."));
- redirect(page_link_to('angeltypes'));
- }
-
- $user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']);
- if ($user_angeltype == null) {
- error(_("User angeltype doesn't exist."));
- redirect(page_link_to('angeltypes'));
- }
-
- $angeltype = AngelType($user_angeltype['angeltype_id']);
- if ($angeltype == null) {
- error(_("Angeltype doesn't exist."));
- redirect(page_link_to('angeltypes'));
- }
-
- $user_source = User($user_angeltype['user_id']);
- if ($user_source == null) {
- error(_("User doesn't exist."));
- redirect(page_link_to('angeltypes'));
- }
-
- if ($user['UID'] != $user_angeltype['user_id'] && ! User_is_AngelType_supporter($user, $angeltype)) {
- error(_("You are not allowed to delete this users angeltype."));
- redirect(page_link_to('angeltypes'));
- }
-
- if (isset($_REQUEST['confirmed'])) {
- $result = UserAngelType_delete($user_angeltype);
- if ($result === false) {
- engelsystem_error("Unable to delete user angeltype.");
- }
-
- $success_message = sprintf(_("User %s removed from %s."), User_Nick_render($user_source), $angeltype['name']);
- engelsystem_log($success_message);
- success($success_message);
-
- redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
- }
-
- return [
- _("Remove angeltype"),
- UserAngelType_delete_view($user_angeltype, $user_source, $angeltype)
- ];
+function user_angeltype_delete_controller()
+{
+ global $user;
+
+ if (!isset($_REQUEST['user_angeltype_id'])) {
+ error(_('User angeltype doesn\'t exist.'));
+ redirect(page_link_to('angeltypes'));
+ }
+
+ $user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']);
+ if ($user_angeltype == null) {
+ error(_('User angeltype doesn\'t exist.'));
+ redirect(page_link_to('angeltypes'));
+ }
+
+ $angeltype = AngelType($user_angeltype['angeltype_id']);
+ if ($angeltype == null) {
+ error(_('Angeltype doesn\'t exist.'));
+ redirect(page_link_to('angeltypes'));
+ }
+
+ $user_source = User($user_angeltype['user_id']);
+ if ($user_source == null) {
+ error(_('User doesn\'t exist.'));
+ redirect(page_link_to('angeltypes'));
+ }
+
+ if ($user['UID'] != $user_angeltype['user_id'] && !User_is_AngelType_supporter($user, $angeltype)) {
+ error(_('You are not allowed to delete this users angeltype.'));
+ redirect(page_link_to('angeltypes'));
+ }
+
+ if (isset($_REQUEST['confirmed'])) {
+ $result = UserAngelType_delete($user_angeltype);
+ if ($result === false) {
+ engelsystem_error('Unable to delete user angeltype.');
+ }
+
+ $success_message = sprintf(_('User %s removed from %s.'), User_Nick_render($user_source), $angeltype['name']);
+ engelsystem_log($success_message);
+ success($success_message);
+
+ redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
+ }
+
+ return [
+ _('Remove angeltype'),
+ UserAngelType_delete_view($user_angeltype, $user_source, $angeltype)
+ ];
}
/**
* Update an UserAngelType.
+ *
+ * @return array
*/
-function user_angeltype_update_controller() {
- global $privileges;
-
- if (! in_array('admin_angel_types', $privileges)) {
- error(_("You are not allowed to set supporter rights."));
- redirect(page_link_to('angeltypes'));
- }
-
- if (! isset($_REQUEST['user_angeltype_id'])) {
- error(_("User angeltype doesn't exist."));
- redirect(page_link_to('angeltypes'));
- }
-
- if (isset($_REQUEST['supporter']) && preg_match("/^[01]$/", $_REQUEST['supporter'])) {
- $supporter = $_REQUEST['supporter'] == "1";
- } else {
- error(_("No supporter update given."));
- redirect(page_link_to('angeltypes'));
- }
-
- $user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']);
- if ($user_angeltype == null) {
- error(_("User angeltype doesn't exist."));
- redirect(page_link_to('angeltypes'));
- }
-
- $angeltype = AngelType($user_angeltype['angeltype_id']);
- if ($angeltype == null) {
- error(_("Angeltype doesn't exist."));
- redirect(page_link_to('angeltypes'));
- }
-
- $user_source = User($user_angeltype['user_id']);
- if ($user_source == null) {
- error(_("User doesn't exist."));
- redirect(page_link_to('angeltypes'));
- }
-
- if (isset($_REQUEST['confirmed'])) {
- UserAngelType_update($user_angeltype['id'], $supporter);
-
- $success_message = sprintf($supporter ? _("Added supporter rights for %s to %s.") : _("Removed supporter rights for %s from %s."), AngelType_name_render($angeltype), User_Nick_render($user_source));
- engelsystem_log($success_message);
- success($success_message);
-
- redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
- }
-
- return [
- $supporter ? _("Add supporter rights") : _("Remove supporter rights"),
- UserAngelType_update_view($user_angeltype, $user_source, $angeltype, $supporter)
- ];
+function user_angeltype_update_controller()
+{
+ global $privileges;
+ $supporter = false;
+
+ if (!in_array('admin_angel_types', $privileges)) {
+ error(_('You are not allowed to set supporter rights.'));
+ redirect(page_link_to('angeltypes'));
+ }
+
+ if (!isset($_REQUEST['user_angeltype_id'])) {
+ error(_('User angeltype doesn\'t exist.'));
+ redirect(page_link_to('angeltypes'));
+ }
+
+ if (isset($_REQUEST['supporter']) && preg_match('/^[01]$/', $_REQUEST['supporter'])) {
+ $supporter = $_REQUEST['supporter'] == '1';
+ } else {
+ error(_('No supporter update given.'));
+ redirect(page_link_to('angeltypes'));
+ }
+
+ $user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']);
+ if ($user_angeltype == null) {
+ error(_('User angeltype doesn\'t exist.'));
+ redirect(page_link_to('angeltypes'));
+ }
+
+ $angeltype = AngelType($user_angeltype['angeltype_id']);
+ if ($angeltype == null) {
+ error(_('Angeltype doesn\'t exist.'));
+ redirect(page_link_to('angeltypes'));
+ }
+
+ $user_source = User($user_angeltype['user_id']);
+ if ($user_source == null) {
+ error(_('User doesn\'t exist.'));
+ redirect(page_link_to('angeltypes'));
+ }
+
+ if (isset($_REQUEST['confirmed'])) {
+ UserAngelType_update($user_angeltype['id'], $supporter);
+
+ $success_message = sprintf(
+ $supporter ? _('Added supporter rights for %s to %s.') : _('Removed supporter rights for %s from %s.'),
+ AngelType_name_render($angeltype),
+ User_Nick_render($user_source)
+ );
+ engelsystem_log($success_message);
+ success($success_message);
+
+ redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
+ }
+
+ return [
+ $supporter ? _('Add supporter rights') : _('Remove supporter rights'),
+ UserAngelType_update_view($user_angeltype, $user_source, $angeltype, $supporter)
+ ];
}
/**
* User joining an Angeltype (Or supporter doing this for him).
*/
-function user_angeltype_add_controller() {
- global $user;
-
- $angeltype = load_angeltype();
-
- // User is joining by itself
- if (! User_is_AngelType_supporter($user, $angeltype)) {
- return user_angeltype_join_controller($angeltype);
- }
-
- // Allow to add any user
-
- // Default selection
- $user_source = $user;
-
- // Load possible users, that are not in the angeltype already
- $users_source = Users_by_angeltype_inverted($angeltype);
-
- if (isset($_REQUEST['submit'])) {
- $user_source = load_user();
-
- if (! UserAngelType_exists($user_source, $angeltype)) {
- $user_angeltype_id = UserAngelType_create($user_source, $angeltype);
-
- engelsystem_log(sprintf("User %s added to %s.", User_Nick_render($user_source), AngelType_name_render($angeltype)));
- success(sprintf(_("User %s added to %s."), User_Nick_render($user_source), AngelType_name_render($angeltype)));
-
- UserAngelType_confirm($user_angeltype_id, $user_source);
- engelsystem_log(sprintf("User %s confirmed as %s.", User_Nick_render($user), AngelType_name_render($angeltype)));
-
- redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
- }
- }
-
- return [
- _("Add user to angeltype"),
- UserAngelType_add_view($angeltype, $users_source, $user_source['UID'])
- ];
+function user_angeltype_add_controller()
+{
+ global $user;
+
+ $angeltype = load_angeltype();
+
+ // User is joining by itself
+ if (!User_is_AngelType_supporter($user, $angeltype)) {
+ return user_angeltype_join_controller($angeltype);
+ }
+
+ // Allow to add any user
+
+ // Default selection
+ $user_source = $user;
+
+ // Load possible users, that are not in the angeltype already
+ $users_source = Users_by_angeltype_inverted($angeltype);
+
+ if (isset($_REQUEST['submit'])) {
+ $user_source = load_user();
+
+ if (!UserAngelType_exists($user_source, $angeltype)) {
+ $user_angeltype_id = UserAngelType_create($user_source, $angeltype);
+
+ engelsystem_log(sprintf(
+ 'User %s added to %s.',
+ User_Nick_render($user_source),
+ AngelType_name_render($angeltype)
+ ));
+ success(sprintf(
+ _('User %s added to %s.'),
+ User_Nick_render($user_source),
+ AngelType_name_render($angeltype)
+ ));
+
+ UserAngelType_confirm($user_angeltype_id, $user_source);
+ engelsystem_log(sprintf(
+ 'User %s confirmed as %s.',
+ User_Nick_render($user),
+ AngelType_name_render($angeltype)
+ ));
+
+ redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
+ }
+ }
+
+ return [
+ _('Add user to angeltype'),
+ UserAngelType_add_view($angeltype, $users_source, $user_source['UID'])
+ ];
}
/**
* A user joins an angeltype.
+ *
+ * @param array $angeltype
+ * @return array
*/
-function user_angeltype_join_controller($angeltype) {
- global $user, $privileges;
-
- $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
- if ($user_angeltype != null) {
- error(sprintf(_("You are already a %s."), $angeltype['name']));
- redirect(page_link_to('angeltypes'));
- }
-
- if (isset($_REQUEST['confirmed'])) {
- $user_angeltype_id = UserAngelType_create($user, $angeltype);
-
- $success_message = sprintf(_("You joined %s."), $angeltype['name']);
- engelsystem_log(sprintf("User %s joined %s.", User_Nick_render($user), AngelType_name_render($angeltype)));
- success($success_message);
-
- if (in_array('admin_user_angeltypes', $privileges)) {
- UserAngelType_confirm($user_angeltype_id, $user);
- engelsystem_log(sprintf("User %s confirmed as %s.", User_Nick_render($user), AngelType_name_render($angeltype)));
- }
-
- redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
- }
-
- return [
- sprintf(_("Become a %s"), $angeltype['name']),
- UserAngelType_join_view($user, $angeltype)
- ];
+function user_angeltype_join_controller($angeltype)
+{
+ global $user, $privileges;
+
+ $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
+ if ($user_angeltype != null) {
+ error(sprintf(_('You are already a %s.'), $angeltype['name']));
+ redirect(page_link_to('angeltypes'));
+ }
+
+ if (isset($_REQUEST['confirmed'])) {
+ $user_angeltype_id = UserAngelType_create($user, $angeltype);
+
+ $success_message = sprintf(_('You joined %s.'), $angeltype['name']);
+ engelsystem_log(sprintf('User %s joined %s.', User_Nick_render($user), AngelType_name_render($angeltype)));
+ success($success_message);
+
+ if (in_array('admin_user_angeltypes', $privileges)) {
+ UserAngelType_confirm($user_angeltype_id, $user);
+ engelsystem_log(sprintf(
+ 'User %s confirmed as %s.',
+ User_Nick_render($user),
+ AngelType_name_render($angeltype)
+ ));
+ }
+
+ redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
+ }
+
+ return [
+ sprintf(_('Become a %s'), $angeltype['name']),
+ UserAngelType_join_view($user, $angeltype)
+ ];
}
/**
* Route UserAngelType actions.
+ *
+ * @return array
*/
-function user_angeltypes_controller() {
- if (! isset($_REQUEST['action'])) {
- redirect(page_link_to('angeltypes'));
- }
-
- switch ($_REQUEST['action']) {
- case 'delete_all':
- return user_angeltypes_delete_all_controller();
- case 'confirm_all':
- return user_angeltypes_confirm_all_controller();
- case 'confirm':
- return user_angeltype_confirm_controller();
- case 'delete':
- return user_angeltype_delete_controller();
- case 'update':
- return user_angeltype_update_controller();
- case 'add':
- return user_angeltype_add_controller();
- default:
- redirect(page_link_to('angeltypes'));
- }
-}
+function user_angeltypes_controller()
+{
+ if (!isset($_REQUEST['action'])) {
+ redirect(page_link_to('angeltypes'));
+ }
-?> \ No newline at end of file
+ switch ($_REQUEST['action']) {
+ case 'delete_all':
+ return user_angeltypes_delete_all_controller();
+ case 'confirm_all':
+ return user_angeltypes_confirm_all_controller();
+ case 'confirm':
+ return user_angeltype_confirm_controller();
+ case 'delete':
+ return user_angeltype_delete_controller();
+ case 'update':
+ return user_angeltype_update_controller();
+ case 'add':
+ return user_angeltype_add_controller();
+ default:
+ redirect(page_link_to('angeltypes'));
+ exit;
+ }
+}
diff --git a/includes/controller/user_driver_licenses_controller.php b/includes/controller/user_driver_licenses_controller.php
index 26deab7d..3098c8ce 100644
--- a/includes/controller/user_driver_licenses_controller.php
+++ b/includes/controller/user_driver_licenses_controller.php
@@ -1,132 +1,148 @@
<?php
/**
- * Generates a hint, if user joined angeltypes that require a driving license and the user has no driver license information provided.
+ * Generates a hint, if user joined angeltypes that require a driving license and the user has no driver license
+ * information provided.
+ *
+ * @return string|null
*/
-function user_driver_license_required_hint() {
- global $user;
-
- $angeltypes = User_angeltypes($user);
- $user_driver_license = UserDriverLicense($user['UID']);
-
- // User has already entered data, no hint needed.
- if ($user_driver_license != null) {
- return null;
- }
-
- foreach ($angeltypes as $angeltype) {
- if ($angeltype['requires_driver_license']) {
- return sprintf(_("You joined an angeltype which requires a driving license. Please edit your driving license information here: %s."), '<a href="' . user_driver_license_edit_link() . '">' . _("driving license information") . '</a>');
+function user_driver_license_required_hint()
+{
+ global $user;
+
+ $angeltypes = User_angeltypes($user);
+ $user_driver_license = UserDriverLicense($user['UID']);
+
+ // User has already entered data, no hint needed.
+ if ($user_driver_license != null) {
+ return null;
}
- }
-
- return null;
+
+ foreach ($angeltypes as $angeltype) {
+ if ($angeltype['requires_driver_license']) {
+ return sprintf(
+ _('You joined an angeltype which requires a driving license. Please edit your driving license information here: %s.'),
+ '<a href="' . user_driver_license_edit_link() . '">' . _('driving license information') . '</a>'
+ );
+ }
+ }
+
+ return null;
}
/**
* Route user driver licenses actions.
+ *
+ * @return array
*/
-function user_driver_licenses_controller() {
- global $user;
-
- if (! isset($user)) {
- redirect(page_link_to(''));
- }
-
- $action = strip_request_item('action', 'edit');
-
- switch ($action) {
- default:
- case 'edit':
- return user_driver_license_edit_controller();
- }
+function user_driver_licenses_controller()
+{
+ global $user;
+
+ if (!isset($user)) {
+ redirect(page_link_to(''));
+ }
+
+ $action = strip_request_item('action', 'edit');
+
+ switch ($action) {
+ default:
+ case 'edit':
+ return user_driver_license_edit_controller();
+ }
}
/**
* Link to user driver license edit page for given user.
*
- * @param User $user
+ * @param array $user
+ * @return string
*/
-function user_driver_license_edit_link($user = null) {
- if ($user == null) {
- return page_link_to('user_driver_licenses');
- }
- return page_link_to('user_driver_licenses') . '&user_id=' . $user['UID'];
+function user_driver_license_edit_link($user = null)
+{
+ if ($user == null) {
+ return page_link_to('user_driver_licenses');
+ }
+ return page_link_to('user_driver_licenses') . '&user_id=' . $user['UID'];
}
/**
* Loads the user for the driver license.
+ *
+ * @return array
*/
-function user_driver_license_load_user() {
- global $user;
-
- $user_source = $user;
-
- if (isset($_REQUEST['user_id'])) {
- $user_source = User($_REQUEST['user_id']);
- if ($user_source == null) {
- redirect(user_driver_license_edit_link());
+function user_driver_license_load_user()
+{
+ global $user;
+
+ $user_source = $user;
+
+ if (isset($_REQUEST['user_id'])) {
+ $user_source = User($_REQUEST['user_id']);
+ if ($user_source == null) {
+ redirect(user_driver_license_edit_link());
+ }
}
- }
-
- return $user_source;
+
+ return $user_source;
}
/**
* Edit a users driver license information.
+ *
+ * @return array
*/
-function user_driver_license_edit_controller() {
- global $privileges, $user;
-
- $user_source = user_driver_license_load_user();
-
- // only privilege admin_user can edit other users driver license information
- if ($user['UID'] != $user_source['UID'] && ! in_array('admin_user', $privileges)) {
- redirect(user_driver_license_edit_link());
- }
-
- $user_driver_license = UserDriverLicense($user_source['UID']);
- if ($user_driver_license == null) {
- $wants_to_drive = false;
- $user_driver_license = UserDriverLicense_new();
- } else {
- $wants_to_drive = true;
- }
-
- if (isset($_REQUEST['submit'])) {
- $wants_to_drive = isset($_REQUEST['wants_to_drive']);
- if ($wants_to_drive) {
- $user_driver_license['has_car'] = isset($_REQUEST['has_car']);
- $user_driver_license['has_license_car'] = isset($_REQUEST['has_license_car']);
- $user_driver_license['has_license_3_5t_transporter'] = isset($_REQUEST['has_license_3_5t_transporter']);
- $user_driver_license['has_license_7_5t_truck'] = isset($_REQUEST['has_license_7_5t_truck']);
- $user_driver_license['has_license_12_5t_truck'] = isset($_REQUEST['has_license_12_5t_truck']);
- $user_driver_license['has_license_forklift'] = isset($_REQUEST['has_license_forklift']);
-
- if (UserDriverLicense_valid($user_driver_license)) {
- if ($user_driver_license['user_id'] == null) {
- $user_driver_license = UserDriverLicenses_create($user_driver_license, $user);
- } else {
- UserDriverLicenses_update($user_driver_license);
+function user_driver_license_edit_controller()
+{
+ global $privileges, $user;
+
+ $user_source = user_driver_license_load_user();
+
+ // only privilege admin_user can edit other users driver license information
+ if ($user['UID'] != $user_source['UID'] && !in_array('admin_user', $privileges)) {
+ redirect(user_driver_license_edit_link());
+ }
+
+ $user_driver_license = UserDriverLicense($user_source['UID']);
+ if ($user_driver_license == null) {
+ $wants_to_drive = false;
+ $user_driver_license = UserDriverLicense_new();
+ } else {
+ $wants_to_drive = true;
+ }
+
+ if (isset($_REQUEST['submit'])) {
+ $wants_to_drive = isset($_REQUEST['wants_to_drive']);
+ if ($wants_to_drive) {
+ $user_driver_license['has_car'] = isset($_REQUEST['has_car']);
+ $user_driver_license['has_license_car'] = isset($_REQUEST['has_license_car']);
+ $user_driver_license['has_license_3_5t_transporter'] = isset($_REQUEST['has_license_3_5t_transporter']);
+ $user_driver_license['has_license_7_5t_truck'] = isset($_REQUEST['has_license_7_5t_truck']);
+ $user_driver_license['has_license_12_5t_truck'] = isset($_REQUEST['has_license_12_5t_truck']);
+ $user_driver_license['has_license_forklift'] = isset($_REQUEST['has_license_forklift']);
+
+ if (UserDriverLicense_valid($user_driver_license)) {
+ if ($user_driver_license['user_id'] == null) {
+ $user_driver_license = UserDriverLicenses_create($user_driver_license, $user_source);
+ } else {
+ UserDriverLicenses_update($user_driver_license);
+ }
+ engelsystem_log('Driver license information updated.');
+ success(_('Your driver license information has been saved.'));
+ redirect(user_link($user_source));
+ } else {
+ error(_('Please select at least one driving license.'));
+ }
+ } elseif ($user_driver_license['user_id'] != null) {
+ UserDriverLicenses_delete($user_source['UID']);
+ engelsystem_log('Driver license information removed.');
+ success(_('Your driver license information has been removed.'));
+ redirect(user_link($user_source));
}
- engelsystem_log("Driver license information updated.");
- success(_("Your driver license information has been saved."));
- redirect(user_link($user_source));
- } else {
- error(_("Please select at least one driving license."));
- }
- } elseif ($user_driver_license['id'] != null) {
- UserDriverLicenses_delete($user_source['UID']);
- engelsystem_log("Driver license information removed.");
- success(_("Your driver license information has been removed."));
- redirect(user_link($user_source));
}
- }
-
- return [
- sprintf(_("Edit %s driving license information"), $user_source['Nick']),
- UserDriverLicense_edit_view($user_source, $wants_to_drive, $user_driver_license)
- ];
-}
-?> \ No newline at end of file
+ return [
+ sprintf(_('Edit %s driving license information'), $user_source['Nick']),
+ UserDriverLicense_edit_view($user_source, $wants_to_drive, $user_driver_license)
+ ];
+}
diff --git a/includes/controller/users_controller.php b/includes/controller/users_controller.php
index 3825af7c..84b6bbda 100644
--- a/includes/controller/users_controller.php
+++ b/includes/controller/users_controller.php
@@ -1,371 +1,467 @@
<?php
-use Engelsystem\ShiftsFilter;
+
+use Engelsystem\Database\DB;
use Engelsystem\ShiftCalendarRenderer;
+use Engelsystem\ShiftsFilter;
/**
* Route user actions.
+ *
+ * @return array
*/
-function users_controller() {
- global $user;
-
- if (! isset($user)) {
- redirect(page_link_to(''));
- }
-
- if (! isset($_REQUEST['action'])) {
- $_REQUEST['action'] = 'list';
- }
-
- switch ($_REQUEST['action']) {
- default:
- case 'list':
- return users_list_controller();
- case 'view':
- return user_controller();
- case 'edit':
- return user_edit_controller();
- case 'delete':
- return user_delete_controller();
- case 'edit_vouchers':
- return user_edit_vouchers_controller();
- }
+function users_controller()
+{
+ global $user;
+
+ if (!isset($user)) {
+ redirect(page_link_to(''));
+ }
+
+ if (!isset($_REQUEST['action'])) {
+ $_REQUEST['action'] = 'list';
+ }
+
+ switch ($_REQUEST['action']) {
+ case 'view':
+ return user_controller();
+ case 'delete':
+ return user_delete_controller();
+ case 'edit_vouchers':
+ return user_edit_vouchers_controller();
+ case 'list':
+ default:
+ return users_list_controller();
+ }
}
/**
* Delete a user, requires to enter own password for reasons.
+ *
+ * @return array
*/
-function user_delete_controller() {
- global $privileges, $user;
-
- if (isset($_REQUEST['user_id'])) {
- $user_source = User($_REQUEST['user_id']);
- } else {
- $user_source = $user;
- }
-
- if (! in_array('admin_user', $privileges)) {
- redirect(page_link_to(''));
- }
-
- // You cannot delete yourself
- if ($user['UID'] == $user_source['UID']) {
- error(_("You cannot delete yourself."));
- redirect(user_link($user));
- }
-
- if (isset($_REQUEST['submit'])) {
- $valid = true;
-
- if (! (isset($_REQUEST['password']) && verify_password($_REQUEST['password'], $user['Passwort'], $user['UID']))) {
- $valid = false;
- error(_("Your password is incorrect. Please try it again."));
+function user_delete_controller()
+{
+ global $privileges, $user;
+
+ if (isset($_REQUEST['user_id'])) {
+ $user_source = User($_REQUEST['user_id']);
+ } else {
+ $user_source = $user;
+ }
+
+ if (!in_array('admin_user', $privileges)) {
+ redirect(page_link_to(''));
}
-
- if ($valid) {
- $result = User_delete($user_source['UID']);
- if ($result === false) {
- engelsystem_error('Unable to delete user.');
- }
-
- mail_user_delete($user_source);
- success(_("User deleted."));
- engelsystem_log(sprintf("Deleted %s", User_Nick_render($user_source)));
-
- redirect(users_link());
+
+ // You cannot delete yourself
+ if ($user['UID'] == $user_source['UID']) {
+ error(_('You cannot delete yourself.'));
+ redirect(user_link($user));
}
- }
-
- return [
- sprintf(_("Delete %s"), $user_source['Nick']),
- User_delete_view($user_source)
- ];
+
+ if (isset($_REQUEST['submit'])) {
+ $valid = true;
+
+ if (!(isset($_REQUEST['password']) && verify_password($_REQUEST['password'], $user['Passwort'],
+ $user['UID']))
+ ) {
+ $valid = false;
+ error(_('Your password is incorrect. Please try it again.'));
+ }
+
+ if ($valid) {
+ $result = User_delete($user_source['UID']);
+ if ($result === false) {
+ engelsystem_error('Unable to delete user.');
+ }
+
+ mail_user_delete($user_source);
+ success(_('User deleted.'));
+ engelsystem_log(sprintf('Deleted %s', User_Nick_render($user_source)));
+
+ redirect(users_link());
+ }
+ }
+
+ return [
+ sprintf(_('Delete %s'), $user_source['Nick']),
+ User_delete_view($user_source)
+ ];
}
-function users_link() {
- return page_link_to('users');
+/**
+ * @return string
+ */
+function users_link()
+{
+ return page_link_to('users');
}
-function user_edit_link($user) {
- return page_link_to('admin_user') . '&user_id=' . $user['UID'];
+/**
+ * @param array $user
+ * @return string
+ */
+function user_edit_link($user)
+{
+ return page_link_to('admin_user') . '&user_id=' . $user['UID'];
}
-function user_delete_link($user) {
- return page_link_to('users') . '&action=delete&user_id=' . $user['UID'];
+/**
+ * @param array $user
+ * @return string
+ */
+function user_delete_link($user)
+{
+ return page_link_to('users') . '&action=delete&user_id=' . $user['UID'];
}
-function user_link($user) {
- return page_link_to('users') . '&action=view&user_id=' . $user['UID'];
+/**
+ * @param array $user
+ * @return string
+ */
+function user_link($user)
+{
+ return page_link_to('users') . '&action=view&user_id=' . $user['UID'];
}
-function user_edit_vouchers_controller() {
- global $privileges, $user;
-
- if (isset($_REQUEST['user_id'])) {
- $user_source = User($_REQUEST['user_id']);
- } else {
- $user_source = $user;
- }
-
- if (! in_array('admin_user', $privileges)) {
- redirect(page_link_to(''));
- }
-
- if (isset($_REQUEST['submit'])) {
- $valid = true;
-
- if (isset($_REQUEST['vouchers']) && test_request_int('vouchers') && trim($_REQUEST['vouchers']) >= 0) {
- $vouchers = trim($_REQUEST['vouchers']);
+/**
+ * @return array
+ */
+function user_edit_vouchers_controller()
+{
+ global $privileges, $user;
+
+ if (isset($_REQUEST['user_id'])) {
+ $user_source = User($_REQUEST['user_id']);
} else {
- $valid = false;
- error(_("Please enter a valid number of vouchers."));
+ $user_source = $user;
}
-
- if ($valid) {
- $user_source['got_voucher'] = $vouchers;
-
- $result = User_update($user_source);
- if ($result === false) {
- engelsystem_error('Unable to update user.');
- }
-
- success(_("Saved the number of vouchers."));
- engelsystem_log(User_Nick_render($user_source) . ': ' . sprintf("Got %s vouchers", $user_source['got_voucher']));
-
- redirect(user_link($user_source));
+
+ if (!in_array('admin_user', $privileges)) {
+ redirect(page_link_to(''));
}
- }
-
- return [
- sprintf(_("%s's vouchers"), $user_source['Nick']),
- User_edit_vouchers_view($user_source)
- ];
+
+ if (isset($_REQUEST['submit'])) {
+ $valid = true;
+
+ $vouchers = '';
+ if (isset($_REQUEST['vouchers']) && test_request_int('vouchers') && trim($_REQUEST['vouchers']) >= 0) {
+ $vouchers = trim($_REQUEST['vouchers']);
+ } else {
+ $valid = false;
+ error(_('Please enter a valid number of vouchers.'));
+ }
+
+ if ($valid) {
+ $user_source['got_voucher'] = $vouchers;
+
+ $result = User_update($user_source);
+ if ($result === false) {
+ engelsystem_error('Unable to update user.');
+ }
+
+ success(_('Saved the number of vouchers.'));
+ engelsystem_log(User_Nick_render($user_source) . ': ' . sprintf('Got %s vouchers',
+ $user_source['got_voucher']));
+
+ redirect(user_link($user_source));
+ }
+ }
+
+ return [
+ sprintf(_('%s\'s vouchers'), $user_source['Nick']),
+ User_edit_vouchers_view($user_source)
+ ];
}
-function user_controller() {
- global $privileges, $user;
-
- $user_source = $user;
- if (isset($_REQUEST['user_id'])) {
- $user_source = User($_REQUEST['user_id']);
- if ($user_source == null) {
- error(_("User not found."));
- redirect('?');
+/**
+ * @return array
+ */
+function user_controller()
+{
+ global $privileges, $user;
+
+ $user_source = $user;
+ if (isset($_REQUEST['user_id'])) {
+ $user_source = User($_REQUEST['user_id']);
+ if ($user_source == null) {
+ error(_('User not found.'));
+ redirect('?');
+ }
}
- }
-
- $shifts = Shifts_by_user($user_source, in_array("user_shifts_admin", $privileges));
- foreach ($shifts as &$shift) {
- // TODO: Move queries to model
- $shift['needed_angeltypes'] = sql_select("SELECT DISTINCT `AngelTypes`.* FROM `ShiftEntry` JOIN `AngelTypes` ON `ShiftEntry`.`TID`=`AngelTypes`.`id` WHERE `ShiftEntry`.`SID`='" . sql_escape($shift['SID']) . "' ORDER BY `AngelTypes`.`name`");
- foreach ($shift['needed_angeltypes'] as &$needed_angeltype) {
- $needed_angeltype['users'] = sql_select("
- SELECT `ShiftEntry`.`freeloaded`, `User`.*
- FROM `ShiftEntry`
- JOIN `User` ON `ShiftEntry`.`UID`=`User`.`UID`
- WHERE `ShiftEntry`.`SID`='" . sql_escape($shift['SID']) . "'
- AND `ShiftEntry`.`TID`='" . sql_escape($needed_angeltype['id']) . "'");
+
+ $shifts = Shifts_by_user($user_source, in_array('user_shifts_admin', $privileges));
+ foreach ($shifts as &$shift) {
+ // TODO: Move queries to model
+ $shift['needed_angeltypes'] = DB::select('
+ SELECT DISTINCT `AngelTypes`.*
+ FROM `ShiftEntry`
+ JOIN `AngelTypes` ON `ShiftEntry`.`TID`=`AngelTypes`.`id`
+ WHERE `ShiftEntry`.`SID` = ?
+ ORDER BY `AngelTypes`.`name`
+ ',
+ [$shift['SID']]
+ );
+ foreach ($shift['needed_angeltypes'] as &$needed_angeltype) {
+ $needed_angeltype['users'] = DB::select('
+ SELECT `ShiftEntry`.`freeloaded`, `User`.*
+ FROM `ShiftEntry`
+ JOIN `User` ON `ShiftEntry`.`UID`=`User`.`UID`
+ WHERE `ShiftEntry`.`SID` = ?
+ AND `ShiftEntry`.`TID` = ?
+ ',
+ [$shift['SID'], $needed_angeltype['id']]
+ );
+ }
+ }
+
+ if ($user_source['api_key'] == '') {
+ User_reset_api_key($user_source, false);
}
- }
-
- if ($user_source['api_key'] == "") {
- User_reset_api_key($user_source, false);
- }
-
- return [
- $user_source['Nick'],
- User_view($user_source, in_array('admin_user', $privileges), User_is_freeloader($user_source), User_angeltypes($user_source), User_groups($user_source), $shifts, $user['UID'] == $user_source['UID'])
- ];
+
+ return [
+ $user_source['Nick'],
+ User_view(
+ $user_source,
+ in_array('admin_user', $privileges),
+ User_is_freeloader($user_source),
+ User_angeltypes($user_source),
+ User_groups($user_source),
+ $shifts,
+ $user['UID'] == $user_source['UID']
+ )
+ ];
}
/**
* List all users.
+ *
+ * @return array
*/
-function users_list_controller() {
- global $privileges;
-
- if (! in_array('admin_user', $privileges)) {
- redirect(page_link_to(''));
- }
-
- $order_by = 'Nick';
- if (isset($_REQUEST['OrderBy']) && in_array($_REQUEST['OrderBy'], User_sortable_columns())) {
- $order_by = $_REQUEST['OrderBy'];
- }
-
- $users = Users($order_by);
- if ($users === false) {
- engelsystem_error('Unable to load users.');
- }
-
- foreach ($users as &$user) {
- $user['freeloads'] = count(ShiftEntries_freeloaded_by_user($user));
- }
-
- return [
- _('All users'),
- Users_view($users, $order_by, User_arrived_count(), User_active_count(), User_force_active_count(), ShiftEntries_freeleaded_count(), User_tshirts_count(), User_got_voucher_count())
- ];
+function users_list_controller()
+{
+ global $privileges;
+
+ if (!in_array('admin_user', $privileges)) {
+ redirect(page_link_to(''));
+ }
+
+ $order_by = 'Nick';
+ if (isset($_REQUEST['OrderBy']) && in_array($_REQUEST['OrderBy'], User_sortable_columns())) {
+ $order_by = $_REQUEST['OrderBy'];
+ }
+
+ $users = Users($order_by);
+ if ($users === false) {
+ engelsystem_error('Unable to load users.');
+ }
+
+ foreach ($users as &$user) {
+ $user['freeloads'] = count(ShiftEntries_freeloaded_by_user($user));
+ }
+
+ return [
+ _('All users'),
+ Users_view(
+ $users,
+ $order_by,
+ User_arrived_count(),
+ User_active_count(),
+ User_force_active_count(),
+ ShiftEntries_freeleaded_count(),
+ User_tshirts_count(),
+ User_got_voucher_count()
+ )
+ ];
}
/**
* Second step of password recovery: set a new password using the token link from email
+ *
+ * @return string
*/
-function user_password_recovery_set_new_controller() {
- global $min_password_length;
- $user_source = User_by_password_recovery_token($_REQUEST['token']);
- if ($user_source == null) {
- error(_("Token is not correct."));
- redirect(page_link_to('login'));
- }
-
- if (isset($_REQUEST['submit'])) {
- $valid = true;
-
- if (isset($_REQUEST['password']) && strlen($_REQUEST['password']) >= $min_password_length) {
- if ($_REQUEST['password'] != $_REQUEST['password2']) {
- $valid = false;
- error(_("Your passwords don't match."));
- }
- } else {
- $valid = false;
- error(_("Your password is to short (please use at least 6 characters)."));
+function user_password_recovery_set_new_controller()
+{
+ $user_source = User_by_password_recovery_token($_REQUEST['token']);
+ if ($user_source == null) {
+ error(_('Token is not correct.'));
+ redirect(page_link_to('login'));
}
-
- if ($valid) {
- set_password($user_source['UID'], $_REQUEST['password']);
- success(_("Password saved."));
- redirect(page_link_to('login'));
+
+ if (isset($_REQUEST['submit'])) {
+ $valid = true;
+
+ if (
+ isset($_REQUEST['password'])
+ && strlen($_REQUEST['password']) >= config('min_password_length')
+ ) {
+ if ($_REQUEST['password'] != $_REQUEST['password2']) {
+ $valid = false;
+ error(_('Your passwords don\'t match.'));
+ }
+ } else {
+ $valid = false;
+ error(_('Your password is to short (please use at least 6 characters).'));
+ }
+
+ if ($valid) {
+ set_password($user_source['UID'], $_REQUEST['password']);
+ success(_('Password saved.'));
+ redirect(page_link_to('login'));
+ }
}
- }
-
- return User_password_set_view();
+
+ return User_password_set_view();
}
/**
* First step of password recovery: display a form that asks for your email and send email with recovery link
+ *
+ * @return string
*/
-function user_password_recovery_start_controller() {
- if (isset($_REQUEST['submit'])) {
- $valid = true;
-
- if (isset($_REQUEST['email']) && strlen(strip_request_item('email')) > 0) {
- $email = strip_request_item('email');
- if (check_email($email)) {
- $user_source = User_by_email($email);
- if ($user_source == null) {
- $valid = false;
- error(_("E-mail address is not correct."));
+function user_password_recovery_start_controller()
+{
+ if (isset($_REQUEST['submit'])) {
+ $valid = true;
+
+ if (isset($_REQUEST['email']) && strlen(strip_request_item('email')) > 0) {
+ $email = strip_request_item('email');
+ if (check_email($email)) {
+ $user_source = User_by_email($email);
+ if ($user_source == null) {
+ $valid = false;
+ error(_('E-mail address is not correct.'));
+ }
+ } else {
+ $valid = false;
+ error(_('E-mail address is not correct.'));
+ }
+ } else {
+ $valid = false;
+ error(_('Please enter your e-mail.'));
+ }
+
+ if ($valid) {
+ $token = User_generate_password_recovery_token($user_source);
+ engelsystem_email_to_user(
+ $user_source,
+ _('Password recovery'),
+ sprintf(
+ _('Please visit %s to recover your password.'),
+ page_link_to_absolute('user_password_recovery') . '&token=' . $token
+ )
+ );
+ success(_('We sent an email containing your password recovery link.'));
+ redirect(page_link_to('login'));
}
- } else {
- $valid = false;
- error(_("E-mail address is not correct."));
- }
- } else {
- $valid = false;
- error(_("Please enter your e-mail."));
- }
-
- if ($valid) {
- $token = User_generate_password_recovery_token($user_source);
- engelsystem_email_to_user($user_source, _("Password recovery"), sprintf(_("Please visit %s to recover your password."), page_link_to_absolute('user_password_recovery') . '&token=' . $token));
- success(_("We sent an email containing your password recovery link."));
- redirect(page_link_to('login'));
}
- }
-
- return User_password_recovery_view();
+
+ return User_password_recovery_view();
}
/**
* User password recovery in 2 steps.
* (By email)
+ *
+ * @return string
*/
-function user_password_recovery_controller() {
- if (isset($_REQUEST['token'])) {
- return user_password_recovery_set_new_controller();
- } else {
+function user_password_recovery_controller()
+{
+ if (isset($_REQUEST['token'])) {
+ return user_password_recovery_set_new_controller();
+ }
+
return user_password_recovery_start_controller();
- }
}
/**
* Menu title for password recovery.
+ *
+ * @return string
*/
-function user_password_recovery_title() {
- return _("Password recovery");
+function user_password_recovery_title()
+{
+ return _('Password recovery');
}
/**
* Loads a user from param user_id.
+ *
+ * return array
*/
-function load_user() {
- if (! isset($_REQUEST['user_id'])) {
- redirect(page_link_to());
- }
-
- $user = User($_REQUEST['user_id']);
- if ($user === false) {
- engelsystem_error("Unable to load user.");
- }
-
- if ($user == null) {
- error(_("User doesn't exist."));
- redirect(page_link_to());
- }
-
- return $user;
+function load_user()
+{
+ if (!isset($_REQUEST['user_id'])) {
+ redirect(page_link_to());
+ }
+
+ $user = User($_REQUEST['user_id']);
+
+ if ($user == null) {
+ error(_('User doesn\'t exist.'));
+ redirect(page_link_to());
+ }
+
+ return $user;
}
-function shiftCalendarRendererByShiftFilter(ShiftsFilter $shiftsFilter) {
- $shifts = Shifts_by_ShiftsFilter($shiftsFilter);
- $needed_angeltypes_source = NeededAngeltypes_by_ShiftsFilter($shiftsFilter);
- $shift_entries_source = ShiftEntries_by_ShiftsFilter($shiftsFilter);
-
- $needed_angeltypes = [];
- $shift_entries = [];
- foreach ($shifts as $shift) {
- $needed_angeltypes[$shift['SID']] = [];
- $shift_entries[$shift['SID']] = [];
- }
- foreach ($shift_entries_source as $shift_entry) {
- if (isset($shift_entries[$shift_entry['SID']])) {
- $shift_entries[$shift_entry['SID']][] = $shift_entry;
+/**
+ * @param ShiftsFilter $shiftsFilter
+ * @return ShiftCalendarRenderer
+ */
+function shiftCalendarRendererByShiftFilter(ShiftsFilter $shiftsFilter)
+{
+ $shifts = Shifts_by_ShiftsFilter($shiftsFilter);
+ $needed_angeltypes_source = NeededAngeltypes_by_ShiftsFilter($shiftsFilter);
+ $shift_entries_source = ShiftEntries_by_ShiftsFilter($shiftsFilter);
+
+ $needed_angeltypes = [];
+ $shift_entries = [];
+ foreach ($shifts as $shift) {
+ $needed_angeltypes[$shift['SID']] = [];
+ $shift_entries[$shift['SID']] = [];
}
- }
- foreach ($needed_angeltypes_source as $needed_angeltype) {
- if (isset($needed_angeltypes[$needed_angeltype['SID']])) {
- $needed_angeltypes[$needed_angeltype['SID']][] = $needed_angeltype;
+ foreach ($shift_entries_source as $shift_entry) {
+ if (isset($shift_entries[$shift_entry['SID']])) {
+ $shift_entries[$shift_entry['SID']][] = $shift_entry;
+ }
}
- }
- unset($needed_angeltypes_source);
- unset($shift_entries_source);
-
- if (in_array(ShiftsFilter::FILLED_FREE, $shiftsFilter->getFilled()) && in_array(ShiftsFilter::FILLED_FILLED, $shiftsFilter->getFilled())) {
- return new ShiftCalendarRenderer($shifts, $needed_angeltypes, $shift_entries, $shiftsFilter);
- }
-
- $filtered_shifts = [];
- foreach ($shifts as $shift) {
- $needed_angels_count = 0;
- foreach ($needed_angeltypes[$shift['SID']] as $needed_angeltype) {
- $taken = 0;
- foreach ($shift_entries[$shift['SID']] as $shift_entry) {
- if ($needed_angeltype['angel_type_id'] == $shift_entry['TID'] && $shift_entry['freeloaded'] == 0) {
- $taken ++;
+ foreach ($needed_angeltypes_source as $needed_angeltype) {
+ if (isset($needed_angeltypes[$needed_angeltype['SID']])) {
+ $needed_angeltypes[$needed_angeltype['SID']][] = $needed_angeltype;
}
- }
-
- $needed_angels_count += max(0, $needed_angeltype['count'] - $taken);
}
- if (in_array(ShiftsFilter::FILLED_FREE, $shiftsFilter->getFilled()) && $taken < $needed_angels_count) {
- $filtered_shifts[] = $shift;
+ unset($needed_angeltypes_source);
+ unset($shift_entries_source);
+
+ if (
+ in_array(ShiftsFilter::FILLED_FREE, $shiftsFilter->getFilled())
+ && in_array(ShiftsFilter::FILLED_FILLED, $shiftsFilter->getFilled())
+ ) {
+ return new ShiftCalendarRenderer($shifts, $needed_angeltypes, $shift_entries, $shiftsFilter);
}
- if (in_array(ShiftsFilter::FILLED_FILLED, $shiftsFilter->getFilled()) && $taken >= $needed_angels_count) {
- $filtered_shifts[] = $shift;
+
+ $filtered_shifts = [];
+ foreach ($shifts as $shift) {
+ $needed_angels_count = 0;
+ $taken = 0;
+ foreach ($needed_angeltypes[$shift['SID']] as $needed_angeltype) {
+ $taken = 0;
+ foreach ($shift_entries[$shift['SID']] as $shift_entry) {
+ if ($needed_angeltype['angel_type_id'] == $shift_entry['TID'] && $shift_entry['freeloaded'] == 0) {
+ $taken++;
+ }
+ }
+
+ $needed_angels_count += max(0, $needed_angeltype['count'] - $taken);
+ }
+ if (in_array(ShiftsFilter::FILLED_FREE, $shiftsFilter->getFilled()) && $taken < $needed_angels_count) {
+ $filtered_shifts[] = $shift;
+ }
+ if (in_array(ShiftsFilter::FILLED_FILLED, $shiftsFilter->getFilled()) && $taken >= $needed_angels_count) {
+ $filtered_shifts[] = $shift;
+ }
}
- }
-
- return new ShiftCalendarRenderer($filtered_shifts, $needed_angeltypes, $shift_entries, $shiftsFilter);
-}
-?>
+ return new ShiftCalendarRenderer($filtered_shifts, $needed_angeltypes, $shift_entries, $shiftsFilter);
+}