Fix #473
[platal.git] / bin / cron / notifs.send.php
1 #!/usr/bin/php4 -q
2 <?php
3 /***************************************************************************
4 * Copyright (C) 2003-2006 Polytechnique.org *
5 * http://opensource.polytechnique.org/ *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the Free Software *
19 * Foundation, Inc., *
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
21 ***************************************************************************/
22
23 require_once('./connect.db.inc.php');
24 require_once("../../include/notifs.inc.php");
25 require_once("diogenes/diogenes.hermes.inc.php");
26
27 $all = new AllNotifs();
28
29 foreach($all->_data as $u) {
30 $week = date("W - Y");
31
32 $text = " ".($u['sexe'] ? 'Chère' : 'Cher')." {$u['prenom']},\n\n"
33 . " Voici les événements survenus dans la semaine écoulée,\n"
34 . "et depuis ta dernière visite sur le site.\n\n"
35 . "Tu trouveras les mêmes informations sur la page :\n"
36 . " https://www.polytechnique.org/carnet/panel\n\n"
37 . "------------------------------------------------------------------------\n\n";
38
39 $html = <<<EOF
40 <html>
41 <head>
42 <title>Notifications de la semaine $week</title>
43 </head>
44 <body>
45 <p>Voici les événements survenus dans la semaine écoulée, et depuis ta dernière visite sur le site.</p>
46 <p>Tu trouveras les mêmes informations sur <a href='https://www.polytechnique.org/carnet/panel'>cette page</a></p>
47 EOF;
48
49 foreach($u['data'] as $cid=>$d) {
50 $text .= " {$all->_cats[$cid][(count($d)==1)?'mail_sg':'mail']} :\n\n";
51 $html .= "<h1 style='font-size: 120%'>{$all->_cats[$cid][(count($d)==1)?'mail_sg':'mail']} :</h1>\n<ul>\n";
52
53 foreach($d as $promo=>$x) {
54 require_once('../../plugins/modifier.date_format.php');
55 $date = smarty_modifier_date_format($x['date'], '%d %b %Y');
56 $text .= " - (X{$x['promo']}) {$x['prenom']} {$x['nom']} le $date\n";
57 $text .= " https://www.polytechnique.org/profile/{$x['bestalias']}?force_login=1\n\n";
58 $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";
59 }
60 $text .= "\n";
61 $html .= "</ul>\n";
62 }
63
64 $text .= "-- \n"
65 . "L'équipe de Polytechnique.org\n\n"
66 . "------------------------------------------------------------------------\n\n"
67 . "Tu recois ce mail car tu as activé la notification automatique \n"
68 . "par mail des événements que tu surveilles.\n\n"
69 . "Tu peux changer cette option sur :\n"
70 . " https://www.polytechnique.org/carnet/notifs";
71 $html .= <<<EOF
72 <hr />
73 <p>L'équipe de Polytechnique.org</p>
74 <br />
75 <p>
76 Tu recois ce mail car tu as activé la notification automatique par mail des événements que tu surveilles.
77 </p>
78 <p>Tu peux changer cette option sur la <a href="https://www.polytechnique.org/carnet/notifs">page
79 de configuration des notifications</a>
80 </p>
81 </body>
82 </html>
83 EOF;
84
85 $mailer = new HermesMailer();
86 $mailer->setFrom("Carnet Polytechnicien <support_carnet@polytechnique.org>");
87 $mailer->addTo("\"{$u['prenom']} {$u['nom']}\" <{$u['bestalias']}@polytechnique.org>");
88 $mailer->setSubject("Notifications de la semaine $week");
89 $mailer->setTxtBody($text);
90 if ($u['mail_fmt'] == 'html') { $mailer->setHtmlBody($html); }
91 $mailer->send();
92 }
93
94 ?>