ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjContentObject.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once "classes/class.ilObject.php";
5 require_once "Services/MetaData/classes/class.ilMDLanguageItem.php";
6 require_once("classes/class.ilNestedSetXML.php");
7 
22 {
23  var $lm_tree;
25  var $layout;
26  var $style_id;
28  var $online;
29 
30  private $import_dir = '';
31 
38  function ilObjContentObject($a_id = 0,$a_call_by_reference = true)
39  {
40  // this also calls read() method! (if $a_id is set)
41  $this->ilObject($a_id,$a_call_by_reference);
42 
43  $this->mob_ids = array();
44  $this->file_ids = array();
45  $this->q_ids = array();
46  }
47 
51  function create($a_upload = false)
52  {
53  global $ilUser;
54 
56 
57  // meta data will be created by
58  // import parser
59  if (!$a_upload)
60  {
61  $this->createMetaData();
62  }
63 
64  $this->createProperties();
65  if (!$a_upload)
66  {
67  if (is_object($ilUser))
68  {
69  //$this->meta_data->setLanguage($ilUser->getLanguage());
70  }
71  }
72  }
73 
80  function initDefaultRoles()
81  {
82  return array();
83 
84  global $rbacadmin, $rbacreview;
85 
86  // create a local role folder
87  $rfoldObj = $this->createRoleFolder("Local roles","Role Folder of content object ".$this->getId());
88 
89  // note: we don't need any roles here, local "author" roles must
90  // be created manually. subscription roles have been abandoned.
91  /*
92  // create author role and assign role to rolefolder...
93  $roleObj = $rfoldObj->createRole("author object ".$this->getRefId(),"author of content object ref id ".$this->getRefId());
94  $roles[] = $roleObj->getId();
95 
96  // copy permissions from author template to new role
97  $rbacadmin->copyRolePermissions($this->getAuthorRoleTemplateId(), 8, $rfoldObj->getRefId(), $roleObj->getId());
98 
99  // grant all allowed operations of role to current learning module
100  $rbacadmin->grantPermission($roleObj->getId(),
101  $rbacreview->getOperationsOfRole($roleObj->getId(), "lm", $rfoldObj->getRefId()),
102  $this->getRefId());*/
103 
104  unset($rfoldObj);
105  //unset($roleObj);
106 
107  return $roles ? $roles : array();
108  }
109 
110 
114  function read()
115  {
116  parent::read();
117 # echo "Content<br>\n";
118 
119  $this->lm_tree = new ilTree($this->getId());
120  $this->lm_tree->setTableNames('lm_tree','lm_data');
121  $this->lm_tree->setTreeTablePK("lm_id");
122 
123  $this->readProperties();
124  //parent::read();
125  }
126 
132  function getTitle()
133  {
134  return parent::getTitle();
135  }
136 
140  function setTitle($a_title)
141  {
142  parent::setTitle($a_title);
143 // $this->meta_data->setTitle($a_title);
144  }
145 
151  function getDescription()
152  {
153  return parent::getDescription();
154  }
155 
159  function setDescription($a_description)
160  {
161  parent::setDescription($a_description);
162 // $this->meta_data->setDescription($a_description);
163  }
164 
165 
166  function getImportId()
167  {
168  return $this->import_id;
169  }
170 
171  function setImportId($a_id)
172  {
173  $this->import_id = $a_id;
174  }
175 
181  function setLayoutPerPage($a_val)
182  {
183  $this->layout_per_page = $a_val;
184  }
185 
191  function getLayoutPerPage()
192  {
193  return $this->layout_per_page;
194  }
195 
196  function &getTree()
197  {
198  return $this->lm_tree;
199  }
200 
204  function update()
205  {
206  $this->updateMetaData();
207  parent::update();
208  $this->updateProperties();
209  }
210 
211 
215  function import()
216  {
217  // nothing to do. just display the dialogue in Out
218  return;
219  }
220 
221 
226  function putInTree($a_parent)
227  {
228  global $tree;
229 
230  // put this object in tree under $a_parent
231  parent::putInTree($a_parent);
232 
233  // make new tree for this object
234  //$tree->addTree($this->getId());
235  }
236 
237 
243  function createLMTree()
244  {
245  $this->lm_tree =& new ilTree($this->getId());
246  $this->lm_tree->setTreeTablePK("lm_id");
247  $this->lm_tree->setTableNames('lm_tree','lm_data');
248  $this->lm_tree->addTree($this->getId(), 1);
249  }
250 
251 
255  function &getLMTree()
256  {
257  return $this->lm_tree;
258  }
259 
260 
267  {
268  $lm_data_dir = ilUtil::getDataDir()."/lm_data";
269  if(!is_writable($lm_data_dir))
270  {
271  $this->ilias->raiseError("Content object Data Directory (".$lm_data_dir
272  .") not writeable.",$this->ilias->error_obj->FATAL);
273  }
274 
275  // create learning module directory (data_dir/lm_data/lm_<id>)
276  $lm_dir = $lm_data_dir."/lm_".$this->getId();
277  ilUtil::makeDir($lm_dir);
278  if(!@is_dir($lm_dir))
279  {
280  $this->ilias->raiseError("Creation of Learning Module Directory failed.",$this->ilias->error_obj->FATAL);
281  }
282 
283  // create import subdirectory (data_dir/lm_data/lm_<id>/import)
284  $import_dir = $lm_dir."/import";
286  if(!@is_dir($import_dir))
287  {
288  $this->ilias->raiseError("Creation of Import Directory failed.",$this->ilias->error_obj->FATAL);
289  }
290  }
291 
295  function getDataDirectory()
296  {
297  return ilUtil::getDataDir()."/lm_data".
298  "/lm_".$this->getId();
299  }
300 
305  {
306  if(strlen($this->import_dir))
307  {
308  return $this->import_dir;
309  }
310 
311  $import_dir = ilUtil::getDataDir()."/lm_data".
312  "/lm_".$this->getId()."/import";
313  if(@is_dir($import_dir))
314  {
315  return $import_dir;
316  }
317  else
318  {
319  return false;
320  }
321  }
322 
329  public function setImportDirectory($a_import_dir)
330  {
331  $this->import_dir = $a_import_dir;
332  }
333 
334 
340  function createExportDirectory($a_type = "xml")
341  {
342  $lm_data_dir = ilUtil::getDataDir()."/lm_data";
343  if(!is_writable($lm_data_dir))
344  {
345  $this->ilias->raiseError("Content object Data Directory (".$lm_data_dir
346  .") not writeable.",$this->ilias->error_obj->FATAL);
347  }
348  // create learning module directory (data_dir/lm_data/lm_<id>)
349  $lm_dir = $lm_data_dir."/lm_".$this->getId();
350  ilUtil::makeDir($lm_dir);
351  if(!@is_dir($lm_dir))
352  {
353  $this->ilias->raiseError("Creation of Learning Module Directory failed.",$this->ilias->error_obj->FATAL);
354  }
355  // create Export subdirectory (data_dir/lm_data/lm_<id>/Export)
356  switch ($a_type)
357  {
358  // html
359  case "html":
360  $export_dir = $lm_dir."/export_html";
361  break;
362 
363  // scorm
364  case "scorm":
365  $export_dir = $lm_dir."/export_scorm";
366  break;
367 
368  default: // = xml
369  $export_dir = $lm_dir."/export";
370  break;
371  }
372  ilUtil::makeDir($export_dir);
373 
374  if(!@is_dir($export_dir))
375  {
376  $this->ilias->raiseError("Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
377  }
378  }
379 
383  function getExportDirectory($a_type = "xml")
384  {
385  switch ($a_type)
386  {
387  case "html":
388  $export_dir = ilUtil::getDataDir()."/lm_data"."/lm_".$this->getId()."/export_html";
389  break;
390 
391  case "scorm":
392  $export_dir = ilUtil::getDataDir()."/lm_data"."/lm_".$this->getId()."/export_scorm";
393  break;
394 
395  default: // = xml
396  $export_dir = ilUtil::getDataDir()."/lm_data"."/lm_".$this->getId()."/export";
397  break;
398  }
399  return $export_dir;
400  }
401 
402 
413  function delete()
414  {
415  global $ilDB;
416 
417  global $ilBench;
418 
419  // always call parent delete function first!!
420  if (!parent::delete())
421  {
422  return false;
423  }
424 
425  // delete lm object data
426  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
428 
429  // delete meta data of content object
430  $this->deleteMetaData();
431 
432  // delete bibitem data
433  $nested = new ilNestedSetXML();
434  $nested->init($this->getId(), "bib");
435  $nested->deleteAllDBData();
436 
437 
438  // delete learning module tree
439  $this->lm_tree->removeTree($this->lm_tree->getTreeId());
440 
441  // delete data directory
443 
444  // delete content object record
445  $q = "DELETE FROM content_object WHERE id = ".
446  $ilDB->quote($this->getId(), "integer");
447  $ilDB->manipulate($q);
448 
449  // delete lm menu entries
450  $q = "DELETE FROM lm_menu WHERE lm_id = ".
451  $ilDB->quote($this->getId(), "integer");
452  $ilDB->manipulate($q);
453 
454  return true;
455  }
456 
457 
463  function getLayout()
464  {
465  return $this->layout;
466  }
467 
473  function setLayout($a_layout)
474  {
475  $this->layout = $a_layout;
476  }
477 
481  function getStyleSheetId()
482  {
483  return $this->style_id;
484  }
485 
489  function setStyleSheetId($a_style_id)
490  {
491  $this->style_id = $a_style_id;
492  }
493 
497  function writeStyleSheetId($a_style_id)
498  {
499  global $ilDB;
500 
501  $q = "UPDATE content_object SET ".
502  " stylesheet = ".$ilDB->quote((int) $a_style_id, "integer").
503  " WHERE id = ".$ilDB->quote($this->getId(), "integer");
504  $ilDB->manipulate($q);
505 
506  $this->style_id = $a_style_id;
507  }
508 
512  function _moveLMStyles($a_from_style, $a_to_style)
513  {
514  global $ilDB, $ilias;
515 
516  if ($a_from_style < 0) // change / delete all individual styles
517  {
518  $q = "SELECT stylesheet FROM content_object, style_data ".
519  " WHERE content_object.stylesheet = style_data.id ".
520  " AND style_data.standard = ".$ilDB->quote(0, "integer").
521  " AND content_object.stylesheet > ".$ilDB->quote(0, "integer");
522  $style_set = $ilDB->query($q);
523  while($style_rec = $ilDB->fetchAssoc($style_set))
524  {
525  // assign learning modules to new style
526  $q = "UPDATE content_object SET ".
527  " stylesheet = ".$ilDB->quote((int) $a_to_style, "integer").
528  " WHERE stylesheet = ".$ilDB->quote($style_rec["stylesheet"], "integer");
529  $ilDB->manipulate($q);
530 
531  // delete style
532  $style_obj =& $ilias->obj_factory->getInstanceByObjId($style_rec["stylesheet"]);
533  $style_obj->delete();
534  }
535  }
536  else
537  {
538  $q = "UPDATE content_object SET ".
539  " stylesheet = ".$ilDB->quote((int) $a_to_style, "integer").
540  " WHERE stylesheet = ".$ilDB->quote($a_from_style, "integer");
541  $ilDB->manipulate($q);
542  }
543  }
544 
548  function _lookupStyleSheetId($a_cont_obj_id)
549  {
550  global $ilDB;
551 
552  $q = "SELECT stylesheet FROM content_object ".
553  " WHERE id = ".$ilDB->quote($a_cont_obj_id, "integer");
554  $res = $ilDB->query($q);
555  $sheet = $ilDB->fetchAssoc($res);
556 
557  return $sheet["stylesheet"];
558  }
559 
563  function _lookupContObjIdByStyleId($a_style_id)
564  {
565  global $ilDB;
566 
567  $q = "SELECT id FROM content_object ".
568  " WHERE stylesheet = ".$ilDB->quote($a_style_id, "integer");
569  $res = $ilDB->query($q);
570  $obj_ids = array();
571  while($cont = $ilDB->fetchAssoc($res))
572  {
573  $obj_ids[] = $cont["id"];
574  }
575  return $obj_ids;
576  }
577 
583  function _getNrOfAssignedLMs($a_style_id)
584  {
585  global $ilDB;
586 
587  $q = "SELECT count(*) as cnt FROM content_object ".
588  " WHERE stylesheet = ".$ilDB->quote($a_style_id, "integer");
589  $cset = $ilDB->query($q);
590  $crow = $ilDB->fetchAssoc($cset);
591 
592  return (int) $crow["cnt"];
593  }
594 
595 
600  {
601  global $ilDB;
602 
603  // joining with style table (not perfectly nice)
604  $q = "SELECT count(*) as cnt FROM content_object, style_data ".
605  " WHERE stylesheet = style_data.id ".
606  " AND standard = ".$ilDB->quote(0, "integer");
607  $cset = $ilDB->query($q);
608  $crow = $ilDB->fetchAssoc($cset);
609 
610  return (int) $crow["cnt"];
611  }
612 
616  function _getNrLMsNoStyle()
617  {
618  global $ilDB;
619 
620  $q = "SELECT count(*) as cnt FROM content_object ".
621  " WHERE stylesheet = ".$ilDB->quote(0, "integer");
622  $cset = $ilDB->query($q);
623  $crow = $ilDB->fetchAssoc($cset);
624 
625  return (int) $crow["cnt"];
626  }
627 
633  function _deleteStyleAssignments($a_style_id)
634  {
635  global $ilDB;
636 
637  $q = "UPDATE content_object SET ".
638  " stylesheet = ".$ilDB->quote(0, "integer").
639  " WHERE stylesheet = ".$ilDB->quote((int) $this->getId($a_style_id), "integer");
640 
641  $ilDB->manipulate($q);
642  }
643 
647  function getPageHeader()
648  {
649  return $this->pg_header;
650  }
651 
657  function setPageHeader($a_pg_header = IL_CHAPTER_TITLE)
658  {
659  $this->pg_header = $a_pg_header;
660  }
661 
665  function getTOCMode()
666  {
667  return $this->toc_mode;
668  }
669 
674  {
675  return $this->public_access_mode;
676  }
677 
683  function setTOCMode($a_toc_mode = "chapters")
684  {
685  $this->toc_mode = $a_toc_mode;
686  }
687 
688  function setOnline($a_online)
689  {
690  $this->online = $a_online;
691  }
692 
693  function getOnline()
694  {
695  return $this->online;
696  }
697 
698  function setActiveLMMenu($a_act_lm_menu)
699  {
700  $this->lm_menu_active = $a_act_lm_menu;
701  }
702 
703  function isActiveLMMenu()
704  {
705  return $this->lm_menu_active;
706  }
707 
708  function setActiveTOC($a_toc)
709  {
710  $this->toc_active = $a_toc;
711  }
712 
713  function isActiveTOC()
714  {
715  return $this->toc_active;
716  }
717 
718  function setActiveNumbering($a_num)
719  {
720  $this->numbering = $a_num;
721  }
722 
723  function isActiveNumbering()
724  {
725  return $this->numbering;
726  }
727 
728  function setActivePrintView($a_print)
729  {
730  $this->print_view_active = $a_print;
731  }
732 
733  function isActivePrintView()
734  {
735  return $this->print_view_active;
736  }
737 
739  {
740  $this->prevent_glossary_appendix_active = $a_print;
741  }
742 
744  {
745  return $this->prevent_glossary_appendix_active;
746  }
747 
748  function setActiveDownloads($a_down)
749  {
750  $this->downloads_active = $a_down;
751  }
752 
753  function isActiveDownloads()
754  {
755  return $this->downloads_active;
756  }
757 
758  function setActiveDownloadsPublic($a_down)
759  {
760  $this->downloads_public_active = $a_down;
761  }
762 
764  {
765  return $this->downloads_public_active;
766  }
767 
768  function setPublicNotes($a_pub_notes)
769  {
770  $this->pub_notes = $a_pub_notes;
771  }
772 
773  function publicNotes()
774  {
775  return $this->pub_notes;
776  }
777 
778  function setCleanFrames($a_clean)
779  {
780  $this->clean_frames = $a_clean;
781  }
782 
783  function cleanFrames()
784  {
785  return $this->clean_frames;
786  }
787 
788  function setHistoryUserComments($a_comm)
789  {
790  $this->user_comments = $a_comm;
791  }
792 
793  function setPublicAccessMode($a_mode)
794  {
795  $this->public_access_mode = $a_mode;
796  }
797 
799  {
800  return $this->user_comments;
801  }
802 
803  function setHeaderPage($a_pg)
804  {
805  $this->header_page = $a_pg;
806  }
807 
808  function getHeaderPage()
809  {
810  return $this->header_page;
811  }
812 
813  function setFooterPage($a_pg)
814  {
815  $this->footer_page = $a_pg;
816  }
817 
818  function getFooterPage()
819  {
820  return $this->footer_page;
821  }
822 
826  function readProperties()
827  {
828  global $ilDB;
829 
830  $q = "SELECT * FROM content_object WHERE id = ".
831  $ilDB->quote($this->getId(), "integer");
832  $lm_set = $ilDB->query($q);
833  $lm_rec = $ilDB->fetchAssoc($lm_set);
834  $this->setLayout($lm_rec["default_layout"]);
835  $this->setStyleSheetId((int) $lm_rec["stylesheet"]);
836  $this->setPageHeader($lm_rec["page_header"]);
837  $this->setTOCMode($lm_rec["toc_mode"]);
838  $this->setOnline(ilUtil::yn2tf($lm_rec["is_online"]));
839  $this->setActiveTOC(ilUtil::yn2tf($lm_rec["toc_active"]));
840  $this->setActiveNumbering(ilUtil::yn2tf($lm_rec["numbering"]));
841  $this->setActivePrintView(ilUtil::yn2tf($lm_rec["print_view_active"]));
842  $this->setActivePreventGlossaryAppendix(ilUtil::yn2tf($lm_rec["no_glo_appendix"]));
843  $this->setActiveDownloads(ilUtil::yn2tf($lm_rec["downloads_active"]));
844  $this->setActiveDownloadsPublic(ilUtil::yn2tf($lm_rec["downloads_public_active"]));
845  $this->setActiveLMMenu(ilUtil::yn2tf($lm_rec["lm_menu_active"]));
846  $this->setCleanFrames(ilUtil::yn2tf($lm_rec["clean_frames"]));
847  $this->setPublicNotes(ilUtil::yn2tf($lm_rec["pub_notes"]));
848  $this->setHeaderPage((int) $lm_rec["header_page"]);
849  $this->setFooterPage((int) $lm_rec["footer_page"]);
850  $this->setHistoryUserComments(ilUtil::yn2tf($lm_rec["hist_user_comments"]));
851  $this->setPublicAccessMode($lm_rec["public_access_mode"]);
852  $this->setPublicExportFile("xml", $lm_rec["public_xml_file"]);
853  $this->setPublicExportFile("html", $lm_rec["public_html_file"]);
854  $this->setPublicExportFile("scorm", $lm_rec["public_scorm_file"]);
855  $this->setLayoutPerPage($lm_rec["layout_per_page"]);
856  }
857 
861  function updateProperties()
862  {
863  global $ilDB;
864 
865  // force clean_frames to be set, if layout per page is activated
866  if ($this->getLayoutPerPage())
867  {
868  $this->setCleanFrames(true);
869  }
870 
871  $q = "UPDATE content_object SET ".
872  " default_layout = ".$ilDB->quote($this->getLayout(), "text").", ".
873  " stylesheet = ".$ilDB->quote($this->getStyleSheetId(), "integer").",".
874  " page_header = ".$ilDB->quote($this->getPageHeader(), "text").",".
875  " toc_mode = ".$ilDB->quote($this->getTOCMode(), "text").",".
876  " is_online = ".$ilDB->quote(ilUtil::tf2yn($this->getOnline()), "text").",".
877  " toc_active = ".$ilDB->quote(ilUtil::tf2yn($this->isActiveTOC()), "text").",".
878  " numbering = ".$ilDB->quote(ilUtil::tf2yn($this->isActiveNumbering()), "text").",".
879  " print_view_active = ".$ilDB->quote(ilUtil::tf2yn($this->isActivePrintView()), "text").",".
880  " no_glo_appendix = ".$ilDB->quote(ilUtil::tf2yn($this->isActivePreventGlossaryAppendix()), "text").",".
881  " downloads_active = ".$ilDB->quote(ilUtil::tf2yn($this->isActiveDownloads()), "text").",".
882  " downloads_public_active = ".$ilDB->quote(ilUtil::tf2yn($this->isActiveDownloadsPublic()), "text").",".
883  " clean_frames = ".$ilDB->quote(ilUtil::tf2yn($this->cleanFrames()), "text").",".
884  " pub_notes = ".$ilDB->quote(ilUtil::tf2yn($this->publicNotes()), "text").",".
885  " hist_user_comments = ".$ilDB->quote(ilUtil::tf2yn($this->isActiveHistoryUserComments()), "text").",".
886  " public_access_mode = ".$ilDB->quote($this->getPublicAccessMode(), "text").",".
887  " public_xml_file = ".$ilDB->quote($this->getPublicExportFile("xml"), "text").",".
888  " public_html_file = ".$ilDB->quote($this->getPublicExportFile("html"), "text").",".
889  " public_scorm_file = ".$ilDB->quote($this->getPublicExportFile("scorm"), "text").",".
890  " header_page = ".$ilDB->quote($this->getHeaderPage(), "integer").",".
891  " footer_page = ".$ilDB->quote($this->getFooterPage(), "integer").",".
892  " lm_menu_active = ".$ilDB->quote(ilUtil::tf2yn($this->isActiveLMMenu()), "text").", ".
893  " layout_per_page = ".$ilDB->quote($this->getLayoutPerPage(), "integer")." ".
894  " WHERE id = ".$ilDB->quote($this->getId(), "integer");
895  $ilDB->manipulate($q);
896  }
897 
901  function createProperties()
902  {
903  global $ilDB;
904 
905  $q = "INSERT INTO content_object (id) VALUES (".$ilDB->quote($this->getId(), "integer").")";
906  $ilDB->manipulate($q);
907  $this->readProperties(); // to get db default values
908  }
909 
913  function _lookupOnline($a_id)
914  {
915  global $ilDB;
916 
917 //echo "class ilObjContentObject::_lookupOnline($a_id) called. Use Access class instead.";
918 
919  $q = "SELECT is_online FROM content_object WHERE id = ".$ilDB->quote($a_id, "integer");
920  $lm_set = $ilDB->query($q);
921  $lm_rec = $ilDB->fetchAssoc($lm_set);
922 
923  return ilUtil::yn2tf($lm_rec["is_online"]);
924  }
925 
932  {
933  // read sdir, copy files and copy directories recursively
934  $dir = opendir("./Modules/LearningModule/layouts/lm");
935 
936  $layouts = array();
937 
938  while($file = readdir($dir))
939  {
940  if ($file != "." && $file != ".." && $file != "CVS" && $file != ".svn")
941  {
942  // directories
943  if (@is_dir("./Modules/LearningModule/layouts/lm/".$file))
944  {
945  $layouts[$file] = $file;
946  }
947  }
948  }
949  asort($layouts);
950  return $layouts;
951  }
952 
956  function _checkPreconditionsOfPage($cont_ref_id,$cont_obj_id, $page_id)
957  {
958  global $ilUser,$ilErr;
959 
960  $lm_tree = new ilTree($cont_obj_id);
961  $lm_tree->setTableNames('lm_tree','lm_data');
962  $lm_tree->setTreeTablePK("lm_id");
963 
964  if ($lm_tree->isInTree($page_id))
965  {
966  $path = $lm_tree->getPathFull($page_id, $lm_tree->readRootId());
967  foreach ($path as $node)
968  {
969  if ($node["type"] == "st")
970  {
971  if (!ilConditionHandler::_checkAllConditionsOfTarget($cont_ref_id,$node["child"], "st"))
972  {
973  return false;
974  }
975  }
976  }
977  }
978 
979  return true;
980  }
981 
985  function _getMissingPreconditionsOfPage($cont_ref_id,$cont_obj_id, $page_id)
986  {
987  $lm_tree = new ilTree($cont_obj_id);
988  $lm_tree->setTableNames('lm_tree','lm_data');
989  $lm_tree->setTreeTablePK("lm_id");
990 
991  $conds = array();
992  if ($lm_tree->isInTree($page_id))
993  {
994  // get full path of page
995  $path = $lm_tree->getPathFull($page_id, $lm_tree->readRootId());
996  foreach ($path as $node)
997  {
998  if ($node["type"] == "st")
999  {
1000  // get all preconditions of upper chapters
1001  $tconds = ilConditionHandler::_getConditionsOfTarget($cont_ref_id,$node["child"], "st");
1002  foreach ($tconds as $tcond)
1003  {
1004  // store all missing preconditions
1005  if (!ilConditionHandler::_checkCondition($tcond["id"]))
1006  {
1007  $conds[] = $tcond;
1008  }
1009  }
1010  }
1011  }
1012  }
1013 
1014  return $conds;
1015  }
1016 
1020  function _getMissingPreconditionsTopChapter($cont_obj_ref_id,$cont_obj_id, $page_id)
1021  {
1022  $lm_tree = new ilTree($cont_obj_id);
1023  $lm_tree->setTableNames('lm_tree','lm_data');
1024  $lm_tree->setTreeTablePK("lm_id");
1025 
1026  $conds = array();
1027  if ($lm_tree->isInTree($page_id))
1028  {
1029  // get full path of page
1030  $path = $lm_tree->getPathFull($page_id, $lm_tree->readRootId());
1031  foreach ($path as $node)
1032  {
1033  if ($node["type"] == "st")
1034  {
1035  // get all preconditions of upper chapters
1036  $tconds = ilConditionHandler::_getConditionsOfTarget($cont_obj_ref_id,$node["child"], "st");
1037  foreach ($tconds as $tcond)
1038  {
1039  // look for missing precondition
1040  if (!ilConditionHandler::_checkCondition($tcond["id"]))
1041  {
1042  return $node["child"];
1043  }
1044  }
1045  }
1046  }
1047  }
1048 
1049  return "";
1050  }
1051 
1062  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
1063  {
1064  global $tree;
1065 
1066  switch ($a_event)
1067  {
1068  case "link":
1069 
1070  //var_dump("<pre>",$a_params,"</pre>");
1071  //echo "Content Object ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
1072  //exit;
1073  break;
1074 
1075  case "cut":
1076 
1077  //echo "Content Object ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
1078  //exit;
1079  break;
1080 
1081  case "copy":
1082 
1083  //var_dump("<pre>",$a_params,"</pre>");
1084  //echo "Content Object ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
1085  //exit;
1086  break;
1087 
1088  case "paste":
1089 
1090  //echo "Content Object ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
1091  //exit;
1092  break;
1093 
1094  case "new":
1095 
1096  //echo "Content Object ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
1097  //exit;
1098  break;
1099  }
1100 
1101  // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
1102  if ($a_node_id==$_GET["ref_id"])
1103  {
1104  $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
1105  $parent_type = $parent_obj->getType();
1106  if($parent_type == $this->getType())
1107  {
1108  $a_node_id = (int) $tree->getParentId($a_node_id);
1109  }
1110  }
1111 
1112  parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
1113  }
1114 
1115 
1119  function hasSuccessorPage($a_cont_obj_id, $a_page_id)
1120  {
1121  $tree = new ilTree($a_cont_obj_id);
1122  $tree->setTableNames('lm_tree','lm_data');
1123  $tree->setTreeTablePK("lm_id");
1124  if ($tree->isInTree($a_page_id))
1125  {
1126  $succ = $tree->fetchSuccessorNode($a_page_id, "pg");
1127  if ($succ > 0)
1128  {
1129  return true;
1130  }
1131  }
1132  return false;
1133  }
1134 
1135 
1136  function checkTree()
1137  {
1138  $tree = new ilTree($this->getId());
1139  $tree->setTableNames('lm_tree','lm_data');
1140  $tree->setTreeTablePK("lm_id");
1141  $tree->checkTree();
1142  $tree->checkTreeChilds();
1143 //echo "checked";
1144  }
1145 
1149  function fixTree()
1150  {
1151  global $ilDB;
1152 
1153  $tree =& $this->getLMTree();
1154 
1155  // delete subtrees that have no lm_data records
1156  $nodes = $tree->getSubtree($tree->getNodeData($tree->getRootId()));
1157  foreach ($nodes as $node)
1158  {
1159  $q = "SELECT * FROM lm_data WHERE obj_id = ".
1160  $ilDB->quote($node["child"], "integer");
1161  $obj_set = $ilDB->query($q);
1162  $obj_rec = $ilDB->fetchAssoc($obj_set);
1163  if (!$obj_rec)
1164  {
1165  $node_data = $tree->getNodeData($node["child"]);
1166  $tree->deleteTree($node_data);
1167  }
1168  }
1169 
1170  // delete subtrees that have pages as parent
1171  $nodes = $tree->getSubtree($tree->getNodeData($tree->getRootId()));
1172  foreach ($nodes as $node)
1173  {
1174  $q = "SELECT * FROM lm_data WHERE obj_id = ".
1175  $ilDB->quote($node["parent"], "integer");
1176  $obj_set = $ilDB->query($q);
1177  $obj_rec = $ilDB->fetchAssoc($obj_set);
1178  if ($obj_rec["type"] == "pg")
1179  {
1180  $node_data = $tree->getNodeData($node["child"]);
1181  if ($tree->isInTree($node["child"]))
1182  {
1183  $tree->deleteTree($node_data);
1184  }
1185  }
1186  }
1187 
1188  }
1189 
1190 
1197  function exportXML(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
1198  {
1199  global $ilBench;
1200 
1201  $attrs = array();
1202  switch($this->getType())
1203  {
1204  case "lm":
1205  $attrs["Type"] = "LearningModule";
1206  break;
1207 
1208  case "dbk":
1209  $attrs["Type"] = "LibObject";
1210  break;
1211  }
1212  $a_xml_writer->xmlStartTag("ContentObject", $attrs);
1213 
1214  // MetaData
1215  $this->exportXMLMetaData($a_xml_writer);
1216 
1217  // StructureObjects
1218 //echo "ContObj:".$a_inst.":<br>";
1219  $expLog->write(date("[y-m-d H:i:s] ")."Start Export Structure Objects");
1220  $ilBench->start("ContentObjectExport", "exportStructureObjects");
1221  $this->exportXMLStructureObjects($a_xml_writer, $a_inst, $expLog);
1222  $ilBench->stop("ContentObjectExport", "exportStructureObjects");
1223  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Structure Objects");
1224 
1225  // PageObjects
1226  $expLog->write(date("[y-m-d H:i:s] ")."Start Export Page Objects");
1227  $ilBench->start("ContentObjectExport", "exportPageObjects");
1228  $this->exportXMLPageObjects($a_xml_writer, $a_inst, $expLog);
1229  $ilBench->stop("ContentObjectExport", "exportPageObjects");
1230  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Page Objects");
1231 
1232  // MediaObjects
1233  $expLog->write(date("[y-m-d H:i:s] ")."Start Export Media Objects");
1234  $ilBench->start("ContentObjectExport", "exportMediaObjects");
1235  $this->exportXMLMediaObjects($a_xml_writer, $a_inst, $a_target_dir, $expLog);
1236  $ilBench->stop("ContentObjectExport", "exportMediaObjects");
1237  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Media Objects");
1238 
1239  // FileItems
1240  $expLog->write(date("[y-m-d H:i:s] ")."Start Export File Items");
1241  $ilBench->start("ContentObjectExport", "exportFileItems");
1242  $this->exportFileItems($a_target_dir, $expLog);
1243  $ilBench->stop("ContentObjectExport", "exportFileItems");
1244  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export File Items");
1245 
1246  // Questions
1247  if (count($this->q_ids) > 0)
1248  {
1249  $qti_file = fopen($a_target_dir."/qti.xml", "w");
1250  include_once("./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php");
1251  $pool = new ilObjQuestionPool();
1252  fwrite($qti_file, $pool->toXML($this->q_ids));
1253  fclose($qti_file);
1254  }
1255 
1256  // To do: implement version selection/detection
1257  // Properties
1258  $expLog->write(date("[y-m-d H:i:s] ")."Start Export Properties");
1259  $this->exportXMLProperties($a_xml_writer, $expLog);
1260  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Properties");
1261 
1262  $a_xml_writer->xmlEndTag("ContentObject");
1263  }
1264 
1271  function exportXMLMetaData(&$a_xml_writer)
1272  {
1273  include_once("Services/MetaData/classes/class.ilMD2XML.php");
1274  $md2xml = new ilMD2XML($this->getId(), 0, $this->getType());
1275  $md2xml->setExportMode(true);
1276  $md2xml->startExport();
1277  $a_xml_writer->appendXML($md2xml->getXML());
1278  }
1279 
1286  function exportXMLStructureObjects(&$a_xml_writer, $a_inst, &$expLog)
1287  {
1288  include_once './Modules/LearningModule/classes/class.ilStructureObject.php';
1289 
1290  $childs = $this->lm_tree->getChilds($this->lm_tree->getRootId());
1291  foreach ($childs as $child)
1292  {
1293  if($child["type"] != "st")
1294  {
1295  continue;
1296  }
1297 
1298  $structure_obj = new ilStructureObject($this, $child["obj_id"]);
1299  $structure_obj->exportXML($a_xml_writer, $a_inst, $expLog);
1300  unset($structure_obj);
1301  }
1302  }
1303 
1304 
1311  function exportXMLPageObjects(&$a_xml_writer, $a_inst, &$expLog)
1312  {
1313  global $ilBench;
1314 
1315  include_once "./Modules/LearningModule/classes/class.ilLMPageObject.php";
1316 
1317  $pages = ilLMPageObject::getPageList($this->getId());
1318  foreach ($pages as $page)
1319  {
1320  if (ilPageObject::_exists($this->getType(), $page["obj_id"]))
1321  {
1322  $expLog->write(date("[y-m-d H:i:s] ")."Page Object ".$page["obj_id"]);
1323 
1324  // export xml to writer object
1325  $page_obj = new ilLMPageObject($this, $page["obj_id"]);
1326  $page_obj->exportXML($a_xml_writer, "normal", $a_inst);
1327 
1328  // collect media objects
1329  $mob_ids = $page_obj->getMediaObjectIDs();
1330  foreach($mob_ids as $mob_id)
1331  {
1332  $this->mob_ids[$mob_id] = $mob_id;
1333  }
1334 
1335  // collect all file items
1336  $file_ids = $page_obj->getFileItemIds();
1337  foreach($file_ids as $file_id)
1338  {
1339  $this->file_ids[$file_id] = $file_id;
1340  }
1341 
1342  // collect all questions
1343  $q_ids = $page_obj->getQuestionIds();
1344  foreach($q_ids as $q_id)
1345  {
1346  $this->q_ids[$q_id] = $q_id;
1347  }
1348 
1349  unset($page_obj);
1350  }
1351  }
1352  }
1353 
1360  function exportXMLMediaObjects(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
1361  {
1362  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1363 
1364  $linked_mobs = array();
1365 
1366  // mobs directly embedded into pages
1367  foreach ($this->mob_ids as $mob_id)
1368  {
1369  if ($mob_id > 0 && ilObject::_lookupType($mob_id) == "mob")
1370  {
1371  $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
1372  $media_obj = new ilObjMediaObject($mob_id);
1373  $media_obj->exportXML($a_xml_writer, $a_inst);
1374  $media_obj->exportFiles($a_target_dir);
1375 
1376  $lmobs = $media_obj->getLinkedMediaObjects($this->mob_ids);
1377  $linked_mobs = array_merge($linked_mobs, $lmobs);
1378 
1379  unset($media_obj);
1380  }
1381  }
1382 
1383  // linked mobs (in map areas)
1384  foreach ($linked_mobs as $mob_id)
1385  {
1386  if ($mob_id > 0)
1387  {
1388  $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
1389  $media_obj = new ilObjMediaObject($mob_id);
1390  $media_obj->exportXML($a_xml_writer, $a_inst);
1391  $media_obj->exportFiles($a_target_dir);
1392  unset($media_obj);
1393  }
1394  }
1395 
1396  }
1397 
1402  function exportFileItems($a_target_dir, &$expLog)
1403  {
1404  include_once("./Modules/File/classes/class.ilObjFile.php");
1405 
1406  foreach ($this->file_ids as $file_id)
1407  {
1408  $expLog->write(date("[y-m-d H:i:s] ")."File Item ".$file_id);
1409  $file_obj = new ilObjFile($file_id, false);
1410  $file_obj->export($a_target_dir);
1411  unset($file_obj);
1412  }
1413  }
1414 
1419  function exportXMLProperties($a_xml_writer, &$expLog)
1420  {
1421  $attrs = array();
1422  $a_xml_writer->xmlStartTag("Properties", $attrs);
1423 
1424  // Layout
1425  $attrs = array("Name" => "Layout", "Value" => $this->getLayout());
1426  $a_xml_writer->xmlElement("Property", $attrs);
1427 
1428  // Page Header
1429  $attrs = array("Name" => "PageHeader", "Value" => $this->getPageHeader());
1430  $a_xml_writer->xmlElement("Property", $attrs);
1431 
1432  // TOC Mode
1433  $attrs = array("Name" => "TOCMode", "Value" => $this->getTOCMode());
1434  $a_xml_writer->xmlElement("Property", $attrs);
1435 
1436  // LM Menu Activation
1437  $attrs = array("Name" => "ActiveLMMenu", "Value" =>
1438  ilUtil::tf2yn($this->isActiveLMMenu()));
1439  $a_xml_writer->xmlElement("Property", $attrs);
1440 
1441  // Numbering Activation
1442  $attrs = array("Name" => "ActiveNumbering", "Value" =>
1443  ilUtil::tf2yn($this->isActiveNumbering()));
1444  $a_xml_writer->xmlElement("Property", $attrs);
1445 
1446  // Table of contents button activation
1447  $attrs = array("Name" => "ActiveTOC", "Value" =>
1448  ilUtil::tf2yn($this->isActiveTOC()));
1449  $a_xml_writer->xmlElement("Property", $attrs);
1450 
1451  // Print view button activation
1452  $attrs = array("Name" => "ActivePrintView", "Value" =>
1453  ilUtil::tf2yn($this->isActivePrintView()));
1454  $a_xml_writer->xmlElement("Property", $attrs);
1455 
1456  // Note that download button is not saved, because
1457  // download files do not exist after import
1458 
1459  // Clean frames
1460  $attrs = array("Name" => "CleanFrames", "Value" =>
1461  ilUtil::tf2yn($this->cleanFrames()));
1462  $a_xml_writer->xmlElement("Property", $attrs);
1463 
1464  // Public notes activation
1465  $attrs = array("Name" => "PublicNotes", "Value" =>
1466  ilUtil::tf2yn($this->publicNotes()));
1467  $a_xml_writer->xmlElement("Property", $attrs);
1468 
1469  // History comments for authors activation
1470  $attrs = array("Name" => "HistoryUserComments", "Value" =>
1472  $a_xml_writer->xmlElement("Property", $attrs);
1473 
1474  // Header Page
1475  if ($this->getHeaderPage() > 0)
1476  {
1477  $attrs = array("Name" => "HeaderPage", "Value" =>
1478  "il_".IL_INST_ID."_pg_".$this->getHeaderPage());
1479  $a_xml_writer->xmlElement("Property", $attrs);
1480  }
1481 
1482  // Footer Page
1483  if ($this->getFooterPage() > 0)
1484  {
1485  $attrs = array("Name" => "FooterPage", "Value" =>
1486  "il_".IL_INST_ID."_pg_".$this->getFooterPage());
1487  $a_xml_writer->xmlElement("Property", $attrs);
1488  }
1489 
1490  $a_xml_writer->xmlEndTag("Properties");
1491  }
1492 
1496  function getExportFiles()
1497  {
1498  $file = array();
1499 
1500  $types = array("xml", "html", "scorm");
1501 
1502  foreach ($types as $type)
1503  {
1504  $dir = $this->getExportDirectory($type);
1505  // quit if import dir not available
1506  if (!@is_dir($dir) or
1507  !is_writeable($dir))
1508  {
1509  continue;
1510  }
1511 
1512  // open directory
1513  $cdir = dir($dir);
1514 
1515  // initialize array
1516 
1517  // get files and save the in the array
1518  while ($entry = $cdir->read())
1519  {
1520  if ($entry != "." and
1521  $entry != ".." and
1522  substr($entry, -4) == ".zip" and
1523  ereg("^[0-9]{10}_{2}[0-9]+_{2}(lm_)*[0-9]+\.zip\$", $entry))
1524  {
1525  $file[$entry.$type] = array("type" => $type, "file" => $entry,
1526  "size" => filesize($dir."/".$entry));
1527  }
1528  }
1529 
1530  // close import directory
1531  $cdir->close();
1532  }
1533 
1534  // sort files
1535  ksort ($file);
1536  reset ($file);
1537  return $file;
1538  }
1539 
1546  function setPublicExportFile($a_type, $a_file)
1547  {
1548  $this->public_export_file[$a_type] = $a_file;
1549  }
1550 
1558  function getPublicExportFile($a_type)
1559  {
1560  return $this->public_export_file[$a_type];
1561  }
1562 
1567  {
1568  // quit if offline dir not available
1569  if (!@is_dir($dir) or
1570  !is_writeable($dir))
1571  {
1572  return array();
1573  }
1574 
1575  // open directory
1576  $dir = dir($dir);
1577 
1578  // initialize array
1579  $file = array();
1580 
1581  // get files and save the in the array
1582  while ($entry = $dir->read())
1583  {
1584  if ($entry != "." and
1585  $entry != ".." and
1586  substr($entry, -4) == ".pdf" and
1587  ereg("^[0-9]{10}_{2}[0-9]+_{2}(lm_)*[0-9]+\.pdf\$", $entry))
1588  {
1589  $file[] = $entry;
1590  }
1591  }
1592 
1593  // close import directory
1594  $dir->close();
1595 
1596  // sort files
1597  sort ($file);
1598  reset ($file);
1599 
1600  return $file;
1601  }
1602 
1606  function exportSCORM($a_target_dir, $log)
1607  {
1608  ilUtil::delDir($a_target_dir);
1609  ilUtil::makeDir($a_target_dir);
1610  //ilUtil::makeDir($a_target_dir."/res");
1611 
1612  // export everything to html
1613  $this->exportHTML($a_target_dir."/res", $log, false, "scorm");
1614 
1615  // build manifest file
1616  include("./Modules/LearningModule/classes/class.ilContObjectManifestBuilder.php");
1617  $man_builder = new ilContObjectManifestBuilder($this);
1618  $man_builder->buildManifest();
1619  $man_builder->dump($a_target_dir);
1620 
1621  // copy scorm 1.2 schema definitions
1622  copy("Modules/LearningModule/scorm_xsd/adlcp_rootv1p2.xsd", $a_target_dir."/adlcp_rootv1p2.xsd");
1623  copy("Modules/LearningModule/scorm_xsd/imscp_rootv1p1p2.xsd", $a_target_dir."/imscp_rootv1p1p2.xsd");
1624  copy("Modules/LearningModule/scorm_xsd/imsmd_rootv1p2p1.xsd", $a_target_dir."/imsmd_rootv1p2p1.xsd");
1625  copy("Modules/LearningModule/scorm_xsd/ims_xml.xsd", $a_target_dir."/ims_xml.xsd");
1626 
1627  // zip it all
1628  $date = time();
1629  $zip_file = $a_target_dir."/".$date."__".IL_INST_ID."__".
1630  $this->getType()."_".$this->getId().".zip";
1631  //echo "zip-".$a_target_dir."-to-".$zip_file;
1632  ilUtil::zip(array($a_target_dir."/res",
1633  $a_target_dir."/imsmanifest.xml",
1634  $a_target_dir."/adlcp_rootv1p2.xsd",
1635  $a_target_dir."/imscp_rootv1p1p2.xsd",
1636  $a_target_dir."/ims_xml.xsd",
1637  $a_target_dir."/imsmd_rootv1p2p1.xsd")
1638  , $zip_file);
1639 
1640  $dest_file = $this->getExportDirectory("scorm")."/".$date."__".IL_INST_ID."__".
1641  $this->getType()."_".$this->getId().".zip";
1642 
1643  rename($zip_file, $dest_file);
1644  ilUtil::delDir($a_target_dir);
1645 
1646  }
1647 
1648 
1652  function exportHTML($a_target_dir, $log, $a_zip_file = true, $a_export_format = "html")
1653  {
1654  global $tpl, $ilBench, $ilLocator, $ilUser;
1655 
1656  // initialize temporary target directory
1657  ilUtil::delDir($a_target_dir);
1658  ilUtil::makeDir($a_target_dir);
1659  $mob_dir = $a_target_dir."/mobs";
1660  ilUtil::makeDir($mob_dir);
1661  $file_dir = $a_target_dir."/files";
1662  ilUtil::makeDir($file_dir);
1663  $teximg_dir = $a_target_dir."/teximg";
1664  ilUtil::makeDir($teximg_dir);
1665  $style_dir = $a_target_dir."/style";
1666  ilUtil::makeDir($style_dir);
1667  $style_img_dir = $a_target_dir."/style/images";
1668  ilUtil::makeDir($style_img_dir);
1669  $content_style_dir = $a_target_dir."/content_style";
1670  ilUtil::makeDir($content_style_dir);
1671  $content_style_img_dir = $a_target_dir."/content_style/images";
1672  ilUtil::makeDir($content_style_img_dir);
1673  $GLOBALS["teximgcnt"] = 0;
1674 
1675  // export system style sheet
1676  $location_stylesheet = ilUtil::getStyleSheetLocation("filesystem");
1677  $style_name = $ilUser->prefs["style"].".css";
1678  copy($location_stylesheet, $style_dir."/".$style_name);
1679  $fh = fopen($location_stylesheet, "r");
1680  $css = fread($fh, filesize($location_stylesheet));
1681  preg_match_all("/url\(([^\)]*)\)/",$css,$files);
1682  foreach (array_unique($files[1]) as $fileref)
1683  {
1684  $fileref = dirname($location_stylesheet)."/".$fileref;
1685  if (is_file($fileref))
1686  {
1687  copy($fileref, $style_img_dir."/".basename($fileref));
1688  }
1689  }
1690  fclose($fh);
1691  $location_stylesheet = ilUtil::getStyleSheetLocation();
1692 
1693  // export content style sheet
1694  $ilBench->start("ExportHTML", "exportContentStyle");
1695  if ($this->getStyleSheetId() < 1)
1696  {
1697  $cont_stylesheet = "./Services/COPage/css/content.css";
1698 
1699  $css = fread(fopen($cont_stylesheet,'r'),filesize($cont_stylesheet));
1700  preg_match_all("/url\(([^\)]*)\)/",$css,$files);
1701  foreach (array_unique($files[1]) as $fileref)
1702  {
1703  if (is_file(str_replace("..", ".", $fileref)))
1704  {
1705  copy(str_replace("..", ".", $fileref), $content_style_img_dir."/".basename($fileref));
1706  }
1707  $css = str_replace($fileref, "images/".basename($fileref),$css);
1708  }
1709  fwrite(fopen($content_style_dir."/content.css",'w'),$css);
1710  }
1711  else
1712  {
1713  $style = new ilObjStyleSheet($this->getStyleSheetId());
1714  $style->writeCSSFile($content_style_dir."/content.css", "images");
1715  $style->copyImagesToDir($content_style_img_dir);
1716  }
1717  $ilBench->stop("ExportHTML", "exportContentStyle");
1718 
1719  // export syntax highlighting style
1720  $syn_stylesheet = ilObjStyleSheet::getSyntaxStylePath();
1721  copy($syn_stylesheet, $a_target_dir."/syntaxhighlight.css");
1722 
1723  // get learning module presentation gui class
1724  include_once("./Modules/LearningModule/classes/class.ilLMPresentationGUI.php");
1725  $_GET["cmd"] = "nop";
1726  $lm_gui =& new ilLMPresentationGUI();
1727  $lm_gui->setOfflineMode(true);
1728  $lm_gui->setOfflineDirectory($a_target_dir);
1729  $lm_gui->setExportFormat($a_export_format);
1730 
1731  // export pages
1732  $ilBench->start("ExportHTML", "exportHTMLPages");
1733  $this->exportHTMLPages($lm_gui, $a_target_dir);
1734  $ilBench->stop("ExportHTML", "exportHTMLPages");
1735 
1736  // export glossary terms
1737  $ilBench->start("ExportHTML", "exportHTMLGlossaryTerms");
1738  $this->exportHTMLGlossaryTerms($lm_gui, $a_target_dir);
1739  $ilBench->stop("ExportHTML", "exportHTMLGlossaryTerms");
1740 
1741  // export all media objects
1742  $ilBench->start("ExportHTML", "exportHTMLMediaObjects");
1743  $linked_mobs = array();
1744  foreach ($this->offline_mobs as $mob)
1745  {
1746  if (ilObject::_exists($mob) && ilObject::_lookupType($mob) == "mob")
1747  {
1748  $this->exportHTMLMOB($a_target_dir, $lm_gui, $mob, "_blank", $linked_mobs);
1749  }
1750  }
1751  $linked_mobs2 = array(); // mobs linked in link areas
1752  foreach ($linked_mobs as $mob)
1753  {
1754  if (ilObject::_exists($mob))
1755  {
1756  $this->exportHTMLMOB($a_target_dir, $lm_gui, $mob, "_blank", $linked_mobs2);
1757  }
1758  }
1759  $_GET["obj_type"] = "MediaObject";
1760  $_GET["obj_id"] = $a_mob_id;
1761  $_GET["cmd"] = "";
1762  $ilBench->stop("ExportHTML", "exportHTMLMediaObjects");
1763 
1764  // export all file objects
1765  $ilBench->start("ExportHTML", "exportHTMLFileObjects");
1766  foreach ($this->offline_files as $file)
1767  {
1768  $this->exportHTMLFile($a_target_dir, $file);
1769  }
1770  $ilBench->stop("ExportHTML", "exportHTMLFileObjects");
1771 
1772  // export table of contents
1773  $ilBench->start("ExportHTML", "exportHTMLTOC");
1774  $ilLocator->clearItems();
1775  if ($this->isActiveTOC())
1776  {
1777  $tpl = new ilTemplate("tpl.main.html", true, true);
1778  //$tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
1779  $content =& $lm_gui->showTableOfContents();
1780  $file = $a_target_dir."/table_of_contents.html";
1781 
1782  // open file
1783  if (!($fp = @fopen($file,"w+")))
1784  {
1785  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
1786  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
1787  }
1788  chmod($file, 0770);
1789  fwrite($fp, $content);
1790  fclose($fp);
1791  }
1792  $ilBench->stop("ExportHTML", "exportHTMLTOC");
1793 
1794  // export images
1795  $ilBench->start("ExportHTML", "exportHTMLImages");
1796  $image_dir = $a_target_dir."/images";
1797  ilUtil::makeDir($image_dir);
1798  ilUtil::makeDir($image_dir."/browser");
1799  copy(ilUtil::getImagePath("enlarge.gif", false, "filesystem"),
1800  $image_dir."/enlarge.gif");
1801  copy(ilUtil::getImagePath("browser/blank.gif", false, "filesystem"),
1802  $image_dir."/browser/plus.gif");
1803  copy(ilUtil::getImagePath("browser/blank.gif", false, "filesystem"),
1804  $image_dir."/browser/minus.gif");
1805  copy(ilUtil::getImagePath("browser/blank.gif", false, "filesystem"),
1806  $image_dir."/browser/blank.gif");
1807  copy(ilUtil::getImagePath("spacer.gif", false, "filesystem"),
1808  $image_dir."/spacer.gif");
1809  copy(ilUtil::getImagePath("icon_st.gif", false, "filesystem"),
1810  $image_dir."/icon_st.gif");
1811  copy(ilUtil::getImagePath("icon_pg.gif", false, "filesystem"),
1812  $image_dir."/icon_pg.gif");
1813  copy(ilUtil::getImagePath("icon_st_s.gif", false, "filesystem"),
1814  $image_dir."/icon_st_s.gif");
1815  copy(ilUtil::getImagePath("icon_pg_s.gif", false, "filesystem"),
1816  $image_dir."/icon_pg_s.gif");
1817  copy(ilUtil::getImagePath("icon_lm.gif", false, "filesystem"),
1818  $image_dir."/icon_lm.gif");
1819  copy(ilUtil::getImagePath("icon_lm_s.gif", false, "filesystem"),
1820  $image_dir."/icon_lm_s.gif");
1821  copy(ilUtil::getImagePath("nav_arr_L.gif", false, "filesystem"),
1822  $image_dir."/nav_arr_L.gif");
1823  copy(ilUtil::getImagePath("nav_arr_R.gif", false, "filesystem"),
1824  $image_dir."/nav_arr_R.gif");
1825  copy(ilUtil::getImagePath("browser/forceexp.gif", false, "filesystem"),
1826  $image_dir."/browser/forceexp.gif");
1827 
1828  copy(ilUtil::getImagePath("download.gif", false, "filesystem"),
1829  $image_dir."/download.gif");
1830  $ilBench->stop("ExportHTML", "exportHTMLImages");
1831 
1832  // export flv/mp3 player
1833  $services_dir = $a_target_dir."/Services";
1834  ilUtil::makeDir($services_dir);
1835  $media_service_dir = $services_dir."/MediaObjects";
1836  ilUtil::makeDir($media_service_dir);
1837  $flv_dir = $media_service_dir."/flash_flv_player";
1838  ilUtil::makeDir($flv_dir);
1839  $mp3_dir = $media_service_dir."/flash_mp3_player";
1840  ilUtil::makeDir($mp3_dir);
1841  copy("./Services/MediaObjects/flash_flv_player/flvplayer.swf",
1842  $flv_dir."/flvplayer.swf");
1843  copy("./Services/MediaObjects/flash_mp3_player/mp3player.swf",
1844  $mp3_dir."/mp3player.swf");
1845 
1846  // js files
1847  ilUtil::makeDir($a_target_dir.'/js');
1848  ilUtil::makeDir($a_target_dir.'/js/yahoo');
1849  ilUtil::makeDir($a_target_dir.'/css');
1850  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
1851  foreach (self::getSupplyingExportFiles($a_target_dir) as $f)
1852  {
1853  copy($f["source"], $f["target"]);
1854  }
1855 
1856  // template workaround: reset of template
1857  $tpl = new ilTemplate("tpl.main.html", true, true);
1858  $tpl->setVariable("LOCATION_STYLESHEET",$location_stylesheet);
1859  $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
1860 
1861  // zip everything
1862  $ilBench->start("ExportHTML", "zip");
1863  if (true)
1864  {
1865  if ($a_zip_file)
1866  {
1867  // zip it all
1868  $date = time();
1869  $zip_file = $this->getExportDirectory("html")."/".$date."__".IL_INST_ID."__".
1870  $this->getType()."_".$this->getId().".zip";
1871  ilUtil::zip($a_target_dir, $zip_file);
1872  ilUtil::delDir($a_target_dir);
1873  }
1874  }
1875  $ilBench->stop("ExportHTML", "zip");
1876 
1877  }
1878 
1885  static function getSupplyingExportFiles($a_target_dir = ".")
1886  {
1887  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
1888  return array(
1889  array("source" => ilYuiUtil::getLocalPath('yahoo/yahoo-min.js'),
1890  "target" => $a_target_dir.'/js/yahoo/yahoo-min.js',
1891  "type" => "js"),
1892  array("source" => ilYuiUtil::getLocalPath('yahoo-dom-event/yahoo-dom-event.js'),
1893  "target" => $a_target_dir.'/js/yahoo/yahoo-dom-event.js',
1894  "type" => "js"),
1895  array("source" => ilYuiUtil::getLocalPath('animation/animation-min.js'),
1896  "target" => $a_target_dir.'/js/yahoo/animation-min.js',
1897  "type" => "js"),
1898  array("source" => './Services/JavaScript/js/Basic.js',
1899  "target" => $a_target_dir.'/js/Basic.js',
1900  "type" => "js"),
1901  array("source" => './Services/Accordion/js/accordion.js',
1902  "target" => $a_target_dir.'/js/accordion.js',
1903  "type" => "js"),
1904  array("source" => './Services/Accordion/css/accordion.css',
1905  "target" => $a_target_dir.'/css/accordion.css',
1906  "type" => "css"),
1907  array("source" => './Modules/Scorm2004/scripts/questions/jquery.js',
1908  "target" => $a_target_dir.'/js/jquery.js',
1909  "type" => "js"),
1910  array("source" => './Modules/Scorm2004/scripts/questions/jquery-ui-min.js',
1911  "target" => $a_target_dir.'/js/jquery-ui-min.js',
1912  "type" => "js"),
1913  array("source" => './Modules/Scorm2004/scripts/questions/pure.js',
1914  "target" => $a_target_dir.'/js/pure.js',
1915  "type" => "js"),
1916  array("source" => './Modules/Scorm2004/scripts/questions/question_handling.js',
1917  "target" => $a_target_dir.'/js/question_handling.js',
1918  "type" => "js")
1919  );
1920  }
1921 
1925  function exportHTMLFile($a_target_dir, $a_file_id)
1926  {
1927  $file_dir = $a_target_dir."/files/file_".$a_file_id;
1928  ilUtil::makeDir($file_dir);
1929  include_once("./Modules/File/classes/class.ilObjFile.php");
1930  $file_obj = new ilObjFile($a_file_id, false);
1931  $source_file = $file_obj->getDirectory($file_obj->getVersion())."/".$file_obj->getFileName();
1932  if (!is_file($source_file))
1933  {
1934  $source_file = $file_obj->getDirectory()."/".$file_obj->getFileName();
1935  }
1936  if (is_file($source_file))
1937  {
1938  copy($source_file, $file_dir."/".$file_obj->getFileName());
1939  }
1940  }
1941 
1945  function exportHTMLMOB($a_target_dir, &$a_lm_gui, $a_mob_id, $a_frame, &$a_linked_mobs)
1946  {
1947  global $tpl;
1948 
1949  $mob_dir = $a_target_dir."/mobs";
1950 
1951  $source_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob_id;
1952  if (@is_dir($source_dir))
1953  {
1954  ilUtil::makeDir($mob_dir."/mm_".$a_mob_id);
1955  ilUtil::rCopy($source_dir, $mob_dir."/mm_".$a_mob_id);
1956  }
1957 
1958  $tpl = new ilTemplate("tpl.main.html", true, true);
1959  $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
1960  $_GET["obj_type"] = "MediaObject";
1961  $_GET["mob_id"] = $a_mob_id;
1962  $_GET["frame"] = $a_frame;
1963  $_GET["cmd"] = "";
1964  $content =& $a_lm_gui->media();
1965  $file = $a_target_dir."/media_".$a_mob_id.".html";
1966 
1967  // open file
1968  if (!($fp = @fopen($file,"w+")))
1969  {
1970  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
1971  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
1972  }
1973  chmod($file, 0770);
1974  fwrite($fp, $content);
1975  fclose($fp);
1976 
1977  // fullscreen
1978  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1979  $mob_obj = new ilObjMediaObject($a_mob_id);
1980  if ($mob_obj->hasFullscreenItem())
1981  {
1982  $tpl = new ilTemplate("tpl.main.html", true, true);
1983  $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
1984  $_GET["obj_type"] = "";
1985  $_GET["frame"] = "";
1986  $_GET["mob_id"] = $a_mob_id;
1987  $_GET["cmd"] = "fullscreen";
1988  $content =& $a_lm_gui->fullscreen();
1989  $file = $a_target_dir."/fullscreen_".$a_mob_id.".html";
1990 
1991  // open file
1992  if (!($fp = @fopen($file,"w+")))
1993  {
1994  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
1995  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
1996  }
1997  chmod($file, 0770);
1998  fwrite($fp, $content);
1999  fclose($fp);
2000  }
2001  $linked_mobs = $mob_obj->getLinkedMediaObjects();
2002  $a_linked_mobs = array_merge($a_linked_mobs, $linked_mobs);
2003  }
2004 
2008  function exportHTMLGlossaryTerms(&$a_lm_gui, $a_target_dir)
2009  {
2010  global $ilLocator;
2011 
2012  foreach($this->offline_int_links as $int_link)
2013  {
2014  $ilLocator->clearItems();
2015  if ($int_link["type"] == "git")
2016  {
2017  $tpl = new ilTemplate("tpl.main.html", true, true);
2018  $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
2019 
2020  $_GET["obj_id"] = $int_link["id"];
2021  $_GET["frame"] = "_blank";
2022  $content =& $a_lm_gui->glossary();
2023  $file = $a_target_dir."/term_".$int_link["id"].".html";
2024 
2025  // open file
2026  if (!($fp = @fopen($file,"w+")))
2027  {
2028  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
2029  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
2030  }
2031  chmod($file, 0770);
2032  fwrite($fp, $content);
2033  fclose($fp);
2034 
2035  // store linked/embedded media objects of glosssary term
2036  include_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
2037  $defs = ilGlossaryDefinition::getDefinitionList($int_link["id"]);
2038  foreach($defs as $def)
2039  {
2040  $def_mobs = ilObjMediaObject::_getMobsOfObject("gdf:pg", $def["id"]);
2041  foreach($def_mobs as $def_mob)
2042  {
2043  $this->offline_mobs[$def_mob] = $def_mob;
2044  }
2045 
2046  // get all files of page
2047  $def_files = ilObjFile::_getFilesOfObject("gdf:pg", $page["obj_id"]);
2048  $this->offline_files = array_merge($this->offline_files, $def_files);
2049 
2050  }
2051 
2052  }
2053  }
2054  }
2055 
2059  function exportHTMLPages(&$a_lm_gui, $a_target_dir)
2060  {
2061  global $tpl, $ilBench, $ilLocator;
2062 
2063  $pages = ilLMPageObject::getPageList($this->getId());
2064 
2065  $lm_tree =& $this->getLMTree();
2066  $first_page = $lm_tree->fetchSuccessorNode($lm_tree->getRootId(), "pg");
2067  $this->first_page_id = $first_page["child"];
2068 
2069  // iterate all learning module pages
2070  $mobs = array();
2071  $int_links = array();
2072  $this->offline_files = array();
2073 
2074  include_once("./Services/COPage/classes/class.ilPageContentUsage.php");
2075  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
2076 
2077  foreach ($pages as $page)
2078  {
2079  if (ilPageObject::_exists($this->getType(), $page["obj_id"]))
2080  {
2081  $ilLocator->clearItems();
2082  $ilBench->start("ExportHTML", "exportHTMLPage");
2083  $ilBench->start("ExportHTML", "exportPageHTML");
2084  $this->exportPageHTML($a_lm_gui, $a_target_dir, $page["obj_id"]);
2085  $ilBench->stop("ExportHTML", "exportPageHTML");
2086 
2087  // get all snippets of page
2088  $pcs = ilPageContentUsage::getUsagesOfPage($page["obj_id"], $this->getType().":pg");
2089  foreach ($pcs as $pc)
2090  {
2091  if ($pc["type"] == "incl")
2092  {
2093  $incl_mobs = ilObjMediaObject::_getMobsOfObject("mep:pg", $pc["id"]);
2094  foreach($incl_mobs as $incl_mob)
2095  {
2096  $mobs[$incl_mob] = $incl_mob;
2097  }
2098  }
2099  }
2100 
2101  // get all media objects of page
2102  $pg_mobs = ilObjMediaObject::_getMobsOfObject($this->getType().":pg", $page["obj_id"]);
2103  foreach($pg_mobs as $pg_mob)
2104  {
2105  $mobs[$pg_mob] = $pg_mob;
2106  }
2107 
2108  // get all internal links of page
2109  $pg_links = ilInternalLink::_getTargetsOfSource($this->getType().":pg", $page["obj_id"]);
2110  $int_links = array_merge($int_links, $pg_links);
2111 
2112  // get all files of page
2113  include_once("./Modules/File/classes/class.ilObjFile.php");
2114  $pg_files = ilObjFile::_getFilesOfObject($this->getType().":pg", $page["obj_id"]);
2115  $this->offline_files = array_merge($this->offline_files, $pg_files);
2116 
2117  $ilBench->stop("ExportHTML", "exportHTMLPage");
2118  }
2119  }
2120  $this->offline_mobs = $mobs;
2121  $this->offline_int_links = $int_links;
2122 
2123 
2124  }
2125 
2126 
2127 
2131  function exportPageHTML(&$a_lm_gui, $a_target_dir, $a_lm_page_id, $a_frame = "")
2132  {
2133  global $tpl, $ilBench;
2134 
2135 //echo "<br>B: export Page HTML ($a_lm_page_id)"; flush();
2136  // template workaround: reset of template
2137  $tpl = new ilTemplate("tpl.main.html", true, true);
2138  $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
2139 
2140  $_GET["obj_id"] = $a_lm_page_id;
2141  $_GET["frame"] = $a_frame;
2142 
2143  if ($a_frame == "")
2144  {
2145  if ($nid = ilLMObject::_lookupNID($a_lm_gui->lm->getId(), $a_lm_page_id, "pg"))
2146  {
2147  $file = $a_target_dir."/lm_pg_".$nid.".html";
2148  }
2149  else
2150  {
2151  $file = $a_target_dir."/lm_pg_".$a_lm_page_id.".html";
2152  }
2153  }
2154  else
2155  {
2156  if ($a_frame != "toc")
2157  {
2158  $file = $a_target_dir."/frame_".$a_lm_page_id."_".$a_frame.".html";
2159  }
2160  else
2161  {
2162  $file = $a_target_dir."/frame_".$a_frame.".html";
2163  }
2164  }
2165 
2166  // return if file is already existing
2167  if (@is_file($file))
2168  {
2169  return;
2170  }
2171 
2172  $ilBench->start("ExportHTML", "layout");
2173  $ilBench->start("ExportHTML", "layout_".$a_frame);
2174  $content =& $a_lm_gui->layout("main.xml", false);
2175  $ilBench->stop("ExportHTML", "layout_".$a_frame);
2176  $ilBench->stop("ExportHTML", "layout");
2177 
2178  // open file
2179  if (!($fp = @fopen($file,"w+")))
2180  {
2181  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
2182  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
2183  }
2184 
2185  // set file permissions
2186  chmod($file, 0770);
2187 
2188  // write xml data into the file
2189  fwrite($fp, $content);
2190 
2191  // close file
2192  fclose($fp);
2193 
2194  if ($this->first_page_id == $a_lm_page_id && $a_frame == "")
2195  {
2196  copy($file, $a_target_dir."/index.html");
2197  }
2198 
2199  // write frames of frameset
2200  $ilBench->start("ExportHTML", "getCurrentFrameSet");
2201  $frameset = $a_lm_gui->getCurrentFrameSet();
2202  $ilBench->stop("ExportHTML", "getCurrentFrameSet");
2203 
2204  foreach ($frameset as $frame)
2205  {
2206  $this->exportPageHTML($a_lm_gui, $a_target_dir, $a_lm_page_id, $frame);
2207  }
2208 
2209  }
2210 
2217  function exportFO(&$a_xml_writer, $a_target_dir)
2218  {
2219  global $ilBench;
2220 
2221  // fo:root (start)
2222  $attrs = array();
2223  $attrs["xmlns:fo"] = "http://www.w3.org/1999/XSL/Format";
2224  $a_xml_writer->xmlStartTag("fo:root", $attrs);
2225 
2226  // fo:layout-master-set (start)
2227  $attrs = array();
2228  $a_xml_writer->xmlStartTag("fo:layout-master-set", $attrs);
2229 
2230  // fo:simple-page-master (start)
2231  $attrs = array();
2232  $attrs["master-name"] = "DinA4";
2233  $attrs["page-height"] = "29.7cm";
2234  $attrs["page-width"] = "21cm";
2235  $attrs["margin-top"] = "4cm";
2236  $attrs["margin-bottom"] = "1cm";
2237  $attrs["margin-left"] = "2.8cm";
2238  $attrs["margin-right"] = "7.3cm";
2239  $a_xml_writer->xmlStartTag("fo:simple-page-master", $attrs);
2240 
2241  // fo:region-body (complete)
2242  $attrs = array();
2243  $attrs["margin-top"] = "0cm";
2244  $attrs["margin-bottom"] = "1.25cm";
2245  $a_xml_writer->xmlElement("fo:region-body", $attrs);
2246 
2247  // fo:region-before (complete)
2248  $attrs = array();
2249  $attrs["extent"] = "1cm";
2250  $a_xml_writer->xmlElement("fo:region-before", $attrs);
2251 
2252  // fo:region-after (complete)
2253  $attrs = array();
2254  $attrs["extent"] = "1cm";
2255  $a_xml_writer->xmlElement("fo:region-after", $attrs);
2256 
2257  // fo:simple-page-master (end)
2258  $a_xml_writer->xmlEndTag("fo:simple-page-master");
2259 
2260  // fo:layout-master-set (end)
2261  $a_xml_writer->xmlEndTag("fo:layout-master-set");
2262 
2263  // fo:page-sequence (start)
2264  $attrs = array();
2265  $attrs["master-reference"] = "DinA4";
2266  $a_xml_writer->xmlStartTag("fo:page-sequence", $attrs);
2267 
2268  // fo:flow (start)
2269  $attrs = array();
2270  $attrs["flow-name"] = "xsl-region-body";
2271  $a_xml_writer->xmlStartTag("fo:flow", $attrs);
2272 
2273 
2274  // StructureObjects
2275  //$expLog->write(date("[y-m-d H:i:s] ")."Start Export Structure Objects");
2276  $ilBench->start("ContentObjectExport", "exportFOStructureObjects");
2277  $this->exportFOStructureObjects($a_xml_writer, $expLog);
2278  $ilBench->stop("ContentObjectExport", "exportFOStructureObjects");
2279  //$expLog->write(date("[y-m-d H:i:s] ")."Finished Export Structure Objects");*/
2280 
2281  // fo:flow (end)
2282  $a_xml_writer->xmlEndTag("fo:flow");
2283 
2284  // fo:page-sequence (end)
2285  $a_xml_writer->xmlEndTag("fo:page-sequence");
2286 
2287  // fo:root (end)
2288  $a_xml_writer->xmlEndTag("fo:root");
2289  }
2290 
2297  function exportFOStructureObjects(&$a_xml_writer)
2298  {
2299  $childs = $this->lm_tree->getChilds($this->lm_tree->getRootId());
2300  foreach ($childs as $child)
2301  {
2302  if($child["type"] != "st")
2303  {
2304  continue;
2305  }
2306 
2307  $structure_obj = new ilStructureObject($this, $child["obj_id"]);
2308  $structure_obj->exportFO($a_xml_writer, $expLog);
2309  unset($structure_obj);
2310  }
2311  }
2312 
2313  function getXMLZip()
2314  {
2315  include_once("./Modules/LearningModule/classes/class.ilContObjectExport.php");
2316 
2317  $cont_exp = new ilContObjectExport($this,'xml');
2318 
2319  $export_file = $cont_exp->buildExportFile();
2320  return $export_file;
2321  }
2322 
2331  function executeDragDrop($source_id, $target_id, $first_child, $as_subitem = false, $movecopy = "move")
2332  {
2333  $lmtree = new ilTree($this->getId());
2334  $lmtree->setTableNames('lm_tree','lm_data');
2335  $lmtree->setTreeTablePK("lm_id");
2336 //echo "-".$source_id."-".$target_id."-".$first_child."-".$as_subitem."-";
2337  $source_obj = ilLMObjectFactory::getInstance($this, $source_id, true);
2338  $source_obj->setLMId($this->getId());
2339 
2340  if (!$first_child)
2341  {
2342  $target_obj = ilLMObjectFactory::getInstance($this, $target_id, true);
2343  $target_obj->setLMId($this->getId());
2344  $target_parent = $lmtree->getParentId($target_id);
2345  }
2346 
2347  // handle pages
2348  if ($source_obj->getType() == "pg")
2349  {
2350 //echo "1";
2351  if ($lmtree->isInTree($source_obj->getId()))
2352  {
2353  $node_data = $lmtree->getNodeData($source_obj->getId());
2354 
2355  // cut on move
2356  if ($movecopy == "move")
2357  {
2358  $parent_id = $lmtree->getParentId($source_obj->getId());
2359  $lmtree->deleteTree($node_data);
2360 
2361  // write history entry
2362  require_once("classes/class.ilHistory.php");
2363  ilHistory::_createEntry($source_obj->getId(), "cut",
2364  array(ilLMObject::_lookupTitle($parent_id), $parent_id),
2365  $this->getType().":pg");
2366  ilHistory::_createEntry($parent_id, "cut_page",
2367  array(ilLMObject::_lookupTitle($source_obj->getId()), $source_obj->getId()),
2368  $this->getType().":st");
2369  }
2370  else
2371  {
2372  // copy page
2373  $new_page =& $source_obj->copy();
2374  $source_id = $new_page->getId();
2375  $source_obj =& $new_page;
2376  }
2377 
2378  // paste page
2379  if(!$lmtree->isInTree($source_obj->getId()))
2380  {
2381  if ($first_child) // as first child
2382  {
2383  $target_pos = IL_FIRST_NODE;
2384  $parent = $target_id;
2385  }
2386  else if ($as_subitem) // as last child
2387  {
2388  $parent = $target_id;
2389  $target_pos = IL_FIRST_NODE;
2390  $pg_childs =& $lmtree->getChildsByType($parent, "pg");
2391  if (count($pg_childs) != 0)
2392  {
2393  $target_pos = $pg_childs[count($pg_childs) - 1]["obj_id"];
2394  }
2395  }
2396  else // at position
2397  {
2398  $target_pos = $target_id;
2399  $parent = $target_parent;
2400  }
2401 
2402  // insert page into tree
2403  $lmtree->insertNode($source_obj->getId(),
2404  $parent, $target_pos);
2405 
2406  // write history entry
2407  if ($movecopy == "move")
2408  {
2409  // write history comments
2410  include_once("classes/class.ilHistory.php");
2411  ilHistory::_createEntry($source_obj->getId(), "paste",
2412  array(ilLMObject::_lookupTitle($parent), $parent),
2413  $this->getType().":pg");
2414  ilHistory::_createEntry($parent, "paste_page",
2415  array(ilLMObject::_lookupTitle($source_obj->getId()), $source_obj->getId()),
2416  $this->getType().":st");
2417  }
2418 
2419  }
2420  }
2421  }
2422 
2423  // handle chapters
2424  if ($source_obj->getType() == "st")
2425  {
2426 //echo "2";
2427  $source_node = $lmtree->getNodeData($source_id);
2428  $subnodes = $lmtree->getSubtree($source_node);
2429 
2430  // check, if target is within subtree
2431  foreach ($subnodes as $subnode)
2432  {
2433  if($subnode["obj_id"] == $target_id)
2434  {
2435  return;
2436  }
2437  }
2438 
2439  $target_pos = $target_id;
2440 
2441  if ($first_child) // as first subchapter
2442  {
2443  $target_pos = IL_FIRST_NODE;
2444  $target_parent = $target_id;
2445 
2446  $pg_childs =& $lmtree->getChildsByType($target_parent, "pg");
2447  if (count($pg_childs) != 0)
2448  {
2449  $target_pos = $pg_childs[count($pg_childs) - 1]["obj_id"];
2450  }
2451  }
2452  else if ($as_subitem) // as last subchapter
2453  {
2454  $target_parent = $target_id;
2455  $target_pos = IL_FIRST_NODE;
2456  $childs =& $lmtree->getChilds($target_parent);
2457  if (count($childs) != 0)
2458  {
2459  $target_pos = $childs[count($childs) - 1]["obj_id"];
2460  }
2461  }
2462 
2463  // insert into
2464 /*
2465  if ($position == "into")
2466  {
2467  $target_parent = $target_id;
2468  $target_pos = IL_FIRST_NODE;
2469 
2470  // if target_pos is still first node we must skip all pages
2471  if ($target_pos == IL_FIRST_NODE)
2472  {
2473  $pg_childs =& $lmtree->getChildsByType($target_parent, "pg");
2474  if (count($pg_childs) != 0)
2475  {
2476  $target_pos = $pg_childs[count($pg_childs) - 1]["obj_id"];
2477  }
2478  }
2479  }
2480 */
2481 
2482 
2483  // delete source tree
2484  if ($movecopy == "move")
2485  {
2486  $lmtree->deleteTree($source_node);
2487  }
2488  else
2489  {
2490  // copy chapter (incl. subcontents)
2491  $new_chapter =& $source_obj->copy($lmtree, $target_parent, $target_pos);
2492  }
2493 
2494  if (!$lmtree->isInTree($source_id))
2495  {
2496  $lmtree->insertNode($source_id, $target_parent, $target_pos);
2497 
2498  // insert moved tree
2499  if ($movecopy == "move")
2500  {
2501  foreach ($subnodes as $node)
2502  {
2503  if($node["obj_id"] != $source_id)
2504  {
2505  $lmtree->insertNode($node["obj_id"], $node["parent"]);
2506  }
2507  }
2508  }
2509  }
2510 
2511  // check the tree
2512  $this->checkTree();
2513  }
2514 
2515  $this->checkTree();
2516  }
2517 
2521  function validatePages()
2522  {
2523  include_once "./Modules/LearningModule/classes/class.ilLMPageObject.php";
2524  include_once "./Services/COPage/classes/class.ilPageObject.php";
2525 
2526  $mess = "";
2527 
2528  $pages = ilLMPageObject::getPageList($this->getId());
2529  foreach ($pages as $page)
2530  {
2531  if (ilPageObject::_exists($this->getType(), $page["obj_id"]))
2532  {
2533  $cpage = new ilPageObject($this->getType(), $page["obj_id"]);
2534  $cpage->buildDom();
2535  $error = @$cpage->validateDom();
2536 
2537  if ($error != "")
2538  {
2539  $this->lng->loadLanguageModule("content");
2540  ilUtil::sendInfo($this->lng->txt("cont_import_validation_errors"));
2541  $title = ilLMObject::_lookupTitle($page["obj_id"]);
2542  $page_obj = new ilLMPageObject($this, $page["obj_id"]);
2543  $mess.= $this->lng->txt("obj_pg").": ".$title;
2544  $mess.= '<div class="small">';
2545  foreach ($error as $e)
2546  {
2547  $err_mess = implode($e, " - ");
2548  if (!is_int(strpos($err_mess, ":0:")))
2549  {
2550  $mess.= htmlentities($err_mess)."<br />";
2551  }
2552  }
2553  $mess.= '</div>';
2554  $mess.= "<br />";
2555  }
2556  }
2557  }
2558 
2559  return $mess;
2560  }
2561 
2568  function importFromZipFile($a_tmp_file, $a_filename, $a_validate = true)
2569  {
2570  global $lng;
2571 
2572  // create import directory
2573  $this->createImportDirectory();
2574 
2575  // copy uploaded file to import directory
2576  $file = pathinfo($a_filename);
2577  $full_path = $this->getImportDirectory()."/".$a_filename;
2578 
2579  ilUtil::moveUploadedFile($a_tmp_file,
2580  $a_filename, $full_path);
2581 
2582  // unzip file
2583  ilUtil::unzip($full_path);
2584 
2585  $subdir = basename($file["basename"],".".$file["extension"]);
2586 
2587  $mess = $this->importFromDirectory(
2588  $this->getImportDirectory()."/".$subdir, $a_validate);
2589 
2590  // delete import directory
2592 
2593  return $mess;
2594  }
2595 
2596 
2603  function importFromDirectory($a_directory, $a_validate = true)
2604  {
2605  global $lng;
2606 
2607  // determine filename of xml file
2608  $subdir = basename($a_directory);
2609  $xml_file = $a_directory."/".$subdir.".xml";
2610 
2611  // check directory exists within zip file
2612  if (!is_dir($a_directory))
2613  {
2614  return sprintf($lng->txt("cont_no_subdir_in_zip"), $subdir);
2615  }
2616 
2617  // check whether xml file exists within zip file
2618  if (!is_file($xml_file))
2619  {
2620  return sprintf($lng->txt("cont_zip_file_invalid"), $subdir."/".$subdir.".xml");
2621  }
2622 
2623  // import questions
2624  $qti_file = $a_directory."/qti.xml";
2625  $qtis = array();
2626  if (is_file($qti_file))
2627  {
2628  include_once "./Services/QTI/classes/class.ilQTIParser.php";
2629  include_once("./Modules/Test/classes/class.ilObjTest.php");
2630  $qtiParser = new ilQTIParser ($qti_file,
2631  IL_MO_VERIFY_QTI, 0, "");
2632  $result = $qtiParser->startParsing ();
2633  $founditems = & $qtiParser->getFoundItems ();
2634  $testObj = new ilObjTest(0, true);
2635  if (count($founditems) > 0)
2636  {
2637  $qtiParser = new ilQTIParser($qti_file, IL_MO_PARSE_QTI, 0, "");
2638  $qtiParser->setTestObject($testObj);
2639  $result = $qtiParser->startParsing();
2640  $qtis = array_merge($qtis, $qtiParser->getImportMapping());
2641  }
2642  }
2643 
2644  include_once ("./Modules/LearningModule/classes/class.ilContObjParser.php");
2645  $contParser = new ilContObjParser($this, $xml_file, $subdir, $qmapping);
2646  $contParser->setQuestionMapping($qtis);
2647  $contParser->startParsing();
2648  ilObject::_writeImportId($this->getId(), $this->getImportId());
2649  $this->MDUpdateListener('General');
2650 
2651  // import style
2652  $style_file = $a_directory."/style.xml";
2653  $style_zip_file = $a_directory."/style.zip";
2654  if (is_file($style_zip_file)) // try to import style.zip first
2655  {
2656  require_once("./Services/Style/classes/class.ilObjStyleSheet.php");
2657  $style = new ilObjStyleSheet();
2658  $style->import($style_zip_file);
2659  $this->writeStyleSheetId($style->getId());
2660  }
2661  else if (is_file($style_file)) // try to import style.xml
2662  {
2663  require_once("./Services/Style/classes/class.ilObjStyleSheet.php");
2664  $style = new ilObjStyleSheet();
2665  $style->import($style_file);
2666  $this->writeStyleSheetId($style->getId());
2667  }
2668 
2669 // // validate
2670  if ($a_validate)
2671  {
2672  $mess = $this->validatePages();
2673  }
2674 
2675  if ($mess == "")
2676  {
2677  // handle internal links to this learning module
2678  include_once("./Services/COPage/classes/class.ilPageObject.php");
2680  $this->getType(), $this->getRefId());
2681  }
2682 
2683  return $mess;
2684  }
2685 
2686 }
2687 ?>