}
}
+// Promotions {{{1
+
+function togglePromotionEdition()
+{
+ $(".promotion_edition").toggle();
+}
+
// Nationalities {{{1
function delNationality(i)
{
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];
}
// }}}
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.";
}
}
{
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;
}
'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),
$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);
}
}
+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 !');
+ $success = false;
+ }
+ return intval($value);
+ }
+}
+
+
class ProfileSettingGeneral extends ProfilePage
{
protected $pg_template = 'profile/general.tpl';
= $this->settings['nationality2']
= $this->settings['nationality3']
= $this->settings['yourself']
- = $this->settings['promo']
+ = $this->settings['promo_display']
= null;
$this->settings['email_directory']
= new ProfileSettingEmail();
$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,
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();
} 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()
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());
+ }
}
}
<tr class="impair">
- <td class="titre">Promotion :</td>
+ <td class="titre">Année d'entrée :</td>
<td>{$valid->entryYear}</td>
</tr>
<tr class="impair">
</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 :</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>
+++ /dev/null
-{**************************************************************************}
-{* *}
-{* 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: *}