ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSCORM2004Sco.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once("./Modules/Scorm2004/classes/class.ilSCORM2004Node.php");
6 
18 {
19 
20  var $q_media = null; //media files in questions
26  function ilSCORM2004Sco($a_slm_object, $a_id = 0)
27  {
28  parent::ilSCORM2004Node($a_slm_object, $a_id);
29  $this->setType("sco");
30  }
31 
35  function delete($a_delete_meta_data = true)
36  {
37  $node_data = $this->tree->getNodeData($this->getId());
38  $this->delete_rec($a_delete_meta_data);
39  $this->tree->deleteTree($node_data);
41  }
42 
46  function create($a_upload = false,$a_template = false)
47  {
48  include_once("./Modules/Scorm2004/classes/seq_editor/class.ilSCORM2004Item.php");
49  include_once("./Modules/Scorm2004/classes/seq_editor/class.ilSCORM2004Objective.php");
50  parent::create($a_upload);
51  if (!$a_template) {
52  $seq_item = new ilSCORM2004Item($this->getId());
53  $seq_item->insert();
54  $obj = new ilSCORM2004Objective($this->getId());
55  $obj->setObjectiveID("Objective SCO ".$this->getId());
56  $obj->setId("local_obj_".$this->getID()."_0");
57  $obj->update();
58  }
59  }
60 
64  private function delete_rec($a_delete_meta_data = true)
65  {
66  $childs = $this->tree->getChilds($this->getId());
67  foreach ($childs as $child)
68  {
69  $obj =& ilSCORM2004NodeFactory::getInstance($this->slm_object, $child["obj_id"], false);
70  if (is_object($obj))
71  {
72  if ($obj->getType() == "page")
73  {
74  $obj->delete($a_delete_meta_data);
75  }
76  }
77  unset($obj);
78  }
79  parent::delete($a_delete_meta_data);
80  }
81 
85  function copy($a_target_slm)
86  {
87  $sco = new ilSCORM2004Sco($a_target_slm);
88  $sco->setTitle($this->getTitle());
89  if ($this->getSLMId() != $a_target_slm->getId())
90  {
91  $sco->setImportId("il__sco_".$this->getId());
92  }
93  $sco->setSLMId($a_target_slm->getId());
94  $sco->setType($this->getType());
95  $sco->setDescription($this->getDescription());
96  $sco->create(true);
97  $a_copied_nodes[$this->getId()] = $sco->getId();
98 
99  // copy meta data
100  include_once("Services/MetaData/classes/class.ilMD.php");
101  $md = new ilMD($this->getSLMId(), $this->getId(), $this->getType());
102  $new_md =& $md->cloneMD($a_target_slm->getId(), $sco->getId(), $this->getType());
103 
104  return $sco;
105  }
106  // @todo: more stuff similar to ilSCORM2004Chapter needed...
107 
108  function exportScorm($a_inst, $a_target_dir, $ver, &$expLog)
109  {
110 
111  copy('./xml/ilias_co_3_7.dtd',$a_target_dir.'/ilias_co_3_7.dtd');
112  copy('./Modules/Scorm2004/templates/xsl/sco.xsl',$a_target_dir.'/sco.xsl');
113 
114  $a_xml_writer = new ilXmlWriter;
115  // MetaData
116  //file_put_contents($a_target_dir.'/indexMD.xml','<lom xmlns="http://ltsc.ieee.org/xsd/LOM"><general/><classification/></lom>');
117  $this->exportXMLMetaData($a_xml_writer);
118  $metadata_xml = $a_xml_writer->xmlDumpMem(false);
119  $a_xml_writer->_XmlWriter;
120 
121  $xsl = file_get_contents("./Modules/Scorm2004/templates/xsl/metadata.xsl");
122  $args = array( '/_xml' => $metadata_xml , '/_xsl' => $xsl );
123  $xh = xslt_create();
124  $output = xslt_process($xh,"arg:/_xml","arg:/_xsl",NULL,$args,NULL);
125  xslt_free($xh);
126  file_put_contents($a_target_dir.'/indexMD.xml',$output);
127 
128  $a_xml_writer = new ilXmlWriter;
129  // set dtd definition
130  $a_xml_writer->xmlSetDtdDef("<!DOCTYPE ContentObject SYSTEM \"http://www.ilias.de/download/dtd/ilias_co_3_7.dtd\">");
131 
132  // set generated comment
133  $a_xml_writer->xmlSetGenCmt("Export of ILIAS Content Module ". $this->getId()." of installation ".$a_inst.".");
134 
135  // set xml header
136  $a_xml_writer->xmlHeader();
137 
138  global $ilBench;
139 
140  $a_xml_writer->xmlStartTag("ContentObject", array("Type"=>"SCORM2004SCO"));
141 
142  $this->exportXMLMetaData($a_xml_writer);
143 
144  $this->exportXMLPageObjects($a_target_dir, $a_xml_writer, $a_inst, $expLog);
145 
146  $this->exportXMLMediaObjects($a_xml_writer, $a_inst, $a_target_dir, $expLog);
147 
148  $this->exportHTML($a_inst, $a_target_dir, $expLog);
149 
150  //overwrite scorm.js for scrom 1.2
151  if ($ver=="12")
152  copy('./Modules/Scorm2004/scripts/scorm_12.js',$a_target_dir.'/js/scorm.js');
153 
154  $a_xml_writer->xmlEndTag("ContentObject");
155 
156  $a_xml_writer->xmlDumpFile($a_target_dir.'/index.xml', false);
157 
158  $a_xml_writer->_XmlWriter;
159 
160  // export sco data (currently only objective) to sco.xml
161  $objectives_text = "";
162  $a_xml_writer = new ilXmlWriter;
163 
164  $tr_data = $this->getObjectives();
165  foreach ($tr_data as $data)
166  {
167  $objectives_text.= $data->getObjectiveID();
168  }
169  $a_xml_writer->xmlStartTag("sco");
170  $a_xml_writer->xmlElement("objective", null, $objectives_text);
171  $a_xml_writer->xmlEndTag("sco");
172  $a_xml_writer->xmlDumpFile($a_target_dir.'/sco.xml', false);
173  $a_xml_writer->_XmlWriter;
174  }
175 
176  function exportHTML($a_inst, $a_target_dir, &$expLog)
177  {
178  ilUtil::makeDir($a_target_dir.'/css');
179  ilUtil::makeDir($a_target_dir.'/css/yahoo');
180  ilUtil::makeDir($a_target_dir.'/objects');
181  ilUtil::makeDir($a_target_dir.'/images');
182  ilUtil::makeDir($a_target_dir.'/js');
183  ilUtil::makeDir($a_target_dir.'/players');
184 
185  copy('./Services/MediaObjects/flash_flv_player/flvplayer.swf', $a_target_dir.'/players/flvplayer.swf');
186  copy('./Services/MediaObjects/flash_mp3_player/mp3player.swf', $a_target_dir.'/players/mp3player.swf');
187  copy('./Modules/Scorm2004/scripts/scorm_2004.js',$a_target_dir.'/js/scorm.js');
188  copy('./Modules/Scorm2004/scripts/pager.js',$a_target_dir.'/js/pager.js');
189  copy('./Modules/Scorm2004/scripts/questions/pure.js',$a_target_dir.'/js/pure.js');
190  copy('./Modules/Scorm2004/scripts/questions/jquery.js',$a_target_dir.'/js/jquery.js');
191  copy('./Modules/Scorm2004/scripts/questions/jquery-ui-min.js',$a_target_dir.'/js/jquery-ui-min.js');
192 
193  // accordion stuff
194  ilUtil::makeDir($a_target_dir.'/js/yahoo');
195  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
196  copy(ilYuiUtil::getLocalPath('yahoo/yahoo-min.js'), $a_target_dir.'/js/yahoo/yahoo-min.js');
197  copy(ilYuiUtil::getLocalPath('yahoo-dom-event/yahoo-dom-event.js'), $a_target_dir.'/js/yahoo/yahoo-dom-event.js');
198  copy(ilYuiUtil::getLocalPath('container/container_core-min.js'), $a_target_dir.'/js/yahoo/container_core-min.js');
199  copy(ilYuiUtil::getLocalPath('animation/animation-min.js'), $a_target_dir.'/js/yahoo/animation-min.js');
200  copy(ilYuiUtil::getLocalPath('container/assets/skins/sam/container.css'), $a_target_dir.'/css/yahoo/container.css');
201  copy('./Services/Accordion/js/accordion.js',$a_target_dir.'/js/accordion.js');
202  copy('./Services/Accordion/css/accordion.css',$a_target_dir.'/css/accordion.css');
203  copy('./Services/JavaScript/js/Basic.js',$a_target_dir.'/js/Basic.js');
204  copy('./Services/UIComponent/Overlay/js/ilOverlay.js',$a_target_dir.'/js/ilOverlay.js');
205 
206  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
207  $active_css = ilObjStyleSheet::getContentStylePath($this->slm_object->getStyleSheetId());
208  $active_css = split(@'\?',$active_css,2);
209  $css = fread(fopen($active_css[0],'r'),filesize($active_css[0]));
210  preg_match_all("/url\(([^\)]*)\)/",$css,$files);
211  $currdir = getcwd();
212  chdir(dirname($active_css[0]));
213  foreach (array_unique($files[1]) as $fileref)
214  {
215  if (is_file($fileref))
216  {
217  copy($fileref,$a_target_dir."/images/".basename($fileref));
218  }
219  $css = str_replace($fileref,"../images/".basename($fileref),$css);
220  }
221  chdir($currdir);
222  fwrite(fopen($a_target_dir.'/css/style.css','w'),$css);
223 
224  // export system style sheet
225  $css = fread(fopen(ilUtil::getStyleSheetLocation("filesystem"),'r'),filesize(ilUtil::getStyleSheetLocation("filesystem")));
226  preg_match_all("/url\(([^\)]*)\)/",$css,$files);
227  $currdir = getcwd();
228  chdir(dirname(ilUtil::getStyleSheetLocation("filesystem")));
229  foreach (array_unique($files[1]) as $fileref)
230  {
231  if(file_exists($fileref))
232  {
233  copy($fileref,$a_target_dir."/images/".basename($fileref));
234  $css = str_replace($fileref,"../images/".basename($fileref),$css);
235  }
236  }
237  copy('images/spacer.gif',$a_target_dir."/images/spacer.gif");
238  copy('images/enlarge.gif',$a_target_dir."/images/enlarge.gif");
239  chdir($currdir);
240  fwrite(fopen($a_target_dir.'/css/system.css','w'),$css);
241  //copy(ilUtil::getStyleSheetLocation("filesystem"), $a_target_dir.'/css/system.css');
242 
243  global $ilBench;
244 
245  $this->exportHTMLPageObjects($a_inst, $a_target_dir, $expLog, 'full');
246 
247  }
248 
249  function exportHTML4PDF($a_inst, $a_target_dir, &$expLog)
250  {
251  ilUtil::makeDir($a_target_dir.'/css');
252  ilUtil::makeDir($a_target_dir.'/objects');
253  ilUtil::makeDir($a_target_dir.'/images');
254  $this->exportHTMLPageObjects($a_inst, $a_target_dir, $expLog, 'pdf');
255  }
256 
257  function exportPDF($a_inst, $a_target_dir, &$expLog)
258  {
259  global $tpl, $lng, $ilCtrl;
260  $a_xml_writer = new ilXmlWriter;
261  $a_xml_writer->xmlStartTag("ContentObject", array("Type"=>"SCORM2004SCO"));
262  $this->exportPDFPrepareXmlNFiles($a_inst, $a_target_dir, $expLog,$a_xml_writer);
263  $a_xml_writer->xmlEndTag("ContentObject");
264  copy('./templates/default/images/icon_attachment_s.png',$a_target_dir."/icon_attachment_s.png");
265  include_once 'Services/Transformation/classes/class.ilXML2FO.php';
266  $xml2FO = new ilXML2FO();
267  $xml2FO->setXSLTLocation('./Modules/Scorm2004/templates/xsl/contentobject2fo.xsl');
268  $xml2FO->setXMLString($a_xml_writer->xmlDumpMem());
269  $xml2FO->setXSLTParams(array ('target_dir' => $a_target_dir));
270  $xml2FO->transform();
271  $fo_string = $xml2FO->getFOString();
272  $fo_xml = simplexml_load_string($fo_string);
273  $fo_ext = $fo_xml->xpath("//fo:declarations");
274  $fo_ext = $fo_ext[0];
275  $results = array();
276  include_once "./Services/Utilities/classes/class.ilFileUtils.php";
277  ilFileUtils::recursive_dirscan($a_target_dir."/objects", $results);
278  if (is_array($results["file"]))
279  {
280  foreach ($results["file"] as $key => $value)
281  {
282  $e = $fo_ext->addChild("fox:embedded-file","","http://xml.apache.org/fop/extensions");
283  $e->addAttribute("src",$results[path][$key].$value);
284  $e->addAttribute("name",$value);
285  $e->addAttribute("desc","");
286  }
287  }
288  $fo_string = $fo_xml->asXML();
289  $a_xml_writer->_XmlWriter;
290  return $fo_string;
291  }
292 
293  function exportPDFPrepareXmlNFiles($a_inst, $a_target_dir, &$expLog, &$a_xml_writer)
294  {
295 
296  $this->exportHTML4PDF($a_inst, $a_target_dir, $expLog);
297  global $tpl, $lng, $ilCtrl;
298  $this->exportXMLPageObjects($a_target_dir, $a_xml_writer, $a_inst, $expLog);
299  $this->exportXMLMediaObjects($a_xml_writer, $a_inst, $a_target_dir, $expLog);
300  $this->exportFileItems($a_target_dir,$expLog);
301 
302  include_once "./Modules/Scorm2004/classes/class.ilSCORM2004PageNode.php";
303  include_once "./Modules/Scorm2004/classes/class.ilSCORM2004Page.php";
304 
305  $tree = new ilTree($this->slm_id);
306  $tree->setTableNames('sahs_sc13_tree', 'sahs_sc13_tree_node');
307  $tree->setTreeTablePK("slm_id");
308  foreach($tree->getSubTree($tree->getNodeData($this->getId()),true,'page') as $page)
309  {
310  $page_obj = new ilSCORM2004Page($page["obj_id"]);
311  $q_ids = ilSCORM2004Page::_getQuestionIdsForPage("sahs", $page["obj_id"]);
312  if (count($q_ids) > 0)
313  {
314  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
315  foreach ($q_ids as $q_id)
316  {
317  $q_obj =& assQuestion::_instanciateQuestion($q_id);
318  $qti_file = fopen($a_target_dir."/qti_".$q_id.".xml", "w");
319  fwrite($qti_file, $q_obj->toXML());
320  fclose($qti_file);
321  $x = file_get_contents($a_target_dir."/qti_".$q_id.".xml");
322  $x = str_replace('<?xml version="1.0" encoding="utf-8"?>', '', $x);
323  $a_xml_writer->appendXML($x);
324  }
325  }
326  unset($page_obj);
327  }
328  }
329 
330  function exportHTMLPageObjects($a_inst, $a_target_dir, &$expLog, $mode)
331  {
332  global $tpl, $ilCtrl, $ilBench,$ilLog, $lng;
333 
334  include_once "./Modules/Scorm2004/classes/class.ilSCORM2004PageGUI.php";
335  include_once "./Modules/Scorm2004/classes/class.ilObjSCORM2004LearningModuleGUI.php";
336  include_once "./Services/MetaData/classes/class.ilMD.php";
337 
338  $output = "";
339  $tree = new ilTree($this->slm_id);
340  $tree->setTableNames('sahs_sc13_tree', 'sahs_sc13_tree_node');
341  $tree->setTreeTablePK("slm_id");
342 
343  $meta = new ilMD($this->getSLMId(), $this->getId(), $this->getType());
344  $desc_ids = $meta->getGeneral()->getDescriptionIds();
345  $sco_description = $meta->getGeneral()->getDescription($desc_ids[0])->getDescription();
346 
347  // @todo
348  // Why is that much HTML code in an application class?
349  // Please extract all this HTML to a tpl.<t_name>.html file and use
350  // placeholders and the template engine to insert data.
351  //
352  // There copy/paste code residenting in ilSCORM2004ScoGUI. This
353  // should be merged.
354  //
355  // alex, 4 Apr 09
356  //
357 
358  $output = '
359  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
360  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
361  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
362  <head>
363  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
364  <meta http-equiv="X-UA-Compatible" content="IE=7" />
365  <link rel="stylesheet" type="text/css" href="./css/system.css" />
366  <link rel="stylesheet" type="text/css" href="./css/style.css" />
367  <link rel="stylesheet" type="text/css" href="./css/accordion.css" />
368  <link rel="stylesheet" type="text/css" href="./css/yahoo/container.css" />
369  <script src="./js/scorm.js" type="text/javascript" language="JavaScript1.2"></script>
370  <script src="./js/jquery.js" type="text/javascript" language="JavaScript1.2"></script>
371  <script src="./js/jquery-ui-min.js" type="text/javascript" language="JavaScript1.2"></script>
372  <script src="./js/pager.js" type="text/javascript" language="JavaScript1.2"></script>
373  <script src="./js/pure.js" type="text/javascript" language="JavaScript1.2"></script>
374  <script src="./js/yahoo/yahoo-min.js" type="text/javascript" language="JavaScript1.2"></script>
375  <script src="./js/yahoo/yahoo-dom-event.js" type="text/javascript" language="JavaScript1.2"></script>
376  <script src="./js/yahoo/container_core-min.js" type="text/javascript" language="JavaScript1.2"></script>
377  <script src="./js/yahoo/animation-min.js" type="text/javascript" language="JavaScript1.2"></script>
378  <script src="./js/Basic.js" type="text/javascript" language="JavaScript1.2"></script>
379  <script src="./js/ilOverlay.js" type="text/javascript" language="JavaScript1.2"></script>
380  <script src="./js/questions_'. $this->getId().'.js" type="text/javascript" language="JavaScript1.2"></script>
381  <script type="text/javascript" language="JavaScript1.2">
382  ilAddOnLoad(function () {init(0);
383  ilias.questions.txt.wrong_answers = "'.$lng->txt("cont_wrong_answers").'";
384  ilias.questions.txt.tries_remaining = "'.$lng->txt("cont_tries_remaining").'";
385  ilias.questions.txt.please_try_again = "'.$lng->txt("cont_please_try_again").'";
386  ilias.questions.txt.all_answers_correct = "'.$lng->txt("cont_all_answers_correct").'";
387  ilias.questions.txt.nr_of_tries_exceeded = "'.$lng->txt("cont_nr_of_tries_exceeded").'";
388  ilias.questions.txt.correct_answers_shown = "'.$lng->txt("cont_correct_answers_shown").'";
389  });
390  </script>
391  <script src="./js/accordion.js" type="text/javascript" language="JavaScript1.2"></script>
392  <title>'.$this->getTitle().'</title>
393  </head>
394  <body class="yui-skin-sam" onunload="finish();">';
395  //<body onLoad="init(0);" onunload="finish();">';
396  // add init(0) per script, see above;
397  // otherwise accordion.js cannot add another function to the onload event.
398 
399  if($mode!='pdf')
400  $output .= '<!-- BEGIN ilLMNavigation -->
401  <div class="ilc_page_tnav_TopNavigation">
402  <!-- BEGIN ilLMNavigation_Prev -->
403  <div class="ilc_page_lnav_LeftNavigation">
404  <a class="ilc_page_lnavlink_LeftNavigationLink">
405  <img class="ilc_page_lnavimage_LeftNavigationImage" border="0" src="./images/spacer.gif" alt="" title="" />&nbsp;'.$lng->txt('scplayer_previous').'</a>
406  </div>
407  <!-- END ilLMNavigation_Prev -->
408  <!-- BEGIN ilLMNavigation_Next -->
409  <div class="ilc_page_rnav_RightNavigation">
410  <a class="ilc_page_rnavlink_RightNavigationLink">'.$lng->txt('scplayer_next').'&nbsp;<img class="ilc_page_rnavimage_RightNavigationImage" border="0" src="./images/spacer.gif" alt="" title="" /></a>
411  </div>
412  <!-- END ilLMNavigation_Next -->
413  <div style="clear:both;"></div>
414  </div>
415  <!-- END ilLMNavigation -->';
416 
417  $output .='<table class="ilc_page_cont_PageContainer" width="100%" cellspacing="0" cellpadding="0" style="display: table;">
418  <tbody><tr><td><div class="ilc_page_Page">';
419  if($mode!='pdf')
420  $output .='<div class="ilc_sco_title_Title">'.$this->getTitle().'</div>';
421  else
422  $output .='<h1>'.$this->getTitle().'</h1>';
423 
424  // sco description
425  if (trim($sco_description) != "")
426  {
427  $output .='<div class="ilc_sco_desct_DescriptionTop">'.$lng->txt("description").'</div>';
428  $output .='<div class="ilc_sco_desc_Description">'.$sco_description.'</div>';
429  }
430 
431  // sco objective(s)
432  $objs = $this->getObjectives();
433  if (count($objs) > 0)
434  {
435  $output .='<div class="ilc_sco_objt_ObjectiveTop">'.$lng->txt("sahs_objectives").'</div>';
436  foreach ($objs as $objective)
437  {
438  $output .= '<div class="ilc_sco_obj_Objective">'.nl2br($objective->getObjectiveID()).'</div>';
439  }
440  $output .= "</div>";
441  }
442  $output .='</td><tr></table>';
443 
444  //notify Question Exporter of new SCO
445  require_once './Modules/Scorm2004/classes/class.ilQuestionExporter.php';
447 
448  if($mode=='pdf') $output .='<!-- PAGE BREAK -->';
449 
450  // init export (this initialises glossary template)
452  $terms = $this->getGlossaryTermIds();
453 
454  include_once("./Modules/Scorm2004/classes/class.ilSCORM2004ScoGUI.php");
455  foreach($tree->getSubTree($tree->getNodeData($this->getId()),true,'page') as $page)
456  {
457  //echo(print_r($page));
458  $page_obj = new ilSCORM2004PageGUI($this->getType(),$page["obj_id"]);
459  $page_obj->setPresentationTitle($page["title"]);
460  $page_obj->setOutputMode(IL_PAGE_OFFLINE);
461  $page_obj->setStyleId($this->slm_object->getStyleSheetId());
462  if (count($terms) > 1)
463  {
464  $page_obj->setGlossaryOverviewInfo(
466  }
467  $output .= '<table class="ilc_page_cont_PageContainer" width="100%" cellspacing="0" cellpadding="0" style="display: table;"><tbody><tr><td><div class="ilc_page_Page">'.$page_obj->showPage("export")."</div></td></tr></table>";
468  if($mode=='pdf') $output .='<!-- PAGE BREAK -->';
469  // collect media objects
470  $ilBench->start("ContentObjectExport", "exportPageObject_CollectMedia");
471  $mob_ids = $page_obj->getSCORM2004Page()->collectMediaObjects(false);
472  foreach($mob_ids as $mob_id)
473  {
474  $this->mob_ids[$mob_id] = $mob_id;
475  $media_obj = new ilObjMediaObject($mob_id);
476  if($media_obj->hasFullscreenItem())
477  $media_obj->exportMediaFullscreen($a_target_dir, $page_obj->getPageObject());
478  }
479  $ilBench->stop("ContentObjectExport", "exportPageObject_CollectMedia");
480 
481  // collect glossary items
482  $int_links = $page_obj->getPageObject()->getInternalLinks(true);
483  include_once("./Services/COPage/classes/class.ilInternalLink.php");
484  include_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
485  include_once("./Services/COPage/classes/class.ilPageObject.php");
486  if (is_array($int_links))
487  {
488  foreach ($int_links as $k => $e)
489  {
490  // glossary link
491  if ($e["Type"] == "GlossaryItem")
492  {
493  $karr = explode(":", $k);
494  $tid = ilInternalLink::_extractObjIdOfTarget($karr[0]);
496  foreach ($dids as $did)
497  {
498  $def_pg = new ilPageObject("gdf", $did["id"]);
499  $def_pg->buildDom();
500  $mob_ids = $def_pg->collectMediaObjects(false);
501  foreach($mob_ids as $mob_id)
502  {
503  $this->mob_ids[$mob_id] = $mob_id;
504 //echo "<br>-$mob_id-";
505  $media_obj = new ilObjMediaObject($mob_id);
506  if($media_obj->hasFullscreenItem())
507  $media_obj->exportMediaFullscreen($a_target_dir, $def_pg);
508  }
509  $file_ids = $def_pg->collectFileItems();
510  foreach($file_ids as $file_id)
511  {
512  $this->file_ids[$file_id] = $file_id;
513  }
514  }
515  }
516  }
517  }
518 //exit;
519  // collect all file items
520  $ilBench->start("ContentObjectExport", "exportPageObject_CollectFileItems");
521  $file_ids = $page_obj->getSCORM2004Page()->collectFileItems();
522  foreach($file_ids as $file_id)
523  {
524  $this->file_ids[$file_id] = $file_id;
525  }
526  $ilBench->stop("ContentObjectExport", "exportPageObject_CollectFileItems");
527 
528  if($mode=='pdf')
529  {
530  $q_ids = ilSCORM2004Page::_getQuestionIdsForPage("sahs", $page["obj_id"]);
531  foreach ($q_ids as $q_id)
532  {
533  include_once("./Modules/TestQuestionPool/classes/class.assQuestionGUI.php");
534  $q_gui =& assQuestionGUI::_getQuestionGUI("", $q_id);
535  $q_gui->outAdditionalOutput();
536  $html = $q_gui->getPreview(TRUE);
537  $output = preg_replace("/&#123;&#123;&#123;&#123;&#123;Question;il__qst_".$q_id."&#125;&#125;&#125;&#125;&#125;/i",$html,$output);
538  }
539  }
540  }
541 
542  if($mode!='pdf')
543  $output.= ilSCORM2004PageGUI::getGlossaryHTML($this);
544 
545  if($mode!='pdf')
546  $output .= '<!-- BEGIN ilLMNavigation2 -->
547  <div class="ilc_page_bnav_BottomNavigation">
548  <!-- BEGIN ilLMNavigation_Prev -->
549  <div class="ilc_page_lnav_LeftNavigation">
550  <a class="ilc_page_lnavlink_LeftNavigationLink">
551  <img class="ilc_page_lnavimage_LeftNavigationImage" border="0" src="./images/spacer.gif" alt="" title="" />&nbsp;'.$lng->txt('scplayer_previous').'</a>
552  </div>
553  <!-- END ilLMNavigation_Prev -->
554  <!-- BEGIN ilLMNavigation_Next -->
555  <div class="ilc_page_rnav_RightNavigation">
556  <a class="ilc_page_rnavlink_RightNavigationLink">'.$lng->txt('scplayer_next').'&nbsp;<img class="ilc_page_rnavimage_RightNavigationImage" border="0" src="./images/spacer.gif" alt="" title="" /></a>
557  </div>
558  <!-- END ilLMNavigation_Next -->
559  <div style="clear:both;"></div>
560  </div>
561  <!-- END ilLMNavigation2 -->';
562 
563  $output .= '</body></html>';
564 
565  if($mode=='pdf')
566  $output = preg_replace("/<div class=\"ilc_page_title_PageTitle\">(.*?)<\/div>/i","<h2>$1</h2>",$output);
567 
568  //$output = preg_replace("/\.\/mobs\/mm_(\d+)\/([^\"]+)/i","./objects/il_".IL_INST_ID."_mob_$1/$2",$output);
569  $output = preg_replace("/mobs\/mm_(\d+)\/([^\"]+)/i","./objects/il_".IL_INST_ID."_mob_$1/$2",$output);
570  $output = preg_replace("/\.\/files\/file_(\d+)\/([^\"]+)/i","./objects/il_".IL_INST_ID."_file_$1/$2",$output);
571  $output = preg_replace("/\.\/Services\/MediaObjects\/flash_mp3_player/i","./players",$output);
572  $output = preg_replace("/\.\/Services\/MediaObjects\/flash_flv_player/i","./players",$output);
573  $output = preg_replace("/file=..\/..\/..\/.\//i","file=../",$output);
574  if($mode!='pdf')
575  {
576  $output = preg_replace_callback("/href=\"&mob_id=(\d+)&pg_id=(\d+)\"/",array(get_class($this), 'fixFullscreeenLink'),$output);
577  // this one is for fullscreen in glossary entries
578  $output = preg_replace_callback("/href=\"fullscreen_(\d+)\.html\"/",array(get_class($this), 'fixFullscreeenLink'),$output);
579  $output = preg_replace_callback("/(Question;)(il__qst_[0-9]+)/",array(get_class($this), 'insertQuestion'),$output);
580  $output = preg_replace("/&#123;/","",$output);
581  $output = preg_replace("/&#125;/","",$output);
582  $q_handling = file_get_contents('./Modules/Scorm2004/scripts/questions/question_handling.js');
583  fputs(fopen($a_target_dir.'/js/questions_'.$this->getId().'.js','w+'),ilQuestionExporter::questionsJS().$q_handling);
584  foreach(ilQuestionExporter::getMobs() as $mob_id)
585  {
586  $this->mob_ids[$mob_id] = $mob_id;
587  }
588  }
589  $this->q_media = ilQuestionExporter::getFiles();
590  //questions export end
591 
592  fputs(fopen($a_target_dir.'/index.html','w+'),$output);
593 
594  $this->exportFileItems($a_target_dir, $expLog);
595 
596  }
597 
598  private function fixFullscreeenLink($matches)
599  {
600  $media_obj = new ilObjMediaObject($matches[1]);
601  if($media_obj->hasFullscreenItem())
602  {
603  return "href=\"./objects/il_".IL_INST_ID."_mob_".$matches[1]."/fullscreen.html\"";
604  //return "href=\"./objects/il_".IL_INST_ID."_mob_".$matches[1]."/".$media_obj->getMediaItem("Fullscreen")->getLocation()."\"";
605  }
606  }
607 
608  //callback function for question export
609  private function insertQuestion($matches) {
610  $q_exporter = new ilQuestionExporter();
611  return $q_exporter->exportQuestion($matches[2]);
612  }
613 
614  function exportXMLPageObjects($a_target_dir, &$a_xml_writer, $a_inst, &$expLog)
615  {
616  global $ilBench;
617 
618  include_once "./Modules/Scorm2004/classes/class.ilSCORM2004PageNode.php";
619  include_once "./Modules/Scorm2004/classes/class.ilSCORM2004Page.php";
620 
621  $tree = new ilTree($this->slm_id);
622  $tree->setTableNames('sahs_sc13_tree', 'sahs_sc13_tree_node');
623  $tree->setTreeTablePK("slm_id");
624  foreach($tree->getSubTree($tree->getNodeData($this->getId()),true,'page') as $page)
625  {
626  $ilBench->start("ContentObjectExport", "exportPageObject");
627  $expLog->write(date("[y-m-d H:i:s] ")."Page Object ".$page["obj_id"]);
628 
629  // export xml to writer object
630  $ilBench->start("ContentObjectExport", "exportPageObject_getLMPageObject");
631  $page_obj = new ilSCORM2004Page($page["obj_id"]);
632  $ilBench->stop("ContentObjectExport", "exportPageObject_getLMPageObject");
633  $ilBench->start("ContentObjectExport", "exportPageObject_XML");
634  //$page_obj->exportXMLMetaData($a_xml_writer);
635  $page_obj->exportXML($a_xml_writer, "normal", $a_inst);
636  $ilBench->stop("ContentObjectExport", "exportPageObject_XML");
637 
638  //collect media objects
639  $ilBench->start("ContentObjectExport", "exportPageObject_CollectMedia");
640  $mob_ids = $page_obj->getMediaObjectIds();
641  foreach($mob_ids as $mob_id)
642  {
643  $this->mob_ids[$mob_id] = $mob_id;
644  }
645  $ilBench->stop("ContentObjectExport", "exportPageObject_CollectMedia");
646 
647  // collect all file items
648  $ilBench->start("ContentObjectExport", "exportPageObject_CollectFileItems");
649  $file_ids = $page_obj->getFileItemIds();
650  foreach($file_ids as $file_id)
651  {
652  $this->file_ids[$file_id] = $file_id;
653  }
654  $ilBench->stop("ContentObjectExport", "exportPageObject_CollectFileItems");
655 
656  $q_ids = ilSCORM2004Page::_getQuestionIdsForPage("sahs", $page["obj_id"]);
657  if (count($q_ids) > 0)
658  {
659  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
660  foreach ($q_ids as $q_id)
661  {
662  $q_obj =& assQuestion::_instanciateQuestion($q_id);
663  $qti_file = fopen($a_target_dir."/qti_".$q_id.".xml", "w");
664  fwrite($qti_file, $q_obj->toXML());
665  fclose($qti_file);
666  }
667  }
668 
669  unset($page_obj);
670 
671  $ilBench->stop("ContentObjectExport", "exportPageObject");
672  }
673  }
674 
675  function exportXMLMediaObjects(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
676  {
677  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
678  include_once("./Modules/File/classes/class.ilObjFile.php");
679  $linked_mobs = array();
680  if(is_array($this->mob_ids ))
681  {
682  // mobs directly embedded into pages
683  foreach ($this->mob_ids as $mob_id)
684  {
685  if ($mob_id > 0)
686  {
687  $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
688  $media_obj = new ilObjMediaObject($mob_id);
689  $media_obj->exportXML($a_xml_writer, $a_inst);
690  $lmobs = $media_obj->getLinkedMediaObjects($this->mob_ids);
691  $linked_mobs = array_merge($linked_mobs, $lmobs);
692  unset($media_obj);
693  }
694  }
695 
696  // linked mobs (in map areas)
697  foreach ($linked_mobs as $mob_id)
698  {
699  if ($mob_id > 0)
700  {
701  $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
702  $media_obj = new ilObjMediaObject($mob_id);
703  $media_obj->exportXML($a_xml_writer, $a_inst);
704  unset($media_obj);
705  }
706  }
707  }
708  if(is_array($this->file_ids))
709  foreach ($this->file_ids as $file_id)
710  {
711  $expLog->write(date("[y-m-d H:i:s] ")."File Item ".$file_id);
712  $file_obj = new ilObjFile($file_id, false);
713  $file_obj->export($a_target_dir);
714  unset($file_obj);
715  }
716 
717  }
718 
723  function exportFileItems($a_target_dir, &$expLog)
724  {
725  include_once("./Modules/File/classes/class.ilObjFile.php");
726  if(is_array($this->file_ids))
727  foreach ($this->file_ids as $file_id)
728  {
729  $expLog->write(date("[y-m-d H:i:s] ")."File Item ".$file_id);
730  $file_obj = new ilObjFile($file_id, false);
731  $file_obj->export($a_target_dir);
732  unset($file_obj);
733  }
734 
735  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
736  $linked_mobs = array();
737  if(is_array($this->mob_ids ))
738  {
739  // mobs directly embedded into pages
740  foreach ($this->mob_ids as $mob_id)
741  {
742  if ($mob_id > 0 && ilObject::_exists($mob_id))
743  {
744  $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
745  $media_obj = new ilObjMediaObject($mob_id);
746  $media_obj->exportFiles($a_target_dir, $expLog);
747  $lmobs = $media_obj->getLinkedMediaObjects($this->mob_ids);
748  $linked_mobs = array_merge($linked_mobs, $lmobs);
749 
750  unset($media_obj);
751  }
752  }
753 
754  // linked mobs (in map areas)
755  foreach ($linked_mobs as $mob_id)
756  {
757  if ($mob_id > 0 && ilObject::_exists($mob_id))
758  {
759  $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
760  $media_obj = new ilObjMediaObject($mob_id);
761  $media_obj->exportFiles($a_target_dir);
762  unset($media_obj);
763  }
764  }
765  }
766 
767  //media files in questions
768  foreach ($this->q_media as $media) {
769  if ($media !="") {
770  error_log($media);
771  copy($media, $a_target_dir."/objects/".basename($media));
772  }
773  }
774  }
775 
776  /* export content objects meta data to xml (see ilias_co.dtd)
777  *
778  * @param object $a_xml_writer ilXmlWriter object that receives the
779  * xml data
780  */
781  function exportXMLMetaData(&$a_xml_writer)
782  {
783  include_once("Services/MetaData/classes/class.ilMD2XML.php");
784  $md2xml = new ilMD2XML($this->getSLMId(), $this->getId(), $this->getType());
785  $md2xml->setExportMode(true);
786  $md2xml->startExport();
787  $a_xml_writer->appendXML($md2xml->getXML());
788  }
789 
790  function getExportFiles()
791  {
792  $file = array();
793 
794  require_once("./Modules/Scorm2004/classes/class.ilSCORM2004Export.php");
795 
796  $export = new ilSCORM2004Export($this);
797  foreach ($export->getSupportedExportTypes() as $type)
798  {
799  $dir = $export->getExportDirectoryForType($type);
800  // quit if import dir not available
801  if (!@is_dir($dir) or !is_writeable($dir))
802  {
803  continue;
804  }
805  // open directory
806  $cdir = dir($dir);
807 
808  // get files and save the in the array
809  while ($entry = $cdir->read())
810  {
811  if ($entry != "." and
812  $entry != ".." and
813  (
814  ereg("^[0-9]{10}_{2}[0-9]+_{2}(".$this->getType()."_)".$this->getId()."+\.zip\$", $entry) or
815  ereg("^[0-9]{10}_{2}[0-9]+_{2}(".$this->getType()."_)".$this->getId()."+\.pdf\$", $entry) or
816  ereg("^[0-9]{10}_{2}[0-9]+_{2}(".$this->getType()."_)".$this->getId()."+\.iso\$", $entry)
817  ))
818  {
819  $file[$entry.$type] = array("type" => $type, "file" => $entry,
820  "size" => filesize($dir."/".$entry));
821  }
822  }
823 
824  // close import directory
825  $cdir->close();
826  }
827 
828  // sort files
829  ksort ($file);
830  reset ($file);
831  return $file;
832  }
833 
841  {
842  include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
843  $childs = $this->tree->getChilds($this->getId());
844  $ids = array();
845  foreach ($childs as $c)
846  {
847  $links = ilInternalLink::_getTargetsOfSource("sahs".":pg",
848  $c["child"]);
849  foreach ($links as $l)
850  {
851  if ($l["type"] == "git" && (int) $l["inst"] == 0 && !isset($ids[$l["id"]]))
852  {
853  $ids[$l["id"]] = ilGlossaryTerm::_lookGlossaryTerm($l["id"]);
854  }
855  }
856 
857  }
858  asort($ids);
859  return $ids;
860  }
861 }
862 ?>