From 20d7932b9db32f4dbf96312efc1981a5bebd9b7d Mon Sep 17 00:00:00 2001 From: x2001corpet Date: Wed, 15 Nov 2006 01:30:26 +0000 Subject: [PATCH] bug 539 rajouter les validations des medailles git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1084 839d8a87-29fc-0310-9880-83ba4fa771e5 --- ChangeLog | 1 + include/profil/get_deco.inc.php | 12 +++- include/validations.inc.php | 6 +- include/validations/aliases.inc.php | 2 +- include/validations/homonymes.inc.php | 8 --- include/validations/medals.inc.php | 97 +++++++++++++++++++++++++++++++++ include/validations/nomusage.inc.php | 8 --- include/validations/orange.inc.php | 8 --- include/validations/photos.inc.php | 2 +- modules/admin.php | 2 +- templates/include/form.valid.medals.tpl | 29 ++++++++++ templates/profil/deco.tpl | 67 ++++++++++++++++++++--- 12 files changed, 203 insertions(+), 39 deletions(-) create mode 100644 include/validations/medals.inc.php create mode 100644 templates/include/form.valid.medals.tpl diff --git a/ChangeLog b/ChangeLog index 54d31b6..776aca6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -48,6 +48,7 @@ Bug/Wish: - #451: vCard are RFC compliant -FRU - #502: Use 'alias' instead of 'aka' to specify the nickname -FRU - #536: Can use login.promo as a valid user identifier -FRU + - #539: Medals and deco need validation from admin -Car - #540: Profile of unregistered user redirects to marketing -FRU * Xnet: diff --git a/include/profil/get_deco.inc.php b/include/profil/get_deco.inc.php index eeea483..b36c878 100644 --- a/include/profil/get_deco.inc.php +++ b/include/profil/get_deco.inc.php @@ -25,7 +25,17 @@ if (Env::has('medal_op')) { } if (Env::v('medal_op')=='ajouter' && Env::i('medal_id')) { - XDB::execute("INSERT INTO profile_medals_sub (uid,mid) VALUES ({?}, {?})", S::v('uid', -1), Env::i('medal_id')); + require_once('validations.inc.php'); + $req = new MedalReq(S::v('uid',-1),Env::i('medal_id'), Env::i('grade_id')); + if ($req->mid == 20) // defnat + { + $req->commit(); + unset($_REQUEST['medal_op']); // pour ne pas avoir le message d'attente de validation + } + else + { + $req->submit(); + } } } if (Post::has('grade')) { diff --git a/include/validations.inc.php b/include/validations.inc.php index 6af52e8..858ea99 100644 --- a/include/validations.inc.php +++ b/include/validations.inc.php @@ -257,7 +257,7 @@ class Validate } // }}} - // {{{ function get_request() + // {{{ function get_typed_request() /** fonction statique qui renvoie la requête de l'utilisateur d'id $uidau timestamp $t * @param $uid l'id de l'utilisateur concerné @@ -265,9 +265,9 @@ class Validate * @param $stamp le timestamp de la requête * * XXX fonction "statique" XXX - * à utiliser uniquement pour récupérer un objet dans la BD avec Validate::get_request(...) + * à utiliser uniquement pour récupérer un objet dans la BD avec Validate::get_typed_request(...) */ - function get_request($uid, $type, $stamp = -1) + function get_typed_request($uid, $type, $stamp = -1) { if ($stamp == -1) { $res = XDB::query('SELECT data FROM requests WHERE user_id={?} and type={?}', $uid, $type); diff --git a/include/validations/aliases.inc.php b/include/validations/aliases.inc.php index f9dab64..34d0133 100644 --- a/include/validations/aliases.inc.php +++ b/include/validations/aliases.inc.php @@ -62,7 +62,7 @@ class AliasReq extends Validate function get_request($uid) { - return parent::get_request($uid,'alias'); + return parent::get_typed_request($uid,'alias'); } // }}} diff --git a/include/validations/homonymes.inc.php b/include/validations/homonymes.inc.php index 742ff5d..9a628da 100644 --- a/include/validations/homonymes.inc.php +++ b/include/validations/homonymes.inc.php @@ -61,14 +61,6 @@ class HomonymeReq extends Validate } // }}} - // {{{ function get_request() - - function get_request($uid) - { - return parent::get_request($uid,$this->title); - } - - // }}} // {{{ function formu() function formu() diff --git a/include/validations/medals.inc.php b/include/validations/medals.inc.php new file mode 100644 index 0000000..14f0b87 --- /dev/null +++ b/include/validations/medals.inc.php @@ -0,0 +1,97 @@ +Validate($_uid, false, 'medal', $_stamp); + $this->mid = $_idmedal; + $this->gid = $_subidmedal; + } + + // }}} + // {{{ function formu() + + function formu() + { + return 'include/form.valid.medals.tpl'; + } + + // }}} + // {{{ function _mail_subj + + function _mail_subj() + { + return "[Polytechnique.org/Décoration] Demande de décoration : ".$this->medal_name(); + } + + // }}} + // {{{ function _mail_body + + function _mail_body($isok) + { + if ($isok) { + return " La décoration ".$this->medal_name()." que tu avais demandée vient d'être acceptée."; + } else { + return " La demande que tu avais faite pour la décoration ".$this->medal_name()." a été refusée."; + } + } + + // }}} + // {{{ function medal_name + + function medal_name() + { + //var_dump($this); + $r = XDB::query(" + SELECT IF (g.text IS NOT NULL, CONCAT(m.text,' - ', g.text), m.text) + FROM profile_medals AS m + LEFT JOIN profile_medals_grades AS g ON(g.mid = m.id AND g.gid = {?}) + WHERE m.id = {?}", $this->gid, $this->mid); + return $r->fetchOneCell(); + } + + // }}} + // {{{ function commit() + + function commit () + { + return XDB::execute('REPLACE INTO profile_medals_sub VALUES({?}, {?}, {?})', $this->uid, $this->mid, $this->gid); + } + + // }}} +} + +// }}} + +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker: +?> diff --git a/include/validations/nomusage.inc.php b/include/validations/nomusage.inc.php index 1f35514..b73779f 100644 --- a/include/validations/nomusage.inc.php +++ b/include/validations/nomusage.inc.php @@ -62,14 +62,6 @@ class UsageReq extends Validate } // }}} - // {{{ function get_request() - - function get_request($uid) - { - return parent::get_request($uid,'usage'); - } - - // }}} // {{{ function formu() function formu() diff --git a/include/validations/orange.inc.php b/include/validations/orange.inc.php index 439961e..60dfa6b 100644 --- a/include/validations/orange.inc.php +++ b/include/validations/orange.inc.php @@ -46,14 +46,6 @@ class OrangeReq extends Validate } // }}} - // {{{ function get_request() - - function get_request($uid) - { - return parent::get_request($uid,'orange'); - } - - // }}} // {{{ function formu() function formu() diff --git a/include/validations/photos.inc.php b/include/validations/photos.inc.php index 95860e3..fa0f4b3 100644 --- a/include/validations/photos.inc.php +++ b/include/validations/photos.inc.php @@ -114,7 +114,7 @@ class PhotoReq extends Validate function get_request($uid) { - return parent::get_request($uid,'photo'); + return parent::get_typed_request($uid,'photo'); } // }}} diff --git a/modules/admin.php b/modules/admin.php index 81e0f8a..ccb5d57 100644 --- a/modules/admin.php +++ b/modules/admin.php @@ -719,7 +719,7 @@ class AdminModule extends PLModule } if(Env::has('uid') && Env::has('type') && Env::has('stamp')) { - $req = Validate::get_request(Env::v('uid'), Env::v('type'), Env::v('stamp')); + $req = Validate::get_typed_request(Env::v('uid'), Env::v('type'), Env::v('stamp')); if($req) { $req->handle_formu(); } } diff --git a/templates/include/form.valid.medals.tpl b/templates/include/form.valid.medals.tpl new file mode 100644 index 0000000..5e8b179 --- /dev/null +++ b/templates/include/form.valid.medals.tpl @@ -0,0 +1,29 @@ +{**************************************************************************} +{* *} +{* Copyright (C) 2003-2006 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 *} +{* *} +{**************************************************************************} + + + + Médaille : + {$valid->medal_name()} + + +{* vim:set et sw=2 sts=2 sws=2: *} diff --git a/templates/profil/deco.tpl b/templates/profil/deco.tpl index 0056e6f..d3ad8b8 100644 --- a/templates/profil/deco.tpl +++ b/templates/profil/deco.tpl @@ -27,6 +27,7 @@ { var selid = document.forms.prof_annu.medal_sel.selectedIndex; document.forms.prof_annu.medal_id.value = document.forms.prof_annu.medal_sel.options[selid].value; + document.forms.prof_annu.grade_id.value = document.forms.prof_annu.grade_sel.value; document.forms.prof_annu.medal_op.value = "ajouter"; document.forms.prof_annu.submit(); } @@ -37,13 +38,63 @@ document.forms.prof_annu.medal_op.value = "retirer"; document.forms.prof_annu.submit(); } + var subgrades = new array(); + function getoption( select_input, j) + { + if (!document.all) + { + return select_input.options[j]; + } + else + { + return j; + } + } + function medal_grades( sel_medal ) + { + var subg = subgrades[sel_medal.selectedIndex]; + document.getElementById("grade_sel_div").style.display = subg?"inline":"none"; + if (!subg) return; + var select = document.getElementById("grade_sel"); + while (select.length > 1) + { + select.remove(1); + } + + for (i=0; i < subg.length; i++) + { + var dmc = document.createElement("option"); + dmc.text= subg[i][1]; + dmc.value = subg[i][0]; + select.add(dmc,getoption(select,i)); + } + select.add(getoption(select,subg.length),getoption(select,0)); + select.remove(subg.length+1); + } //]]> - {/literal} +{foreach from=$medal_list key=type item=list} + {foreach from=$list item=m}{if $grades[$m.id]|@count} + subgrades[{$m.id}] = new array({$grades[$m.id]|@count}); + i = 0; + {foreach from=$grades[$m.id] item=g} + subgrades[{$m.id}][i] = [{$g.gid},"{$g.text}"]; + i++; + {/foreach} + {/if}{/foreach} +{/foreach} + + +{if $smarty.request.medal_op eq "ajouter"} +
+ Ta demande a bien été prise en compte, elle sera validée prochainement par un administrateur. +
+{/if}
+
@@ -72,14 +123,9 @@ {$m.medal}
{if $grades[$m.id]|@count} - - {else} - -- non précisé -- {/if}
@@ -94,7 +140,7 @@   - {foreach from=$medal_list key=type item=list} @@ -104,6 +150,11 @@ {/foreach} + -- 2.1.4