Support setting user's style when editing user in ACP
authorMatthias Schmidt <gravatronics@live.com>
Tue, 30 Jun 2020 16:10:50 +0000 (18:10 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Tue, 30 Jun 2020 16:10:50 +0000 (18:10 +0200)
Close #3254

wcfsetup/install/files/acp/templates/userAdd.tpl
wcfsetup/install/files/lib/acp/form/UserEditForm.class.php

index 3ca491e1e1a9b8523c355c2aeffff3841f7d3d84..a735f59c25786e52dcf48f6bbacd0a493469f49a 100644 (file)
                                        <section class="section">
                                                <h2 class="sectionTitle">{lang}wcf.user.option.category.{@$categoryLevel2[object]->categoryName}{/lang}</h2>
                                                
-                                               {if $categoryLevel2[object]->categoryName == 'settings.general' && $availableLanguages|count > 1}
-                                                       <dl>
-                                                               <dt><label for="languageID">{lang}wcf.user.language{/lang}</label></dt>
-                                                               <dd>
-                                                                       {htmlOptions options=$availableLanguages selected=$languageID name=languageID id=languageID disableEncoding=true}
-                                                               </dd>
-                                                       </dl>
+                                               {if $categoryLevel2[object]->categoryName == 'settings.general'}
+                                                       {if $availableLanguages|count > 1}
+                                                               <dl>
+                                                                       <dt><label for="languageID">{lang}wcf.user.language{/lang}</label></dt>
+                                                                       <dd>
+                                                                               {htmlOptions options=$availableLanguages selected=$languageID name=languageID id=languageID disableEncoding=true}
+                                                                       </dd>
+                                                               </dl>
+                                                               
+                                                               {if $availableContentLanguages|count > 1}
+                                                                       <dl>
+                                                                               <dt>
+                                                                                       <label>{lang}wcf.user.visibleLanguages{/lang}</label>
+                                                                               </dt>
+                                                                               <dd>
+                                                                                       {foreach from=$availableContentLanguages key=availableLanguageID item=availableLanguage}
+                                                                                               <label><input type="checkbox" name="visibleLanguages[]" value="{@$availableLanguageID}"{if $availableLanguageID|in_array:$visibleLanguages} checked{/if}> {@$availableLanguage}</label>
+                                                                                       {/foreach}
+                                                                               </dd>
+                                                                       </dl>
+                                                               {/if}
+                                                       {/if}
                                                        
-                                                       {if $availableContentLanguages|count > 1}
+                                                       {if $action === 'edit' && $availableStyles|count > 1}
                                                                <dl>
-                                                                       <dt>
-                                                                               <label>{lang}wcf.user.visibleLanguages{/lang}</label>
-                                                                       </dt>
+                                                                       <dt><label for="styleID">{lang}wcf.user.style{/lang}</label></dt>
                                                                        <dd>
-                                                                               {foreach from=$availableContentLanguages key=availableLanguageID item=availableLanguage}
-                                                                                       <label><input type="checkbox" name="visibleLanguages[]" value="{@$availableLanguageID}"{if $availableLanguageID|in_array:$visibleLanguages} checked{/if}> {@$availableLanguage}</label>
-                                                                               {/foreach}
+                                                                               <select id="styleID" name="styleID">
+                                                                                       <option value="0">{lang}wcf.global.defaultValue{/lang}</option>
+                                                                                       {foreach from=$availableStyles item=style}
+                                                                                               <option value="{@$style->styleID}"{if $style->styleID == $styleID} selected{/if}>{$style->styleName}</option>
+                                                                                       {/foreach}
+                                                                               </select>
+                                                                               {if $errorField === 'styleID'}
+                                                                                       <small class="innerError">
+                                                                                               {if $errorType === 'empty' || $errorType === 'noValidSelection'}
+                                                                                                       {lang}wcf.global.form.error.{@$errorType}{/lang}
+                                                                                               {else}
+                                                                                                       {lang}wcf.user.style.error.{@$errorType.password}{/lang}
+                                                                                               {/if}
+                                                                                       </small>
+                                                                               {/if}
+                                                                               <small>{lang}wcf.user.style.description{/lang}</small>
                                                                        </dd>
                                                                </dl>
                                                        {/if}
index c1c5045b12dfa1a5998930216466899abba53adb..9a94c562f99a923027d0f416dab0d16a98713357 100755 (executable)
@@ -1,5 +1,6 @@
 <?php
 namespace wcf\acp\form;
+use wcf\data\style\Style;
 use wcf\data\user\avatar\Gravatar;
 use wcf\data\user\avatar\UserAvatar;
 use wcf\data\user\avatar\UserAvatarAction;
@@ -15,6 +16,7 @@ use wcf\system\exception\IllegalLinkException;
 use wcf\system\exception\PermissionDeniedException;
 use wcf\system\exception\UserInputException;
 use wcf\system\moderation\queue\ModerationQueueManager;
+use wcf\system\style\StyleHandler;
 use wcf\system\WCF;
 use wcf\util\StringUtil;
 
@@ -22,7 +24,7 @@ use wcf\util\StringUtil;
  * Shows the user edit form.
  * 
  * @author     Marcel Werk
- * @copyright  2001-2019 WoltLab GmbH
+ * @copyright  2001-2020 WoltLab GmbH
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @package    WoltLabSuite\Core\Acp\Form
  */
@@ -133,6 +135,20 @@ class UserEditForm extends UserAddForm {
         */
        public $disconnect3rdParty = 0;
        
+       /**
+        * list of available styles for the edited user
+        * @var         Style[]
+        * @since       5.3
+        */
+       public $availableStyles = [];
+       
+       /**
+        * id of the used style
+        * @var         int
+        * @since       5.3
+        */
+       public $styleID;
+       
        /**
         * @inheritDoc
         */
@@ -175,6 +191,7 @@ class UserEditForm extends UserAddForm {
                }
                
                if (isset($_POST['avatarType'])) $this->avatarType = $_POST['avatarType'];
+               if (isset($_POST['styleID'])) $this->styleID = intval($_POST['styleID']);
                
                if (WCF::getSession()->getPermission('admin.user.canDisableAvatar')) {
                        if (!empty($_POST['disableAvatar'])) $this->disableAvatar = 1;
@@ -208,6 +225,13 @@ class UserEditForm extends UserAddForm {
                        $this->readDefaultValues();
                }
                
+               $userProfile = UserProfileRuntimeCache::getInstance()->getObject($this->userID);
+               foreach (StyleHandler::getInstance()->getStyles() as $style) {
+                       if (!$style->isDisabled || $userProfile->getPermission('admin.style.canUseDisabledStyle')) {
+                               $this->availableStyles[$style->styleID] = $style;
+                       }
+               }
+               
                parent::readData();
                
                // get the avatar object
@@ -217,8 +241,6 @@ class UserEditForm extends UserAddForm {
                
                // get the user cover photo object
                if ($this->user->coverPhotoHash) {
-                       $userProfile = UserProfileRuntimeCache::getInstance()->getObject($this->userID);
-                       
                        // If the editing user lacks the permissions to view the cover photo, the system
                        // will try to load the default cover photo. However, the default cover photo depends
                        // on the style, eventually triggering a change to the template group which will
@@ -248,6 +270,7 @@ class UserEditForm extends UserAddForm {
                $this->banReason = $this->user->banReason;
                $this->banExpires = $this->user->banExpires;
                $this->userTitle = $this->user->userTitle;
+               $this->styleID = $this->user->styleID;
                
                $this->signature = $this->user->signature;
                $this->disableSignature = $this->user->disableSignature;
@@ -292,6 +315,8 @@ class UserEditForm extends UserAddForm {
                        'disableCoverPhotoExpires' => $this->disableCoverPhotoExpires,
                        'deleteCoverPhoto' => $this->deleteCoverPhoto,
                        'ownerGroupID' => UserGroup::getOwnerGroupID(),
+                       'availableStyles' => $this->availableStyles,
+                       'styleID' => $this->styleID,
                ]);
        }
        
@@ -351,7 +376,7 @@ class UserEditForm extends UserAddForm {
                
                // save user
                $saveOptions = $this->optionHandler->save();
-
+               
                $data = [
                        'data' => array_merge($this->additionalFields, [
                                'username' => $this->username,
@@ -359,11 +384,12 @@ class UserEditForm extends UserAddForm {
                                'password' => $this->password,
                                'languageID' => $this->languageID,
                                'userTitle' => $this->userTitle,
-                               'signature' => $this->htmlInputProcessor->getHtml()
+                               'signature' => $this->htmlInputProcessor->getHtml(),
+                               'styleID' => $this->styleID,
                        ]),
                        'groups' => $this->groupIDs,
                        'languageIDs' => $this->visibleLanguages,
-                       'options' => $saveOptions
+                       'options' => $saveOptions,
                ];
                // handle changed username
                if (mb_strtolower($this->username) != mb_strtolower($this->user->username)) {
@@ -520,5 +546,9 @@ class UserEditForm extends UserAddForm {
                $this->validateAvatar();
                
                parent::validate();
+               
+               if (!isset($this->availableStyles[$this->styleID])) {
+                       throw new UserInputException('styleID', 'noValidSelection');
+               }
        }
 }