+ } else {
+ // User is of type xnet.
+ list($firstname, $lastname) = explode('@', $email);
+ $hruid = User::makeHrid($firstname, $lastname, 'ext');
+ // User might already have an account (in another group for example).
+ $user = User::get($hruid);
+
+ // If the user has no account yet, creates new account: build names from email address.
+ if (empty($user)) {
+ $display_name = ucwords(strtolower(substr($hruid, strpos('.', $hruid))));
+ $full_name = ucwords(strtolower(str_replace('.', ' ', substr($email, strpos('@', $email)))));
+ XDB::execute('INSERT INTO accounts (hruid, display_name, full_name, email, type)
+ VALUES ({?}, {?}, {?}, {?}, \'xnet\')',
+ $hruid, $display_name, $full_name, $email);
+ $user = User::get($hruid);
+ }
+ }
+
+ if ($user) {
+ XDB::execute('REPLACE INTO group_members (uid, asso_id)
+ VALUES ({?}, {?})',
+ $user->id(), $globals->asso('id'));
+ $this->removeSubscriptionRequest($user->id());
+ pl_redirect('member/' . $user->login());