ILIAS  Release_4_2_x_branch Revision 61807
 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_no_meta_data = false)
52  {
53  global $ilUser;
54 
56 
57  // meta data will be created by
58  // import parser
59  if (!$a_no_meta_data)
60  {
61  $this->createMetaData();
62  }
63 
64  $this->createProperties();
65  }
66 
73  function initDefaultRoles()
74  {
75  return array();
76 
77  global $rbacadmin, $rbacreview;
78 
79  // create a local role folder
80  $rfoldObj = $this->createRoleFolder("Local roles","Role Folder of content object ".$this->getId());
81 
82  // note: we don't need any roles here, local "author" roles must
83  // be created manually. subscription roles have been abandoned.
84  /*
85  // create author role and assign role to rolefolder...
86  $roleObj = $rfoldObj->createRole("author object ".$this->getRefId(),"author of content object ref id ".$this->getRefId());
87  $roles[] = $roleObj->getId();
88 
89  // copy permissions from author template to new role
90  $rbacadmin->copyRolePermissions($this->getAuthorRoleTemplateId(), 8, $rfoldObj->getRefId(), $roleObj->getId());
91 
92  // grant all allowed operations of role to current learning module
93  $rbacadmin->grantPermission($roleObj->getId(),
94  $rbacreview->getOperationsOfRole($roleObj->getId(), "lm", $rfoldObj->getRefId()),
95  $this->getRefId());*/
96 
97  unset($rfoldObj);
98  //unset($roleObj);
99 
100  return $roles ? $roles : array();
101  }
102 
103 
107  function read()
108  {
109  parent::read();
110 # echo "Content<br>\n";
111 
112  $this->lm_tree = new ilTree($this->getId());
113  $this->lm_tree->setTableNames('lm_tree','lm_data');
114  $this->lm_tree->setTreeTablePK("lm_id");
115 
116  $this->readProperties();
117  //parent::read();
118  }
119 
125  function getTitle()
126  {
127  return parent::getTitle();
128  }
129 
133  function setTitle($a_title)
134  {
135  parent::setTitle($a_title);
136 // $this->meta_data->setTitle($a_title);
137  }
138 
144  function getDescription()
145  {
146  return parent::getDescription();
147  }
148 
152  function setDescription($a_description)
153  {
154  parent::setDescription($a_description);
155 // $this->meta_data->setDescription($a_description);
156  }
157 
158 
159  function getImportId()
160  {
161  return $this->import_id;
162  }
163 
164  function setImportId($a_id)
165  {
166  $this->import_id = $a_id;
167  }
168 
174  function setLayoutPerPage($a_val)
175  {
176  $this->layout_per_page = $a_val;
177  }
178 
184  function getLayoutPerPage()
185  {
186  return $this->layout_per_page;
187  }
188 
189  function &getTree()
190  {
191  return $this->lm_tree;
192  }
193 
197  function update()
198  {
199  $this->updateMetaData();
200  parent::update();
201  $this->updateProperties();
202  }
203 
204 
208  function import()
209  {
210  // nothing to do. just display the dialogue in Out
211  return;
212  }
213 
214 
219  function putInTree($a_parent)
220  {
221  global $tree;
222 
223  // put this object in tree under $a_parent
224  parent::putInTree($a_parent);
225 
226  // make new tree for this object
227  //$tree->addTree($this->getId());
228  }
229 
230 
236  function createLMTree()
237  {
238  $this->lm_tree =& new ilTree($this->getId());
239  $this->lm_tree->setTreeTablePK("lm_id");
240  $this->lm_tree->setTableNames('lm_tree','lm_data');
241  $this->lm_tree->addTree($this->getId(), 1);
242  }
243 
248  {
249  global $lng;
250 
251  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
252  include_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
253  include_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
254 
255  $root_id = $this->lm_tree->getRootId();
256 
257  // chapter
258  $chap = new ilStructureObject($this);
259  $chap->setType("st");
260  $chap->setTitle($lng->txt("cont_new_chap"));
261  $chap->setLMId($this->getId());
262  $chap->create();
263  ilLMObject::putInTree($chap, $root_id, IL_FIRST_NODE);
264 
265  // page
266  $page = new ilLMPageObject($this);
267  $page->setType("pg");
268  $page->setTitle($lng->txt("cont_new_page"));
269  $page->setLMId($this->getId());
270  $page->create();
271  ilLMObject::putInTree($page, $chap->getId(), IL_FIRST_NODE);
272  }
273 
274 
278  function &getLMTree()
279  {
280  return $this->lm_tree;
281  }
282 
283 
290  {
291  $lm_data_dir = ilUtil::getDataDir()."/lm_data";
292  if(!is_writable($lm_data_dir))
293  {
294  $this->ilias->raiseError("Content object Data Directory (".$lm_data_dir
295  .") not writeable.",$this->ilias->error_obj->FATAL);
296  }
297 
298  // create learning module directory (data_dir/lm_data/lm_<id>)
299  $lm_dir = $lm_data_dir."/lm_".$this->getId();
300  ilUtil::makeDir($lm_dir);
301  if(!@is_dir($lm_dir))
302  {
303  $this->ilias->raiseError("Creation of Learning Module Directory failed.",$this->ilias->error_obj->FATAL);
304  }
305 
306  // create import subdirectory (data_dir/lm_data/lm_<id>/import)
307  $import_dir = $lm_dir."/import";
309  if(!@is_dir($import_dir))
310  {
311  $this->ilias->raiseError("Creation of Import Directory failed.",$this->ilias->error_obj->FATAL);
312  }
313  }
314 
318  function getDataDirectory()
319  {
320  return ilUtil::getDataDir()."/lm_data".
321  "/lm_".$this->getId();
322  }
323 
328  {
329  if(strlen($this->import_dir))
330  {
331  return $this->import_dir;
332  }
333 
334  $import_dir = ilUtil::getDataDir()."/lm_data".
335  "/lm_".$this->getId()."/import";
336  if(@is_dir($import_dir))
337  {
338  return $import_dir;
339  }
340  else
341  {
342  return false;
343  }
344  }
345 
352  public function setImportDirectory($a_import_dir)
353  {
354  $this->import_dir = $a_import_dir;
355  }
356 
357 
363  function createExportDirectory($a_type = "xml")
364  {
365  $lm_data_dir = ilUtil::getDataDir()."/lm_data";
366  if(!is_writable($lm_data_dir))
367  {
368  $this->ilias->raiseError("Content object Data Directory (".$lm_data_dir
369  .") not writeable.",$this->ilias->error_obj->FATAL);
370  }
371  // create learning module directory (data_dir/lm_data/lm_<id>)
372  $lm_dir = $lm_data_dir."/lm_".$this->getId();
373  ilUtil::makeDir($lm_dir);
374  if(!@is_dir($lm_dir))
375  {
376  $this->ilias->raiseError("Creation of Learning Module Directory failed.",$this->ilias->error_obj->FATAL);
377  }
378  // create Export subdirectory (data_dir/lm_data/lm_<id>/Export)
379  switch ($a_type)
380  {
381  // html
382  case "html":
383  $export_dir = $lm_dir."/export_html";
384  break;
385 
386  // scorm
387  case "scorm":
388  $export_dir = $lm_dir."/export_scorm";
389  break;
390 
391  default: // = xml
392  $export_dir = $lm_dir."/export";
393  break;
394  }
395  ilUtil::makeDir($export_dir);
396 
397  if(!@is_dir($export_dir))
398  {
399  $this->ilias->raiseError("Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
400  }
401  }
402 
406  function getExportDirectory($a_type = "xml")
407  {
408  switch ($a_type)
409  {
410  case "html":
411  $export_dir = ilUtil::getDataDir()."/lm_data"."/lm_".$this->getId()."/export_html";
412  break;
413 
414  case "scorm":
415  $export_dir = ilUtil::getDataDir()."/lm_data"."/lm_".$this->getId()."/export_scorm";
416  break;
417 
418  default: // = xml
419  $export_dir = ilUtil::getDataDir()."/lm_data"."/lm_".$this->getId()."/export";
420  break;
421  }
422  return $export_dir;
423  }
424 
425 
436  function delete()
437  {
438  global $ilDB;
439 
440  global $ilBench;
441 
442  // always call parent delete function first!!
443  if (!parent::delete())
444  {
445  return false;
446  }
447 
448  // delete lm object data
449  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
451 
452  // delete meta data of content object
453  $this->deleteMetaData();
454 
455  // delete bibitem data
456  $nested = new ilNestedSetXML();
457  $nested->init($this->getId(), "bib");
458  $nested->deleteAllDBData();
459 
460 
461  // delete learning module tree
462  $this->lm_tree->removeTree($this->lm_tree->getTreeId());
463 
464  // delete data directory
466 
467  // delete content object record
468  $q = "DELETE FROM content_object WHERE id = ".
469  $ilDB->quote($this->getId(), "integer");
470  $ilDB->manipulate($q);
471 
472  // delete lm menu entries
473  $q = "DELETE FROM lm_menu WHERE lm_id = ".
474  $ilDB->quote($this->getId(), "integer");
475  $ilDB->manipulate($q);
476 
477  return true;
478  }
479 
480 
486  function getLayout()
487  {
488  return $this->layout;
489  }
490 
496  function setLayout($a_layout)
497  {
498  $this->layout = $a_layout;
499  }
500 
504  function getStyleSheetId()
505  {
506  return $this->style_id;
507  }
508 
512  function setStyleSheetId($a_style_id)
513  {
514  $this->style_id = $a_style_id;
515  }
516 
520  function writeStyleSheetId($a_style_id)
521  {
522  global $ilDB;
523 
524  $q = "UPDATE content_object SET ".
525  " stylesheet = ".$ilDB->quote((int) $a_style_id, "integer").
526  " WHERE id = ".$ilDB->quote($this->getId(), "integer");
527  $ilDB->manipulate($q);
528 
529  $this->style_id = $a_style_id;
530  }
531 
535  function _moveLMStyles($a_from_style, $a_to_style)
536  {
537  global $ilDB, $ilias;
538 
539  if ($a_from_style < 0) // change / delete all individual styles
540  {
541  $q = "SELECT stylesheet FROM content_object, style_data ".
542  " WHERE content_object.stylesheet = style_data.id ".
543  " AND style_data.standard = ".$ilDB->quote(0, "integer").
544  " AND content_object.stylesheet > ".$ilDB->quote(0, "integer");
545  $style_set = $ilDB->query($q);
546  while($style_rec = $ilDB->fetchAssoc($style_set))
547  {
548  // assign learning modules to new style
549  $q = "UPDATE content_object SET ".
550  " stylesheet = ".$ilDB->quote((int) $a_to_style, "integer").
551  " WHERE stylesheet = ".$ilDB->quote($style_rec["stylesheet"], "integer");
552  $ilDB->manipulate($q);
553 
554  // delete style
555  $style_obj =& $ilias->obj_factory->getInstanceByObjId($style_rec["stylesheet"]);
556  $style_obj->delete();
557  }
558  }
559  else
560  {
561  $q = "UPDATE content_object SET ".
562  " stylesheet = ".$ilDB->quote((int) $a_to_style, "integer").
563  " WHERE stylesheet = ".$ilDB->quote($a_from_style, "integer");
564  $ilDB->manipulate($q);
565  }
566  }
567 
571  function _lookupStyleSheetId($a_cont_obj_id)
572  {
573  global $ilDB;
574 
575  $q = "SELECT stylesheet FROM content_object ".
576  " WHERE id = ".$ilDB->quote($a_cont_obj_id, "integer");
577  $res = $ilDB->query($q);
578  $sheet = $ilDB->fetchAssoc($res);
579 
580  return $sheet["stylesheet"];
581  }
582 
586  function _lookupContObjIdByStyleId($a_style_id)
587  {
588  global $ilDB;
589 
590  $q = "SELECT id FROM content_object ".
591  " WHERE stylesheet = ".$ilDB->quote($a_style_id, "integer");
592  $res = $ilDB->query($q);
593  $obj_ids = array();
594  while($cont = $ilDB->fetchAssoc($res))
595  {
596  $obj_ids[] = $cont["id"];
597  }
598  return $obj_ids;
599  }
600 
606  function _getNrOfAssignedLMs($a_style_id)
607  {
608  global $ilDB;
609 
610  $q = "SELECT count(*) as cnt FROM content_object ".
611  " WHERE stylesheet = ".$ilDB->quote($a_style_id, "integer");
612  $cset = $ilDB->query($q);
613  $crow = $ilDB->fetchAssoc($cset);
614 
615  return (int) $crow["cnt"];
616  }
617 
618 
623  {
624  global $ilDB;
625 
626  // joining with style table (not perfectly nice)
627  $q = "SELECT count(*) as cnt FROM content_object, style_data ".
628  " WHERE stylesheet = style_data.id ".
629  " AND standard = ".$ilDB->quote(0, "integer");
630  $cset = $ilDB->query($q);
631  $crow = $ilDB->fetchAssoc($cset);
632 
633  return (int) $crow["cnt"];
634  }
635 
639  function _getNrLMsNoStyle()
640  {
641  global $ilDB;
642 
643  $q = "SELECT count(*) as cnt FROM content_object ".
644  " WHERE stylesheet = ".$ilDB->quote(0, "integer");
645  $cset = $ilDB->query($q);
646  $crow = $ilDB->fetchAssoc($cset);
647 
648  return (int) $crow["cnt"];
649  }
650 
656  function _deleteStyleAssignments($a_style_id)
657  {
658  global $ilDB;
659 
660  $q = "UPDATE content_object SET ".
661  " stylesheet = ".$ilDB->quote(0, "integer").
662  " WHERE stylesheet = ".$ilDB->quote((int) $this->getId($a_style_id), "integer");
663 
664  $ilDB->manipulate($q);
665  }
666 
670  function getPageHeader()
671  {
672  return $this->pg_header;
673  }
674 
680  function setPageHeader($a_pg_header = IL_CHAPTER_TITLE)
681  {
682  $this->pg_header = $a_pg_header;
683  }
684 
688  function getTOCMode()
689  {
690  return $this->toc_mode;
691  }
692 
697  {
698  return $this->public_access_mode;
699  }
700 
706  function setTOCMode($a_toc_mode = "chapters")
707  {
708  $this->toc_mode = $a_toc_mode;
709  }
710 
711  function setOnline($a_online)
712  {
713  $this->online = $a_online;
714  }
715 
716  function getOnline()
717  {
718  return $this->online;
719  }
720 
721  function setActiveLMMenu($a_act_lm_menu)
722  {
723  $this->lm_menu_active = $a_act_lm_menu;
724  }
725 
726  function isActiveLMMenu()
727  {
728  return $this->lm_menu_active;
729  }
730 
731  function setActiveTOC($a_toc)
732  {
733  $this->toc_active = $a_toc;
734  }
735 
736  function isActiveTOC()
737  {
738  return $this->toc_active;
739  }
740 
741  function setActiveNumbering($a_num)
742  {
743  $this->numbering = $a_num;
744  }
745 
746  function isActiveNumbering()
747  {
748  return $this->numbering;
749  }
750 
751  function setActivePrintView($a_print)
752  {
753  $this->print_view_active = $a_print;
754  }
755 
756  function isActivePrintView()
757  {
758  return $this->print_view_active;
759  }
760 
762  {
763  $this->prevent_glossary_appendix_active = $a_print;
764  }
765 
767  {
768  return $this->prevent_glossary_appendix_active;
769  }
770 
771  function setActiveDownloads($a_down)
772  {
773  $this->downloads_active = $a_down;
774  }
775 
776  function isActiveDownloads()
777  {
778  return $this->downloads_active;
779  }
780 
781  function setActiveDownloadsPublic($a_down)
782  {
783  $this->downloads_public_active = $a_down;
784  }
785 
787  {
788  return $this->downloads_public_active;
789  }
790 
791  function setPublicNotes($a_pub_notes)
792  {
793  $this->pub_notes = $a_pub_notes;
794  }
795 
796  function publicNotes()
797  {
798  return $this->pub_notes;
799  }
800 
801  function setCleanFrames($a_clean)
802  {
803  $this->clean_frames = $a_clean;
804  }
805 
806  function cleanFrames()
807  {
808  return $this->clean_frames;
809  }
810 
811  function setHistoryUserComments($a_comm)
812  {
813  $this->user_comments = $a_comm;
814  }
815 
816  function setPublicAccessMode($a_mode)
817  {
818  $this->public_access_mode = $a_mode;
819  }
820 
822  {
823  return $this->user_comments;
824  }
825 
826  function setHeaderPage($a_pg)
827  {
828  $this->header_page = $a_pg;
829  }
830 
831  function getHeaderPage()
832  {
833  return $this->header_page;
834  }
835 
836  function setFooterPage($a_pg)
837  {
838  $this->footer_page = $a_pg;
839  }
840 
841  function getFooterPage()
842  {
843  return $this->footer_page;
844  }
845 
849  function readProperties()
850  {
851  global $ilDB;
852 
853  $q = "SELECT * FROM content_object WHERE id = ".
854  $ilDB->quote($this->getId(), "integer");
855  $lm_set = $ilDB->query($q);
856  $lm_rec = $ilDB->fetchAssoc($lm_set);
857  $this->setLayout($lm_rec["default_layout"]);
858  $this->setStyleSheetId((int) $lm_rec["stylesheet"]);
859  $this->setPageHeader($lm_rec["page_header"]);
860  $this->setTOCMode($lm_rec["toc_mode"]);
861  $this->setOnline(ilUtil::yn2tf($lm_rec["is_online"]));
862  $this->setActiveTOC(ilUtil::yn2tf($lm_rec["toc_active"]));
863  $this->setActiveNumbering(ilUtil::yn2tf($lm_rec["numbering"]));
864  $this->setActivePrintView(ilUtil::yn2tf($lm_rec["print_view_active"]));
865  $this->setActivePreventGlossaryAppendix(ilUtil::yn2tf($lm_rec["no_glo_appendix"]));
866  $this->setActiveDownloads(ilUtil::yn2tf($lm_rec["downloads_active"]));
867  $this->setActiveDownloadsPublic(ilUtil::yn2tf($lm_rec["downloads_public_active"]));
868  $this->setActiveLMMenu(ilUtil::yn2tf($lm_rec["lm_menu_active"]));
869  $this->setCleanFrames(ilUtil::yn2tf($lm_rec["clean_frames"]));
870  $this->setPublicNotes(ilUtil::yn2tf($lm_rec["pub_notes"]));
871  $this->setHeaderPage((int) $lm_rec["header_page"]);
872  $this->setFooterPage((int) $lm_rec["footer_page"]);
873  $this->setHistoryUserComments(ilUtil::yn2tf($lm_rec["hist_user_comments"]));
874  $this->setPublicAccessMode($lm_rec["public_access_mode"]);
875  $this->setPublicExportFile("xml", $lm_rec["public_xml_file"]);
876  $this->setPublicExportFile("html", $lm_rec["public_html_file"]);
877  $this->setPublicExportFile("scorm", $lm_rec["public_scorm_file"]);
878  $this->setLayoutPerPage($lm_rec["layout_per_page"]);
879  }
880 
884  function updateProperties()
885  {
886  global $ilDB;
887 
888  // force clean_frames to be set, if layout per page is activated
889  if ($this->getLayoutPerPage())
890  {
891  $this->setCleanFrames(true);
892  }
893 
894  $q = "UPDATE content_object SET ".
895  " default_layout = ".$ilDB->quote($this->getLayout(), "text").", ".
896  " stylesheet = ".$ilDB->quote($this->getStyleSheetId(), "integer").",".
897  " page_header = ".$ilDB->quote($this->getPageHeader(), "text").",".
898  " toc_mode = ".$ilDB->quote($this->getTOCMode(), "text").",".
899  " is_online = ".$ilDB->quote(ilUtil::tf2yn($this->getOnline()), "text").",".
900  " toc_active = ".$ilDB->quote(ilUtil::tf2yn($this->isActiveTOC()), "text").",".
901  " numbering = ".$ilDB->quote(ilUtil::tf2yn($this->isActiveNumbering()), "text").",".
902  " print_view_active = ".$ilDB->quote(ilUtil::tf2yn($this->isActivePrintView()), "text").",".
903  " no_glo_appendix = ".$ilDB->quote(ilUtil::tf2yn($this->isActivePreventGlossaryAppendix()), "text").",".
904  " downloads_active = ".$ilDB->quote(ilUtil::tf2yn($this->isActiveDownloads()), "text").",".
905  " downloads_public_active = ".$ilDB->quote(ilUtil::tf2yn($this->isActiveDownloadsPublic()), "text").",".
906  " clean_frames = ".$ilDB->quote(ilUtil::tf2yn($this->cleanFrames()), "text").",".
907  " pub_notes = ".$ilDB->quote(ilUtil::tf2yn($this->publicNotes()), "text").",".
908  " hist_user_comments = ".$ilDB->quote(ilUtil::tf2yn($this->isActiveHistoryUserComments()), "text").",".
909  " public_access_mode = ".$ilDB->quote($this->getPublicAccessMode(), "text").",".
910  " public_xml_file = ".$ilDB->quote($this->getPublicExportFile("xml"), "text").",".
911  " public_html_file = ".$ilDB->quote($this->getPublicExportFile("html"), "text").",".
912  " public_scorm_file = ".$ilDB->quote($this->getPublicExportFile("scorm"), "text").",".
913  " header_page = ".$ilDB->quote($this->getHeaderPage(), "integer").",".
914  " footer_page = ".$ilDB->quote($this->getFooterPage(), "integer").",".
915  " lm_menu_active = ".$ilDB->quote(ilUtil::tf2yn($this->isActiveLMMenu()), "text").", ".
916  " layout_per_page = ".$ilDB->quote($this->getLayoutPerPage(), "integer")." ".
917  " WHERE id = ".$ilDB->quote($this->getId(), "integer");
918  $ilDB->manipulate($q);
919  }
920 
924  function createProperties()
925  {
926  global $ilDB;
927 
928  $q = "INSERT INTO content_object (id) VALUES (".$ilDB->quote($this->getId(), "integer").")";
929  $ilDB->manipulate($q);
930  $this->readProperties(); // to get db default values
931  }
932 
936  function _lookupOnline($a_id)
937  {
938  global $ilDB;
939 
940 //echo "class ilObjContentObject::_lookupOnline($a_id) called. Use Access class instead.";
941 
942  $q = "SELECT is_online FROM content_object WHERE id = ".$ilDB->quote($a_id, "integer");
943  $lm_set = $ilDB->query($q);
944  $lm_rec = $ilDB->fetchAssoc($lm_set);
945 
946  return ilUtil::yn2tf($lm_rec["is_online"]);
947  }
948 
955  {
956  $dir = opendir("./Modules/LearningModule/layouts/lm");
957 
958  $layouts = array();
959 
960  while($file = readdir($dir))
961  {
962  if ($file != "." && $file != ".." && $file != "CVS" && $file != ".svn")
963  {
964  // directories
965  if (@is_dir("./Modules/LearningModule/layouts/lm/".$file))
966  {
967  $layouts[$file] = $file;
968  }
969  }
970  }
971  asort($layouts);
972 
973  // workaround: fix ordering
974  return array(
975  'toc2win' => 'toc2win',
976  'toc2windyn' => 'toc2windyn',
977  '1window' => '1window',
978  '2window' => '2window',
979  '3window' => '3window',
980  'presentation' => 'presentation',
981  'fullscreen' => 'fullscreen'
982  );
983 
984  return $layouts;
985  }
986 
990  function _checkPreconditionsOfPage($cont_ref_id,$cont_obj_id, $page_id)
991  {
992  global $ilUser,$ilErr;
993 
994  $lm_tree = new ilTree($cont_obj_id);
995  $lm_tree->setTableNames('lm_tree','lm_data');
996  $lm_tree->setTreeTablePK("lm_id");
997 
998  if ($lm_tree->isInTree($page_id))
999  {
1000  $path = $lm_tree->getPathFull($page_id, $lm_tree->readRootId());
1001  foreach ($path as $node)
1002  {
1003  if ($node["type"] == "st")
1004  {
1005  if (!ilConditionHandler::_checkAllConditionsOfTarget($cont_ref_id,$node["child"], "st"))
1006  {
1007  return false;
1008  }
1009  }
1010  }
1011  }
1012 
1013  return true;
1014  }
1015 
1019  function _getMissingPreconditionsOfPage($cont_ref_id,$cont_obj_id, $page_id)
1020  {
1021  $lm_tree = new ilTree($cont_obj_id);
1022  $lm_tree->setTableNames('lm_tree','lm_data');
1023  $lm_tree->setTreeTablePK("lm_id");
1024 
1025  $conds = array();
1026  if ($lm_tree->isInTree($page_id))
1027  {
1028  // get full path of page
1029  $path = $lm_tree->getPathFull($page_id, $lm_tree->readRootId());
1030  foreach ($path as $node)
1031  {
1032  if ($node["type"] == "st")
1033  {
1034  // get all preconditions of upper chapters
1035  $tconds = ilConditionHandler::_getConditionsOfTarget($cont_ref_id,$node["child"], "st");
1036  foreach ($tconds as $tcond)
1037  {
1038  // store all missing preconditions
1039  if (!ilConditionHandler::_checkCondition($tcond["id"]))
1040  {
1041  $conds[] = $tcond;
1042  }
1043  }
1044  }
1045  }
1046  }
1047 
1048  return $conds;
1049  }
1050 
1054  function _getMissingPreconditionsTopChapter($cont_obj_ref_id,$cont_obj_id, $page_id)
1055  {
1056  $lm_tree = new ilTree($cont_obj_id);
1057  $lm_tree->setTableNames('lm_tree','lm_data');
1058  $lm_tree->setTreeTablePK("lm_id");
1059 
1060  $conds = array();
1061  if ($lm_tree->isInTree($page_id))
1062  {
1063  // get full path of page
1064  $path = $lm_tree->getPathFull($page_id, $lm_tree->readRootId());
1065  foreach ($path as $node)
1066  {
1067  if ($node["type"] == "st")
1068  {
1069  // get all preconditions of upper chapters
1070  $tconds = ilConditionHandler::_getConditionsOfTarget($cont_obj_ref_id,$node["child"], "st");
1071  foreach ($tconds as $tcond)
1072  {
1073  // look for missing precondition
1074  if (!ilConditionHandler::_checkCondition($tcond["id"]))
1075  {
1076  return $node["child"];
1077  }
1078  }
1079  }
1080  }
1081  }
1082 
1083  return "";
1084  }
1085 
1096  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
1097  {
1098  global $tree;
1099 
1100  switch ($a_event)
1101  {
1102  case "link":
1103 
1104  //var_dump("<pre>",$a_params,"</pre>");
1105  //echo "Content Object ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
1106  //exit;
1107  break;
1108 
1109  case "cut":
1110 
1111  //echo "Content Object ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
1112  //exit;
1113  break;
1114 
1115  case "copy":
1116 
1117  //var_dump("<pre>",$a_params,"</pre>");
1118  //echo "Content Object ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
1119  //exit;
1120  break;
1121 
1122  case "paste":
1123 
1124  //echo "Content Object ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
1125  //exit;
1126  break;
1127 
1128  case "new":
1129 
1130  //echo "Content Object ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
1131  //exit;
1132  break;
1133  }
1134 
1135  // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
1136  if ($a_node_id==$_GET["ref_id"])
1137  {
1138  $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
1139  $parent_type = $parent_obj->getType();
1140  if($parent_type == $this->getType())
1141  {
1142  $a_node_id = (int) $tree->getParentId($a_node_id);
1143  }
1144  }
1145 
1146  parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
1147  }
1148 
1149 
1153  function hasSuccessorPage($a_cont_obj_id, $a_page_id)
1154  {
1155  $tree = new ilTree($a_cont_obj_id);
1156  $tree->setTableNames('lm_tree','lm_data');
1157  $tree->setTreeTablePK("lm_id");
1158  if ($tree->isInTree($a_page_id))
1159  {
1160  $succ = $tree->fetchSuccessorNode($a_page_id, "pg");
1161  if ($succ > 0)
1162  {
1163  return true;
1164  }
1165  }
1166  return false;
1167  }
1168 
1169 
1170  function checkTree()
1171  {
1172  $tree = new ilTree($this->getId());
1173  $tree->setTableNames('lm_tree','lm_data');
1174  $tree->setTreeTablePK("lm_id");
1175  $tree->checkTree();
1176  $tree->checkTreeChilds();
1177 //echo "checked";
1178  }
1179 
1183  function fixTree()
1184  {
1185  global $ilDB;
1186 
1187  $tree =& $this->getLMTree();
1188 
1189  // check numbering, if errors, renumber
1190  // it is very important to keep this step before deleting subtrees
1191  // in the following steps
1192  $set = $ilDB->query("SELECT DISTINCT l1.lm_id".
1193  " FROM lm_tree l1".
1194  " JOIN lm_tree l2 ON ( l1.child = l2.parent".
1195  " AND l1.lm_id = l2.lm_id )".
1196  " JOIN lm_data ON ( l1.child = lm_data.obj_id )".
1197  " WHERE (l2.lft < l1.lft".
1198  " OR l2.rgt > l1.rgt OR l2.lft > l1.rgt OR l2.rgt < l1.lft)".
1199  " AND l1.lm_id = ".$ilDB->quote($this->getId(), "integer").
1200  " ORDER BY lm_data.create_date DESC"
1201  );
1202  if ($rec = $ilDB->fetchAssoc($set))
1203  {
1204  $tree->renumber();
1205  }
1206 
1207  // delete subtrees that have no lm_data records
1208  $nodes = $tree->getSubtree($tree->getNodeData($tree->getRootId()));
1209  foreach ($nodes as $node)
1210  {
1211  $q = "SELECT * FROM lm_data WHERE obj_id = ".
1212  $ilDB->quote($node["child"], "integer");
1213  $obj_set = $ilDB->query($q);
1214  $obj_rec = $ilDB->fetchAssoc($obj_set);
1215  if (!$obj_rec)
1216  {
1217  $node_data = $tree->getNodeData($node["child"]);
1218  $tree->deleteTree($node_data);
1219  }
1220  }
1221 
1222  // delete subtrees that have pages as parent
1223  $nodes = $tree->getSubtree($tree->getNodeData($tree->getRootId()));
1224  foreach ($nodes as $node)
1225  {
1226  $q = "SELECT * FROM lm_data WHERE obj_id = ".
1227  $ilDB->quote($node["parent"], "integer");
1228  $obj_set = $ilDB->query($q);
1229  $obj_rec = $ilDB->fetchAssoc($obj_set);
1230  if ($obj_rec["type"] == "pg")
1231  {
1232  $node_data = $tree->getNodeData($node["child"]);
1233  if ($tree->isInTree($node["child"]))
1234  {
1235  $tree->deleteTree($node_data);
1236  }
1237  }
1238  }
1239 
1240  // check for multi-references pages or chapters
1241  // if errors -> create copies of them here
1242  $set = $ilDB->query("SELECT DISTINCT l1.lm_id".
1243  " FROM lm_tree l1".
1244  " JOIN lm_tree l2 ON ( l1.child = l2.child AND l1.lm_id <> l2.lm_id )".
1245  " JOIN lm_data ON (l1.child = lm_data.obj_id)".
1246  " WHERE l1.child <> 1".
1247  " AND l1.lm_id <> lm_data.lm_id".
1248  " AND l1.lm_id = ".$ilDB->quote($this->getId(), "integer"));
1249  if ($rec = $ilDB->fetchAssoc($set))
1250  {
1251  $set = $ilDB->query("SELECT DISTINCT l1.child ".
1252  " FROM lm_tree l1".
1253  " JOIN lm_tree l2 ON ( l1.child = l2.child AND l1.lm_id <> l2.lm_id )".
1254  " JOIN lm_data ON (l1.child = lm_data.obj_id)".
1255  " WHERE l1.child <> 1".
1256  " AND l1.lm_id <> lm_data.lm_id".
1257  " AND l1.lm_id = ".$ilDB->quote($this->getId(), "integer"));
1258  include_once("./Modules/LearningModule/classes/class.ilLMObjectFactory.php");
1259  while ($rec = $ilDB->fetchAssoc($set))
1260  {
1261  $cobj = ilLMObjectFactory::getInstance($this, $rec["child"]);
1262 
1263  if (is_object($cobj))
1264  {
1265  if ($cobj->getType() == "pg")
1266  {
1267  // make a copy of it
1268  $pg_copy = $cobj->copy($this);
1269 
1270  // replace the child in the tree with the copy (id)
1271  $ilDB->manipulate("UPDATE lm_tree SET ".
1272  " child = ".$ilDB->quote($pg_copy->getId(), "integer").
1273  " WHERE child = ".$ilDB->quote($cobj->getId(), "integer").
1274  " AND lm_id = ".$ilDB->quote($this->getId(), "integer")
1275  );
1276  }
1277  else if ($cobj->getType() == "st")
1278  {
1279  // make a copy of it
1280  $st_copy = $cobj->copy($this);
1281 
1282  // replace the child in the tree with the copy (id)
1283  $ilDB->manipulate("UPDATE lm_tree SET ".
1284  " child = ".$ilDB->quote($st_copy->getId(), "integer").
1285  " WHERE child = ".$ilDB->quote($cobj->getId(), "integer").
1286  " AND lm_id = ".$ilDB->quote($this->getId(), "integer")
1287  );
1288 
1289  // make all childs refer to the copy now
1290  $ilDB->manipulate("UPDATE lm_tree SET ".
1291  " parent = ".$ilDB->quote($st_copy->getId(), "integer").
1292  " WHERE parent = ".$ilDB->quote($cobj->getId(), "integer").
1293  " AND lm_id = ".$ilDB->quote($this->getId(), "integer")
1294  );
1295  }
1296  }
1297  }
1298  }
1299  }
1300 
1301 
1308  function exportXML(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
1309  {
1310  global $ilBench;
1311 
1312  $attrs = array();
1313  switch($this->getType())
1314  {
1315  case "lm":
1316  $attrs["Type"] = "LearningModule";
1317  break;
1318 
1319  case "dbk":
1320  $attrs["Type"] = "LibObject";
1321  break;
1322  }
1323  $a_xml_writer->xmlStartTag("ContentObject", $attrs);
1324 
1325  // MetaData
1326  $this->exportXMLMetaData($a_xml_writer);
1327 
1328  // StructureObjects
1329 //echo "ContObj:".$a_inst.":<br>";
1330  $expLog->write(date("[y-m-d H:i:s] ")."Start Export Structure Objects");
1331  $ilBench->start("ContentObjectExport", "exportStructureObjects");
1332  $this->exportXMLStructureObjects($a_xml_writer, $a_inst, $expLog);
1333  $ilBench->stop("ContentObjectExport", "exportStructureObjects");
1334  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Structure Objects");
1335 
1336  // PageObjects
1337  $expLog->write(date("[y-m-d H:i:s] ")."Start Export Page Objects");
1338  $ilBench->start("ContentObjectExport", "exportPageObjects");
1339  $this->exportXMLPageObjects($a_xml_writer, $a_inst, $expLog);
1340  $ilBench->stop("ContentObjectExport", "exportPageObjects");
1341  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Page Objects");
1342 
1343  // MediaObjects
1344  $expLog->write(date("[y-m-d H:i:s] ")."Start Export Media Objects");
1345  $ilBench->start("ContentObjectExport", "exportMediaObjects");
1346  $this->exportXMLMediaObjects($a_xml_writer, $a_inst, $a_target_dir, $expLog);
1347  $ilBench->stop("ContentObjectExport", "exportMediaObjects");
1348  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Media Objects");
1349 
1350  // FileItems
1351  $expLog->write(date("[y-m-d H:i:s] ")."Start Export File Items");
1352  $ilBench->start("ContentObjectExport", "exportFileItems");
1353  $this->exportFileItems($a_target_dir, $expLog);
1354  $ilBench->stop("ContentObjectExport", "exportFileItems");
1355  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export File Items");
1356 
1357  // Questions
1358  if (count($this->q_ids) > 0)
1359  {
1360  $qti_file = fopen($a_target_dir."/qti.xml", "w");
1361  include_once("./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php");
1362  $pool = new ilObjQuestionPool();
1363  fwrite($qti_file, $pool->toXML($this->q_ids));
1364  fclose($qti_file);
1365  }
1366 
1367  // To do: implement version selection/detection
1368  // Properties
1369  $expLog->write(date("[y-m-d H:i:s] ")."Start Export Properties");
1370  $this->exportXMLProperties($a_xml_writer, $expLog);
1371  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Properties");
1372 
1373  $a_xml_writer->xmlEndTag("ContentObject");
1374  }
1375 
1382  function exportXMLMetaData(&$a_xml_writer)
1383  {
1384  include_once("Services/MetaData/classes/class.ilMD2XML.php");
1385  $md2xml = new ilMD2XML($this->getId(), 0, $this->getType());
1386  $md2xml->setExportMode(true);
1387  $md2xml->startExport();
1388  $a_xml_writer->appendXML($md2xml->getXML());
1389  }
1390 
1397  function exportXMLStructureObjects(&$a_xml_writer, $a_inst, &$expLog)
1398  {
1399  include_once './Modules/LearningModule/classes/class.ilStructureObject.php';
1400 
1401  $childs = $this->lm_tree->getChilds($this->lm_tree->getRootId());
1402  foreach ($childs as $child)
1403  {
1404  if($child["type"] != "st")
1405  {
1406  continue;
1407  }
1408 
1409  $structure_obj = new ilStructureObject($this, $child["obj_id"]);
1410  $structure_obj->exportXML($a_xml_writer, $a_inst, $expLog);
1411  unset($structure_obj);
1412  }
1413  }
1414 
1415 
1422  function exportXMLPageObjects(&$a_xml_writer, $a_inst, &$expLog)
1423  {
1424  global $ilBench;
1425 
1426  include_once "./Modules/LearningModule/classes/class.ilLMPageObject.php";
1427 
1428  $pages = ilLMPageObject::getPageList($this->getId());
1429  foreach ($pages as $page)
1430  {
1431  if (ilPageObject::_exists($this->getType(), $page["obj_id"]))
1432  {
1433  $expLog->write(date("[y-m-d H:i:s] ")."Page Object ".$page["obj_id"]);
1434 
1435  // export xml to writer object
1436  $page_obj = new ilLMPageObject($this, $page["obj_id"]);
1437  $page_obj->exportXML($a_xml_writer, "normal", $a_inst);
1438 
1439  // collect media objects
1440  $mob_ids = $page_obj->getMediaObjectIDs();
1441  foreach($mob_ids as $mob_id)
1442  {
1443  $this->mob_ids[$mob_id] = $mob_id;
1444  }
1445 
1446  // collect all file items
1447  $file_ids = $page_obj->getFileItemIds();
1448  foreach($file_ids as $file_id)
1449  {
1450  $this->file_ids[$file_id] = $file_id;
1451  }
1452 
1453  // collect all questions
1454  $q_ids = $page_obj->getQuestionIds();
1455  foreach($q_ids as $q_id)
1456  {
1457  $this->q_ids[$q_id] = $q_id;
1458  }
1459 
1460  unset($page_obj);
1461  }
1462  }
1463  }
1464 
1471  function exportXMLMediaObjects(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
1472  {
1473  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1474 
1475  $linked_mobs = array();
1476 
1477  // mobs directly embedded into pages
1478  foreach ($this->mob_ids as $mob_id)
1479  {
1480  if ($mob_id > 0 && ilObject::_lookupType($mob_id) == "mob")
1481  {
1482  $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
1483  $media_obj = new ilObjMediaObject($mob_id);
1484  $media_obj->exportXML($a_xml_writer, $a_inst);
1485  $media_obj->exportFiles($a_target_dir);
1486 
1487  $lmobs = $media_obj->getLinkedMediaObjects($this->mob_ids);
1488  $linked_mobs = array_merge($linked_mobs, $lmobs);
1489 
1490  unset($media_obj);
1491  }
1492  }
1493 
1494  // linked mobs (in map areas)
1495  foreach ($linked_mobs as $mob_id)
1496  {
1497  if ($mob_id > 0)
1498  {
1499  $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
1500  $media_obj = new ilObjMediaObject($mob_id);
1501  $media_obj->exportXML($a_xml_writer, $a_inst);
1502  $media_obj->exportFiles($a_target_dir);
1503  unset($media_obj);
1504  }
1505  }
1506 
1507  }
1508 
1513  function exportFileItems($a_target_dir, &$expLog)
1514  {
1515  include_once("./Modules/File/classes/class.ilObjFile.php");
1516 
1517  foreach ($this->file_ids as $file_id)
1518  {
1519  $expLog->write(date("[y-m-d H:i:s] ")."File Item ".$file_id);
1520  $file_obj = new ilObjFile($file_id, false);
1521  $file_obj->export($a_target_dir);
1522  unset($file_obj);
1523  }
1524  }
1525 
1530  function exportXMLProperties($a_xml_writer, &$expLog)
1531  {
1532  $attrs = array();
1533  $a_xml_writer->xmlStartTag("Properties", $attrs);
1534 
1535  // Layout
1536  $attrs = array("Name" => "Layout", "Value" => $this->getLayout());
1537  $a_xml_writer->xmlElement("Property", $attrs);
1538 
1539  // Page Header
1540  $attrs = array("Name" => "PageHeader", "Value" => $this->getPageHeader());
1541  $a_xml_writer->xmlElement("Property", $attrs);
1542 
1543  // TOC Mode
1544  $attrs = array("Name" => "TOCMode", "Value" => $this->getTOCMode());
1545  $a_xml_writer->xmlElement("Property", $attrs);
1546 
1547  // LM Menu Activation
1548  $attrs = array("Name" => "ActiveLMMenu", "Value" =>
1549  ilUtil::tf2yn($this->isActiveLMMenu()));
1550  $a_xml_writer->xmlElement("Property", $attrs);
1551 
1552  // Numbering Activation
1553  $attrs = array("Name" => "ActiveNumbering", "Value" =>
1554  ilUtil::tf2yn($this->isActiveNumbering()));
1555  $a_xml_writer->xmlElement("Property", $attrs);
1556 
1557  // Table of contents button activation
1558  $attrs = array("Name" => "ActiveTOC", "Value" =>
1559  ilUtil::tf2yn($this->isActiveTOC()));
1560  $a_xml_writer->xmlElement("Property", $attrs);
1561 
1562  // Print view button activation
1563  $attrs = array("Name" => "ActivePrintView", "Value" =>
1564  ilUtil::tf2yn($this->isActivePrintView()));
1565  $a_xml_writer->xmlElement("Property", $attrs);
1566 
1567  // Note that download button is not saved, because
1568  // download files do not exist after import
1569 
1570  // Clean frames
1571  $attrs = array("Name" => "CleanFrames", "Value" =>
1572  ilUtil::tf2yn($this->cleanFrames()));
1573  $a_xml_writer->xmlElement("Property", $attrs);
1574 
1575  // Public notes activation
1576  $attrs = array("Name" => "PublicNotes", "Value" =>
1577  ilUtil::tf2yn($this->publicNotes()));
1578  $a_xml_writer->xmlElement("Property", $attrs);
1579 
1580  // History comments for authors activation
1581  $attrs = array("Name" => "HistoryUserComments", "Value" =>
1583  $a_xml_writer->xmlElement("Property", $attrs);
1584 
1585  // Header Page
1586  if ($this->getHeaderPage() > 0)
1587  {
1588  $attrs = array("Name" => "HeaderPage", "Value" =>
1589  "il_".IL_INST_ID."_pg_".$this->getHeaderPage());
1590  $a_xml_writer->xmlElement("Property", $attrs);
1591  }
1592 
1593  // Footer Page
1594  if ($this->getFooterPage() > 0)
1595  {
1596  $attrs = array("Name" => "FooterPage", "Value" =>
1597  "il_".IL_INST_ID."_pg_".$this->getFooterPage());
1598  $a_xml_writer->xmlElement("Property", $attrs);
1599  }
1600 
1601  $a_xml_writer->xmlEndTag("Properties");
1602  }
1603 
1607  function getExportFiles()
1608  {
1609  $file = array();
1610 
1611  $types = array("xml", "html", "scorm");
1612 
1613  foreach ($types as $type)
1614  {
1615  $dir = $this->getExportDirectory($type);
1616  // quit if import dir not available
1617  if (!@is_dir($dir) or
1618  !is_writeable($dir))
1619  {
1620  continue;
1621  }
1622 
1623  // open directory
1624  $cdir = dir($dir);
1625 
1626  // initialize array
1627 
1628  // get files and save the in the array
1629  while ($entry = $cdir->read())
1630  {
1631  if ($entry != "." and
1632  $entry != ".." and
1633  substr($entry, -4) == ".zip" and
1634  ereg("^[0-9]{10}_{2}[0-9]+_{2}(lm_)*[0-9]+\.zip\$", $entry))
1635  {
1636  $file[$entry.$type] = array("type" => $type, "file" => $entry,
1637  "size" => filesize($dir."/".$entry));
1638  }
1639  }
1640 
1641  // close import directory
1642  $cdir->close();
1643  }
1644 
1645  // sort files
1646  ksort ($file);
1647  reset ($file);
1648  return $file;
1649  }
1650 
1657  function setPublicExportFile($a_type, $a_file)
1658  {
1659  $this->public_export_file[$a_type] = $a_file;
1660  }
1661 
1669  function getPublicExportFile($a_type)
1670  {
1671  return $this->public_export_file[$a_type];
1672  }
1673 
1678  {
1679  // quit if offline dir not available
1680  if (!@is_dir($dir) or
1681  !is_writeable($dir))
1682  {
1683  return array();
1684  }
1685 
1686  // open directory
1687  $dir = dir($dir);
1688 
1689  // initialize array
1690  $file = array();
1691 
1692  // get files and save the in the array
1693  while ($entry = $dir->read())
1694  {
1695  if ($entry != "." and
1696  $entry != ".." and
1697  substr($entry, -4) == ".pdf" and
1698  ereg("^[0-9]{10}_{2}[0-9]+_{2}(lm_)*[0-9]+\.pdf\$", $entry))
1699  {
1700  $file[] = $entry;
1701  }
1702  }
1703 
1704  // close import directory
1705  $dir->close();
1706 
1707  // sort files
1708  sort ($file);
1709  reset ($file);
1710 
1711  return $file;
1712  }
1713 
1717  function exportSCORM($a_target_dir, $log)
1718  {
1719  ilUtil::delDir($a_target_dir);
1720  ilUtil::makeDir($a_target_dir);
1721  //ilUtil::makeDir($a_target_dir."/res");
1722 
1723  // export everything to html
1724  $this->exportHTML($a_target_dir."/res", $log, false, "scorm");
1725 
1726  // build manifest file
1727  include("./Modules/LearningModule/classes/class.ilContObjectManifestBuilder.php");
1728  $man_builder = new ilContObjectManifestBuilder($this);
1729  $man_builder->buildManifest();
1730  $man_builder->dump($a_target_dir);
1731 
1732  // copy scorm 1.2 schema definitions
1733  copy("Modules/LearningModule/scorm_xsd/adlcp_rootv1p2.xsd", $a_target_dir."/adlcp_rootv1p2.xsd");
1734  copy("Modules/LearningModule/scorm_xsd/imscp_rootv1p1p2.xsd", $a_target_dir."/imscp_rootv1p1p2.xsd");
1735  copy("Modules/LearningModule/scorm_xsd/imsmd_rootv1p2p1.xsd", $a_target_dir."/imsmd_rootv1p2p1.xsd");
1736  copy("Modules/LearningModule/scorm_xsd/ims_xml.xsd", $a_target_dir."/ims_xml.xsd");
1737 
1738  // zip it all
1739  $date = time();
1740  $zip_file = $a_target_dir."/".$date."__".IL_INST_ID."__".
1741  $this->getType()."_".$this->getId().".zip";
1742  //echo "zip-".$a_target_dir."-to-".$zip_file;
1743  ilUtil::zip(array($a_target_dir."/res",
1744  $a_target_dir."/imsmanifest.xml",
1745  $a_target_dir."/adlcp_rootv1p2.xsd",
1746  $a_target_dir."/imscp_rootv1p1p2.xsd",
1747  $a_target_dir."/ims_xml.xsd",
1748  $a_target_dir."/imsmd_rootv1p2p1.xsd")
1749  , $zip_file);
1750 
1751  $dest_file = $this->getExportDirectory("scorm")."/".$date."__".IL_INST_ID."__".
1752  $this->getType()."_".$this->getId().".zip";
1753 
1754  rename($zip_file, $dest_file);
1755  ilUtil::delDir($a_target_dir);
1756 
1757  }
1758 
1759 
1763  function exportHTML($a_target_dir, $log, $a_zip_file = true, $a_export_format = "html")
1764  {
1765  global $tpl, $ilBench, $ilLocator, $ilUser;
1766 
1767  // initialize temporary target directory
1768  ilUtil::delDir($a_target_dir);
1769  ilUtil::makeDir($a_target_dir);
1770  $mob_dir = $a_target_dir."/mobs";
1771  ilUtil::makeDir($mob_dir);
1772  $file_dir = $a_target_dir."/files";
1773  ilUtil::makeDir($file_dir);
1774  $teximg_dir = $a_target_dir."/teximg";
1775  ilUtil::makeDir($teximg_dir);
1776  $style_dir = $a_target_dir."/style";
1777  ilUtil::makeDir($style_dir);
1778  $style_img_dir = $a_target_dir."/style/images";
1779  ilUtil::makeDir($style_img_dir);
1780  $content_style_dir = $a_target_dir."/content_style";
1781  ilUtil::makeDir($content_style_dir);
1782  $content_style_img_dir = $a_target_dir."/content_style/images";
1783  ilUtil::makeDir($content_style_img_dir);
1784  $GLOBALS["teximgcnt"] = 0;
1785 
1786  // export system style sheet
1787  $location_stylesheet = ilUtil::getStyleSheetLocation("filesystem");
1788  $style_name = $ilUser->prefs["style"].".css";
1789  copy($location_stylesheet, $style_dir."/".$style_name);
1790  $fh = fopen($location_stylesheet, "r");
1791  $css = fread($fh, filesize($location_stylesheet));
1792  preg_match_all("/url\(([^\)]*)\)/",$css,$files);
1793  foreach (array_unique($files[1]) as $fileref)
1794  {
1795  $fileref = dirname($location_stylesheet)."/".$fileref;
1796  if (is_file($fileref))
1797  {
1798  copy($fileref, $style_img_dir."/".basename($fileref));
1799  }
1800  }
1801  fclose($fh);
1802  $location_stylesheet = ilUtil::getStyleSheetLocation();
1803 
1804  // export content style sheet
1805  $ilBench->start("ExportHTML", "exportContentStyle");
1806  if ($this->getStyleSheetId() < 1)
1807  {
1808  $cont_stylesheet = "./Services/COPage/css/content.css";
1809 
1810  $css = fread(fopen($cont_stylesheet,'r'),filesize($cont_stylesheet));
1811  preg_match_all("/url\(([^\)]*)\)/",$css,$files);
1812  foreach (array_unique($files[1]) as $fileref)
1813  {
1814  if (is_file(str_replace("..", ".", $fileref)))
1815  {
1816  copy(str_replace("..", ".", $fileref), $content_style_img_dir."/".basename($fileref));
1817  }
1818  $css = str_replace($fileref, "images/".basename($fileref),$css);
1819  }
1820  fwrite(fopen($content_style_dir."/content.css",'w'),$css);
1821  }
1822  else
1823  {
1824  $style = new ilObjStyleSheet($this->getStyleSheetId());
1825  $style->writeCSSFile($content_style_dir."/content.css", "images");
1826  $style->copyImagesToDir($content_style_img_dir);
1827  }
1828  $ilBench->stop("ExportHTML", "exportContentStyle");
1829 
1830  // export syntax highlighting style
1831  $syn_stylesheet = ilObjStyleSheet::getSyntaxStylePath();
1832  copy($syn_stylesheet, $a_target_dir."/syntaxhighlight.css");
1833 
1834  // get learning module presentation gui class
1835  include_once("./Modules/LearningModule/classes/class.ilLMPresentationGUI.php");
1836  $_GET["cmd"] = "nop";
1837  $lm_gui =& new ilLMPresentationGUI();
1838  $lm_gui->setOfflineMode(true);
1839  $lm_gui->setOfflineDirectory($a_target_dir);
1840  $lm_gui->setExportFormat($a_export_format);
1841 
1842  // export pages
1843  $ilBench->start("ExportHTML", "exportHTMLPages");
1844  $this->exportHTMLPages($lm_gui, $a_target_dir);
1845  $ilBench->stop("ExportHTML", "exportHTMLPages");
1846 
1847  // export glossary terms
1848  $ilBench->start("ExportHTML", "exportHTMLGlossaryTerms");
1849  $this->exportHTMLGlossaryTerms($lm_gui, $a_target_dir);
1850  $ilBench->stop("ExportHTML", "exportHTMLGlossaryTerms");
1851 
1852  // export all media objects
1853  $ilBench->start("ExportHTML", "exportHTMLMediaObjects");
1854  $linked_mobs = array();
1855  foreach ($this->offline_mobs as $mob)
1856  {
1857  if (ilObject::_exists($mob) && ilObject::_lookupType($mob) == "mob")
1858  {
1859  $this->exportHTMLMOB($a_target_dir, $lm_gui, $mob, "_blank", $linked_mobs);
1860  }
1861  }
1862  $linked_mobs2 = array(); // mobs linked in link areas
1863  foreach ($linked_mobs as $mob)
1864  {
1865  if (ilObject::_exists($mob))
1866  {
1867  $this->exportHTMLMOB($a_target_dir, $lm_gui, $mob, "_blank", $linked_mobs2);
1868  }
1869  }
1870  $_GET["obj_type"] = "MediaObject";
1871  $_GET["obj_id"] = $a_mob_id;
1872  $_GET["cmd"] = "";
1873  $ilBench->stop("ExportHTML", "exportHTMLMediaObjects");
1874 
1875  // export all file objects
1876  $ilBench->start("ExportHTML", "exportHTMLFileObjects");
1877  foreach ($this->offline_files as $file)
1878  {
1879  $this->exportHTMLFile($a_target_dir, $file);
1880  }
1881  $ilBench->stop("ExportHTML", "exportHTMLFileObjects");
1882 
1883  // export table of contents
1884  $ilBench->start("ExportHTML", "exportHTMLTOC");
1885  $ilLocator->clearItems();
1886  if ($this->isActiveTOC())
1887  {
1888  $tpl = new ilTemplate("tpl.main.html", true, true);
1889  //$tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
1890  $content =& $lm_gui->showTableOfContents();
1891  $file = $a_target_dir."/table_of_contents.html";
1892 
1893  // open file
1894  if (!($fp = @fopen($file,"w+")))
1895  {
1896  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
1897  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
1898  }
1899  chmod($file, 0770);
1900  fwrite($fp, $content);
1901  fclose($fp);
1902  }
1903  $ilBench->stop("ExportHTML", "exportHTMLTOC");
1904 
1905  // export images
1906  $ilBench->start("ExportHTML", "exportHTMLImages");
1907  $image_dir = $a_target_dir."/images";
1908  ilUtil::makeDir($image_dir);
1909  ilUtil::makeDir($image_dir."/browser");
1910  copy(ilUtil::getImagePath("enlarge.gif", false, "filesystem"),
1911  $image_dir."/enlarge.gif");
1912  copy(ilUtil::getImagePath("browser/blank.gif", false, "filesystem"),
1913  $image_dir."/browser/plus.gif");
1914  copy(ilUtil::getImagePath("browser/blank.gif", false, "filesystem"),
1915  $image_dir."/browser/minus.gif");
1916  copy(ilUtil::getImagePath("browser/blank.gif", false, "filesystem"),
1917  $image_dir."/browser/blank.gif");
1918  copy(ilUtil::getImagePath("spacer.gif", false, "filesystem"),
1919  $image_dir."/spacer.gif");
1920  copy(ilUtil::getImagePath("icon_st.gif", false, "filesystem"),
1921  $image_dir."/icon_st.gif");
1922  copy(ilUtil::getImagePath("icon_pg.gif", false, "filesystem"),
1923  $image_dir."/icon_pg.gif");
1924  copy(ilUtil::getImagePath("icon_st_s.gif", false, "filesystem"),
1925  $image_dir."/icon_st_s.gif");
1926  copy(ilUtil::getImagePath("icon_pg_s.gif", false, "filesystem"),
1927  $image_dir."/icon_pg_s.gif");
1928  copy(ilUtil::getImagePath("icon_lm.gif", false, "filesystem"),
1929  $image_dir."/icon_lm.gif");
1930  copy(ilUtil::getImagePath("icon_lm_s.gif", false, "filesystem"),
1931  $image_dir."/icon_lm_s.gif");
1932  copy(ilUtil::getImagePath("nav_arr_L.gif", false, "filesystem"),
1933  $image_dir."/nav_arr_L.gif");
1934  copy(ilUtil::getImagePath("nav_arr_R.gif", false, "filesystem"),
1935  $image_dir."/nav_arr_R.gif");
1936  copy(ilUtil::getImagePath("browser/forceexp.gif", false, "filesystem"),
1937  $image_dir."/browser/forceexp.gif");
1938 
1939  copy(ilUtil::getImagePath("download.gif", false, "filesystem"),
1940  $image_dir."/download.gif");
1941  $ilBench->stop("ExportHTML", "exportHTMLImages");
1942 
1943  // export flv/mp3 player
1944  $services_dir = $a_target_dir."/Services";
1945  ilUtil::makeDir($services_dir);
1946  $media_service_dir = $services_dir."/MediaObjects";
1947  ilUtil::makeDir($media_service_dir);
1948  $flv_dir = $media_service_dir."/flash_flv_player";
1949  ilUtil::makeDir($flv_dir);
1950  $mp3_dir = $media_service_dir."/flash_mp3_player";
1951  ilUtil::makeDir($mp3_dir);
1952  copy("./Services/MediaObjects/flash_flv_player/flvplayer.swf",
1953  $flv_dir."/flvplayer.swf");
1954  copy("./Services/MediaObjects/flash_mp3_player/mp3player.swf",
1955  $mp3_dir."/mp3player.swf");
1956 
1957  // js files
1958  ilUtil::makeDir($a_target_dir.'/js');
1959  ilUtil::makeDir($a_target_dir.'/js/yahoo');
1960  ilUtil::makeDir($a_target_dir.'/css');
1961  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
1962  foreach (self::getSupplyingExportFiles($a_target_dir) as $f)
1963  {
1964  copy($f["source"], $f["target"]);
1965  }
1966 
1967  // template workaround: reset of template
1968  $tpl = new ilTemplate("tpl.main.html", true, true);
1969  $tpl->setVariable("LOCATION_STYLESHEET",$location_stylesheet);
1970  $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
1971 
1972  // zip everything
1973  $ilBench->start("ExportHTML", "zip");
1974  if (true)
1975  {
1976  if ($a_zip_file)
1977  {
1978  // zip it all
1979  $date = time();
1980  $zip_file = $this->getExportDirectory("html")."/".$date."__".IL_INST_ID."__".
1981  $this->getType()."_".$this->getId().".zip";
1982  ilUtil::zip($a_target_dir, $zip_file);
1983  ilUtil::delDir($a_target_dir);
1984  }
1985  }
1986  $ilBench->stop("ExportHTML", "zip");
1987 
1988  }
1989 
1996  static function getSupplyingExportFiles($a_target_dir = ".")
1997  {
1998  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
1999  include_once("./Services/jQuery/classes/class.iljQueryUtil.php");
2000  return array(
2001  array("source" => ilYuiUtil::getLocalPath('yahoo/yahoo-min.js'),
2002  "target" => $a_target_dir.'/js/yahoo/yahoo-min.js',
2003  "type" => "js"),
2004  array("source" => ilYuiUtil::getLocalPath('yahoo-dom-event/yahoo-dom-event.js'),
2005  "target" => $a_target_dir.'/js/yahoo/yahoo-dom-event.js',
2006  "type" => "js"),
2007  array("source" => ilYuiUtil::getLocalPath('animation/animation-min.js'),
2008  "target" => $a_target_dir.'/js/yahoo/animation-min.js',
2009  "type" => "js"),
2010  array("source" => './Services/JavaScript/js/Basic.js',
2011  "target" => $a_target_dir.'/js/Basic.js',
2012  "type" => "js"),
2013  array("source" => './Services/Accordion/js/accordion.js',
2014  "target" => $a_target_dir.'/js/accordion.js',
2015  "type" => "js"),
2016  array("source" => './Services/Accordion/css/accordion.css',
2017  "target" => $a_target_dir.'/css/accordion.css',
2018  "type" => "css"),
2019  array("source" => iljQueryUtil::getLocaljQueryPath(),
2020  "target" => $a_target_dir.'/js/jquery.js',
2021  "type" => "js"),
2022  array("source" => iljQueryUtil::getLocaljQueryUIPath(),
2023  "target" => $a_target_dir.'/js/jquery-ui-min.js',
2024  "type" => "js"),
2025  array("source" => './Services/COPage/js/ilCOPagePres.js',
2026  "target" => $a_target_dir.'/js/ilCOPagePres.js',
2027  "type" => "js"),
2028  array("source" => './Modules/Scorm2004/scripts/questions/pure.js',
2029  "target" => $a_target_dir.'/js/pure.js',
2030  "type" => "js"),
2031  array("source" => './Modules/Scorm2004/scripts/questions/question_handling.js',
2032  "target" => $a_target_dir.'/js/question_handling.js',
2033  "type" => "js"),
2034  array("source" => './Modules/Scorm2004/templates/default/question_handling.css',
2035  "target" => $a_target_dir.'/css/question_handling.css',
2036  "type" => "css")
2037  );
2038  }
2039 
2043  function exportHTMLFile($a_target_dir, $a_file_id)
2044  {
2045  $file_dir = $a_target_dir."/files/file_".$a_file_id;
2046  ilUtil::makeDir($file_dir);
2047  include_once("./Modules/File/classes/class.ilObjFile.php");
2048  $file_obj = new ilObjFile($a_file_id, false);
2049  $source_file = $file_obj->getDirectory($file_obj->getVersion())."/".$file_obj->getFileName();
2050  if (!is_file($source_file))
2051  {
2052  $source_file = $file_obj->getDirectory()."/".$file_obj->getFileName();
2053  }
2054  if (is_file($source_file))
2055  {
2056  copy($source_file, $file_dir."/".$file_obj->getFileName());
2057  }
2058  }
2059 
2063  function exportHTMLMOB($a_target_dir, &$a_lm_gui, $a_mob_id, $a_frame, &$a_linked_mobs)
2064  {
2065  global $tpl;
2066 
2067  $mob_dir = $a_target_dir."/mobs";
2068 
2069  $source_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob_id;
2070  if (@is_dir($source_dir))
2071  {
2072  ilUtil::makeDir($mob_dir."/mm_".$a_mob_id);
2073  ilUtil::rCopy($source_dir, $mob_dir."/mm_".$a_mob_id);
2074  }
2075 
2076  $tpl = new ilTemplate("tpl.main.html", true, true);
2077  $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
2078  $_GET["obj_type"] = "MediaObject";
2079  $_GET["mob_id"] = $a_mob_id;
2080  $_GET["frame"] = $a_frame;
2081  $_GET["cmd"] = "";
2082  $content =& $a_lm_gui->media();
2083  $file = $a_target_dir."/media_".$a_mob_id.".html";
2084 
2085  // open file
2086  if (!($fp = @fopen($file,"w+")))
2087  {
2088  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
2089  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
2090  }
2091  chmod($file, 0770);
2092  fwrite($fp, $content);
2093  fclose($fp);
2094 
2095  // fullscreen
2096  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
2097  $mob_obj = new ilObjMediaObject($a_mob_id);
2098  if ($mob_obj->hasFullscreenItem())
2099  {
2100  $tpl = new ilTemplate("tpl.main.html", true, true);
2101  $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
2102  $_GET["obj_type"] = "";
2103  $_GET["frame"] = "";
2104  $_GET["mob_id"] = $a_mob_id;
2105  $_GET["cmd"] = "fullscreen";
2106  $content =& $a_lm_gui->fullscreen();
2107  $file = $a_target_dir."/fullscreen_".$a_mob_id.".html";
2108 
2109  // open file
2110  if (!($fp = @fopen($file,"w+")))
2111  {
2112  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
2113  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
2114  }
2115  chmod($file, 0770);
2116  fwrite($fp, $content);
2117  fclose($fp);
2118  }
2119  $linked_mobs = $mob_obj->getLinkedMediaObjects();
2120  $a_linked_mobs = array_merge($a_linked_mobs, $linked_mobs);
2121  }
2122 
2126  function exportHTMLGlossaryTerms(&$a_lm_gui, $a_target_dir)
2127  {
2128  global $ilLocator;
2129 
2130  foreach($this->offline_int_links as $int_link)
2131  {
2132  $ilLocator->clearItems();
2133  if ($int_link["type"] == "git")
2134  {
2135  $tpl = new ilTemplate("tpl.main.html", true, true);
2136  $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
2137 
2138  $_GET["obj_id"] = $int_link["id"];
2139  $_GET["frame"] = "_blank";
2140  $content =& $a_lm_gui->glossary();
2141  $file = $a_target_dir."/term_".$int_link["id"].".html";
2142 
2143  // open file
2144  if (!($fp = @fopen($file,"w+")))
2145  {
2146  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
2147  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
2148  }
2149  chmod($file, 0770);
2150  fwrite($fp, $content);
2151  fclose($fp);
2152 
2153  // store linked/embedded media objects of glosssary term
2154  include_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
2155  $defs = ilGlossaryDefinition::getDefinitionList($int_link["id"]);
2156  foreach($defs as $def)
2157  {
2158  $def_mobs = ilObjMediaObject::_getMobsOfObject("gdf:pg", $def["id"]);
2159  foreach($def_mobs as $def_mob)
2160  {
2161  $this->offline_mobs[$def_mob] = $def_mob;
2162  }
2163 
2164  // get all files of page
2165  $def_files = ilObjFile::_getFilesOfObject("gdf:pg", $page["obj_id"]);
2166  $this->offline_files = array_merge($this->offline_files, $def_files);
2167 
2168  }
2169 
2170  }
2171  }
2172  }
2173 
2177  function exportHTMLPages(&$a_lm_gui, $a_target_dir)
2178  {
2179  global $tpl, $ilBench, $ilLocator;
2180 
2181  $pages = ilLMPageObject::getPageList($this->getId());
2182 
2183  $lm_tree =& $this->getLMTree();
2184  $first_page = $lm_tree->fetchSuccessorNode($lm_tree->getRootId(), "pg");
2185  $this->first_page_id = $first_page["child"];
2186 
2187  // iterate all learning module pages
2188  $mobs = array();
2189  $int_links = array();
2190  $this->offline_files = array();
2191 
2192  include_once("./Services/COPage/classes/class.ilPageContentUsage.php");
2193  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
2194 
2195  // get html export id mapping
2196  $lm_set = new ilSetting("lm");
2197  $exp_id_map = array();
2198 
2199  if ($lm_set->get("html_export_ids"))
2200  {
2201  foreach ($pages as $page)
2202  {
2203  $exp_id = ilLMPageObject::getExportId($this->getId(), $page["obj_id"]);
2204  if (trim($exp_id) != "")
2205  {
2206  $exp_id_map[$page["obj_id"]] = trim($exp_id);
2207  }
2208  }
2209  }
2210 //exit;
2211  reset($pages);
2212  foreach ($pages as $page)
2213  {
2214  if (ilPageObject::_exists($this->getType(), $page["obj_id"]))
2215  {
2216  $ilLocator->clearItems();
2217  $ilBench->start("ExportHTML", "exportHTMLPage");
2218  $ilBench->start("ExportHTML", "exportPageHTML");
2219  $this->exportPageHTML($a_lm_gui, $a_target_dir, $page["obj_id"],
2220  "", $exp_id_map);
2221  $ilBench->stop("ExportHTML", "exportPageHTML");
2222 
2223  // get all snippets of page
2224  $pcs = ilPageContentUsage::getUsagesOfPage($page["obj_id"], $this->getType().":pg");
2225  foreach ($pcs as $pc)
2226  {
2227  if ($pc["type"] == "incl")
2228  {
2229  $incl_mobs = ilObjMediaObject::_getMobsOfObject("mep:pg", $pc["id"]);
2230  foreach($incl_mobs as $incl_mob)
2231  {
2232  $mobs[$incl_mob] = $incl_mob;
2233  }
2234  }
2235  }
2236 
2237  // get all media objects of page
2238  $pg_mobs = ilObjMediaObject::_getMobsOfObject($this->getType().":pg", $page["obj_id"]);
2239  foreach($pg_mobs as $pg_mob)
2240  {
2241  $mobs[$pg_mob] = $pg_mob;
2242  }
2243 
2244  // get all internal links of page
2245  $pg_links = ilInternalLink::_getTargetsOfSource($this->getType().":pg", $page["obj_id"]);
2246  $int_links = array_merge($int_links, $pg_links);
2247 
2248  // get all files of page
2249  include_once("./Modules/File/classes/class.ilObjFile.php");
2250  $pg_files = ilObjFile::_getFilesOfObject($this->getType().":pg", $page["obj_id"]);
2251  $this->offline_files = array_merge($this->offline_files, $pg_files);
2252 
2253  $ilBench->stop("ExportHTML", "exportHTMLPage");
2254  }
2255  }
2256  $this->offline_mobs = $mobs;
2257  $this->offline_int_links = $int_links;
2258 
2259 
2260  }
2261 
2262 
2263 
2267  function exportPageHTML(&$a_lm_gui, $a_target_dir, $a_lm_page_id, $a_frame = "",
2268  $a_exp_id_map = array())
2269  {
2270  global $tpl, $ilBench;
2271 
2272 //echo "<br>B: export Page HTML ($a_lm_page_id)"; flush();
2273  // template workaround: reset of template
2274  $tpl = new ilTemplate("tpl.main.html", true, true);
2275  $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
2276 
2277  $_GET["obj_id"] = $a_lm_page_id;
2278  $_GET["frame"] = $a_frame;
2279 
2280  if ($a_frame == "")
2281  {
2282  //if ($nid = ilLMObject::_lookupNID($a_lm_gui->lm->getId(), $a_lm_page_id, "pg"))
2283  if (is_array($a_exp_id_map) && isset($a_exp_id_map[$a_lm_page_id]))
2284  {
2285  $file = $a_target_dir."/lm_pg_".$a_exp_id_map[$a_lm_page_id].".html";
2286  }
2287  else
2288  {
2289  $file = $a_target_dir."/lm_pg_".$a_lm_page_id.".html";
2290  }
2291  }
2292  else
2293  {
2294  if ($a_frame != "toc")
2295  {
2296  $file = $a_target_dir."/frame_".$a_lm_page_id."_".$a_frame.".html";
2297  }
2298  else
2299  {
2300  $file = $a_target_dir."/frame_".$a_frame.".html";
2301  }
2302  }
2303 
2304  // return if file is already existing
2305  if (@is_file($file))
2306  {
2307  return;
2308  }
2309 
2310  $ilBench->start("ExportHTML", "layout");
2311  $ilBench->start("ExportHTML", "layout_".$a_frame);
2312  $content =& $a_lm_gui->layout("main.xml", false);
2313  $ilBench->stop("ExportHTML", "layout_".$a_frame);
2314  $ilBench->stop("ExportHTML", "layout");
2315 
2316  // open file
2317  if (!($fp = @fopen($file,"w+")))
2318  {
2319  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
2320  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
2321  }
2322 
2323  // set file permissions
2324  chmod($file, 0770);
2325 
2326  // write xml data into the file
2327  fwrite($fp, $content);
2328 
2329  // close file
2330  fclose($fp);
2331 
2332  if ($this->first_page_id == $a_lm_page_id && $a_frame == "")
2333  {
2334  copy($file, $a_target_dir."/index.html");
2335  }
2336 
2337  // write frames of frameset
2338  $ilBench->start("ExportHTML", "getCurrentFrameSet");
2339  $frameset = $a_lm_gui->getCurrentFrameSet();
2340  $ilBench->stop("ExportHTML", "getCurrentFrameSet");
2341 
2342  foreach ($frameset as $frame)
2343  {
2344  $this->exportPageHTML($a_lm_gui, $a_target_dir, $a_lm_page_id, $frame);
2345  }
2346 
2347  }
2348 
2355  function exportFO(&$a_xml_writer, $a_target_dir)
2356  {
2357  global $ilBench;
2358 
2359  // fo:root (start)
2360  $attrs = array();
2361  $attrs["xmlns:fo"] = "http://www.w3.org/1999/XSL/Format";
2362  $a_xml_writer->xmlStartTag("fo:root", $attrs);
2363 
2364  // fo:layout-master-set (start)
2365  $attrs = array();
2366  $a_xml_writer->xmlStartTag("fo:layout-master-set", $attrs);
2367 
2368  // fo:simple-page-master (start)
2369  $attrs = array();
2370  $attrs["master-name"] = "DinA4";
2371  $attrs["page-height"] = "29.7cm";
2372  $attrs["page-width"] = "21cm";
2373  $attrs["margin-top"] = "4cm";
2374  $attrs["margin-bottom"] = "1cm";
2375  $attrs["margin-left"] = "2.8cm";
2376  $attrs["margin-right"] = "7.3cm";
2377  $a_xml_writer->xmlStartTag("fo:simple-page-master", $attrs);
2378 
2379  // fo:region-body (complete)
2380  $attrs = array();
2381  $attrs["margin-top"] = "0cm";
2382  $attrs["margin-bottom"] = "1.25cm";
2383  $a_xml_writer->xmlElement("fo:region-body", $attrs);
2384 
2385  // fo:region-before (complete)
2386  $attrs = array();
2387  $attrs["extent"] = "1cm";
2388  $a_xml_writer->xmlElement("fo:region-before", $attrs);
2389 
2390  // fo:region-after (complete)
2391  $attrs = array();
2392  $attrs["extent"] = "1cm";
2393  $a_xml_writer->xmlElement("fo:region-after", $attrs);
2394 
2395  // fo:simple-page-master (end)
2396  $a_xml_writer->xmlEndTag("fo:simple-page-master");
2397 
2398  // fo:layout-master-set (end)
2399  $a_xml_writer->xmlEndTag("fo:layout-master-set");
2400 
2401  // fo:page-sequence (start)
2402  $attrs = array();
2403  $attrs["master-reference"] = "DinA4";
2404  $a_xml_writer->xmlStartTag("fo:page-sequence", $attrs);
2405 
2406  // fo:flow (start)
2407  $attrs = array();
2408  $attrs["flow-name"] = "xsl-region-body";
2409  $a_xml_writer->xmlStartTag("fo:flow", $attrs);
2410 
2411 
2412  // StructureObjects
2413  //$expLog->write(date("[y-m-d H:i:s] ")."Start Export Structure Objects");
2414  $ilBench->start("ContentObjectExport", "exportFOStructureObjects");
2415  $this->exportFOStructureObjects($a_xml_writer, $expLog);
2416  $ilBench->stop("ContentObjectExport", "exportFOStructureObjects");
2417  //$expLog->write(date("[y-m-d H:i:s] ")."Finished Export Structure Objects");*/
2418 
2419  // fo:flow (end)
2420  $a_xml_writer->xmlEndTag("fo:flow");
2421 
2422  // fo:page-sequence (end)
2423  $a_xml_writer->xmlEndTag("fo:page-sequence");
2424 
2425  // fo:root (end)
2426  $a_xml_writer->xmlEndTag("fo:root");
2427  }
2428 
2435  function exportFOStructureObjects(&$a_xml_writer)
2436  {
2437  $childs = $this->lm_tree->getChilds($this->lm_tree->getRootId());
2438  foreach ($childs as $child)
2439  {
2440  if($child["type"] != "st")
2441  {
2442  continue;
2443  }
2444 
2445  $structure_obj = new ilStructureObject($this, $child["obj_id"]);
2446  $structure_obj->exportFO($a_xml_writer, $expLog);
2447  unset($structure_obj);
2448  }
2449  }
2450 
2451  function getXMLZip()
2452  {
2453  include_once("./Modules/LearningModule/classes/class.ilContObjectExport.php");
2454 
2455  $cont_exp = new ilContObjectExport($this,'xml');
2456 
2457  $export_file = $cont_exp->buildExportFile();
2458  return $export_file;
2459  }
2460 
2469  function executeDragDrop($source_id, $target_id, $first_child, $as_subitem = false, $movecopy = "move")
2470  {
2471  $lmtree = new ilTree($this->getId());
2472  $lmtree->setTableNames('lm_tree','lm_data');
2473  $lmtree->setTreeTablePK("lm_id");
2474 //echo "-".$source_id."-".$target_id."-".$first_child."-".$as_subitem."-";
2475  $source_obj = ilLMObjectFactory::getInstance($this, $source_id, true);
2476  $source_obj->setLMId($this->getId());
2477 
2478  if (!$first_child)
2479  {
2480  $target_obj = ilLMObjectFactory::getInstance($this, $target_id, true);
2481  $target_obj->setLMId($this->getId());
2482  $target_parent = $lmtree->getParentId($target_id);
2483  }
2484 
2485  // handle pages
2486  if ($source_obj->getType() == "pg")
2487  {
2488 //echo "1";
2489  if ($lmtree->isInTree($source_obj->getId()))
2490  {
2491  $node_data = $lmtree->getNodeData($source_obj->getId());
2492 
2493  // cut on move
2494  if ($movecopy == "move")
2495  {
2496  $parent_id = $lmtree->getParentId($source_obj->getId());
2497  $lmtree->deleteTree($node_data);
2498 
2499  // write history entry
2500  require_once("classes/class.ilHistory.php");
2501  ilHistory::_createEntry($source_obj->getId(), "cut",
2502  array(ilLMObject::_lookupTitle($parent_id), $parent_id),
2503  $this->getType().":pg");
2504  ilHistory::_createEntry($parent_id, "cut_page",
2505  array(ilLMObject::_lookupTitle($source_obj->getId()), $source_obj->getId()),
2506  $this->getType().":st");
2507  }
2508  else
2509  {
2510  // copy page
2511  $new_page =& $source_obj->copy();
2512  $source_id = $new_page->getId();
2513  $source_obj =& $new_page;
2514  }
2515 
2516  // paste page
2517  if(!$lmtree->isInTree($source_obj->getId()))
2518  {
2519  if ($first_child) // as first child
2520  {
2521  $target_pos = IL_FIRST_NODE;
2522  $parent = $target_id;
2523  }
2524  else if ($as_subitem) // as last child
2525  {
2526  $parent = $target_id;
2527  $target_pos = IL_FIRST_NODE;
2528  $pg_childs =& $lmtree->getChildsByType($parent, "pg");
2529  if (count($pg_childs) != 0)
2530  {
2531  $target_pos = $pg_childs[count($pg_childs) - 1]["obj_id"];
2532  }
2533  }
2534  else // at position
2535  {
2536  $target_pos = $target_id;
2537  $parent = $target_parent;
2538  }
2539 
2540  // insert page into tree
2541  $lmtree->insertNode($source_obj->getId(),
2542  $parent, $target_pos);
2543 
2544  // write history entry
2545  if ($movecopy == "move")
2546  {
2547  // write history comments
2548  include_once("classes/class.ilHistory.php");
2549  ilHistory::_createEntry($source_obj->getId(), "paste",
2550  array(ilLMObject::_lookupTitle($parent), $parent),
2551  $this->getType().":pg");
2552  ilHistory::_createEntry($parent, "paste_page",
2553  array(ilLMObject::_lookupTitle($source_obj->getId()), $source_obj->getId()),
2554  $this->getType().":st");
2555  }
2556 
2557  }
2558  }
2559  }
2560 
2561  // handle chapters
2562  if ($source_obj->getType() == "st")
2563  {
2564 //echo "2";
2565  $source_node = $lmtree->getNodeData($source_id);
2566  $subnodes = $lmtree->getSubtree($source_node);
2567 
2568  // check, if target is within subtree
2569  foreach ($subnodes as $subnode)
2570  {
2571  if($subnode["obj_id"] == $target_id)
2572  {
2573  return;
2574  }
2575  }
2576 
2577  $target_pos = $target_id;
2578 
2579  if ($first_child) // as first subchapter
2580  {
2581  $target_pos = IL_FIRST_NODE;
2582  $target_parent = $target_id;
2583 
2584  $pg_childs =& $lmtree->getChildsByType($target_parent, "pg");
2585  if (count($pg_childs) != 0)
2586  {
2587  $target_pos = $pg_childs[count($pg_childs) - 1]["obj_id"];
2588  }
2589  }
2590  else if ($as_subitem) // as last subchapter
2591  {
2592  $target_parent = $target_id;
2593  $target_pos = IL_FIRST_NODE;
2594  $childs =& $lmtree->getChilds($target_parent);
2595  if (count($childs) != 0)
2596  {
2597  $target_pos = $childs[count($childs) - 1]["obj_id"];
2598  }
2599  }
2600 
2601  // insert into
2602 /*
2603  if ($position == "into")
2604  {
2605  $target_parent = $target_id;
2606  $target_pos = IL_FIRST_NODE;
2607 
2608  // if target_pos is still first node we must skip all pages
2609  if ($target_pos == IL_FIRST_NODE)
2610  {
2611  $pg_childs =& $lmtree->getChildsByType($target_parent, "pg");
2612  if (count($pg_childs) != 0)
2613  {
2614  $target_pos = $pg_childs[count($pg_childs) - 1]["obj_id"];
2615  }
2616  }
2617  }
2618 */
2619 
2620 
2621  // delete source tree
2622  if ($movecopy == "move")
2623  {
2624  $lmtree->deleteTree($source_node);
2625  }
2626  else
2627  {
2628  // copy chapter (incl. subcontents)
2629  $new_chapter =& $source_obj->copy($lmtree, $target_parent, $target_pos);
2630  }
2631 
2632  if (!$lmtree->isInTree($source_id))
2633  {
2634  $lmtree->insertNode($source_id, $target_parent, $target_pos);
2635 
2636  // insert moved tree
2637  if ($movecopy == "move")
2638  {
2639  foreach ($subnodes as $node)
2640  {
2641  if($node["obj_id"] != $source_id)
2642  {
2643  $lmtree->insertNode($node["obj_id"], $node["parent"]);
2644  }
2645  }
2646  }
2647  }
2648 
2649  // check the tree
2650  $this->checkTree();
2651  }
2652 
2653  $this->checkTree();
2654  }
2655 
2659  function validatePages()
2660  {
2661  include_once "./Modules/LearningModule/classes/class.ilLMPageObject.php";
2662  include_once "./Services/COPage/classes/class.ilPageObject.php";
2663 
2664  $mess = "";
2665 
2666  $pages = ilLMPageObject::getPageList($this->getId());
2667  foreach ($pages as $page)
2668  {
2669  if (ilPageObject::_exists($this->getType(), $page["obj_id"]))
2670  {
2671  $cpage = new ilPageObject($this->getType(), $page["obj_id"]);
2672  $cpage->buildDom();
2673  $error = @$cpage->validateDom();
2674 
2675  if ($error != "")
2676  {
2677  $this->lng->loadLanguageModule("content");
2678  ilUtil::sendInfo($this->lng->txt("cont_import_validation_errors"));
2679  $title = ilLMObject::_lookupTitle($page["obj_id"]);
2680  $page_obj = new ilLMPageObject($this, $page["obj_id"]);
2681  $mess.= $this->lng->txt("obj_pg").": ".$title;
2682  $mess.= '<div class="small">';
2683  foreach ($error as $e)
2684  {
2685  $err_mess = implode($e, " - ");
2686  if (!is_int(strpos($err_mess, ":0:")))
2687  {
2688  $mess.= htmlentities($err_mess)."<br />";
2689  }
2690  }
2691  $mess.= '</div>';
2692  $mess.= "<br />";
2693  }
2694  }
2695  }
2696 
2697  return $mess;
2698  }
2699 
2706  function importFromZipFile($a_tmp_file, $a_filename, $a_validate = true)
2707  {
2708  global $lng;
2709 
2710  // create import directory
2711  $this->createImportDirectory();
2712 
2713  // copy uploaded file to import directory
2714  $file = pathinfo($a_filename);
2715  $full_path = $this->getImportDirectory()."/".$a_filename;
2716 
2717  ilUtil::moveUploadedFile($a_tmp_file,
2718  $a_filename, $full_path);
2719 
2720  // unzip file
2721  ilUtil::unzip($full_path);
2722 
2723  $subdir = basename($file["basename"],".".$file["extension"]);
2724 
2725  $mess = $this->importFromDirectory(
2726  $this->getImportDirectory()."/".$subdir, $a_validate);
2727 
2728  // delete import directory
2730 
2731  return $mess;
2732  }
2733 
2734 
2741  function importFromDirectory($a_directory, $a_validate = true)
2742  {
2743  global $lng;
2744 
2745  // determine filename of xml file
2746  $subdir = basename($a_directory);
2747  $xml_file = $a_directory."/".$subdir.".xml";
2748 
2749  // check directory exists within zip file
2750  if (!is_dir($a_directory))
2751  {
2752  return sprintf($lng->txt("cont_no_subdir_in_zip"), $subdir);
2753  }
2754 
2755  // check whether xml file exists within zip file
2756  if (!is_file($xml_file))
2757  {
2758  return sprintf($lng->txt("cont_zip_file_invalid"), $subdir."/".$subdir.".xml");
2759  }
2760 
2761  // import questions
2762  $qti_file = $a_directory."/qti.xml";
2763  $qtis = array();
2764  if (is_file($qti_file))
2765  {
2766  include_once "./Services/QTI/classes/class.ilQTIParser.php";
2767  include_once("./Modules/Test/classes/class.ilObjTest.php");
2768  $qtiParser = new ilQTIParser ($qti_file,
2769  IL_MO_VERIFY_QTI, 0, "");
2770  $result = $qtiParser->startParsing ();
2771  $founditems = & $qtiParser->getFoundItems ();
2772  $testObj = new ilObjTest(0, true);
2773  if (count($founditems) > 0)
2774  {
2775  $qtiParser = new ilQTIParser($qti_file, IL_MO_PARSE_QTI, 0, "");
2776  $qtiParser->setTestObject($testObj);
2777  $result = $qtiParser->startParsing();
2778  $qtis = array_merge($qtis, $qtiParser->getImportMapping());
2779  }
2780  }
2781 
2782  include_once ("./Modules/LearningModule/classes/class.ilContObjParser.php");
2783  $contParser = new ilContObjParser($this, $xml_file, $subdir, $qmapping);
2784  $contParser->setQuestionMapping($qtis);
2785  $contParser->startParsing();
2786  ilObject::_writeImportId($this->getId(), $this->getImportId());
2787  $this->MDUpdateListener('General');
2788 
2789  // import style
2790  $style_file = $a_directory."/style.xml";
2791  $style_zip_file = $a_directory."/style.zip";
2792  if (is_file($style_zip_file)) // try to import style.zip first
2793  {
2794  require_once("./Services/Style/classes/class.ilObjStyleSheet.php");
2795  $style = new ilObjStyleSheet();
2796  $style->import($style_zip_file);
2797  $this->writeStyleSheetId($style->getId());
2798  }
2799  else if (is_file($style_file)) // try to import style.xml
2800  {
2801  require_once("./Services/Style/classes/class.ilObjStyleSheet.php");
2802  $style = new ilObjStyleSheet();
2803  $style->import($style_file);
2804  $this->writeStyleSheetId($style->getId());
2805  }
2806 
2807 // // validate
2808  if ($a_validate)
2809  {
2810  $mess = $this->validatePages();
2811  }
2812 
2813  if ($mess == "")
2814  {
2815  // handle internal links to this learning module
2816  include_once("./Services/COPage/classes/class.ilPageObject.php");
2818  $this->getType(), $this->getRefId());
2819  }
2820 
2821  return $mess;
2822  }
2823 
2832  public function cloneObject($a_target_id,$a_copy_id = 0)
2833  {
2834  global $ilDB, $ilUser, $ilias;
2835 
2836  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
2837  $this->cloneMetaData($new_obj);
2838  //$new_obj->createProperties();
2839 
2840  $new_obj->setTitle($this->getTitle());
2841  $new_obj->setDescription($this->getDescription());
2842  $new_obj->setLayoutPerPage($this->getLayoutPerPage());
2843  $new_obj->setLayout($this->getLayout());
2844  $new_obj->setTOCMode($this->getTOCMode());
2845  $new_obj->setActiveLMMenu($this->isActiveLMMenu());
2846  $new_obj->setActiveTOC($this->isActiveTOC());
2847  $new_obj->setActiveNumbering($this->isActiveNumbering());
2848  $new_obj->setActivePrintView($this->isActivePrintView());
2849  $new_obj->setActivePreventGlossaryAppendix($this->isActivePreventGlossaryAppendix());
2850  $new_obj->setActiveDownloads($this->isActiveDownloads());
2851  $new_obj->setActiveDownloadsPublic($this->isActiveDownloadsPublic());
2852  $new_obj->setPublicNotes($this->publicNotes());
2853  $new_obj->setCleanFrames($this->cleanFrames());
2854  $new_obj->setHistoryUserComments($this->isActiveHistoryUserComments());
2855  $new_obj->setPublicAccessMode($this->getPublicAccessMode());
2856 
2857  $new_obj->update();
2858 
2859  $new_obj->createLMTree();
2860 
2861  // copy style
2862  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
2863  $style_id = $this->getStyleSheetId();
2864  if ($style_id > 0 &&
2866  {
2867  $style_obj = $ilias->obj_factory->getInstanceByObjId($style_id);
2868  $new_id = $style_obj->ilClone();
2869  $new_obj->setStyleSheetId($new_id);
2870  $new_obj->update();
2871  }
2872 
2873  // copy content
2874  $this->copyAllPagesAndChapters($new_obj);
2875 
2876  // Copy learning progress settings
2877  include_once('Services/Tracking/classes/class.ilLPObjSettings.php');
2878  $obj_settings = new ilLPObjSettings($this->getId());
2879  $obj_settings->cloneSettings($new_obj->getId());
2880  unset($obj_settings);
2881 
2882 
2883  return $new_obj;
2884  }
2885 
2891  function copyAllPagesAndChapters($a_target_obj)
2892  {
2893  $parent_id = $a_target_obj->lm_tree->readRootId();
2894 
2895  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
2896  include_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
2897 
2898  // get all chapters of root lm
2899  $chapters = $this->lm_tree->getChildsByType($this->lm_tree->readRootId(), "st");
2900  $copied_nodes = array();
2901  //$time = time();
2902  foreach ($chapters as $chap)
2903  {
2904  $cid = ilLMObject::pasteTree($a_target_obj, $chap["child"], $parent_id,
2905  IL_LAST_NODE, $time, $copied_nodes, true, $this);
2906  $target = $cid;
2907  }
2908 
2909  // copy free pages
2910  $pages = ilLMPageObject::getPageList($this->getId());
2911  foreach ($pages as $p)
2912  {
2913  if (!$this->lm_tree->isInTree($p["obj_id"]))
2914  {
2915  $item = new ilLMPageObject($this, $p["obj_id"]);
2916  $target_item = $item->copy($a_target_obj);
2917  $copied_nodes[$item->getId()] = $target_item->getId();
2918  }
2919  }
2920 
2921  ilLMObject::updateInternalLinks($copied_nodes);
2922 
2923  $a_target_obj->checkTree();
2924 
2925  }
2926 
2927 
2928 }
2929 ?>