/**
  * @see Action::execute()
  */
 public function execute()
 {
     parent::execute();
     // check permission
     WCF::getUser()->checkPermission('admin.user.option.canDeleteOption');
     // delete user option
     require_once WCF_DIR . 'lib/data/user/option/UserOptionEditor.class.php';
     $userOption = new UserOptionEditor($this->optionID);
     if (!$userOption->optionID) {
         throw new IllegalLinkException();
     }
     $userOption->delete();
     // delete cache
     WCF::getCache()->clear(WCF_DIR . 'cache', 'cache.user-option-*');
     $this->executed();
     // forward to list page
     HeaderUtil::redirect('index.php?page=UserOptionList&deletedOptionID=' . $this->optionID . '&packageID=' . PACKAGE_ID . SID_ARG_2ND_NOT_ENCODED);
     exit;
 }
 /**
  * @see Form::save()
  */
 public function save()
 {
     parent::save();
     // create random name
     $name = "userOption" . time();
     // save option
     $this->optionID = UserOptionEditor::create($name, $this->categoryName, $this->optionType, $this->defaultValue, $this->validationPattern, $this->selectOptions, '', $this->required, $this->askDuringRegistration, $this->editable, $this->visible, $this->getOutputClass(), $this->searchable, $this->showOrder);
     // change random name
     $name = "userOption" . $this->optionID;
     WCF::getDB()->sendQuery("UPDATE\t\twcf" . WCF_N . "_user_option\n\t\t\t\t\tSET\t\toptionName = '{$name}'\n\t\t\t\t\tWHERE \t\toptionID = " . $this->optionID);
     // save language variables
     require_once WCF_DIR . 'lib/system/language/LanguageEditor.class.php';
     $language = new LanguageEditor(WCF::getLanguage()->getLanguageID());
     $language->updateItems(array('wcf.user.option.' . $name => $this->optionName, 'wcf.user.option.' . $name . '.description' => $this->optionDescription));
     // delete cache
     WCF::getCache()->clear(WCF_DIR . 'cache', 'cache.user-option-*');
     $this->saved();
     // reset values
     $this->optionName = $this->optionDescription = $this->categoryName = $this->optionType = $this->defaultValue = $this->validationPattern = '';
     $this->optionType = $this->selectOptions = '';
     $this->required = $this->editable = $this->visible = $this->searchable = $this->showOrder = $this->askDuringRegistration = 0;
     // show success message
     WCF::getTPL()->assign('success', true);
 }
 /**
  * @see	 AbstractOptionPackageInstallationPlugin::saveOption()
  */
 protected function saveOption($option, $categoryName, $existingOptionID = 0)
 {
     // default values
     $optionName = $optionType = $defaultValue = $validationPattern = $outputClass = $selectOptions = $enableOptions = $permissions = $options = '';
     $required = $editable = $visible = $searchable = $disabled = $askDuringRegistration = 0;
     $showOrder = null;
     // make xml tags-names (keys in array) to lower case
     $this->keysToLowerCase($option);
     // get values
     if (isset($option['name'])) {
         $optionName = $option['name'];
     }
     if (isset($option['optiontype'])) {
         $optionType = $option['optiontype'];
     }
     if (isset($option['defaultvalue'])) {
         $defaultValue = $option['defaultvalue'];
     }
     if (isset($option['validationpattern'])) {
         $validationPattern = $option['validationpattern'];
     }
     if (isset($option['required'])) {
         $required = intval($option['required']);
     }
     if (isset($option['askduringregistration'])) {
         $askDuringRegistration = intval($option['askduringregistration']);
     }
     if (isset($option['editable'])) {
         $editable = intval($option['editable']);
     }
     if (isset($option['visible'])) {
         $visible = intval($option['visible']);
     }
     if (isset($option['searchable'])) {
         $searchable = intval($option['searchable']);
     }
     if (isset($option['showorder'])) {
         $showOrder = intval($option['showorder']);
     }
     if (isset($option['outputclass'])) {
         $outputClass = $option['outputclass'];
     }
     if (isset($option['selectoptions'])) {
         $selectOptions = $option['selectoptions'];
     }
     if (isset($option['enableoptions'])) {
         $enableOptions = $option['enableoptions'];
     }
     if (isset($option['disabled'])) {
         $disabled = intval($option['disabled']);
     }
     $showOrder = $this->getShowOrder($showOrder, $categoryName, 'categoryName');
     if (isset($option['permissions'])) {
         $permissions = $option['permissions'];
     }
     if (isset($option['options'])) {
         $options = $option['options'];
     }
     // check if optionType exists
     $classFile = WCF_DIR . 'lib/acp/option/OptionType' . ucfirst($optionType) . '.class.php';
     if (!@file_exists($classFile)) {
         throw new SystemException('Unable to find file ' . $classFile, 11002);
     }
     // collect additional tags and their values
     $additionalData = array();
     foreach ($option as $tag => $value) {
         if (!in_array($tag, self::$reservedTags)) {
             $additionalData[$tag] = $value;
         }
     }
     // get optionID if it was installed by this package already
     $sql = "SELECT\t*\n\t\t\tFROM \twcf" . WCF_N . "_" . $this->tableName . "\n\t\t\tWHERE \toptionName = '" . escapeString($optionName) . "'\n\t\t\tAND\tpackageID = " . $this->installation->getPackageID();
     $result = WCF::getDB()->getFirstRow($sql);
     // update option
     if (!empty($result['optionID']) && $this->installation->getAction() == 'update') {
         $userOption = new UserOptionEditor(null, $result);
         $userOption->update($optionName, $categoryName, $optionType, $defaultValue, $validationPattern, $selectOptions, $enableOptions, $required, $askDuringRegistration, $editable, $visible, $outputClass, $searchable, $showOrder, $disabled, $permissions, $options, $additionalData);
     } else {
         UserOptionEditor::create($optionName, $categoryName, $optionType, $defaultValue, $validationPattern, $selectOptions, $enableOptions, $required, $askDuringRegistration, $editable, $visible, $outputClass, $searchable, $showOrder, $disabled, $this->installation->getPackageID(), $permissions, $options, $additionalData);
     }
 }