New PlMailer based on Hermes code:
[platal.git] / include / register.inc.php
index a05f8f5..d073be3 100644 (file)
@@ -70,7 +70,6 @@ function get_X_mat($ourmat)
 
 function check_mat($promo, $mat, $nom, $prenom, &$ourmat, &$ourid)
 {
-    global $globals;
     if (!preg_match('/^[0-9][0-9][0-9][0-9][0-9][0-9]$/', $mat)) {
         return "Le matricule doit comporter 6 chiffres.";
     }
@@ -84,7 +83,7 @@ function check_mat($promo, $mat, $nom, $prenom, &$ourmat, &$ourid)
         $ourmat = sprintf('%04u%04u', 1900+$year, $rang);
     }
 
-    $res = $globals->xdb->query(
+    $res = XDB::query(
             'SELECT  user_id, promo, perms IN ("admin","user"), nom, prenom 
               FROM  auth_user_md5
              WHERE  matricule={?} and deces = 0', $ourmat);
@@ -105,9 +104,7 @@ function check_mat($promo, $mat, $nom, $prenom, &$ourmat, &$ourid)
 
 function check_old_mat($promo, $mat, $nom, $prenom, &$ourmat, &$ourid)
 {
-    global $globals;
-
-    $res = $globals->xdb->iterRow(
+    $res = XDB::iterRow(
             'SELECT  user_id, nom, prenom, matricule
                FROM  auth_user_md5
               WHERE  promo={?} AND deces=0 AND perms="pending"', $promo);
@@ -119,7 +116,7 @@ function check_old_mat($promo, $mat, $nom, $prenom, &$ourmat, &$ourid)
         }
     }
 
-    $res = $globals->xdb->iterRow(
+    $res = XDB::iterRow(
             'SELECT  user_id, nom, prenom, matricule, alias
                FROM  auth_user_md5 AS u
          INNER JOIN  aliases       AS a ON (u.user_id = a.id and FIND_IN_SET("bestalias", a.flags))
@@ -128,7 +125,7 @@ function check_old_mat($promo, $mat, $nom, $prenom, &$ourmat, &$ourid)
         if (user_cmp($prenom, $nom, $_prenom, $_nom)) {
             $ourid  = $_uid;
             $ourmat = $_mat;
-            return "Tu es vraissemblablement déjà inscrit !";
+            return "Tu es vraisemblablement déjà inscrit !";
         }
     }
     return "erreur: vérifie que tu as bien orthographié ton nom !";
@@ -139,7 +136,6 @@ function check_old_mat($promo, $mat, $nom, $prenom, &$ourmat, &$ourid)
 
 function check_new_user(&$sub)
 {
-    global $globals;
     extract($sub);
 
     $prenom  = preg_replace("/[ \t]+/", ' ', trim($prenom));
@@ -172,35 +168,32 @@ function check_new_user(&$sub)
 
 function create_aliases (&$sub)
 {
-    global $globals;
     extract ($sub);
 
     $mailorg  = make_username($prenom, $nom);
     $mailorg2 = $mailorg.sprintf(".%02u", ($promo%100));
     $forlife  = make_forlife($prenom, $nom, $promo);
 
-    $res      = $globals->xdb->query('SELECT COUNT(*) FROM aliases WHERE alias={?}', $forlife);
+    $res      = XDB::query('SELECT COUNT(*) FROM aliases WHERE alias={?}', $forlife);
     if ($res->fetchOneCell() > 0) {
         return "Tu as un homonyme dans ta promo, il faut traiter ce cas manuellement.<br />".
             "envoie un mail à <a href=\"mailto:support@polytechnique.org\">support@polytechnique.org</a> en expliquant ta situation.";
     }
     
-    $res      = $globals->xdb->query('SELECT id, type, expire FROM aliases WHERE alias={?}', $mailorg);
+    $res      = XDB::query('SELECT id, type, expire FROM aliases WHERE alias={?}', $mailorg);
 
     if ( $res->numRows() ) {
 
         list($h_id, $h_type, $expire) = $res->fetchOneRow();
-        $res->free();
 
         if ( $h_type != 'homonyme' and empty($expire) ) {
-            $globals->xdb->execute('UPDATE aliases SET expire=ADDDATE(NOW(),INTERVAL 1 MONTH) WHERE alias={?}', $mailorg);
-            $globals->xdb->execute('REPLACE INTO homonymes (homonyme_id,user_id) VALUES ({?},{?})', $h_id, $h_id);
-            $globals->xdb->execute('REPLACE INTO homonymes (homonyme_id,user_id) VALUES ({?},{?})', $h_id, $uid);
-            $res = $globals->xdb->query("SELECT alias FROM aliases WHERE id={?} AND expire IS NULL", $h_id);
+            XDB::execute('UPDATE aliases SET expire=ADDDATE(NOW(),INTERVAL 1 MONTH) WHERE alias={?}', $mailorg);
+            XDB::execute('REPLACE INTO homonymes (homonyme_id,user_id) VALUES ({?},{?})', $h_id, $h_id);
+            XDB::execute('REPLACE INTO homonymes (homonyme_id,user_id) VALUES ({?},{?})', $h_id, $uid);
+            $res = XDB::query("SELECT alias FROM aliases WHERE id={?} AND expire IS NULL", $h_id);
             $als = $res->fetchColumn();
 
-            require_once('diogenes/diogenes.hermes.inc.php');
-            $mailer = new HermesMailer();
+            $mailer = new PlMailer();
             $mailer->setFrom('"Support Polytechnique.org" <support@polytechnique.org>');
             $mailer->addTo("$mailorg@polytechnique.org");
             $mailer->setSubject("perte de ton alias $mailorg dans un mois !");
@@ -246,6 +239,22 @@ function create_aliases (&$sub)
 }
 
 // }}}
+// {{{ function send_alert_mail
+
+function send_alert_mail($state, $body)
+{
+    $mailer = new PlMailer();
+    $mailer->setFrom("webmaster@polytechnique.org");
+    $mailer->addTo("hotliners@staff.polytechnique.org");
+    $mailer->setSubject("ALERTE LORS DE L'INSCRIPTION de "
+        . $state['prenom'] . ' ' . $state['nom'] . '(' . $promo . ')');
+    $mailer->setTxtBody($body
+        . "\n\nIndentifiants :\n" . var_export($state, true)
+        . "\n\nInformations de connexion :\n" . var_export($_SERVER, true));
+    $mailer->send();
+}
+
+// }}}
 // {{{ function finish_ins
 
 function finish_ins($sub_state)
@@ -258,15 +267,14 @@ function finish_ins($sub_state)
     $pass_encrypted = hash_encrypt($pass_clair);
     $hash     = rand_url_id(12);
   
-    $globals->xdb->execute('UPDATE auth_user_md5 SET last_known_email={?} WHERE matricule = {?}', $email, $mat);
+    XDB::execute('UPDATE auth_user_md5 SET last_known_email={?} WHERE matricule = {?}', $email, $mat);
 
-    $globals->xdb->execute(
+    XDB::execute(
             "REPLACE INTO  register_pending (uid, forlife, bestalias, mailorg2, password, email, date, relance, naissance, hash)
                    VALUES  ({?}, {?}, {?}, {?}, {?}, {?}, NOW(), 0, {?}, {?})",
             $uid, $forlife, $bestalias, $mailorg2, $pass_encrypted, $email, $naissance, $hash);
 
-    require_once('xorg.mailer.inc.php');
-    $mymail = new XOrgMailer('inscrire.mail.tpl');
+    $mymail = new PlMailer('register/inscrire.mail.tpl');
     $mymail->assign('mailorg', $bestalias);
     $mymail->assign('lemail',  $email);
     $mymail->assign('pass',    $pass);