You are here

function invite_user in Invite 6.2

Same name and namespace in other branches
  1. 5.2 invite.module \invite_user()
  2. 5 invite.module \invite_user()

Implementation of hook_user().

File

./invite.module, line 460
Allows your users to send and track invitations to join your site.

Code

function invite_user($op, &$edit, &$account, $category = NULL) {
  switch ($op) {
    case 'insert':
      $invite = invite_load_from_session();
      if (!$invite) {

        // Try to look up an invitation in case a user has been invited to join
        // the site, but did go straight to the site and signed up without
        // using the invite link.
        $code = db_result(db_query("SELECT reg_code FROM {invite} WHERE email = '%s'", $account->mail));
        if ($code) {
          $invite = invite_load($code);
        }
      }
      if ($invite) {

        // Process the invitation and assign target roles to the user. These
        // will be saved by user_save().
        $roles = invite_process($invite, $account);
        if ($roles) {
          if (!isset($edit['roles']) || !is_array($edit['roles'])) {
            $edit['roles'] = array();
          }
          $edit['roles'] += $roles;

          // We need to notify other modules of the role change, otherwise they
          // will be unaware of it.
          user_module_invoke('update', $edit, $account);
        }

        // Flag the inviting user, this triggers status notifications and
        // saves us some queries otherwise.
        if ($invite->inviter->uid) {
          user_save($invite->inviter, array(
            'invite_sent' => TRUE,
          ));
        }
        unset($_SESSION[INVITE_SESSION]);
      }
      break;
    case 'delete':
      invite_delete($account->uid);
      break;
  }
}