@ -7,14 +7,17 @@ function user_angeltypes_unconfirmed_hint() {
global $user;
global $user;
$unconfirmed_user_angeltypes = User_unconfirmed_AngelTypes($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.");
engelsystem_error("Unable to load user angeltypes.");
if (count($unconfirmed_user_angeltypes) == 0)
}
if (count($unconfirmed_user_angeltypes) == 0) {
return '';
return '';
}
$unconfirmed_links = [];
$unconfirmed_links = [];
foreach ($unconfirmed_user_angeltypes as $user_angeltype)
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 > ';
$unconfirmed_links[] = '< a href = "' . page_link_to('angeltypes') . '&action=view&angeltype_id=' . $user_angeltype['angeltype_id'] . '" > ' . $user_angeltype['name'] . ' (+' . $user_angeltype['count'] . ')' . '< / a > ';
}
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);
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']);
$angeltype = AngelType($_REQUEST['angeltype_id']);
if ($angeltype === false)
if ($angeltype === false) {
engelsystem_error("Unable to load angeltype.");
engelsystem_error("Unable to load angeltype.");
}
if ($angeltype == null) {
if ($angeltype == null) {
error(_("Angeltype doesn't exist."));
error(_("Angeltype doesn't exist."));
redirect(page_link_to('angeltypes'));
redirect(page_link_to('angeltypes'));
@ -45,18 +49,19 @@ function user_angeltypes_delete_all_controller() {
if (isset($_REQUEST['confirmed'])) {
if (isset($_REQUEST['confirmed'])) {
$result = UserAngelTypes_delete_all($angeltype['id']);
$result = UserAngelTypes_delete_all($angeltype['id']);
if ($result === false)
if ($result === false) {
engelsystem_error("Unable to confirm all users.");
engelsystem_error("Unable to confirm all users.");
}
engelsystem_log(sprintf("Denied all users for angeltype %s", AngelType_name_render($angeltype)));
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)));
success(sprintf(_("Denied all users for angeltype %s."), AngelType_name_render($angeltype)));
redirect(page_link_to('angeltypes') . '& action=view& angeltype_id=' . $angeltype['id']);
redirect(page_link_to('angeltypes') . '& action=view& angeltype_id=' . $angeltype['id']);
}
}
return array(
return [
_("Deny all users"),
_("Deny all users"),
UserAngelTypes_delete_all_view($angeltype)
UserAngelTypes_delete_all_view($angeltype)
) ;
] ;
}
}
/**
/**
@ -71,16 +76,18 @@ function user_angeltypes_confirm_all_controller() {
}
}
$angeltype = AngelType($_REQUEST['angeltype_id']);
$angeltype = AngelType($_REQUEST['angeltype_id']);
if ($angeltype === false)
if ($angeltype === false) {
engelsystem_error("Unable to load angeltype.");
engelsystem_error("Unable to load angeltype.");
}
if ($angeltype == null) {
if ($angeltype == null) {
error(_("Angeltype doesn't exist."));
error(_("Angeltype doesn't exist."));
redirect(page_link_to('angeltypes'));
redirect(page_link_to('angeltypes'));
}
}
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
if ($user_angeltype === false)
if ($user_angeltype === false) {
engelsystem_error("Unable to load user angeltype.");
engelsystem_error("Unable to load user angeltype.");
}
if ($user_angeltype == null) {
if ($user_angeltype == null) {
error(_("User angeltype doesn't exist."));
error(_("User angeltype doesn't exist."));
redirect(page_link_to('angeltypes'));
redirect(page_link_to('angeltypes'));
@ -93,18 +100,19 @@ function user_angeltypes_confirm_all_controller() {
if (isset($_REQUEST['confirmed'])) {
if (isset($_REQUEST['confirmed'])) {
$result = UserAngelTypes_confirm_all($angeltype['id'], $user);
$result = UserAngelTypes_confirm_all($angeltype['id'], $user);
if ($result === false)
if ($result === false) {
engelsystem_error("Unable to confirm all users.");
engelsystem_error("Unable to confirm all users.");
}
engelsystem_log(sprintf("Confirmed all users for angeltype %s", AngelType_name_render($angeltype)));
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)));
success(sprintf(_("Confirmed all users for angeltype %s."), AngelType_name_render($angeltype)));
redirect(page_link_to('angeltypes') . '& action=view& angeltype_id=' . $angeltype['id']);
redirect(page_link_to('angeltypes') . '& action=view& angeltype_id=' . $angeltype['id']);
}
}
return array(
return [
_("Confirm all users"),
_("Confirm all users"),
UserAngelTypes_confirm_all_view($angeltype)
UserAngelTypes_confirm_all_view($angeltype)
) ;
] ;
}
}
/**
/**
@ -119,16 +127,18 @@ function user_angeltype_confirm_controller() {
}
}
$user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']);
$user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']);
if ($user_angeltype === false)
if ($user_angeltype === false) {
engelsystem_error("Unable to load user angeltype.");
engelsystem_error("Unable to load user angeltype.");
}
if ($user_angeltype == null) {
if ($user_angeltype == null) {
error(_("User angeltype doesn't exist."));
error(_("User angeltype doesn't exist."));
redirect(page_link_to('angeltypes'));
redirect(page_link_to('angeltypes'));
}
}
$angeltype = AngelType($user_angeltype['angeltype_id']);
$angeltype = AngelType($user_angeltype['angeltype_id']);
if ($angeltype === false)
if ($angeltype === false) {
engelsystem_error("Unable to load angeltype.");
engelsystem_error("Unable to load angeltype.");
}
if ($angeltype == null) {
if ($angeltype == null) {
error(_("Angeltype doesn't exist."));
error(_("Angeltype doesn't exist."));
redirect(page_link_to('angeltypes'));
redirect(page_link_to('angeltypes'));
@ -140,8 +150,9 @@ function user_angeltype_confirm_controller() {
}
}
$user_source = User($user_angeltype['user_id']);
$user_source = User($user_angeltype['user_id']);
if ($user_source === false)
if ($user_source === false) {
engelsystem_error("Unable to load user.");
engelsystem_error("Unable to load user.");
}
if ($user_source == null) {
if ($user_source == null) {
error(_("User doesn't exist."));
error(_("User doesn't exist."));
redirect(page_link_to('angeltypes'));
redirect(page_link_to('angeltypes'));
@ -149,18 +160,19 @@ function user_angeltype_confirm_controller() {
if (isset($_REQUEST['confirmed'])) {
if (isset($_REQUEST['confirmed'])) {
$result = UserAngelType_confirm($user_angeltype['id'], $user);
$result = UserAngelType_confirm($user_angeltype['id'], $user);
if ($result === false)
if ($result === false) {
engelsystem_error("Unable to confirm user angeltype.");
engelsystem_error("Unable to confirm user angeltype.");
}
engelsystem_log(sprintf("%s confirmed for angeltype %s", User_Nick_render($user_source), AngelType_name_render($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)));
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']);
redirect(page_link_to('angeltypes') . '& action=view& angeltype_id=' . $angeltype['id']);
}
}
return array(
return [
_("Confirm angeltype for user"),
_("Confirm angeltype for user"),
UserAngelType_confirm_view($user_angeltype, $user_source, $angeltype)
UserAngelType_confirm_view($user_angeltype, $user_source, $angeltype)
) ;
] ;
}
}
/**
/**
@ -175,24 +187,27 @@ function user_angeltype_delete_controller() {
}
}
$user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']);
$user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']);
if ($user_angeltype === false)
if ($user_angeltype === false) {
engelsystem_error("Unable to load user angeltype.");
engelsystem_error("Unable to load user angeltype.");
}
if ($user_angeltype == null) {
if ($user_angeltype == null) {
error(_("User angeltype doesn't exist."));
error(_("User angeltype doesn't exist."));
redirect(page_link_to('angeltypes'));
redirect(page_link_to('angeltypes'));
}
}
$angeltype = AngelType($user_angeltype['angeltype_id']);
$angeltype = AngelType($user_angeltype['angeltype_id']);
if ($angeltype === false)
if ($angeltype === false) {
engelsystem_error("Unable to load angeltype.");
engelsystem_error("Unable to load angeltype.");
}
if ($angeltype == null) {
if ($angeltype == null) {
error(_("Angeltype doesn't exist."));
error(_("Angeltype doesn't exist."));
redirect(page_link_to('angeltypes'));
redirect(page_link_to('angeltypes'));
}
}
$user_source = User($user_angeltype['user_id']);
$user_source = User($user_angeltype['user_id']);
if ($user_source === false)
if ($user_source === false) {
engelsystem_error("Unable to load user.");
engelsystem_error("Unable to load user.");
}
if ($user_source == null) {
if ($user_source == null) {
error(_("User doesn't exist."));
error(_("User doesn't exist."));
redirect(page_link_to('angeltypes'));
redirect(page_link_to('angeltypes'));
@ -205,8 +220,9 @@ function user_angeltype_delete_controller() {
if (isset($_REQUEST['confirmed'])) {
if (isset($_REQUEST['confirmed'])) {
$result = UserAngelType_delete($user_angeltype);
$result = UserAngelType_delete($user_angeltype);
if ($result === false)
if ($result === false) {
engelsystem_error("Unable to delete user angeltype.");
engelsystem_error("Unable to delete user angeltype.");
}
$success_message = sprintf(_("User %s removed from %s."), User_Nick_render($user_source), $angeltype['name']);
$success_message = sprintf(_("User %s removed from %s."), User_Nick_render($user_source), $angeltype['name']);
engelsystem_log($success_message);
engelsystem_log($success_message);
@ -215,10 +231,10 @@ function user_angeltype_delete_controller() {
redirect(page_link_to('angeltypes') . '& action=view& angeltype_id=' . $angeltype['id']);
redirect(page_link_to('angeltypes') . '& action=view& angeltype_id=' . $angeltype['id']);
}
}
return array(
return [
_("Remove angeltype"),
_("Remove angeltype"),
UserAngelType_delete_view($user_angeltype, $user_source, $angeltype)
UserAngelType_delete_view($user_angeltype, $user_source, $angeltype)
) ;
] ;
}
}
/**
/**
@ -237,32 +253,35 @@ function user_angeltype_update_controller() {
redirect(page_link_to('angeltypes'));
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";
$coordinator = $_REQUEST['coordinator'] == "1";
else {
} else {
error(_("No coordinator update given."));
error(_("No coordinator update given."));
redirect(page_link_to('angeltypes'));
redirect(page_link_to('angeltypes'));
}
}
$user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']);
$user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']);
if ($user_angeltype === false)
if ($user_angeltype === false) {
engelsystem_error("Unable to load user angeltype.");
engelsystem_error("Unable to load user angeltype.");
}
if ($user_angeltype == null) {
if ($user_angeltype == null) {
error(_("User angeltype doesn't exist."));
error(_("User angeltype doesn't exist."));
redirect(page_link_to('angeltypes'));
redirect(page_link_to('angeltypes'));
}
}
$angeltype = AngelType($user_angeltype['angeltype_id']);
$angeltype = AngelType($user_angeltype['angeltype_id']);
if ($angeltype === false)
if ($angeltype === false) {
engelsystem_error("Unable to load angeltype.");
engelsystem_error("Unable to load angeltype.");
}
if ($angeltype == null) {
if ($angeltype == null) {
error(_("Angeltype doesn't exist."));
error(_("Angeltype doesn't exist."));
redirect(page_link_to('angeltypes'));
redirect(page_link_to('angeltypes'));
}
}
$user_source = User($user_angeltype['user_id']);
$user_source = User($user_angeltype['user_id']);
if ($user_source === false)
if ($user_source === false) {
engelsystem_error("Unable to load user.");
engelsystem_error("Unable to load user.");
}
if ($user_source == null) {
if ($user_source == null) {
error(_("User doesn't exist."));
error(_("User doesn't exist."));
redirect(page_link_to('angeltypes'));
redirect(page_link_to('angeltypes'));
@ -270,8 +289,9 @@ function user_angeltype_update_controller() {
if (isset($_REQUEST['confirmed'])) {
if (isset($_REQUEST['confirmed'])) {
$result = UserAngelType_update($user_angeltype['id'], $coordinator);
$result = UserAngelType_update($user_angeltype['id'], $coordinator);
if ($result === false)
if ($result === false) {
engelsystem_error("Unable to update coordinator rights.");
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));
$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);
engelsystem_log($success_message);
@ -280,10 +300,10 @@ function user_angeltype_update_controller() {
redirect(page_link_to('angeltypes') . '& action=view& angeltype_id=' . $angeltype['id']);
redirect(page_link_to('angeltypes') . '& action=view& angeltype_id=' . $angeltype['id']);
}
}
return array(
return [
$coordinator ? _("Add coordinator rights") : _("Remove coordinator rights"),
$coordinator ? _("Add coordinator rights") : _("Remove coordinator rights"),
UserAngelType_update_view($user_angeltype, $user_source, $angeltype, $coordinator)
UserAngelType_update_view($user_angeltype, $user_source, $angeltype, $coordinator)
) ;
] ;
}
}
/**
/**
@ -298,8 +318,9 @@ function user_angeltype_add_controller() {
}
}
$angeltype = AngelType($_REQUEST['angeltype_id']);
$angeltype = AngelType($_REQUEST['angeltype_id']);
if ($angeltype === false)
if ($angeltype === false) {
engelsystem_error("Unable to load angeltype.");
engelsystem_error("Unable to load angeltype.");
}
if ($angeltype == null) {
if ($angeltype == null) {
error(_("Angeltype doesn't exist."));
error(_("Angeltype doesn't exist."));
redirect(page_link_to('angeltypes'));
redirect(page_link_to('angeltypes'));
@ -310,50 +331,55 @@ function user_angeltype_add_controller() {
$user_id = $user['UID'];
$user_id = $user['UID'];
$users_source = Users_by_angeltype_inverted($angeltype);
$users_source = Users_by_angeltype_inverted($angeltype);
if ($users_source === false)
if ($users_source === false) {
engelsystem_error("Unable to load users.");
engelsystem_error("Unable to load users.");
}
if (isset($_REQUEST['submit'])) {
if (isset($_REQUEST['submit'])) {
$ok = true;
$ok = true;
if (isset($_REQUEST['user_id']) & & in_array($_REQUEST['user_id'], array_map(function ($user) {
if (isset($_REQUEST['user_id']) & & in_array($_REQUEST['user_id'], array_map(function ($user) {
return $user['UID'];
return $user['UID'];
}, $users_source)))
}, $users_source))) {
$user_id = $_REQUEST['user_id'];
$user_id = $_REQUEST['user_id'];
else {
} else {
$ok = false;
$ok = false;
error(_("Please select a user."));
error(_("Please select a user."));
}
}
if ($ok) {
if ($ok) {
foreach ($users_source as $user_source)
foreach ($users_source as $user_source) {
if ($user_source['UID'] == $user_id) {
if ($user_source['UID'] == $user_id) {
$user_angeltype_id = UserAngelType_create($user_source, $angeltype);
$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_error("Unable to create user angeltype.");
}
engelsystem_log(sprintf("User %s added to %s.", User_Nick_render($user_source), AngelType_name_render($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)));
success(sprintf(_("User %s added to %s."), User_Nick_render($user_source), AngelType_name_render($angeltype)));
$result = UserAngelType_confirm($user_angeltype_id, $user_source);
$result = UserAngelType_confirm($user_angeltype_id, $user_source);
if ($result === false)
if ($result === false) {
engelsystem_error("Unable to confirm user angeltype.");
engelsystem_error("Unable to confirm user angeltype.");
}
engelsystem_log(sprintf("User %s confirmed as %s.", User_Nick_render($user), AngelType_name_render($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']);
redirect(page_link_to('angeltypes') . '& action=view& angeltype_id=' . $angeltype['id']);
}
}
}
}
}
}
}
return array(
return [
_("Add user to angeltype"),
_("Add user to angeltype"),
UserAngelType_add_view($angeltype, $users_source, $user_id)
UserAngelType_add_view($angeltype, $users_source, $user_id)
) ;
] ;
} else {
} else {
// Allow only me
// Allow only me
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
if ($user_angeltype === false)
if ($user_angeltype === false) {
engelsystem_error("Unable to load user angeltype.");
engelsystem_error("Unable to load user angeltype.");
}
if ($user_angeltype != null) {
if ($user_angeltype != null) {
error(sprintf(_("You are already a %s."), $angeltype['name']));
error(sprintf(_("You are already a %s."), $angeltype['name']));
redirect(page_link_to('angeltypes'));
redirect(page_link_to('angeltypes'));
@ -361,8 +387,9 @@ function user_angeltype_add_controller() {
if (isset($_REQUEST['confirmed'])) {
if (isset($_REQUEST['confirmed'])) {
$user_angeltype_id = UserAngelType_create($user, $angeltype);
$user_angeltype_id = UserAngelType_create($user, $angeltype);
if ($user_angeltype_id === false)
if ($user_angeltype_id === false) {
engelsystem_error("Unable to create user angeltype.");
engelsystem_error("Unable to create user angeltype.");
}
$success_message = sprintf(_("You joined %s."), $angeltype['name']);
$success_message = sprintf(_("You joined %s."), $angeltype['name']);
engelsystem_log(sprintf("User %s joined %s.", User_Nick_render($user), AngelType_name_render($angeltype)));
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)) {
if (in_array('admin_user_angeltypes', $privileges)) {
$result = UserAngelType_confirm($user_angeltype_id, $user);
$result = UserAngelType_confirm($user_angeltype_id, $user);
if ($result === false)
if ($result === false) {
engelsystem_error("Unable to confirm user angeltype.");
engelsystem_error("Unable to confirm user angeltype.");
}
engelsystem_log(sprintf("User %s confirmed as %s.", User_Nick_render($user), AngelType_name_render($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']);
redirect(page_link_to('angeltypes') . '& action=view& angeltype_id=' . $angeltype['id']);
}
}
return array(
return [
sprintf(_("Become a %s"), $angeltype['name']),
sprintf(_("Become a %s"), $angeltype['name']),
UserAngelType_join_view($user, $angeltype)
UserAngelType_join_view($user, $angeltype)
) ;
] ;
}
}
}
}
@ -389,8 +417,9 @@ function user_angeltype_add_controller() {
* Route UserAngelType actions.
* Route UserAngelType actions.
*/
*/
function user_angeltypes_controller() {
function user_angeltypes_controller() {
if (! isset($_REQUEST['action']))
if (! isset($_REQUEST['action'])) {
redirect(page_link_to('angeltypes'));
redirect(page_link_to('angeltypes'));
}
switch ($_REQUEST['action']) {
switch ($_REQUEST['action']) {
case 'delete_all':
case 'delete_all':