Fixes registration and promo addition.
authorStéphane Jacob <sj@m4x.org>
Mon, 7 Mar 2011 13:40:32 +0000 (14:40 +0100)
committerStéphane Jacob <sj@m4x.org>
Mon, 7 Mar 2011 13:40:32 +0000 (14:40 +0100)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
include/emails.inc.php
include/reminder/email_backup.inc.php
modules/admin.php
modules/register.php
modules/register/register.inc.php
templates/register/step2.tpl
upgrade/1.1.0/11_xorg_id.sql [new file with mode: 0644]

index 4f0e1ba..aac9a25 100644 (file)
@@ -596,7 +596,7 @@ class Email
         }
         $res = XDB::fetchOneCell('SELECT  COUNT(*)
                                     FROM  email_redirect_account
-                                   WHERE  uid = {?} AND type = {?} AND flags = \'active\')',
+                                   WHERE  uid = {?} AND type = {?} AND flags = \'active\'',
                                  $user->id(), $storage);
         return !is_null($res) && $res > 0;
     }
index 9bd599b..6336b8b 100644 (file)
@@ -60,7 +60,7 @@ class ReminderEmailBackup extends Reminder
         }
 
         require_once 'emails.inc.php';
-        $active = Email::is_active_storage($user, 'imap')
+        $active = Email::is_active_storage($user, 'imap');
         if ($active) {
             Reminder::MarkCandidateAsAccepted($user->id(), $candidate);
         }
index f97f83a..9c1e108 100644 (file)
@@ -778,9 +778,9 @@ class AdminModule extends PLModule
     {
         switch ($sex) {
           case 'F':
-            return PlUser::GENDER_FEMALE;
+            return 'female';
           case 'M':
-            return PlUser::GENDER_MALE;
+            return 'male';
           default:
             $page->trigError("La ligne $line n'a pas été ajoutée car le sexe $sex n'est pas pris en compte.");
             return null;
@@ -806,7 +806,6 @@ class AdminModule extends PLModule
             $nameTypes = array_flip($nameTypes);
 
             if (Env::t('add_type') == 'promo') {
-                $type = 'x';
                 $eduSchools = DirEnum::getOptions(DirEnum::EDUSCHOOLS);
                 $eduSchools = array_flip($eduSchools);
                 $eduDegrees = DirEnum::getOptions(DirEnum::EDUDEGREES);
@@ -818,6 +817,7 @@ class AdminModule extends PLModule
                     $grad_year = $promotion + 3;
                     $promo = 'X' . $promotion;
                     $hrpromo = $promotion;
+                    $type = 'x';
                     break;
                   case 'M':
                     $degreeid = $eduDegrees[Profile::DEGREE_M];
@@ -847,7 +847,11 @@ class AdminModule extends PLModule
                             $fullName = $infos[1] . ' ' . $infos[0];
                             $directoryName = $infos[0] . ' ' . $infos[1];
                             $birthDate = self::formatBirthDate($infos[2]);
-                            $xorgId = Profile::getXorgId($infos[4]);
+                            if ($type == 'x') {
+                                $xorgId = Profile::getXorgId($infos[4]);
+                            } else {
+                                $xorgId = trim($infos[4]);
+                            }
                             if (is_null($xorgId)) {
                                 $page->trigError("La ligne $line n'a pas été ajoutée car le matricule École est mal renseigné.");
                                 continue;
index 95b896f..150da42 100644 (file)
@@ -93,8 +93,9 @@ class RegisterModule extends PLModule
 
             case 1:
                 if (Post::has('yearpromo')) {
-                    $promo = Post::t('edu_type') . Post::t('yearpromo');
+                    $edu_type = Post::t('edu_type');
                     $yearpromo = Post::i('yearpromo');
+                    $promo = $edu_type . $yearpromo;
                     $res = XDB::query("SELECT  COUNT(*)
                                          FROM  accounts         AS a
                                    INNER JOIN  account_profiles AS ap ON (a.uid = ap.uid AND FIND_IN_SET('owner', ap.perms))
@@ -109,10 +110,15 @@ class RegisterModule extends PLModule
                         $subState->set('step', 2);
                         $subState->set('promo', $promo);
                         $subState->set('yearpromo', $yearpromo);
-                        if ($yearpromo >= 1996 && $yearpromo < 2000) {
-                            $subState->set('schoolid', ($yearpromo % 100) * 10 . '???');
-                        } elseif($yearpromo >= 2000) {
-                            $subState->set('schoolid', 100 + ($yearpromo % 100) . '???');
+                        $subState->set('edu_type', $edu_type);
+                        if ($edu_type == 'X') {
+                            if ($yearpromo >= 1996 && $yearpromo < 2000) {
+                                $subState->set('schoolid', ($yearpromo % 100) * 10 . '???');
+                            } elseif($yearpromo >= 2000) {
+                                $subState->set('schoolid', 100 + ($yearpromo % 100) . '???');
+                            }
+                        } else {
+                            $subState->set('schoolid', '');
                         }
                     }
                 }
@@ -306,7 +312,7 @@ class RegisterModule extends PLModule
              $birthdate, $lastname, $firstname, $promo, $sex, $birthdate_ref, $eduType) = $res->fetchOneRow();
         $isX = ($eduType == 'x');
         $yearpromo = substr($promo, 1, 4);
-        $mail_domain = User::$sub_mail_domains[$eduType];
+        $mail_domain = User::$sub_mail_domains[$eduType] . $globals->mail->domain;
 
         // Prepare the template for display.
         $page->changeTpl('register/end.tpl');
@@ -358,12 +364,13 @@ class RegisterModule extends PLModule
 
         // Add the registration email address as first and only redirection.
         require_once 'emails.inc.php';
+        $user = User::getSilentWithUID($uid);
         $redirect = new Redirect($user);
         $redirect->add_email($email);
 
         // Try to start a session (so the user don't have to log in); we will use
         // the password available in Post:: to authenticate the user.
-        $success = Platal::session()->start(AUTH_MDP);
+        Platal::session()->start(AUTH_MDP);
 
         // Subscribe the user to the services she did request at registration time.
         foreach (explode(',', $services) as $service) {
index 83f5ea2..47e59d2 100644 (file)
@@ -110,11 +110,15 @@ function checkNewUser($subState)
     $lastname = preg_replace("/''+/", '\'', $lastname);
     $subState->set('lastname', mb_strtoupper($lastname));
 
-    if ($subState->i('yearpromo') >= 1996) {
+    if ($subState->i('yearpromo') >= 1996 && $subState->v('edu_type') == 'X') {
         $res = checkId($subState);
     } else {
         $res = checkOldId($subState);
     }
+    if ($subState->v('edu_type') != 'X' &&
+        $subState->v('xorgid') != $subState->v('schoolid')) {
+        return 'Le matricule est incorrect.';
+    }
     if ($res !== true) {
         return $res;
     }
@@ -132,7 +136,7 @@ function createAliases($subState)
     $emailXorg  = PlUser::makeUserName($subState->t('firstname'), $subState->t('lastname'));
     $emailXorg2 = $emailXorg . sprintf(".%02u", ($subState->i('yearpromo') % 100));
 
-    $res = XDB::query("SELECT  hruid, state
+    $res = XDB::query("SELECT  hruid, state, type
                          FROM  accounts
                         WHERE  uid = {?} AND hruid != ''",
                       $subState->i('uid'));
@@ -141,7 +145,7 @@ function createAliases($subState)
             . "Envoie un mail à <a href=\"mailto:support@{$globals->mail->domain}\">"
             . "support@{$globals->mail->domain}</a> en expliquant ta situation.";
     } else {
-        list($forlife, $state) = $res->fetchOneRow();
+        list($forlife, $state, $type) = $res->fetchOneRow();
     }
     if ($state == 'active') {
         return "Tu es déjà inscrit, si tu ne te souviens plus de ton mot de passe d'accès au site, "
@@ -152,11 +156,11 @@ function createAliases($subState)
              . "<a href=\"mailto:support@{$globals->mail->domain}\">support@{$globals->mail->domain}</a>.";
     }
 
-    $count = XDB::numRows('SELECT  uid, expire
-                             FROM  email_source_account
-                            WHERE  email = {?} AND type != \'alias_aux\'',
-                          $emailXorg);
-    if ($count) {
+    $res = XDB::query('SELECT  uid, expire
+                         FROM  email_source_account
+                        WHERE  email = {?} AND type != \'alias_aux\'',
+                      $emailXorg);
+    if ($res->numRows()) {
         list($h_id, $expire) = $res->fetchOneRow();
         if (empty($expire)) {
             XDB::execute('UPDATE  email_source_account
@@ -190,6 +194,7 @@ function createAliases($subState)
         $subState->set('bestalias', $emailXorg);
         $subState->set('emailXorg2', $emailXorg2);
     }
+    $subState->set('main_mail_domain', User::$sub_mail_domains[$type] . Platal::globals()->mail->domain);
 
     return true;
 }
index 6ae6a64..b16d516 100644 (file)
 
 <form action="register" method="post">
   <table class="bicol" summary="Identification" cellpadding="3">
-    {if $smarty.session.subState.yearpromo >= 1996}
+    {if $smarty.session.subState.edu_type neq 'X' || $smarty.session.subState.yearpromo >= 1996}
     {assign var="promo" value=$smarty.session.subState.yearpromo}
     <tr>
-      <th colspan="2">matricule</th>
+      <th colspan="2">Matricule</th>
     </tr>
     <tr>
       <td class="titre">
-        Matricule X&nbsp;:
+        Matricule École&nbsp;:
       </td>
       <td>
         <input type="text" size="6" maxlength="6" name="schoolid"
@@ -45,6 +45,7 @@
       </td>
     </tr>
     <tr class="pair">
+      {if $smarty.session.subState.edu_type eq 'X'}
       <td></td>
       <td>
         6 chiffres terminant par le numéro d'entrée (ex&nbsp;:
@@ -61,6 +62,7 @@
         {math equation="((promo + 1) % 100) + 100" promo=$promo}XXX
         {/if}
       </td>
+      {/if}
     </tr>
     {/if}
     <tr>
diff --git a/upgrade/1.1.0/11_xorg_id.sql b/upgrade/1.1.0/11_xorg_id.sql
new file mode 100644 (file)
index 0000000..041a17b
--- /dev/null
@@ -0,0 +1,4 @@
+ALTER TABLE profiles DROP KEY xorg_id;
+ALTER TABLE profiles ADD KEY xorg_id (xorg_id);
+
+-- vim:set syntax=mysql: