From 8c5f91c498e3838a6207d6d45ee5e868719d6c83 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Sun, 28 Nov 2010 00:02:08 +0100 Subject: [PATCH] Only admin can edit original corps (Closes #1364). MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- modules/profile/jobs.inc.php | 37 ++++++++++++++++++++++++------------- templates/profile/jobs.tpl | 7 +++++++ 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/modules/profile/jobs.inc.php b/modules/profile/jobs.inc.php index 723370b..83dcade 100644 --- a/modules/profile/jobs.inc.php +++ b/modules/profile/jobs.inc.php @@ -312,10 +312,11 @@ class ProfileSettingCorps implements ProfileSetting { $success = true; if (is_null($value)) { - $res = XDB::query("SELECT original_corpsid AS original, current_corpsid AS current, - rankid AS rank, corps_pub AS pub - FROM profile_corps - WHERE pid = {?}", + $res = XDB::query('SELECT c.original_corpsid AS original, e.name AS originalText, + c.current_corpsid AS current, c.rankid AS rank, c.corps_pub AS pub + FROM profile_corps AS c + INNER JOIN profile_corps_enum AS e ON (c.original_corpsid = e.id) + WHERE c.pid = {?}', $page->pid()); return $res->fetchOneAssoc(); } @@ -324,11 +325,19 @@ class ProfileSettingCorps implements ProfileSetting public function save(ProfilePage &$page, $field, $value) { - XDB::execute('INSERT INTO profile_corps (original_corpsid, current_corpsid, rankid, corps_pub, pid) - VALUES ({?}, {?}, {?}, {?}, {?}) - ON DUPLICATE KEY UPDATE original_corpsid = VALUES(original_corpsid), current_corpsid = VALUES(current_corpsid), - rankid = VALUES(rankid), corps_pub = VALUES(corps_pub)', - $value['original'], $value['current'], $value['rank'], $value['pub'], $page->pid()); + if (!S::user()->isMe($page->owner)) { + XDB::execute('INSERT INTO profile_corps (original_corpsid, current_corpsid, rankid, corps_pub, pid) + VALUES ({?}, {?}, {?}, {?}, {?}) + ON DUPLICATE KEY UPDATE original_corpsid = VALUES(original_corpsid), current_corpsid = VALUES(current_corpsid), + rankid = VALUES(rankid), corps_pub = VALUES(corps_pub)', + $value['original'], $value['current'], $value['rank'], $value['pub'], $page->pid()); + } else { + XDB::execute('INSERT INTO profile_corps (current_corpsid, rankid, corps_pub, pid) + VALUES ({?}, {?}, {?}, {?}) + ON DUPLICATE KEY UPDATE current_corpsid = VALUES(current_corpsid), + rankid = VALUES(rankid), corps_pub = VALUES(corps_pub)', + $value['current'], $value['rank'], $value['pub'], $page->pid()); + } } public function getText($value) @@ -384,10 +393,12 @@ class ProfilePageJobs extends ProfilePage require_once 'emails.combobox.inc.php'; fill_email_combobox($page, $this->owner); - $res = XDB::iterator("SELECT id, name - FROM profile_corps_enum - ORDER BY id = 1 DESC, name"); - $page->assign('original_corps', $res->fetchAllAssoc()); + if (!S::user()->isMe($page->owner)) { + $res = XDB::iterator('SELECT id, name + FROM profile_corps_enum + ORDER BY id = 1 DESC, name'); + $page->assign('original_corps', $res->fetchAllAssoc()); + } $res = XDB::iterator("SELECT id, name FROM profile_corps_enum diff --git a/templates/profile/jobs.tpl b/templates/profile/jobs.tpl index aa6e0df..f496e24 100644 --- a/templates/profile/jobs.tpl +++ b/templates/profile/jobs.tpl @@ -48,11 +48,18 @@ Corps d'origine + {if $isMe} + {$corps.originalText} + + + {else} + + {/if} -- 2.1.4