diff --git a/includes/controller/angeltypes_controller.php b/includes/controller/angeltypes_controller.php
index f8191b2e..eeb42d75 100644
--- a/includes/controller/angeltypes_controller.php
+++ b/includes/controller/angeltypes_controller.php
@@ -11,8 +11,9 @@ function angeltypes_title() {
* Route angeltype actions.
*/
function angeltypes_controller() {
- if (! isset($_REQUEST['action']))
+ if (! isset($_REQUEST['action'])) {
$_REQUEST['action'] = 'list';
+ }
switch ($_REQUEST['action']) {
default:
@@ -44,17 +45,19 @@ function angeltype_link($angeltype_id) {
function angeltypes_about_controller() {
global $user;
- if (isset($user))
+ if (isset($user)) {
$angeltypes = AngelTypes_with_user($user);
- else
+ } else {
$angeltypes = AngelTypes();
- if ($angeltypes === false)
+ }
+ if ($angeltypes === false) {
engelsystem_error("Unable to load angeltypes.");
+ }
- return array(
+ return [
_("Teams/Job description"),
AngelTypes_about_view($angeltypes, isset($user))
- );
+ ];
}
/**
@@ -63,29 +66,33 @@ function angeltypes_about_controller() {
function angeltype_delete_controller() {
global $privileges;
- if (! in_array('admin_angel_types', $privileges))
+ if (! in_array('admin_angel_types', $privileges)) {
redirect(page_link_to('angeltypes'));
+ }
$angeltype = AngelType($_REQUEST['angeltype_id']);
- if ($angeltype === false)
+ if ($angeltype === false) {
engelsystem_error("Unable to load angeltype.");
- if ($angeltype == null)
+ }
+ if ($angeltype == null) {
redirect(page_link_to('angeltypes'));
+ }
if (isset($_REQUEST['confirmed'])) {
$result = AngelType_delete($angeltype);
- if ($result === false)
+ if ($result === false) {
engelsystem_error("Unable to delete angeltype.");
+ }
engelsystem_log("Deleted angeltype: " . AngelType_name_render($angeltype));
success(sprintf(_("Angeltype %s deleted."), AngelType_name_render($angeltype)));
redirect(page_link_to('angeltypes'));
}
- return array(
+ return [
sprintf(_("Delete angeltype %s"), $angeltype['name']),
AngelType_delete_view($angeltype)
- );
+ ];
}
/**
@@ -101,21 +108,25 @@ function angeltype_edit_controller() {
if (isset($_REQUEST['angeltype_id'])) {
$angeltype = AngelType($_REQUEST['angeltype_id']);
- if ($angeltype === false)
+ if ($angeltype === false) {
engelsystem_error("Unable to load angeltype.");
- if ($angeltype == null)
+ }
+ if ($angeltype == null) {
redirect(page_link_to('angeltypes'));
+ }
$name = $angeltype['name'];
$restricted = $angeltype['restricted'];
$description = $angeltype['description'];
$requires_driver_license = $angeltype['requires_driver_license'];
- if (! User_is_AngelType_coordinator($user, $angeltype))
+ if (! User_is_AngelType_coordinator($user, $angeltype)) {
redirect(page_link_to('angeltypes'));
+ }
} else {
- if (! in_array('admin_angel_types', $privileges))
+ if (! in_array('admin_angel_types', $privileges)) {
redirect(page_link_to('angeltypes'));
+ }
}
// In coordinator mode only allow to modify description
@@ -137,20 +148,23 @@ function angeltype_edit_controller() {
$requires_driver_license = isset($_REQUEST['requires_driver_license']);
}
- if (isset($_REQUEST['description']))
+ if (isset($_REQUEST['description'])) {
$description = strip_request_item_nl('description');
+ }
if ($ok) {
if (isset($angeltype)) {
$result = AngelType_update($angeltype['id'], $name, $restricted, $description, $requires_driver_license);
- if ($result === false)
+ if ($result === false) {
engelsystem_error("Unable to update angeltype.");
+ }
engelsystem_log("Updated angeltype: " . $name . ($restricted ? ", restricted" : "") . ($requires_driver_license ? ", requires driver license" : ""));
$angeltype_id = $angeltype['id'];
} else {
$angeltype_id = AngelType_create($name, $restricted, $description, $requires_driver_license);
- if ($angeltype_id === false)
+ if ($angeltype_id === false) {
engelsystem_error("Unable to create angeltype.");
+ }
engelsystem_log("Created angeltype: " . $name . ($restricted ? ", restricted" : "") . ($requires_driver_license ? ", requires driver license" : ""));
}
@@ -159,10 +173,10 @@ function angeltype_edit_controller() {
}
}
- return array(
+ return [
sprintf(_("Edit %s"), $name),
AngelType_edit_view($name, $restricted, $description, $coordinator_mode, $requires_driver_license)
- );
+ ];
}
/**
@@ -171,34 +185,41 @@ function angeltype_edit_controller() {
function angeltype_controller() {
global $privileges, $user;
- if (! in_array('angeltypes', $privileges))
+ if (! in_array('angeltypes', $privileges)) {
redirect('?');
+ }
- if (! isset($_REQUEST['angeltype_id']))
+ if (! isset($_REQUEST['angeltype_id'])) {
redirect(page_link_to('angeltypes'));
+ }
$angeltype = AngelType($_REQUEST['angeltype_id']);
- if ($angeltype === false)
+ if ($angeltype === false) {
engelsystem_error("Unable to load angeltype.");
- if ($angeltype == null)
+ }
+ if ($angeltype == null) {
redirect(page_link_to('angeltypes'));
+ }
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
- if ($user_angeltype === false)
+ if ($user_angeltype === false) {
engelsystem_error("Unable to load user angeltype.");
+ }
$user_driver_license = UserDriverLicense($user['UID']);
- if ($user_driver_license === false)
+ if ($user_driver_license === false) {
engelsystem_error("Unable to load user driver license.");
+ }
$members = Users_by_angeltype($angeltype);
- if ($members === false)
+ if ($members === false) {
engelsystem_error("Unable to load members.");
+ }
- return array(
+ return [
sprintf(_("Team %s"), $angeltype['name']),
AngelType_view($angeltype, $members, $user_angeltype, in_array('admin_user_angeltypes', $privileges) || $user_angeltype['coordinator'], in_array('admin_angel_types', $privileges), $user_angeltype['coordinator'], $user_driver_license, $user)
- );
+ ];
}
/**
@@ -207,17 +228,19 @@ function angeltype_controller() {
function angeltypes_list_controller() {
global $privileges, $user;
- if (! in_array('angeltypes', $privileges))
+ if (! in_array('angeltypes', $privileges)) {
redirect('?');
+ }
$angeltypes = AngelTypes_with_user($user);
- if ($angeltypes === false)
+ if ($angeltypes === false) {
engelsystem_error("Unable to load angeltypes.");
+ }
foreach ($angeltypes as &$angeltype) {
- $actions = array(
+ $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");
@@ -237,9 +260,9 @@ function angeltypes_list_controller() {
$angeltype['actions'] = table_buttons($actions);
}
- return array(
+ return [
angeltypes_title(),
AngelTypes_list_view($angeltypes, in_array('admin_angel_types', $privileges))
- );
+ ];
}
?>
diff --git a/includes/controller/event_config_controller.php b/includes/controller/event_config_controller.php
index 29a5b979..dc789ca6 100644
--- a/includes/controller/event_config_controller.php
+++ b/includes/controller/event_config_controller.php
@@ -7,8 +7,9 @@ function event_config_title() {
function event_config_edit_controller() {
global $privileges;
- if (! in_array('admin_event_config', $privileges))
+ if (! in_array('admin_event_config', $privileges)) {
redirect('?');
+ }
$event_name = null;
$event_welcome_msg = null;
@@ -18,8 +19,9 @@ function event_config_edit_controller() {
$teardown_end_date = null;
$event_config = EventConfig();
- if ($event_config === false)
+ if ($event_config === false) {
engelsystem_error('Unable to load event config.');
+ }
if ($event_config != null) {
$event_name = $event_config['event_name'];
$buildup_start_date = $event_config['buildup_start_date'];
@@ -32,15 +34,19 @@ function event_config_edit_controller() {
if (isset($_REQUEST['submit'])) {
$ok = true;
- if (isset($_REQUEST['event_name']))
+ if (isset($_REQUEST['event_name'])) {
$event_name = strip_request_item('event_name');
- if ($event_name == '')
+ }
+ if ($event_name == '') {
$event_name = null;
+ }
- if (isset($_REQUEST['event_welcome_msg']))
+ if (isset($_REQUEST['event_welcome_msg'])) {
$event_welcome_msg = strip_request_item_nl('event_welcome_msg');
- if ($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();
@@ -81,8 +87,9 @@ function event_config_edit_controller() {
if ($ok) {
$result = EventConfig_update($event_name, $buildup_start_date, $event_start_date, $event_end_date, $teardown_end_date, $event_welcome_msg);
- if ($result === false)
+ 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."));
diff --git a/includes/controller/shifttypes_controller.php b/includes/controller/shifttypes_controller.php
index 443ce470..5380389e 100644
--- a/includes/controller/shifttypes_controller.php
+++ b/includes/controller/shifttypes_controller.php
@@ -8,28 +8,34 @@ function shifttype_link($shifttype) {
* Delete a shifttype.
*/
function shifttype_delete_controller() {
- if (! isset($_REQUEST['shifttype_id']))
+ if (! isset($_REQUEST['shifttype_id'])) {
redirect(page_link_to('shifttypes'));
+ }
+
$shifttype = ShiftType($_REQUEST['shifttype_id']);
- if ($shifttype === false)
+ if ($shifttype === false) {
engelsystem_error('Unable to load shifttype.');
- if ($shifttype == null)
+ }
+
+ if ($shifttype == null) {
redirect(page_link_to('shifttypes'));
+ }
if (isset($_REQUEST['confirmed'])) {
$result = ShiftType_delete($shifttype['id']);
- if ($result === false)
+ if ($result === false) {
engelsystem_error('Unable to delete shifttype.');
+ }
engelsystem_log('Deleted shifttype ' . $shifttype['name']);
success(sprintf(_('Shifttype %s deleted.'), $shifttype['name']));
redirect(page_link_to('shifttypes'));
}
- return array(
+ return [
sprintf(_("Delete shifttype %s"), $shifttype['name']),
ShiftType_delete_view($shifttype)
- );
+ ];
}
/**
@@ -42,13 +48,15 @@ function shifttype_edit_controller() {
$description = "";
$angeltypes = AngelTypes();
- if ($angeltypes === false)
+ if ($angeltypes === false) {
engelsystem_error("Unable to load angel types.");
+ }
if (isset($_REQUEST['shifttype_id'])) {
$shifttype = ShiftType($_REQUEST['shifttype_id']);
- if ($shifttype === false)
+ if ($shifttype === false) {
engelsystem_error('Unable to load shifttype.');
+ }
if ($shifttype == null) {
error(_('Shifttype not found.'));
redirect(page_link_to('shifttypes'));
@@ -62,32 +70,36 @@ function shifttype_edit_controller() {
if (isset($_REQUEST['submit'])) {
$ok = true;
- if (isset($_REQUEST['name']) && $_REQUEST['name'] != '')
+ if (isset($_REQUEST['name']) && $_REQUEST['name'] != '') {
$name = strip_request_item('name');
- else {
+ } else {
$ok = false;
error(_('Please enter a name.'));
}
- if (isset($_REQUEST['angeltype_id']) && preg_match("/^[0-9]+$/", $_REQUEST['angeltype_id']))
+ if (isset($_REQUEST['angeltype_id']) && preg_match("/^[0-9]+$/", $_REQUEST['angeltype_id'])) {
$angeltype_id = $_REQUEST['angeltype_id'];
- else
+ } else {
$angeltype_id = null;
+ }
- if (isset($_REQUEST['description']))
+ if (isset($_REQUEST['description'])) {
$description = strip_request_item_nl('description');
+ }
if ($ok) {
if ($shifttype_id) {
$result = ShiftType_update($shifttype_id, $name, $angeltype_id, $description);
- if ($result === false)
+ 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)
+ if ($shifttype_id === false) {
engelsystem_error('Unable to create shifttype.');
+ }
engelsystem_log('Created shifttype ' . $name);
success(_('Created shifttype.'));
}
@@ -102,19 +114,23 @@ function shifttype_edit_controller() {
}
function shifttype_controller() {
- if (! isset($_REQUEST['shifttype_id']))
+ if (! isset($_REQUEST['shifttype_id'])) {
redirect(page_link_to('shifttypes'));
+ }
$shifttype = ShiftType($_REQUEST['shifttype_id']);
- if ($shifttype === false)
+ if ($shifttype === false) {
engelsystem_error('Unable to load shifttype.');
- if ($shifttype == null)
+ }
+ if ($shifttype == null) {
redirect(page_link_to('shifttypes'));
+ }
$angeltype = null;
if ($shifttype['angeltype_id'] != null) {
$angeltype = AngelType($shifttype['angeltype_id']);
- if ($angeltype === false)
+ if ($angeltype === false) {
engelsystem_error('Unable to load angeltype.');
+ }
}
return [
@@ -128,8 +144,9 @@ function shifttype_controller() {
*/
function shifttypes_list_controller() {
$shifttypes = ShiftTypes();
- if ($shifttypes === false)
+ if ($shifttypes === false) {
engelsystem_error("Unable to load shifttypes.");
+ }
return [
shifttypes_title(),
@@ -148,8 +165,9 @@ function shifttypes_title() {
* Route shift type actions
*/
function shifttypes_controller() {
- if (! isset($_REQUEST['action']))
+ if (! isset($_REQUEST['action'])) {
$_REQUEST['action'] = 'list';
+ }
switch ($_REQUEST['action']) {
default:
diff --git a/includes/controller/user_angeltypes_controller.php b/includes/controller/user_angeltypes_controller.php
index dfc22a71..e0c0b38f 100644
--- a/includes/controller/user_angeltypes_controller.php
+++ b/includes/controller/user_angeltypes_controller.php
@@ -7,14 +7,17 @@ function user_angeltypes_unconfirmed_hint() {
global $user;
$unconfirmed_user_angeltypes = User_unconfirmed_AngelTypes($user);
- if ($unconfirmed_user_angeltypes === false)
+ if ($unconfirmed_user_angeltypes === false) {
engelsystem_error("Unable to load user angeltypes.");
- if (count($unconfirmed_user_angeltypes) == 0)
+ }
+ if (count($unconfirmed_user_angeltypes) == 0) {
return '';
+ }
$unconfirmed_links = [];
- foreach ($unconfirmed_user_angeltypes as $user_angeltype)
+ foreach ($unconfirmed_user_angeltypes as $user_angeltype) {
$unconfirmed_links[] = '' . $user_angeltype['name'] . ' (+' . $user_angeltype['count'] . ')' . '';
+ }
return info(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), true);
}
@@ -31,8 +34,9 @@ function user_angeltypes_delete_all_controller() {
}
$angeltype = AngelType($_REQUEST['angeltype_id']);
- if ($angeltype === false)
+ if ($angeltype === false) {
engelsystem_error("Unable to load angeltype.");
+ }
if ($angeltype == null) {
error(_("Angeltype doesn't exist."));
redirect(page_link_to('angeltypes'));
@@ -45,18 +49,19 @@ function user_angeltypes_delete_all_controller() {
if (isset($_REQUEST['confirmed'])) {
$result = UserAngelTypes_delete_all($angeltype['id']);
- if ($result === false)
+ if ($result === false) {
engelsystem_error("Unable to confirm all users.");
+ }
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 array(
+ return [
_("Deny all users"),
UserAngelTypes_delete_all_view($angeltype)
- );
+ ];
}
/**
@@ -71,16 +76,18 @@ function user_angeltypes_confirm_all_controller() {
}
$angeltype = AngelType($_REQUEST['angeltype_id']);
- if ($angeltype === false)
+ if ($angeltype === false) {
engelsystem_error("Unable to load angeltype.");
+ }
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 === false)
+ if ($user_angeltype === false) {
engelsystem_error("Unable to load user angeltype.");
+ }
if ($user_angeltype == null) {
error(_("User angeltype doesn't exist."));
redirect(page_link_to('angeltypes'));
@@ -93,18 +100,19 @@ function user_angeltypes_confirm_all_controller() {
if (isset($_REQUEST['confirmed'])) {
$result = UserAngelTypes_confirm_all($angeltype['id'], $user);
- if ($result === false)
+ if ($result === false) {
engelsystem_error("Unable to confirm all users.");
+ }
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 array(
+ return [
_("Confirm all users"),
UserAngelTypes_confirm_all_view($angeltype)
- );
+ ];
}
/**
@@ -119,16 +127,18 @@ function user_angeltype_confirm_controller() {
}
$user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']);
- if ($user_angeltype === false)
+ if ($user_angeltype === false) {
engelsystem_error("Unable to load user angeltype.");
+ }
if ($user_angeltype == null) {
error(_("User angeltype doesn't exist."));
redirect(page_link_to('angeltypes'));
}
$angeltype = AngelType($user_angeltype['angeltype_id']);
- if ($angeltype === false)
+ if ($angeltype === false) {
engelsystem_error("Unable to load angeltype.");
+ }
if ($angeltype == null) {
error(_("Angeltype doesn't exist."));
redirect(page_link_to('angeltypes'));
@@ -140,8 +150,9 @@ function user_angeltype_confirm_controller() {
}
$user_source = User($user_angeltype['user_id']);
- if ($user_source === false)
+ if ($user_source === false) {
engelsystem_error("Unable to load user.");
+ }
if ($user_source == null) {
error(_("User doesn't exist."));
redirect(page_link_to('angeltypes'));
@@ -149,18 +160,19 @@ function user_angeltype_confirm_controller() {
if (isset($_REQUEST['confirmed'])) {
$result = UserAngelType_confirm($user_angeltype['id'], $user);
- if ($result === false)
+ 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 array(
+ return [
_("Confirm angeltype for user"),
UserAngelType_confirm_view($user_angeltype, $user_source, $angeltype)
- );
+ ];
}
/**
@@ -175,24 +187,27 @@ function user_angeltype_delete_controller() {
}
$user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']);
- if ($user_angeltype === false)
+ if ($user_angeltype === false) {
engelsystem_error("Unable to load user angeltype.");
+ }
if ($user_angeltype == null) {
error(_("User angeltype doesn't exist."));
redirect(page_link_to('angeltypes'));
}
$angeltype = AngelType($user_angeltype['angeltype_id']);
- if ($angeltype === false)
+ if ($angeltype === false) {
engelsystem_error("Unable to load angeltype.");
+ }
if ($angeltype == null) {
error(_("Angeltype doesn't exist."));
redirect(page_link_to('angeltypes'));
}
$user_source = User($user_angeltype['user_id']);
- if ($user_source === false)
+ if ($user_source === false) {
engelsystem_error("Unable to load user.");
+ }
if ($user_source == null) {
error(_("User doesn't exist."));
redirect(page_link_to('angeltypes'));
@@ -205,8 +220,9 @@ function user_angeltype_delete_controller() {
if (isset($_REQUEST['confirmed'])) {
$result = UserAngelType_delete($user_angeltype);
- if ($result === false)
+ 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);
@@ -215,10 +231,10 @@ function user_angeltype_delete_controller() {
redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
}
- return array(
+ return [
_("Remove angeltype"),
UserAngelType_delete_view($user_angeltype, $user_source, $angeltype)
- );
+ ];
}
/**
@@ -237,32 +253,35 @@ function user_angeltype_update_controller() {
redirect(page_link_to('angeltypes'));
}
- if (isset($_REQUEST['coordinator']) && preg_match("/^[01]$/", $_REQUEST['coordinator']))
+ if (isset($_REQUEST['coordinator']) && preg_match("/^[01]$/", $_REQUEST['coordinator'])) {
$coordinator = $_REQUEST['coordinator'] == "1";
- else {
+ } else {
error(_("No coordinator update given."));
redirect(page_link_to('angeltypes'));
}
$user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']);
- if ($user_angeltype === false)
+ if ($user_angeltype === false) {
engelsystem_error("Unable to load user angeltype.");
+ }
if ($user_angeltype == null) {
error(_("User angeltype doesn't exist."));
redirect(page_link_to('angeltypes'));
}
$angeltype = AngelType($user_angeltype['angeltype_id']);
- if ($angeltype === false)
+ if ($angeltype === false) {
engelsystem_error("Unable to load angeltype.");
+ }
if ($angeltype == null) {
error(_("Angeltype doesn't exist."));
redirect(page_link_to('angeltypes'));
}
$user_source = User($user_angeltype['user_id']);
- if ($user_source === false)
+ if ($user_source === false) {
engelsystem_error("Unable to load user.");
+ }
if ($user_source == null) {
error(_("User doesn't exist."));
redirect(page_link_to('angeltypes'));
@@ -270,8 +289,9 @@ function user_angeltype_update_controller() {
if (isset($_REQUEST['confirmed'])) {
$result = UserAngelType_update($user_angeltype['id'], $coordinator);
- if ($result === false)
+ if ($result === false) {
engelsystem_error("Unable to update coordinator rights.");
+ }
$success_message = sprintf($coordinator ? _("Added coordinator rights for %s to %s.") : _("Removed coordinator rights for %s from %s."), AngelType_name_render($angeltype), User_Nick_render($user_source));
engelsystem_log($success_message);
@@ -280,10 +300,10 @@ function user_angeltype_update_controller() {
redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
}
- return array(
+ return [
$coordinator ? _("Add coordinator rights") : _("Remove coordinator rights"),
UserAngelType_update_view($user_angeltype, $user_source, $angeltype, $coordinator)
- );
+ ];
}
/**
@@ -298,8 +318,9 @@ function user_angeltype_add_controller() {
}
$angeltype = AngelType($_REQUEST['angeltype_id']);
- if ($angeltype === false)
+ if ($angeltype === false) {
engelsystem_error("Unable to load angeltype.");
+ }
if ($angeltype == null) {
error(_("Angeltype doesn't exist."));
redirect(page_link_to('angeltypes'));
@@ -310,50 +331,55 @@ function user_angeltype_add_controller() {
$user_id = $user['UID'];
$users_source = Users_by_angeltype_inverted($angeltype);
- if ($users_source === false)
+ if ($users_source === false) {
engelsystem_error("Unable to load users.");
+ }
if (isset($_REQUEST['submit'])) {
$ok = true;
if (isset($_REQUEST['user_id']) && in_array($_REQUEST['user_id'], array_map(function ($user) {
return $user['UID'];
- }, $users_source)))
+ }, $users_source))) {
$user_id = $_REQUEST['user_id'];
- else {
+ } else {
$ok = false;
error(_("Please select a user."));
}
if ($ok) {
- foreach ($users_source as $user_source)
+ foreach ($users_source as $user_source) {
if ($user_source['UID'] == $user_id) {
$user_angeltype_id = UserAngelType_create($user_source, $angeltype);
- if ($user_angeltype_id === false)
+ if ($user_angeltype_id === false) {
engelsystem_error("Unable to create user 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)));
$result = UserAngelType_confirm($user_angeltype_id, $user_source);
- if ($result === false)
+ if ($result === false) {
engelsystem_error("Unable to confirm user angeltype.");
+ }
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 array(
+ return [
_("Add user to angeltype"),
UserAngelType_add_view($angeltype, $users_source, $user_id)
- );
+ ];
} else {
// Allow only me
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
- if ($user_angeltype === false)
+ if ($user_angeltype === false) {
engelsystem_error("Unable to load user angeltype.");
+ }
if ($user_angeltype != null) {
error(sprintf(_("You are already a %s."), $angeltype['name']));
redirect(page_link_to('angeltypes'));
@@ -361,8 +387,9 @@ function user_angeltype_add_controller() {
if (isset($_REQUEST['confirmed'])) {
$user_angeltype_id = UserAngelType_create($user, $angeltype);
- if ($user_angeltype_id === false)
+ if ($user_angeltype_id === false) {
engelsystem_error("Unable to 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)));
@@ -370,18 +397,19 @@ function user_angeltype_add_controller() {
if (in_array('admin_user_angeltypes', $privileges)) {
$result = UserAngelType_confirm($user_angeltype_id, $user);
- if ($result === false)
+ if ($result === false) {
engelsystem_error("Unable to confirm user angeltype.");
+ }
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 array(
+ return [
sprintf(_("Become a %s"), $angeltype['name']),
UserAngelType_join_view($user, $angeltype)
- );
+ ];
}
}
@@ -389,8 +417,9 @@ function user_angeltype_add_controller() {
* Route UserAngelType actions.
*/
function user_angeltypes_controller() {
- if (! isset($_REQUEST['action']))
+ if (! isset($_REQUEST['action'])) {
redirect(page_link_to('angeltypes'));
+ }
switch ($_REQUEST['action']) {
case 'delete_all':
diff --git a/includes/controller/user_driver_licenses_controller.php b/includes/controller/user_driver_licenses_controller.php
index 0118eeb4..62e491f1 100644
--- a/includes/controller/user_driver_licenses_controller.php
+++ b/includes/controller/user_driver_licenses_controller.php
@@ -7,21 +7,25 @@ function user_driver_license_required_hint() {
global $user;
$angeltypes = User_angeltypes($user);
- if ($angeltypes === false)
+ if ($angeltypes === false) {
engelsystem_error("Unable to load user angeltypes.");
+ }
$user_driver_license = UserDriverLicense($user['UID']);
- if ($user_driver_license === false)
+ if ($user_driver_license === false) {
engelsystem_error("Unable to load user driver license.");
+ }
$driving_license_information_required = false;
- foreach ($angeltypes as $angeltype)
+ foreach ($angeltypes as $angeltype) {
if ($angeltype['requires_driver_license']) {
$driving_license_information_required = true;
break;
}
+ }
- if ($driving_license_information_required && $user_driver_license == null)
+ if ($driving_license_information_required && $user_driver_license == null) {
return info(sprintf(_("You joined an angeltype which requires a driving license. Please edit your driving license information here: %s."), '' . _("driving license information") . ''), true);
+ }
return '';
}
@@ -32,11 +36,13 @@ function user_driver_license_required_hint() {
function user_driver_licenses_controller() {
global $user;
- if (! isset($user))
+ if (! isset($user)) {
redirect(page_link_to(''));
+ }
- if (! isset($_REQUEST['action']))
+ if (! isset($_REQUEST['action'])) {
$_REQUEST['action'] = 'edit';
+ }
switch ($_REQUEST['action']) {
default:
@@ -51,8 +57,9 @@ function user_driver_licenses_controller() {
* @param User $user
*/
function user_driver_license_edit_link($user = null) {
- if ($user == null)
+ if ($user == null) {
return page_link_to('user_driver_licenses');
+ }
return page_link_to('user_driver_licenses') . '&user_id=' . $user['UID'];
}
@@ -64,14 +71,17 @@ function user_driver_license_edit_controller() {
if (isset($_REQUEST['user_id'])) {
$user_source = User($_REQUEST['user_id']);
- if ($user_source === false)
+ if ($user_source === false) {
engelsystem_error('Unable to load angeltype.');
- if ($user_source == null)
+ }
+ if ($user_source == null) {
redirect(user_driver_license_edit_link());
-
- // only privilege admin_user can edit other users driver license information
- if ($user['UID'] != $user_source['UID'] && ! in_array('admin_user', $privileges))
+ }
+
+ // 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());
+ }
} else {
$user_source = $user;
}
@@ -85,8 +95,9 @@ function user_driver_license_edit_controller() {
$has_license_forklift = false;
$user_driver_license = UserDriverLicense($user_source['UID']);
- if ($user_driver_license === false)
+ if ($user_driver_license === false) {
engelsystem_error('Unable to load user driver license.');
+ }
if ($user_driver_license != null) {
$wants_to_drive = true;
$has_car = $user_driver_license['has_car'];
@@ -115,19 +126,22 @@ function user_driver_license_edit_controller() {
if ($ok) {
if (! $wants_to_drive && $user_driver_license != null) {
$result = UserDriverLicenses_delete($user_source['UID']);
- if ($result === false)
+ if ($result === false) {
engelsystem_error("Unable to remove user driver license information");
+ }
engelsystem_log("Driver license information removed.");
success(_("Your driver license information has been removed."));
} else {
if ($wants_to_drive) {
- if ($user_driver_license == null)
+ if ($user_driver_license == null) {
$result = UserDriverLicenses_create($user_source['UID'], $has_car, $has_license_car, $has_license_3_5t_transporter, $has_license_7_5t_truck, $has_license_12_5t_truck, $has_license_forklift);
- else
+ } else {
$result = UserDriverLicenses_update($user_source['UID'], $has_car, $has_license_car, $has_license_3_5t_transporter, $has_license_7_5t_truck, $has_license_12_5t_truck, $has_license_forklift);
+ }
- if ($result === false)
+ if ($result === false) {
engelsystem_error("Unable to save user driver license information.");
+ }
engelsystem_log("Driver license information updated.");
}
success(_("Your driver license information has been saved."));
diff --git a/includes/controller/users_controller.php b/includes/controller/users_controller.php
index 672cbb0f..512a5723 100644
--- a/includes/controller/users_controller.php
+++ b/includes/controller/users_controller.php
@@ -6,11 +6,13 @@
function users_controller() {
global $user;
- if (! isset($user))
+ if (! isset($user)) {
redirect(page_link_to(''));
+ }
- if (! isset($_REQUEST['action']))
+ if (! isset($_REQUEST['action'])) {
$_REQUEST['action'] = 'list';
+ }
switch ($_REQUEST['action']) {
default:
@@ -35,13 +37,15 @@ function user_delete_controller() {
if (isset($_REQUEST['user_id'])) {
$user_source = User($_REQUEST['user_id']);
- } else
+ } else {
$user_source = $user;
+ }
- if (! in_array('admin_user', $privileges))
+ if (! in_array('admin_user', $privileges)) {
redirect(page_link_to(''));
-
- // You cannot delete yourself
+ }
+
+ // You cannot delete yourself
if ($user['UID'] == $user_source['UID']) {
error(_("You cannot delete yourself."));
redirect(user_link($user));
@@ -57,8 +61,9 @@ function user_delete_controller() {
if ($ok) {
$result = User_delete($user_source['UID']);
- if ($result === false)
+ if ($result === false) {
engelsystem_error('Unable to delete user.');
+ }
mail_user_delete($user_source);
success(_("User deleted."));
@@ -68,10 +73,10 @@ function user_delete_controller() {
}
}
- return array(
+ return [
sprintf(_("Delete %s"), $user_source['Nick']),
User_delete_view($user_source)
- );
+ ];
}
function users_link() {
@@ -95,18 +100,20 @@ function user_edit_vouchers_controller() {
if (isset($_REQUEST['user_id'])) {
$user_source = User($_REQUEST['user_id']);
- } else
+ } else {
$user_source = $user;
+ }
- if (! in_array('admin_user', $privileges))
+ if (! in_array('admin_user', $privileges)) {
redirect(page_link_to(''));
+ }
if (isset($_REQUEST['submit'])) {
$ok = true;
- if (isset($_REQUEST['vouchers']) && test_request_int('vouchers') && trim($_REQUEST['vouchers']) >= 0)
+ if (isset($_REQUEST['vouchers']) && test_request_int('vouchers') && trim($_REQUEST['vouchers']) >= 0) {
$vouchers = trim($_REQUEST['vouchers']);
- else {
+ } else {
$ok = false;
error(_("Please enter a valid number of vouchers."));
}
@@ -115,8 +122,9 @@ function user_edit_vouchers_controller() {
$user_source['got_voucher'] = $vouchers;
$result = User_update($user_source);
- if ($result === false)
+ 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']));
@@ -125,10 +133,10 @@ function user_edit_vouchers_controller() {
}
}
- return array(
+ return [
sprintf(_("%s's vouchers"), $user_source['Nick']),
User_edit_vouchers_view($user_source)
- );
+ ];
}
function user_controller() {
@@ -136,14 +144,16 @@ function user_controller() {
if (isset($_REQUEST['user_id'])) {
$user_source = User($_REQUEST['user_id']);
- if ($user_source === false)
+ if ($user_source === false) {
engelsystem_error("Unable to load user.");
+ }
if ($user_source == null) {
error(_("User not found."));
redirect('?');
}
- } else
+ } else {
$user_source = $user;
+ }
$shifts = Shifts_by_user($user_source);
foreach ($shifts as &$shift) {
@@ -159,13 +169,14 @@ function user_controller() {
}
}
- if ($user_source['api_key'] == "")
+ if ($user_source['api_key'] == "") {
User_reset_api_key($user_source, false);
+ }
- return array(
+ 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'])
- );
+ ];
}
/**
@@ -174,24 +185,28 @@ function user_controller() {
function users_list_controller() {
global $privileges;
- if (! in_array('admin_user', $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()))
+ if (isset($_REQUEST['OrderBy']) && in_array($_REQUEST['OrderBy'], User_sortable_columns())) {
$order_by = $_REQUEST['OrderBy'];
+ }
$users = Users($order_by);
- if ($users === false)
+ if ($users === false) {
engelsystem_error('Unable to load users.');
+ }
- foreach ($users as &$user)
+ foreach ($users as &$user) {
$user['freeloads'] = count(ShiftEntries_freeloaded_by_user($user));
+ }
- return array(
+ 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())
- );
+ ];
}
/**
@@ -201,8 +216,9 @@ function users_list_controller() {
function user_password_recovery_controller() {
if (isset($_REQUEST['token'])) {
$user_source = User_by_password_recovery_token($_REQUEST['token']);
- if ($user_source === false)
+ if ($user_source === false) {
engelsystem_error("Unable to load user.");
+ }
if ($user_source == null) {
error(_("Token is not correct."));
redirect(page_link_to('login'));
@@ -223,8 +239,9 @@ function user_password_recovery_controller() {
if ($ok) {
$result = set_password($user_source['UID'], $_REQUEST['password']);
- if ($result === false)
+ if ($result === false) {
engelsystem_error(_("Password could not be updated."));
+ }
success(_("Password saved."));
redirect(page_link_to('login'));
@@ -240,8 +257,9 @@ function user_password_recovery_controller() {
$email = strip_request_item('email');
if (check_email($email)) {
$user_source = User_by_email($email);
- if ($user_source === false)
+ if ($user_source === false) {
engelsystem_error("Unable to load user.");
+ }
if ($user_source == null) {
$ok = false;
error(_("E-mail address is not correct."));
@@ -257,11 +275,13 @@ function user_password_recovery_controller() {
if ($ok) {
$token = User_generate_password_recovery_token($user_source);
- if ($token === false)
+ if ($token === false) {
engelsystem_error("Unable to generate password recovery token.");
+ }
$result = 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));
- if ($result === false)
+ if ($result === false) {
engelsystem_error("Unable to send password recovery email.");
+ }
success(_("We sent an email containing your password recovery link."));
redirect(page_link_to('login'));