Handles canceled payment transactions.
[platal.git] / bin / cron / notifs.send.php
index 891700f..8a873aa 100755 (executable)
@@ -1,7 +1,7 @@
-#!/usr/bin/php4 -q
+#!/usr/bin/php5 -q
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2004 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("../../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"
-          .  "    {$globals->baseurl}/carnet/panel.php\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='{$globals->baseurl}/carnet/panel.php'>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 .= "      {$globals->baseurl}/fiche.php?user={$x['bestalias']}&force_login=1\n\n";
-            $html .= "<li>(X{$x['promo']}) <a href='{$globals->baseurl}/fiche.php?user={$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';
+ini_set('memory_limit', '128M');
+
+$uids = XDB::query('SELECT  uid
+                      FROM  watch
+                     WHERE  FIND_IN_SET(\'mail\', flags)
+                  ORDER BY  uid');
+$iterator = User::iterOverUIDs($uids->fetchColumn());
+
+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);
     }
-
-    $text .= "-- \n"
-           . "L'équipe de Polytechnique.org\n\n"
-           . "------------------------------------------------------------------------\n\n"
-           . "Tu recois ce mail car tu as activé la notification automatique \n"
-           . "par mail des évènements que tu surveilles.\n\n"
-           . "Tu peux changer cette option sur :\n"
-           . "    {$globals->baseurl}/carnet/notifs.php";
-    $html .= <<<EOF
-    <hr />
-    <p>L'équipe de Polytechnique.org</p>
-    <br />
-    <p>
-    Tu recois ce mail car tu as activé la notification automatique par mail des évènements que tu surveilles.
-    </p>
-    <p>Tu peux changer cette option sur la <a href="{$globals->baseurl}/carnet/notifs.php">page
-    de configuration des notifications</a>
-    </p>
-  </body>
-</html>
-EOF;
-    
-    $mailer = new HermesMailer();
-    $mailer->setFrom("Carnet Polytechnicien <support_carnet@polytechnique.org>");
-    $mailer->addTo("\"{$u['prenom']} {$u['nom']}\" <{$u['bestalias']}@polytechnique.org>");
-    $mailer->setSubject("Notifications de la semaine $week");
-    $mailer->setTxtBody($text);
-    if ($u['mail_fmt'] == 'html') { $mailer->setHtmlBody($html); }
-    $mailer->send();
+    unset($watch);
+    unset($user);
 }
 
+XDB::execute("UPDATE  watch_profile
+                 SET  ts = NOW()
+               WHERE  field = 'broken'");
+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 fenc=utf-8:
 ?>