From 85cc366b075d06f805c16ac3df82acabdedcef3d Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Sun, 2 Sep 2007 22:44:41 +0200 Subject: [PATCH] Medals page working Signed-off-by: Florent Bruneau --- include/validations/medals.inc.php | 14 +++++ modules/profile.php | 25 ++++++++- modules/profile/assign_deco.inc.php | 46 --------------- modules/profile/decos.inc.php | 20 ++++--- modules/profile/get_deco.inc.php | 64 --------------------- modules/profile/page.inc.php | 4 +- modules/profile/update_deco.inc.php | 25 --------- modules/profile/verif_deco.inc.php | 22 -------- templates/profile/deco.medal.tpl | 42 ++++++++++++++ templates/profile/deco.tpl | 109 +++++++++++++++--------------------- 10 files changed, 138 insertions(+), 233 deletions(-) delete mode 100644 modules/profile/assign_deco.inc.php delete mode 100644 modules/profile/get_deco.inc.php delete mode 100644 modules/profile/update_deco.inc.php delete mode 100644 modules/profile/verif_deco.inc.php create mode 100644 templates/profile/deco.medal.tpl diff --git a/include/validations/medals.inc.php b/include/validations/medals.inc.php index e419e46..7e65dc5 100644 --- a/include/validations/medals.inc.php +++ b/include/validations/medals.inc.php @@ -104,6 +104,20 @@ class MedalReq extends Validate } // }}} + // {{{ function get_request($medal) + + static public function get_request($uid, $type) + { + $reqs = Validate::get_typed_requests($uid, 'medal'); + foreach ($reqs as &$req) { + if ($req->mid == $type) { + return $req; + } + } + return null; + } + + // }}} } // }}} diff --git a/modules/profile.php b/modules/profile.php index a4c2d57..f001599 100644 --- a/modules/profile.php +++ b/modules/profile.php @@ -32,8 +32,10 @@ class ProfileModule extends PLModule 'profile/private' => $this->make_hook('profile', AUTH_COOKIE), 'profile/ax' => $this->make_hook('ax', AUTH_COOKIE, 'admin'), 'profile/edit' => $this->make_hook('p_edit', AUTH_MDP), - 'profile/ajax/address' => $this->make_hook('ajax_address', AUTH_PUBLIC, 'user', NO_AUTH), + 'profile/ajax/address' => $this->make_hook('ajax_address', AUTH_COOKIE, 'user', NO_AUTH), 'profile/ajax/tel' => $this->make_hook('ajax_tel', AUTH_COOKIE, 'user', NO_AUTH), + 'profile/ajax/medal' => $this->make_hook('ajax_medal', AUTH_COOKIE, 'user', NO_AUTH), + 'profile/medal' => $this->make_hook('medal', AUTH_PUBLIC), 'profile/orange' => $this->make_hook('p_orange', AUTH_MDP), 'profile/usage' => $this->make_hook('p_usage', AUTH_MDP), @@ -97,6 +99,19 @@ class ProfileModule extends PLModule exit; } + function handler_medal(&$page, $mid) + { + $res = XDB::query("SELECT img + FROM profile_medals + WHERE id = {?}", + $mid); + $img = dirname(__FILE__).'/../htdocs/images/medals/' . $res->fetchOneCell(); + $type = mime_content_type($img); + header("Content-Type: $type"); + echo file_get_contents($img); + exit; + } + function handler_photo_change(&$page) { $page->changeTpl('profile/trombino.tpl'); @@ -348,6 +363,14 @@ class ProfileModule extends PLModule $page->assign('ajaxtel', true); } + function handler_ajax_medal(&$page, $id) + { + $page->changeTpl('profile/deco.medal.tpl', NO_SKIN); + $page->assign('id', $id); + $page->assign('medal', array('valid' => 0, 'grade' => 0)); + $page->assign('ajaxdeco', true); + } + function handler_p_orange(&$page) { $page->changeTpl('profile/orange.tpl'); diff --git a/modules/profile/assign_deco.inc.php b/modules/profile/assign_deco.inc.php deleted file mode 100644 index 4f3c931..0000000 --- a/modules/profile/assign_deco.inc.php +++ /dev/null @@ -1,46 +0,0 @@ -next()) { - $grades[$tmp['mid']][] = $tmp; -} - -$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; -} - -$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('grades', $grades); -$page->assign('medals', $medals); -$page->assign('trad', $trad); -$page->assign('medals_pub', $medals_pub); -$page->assign('medal_list', $mlist); -$page->assign('medals_valid', $medals_valid); - -// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: -?> diff --git a/modules/profile/decos.inc.php b/modules/profile/decos.inc.php index ee000d9..ebd8f12 100644 --- a/modules/profile/decos.inc.php +++ b/modules/profile/decos.inc.php @@ -34,15 +34,15 @@ class ProfileDeco implements ProfileSetting $value = array(); while (list($id, $grade) = $res->next()) { $value[$id] = array('grade' => $grade, - 'valid' => true); + 'valid' => '1'); } // 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); + $value[$medal->mid] = array('grade' => $medal->gid, + 'valid' => '0'); } } else if (!is_array($value)) { $value = array(); @@ -55,23 +55,27 @@ class ProfileDeco implements ProfileSetting { require_once('validations.inc.php'); + $orig =& $page->orig[$field]; + // Remove old ones - foreach ($page->orig as $id=>&$val) { + foreach ($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 = {?}", + WHERE uid = {?} AND mid = {?}", S::i('uid'), $id); } else { - $req = Validate::get_typed_request(S::i('uid'), 'medal', $id); - $req->clean(); + $req = MedalReq::get_request(S::i('uid'), $id); + if ($req) { + $req->clean(); + } } } } // Add new ones foreach ($value as $id=>&$val) { - if (!isset($this->orig[$id]) || $this->orig[$id]['grade'] != $val['grade']) { + if (!isset($orig[$id]) || $orig[$id]['grade'] != $val['grade']) { $req = new MedalReq(S::i('uid'), $id, $val['grade']); $req->submit(); } diff --git a/modules/profile/get_deco.inc.php b/modules/profile/get_deco.inc.php deleted file mode 100644 index f0e658c..0000000 --- a/modules/profile/get_deco.inc.php +++ /dev/null @@ -1,64 +0,0 @@ -submit(); - unset($_REQUEST['medal_op']); // pour ne pas avoir le message d'attente de validation - } - - if (Env::v('medal_op')=='annuler' && Env::i('medal_id')) { - $req = Validate::get_typed_request(S::i('uid'), 'medal', Env::v('medal_id')); - $req->clean(); - } -} -if (Post::has('grade')) { - foreach (Post::v('grade') as $mid=>$gid) { - XDB::execute('UPDATE profile_medals_sub SET gid={?} WHERE uid={?} AND mid={?}', $gid, S::v('uid'), $mid); - } -} - -$res = XDB::query( - "SELECT m.id, m.text AS medal, m.type, m.img, s.gid - FROM profile_medals_sub AS s - INNER JOIN profile_medals AS m ON ( s.mid = m.id ) - WHERE s.uid = {?}", S::v('uid', -1)); - -$medals = $res->fetchAllAssoc(); - -$res = XDB::query("SELECT profile_medals_pub FROM auth_user_quick WHERE user_id = {?}", S::v('uid', -1)); -$medals_pub = $res->fetchOneCell(); - -$medals_valid = Validate::get_typed_requests(S::i('uid'), 'medal'); - -if(Env::has('modifier') || Env::has('suivant')) { - $medals_pub = Env::has('medals_pub')?'public':'private'; -} - -// vim:set et sws=4 sw=4 sts=4 enc=utf-8: -?> diff --git a/modules/profile/page.inc.php b/modules/profile/page.inc.php index 233a514..2f454af 100644 --- a/modules/profile/page.inc.php +++ b/modules/profile/page.inc.php @@ -201,10 +201,10 @@ abstract class ProfilePage implements PlWizardPage foreach ($this->settings as $field=>&$setting) { $success = false; if (!is_null($setting)) { - $this->values[$field] = $setting->value($this, $field, Post::v($field), $success); + $this->values[$field] = $setting->value($this, $field, Post::v($field, ''), $success); } else { $success = true; - $this->values[$field] = Post::v($field); + $this->values[$field] = Post::v($field, ''); } $this->errors[$field] = !$success; $global_success = $global_success && $success; diff --git a/modules/profile/update_deco.inc.php b/modules/profile/update_deco.inc.php deleted file mode 100644 index da6d8ad..0000000 --- a/modules/profile/update_deco.inc.php +++ /dev/null @@ -1,25 +0,0 @@ - diff --git a/modules/profile/verif_deco.inc.php b/modules/profile/verif_deco.inc.php deleted file mode 100644 index 4c844bd..0000000 --- a/modules/profile/verif_deco.inc.php +++ /dev/null @@ -1,22 +0,0 @@ - diff --git a/templates/profile/deco.medal.tpl b/templates/profile/deco.medal.tpl new file mode 100644 index 0000000..20dcab6 --- /dev/null +++ b/templates/profile/deco.medal.tpl @@ -0,0 +1,42 @@ +{**************************************************************************} +{* *} +{* 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 *} +{* *} +{**************************************************************************} + +{if $ajaxdeco} + +{/if} +
+
+ +
+
+
+ {if !$medal.valid}(en attente de {if $ajaxdeco}validation{else}modération{/if}){/if}
+
+
+ {icon name="cross" title="Supprimer cette médaille"} + +
+ +{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} diff --git a/templates/profile/deco.tpl b/templates/profile/deco.tpl index 1dd1f24..935ce49 100644 --- a/templates/profile/deco.tpl +++ b/templates/profile/deco.tpl @@ -21,90 +21,69 @@ {**************************************************************************} -{literal} @@ -123,7 +102,7 @@ function update() ces informations sont normalement publiques (JO, ...) mais tu peux choisir de les associer a ta fiche publique -
+