From: Stéphane Jacob Date: Sat, 27 Nov 2010 23:02:08 +0000 (+0100) Subject: Only admin can edit original corps (Closes #1364). X-Git-Tag: xorg/1.0.2~125 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=8c5f91c498e3838a6207d6d45ee5e868719d6c83;p=platal.git Only admin can edit original corps (Closes #1364). Signed-off-by: Stéphane Jacob --- 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}