/** * Updates option values for given option id. */ public function updateValues() { $option = current($this->objects); // remove old values $sql = "DELETE FROM wcf".WCF_N."_user_group_option_value WHERE optionID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array( $option->optionID )); if (!empty($this->parameters['values'])) { $sql = "INSERT INTO wcf".WCF_N."_user_group_option_value (optionID, groupID, optionValue) VALUES (?, ?, ?)"; $statement = WCF::getDB()->prepareStatement($sql); WCF::getDB()->beginTransaction(); foreach ($this->parameters['values'] as $groupID => $optionValue) { $statement->execute(array( $option->optionID, $groupID, $optionValue )); } WCF::getDB()->commitTransaction(); } // clear cache UserGroupEditor::resetCache(); }
/** * @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; }
/** * Copies a user group. */ public function copy() { // fetch user group option values if ($this->parameters['copyUserGroupOptions']) { $sql = "SELECT\toptionID, optionValue\n\t\t\t\tFROM\twcf" . WCF_N . "_user_group_option_value\n\t\t\t\tWHERE\tgroupID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->groupEditor->groupID)); } else { $sql = "SELECT\toptionID, defaultValue AS optionValue\n\t\t\t\tFROM\twcf" . WCF_N . "_user_group_option"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(); } $optionValues = array(); while ($row = $statement->fetchArray()) { $optionValues[$row['optionID']] = $row['optionValue']; } $groupAction = new UserGroupAction(array(), 'create', array('data' => array('groupName' => $this->groupEditor->groupName, 'groupDescription' => $this->groupEditor->groupDescription, 'priority' => $this->groupEditor->priority, 'userOnlineMarking' => $this->groupEditor->userOnlineMarking, 'showOnTeamPage' => $this->groupEditor->showOnTeamPage), 'options' => $optionValues)); $returnValues = $groupAction->executeAction(); $group = $returnValues['returnValues']; $groupEditor = new UserGroupEditor($group); // update group name $groupName = $this->groupEditor->groupName; if (preg_match('~^wcf\\.acp\\.group\\.group\\d+$~', $this->groupEditor->groupName)) { $groupName = 'wcf.acp.group.group' . $group->groupID; // create group name language item $sql = "INSERT INTO\twcf" . WCF_N . "_language_item\n\t\t\t\t\t\t(languageID, languageItem, languageItemValue, languageItemOriginIsSystem, languageCategoryID, packageID)\n\t\t\t\tSELECT\t\tlanguageID, '" . $groupName . "', CONCAT(languageItemValue, ' (2)'), 0, languageCategoryID, packageID\n\t\t\t\tFROM\t\twcf" . WCF_N . "_language_item\n\t\t\t\tWHERE\t\tlanguageItem = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->groupEditor->groupName)); } else { $groupName .= ' (2)'; } // update group name $groupDescription = $this->groupEditor->groupName; if (preg_match('~^wcf\\.acp\\.group\\.groupDescription\\d+$~', $this->groupEditor->groupDescription)) { $groupDescription = 'wcf.acp.group.groupDescription' . $group->groupID; // create group name language item $sql = "INSERT INTO\twcf" . WCF_N . "_language_item\n\t\t\t\t\t\t(languageID, languageItem, languageItemValue, languageItemOriginIsSystem, languageCategoryID, packageID)\n\t\t\t\tSELECT\t\tlanguageID, '" . $groupDescription . "', languageItemValue, 0, languageCategoryID, packageID\n\t\t\t\tFROM\t\twcf" . WCF_N . "_language_item\n\t\t\t\tWHERE\t\tlanguageItem = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->groupEditor->groupDescription)); } $groupEditor->update(array('groupDescription' => $groupDescription, 'groupName' => $groupName)); // copy members if ($this->parameters['copyMembers']) { $sql = "INSERT INTO\twcf" . WCF_N . "_user_to_group\n\t\t\t\t\t\t(userID, groupID)\n\t\t\t\tSELECT\t\tuserID, " . $group->groupID . "\n\t\t\t\tFROM\t\twcf" . WCF_N . "_user_to_group\n\t\t\t\tWHERE\t\tgroupID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->groupEditor->groupID)); } // copy acl options if ($this->parameters['copyACLOptions']) { $sql = "INSERT INTO\twcf" . WCF_N . "_acl_option_to_group\n\t\t\t\t\t\t(optionID, objectID, groupID, optionValue)\n\t\t\t\tSELECT\t\toptionID, objectID, " . $group->groupID . ", optionValue\n\t\t\t\tFROM\t\twcf" . WCF_N . "_acl_option_to_group\n\t\t\t\tWHERE\t\tgroupID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->groupEditor->groupID)); // it is likely that applications or plugins use caches // for acl option values like for the labels which have // to be renewed after copying the acl options; because // there is no other way to delete these caches, we simply // delete all caches CacheHandler::getInstance()->flushAll(); } // reset language cache LanguageFactory::getInstance()->deleteLanguageCache(); UserGroupEditor::resetCache(); return array('redirectURL' => LinkHandler::getInstance()->getLink('UserGroupEdit', array('id' => $group->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); }