bug 539 rajouter les validations des medailles
authorx2001corpet <x2001corpet@839d8a87-29fc-0310-9880-83ba4fa771e5>
Wed, 15 Nov 2006 01:30:26 +0000 (01:30 +0000)
committerx2001corpet <x2001corpet@839d8a87-29fc-0310-9880-83ba4fa771e5>
Wed, 15 Nov 2006 01:30:26 +0000 (01:30 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1084 839d8a87-29fc-0310-9880-83ba4fa771e5

12 files changed:
ChangeLog
include/profil/get_deco.inc.php
include/validations.inc.php
include/validations/aliases.inc.php
include/validations/homonymes.inc.php
include/validations/medals.inc.php [new file with mode: 0644]
include/validations/nomusage.inc.php
include/validations/orange.inc.php
include/validations/photos.inc.php
modules/admin.php
templates/include/form.valid.medals.tpl [new file with mode: 0644]
templates/profil/deco.tpl

index 54d31b6..776aca6 100644 (file)
--- 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:
index eeea483..b36c878 100644 (file)
@@ -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')) {
index 6af52e8..858ea99 100644 (file)
@@ -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);
index f9dab64..34d0133 100644 (file)
@@ -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');
     }
 
     // }}}
index 742ff5d..9a628da 100644 (file)
@@ -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 (file)
index 0000000..14f0b87
--- /dev/null
@@ -0,0 +1,97 @@
+<?php
+/***************************************************************************
+ *  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                *
+ ***************************************************************************/
+
+// {{{ class MedalReq
+
+class MedalReq extends Validate
+{
+    // {{{ properties
+
+    var $mid;
+    var $gid;
+
+    // }}}
+    // {{{ constructor
+
+    function MedalReq ($_uid, $_idmedal, $_subidmedal, $_stamp=0)
+    {
+        $this->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:
+?>
index 1f35514..b73779f 100644 (file)
@@ -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()
index 439961e..60dfa6b 100644 (file)
@@ -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()
index 95860e3..fa0f4b3 100644 (file)
@@ -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');
     }
 
     // }}}
index 81e0f8a..ccb5d57 100644 (file)
@@ -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 (file)
index 0000000..5e8b179
--- /dev/null
@@ -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               *}
+{*                                                                        *}
+{**************************************************************************}
+
+
+<tr class="pair">
+  <td class="titre">Médaille :</td>
+  <td>{$valid->medal_name()}</td>
+</tr>
+
+{* vim:set et sw=2 sts=2 sws=2: *}
index 0056e6f..d3ad8b8 100644 (file)
@@ -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();
   }
     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);
+  }
   //]]>
-</script>
 {/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}
+
+</script>
 
+{if $smarty.request.medal_op eq "ajouter"}
+<div class="erreur">
+       Ta demande a bien été prise en compte, elle sera validée prochainement par un administrateur.
+</div>
+{/if}
 <div class="blocunite_tab">
   <input type="hidden" value="" name="medal_op" />
   <input type="hidden" value="" name="medal_id" />
+  <input type="hidden" value="" name="grade_id" />
   <table class="bicol" cellspacing="0" cellpadding="0">
     <tr>
       <th colspan="3">
       <td class="colm">
         <span class="valeur">{$m.medal}</span><br />
         {if $grades[$m.id]|@count}
-        <select name="grade[{$m.id}]">
-          <option value='0'>-- non précisé --</option>
           {foreach from=$grades[$m.id] item=g}
-          <option value='{$g.gid}' {if $g.gid eq $m.gid}selected='selected'{/if}>{$g.text}</option>
+            {if $g.gid eq $m.gid}{$g.text}{/if}
           {/foreach}
-        </select>
-        {else}
-        -- non précisé --
         {/if}
       </td>
       <td class="cold">
         &nbsp;
       </td>
       <td class="colm">
-        <select name="medal_sel">
+        <select name="medal_sel" onchange="medal_grades(this)">
           <option value=''></option>
           {foreach from=$medal_list key=type item=list}
           <optgroup label="{$trad[$type]}">
           </optgroup>
           {/foreach}
         </select>
+        <div id="grade_sel_div" style="display:none"><br/>
+          <select name="grade_sel" id="grade_sel">
+            <option value="0"></option>
+          </select>
+        </div>
       </td>
       <td class="cold">
         <span class="lien">