/**
  * @see	Action::execute()
  */
 public function execute()
 {
     parent::execute();
     // remove entries
     DynamicPageEditor::remove($this->pageID);
     $this->page->moduleManager->remove();
     // clear cache
     DynamicPageEditor::clearCache($this->pageID, $this->page->hostID);
     // page menu entry
     if ($this->page->menuItemID) {
         require_once WCF_DIR . 'lib/data/page/menu/PageMenuItemEditor.class.php';
         // create editor object
         $menuItem = new PageMenuItemEditor($this->page->menuItemID);
         // remove item
         $menuItem->remove();
         // clear cache
         PageMenuItemEditor::clearCache();
     }
     // send redirect headers
     if (!isset($_REQUEST['ajax'])) {
         HeaderUtil::redirect('index.php?page=DynamicPageList&hostID=' . $this->page->hostID . '&packageID=' . PACKAGE_ID . SID_ARG_2ND_NOT_ENCODED);
     }
     // call event
     $this->executed();
 }
 /**
  * @see Form::save()
  */
 public function save()
 {
     ACPForm::save();
     // read variables
     $this->page->title = $this->title;
     $this->page->allowSpidersToIndexThisPage = $this->allowSpidersToIndexThisPage;
     $this->page->additionalHeadContent = $this->additionalHeadContent;
     $this->page->isPublic = $this->isPublic;
     $this->page->isDefaultPage = $this->isDefaultPage;
     // update
     $this->page->update();
     // handle isDefaultPage checkbox
     if ($this->isDefaultPage) {
         $sql = "UPDATE\r\n\t\t\t\t\t\twcf" . WCF_N . "_page\r\n\t\t\t\t\tSET\r\n\t\t\t\t\t\tisDefaultPage = 0\r\n\t\t\t\t\tWHERE\r\n\t\t\t\t\t\tpageID NOT IN (" . $this->page->pageID . ")";
         WCF::getDB()->sendQuery($sql);
     }
     DynamicPageEditor::clearCache($this->page->pageID, $this->page->hostID);
     if ($this->menuEntry !== null) {
         // create language variable name
         $lang = 'wcf.header.menu.host' . $this->page->hostID . '.page' . $this->pageID;
         // get menu entry title
         $title = empty($this->menuItemTitle) ? $this->title : $this->menuItemTitle;
         // update menu entry
         $this->menuEntry->update($lang, $this->menuEntry->menuItemLink, $this->menuItemIconS, $this->menuItemIconM, $this->menuItemSortOrder, $this->menuItemPosition);
         // enable or disable entry
         $this->menuEntry->enable($this->isPublic);
         // update language
         require_once WCF_DIR . 'lib/system/language/LanguageEditor.class.php';
         $language = new LanguageEditor(WCF::getLanguage()->getLanguageID());
         $language->updateItems(array($lang => $title));
         // clear cache
         PageMenuItemEditor::clearCache();
     }
     if ($this->createMenuItem) {
         // build language var
         $lang = 'wcf.header.menu.host' . $this->page->hostID . '.page' . $item->pageID;
         $title = empty($this->menuItemTitle) ? $this->title : $this->menuItemTitle;
         // create menu item
         $menuItem = PageMenuItemEditor::create($lang, 'index.php?page=CMS&pageID=' . $this->pageID, $this->menuItemIconS, $this->menuItemIconM, $this->menuItemSortOrder, $this->menuItemPosition);
         $menuItemID = $menuItem->menuItemID;
         // clear cache
         PageMenuItemEditor::clearCache();
         // create language var
         require_once WCF_DIR . 'lib/system/language/LanguageEditor.class.php';
         // save language variable
         $language = new LanguageEditor(WCF::getLanguage()->getLanguageID());
         $language->updateItems(array($lang => $title));
         // include host
         require_once WCF_DIR . 'lib/data/host/Host.class.php';
         // remove menu item ID cache
         Host::removeMenuItemIDCache();
     }
     // show success message
     WCF::getTPL()->assign('success', true);
 }
 /**
  * @see	Action::execute()
  */
 public function execute()
 {
     parent::execute();
     // remove host
     HostEditor::remove($this->hostID);
     DynamicPageEditor::removeFromHost($this->hostID);
     // send redirect headers
     HeaderUtil::redirect('index.php?page=DynamicHostList&packageID=' . PACKAGE_ID . SID_ARG_2ND_NOT_ENCODED);
     // execute event
     $this->executed();
 }
 /**
  * @see	Form::save()
  */
 public function save()
 {
     parent::save();
     $menuItemID = 0;
     // create dynamic page
     $item = DynamicPageEditor::create($this->title, $this->allowSpidersToIndexThisPage, $this->additionalHeadContent, $menuItemID, $this->isPublic, $this->isDefaultPage, $this->hostID);
     DynamicPageEditor::clearCache($item->pageID, $this->hostID);
     // create menu item
     if ($this->createMenuItem) {
         require_once WCF_DIR . 'lib/data/page/menu/PageMenuItemEditor.class.php';
         // build language var
         $lang = 'wcf.header.menu.host' . $this->hostID . '.page' . $item->pageID;
         $title = empty($this->menuItemTitle) ? $this->title : $this->menuItemTitle;
         // create menu item
         $menuItem = PageMenuItemEditor::create($lang, 'index.php?page=CMS&pageID=' . $item->pageID, $this->menuItemIconS, $this->menuItemIconM, $this->menuItemSortOrder, $this->menuItemPosition);
         $menuItemID = $menuItem->menuItemID;
         // clear cache
         PageMenuItemEditor::clearCache();
         // enable or disable entry
         $menuItem->enable($this->isPublic);
         // create language var
         require_once WCF_DIR . 'lib/system/language/LanguageEditor.class.php';
         // save language variable
         $language = new LanguageEditor($this->host->languageID);
         $language->updateItems(array($lang => $title));
         // include host
         require_once WCF_DIR . 'lib/data/host/Host.class.php';
         // remove menu item ID cache
         Host::removeMenuItemIDCache();
     }
     // update menu item id
     $item->menuItemID = $menuItemID;
     $item->update();
     // write to property
     $this->newPage = $item;
     // send redirect headers
     HeaderUtil::redirect('index.php?form=DynamicPageEdit&pageID=' . $item->pageID . '&packageID=' . PACKAGE_ID . '&created=1' . SID_ARG_2ND_NOT_ENCODED);
     // call event
     $this->saved();
 }
 /**
  * @see PackageInstallationPlugin::install()
  */
 public function install()
 {
     parent::install();
     if (!($xml = $this->getXML())) {
         return;
     }
     // Create an array with the data blocks (import or delete) from the xml file.
     $XML = $xml->getElementTree('data');
     // Loop through the array and install or uninstall items.
     foreach ($XML['children'] as $key => $block) {
         if (count($block['children'])) {
             // Handle the import instructions
             if ($block['name'] == 'import') {
                 // Loop through items and create or update them.
                 foreach ($block['children'] as $module) {
                     $moduleInformation = $moduleOptions = $moduleOptionGroups = array();
                     // Extract item properties.
                     foreach ($module['children'] as $child) {
                         if ($child['name'] == 'options') {
                             foreach ($child['children'] as $option) {
                                 $newOption = array('name' => '', 'optiontype' => '', 'defaultvalue' => '', 'cssclass' => '', 'group' => '', 'displaydescription' => true, 'fields' => '');
                                 // Extract option properties.
                                 foreach ($option['children'] as $optionVar) {
                                     if (!isset($optionVar['cdata'])) {
                                         continue;
                                     }
                                     $newOption[$optionVar['name']] = $optionVar['cdata'];
                                 }
                                 // write option to options array
                                 $moduleOptions[] = $newOption;
                                 // remove temp array
                                 unset($newOption);
                             }
                             // exit loop
                             continue;
                         }
                         if ($child['name'] == 'optiongroups') {
                             foreach ($child['children'] as $option) {
                                 $newOptionGroup = array('name' => '');
                                 // Extract option group properties.
                                 foreach ($option['children'] as $optionVar) {
                                     if (!isset($optionVar['cdata'])) {
                                         continue;
                                     }
                                     $newOptionGroup[$optionVar['name']] = $optionVar['cdata'];
                                 }
                                 // write option group to option group array
                                 $moduleOptionGroups[] = $newOptionGroup;
                                 // remove temp array
                                 unset($newOptionGroup);
                             }
                             // exit loop
                             continue;
                         }
                         if (!isset($child['cdata'])) {
                             continue;
                         }
                         $moduleInformation[$child['name']] = $child['cdata'];
                     }
                     // default values
                     $name = $file = '';
                     // get values
                     if (isset($moduleInformation['name'])) {
                         $name = $moduleInformation['name'];
                     }
                     if (isset($moduleInformation['file'])) {
                         $file = $moduleInformation['file'];
                     }
                     // validate xml input
                     if (empty($name)) {
                         throw new SystemException("Required 'name' tag is missing", 13023);
                     }
                     if (empty($file)) {
                         throw new SystemException("Required 'file' tag is missing", 13023);
                     }
                     // include template editor
                     require_once WCF_DIR . 'lib/data/dynamic/page/module/template/DynamicPageModuleTemplateEditor.class.php';
                     // create module template
                     $template = DynamicPageModuleTemplateEditor::create($name, $file, $this->installation->getPackageID());
                     // clear cache
                     DynamicPageModuleTemplateEditor::clearCache();
                     // include group editor
                     require_once WCF_DIR . 'lib/data/dynamic/page/module/option/group/DynamicPageModuleOptionGroupEditor.class.php';
                     // create module option groups
                     foreach ($moduleOptionGroups as $group) {
                         // just for debugging
                         print_r($group);
                         // validate group xml
                         if (empty($group['name'])) {
                             throw new SystemException("Required 'name' tag is missing", 13023);
                         }
                         // create group
                         DynamicPageModuleOptionGroupEditor::create($group['name'], $template->moduleID);
                     }
                     // include option editor
                     require_once WCF_DIR . 'lib/data/dynamic/page/module/option/DynamicPageModuleOptionEditor.class.php';
                     // create module options
                     foreach ($moduleOptions as $option) {
                         // validate option xml
                         if (empty($option['name'])) {
                             throw new SystemException("Required 'name' tag is missing", 13023);
                         }
                         if (empty($option['optiontype'])) {
                             throw new SystemException("Required 'optiontype' tag is missing", 13023);
                         }
                         if (empty($option['group'])) {
                             throw new SystemException("Required 'group' tag is missing", 13023);
                         }
                         // convert fields
                         $option['displaydescription'] = (bool) intval($option['displaydescription']);
                         // validate group
                         if (($groupID = DynamicPageModuleOptionGroup::isValidGroup($option['group'], $template->moduleID)) === false) {
                             throw new SystemException("Unknown module option group '" . $option['group'] . "'");
                         }
                         // create option
                         DynamicPageModuleOptionEditor::create($option['name'], $option['optiontype'], $option['defaultvalue'], $option['cssclass'], $option['displaydescription'], $option['fields'], $groupID, $template->moduleID);
                     }
                 }
             } else {
                 if ($block['name'] == 'delete' && $this->installation->getAction() == 'update') {
                     // Loop through items and delete them.
                     $nameArray = array();
                     foreach ($block['children'] as $module) {
                         // Extract item properties.
                         foreach ($module['children'] as $child) {
                             if (!isset($child['cdata'])) {
                                 continue;
                             }
                             $module[$child['name']] = $child['cdata'];
                         }
                         // validate input
                         if (empty($module['name'])) {
                             throw new SystemException("Required 'name' attribute is missing", 13023);
                         }
                         $nameArray[] = $module['name'];
                     }
                     if (count($nameArray)) {
                         $sql = "SELECT\r\n\t\t\t\t    \t\t\t\tmoduleID\r\n\t\t\t\t    \t\t\tFROM\r\n\t\t\t\t    \t\t\t\twcf" . WCF_N . "_page_module\r\n\t\t\t\t    \t\t\tWHERE\r\n\t\t\t\t    \t\t\t\tpackageID = " . $this->installation->getPackageID() . "\r\n\t\t\t\t    \t\t\tAND\r\n\t\t\t\t    \t\t\t\tname IN ('" . implode("','", array_map('escapeString', $nameArray)) . "')";
                         $result = WCF::getDB()->sendQuery($sql);
                         // create needed variables
                         $moduleIDs = array();
                         // loop through modules
                         while ($row = WCF::getDB()->fetchArray($result)) {
                             $moduleIDs[] = $row['moduleID'];
                         }
                         // remove options
                         $sql = "DELETE FROM\r\n\t\t\t\t    \t\t\t\twcf" . WCF_N . "_page_module_option\r\n\t\t\t\t    \t\t\tWHERE\r\n\t\t\t\t    \t\t\t\tmoduleID IN (" . implode(',', $moduleIDs) . ")";
                         WCF::getDB()->sendQuery($sql);
                         // remove option groups
                         $sql = "DELETE FROM\r\n\t\t\t\t    \t\t\t\twcf" . WCF_N . "_gpage_module_option_group\r\n\t\t\t\t    \t\t\tWHERE\r\n\t\t\t\t    \t\t\t\tmoduleID IN (" . implode(',', $moduleIDs) . ")";
                         WCF::getDB()->sendQuery($sql);
                         // remove modules
                         $sql = "DELETE FROM\r\n\t\t\t\t\t\t\t    \twcf" . WCF_N . "_page_module\r\n\t\t\t\t\t\t\t\tWHERE\r\n\t\t\t\t    \t\t\t\tmoduleID IN (" . implode(',', $moduleIDs) . ")";
                         WCF::getDB()->sendQuery($sql);
                         // include template editor
                         require_once WCF_DIR . 'lib/data/dynamic/page/module/template/DynamicPageModuleTemplateEditor.class.php';
                         // clear cache
                         DynamicPageModuleTemplateEditor::clearCache();
                         // include dynamic page editor
                         require_once WCF_DIR . 'lib/data/dynamic/page/DynamicPageEditor.class.php';
                         // clear cache
                         DynamicPageEditor::clearCache('*', '*');
                     }
                 }
             }
         }
     }
 }