first reimport from platal
[platal.git] / include / marketing.inc.php
CommitLineData
0337d704 1<?php
2/***************************************************************************
3 * Copyright (C) 2003-2004 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
22require_once("xorg.misc.inc.php");
23
24// {{{ function mark_from_mail
25function mark_from_mail($uid, $email) {
26 global $globals;
27 $res = $globals->xdb->query(
28 "SELECT u.nom, u.prenom, a.alias
29 FROM register_marketing AS r
30 INNER JOIN auth_user_md5 AS u ON (r.sender = u.user_id)
31 INNER JOIN aliases AS a ON (a.id = r.sender AND a.type='a_vie')
32 WHERE r.uid = {?} AND r.email = {?}",
33 $uid, $email);
34 $sender = $res->fetchOneAssoc();
35 return "\"".$sender['prenom']." ".$sender['nom']."\" <".$sender['alias']."@polytechnique.org>";
36
37}
38// }}}
39
40// {{{ function mark_text_mail
41
42function mark_text_mail($uid, $email)
43{
44 global $globals;
45 $title = "Annuaire en ligne des Polytechniciens";
46
47 $res = $globals->xdb->query("SELECT COUNT(*) FROM auth_user_md5 WHERE perms IN ('admin', 'user') and deces = 0");
48 $num_users = $res->fetchOneCell();
49
50 $res = $globals->xdb->query("SELECT flags, nom, prenom, promo FROM auth_user_md5 WHERE user_id = {?}", $uid);
51 $u = $res->fetchOneAssoc();
52
53 $mailorg = make_forlife($u['prenom'],$u['nom'],$u['promo']);
54
55 $to = "\"".$u['prenom']." ".$u['nom']."\" <".$email.">";
56
57 $titre = "Annuaire en ligne des Polytechniciens";
58 $text = " ".($u['flags']?"Chère":"Cher")." camarade,\n\n";
59 $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";
60 $text .= "==========================================================\n";
61 $text .= $globals->baseurl."/register/?hash=%%hash%%\n";
62 $text .= "==========================================================\n\n";
63 $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";
64 $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";
65 $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";
66 $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";
67 $text .= "A bientôt sur http://www.polytechnique.org !\n";
68 $text .= "Bien à toi,\n";
69 $text .= "%%sender%%\n\n";
70 $text .= "--\n";
71 $text .= "Polytechnique.org\n";
72 $text .= "\"Le portail des élèves & anciens élèves de l'X\"\n";
73 $text .= "http://www.polytechnique.org/\n";
74 $text .= "http://www.polytechnique.net/\n";
75 return array($to, $title, $text);
76}
77// }}}
78
79// {{{ function mark_send_mail()
80
81function 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
111function 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 $hash = rand_url_id(12);
131 $pass = rand_pass();
132 $pass_md5 = md5($pass);
133 $fdate = strftime('%d %B %Y', strtotime($date));
134
135 $mymail = new XOrgMailer('marketing.relance.tpl');
136 $mymail->assign('nbdix', $nbx);
137 $mymail->assign('fdate', $fdate);
138 $mymail->assign('lusername', $alias);
139 $mymail->assign('nveau_pass', $pass);
140 $mymail->assign('baseurl', $globals->baseurl);
141 $mymail->assign('lins_id', $hash);
142 $mymail->assign('lemail', $email);
143 $mymail->assign('subj', $alias.'@'.$globals->mail->domain);
144 $mymail->send();
145 $globals->xdb->execute('UPDATE register_pending SET hash={?}, password={?}, relance=NOW() WHERE uid={?}', $hash, $pass_md5, $uid);
146
147 return "$prenom $nom ($promo)";
148}
149
150// }}}
151
152// vim:set et sw=4 sts=4 sws=4:
153?>