You are here

function invite_user in Invite 5

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

Implementation of hook_user().

File

./invite.module, line 210
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'", $edit['mail']));
        if ($code) {
          $invite = invite_load($code);
        }
      }
      if ($invite) {

        // Update invite status
        _invite_set_accepted($edit['mail'], $account->uid, $invite->reg_code);

        // Escalate user role
        _invite_role_escalate($account);

        // Unblock user account
        _invite_unblock($account->uid);
        unset($_SESSION[INVITE_SESSION_NAME]);
      }
      break;
    case 'delete':

      // Only delete invites of existing users if the configuration allows it to
      $delete_joined = user_access('withdraw accepted invitations');

      // Delete invite for this user
      if ($delete_joined) {
        db_query("DELETE FROM {invite} WHERE mid = %d", $account->uid);
      }

      // Delete any invites originating from this user
      $sql = "DELETE FROM {invite} WHERE uid = %d";
      if (!$delete_joined) {
        $sql .= " AND timestamp != 0";
      }
      db_query($sql, $account->uid);
      break;
  }
}