toggle_admin.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /**
  3. * add/remove a user as a group admin
  4. */
  5. $group_guid = (int) get_input("group_guid");
  6. $user_guid = (int) get_input("user_guid");
  7. $group = get_entity($group_guid);
  8. $user = get_user($user_guid);
  9. if (!empty($group) && !empty($user)) {
  10. if (($group instanceof ElggGroup) && $group->canEdit() && $group->isMember($user) && ($group->getOwnerGUID() != $user->getGUID())) {
  11. if (!check_entity_relationship($user->getGUID(), "group_admin", $group->getGUID())) {
  12. // user is admin, so remove
  13. if (add_entity_relationship($user->getGUID(), "group_admin", $group->getGUID())) {
  14. system_message(elgg_echo("group_tools:action:toggle_admin:success:add"));
  15. } else {
  16. register_error(elgg_echo("group_tools:action:toggle_admin:error:add"));
  17. }
  18. } else {
  19. // user is not admin, so add
  20. if (remove_entity_relationship($user->getGUID(), "group_admin", $group->getGUID())) {
  21. system_message(elgg_echo("group_tools:action:toggle_admin:success:remove"));
  22. } else {
  23. register_error(elgg_echo("group_tools:action:toggle_admin:error:remove"));
  24. }
  25. }
  26. } else {
  27. register_error(elgg_echo("group_tools:action:toggle_admin:error:group"));
  28. }
  29. } else {
  30. register_error(elgg_echo("group_tools:action:error:input"));
  31. }
  32. forward(REFERER);