/** * @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 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 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<addresses>\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 "<address><![CDATA[".StringUtil::escapeCDATA($row['email'])."]]></address>\n"; else echo $this->textSeparator . $row['email'] . $this->textSeparator . ($i < $count['count'] ? $this->separator : ''); $i++; $this->affectedUsers++; } if ($this->fileType == 'xml') { echo "</addresses>"; } $this->saved(); exit; break; case 'assignToGroup': WCF::getSession()->checkPermissions(array('admin.user.canEditUser')); $userIDArray = $this->fetchUsers(function($userID, array $userData) { $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); }