/**
	 * @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);
	}
Example #2
0
 /**
  * Creates a new user.
  * 
  * @return	User
  */
 public function create()
 {
     if (!isset($this->parameters['data']['socialNetworkPrivacySettings'])) {
         $this->parameters['data']['socialNetworkPrivacySettings'] = '';
     }
     $user = parent::create();
     $userEditor = new UserEditor($user);
     // updates user options
     if (isset($this->parameters['options'])) {
         $userEditor->updateUserOptions($this->parameters['options']);
     }
     // insert user groups
     $addDefaultGroups = isset($this->parameters['addDefaultGroups']) ? $this->parameters['addDefaultGroups'] : true;
     $groupIDs = isset($this->parameters['groups']) ? $this->parameters['groups'] : array();
     $userEditor->addToGroups($groupIDs, false, $addDefaultGroups);
     // insert visible languages
     if (!isset($this->parameters['languageIDs'])) {
         // using the 'languages' key is deprecated since WCF 2.1, please use 'languageIDs' instead
         $this->parameters['languageIDs'] = !empty($this->parameters['languages']) ? $this->parameters['languages'] : array();
     }
     $userEditor->addToLanguages($this->parameters['languageIDs'], false);
     if (PACKAGE_ID) {
         // set default notifications
         $sql = "INSERT INTO\twcf" . WCF_N . "_user_notification_event_to_user\n\t\t\t\t\t\t(userID, eventID, mailNotificationType)\n\t\t\t\tSELECT\t\t?, eventID, presetMailNotificationType\n\t\t\t\tFROM\t\twcf" . WCF_N . "_user_notification_event\n\t\t\t\tWHERE\t\tpreset = ?";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute(array($user->userID, 1));
         // update user rank
         if (MODULE_USER_RANK) {
             $action = new UserProfileAction(array($userEditor), 'updateUserRank');
             $action->executeAction();
         }
         // update user online marking
         $action = new UserProfileAction(array($userEditor), 'updateUserOnlineMarking');
         $action->executeAction();
     }
     return $user;
 }
Example #3
0
 /**
  * Creates a new user.
  * 
  * @return	User
  */
 public function create()
 {
     $user = parent::create();
     $userEditor = new UserEditor($user);
     // updates user options
     if (isset($this->parameters['options'])) {
         $userEditor->updateUserOptions($this->parameters['options']);
     }
     // insert user groups
     $addDefaultGroups = isset($this->parameters['addDefaultGroups']) ? $this->parameters['addDefaultGroups'] : true;
     $groupIDs = isset($this->parameters['groups']) ? $this->parameters['groups'] : array();
     $userEditor->addToGroups($groupIDs, false, $addDefaultGroups);
     // insert visible languages
     $languageIDs = isset($this->parameters['languages']) ? $this->parameters['languages'] : array();
     $userEditor->addToLanguages($languageIDs);
     return $user;
 }
 /**
  * @see	\wcf\form\IForm::save()
  */
 public function save()
 {
     parent::save();
     // build conditions
     $this->conditions = new PreparedStatementConditionBuilder();
     // deny self delete
     if ($this->action == 'delete') {
         $this->conditions->add("user_table.userID <> ?", array(WCF::getUser()->userID));
     }
     // static fields
     if (!empty($this->username)) {
         $this->conditions->add("user_table.username LIKE ?", array('%' . addcslashes($this->username, '_%') . '%'));
     }
     if (!empty($this->email)) {
         $this->conditions->add("user_table.email LIKE ?", array('%' . addcslashes($this->email, '_%') . '%'));
     }
     if (!empty($this->groupIDs)) {
         $this->conditions->add("user_table.userID " . ($this->invertGroupIDs == 1 ? 'NOT ' : '') . "IN (SELECT userID FROM wcf" . WCF_N . "_user_to_group WHERE groupID IN (?))", array($this->groupIDs));
     }
     if (!empty($this->languageIDs)) {
         $this->conditions->add("user_table.languageID IN (?)", array($this->languageIDs));
     }
     // registration date
     if ($startDate = @strtotime($this->registrationDateStart)) {
         $this->conditions->add('user_table.registrationDate >= ?', array($startDate));
     }
     if ($endDate = @strtotime($this->registrationDateEnd)) {
         $this->conditions->add('user_table.registrationDate <= ?', array($endDate));
     }
     if ($this->banned) {
         $this->conditions->add('user_table.banned = ?', array(1));
     }
     if ($this->notBanned) {
         $this->conditions->add('user_table.banned = ?', array(0));
     }
     // last activity time
     if ($startDate = @strtotime($this->lastActivityTimeStart)) {
         $this->conditions->add('user_table.lastActivityTime >= ?', array($startDate));
     }
     if ($endDate = @strtotime($this->lastActivityTimeEnd)) {
         $this->conditions->add('user_table.lastActivityTime <= ?', array($endDate));
     }
     if ($this->enabled) {
         $this->conditions->add('user_table.activationCode = ?', array(0));
     }
     if ($this->disabled) {
         $this->conditions->add('user_table.activationCode <> ?', array(0));
     }
     // 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
             $userIDs = array();
             $sql = "SELECT\t\tuser_table.userID\n\t\t\t\t\tFROM\t\twcf" . WCF_N . "_user user_table\n\t\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_option_value option_value\n\t\t\t\t\tON\t\t(option_value.userID = user_table.userID)" . $this->conditions;
             $statement = WCF::getDB()->prepareStatement($sql);
             $statement->execute($this->conditions->getParameters());
             while ($row = $statement->fetchArray()) {
                 $userIDs[] = $row['userID'];
                 $this->affectedUsers++;
             }
             if (!empty($userIDs)) {
                 // save config in session
                 $userMailData = WCF::getSession()->getVar('userMailData');
                 if ($userMailData === null) {
                     $userMailData = array();
                 }
                 $mailID = count($userMailData);
                 $userMailData[$mailID] = array('action' => '', 'userIDs' => $userIDs, 'groupIDs' => '', 'subject' => $this->subject, 'text' => $this->text, 'from' => $this->from, 'enableHTML' => $this->enableHTML);
                 WCF::getSession()->register('userMailData', $userMailData);
                 WCF::getTPL()->assign('mailID', $mailID);
             }
             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\t\tCOUNT(*) AS count\n\t\t\t\t\tFROM\t\twcf" . WCF_N . "_user user_table\n\t\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_option_value option_value\n\t\t\t\t\tON\t\t(option_value.userID = user_table.userID)\n\t\t\t\t\t" . $this->conditions;
             $statement = WCF::getDB()->prepareStatement($sql);
             $statement->execute($this->conditions->getParameters());
             $count = $statement->fetchArray();
             // get users
             $sql = "SELECT\t\tuser_table.email\n\t\t\t\t\tFROM\t\twcf" . WCF_N . "_user user_table\n\t\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_option_value option_value\n\t\t\t\t\tON\t\t(option_value.userID = user_table.userID)\n\t\t\t\t\t" . $this->conditions . "\n\t\t\t\t\tORDER BY\tuser_table.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'));
             $_this = $this;
             $userIDs = $this->fetchUsers(function ($userID, array $userData) use($_this) {
                 $user = new UserEditor(new User(null, $userData));
                 $user->addToGroups($_this->assignToGroupIDs, false, false);
             });
             if (!empty($userIDs)) {
                 UserStorageHandler::getInstance()->reset($userIDs, 'groupIDs', 1);
             }
             break;
         case 'delete':
             WCF::getSession()->checkPermissions(array('admin.user.canDeleteUser'));
             $userIDs = $this->fetchUsers();
             if (!empty($userIDs)) {
                 $userAction = new UserAction($userIDs, 'delete');
                 $userAction->executeAction();
             }
             break;
     }
     $this->saved();
     WCF::getTPL()->assign('affectedUsers', $this->affectedUsers);
 }
 /**
  * @see wcf\form\IForm::save()
  */
 public function save()
 {
     parent::save();
     $conditions = new PreparedStatementConditionBuilder();
     $conditions->add("userID IN (?)", array($this->userIDs));
     $sql = "SELECT\tuserID, groupID\n\t\t\tFROM\twcf" . WCF_N . "_user_to_group\n\t\t\t" . $conditions;
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute($conditions->getParameters());
     $groups = array();
     while ($row = $statement->fetchArray()) {
         $groups[$row['userID']][] = $row['groupID'];
     }
     foreach ($this->users as $user) {
         if (!UserGroup::isAccessibleGroup($groups[$user->userID])) {
             throw new PermissionDeniedException();
         }
         $groupsIDs = array_merge($groups[$user->userID], $this->groupIDs);
         $groupsIDs = array_unique($groupsIDs);
         $userEditor = new UserEditor($user);
         $userEditor->addToGroups($groupsIDs, true, false);
     }
     ClipboardHandler::getInstance()->removeItems($this->typeID);
     SessionHandler::resetSessions($this->userIDs);
     $this->saved();
     WCF::getTPL()->assign('message', 'wcf.acp.user.assignToGroup.success');
     WCF::getTPL()->display('success');
     exit;
 }