Proof of concept:
[platal.git] / include / marketing.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2006 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22 require_once("xorg.misc.inc.php");
23
24 // {{{ function mark_from_mail
25
26 function mark_from_mail($uid, $email) {
27 global $globals;
28 $res = $globals->xdb->query(
29 "SELECT u.nom, u.prenom, a.alias
30 FROM register_marketing AS r
31 INNER JOIN auth_user_md5 AS u ON (r.sender = u.user_id)
32 INNER JOIN aliases AS a ON (a.id = r.sender AND a.type='a_vie')
33 WHERE r.uid = {?} AND r.email = {?}",
34 $uid, $email);
35 $sender = $res->fetchOneAssoc();
36 return "\"".$sender['prenom']." ".$sender['nom']."\" <".$sender['alias']."@polytechnique.org>";
37
38 }
39
40 // }}}
41 // {{{ function mark_text_mail
42
43 function mark_text_mail($uid, $email)
44 {
45 global $globals;
46 $title = "Annuaire en ligne des Polytechniciens";
47
48 $res = $globals->xdb->query("SELECT COUNT(*) FROM auth_user_md5 WHERE perms IN ('admin', 'user') and deces = 0");
49 $num_users = $res->fetchOneCell();
50
51 $res = $globals->xdb->query("SELECT flags, nom, prenom, promo FROM auth_user_md5 WHERE user_id = {?}", $uid);
52 $u = $res->fetchOneAssoc();
53
54 $mailorg = make_forlife($u['prenom'],$u['nom'],$u['promo']);
55
56 $to = "\"".$u['prenom']." ".$u['nom']."\" <".$email.">";
57
58 $titre = "Annuaire en ligne des Polytechniciens";
59 $text = " ".($u['flags']?"Chère":"Cher")." camarade,\n\n";
60 $text .= " Ta fiche n'est pas à jour dans l'annuaire des Polytechniciens sur Internet. Pour la mettre à jour, il te suffit de visiter cette page ou de copier cette adresse dans la barre de ton navigateur :\n\n";
61 $text .= "==========================================================\n";
62 $text .= $globals->baseurl."/register/?hash=%%hash%%\n";
63 $text .= "==========================================================\n\n";
64 $text .= "Il ne te faut que 5 minutes sur http://www.polytechnique.org/ pour rejoindre les $num_users camarades branchés grâce au système de reroutage de l'X et qui permet de joindre un camarade en connaissant seulement son nom et son prénom... et de bénéficier pour la vie d'une adresse prestigieuse $mailorg@polytechnique.org et son alias discret $mailorg@m4x.org (m4x = mail for X).\n\n";
65 $text .= "Pas de nouvelle boîte aux lettres à relever, il suffit de la rerouter vers ton adresse personnelle et/ou professionnelle que tu indiques et que tu peux changer tous les jours si tu veux sans imposer à tes correspondants de modifier leur carnet d'adresses...\n\n";
66 $text .= "De plus, le site web offre les services d'annuaire (recherche multi-critères), de forums, de mailing-lists. Ce portail est géré par une dizaine de jeunes camarades, avec le soutien et les conseils de nombreux X de toutes promotions, incluant notamment des camarades de la Kès des élèves de l'X et d'autres de l'AX. Les serveurs sont hébergés au sein même de l'Ecole polytechnique, sur une connexion rapide, et les services évoluent en fonction des besoins exprimés par la communauté sur Internet.\n\n";
67 $text .="N'hésite pas à transmettre ce message à tes camarades ou à nous écrire, nous proposer toute amélioration ou suggestion pour les versions prochaines du site.\n\n";
68 $text .= "A bientôt sur http://www.polytechnique.org !\n";
69 $text .= "Bien à toi,\n";
70 $text .= "%%sender%%\n\n";
71 $text .= "--\n";
72 $text .= "Polytechnique.org\n";
73 $text .= "\"Le portail des élèves & anciens élèves de l'X\"\n";
74 $text .= "http://www.polytechnique.org/\n";
75 $text .= "http://www.polytechnique.net/\n";
76 return array($to, $title, $text);
77 }
78 // }}}
79 // {{{ function mark_send_mail()
80
81 function mark_send_mail($uid, $email, $perso, $to='', $title='', $text='')
82 {
83 require_once("diogenes/diogenes.hermes.inc.php");
84 global $globals;
85
86 $hash = rand_url_id(12);
87 $globals->xdb->execute('UPDATE register_marketing SET nb=nb+1,hash={?},last=NOW() WHERE uid={?} AND email={?}', $hash, $uid, $email);
88
89 if ($to == '')
90 list($to, $title, $text) = mark_text_mail($uid, $email);
91
92 if ($perso == 'staff')
93 $from = "\"Equipe Polytechnique.org\" <register@polytechnique.org>";
94 else
95 $from = mark_from_mail($uid, $email);
96
97 $sender = substr($from, 1, strpos($from, '"', 2)-1);
98 $text = str_replace(array("%%hash%%", "%%sender%%"), array($hash, $sender), $text);
99
100 $mailer = new HermesMailer();
101 $mailer->setFrom($from);
102 $mailer->addTo($to);
103 $mailer->setSubject($title);
104 $mailer->setTxtBody(wordwrap($text, 80));
105 $mailer->send();
106 }
107
108 // }}}
109 // {{{ function relance
110
111 function relance($uid, $nbx = -1)
112 {
113 require_once('xorg.mailer.inc.php');
114 global $globals;
115
116 if ($nbx < 0) {
117 $res = $globals->xdb->query("SELECT COUNT(*) FROM auth_user_md5 WHERE deces=0");
118 $nbx = $res->fetchOneCell();
119 }
120
121 $res = $globals->xdb->query(
122 "SELECT r.date, u.promo, u.nom, u.prenom, r.email, r.bestalias
123 FROM register_pending AS r
124 INNER JOIN auth_user_md5 AS u ON u.user_id = r.uid
125 WHERE hash!='INSCRIT' AND uid={?} AND TO_DAYS(relance) < TO_DAYS(NOW())", $uid);
126 if (!list($date, $promo, $nom, $prenom, $email, $alias) = $res->fetchOneRow()) {
127 return false;
128 }
129
130 require_once('secure_hash.inc.php');
131
132 $hash = rand_url_id(12);
133 $pass = rand_pass();
134 $pass_encrypted = hash_encrypt($pass);
135 $fdate = strftime('%d %B %Y', strtotime($date));
136
137 $mymail = new XOrgMailer('marketing.relance.tpl');
138 $mymail->assign('nbdix', $nbx);
139 $mymail->assign('fdate', $fdate);
140 $mymail->assign('lusername', $alias);
141 $mymail->assign('nveau_pass', $pass);
142 $mymail->assign('baseurl', $globals->baseurl);
143 $mymail->assign('lins_id', $hash);
144 $mymail->assign('lemail', $email);
145 $mymail->assign('subj', $alias.'@'.$globals->mail->domain);
146 $mymail->send();
147 $globals->xdb->execute('UPDATE register_pending SET hash={?}, password={?}, relance=NOW() WHERE uid={?}', $hash, $pass_encrypted, $uid);
148
149 return "$prenom $nom ($promo)";
150 }
151
152 // }}}
153
154 // vim:set et sw=4 sts=4 sws=4:
155 ?>