From: x2000habouzit Date: Sun, 7 Nov 2004 14:30:32 +0000 (+0000) Subject: mail is ok X-Git-Tag: xorg/old~1032 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=7a72452af7746cfa46105966ca58b7d01d190a89;p=platal.git mail is ok --- diff --git a/include/notifs.inc.php b/include/notifs.inc.php index d65de98..570238a 100644 --- a/include/notifs.inc.php +++ b/include/notifs.inc.php @@ -18,7 +18,7 @@ * 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); @@ -93,6 +93,76 @@ function getNbNotifs() { return "$n notifications !"; } +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(); diff --git a/scripts/cron/send_notifs.php b/scripts/cron/send_notifs.php new file mode 100755 index 0000000..83caa3a --- /dev/null +++ b/scripts/cron/send_notifs.php @@ -0,0 +1,62 @@ +#!/usr/bin/php4 -q +_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 ", + replace_accent("{$u['prenom']} {$u['nom']} <{$u['forlife']}@polytechnique.org>"), + "Notifications de la semaine ".date("W - Y")); + $mailer->setBody($text); + $mailer->send(); +} + +?> diff --git a/scripts/migration/0.9.2/notifs.sql b/scripts/migration/0.9.2/notifs.sql index 4b04f1c..ed5aade 100644 --- a/scripts/migration/0.9.2/notifs.sql +++ b/scripts/migration/0.9.2/notifs.sql @@ -1,6 +1,7 @@ alter table aliases add index (type); alter table auth_user_quick add column watch_flags set('contacts','mail') not null default 'contacts'; alter table auth_user_quick add column watch_last timestamp not null; +alter table auth_user_quick add index(watch_flags); create table watch_cat ( id smallint not null auto_increment,