X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Femail.php;h=360c4623a34186fada001f4f948dec7393e1dd75;hb=96b778a679b261235ede8c5c4e7356680f4e5895;hp=e7f1e28d6566a5cfef58ed1777aa9fb22364788d;hpb=bc0276a2d79d88a56656514fe24bd427c0ef3b88;p=platal.git diff --git a/modules/email.php b/modules/email.php index e7f1e28..360c462 100644 --- a/modules/email.php +++ b/modules/email.php @@ -1,6 +1,6 @@ $this->make_hook('duplicated', AUTH_PASSWD, 'admin'), 'admin/emails/watch' => $this->make_hook('duplicated', AUTH_PASSWD, 'admin'), 'admin/emails/lost' => $this->make_hook('lost', AUTH_PASSWD, 'admin'), - 'admin/emails/broken' => $this->make_hook('broken_addr', AUTH_PASSWD, 'admin'), + 'admin/emails/broken' => $this->make_hook('broken_addr', AUTH_PASSWD, 'admin,edit_directory'), ); } @@ -98,9 +98,23 @@ class EmailModule extends PLModule 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 !alias, s.email", + ORDER BY !alias, s.email, d.name", $user->id()); - $page->assign('aliases', $aliases); + $aliases_forlife = array(); + $aliases_hundred = array(); + $aliases_other = array(); + while ($a = $aliases->next()) { + if ($a['forlife']) { + $aliases_forlife[] = $a; + } elseif ($a['hundred_year']) { + $aliases_hundred[] = $a; + } else { + $aliases_other[] = $a; + } + } + $page->assign('aliases_forlife', $aliases_forlife); + $page->assign('aliases_hundred', $aliases_hundred); + $page->assign('aliases_other', $aliases_other); $alias = XDB::fetchOneCell('SELECT COUNT(email) FROM email_source_account @@ -791,7 +805,8 @@ class EmailModule extends PLModule AND er.type != \'imap\' AND er.type != \'homonym\') LEFT JOIN account_profiles AS ap ON (ap.uid = a.uid AND FIND_IN_SET(\'owner\', ap.perms)) LEFT JOIN profile_display AS pd ON (ap.pid = pd.pid) - WHERE a.state = \'active\' AND er.redirect IS NULL AND FIND_IN_SET(\'mail\', at.perms) + LEFT JOIN profiles AS p ON (ap.pid = p.pid) + WHERE a.state = \'active\' AND er.redirect IS NULL AND FIND_IN_SET(\'mail\', at.perms) AND p.deathdate IS NULL GROUP BY a.uid ORDER BY pd.promo, a.hruid')); } @@ -847,30 +862,40 @@ class EmailModule extends PLModule $broken_user_list = array(); $broken_user_email_count = array(); + $broken_user_profiles = array(); $broken_list = explode("\n", $list); sort($broken_list); foreach ($broken_list as $email) { + $userobj = null; if ($user = mark_broken_email($email, true)) { - if ($user['nb_mails'] > 0 && $user['notify']) { - $mail = new PlMailer('emails/broken.mail.tpl'); - $dest = User::getSilentWithUID($user['uid']); - $mail->setTo($dest); - $mail->assign('user', $user); - $mail->assign('email', $email); - $mail->send(); - } else { - $profile = Profile::get($user['alias']); - WatchProfileUpdate::register($profile, 'broken'); - } + $userobj = User::getSilentWithUID($user['uid']); + } + if (is_null($userobj)) { + continue; + } + $profile = $userobj->profile(); + if (is_null($profile)) { + continue; + } + if ($user['nb_mails'] > 0 && $user['notify']) { + $mail = new PlMailer('emails/broken.mail.tpl'); + $mail->setTo($userobj); + $mail->assign('user', $user); + $mail->assign('email', $email); + $mail->send(); + } else { + WatchProfileUpdate::register($profile, 'broken'); + } - if (!isset($broken_user_list[$user['uid']])) { - $broken_user_list[$user['uid']] = array($email); - } else { - $broken_user_list[$user['uid']][] = $email; - } - $broken_user_email_count[$user['uid']] = $user['nb_mails']; + $pid = $profile->id(); + if (!isset($broken_user_list[$pid])) { + $broken_user_list[$pid] = array($email); + } else { + $broken_user_list[$pid][] = $email; } + $broken_user_email_count[$pid] = $user['nb_mails']; + $broken_user_profiles[$pid] = $profile; } XDB::execute('UPDATE email_redirect_account @@ -889,8 +914,8 @@ class EmailModule extends PLModule $csv = fopen('php://output', 'w'); fputcsv($csv, array('nom', 'promo', 'bounces', 'nbmails', 'url', 'corps', 'job', 'networking'), ';'); $corpsList = DirEnum::getOptions(DirEnum::CURRENTCORPS); - foreach ($broken_user_list as $uid => $mails) { - $profile = Profile::get($uid); + foreach ($broken_user_list as $pid => $mails) { + $profile = $broken_user_profiles[$pid]; $current_corps = $profile->getCorpsName(); $jobs = $profile->getJobs(); $companies = array(); @@ -903,7 +928,7 @@ class EmailModule extends PLModule $networking_list[] = $networking['address']; } fputcsv($csv, array($profile->fullName(), $profile->promo(), - join(',', $mails), $broken_user_email_count[$uid], + join(',', $mails), $broken_user_email_count[$pid], 'https://www.polytechnique.org/marketing/broken/' . $profile->hrid(), $current_corps, implode(',', $companies), implode(',', $networking_list)), ';'); } @@ -914,5 +939,5 @@ class EmailModule extends PLModule } } -// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8: ?>