}
};
+/**
+ * Namespace for user group management.
+ */
+WCF.ACP.User.Group = { };
+
+/**
+ * Handles copying user groups.
+ */
+WCF.ACP.User.Group.Copy = Class.extend({
+ /**
+ * id of the copied group
+ * @var integer
+ */
+ _groupID: 0,
+
+ /**
+ * Initializes a new instance of WCF.ACP.User.Group.Copy.
+ *
+ * @param integer groupID
+ */
+ init: function(groupID) {
+ this._groupID = groupID;
+
+ $('.jsButtonUserGroupCopy').click($.proxy(this._click, this));
+ },
+
+ /**
+ * Handles clicking on a 'copy user group' button.
+ */
+ _click: function() {
+ var $template = $('<div />');
+ $template.append($('<dl class="wide marginTop"><dt /><dd><label><input type="checkbox" id="copyMembers" value="1" /> ' + WCF.Language.get('wcf.acp.group.copy.copyMembers') + '</label><small>' + WCF.Language.get('wcf.acp.group.copy.copyMembers.description') + '</small></dd></dl>'));
+ $template.append($('<dl class="wide marginTopSmall"><dt /><dd><label><input type="checkbox" id="copyUserGroupOptions" value="1" /> ' + WCF.Language.get('wcf.acp.group.copy.copyUserGroupOptions') + '</label><small>' + WCF.Language.get('wcf.acp.group.copy.copyUserGroupOptions.description') + '</small></dd></dl>'));
+ $template.append($('<dl class="wide marginTopSmall"><dt /><dd><label><input type="checkbox" id="copyACLOptions" value="1" /> ' + WCF.Language.get('wcf.acp.group.copy.copyACLOptions') + '</label><small>' + WCF.Language.get('wcf.acp.group.copy.copyACLOptions.description') + '</small></dd></dl>'));
+
+ WCF.System.Confirmation.show(WCF.Language.get('wcf.acp.group.copy.confirmMessage'), $.proxy(function(action) {
+ if (action === 'confirm') {
+ new WCF.Action.Proxy({
+ autoSend: true,
+ data: {
+ actionName: 'copy',
+ className: 'wcf\\data\\user\\group\\UserGroupAction',
+ objectIDs: [ this._groupID ],
+ parameters: {
+ copyACLOptions: $('#copyACLOptions').is(':checked'),
+ copyMembers: $('#copyMembers').is(':checked'),
+ copyUserGroupOptions: $('#copyUserGroupOptions').is(':checked')
+ }
+ },
+ success: function(data) {
+ window.location = data.returnValues.redirectURL;
+ }
+ });
+ }
+ }, this), '', $template);
+ }
+});
+
/**
* Generic implementation to enable users.
*/
//<![CDATA[
$(function() {
WCF.TabMenu.init();
+
new WCF.Option.Handler();
+
+ {if $action == 'edit' && $group->groupType == 4 && $__wcf->session->getPermission('admin.user.canAddGroup')}
+ WCF.Language.addObject({
+ 'wcf.acp.group.copy.confirmMessage': '{lang}wcf.acp.group.copy.confirmMessage{/lang}',
+ 'wcf.acp.group.copy.copyACLOptions': '{lang}wcf.acp.group.copy.copyACLOptions{/lang}',
+ 'wcf.acp.group.copy.copyACLOptions.description': '{lang}wcf.acp.group.copy.copyACLOptions.description{/lang}',
+ 'wcf.acp.group.copy.copyMembers': '{lang}wcf.acp.group.copy.copyMembers{/lang}',
+ 'wcf.acp.group.copy.copyMembers.description': '{lang}wcf.acp.group.copy.copyMembers.description{/lang}',
+ 'wcf.acp.group.copy.copyUserGroupOptions': '{lang}wcf.acp.group.copy.copyUserGroupOptions{/lang}',
+ 'wcf.acp.group.copy.copyUserGroupOptions.description': '{lang}wcf.acp.group.copy.copyUserGroupOptions.description{/lang}'
+ });
+
+ new WCF.ACP.User.Group.Copy({@$groupID});
+ {/if}
});
//]]>
</script>
<div class="contentNavigation">
<nav>
<ul>
- {if $action == 'edit' && $availableUserGroups|count > 1}
- <li class="dropdown">
- <a class="button dropdownToggle"><span class="icon icon16 icon-sort"></span> <span>{lang}wcf.acp.group.button.choose{/lang}</span></a>
- <div class="dropdownMenu">
- <ul class="scrollableDropdownMenu">
- {foreach from=$availableUserGroups item='availableUserGroup'}
- <li{if $availableUserGroup->groupID == $groupID} class="active"{/if}><a href="{link controller='UserGroupEdit' id=$availableUserGroup->groupID}{/link}">{$availableUserGroup->getName()}</a></li>
- {/foreach}
- </ul>
- </div>
- </li>
+ {if $action == 'edit'}
+ {if $availableUserGroups|count > 1}
+ <li class="dropdown">
+ <a class="button dropdownToggle"><span class="icon icon16 icon-sort"></span> <span>{lang}wcf.acp.group.button.choose{/lang}</span></a>
+ <div class="dropdownMenu">
+ <ul class="scrollableDropdownMenu">
+ {foreach from=$availableUserGroups item='availableUserGroup'}
+ <li{if $availableUserGroup->groupID == $groupID} class="active"{/if}><a href="{link controller='UserGroupEdit' id=$availableUserGroup->groupID}{/link}">{$availableUserGroup->getName()}</a></li>
+ {/foreach}
+ </ul>
+ </div>
+ </li>
+ {/if}
+
+ {if $__wcf->session->getPermission('admin.user.canAddGroup') && $group->groupType == 4}
+ <li><a class="jsButtonUserGroupCopy button"><span class="icon icon16 icon-copy"></span> <span>{lang}wcf.acp.group.button.copy{/lang}</span></a></li>
+ {/if}
{/if}
<li><a href="{link controller='UserGroupList'}{/link}" class="button"><span class="icon icon16 icon-list"></span> <span>{lang}wcf.acp.menu.link.group.list{/lang}</span></a></li>
<?php
namespace wcf\data\user\group;
use wcf\data\AbstractDatabaseObjectAction;
+use wcf\system\cache\CacheHandler;
+use wcf\system\exception\PermissionDeniedException;
+use wcf\system\language\LanguageFactory;
+use wcf\system\request\LinkHandler;
+use wcf\system\user\storage\UserStorageHandler;
+use wcf\system\WCF;
/**
* Executes user group-related actions.
*/
public $className = 'wcf\data\user\group\UserGroupEditor';
+ /**
+ * editor object for the copied user group
+ * @var \wcf\data\user\group\UserGroupEditor
+ */
+ public $groupEditor = null;
+
/**
* @see \wcf\data\AbstractDatabaseObjectAction::$permissionsCreate
*/
/**
* @see \wcf\data\AbstractDatabaseObjectAction::$requireACP
*/
- protected $requireACP = array('create', 'delete', 'update');
+ protected $requireACP = array('copy', 'create', 'delete', 'update');
/**
* @see \wcf\data\AbstractDatabaseObjectAction::create()
$object->updateGroupOptions($this->parameters['options']);
}
}
+
+ /**
+ * Validates the 'copy' action.
+ */
+ public function validateCopy() {
+ WCF::getSession()->checkPermissions(array(
+ 'admin.user.canAddGroup',
+ 'admin.user.canEditGroup'
+ ));
+
+ $this->readBoolean('copyACLOptions');
+ $this->readBoolean('copyMembers');
+ $this->readBoolean('copyUserGroupOptions');
+
+ $this->groupEditor = $this->getSingleObject();
+ if (!$this->groupEditor->isAccessible() || $this->groupEditor->groupType != UserGroup::OTHER) {
+ throw new PermissionDeniedException();
+ }
+ }
+
+ /**
+ * Copies a user group.
+ */
+ public function copy() {
+ // fetch user group option values
+ if ($this->parameters['copyUserGroupOptions']) {
+ $sql = "SELECT optionID, optionValue
+ FROM wcf".WCF_N."_user_group_option_value
+ WHERE groupID = ?";
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute(array($this->groupEditor->groupID));
+ }
+ else {
+ $sql = "SELECT optionID, defaultValue AS optionValue
+ FROM wcf".WCF_N."_user_group_option";
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute();
+ }
+
+ $optionValues = array();
+ while ($row = $statement->fetchArray()) {
+ $optionValues[$row['optionID']] = $row['optionValue'];
+ }
+
+ $groupAction = new UserGroupAction(array(), 'create', array(
+ 'data' => array(
+ 'groupName' => $this->groupEditor->groupName,
+ 'groupDescription' => $this->groupEditor->groupDescription,
+ 'priority' => $this->groupEditor->priority,
+ 'userOnlineMarking' => $this->groupEditor->userOnlineMarking,
+ 'showOnTeamPage' => $this->groupEditor->showOnTeamPage
+ ),
+ 'options' => $optionValues
+ ));
+ $returnValues = $groupAction->executeAction();
+ $group = $returnValues['returnValues'];
+ $groupEditor = new UserGroupEditor($group);
+
+ // update group name
+ $groupName = $this->groupEditor->groupName;
+ if (preg_match('~^wcf\.acp\.group\.group\d+$~', $this->groupEditor->groupName)) {
+ $groupName = 'wcf.acp.group.group'.$group->groupID;
+
+ // create group name language item
+ $sql = "INSERT INTO wcf".WCF_N."_language_item
+ (languageID, languageItem, languageItemValue, languageItemOriginIsSystem, languageCategoryID, packageID)
+ SELECT languageID, '".$groupName."', CONCAT(languageItemValue, ' (2)'), 0, languageCategoryID, packageID
+ FROM wcf".WCF_N."_language_item
+ WHERE languageItem = ?";
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute(array($this->groupEditor->groupName));
+ }
+ else {
+ $groupName .= ' (2)';
+ }
+
+ // update group name
+ $groupDescription = $this->groupEditor->groupName;
+ if (preg_match('~^wcf\.acp\.group\.groupDescription\d+$~', $this->groupEditor->groupDescription)) {
+ $groupDescription = 'wcf.acp.group.groupDescription'.$group->groupID;
+
+ // create group name language item
+ $sql = "INSERT INTO wcf".WCF_N."_language_item
+ (languageID, languageItem, languageItemValue, languageItemOriginIsSystem, languageCategoryID, packageID)
+ SELECT languageID, '".$groupDescription."', languageItemValue, 0, languageCategoryID, packageID
+ FROM wcf".WCF_N."_language_item
+ WHERE languageItem = ?";
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute(array($this->groupEditor->groupDescription));
+ }
+
+ $groupEditor->update(array(
+ 'groupDescription' => $groupDescription,
+ 'groupName' => $groupName
+ ));
+
+ // copy members
+ if ($this->parameters['copyMembers']) {
+ $sql = "INSERT INTO wcf".WCF_N."_user_to_group
+ (userID, groupID)
+ SELECT userID, ".$group->groupID."
+ FROM wcf".WCF_N."_user_to_group
+ WHERE groupID = ?";
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute(array($this->groupEditor->groupID));
+ }
+
+ // copy acl options
+ if ($this->parameters['copyACLOptions']) {
+ $sql = "INSERT INTO wcf".WCF_N."_acl_option_to_group
+ (optionID, objectID, groupID, optionValue)
+ SELECT optionID, objectID, ".$group->groupID.", optionValue
+ FROM wcf".WCF_N."_acl_option_to_group
+ WHERE groupID = ?";
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute(array($this->groupEditor->groupID));
+
+ // it is likely that applications or plugins use caches
+ // for acl option values like for the labels which have
+ // to be renewed after copying the acl options; because
+ // there is no other way to delete these caches, we simply
+ // delete all caches
+ CacheHandler::getInstance()->flushAll();
+ }
+
+ // reset language cache
+ LanguageFactory::getInstance()->deleteLanguageCache();
+
+ UserGroupEditor::resetCache();
+
+ return array(
+ 'redirectURL' => LinkHandler::getInstance()->getLink('UserGroupEdit', array(
+ 'id' => $group->groupID
+ ))
+ );
+ }
}