From: Marcel Werk Date: Sat, 11 May 2013 18:22:40 +0000 (+0200) Subject: User bulk processing overhaul X-Git-Tag: 2.0.0_Beta_1~203^2~5 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=a82f9b2c4feab9e8af72411a66a06978c3408c00;p=GitHub%2FWoltLab%2FWCF.git User bulk processing overhaul --- diff --git a/com.woltlab.wcf/acpMenu.xml b/com.woltlab.wcf/acpMenu.xml index 09dad4fbc5..e2f5f25089 100644 --- a/com.woltlab.wcf/acpMenu.xml +++ b/com.woltlab.wcf/acpMenu.xml @@ -173,8 +173,8 @@ 2 - - + + wcf.acp.menu.link.user.management.additional admin.user.canEditUser,admin.user.canDeleteUser,admin.user.canMailUser 1 diff --git a/wcfsetup/install/files/acp/templates/userBulkProcessing.tpl b/wcfsetup/install/files/acp/templates/userBulkProcessing.tpl new file mode 100644 index 0000000000..6b51ae3197 --- /dev/null +++ b/wcfsetup/install/files/acp/templates/userBulkProcessing.tpl @@ -0,0 +1,291 @@ +{include file='header' pageTitle='wcf.acp.user.bulkProcessing'} + + + +
+

{lang}wcf.acp.user.bulkProcessing{/lang}

+
+ +{if $errorField} +

{lang}wcf.global.form.error{/lang}

+{/if} + +

{lang}wcf.acp.user.bulkProcessing.warning{/lang}

+ +{if $affectedUsers|isset} +

{lang}wcf.acp.user.bulkProcessing.success{/lang}

+{/if} + +
+ {hascontent} + + {/hascontent} +
+ +
+
+ + +
+
+ {lang}wcf.acp.user.search.conditions.general{/lang} + +
+
+
+ +
+
+ + {if $__wcf->session->getPermission('admin.user.canEditMailAddress')} +
+
+
+ +
+
+ {/if} + + {if $availableGroups|count} +
+
+
+ {htmlCheckboxes options=$availableGroups name='groupIDArray' selected=$groupIDArray} + + +
+
+ {/if} + + {if $availableLanguages|count > 1} +
+
+
+ {htmlCheckboxes options=$availableLanguages name='languageIDArray' selected=$languageIDArray disableEncoding=true} +
+
+ {/if} + + {event name='generalFields'} +
+
+ + {if $options|count} +
+
+ {lang}wcf.acp.user.search.conditions.profile{/lang} + + {include file='optionFieldList' langPrefix='wcf.user.option.'} +
+
+ {/if} + +
+ + {lang}wcf.acp.user.bulkProcessing.action{/lang} + +
+
+ {if $__wcf->session->getPermission('admin.user.canMailUser')} + + + {/if} + {if $__wcf->session->getPermission('admin.user.canEditUser')} + + {/if} + {if $__wcf->session->getPermission('admin.user.canDeleteUser')} + + {/if} + + {event name='additionalActions'} + + {if $errorField == 'action'} + + {if $errorType == 'empty'}{lang}wcf.global.form.error.empty{/lang}{/if} + + {/if} +
+
+ + +
+
+ {lang}wcf.acp.user.sendMail.mail{/lang} + + +
+
+ + {if $errorField == 'from'} + + {if $errorType == 'empty'}{lang}wcf.global.form.error.empty{/lang}{/if} + + {/if} + {lang}wcf.acp.user.sendMail.from.description{/lang} +
+ + + +
+
+ + {if $errorField == 'subject'} + + {if $errorType == 'empty'}{lang}wcf.global.form.error.empty{/lang}{/if} + + {/if} + {lang}wcf.acp.user.sendMail.subject.description{/lang} +
+ + + +
+
+ + {if $errorField == 'text'} + + {if $errorType == 'empty'}{lang}wcf.global.form.error.empty{/lang}{/if} + + {/if} + {lang}wcf.acp.user.sendMail.text.description{/lang} +
+ + +
+
+ +
+
+
+
+ +
+
+ {lang}wcf.acp.user.exportEmailAddress.format{/lang} + +
+
+
+ + +
+
+ +
+
+
+ +
+
+ +
+
+
+ +
+
+
+
+ +
+
+ {lang}wcf.acp.user.groups{/lang} + +
+ + {htmlCheckboxes options=$availableGroups name=assignToGroupIDArray selected=$assignToGroupIDArray} + {if $errorField == 'assignToGroupIDArray'} + + {if $errorType == 'empty'}{lang}wcf.global.form.error.empty{/lang}{/if} + + {/if} + +
+
+
+ + {event name='actionSettings'} +
+
+ +
+ +
+
+ +{include file='footer'} diff --git a/wcfsetup/install/files/acp/templates/usersMassProcessing.tpl b/wcfsetup/install/files/acp/templates/usersMassProcessing.tpl deleted file mode 100644 index 5725649353..0000000000 --- a/wcfsetup/install/files/acp/templates/usersMassProcessing.tpl +++ /dev/null @@ -1,292 +0,0 @@ -{include file='header' pageTitle='wcf.acp.user.massProcessing'} - - - -
-

{lang}wcf.acp.user.massProcessing{/lang}

-
- -{if $errorField} -

{lang}wcf.global.form.error{/lang}

-{/if} - -

{lang}wcf.acp.user.massProcessing.warning{/lang}

- -{if $affectedUsers|isset} -

{lang}wcf.acp.user.massProcessing.success{/lang}

-{/if} - -
- {hascontent} - - {/hascontent} -
- -
-
-
- {lang}wcf.acp.user.search.conditions.general{/lang} - -
-
-
- -
-
- - {if $__wcf->session->getPermission('admin.user.canEditMailAddress')} -
-
-
- -
-
- {/if} - - {if $availableGroups|count} -
-
-
- {htmlCheckboxes options=$availableGroups name='groupIDArray' selected=$groupIDArray} - - -
-
- {/if} - - {if $availableLanguages|count > 1} -
-
-
- {htmlCheckboxes options=$availableLanguages name='languageIDArray' selected=$languageIDArray disableEncoding=true} -
-
- {/if} - - {event name='generalFields'} -
- - {event name='fieldsets'} - - {hascontent} -
- - - {if $options|count} - - {/if} - - {event name='tabMenuContents'} -
- {/hascontent} -
- -
- - {lang}wcf.acp.user.massProcessing.action{/lang} - -
-
- {if $__wcf->session->getPermission('admin.user.canMailUser')} - - - {/if} - {if $__wcf->session->getPermission('admin.user.canEditUser')} - - {/if} - {if $__wcf->session->getPermission('admin.user.canDeleteUser')} - - {/if} - - {event name='additionalActions'} - - {if $errorField == 'action'} - - {if $errorType == 'empty'}{lang}wcf.global.form.error.empty{/lang}{/if} - - {/if} -
-
- - -
-
- {lang}wcf.acp.user.sendMail.mail{/lang} - - -
-
- - {if $errorField == 'from'} - - {if $errorType == 'empty'}{lang}wcf.global.form.error.empty{/lang}{/if} - - {/if} - {lang}wcf.acp.user.sendMail.from.description{/lang} -
- - - -
-
- - {if $errorField == 'subject'} - - {if $errorType == 'empty'}{lang}wcf.global.form.error.empty{/lang}{/if} - - {/if} - {lang}wcf.acp.user.sendMail.subject.description{/lang} -
- - - -
-
- - {if $errorField == 'text'} - - {if $errorType == 'empty'}{lang}wcf.global.form.error.empty{/lang}{/if} - - {/if} - {lang}wcf.acp.user.sendMail.text.description{/lang} -
- - -
-
- -
-
-
-
- -
-
- {lang}wcf.acp.user.exportEmailAddress.format{/lang} - -
-
-
- - -
-
- -
-
-
- -
-
- -
-
-
- -
-
-
-
- -
-
- {lang}wcf.acp.user.groups{/lang} - -
- - {htmlCheckboxes options=$availableGroups name=assignToGroupIDArray selected=$assignToGroupIDArray} - {if $errorField == 'assignToGroupIDArray'} - - {if $errorType == 'empty'}{lang}wcf.global.form.error.empty{/lang}{/if} - - {/if} - -
-
-
- - {event name='actionSettings'} -
- -
- -
-
- -{include file='footer'} diff --git a/wcfsetup/install/files/lib/acp/form/UserBulkProcessingForm.class.php b/wcfsetup/install/files/lib/acp/form/UserBulkProcessingForm.class.php new file mode 100644 index 0000000000..9a42489fe6 --- /dev/null +++ b/wcfsetup/install/files/lib/acp/form/UserBulkProcessingForm.class.php @@ -0,0 +1,429 @@ + + * @package com.woltlab.wcf + * @subpackage acp.form + * @category Community Framework + */ +class UserBulkProcessingForm extends UserOptionListForm { + /** + * @see wcf\page\AbstractPage::$neededPermissions + */ + public $neededPermissions = array('admin.user.canEditUser', 'admin.user.canDeleteUser', 'admin.user.canMailUser'); + + /** + * searched username + * @var string + */ + public $username = ''; + + /** + * searched email adress + * @var string + */ + public $email = ''; + + /** + * ids of the searched user group ids + * @var array + */ + public $groupIDArray = array(); + + /** + * ids of the users' languages + * @var array + */ + public $languageIDArray = array(); + + /** + * indicates if the user may not be in the user groups with the selected + * ids + * @var integer + */ + public $invertGroupIDs = 0; + + // assign to group + public $assignToGroupIDArray = array(); + + // export mail address + public $fileType = 'csv'; + public $separator = ','; + public $textSeparator = '"'; + + // send mail + public $subject = ''; + public $text = ''; + public $from = ''; + public $enableHTML = 0; + + // data + public $availableGroups = array(); + public $options = array(); + public $availableActions = array('sendMail', 'exportMailAddress', 'assignToGroup', 'delete'); + public $affectedUsers = 0; + + /** + * conditions builder object + * @var wcf\system\database\condition\PreparedStatementConditionBuilder + */ + public $conditions = null; + + /** + * options of the active category + * @var array + */ + public $activeOptions = array(); + + /** + * @see wcf\form\IForm::readFormParameters() + */ + public function readFormParameters() { + parent::readFormParameters(); + + if (isset($_POST['username'])) $this->username = StringUtil::trim($_POST['username']); + if (isset($_POST['email'])) $this->email = StringUtil::trim($_POST['email']); + if (isset($_POST['groupIDArray']) && is_array($_POST['groupIDArray'])) $this->groupIDArray = ArrayUtil::toIntegerArray($_POST['groupIDArray']); + if (isset($_POST['languageIDArray']) && is_array($_POST['languageIDArray'])) $this->languageIDArray = ArrayUtil::toIntegerArray($_POST['languageIDArray']); + if (isset($_POST['invertGroupIDs'])) $this->invertGroupIDs = intval($_POST['invertGroupIDs']); + // assign to group + if (isset($_POST['assignToGroupIDArray']) && is_array($_POST['assignToGroupIDArray'])) $this->assignToGroupIDArray = ArrayUtil::toIntegerArray($_POST['assignToGroupIDArray']); + // export mail address + if (isset($_POST['fileType']) && $_POST['fileType'] == 'xml') $this->fileType = $_POST['fileType']; + if (isset($_POST['separator'])) $this->separator = $_POST['separator']; + if (isset($_POST['textSeparator'])) $this->textSeparator = $_POST['textSeparator']; + // send mail + if (isset($_POST['subject'])) $this->subject = StringUtil::trim($_POST['subject']); + if (isset($_POST['text'])) $this->text = StringUtil::trim($_POST['text']); + if (isset($_POST['from'])) $this->from = StringUtil::trim($_POST['from']); + if (isset($_POST['enableHTML'])) $this->enableHTML = intval($_POST['enableHTML']); + } + + /** + * @see wcf\form\IForm::validate() + */ + public function validate() { + AbstractForm::validate(); + + // action + if (!in_array($this->action, $this->availableActions)) { + throw new UserInputException('action'); + } + + // assign to group + if ($this->action == 'assignToGroup') { + if (empty($this->assignToGroupIDArray)) { + throw new UserInputException('assignToGroupIDArray'); + } + } + + // send mail + if ($this->action == 'sendMail') { + if (empty($this->subject)) { + throw new UserInputException('subject'); + } + + if (empty($this->text)) { + throw new UserInputException('text'); + } + + if (empty($this->from)) { + throw new UserInputException('from'); + } + } + } + + /** + * @see wcf\form\IForm::save() + */ + public function save() { + parent::save(); + + // build conditions + $this->conditions = new PreparedStatementConditionBuilder(); + + // static fields + if (!empty($this->username)) { + $this->conditions->add("user.username LIKE ?", array('%'.addcslashes($this->username, '_%').'%')); + } + if (!empty($this->email)) { + $this->conditions->add("user.email LIKE ?", array('%'.addcslashes($this->email, '_%').'%')); + } + if (!empty($this->groupIDArray)) { + $this->conditions->add("user.userID ".($this->invertGroupIDs == 1 ? 'NOT ' : '')."IN (SELECT userID FROM wcf".WCF_N."_user_to_group WHERE groupID IN (?))", array($this->groupIDArray)); + } + if (!empty($this->languageIDArray)) { + $this->conditions->add("user.languageID IN (?)", array($this->languageIDArray)); + } + + // dynamic fields + foreach ($this->activeOptions as $name => $option) { + $value = isset($this->values[$option['optionName']]) ? $this->values[$option['optionName']] : null; + $this->getTypeObject($option['optionType'])->getCondition($this->conditions, $option, $value); + } + + // call buildConditions event + EventHandler::getInstance()->fireAction($this, 'buildConditions'); + + // execute action + switch ($this->action) { + case 'sendMail': + WCF::getSession()->checkPermissions(array('admin.user.canMailUser')); + // get user ids + $userIDArray = array(); + $sql = "SELECT user.userID + FROM wcf".WCF_N."_user user + LEFT JOIN wcf".WCF_N."_user_option_value option_value + ON (option_value.userID = user.userID)". + $this->conditions; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute($this->conditions->getParameters()); + while ($row = $statement->fetchArray()) { + $userIDArray[] = $row['userID']; + $this->affectedUsers++; + } + + // save config in session + $userMailData = WCF::getSession()->getVar('userMailData'); + if ($userMailData === null) $userMailData = array(); + $mailID = count($userMailData); + $userMailData[$mailID] = array( + 'action' => '', + 'userIDs' => implode(',', $userIDArray), + 'groupIDs' => '', + 'subject' => $this->subject, + 'text' => $this->text, + 'from' => $this->from, + 'enableHTML' => $this->enableHTML + ); + WCF::getSession()->register('userMailData', $userMailData); + $this->saved(); + + $url = LinkHandler::getInstance()->getLink('UserMail', array('id' => $mailID)); + + // show worker template + WCF::getTPL()->assign(array( + 'pageTitle' => WCF::getLanguage()->get('wcf.acp.user.sendMail'), + 'url' => $url + )); + WCF::getTPL()->display('worker'); + exit; + break; + + case 'exportMailAddress': + WCF::getSession()->checkPermissions(array('admin.user.canMailUser')); + // send content type + header('Content-Type: text/'.$this->fileType.'; charset=UTF-8'); + header('Content-Disposition: attachment; filename="export.'.$this->fileType.'"'); + + if ($this->fileType == 'xml') { + echo "\n\n"; + } + + // count users + $sql = "SELECT COUNT(*) AS count + FROM wcf".WCF_N."_user user + LEFT JOIN wcf".WCF_N."_user_option_value option_value + ON (option_value.userID = user.userID) + ".$this->conditions; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute($this->conditions->getParameters()); + $count = $statement->fetchArray(); + + // get users + $sql = "SELECT user.email + FROM wcf".WCF_N."_user user + LEFT JOIN wcf".WCF_N."_user_option_value option_value + ON (option_value.userID = user.userID) + ".$this->conditions." + ORDER BY user.email"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute($this->conditions->getParameters()); + + $i = 0; + while ($row = $statement->fetchArray()) { + if ($this->fileType == 'xml') echo "
\n"; + else echo $this->textSeparator . $row['email'] . $this->textSeparator . ($i < $count['count'] ? $this->separator : ''); + $i++; + $this->affectedUsers++; + } + + if ($this->fileType == 'xml') { + echo "
"; + } + $this->saved(); + exit; + break; + + case 'assignToGroup': + WCF::getSession()->checkPermissions(array('admin.user.canEditUser')); + + $_this = $this; + $userIDArray = $this->fetchUsers(function($userID, array $userData) use ($_this) { + $user = new UserEditor(new User(null, $userData)); + $user->addToGroups($_this->assignToGroupIDArray, false, false); + }); + + UserStorageHandler::getInstance()->reset($userIDArray, 'groupIDs', 1); + break; + + case 'delete': + WCF::getSession()->checkPermissions(array('admin.user.canDeleteUser')); + + $userIDArray = $this->fetchUsers(); + + UserEditor::deleteUsers($userIDArray); + break; + } + $this->saved(); + + WCF::getTPL()->assign('affectedUsers', $this->affectedUsers); + } + + /** + * Fetches a list of users. + * + * @param mixed $loopFunction + * @return array + */ + protected function fetchUsers($loopFunction = null) { + // select users + $sql = "SELECT user.* + FROM wcf".WCF_N."_user user + LEFT JOIN wcf".WCF_N."_user_option_value option_value + ON (option_value.userID = user.userID) + ".$this->conditions; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute($this->conditions->getParameters()); + + $users = array(); + while ($row = $statement->fetchArray()) { + $users[$row['userID']] = $row; + } + + // select group ids + $conditions = new PreparedStatementConditionBuilder(); + $conditions->add("userID = ?", array(array_keys($users))); + + $sql = "SELECT userID, groupID + FROM wcf".WCF_N."_user_to_group + ".$conditions; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute($conditions->getParameters()); + + $groupIDs = array(); + while ($row = $statement->fetchArray()) { + if (!isset($groupIDs[$row['userID']])) { + $groupIDs[$row['userID']] = array(); + } + + $groupIDs[$row['userID']][] = $row['groupID']; + } + + foreach ($users as $userID => $userData) { + if (!UserGroup::isAccessibleGroup($groupIDs[$userID])) { + throw new PermissionDeniedException(); + } + + if ($loopFunction !== null) { + $loopFunction($userID, $userData); + } + + $userIDArray[] = $userID; + $this->affectedUsers++; + } + + return $userIDArray; + } + + /** + * @see wcf\page\IPage::readData() + */ + public function readData() { + parent::readData(); + + if (empty($_POST)) { + if (MAIL_USE_FORMATTED_ADDRESS) { + $this->from = MAIL_FROM_NAME.' <'.MAIL_FROM_ADDRESS.'>'; + } + else { + $this->from = MAIL_FROM_ADDRESS; + } + } + + $this->availableGroups = $this->getAvailableGroups(); + + foreach ($this->activeOptions as $name => $option) { + if (isset($this->values[$name])) { + $this->activeOptions[$name]['optionValue'] = $this->values[$name]; + } + } + + $this->options = $this->optionHandler->getCategoryOptions('profile'); + } + + /** + * @see wcf\page\IPage::assignVariables() + */ + public function assignVariables() { + parent::assignVariables(); + + WCF::getTPL()->assign(array( + 'username' => $this->username, + 'email' => $this->email, + 'groupIDArray' => $this->groupIDArray, + 'languageIDArray' => $this->languageIDArray, + 'invertGroupIDs' => $this->invertGroupIDs, + 'availableGroups' => $this->availableGroups, + 'availableLanguages' => LanguageFactory::getInstance()->getLanguages(), + 'options' => $this->options, + 'availableActions' => $this->availableActions, + // assign to group + 'assignToGroupIDArray' => $this->assignToGroupIDArray, + // export mail address + 'separator' => $this->separator, + 'textSeparator' => $this->textSeparator, + 'fileType' => $this->fileType, + // send mail + 'subject' => $this->subject, + 'text' => $this->text, + 'from' => $this->from, + 'enableHTML' => $this->enableHTML + )); + } + + /** + * @see wcf\form\IForm::show() + */ + public function show() { + // set active menu item + ACPMenu::getInstance()->setActiveMenuItem('wcf.acp.menu.link.user.bulkProcessing'); + + // check master password + WCFACP::checkMasterPassword(); + + // show form + parent::show(); + } +} diff --git a/wcfsetup/install/files/lib/acp/form/UsersMassProcessingForm.class.php b/wcfsetup/install/files/lib/acp/form/UsersMassProcessingForm.class.php deleted file mode 100644 index 2bdffc3d54..0000000000 --- a/wcfsetup/install/files/lib/acp/form/UsersMassProcessingForm.class.php +++ /dev/null @@ -1,429 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage acp.form - * @category Community Framework - */ -class UsersMassProcessingForm extends UserOptionListForm { - /** - * @see wcf\page\AbstractPage::$neededPermissions - */ - public $neededPermissions = array('admin.user.canEditUser', 'admin.user.canDeleteUser', 'admin.user.canMailUser'); - - /** - * searched username - * @var string - */ - public $username = ''; - - /** - * searched email adress - * @var string - */ - public $email = ''; - - /** - * ids of the searched user group ids - * @var array - */ - public $groupIDArray = array(); - - /** - * ids of the users' languages - * @var array - */ - public $languageIDArray = array(); - - /** - * indicates if the user may not be in the user groups with the selected - * ids - * @var integer - */ - public $invertGroupIDs = 0; - - // assign to group - public $assignToGroupIDArray = array(); - - // export mail address - public $fileType = 'csv'; - public $separator = ','; - public $textSeparator = '"'; - - // send mail - public $subject = ''; - public $text = ''; - public $from = ''; - public $enableHTML = 0; - - // data - public $availableGroups = array(); - public $options = array(); - public $availableActions = array('sendMail', 'exportMailAddress', 'assignToGroup', 'delete'); - public $affectedUsers = 0; - - /** - * conditions builder object - * @var wcf\system\database\condition\PreparedStatementConditionBuilder - */ - public $conditions = null; - - /** - * options of the active category - * @var array - */ - public $activeOptions = array(); - - /** - * @see wcf\form\IForm::readFormParameters() - */ - public function readFormParameters() { - parent::readFormParameters(); - - if (isset($_POST['username'])) $this->username = StringUtil::trim($_POST['username']); - if (isset($_POST['email'])) $this->email = StringUtil::trim($_POST['email']); - if (isset($_POST['groupIDArray']) && is_array($_POST['groupIDArray'])) $this->groupIDArray = ArrayUtil::toIntegerArray($_POST['groupIDArray']); - if (isset($_POST['languageIDArray']) && is_array($_POST['languageIDArray'])) $this->languageIDArray = ArrayUtil::toIntegerArray($_POST['languageIDArray']); - if (isset($_POST['invertGroupIDs'])) $this->invertGroupIDs = intval($_POST['invertGroupIDs']); - // assign to group - if (isset($_POST['assignToGroupIDArray']) && is_array($_POST['assignToGroupIDArray'])) $this->assignToGroupIDArray = ArrayUtil::toIntegerArray($_POST['assignToGroupIDArray']); - // export mail address - if (isset($_POST['fileType']) && $_POST['fileType'] == 'xml') $this->fileType = $_POST['fileType']; - if (isset($_POST['separator'])) $this->separator = $_POST['separator']; - if (isset($_POST['textSeparator'])) $this->textSeparator = $_POST['textSeparator']; - // send mail - if (isset($_POST['subject'])) $this->subject = StringUtil::trim($_POST['subject']); - if (isset($_POST['text'])) $this->text = StringUtil::trim($_POST['text']); - if (isset($_POST['from'])) $this->from = StringUtil::trim($_POST['from']); - if (isset($_POST['enableHTML'])) $this->enableHTML = intval($_POST['enableHTML']); - } - - /** - * @see wcf\form\IForm::validate() - */ - public function validate() { - AbstractForm::validate(); - - // action - if (!in_array($this->action, $this->availableActions)) { - throw new UserInputException('action'); - } - - // assign to group - if ($this->action == 'assignToGroup') { - if (empty($this->assignToGroupIDArray)) { - throw new UserInputException('assignToGroupIDArray'); - } - } - - // send mail - if ($this->action == 'sendMail') { - if (empty($this->subject)) { - throw new UserInputException('subject'); - } - - if (empty($this->text)) { - throw new UserInputException('text'); - } - - if (empty($this->from)) { - throw new UserInputException('from'); - } - } - } - - /** - * @see wcf\form\IForm::save() - */ - public function save() { - parent::save(); - - // build conditions - $this->conditions = new PreparedStatementConditionBuilder(); - - // static fields - if (!empty($this->username)) { - $this->conditions->add("user.username LIKE ?", array('%'.addcslashes($this->username, '_%').'%')); - } - if (!empty($this->email)) { - $this->conditions->add("user.email LIKE ?", array('%'.addcslashes($this->email, '_%').'%')); - } - if (!empty($this->groupIDArray)) { - $this->conditions->add("user.userID ".($this->invertGroupIDs == 1 ? 'NOT ' : '')."IN (SELECT userID FROM wcf".WCF_N."_user_to_group WHERE groupID IN (?))", array($this->groupIDArray)); - } - if (!empty($this->languageIDArray)) { - $this->conditions->add("user.languageID IN (?)", array($this->languageIDArray)); - } - - // dynamic fields - foreach ($this->activeOptions as $name => $option) { - $value = isset($this->values[$option['optionName']]) ? $this->values[$option['optionName']] : null; - $this->getTypeObject($option['optionType'])->getCondition($this->conditions, $option, $value); - } - - // call buildConditions event - EventHandler::getInstance()->fireAction($this, 'buildConditions'); - - // execute action - switch ($this->action) { - case 'sendMail': - WCF::getSession()->checkPermissions(array('admin.user.canMailUser')); - // get user ids - $userIDArray = array(); - $sql = "SELECT user.userID - FROM wcf".WCF_N."_user user - LEFT JOIN wcf".WCF_N."_user_option_value option_value - ON (option_value.userID = user.userID)". - $this->conditions; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute($this->conditions->getParameters()); - while ($row = $statement->fetchArray()) { - $userIDArray[] = $row['userID']; - $this->affectedUsers++; - } - - // save config in session - $userMailData = WCF::getSession()->getVar('userMailData'); - if ($userMailData === null) $userMailData = array(); - $mailID = count($userMailData); - $userMailData[$mailID] = array( - 'action' => '', - 'userIDs' => implode(',', $userIDArray), - 'groupIDs' => '', - 'subject' => $this->subject, - 'text' => $this->text, - 'from' => $this->from, - 'enableHTML' => $this->enableHTML - ); - WCF::getSession()->register('userMailData', $userMailData); - $this->saved(); - - $url = LinkHandler::getInstance()->getLink('UserMail', array('id' => $mailID)); - - // show worker template - WCF::getTPL()->assign(array( - 'pageTitle' => WCF::getLanguage()->get('wcf.acp.user.sendMail'), - 'url' => $url - )); - WCF::getTPL()->display('worker'); - exit; - break; - - case 'exportMailAddress': - WCF::getSession()->checkPermissions(array('admin.user.canMailUser')); - // send content type - header('Content-Type: text/'.$this->fileType.'; charset=UTF-8'); - header('Content-Disposition: attachment; filename="export.'.$this->fileType.'"'); - - if ($this->fileType == 'xml') { - echo "\n\n"; - } - - // count users - $sql = "SELECT COUNT(*) AS count - FROM wcf".WCF_N."_user user - LEFT JOIN wcf".WCF_N."_user_option_value option_value - ON (option_value.userID = user.userID) - ".$this->conditions; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute($this->conditions->getParameters()); - $count = $statement->fetchArray(); - - // get users - $sql = "SELECT user.email - FROM wcf".WCF_N."_user user - LEFT JOIN wcf".WCF_N."_user_option_value option_value - ON (option_value.userID = user.userID) - ".$this->conditions." - ORDER BY user.email"; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute($this->conditions->getParameters()); - - $i = 0; - while ($row = $statement->fetchArray()) { - if ($this->fileType == 'xml') echo "
\n"; - else echo $this->textSeparator . $row['email'] . $this->textSeparator . ($i < $count['count'] ? $this->separator : ''); - $i++; - $this->affectedUsers++; - } - - if ($this->fileType == 'xml') { - echo "
"; - } - $this->saved(); - exit; - break; - - case 'assignToGroup': - WCF::getSession()->checkPermissions(array('admin.user.canEditUser')); - - $_this = $this; - $userIDArray = $this->fetchUsers(function($userID, array $userData) use ($_this) { - $user = new UserEditor(new User(null, $userData)); - $user->addToGroups($_this->assignToGroupIDArray, false, false); - }); - - UserStorageHandler::getInstance()->reset($userIDArray, 'groupIDs', 1); - break; - - case 'delete': - WCF::getSession()->checkPermissions(array('admin.user.canDeleteUser')); - - $userIDArray = $this->fetchUsers(); - - UserEditor::deleteUsers($userIDArray); - break; - } - $this->saved(); - - WCF::getTPL()->assign('affectedUsers', $this->affectedUsers); - } - - /** - * Fetches a list of users. - * - * @param mixed $loopFunction - * @return array - */ - protected function fetchUsers($loopFunction = null) { - // select users - $sql = "SELECT user.* - FROM wcf".WCF_N."_user user - LEFT JOIN wcf".WCF_N."_user_option_value option_value - ON (option_value.userID = user.userID) - ".$this->conditions; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute($this->conditions->getParameters()); - - $users = array(); - while ($row = $statement->fetchArray()) { - $users[$row['userID']] = $row; - } - - // select group ids - $conditions = new PreparedStatementConditionBuilder(); - $conditions->add("userID = ?", array(array_keys($users))); - - $sql = "SELECT userID, groupID - FROM wcf".WCF_N."_user_to_group - ".$conditions; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute($conditions->getParameters()); - - $groupIDs = array(); - while ($row = $statement->fetchArray()) { - if (!isset($groupIDs[$row['userID']])) { - $groupIDs[$row['userID']] = array(); - } - - $groupIDs[$row['userID']][] = $row['groupID']; - } - - foreach ($users as $userID => $userData) { - if (!UserGroup::isAccessibleGroup($groupIDs[$userID])) { - throw new PermissionDeniedException(); - } - - if ($loopFunction !== null) { - $loopFunction($userID, $userData); - } - - $userIDArray[] = $userID; - $this->affectedUsers++; - } - - return $userIDArray; - } - - /** - * @see wcf\page\IPage::readData() - */ - public function readData() { - parent::readData(); - - if (empty($_POST)) { - if (MAIL_USE_FORMATTED_ADDRESS) { - $this->from = MAIL_FROM_NAME.' <'.MAIL_FROM_ADDRESS.'>'; - } - else { - $this->from = MAIL_FROM_ADDRESS; - } - } - - $this->availableGroups = $this->getAvailableGroups(); - - foreach ($this->activeOptions as $name => $option) { - if (isset($this->values[$name])) { - $this->activeOptions[$name]['optionValue'] = $this->values[$name]; - } - } - - $this->options = $this->optionHandler->getCategoryOptions('profile'); - } - - /** - * @see wcf\page\IPage::assignVariables() - */ - public function assignVariables() { - parent::assignVariables(); - - WCF::getTPL()->assign(array( - 'username' => $this->username, - 'email' => $this->email, - 'groupIDArray' => $this->groupIDArray, - 'languageIDArray' => $this->languageIDArray, - 'invertGroupIDs' => $this->invertGroupIDs, - 'availableGroups' => $this->availableGroups, - 'availableLanguages' => LanguageFactory::getInstance()->getLanguages(), - 'options' => $this->options, - 'availableActions' => $this->availableActions, - // assign to group - 'assignToGroupIDArray' => $this->assignToGroupIDArray, - // export mail address - 'separator' => $this->separator, - 'textSeparator' => $this->textSeparator, - 'fileType' => $this->fileType, - // send mail - 'subject' => $this->subject, - 'text' => $this->text, - 'from' => $this->from, - 'enableHTML' => $this->enableHTML - )); - } - - /** - * @see wcf\form\IForm::show() - */ - public function show() { - // set active menu item - ACPMenu::getInstance()->setActiveMenuItem('wcf.acp.menu.link.user.massProcessing'); - - // check master password - WCFACP::checkMasterPassword(); - - // show form - parent::show(); - } -} diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index f691b0725a..f5935f2f82 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -264,7 +264,7 @@ - + @@ -708,11 +708,11 @@ - - - - - ohne zusätzliche Sicherheitsabfrage auf alle Benutzer aus, die unter die eingestellten Bedingungen fallen. Die Bearbeitungen können unter Umständen sehr rechenintensiv werden und sollten deshalb möglichst nur dann ausgeführt werden, wenn sich die Seite im Wartungsmodus befindet! Die Veränderungen können nicht rückgängig gemacht werden. Bitte benutzen Sie diese Funktion mit der nötigen Vorsicht!]]> + + + + + ohne zusätzliche Sicherheitsabfrage auf alle Benutzer aus, die unter die eingestellten Bedingungen fallen. Die Bearbeitungen können unter Umständen sehr rechenintensiv werden und sollten deshalb möglichst nur dann ausgeführt werden, wenn sich die Seite im Wartungsmodus befindet! Die Veränderungen können nicht rückgängig gemacht werden. Bitte benutzen Sie diese Funktion mit der nötigen Vorsicht!]]> diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 0e2729538c..535f2532e8 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -264,7 +264,7 @@ - + @@ -708,11 +708,11 @@ - - - - - + + + + +