summaryrefslogtreecommitdiff
path: root/includes/controller
diff options
context:
space:
mode:
Diffstat (limited to 'includes/controller')
-rw-r--r--includes/controller/angeltypes_controller.php12
-rw-r--r--includes/controller/user_angeltypes_controller.php200
2 files changed, 158 insertions, 54 deletions
diff --git a/includes/controller/angeltypes_controller.php b/includes/controller/angeltypes_controller.php
index bcd7696e..6b94545b 100644
--- a/includes/controller/angeltypes_controller.php
+++ b/includes/controller/angeltypes_controller.php
@@ -174,7 +174,7 @@ function angeltype_controller() {
return array(
sprintf(_("Team %s"), $angeltype['name']),
- AngelType_view($angeltype, $members, $user_angeltype, in_array('admin_user_angeltypes', $privileges), in_array('admin_angel_types', $privileges))
+ AngelType_view($angeltype, $members, $user_angeltype, in_array('admin_user_angeltypes', $privileges) || $user_angeltype['coordinator'], in_array('admin_angel_types', $privileges))
);
}
@@ -201,18 +201,10 @@ function angeltypes_list_controller() {
$actions[] = '<a class="delete" href="' . page_link_to('angeltypes') . '&action=delete&angeltype_id=' . $angeltype['id'] . '">' . _("delete") . '</a>';
}
- $angeltype['membership'] = "";
+ $angeltype['membership'] = AngelType_render_membership($angeltype);
if ($angeltype['user_angeltype_id'] != null) {
- if ($angeltype['restricted']) {
- if ($angeltype['confirm_user_id'] == null)
- $angeltype['membership'] = '<img src="pic/icons/lock.png" alt="' . _("Unconfirmed") . '" title="' . _("Unconfirmed") . '"> ' . _("Unconfirmed");
- else
- $angeltype['membership'] = '<img src="pic/icons/tick.png" alt="' . _("Member") . '" title="' . _("Member") . '"> ' . _("Member");
- } else
- $angeltype['membership'] = '<img src="pic/icons/tick.png" alt="' . _("Member") . '" title="' . _("Member") . '"> ' . _("Member");
$actions[] = '<a class="cancel" href="' . page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $angeltype['user_angeltype_id'] . '">' . _("leave") . '</a>';
} else {
- $angeltype['membership'] = '<img src="pic/icons/cross.png" alt="" title="">';
$actions[] = '<a class="add" href="' . page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'] . '">' . _("join") . '</a>';
}
diff --git a/includes/controller/user_angeltypes_controller.php b/includes/controller/user_angeltypes_controller.php
index b955fe6d..095b35f5 100644
--- a/includes/controller/user_angeltypes_controller.php
+++ b/includes/controller/user_angeltypes_controller.php
@@ -6,11 +6,6 @@
function user_angeltypes_delete_all_controller() {
global $user, $privileges;
- if (! in_array('admin_user_angeltypes', $privileges)) {
- error(_("You are not allowed to delete all users for this angeltype."));
- redirect(page_link_to('angeltypes'));
- }
-
if (! isset($_REQUEST['angeltype_id'])) {
error(_("Angeltype doesn't exist."));
redirect(page_link_to('angeltypes'));
@@ -24,6 +19,11 @@ function user_angeltypes_delete_all_controller() {
redirect(page_link_to('angeltypes'));
}
+ if (! User_is_AngelType_coordinator($user, $angeltype)) {
+ error(_("You are not allowed to delete all users for this angeltype."));
+ redirect(page_link_to('angeltypes'));
+ }
+
if (isset($_REQUEST['confirmed'])) {
$result = UserAngelTypes_delete_all($angeltype['id']);
if ($result === false)
@@ -46,11 +46,6 @@ function user_angeltypes_delete_all_controller() {
function user_angeltypes_confirm_all_controller() {
global $user, $privileges;
- if (! in_array('admin_user_angeltypes', $privileges)) {
- error(_("You are not allowed to confirm all users for this angeltype."));
- redirect(page_link_to('angeltypes'));
- }
-
if (! isset($_REQUEST['angeltype_id'])) {
error(_("Angeltype doesn't exist."));
redirect(page_link_to('angeltypes'));
@@ -64,6 +59,19 @@ function user_angeltypes_confirm_all_controller() {
redirect(page_link_to('angeltypes'));
}
+ $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(_("User angeltype doesn't exist."));
+ redirect(page_link_to('angeltypes'));
+ }
+
+ if (! in_array('admin_user_angeltypes', $privileges) && ! $user_angeltype['coordinator']) {
+ error(_("You are not allowed to confirm all users for this angeltype."));
+ redirect(page_link_to('angeltypes'));
+ }
+
if (isset($_REQUEST['confirmed'])) {
$result = UserAngelTypes_confirm_all($angeltype['id'], $user);
if ($result === false)
@@ -86,11 +94,6 @@ function user_angeltypes_confirm_all_controller() {
function user_angeltype_confirm_controller() {
global $user, $privileges;
- if (! in_array('admin_user_angeltypes', $privileges)) {
- error(_("You are not allowed to confirm this users angeltype."));
- redirect(page_link_to('angeltypes'));
- }
-
if (! isset($_REQUEST['user_angeltype_id'])) {
error(_("User angeltype doesn't exist."));
redirect(page_link_to('angeltypes'));
@@ -112,6 +115,11 @@ function user_angeltype_confirm_controller() {
redirect(page_link_to('angeltypes'));
}
+ if (! User_is_AngelType_coordinator($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 === false)
engelsystem_error("Unable to load user.");
@@ -171,7 +179,7 @@ function user_angeltype_delete_controller() {
redirect(page_link_to('angeltypes'));
}
- if ($user['UID'] != $user_angeltype['user_id'] && ! in_array('admin_user_angeltypes', $privileges)) {
+ if ($user['UID'] != $user_angeltype['user_id'] && ! User_is_AngelType_coordinator($user, $angeltype)) {
error(_("You are not allowed to delete this users angeltype."));
redirect(page_link_to('angeltypes'));
}
@@ -198,7 +206,65 @@ function user_angeltype_delete_controller() {
* Update an UserAngelType.
*/
function user_angeltype_update_controller() {
-
+ global $user, $privileges;
+
+ if (! in_array('admin_angel_types', $privileges)) {
+ error(_("You are not allowed to set coordinator 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['coordinator']) && preg_match("/^[01]$/", $_REQUEST['coordinator']))
+ $coordinator = $_REQUEST['coordinator'] == "1";
+ else {
+ error(_("No coordinator update given."));
+ redirect(page_link_to('angeltypes'));
+ }
+
+ $user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']);
+ 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)
+ 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)
+ engelsystem_error("Unable to load user.");
+ if ($user_source == null) {
+ error(_("User doesn't exist."));
+ redirect(page_link_to('angeltypes'));
+ }
+
+ if (isset($_REQUEST['confirmed'])) {
+ $result = UserAngelType_update($user_angeltype['id'], $coordinator);
+ 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'], User_Nick_render($user_source));
+ engelsystem_log($success_message);
+ success($success_message);
+
+ redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
+ }
+
+ return array(
+ $coordinator ? _("Add coordinator rights") : _("Remove coordinator rights"),
+ UserAngelType_update_view($user_angeltype, $user, $angeltype, $coordinator)
+ );
}
/**
@@ -220,38 +286,84 @@ function user_angeltype_add_controller() {
redirect(page_link_to('angeltypes'));
}
- $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(_("User is already an %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.");
+ if (User_is_AngelType_coordinator($user, $angeltype)) {
+ // Allow to add any user
+ $user_id = $user['UID'];
- $success_message = sprintf(_("User %s joined %s."), User_Nick_render($user), $angeltype['name']);
- engelsystem_log($success_message);
- success($success_message);
+ $users_source = Users_by_angeltype_inverted($angeltype);
+ if ($users_source === false)
+ engelsystem_error("Unable to load users.");
- if (in_array('admin_user_angeltypes', $privileges)) {
- $result = UserAngelType_confirm($user_angeltype_id, $user);
- if ($result === false)
- engelsystem_error("Unable to confirm user angeltype.");
- $success_message = sprintf(_("User %s confirmed as %s."), User_Nick_render($user), $angeltype['name']);
- engelsystem_log($success_message);
+ 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)))
+ $user_id = $_REQUEST['user_id'];
+ else {
+ $ok = false;
+ error(_("Please select a user."));
+ }
+
+ if ($ok) {
+ 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']));
+ success(sprintf(_("User %s added to %s."), User_Nick_render($user_source), $angeltype['name']));
+
+ $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']));
+
+ redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
+ }
+ }
}
- redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
+ return array(
+ _("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'])) {
+ $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']));
+ success($success_message);
+
+ if (in_array('admin_user_angeltypes', $privileges)) {
+ $result = UserAngelType_confirm($user_angeltype_id, $user);
+ if ($result === false)
+ engelsystem_error("Unable to confirm user angeltype.");
+ engelsystem_log(sprintf("User %s confirmed as %s.", User_Nick_render($user), $angeltype['name']));
+ }
+
+ redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
+ }
+
+ return array(
+ sprintf(_("Become a %s"), $angeltype['name']),
+ UserAngelType_join_view($user, $angeltype)
+ );
}
-
- return array(
- _("Add user to angeltype"),
- UserAngelType_add_view($user, $angeltype)
- );
}
/**