From 154ee23ac13734b27271d6da78952649616a4378 Mon Sep 17 00:00:00 2001 From: Olivier Le Floch Date: Fri, 6 Jun 2008 02:59:22 +0200 Subject: [PATCH] Fixes #811: Improve interface to add medal ranks and avoid losing data --- ChangeLog | 4 ++++ modules/profile.php | 23 ++++++++++++++++------- templates/profile/admin_decos.tpl | 28 +++++++++++++--------------- 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2296f85..6a26ba4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,10 @@ New: - Add a 'disallow all' robots.txt in development working copies. -VZA Bug/Wish: + + * Admin: + - #811: Improve interface to add medal ranks and avoid losing data -ALK + * Core: - Fix email sending, correcting bugs introduced in r1897 -VZA - #841: Improves contrast of links in legends in skin 'Espace' -FRU diff --git a/modules/profile.php b/modules/profile.php index bef05a8..467f11e 100644 --- a/modules/profile.php +++ b/modules/profile.php @@ -791,15 +791,24 @@ class ProfileModule extends PLModule if (Post::v('act') == 'del') { XDB::execute('DELETE FROM profile_medals_grades WHERE mid={?} AND gid={?}', $mid, Post::i('gid')); - } elseif (Post::v('act') == 'new') { - XDB::execute('INSERT INTO profile_medals_grades (mid,gid) - VALUES ({?},{?})', - $mid, max(array_keys(Post::v('grades', array(0))))+1); } else { foreach (Post::v('grades', array()) as $gid=>$text) { - XDB::execute('UPDATE profile_medals_grades - SET pos={?}, text={?} - WHERE gid={?} AND mid={?}', $_POST['pos'][$gid], $text, $gid, $mid); + if ($gid === 0) { + if (!empty($text)) { + $res = XDB::query('SELECT MAX(gid) + FROM profile_medals_grades + WHERE mid = {?}', $mid); + $gid = $res->fetchOneCell() + 1; + + XDB::execute('INSERT INTO profile_medals_grades (mid, gid, text, pos) + VALUES ({?}, {?}, {?}, {?})', + $mid, $gid, $text, $_POST['pos']['0']); + } + } else { + XDB::execute('UPDATE profile_medals_grades + SET pos={?}, text={?} + WHERE gid={?} AND mid={?}', $_POST['pos'][$gid], $text, $gid, $mid); + } } } $res = XDB::iterator('SELECT gid, text, pos FROM profile_medals_grades WHERE mid={?} ORDER BY pos', $mid); diff --git a/templates/profile/admin_decos.tpl b/templates/profile/admin_decos.tpl index 722ebd8..fe8e526 100644 --- a/templates/profile/admin_decos.tpl +++ b/templates/profile/admin_decos.tpl @@ -27,12 +27,6 @@ {literal}