-require_once('./connect.db.inc.php');
-require_once("../../include/notifs.inc.php");
-require_once("diogenes/diogenes.hermes.inc.php");
-
-$all = new AllNotifs();
-
-foreach($all->_data as $u) {
- $week = date("W - Y");
-
- $text = " ".($u['sexe'] ? 'Chère' : 'Cher')." {$u['prenom']},\n\n"
- . " Voici les évènements survenus dans la semaine écoulée,\n"
- . "et depuis ta dernière visite sur le site.\n\n"
- . "Tu trouveras les mêmes informations sur la page :\n"
- . " https://www.polytechnique.org/carnet/panel\n\n"
- . "------------------------------------------------------------------------\n\n";
-
- $html = <<<EOF
-<html>
- <head>
- <title>Notifications de la semaine $week</title>
- </head>
- <body>
- <p>Voici les évènements survenus dans la semaine écoulée, et depuis ta dernière visite sur le site.</p>
- <p>Tu trouveras les mêmes informations sur <a href='https://www.polytechnique.org/carnet/panel'>cette page</a></p>
-EOF;
-
- foreach($u['data'] as $cid=>$d) {
- $text .= " {$all->_cats[$cid][(count($d)==1)?'mail_sg':'mail']} :\n\n";
- $html .= "<h1 style='font-size: 120%'>{$all->_cats[$cid][(count($d)==1)?'mail_sg':'mail']} :</h1>\n<ul>\n";
-
- foreach($d as $promo=>$x) {
- require_once('../../plugins/modifier.date_format.php');
- $date = smarty_modifier_date_format($x['date'], '%d %b %Y');
- $text .= " - (X{$x['promo']}) {$x['prenom']} {$x['nom']} le $date\n";
- $text .= " https://www.polytechnique.org/profile/{$x['bestalias']}?force_login=1\n\n";
- $html .= "<li>(X{$x['promo']}) <a href='https://www.polytechnique.org/profile/{$x['bestalias']}?force_login=1'>{$x['prenom']} {$x['nom']}</a> le $date</li>\n";
- }
- $text .= "\n";
- $html .= "</ul>\n";
+require_once 'connect.db.inc.php';
+require_once 'plmailer.php';
+require_once 'notifs.inc.php';
+
+$uids = XDB::query('SELECT uid
+ FROM watch
+ WHERE FIND_IN_SET(\'mail\', flags)
+ ORDER BY uid');
+$iterator = User::iterOverUIDs($uids->fetchColumn());
+
+$mailer = new PlMailer('carnet/notif.mail.tpl');
+while($user = $iterator->next()) {
+ $watch = new Watch($user);
+ if ($watch->count() > 0) {
+ $notifs = $watch->events();
+ $mailer->assign('sex', $user->isFemale());
+ $mailer->assign('yourself', $user->display_name);
+ $mailer->assign('week', date('W - Y'));
+ $mailer->assign('notifs', $notifs);
+ $mailer->sendTo($user);
+ unset($notifs);