Example #1
0
function fill_email_combobox(PlPage $page, array $retrieve, $user = null)
{
    require_once 'emails.inc.php';
    if (is_null($user)) {
        $user = S::user();
    }
    /* Always refetch the profile. */
    $profile = $user->profile(true);
    $emails = array();
    if (in_array('source', $retrieve)) {
        $emails['Emails polytechniciens'] = XDB::fetchColumn('SELECT  CONCAT(s.email, \'@\', d.name)
                                                                FROM  email_source_account  AS s
                                                          INNER JOIN  email_virtual_domains AS m ON (s.domain = m.id)
                                                          INNER JOIN  email_virtual_domains AS d ON (d.aliasing = m.id)
                                                               WHERE  s.uid = {?}
                                                            ORDER BY  s.email, d.name', $user->id());
    }
    if (in_array('redirect', $retrieve)) {
        $redirect = new Redirect($user);
        $emails['Redirections'] = array();
        foreach ($redirect->emails as $redirect_it) {
            if ($redirect_it->is_redirection()) {
                $emails['Redirections'][] = $redirect_it->email;
            }
        }
    }
    if ($profile) {
        if (in_array('job', $retrieve)) {
            $emails['Emails professionels'] = XDB::fetchColumn('SELECT  email
                                                                  FROM  profile_job
                                                                 WHERE  pid = {?} AND email IS NOT NULL AND email != \'\'', $profile->id());
        }
        if ($profile->email_directory) {
            if (in_array('directory', $retrieve)) {
                foreach ($emails as &$email_list) {
                    foreach ($email_list as $key => $email) {
                        if ($profile->email_directory == $email) {
                            unset($email_list[$key]);
                        }
                    }
                }
                $emails['Email annuaire AX'] = array($profile->email_directory);
            } elseif (in_array('stripped_directory', $retrieve)) {
                if (User::isForeignEmailAddress($profile->email_directory)) {
                    $is_redirect = XDB::fetchOneCell('SELECT  COUNT(*)
                                                        FROM  email_redirect_account
                                                       WHERE  uid = {?} AND redirect = {?}', $user->id(), $profile->email_directory);
                    if ($is_redirect == 0) {
                        $emails['Email annuaire AX'] = array($profile->email_directory);
                    }
                }
            }
        }
        if (isset($emails['Emails professionels']) && isset($emails['Redirections'])) {
            $intersect = array_intersect($emails['Emails professionels'], $emails['Redirections']);
            foreach ($intersect as $key => $email) {
                unset($emails['Emails professionels'][$key]);
            }
        }
    }
    $emails_count = 0;
    foreach ($emails as $email_list) {
        $emails_count += count($email_list);
    }
    $page->assign('emails_count', $emails_count);
    $page->assign('email_lists', $emails);
}
Example #2
0
 function handler_batch($page)
 {
     $page->changeTpl('carnet/batch.tpl');
     $errors = false;
     $incomplete = array();
     if (Post::has('add')) {
         S::assert_xsrf_token();
         require_once 'userset.inc.php';
         require_once 'emails.inc.php';
         require_once 'marketing.inc.php';
         $list = explode("\n", Post::v('list'));
         $origin = Post::v('origin');
         foreach ($list as $item) {
             if ($item = trim($item)) {
                 $elements = preg_split("/\\s/", $item);
                 $email = array_pop($elements);
                 if (!isvalid_email($email)) {
                     $page->trigError('Email invalide : ' . $email);
                     $incomplete[] = $item;
                     $errors = true;
                     continue;
                 }
                 $user = User::getSilent($email);
                 if (is_null($user)) {
                     $details = implode(' ', $elements);
                     $promo = trim(array_pop($elements));
                     $cond = new PFC_And();
                     if (preg_match('/^[MDX]\\d{4}$/', $promo)) {
                         $cond->addChild(new UFC_Promo('=', UserFilter::DISPLAY, $promo));
                     } else {
                         $cond->addChild(new UFC_NameTokens($promo));
                     }
                     foreach ($elements as $element) {
                         $cond->addChild(new UFC_NameTokens($element));
                     }
                     $uf = new UserFilter($cond);
                     $count = $uf->getTotalCount();
                     if ($count == 0) {
                         $page->trigError('Les informations : « ' . $item . ' » ne correspondent à aucun camarade.');
                         $incomplete[] = $item;
                         $errors = true;
                         continue;
                     } elseif ($count > 1) {
                         $page->trigError('Les informations : « ' . $item . ' » sont ambigues et correspondent à plusieurs camarades.');
                         $incomplete[] = $item;
                         $errors = true;
                         continue;
                     } else {
                         $user = $uf->getUser();
                     }
                 }
                 if ($user->state == 'active') {
                     $this->addRegistered($page, $user->profile());
                 } else {
                     if (!User::isForeignEmailAddress($email)) {
                         $page->trigError('Email pas encore attribué : ' . $email);
                         $incomplete[] = $item;
                         $errors = true;
                     } else {
                         $this->addNonRegistered($page, $user);
                         if (!Marketing::get($user->id(), $email, true)) {
                             check_email($email, "Une adresse surveillée est proposée au marketing par " . S::user()->login());
                             $market = new Marketing($user->id(), $email, 'default', null, $origin, S::v('uid'), null);
                             $market->add();
                         }
                     }
                 }
             }
         }
     }
     $page->assign('errors', $errors);
     $page->assign('incomplete', $incomplete);
 }
Example #3
0
 function handler_broken($page, $warn = null, $email = null)
 {
     require_once 'emails.inc.php';
     $wp = new PlWikiPage('Xorg.PatteCassée');
     $wp->buildCache();
     global $globals;
     $page->changeTpl('emails/broken.tpl');
     if ($warn == 'warn' && $email) {
         S::assert_xsrf_token();
         // Usual verifications.
         $email = valide_email($email);
         $uid = XDB::fetchOneCell('SELECT  uid
                                     FROM  email_redirect_account
                                    WHERE  redirect = {?}', $email);
         if ($uid) {
             $dest = User::getWithUID($uid);
             $active = XDB::fetchOneCell('SELECT flags
                                            FROM email_redirect_account
                                           WHERE redirect = {?} AND uid = {?}', $email, $uid) == 'active';
             $mail = new PlMailer('emails/broken-web.mail.tpl');
             $mail->assign('email', $email);
             $mail->assign('request', S::user());
             $mail->sendTo($dest);
             $page->trigSuccess('Email envoyé !');
         }
     } elseif (Post::has('email')) {
         S::assert_xsrf_token();
         $email = Post::t('email');
         if (!User::isForeignEmailAddress($email)) {
             $page->assign('neuneu', true);
         } else {
             $user = mark_broken_email($email);
             $page->assign('user', $user);
             $page->assign('email', $email);
         }
     }
 }
Example #4
0
function ids_from_mails(array $emails)
{
    // Removes duplicates, if any.
    $emails = array_unique($emails);
    // Formats and splits by domain type (locally managed or external) emails.
    $main_domain_emails = array();
    $aux_domain_emails = array();
    $other_emails = array();
    foreach ($emails as $email) {
        if (strpos($email, '@') === false) {
            $main_domain_emails[] = $email;
        } else {
            if (User::isForeignEmailAddress($email)) {
                $other_emails[$email] = strtolower($user . '@' . $domain);
            } else {
                list($local_part, $domain) = explode('@', $email);
                list($local_part) = explode('+', $local_part);
                list($local_part) = explode('_', $local_part);
                if (User::isMainMailDomain($domain)) {
                    $main_domain_emails[$email] = strtolower($local_part);
                } elseif (User::isAliasMailDomain($domain)) {
                    $aux_domain_emails[$email] = strtolower($local_part);
                }
            }
        }
    }
    // Retrieves emails from our domains.
    $main_domain_uids = XDB::fetchAllAssoc('email', 'SELECT  email, uid
                                              FROM  email_source_account
                                             WHERE  email IN {?} AND type != \'alias_aux\'', array_unique($main_domain_emails));
    $aux_domain_uids = XDB::fetchAllAssoc('email', 'SELECT  email, uid
                                             FROM  email_source_account
                                            WHERE  email IN {?} AND type = \'alias_aux\'', array_unique($aux_domain_emails));
    // Retrieves emails from redirections.
    $other_uids = XDB::fetchAllAssoc('redirect', 'SELECT  redirect, uid
                                        FROM  email_redirect_account
                                       WHERE  redirect IN {?}', array_unique($other_emails));
    // Associates given emails with the corresponding uid.
    $uids = array();
    foreach ($main_domain_emails as $email => $key) {
        $uids[$email] = $main_domain_uids[$key];
    }
    foreach ($aux_domain_emails as $email => $key) {
        $uids[$email] = $aux_domain_uids[$key];
    }
    foreach ($other_emails as $email => $key) {
        $uids[$email] = $other_uids[$key];
    }
    return array_unique($uids);
}
Example #5
0
 public static function getBulkForlifeEmailsFromEmail($emails)
 {
     if (!is_array($emails)) {
         if (strlen(trim($emails)) == 0) {
             return null;
         }
         $emails = preg_split("/[; ,\r\n\\|]+/", $emails);
     }
     if ($emails) {
         $list = array();
         foreach ($emails as $i => $email) {
             $email = trim($email);
             if (empty($email)) {
                 continue;
             }
             if ($user = User::getUserFromEmail($email)) {
                 $list[$i] = $user->forlifeEmail();
             } else {
                 if (User::isForeignEmailAddress($email) && isvalid_email($email)) {
                     $list[$i] = $email;
                 }
             }
         }
         return array_unique($list);
     }
     return null;
 }
Example #6
0
 function handler_admin_member_new($page, $email = null)
 {
     global $globals;
     $page->changeTpl('xnetgrp/membres-add.tpl');
     $page->addJsLink('xnet_members.js');
     if (is_null($email)) {
         return;
     }
     S::assert_xsrf_token();
     $suggest_account_activation = false;
     // FS#703 : $_GET is urldecoded twice, hence
     // + (the data) => %2B (in the url) => + (first decoding) => ' ' (second decoding)
     // Since there can be no spaces in emails, we can fix this with :
     $email = str_replace(' ', '+', $email);
     $is_valid_email = isvalid_email($email);
     // X not registered to main site.
     if (Env::v('x') && Env::i('userid') && $is_valid_email) {
         $user = User::getSilentWithUID(Env::i('userid'));
         if (!$user) {
             $page->trigError('Utilisateur invalide.');
             return;
         }
         // User has an account but is not yet registered.
         if ($user->state == 'pending') {
             // Add email in account table.
             XDB::query('UPDATE  accounts
                            SET  email = {?}
                          WHERE  uid = {?} AND email IS NULL', $email, $user->id());
             // Add email for marketing if required.
             if (Env::v('marketing')) {
                 $market = Marketing::get($user->uid, $email);
                 if (!$market) {
                     $market = new Marketing($user->uid, $email, 'group', $globals->asso('nom'), Env::v('marketing_from'), S::v('uid'));
                     $market->add();
                 }
             }
         } elseif (Env::v('broken')) {
             // Add email for broken if required.
             $valid = new BrokenReq(S::user(), $user, $email, 'Groupe : ' . $globals->asso('nom'));
             $valid->submit();
         }
     } else {
         $user = User::getSilent($email);
         // Wrong email and no user: failure.
         if (is_null($user) && (!$is_valid_email || !User::isForeignEmailAddress($email))) {
             $page->trigError('«&nbsp;<strong>' . $email . '</strong>&nbsp;» n\'est pas une adresse email valide.');
             return;
         }
         // 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);
         }
     }
     if ($user) {
         // First check if the user used to be in this group.
         XDB::rawExecute('DELETE FROM  group_former_members
                                WHERE  remember AND DATE_SUB(NOW(), INTERVAL 1 YEAR) > unsubsciption_date');
         $former_member = XDB::fetchOneCell('SELECT  remember
                                               FROM  group_former_members
                                              WHERE  uid = {?} AND asso_id = {?}', $user->id(), $globals->asso('id'));
         if ($former_member === 1) {
             $page->trigError($user->fullName() . ' est un ancien membre du groupe qui ne souhaite pas y revenir. S\'il souhaite revenir dans le groupe, il faut qu\'il en fasse la demande sur la page d\'accueil du groupe.');
             return;
         } elseif (!is_null($former_member) && Post::i('force_continue') == 0) {
             $page->trigWarning($user->fullName() . ' est un ancien membre du groupe qui s\'est récemment désinscrit. Malgré cela, si tu penses qu\'il souhaite revenir, cliquer sur « Ajouter » l\'ajoutera bien au groupe cette fois.');
             $page->assign('force_continue', 1);
             return;
         }
         Group::subscribe($globals->asso('id'), $user->id());
         $this->removeSubscriptionRequest($user->id());
         if ($user->isActive() && $user->bestEmail()) {
             $mailer = new PlMailer('xnetgrp/forced-subscription.mail.tpl');
             $mailer->addTo($user->bestEmail());
             $mailer->assign('group', $globals->asso('nom'));
             $mailer->assign('anim', S::user()->fullname());
             $mailer->assign('diminutif', $globals->asso('diminutif'));
             $mailer->send();
         }
         // Check if the group has more than 1000 members, if so, disable the "send mail" function.
         $full_count = XDB::fetchOneCell('SELECT COUNT(*)
                                            FROM group_members
                                           WHERE asso_id = {?}', $globals->asso('id'));
         if ($full_count > 999) {
             XDB::execute("UPDATE groups\n                    SET disable_mails = 1\n                    WHERE id = {?}", $globals->asso('id'));
         }
         if ($suggest_account_activation) {
             pl_redirect('member/suggest/' . $user->login() . '/' . $email . '/' . $globals->asso('nom'));
         } else {
             pl_redirect('member/' . $user->login());
         }
     }
 }
Example #7
0
 public function buildCondition(PlFilter $uf)
 {
     $foreign = array();
     $local = array();
     $cond = array();
     if (count($this->emails) == 0) {
         return PlFilterCondition::COND_FALSE;
     }
     foreach ($this->emails as $entry) {
         if (User::isForeignEmailAddress($entry)) {
             $foreign[] = $entry;
         } else {
             list($local_part, ) = explode('@', $entry);
             $local[] = $local_part;
         }
     }
     if (count($foreign) > 0) {
         $sub = $uf->addEmailRedirectFilter($foreign);
         $cond[] = XDB::format('ra' . $sub . '.redirect IS NOT NULL OR ra' . $sub . '.redirect IN {?} OR a.email IN {?}', $foreign, $foreign);
     }
     if (count($local) > 0) {
         $sub = $uf->addAliasFilter($local);
         $cond[] = 'sa' . $sub . '.email IS NOT NULL';
     }
     return '(' . implode(') OR (', $cond) . ')';
 }