Handles canceled payment transactions.
[platal.git] / bin / cron / notifs.send.php
index abaa47d..8a873aa 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/php5 -q
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2009 Polytechnique.org                              *
+ *  Copyright (C) 2003-2014 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************/
 
-require_once('connect.db.inc.php');
-require_once('plmailer.php');
-require_once('notifs.inc.php');
+require_once 'connect.db.inc.php';
+require_once 'plmailer.php';
+require_once 'notifs.inc.php';
+ini_set('memory_limit', '128M');
 
-$all = new AllNotifs();
+$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');
-foreach ($all->_data as $u) {
-    $mailer = new PlMailer('carnet/notif.mail.tpl');
-    $mailer->assign('u', $u);
-    $mailer->assign('week', date("W - Y"));
-    $mailer->assign('cats', $all->_cats);
-    $mailer->addTo('"' . $u['prenom'] . ' ' . $u['nom'] . '" <' . $u['bestalias'] . '@polytechnique.org>');
-    $mailer->send($u['mail_fmt'] == 'html');
+while($user = $iterator->next()) {
+    $watch = new Watch($user);
+    if ($watch->count() > 0) {
+        $notifs = $watch->events();
+        $mailer = new PlMailer('carnet/notif.mail.tpl');
+        $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($mailer);
+        unset($notifs);
+    }
+    unset($watch);
+    unset($user);
 }
 
 XDB::execute("UPDATE  watch_profile
@@ -42,5 +54,5 @@ XDB::execute("UPDATE  watch_profile
 XDB::execute('DELETE FROM  watch_profile
                     WHERE  ts < DATE_SUB(CURRENT_DATE, INTERVAL 15 DAY)');
 
-// 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:
 ?>