/**
  * Object specific configuration 
  *
  * @param int $a_obj_id object id
  */
 function configureByObjectId($a_obj_id)
 {
     if ($a_obj_id > 0) {
         include_once "./Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php";
         $this->setLocalizationLanguage(ilObjSAHSLearningModule::getAffectiveLocalization($a_obj_id));
         $glo_id = ilObjSAHSLearningModule::lookupAssignedGlossary($a_obj_id);
         if ($glo_id > 0) {
             $this->addIntLinkFilter(array("GlossaryItem"));
         }
     }
 }
 /**
  * Post output processing:
  * - Add glossary divs
  */
 function postOutputProcessing($a_output)
 {
     //var_dump($this->glossary_links);
     include_once "./Services/UIComponent/Overlay/classes/class.ilOverlayGUI.php";
     if ($this->scorm_mode != "export") {
         $tpl = new ilTemplate("tpl.glossary_entries.html", true, true, "Modules/Scorm2004");
     } else {
         $tpl = self::$export_glo_tpl;
     }
     $glossary = false;
     $overlays = array();
     // overlay for sco glossary
     if ($this->getGlossaryOverviewId() != "" && $this->getOutputMode() != "edit") {
         $ovov = $overlays[$this->getGlossaryOverviewId()] = new ilOverlayGUI($this->getGlossaryOverviewId());
         //			$ovov->setFixedCenter(true);
         $ovov->setAutoHide(false);
         $ovov->setCloseElementId("glo_ov_close");
         if ($this->getGlossaryOverviewId() != "") {
             if ($this->scorm_mode != "export" || $this->getOutputMode() == IL_PAGE_PREVIEW) {
                 $overlays[$this->getGlossaryOverviewId()]->add();
             } else {
                 $tpl->setCurrentBlock("add_script");
                 $tpl->setVariable("ADD_SCRIPT", "il.Util.addOnLoad(function () {" . $overlays[$this->getGlossaryOverviewId()]->getOnLoadCode() . "});");
                 $tpl->parseCurrentBlock();
             }
         }
     }
     if ($this->getOutputMode() != "edit") {
         if (is_array($this->glossary_links)) {
             foreach ($this->glossary_links as $k => $e) {
                 // glossary link
                 if ($e["Type"] == "GlossaryItem") {
                     $karr = explode(":", $k);
                     $link_id = $karr[0] . "_" . $this->getPageObject()->getId() . "_" . $karr[4];
                     //$ov_id = "ov".$karr[0]."_".$karr[4];
                     $ov_id = "ov" . $karr[0];
                     $cl_id = "ov" . $karr[0] . "cl";
                     $glov_id = "ov" . $karr[0] . "ov";
                     $term_id_arr = explode("_", $karr[0]);
                     $term_id = $term_id_arr[count($term_id_arr) - 1];
                     // get overlay html from glossary term
                     include_once "./Modules/Glossary/classes/class.ilGlossaryTermGUI.php";
                     $id_arr = explode("_", $karr[0]);
                     $term_gui =& new ilGlossaryTermGUI($id_arr[count($id_arr) - 1]);
                     $html = $term_gui->getOverlayHTML($cl_id, $this->getGlossaryOverviewId() != "" ? $glov_id : "", ilObjSAHSLearningModule::getAffectiveLocalization($this->slm_id));
                     $tpl->setCurrentBlock("entry");
                     $tpl->setVariable("CONTENT", $html);
                     $tpl->setVariable("OVERLAY_ID", $ov_id);
                     $glossary = true;
                     // first time the term is used
                     if (!isset($overlays[$ov_id])) {
                         $overlays[$ov_id] = new ilOverlayGUI($ov_id);
                         $overlays[$ov_id]->setAnchor($link_id);
                         $overlays[$ov_id]->setTrigger($link_id, "click", $link_id);
                         $overlays[$ov_id]->setAutoHide(false);
                         $overlays[$ov_id]->setCloseElementId($cl_id);
                         if ($this->scorm_mode != "export" || $this->getOutputMode() == IL_PAGE_PREVIEW) {
                             $overlays[$ov_id]->add();
                         } else {
                             $tpl->setVariable("SCRIPT", "il.Util.addOnLoad(function () {" . $overlays[$ov_id]->getOnLoadCode() . "});");
                         }
                     } else {
                         if ($this->scorm_mode != "export" || $this->getOutputMode() == IL_PAGE_PREVIEW) {
                             $overlays[$ov_id]->addTrigger($link_id, "click", $link_id);
                         } else {
                             $tpl->setVariable("SCRIPT", "il.Util.addOnLoad(function () {" . $overlays[$ov_id]->getTriggerOnLoadCode($link_id, "click", $link_id) . "});");
                         }
                     }
                     if ($this->getGlossaryOverviewId() != "") {
                         if ($this->scorm_mode != "export" || $this->getOutputMode() == IL_PAGE_PREVIEW) {
                             //$overlays[$this->getGlossaryOverviewId()]->addTrigger($glov_id, "click", null);
                             $overlays[$this->getGlossaryOverviewId()]->addTrigger($glov_id, "click", $ov_id, false, "tl", "tl");
                             //$overlays[$ov_id]->addTrigger("glo_ov_t".$term_id, "click", null, true);
                             $overlays[$ov_id]->addTrigger("glo_ov_t" . $term_id, "click", $this->getGlossaryOverviewId(), false, "tl", "tl");
                         } else {
                             $tpl->setVariable("SCRIPT2", "il.Util.addOnLoad(function () {" . $overlays[$this->getGlossaryOverviewId()]->getTriggerOnLoadCode($glov_id, "click", $ov_id, false, "tl", "tl") . "});");
                             $tpl->setVariable("SCRIPT3", "il.Util.addOnLoad(function () {" . $overlays[$ov_id]->getTriggerOnLoadCode("glo_ov_t" . $term_id, "click", $this->getGlossaryOverviewId(), false, "tl", "tl") . "});");
                         }
                     }
                     $tpl->parseCurrentBlock();
                 }
             }
         }
         if ($glossary && $this->scorm_mode != "export") {
             $ret = $a_output . $tpl->get();
             if ($this->getGlossaryOverviewId() != "") {
                 $ret .= ilSCORM2004ScoGUI::getGloOverviewOv($this->sco);
             }
             return $ret;
         }
     }
     return $a_output;
 }
 /**
  * Export HTML pages of SCO
  */
 function exportHTMLPageObjects($a_inst, $a_target_dir, &$expLog, $mode, $a_asset_type = "sco", $a_one_file = "", $a_sco_tpl = null)
 {
     global $tpl, $ilCtrl, $ilBench, $ilLog, $lng;
     include_once "./Modules/Scorm2004/classes/class.ilSCORM2004PageGUI.php";
     include_once "./Modules/Scorm2004/classes/class.ilObjSCORM2004LearningModuleGUI.php";
     include_once "./Services/MetaData/classes/class.ilMD.php";
     $output = "";
     $tree = new ilTree($this->slm_id);
     $tree->setTableNames('sahs_sc13_tree', 'sahs_sc13_tree_node');
     $tree->setTreeTablePK("slm_id");
     // @todo
     // Why is that much HTML code in an application class?
     // Please extract all this HTML to a tpl.<t_name>.html file and use
     // placeholders and the template engine to insert data.
     //
     // There copy/paste code residenting in ilSCORM2004ScoGUI. This
     // should be merged.
     //
     // alex, 4 Apr 09
     //
     //		if ($a_one_file == "")
     //		{
     $sco_tpl = new ilTemplate("tpl.sco.html", true, true, "Modules/Scorm2004");
     //		}
     //		else
     //		{
     //			$sco_tpl = $a_sco_tpl;
     //		}
     if ($mode != 'pdf' && $a_one_file == "") {
         include_once "./Services/COPage/classes/class.ilCOPageHTMLExport.php";
         $pg_exp = new ilCOPageHTMLExport($a_target_dir);
         $pg_exp->getPreparedMainTemplate($sco_tpl);
         // init and question lang vars
         $lk = ilObjSAHSLearningModule::getAffectiveLocalization($this->slm_id);
         $sco_tpl->setCurrentBlock("init");
         include_once "./Services/COPage/classes/class.ilPCQuestion.php";
         $sco_tpl->setVariable("TXT_INIT_CODE", ilPCQuestion::getJSTextInitCode($lk));
         $sco_tpl->parseCurrentBlock();
         // (additional) style sheets needed
         $styles = array("./css/yahoo/container.css", "./css/question_handling.css");
         foreach ($styles as $style) {
             $sco_tpl->setCurrentBlock("css_file");
             $sco_tpl->setVariable("CSS_FILE", $style);
             $sco_tpl->parseCurrentBlock();
         }
         // (additional) scripts needed
         $scripts = array("./js/scorm.js", "./js/pager.js", "./js/pure.js", "./js/questions_" . $this->getId() . ".js");
         foreach ($scripts as $script) {
             $sco_tpl->setCurrentBlock("js_file");
             $sco_tpl->setVariable("JS_FILE", $script);
             $sco_tpl->parseCurrentBlock();
         }
         if ($a_asset_type != "entry_asset" && $a_asset_type != "final_asset") {
             self::renderNavigation($sco_tpl, "./images/spacer.png", $lk);
         }
         $sco_tpl->touchBlock("finish");
     }
     // render head
     $sco_tpl->setCurrentBlock("head");
     $sco_tpl->setVariable("SCO_TITLE", $this->getTitle());
     $sco_tpl->parseCurrentBlock();
     $sco_tpl->touchBlock("tail");
     // meta page (meta info at SCO beginning)
     self::renderMetaPage($sco_tpl, $this, $a_asset_type, $mode);
     if ($a_one_file != "") {
         fputs($a_one_file, "<a name='sco" . $this->getId() . "'></a>");
         fputs($a_one_file, $sco_tpl->get("meta_page"));
     }
     //notify Question Exporter of new SCO
     require_once './Modules/Scorm2004/classes/class.ilQuestionExporter.php';
     ilQuestionExporter::indicateNewSco();
     // init export (this initialises glossary template)
     ilSCORM2004PageGUI::initExport();
     $terms = array();
     $terms = $this->getGlossaryTermIds();
     include_once "./Modules/Scorm2004/classes/class.ilSCORM2004ScoGUI.php";
     $pages = $tree->getSubTree($tree->getNodeData($this->getId()), true, 'page');
     $sco_q_ids = array();
     foreach ($pages as $page) {
         //echo(print_r($page));
         $page_obj = new ilSCORM2004PageGUI($this->getType(), $page["obj_id"], 0, $this->slm_object->getId());
         $page_obj->setPresentationTitle($page["title"]);
         $page_obj->setOutputMode(IL_PAGE_OFFLINE);
         $page_obj->setStyleId($this->slm_object->getStyleSheetId());
         if (count($terms) > 1) {
             $page_obj->setGlossaryOverviewInfo(ilSCORM2004ScoGUI::getGlossaryOverviewId(), $this);
         }
         $page_output = $page_obj->showPage("export");
         // collect media objects
         $mob_ids = $page_obj->getSCORM2004Page()->collectMediaObjects(false);
         foreach ($mob_ids as $mob_id) {
             $this->mob_ids[$mob_id] = $mob_id;
             $media_obj = new ilObjMediaObject($mob_id);
             if ($media_obj->hasFullscreenItem()) {
                 $media_obj->exportMediaFullscreen($a_target_dir, $page_obj->getPageObject());
             }
         }
         // collect glossary items
         $int_links = $page_obj->getPageObject()->getInternalLinks(true);
         include_once "./Services/Link/classes/class.ilInternalLink.php";
         include_once "./Modules/Glossary/classes/class.ilGlossaryDefinition.php";
         if (is_array($int_links)) {
             foreach ($int_links as $k => $e) {
                 // glossary link
                 if ($e["Type"] == "GlossaryItem") {
                     $karr = explode(":", $k);
                     $tid = ilInternalLink::_extractObjIdOfTarget($karr[0]);
                     $dids = ilGlossaryDefinition::getDefinitionList($tid);
                     foreach ($dids as $did) {
                         include_once "./Modules/Glossary/classes/class.ilGlossaryDefPage.php";
                         $def_pg = new ilGlossaryDefPage($did["id"]);
                         $def_pg->buildDom();
                         $mob_ids = $def_pg->collectMediaObjects(false);
                         foreach ($mob_ids as $mob_id) {
                             $this->mob_ids[$mob_id] = $mob_id;
                             //echo "<br>-$mob_id-";
                             $media_obj = new ilObjMediaObject($mob_id);
                             if ($media_obj->hasFullscreenItem()) {
                                 $media_obj->exportMediaFullscreen($a_target_dir, $def_pg);
                             }
                         }
                         include_once "./Services/COPage/classes/class.ilPCFileList.php";
                         $file_ids = ilPCFileList::collectFileItems($def_pg, $def_pg->getDomDoc());
                         foreach ($file_ids as $file_id) {
                             $this->file_ids[$file_id] = $file_id;
                         }
                     }
                 }
             }
         }
         //exit;
         // collect all file items
         include_once "./Services/COPage/classes/class.ilPCFileList.php";
         $file_ids = ilPCFileList::collectFileItems($page_obj->getSCORM2004Page(), $page_obj->getSCORM2004Page()->getDomDoc());
         foreach ($file_ids as $file_id) {
             $this->file_ids[$file_id] = $file_id;
         }
         if ($mode == 'pdf') {
             include_once "./Services/COPage/classes/class.ilPCQuestion.php";
             $q_ids = ilPCQuestion::_getQuestionIdsForPage("sahs", $page["obj_id"]);
             foreach ($q_ids as $q_id) {
                 include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
                 $q_gui =& assQuestionGUI::_getQuestionGUI("", $q_id);
                 $q_gui->outAdditionalOutput();
                 $html = $q_gui->getPreview(TRUE);
                 $page_output = preg_replace("/{{{{{Question;il__qst_" . $q_id . "}}}}}/i", $html, $page_output);
             }
             $sco_tpl->touchBlock("pdf_pg_break");
         }
         $sco_tpl->setCurrentBlock("page");
         $sco_tpl->setVariable("PAGE", $page_output);
         $sco_tpl->parseCurrentBlock();
         // get all question ids of the sco
         if ($a_one_file != "") {
             include_once "./Services/COPage/classes/class.ilPCQuestion.php";
             $q_ids = ilPCQuestion::_getQuestionIdsForPage("sahs", $page["obj_id"]);
             foreach ($q_ids as $i) {
                 if (!in_array($i, $sco_q_ids)) {
                     $sco_q_ids[] = $i;
                 }
             }
         }
     }
     // glossary
     if ($mode != 'pdf') {
         $sco_tpl->setVariable("GLOSSARY_HTML", ilSCORM2004PageGUI::getGlossaryHTML($this));
     }
     if ($a_one_file == "") {
         $output = $sco_tpl->get();
     } else {
         $output = $sco_tpl->get("page");
     }
     if ($mode == 'pdf') {
         $output = preg_replace("/<div class=\"ilc_page_title_PageTitle\">(.*?)<\\/div>/i", "<h2>\$1</h2>", $output);
     }
     //$output = preg_replace("/\.\/mobs\/mm_(\d+)\/([^\"]+)/i","./objects/il_".IL_INST_ID."_mob_$1/$2",$output);
     $output = preg_replace("/mobs\\/mm_(\\d+)\\/([^\"]+)/i", "./objects/il_" . IL_INST_ID . "_mob_\$1/\$2", $output);
     $output = preg_replace("/\\.\\/files\\/file_(\\d+)\\/([^\"]+)/i", "./objects/il_" . IL_INST_ID . "_file_\$1/\$2", $output);
     $output = preg_replace("/\\.\\/Services\\/MediaObjects\\/flash_mp3_player/i", "./players", $output);
     //		$output = preg_replace("/\.\/".str_replace("/", "\/", ilPlayerUtil::getFlashVideoPlayerDirectory())."/i","./players",$output);
     $output = preg_replace("/file=..\\/..\\/..\\/.\\//i", "file=../", $output);
     if ($mode != 'pdf') {
         $output = preg_replace_callback("/href=\"&mob_id=(\\d+)&pg_id=(\\d+)\"/", array(get_class($this), 'fixFullscreeenLink'), $output);
         // this one is for fullscreen in glossary entries
         $output = preg_replace_callback("/href=\"fullscreen_(\\d+)\\.html\"/", array(get_class($this), 'fixFullscreeenLink'), $output);
         $output = preg_replace_callback("/{{{{{(Question;)(il__qst_[0-9]+)}}}}}/", array(get_class($this), 'insertQuestion'), $output);
         //			$output = preg_replace("/&#123;/","",$output);
         //			$output = preg_replace("/&#125;/","",$output);
         $q_handling = file_get_contents('./Modules/Scorm2004/scripts/questions/question_handling.js');
         fputs(fopen($a_target_dir . '/js/questions_' . $this->getId() . '.js', 'w+'), ilQuestionExporter::questionsJS() . $q_handling);
         copy("./Modules/Scorm2004/templates/default/question_handling.css", $a_target_dir . '/css/question_handling.css');
         // hack to get the question js into the file and to display the correct answers
         if ($a_one_file != "") {
             $output = '<script type="text/javascript">' . ilQuestionExporter::questionsJS() . '</script>' . $output;
             if (count($sco_q_ids) > 0) {
                 $output .= '<script type="text/javascript">';
                 foreach ($sco_q_ids as $i) {
                     if ($i > 0) {
                         $output .= "ilias.questions.showCorrectAnswers(" . $i . "); \n";
                     }
                 }
                 $output .= '</script>';
             }
         }
         foreach (ilQuestionExporter::getMobs() as $mob_id) {
             $this->mob_ids[$mob_id] = $mob_id;
         }
     }
     $this->q_media = ilQuestionExporter::getFiles();
     //questions export end
     if ($a_one_file != "") {
         fputs($a_one_file, $output);
     } else {
         fputs(fopen($a_target_dir . '/index.html', 'w+'), $output);
     }
     $this->exportFileItems($a_target_dir, $expLog);
 }
 /**
  * des
  *
  * @param
  * @return
  */
 static function getGloOverviewOv($a_sco)
 {
     global $lng;
     $tpl = new ilTemplate("tpl.sco_glossary_overview.html", true, true, "Modules/Scorm2004");
     $terms = $a_sco->getGlossaryTermIds();
     $lk = ilObjSAHSLearningModule::getAffectiveLocalization($a_sco->getSLMId());
     foreach ($terms as $k => $t) {
         $tpl->setCurrentBlock("link");
         $tpl->setVariable("TXT_LINK", $t);
         $tpl->setVariable("ID_LINK", "glo_ov_t" . $k);
         $tpl->parseCurrentBlock();
     }
     $tpl->setVariable("DIV_ID", ilSCORM2004ScoGUI::getGlossaryOverviewId());
     $tpl->setVariable("TXT_SCO_GLOSSARY", $lng->txtlng("content", "cont_sco_glossary", $lk));
     $tpl->setVariable("TXT_CLOSE", $lng->txtlng("common", "close", $lk));
     if (count($terms) > 1) {
         return $tpl->get();
     } else {
         return "";
     }
 }