From 7e233317e499e346349390c33c57cde4e1f90fb5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Thu, 25 Mar 2010 15:13:25 +0100 Subject: [PATCH] Adapts orangisation to master and PhD and merges it into the main profile edition. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- htdocs/javascript/profile.js | 7 +++ include/validations/orange.inc.php | 14 +++-- modules/profile.php | 47 -------------- modules/profile/general.inc.php | 108 +++++++++++++++++++++++++------- templates/include/form.valid.orange.tpl | 2 +- templates/profile/general.tpl | 25 ++++++-- templates/profile/orange.tpl | 62 ------------------ 7 files changed, 121 insertions(+), 144 deletions(-) delete mode 100644 templates/profile/orange.tpl diff --git a/htdocs/javascript/profile.js b/htdocs/javascript/profile.js index a93af36..56255ef 100644 --- a/htdocs/javascript/profile.js +++ b/htdocs/javascript/profile.js @@ -129,6 +129,13 @@ function toggleParticle(id) } } +// Promotions {{{1 + +function togglePromotionEdition() +{ + $(".promotion_edition").toggle(); +} + // Nationalities {{{1 function delNationality(i) diff --git a/include/validations/orange.inc.php b/include/validations/orange.inc.php index 3c7d3fd..e2e2987 100644 --- a/include/validations/orange.inc.php +++ b/include/validations/orange.inc.php @@ -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; } diff --git a/modules/profile.php b/modules/profile.php index d0f1fbd..79d8019 100644 --- a/modules/profile.php +++ b/modules/profile.php @@ -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); diff --git a/modules/profile/general.inc.php b/modules/profile/general.inc.php index 0c20a7e..2449a6c 100644 --- a/modules/profile/general.inc.php +++ b/modules/profile/general.inc.php @@ -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 !'); + $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()); + } } } diff --git a/templates/include/form.valid.orange.tpl b/templates/include/form.valid.orange.tpl index eeb8869..3419c3a 100644 --- a/templates/include/form.valid.orange.tpl +++ b/templates/include/form.valid.orange.tpl @@ -22,7 +22,7 @@ - Promotion : + Année d'entrée : {$valid->entryYear} diff --git a/templates/profile/general.tpl b/templates/profile/general.tpl index ebed93d..7c5a079 100644 --- a/templates/profile/general.tpl +++ b/templates/profile/general.tpl @@ -98,16 +98,31 @@ {if !$promo_choice} - {$promo} - + {$profile->promo()} + {else} - {foreach from=$promo_choice item="promo_to_display"} - + {/foreach} {/if} - {icon name="page_edit" title="modifier"} + {icon name="page_edit" title="modifier"} + + + + + 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. +
Attention : + cette modification ne sera prise en compte qu'après validation par les administrateurs du site. + + + + Promotion d'adoption + + {$profile->mainEducation()} + (que les chiffres) diff --git a/templates/profile/orange.tpl b/templates/profile/orange.tpl deleted file mode 100644 index f3a242b..0000000 --- a/templates/profile/orange.tpl +++ /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 *} -{* *} -{**************************************************************************} - -

Année de sortie

- -{if $myorange} - -

- Tu recevras un email dès que les changements demandés auront été effectués. - Encore merci de nous faire confiance pour tes emails ! -

- -{else} - -

- 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}. -

- -
- -
- {xsrf_token_field} - - - - - - - - - - -
Année de sortie
-
- -{/if} - -

[Revenir au profil]

- -{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} -- 2.1.4