- } else {
- if (isvalid_email($email)) {
- if (Env::v('x') && Env::i('userid')) {
- $uid = Env::i('userid');
- $user = User::getWithUID($uid);
- if ($user && $user->state == 'pending') {
- if (Env::v('market')) {
- $market = Marketing::get($uid, $email);
- if (!$market) {
- $market = new Marketing($uid, $email, 'group', $globals->asso('nom'),
- Env::v('market_from'), S::v('uid'));
- $market->add();
- }
- }
- XDB::execute('REPLACE INTO #groupex#.membres (uid, asso_id, origine, email)
- VALUES ({?}, {?}, "X", {?})',
- $uid, $globals->asso('id'), $email);
- $this->removeSubscriptionRequest($uid);
- pl_redirect("member/$email");
- }
- $page->trigError("Utilisateur invalide");
- } else {
- $res = XDB::query('SELECT MAX(uid) + 1 FROM #groupex#.membres');
- $uid = max(intval($res->fetchOneCell()), 50001);
- XDB::execute('REPLACE INTO #groupex#.membres (uid, asso_id, origine, email)
- VALUES ({?}, {?}, "ext", {?})',
- $uid, $globals->asso('id'), $email);
- pl_redirect("member/$email");
+ } else if (Env::v('x') && Env::i('userid')) {
+ // user is an x but might not yet be registered
+ $user = User::getWithUID(Env::i('userid'));
+ if (!$user) {
+ $page->trigError("Utilisateur invalide");
+ return;
+ }
+ // add email for marketing if unknown
+ if ($user->state == 'pending' && Env::v('market')) {
+ $market = Marketing::get($user->uid, $email);
+ if (!$market) {
+ $market = new Marketing($user->uid, $email, 'group', $globals->asso('nom'),
+ Env::v('market_from'), S::v('uid'));
+ $market->add();