/**
  * @see	wcf\system\option\IOptionHandler::readData()
  */
 public function readData()
 {
     $defaultGroup = UserGroup::getGroupByType(UserGroup::EVERYONE);
     foreach ($this->options as $option) {
         $this->optionValues[$option->optionName] = $defaultGroup->getGroupOption($option->optionName);
         // use group values over default values
         if ($this->group !== null) {
             $groupValue = $this->group->getGroupOption($option->optionName);
             if ($groupValue !== null) {
                 $this->optionValues[$option->optionName] = $groupValue;
             }
         }
     }
 }
 /**
  * @see	\wcf\system\option\OptionHandler::validateOption()
  */
 protected function validateOption(Option $option)
 {
     parent::validateOption($option);
     if (!$this->isAdmin()) {
         // get type object
         $typeObj = $this->getTypeObject($option->optionType);
         if ($typeObj->compare($this->optionValues[$option->optionName], WCF::getSession()->getPermission($option->optionName)) == 1) {
             throw new UserInputException($option->optionName, 'exceedsOwnPermission');
         }
     } else {
         if ($option->optionName == 'admin.user.accessibleGroups' && $this->group !== null && $this->group->isAdminGroup()) {
             $hasOtherAdminGroup = false;
             foreach (UserGroup::getGroupsByType() as $userGroup) {
                 if ($userGroup->groupID != $this->group->groupID && $userGroup->isAdminGroup()) {
                     $hasOtherAdminGroup = true;
                     break;
                 }
             }
             // prevent users from dropping their own admin state
             if (!$hasOtherAdminGroup) {
                 // get type object
                 $typeObj = $this->getTypeObject($option->optionType);
                 if ($typeObj->compare($this->optionValues[$option->optionName], WCF::getSession()->getPermission($option->optionName)) == -1) {
                     throw new UserInputException($option->optionName, 'cannotDropPrivileges');
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Assignes the acl values to the template.
  * 
  * @param	integer		$objectTypeID
  */
 public function assignVariables($objectTypeID)
 {
     if (WCF::getTPL()->get('aclValues') === null) {
         WCF::getTPL()->assign('aclValues', array());
     }
     if (!$this->assignVariablesDisabled && isset($_POST['aclValues'])) {
         $values = $_POST['aclValues'];
         $data = $this->getPermissions($objectTypeID, array(), null, true);
         foreach ($values as $type => $optionData) {
             if ($type === 'user') {
                 $users = User::getUsers(array_keys($optionData));
             }
             $values[$type] = array('label' => array(), 'option' => array());
             foreach ($optionData as $typeID => $optionValues) {
                 foreach ($optionValues as $optionID => $optionValue) {
                     if (!isset($data['options'][$optionID])) {
                         unset($optionValues[$optionID]);
                     }
                 }
                 if (empty($optionValues)) {
                     continue;
                 }
                 $values[$type]['option'][$typeID] = $optionValues;
                 if ($type === 'group') {
                     $values[$type]['label'][$typeID] = UserGroup::getGroupByID($typeID)->getName();
                 } else {
                     $values[$type]['label'][$typeID] = $users[$typeID]->username;
                 }
             }
         }
         $values['options'] = $data['options'];
         $values['categories'] = $data['categories'];
         WCF::getTPL()->append('aclValues', array($objectTypeID => $values));
     }
 }
Exemplo n.º 4
0
 /**
  * @see	\wcf\system\importer\IImporter::import()
  */
 public function import($oldID, array $data, array $additionalData = array())
 {
     $data['groupID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user.group', $data['groupID']);
     if (!$data['groupID']) {
         $data['groupID'] = UserGroup::getGroupByType(UserGroup::USERS)->groupID;
     }
     $rank = UserRankEditor::create($data);
     ImportHandler::getInstance()->saveNewID('com.woltlab.wcf.user.rank', $oldID, $rank->rankID);
     return $rank->rankID;
 }
Exemplo n.º 5
0
 /**
  * Returns a list of all available user groups.
  * 
  * @return	array
  */
 protected function getAvailableGroups()
 {
     $userGroups = UserGroup::getAccessibleGroups(array(), array(UserGroup::GUESTS, UserGroup::EVERYONE, UserGroup::USERS));
     // work-around for PHP 5.3.3 randomly failing in uasort()
     foreach ($userGroups as $userGroup) {
         $userGroup->getName();
     }
     uasort($userGroups, function (UserGroup $groupA, UserGroup $groupB) {
         return strcmp($groupA->getName(), $groupB->getName());
     });
     return $userGroups;
 }
Exemplo n.º 6
0
 /**
  * @see	\wcf\system\importer\IImporter::import()
  */
 public function import($oldID, array $data, array $additionalData = array())
 {
     if ($data['groupType'] < 4) {
         $newGroupID = UserGroup::getGroupByType($data['groupType'])->groupID;
     } else {
         $action = new UserGroupAction(array(), 'create', array('data' => $data));
         $returnValues = $action->executeAction();
         $newGroupID = $returnValues['returnValues']->groupID;
     }
     ImportHandler::getInstance()->saveNewID('com.woltlab.wcf.user.group', $oldID, $newGroupID);
     return $newGroupID;
 }
 /**
  * @see	\wcf\page\IPage::readData()
  */
 public function readData()
 {
     parent::readData();
     $this->userGroups = UserGroup::getGroupsByType(array(), array(UserGroup::EVERYONE, UserGroup::GUESTS, UserGroup::USERS));
     foreach ($this->userGroups as $key => $group) {
         if ($group->isAdminGroup()) {
             unset($this->userGroups[$key]);
         }
     }
     $sql = "SELECT\tCOUNT(*)\n\t\t\tFROM\twcf" . WCF_N . "_user";
     $statement = \wcf\system\WCF::getDB()->prepareStatement($sql);
     $statement->execute();
     $this->userCount = $statement->fetchColumn();
 }
 /**
  * @see	\wcf\page\IPage::readData()
  */
 public function readData()
 {
     $this->userGroups = UserGroup::getGroupsByType(array(), array(UserGroup::EVERYONE, UserGroup::GUESTS, UserGroup::USERS));
     foreach ($this->userGroups as $key => $userGroup) {
         if (!$userGroup->isAccessible()) {
             unset($this->userGroups[$key]);
         }
     }
     uasort($this->userGroups, function (UserGroup $groupA, UserGroup $groupB) {
         return strcmp($groupA->getName(), $groupB->getName());
     });
     $this->conditions = UserGroupAssignmentHandler::getInstance()->getGroupedObjectTypes('com.woltlab.wcf.condition.userGroupAssignment');
     parent::readData();
 }
Exemplo n.º 9
0
 /**
  * @see	\wcf\data\DatabaseObjectList::readObjects()
  */
 public function readObjects()
 {
     parent::readObjects();
     $sql = "SELECT\t\tuser_to_group.*\n\t\t\tFROM\t\twcf" . WCF_N . "_user_group user_group,\n\t\t\t\t\twcf" . WCF_N . "_user_to_group user_to_group\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_user user_table\n\t\t\tON\t\t(user_table.userID = user_to_group.userID)\n\t\t\tWHERE\t\tuser_to_group.groupID = user_group.groupID\n\t\t\t\t\tAND user_group.showOnTeamPage = 1\n\t\t\tORDER BY\tuser_group.priority DESC" . (!empty($this->sqlOrderBy) ? ", " . $this->sqlOrderBy : '');
     $statement = WCF::getDB()->prepareStatement($sql, $this->sqlLimit, $this->sqlOffset);
     $statement->execute();
     while ($row = $statement->fetchArray()) {
         if (!isset($this->teams[$row['groupID']])) {
             $userGroup = UserGroup::getGroupByID($row['groupID']);
             $this->teams[$row['groupID']] = new Team($userGroup);
         }
         $this->teams[$row['groupID']]->addMember($this->objects[$row['userID']]);
     }
 }
	/**
	 * @see	wcf\system\option\IOptionType::validate()
	 */
	public function validate(Option $option, $newValue) {
		// get all groups
		$groups = UserGroup::getGroupsByType();
		
		// get new value
		if (!is_array($newValue)) $newValue = array();
		$selectedGroups = ArrayUtil::toIntegerArray($newValue);
		
		// check groups
		foreach ($selectedGroups as $groupID) {
			if (!isset($groups[$groupID])) {
				throw new UserInputException($option->optionName, 'validationFailed');
			}
		}
	}
 /**
  * @see	\wcf\system\search\acp\IACPSearchResultProvider::search()
  */
 public function search($query)
 {
     if (!WCF::getSession()->getPermission('admin.user.canEditUser')) {
         return array();
     }
     $results = array();
     $sql = "SELECT\t*\n\t\t\tFROM\twcf" . WCF_N . "_user\n\t\t\tWHERE\tusername LIKE ?";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute(array($query . '%'));
     while ($user = $statement->fetchObject('wcf\\data\\user\\User')) {
         if (UserGroup::isAccessibleGroup($user->getGroupIDs())) {
             $results[] = new ACPSearchResult($user->username, LinkHandler::getInstance()->getLink('UserEdit', array('object' => $user)));
         }
     }
     return $results;
 }
Exemplo n.º 12
0
 /**
  * @see	\wcf\data\AbstractDatabaseObjectAction::create()
  */
 public function create()
 {
     $bbCode = parent::create();
     // add bbcode to BBCodeSelect user group options
     $sql = "SELECT\toptionID\n\t\t\tFROM\twcf" . WCF_N . "_user_group_option\n\t\t\tWHERE\toptionType = ?";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute(array('BBCodeSelect'));
     $optionIDs = array();
     while ($optionID = $statement->fetchColumn()) {
         $optionIDs[] = $optionID;
     }
     if (!empty($optionIDs)) {
         $conditionBuilder = new PreparedStatementConditionBuilder();
         $conditionBuilder->add("optionID IN (?)", array($optionIDs));
         $conditionBuilder->add("groupID IN (?)", array(UserGroup::getGroupIDsByType(array(UserGroup::EVERYONE))));
         $conditionBuilder->add("optionValue <> ?", array('all'));
         $sql = "SELECT\t*\n\t\t\t\tFROM\twcf" . WCF_N . "_user_group_option_value\n\t\t\t\t" . $conditionBuilder;
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute($conditionBuilder->getParameters());
         $sql = "UPDATE\twcf" . WCF_N . "_user_group_option_value\n\t\t\t\tSET\toptionValue = ?\n\t\t\t\tWHERE\toptionID = ?\n\t\t\t\t\tAND groupID = ?";
         $updateStatement = WCF::getDB()->prepareStatement($sql);
         WCF::getDB()->beginTransaction();
         while ($row = $statement->fetchArray()) {
             if (!empty($row['optionValue'])) {
                 $row['optionValue'] .= ',' . $bbCode->bbcodeTag;
             } else {
                 $row['optionValue'] = $bbCode->bbcodeTag;
             }
             $updateStatement->execute(array($row['optionValue'], $row['optionID'], $row['groupID']));
         }
         WCF::getDB()->commitTransaction();
         // clear user group option cache
         UserGroupEditor::resetCache();
     }
     return $bbCode;
 }
Exemplo n.º 13
0
 /**
  * @see \wcf\form\IForm::save()
  */
 public function save()
 {
     AbstractForm::save();
     // get options
     $saveOptions = $this->optionHandler->save();
     $registerVia3rdParty = true;
     $avatarURL = '';
     if (isset($this->ttid_profile['avatar_url']) && !empty($this->ttid_profile['avatar_url'])) {
         $avatarURL = $this->ttid_profile['avatar_url'];
     }
     $this->additionalFields['languageID'] = $this->languageID;
     if (LOG_IP_ADDRESS) {
         $this->additionalFields['registrationIpAddress'] = WCF::getSession()->ipAddress;
     }
     // generate activation code
     $addDefaultGroups = true;
     if ($this->verified !== true && REGISTER_ACTIVATION_METHOD != 0 || $this->verified === true && REGISTER_ACTIVATION_METHOD == 2 && !WBB_TAPATALK_REG_AUTO_APPROVAL) {
         $activationCode = UserRegistrationUtil::getActivationCode();
         $this->additionalFields['activationCode'] = $activationCode;
         $addDefaultGroups = false;
         $this->groupIDs = UserGroup::getGroupIDsByType(array(UserGroup::EVERYONE, UserGroup::GUESTS));
     }
     // check gravatar support
     if (MODULE_GRAVATAR && Gravatar::test($this->email)) {
         $this->additionalFields['enableGravatar'] = 1;
     }
     // create user
     $data = array('data' => array_merge($this->additionalFields, array('username' => $this->username, 'email' => $this->email, 'password' => $this->password)), 'groups' => $this->groupIDs, 'languageIDs' => $this->visibleLanguages, 'options' => $saveOptions, 'addDefaultGroups' => $addDefaultGroups);
     $this->objectAction = new UserAction(array(), 'create', $data);
     $result = $this->objectAction->executeAction();
     $user = $result['returnValues'];
     $userEditor = new UserEditor($user);
     // set avatar if provided
     if (!empty($avatarURL)) {
         $userAvatarAction = new UserAvatarAction(array(), 'fetchRemoteAvatar', array('url' => $avatarURL, 'userEditor' => $userEditor));
         $userAvatarAction->executeAction();
     }
     // update session
     WCF::getSession()->changeUser($user);
     // activation management
     if (REGISTER_ACTIVATION_METHOD == 0) {
         $this->message = 'wcf.user.register.success';
     } else {
         if (REGISTER_ACTIVATION_METHOD == 1) {
             // registering via 3rdParty leads to instant activation
             if ($registerVia3rdParty && $this->verified) {
                 $this->message = 'wcf.user.register.success';
             } else {
                 $mail = new Mail(array($this->username => $this->email), WCF::getLanguage()->getDynamicVariable('wcf.user.register.needActivation.mail.subject'), WCF::getLanguage()->getDynamicVariable('wcf.user.register.needActivation.mail', array('user' => $user)));
                 $mail->send();
                 $this->message = 'wcf.user.register.needActivation';
             }
         } else {
             if (REGISTER_ACTIVATION_METHOD == 2 && (!$this->verified || $this->verified && !WBB_TAPATALK_REG_AUTO_APPROVAL)) {
                 $this->message = 'wcf.user.register.awaitActivation';
             }
         }
     }
     // notify admin
     if (REGISTER_ADMIN_NOTIFICATION) {
         // get default language
         $language = LanguageFactory::getInstance()->getLanguage(LanguageFactory::getInstance()->getDefaultLanguageID());
         // send mail
         $mail = new Mail(MAIL_ADMIN_ADDRESS, $language->getDynamicVariable('wcf.user.register.notification.mail.subject'), $language->getDynamicVariable('wcf.user.register.notification.mail', array('user' => $user)));
         $mail->setLanguage($language);
         $mail->send();
     }
     if ($this->captchaObjectType) {
         $this->captchaObjectType->getProcessor()->reset();
     }
     if (WCF::getSession()->getVar('noRegistrationCaptcha')) {
         WCF::getSession()->unregister('noRegistrationCaptcha');
     }
     // login user
     UserAuthenticationFactory::getInstance()->getUserAuthentication()->storeAccessData($user, $this->username, $this->password);
     WCF::getSession()->unregister('registrationStartTime');
     $this->saved();
 }
Exemplo n.º 14
0
 /**
  * Gets the list of results.
  */
 protected function readUsers()
 {
     // get user ids
     $userIDs = array();
     $sql = "SELECT\t\tuser_table.userID\n\t\t\tFROM\t\twcf" . WCF_N . "_user user_table\n\t\t\t" . (isset($this->options[$this->sortField]) ? "LEFT JOIN wcf" . WCF_N . "_user_option_value user_option_value ON (user_option_value.userID = user_table.userID)" : '') . "\n\t\t\t" . $this->conditions . "\n\t\t\tORDER BY\t" . ($this->sortField != 'email' && isset($this->options[$this->sortField]) ? 'user_option_value.userOption' . $this->options[$this->sortField]['optionID'] : $this->sortField) . " " . $this->sortOrder;
     $statement = WCF::getDB()->prepareStatement($sql, $this->itemsPerPage, ($this->pageNo - 1) * $this->itemsPerPage);
     $statement->execute($this->conditions->getParameters());
     while ($row = $statement->fetchArray()) {
         $userIDs[] = $row['userID'];
     }
     // get user data
     if (count($userIDs)) {
         $userToGroups = array();
         // get group ids
         $conditions = new PreparedStatementConditionBuilder();
         $conditions->add("user_table.userID IN (?)", array($userIDs));
         $sql = "SELECT\tuserID, groupID\n\t\t\t\tFROM\twcf" . WCF_N . "_user_to_group user_table\n\t\t\t\t" . $conditions;
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute($conditions->getParameters());
         while ($row = $statement->fetchArray()) {
             $userToGroups[$row['userID']][] = $row['groupID'];
         }
         $sql = "SELECT\t\toption_value.*, user_table.*\n\t\t\t\tFROM\t\twcf" . WCF_N . "_user user_table\n\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_option_value option_value\n\t\t\t\tON\t\t(option_value.userID = user_table.userID)\n\t\t\t\t" . $conditions . "\n\t\t\t\tORDER BY\t" . ($this->sortField != 'email' && isset($this->options[$this->sortField]) ? 'option_value.userOption' . $this->options[$this->sortField]['optionID'] : 'user_table.' . $this->sortField) . " " . $this->sortOrder;
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute($conditions->getParameters());
         while ($row = $statement->fetchArray()) {
             $row['groupIDs'] = implode(',', $userToGroups[$row['userID']]);
             $accessible = UserGroup::isAccessibleGroup($userToGroups[$row['userID']]);
             $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['isMarked'] = intval(in_array($row['userID'], $this->markedUsers));
             $this->users[] = new User(null, $row);
         }
         // get special columns
         foreach ($this->users as $key => $user) {
             foreach ($this->columns as $column) {
                 switch ($column) {
                     case 'email':
                         $this->columnValues[$user->userID][$column] = '<a href="mailto:' . StringUtil::encodeHTML($user->email) . '">' . StringUtil::encodeHTML($user->email) . '</a>';
                         break;
                     case 'registrationDate':
                         $this->columnValues[$user->userID][$column] = DateUtil::format(DateUtil::getDateTimeByTimestamp($user->{$column}), DateUtil::DATE_FORMAT);
                         break;
                     default:
                         if (isset($this->options[$column])) {
                             if ($this->options[$column]->outputClass) {
                                 $this->options[$column]->setOptionValue($user);
                                 $outputObj = $this->options[$column]->getOutputObject();
                                 $this->columnValues[$user->userID][$column] = $outputObj->getOutput($user, $this->options[$column]->getDecoratedObject(), $user->{$column});
                             } else {
                                 $this->columnValues[$user->userID][$column] = StringUtil::encodeHTML($user->{$column});
                             }
                         }
                         break;
                 }
             }
         }
     }
 }
Exemplo n.º 15
0
	/**
	 * Reads accessible user groups.
	 */
	protected function readAccessibleGroups() {
		$this->groups = UserGroup::getAccessibleGroups();
		$this->canEditEveryone = false;
		foreach ($this->groups as $groupID => $group) {
			if ($group->groupType == UserGroup::EVERYONE) {
				$this->canEditEveryone = true;
				
				// remove 'Everyone' from groups
				$this->groupEveryone = $group;
				unset($this->groups[$groupID]);
			}
		}
		
		// add 'Everyone' group
		if (!$this->canEditEveryone) {
			$this->groupEveryone = UserGroup::getGroupByType(UserGroup::EVERYONE);
		}
	}
Exemplo n.º 16
0
 /**
  * init one user by condition
  *
  * @param  Mixed  $var
  * @param  Array  $mbqOpt
  * $mbqOpt['case'] = 'oUserProfile' means init user by oUserProfile.$var is oUserProfile.
  * $mbqOpt['case'] = 'byUserId' means init user by user id.$var is user id.
  * $mbqOpt['case'] = 'byLoginName' means init user by login name.$var is login name.
  * @return  Mixed
  */
 public function initOMbqEtUser($var = null, $mbqOpt = array())
 {
     if ($mbqOpt['case'] == 'oUserProfile') {
         $oMbqEtUser = MbqMain::$oClk->newObj('MbqEtUser');
         $oUser = $var->getDecoratedObject();
         $oMbqEtUser->userId->setOriValue($oUser->userID);
         $oMbqEtUser->loginName->setOriValue($oUser->username);
         $oMbqEtUser->userName->setOriValue($oUser->username);
         $oMbqEtUser->userEmail->setOriValue($oUser->email);
         $oMbqEtUser->userGroupIds->setOriValue($oUser->getGroupIDs());
         $oMbqEtUser->iconUrl->setOriValue($var->getAvatar()->getURL());
         $oMbqEtUser->postCount->setOriValue($oUser->wbbPosts);
         $oMbqEtUser->canSearch->setOriValue(MbqBaseFdt::getFdt('MbqFdtUser.MbqEtUser.canSearch.range.yes'));
         $oMbqEtUser->canWhosonline->setOriValue(MbqBaseFdt::getFdt('MbqFdtUser.MbqEtUser.canWhosonline.range.yes'));
         $oMbqEtUser->regTime->setOriValue($oUser->registrationDate);
         $oMbqEtUser->lastActivityTime->setOriValue($oUser->lastActivityTime);
         if ($var->isOnline()) {
             $oMbqEtUser->isOnline->setOriValue(MbqBaseFdt::getFdt('MbqFdtUser.MbqEtUser.isOnline.range.yes'));
         } else {
             $oMbqEtUser->isOnline->setOriValue(MbqBaseFdt::getFdt('MbqFdtUser.MbqEtUser.isOnline.range.no'));
         }
         if (MODULE_CONVERSATION && $var->getPermission('user.conversation.canUseConversation')) {
             $oMbqEtUser->canPm->setOriValue(MbqBaseFdt::getFdt('MbqFdtUser.MbqEtUser.canPm.range.yes'));
             $oMbqEtUser->acceptPm->setOriValue(MbqBaseFdt::getFdt('MbqFdtUser.MbqEtUser.acceptPm.range.yes'));
             $oMbqEtUser->canSendPm->setOriValue(MbqBaseFdt::getFdt('MbqFdtUser.MbqEtUser.canSendPm.range.yes'));
         }
         $oMbqEtUser->maxAttachment->setOriValue(10);
         //todo,hard code
         $oMbqEtUser->maxPngSize->setOriValue(1024 * 1024);
         //todo,hard code
         $oMbqEtUser->maxJpgSize->setOriValue(1024 * 1024);
         //todo,hard code
         $group = UserGroup::getGroupByID($oUser->groupID);
         if ($oUser->banned) {
             $oMbqEtUser->userType->setOriValue(MbqBaseFdt::getFdt('MbqFdtUser.MbqEtUser.userType.range.banned'));
         } else {
             if (empty($oUser->groupID) || empty($group)) {
                 if (REGISTER_ACTIVATION_METHOD == 1) {
                     $oMbqEtUser->userType->setOriValue(MbqBaseFdt::getFdt('MbqFdtUser.MbqEtUser.userType.range.inactive'));
                 } else {
                     $oMbqEtUser->userType->setOriValue(MbqBaseFdt::getFdt('MbqFdtUser.MbqEtUser.userType.range.unapproved'));
                 }
             } else {
                 if ($group->isAdminGroup()) {
                     $oMbqEtUser->userType->setOriValue(MbqBaseFdt::getFdt('MbqFdtUser.MbqEtUser.userType.range.admin'));
                 } else {
                     if (method_exists($group, 'isModGroup') && $group->isModGroup()) {
                         $oMbqEtUser->userType->setOriValue(MbqBaseFdt::getFdt('MbqFdtUser.MbqEtUser.userType.range.mod'));
                     } else {
                         $oMbqEtUser->userType->setOriValue(MbqBaseFdt::getFdt('MbqFdtUser.MbqEtUser.userType.range.normal'));
                     }
                 }
             }
         }
         $oMbqEtUser->mbqBind['oUser'] = $oUser;
         $oMbqEtUser->mbqBind['oUserProfile'] = $var;
         return $oMbqEtUser;
     } elseif ($mbqOpt['case'] == 'byUserId') {
         $userIds = array($var);
         $objsMbqEtUser = $this->getObjsMbqEtUser($userIds, array('case' => 'byUserIds'));
         if (is_array($objsMbqEtUser) && count($objsMbqEtUser) == 1) {
             return $objsMbqEtUser[0];
         }
         return;
     } elseif ($mbqOpt['case'] == 'byLoginName') {
         $oUserProfile = UserProfile::getUserProfileByUsername($var);
         if ($oUserProfile) {
             return $this->initOMbqEtUser($oUserProfile, array('case' => 'oUserProfile'));
         }
         return;
     } elseif ($mbqOpt['case'] == 'byEmail') {
         $userList = new UserProfileList();
         $userList->getConditionBuilder()->add("user_table.email IN (?)", array(array($var)));
         $userList->readObjects();
         $oUserProfile = current($userList->objects);
         if ($oUserProfile) {
             return $this->initOMbqEtUser($oUserProfile, array('case' => 'oUserProfile'));
         }
         return;
     }
     MbqError::alert('', __METHOD__ . ',line:' . __LINE__ . '.' . MBQ_ERR_INFO_UNKNOWN_CASE);
 }
Exemplo n.º 17
0
 /**
  * @see	\wcf\form\IForm::save()
  */
 public function save()
 {
     AbstractForm::save();
     // handle avatar
     if ($this->avatarType != 'custom') {
         // delete custom avatar
         if ($this->user->avatarID) {
             $action = new UserAvatarAction(array($this->user->avatarID), 'delete');
             $action->executeAction();
         }
     }
     switch ($this->avatarType) {
         case 'none':
             $avatarData = array('avatarID' => null, 'enableGravatar' => 0);
             break;
         case 'custom':
             $avatarData = array('enableGravatar' => 0);
             break;
         case 'gravatar':
             $avatarData = array('avatarID' => null, 'enableGravatar' => 1);
             break;
     }
     $this->additionalFields = array_merge($this->additionalFields, $avatarData);
     // add default groups
     $defaultGroups = UserGroup::getAccessibleGroups(array(UserGroup::GUESTS, UserGroup::EVERYONE, UserGroup::USERS));
     $oldGroupIDs = $this->user->getGroupIDs();
     foreach ($oldGroupIDs as $oldGroupID) {
         if (isset($defaultGroups[$oldGroupID])) {
             $this->groupIDs[] = $oldGroupID;
         }
     }
     $this->groupIDs = array_unique($this->groupIDs);
     // save user
     $saveOptions = $this->optionHandler->save();
     $data = array('data' => array_merge($this->additionalFields, array('username' => $this->username, 'email' => $this->email, 'password' => $this->password, 'languageID' => $this->languageID, 'userTitle' => $this->userTitle, 'signature' => $this->signature, 'signatureEnableBBCodes' => $this->signatureEnableBBCodes, 'signatureEnableSmilies' => $this->signatureEnableSmilies, 'signatureEnableHtml' => $this->signatureEnableHtml)), 'groups' => $this->groupIDs, 'languageIDs' => $this->visibleLanguages, 'options' => $saveOptions);
     // handle ban
     if (WCF::getSession()->getPermission('admin.user.canBanUser')) {
         if ($this->banExpires) {
             $this->banExpires = strtotime($this->banExpires);
         } else {
             $this->banExpires = 0;
         }
         $data['data']['banned'] = $this->banned;
         $data['data']['banReason'] = $this->banReason;
         $data['data']['banExpires'] = $this->banExpires;
     }
     // handle disabled signature
     if (WCF::getSession()->getPermission('admin.user.canDisableSignature')) {
         if ($this->disableSignatureExpires) {
             $this->disableSignatureExpires = strtotime($this->disableSignatureExpires);
         } else {
             $this->disableSignatureExpires = 0;
         }
         $data['data']['disableSignature'] = $this->disableSignature;
         $data['data']['disableSignatureReason'] = $this->disableSignatureReason;
         $data['data']['disableSignatureExpires'] = $this->disableSignatureExpires;
     }
     // handle disabled avatar
     if (WCF::getSession()->getPermission('admin.user.canDisableAvatar')) {
         if ($this->disableAvatarExpires) {
             $this->disableAvatarExpires = strtotime($this->disableAvatarExpires);
         } else {
             $this->disableAvatarExpires = 0;
         }
         $data['data']['disableAvatar'] = $this->disableAvatar;
         $data['data']['disableAvatarReason'] = $this->disableAvatarReason;
         $data['data']['disableAvatarExpires'] = $this->disableAvatarExpires;
     }
     $this->objectAction = new UserAction(array($this->userID), 'update', $data);
     $this->objectAction->executeAction();
     // update user rank
     $editor = new UserEditor(new User($this->userID));
     if (MODULE_USER_RANK) {
         $action = new UserProfileAction(array($editor), 'updateUserRank');
         $action->executeAction();
     }
     if (MODULE_USERS_ONLINE) {
         $action = new UserProfileAction(array($editor), 'updateUserOnlineMarking');
         $action->executeAction();
     }
     // remove assignments
     $sql = "DELETE FROM\twcf" . WCF_N . "_moderation_queue_to_user\n\t\t\tWHERE\t\tuserID = ?";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute(array($this->user->userID));
     // reset moderation count
     ModerationQueueManager::getInstance()->resetModerationCount($this->user->userID);
     $this->saved();
     // reset password
     $this->password = $this->confirmPassword = '';
     // show success message
     WCF::getTPL()->assign('success', true);
 }
Exemplo n.º 18
0
 /**
  * Adds a user to the groups he should be in.
  * 
  * @param	array		$groups
  * @param	boolean		$deleteOldGroups
  * @param	boolean		$addDefaultGroups
  */
 public function addToGroups(array $groupIDs, $deleteOldGroups = true, $addDefaultGroups = true)
 {
     // add default groups
     if ($addDefaultGroups) {
         $groupIDs = array_merge($groupIDs, UserGroup::getGroupIDsByType(array(UserGroup::EVERYONE, UserGroup::USERS)));
         $groupIDs = array_unique($groupIDs);
     }
     // remove old groups
     if ($deleteOldGroups) {
         $sql = "DELETE FROM\twcf" . WCF_N . "_user_to_group\n\t\t\t\tWHERE\t\tuserID = ?";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute(array($this->userID));
     }
     // insert new groups
     if (!empty($groupIDs)) {
         $sql = "INSERT IGNORE INTO\twcf" . WCF_N . "_user_to_group\n\t\t\t\t\t\t\t(userID, groupID)\n\t\t\t\tVALUES\t\t\t(?, ?)";
         $statement = WCF::getDB()->prepareStatement($sql);
         foreach ($groupIDs as $groupID) {
             $statement->execute(array($this->userID, $groupID));
         }
     }
 }
Exemplo n.º 19
0
	/**
	 * @todo	add documentation
	 */
	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(array($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 (!is_array($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;
	}
Exemplo n.º 20
0
	/**
	 * Returns the ids of the users which can be deleted.
	 * 
	 * @return	array<integer>
	 */
	protected function validateDelete() {
		// check permissions
		if (!WCF::getSession()->getPermission('admin.user.canDeleteUser')) {
			return 0;
		}
		
		// user cannot delete itself
		$userIDs = array_keys($this->objects);
		foreach ($userIDs as $index => $userID) {
			if ($userID == WCF::getUser()->userID) {
				unset($userIDs[$index]);
			}
		}
		
		// no valid users found
		if (empty($userIDs)) return array();
		
		// fetch user to group associations
		$conditions = new PreparedStatementConditionBuilder();
		$conditions->add("userID IN (?)", array($userIDs));
		
		$sql = "SELECT	userID, groupID
			FROM	wcf".WCF_N."_user_to_group
			".$conditions;
		$statement = WCF::getDB()->prepareStatement($sql);
		$statement->execute($conditions->getParameters());
		
		$userToGroup = array();
		while ($row = $statement->fetchArray()) {
			if (!isset($userToGroup[$row['userID']])) {
				$userToGroup[$row['userID']] = array();
			}
			
			$userToGroup[$row['userID']][] = $row['groupID'];
		}
		
		// validate if user's group is accessible for current user
		foreach ($userIDs as $userID) {
			if (!isset($userToGroup[$userID]) || !UserGroup::isAccessibleGroup($userToGroup[$userID])) {
				unset($userIDs[$userID]);
			}
		}
		
		return $userIDs;
	}
 /**
  * Fetches a list of users.
  * 
  * @param	mixed		$loopFunction
  * @return	array<integer>
  */
 public function fetchUsers($loopFunction = null)
 {
     // select users
     $sql = "SELECT\t\tuser_table.*\n\t\t\tFROM\t\twcf" . WCF_N . "_user user_table\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_option_value option_value\n\t\t\tON\t\t(option_value.userID = user_table.userID)\n\t\t\t" . $this->conditions;
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute($this->conditions->getParameters());
     $users = array();
     while ($row = $statement->fetchArray()) {
         $users[$row['userID']] = $row;
     }
     if (empty($users)) {
         return array();
     }
     // select group ids
     $conditions = new PreparedStatementConditionBuilder();
     $conditions->add("userID IN (?)", array(array_keys($users)));
     $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());
     $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 (!empty($groupIDs[$userID]) && !UserGroup::isAccessibleGroup($groupIDs[$userID])) {
             throw new PermissionDeniedException();
         }
         if ($loopFunction !== null) {
             $loopFunction($userID, $userData);
         }
         $userIDs[] = $userID;
         $this->affectedUsers++;
     }
     return $userIDs;
 }
Exemplo n.º 22
0
 /**
  * Returns a list of users and -groups based upon given search criteria.
  * 
  * @return	array<array>
  */
 public function getList()
 {
     $searchString = $this->parameters['data']['searchString'];
     $excludedSearchValues = array();
     if (isset($this->parameters['data']['excludedSearchValues'])) {
         $excludedSearchValues = $this->parameters['data']['excludedSearchValues'];
     }
     $list = array();
     if ($this->parameters['data']['includeUserGroups']) {
         $accessibleGroups = UserGroup::getAccessibleGroups();
         foreach ($accessibleGroups as $group) {
             $groupName = $group->getName();
             if (!in_array($groupName, $excludedSearchValues)) {
                 $pos = StringUtil::indexOfIgnoreCase($groupName, $searchString);
                 if ($pos !== false && $pos == 0) {
                     $list[] = array('label' => $groupName, 'objectID' => $group->groupID, 'type' => 'group');
                 }
             }
         }
     }
     $conditionBuilder = new PreparedStatementConditionBuilder();
     $conditionBuilder->add("username LIKE ?", array($searchString . '%'));
     if (count($excludedSearchValues)) {
         $conditionBuilder->add("username NOT IN (?)", array($excludedSearchValues));
     }
     // find users
     $sql = "SELECT\tuserID, username\n\t\t\tFROM\twcf" . WCF_N . "_user\n\t\t\t" . $conditionBuilder;
     $statement = WCF::getDB()->prepareStatement($sql, 10);
     /* TODO: add limit parameter */
     $statement->execute($conditionBuilder->getParameters());
     while ($row = $statement->fetchArray()) {
         $list[] = array('label' => $row['username'], 'objectID' => $row['userID'], 'type' => 'user');
     }
     return $list;
 }
Exemplo n.º 23
0
 /**
  * Returns an array with all the groups in which the actual user is a member.
  *
  * @return 	array 		$groupIDs
  */
 public function getGroupIDs()
 {
     if ($this->groupIDs === null) {
         if (!$this->userID) {
             // user is a guest, use default guest group
             $this->groupIDs = UserGroup::getGroupIDsByType(array(UserGroup::GUESTS, UserGroup::EVERYONE));
         } else {
             // load storage data
             UserStorageHandler::getInstance()->loadStorage(array($this->userID));
             // get group ids
             $data = UserStorageHandler::getInstance()->getStorage(array($this->userID), 'groupIDs');
             // cache does not exist or is outdated
             if ($data[$this->userID] === null) {
                 $this->groupIDs = array();
                 $sql = "SELECT\tgroupID\n\t\t\t\t\t\tFROM\twcf" . WCF_N . "_user_to_group\n\t\t\t\t\t\tWHERE\tuserID = ?";
                 $statement = WCF::getDB()->prepareStatement($sql);
                 $statement->execute(array($this->userID));
                 while ($row = $statement->fetchArray()) {
                     $this->groupIDs[] = $row['groupID'];
                 }
                 // update storage data
                 UserStorageHandler::getInstance()->update($this->userID, 'groupIDs', serialize($this->groupIDs), 1);
             } else {
                 $this->groupIDs = unserialize($data[$this->userID]);
             }
         }
     }
     return $this->groupIDs;
 }
Exemplo n.º 24
0
 /**
  * @see	\wcf\page\IPage::assignVariables()
  */
 public function readData()
 {
     parent::readData();
     if (empty($_POST)) {
         // get marked user ids
         if (empty($this->action)) {
             // get type id
             $objectTypeID = ClipboardHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.user');
             if ($objectTypeID === null) {
                 throw new SystemException("Unknown clipboard item type 'com.woltlab.wcf.user'");
             }
             // get user ids
             $users = ClipboardHandler::getInstance()->getMarkedItems($objectTypeID);
             if (empty($users)) {
                 throw new IllegalLinkException();
             }
             // load users
             $this->userIDs = array_keys($users);
         }
         if (MAIL_USE_FORMATTED_ADDRESS) {
             $this->from = MAIL_FROM_NAME . ' <' . MAIL_FROM_ADDRESS . '>';
         } else {
             $this->from = MAIL_FROM_ADDRESS;
         }
     }
     if (!empty($this->userIDs)) {
         $this->userList = new UserList();
         $this->userList->getConditionBuilder()->add("user_table.userID IN (?)", array($this->userIDs));
         $this->userList->sqlOrderBy = "user_table.username ASC";
         $this->userList->readObjects();
     }
     $this->groups = UserGroup::getAccessibleGroups(array(), array(UserGroup::GUESTS, UserGroup::EVERYONE));
 }
Exemplo n.º 25
0
 /**
  * Disables users.
  */
 public function disable()
 {
     if (empty($this->objects)) {
         $this->readObjects();
     }
     $action = new UserAction($this->objects, 'update', array('data' => array('activationCode' => UserRegistrationUtil::getActivationCode()), 'removeGroups' => UserGroup::getGroupIDsByType(array(UserGroup::USERS))));
     $action->executeAction();
     $action = new UserAction($this->objects, 'addToGroups', array('groups' => UserGroup::getGroupIDsByType(array(UserGroup::GUESTS)), 'deleteOldGroups' => false, 'addDefaultGroups' => false));
     $action->executeAction();
     $this->unmarkItems();
 }
Exemplo n.º 26
0
 /**
  * @see	\wcf\form\IForm::validate()
  */
 public function validate()
 {
     parent::validate();
     $isAdmin = false;
     foreach (WCF::getUser()->getGroupIDs() as $groupID) {
         if (UserGroup::getGroupByID($groupID)->isAdminGroup()) {
             $isAdmin = true;
             break;
         }
     }
     // validate option values
     foreach ($this->values as $groupID => &$optionValue) {
         if (!isset($this->groups[$groupID])) {
             throw new PermissionDeniedException();
         }
         $optionValue = $this->optionType->getData($this->userGroupOption, $optionValue);
         try {
             $this->optionType->validate($this->userGroupOption, $optionValue);
         } catch (UserInputException $e) {
             $this->errorType[$groupID] = $e->getType();
         }
         if (!$isAdmin && $this->optionType->compare($optionValue, WCF::getSession()->getPermission($this->userGroupOption->optionName)) == 1) {
             $this->errorType[$groupID] = 'exceedsOwnPermission';
         }
     }
     // add missing values for option type 'boolean'
     if ($this->userGroupOption->optionType == 'boolean') {
         foreach ($this->groups as $groupID => $group) {
             if (!isset($this->values[$groupID])) {
                 $this->values[$groupID] = 0;
             }
         }
     }
     if (!empty($this->errorType)) {
         throw new UserInputException('optionValues', $this->errorType);
     }
 }
Exemplo n.º 27
0
 /**
  * Returns a list of the users online markings.
  * 
  * @return	array
  */
 public function getUsersOnlineMarkings()
 {
     if ($this->usersOnlineMarkings === null) {
         $this->usersOnlineMarkings = $priorities = array();
         // get groups
         foreach (UserGroup::getGroupsByType() as $group) {
             if ($group->userOnlineMarking != '%s') {
                 $priorities[] = $group->priority;
                 $this->usersOnlineMarkings[] = str_replace('%s', StringUtil::encodeHTML(WCF::getLanguage()->get($group->groupName)), $group->userOnlineMarking);
             }
         }
         // sort list
         array_multisort($priorities, SORT_DESC, $this->usersOnlineMarkings);
     }
     return $this->usersOnlineMarkings;
 }
Exemplo n.º 28
0
	/**
	 * @see	wcf\form\IForm::validate()
	 */
	public function validate() {
		// validate static user options 
		try {
			$this->validateUsername($this->username);
		}
		catch (UserInputException $e) {
			$this->errorType[$e->getField()] = $e->getType();
		}
		
		try {
			$this->validateEmail($this->email, $this->confirmEmail);
		}
		catch (UserInputException $e) {
			$this->errorType[$e->getField()] = $e->getType();
		}
		
		try {
			$this->validatePassword($this->password, $this->confirmPassword);
		}
		catch (UserInputException $e) {
			$this->errorType[$e->getField()] = $e->getType();
		}
		
		// validate user groups
		if (!empty($this->groupIDs)) {
			$conditions = new PreparedStatementConditionBuilder();
			$conditions->add("groupID IN (?)", array($this->groupIDs));
			$conditions->add("groupType NOT IN (?)", array(array(UserGroup::GUESTS, UserGroup::EVERYONE, UserGroup::USERS)));
			
			$sql = "SELECT	groupID
				FROM	wcf".WCF_N."_user_group
				".$conditions;
			$statement = WCF::getDB()->prepareStatement($sql);
			$statement->execute($conditions->getParameters());
			$this->groupIDs = array();
			while ($row = $statement->fetchArray()) {
				if (UserGroup::isAccessibleGroup(array($row['groupID']))) {
					$this->groupIDs[] = $row['groupID'];
				}
			}
		}
		
		// validate user language
		$language = LanguageFactory::getInstance()->getLanguage($this->languageID);
		if ($language === null || !$language->languageID) {
			// use default language
			$this->languageID = LanguageFactory::getInstance()->getDefaultLanguageID();
		}
		
		// validate visible languages
		foreach ($this->visibleLanguages as $key => $visibleLanguage) {
			$language = LanguageFactory::getInstance()->getLanguage($visibleLanguage);
			if (!$language->languageID || !$language->hasContent) {
				unset($this->visibleLanguages[$key]);
			}
		}
		if (empty($this->visibleLanguages) && ($language = LanguageFactory::getInstance()->getLanguage($this->languageID)) && $language->hasContent) {
			$this->visibleLanguages[] = $this->languageID;
		}
		
		// validate dynamic options
		parent::validate();
	}
Exemplo n.º 29
0
 /**
  * @see	\wcf\page\IPage::assignVariables()
  */
 public function assignVariables()
 {
     parent::assignVariables();
     WCF::getTPL()->assign(array('editOnInit' => $this->editOnInit, 'overviewObjectType' => $this->objectType, 'profileContent' => $this->profileContent, 'userID' => $this->userID, 'user' => $this->user, 'followers' => $this->followerList->getObjects(), 'followerCount' => $this->followerList->countObjects(), 'following' => $this->followingList->getObjects(), 'followingCount' => $this->followingList->countObjects(), 'visitors' => $this->visitorList !== null ? $this->visitorList->getObjects() : array(), 'visitorCount' => $this->visitorList !== null ? $this->visitorList->countObjects() : 0, 'allowSpidersToIndexThisPage' => true, 'isAccessible' => UserGroup::isAccessibleGroup($this->user->getGroupIDs())));
 }
Exemplo n.º 30
0
	/**
	 * @see	wcf\form\IForm::save()
	 */
	public function save() {
		parent::save();
		
		// get default group
		$defaultGroup = UserGroup::getGroupByType(UserGroup::EVERYONE);
		$optionValues = $this->optionHandler->save();
		$saveOptions = array();
		foreach ($this->optionHandler->getCategoryOptions() as $option) {
			$option = $option['object'];
			$defaultValue = $defaultGroup->getGroupOption($option->optionName);
			$typeObject = $this->optionHandler->getTypeObject($option->optionType);
			
			$newValue = $typeObject->diff($defaultValue, $optionValues[$option->optionID]);
			if ($newValue !== null) {
				$saveOptions[$option->optionID] = $newValue;
			}
		}
		
		$data = array(
			'data' => array_merge($this->additionalFields, array('groupName' => $this->groupName)),
			'options' => $saveOptions
		);
		$this->objectAction = new UserGroupAction(array(), 'create', $data);
		$this->objectAction->executeAction();
		
		if (!I18nHandler::getInstance()->isPlainValue('groupName')) {
			$returnValues = $this->objectAction->getReturnValues();
			$groupID = $returnValues['returnValues']->groupID;
			I18nHandler::getInstance()->save('groupName', 'wcf.acp.group.group'.$groupID, 'wcf.acp.group', 1);
			
			// update group name
			$groupEditor = new UserGroupEditor($returnValues['returnValues']);
			$groupEditor->update(array(
				'groupName' => 'wcf.acp.group.group'.$groupID
			));
		}
		
		$this->saved();
		
		// show success message
		WCF::getTPL()->assign(array(
			'success' => true
		));
		
		// reset values
		$this->groupName = '';
		$this->optionValues = array();
	}