Adapts orangisation to master and PhD and merges it into the main profile edition.
authorStéphane Jacob <sj@m4x.org>
Thu, 25 Mar 2010 14:13:25 +0000 (15:13 +0100)
committerStéphane Jacob <sj@m4x.org>
Fri, 26 Mar 2010 14:47:40 +0000 (15:47 +0100)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
htdocs/javascript/profile.js
include/validations/orange.inc.php
modules/profile.php
modules/profile/general.inc.php
templates/include/form.valid.orange.tpl
templates/profile/general.tpl
templates/profile/orange.tpl [deleted file]

index a93af36..56255ef 100644 (file)
@@ -129,6 +129,13 @@ function toggleParticle(id)
     }
 }
 
+// Promotions {{{1
+
+function togglePromotionEdition()
+{
+    $(".promotion_edition").toggle();
+}
+
 // Nationalities {{{1
 
 function delNationality(i)
index 3c7d3fd..e2e2987 100644 (file)
@@ -42,11 +42,12 @@ class OrangeReq extends Validate
     {
         parent::__construct($_user, true, 'orange');
         $this->newGradYear  = $_newGradYear;
-        $res = XDB::query("SELECT  entry_year
+        $res = XDB::query("SELECT  entry_year, grad_year
                              FROM  profile_education
                             WHERE  pid = {?} AND FIND_IN_SET('primary', flags)", $this->user->profile()->id());
-        $this->entryYear   = $res->fetchOneCell();
-        $this->oldGradYear = $this->entryYear + 3;
+        $years = $res->fetchOneRow();
+        $this->entryYear   = $years[0];
+        $this->oldGradYear = $years[1];
     }
 
     // }}}
@@ -71,11 +72,11 @@ class OrangeReq extends Validate
     protected function _mail_body($isok)
     {
         if ($isok) {
-            return "  La demande de changement de promotion de sortie que tu as demandée vient d'être effectuée. "
+            return "  La demande de changement de promotion que tu as demandée vient d'être effectuée. "
                    . "Si tu le souhaites, tu peux maintenant modifier l'affichage de ta promotion sur le site sur la page suivante : "
                    . "https://www.polytechnique.org/profile/edit";
         } else {
-            return "  La demande de changement de promotion de sortie tu avais faite a été refusée.";
+            return "  La demande de changement de promotion tu avais faite a été refusée.";
         }
     }
 
@@ -86,7 +87,8 @@ class OrangeReq extends Validate
     {
         XDB::execute("UPDATE  profile_education
                          SET  grad_year = {?}
-                       WHERE  pid = {?} AND FIND_IN_SET('primary', flags)", $this->newGradYear, $this->user->profile()->id());
+                       WHERE  pid = {?} AND FIND_IN_SET('primary', flags)",
+                     $this->newGradYear, $this->user->profile()->id());
         return true;
     }
 
index d0f1fbd..79d8019 100644 (file)
@@ -48,7 +48,6 @@ class ProfileModule extends PLModule
             'javascript/grades.js'       => $this->make_hook('grades_js',                  AUTH_COOKIE),
             'profile/medal'              => $this->make_hook('medal',                      AUTH_PUBLIC),
             'profile/name_info'          => $this->make_hook('name_info',                  AUTH_PUBLIC),
-            'profile/orange'             => $this->make_hook('p_orange',                   AUTH_MDP),
 
             'referent'                   => $this->make_hook('referent',                   AUTH_COOKIE),
             'emploi'                     => $this->make_hook('ref_search',                 AUTH_COOKIE),
@@ -492,52 +491,6 @@ class ProfileModule extends PLModule
         $page->assign('names', build_javascript_names($data));
     }
 
-    function handler_p_orange(&$page, $pid = null)
-    {
-        $page->changeTpl('profile/orange.tpl');
-
-        require_once 'validations.inc.php';
-        $profile = Profile::get($pid);
-        if (is_null($profile)) {
-            return PL_NOT_FOUND;
-        }
-        $page->assign('promo_sortie_old', $profile->grad_year);
-        $page->assign('promo', $profile->entry_year);
-        $page->assign('promo_display', $profile->promo());
-        $page->assign('sexe', $profile->isFemale());
-
-        if (!Env::has('promo_sortie')) {
-            return;
-        } else {
-            S::assert_xsrf_token();
-        }
-
-        $promo_sortie = Env::i('promo_sortie');
-        $promo = $profile->entry_year;
-        if ($promo_sortie < 1000 || $promo_sortie > 9999) {
-            $page->trigError('L\'année de sortie doit être un nombre de quatre chiffres.');
-        } elseif ($promo_sortie < $promo + 3) {
-            $page->trigError('Trop tôt !');
-        } elseif ($promo_sortie == $promo_sortie_old) {
-            $page->trigWarning('Tu appartiens déjà à la promotion correspondante à cette année de sortie.');
-        } elseif ($promo_sortie == $promo + 3) {
-            XDB::execute('UPDATE  profile_education
-                             SET  grad_year = {?}
-                           WHERE  pid = {?} AND FIND_IN_SET(\'primary\', flags)',
-                         $promo_sortie, $profile->id());
-            $page->trigSuccess('Ton statut "orange" a été supprimé.');
-            $page->assign('promo_sortie_old', $promo_sortie);
-        } else {
-            $page->assign('promo_sortie', $promo_sortie);
-
-            if (Env::has('submit')) {
-                $myorange = new OrangeReq(S::user(), $promo_sortie);
-                $myorange->submit();
-                $page->assign('myorange', $myorange);
-            }
-        }
-    }
-
     function handler_referent(&$page, $pf)
     {
         $page->changeTpl('profile/fiche_referent.tpl', SIMPLE);
index 0c20a7e..2449a6c 100644 (file)
@@ -352,6 +352,73 @@ class ProfileSettingNetworking implements ProfileSetting
     }
 }
 
+class ProfileSettingPromo implements ProfileSetting
+{
+    public function __construct(){}
+
+    public function save(ProfilePage &$page, $field, $value)
+    {
+        $gradYearNew = $value;
+        if ($page->profile->mainEducation() == 'X') {
+            $gradYearNew += $page->profile->mainEducationDuration();
+        }
+        if ($value == $page->profile->entry_year + $page->profile->mainEducationDuration()) {
+            XDB::execute('UPDATE  profile_display
+                             SET  promo = {?}
+                           WHERE  pid = {?}',
+                         $page->profile->mainEducation() . strval($value), $page->profile->id());
+            XDB::execute('UPDATE  profile_education
+                             SET  grad_year = {?}
+                           WHERE  pid = {?} AND FIND_IN_SET(\'primary\', flags)',
+                         $gradYearNew, $page->profile->id());
+            $page->trigSuccess('Ton statut "orange" a été supprimé.');
+        } else {
+            require_once 'validations.inc.php';
+
+            $myorange = new OrangeReq(S::user(), $gradYearNew);
+            $myorange->submit();
+            Platal::page()->trigSuccess('Tu pourras changer l\'affichage de ta promotion dès que ta nouvelle promotion aura été validée.');
+        }
+    }
+
+    public function value(ProfilePage &$page, $field, $value, &$success)
+    {
+        $entryYear = $page->profile->entry_year;
+        $gradYear  = $page->profile->grad_year;
+        $success   = true;
+        if (is_null($value) || $value == $page->profile->yearpromo()) {
+            if ($gradYear != $entryYear + $page->profile->mainEducationDuration()) {
+                $promoChoice = array();
+                for ($i = $entryYear + $page->profile->mainEducationDuration(); $i <= $gradYear; ++$i) {
+                    $promoChoice[] = $page->profile->mainEducation() . strval($i);
+                }
+                Platal::page()->assign('promo_choice', $promoChoice);
+            }
+            if ($page->profile->mainEducation() == 'X') {
+                return $page->profile->grad_year - $page->profile->mainEducationDuration();
+            }
+            return $page->profile->yearpromo();
+        }
+
+        // If this profile belongs to an X, $promoNew needs to be changed to
+        // the graduation year.
+        $gradYearNew = $value;
+        if ($page->profile->mainEducation() == 'X') {
+            $gradYearNew += $page->profile->mainEducationDuration();
+        }
+
+        if ($value < 1000 || $value > 9999) {
+            Platal::page()->trigError('L\'année de sortie doit être un nombre de quatre chiffres.');
+            $success = false;
+        } elseif ($gradYearNew < $entryYear + $page->profile->mainEducationDuration()) {
+            Platal::page()->trigError('Trop tôt&nbsp;!');
+            $success = false;
+        }
+        return intval($value);
+    }
+}
+
+
 class ProfileSettingGeneral extends ProfilePage
 {
     protected $pg_template = 'profile/general.tpl';
@@ -370,7 +437,7 @@ class ProfileSettingGeneral extends ProfilePage
                                   = $this->settings['nationality2']
                                   = $this->settings['nationality3']
                                   = $this->settings['yourself']
-                                  = $this->settings['promo']
+                                  = $this->settings['promo_display']
                                   = null;
         $this->settings['email_directory']
                                   = new ProfileSettingEmail();
@@ -379,6 +446,7 @@ class ProfileSettingGeneral extends ProfilePage
         $this->settings['networking'] = new ProfileSettingNetworking();
         $this->settings['tels']   = new ProfileSettingPhones('user', 0);
         $this->settings['edus']   = new ProfileSettingEdu();
+        $this->settings['promo']  = new ProfileSettingPromo();
         $this->watched= array('freetext' => true, 'tels' => true,
                               'networking' => true, 'edus' => true,
                               'nationality1' => true, 'nationality2' => true,
@@ -388,16 +456,14 @@ class ProfileSettingGeneral extends ProfilePage
     protected function _fetchData()
     {
         // Checkout all data...
-        $res = XDB::query("SELECT  p.promo, e.entry_year AS entry_year, e.grad_year AS grad_year,
-                                   pr.nationality1, pr.nationality2, pr.nationality3, pr.birthdate,
-                                   t.display_tel as mobile, t.pub as mobile_pub,
-                                   pr.email_directory as email_directory,
-                                   pr.freetext, pr.freetext_pub, pr.ax_id AS matricule_ax, p.yourself
-                             FROM  profiles              AS pr
-                       INNER JOIN  profile_display       AS p ON (p.pid = pr.pid)
-                       INNER JOIN  profile_education     AS e ON (e.pid = pr.pid AND FIND_IN_SET('primary', e.flags))
-                        LEFT JOIN  profile_phones        AS t ON (t.pid = pr.pid AND link_type = 'user')
-                            WHERE  pr.pid = {?}", $this->pid());
+        $res = XDB::query("SELECT  p.nationality1, p.nationality2, p.nationality3, p.birthdate,
+                                   pp.display_tel as mobile, pp.pub as mobile_pub,
+                                   p.email_directory as email_directory, pd.promo AS promo_display,
+                                   p.freetext, p.freetext_pub, p.ax_id AS matricule_ax, pd.yourself
+                             FROM  profiles              AS p
+                       INNER JOIN  profile_display       AS pd ON (pd.pid = p.pid)
+                        LEFT JOIN  profile_phones        AS pp ON (pp.pid = p.pid AND link_type = 'user')
+                            WHERE  p.pid = {?}", $this->pid());
         $this->values = $res->fetchOneAssoc();
         if ($this->owner) {
             $this->values['yourself'] = $this->owner->displayName();
@@ -418,13 +484,6 @@ class ProfileSettingGeneral extends ProfilePage
         } else {
             $this->values['nouvellephoto'] = 0;
         }
-
-        // Proposes choice for promotion
-        if ($this->values['entry_year'] != $this->values['grad_year'] - 3) {
-            for ($i = $this->values['entry_year']; $i < $this->values['grad_year'] - 2; $i++) {
-                $this->values['promo_choice'][] = "X" . $i;
-            }
-        }
     }
 
     protected function _saveData()
@@ -469,11 +528,14 @@ class ProfileSettingGeneral extends ProfilePage
                              SET  display_name = {?}
                            WHERE  pid = {?}', $this->pid());
         }
-        if ($this->changed['promo']) {
-            XDB::execute("UPDATE  profile_display
-                             SET  promo = {?}
-                           WHERE  pid = {?}",
-                         $this->values['promo'], $this->pid());
+        if ($this->changed['promo_display']) {
+            if ($this->values['promo_display']{0} == $this->profile->mainEducation()
+                && intval(substr($this->values['promo_display'], 1, 4)) >= $this->profile->entry_year + $this->profile->mainEducationDuration()) {
+                XDB::execute('UPDATE  profile_display
+                                 SET  promo = {?}
+                               WHERE  pid = {?}',
+                             $this->values['promo_display'], $this->pid());
+            }
         }
     }
 
index eeb8869..3419c3a 100644 (file)
@@ -22,7 +22,7 @@
 
 
 <tr class="impair">
-  <td class="titre">Promotion&nbsp;:</td>
+  <td class="titre">Année d'entrée&nbsp;:</td>
   <td>{$valid->entryYear}</td>
 </tr>
 <tr class="impair">
index ebed93d..7c5a079 100644 (file)
     </td>
     <td>
       {if !$promo_choice}
-        <span class="nom">{$promo}</span>
-        <input type="hidden" name="promo" value="{$promo}"/>
+        <span class="nom">{$profile->promo()}</span>
+        <input type="hidden" name="promo_display" value="{$profile->promo()}"/>
       {else}
-        <select name="promo">
+        <select name="promo_display">
         {foreach from=$promo_choice item="promo_to_display"}
-          <option value="{$promo_to_display}" {if $promo_to_display eq $promo}selected="selected"{/if}>{$promo_to_display}</option>
+          <option value="{$promo_to_display}" {if $promo_to_display eq $promo_display}selected="selected"{/if}>{$promo_to_display}</option>
         {/foreach}
         </select>
       {/if}
-      <span class="lien"><a href="profile/orange" {if ($grad_year -3 == $entry_year)} {popup text="pour les oranges"}{/if}>{icon name="page_edit" title="modifier"}</a></span>
+      <span class="lien"><a href="javascript:togglePromotionEdition();" {popup text="pour les oranges"}>{icon name="page_edit" title="modifier"}</a></span>
+    </td>
+  </tr>
+  <tr class="promotion_edition" style="display: none">
+    <td colspan="2">
+      Afin de pouvoir être considéré{if $profile->isFemale()}e{/if} à la fois dans ta promotion d'origine et ta
+      ou tes promotions d'adoption tu peux entrer ici ta promotion d'adoption.
+      <br /><span class="smaller"><span class="titre">Attention&nbsp;:</span>
+      cette modification ne sera prise en compte qu'après validation par les administrateurs du site.</span>
+    </td>
+  </tr>
+  <tr class="promotion_edition" style="display: none">
+    <td class="titre">Promotion d'adoption</td>
+    <td>
+      {$profile->mainEducation()}<input type="text" name="promo" size="4" maxlength="4" value="{$promo}" />
+      <span class="smaller"> (que les chiffres)</span>
     </td>
   </tr>
   <tr>
diff --git a/templates/profile/orange.tpl b/templates/profile/orange.tpl
deleted file mode 100644 (file)
index f3a242b..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-{**************************************************************************}
-{*                                                                        *}
-{*  Copyright (C) 2003-2010 Polytechnique.org                             *}
-{*  http://opensource.polytechnique.org/                                  *}
-{*                                                                        *}
-{*  This program is free software; you can redistribute it and/or modify  *}
-{*  it under the terms of the GNU General Public License as published by  *}
-{*  the Free Software Foundation; either version 2 of the License, or     *}
-{*  (at your option) any later version.                                   *}
-{*                                                                        *}
-{*  This program is distributed in the hope that it will be useful,       *}
-{*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *}
-{*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *}
-{*  GNU General Public License for more details.                          *}
-{*                                                                        *}
-{*  You should have received a copy of the GNU General Public License     *}
-{*  along with this program; if not, write to the Free Software           *}
-{*  Foundation, Inc.,                                                     *}
-{*  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA               *}
-{*                                                                        *}
-{**************************************************************************}
-
-<h1>Année de sortie</h1>
-
-{if $myorange}
-
-<p>
-  Tu recevras un email dès que les changements demandés auront été effectués. 
-  Encore merci de nous faire confiance pour tes emails !
-</p>
-
-{else}
-
-<p>
-  Afin de pouvoir être considéré{if $sexe}e{/if} à la fois dans ta promotion d'origine et ta
-  ou tes promotions d'adoption tu peux entrer ici ton année de sortie de l'École.
-  Plus précisément, il s'agit de l'année d'entrée en quatrième année ou année d'application.
-  Pour tes cocons d'origine ({$promo}) il s'agit de l'année {math equation="a + b" a=$promo b=3}.
-</p>
-
-<br />
-
-<form action="profile/orange" method="post">
-  {xsrf_token_field}
-  <table class="bicol" cellpadding="4" summary="Année de sortie">
-    <tr>
-      <th>Année de sortie</th>
-    </tr>
-    <tr>
-      <td class="center"><input type="text" name="promo_sortie" value="{$promo_sortie_old}" /></td>
-    </tr>
-    <tr>
-      <td class="center"><input type="submit" name="submit" value="Envoyer" /></td>
-    </tr>
-  </table>
-</form>
-
-{/if}
-
-<p>[<a href="profile/edit">Revenir au profil</a>]</p>
-
-{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}