コード例 #1
0
 /**
  * @see Action::execute()
  */
 public function execute()
 {
     parent::execute();
     WCF::getUser()->checkPermission('admin.user.canDeleteUser');
     require_once WCF_DIR . 'lib/data/user/UserEditor.class.php';
     require_once WCF_DIR . 'lib/data/user/group/Group.class.php';
     if ($this->userID !== 0) {
         $this->userIDs[] = $this->userID;
     }
     // active user can't delete himself
     $activeUserID = WCF::getSession()->getUser()->userID;
     $this->userIDs = array_diff($this->userIDs, array($activeUserID));
     // check permission
     if (count($this->userIDs) > 0) {
         $sql = "SELECT\tDISTINCT groupID\n\t\t\t\tFROM\twcf" . WCF_N . "_user_to_groups\n\t\t\t\tWHERE\tuserID IN (" . implode(',', $this->userIDs) . ")";
         $result = WCF::getDB()->sendQuery($sql);
         while ($row = WCF::getDB()->fetchArray($result)) {
             if (!Group::isAccessibleGroup($row['groupID'])) {
                 throw new PermissionDeniedException();
             }
         }
     }
     $deletedUsers = UserEditor::deleteUsers($this->userIDs);
     $this->executed();
     if (!empty($this->url) && (strpos($this->url, 'searchID=0') !== false || strpos($this->url, 'searchID=') === false)) {
         HeaderUtil::redirect($this->url);
     } else {
         HeaderUtil::redirect('index.php?form=UserSearch&deletedUsers=' . $deletedUsers . '&packageID=' . PACKAGE_ID . SID_ARG_2ND_NOT_ENCODED);
     }
     exit;
 }
コード例 #2
0
 /**
  * @see Cronjob::execute()
  */
 public function execute($data)
 {
     // get user ids
     $sql = "SELECT\tuserID\n\t\t\tFROM\twcf" . WCF_N . "_user\n\t\t\tWHERE\tquitStarted > 0\n\t\t\t\tAND quitStarted < " . (TIME_NOW - 7 * 24 * 3600);
     $result = WCF::getDB()->sendQuery($sql);
     $userIDs = array();
     while ($row = WCF::getDB()->fetchArray($result)) {
         $userIDs[] = $row['userID'];
     }
     // delete users
     UserEditor::deleteUsers($userIDs);
 }
コード例 #3
0
ファイル: WCFTest.php プロジェクト: CaribeSoy/contest-wcf
 /**
  * Tears down the fixture, for example, closes a network connection.
  * This method is called after a test is executed.
  */
 protected function tearDown()
 {
     foreach ($this->deleteArray as $delete) {
         if (class_exists('UserEditor') && $delete instanceof User) {
             UserEditor::deleteUsers(array($delete->userID));
         } else {
             if (class_exists('GroupEditor') && $delete instanceof Group) {
                 GroupEditor::deleteGroups(array($delete->groupID));
             } else {
                 $delete->delete();
             }
         }
     }
     chdir($this->returndir);
 }
コード例 #4
0
 /**
  * @see Form::save()
  */
 public function save()
 {
     parent::save();
     // merge
     $userIDs = $this->userIDs;
     $key = array_search($this->userID, $userIDs);
     unset($userIDs[$key]);
     $userIDsString = implode(',', $userIDs);
     // board
     $sql = "UPDATE IGNORE\twbb" . WBB_N . "_board_closed_category_to_user\n\t\t\tSET\t\tuserID = " . $this->userID . "\n\t\t\tWHERE\t\tuserID IN (" . $userIDsString . ")";
     WCF::getDB()->sendQuery($sql);
     $sql = "UPDATE IGNORE\twbb" . WBB_N . "_board_closed_category_to_admin\n\t\t\tSET\t\tuserID = " . $this->userID . "\n\t\t\tWHERE\t\tuserID IN (" . $userIDsString . ")";
     WCF::getDB()->sendQuery($sql);
     $sql = "UPDATE\twbb" . WBB_N . "_board_moderator\n\t\t\tSET\tuserID = " . $this->userID . "\n\t\t\tWHERE\tuserID IN (" . $userIDsString . ")";
     WCF::getDB()->sendQuery($sql);
     $sql = "UPDATE IGNORE\twbb" . WBB_N . "_board_subscription\n\t\t\tSET\t\tuserID = " . $this->userID . "\n\t\t\tWHERE\t\tuserID IN (" . $userIDsString . ")";
     WCF::getDB()->sendQuery($sql);
     $sql = "UPDATE IGNORE\twbb" . WBB_N . "_board_to_user\n\t\t\tSET\t\tuserID = " . $this->userID . "\n\t\t\tWHERE\t\tuserID IN (" . $userIDsString . ")";
     WCF::getDB()->sendQuery($sql);
     $sql = "UPDATE IGNORE\twbb" . WBB_N . "_board_visit\n\t\t\tSET\t\tuserID = " . $this->userID . "\n\t\t\tWHERE\t\tuserID IN (" . $userIDsString . ")";
     WCF::getDB()->sendQuery($sql);
     // posts
     $sql = "UPDATE\twbb" . WBB_N . "_post\n\t\t\tSET\tuserID = " . $this->userID . "\n\t\t\tWHERE\tuserID IN (" . $userIDsString . ")";
     WCF::getDB()->sendQuery($sql);
     $sql = "UPDATE\twbb" . WBB_N . "_post_report\n\t\t\tSET\tuserID = " . $this->userID . "\n\t\t\tWHERE\tuserID IN (" . $userIDsString . ")";
     WCF::getDB()->sendQuery($sql);
     // thread
     $sql = "UPDATE\twbb" . WBB_N . "_thread\n\t\t\tSET\tuserID = " . $this->userID . "\n\t\t\tWHERE\tuserID IN (" . $userIDsString . ")";
     WCF::getDB()->sendQuery($sql);
     $sql = "UPDATE IGNORE\twbb" . WBB_N . "_thread_rating\n\t\t\tSET\t\tuserID = " . $this->userID . "\n\t\t\tWHERE\t\tuserID IN (" . $userIDsString . ")";
     WCF::getDB()->sendQuery($sql);
     $sql = "UPDATE IGNORE\twbb" . WBB_N . "_thread_subscription\n\t\t\tSET\t\tuserID = " . $this->userID . "\n\t\t\tWHERE\t\tuserID IN (" . $userIDsString . ")";
     WCF::getDB()->sendQuery($sql);
     $sql = "UPDATE IGNORE\twbb" . WBB_N . "_thread_visit\n\t\t\tSET\t\tuserID = " . $this->userID . "\n\t\t\tWHERE\t\tuserID IN (" . $userIDsString . ")";
     WCF::getDB()->sendQuery($sql);
     // attachment
     $sql = "UPDATE\twcf" . WCF_N . "_attachment\n\t\t\tSET\tuserID = " . $this->userID . "\n\t\t\tWHERE\tuserID IN (" . $userIDsString . ")";
     WCF::getDB()->sendQuery($sql);
     // groups
     $sql = "UPDATE IGNORE\twcf" . WCF_N . "_group_application\n\t\t\tSET\t\tuserID = " . $this->userID . "\n\t\t\tWHERE\t\tuserID IN (" . $userIDsString . ")";
     WCF::getDB()->sendQuery($sql);
     $sql = "UPDATE IGNORE\twcf" . WCF_N . "_group_leader\n\t\t\tSET\t\tleaderUserID = " . $this->userID . "\n\t\t\tWHERE\t\tleaderUserID IN (" . $userIDsString . ")";
     WCF::getDB()->sendQuery($sql);
     $sql = "UPDATE IGNORE\twcf" . WCF_N . "_user_to_groups\n\t\t\tSET\t\tuserID = " . $this->userID . "\n\t\t\tWHERE\t\tuserID IN (" . $userIDsString . ")";
     WCF::getDB()->sendQuery($sql);
     // pm
     $sql = "UPDATE\twcf" . WCF_N . "_pm\n\t\t\tSET\tuserID = " . $this->userID . "\n\t\t\tWHERE\tuserID IN (" . $userIDsString . ")";
     WCF::getDB()->sendQuery($sql);
     $sql = "UPDATE\twcf" . WCF_N . "_pm_folder\n\t\t\tSET\tuserID = " . $this->userID . "\n\t\t\tWHERE\tuserID IN (" . $userIDsString . ")";
     WCF::getDB()->sendQuery($sql);
     $sql = "UPDATE IGNORE\twcf" . WCF_N . "_pm_to_user\n\t\t\tSET\t\trecipientID = " . $this->userID . "\n\t\t\tWHERE\t\trecipientID IN (" . $userIDsString . ")";
     WCF::getDB()->sendQuery($sql);
     // poll
     $sql = "UPDATE IGNORE\twcf" . WCF_N . "_poll_option_vote\n\t\t\tSET\t\tuserID = " . $this->userID . "\n\t\t\tWHERE\t\tuserID IN (" . $userIDsString . ")";
     WCF::getDB()->sendQuery($sql);
     $sql = "UPDATE IGNORE\twcf" . WCF_N . "_poll_vote\n\t\t\tSET\t\tuserID = " . $this->userID . "\n\t\t\tWHERE\t\tuserID IN (" . $userIDsString . ")";
     WCF::getDB()->sendQuery($sql);
     // blacklist / whitelist
     $sql = "UPDATE IGNORE\twcf" . WCF_N . "_user_blacklist\n\t\t\tSET\t\tuserID = " . $this->userID . "\n\t\t\tWHERE\t\tuserID IN (" . $userIDsString . ")";
     WCF::getDB()->sendQuery($sql);
     $sql = "UPDATE IGNORE\twcf" . WCF_N . "_user_blacklist\n\t\t\tSET\t\tblackUserID = " . $this->userID . "\n\t\t\tWHERE\t\tblackUserID IN (" . $userIDsString . ")";
     WCF::getDB()->sendQuery($sql);
     $sql = "UPDATE IGNORE\twcf" . WCF_N . "_user_whitelist\n\t\t\tSET\t\tuserID = " . $this->userID . "\n\t\t\tWHERE\t\tuserID IN (" . $userIDsString . ")";
     WCF::getDB()->sendQuery($sql);
     $sql = "UPDATE IGNORE\twcf" . WCF_N . "_user_whitelist\n\t\t\tSET\t\twhiteUserID = " . $this->userID . "\n\t\t\tWHERE\t\twhiteUserID IN (" . $userIDsString . ")";
     WCF::getDB()->sendQuery($sql);
     // languages
     $sql = "UPDATE IGNORE\twcf" . WCF_N . "_user_to_languages\n\t\t\tSET\t\tuserID = " . $this->userID . "\n\t\t\tWHERE\t\tuserID IN (" . $userIDsString . ")";
     WCF::getDB()->sendQuery($sql);
     // delete users
     UserEditor::deleteUsers($userIDs);
     // unmark users
     UserEditor::unmarkAll();
     $this->saved();
     // show succes message
     WCF::getTPL()->assign('message', 'wbb.acp.user.merge.success');
     WCF::getTPL()->display('success');
     exit;
 }
コード例 #5
0
 /**
  * Deletes users
  *
  * @param array $generalOptions
  */
 protected function deleteUsers($generalOptions)
 {
     $deleteOptions = $this->data['parameters']['user.inactiveUsers.inactive'];
     $sql = "SELECT user.* FROM wcf" . WCF_N . "_user user\n\t\t\t\tLEFT JOIN wcf" . WCF_N . "_user_option_value user_option ON (user_option.userID = user.userID)\t\t\t\t\n\t\t\t\tWHERE user.lastActivityTime < " . (TIME_NOW - $deleteOptions['time'] * 86400) . "\t\t\t\t\n\t\t\t\tAND " . $this->ignoreCondition->get() . "\n\t\t\t\tGROUP BY user.userID";
     $result = WCF::getDB()->sendQuery($sql);
     $userIDs = array();
     while ($row = WCF::getDB()->fetchArray($result)) {
         $this->deletedInactiveUsers[] = new User(null, $row);
         $userIDs[] = $row['userID'];
     }
     UserEditor::deleteUsers($userIDs);
 }
コード例 #6
0
 /**
  * @see Form::save()
  */
 public function save()
 {
     parent::save();
     // build conditions
     $this->conditions = new ConditionBuilder();
     // static fields
     if (!empty($this->username)) {
         $this->conditions->add("user.username LIKE '%" . addcslashes(escapeString($this->username), '_%') . "%'");
     }
     if (!empty($this->email)) {
         $this->conditions->add("user.email LIKE '%" . addcslashes(escapeString($this->email), '_%') . "%'");
     }
     if (count($this->groupIDArray) > 0) {
         $this->conditions->add("user.userID " . ($this->invertGroupIDs == 1 ? 'NOT ' : '') . "IN (SELECT userID FROM wcf" . WCF_N . "_user_to_groups WHERE groupID IN (" . implode(',', $this->groupIDArray) . "))");
     }
     if (count($this->languageIDArray) > 0) {
         $this->conditions->add("user.languageID IN (" . implode(',', $this->languageIDArray) . ")");
     }
     // dynamic fields
     foreach ($this->activeOptions as $name => $option) {
         $value = isset($this->values[$option['optionName']]) ? $this->values[$option['optionName']] : null;
         $condition = $this->getTypeObject($option['optionType'])->getCondition($option, $value, isset($this->matchExactly[$name]));
         if ($condition !== false) {
             $this->conditions->add($condition);
         }
     }
     // call buildConditions event
     EventHandler::fireAction($this, 'buildConditions');
     // execute action
     switch ($this->action) {
         case 'sendMail':
             WCF::getUser()->checkPermission('admin.user.canMailUser');
             // get user ids
             $userIDArray = array();
             $sql = "SELECT\t\tuser.userID\n\t\t\t\t\tFROM\t\twcf" . WCF_N . "_user user\n\t\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_option_value option_value USING (userID)\n\t\t\t\t\t" . $this->conditions->get();
             $result = WCF::getDB()->sendQuery($sql);
             while ($row = WCF::getDB()->fetchArray($result)) {
                 $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();
             // show worker template
             WCF::getTPL()->assign(array('pageTitle' => WCF::getLanguage()->get('wcf.acp.user.sendMail'), 'url' => 'index.php?action=UserMail&mailID=' . $mailID . '&packageID=' . PACKAGE_ID . SID_ARG_2ND_NOT_ENCODED));
             WCF::getTPL()->display('worker');
             exit;
             break;
         case 'exportMailAddress':
             WCF::getUser()->checkPermission('admin.user.canMailUser');
             // send content type
             header('Content-Type: text/' . $this->fileType . '; charset=' . CHARSET);
             header('Content-Disposition: attachment; filename="export.' . $this->fileType . '"');
             if ($this->fileType == 'xml') {
                 echo "<?xml version=\"1.0\" encoding=\"" . CHARSET . "\"?>\n<addresses>\n";
             }
             // get users
             $sql = "SELECT\t\tuser.email\n\t\t\t\t\tFROM\t\twcf" . WCF_N . "_user user\n\t\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_option_value option_value USING (userID)\n\t\t\t\t\t" . $this->conditions->get() . "\n\t\t\t\t\tORDER BY\tuser.email";
             $result = WCF::getDB()->sendQuery($sql);
             $i = 0;
             $j = WCF::getDB()->countRows($result) - 1;
             while ($row = WCF::getDB()->fetchArray($result)) {
                 if ($this->fileType == 'xml') {
                     echo "<address><![CDATA[" . StringUtil::escapeCDATA($row['email']) . "]]></address>\n";
                 } else {
                     echo $this->textSeparator . $row['email'] . $this->textSeparator . ($i < $j ? $this->separator : '');
                 }
                 $i++;
                 $this->affectedUsers++;
             }
             if ($this->fileType == 'xml') {
                 echo "</addresses>";
             }
             $this->saved();
             exit;
             break;
         case 'assignToGroup':
             WCF::getUser()->checkPermission('admin.user.canEditUser');
             $userIDArray = array();
             $sql = "SELECT\t\tuser.*,\n\t\t\t\t\t\t\tGROUP_CONCAT(groupID SEPARATOR ',') AS groupIDs\n\t\t\t\t\tFROM\t\twcf" . WCF_N . "_user user\n\t\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_option_value option_value USING (userID)\n\t\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_to_groups groups\n\t\t\t\t\tON\t\t(groups.userID = user.userID)\n\t\t\t\t\t" . $this->conditions->get() . "\t\t\n\t\t\t\t\tGROUP BY\tuser.userID";
             $result = WCF::getDB()->sendQuery($sql);
             while ($row = WCF::getDB()->fetchArray($result)) {
                 if (!Group::isAccessibleGroup(explode(',', $row['groupIDs']))) {
                     throw new PermissionDeniedException();
                 }
                 $user = new UserEditor(null, $row);
                 $user->addToGroups($this->assignToGroupIDArray, false, false);
                 $userIDArray[] = $row['userID'];
                 $this->affectedUsers++;
             }
             Session::resetSessions($userIDArray);
             break;
         case 'delete':
             WCF::getUser()->checkPermission('admin.user.canDeleteUser');
             $userIDArray = array();
             $sql = "SELECT\t\tuser.*,\n\t\t\t\t\t\t\tGROUP_CONCAT(groupID SEPARATOR ',') AS groupIDs\n\t\t\t\t\tFROM\t\twcf" . WCF_N . "_user user\n\t\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_option_value option_value USING (userID)\n\t\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_to_groups groups\n\t\t\t\t\tON\t\t(groups.userID = user.userID)\n\t\t\t\t\t" . $this->conditions->get() . "\t\t\n\t\t\t\t\tGROUP BY\tuser.userID";
             $result = WCF::getDB()->sendQuery($sql);
             while ($row = WCF::getDB()->fetchArray($result)) {
                 if (!Group::isAccessibleGroup(explode(',', $row['groupIDs']))) {
                     throw new PermissionDeniedException();
                 }
                 $userIDArray[] = $row['userID'];
                 $this->affectedUsers++;
             }
             UserEditor::deleteUsers($userIDArray);
             break;
     }
     $this->saved();
     WCF::getTPL()->assign('affectedUsers', $this->affectedUsers);
 }
コード例 #7
0
 /**
  * Deletes marked users.
  */
 public function deleteMarked()
 {
     WCF::getUser()->checkPermission('admin.user.canDeleteUser');
     $userIDs = WCF::getSession()->getVar('markedUsers');
     if (!is_array($userIDs)) {
         $userIDs = array();
     }
     $deletedUsers = 0;
     // active user can't delete himself
     $activeUserID = WCF::getSession()->getUser()->userID;
     $userIDs = array_diff($userIDs, array($activeUserID));
     // check permission
     if (count($userIDs) > 0) {
         $sql = "SELECT\tDISTINCT groupID\n\t\t\t\tFROM\twcf" . WCF_N . "_user_to_groups\n\t\t\t\tWHERE\tuserID IN (" . implode(',', $userIDs) . ")";
         $result = WCF::getDB()->sendQuery($sql);
         while ($row = WCF::getDB()->fetchArray($result)) {
             if (!Group::isAccessibleGroup($row['groupID'])) {
                 throw new PermissionDeniedException();
             }
         }
         $deletedUsers = UserEditor::deleteUsers($userIDs);
     }
     self::unmarkAll();
     HeaderUtil::redirect('index.php?form=UserSearch&deletedUsers=' . $deletedUsers . '&packageID=' . PACKAGE_ID . SID_ARG_2ND_NOT_ENCODED);
     exit;
 }
コード例 #8
0
 public function deleteInactiveUser($days, $exclUser = 0, $exclGrp = 0)
 {
     if ($days > 0) {
         $userIDs = array();
         $sql = "SELECT userID, username, registrationDate, lastActivityTime" . "\n  FROM wcf" . WCF_N . "_user" . "\n WHERE activationCode > 0" . "\n   AND lastActivityTime < " . (TIME_NOW - $days * 86400);
         if (!empty($exclUser)) {
             $sql .= "\n   AND userID NOT IN (" . $exclUser . ")";
         }
         if (!empty($exclGrp)) {
             $sql .= "\n   AND userID NOT IN (SELECT userID FROM wcf" . WCF_N . "_user_to_groups WHERE groupID IN (" . $exclGrp . "))";
         }
         $result = WCF::getDB()->sendQuery($sql);
         while ($row = WCF::getDB()->fetchArray($result)) {
             $userIDs[] = $row['userID'];
         }
         if (count($userIDs) > 0) {
             require_once WCF_DIR . 'lib/data/user/UserEditor.class.php';
             UserEditor::deleteUsers($userIDs);
         }
     }
 }