You are here

function og_ui_unsubscribe in Organic groups 7.2

Same name and namespace in other branches
  1. 7 og_ui/og_ui.pages.inc \og_ui_unsubscribe()

Confirm OG unsubscription form.

The unsubscribing user is always the acting user - like this we make sure no malicious user will unsubscribe another user. Administrators can reject or ban another group member from the "people" page.

1 string reference to 'og_ui_unsubscribe'
og_ui_menu in og_ui/og_ui.module
Implements hook_menu().

File

og_ui/og_ui.pages.inc, line 203
Page callbacks for Organic groups module.

Code

function og_ui_unsubscribe($group_type, $gid) {
  global $user;
  $account = clone $user;
  $group = entity_load_single($group_type, $gid);
  if (!$group || !og_is_group($group_type, $group)) {

    // Not a valid entity, or not a group.
    drupal_not_found();
    return;
  }

  // Check the user isn't the manager of the group.
  if ($group->uid != $user->uid) {
    if (og_is_member($group_type, $gid, 'user', $account, array(
      OG_STATE_ACTIVE,
      OG_STATE_PENDING,
    ))) {

      // Show the user a subscription confirmation.
      return drupal_get_form('og_ui_confirm_unsubscribe', $group_type, $group);
    }
    drupal_access_denied();
    return;
  }
  else {
    $label = entity_label($group_type, $group);
    drupal_set_message(t('As the manager of %group, you can not leave the group.', array(
      '%group' => $label,
    )));
    $url = entity_uri($group_type, $group);
    drupal_goto($url['path'], $url['options']);
  }
}