/**
  * @return class_admin_formgenerator|null
  */
 public function getAdminForm()
 {
     $objForm = parent::getAdminForm();
     $arrNavigationsDropdown = array();
     foreach (class_module_navigation_tree::getObjectList() as $objOneNavigation) {
         $arrNavigationsDropdown[$objOneNavigation->getSystemid()] = $objOneNavigation->getStrDisplayName();
     }
     $objForm->getField("repo")->setArrKeyValues($arrNavigationsDropdown);
     return $objForm;
 }
 /**
  * @see interface_admin_systemtask::executeTask()
  * @return string
  */
 public function executeTask()
 {
     if (!class_module_system_module::getModuleByName("navigation")->rightEdit()) {
         return $this->getLang("commons_error_permissions");
     }
     $strReturn = "";
     //load all navigation points, tree by tree
     $arrTrees = class_module_navigation_tree::getObjectList();
     foreach ($arrTrees as $objOneTree) {
         $strReturn .= $this->getLang("systemtask_navigationcheck_treescan") . " \"" . $objOneTree->getStrName() . "\"...<br />";
         if (validateSystemid($objOneTree->getStrFolderId())) {
             $strReturn .= $this->getLang("systemtask_navigationcheck_autogenerated") . "<br />";
         } else {
             $strReturn .= $this->processLevel($objOneTree->getSystemid(), 0) . "<br />";
         }
     }
     return $strReturn;
 }
 public function testGeneration()
 {
     echo "test auto navigation...\n";
     class_carrier::getInstance()->getObjDB()->flushQueryCache();
     $objTestNavigation = new class_module_navigation_tree();
     $objTestNavigation->setStrName("autotest");
     $objTestNavigation->setStrFolderId(self::$strFolderSystemid);
     $objTestNavigation->updateObjectToDb();
     $arrNodes = $objTestNavigation->getCompleteNaviStructure();
     $this->assertEquals(2, count($arrNodes["subnodes"]));
     $objFirstNode = $arrNodes["subnodes"][0]["node"];
     $this->assertEquals("testpage1", $objFirstNode->getStrName());
     $this->assertEquals("testpage1", $objFirstNode->getStrPageI());
     $objFirstNode = $arrNodes["subnodes"][1]["node"];
     $this->assertEquals("testpage2", $objFirstNode->getStrName());
     $this->assertEquals("testpage2a", $objFirstNode->getStrPageI());
     $arrNodesOnSecLevel = $arrNodes["subnodes"][1]["subnodes"][0];
     $this->assertEquals(0, count($arrNodesOnSecLevel["subnodes"]));
     $objFirstNode = $arrNodesOnSecLevel["node"];
     $this->assertEquals("testpage2a", $objFirstNode->getStrName());
     $this->assertEquals("testpage2a", $objFirstNode->getStrPageI());
     $objTestNavigation->deleteObjectFromDatabase();
 }
 /**
  * Saves or updates a navigation
  *
  * @throws class_exception
  * @return string, "" in case of success
  * @permissions edit
  */
 protected function actionSaveNavi()
 {
     $strReturn = "";
     $objNavi = new class_module_navigation_tree();
     if ($this->getParam("mode") == "edit") {
         $objNavi = new class_module_navigation_tree($this->getSystemid());
         if (!$objNavi->rightEdit()) {
             return $this->getLang("commons_error_permissions");
         }
     }
     $objForm = $this->getNaviAdminForm($objNavi);
     if (!$objForm->validateForm()) {
         return $this->actionNewNavi($this->getParam("mode"), $objForm);
     }
     $objForm->updateSourceObject();
     $objNavi->setStrFolderId($this->getParam("navi_folder_i_id"));
     if (!$objNavi->updateObjectToDb()) {
         throw new class_exception("Error saving object to db", class_exception::$level_ERROR);
     }
     $this->adminReload(class_link::getLinkAdminHref($this->getArrModule("modul")));
     return $strReturn;
 }
 /**
  * Searches the current page in other navigation-trees found on the current page.
  * This can be useful to avoid a session-based "opening" of the current tree.
  * The user may find it confusing, if the current tree remains opened but he clicked
  * a navigation-point of another tree.
  *
  * @return bool
  */
 private function isPageVisibleInOtherNavigation()
 {
     //load the placeholders placed on the current page-template. therefore, instantiate a page-object
     $objPageData = class_module_pages_page::getPageByName($this->getPagename());
     $objMasterPageData = class_module_pages_page::getPageByName("master");
     if ($objPageData != null) {
         //analyze the placeholders on the page, faster than iterating the the elements available in the db
         $strTemplateId = $this->objTemplate->readTemplate("/module_pages/" . $objPageData->getStrTemplate());
         $arrElementsTemplate = array_merge($this->objTemplate->getElements($strTemplateId, 0), $this->objTemplate->getElements($strTemplateId, 1));
         //loop elements to remove navigation-elements. to do so, get the current elements-name (maybe the user renamed the default "navigation")
         foreach ($arrElementsTemplate as $arrPlaceholder) {
             if ($arrPlaceholder["placeholder"] != $this->arrElementData["page_element_ph_placeholder"]) {
                 //loop the elements-list
                 foreach ($arrPlaceholder["elementlist"] as $arrOneElement) {
                     if ($arrOneElement["element"] == $this->arrElementData["page_element_ph_element"]) {
                         //seems as we have a navigation-element different than the current one.
                         //check, if the element is installed on the current page
                         $arrElements = class_module_pages_pageelement::getElementsByPlaceholderAndPage($objPageData->getSystemid(), $arrPlaceholder["placeholder"], $this->getStrPortalLanguage());
                         //maybe on the masters-page?
                         if (count($arrElements) == 0 && $objMasterPageData != null) {
                             $arrElements = class_module_pages_pageelement::getElementsByPlaceholderAndPage($objMasterPageData->getSystemid(), $arrPlaceholder["placeholder"], $this->getStrPortalLanguage());
                         }
                         if (count($arrElements) > 0) {
                             foreach ($arrElements as $objElement) {
                                 //wohooooo, an element was found.
                                 //check, if the current point is in the tree linked by the navigation - if it's a different navigation....
                                 //load the real-pageelement
                                 $objRealElement = new class_element_navigation_portal($objElement);
                                 $arrContent = $objRealElement->getElementContent($objElement->getSystemid());
                                 if (count($arrContent) == 0) {
                                     continue;
                                 }
                                 //navigation found. trigger loading of nodes if not yet happend
                                 if (!isset($this->arrTempNodes[$arrContent["navigation_id"]])) {
                                     $objNavigation = new class_module_navigation_tree($arrContent["navigation_id"]);
                                     if ($objNavigation->getStatus() == 0) {
                                         $this->arrTempNodes[$arrContent["navigation_id"]] = array("node" => null, "subnodes" => array());
                                     } else {
                                         $this->arrTempNodes[$arrContent["navigation_id"]] = $objNavigation->getCompleteNaviStructure();
                                     }
                                 }
                                 //search navigation tree
                                 $this->arrNodeTempHelper = array();
                                 foreach ($this->arrTempNodes[$arrContent["navigation_id"]]["subnodes"] as $objOneNodeToScan) {
                                     $this->searchPageInNavigationTreeHelper(0, $this->strCurrentSite, $objOneNodeToScan);
                                 }
                                 $intMaxLevel = 0;
                                 $objEntry = null;
                                 foreach ($this->arrNodeTempHelper as $intLevel => $arrNodes) {
                                     if (count($arrNodes) > 0 && $intLevel >= $intMaxLevel) {
                                         $intMaxLevel = $intLevel;
                                         $objEntry = $arrNodes[0];
                                     }
                                 }
                                 //jepp, page found in another tree, so return true
                                 if ($objEntry != null) {
                                     return true;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return false;
 }
 /**
  * Does the hard work: installs the module and registers needed constants
  *
  * @return string
  */
 public function install()
 {
     //search the master page
     $objMaster = class_module_pages_page::getPageByName("master");
     if ($objMaster != null) {
         $this->strMasterID = $objMaster->getSystemid();
     }
     //fetch navifolder-id
     $strNaviFolderId = "";
     $arrFolder = class_module_pages_folder::getFolderList();
     foreach ($arrFolder as $objOneFolder) {
         if ($objOneFolder->getStrName() == "mainnavigation") {
             $strNaviFolderId = $objOneFolder->getSystemid();
         }
     }
     $strReturn = "";
     $strReturn .= "Creating new mainnavigation-tree\n";
     $objNaviTree = new class_module_navigation_tree();
     $objNaviTree->setStrName("mainnavigation");
     $objNaviTree->setStrFolderId($strNaviFolderId);
     $objNaviTree->updateObjectToDb();
     $strTreeId = $objNaviTree->getSystemid();
     $strReturn .= "ID of new navigation-tree: " . $strTreeId . "\n";
     $strReturn .= "Creating new portalnavigation-tree\n";
     $objNaviTree = new class_module_navigation_tree();
     $objNaviTree->setStrName("portalnavigation");
     $objNaviTree->updateObjectToDb();
     $strTreePortalId = $objNaviTree->getSystemid();
     $strReturn .= "ID of new navigation-tree: " . $strTreePortalId . "\n";
     $strReturn .= "Creating navigation points\n";
     $objNaviPoint = new class_module_navigation_point();
     $objNaviPoint->setStrName("Home");
     $objNaviPoint->setStrPageI("index");
     $objNaviPoint->updateObjectToDb($strTreePortalId);
     if ($this->strMasterID != "") {
         $strReturn .= "Adding mainnavigation to master page\n";
         $strReturn .= "ID of master page: " . $this->strMasterID . "\n";
         if (class_module_pages_element::getElement("navigation") != null) {
             $objPagelement = new class_module_pages_pageelement();
             $objPagelement->setStrPlaceholder("mastermainnavi_navigation");
             $objPagelement->setStrName("mastermainnavi");
             $objPagelement->setStrElement("navigation");
             $objPagelement->updateObjectToDb($this->strMasterID);
             $strElementId = $objPagelement->getSystemid();
             $strQuery = "UPDATE " . _dbprefix_ . "element_navigation\n                                SET navigation_id= ?,\n                                    navigation_template = ?\n                                WHERE content_id = ?";
             if ($this->objDB->_pQuery($strQuery, array($strTreeId, "mainnavi.tpl", $strElementId))) {
                 $strReturn .= "Navigation element created.\n";
             } else {
                 $strReturn .= "Error creating navigation element.\n";
             }
         }
         $strReturn .= "Adding portalnavigation to master page\n";
         $strReturn .= "ID of master page: " . $this->strMasterID . "\n";
         if (class_module_pages_element::getElement("navigation") != null) {
             $objPagelement = new class_module_pages_pageelement();
             $objPagelement->setStrPlaceholder("masterportalnavi_navigation");
             $objPagelement->setStrName("masterportalnavi");
             $objPagelement->setStrElement("navigation");
             $objPagelement->updateObjectToDb($this->strMasterID);
             $strElementId = $objPagelement->getSystemid();
             $strQuery = "UPDATE " . _dbprefix_ . "element_navigation\n                                SET navigation_id= ?,\n                                    navigation_template = ?\n                                WHERE content_id = ?";
             if ($this->objDB->_pQuery($strQuery, array($strTreePortalId, "portalnavi.tpl", $strElementId))) {
                 $strReturn .= "Navigation element created.\n";
             } else {
                 $strReturn .= "Error creating navigation element.\n";
             }
         }
         $strReturn .= "Adding pathnavigation to master page\n";
         $strReturn .= "ID of master page: " . $this->strMasterID . "\n";
         if (class_module_pages_element::getElement("navigation") != null) {
             $objPagelement = new class_module_pages_pageelement();
             $objPagelement->setStrPlaceholder("masterpathnavi_navigation");
             $objPagelement->setStrName("masterpathnavi");
             $objPagelement->setStrElement("navigation");
             $objPagelement->updateObjectToDb($this->strMasterID);
             $strElementId = $objPagelement->getSystemid();
             $strQuery = "UPDATE " . _dbprefix_ . "element_navigation\n                                SET navigation_id= ?,\n                                    navigation_template = ?\n                                WHERE content_id = ?";
             if ($this->objDB->_pQuery($strQuery, array($strTreeId, "breadcrumbnavi.tpl", $strElementId))) {
                 $strReturn .= "Navigation element created.\n";
             } else {
                 $strReturn .= "Error creating navigation element.\n";
             }
         }
     }
     $strReturn .= "Creating simple sitemap...\n";
     $objPage = new class_module_pages_page();
     $objPage->setStrName("sitemap");
     $objPage->setStrBrowsername("Sitemap");
     $objPage->setStrTemplate("standard.tpl");
     $objPage->updateObjectToDb();
     $strSitemapId = $objPage->getSystemid();
     $strReturn .= "ID of new page: " . $strSitemapId . "\n";
     $strReturn .= "Adding sitemap to new page\n";
     if (class_module_pages_element::getElement("navigation") != null) {
         $objPagelement = new class_module_pages_pageelement();
         $objPagelement->setStrPlaceholder("special_news|guestbook|downloads|gallery|galleryRandom|form|tellafriend|maps|search|navigation|faqs|postacomment|votings|userlist|rssfeed|tagto|portallogin|portalregistration|portalupload|directorybrowser|lastmodified|tagcloud|downloadstoplist|flash|mediaplayer|tags|eventmanager");
         $objPagelement->setStrName("special");
         $objPagelement->setStrElement("navigation");
         $objPagelement->updateObjectToDb($strSitemapId);
         $strElementId = $objPagelement->getSystemid();
         $strQuery = "UPDATE " . _dbprefix_ . "element_navigation\n                            SET navigation_id=?,\n                                navigation_template = ?\n                                WHERE content_id = ?";
         if ($this->objDB->_pQuery($strQuery, array($strTreeId, "sitemap.tpl", $strElementId))) {
             $strReturn .= "Sitemapelement created.\n";
         } else {
             $strReturn .= "Error creating sitemapelement.\n";
         }
     }
     $strReturn .= "Adding headline-element to new page\n";
     if (class_module_pages_element::getElement("row") != null) {
         $objPagelement = new class_module_pages_pageelement();
         $objPagelement->setStrPlaceholder("headline_row");
         $objPagelement->setStrName("headline");
         $objPagelement->setStrElement("row");
         $objPagelement->updateObjectToDb($strSitemapId);
         $strElementId = $objPagelement->getSystemid();
         $strQuery = "UPDATE " . _dbprefix_ . "element_paragraph\n                            SET paragraph_title = ?\n                          WHERE content_id = ? ";
         if ($this->objDB->_pQuery($strQuery, array("Sitemap", $strElementId))) {
             $strReturn .= "Headline element created.\n";
         } else {
             $strReturn .= "Error creating headline element.\n";
         }
     }
     $strReturn .= "Creating navigation points\n";
     $objNaviPoint = new class_module_navigation_point();
     $objNaviPoint->setStrName("Sitemap");
     $objNaviPoint->setStrPageI("sitemap");
     $objNaviPoint->updateObjectToDb($strTreePortalId);
     $strReturn .= "ID of new navigation point " . $objNaviPoint->getSystemid() . ".\n";
     $objNaviPoint = new class_module_navigation_point();
     if ($this->strContentLanguage == "de") {
         $objNaviPoint->setStrName("Impressum");
     } else {
         $objNaviPoint->setStrName("Imprint");
     }
     $objNaviPoint->setStrPageI("imprint");
     $objNaviPoint->updateObjectToDb($strTreePortalId);
     $strReturn .= "ID of new navigation point " . $objNaviPoint->getSystemid() . ".\n";
     return $strReturn;
 }
 /**
  * Removes the elements / modules handled by the current installer.
  * Use the reference param to add a human readable logging.
  *
  * @param string &$strReturn
  *
  * @return bool
  */
 public function remove(&$strReturn)
 {
     //delete the page-element
     $objElement = class_module_pages_element::getElement("navigation");
     if ($objElement != null) {
         $strReturn .= "Deleting page-element 'navigation'...\n";
         $objElement->deleteObjectFromDatabase();
     } else {
         $strReturn .= "Error finding page-element 'navigation', aborting.\n";
         return false;
     }
     /** @var class_module_navigation_tree $objOneObject */
     foreach (class_module_navigation_tree::getObjectList() as $objOneObject) {
         $strReturn .= "Deleting object '" . $objOneObject->getStrDisplayName() . "' ...\n";
         if (!$objOneObject->deleteObjectFromDatabase()) {
             $strReturn .= "Error deleting object, aborting.\n";
             return false;
         }
     }
     //delete the module-node
     $strReturn .= "Deleting the module-registration...\n";
     $objModule = class_module_system_module::getModuleByName($this->objMetadata->getStrTitle(), true);
     if (!$objModule->deleteObjectFromDatabase()) {
         $strReturn .= "Error deleting module, aborting.\n";
         return false;
     }
     //delete the tables
     foreach (array("navigation", "element_navigation") as $strOneTable) {
         $strReturn .= "Dropping table " . $strOneTable . "...\n";
         if (!$this->objDB->_pQuery("DROP TABLE " . $this->objDB->encloseTableName(_dbprefix_ . $strOneTable) . "", array())) {
             $strReturn .= "Error deleting table, aborting.\n";
             return false;
         }
     }
     return true;
 }
 /**
  * Does the hard work: installs the module and registers needed constants
  */
 public function install()
 {
     $strReturn = "";
     //fetch navifolder-id
     //navigations installed?
     $objModule = null;
     try {
         $objModule = class_module_system_module::getModuleByName("pages", true);
     } catch (class_exception $objException) {
         $objModule = null;
     }
     if ($objModule != null) {
         $strSystemFolderId = "";
         $arrFolder = class_module_pages_folder::getFolderList();
         foreach ($arrFolder as $objOneFolder) {
             if ($objOneFolder->getStrName() == "_system") {
                 $strSystemFolderId = $objOneFolder->getSystemid();
             }
         }
         //search the master page
         $objMaster = class_module_pages_page::getPageByName("master");
         if ($objMaster != null) {
             $this->strMasterID = $objMaster->getSystemid();
         }
         $strReturn .= "Adding search-element to master page\n";
         if ($this->strMasterID != "" && class_module_pages_element::getElement("search") != null) {
             $objPagelement = new class_module_pages_pageelement();
             $objPagelement->setStrPlaceholder("mastersearch_search");
             $objPagelement->setStrName("mastersearch");
             $objPagelement->setStrElement("search");
             $objPagelement->updateObjectToDb($this->strMasterID);
             $strElementId = $objPagelement->getSystemid();
             $strQuery = "UPDATE " . _dbprefix_ . "element_search\n                                        SET search_template = ?,\n                                            search_amount = ?,\n                                            search_page = ?\n                                        WHERE content_id = ?";
             if ($this->objDB->_pQuery($strQuery, array("search_ajax_small.tpl", 0, "search", $strElementId))) {
                 $strReturn .= "Search element created.\n";
             } else {
                 $strReturn .= "Error creating search element.\n";
             }
         }
         $strReturn .= "Creating search page\n";
         $objPage = new class_module_pages_page();
         $objPage->setStrName("search");
         if ($this->strContentLanguage == "de") {
             $objPage->setStrBrowsername("Suchergebnisse");
         } else {
             $objPage->setStrBrowsername("Search results");
         }
         $objPage->setStrTemplate("standard.tpl");
         $objPage->updateObjectToDb($strSystemFolderId);
         $strSearchresultsId = $objPage->getSystemid();
         $strReturn .= "ID of new page: " . $strSearchresultsId . "\n";
         $strReturn .= "Adding search-element to new page\n";
         if (class_module_pages_element::getElement("search") != null) {
             $objPagelement = new class_module_pages_pageelement();
             $objPagelement->setStrPlaceholder("special_news|guestbook|downloads|gallery|galleryRandom|form|tellafriend|maps|search|navigation|faqs|postacomment|votings|userlist|rssfeed|tagto|portallogin|portalregistration|portalupload|directorybrowser|lastmodified|tagcloud|downloadstoplist|flash|mediaplayer|tags|eventmanager");
             $objPagelement->setStrName("special");
             $objPagelement->setStrElement("search");
             $objPagelement->updateObjectToDb($strSearchresultsId);
             $strElementId = $objPagelement->getSystemid();
             $strQuery = "UPDATE " . _dbprefix_ . "element_search\n                                        SET search_template = ?,\n                                            search_amount = ?,\n                                            search_page = ?\n                                        WHERE content_id = ?";
             if ($this->objDB->_pQuery($strQuery, array("search_ajax.tpl", 0, "", $strElementId))) {
                 $strReturn .= "Search element created.\n";
             } else {
                 $strReturn .= "Error creating search element.\n";
             }
         }
         $strReturn .= "Adding headline-element to new page\n";
         if (class_module_pages_element::getElement("row") != null) {
             $objPagelement = new class_module_pages_pageelement();
             $objPagelement->setStrPlaceholder("headline_row");
             $objPagelement->setStrName("headline");
             $objPagelement->setStrElement("row");
             $objPagelement->updateObjectToDb($strSearchresultsId);
             $strElementId = $objPagelement->getSystemid();
             $arrParams = array();
             if ($this->strContentLanguage == "de") {
                 $arrParams = array("Suchergebnisse", $strElementId);
             } else {
                 $arrParams = array("Search results", $strElementId);
             }
             $strQuery = "UPDATE " . _dbprefix_ . "element_paragraph\n                                        SET paragraph_title = ?\n                                        WHERE content_id = ?";
             if ($this->objDB->_pQuery($strQuery, $arrParams)) {
                 $strReturn .= "Headline element created.\n";
             } else {
                 $strReturn .= "Error creating headline element.\n";
             }
         }
     }
     $strReturn .= "Creating navigation point.\n";
     //navigations installed?
     $objModule = null;
     try {
         $objModule = class_module_system_module::getModuleByName("navigation", true);
     } catch (class_exception $objException) {
         $objModule = null;
     }
     if ($objModule != null) {
         $objNavi = class_module_navigation_tree::getNavigationByName("portalnavigation");
         $strTreeId = $objNavi->getSystemid();
         $objNaviPoint = new class_module_navigation_point();
         if ($this->strContentLanguage == "de") {
             $objNaviPoint->setStrName("Suche");
         } else {
             $objNaviPoint->setStrName("Search");
         }
         $objNaviPoint->setStrPageI("search");
         $objNaviPoint->updateObjectToDb($strTreeId);
         $strReturn .= "ID of new navigation point: " . $objNaviPoint->getSystemid() . "\n";
     }
     return $strReturn;
 }