window.location = this._list.find('li.dropdownNavigationItem > a').attr('href');
}
});
+
+/**
+ * Namespace for user management.
+ */
+WCF.ACP.User = { };
+
+/**
+ * Generic implementation to ban users.
+ */
+WCF.ACP.User.BanHandler = {
+ /**
+ * callback object
+ * @var object
+ */
+ _callback: null,
+
+ /**
+ * dialog overlay
+ * @var jQuery
+ */
+ _dialog: null,
+
+ /**
+ * action proxy
+ * @var WCF.Action.Proxy
+ */
+ _proxy: null,
+
+ /**
+ * Initializes WCF.ACP.User.BanHandler on first use.
+ */
+ init: function() {
+ this._dialog = $('<div />').hide().appendTo(document.body);
+ this._proxy = new WCF.Action.Proxy({
+ success: $.proxy(this._success, this)
+ });
+
+ $('.jsBanButton').click($.proxy(function(event) {
+ var $button = $(event.currentTarget);
+ if ($button.data('banned')) {
+ this.unban([ $button.data('objectID') ]);
+ }
+ else {
+ this.ban([ $button.data('objectID') ]);
+ }
+ }, this));
+ },
+
+ /**
+ * Unbans users.
+ *
+ * @param array<integer> userIDs
+ */
+ unban: function(userIDs) {
+ this._proxy.setOption('data', {
+ actionName: 'unban',
+ className: 'wcf\\data\\user\\UserAction',
+ objectIDs: userIDs
+ });
+ this._proxy.sendRequest();
+ },
+
+ /**
+ * Bans users.
+ *
+ * @param array<integer> userIDs
+ */
+ ban: function(userIDs) {
+ WCF.System.Confirmation.show(WCF.Language.get('wcf.acp.user.ban.sure'), $.proxy(function(action) {
+ if (action === 'confirm') {
+ this._proxy.setOption('data', {
+ actionName: 'ban',
+ className: 'wcf\\data\\user\\UserAction',
+ objectIDs: userIDs,
+ parameters: {
+ banReason: $('#userBanReason').val()
+ }
+ });
+ this._proxy.sendRequest();
+ }
+ }, this), '', $('<fieldset><dl><dt><label for="userBanReason">' + WCF.Language.get('wcf.acp.user.banReason') + '</label></dt><dd><textarea id="userBanReason" cols="40" rows="3" /><small>' + WCF.Language.get('wcf.acp.user.banReason.description') + '</small></dd></dl></fieldset>'));
+ },
+
+ /**
+ * Handles successful AJAX calls.
+ *
+ * @param object data
+ * @param string textStatus
+ * @param jQuery jqXHR
+ */
+ _success: function(data, textStatus, jqXHR) {
+ $('.jsBanButton').each(function(index, button) {
+ var $button = $(button);
+ if (WCF.inArray($button.data('objectID'), data.objectIDs)) {
+ if (data.actionName == 'unban') {
+ $button.data('banned', false).data('tooltip', $button.data('banMessage')).removeClass('icon-lock').addClass('icon-unlock');
+ }
+ else {
+ $button.data('banned', true).data('tooltip', $button.data('unbanMessage')).removeClass('icon-unlock').addClass('icon-lock');
+ }
+ }
+ });
+
+ var $notification = new WCF.System.Notification();
+ $notification.show();
+ }
+};
\ No newline at end of file
{/if}
new WCF.Table.EmptyTableHandler($('#userTableContainer'), 'jsUserRow', options);
+
+ WCF.Language.addObject({
+ 'wcf.acp.user.banReason': '{lang}wcf.acp.user.banReason{/lang}',
+ 'wcf.acp.user.banReason.description': '{lang}wcf.acp.user.banReason.description{/lang}',
+ 'wcf.acp.user.ban.sure': '{lang}wcf.acp.user.ban.sure{/lang}'
+ });
+ WCF.ACP.User.BanHandler.init();
});
//]]>
</script>
{else}
<span class="icon icon16 icon-remove disabled" title="{lang}wcf.global.button.delete{/lang}"></span>
{/if}
+ {if $user->bannable}
+ <span class="icon icon16 icon-{if $user->banned}lock{else}unlock{/if} jsBanButton jsTooltip pointer" title="{lang}wcf.acp.user.{if $user->banned}unban{else}ban{/if}{/lang}" data-object-id="{@$user->userID}" data-ban-message="{lang}wcf.acp.user.ban{/lang}" data-unban-message="{lang}wcf.acp.user.unban{/lang}" data-banned="{if $user->banned}true{else}false{/if}"></span>
+ {else}
+ <span class="icon icon16 icon-{if $user->banned}lock{else}unlock{/if} disabled" title="{lang}wcf.acp.user.{if $user->banned}unban{else}ban{/if}{/lang}"></span>
+ {/if}
{event name='rowButtons'}
</td>
*/
init: function(message, cssClassNames) {
this._cssClassNames = cssClassNames || 'success';
- this._message = message;
+ this._message = message || WCF.Language.get('wcf.global.success');
this._overlay = $('#systemNotification');
if (!this._overlay.length) {
$row['accessible'] = $accessible;
$row['deletable'] = ($accessible && WCF::getSession()->getPermission('admin.user.canDeleteUser') && $row['userID'] != WCF::getUser()->userID) ? 1 : 0;
$row['editable'] = ($accessible && WCF::getSession()->getPermission('admin.user.canEditUser')) ? 1 : 0;
+ $row['bannable'] = ($accessible && WCF::getSession()->getPermission('admin.user.canBanUser') && $row['userID'] != WCF::getUser()->userID) ? 1 : 0;
$row['isMarked'] = intval(in_array($row['userID'], $this->markedUsers));
$this->users[] = new User(null, $row);
}
/**
- * Validates permissions and parameters.
+ * Validates accessible groups.
+ *
+ * @param boolean $ignoreOwnUser
*/
- public function validateDelete() {
- // read and validate user objects
- parent::validateDelete();
-
- $userIDs = array();
- foreach ($this->objects as $user) {
- // you cannot delete yourself
- if ($user->userID == WCF::getUser()->userID) {
- continue;
+ protected function __validateAccessibleGroups($ignoreOwnUser = true) {
+ if ($ignoreOwnUser) {
+ if (in_array(WCF::getUser()->userID, $this->objectIDs)) {
+ unset($this->objectIDs[array_search(WCF::getUser()->userID, $this->objectIDs)]);
+ if (isset($this->objects[WCF::getUser()->userID])) {
+ unset($this->objects[WCF::getUser()->userID]);
+ }
}
-
- $userIDs[] = $user->userID;
}
// list might be empty because only our own user id was given
- if (empty($userIDs)) {
+ if (empty($this->objectIDs)) {
throw new UserInputException('objectIDs');
}
// validate groups
$conditions = new PreparedStatementConditionBuilder();
- $conditions->add("userID IN (?)", array($userIDs));
+ $conditions->add("userID IN (?)", array($this->objectIDs));
$sql = "SELECT DISTINCT groupID
FROM wcf".WCF_N."_user_to_group
}
}
+ /**
+ * Validates permissions and parameters.
+ */
+ public function validateDelete() {
+ // read and validate user objects
+ parent::validateDelete();
+
+ $this->__validateAccessibleGroups();
+ }
+
/**
* Validates permissions and parameters.
*/
}
}
+ /**
+ * Validates the ban action.
+ */
+ public function validateBan() {
+ WCF::getSession()->checkPermissions(array('admin.user.canBanUser'));
+
+ $this->__validateAccessibleGroups();
+ }
+
+ /**
+ * Validates the unban action.
+ */
+ public function validateUnban() {
+ $this->validateBan();
+ }
+
+ /**
+ * Bans users.
+ */
+ public function ban() {
+ $conditionBuilder = new PreparedStatementConditionBuilder();
+ $conditionBuilder->add('userID IN (?)', array($this->objectIDs));
+ $sql = "UPDATE wcf".WCF_N."_user
+ SET banned = ?,
+ banReason = ?
+ ".$conditionBuilder;
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute(
+ array_merge(array(1, $this->parameters['banReason']), $conditionBuilder->getParameters())
+ );
+ }
+
+ /**
+ * Unbans users.
+ */
+ public function unban() {
+ $conditionBuilder = new PreparedStatementConditionBuilder();
+ $conditionBuilder->add('userID IN (?)', array($this->objectIDs));
+ $sql = "UPDATE wcf".WCF_N."_user
+ SET banned = 0
+ ".$conditionBuilder;
+ $statement = WCF::getDB()->prepareStatement($sql);
+ $statement->execute($conditionBuilder->getParameters());
+ }
+
/**
* Creates a new user.
*
<item name="wcf.acp.user.banUser.description"><![CDATA[Der Benutzer wird dauerhaft von der Nutzung aller Funktionen ausgeschlossen und erhält beim Aufruf der Seite eine entsprechende Fehlermeldung.]]></item>
<item name="wcf.acp.user.banReason"><![CDATA[Begründung]]></item>
<item name="wcf.acp.user.banReason.description"><![CDATA[Die Begründung wird dem gesperrten Benutzer beim Aufruf der Seite angezeigt.]]></item>
+ <item name="wcf.acp.user.ban"><![CDATA[Sperren]]></item>
+ <item name="wcf.acp.user.unban"><![CDATA[Sperrung aufheben]]></item>
+ <item name="wcf.acp.user.ban.sure"><![CDATA[Wollen Sie den/die Benutzer wirklich sperren?]]></item>
<item name="wcf.acp.user.delete.sure"><![CDATA[Wollen Sie Benutzer „{$user->username}“ wirklich löschen?]]></item>
<item name="wcf.acp.user.edit"><![CDATA[Benutzer bearbeiten]]></item>
<item name="wcf.acp.user.edit.warning.selfEdit"><![CDATA[Sie bearbeiten Ihr eigenes Benutzerkonto. Änderungen an den Mitgliedschaften in Benutzergruppen können womöglich dazu führen, dass Sie aus der Administrationsoberfläche ausgeschlossen werden. Bitte seien Sie entsprechend vorsichtig!]]></item>
<item name="wcf.acp.user.banUser.description"><![CDATA[TODO: Der Benutzer wird dauerhaft von der Nutzung aller Funktionen ausgeschlossen und erhält beim Aufruf der Seite eine entsprechende Fehlermeldung.]]></item>
<item name="wcf.acp.user.banReason"><![CDATA[TODO: Begründung]]></item>
<item name="wcf.acp.user.banReason.description"><![CDATA[TODO: Die Begründung wird dem gesperrten Benutzer beim Aufruf der Seite angezeigt.]]></item>
+ <item name="wcf.acp.user.ban"><![CDATA[TODO: Sperren]]></item>
+ <item name="wcf.acp.user.unban"><![CDATA[TODO: Sperrung aufheben]]></item>
+ <item name="wcf.acp.user.ban.sure"><![CDATA[TODO: Wollen Sie den/die Benutzer wirklich sperren?]]></item>
<item name="wcf.acp.user.delete.sure"><![CDATA[Do you really want to delete the user “{$user->username}”?]]></item>
<item name="wcf.acp.user.edit"><![CDATA[Edit User]]></item>
<item name="wcf.acp.user.edit.warning.selfEdit"><![CDATA[Heads up! You’re editing your own user account and changes might result in yourself being locked out from the Administration Control Panel.]]></item>