You are here

function og_approve in Organic groups 5

Same name and namespace in other branches
  1. 5.8 og.module \og_approve()
  2. 5.2 og.module \og_approve()
  3. 5.3 og.module \og_approve()
  4. 5.7 og.module \og_approve()
  5. 6.2 og.module \og_approve()
  6. 6 og.module \og_approve()
1 string reference to 'og_approve'
og_menu in ./og.module

File

./og.module, line 462

Code

function og_approve($gid, $uid) {
  $node = node_load($gid);
  if (og_is_node_admin($node)) {
    $account = user_load(array(
      'uid' => (int) $uid,
    ));
    if ($account === FALSE) {
      drupal_set_message(t("User approval failed, user no longer available on website."), 'error');
      return '';
    }
    if (in_array($gid, array_keys($account->og_groups))) {
      drupal_set_message(t("!name already approved to group %group.", array(
        '!name' => theme('username', $account),
        '%group' => $node->title,
      )), 'error');
      return '';
    }
    else {
      og_save_subscription($gid, $uid, array(
        'is_active' => 1,
      ));
      drupal_set_message(t('Membership request approved.'));
      $variables = array(
        '@title' => $node->title,
        '!group_url' => url("node/{$node->nid}", NULL, NULL, TRUE),
      );
      $from = variable_get('site_mail', ini_get('sendmail_from'));
      $account = user_load(array(
        'uid' => $uid,
      ));
      drupal_mail('og_approve', $account->mail, _og_user_mail_text('og_approve_user_subject', $variables), _og_user_mail_text('og_approve_user_body', $variables), $from);
      drupal_goto("node/{$gid}");
    }
  }
  else {
    drupal_access_denied();
  }
}