/** * 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() { 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(); }
/** * @see \wcf\form\IForm::save() */ public function save() { parent::save(); $optionValues = $this->optionHandler->save(); $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(), 'create', $data); $this->objectAction->executeAction(); $returnValues = $this->objectAction->getReturnValues(); $groupID = $returnValues['returnValues']->groupID; if (!I18nHandler::getInstance()->isPlainValue('groupName')) { 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)); } if (!I18nHandler::getInstance()->isPlainValue('groupDescription')) { I18nHandler::getInstance()->save('groupDescription', 'wcf.acp.group.groupDescription' . $groupID, 'wcf.acp.group', 1); // update group name $groupEditor = new UserGroupEditor($returnValues['returnValues']); $groupEditor->update(array('groupDescription' => 'wcf.acp.group.groupDescription' . $groupID)); } $this->saved(); // show success message WCF::getTPL()->assign(array('success' => true)); // reset values $this->groupName = ''; $this->optionValues = array(); I18nHandler::getInstance()->reset(); }