/** * 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)); } }
/** * @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']]); } }
/** * Returns true if current user has the permissions to edit every user group. * * @return boolean */ protected function isAdmin() { if ($this->isAdmin === null) { $this->isAdmin = false; foreach (WCF::getUser()->getGroupIDs() as $groupID) { if (UserGroup::getGroupByID($groupID)->isAdminGroup()) { $this->isAdmin = true; break; } } } return $this->isAdmin; }
/** * 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); }
/** * @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); } }
/** * Returns the formatted username. * * @return string */ public function getFormattedUsername() { $username = StringUtil::encodeHTML($this->username); if ($this->userOnlineGroupID) { $group = UserGroup::getGroupByID($this->userOnlineGroupID); if ($group !== null && $group->userOnlineMarking && $group->userOnlineMarking != '%s') { return str_replace('%s', $username, $group->userOnlineMarking); } } return $username; }
/** * Returns the user group the automatic assignment belongs to. * * @return \wcf\data\user\group\UserGroup */ public function getUserGroup() { return UserGroup::getGroupByID($this->groupID); }
/** * @see \wcf\form\IForm::save() */ public function save() { AbstractForm::save(); // save group $optionValues = $this->optionHandler->save(); $this->groupName = 'wcf.acp.group.group' . $this->group->groupID; if (I18nHandler::getInstance()->isPlainValue('groupName')) { I18nHandler::getInstance()->remove($this->groupName); $this->groupName = I18nHandler::getInstance()->getValue('groupName'); UserGroup::getGroupByID($this->groupID)->setName($this->groupName); } else { I18nHandler::getInstance()->save('groupName', $this->groupName, 'wcf.acp.group', 1); $groupNames = I18nHandler::getInstance()->getValues('groupName'); UserGroup::getGroupByID($this->groupID)->setName($groupNames[WCF::getLanguage()->languageID]); } $this->groupDescription = 'wcf.acp.group.groupDescription' . $this->group->groupID; if (I18nHandler::getInstance()->isPlainValue('groupDescription')) { I18nHandler::getInstance()->remove($this->groupDescription); $this->groupDescription = I18nHandler::getInstance()->getValue('groupDescription'); } else { I18nHandler::getInstance()->save('groupDescription', $this->groupDescription, 'wcf.acp.group', 1); } $data = array('data' => array_merge($this->additionalFields, array('groupName' => $this->groupName, 'groupDescription' => $this->groupDescription, 'priority' => $this->priority, 'userOnlineMarking' => $this->userOnlineMarking, 'showOnTeamPage' => $this->showOnTeamPage)), 'options' => $optionValues); $this->objectAction = new UserGroupAction(array($this->groupID), 'update', $data); $this->objectAction->executeAction(); $this->saved(); // reset user group cache UserGroupEditor::resetCache(); // show success message WCF::getTPL()->assign('success', true); }
/** * Returns true, if this user has access to the ACP. * * @return boolean */ public function hasAdministrativeAccess() { if ($this->hasAdministrativePermissions === null) { $this->hasAdministrativePermissions = false; if ($this->userID) { foreach ($this->getGroupIDs() as $groupID) { $group = UserGroup::getGroupByID($groupID); if ($group->isAdminGroup()) { $this->hasAdministrativePermissions = true; break; } } } } return $this->hasAdministrativePermissions; }
public function getUserType() { if (empty($this->oUser)) { return ''; } $group = UserGroup::getGroupByID($this->oUser->userOnlineGroupID); if ($this->oUser->banned) { $oMbqEtUser->userType->setOriValue(MbqBaseFdt::getFdt('MbqFdtUser.MbqEtUser.userType.range.banned')); } else { if (empty($this->oUser->userOnlineGroupID) || empty($group)) { if (REGISTER_ACTIVATION_METHOD == 1) { return 'inactive'; } else { return 'unapproved'; } } else { if ($group->isAdminGroup()) { return 'admin'; } if (method_exists($group, 'isModGroup') && $group->isModGroup()) { return 'mod'; } return 'normal'; } } }
/** * @see \wcf\form\IForm::validate() */ public function validate() { parent::validate(); // validate label if (!I18nHandler::getInstance()->validateValue('rankTitle')) { if (I18nHandler::getInstance()->isPlainValue('rankTitle')) { throw new UserInputException('rankTitle'); } else { throw new UserInputException('rankTitle', 'multilingual'); } } // validate group if (!$this->groupID) { throw new UserInputException('groupID'); } $userGroup = UserGroup::getGroupByID($this->groupID); if ($userGroup === null || $userGroup->groupType == UserGroup::GUESTS || $userGroup->groupType == UserGroup::EVERYONE) { throw new UserInputException('groupID', 'notValid'); } // css class name if (empty($this->cssClassName)) { throw new UserInputException('cssClassName', 'empty'); } else { if (!in_array($this->cssClassName, $this->availableCssClassNames)) { throw new UserInputException('cssClassName', 'notValid'); } else { if ($this->cssClassName == 'custom') { if (!empty($this->customCssClassName) && !Regex::compile('^-?[_a-zA-Z]+[_a-zA-Z0-9-]+$')->match($this->customCssClassName)) { throw new UserInputException('cssClassName', 'notValid'); } } } } // required gender if ($this->requiredGender < 0 || $this->requiredGender > 2) { $this->requiredGender = 0; } }
/** * Removes group memberships. */ public function removeGroupMemberships() { if (empty($this->objects)) { $this->readObjects(); } foreach ($this->objects as $subscriptionUser) { $groupIDs = array(); foreach (explode(',', $subscriptionUser->getSubscription()->groupIDs) as $groupID) { if (UserGroup::getGroupByID($groupID) !== null) { $groupIDs[] = $groupID; } } if (!empty($groupIDs)) { $action = new UserAction(array($subscriptionUser->userID), 'removeFromGroups', array('groups' => $groupIDs)); $action->executeAction(); } } }