Example #1
0
 /**
  * Creates a new group.
  * 
  * @return	UserGroup
  */
 public function create()
 {
     $group = parent::create();
     $groupEditor = new UserGroupEditor($group);
     $groupEditor->updateGroupOptions($this->parameters['options']);
     return $group;
 }
 /**
  * Validates the 'copy' action.
  */
 public function validateCopy()
 {
     WCF::getSession()->checkPermissions(array('admin.user.canAddGroup', 'admin.user.canEditGroup'));
     $this->readBoolean('copyACLOptions');
     $this->readBoolean('copyMembers');
     $this->readBoolean('copyUserGroupOptions');
     $this->groupEditor = $this->getSingleObject();
     if (!$this->groupEditor->isAccessible() || $this->groupEditor->groupType != UserGroup::OTHER) {
         throw new PermissionDeniedException();
     }
 }
	/**
	 * 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();
	}
Example #4
0
	/**
	 * @see	wcf\page\IPage::assignVariables()
	 */
	public function assignVariables() {
		parent::assignVariables();
		
		I18nHandler::getInstance()->assignVariables(!empty($_POST));
		
		WCF::getTPL()->assign(array(
			'groupID' => $this->group->groupID,
			'group' => $this->group,
			'action' => 'edit'
		));
		
		// add warning when the initiator is in the group
		if ($this->group->isMember()) {
			WCF::getTPL()->assign('warningSelfEdit', true);
		}
	}
Example #5
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;
 }
Example #6
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();
	}
 /**
  * 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);
 }
 /**
  * @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();
 }