$wiz->addPage('ProfileGeneral', 'Général', 'general');
$wiz->addPage('ProfileAddresses', 'Adresses personnelles', 'adresses');
$wiz->addPage('ProfileGroups', 'Groupes X - Binets', 'poly');
- $wiz->addPage('ProfileDeco', 'Décorations - Medals', 'deco');
+ $wiz->addPage('ProfileDecos', 'Décorations - Medailles', 'deco');
$wiz->addPage('ProfilePro', 'Informations professionnelles', 'emploi');
$wiz->addPage('ProfileSkills', 'Compétences diverses', 'skill');
$wiz->addPage('ProfileMentor', 'Mentoring', 'mentor');
--- /dev/null
+<?php
+/***************************************************************************
+ * Copyright (C) 2003-2007 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 ProfileDeco implements ProfileSetting
+{
+ public function value(ProfilePage &$page, $field, $value, &$success)
+ {
+ $success = true;
+ if (is_null($value)) {
+ // Fetch already attributed medals
+ $res = XDB::iterRow("SELECT m.id AS id, s.gid AS grade
+ FROM profile_medals_sub AS s
+ INNER JOIN profile_medals AS m ON ( s.mid = m.id )
+ WHERE s.uid = {?}",
+ S::i('uid'));
+ $value = array();
+ while (list($id, $grade) = $res->next()) {
+ $value[$id] = array('grade' => $grade,
+ 'valid' => true);
+ }
+
+ // Fetch not yet validated medals
+ require_once('validations.inc.php');
+ $medals = Validate::get_typed_requests(S::i('uid'), 'medal');
+ foreach ($medals as &$medal) {
+ $medals[$medal->mid] = array('grade' => $medal->gid,
+ 'valid' => false);
+ }
+ } else if (!is_array($value)) {
+ $value = array();
+ }
+ ksort($value);
+ return $value;
+ }
+
+ public function save(ProfilePage &$page, $field, $value)
+ {
+ require_once('validations.inc.php');
+
+ // Remove old ones
+ foreach ($page->orig as $id=>&$val) {
+ if (!isset($value[$id]) || $val['grade'] != $value[$id]['grade']) {
+ if ($val['valid']) {
+ XDB::execute("DELETE FROM profile_medals_sub
+ WHERE uid = {?} AND id = {?}",
+ S::i('uid'), $id);
+ } else {
+ $req = Validate::get_typed_request(S::i('uid'), 'medal', $id);
+ $req->clean();
+ }
+ }
+ }
+
+ // Add new ones
+ foreach ($value as $id=>&$val) {
+ if (!isset($this->orig[$id]) || $this->orig[$id]['grade'] != $val['grade']) {
+ $req = new MedalReq(S::i('uid'), $id, $val['grade']);
+ $req->submit();
+ }
+ }
+ }
+}
+
+class ProfileDecos extends ProfilePage
+{
+ protected $pg_template = 'profile/deco.tpl';
+
+ public function __construct(PlWizard &$wiz)
+ {
+ parent::__construct($wiz);
+ $this->settings['medals'] = new ProfileDeco();
+ $this->settings['medals_pub'] = new ProfilePub();
+ }
+
+ protected function fetchData()
+ {
+ $res = XDB::query("SELECT profile_medals_pub
+ FROM auth_user_quick
+ WHERE user_id = {?}",
+ S::i('uid'));
+ $this->values['medals_pub'] = $res->fetchOneCell();
+ parent::fetchData();
+ }
+
+ protected function saveData()
+ {
+ parent::saveData();
+ if ($this->changed['medals_pub']) {
+ XDB::execute("UPDATE auth_user_quick
+ SET profile_medals_pub = {?}
+ WHERE user_id = {?}",
+ $this->values['medals_pub'], S::i('uid'));
+ }
+ }
+
+ public function prepare(PlatalPage &$page)
+ {
+ parent::prepare($page);
+ $res = XDB::iterator("SELECT *
+ FROM profile_medals_grades
+ ORDER BY mid, pos");
+ $grades = array();
+ while ($tmp = $res->next()) {
+ $grades[$tmp['mid']][] = $tmp;
+ }
+ $page->assign('grades', $grades);
+
+ $res = XDB::iterator("SELECT *, FIND_IN_SET('validation', flags) AS validate
+ FROM profile_medals
+ ORDER BY type, text");
+ $mlist = array();
+ while ($tmp = $res->next()) {
+ $mlist[$tmp['type']][] = $tmp;
+ }
+ $page->assign('medal_list', $mlist);
+
+ $trad = Array('ordre' => 'Ordres',
+ 'croix' => 'Croix',
+ 'militaire' => 'Médailles militaires',
+ 'honneur' => 'Médailles d\'honneur',
+ 'resistance' => 'Médailles de la résistance',
+ 'prix' => 'Prix');
+ $page->assign('trad', $trad);
+ }
+}
+
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+?>
parent::saveData();
if ($this->changed['nationalite'] || $this->changed['nom'] || $this->changed['prenom']) {
XDB::execute("UPDATE auth_user_md5
- SET nationalite = {?}, nom={?}, prenom={?} WHERE user_id = {?}",
+ SET nationalite = {?}, nom={?}, prenom={?}
+ WHERE user_id = {?}",
$this->values['nationalite'], $this->values['nom'], $this->values['prenom'], S::v('uid'));
}
if ($this->changed['nick'] || $this->changed['mobile'] || $this->changed['mobile_pub']
require_once('user.func.inc.php');
user_reindex(S::v('uid'));
}
- XDB::execute("UPDATE photo SET pub = {?} WHERE uid = {?}", $this->values['photo_pub'], S::v('uid'));
+ if ($this->changed['photo_pub']) {
+ XDB::execute("UPDATE photo
+ SET pub = {?}
+ WHERE uid = {?}",
+ $this->values['photo_pub'], S::v('uid'));
+ }
}
public function prepare(PlatalPage &$page)
require_once dirname(__FILE__) . '/general.inc.php';
require_once dirname(__FILE__) . '/addresses.inc.php';
require_once dirname(__FILE__) . '/groups.inc.php';
+require_once dirname(__FILE__) . '/decos.inc.php';
// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
?>
{literal}
<script type="text/javascript">//<![CDATA[
+function update()
+{
+ var val = document.forms.prof_annu['medal_sel'].value;
+ if (val == '' || document.getElementById('medal_' + val) != null) {
+ document.getElementById('medal_add').display.style = 'none';
+ } else {
+ document.getElementById('medal_add').display.style = '';
+ }
+}
+
var valid = new array();
function medal_add()
{
</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">
- Médailles, Décorations, Prix, ...
- </th>
- </tr>
- <tr>
- <td colspan="3" class="pflags">
- <table class="flags" summary="Flags" cellpadding="0" cellspacing="0">
- <tr>
- <td class="vert">
- <input type="checkbox" name="medals_pub"{if $medals_pub eq 'public'} checked="checked"{/if} />
- </td>
- <td class="texte">
- ces informations sont normalement publiques (JO, ...) mais tu peux choisir de les associer a ta fiche publique
- </td>
- </tr>
- </table>
- </td>
- </tr>
- {foreach from=$medals item=m}
- <tr>
- <td class="colg">
- <img src='images/medals/{$m.img}' width="32" alt="{$m.medal}" title="{$m.medal}" />
- </td>
- <td class="colm">
- <span class="valeur">{$m.medal}</span><br />
- {if $grades[$m.id]|@count}
- {foreach from=$grades[$m.id] item=g}
- {if $g.gid eq $m.gid}{$g.text}{/if}
- {/foreach}
- {/if}
- </td>
- <td class="cold">
- <span class="lien">
- <a href="javascript:medal_del({$m.id});">retirer</a>
- </span>
- </td>
- </tr>
- {/foreach}
- {foreach from=$medals_valid item=v}
- <tr>
- <td class="colg">
- <img
- {foreach from=$medal_list item=list}
- {foreach from=$list item=m}
- {if $m.id eq $v->mid}src="images/medals/{$m.img}"{/if}
- {/foreach}
- {/foreach}
- title="Validation" alt="Validation" width="32" />
- <td class="colm">
- <span class="valeur">
- {foreach from=$medal_list item=list}
- {foreach from=$list item=m}
- {if $m.id eq $v->mid}{$m.text} <em>(en attente de validation)</em>{/if}
- {/foreach}
- {/foreach}
- </span><br />
- {foreach from=$grades key=mid item=grd}
- {if $mid eq $v->mid}
- {foreach from=$grd item=g}
- {if $g.gid eq $v->gid}{$g.text}{/if}
- {/foreach}
- {/if}
- {/foreach}
- </td>
- <td class="cold">
- <span class="lien">
- <a href="javascript:medal_cancel({$v->stamp});">annuler</a>
- </span>
- </tr>
- </tr>
- {/foreach}
- <tr>
- <td class="colg">
-
- </td>
- <td class="colm">
- <select name="medal_sel" onchange="medal_grades(this)">
+<table class="bicol">
+ <tr>
+ <th>
+ Médailles, Décorations, Prix, ...
+ </th>
+ </tr>
+ <tr>
+ <td>
+ <div class="flags">
+ <div class="vert" style="float: left">
+ <input type="checkbox" name="medals_pub"{if $medals_pub eq 'public'} checked="checked"{/if} />
+ </div>
+ <div class="texte">
+ ces informations sont normalement publiques (JO, ...) mais tu peux choisir de les associer a ta fiche publique
+ </div>
+ </div>
+ <div style="clear: both; margin-top: 0.2em">
+ <select name="medal_sel" onchange="update()">
<option value=''></option>
{foreach from=$medal_list key=type item=list}
- <optgroup label="{$trad[$type]}">
+ <optgroup label="{$trad[$type]}...">
{foreach from=$list item=m}
<option value="{$m.id}">{$m.text}</option>
{/foreach}
</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">
- <a href="javascript:medal_add();">ajouter</a>
+ <span id="medal_add">
+ <a href="javascript:add();">{icon name=add title="Ajouter cette médaille"}</a>
</span>
- </td>
- </tr>
- </table>
-</div>
+ </div>
+ {foreach from=$medals item=medal key=id}
+ {include file="profile/deco.medal.tpl" medal=$medal id=$id}
+ {/foreach}
+ </td>
+ </tr>
+</table>
+
+<script type="text/javascript">
+update();
+</script>
{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}