+ // Deals with xnet accounts.
+ if (is_null($user) || $user->type == 'xnet') {
+ // User is of type xnet. There are 3 possible cases:
+ // * the email is not known yet: we create a new account and
+ // propose to send an email to the user so he can activate
+ // his account,
+ // * the email is known but the user was not contacted in order to
+ // activate yet: we propose to send an email to the user so he
+ // can activate his account,
+ // * the email is known and the user was already contacted or has
+ // an active account: nothing to be done.
+ list($mbox, $domain) = explode('@', strtolower($email));
+ $hruid = User::makeHrid($mbox, $domain, 'ext');
+ // User might already have an account (in another group for example).
+ $user = User::getSilent($hruid);
+
+ // If the user has no account yet, creates new account: build names from email address.
+ if (empty($user)) {
+ require_once 'name.func.inc.php';
+ $parts = explode('.', $mbox);
+ if (count($parts) == 1) {
+ $lastname = $display_name = capitalize_name($mbox);
+ $firstname = '';
+ } else {
+ $display_name = $firstname = capitalize_name($parts[0]);
+ $lastname = capitalize_name(implode(' ', array_slice($parts, 1)));
+ }
+ $full_name = build_full_name($firstname, $lastname);
+ $directory_name = build_directory_name($firstname, $lastname);
+ $sort_name = build_sort_name($firstname, $lastname);
+ XDB::execute('INSERT INTO accounts (hruid, display_name, full_name, directory_name, sort_name,
+ firstname, lastname, email, type, state)
+ VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, \'xnet\', \'disabled\')',
+ $hruid, $display_name, $full_name, $directory_name, $sort_name, $firstname, $lastname, $email);
+ $user = User::getSilent($hruid);
+ }
+
+ $suggest_account_activation = $this->suggest($user);
+ }