Improves registration's first part to properly take into account master and doctorate...
authorStéphane Jacob <sj@m4x.org>
Fri, 22 Apr 2011 14:15:18 +0000 (16:15 +0200)
committerStéphane Jacob <sj@m4x.org>
Fri, 22 Apr 2011 14:32:25 +0000 (16:32 +0200)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
classes/profile.php
modules/register.php
modules/register/register.inc.php
templates/register/step1.tpl
templates/register/step2.tpl
templates/register/step3.tpl

index dffc869..249de86 100644 (file)
@@ -53,6 +53,11 @@ class Profile implements PlExportable
         self::DEGREE_M => 'master',
         self::DEGREE_D => 'docteur'
     );
+    static public $cycle_prefixes = array(
+        self::DEGREE_X => 'X',
+        self::DEGREE_M => 'M',
+        self::DEGREE_D => 'D'
+    );
 
     static public $name_variants = array(
             self::LASTNAME => array(self::VN_MARITAL, self::VN_ORDINARY),
index 8dd0a53..1a88393 100644 (file)
@@ -51,7 +51,8 @@ class RegisterModule extends PLModule
         if ($hash) {
             $nameTypes = DirEnum::getOptions(DirEnum::NAMETYPES);
             $nameTypes = array_flip($nameTypes);
-            $res = XDB::query("SELECT  a.uid, a.hruid, pnl.name AS lastname, pnf.name AS firstname, p.xorg_id AS xorgid, pd.promo, pe.promo_year AS yearpromo
+            $res = XDB::query("SELECT  a.uid, a.hruid, pnl.name AS lastname, pnf.name AS firstname, p.xorg_id AS xorgid,
+                                       pd.promo, pe.promo_year AS yearpromo, pde.degree AS edu_type,
                                        p.birthdate_ref AS birthdateRef, FIND_IN_SET('watch', a.flags) AS watch, m.hash, a.type
                                  FROM  register_marketing AS m
                            INNER JOIN  accounts           AS a   ON (m.uid = a.uid)
@@ -59,6 +60,7 @@ class RegisterModule extends PLModule
                            INNER JOIN  profiles           AS p   ON (p.pid = ap.pid)
                            INNER JOIN  profile_display    AS pd  ON (p.pid = pd.pid)
                            INNER JOIN  profile_education  AS pe  ON (pe.pid = p.pid AND FIND_IN_SET('primary', pe.flags))
+                           INNER JOIN  profile_education_degree_enum AS pde ON (pde.id = pe.degreeid)
                            INNER JOIN  profile_name       AS pnl ON (p.pid = pnl.pid AND pnl.typeid = {?})
                            INNER JOIN  profile_name       AS pnf ON (p.pid = pnf.pid AND pnf.typeid = {?})
                                 WHERE  m.hash = {?} AND a.state = 'pending'",
@@ -95,8 +97,7 @@ class RegisterModule extends PLModule
                 if (Post::has('yearpromo')) {
                     $edu_type = Post::t('edu_type');
                     $yearpromo = Post::i('yearpromo');
-                    $promo = $edu_type . $yearpromo;
-                    $year = ($edu_type == 'X') ? 'entry_year' : 'grad_year';
+                    $promo = Profile::$cycle_prefixes[$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))
@@ -112,14 +113,16 @@ class RegisterModule extends PLModule
                         $subState->set('promo', $promo);
                         $subState->set('yearpromo', $yearpromo);
                         $subState->set('edu_type', $edu_type);
-                        if ($edu_type == 'X') {
+                        if ($edu_type == Profile::DEGREE_X) {
                             if ($yearpromo >= 1996 && $yearpromo < 2000) {
                                 $subState->set('schoolid', ($yearpromo % 100) * 10 . '???');
+                                $subState->set('schoolid_exemple', ($yearpromo % 100) * 10000 + 532);
+                                $subState->set('schoolid_exemple_ev2', (($yearpromo + 1) % 100) * 10000 + 532);
                             } elseif($yearpromo >= 2000) {
                                 $subState->set('schoolid', 100 + ($yearpromo % 100) . '???');
+                                $subState->set('schoolid_exemple', (100 + ($yearpromo % 100)) * 1000 + 532);
+                                $subState->set('schoolid_exemple_ev2', (100 + (($yearpromo + 1) % 100)) * 1000 + 532);
                             }
-                        } else {
-                            $subState->set('schoolid', '');
                         }
                     }
                 }
@@ -130,7 +133,9 @@ class RegisterModule extends PLModule
                     $this->load('register.inc.php');
                     $subState->set('firstname', Post::t('firstname'));
                     $subState->set('lastname', Post::t('lastname'));
-                    $subState->set('schoolid', Post::i('schoolid'));
+                    if (Post::has('schoolid')) {
+                        $subState->set('schoolid', Post::i('schoolid'));
+                    }
                     $error = checkNewUser($subState);
 
                     if ($error !== true) {
@@ -169,8 +174,9 @@ class RegisterModule extends PLModule
                         if ($birth[2] < 100) {
                             $birth[2] += 1900;
                         }
-                        $year  = $birth[2];
-                        if ($year > $subState->i('yearpromo') - 15 || $subState->i('yearpromo') < $promo - 30) {
+                        $year = $birth[2];
+                        $ref_year = substr($subState->v('birthdateRef'), 0, 4);
+                        if (abs($ref_year - $year) > 2) {
                             $error[] = "La 'Date de naissance' n'est pas correcte.";
                             $alert = "Date de naissance incorrecte à l'inscription - ";
                             $subState->set('wrong_birthdate', $birth);
index 17f9789..9393bd6 100644 (file)
@@ -19,9 +19,9 @@
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************/
 
-// {{{ function checkId
+// {{{ function strongCheckId
 
-function checkId($subState)
+function strongCheckId($subState)
 {
     $subState->set('xorgid', Profile::getXorgId($subState->i('schoolid')));
     if (!$subState->v('xorgid')) {
@@ -55,13 +55,13 @@ function checkId($subState)
 }
 
 // }}}
-// {{{ function checkOldId
+// {{{ function weakCheckId
 
-function checkOldId($subState)
+function weakCheckId($subState)
 {
     $uf = new UserFilter(new PFC_And(
             new PFC_Not(new UFC_Dead()),
-            new UFC_Promo('=', UserFilter::DISPLAY, $subState->s('promo')),
+            new UFC_Promo('=', $subState->s('edu_type'), $subState->s('yearpromo')),
             new PFC_Not(new UFC_Registered(true))
     ));
     if ($it = $uf->iterProfiles()) {
@@ -80,7 +80,7 @@ function checkOldId($subState)
 
     $uf = new UserFilter(new PFC_And(
             new PFC_Not(new UFC_Dead()),
-            new UFC_Promo('=', UserFilter::DISPLAY, $subState->s('promo')),
+            new UFC_Promo('=', $subState->s('edu_type'), $subState->s('yearpromo')),
             new UFC_Registered(true)
     ));
     if ($it = $uf->iterProfiles()) {
@@ -112,14 +112,10 @@ function checkNewUser($subState)
     $lastname = preg_replace("/''+/", '\'', $lastname);
     $subState->set('lastname', mb_strtoupper($lastname));
 
-    if ($subState->i('yearpromo') >= 1996 && $subState->v('edu_type') == 'X') {
-        $res = checkId($subState);
+    if ($subState->v('edu_type') == Profile::DEGREE_X && $subState->i('yearpromo') >= 1996) {
+        $res = strongCheckId($subState);
     } else {
-        $res = checkOldId($subState);
-    }
-    if ($subState->v('edu_type') != 'X' &&
-        $subState->v('xorgid') != $subState->v('schoolid')) {
-        return 'Le matricule est incorrect.';
+        $res = weakCheckId($subState);
     }
     if ($res !== true) {
         return $res;
@@ -135,9 +131,6 @@ function createAliases($subState)
 {
     global $globals;
 
-    $emailXorg  = PlUser::makeUserName($subState->t('firstname'), $subState->t('lastname'));
-    $emailXorg2 = $emailXorg . sprintf(".%02u", ($subState->i('yearpromo') % 100));
-
     $res = XDB::query("SELECT  hruid, state, type
                          FROM  accounts
                         WHERE  uid = {?} AND hruid != ''",
@@ -158,6 +151,10 @@ function createAliases($subState)
              . "<a href=\"mailto:support@{$globals->mail->domain}\">support@{$globals->mail->domain}</a>.";
     }
 
+
+    $emailXorg  = PlUser::makeUserName($subState->t('firstname'), $subState->t('lastname'));
+    $suffix = (User::$sub_mail_domains[$type] ? substr(User::$sub_mail_domains[$type], 0, 1) : '') . substr($subState->v('yearpromo'), -2);
+    $emailXorg2 = $emailXorg . '.' . $suffix;
     $res = XDB::query('SELECT  uid, expire
                          FROM  email_source_account
                         WHERE  email = {?} AND type != \'alias_aux\'',
index 87251c5..2feeace 100644 (file)
@@ -48,9 +48,9 @@
       </td>
       <td>
         <select name="edu_type">
-          <option value="X" selected="selected">polytechnicienne</option>
-          <option value="M">master</option>
-          <option value="D">doctorat</option>
+          <option value="{#Profile::DEGREE_X#}" selected="selected">polytechnicienne</option>
+          <option value="{#Profile::DEGREE_M#}">master</option>
+          <option value="{#Profile::DEGREE_D#}">doctorat</option>
         </select>
       </td>
     </tr>
index b16d516..308ca9c 100644 (file)
@@ -30,8 +30,7 @@
 
 <form action="register" method="post">
   <table class="bicol" summary="Identification" cellpadding="3">
-    {if $smarty.session.subState.edu_type neq 'X' || $smarty.session.subState.yearpromo >= 1996}
-    {assign var="promo" value=$smarty.session.subState.yearpromo}
+    {if t($smarty.session.subState.schoolid)}
     <tr>
       <th colspan="2">Matricule</th>
     </tr>
       </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;:
-        {if $promo < 2000}
-        {math equation="promo % 100" promo=$promo}0532)<br />
-        {else}
-        {math equation="(promo % 100) + 100" promo=$promo}532)<br />
-        {/if}
-        Voir sur le GU ou un bulletin de solde pour trouver cette information<br /><br />
-        Pour les élèves étrangers voie 2, il peut être aussi du type&nbsp;:
-        {if $promo < 1999}
-        {math equation="(promo + 1) % 100" promo=$promo}0XXX
-        {else}
-        {math equation="((promo + 1) % 100) + 100" promo=$promo}XXX
-        {/if}
+        6 chiffres terminant par le numéro d'entrée (ex&nbsp;: {$smarty.session.subState.schoolid_exemple}).
+        Voir sur le GU ou un bulletin de solde pour trouver cette information.<br /><br />
+        Pour les élèves étrangers voie 2, il peut être aussi du type&nbsp;: {$smarty.session.subState.schoolid_exemple_ev2}.
       </td>
-      {/if}
     </tr>
     {/if}
     <tr>
index ab97b27..71b8b03 100644 (file)
           <dd>
             de recevoir les informations importantes de l'AX.
           </dd>
-          {if $smarty.session.subState.edu_type eq 'X'}
+          {if $smarty.session.subState.edu_type eq #Profile::DEGREE_X#}
           <dt><label><input type="checkbox" checked="checked" name="ml_promo" /> ta promotion</label></dt>
           <dd>
             de recevoir les informations plus spécifiques de ta promotion pour pouvoir participer plus facilement aux événements