You are here

function invite_accept in Invite 7.4

Same name and namespace in other branches
  1. 5.2 invite.module \invite_accept()
  2. 6.2 invite.module \invite_accept()
  3. 7.2 invite.pages.inc \invite_accept()

Invitation accept callback.

Parameters

Invite $invite:

2 string references to 'invite_accept'
invite_invite_update in ./invite.module
Implements hook_invite_update().
invite_menu in ./invite.module
Implements hook_menu().

File

includes/invite.pages.inc, line 24

Code

function invite_accept($invite) {
  global $user;
  $redirect = '<front>';
  $message = '';
  $type = 'status';
  if ($user->uid == $invite->uid) {
    $message = t('You could not use own invite.');
    $type = 'error';
    $redirect = '<front>';
  }
  elseif (!$user->uid && empty($invite->invitee) && $invite
    ->status() == INVITE_VALID) {

    // Process new user invitation.
    $_SESSION[INVITE_SESSION_CODE] = $invite->reg_code;
    $redirect = variable_get('invite_registration_path', 'user/register');
  }
  elseif (!empty($user->uid) && $invite
    ->status() == INVITE_VALID) {
    $invite->invitee = $user->uid;
    $invite->joined = REQUEST_TIME;
    $invite->status = INVITE_USED;
    entity_save('invite', $invite);
    unset($_SESSION[INVITE_SESSION_CODE]);
    $inviter = $invite
      ->inviter();
    $message = t('You have accepted the invitation from !user.', array(
      '!user' => theme('username', array(
        'account' => $inviter,
      )),
    ));
    $redirect = 'user';
  }
  elseif (empty($user->uid) && !empty($invite->invitee) && $invite
    ->status() == INVITE_VALID) {
    $_SESSION[INVITE_SESSION_CODE] = $invite->reg_code;
    $message = t('You should login first to accept this invitation.');
    $type = 'warning';
    $redirect = 'user/login';
  }
  else {

    // Cover the rest of the error which redirect to /user instead of 403.
    $type = 'error';
    $redirect = 'user';
    switch ($invite
      ->status()) {
      case INVITE_WITHDRAWN:
        $message = t('This invitation has been withdrawn.');
        break;
      case INVITE_USED:
        $message = t('This invitation has already been used.');
        break;
      case INVITE_EXPIRED:
        $message = t('This invitation has expired.');
        break;
    }
  }

  // Give a chance for customization.
  $data = array(
    'redirect' => &$redirect,
    'message' => &$message,
    'type' => &$type,
    'invite' => $invite,
  );
  drupal_alter('invite_accept', $data);
  if (!empty($message)) {
    drupal_set_message($message, $type);
  }
  drupal_redirect_form($data);
}