Fixes AX profile edition for medal pages.
authorStéphane Jacob <sj@m4x.org>
Mon, 31 Oct 2011 22:27:04 +0000 (23:27 +0100)
committerStéphane Jacob <sj@m4x.org>
Mon, 31 Oct 2011 22:27:04 +0000 (23:27 +0100)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
modules/profile/decos.inc.php
templates/profile/deco.tpl

index dcdffe5..1749972 100644 (file)
@@ -35,7 +35,8 @@ class ProfileSettingDeco implements ProfileSetting
     public function value(ProfilePage $page, $field, $value, &$success)
     {
         $success = true;
-        if (is_null($value)) {
+        if (is_null($value) || !S::user()->isMyProfile($profile) &&
+            $page->values['medals_pub'] == 'private' && !S::user()->checkPerms(User::PERM_DIRECTORY_PRIVATE)) {
             // Fetch already attributed medals
             $value = XDB::fetchAllAssoc("SELECT  m.mid AS id, m.gid AS grade, 1 AS valid, FIND_IN_SET('has_levels', e.flags) AS has_levels, m.level
                                            FROM  profile_medals     AS m
@@ -69,6 +70,11 @@ class ProfileSettingDeco implements ProfileSetting
         $total_original = count($original);
         $total_value = count($value);
 
+        if ($total_original && !S::user()->isMyProfile($profile) &&
+            $page->values['medals_pub'] == 'private' && !S::user()->checkPerms(User::PERM_DIRECTORY_PRIVATE)) {
+            return;
+        }
+
         while ($i < $total_original || $j < $total_value) {
             if (isset($value[$j]) && (!isset($original[$i]) || self::compareMedals($original[$i], $value[$j]))) {
                 $req = new MedalReq(S::user(), $page->profile, $value[$j]['id'], $value[$j]['grade'], $value[$j]['level'], $value[$j]['has_levels']);
@@ -111,8 +117,8 @@ class ProfilePageDecos extends ProfilePage
     public function __construct(PlWizard $wiz)
     {
         parent::__construct($wiz);
-        $this->settings['medals'] = new ProfileSettingDeco();
         $this->settings['medals_pub'] = new ProfileSettingPub();
+        $this->settings['medals'] = new ProfileSettingDeco();
         $this->watched['medals'] = true;
     }
 
@@ -127,7 +133,7 @@ class ProfilePageDecos extends ProfilePage
 
     protected function _saveData()
     {
-        if ($this->changed['medals_pub']) {
+        if ($this->changed['medals_pub'] && (S::user()->isMyProfile($profile) || S::user()->checkPerms(User::PERM_DIRECTORY_PRIVATE))) {
             XDB::execute("UPDATE  profiles
                              SET  medals_pub = {?}
                            WHERE  pid = {?}",
index 334ca32..2dec241 100644 (file)
 {*                                                                        *}
 {**************************************************************************}
 
+{if !hasPerm('directory_private') && ($medals_pub eq 'private') && ($medals|@count neq 0)}
+{assign var=hidden_medal value=true}
+{else}
+{assign var=hidden_medal value=false}
+{/if}
 <table class="bicol">
   <tr>
     <th>
       <div class="flags" style="float: left">
-        <label><input type="checkbox" name="medals_pub"{if $medals_pub eq 'public'} checked="checked"{/if} />
+        <label><input type="checkbox" name="medals_pub"{if $medals_pub eq 'public'} checked="checked"{/if}{if $hidden_medal} disabled="disabled"{/if} />
         {icon name="flag_green" title="site public"}</label>
       </div>
-      Médailles, Décorations, Prix&hellip;
+      Médailles, Décorations, Prix&hellip;{if $hidden_medal} (masqué){/if}
     </th>
   </tr>
+{if !$hidden_medal}
   <tr>
     <td>
       <div style="clear: both; margin-top: 0.2em" id="medals">
@@ -59,6 +65,7 @@
       </p>
     </td>
   </tr>
+{/if}
 </table>
 
 {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}