Convert source code to UTF-8
[platal.git] / include / marketing.inc.php
CommitLineData
0337d704 1<?php
2/***************************************************************************
5ddeb07c 3 * Copyright (C) 2003-2007 Polytechnique.org *
0337d704 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
7460eb99 25
0337d704 26function mark_from_mail($uid, $email) {
08cce2ff 27 $res = XDB::query(
0337d704 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>";
0337d704 36}
0337d704 37
7460eb99 38// }}}
0337d704 39// {{{ function mark_text_mail
40
41function mark_text_mail($uid, $email)
42{
43 global $globals;
44 $title = "Annuaire en ligne des Polytechniciens";
45
08cce2ff 46 $res = XDB::query("SELECT COUNT(*) FROM auth_user_md5 WHERE perms IN ('admin', 'user') and deces = 0");
0337d704 47 $num_users = $res->fetchOneCell();
48
08cce2ff 49 $res = XDB::query("SELECT flags, nom, prenom, promo FROM auth_user_md5 WHERE user_id = {?}", $uid);
0337d704 50 $u = $res->fetchOneAssoc();
51
52 $mailorg = make_forlife($u['prenom'],$u['nom'],$u['promo']);
53
54 $to = "\"".$u['prenom']." ".$u['nom']."\" <".$email.">";
55
56 $titre = "Annuaire en ligne des Polytechniciens";
a7de4ef7 57 $text = " ".($u['flags']?"Chère":"Cher")." camarade,\n\n";
58 $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";
0337d704 59 $text .= "==========================================================\n";
20d90835 60 $text .= $globals->baseurl."/register/%%hash%%\n";
0337d704 61 $text .= "==========================================================\n\n";
a7de4ef7 62 $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";
63 $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";
64 $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";
65 $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";
66 $text .= "A bientôt sur http://www.polytechnique.org !\n";
67 $text .= "Bien à toi,\n";
0337d704 68 $text .= "%%sender%%\n\n";
69 $text .= "--\n";
70 $text .= "Polytechnique.org\n";
a7de4ef7 71 $text .= "\"Le portail des élèves & anciens élèves de l'X\"\n";
0337d704 72 $text .= "http://www.polytechnique.org/\n";
73 $text .= "http://www.polytechnique.net/\n";
74 return array($to, $title, $text);
75}
76// }}}
0337d704 77// {{{ function mark_send_mail()
78
79function mark_send_mail($uid, $email, $perso, $to='', $title='', $text='')
80{
0337d704 81 $hash = rand_url_id(12);
08cce2ff 82 XDB::execute('UPDATE register_marketing SET nb=nb+1,hash={?},last=NOW() WHERE uid={?} AND email={?}', $hash, $uid, $email);
0337d704 83
84 if ($to == '')
85 list($to, $title, $text) = mark_text_mail($uid, $email);
86
87 if ($perso == 'staff')
88 $from = "\"Equipe Polytechnique.org\" <register@polytechnique.org>";
89 else
90 $from = mark_from_mail($uid, $email);
91
92 $sender = substr($from, 1, strpos($from, '"', 2)-1);
93 $text = str_replace(array("%%hash%%", "%%sender%%"), array($hash, $sender), $text);
94
1e33266a 95 $mailer = new PlMailer();
0337d704 96 $mailer->setFrom($from);
97 $mailer->addTo($to);
98 $mailer->setSubject($title);
99 $mailer->setTxtBody(wordwrap($text, 80));
100 $mailer->send();
101}
102
103// }}}
104// {{{ function relance
105
106function relance($uid, $nbx = -1)
107{
0337d704 108 global $globals;
109
110 if ($nbx < 0) {
08cce2ff 111 $res = XDB::query("SELECT COUNT(*) FROM auth_user_md5 WHERE deces=0");
0337d704 112 $nbx = $res->fetchOneCell();
113 }
114
08cce2ff 115 $res = XDB::query(
0337d704 116 "SELECT r.date, u.promo, u.nom, u.prenom, r.email, r.bestalias
117 FROM register_pending AS r
118 INNER JOIN auth_user_md5 AS u ON u.user_id = r.uid
119 WHERE hash!='INSCRIT' AND uid={?} AND TO_DAYS(relance) < TO_DAYS(NOW())", $uid);
120 if (!list($date, $promo, $nom, $prenom, $email, $alias) = $res->fetchOneRow()) {
121 return false;
122 }
123
46bde4d1 124 require_once('secure_hash.inc.php');
125
0337d704 126 $hash = rand_url_id(12);
127 $pass = rand_pass();
46bde4d1 128 $pass_encrypted = hash_encrypt($pass);
0337d704 129 $fdate = strftime('%d %B %Y', strtotime($date));
130
1e33266a 131 $mymail = new PlMailer('marketing/mail.relance.tpl');
0337d704 132 $mymail->assign('nbdix', $nbx);
133 $mymail->assign('fdate', $fdate);
134 $mymail->assign('lusername', $alias);
135 $mymail->assign('nveau_pass', $pass);
136 $mymail->assign('baseurl', $globals->baseurl);
137 $mymail->assign('lins_id', $hash);
138 $mymail->assign('lemail', $email);
139 $mymail->assign('subj', $alias.'@'.$globals->mail->domain);
140 $mymail->send();
08cce2ff 141 XDB::execute('UPDATE register_pending SET hash={?}, password={?}, relance=NOW() WHERE uid={?}', $hash, $pass_encrypted, $uid);
0337d704 142
143 return "$prenom $nom ($promo)";
144}
145
146// }}}
147
a7de4ef7 148// vim:set et sw=4 sts=4 sws=4 enc=utf-8:
0337d704 149?>