* Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
***************************************************************************
- $Id: notifs.inc.php,v 1.12 2004-11-07 11:54:08 x2000habouzit Exp $
+ $Id: notifs.inc.php,v 1.13 2004-11-07 14:30:32 x2000habouzit Exp $
***************************************************************************/
define("WATCH_FICHE", 1);
return "<a href='$url'>$n notifications !</a>";
}
+class AllNotifs {
+ var $_cats = Array();
+ var $_data = Array();
+
+ function AllNotifs() {
+ global $globals;
+
+ $res = $globals->db->query("SELECT * FROM watch_cat");
+ while($tmp = mysql_fetch_assoc($res)) $this->_cats[$tmp['id']] = $tmp;
+ mysql_free_result($res);
+
+ $res = $globals->db->query("
+ (
+ SELECT q.user_id AS aid, v.prenom AS aprenom, IF(v.epouse='',v.nom,v.prenom) AS anom,
+ b.alias AS aforlife, (v.flags='femme') AS sexe,
+ u.promo, u.prenom, IF(u.epouse='',u.nom,u.epouse) AS nom, a.alias AS forlife,
+ wo.*, 1 AS contact, (u.perms='admin' OR u.perms='user') AS inscrit
+ FROM auth_user_quick AS q
+ INNER JOIN auth_user_md5 AS v USING(user_id)
+ INNER JOIN aliases AS b ON(q.user_id = b.id AND b.type='a_vie')
+ INNER JOIN contacts AS c ON(q.user_id = c.uid)
+ INNER JOIN watch_ops AS wo ON(wo.uid=c.contact AND wo.known > q.watch_last)
+ INNER JOIN watch_sub AS ws ON(ws.uid=q.user_id AND wo.cid=ws.cid)
+ INNER JOIN auth_user_md5 AS u ON(u.user_id = wo.uid)
+ LEFT JOIN aliases AS a ON(u.user_id = a.id AND a.type='a_vie')
+ WHERE q.watch_flags=3
+ ) UNION DISTINCT (
+ SELECT q.user_id AS aid, v.prenom AS aprenom, IF(v.epouse='',v.nom,v.prenom) AS anom,
+ b.alias AS aforlife, (v.flags='femme') AS sexe,
+ u.promo, u.prenom, IF(u.epouse='',u.nom,u.epouse) AS nom, a.alias AS forlife,
+ wo.*, NOT (c.contact IS NULL) AS contact, (u.perms='admin' OR u.perms='user') AS inscrit
+ FROM auth_user_quick AS q
+ INNER JOIN auth_user_md5 AS v USING(user_id)
+ INNER JOIN aliases AS b ON(q.user_id = b.id AND b.type='a_vie')
+ INNER JOIN watch_promo AS w ON(w.uid=q.user_id)
+ INNER JOIN auth_user_md5 AS u USING(promo)
+ LEFT JOIN contacts AS c ON(w.uid = c.uid AND c.contact=u.user_id)
+ INNER JOIN watch_sub AS ws ON(ws.uid=w.uid)
+ INNER JOIN watch_cat AS wc ON(wc.id=wo.cid AND wc.frequent=0)
+ INNER JOIN watch_ops AS wo ON(wo.cid=ws.cid AND wo.uid=u.user_id AND wo.known > q.watch_last)
+ LEFT JOIN aliases AS a ON(u.user_id = a.id AND a.type='a_vie')
+ WHERE q.watch_flags=3 OR q.watch_flags=1
+ ) UNION DISTINCT (
+ SELECT q.user_id AS aid, v.prenom AS aprenom, IF(v.epouse='',v.nom,v.prenom) AS anom,
+ b.alias AS aforlife, (v.flags='femme') AS sexe,
+ u.promo, u.prenom, IF(u.epouse='',u.nom,u.epouse) AS nom, a.alias AS forlife,
+ wo.*, 0 AS contact, (u.perms='admin' OR u.perms='user') AS inscrit
+ FROM auth_user_quick AS q
+ INNER JOIN auth_user_md5 AS v USING(user_id)
+ INNER JOIN aliases AS b ON(q.user_id = b.id AND b.type='a_vie')
+ INNER JOIN watch_nonins AS w ON(w.uid=q.user_id)
+ INNER JOIN auth_user_md5 AS u ON(w.ni_id=u.user_id)
+ INNER JOIN watch_sub AS ws ON(ws.uid=w.uid)
+ INNER JOIN watch_cat AS wc ON(wc.id=wo.cid)
+ INNER JOIN watch_ops AS wo ON(wo.cid=ws.cid AND wo.uid=u.user_id AND wo.known > q.watch_last)
+ LEFT JOIN aliases AS a ON(u.user_id = a.id AND a.type='a_vie')
+ WHERE q.watch_flags=3 OR q.watch_flags=1
+ )
+ ORDER BY cid,promo,nom");
+
+ while($tmp = mysql_fetch_assoc($res)) {
+ $aid = $tmp['aid'];
+ $this->_data[$aid] = Array("prenom" => $tmp['aprenom'], 'nom' => $tmp['anom'],
+ 'forlife'=>$tmp['aforlife'], 'sexe' => $tmp['sexe']);
+ unset($tmp['aprenom'],$tmp['anom'],$tmp['aforlife'],$tmp['aid'],$tmp['sexe']);
+ $this->_data[$aid]['data'][$tmp['cid']][] = $tmp;
+ }
+ }
+}
+
class Notifs {
var $_uid;
var $_cats = Array();
--- /dev/null
+#!/usr/bin/php4 -q
+<?php
+/***************************************************************************
+ * Copyright (C) 2003-2004 Polytechnique.org *
+ * http://opensource.polytechnique.org/ *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software *
+ * Foundation, Inc., *
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
+ ***************************************************************************
+ $Id: send_notifs.php,v 1.1 2004-11-07 14:30:32 x2000habouzit Exp $
+ ***************************************************************************/
+
+require('./connect.db.inc.php');
+require("../../include/notifs.inc.php");
+require("diogenes.mailer.inc.php");
+require("diogenes.misc.inc.php");
+
+$all = new AllNotifs();
+
+foreach($all->_data as $u) {
+ $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"
+ . " $baseurl/carnet/panel.php\n\n";
+ $text .= "------------------------------------------------------------\n\n";
+ foreach($u['data'] as $cid=>$d) {
+ $text .= " {$all->_cats[$cid]['mail']} :\n\n";
+ foreach($d as $promo=>$x) {
+ $text .= " - (X{$x['promo']}) {$x['prenom']} {$x['nom']} le {$x['date']}\n";
+ }
+ $text .= "\n";
+ }
+
+ $text .= "------------------------------------------------------------\n\n"
+ . "Tu recois ce mail car tu as activé la notification\n"
+ . "automatique par mail des évènements que tu surveilles.\n\n"
+ . "Tu peux changer cette option sur :\n"
+ . " $baseurl/carnet/notifs.php\n\n"
+ . "-- \n"
+ . "L'équipe de Polytechnique.org";
+
+ $mailer = new DiogenesMailer("Carnet Polytechnicien <support_carnet@polytechnique.org>",
+ replace_accent("{$u['prenom']} {$u['nom']} <{$u['forlife']}@polytechnique.org>"),
+ "Notifications de la semaine ".date("W - Y"));
+ $mailer->setBody($text);
+ $mailer->send();
+}
+
+?>