Merge branch 'platal-0.10.0'
[platal.git] / modules / register / register.inc.php
index 4839e36..f7a5c4e 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2008 Polytechnique.org                              *
+ *  Copyright (C) 2003-2009 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -44,7 +44,7 @@ function user_cmp($prenom, $nom, $_prenom, $_nom)
 // }}}
 // {{{ function check_mat
 
-function check_mat($promo, $mat, $nom, $prenom, &$ourmat, &$ourid, &$watch, &$naiss)
+function check_mat($promo, $mat, &$nom, &$prenom, &$ourmat, &$ourid, &$watch, &$naiss)
 {
     if (!preg_match('/^[0-9][0-9][0-9][0-9][0-9][0-9]$/', $mat)) {
         return "Le matricule doit comporter 6 chiffres.";
@@ -71,6 +71,8 @@ function check_mat($promo, $mat, $nom, $prenom, &$ourmat, &$ourid, &$watch, &$na
         return "erreur dans l'identification.  Réessaie, il y a une erreur quelque part !";
     }
 
+    $nom = $_nom;
+    $prenom = $_prenom;
     $ourid = $uid;
     return true;
 }
@@ -78,7 +80,7 @@ function check_mat($promo, $mat, $nom, $prenom, &$ourmat, &$ourid, &$watch, &$na
 // }}}
 // {{{ function check_old_mat
 
-function check_old_mat($promo, $mat, $nom, $prenom, &$ourmat, &$ourid, &$watch, &$naiss)
+function check_old_mat($promo, $mat, &$nom, &$prenom, &$ourmat, &$ourid, &$watch, &$naiss)
 {
     $res = XDB::iterRow(
             'SELECT  user_id, nom, prenom, matricule, FIND_IN_SET(\'watch\', flags), naissance_ini
@@ -86,6 +88,8 @@ function check_old_mat($promo, $mat, $nom, $prenom, &$ourmat, &$ourid, &$watch,
               WHERE  promo={?} AND deces=0 AND perms="pending"', $promo);
     while (list($_uid, $_nom, $_prenom, $_mat, $watch, $naiss) = $res->next()) {
         if (user_cmp($prenom, $nom, $_prenom, $_nom)) {
+            $nom = $_nom;
+            $prenom = $_prenom;
             $ourid  = $_uid;
             $ourmat = $_mat;
             return true;
@@ -149,24 +153,24 @@ function create_aliases (&$sub)
     global $globals;
     extract ($sub);
 
-    $mailorg  = make_username($prenom, $nom);
+    $mailorg = make_username($prenom, $nom);
     $mailorg2 = $mailorg.sprintf(".%02u", ($promo%100));
-    $forlife  = make_forlife($prenom, $nom, $promo);
 
-    $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@{$globals->mail->domain}</a>\">" .
-            "support@{$globals->mail->domain}</a> en expliquant ta situation.";
+    $res = XDB::query("SELECT hruid FROM auth_user_md5 WHERE user_id = {?} AND hruid != ''", $uid);
+    if ($res->numRows() == 0) {
+        return "Tu n'as pas d'adresse à vie pré-attribuée.<br />"
+            . "Envoie un mail à <a href=\"mailto:support@{$globals->mail->domain}</a>\">"
+            . "support@{$globals->mail->domain}</a> en expliquant ta situation.";
+    } else {
+        // TODO: at the moment forlife == hruid, however we'll have to change
+        // that behaviour when masters will be on plat/al.
+        $forlife = $res->fetchOneCell();
     }
 
-    $res      = XDB::query('SELECT id, type, expire FROM aliases WHERE alias={?}', $mailorg);
-
-    if ( $res->numRows() ) {
-
+    $res = XDB::query('SELECT id, type, expire FROM aliases WHERE alias={?}', $mailorg);
+    if ($res->numRows()) {
         list($h_id, $h_type, $expire) = $res->fetchOneRow();
-
-        if ( $h_type != 'homonyme' and empty($expire) ) {
+        if ($h_type != 'homonyme' and empty($expire)) {
             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);