|
|
@ -310,107 +310,94 @@ function user_angeltype_update_controller() {
|
|
|
|
* User joining an Angeltype (Or Coordinator doing this for him).
|
|
|
|
* User joining an Angeltype (Or Coordinator doing this for him).
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function user_angeltype_add_controller() {
|
|
|
|
function user_angeltype_add_controller() {
|
|
|
|
global $user, $privileges;
|
|
|
|
global $user;
|
|
|
|
|
|
|
|
|
|
|
|
if (! isset($_REQUEST['angeltype_id'])) {
|
|
|
|
$angeltype = load_angeltype();
|
|
|
|
error(_("Angeltype doesn't exist."));
|
|
|
|
|
|
|
|
redirect(page_link_to('angeltypes'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$angeltype = AngelType($_REQUEST['angeltype_id']);
|
|
|
|
// User is joining by itself
|
|
|
|
if ($angeltype === false) {
|
|
|
|
if (! User_is_AngelType_coordinator($user, $angeltype)) {
|
|
|
|
engelsystem_error("Unable to load angeltype.");
|
|
|
|
return user_angeltype_join_controller($angeltype);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($angeltype == null) {
|
|
|
|
|
|
|
|
error(_("Angeltype doesn't exist."));
|
|
|
|
// Allow to add any user
|
|
|
|
redirect(page_link_to('angeltypes'));
|
|
|
|
|
|
|
|
|
|
|
|
// Default selection
|
|
|
|
|
|
|
|
$user_source = $user;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Load possible users, that are not in the angeltype already
|
|
|
|
|
|
|
|
$users_source = Users_by_angeltype_inverted($angeltype);
|
|
|
|
|
|
|
|
if ($users_source === false) {
|
|
|
|
|
|
|
|
engelsystem_error("Unable to load users.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (User_is_AngelType_coordinator($user, $angeltype)) {
|
|
|
|
if (isset($_REQUEST['submit'])) {
|
|
|
|
// Allow to add any user
|
|
|
|
$user_source = load_user();
|
|
|
|
$user_id = $user['UID'];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$users_source = Users_by_angeltype_inverted($angeltype);
|
|
|
|
|
|
|
|
if ($users_source === false) {
|
|
|
|
|
|
|
|
engelsystem_error("Unable to load users.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isset($_REQUEST['submit'])) {
|
|
|
|
|
|
|
|
$valid = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isset($_REQUEST['user_id']) && in_array($_REQUEST['user_id'], array_map(function ($user) {
|
|
|
|
|
|
|
|
return $user['UID'];
|
|
|
|
|
|
|
|
}, $users_source))) {
|
|
|
|
|
|
|
|
$user_id = $_REQUEST['user_id'];
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$valid = false;
|
|
|
|
|
|
|
|
error(_("Please select a user."));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($valid) {
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
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 [
|
|
|
|
|
|
|
|
_("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) {
|
|
|
|
|
|
|
|
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'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isset($_REQUEST['confirmed'])) {
|
|
|
|
if (! UserAngelType_exists($user_source, $angeltype)) {
|
|
|
|
$user_angeltype_id = UserAngelType_create($user, $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.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$success_message = sprintf(_("You joined %s."), $angeltype['name']);
|
|
|
|
engelsystem_log(sprintf("User %s added to %s.", User_Nick_render($user_source), AngelType_name_render($angeltype)));
|
|
|
|
engelsystem_log(sprintf("User %s joined %s.", User_Nick_render($user), AngelType_name_render($angeltype)));
|
|
|
|
success(sprintf(_("User %s added to %s."), User_Nick_render($user_source), AngelType_name_render($angeltype)));
|
|
|
|
success($success_message);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (in_array('admin_user_angeltypes', $privileges)) {
|
|
|
|
$result = UserAngelType_confirm($user_angeltype_id, $user_source);
|
|
|
|
$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 [
|
|
|
|
|
|
|
|
_("Add user to angeltype"),
|
|
|
|
|
|
|
|
UserAngelType_add_view($angeltype, $users_source, $user_source['UID'])
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* A user joins an angeltype.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
function user_angeltype_join_controller($angeltype) {
|
|
|
|
|
|
|
|
global $user, $privileges;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
|
|
|
|
|
|
|
|
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'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isset($_REQUEST['confirmed'])) {
|
|
|
|
|
|
|
|
$user_angeltype_id = UserAngelType_create($user, $angeltype);
|
|
|
|
|
|
|
|
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)));
|
|
|
|
|
|
|
|
success($success_message);
|
|
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
if (in_array('admin_user_angeltypes', $privileges)) {
|
|
|
|
sprintf(_("Become a %s"), $angeltype['name']),
|
|
|
|
$result = UserAngelType_confirm($user_angeltype_id, $user);
|
|
|
|
UserAngelType_join_view($user, $angeltype)
|
|
|
|
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 [
|
|
|
|
|
|
|
|
sprintf(_("Become a %s"), $angeltype['name']),
|
|
|
|
|
|
|
|
UserAngelType_join_view($user, $angeltype)
|
|
|
|
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|