first reimport from platal
[platal.git] / htdocs / register / end.php
1 <?
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
22 require_once('xorg.inc.php');
23 new_simple_page('register/end.tpl', AUTH_PUBLIC);
24 require_once('user.func.inc.php');
25
26 if (Env::has('hash')) {
27 $res = $globals->xdb->query(
28 "SELECT r.uid, r.forlife, r.bestalias, r.mailorg2, r.password, r.email, r.naissance, u.nom, u.prenom, u.promo
29 FROM register_pending AS r
30 INNER JOIN auth_user_md5 AS u ON r.uid = u.user_id
31 WHERE hash={?} AND hash!='INSCRIT'", Env::get('hash'));
32 }
33
34 if ( !Env::has('hash') ||
35 !list($uid, $forlife, $bestalias, $mailorg2, $password, $email, $naissance, $nom, $prenom, $promo) = $res->fetchOneRow())
36 {
37 $page->kill("<p>Cette adresse n'existe pas, ou plus, sur le serveur.</p>
38 <p>Causes probables :</p>
39 <ol>
40 <li>Vérifie que tu visites l'adresse du dernier e-mail reçu s'il y en a eu plusieurs.</li>
41 <li>Tu as peut-être mal copié l'adresse reçue par mail, vérifie-la à la main.</li>
42 <li>
43 Tu as peut-être attendu trop longtemps pour confirmer. Les
44 pré-inscriptions sont annulées tous les 30 jours.
45 </li>
46 <li>
47 Tu es en fait déjà inscrit.
48 </li>
49 </ol>");
50 }
51
52
53
54 /***********************************************************/
55 /****************** REALLY CREATE ACCOUNT ******************/
56 /***********************************************************/
57
58 $globals->xdb->execute('UPDATE auth_user_md5
59 SET password={?}, perms="user", date=NOW(), naissance={?}, date_ins = NOW()
60 WHERE user_id={?}', $password, $naissance, $uid);
61 $globals->xdb->execute('REPLACE INTO auth_user_quick (user_id) VALUES ({?})', $uid);
62 $globals->xdb->execute('INSERT INTO aliases (id,alias,type) VALUES ({?}, {?}, "a_vie")', $uid, $forlife);
63 $globals->xdb->execute('INSERT INTO aliases (id,alias,type,flags) VALUES ({?}, {?}, "alias", "bestalias")', $uid, $bestalias);
64 if ($mailorg2) {
65 $globals->xdb->execute('INSERT INTO aliases (id,alias,type) VALUES ({?}, {?}, "alias")', $uid, $mailorg2);
66 }
67
68 require_once('emails.inc.php');
69 $redirect = new Redirect($uid);
70 $redirect->add_email($email);
71
72 // on cree un objet logger et on log l'inscription
73 $logger = new DiogenesCoreLogger($uid);
74 $logger->log('inscription', $email);
75
76 $globals->xdb->execute('UPDATE register_pending SET hash="INSCRIT" WHERE uid={?}', $uid);
77
78 $globals->hook->subscribe($forlife, $uid, $promo, $password);
79
80 require_once('xorg.mailer.inc.php');
81 $mymail = new XOrgMailer('inscription.reussie.tpl');
82 $mymail->assign('forlife', $forlife);
83 $mymail->assign('prenom', $prenom);
84 $mymail->send();
85
86 start_connexion($uid,false);
87 $_SESSION['auth'] = AUTH_MDP;
88
89 /***********************************************************/
90 /************* envoi d'un mail au démarcheur ***************/
91 /***********************************************************/
92 $res = $globals->xdb->iterRow(
93 "SELECT DISTINCT sa.alias, s.nom, s.prenom
94 FROM register_marketing AS m
95 INNER JOIN auth_user_md5 AS s ON ( m.sender = s.user_id )
96 INNER JOIN aliases AS sa ON ( sa.id = m.sender AND FIND_IN_SET('bestalias', sa.flags) )
97 WHERE m.uid = {?}", $uid);
98 $globals->xdb->execute("UPDATE register_mstats SET success=NOW() WHERE uid={?}", $uid);
99
100 while (list($salias, $snom, $sprenom) = $res->next()) {
101 require_once('diogenes/diogenes.hermes.inc.php');
102 $mymail = new HermesMailer();
103 $mymail->setSubject("$prenom $nom s'est inscrit à Polytechnique.org !");
104 $mymail->setFrom('"Marketing Polytechnique.org" <register@polytechnique.org>');
105 $mymail->addTo("\"$sprenom $snom\" <$salias@{$globals->mail->domain}>");
106 $msg = "Cher $sprenom,\n\n"
107 . "Nous t'écrivons pour t'informer que {$prenom} {$nom} (X{$promo}), "
108 . "que tu avais incité à s'inscrire à Polytechnique.org, "
109 . "vient à l'instant de terminer son inscription !!\n\n"
110 . "Merci de ta participation active à la reconnaissance de ce site !!!\n\n"
111 . "Bien cordialement,\n"
112 . "L'équipe Polytechnique.org";
113 $mymail->setTxtBody(wordwrap($msg, 72));
114 $mymail->send();
115 }
116
117 $globals->xdb->execute("DELETE FROM register_marketing WHERE uid = {?}", $uid);
118
119 header('Location: success.php');
120 $page->assign('uid', $uid);
121 $page->run();
122
123 ?>