/**
  * generates frame layout
  */
 function layout($a_xml = "main.xml", $doShow = true)
 {
     global $tpl, $ilSetting, $ilCtrl, $ilUser;
     $layout = $this->determineLayout();
     // xmldocfile is deprecated! Use domxml_open_file instead.
     // But since using relative pathes with domxml under windows don't work,
     // we need another solution:
     $xmlfile = file_get_contents("./Modules/LearningModule/layouts/lm/" . $layout . "/" . $a_xml);
     if (!($doc = domxml_open_mem($xmlfile))) {
         include_once "./Modules/LearningModule/exceptions/class.ilLMPresentationException.php";
         throw new ilLMPresentationException("ilLMPresentation: XML File invalid. Error reading " . $layout . "/" . $a_xml . ".");
     }
     $this->layout_doc = $doc;
     //echo ":".htmlentities($xmlfile).":$layout:$a_xml:";
     // get current frame node
     $xpc = xpath_new_context($doc);
     $path = empty($_GET["frame"]) || $_GET["frame"] == "_blank" ? "/ilLayout/ilFrame[1]" : "//ilFrame[@name='" . $_GET["frame"] . "']";
     $result = xpath_eval($xpc, $path);
     $found = $result->nodeset;
     if (count($found) != 1) {
         include_once "./Modules/LearningModule/exceptions/class.ilLMPresentationException.php";
         throw new ilLMPresentationException("ilLMPresentation: XML File invalid. Found " . count($found) . " nodes for " . " path " . $path . " in " . $layout . "/" . $a_xml . ". LM Layout is " . $this->lm->getLayout());
     }
     $node = $found[0];
     // ProcessFrameset
     // node is frameset, if it has cols or rows attribute
     $attributes = $this->attrib2arr($node->attributes());
     $this->frames = array();
     if (!empty($attributes["rows"]) || !empty($attributes["cols"])) {
         $content .= $this->buildTag("start", "frameset", $attributes);
         //$this->frames = array();
         $this->processNodes($content, $node);
         $content .= $this->buildTag("end", "frameset");
         $this->tpl = new ilTemplate("tpl.frameset.html", true, true, "Modules/LearningModule");
         $this->renderPageTitle();
         $this->tpl->setVariable("FS_CONTENT", $content);
         if (!$doshow) {
             $content = $this->tpl->get();
         }
     } else {
         // ProcessContentTag
         //if ((empty($attributes["template"]) || !empty($_GET["obj_type"])))
         if ((empty($attributes["template"]) || !empty($_GET["obj_type"])) && ($_GET["frame"] != "_blank" || $_GET["obj_type"] != "MediaObject")) {
             // we got a variable content frame (can display different
             // object types (PageObject, MediaObject, GlossarItem)
             // and contains elements for them)
             // determine object type
             if (empty($_GET["obj_type"])) {
                 $obj_type = "PageObject";
             } else {
                 $obj_type = $_GET["obj_type"];
             }
             // get object specific node
             $childs = $node->child_nodes();
             $found = false;
             foreach ($childs as $child) {
                 if ($child->node_name() == $obj_type) {
                     $found = true;
                     $attributes = $this->attrib2arr($child->attributes());
                     $node = $child;
                     //echo "<br>2node:".$node->node_name();
                     break;
                 }
             }
             if (!$found) {
                 echo "ilLMPresentation: No template specified for frame '" . $_GET["frame"] . "' and object type '" . $obj_type . "'.";
                 exit;
             }
         }
         // get template
         $in_module = $attributes["template_location"] == "module" ? true : false;
         if ($in_module) {
             $this->tpl = new ilTemplate($attributes["template"], true, true, $in_module);
             $this->tpl->setBodyClass("");
         } else {
             $this->tpl = $tpl;
         }
         // set style sheets
         if (!$this->offlineMode()) {
             $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
         } else {
             $style_name = $ilUser->getPref("style") . ".css";
             $this->tpl->setVariable("LOCATION_STYLESHEET", "./style/" . $style_name);
         }
         include_once "./Services/jQuery/classes/class.iljQueryUtil.php";
         iljQueryUtil::initjQuery($this->tpl);
         iljQueryUtil::initjQueryUI($this->tpl);
         include_once "./Services/UICore/classes/class.ilUIFramework.php";
         ilUIFramework::init($this->tpl);
         // to make e.g. advanced seletions lists work:
         $GLOBALS["tpl"] = $this->tpl;
         $childs = $node->child_nodes();
         foreach ($childs as $child) {
             $child_attr = $this->attrib2arr($child->attributes());
             switch ($child->node_name()) {
                 case "ilMainMenu":
                     $this->ilMainMenu();
                     $this->renderPageTitle();
                     break;
                 case "ilTOC":
                     $this->ilTOC($child_attr["target_frame"]);
                     break;
                 case "ilPage":
                     switch ($this->lm->getType()) {
                         case "lm":
                             unset($_SESSION["tr_id"]);
                             unset($_SESSION["bib_id"]);
                             unset($_SESSION["citation"]);
                             $content = $this->ilPage($child);
                             break;
                     }
                     break;
                 case "ilGlossary":
                     $content = $this->ilGlossary($child);
                     break;
                 case "ilLMNavigation":
                     $this->ilLMNavigation();
                     break;
                 case "ilMedia":
                     $this->ilMedia();
                     break;
                 case "ilLocator":
                     $this->ilLocator();
                     break;
                 case "ilJavaScript":
                     $this->ilJavaScript($child_attr["inline"], $child_attr["file"], $child_attr["location"]);
                     break;
                 case "ilLMMenu":
                     $this->ilLMMenu();
                     break;
                 case "ilLMHead":
                     $this->ilLMHead();
                     break;
                 case "ilLMSubMenu":
                     $this->ilLMSubMenu();
                     break;
                 case "ilLMNotes":
                     $this->ilLMNotes();
                     break;
             }
         }
         // TODO: Very dirty hack to force the import of JavaScripts in learning content in the FAQ frame (e.g. if jsMath is in the content)
         // Unfortunately there is no standardized way to do this somewhere else. Calling fillJavaScripts always in ilTemplate causes multiple additions of the the js files.
         // 19.7.2014: outcommented, since fillJavaScriptFiles is called in the next blocks, and the
         // following lines would add the js files two times
         //			if (strcmp($_GET["frame"], "topright") == 0) $this->tpl->fillJavaScriptFiles();
         //			if (strcmp($_GET["frame"], "right") == 0) $this->tpl->fillJavaScriptFiles();
         //			if (strcmp($_GET["frame"], "botright") == 0) $this->tpl->fillJavaScriptFiles();
         if (!$this->offlineMode()) {
             include_once "./Services/Accordion/classes/class.ilAccordionGUI.php";
             ilAccordionGUI::addJavaScript();
             ilAccordionGUI::addCss();
             $this->tpl->addJavascript("./Modules/LearningModule/js/LearningModule.js");
             include_once "./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php";
             $close_call = "il.LearningModule.setCloseHTML('" . ilGlyphGUI::get(ilGlyphGUI::CLOSE) . "');";
             $this->tpl->addOnLoadCode($close_call);
             //$store->set("cf_".$this->lm->getId());
             // handle initial content
             if ($_GET["frame"] == "") {
                 include_once "./Services/Authentication/classes/class.ilSessionIStorage.php";
                 $store = new ilSessionIStorage("lm");
                 $last_frame_url = $store->get("cf_" . $this->lm->getId());
                 if ($last_frame_url != "") {
                     $this->tpl->addOnLoadCode("il.LearningModule.setLastFrameUrl('" . $last_frame_url . "', 'center_bottom');");
                 }
                 if (in_array($layout, array("toc2windyn"))) {
                     $this->tpl->addOnLoadCode("il.LearningModule.setSaveUrl('" . $ilCtrl->getLinkTarget($this, "saveFrameUrl", "", false, false) . "');\n\t\t\t\t\t\t\til.LearningModule.openInitFrames();\n\t\t\t\t\t\t\t");
                 }
                 $this->tpl->addOnLoadCode("il.LearningModule.setTocRefreshUrl('" . $ilCtrl->getLinkTarget($this, "refreshToc", "", false, false) . "');\n\t\t\t\t\t\t\t");
             }
             // from main menu
             //				$this->tpl->addJavascript("./Services/JavaScript/js/Basic.js");
             $this->tpl->addJavascript("./Services/Navigation/js/ServiceNavigation.js");
             $this->tpl->fillJavaScriptFiles();
             $this->tpl->fillScreenReaderFocus();
             $this->tpl->fillCssFiles();
         } else {
             // reset standard css files
             $this->tpl->resetJavascript();
             $this->tpl->resetCss();
             include_once "./Modules/LearningModule/classes/class.ilObjContentObject.php";
             foreach (ilObjContentObject::getSupplyingExportFiles() as $f) {
                 if ($f["type"] == "js") {
                     $this->tpl->addJavascript($f["target"]);
                 }
                 if ($f["type"] == "css") {
                     $this->tpl->addCSS($f["target"]);
                 }
             }
             $this->tpl->fillJavaScriptFiles(true);
             $this->tpl->fillCssFiles(true);
         }
         $this->tpl->fillBodyClass();
     }
     if ($doShow) {
         // (horrible) workaround for preventing template engine
         // from hiding paragraph text that is enclosed
         // in curly brackets (e.g. "{a}", see ilPageObjectGUI::showPage())
         $this->tpl->fillTabs();
         if ($this->fill_on_load_code) {
             $this->tpl->fillOnLoadCode();
         }
         $content = $this->tpl->get();
         $content = str_replace("&#123;", "{", $content);
         $content = str_replace("&#125;", "}", $content);
         header('Content-type: text/html; charset=UTF-8');
         echo $content;
     } else {
         $this->tpl->fillLeftNav();
         $this->tpl->fillOnLoadCode();
         $content = $this->tpl->get();
     }
     return $content;
 }