X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Femail.php;h=41e5d2518914a7f893010c121d3f8e4bfd322bee;hb=9483a7c7e923556fcafbe5154910dcc53a8e3d5a;hp=ac943becfce7ec7a40f346e8b275d4b9a21a20a0;hpb=fb813fb52d5ab65ca9a5b92b5cb9089523380d79;p=platal.git diff --git a/modules/email.php b/modules/email.php index ac943be..41e5d25 100644 --- a/modules/email.php +++ b/modules/email.php @@ -63,10 +63,10 @@ class EmailModule extends PLModule XDB::execute("UPDATE aliases SET flags = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', flags, ','), ',bestalias,', ',')) - WHERE id = {?}", $user->id()); + WHERE uid = {?}", $user->id()); XDB::execute("UPDATE aliases SET flags = CONCAT_WS(',', IF(flags = '', NULL, flags), 'bestalias') - WHERE id = {?} AND alias = {?}", $user->id(), $email); + WHERE uid = {?} AND alias = {?}", $user->id(), $email); // As having a non-null bestalias value is critical in // plat/al's code, we do an a posteriori check on the @@ -79,17 +79,12 @@ class EmailModule extends PLModule (alias REGEXP '\\\\.[0-9]{2}$') AS cent_ans, FIND_IN_SET('bestalias',flags) AS best, expire FROM aliases - WHERE id = {?} AND type!='homonyme' + WHERE uid = {?} AND type!='homonyme' ORDER BY LENGTH(alias)"; $page->assign('aliases', XDB::iterator($sql, $user->id())); // Check for homonyms. - $homonyme = XDB::query( - "SELECT alias - FROM aliases - INNER JOIN homonymes ON (id = homonyme_id) - WHERE user_id = {?} AND type = 'homonyme'", $user->id()); - $page->assign('homonyme', $homonyme->fetchOneCell()); + $page->assign('homonyme', $user->homonyme); // Display active redirections. $redirect = new Redirect($user); @@ -136,6 +131,9 @@ class EmailModule extends PLModule // Fetch existing @alias_dom aliases. $alias = $user->emailAlias(); $visibility = $user->hasProfile() && $user->profile()->alias_pub; + $page->assign('actuel', $alias); + $page->assign('user', $user); + $page->assign('mail_public', $visibility); if ($action == 'ask' && Env::has('alias') && Env::has('raison')) { S::assert_xsrf_token(); @@ -303,7 +301,7 @@ class EmailModule extends PLModule $res = XDB::query( "SELECT alias,expire FROM aliases - WHERE id={?} AND (type='a_vie' OR type='alias') + WHERE uid={?} AND (type='a_vie' OR type='alias') ORDER BY !FIND_IN_SET('usage',flags), LENGTH(alias)", $user->id()); $page->assign('alias', $res->fetchAllAssoc()); $page->assign('emails', $redirect->emails); @@ -386,7 +384,8 @@ class EmailModule extends PLModule $_POST['cc_contacts'] = explode(';', @$_POST['cc_contacts']); $data = serialize($_POST); XDB::execute("REPLACE INTO email_send_save - VALUES ({?}, {?})", S::i('uid'), $data); + VALUES ({?}, {?})", + S::user()->id('uid'), $data); } exit; } else if (Env::v('submit') == 'Envoyer') { @@ -397,10 +396,11 @@ class EmailModule extends PLModule if (!is_array($aliases)) { return null; } - $rel = Env::v('contacts'); + $uf = new UserFilter(new UFC_Hrpid($aliases)); + $users = $uf->iterUsers(); $ret = array(); - foreach ($aliases as $alias) { - $ret[$alias] = $rel[$alias]; + while ($user = $users->next()) { + $ret[] = $user->forlife; } return join(', ', $ret); } @@ -416,7 +416,8 @@ class EmailModule extends PLModule if (!$error) { XDB::execute("DELETE FROM email_send_save - WHERE uid = {?}", S::i('uid')); + WHERE uid = {?}", + S::user()->id()); $to2 = getEmails(Env::v('to_contacts')); $cc2 = getEmails(Env::v('cc_contacts')); @@ -483,14 +484,11 @@ class EmailModule extends PLModule } } - $res = XDB::query( - "SELECT ac.full_name, a.alias as forlife - FROM accounts AS ac - INNER JOIN contacts AS c ON (ac.uid = c.contact) - INNER JOIN aliases AS a ON (ac.uid = a.id AND FIND_IN_SET('bestalias', a.flags)) - WHERE c.uid = {?} - ORDER BY ac.full_name", S::i('uid')); - $page->assign('contacts', $res->fetchAllAssoc()); + $uf = new UserFilter(new PFC_And(new UFC_Contact(S::user()), + new UFC_Registered()), + UserFilter::sortByName()); + $contacts = $uf->getProfiles(); + $page->assign('contacts', $contacts); $page->assign('maxsize', ini_get('upload_max_filesize') . 'o'); $page->assign('user', S::user()); } @@ -574,7 +572,7 @@ class EmailModule extends PLModule global $globals; $res = XDB::query("SELECT e.email, e.rewrite, a.alias FROM emails AS e - INNER JOIN aliases AS a ON (a.id = e.uid AND a.type = 'a_vie') + INNER JOIN aliases AS a ON (a.uid = e.uid AND a.type = 'a_vie') WHERE e.email = {?} AND e.hash = {?}", $mail, $hash); XDB::query("UPDATE emails @@ -601,7 +599,10 @@ class EmailModule extends PLModule if (!empty($hash) || !empty($login)) { $user = User::getSilent($login); if ($user) { - $req = XDB::query("SELECT 1 FROM newsletter_ins WHERE user_id = {?} AND hash = {?}", $user->id(), $hash); + $req = XDB::query('SELECT 1 + FROM newsletter_ins + WHERE uid = {?} AND hash = {?}', + $user->id(), $hash); if ($req->numRows() == 0) { $user = null; } @@ -706,21 +707,21 @@ class EmailModule extends PLModule switch (Post::v('action')) { case 'create': if (trim(Post::v('emailN')) != '') { - Xdb::execute('INSERT IGNORE INTO emails_watch (email, state, detection, last, uid, description) + Xdb::execute('INSERT IGNORE INTO email_watch (email, state, detection, last, uid, description) VALUES ({?}, {?}, CURDATE(), NOW(), {?}, {?})', trim(Post::v('emailN')), Post::v('stateN'), S::i('uid'), Post::v('descriptionN')); }; break; case 'edit': - Xdb::execute('UPDATE emails_watch + Xdb::execute('UPDATE email_watch SET state = {?}, last = NOW(), uid = {?}, description = {?} WHERE email = {?}', Post::v('stateN'), S::i('uid'), Post::v('descriptionN'), Post::v('emailN')); break; default: if ($action == 'delete' && !is_null($email)) { - Xdb::execute('DELETE FROM emails_watch WHERE email = {?}', $email); + Xdb::execute('DELETE FROM email_watch WHERE email = {?}', $email); } } if ($action != 'create' && $action != 'edit') { @@ -730,9 +731,9 @@ class EmailModule extends PLModule if ($action == 'list') { $sql = "SELECT w.email, w.detection, w.state, a.alias AS forlife - FROM emails_watch AS w + FROM email_watch AS w LEFT JOIN emails AS e USING(email) - LEFT JOIN aliases AS a ON (a.id = e.uid AND a.type = 'a_vie') + LEFT JOIN aliases AS a ON (a.uid = e.uid AND a.type = 'a_vie') ORDER BY w.state, w.email, a.alias"; $it = Xdb::iterRow($sql); @@ -758,10 +759,10 @@ class EmailModule extends PLModule } elseif ($action == 'edit') { $sql = "SELECT w.detection, w.state, w.last, w.description, a1.alias AS edit, a2.alias AS forlife - FROM emails_watch AS w - LEFT JOIN aliases AS a1 ON (a1.id = w.uid AND a1.type = 'a_vie') + FROM email_watch AS w + LEFT JOIN aliases AS a1 ON (a1.uid = w.uid AND a1.type = 'a_vie') LEFT JOIN emails AS e ON (w.email = e.email) - LEFT JOIN aliases AS a2 ON (a2.id = e.uid AND a2.type = 'a_vie') + LEFT JOIN aliases AS a2 ON (a2.uid = e.uid AND a2.type = 'a_vie') WHERE w.email = {?} ORDER BY a2.alias"; $it = Xdb::iterRow($sql, $email); @@ -859,12 +860,12 @@ class EmailModule extends PLModule $sel = XDB::query( "SELECT e1.uid, e1.panne != 0 AS panne, count(e2.uid) AS nb_mails, - u.nom, u.prenom, u.promo, a.alias + acc.full_name, a.alias FROM emails AS e1 LEFT JOIN emails AS e2 ON (e1.uid = e2.uid AND FIND_IN_SET('active', e2.flags) AND e1.email != e2.email) - INNER JOIN auth_user_md5 AS u ON (e1.uid = u.user_id) - INNER JOIN aliases AS a ON (u.user_id = a.id AND FIND_IN_SET('bestalias', a.flags)) + INNER JOIN accounts AS acc ON (e1.uid = acc.uid) + INNER JOIN aliases AS a ON (acc.uid = a.uid AND FIND_IN_SET('bestalias', a.flags)) WHERE e1.email = {?} GROUP BY e1.uid", $email); @@ -884,7 +885,7 @@ class EmailModule extends PLModule if (!empty($x['nb_mails'])) { $mail = new PlMailer('emails/broken.mail.tpl'); - $mail->addTo("\"{$x['prenom']} {$x['nom']}\" <{$x['alias']}@" + $mail->addTo("\"{$x['full_name']}\" <{$x['alias']}@" . $globals->mail->domain . '>'); $mail->assign('x', $x); $mail->assign('email', $email); @@ -914,22 +915,28 @@ class EmailModule extends PLModule pl_content_headers("text/x-csv"); $csv = fopen('php://output', 'w'); - fputcsv($csv, array('nom', 'prenom', 'promo', 'alias', 'bounce', 'nbmails', 'url'), ';'); + fputcsv($csv, array('nom', 'promo', 'alias', 'bounce', 'nbmails', 'url'), ';'); foreach ($broken_user_list as $alias => $mails) { $sel = Xdb::query( - "SELECT u.user_id, count(e.email) AS nb_mails, u.nom, u.prenom, u.promo - FROM aliases AS a - INNER JOIN auth_user_md5 AS u ON a.id = u.user_id - LEFT JOIN emails AS e ON (e.uid = u.user_id - AND FIND_IN_SET('active', e.flags) AND e.panne = 0) + "SELECT acc.uid, count(e.email) AS nb_mails, + IFNULL(pd.public_name, acc.full_name) AS fullname, + IFNULL(pd.promo, 0) AS promo + FROM aliases AS a + INNER JOIN accounts AS acc ON (a.uid = acc.uid) + LEFT JOIN emails AS e ON (e.uid = acc.uid + AND FIND_IN_SET('active', e.flags) AND e.panne = 0) + LEFT JOIN account_profiles AS ap ON (acc.uid = ap.uid AND FIND_IN_SET('owner', ap.perms)) + LEFT JOIN profile_display AS pd ON (pd.pid = ap.pid) WHERE a.alias = {?} - GROUP BY u.user_id", $alias); + GROUP BY acc.uid", $alias); if ($x = $sel->fetchOneAssoc()) { if ($x['nb_mails'] == 0) { - register_profile_update($x['user_id'], 'broken'); + $user = User::getSilentWithUID($x['uid']); + $profile = $user->profile(); + WatchProfileUpdate::register($profile, 'broken'); } - fputcsv($csv, array($x['nom'], $x['prenom'], $x['promo'], $alias, + fputcsv($csv, array($x['fullname'], $x['promo'], $alias, join(',', $mails), $x['nb_mails'], 'https://www.polytechnique.org/marketing/broken/' . $alias), ';'); }