ILIAS  release_4-4 Revision
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 "./Services/Object/classes/class.ilObject.php";
5 require_once "Services/MetaData/classes/class.ilMDLanguageItem.php";
6 require_once("./Services/Xml/classes/class.ilNestedSetXML.php");
7 
22 {
23  var $lm_tree;
25  var $layout;
26  var $style_id;
28  var $online;
29  protected $rating;
30  protected $rating_pages;
31  var $auto_glossaries = array();
32 
33  private $import_dir = '';
34 
41  function ilObjContentObject($a_id = 0,$a_call_by_reference = true)
42  {
43  // this also calls read() method! (if $a_id is set)
44  $this->ilObject($a_id,$a_call_by_reference);
45 
46  $this->mob_ids = array();
47  $this->file_ids = array();
48  $this->q_ids = array();
49  }
50 
54  function create($a_no_meta_data = false)
55  {
56  global $ilUser;
57 
58  parent::create();
59 
60  // meta data will be created by
61  // import parser
62  if (!$a_no_meta_data)
63  {
64  $this->createMetaData();
65  }
66 
67  $this->createProperties();
68  $this->updateAutoGlossaries();
69  }
70 
77  function initDefaultRoles()
78  {
79  return array();
80 
81  global $rbacadmin, $rbacreview;
82 
83  // create a local role folder
84  $rfoldObj = $this->createRoleFolder("Local roles","Role Folder of content object ".$this->getId());
85 
86  // note: we don't need any roles here, local "author" roles must
87  // be created manually. subscription roles have been abandoned.
88  /*
89  // create author role and assign role to rolefolder...
90  $roleObj = $rfoldObj->createRole("author object ".$this->getRefId(),"author of content object ref id ".$this->getRefId());
91  $roles[] = $roleObj->getId();
92 
93  // copy permissions from author template to new role
94  $rbacadmin->copyRolePermissions($this->getAuthorRoleTemplateId(), 8, $rfoldObj->getRefId(), $roleObj->getId());
95 
96  // grant all allowed operations of role to current learning module
97  $rbacadmin->grantPermission($roleObj->getId(),
98  $rbacreview->getOperationsOfRole($roleObj->getId(), "lm", $rfoldObj->getRefId()),
99  $this->getRefId());*/
100 
101  unset($rfoldObj);
102  //unset($roleObj);
103 
104  return $roles ? $roles : array();
105  }
106 
107 
111  function read()
112  {
113  global $ilDB;
114 
115  parent::read();
116 # echo "Content<br>\n";
117 
118  $this->lm_tree = new ilTree($this->getId());
119  $this->lm_tree->setTableNames('lm_tree','lm_data');
120  $this->lm_tree->setTreeTablePK("lm_id");
121 
122  $this->readProperties();
123 
124  // read auto glossaries
125  $set = $ilDB->query("SELECT * FROM lm_glossaries ".
126  " WHERE lm_id = ".$ilDB->quote($this->getId(), "integer")
127  );
128  $glos = array();
129  while ($rec = $ilDB->fetchAssoc($set))
130  {
131  $glos[] = $rec["glo_id"];
132  }
133  $this->setAutoGlossaries($glos);
134 
135  //parent::read();
136  }
137 
143  function getTitle()
144  {
145  return parent::getTitle();
146  }
147 
151  function setTitle($a_title)
152  {
153  parent::setTitle($a_title);
154 // $this->meta_data->setTitle($a_title);
155  }
156 
162  function getDescription()
163  {
164  return parent::getDescription();
165  }
166 
170  function setDescription($a_description)
171  {
172  parent::setDescription($a_description);
173 // $this->meta_data->setDescription($a_description);
174  }
175 
176 
177  function getImportId()
178  {
179  return $this->import_id;
180  }
181 
182  function setImportId($a_id)
183  {
184  $this->import_id = $a_id;
185  }
186 
192  function setLayoutPerPage($a_val)
193  {
194  $this->layout_per_page = $a_val;
195  }
196 
202  function getLayoutPerPage()
203  {
204  return $this->layout_per_page;
205  }
206 
212  function setDisableDefaultFeedback($a_val)
213  {
214  $this->disable_def_feedback = $a_val;
215  }
216 
223  {
224  return $this->disable_def_feedback;
225  }
226 
227  function &getTree()
228  {
229  return $this->lm_tree;
230  }
231 
235  function update()
236  {
237  $this->updateMetaData();
238  parent::update();
239  $this->updateProperties();
240  $this->updateAutoGlossaries();
241  }
242 
250  {
251  global $ilDB;
252 
253  // update auto glossaries
254  $ilDB->manipulate("DELETE FROM lm_glossaries WHERE ".
255  " lm_id = ".$ilDB->quote($this->getId(), "integer")
256  );
257  foreach ($this->getAutoGlossaries() as $glo_id)
258  {
259  $ilDB->manipulate("INSERT INTO lm_glossaries ".
260  "(lm_id, glo_id) VALUES (".
261  $ilDB->quote($this->getId(), "integer").",".
262  $ilDB->quote($glo_id, "integer").
263  ")");
264  }
265  }
266 
267 
271  function import()
272  {
273  // nothing to do. just display the dialogue in Out
274  return;
275  }
276 
277 
282  function putInTree($a_parent)
283  {
284  global $tree;
285 
286  // put this object in tree under $a_parent
287  parent::putInTree($a_parent);
288 
289  // make new tree for this object
290  //$tree->addTree($this->getId());
291  }
292 
293 
299  function createLMTree()
300  {
301  $this->lm_tree =& new ilTree($this->getId());
302  $this->lm_tree->setTreeTablePK("lm_id");
303  $this->lm_tree->setTableNames('lm_tree','lm_data');
304  $this->lm_tree->addTree($this->getId(), 1);
305  }
306 
312  function setAutoGlossaries($a_val)
313  {
314  $this->auto_glossaries = array();
315  if (is_array($a_val))
316  {
317  foreach ($a_val as $v)
318  {
319  $v = (int) $v;
320  if ($v > 0 && ilObject::_lookupType($v) == "glo" &&
321  !in_array($v, $this->auto_glossaries))
322  {
323  $this->auto_glossaries[] = $v;
324  }
325  }
326  }
327  }
328 
334  function getAutoGlossaries()
335  {
336  return $this->auto_glossaries;
337  }
338 
345  function removeAutoGlossary($a_glo_id)
346  {
347  $glo_ids = array();
348  foreach($this->getAutoGlossaries() as $g)
349  {
350  if ($g != $a_glo_id)
351  {
352  $glo_ids[] = $g;
353  }
354  }
355  $this->setAutoGlossaries($glo_ids);
356  }
357 
358 
363  {
364  global $lng;
365 
366  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
367  include_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
368  include_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
369 
370  $root_id = $this->lm_tree->getRootId();
371 
372  // chapter
373  $chap = new ilStructureObject($this);
374  $chap->setType("st");
375  $chap->setTitle($lng->txt("cont_new_chap"));
376  $chap->setLMId($this->getId());
377  $chap->create();
378  ilLMObject::putInTree($chap, $root_id, IL_FIRST_NODE);
379 
380  // page
381  $page = new ilLMPageObject($this);
382  $page->setType("pg");
383  $page->setTitle($lng->txt("cont_new_page"));
384  $page->setLMId($this->getId());
385  $page->create();
386  ilLMObject::putInTree($page, $chap->getId(), IL_FIRST_NODE);
387  }
388 
389 
393  function &getLMTree()
394  {
395  return $this->lm_tree;
396  }
397 
398 
405  {
406  $lm_data_dir = ilUtil::getDataDir()."/lm_data";
407  if(!is_writable($lm_data_dir))
408  {
409  $this->ilias->raiseError("Content object Data Directory (".$lm_data_dir
410  .") not writeable.",$this->ilias->error_obj->FATAL);
411  }
412 
413  // create learning module directory (data_dir/lm_data/lm_<id>)
414  $lm_dir = $lm_data_dir."/lm_".$this->getId();
415  ilUtil::makeDir($lm_dir);
416  if(!@is_dir($lm_dir))
417  {
418  $this->ilias->raiseError("Creation of Learning Module Directory failed.",$this->ilias->error_obj->FATAL);
419  }
420 
421  // create import subdirectory (data_dir/lm_data/lm_<id>/import)
422  $import_dir = $lm_dir."/import";
424  if(!@is_dir($import_dir))
425  {
426  $this->ilias->raiseError("Creation of Import Directory failed.",$this->ilias->error_obj->FATAL);
427  }
428  }
429 
433  function getDataDirectory()
434  {
435  return ilUtil::getDataDir()."/lm_data".
436  "/lm_".$this->getId();
437  }
438 
443  {
444  if(strlen($this->import_dir))
445  {
446  return $this->import_dir;
447  }
448 
449  $import_dir = ilUtil::getDataDir()."/lm_data".
450  "/lm_".$this->getId()."/import";
451  if(@is_dir($import_dir))
452  {
453  return $import_dir;
454  }
455  else
456  {
457  return false;
458  }
459  }
460 
467  public function setImportDirectory($a_import_dir)
468  {
469  $this->import_dir = $a_import_dir;
470  }
471 
472 
478  function createExportDirectory($a_type = "xml")
479  {
480  $lm_data_dir = ilUtil::getDataDir()."/lm_data";
481  if(!is_writable($lm_data_dir))
482  {
483  $this->ilias->raiseError("Content object Data Directory (".$lm_data_dir
484  .") not writeable.",$this->ilias->error_obj->FATAL);
485  }
486  // create learning module directory (data_dir/lm_data/lm_<id>)
487  $lm_dir = $lm_data_dir."/lm_".$this->getId();
488  ilUtil::makeDir($lm_dir);
489  if(!@is_dir($lm_dir))
490  {
491  $this->ilias->raiseError("Creation of Learning Module Directory failed.",$this->ilias->error_obj->FATAL);
492  }
493  // create Export subdirectory (data_dir/lm_data/lm_<id>/Export)
494  switch ($a_type)
495  {
496  // scorm
497  case "scorm":
498  $export_dir = $lm_dir."/export_scorm";
499  break;
500 
501  default: // = xml
502  if (substr($a_type, 0, 4) == "html")
503  {
504  $export_dir = $lm_dir."/export_".$a_type;
505  }
506  else
507  {
508  $export_dir = $lm_dir."/export";
509  }
510  break;
511  }
512  ilUtil::makeDir($export_dir);
513 
514  if(!@is_dir($export_dir))
515  {
516  $this->ilias->raiseError("Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
517  }
518  }
519 
523  function getExportDirectory($a_type = "xml")
524  {
525  switch ($a_type)
526  {
527  case "scorm":
528  $export_dir = ilUtil::getDataDir()."/lm_data"."/lm_".$this->getId()."/export_scorm";
529  break;
530 
531  default: // = xml
532  if (substr($a_type, 0, 4) == "html")
533  {
534  $export_dir = ilUtil::getDataDir()."/lm_data"."/lm_".$this->getId()."/export_".$a_type;
535  }
536  else
537  {
538  $export_dir = ilUtil::getDataDir()."/lm_data"."/lm_".$this->getId()."/export";
539  }
540  break;
541  }
542  return $export_dir;
543  }
544 
545 
556  function delete()
557  {
558  global $ilDB;
559 
560  global $ilBench;
561 
562  // always call parent delete function first!!
563  if (!parent::delete())
564  {
565  return false;
566  }
567 
568  // delete lm object data
569  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
571 
572  // delete meta data of content object
573  $this->deleteMetaData();
574 
575  // delete bibitem data
576  $nested = new ilNestedSetXML();
577  $nested->init($this->getId(), "bib");
578  $nested->deleteAllDBData();
579 
580 
581  // delete learning module tree
582  $this->lm_tree->removeTree($this->lm_tree->getTreeId());
583 
584  // delete data directory
586 
587  // delete content object record
588  $q = "DELETE FROM content_object WHERE id = ".
589  $ilDB->quote($this->getId(), "integer");
590  $ilDB->manipulate($q);
591 
592  // delete lm menu entries
593  $q = "DELETE FROM lm_menu WHERE lm_id = ".
594  $ilDB->quote($this->getId(), "integer");
595  $ilDB->manipulate($q);
596 
597  // remove auto glossary entries
598  $ilDB->manipulate("DELETE FROM lm_glossaries WHERE ".
599  " lm_id = ".$ilDB->quote($this->getId(), "integer")
600  );
601 
602 
603  return true;
604  }
605 
606 
612  function getLayout()
613  {
614  return $this->layout;
615  }
616 
622  function setLayout($a_layout)
623  {
624  $this->layout = $a_layout;
625  }
626 
630  function getStyleSheetId()
631  {
632  return $this->style_id;
633  }
634 
638  function setStyleSheetId($a_style_id)
639  {
640  $this->style_id = $a_style_id;
641  }
642 
646  function writeStyleSheetId($a_style_id)
647  {
648  global $ilDB;
649 
650  $q = "UPDATE content_object SET ".
651  " stylesheet = ".$ilDB->quote((int) $a_style_id, "integer").
652  " WHERE id = ".$ilDB->quote($this->getId(), "integer");
653  $ilDB->manipulate($q);
654 
655  $this->style_id = $a_style_id;
656  }
657 
661  function _moveLMStyles($a_from_style, $a_to_style)
662  {
663  global $ilDB, $ilias;
664 
665  if ($a_from_style < 0) // change / delete all individual styles
666  {
667  $q = "SELECT stylesheet FROM content_object, style_data ".
668  " WHERE content_object.stylesheet = style_data.id ".
669  " AND style_data.standard = ".$ilDB->quote(0, "integer").
670  " AND content_object.stylesheet > ".$ilDB->quote(0, "integer");
671  $style_set = $ilDB->query($q);
672  while($style_rec = $ilDB->fetchAssoc($style_set))
673  {
674  // assign learning modules to new style
675  $q = "UPDATE content_object SET ".
676  " stylesheet = ".$ilDB->quote((int) $a_to_style, "integer").
677  " WHERE stylesheet = ".$ilDB->quote($style_rec["stylesheet"], "integer");
678  $ilDB->manipulate($q);
679 
680  // delete style
681  $style_obj =& $ilias->obj_factory->getInstanceByObjId($style_rec["stylesheet"]);
682  $style_obj->delete();
683  }
684  }
685  else
686  {
687  $q = "UPDATE content_object SET ".
688  " stylesheet = ".$ilDB->quote((int) $a_to_style, "integer").
689  " WHERE stylesheet = ".$ilDB->quote($a_from_style, "integer");
690  $ilDB->manipulate($q);
691  }
692  }
693 
697  function _lookupStyleSheetId($a_cont_obj_id)
698  {
699  global $ilDB;
700 
701  $q = "SELECT stylesheet FROM content_object ".
702  " WHERE id = ".$ilDB->quote($a_cont_obj_id, "integer");
703  $res = $ilDB->query($q);
704  $sheet = $ilDB->fetchAssoc($res);
705 
706  return $sheet["stylesheet"];
707  }
708 
712  function _lookupContObjIdByStyleId($a_style_id)
713  {
714  global $ilDB;
715 
716  $q = "SELECT id FROM content_object ".
717  " WHERE stylesheet = ".$ilDB->quote($a_style_id, "integer");
718  $res = $ilDB->query($q);
719  $obj_ids = array();
720  while($cont = $ilDB->fetchAssoc($res))
721  {
722  $obj_ids[] = $cont["id"];
723  }
724  return $obj_ids;
725  }
726 
730  static function _lookupDisableDefaultFeedback($a_id)
731  {
732  global $ilDB;
733 
734  $q = "SELECT disable_def_feedback FROM content_object ".
735  " WHERE id = ".$ilDB->quote($a_id, "integer");
736  $res = $ilDB->query($q);
737  $rec = $ilDB->fetchAssoc($res);
738 
739  return $rec["disable_def_feedback"];
740  }
741 
742 
748  function _getNrOfAssignedLMs($a_style_id)
749  {
750  global $ilDB;
751 
752  $q = "SELECT count(*) as cnt FROM content_object ".
753  " WHERE stylesheet = ".$ilDB->quote($a_style_id, "integer");
754  $cset = $ilDB->query($q);
755  $crow = $ilDB->fetchAssoc($cset);
756 
757  return (int) $crow["cnt"];
758  }
759 
760 
765  {
766  global $ilDB;
767 
768  // joining with style table (not perfectly nice)
769  $q = "SELECT count(*) as cnt FROM content_object, style_data ".
770  " WHERE stylesheet = style_data.id ".
771  " AND standard = ".$ilDB->quote(0, "integer");
772  $cset = $ilDB->query($q);
773  $crow = $ilDB->fetchAssoc($cset);
774 
775  return (int) $crow["cnt"];
776  }
777 
781  function _getNrLMsNoStyle()
782  {
783  global $ilDB;
784 
785  $q = "SELECT count(*) as cnt FROM content_object ".
786  " WHERE stylesheet = ".$ilDB->quote(0, "integer");
787  $cset = $ilDB->query($q);
788  $crow = $ilDB->fetchAssoc($cset);
789 
790  return (int) $crow["cnt"];
791  }
792 
798  function _deleteStyleAssignments($a_style_id)
799  {
800  global $ilDB;
801 
802  $q = "UPDATE content_object SET ".
803  " stylesheet = ".$ilDB->quote(0, "integer").
804  " WHERE stylesheet = ".$ilDB->quote((int) $this->getId($a_style_id), "integer");
805 
806  $ilDB->manipulate($q);
807  }
808 
812  function getPageHeader()
813  {
814  return $this->pg_header;
815  }
816 
822  function setPageHeader($a_pg_header = IL_CHAPTER_TITLE)
823  {
824  $this->pg_header = $a_pg_header;
825  }
826 
830  function getTOCMode()
831  {
832  return $this->toc_mode;
833  }
834 
839  {
840  return $this->public_access_mode;
841  }
842 
848  function setTOCMode($a_toc_mode = "chapters")
849  {
850  $this->toc_mode = $a_toc_mode;
851  }
852 
853  function setOnline($a_online)
854  {
855  $this->online = $a_online;
856  }
857 
858  function getOnline()
859  {
860  return $this->online;
861  }
862 
863  function setActiveLMMenu($a_act_lm_menu)
864  {
865  $this->lm_menu_active = $a_act_lm_menu;
866  }
867 
868  function isActiveLMMenu()
869  {
870  return $this->lm_menu_active;
871  }
872 
873  function setActiveTOC($a_toc)
874  {
875  $this->toc_active = $a_toc;
876  }
877 
878  function isActiveTOC()
879  {
880  return $this->toc_active;
881  }
882 
883  function setActiveNumbering($a_num)
884  {
885  $this->numbering = $a_num;
886  }
887 
888  function isActiveNumbering()
889  {
890  return $this->numbering;
891  }
892 
893  function setActivePrintView($a_print)
894  {
895  $this->print_view_active = $a_print;
896  }
897 
898  function isActivePrintView()
899  {
900  return $this->print_view_active;
901  }
902 
904  {
905  $this->prevent_glossary_appendix_active = $a_print;
906  }
907 
909  {
910  return $this->prevent_glossary_appendix_active;
911  }
912 
918  function setHideHeaderFooterPrint($a_val)
919  {
920  $this->hide_header_footer_print = $a_val;
921  }
922 
929  {
930  return $this->hide_header_footer_print;
931  }
932 
933  function setActiveDownloads($a_down)
934  {
935  $this->downloads_active = $a_down;
936  }
937 
938  function isActiveDownloads()
939  {
940  return $this->downloads_active;
941  }
942 
943  function setActiveDownloadsPublic($a_down)
944  {
945  $this->downloads_public_active = $a_down;
946  }
947 
949  {
950  return $this->downloads_public_active;
951  }
952 
953  function setPublicNotes($a_pub_notes)
954  {
955  $this->pub_notes = $a_pub_notes;
956  }
957 
958  function publicNotes()
959  {
960  return $this->pub_notes;
961  }
962 
963  function setCleanFrames($a_clean)
964  {
965  $this->clean_frames = $a_clean;
966  }
967 
968  function cleanFrames()
969  {
970  return $this->clean_frames;
971  }
972 
973  function setHistoryUserComments($a_comm)
974  {
975  $this->user_comments = $a_comm;
976  }
977 
978  function setPublicAccessMode($a_mode)
979  {
980  $this->public_access_mode = $a_mode;
981  }
982 
984  {
985  return $this->user_comments;
986  }
987 
988  function setHeaderPage($a_pg)
989  {
990  $this->header_page = $a_pg;
991  }
992 
993  function getHeaderPage()
994  {
995  return $this->header_page;
996  }
997 
998  function setFooterPage($a_pg)
999  {
1000  $this->footer_page = $a_pg;
1001  }
1002 
1003  function getFooterPage()
1004  {
1005  return $this->footer_page;
1006  }
1007 
1011  function readProperties()
1012  {
1013  global $ilDB;
1014 
1015  $q = "SELECT * FROM content_object WHERE id = ".
1016  $ilDB->quote($this->getId(), "integer");
1017  $lm_set = $ilDB->query($q);
1018  $lm_rec = $ilDB->fetchAssoc($lm_set);
1019  $this->setLayout($lm_rec["default_layout"]);
1020  $this->setStyleSheetId((int) $lm_rec["stylesheet"]);
1021  $this->setPageHeader($lm_rec["page_header"]);
1022  $this->setTOCMode($lm_rec["toc_mode"]);
1023  $this->setOnline(ilUtil::yn2tf($lm_rec["is_online"]));
1024  $this->setActiveTOC(ilUtil::yn2tf($lm_rec["toc_active"]));
1025  $this->setActiveNumbering(ilUtil::yn2tf($lm_rec["numbering"]));
1026  $this->setActivePrintView(ilUtil::yn2tf($lm_rec["print_view_active"]));
1027  $this->setActivePreventGlossaryAppendix(ilUtil::yn2tf($lm_rec["no_glo_appendix"]));
1028  $this->setHideHeaderFooterPrint($lm_rec["hide_head_foot_print"]);
1029  $this->setActiveDownloads(ilUtil::yn2tf($lm_rec["downloads_active"]));
1030  $this->setActiveDownloadsPublic(ilUtil::yn2tf($lm_rec["downloads_public_active"]));
1031  $this->setActiveLMMenu(ilUtil::yn2tf($lm_rec["lm_menu_active"]));
1032  $this->setCleanFrames(ilUtil::yn2tf($lm_rec["clean_frames"]));
1033  $this->setPublicNotes(ilUtil::yn2tf($lm_rec["pub_notes"]));
1034  $this->setHeaderPage((int) $lm_rec["header_page"]);
1035  $this->setFooterPage((int) $lm_rec["footer_page"]);
1036  $this->setHistoryUserComments(ilUtil::yn2tf($lm_rec["hist_user_comments"]));
1037  $this->setPublicAccessMode($lm_rec["public_access_mode"]);
1038  $this->setPublicExportFile("xml", $lm_rec["public_xml_file"]);
1039  $this->setPublicExportFile("html", $lm_rec["public_html_file"]);
1040  $this->setPublicExportFile("scorm", $lm_rec["public_scorm_file"]);
1041  $this->setLayoutPerPage($lm_rec["layout_per_page"]);
1042  $this->setRating($lm_rec["rating"]);
1043  $this->setRatingPages($lm_rec["rating_pages"]);
1044  $this->setDisableDefaultFeedback($lm_rec["disable_def_feedback"]);
1045  }
1046 
1050  function updateProperties()
1051  {
1052  global $ilDB;
1053 
1054  // force clean_frames to be set, if layout per page is activated
1055  if ($this->getLayoutPerPage())
1056  {
1057  $this->setCleanFrames(true);
1058  }
1059 
1060  $q = "UPDATE content_object SET ".
1061  " default_layout = ".$ilDB->quote($this->getLayout(), "text").", ".
1062  " stylesheet = ".$ilDB->quote($this->getStyleSheetId(), "integer").",".
1063  " page_header = ".$ilDB->quote($this->getPageHeader(), "text").",".
1064  " toc_mode = ".$ilDB->quote($this->getTOCMode(), "text").",".
1065  " is_online = ".$ilDB->quote(ilUtil::tf2yn($this->getOnline()), "text").",".
1066  " toc_active = ".$ilDB->quote(ilUtil::tf2yn($this->isActiveTOC()), "text").",".
1067  " numbering = ".$ilDB->quote(ilUtil::tf2yn($this->isActiveNumbering()), "text").",".
1068  " print_view_active = ".$ilDB->quote(ilUtil::tf2yn($this->isActivePrintView()), "text").",".
1069  " no_glo_appendix = ".$ilDB->quote(ilUtil::tf2yn($this->isActivePreventGlossaryAppendix()), "text").",".
1070  " hide_head_foot_print = ".$ilDB->quote($this->getHideHeaderFooterPrint(), "integer").",".
1071  " downloads_active = ".$ilDB->quote(ilUtil::tf2yn($this->isActiveDownloads()), "text").",".
1072  " downloads_public_active = ".$ilDB->quote(ilUtil::tf2yn($this->isActiveDownloadsPublic()), "text").",".
1073  " clean_frames = ".$ilDB->quote(ilUtil::tf2yn($this->cleanFrames()), "text").",".
1074  " pub_notes = ".$ilDB->quote(ilUtil::tf2yn($this->publicNotes()), "text").",".
1075  " hist_user_comments = ".$ilDB->quote(ilUtil::tf2yn($this->isActiveHistoryUserComments()), "text").",".
1076  " public_access_mode = ".$ilDB->quote($this->getPublicAccessMode(), "text").",".
1077  " public_xml_file = ".$ilDB->quote($this->getPublicExportFile("xml"), "text").",".
1078  " public_html_file = ".$ilDB->quote($this->getPublicExportFile("html"), "text").",".
1079  " public_scorm_file = ".$ilDB->quote($this->getPublicExportFile("scorm"), "text").",".
1080  " header_page = ".$ilDB->quote($this->getHeaderPage(), "integer").",".
1081  " footer_page = ".$ilDB->quote($this->getFooterPage(), "integer").",".
1082  " lm_menu_active = ".$ilDB->quote(ilUtil::tf2yn($this->isActiveLMMenu()), "text").", ".
1083  " layout_per_page = ".$ilDB->quote($this->getLayoutPerPage(), "integer").", ".
1084  " rating = ".$ilDB->quote($this->hasRating(), "integer").", ".
1085  " rating_pages = ".$ilDB->quote($this->hasRatingPages(), "integer").", ".
1086  " disable_def_feedback = ".$ilDB->quote($this->getDisableDefaultFeedback(), "integer")." ".
1087  " WHERE id = ".$ilDB->quote($this->getId(), "integer");
1088  $ilDB->manipulate($q);
1089  }
1090 
1094  function createProperties()
1095  {
1096  global $ilDB;
1097 
1098  $q = "INSERT INTO content_object (id) VALUES (".$ilDB->quote($this->getId(), "integer").")";
1099  $ilDB->manipulate($q);
1100  $this->readProperties(); // to get db default values
1101  }
1102 
1106  function _lookupOnline($a_id)
1107  {
1108  global $ilDB;
1109 
1110 //echo "class ilObjContentObject::_lookupOnline($a_id) called. Use Access class instead.";
1111 
1112  $q = "SELECT is_online FROM content_object WHERE id = ".$ilDB->quote($a_id, "integer");
1113  $lm_set = $ilDB->query($q);
1114  $lm_rec = $ilDB->fetchAssoc($lm_set);
1115 
1116  return ilUtil::yn2tf($lm_rec["is_online"]);
1117  }
1118 
1125  {
1126  $dir = opendir("./Modules/LearningModule/layouts/lm");
1127 
1128  $layouts = array();
1129 
1130  while($file = readdir($dir))
1131  {
1132  if ($file != "." && $file != ".." && $file != "CVS" && $file != ".svn")
1133  {
1134  // directories
1135  if (@is_dir("./Modules/LearningModule/layouts/lm/".$file))
1136  {
1137  $layouts[$file] = $file;
1138  }
1139  }
1140  }
1141  asort($layouts);
1142 
1143  // workaround: fix ordering
1144  $ret = array(
1145  'toc2win' => 'toc2win',
1146  'toc2windyn' => 'toc2windyn',
1147  '1window' => '1window',
1148  '2window' => '2window',
1149  '3window' => '3window',
1150  'presentation' => 'presentation',
1151  'fullscreen' => 'fullscreen'
1152  );
1153 
1154  foreach ($layouts as $l)
1155  {
1156  if (!in_array($l, $ret))
1157  {
1158  $ret[$l] = $l;
1159  }
1160  }
1161 
1162  return $ret;
1163  }
1164 
1168  function _checkPreconditionsOfPage($cont_ref_id,$cont_obj_id, $page_id)
1169  {
1170  global $ilUser,$ilErr;
1171 
1172  $lm_tree = new ilTree($cont_obj_id);
1173  $lm_tree->setTableNames('lm_tree','lm_data');
1174  $lm_tree->setTreeTablePK("lm_id");
1175 
1176  if ($lm_tree->isInTree($page_id))
1177  {
1178  $path = $lm_tree->getPathFull($page_id, $lm_tree->readRootId());
1179  foreach ($path as $node)
1180  {
1181  if ($node["type"] == "st")
1182  {
1183  if (!ilConditionHandler::_checkAllConditionsOfTarget($cont_ref_id,$node["child"], "st"))
1184  {
1185  return false;
1186  }
1187  }
1188  }
1189  }
1190 
1191  return true;
1192  }
1193 
1197  function _getMissingPreconditionsOfPage($cont_ref_id,$cont_obj_id, $page_id)
1198  {
1199  $lm_tree = new ilTree($cont_obj_id);
1200  $lm_tree->setTableNames('lm_tree','lm_data');
1201  $lm_tree->setTreeTablePK("lm_id");
1202 
1203  $conds = array();
1204  if ($lm_tree->isInTree($page_id))
1205  {
1206  // get full path of page
1207  $path = $lm_tree->getPathFull($page_id, $lm_tree->readRootId());
1208  foreach ($path as $node)
1209  {
1210  if ($node["type"] == "st")
1211  {
1212  // get all preconditions of upper chapters
1213  $tconds = ilConditionHandler::_getConditionsOfTarget($cont_ref_id,$node["child"], "st");
1214  foreach ($tconds as $tcond)
1215  {
1216  // store all missing preconditions
1217  if (!ilConditionHandler::_checkCondition($tcond["id"]))
1218  {
1219  $conds[] = $tcond;
1220  }
1221  }
1222  }
1223  }
1224  }
1225 
1226  return $conds;
1227  }
1228 
1232  function _getMissingPreconditionsTopChapter($cont_obj_ref_id,$cont_obj_id, $page_id)
1233  {
1234  $lm_tree = new ilTree($cont_obj_id);
1235  $lm_tree->setTableNames('lm_tree','lm_data');
1236  $lm_tree->setTreeTablePK("lm_id");
1237 
1238  $conds = array();
1239  if ($lm_tree->isInTree($page_id))
1240  {
1241  // get full path of page
1242  $path = $lm_tree->getPathFull($page_id, $lm_tree->readRootId());
1243  foreach ($path as $node)
1244  {
1245  if ($node["type"] == "st")
1246  {
1247  // get all preconditions of upper chapters
1248  $tconds = ilConditionHandler::_getConditionsOfTarget($cont_obj_ref_id,$node["child"], "st");
1249  foreach ($tconds as $tcond)
1250  {
1251  // look for missing precondition
1252  if (!ilConditionHandler::_checkCondition($tcond["id"]))
1253  {
1254  return $node["child"];
1255  }
1256  }
1257  }
1258  }
1259  }
1260 
1261  return "";
1262  }
1263 
1274  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
1275  {
1276  global $tree;
1277 
1278  switch ($a_event)
1279  {
1280  case "link":
1281 
1282  //var_dump("<pre>",$a_params,"</pre>");
1283  //echo "Content Object ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
1284  //exit;
1285  break;
1286 
1287  case "cut":
1288 
1289  //echo "Content Object ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
1290  //exit;
1291  break;
1292 
1293  case "copy":
1294 
1295  //var_dump("<pre>",$a_params,"</pre>");
1296  //echo "Content Object ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
1297  //exit;
1298  break;
1299 
1300  case "paste":
1301 
1302  //echo "Content Object ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
1303  //exit;
1304  break;
1305 
1306  case "new":
1307 
1308  //echo "Content Object ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
1309  //exit;
1310  break;
1311  }
1312 
1313  // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
1314  if ($a_node_id==$_GET["ref_id"])
1315  {
1316  $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
1317  $parent_type = $parent_obj->getType();
1318  if($parent_type == $this->getType())
1319  {
1320  $a_node_id = (int) $tree->getParentId($a_node_id);
1321  }
1322  }
1323 
1324  parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
1325  }
1326 
1327 
1331  function hasSuccessorPage($a_cont_obj_id, $a_page_id)
1332  {
1333  $tree = new ilTree($a_cont_obj_id);
1334  $tree->setTableNames('lm_tree','lm_data');
1335  $tree->setTreeTablePK("lm_id");
1336  if ($tree->isInTree($a_page_id))
1337  {
1338  $succ = $tree->fetchSuccessorNode($a_page_id, "pg");
1339  if ($succ > 0)
1340  {
1341  return true;
1342  }
1343  }
1344  return false;
1345  }
1346 
1347 
1348  function checkTree()
1349  {
1350  $tree = new ilTree($this->getId());
1351  $tree->setTableNames('lm_tree','lm_data');
1352  $tree->setTreeTablePK("lm_id");
1353  $tree->checkTree();
1354  $tree->checkTreeChilds();
1355 //echo "checked";
1356  }
1357 
1361  function fixTree()
1362  {
1363  global $ilDB;
1364 
1365  $tree =& $this->getLMTree();
1366 
1367  // check numbering, if errors, renumber
1368  // it is very important to keep this step before deleting subtrees
1369  // in the following steps
1370  $set = $ilDB->query("SELECT DISTINCT l1.lm_id".
1371  " FROM lm_tree l1".
1372  " JOIN lm_tree l2 ON ( l1.child = l2.parent".
1373  " AND l1.lm_id = l2.lm_id )".
1374  " JOIN lm_data ON ( l1.child = lm_data.obj_id )".
1375  " WHERE (l2.lft < l1.lft".
1376  " OR l2.rgt > l1.rgt OR l2.lft > l1.rgt OR l2.rgt < l1.lft)".
1377  " AND l1.lm_id = ".$ilDB->quote($this->getId(), "integer").
1378  " ORDER BY lm_data.create_date DESC"
1379  );
1380  if ($rec = $ilDB->fetchAssoc($set))
1381  {
1382  $tree->renumber();
1383  }
1384 
1385  // delete subtrees that have no lm_data records
1386  $nodes = $tree->getSubtree($tree->getNodeData($tree->getRootId()));
1387  foreach ($nodes as $node)
1388  {
1389  $q = "SELECT * FROM lm_data WHERE obj_id = ".
1390  $ilDB->quote($node["child"], "integer");
1391  $obj_set = $ilDB->query($q);
1392  $obj_rec = $ilDB->fetchAssoc($obj_set);
1393  if (!$obj_rec)
1394  {
1395  $node_data = $tree->getNodeData($node["child"]);
1396  $tree->deleteTree($node_data);
1397  }
1398  }
1399 
1400  // delete subtrees that have pages as parent
1401  $nodes = $tree->getSubtree($tree->getNodeData($tree->getRootId()));
1402  foreach ($nodes as $node)
1403  {
1404  $q = "SELECT * FROM lm_data WHERE obj_id = ".
1405  $ilDB->quote($node["parent"], "integer");
1406  $obj_set = $ilDB->query($q);
1407  $obj_rec = $ilDB->fetchAssoc($obj_set);
1408  if ($obj_rec["type"] == "pg")
1409  {
1410  $node_data = $tree->getNodeData($node["child"]);
1411  if ($tree->isInTree($node["child"]))
1412  {
1413  $tree->deleteTree($node_data);
1414  }
1415  }
1416  }
1417 
1418  // check for multi-references pages or chapters
1419  // if errors -> create copies of them here
1420  $set = $ilDB->query("SELECT DISTINCT l1.lm_id".
1421  " FROM lm_tree l1".
1422  " JOIN lm_tree l2 ON ( l1.child = l2.child AND l1.lm_id <> l2.lm_id )".
1423  " JOIN lm_data ON (l1.child = lm_data.obj_id)".
1424  " WHERE l1.child <> 1".
1425  " AND l1.lm_id <> lm_data.lm_id".
1426  " AND l1.lm_id = ".$ilDB->quote($this->getId(), "integer"));
1427  if ($rec = $ilDB->fetchAssoc($set))
1428  {
1429  $set = $ilDB->query("SELECT DISTINCT l1.child ".
1430  " FROM lm_tree l1".
1431  " JOIN lm_tree l2 ON ( l1.child = l2.child AND l1.lm_id <> l2.lm_id )".
1432  " JOIN lm_data ON (l1.child = lm_data.obj_id)".
1433  " WHERE l1.child <> 1".
1434  " AND l1.lm_id <> lm_data.lm_id".
1435  " AND l1.lm_id = ".$ilDB->quote($this->getId(), "integer"));
1436  include_once("./Modules/LearningModule/classes/class.ilLMObjectFactory.php");
1437  while ($rec = $ilDB->fetchAssoc($set))
1438  {
1439  $cobj = ilLMObjectFactory::getInstance($this, $rec["child"]);
1440 
1441  if (is_object($cobj))
1442  {
1443  if ($cobj->getType() == "pg")
1444  {
1445  // make a copy of it
1446  $pg_copy = $cobj->copy($this);
1447 
1448  // replace the child in the tree with the copy (id)
1449  $ilDB->manipulate("UPDATE lm_tree SET ".
1450  " child = ".$ilDB->quote($pg_copy->getId(), "integer").
1451  " WHERE child = ".$ilDB->quote($cobj->getId(), "integer").
1452  " AND lm_id = ".$ilDB->quote($this->getId(), "integer")
1453  );
1454  }
1455  else if ($cobj->getType() == "st")
1456  {
1457  // make a copy of it
1458  $st_copy = $cobj->copy($this);
1459 
1460  // replace the child in the tree with the copy (id)
1461  $ilDB->manipulate("UPDATE lm_tree SET ".
1462  " child = ".$ilDB->quote($st_copy->getId(), "integer").
1463  " WHERE child = ".$ilDB->quote($cobj->getId(), "integer").
1464  " AND lm_id = ".$ilDB->quote($this->getId(), "integer")
1465  );
1466 
1467  // make all childs refer to the copy now
1468  $ilDB->manipulate("UPDATE lm_tree SET ".
1469  " parent = ".$ilDB->quote($st_copy->getId(), "integer").
1470  " WHERE parent = ".$ilDB->quote($cobj->getId(), "integer").
1471  " AND lm_id = ".$ilDB->quote($this->getId(), "integer")
1472  );
1473  }
1474  }
1475  }
1476  }
1477  }
1478 
1479 
1486  function exportXML(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
1487  {
1488  global $ilBench;
1489 
1490  $attrs = array();
1491  switch($this->getType())
1492  {
1493  case "lm":
1494  $attrs["Type"] = "LearningModule";
1495  break;
1496 
1497  case "dbk":
1498  $attrs["Type"] = "LibObject";
1499  break;
1500  }
1501  $a_xml_writer->xmlStartTag("ContentObject", $attrs);
1502 
1503  // MetaData
1504  $this->exportXMLMetaData($a_xml_writer);
1505 
1506  // StructureObjects
1507 //echo "ContObj:".$a_inst.":<br>";
1508  $expLog->write(date("[y-m-d H:i:s] ")."Start Export Structure Objects");
1509  $ilBench->start("ContentObjectExport", "exportStructureObjects");
1510  $this->exportXMLStructureObjects($a_xml_writer, $a_inst, $expLog);
1511  $ilBench->stop("ContentObjectExport", "exportStructureObjects");
1512  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Structure Objects");
1513 
1514  // PageObjects
1515  $expLog->write(date("[y-m-d H:i:s] ")."Start Export Page Objects");
1516  $ilBench->start("ContentObjectExport", "exportPageObjects");
1517  $this->exportXMLPageObjects($a_xml_writer, $a_inst, $expLog);
1518  $ilBench->stop("ContentObjectExport", "exportPageObjects");
1519  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Page Objects");
1520 
1521  // MediaObjects
1522  $expLog->write(date("[y-m-d H:i:s] ")."Start Export Media Objects");
1523  $ilBench->start("ContentObjectExport", "exportMediaObjects");
1524  $this->exportXMLMediaObjects($a_xml_writer, $a_inst, $a_target_dir, $expLog);
1525  $ilBench->stop("ContentObjectExport", "exportMediaObjects");
1526  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Media Objects");
1527 
1528  // FileItems
1529  $expLog->write(date("[y-m-d H:i:s] ")."Start Export File Items");
1530  $ilBench->start("ContentObjectExport", "exportFileItems");
1531  $this->exportFileItems($a_target_dir, $expLog);
1532  $ilBench->stop("ContentObjectExport", "exportFileItems");
1533  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export File Items");
1534 
1535  // Questions
1536  if (count($this->q_ids) > 0)
1537  {
1538  $qti_file = fopen($a_target_dir."/qti.xml", "w");
1539  include_once("./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php");
1540  $pool = new ilObjQuestionPool();
1541  fwrite($qti_file, $pool->toXML($this->q_ids));
1542  fclose($qti_file);
1543  }
1544 
1545  // To do: implement version selection/detection
1546  // Properties
1547  $expLog->write(date("[y-m-d H:i:s] ")."Start Export Properties");
1548  $this->exportXMLProperties($a_xml_writer, $expLog);
1549  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Properties");
1550 
1551  $a_xml_writer->xmlEndTag("ContentObject");
1552  }
1553 
1560  function exportXMLMetaData(&$a_xml_writer)
1561  {
1562  include_once("Services/MetaData/classes/class.ilMD2XML.php");
1563  $md2xml = new ilMD2XML($this->getId(), 0, $this->getType());
1564  $md2xml->setExportMode(true);
1565  $md2xml->startExport();
1566  $a_xml_writer->appendXML($md2xml->getXML());
1567  }
1568 
1575  function exportXMLStructureObjects(&$a_xml_writer, $a_inst, &$expLog)
1576  {
1577  include_once './Modules/LearningModule/classes/class.ilStructureObject.php';
1578 
1579  $childs = $this->lm_tree->getChilds($this->lm_tree->getRootId());
1580  foreach ($childs as $child)
1581  {
1582  if($child["type"] != "st")
1583  {
1584  continue;
1585  }
1586 
1587  $structure_obj = new ilStructureObject($this, $child["obj_id"]);
1588  $structure_obj->exportXML($a_xml_writer, $a_inst, $expLog);
1589  unset($structure_obj);
1590  }
1591  }
1592 
1593 
1600  function exportXMLPageObjects(&$a_xml_writer, $a_inst, &$expLog)
1601  {
1602  global $ilBench;
1603 
1604  include_once "./Modules/LearningModule/classes/class.ilLMPageObject.php";
1605  include_once "./Modules/LearningModule/classes/class.ilLMPage.php";
1606 
1607  $pages = ilLMPageObject::getPageList($this->getId());
1608  foreach ($pages as $page)
1609  {
1610  if (ilLMPage::_exists($this->getType(), $page["obj_id"]))
1611  {
1612  $expLog->write(date("[y-m-d H:i:s] ")."Page Object ".$page["obj_id"]);
1613 
1614  // export xml to writer object
1615  $page_obj = new ilLMPageObject($this, $page["obj_id"]);
1616  $page_obj->exportXML($a_xml_writer, "normal", $a_inst);
1617 
1618  // collect media objects
1619  $mob_ids = $page_obj->getMediaObjectIDs();
1620  foreach($mob_ids as $mob_id)
1621  {
1622  $this->mob_ids[$mob_id] = $mob_id;
1623  }
1624 
1625  // collect all file items
1626  $file_ids = $page_obj->getFileItemIds();
1627  foreach($file_ids as $file_id)
1628  {
1629  $this->file_ids[$file_id] = $file_id;
1630  }
1631 
1632  // collect all questions
1633  $q_ids = $page_obj->getQuestionIds();
1634  foreach($q_ids as $q_id)
1635  {
1636  $this->q_ids[$q_id] = $q_id;
1637  }
1638 
1639  unset($page_obj);
1640  }
1641  }
1642  }
1643 
1650  function exportXMLMediaObjects(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
1651  {
1652  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1653 
1654  $linked_mobs = array();
1655 
1656  // mobs directly embedded into pages
1657  foreach ($this->mob_ids as $mob_id)
1658  {
1659  if ($mob_id > 0 && ilObject::_lookupType($mob_id) == "mob")
1660  {
1661  $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
1662  $media_obj = new ilObjMediaObject($mob_id);
1663  $media_obj->exportXML($a_xml_writer, $a_inst);
1664  $media_obj->exportFiles($a_target_dir);
1665 
1666  $lmobs = $media_obj->getLinkedMediaObjects($this->mob_ids);
1667  $linked_mobs = array_merge($linked_mobs, $lmobs);
1668 
1669  unset($media_obj);
1670  }
1671  }
1672 
1673  // linked mobs (in map areas)
1674  foreach ($linked_mobs as $mob_id)
1675  {
1676  if ($mob_id > 0)
1677  {
1678  $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
1679  $media_obj = new ilObjMediaObject($mob_id);
1680  $media_obj->exportXML($a_xml_writer, $a_inst);
1681  $media_obj->exportFiles($a_target_dir);
1682  unset($media_obj);
1683  }
1684  }
1685 
1686  }
1687 
1692  function exportFileItems($a_target_dir, &$expLog)
1693  {
1694  include_once("./Modules/File/classes/class.ilObjFile.php");
1695 
1696  foreach ($this->file_ids as $file_id)
1697  {
1698  $expLog->write(date("[y-m-d H:i:s] ")."File Item ".$file_id);
1699  $file_obj = new ilObjFile($file_id, false);
1700  $file_obj->export($a_target_dir);
1701  unset($file_obj);
1702  }
1703  }
1704 
1709  function exportXMLProperties($a_xml_writer, &$expLog)
1710  {
1711  $attrs = array();
1712  $a_xml_writer->xmlStartTag("Properties", $attrs);
1713 
1714  // Layout
1715  $attrs = array("Name" => "Layout", "Value" => $this->getLayout());
1716  $a_xml_writer->xmlElement("Property", $attrs);
1717 
1718  // Page Header
1719  $attrs = array("Name" => "PageHeader", "Value" => $this->getPageHeader());
1720  $a_xml_writer->xmlElement("Property", $attrs);
1721 
1722  // TOC Mode
1723  $attrs = array("Name" => "TOCMode", "Value" => $this->getTOCMode());
1724  $a_xml_writer->xmlElement("Property", $attrs);
1725 
1726  // LM Menu Activation
1727  $attrs = array("Name" => "ActiveLMMenu", "Value" =>
1728  ilUtil::tf2yn($this->isActiveLMMenu()));
1729  $a_xml_writer->xmlElement("Property", $attrs);
1730 
1731  // Numbering Activation
1732  $attrs = array("Name" => "ActiveNumbering", "Value" =>
1733  ilUtil::tf2yn($this->isActiveNumbering()));
1734  $a_xml_writer->xmlElement("Property", $attrs);
1735 
1736  // Table of contents button activation
1737  $attrs = array("Name" => "ActiveTOC", "Value" =>
1738  ilUtil::tf2yn($this->isActiveTOC()));
1739  $a_xml_writer->xmlElement("Property", $attrs);
1740 
1741  // Print view button activation
1742  $attrs = array("Name" => "ActivePrintView", "Value" =>
1743  ilUtil::tf2yn($this->isActivePrintView()));
1744  $a_xml_writer->xmlElement("Property", $attrs);
1745 
1746  // Note that download button is not saved, because
1747  // download files do not exist after import
1748 
1749  // Clean frames
1750  $attrs = array("Name" => "CleanFrames", "Value" =>
1751  ilUtil::tf2yn($this->cleanFrames()));
1752  $a_xml_writer->xmlElement("Property", $attrs);
1753 
1754  // Public notes activation
1755  $attrs = array("Name" => "PublicNotes", "Value" =>
1756  ilUtil::tf2yn($this->publicNotes()));
1757  $a_xml_writer->xmlElement("Property", $attrs);
1758 
1759  // History comments for authors activation
1760  $attrs = array("Name" => "HistoryUserComments", "Value" =>
1762  $a_xml_writer->xmlElement("Property", $attrs);
1763 
1764  // Rating
1765  $attrs = array("Name" => "Rating", "Value" =>
1766  ilUtil::tf2yn($this->hasRating()));
1767  $a_xml_writer->xmlElement("Property", $attrs);
1768  $attrs = array("Name" => "RatingPages", "Value" =>
1769  ilUtil::tf2yn($this->hasRatingPages()));
1770  $a_xml_writer->xmlElement("Property", $attrs);
1771 
1772  // Header Page
1773  if ($this->getHeaderPage() > 0)
1774  {
1775  $attrs = array("Name" => "HeaderPage", "Value" =>
1776  "il_".IL_INST_ID."_pg_".$this->getHeaderPage());
1777  $a_xml_writer->xmlElement("Property", $attrs);
1778  }
1779 
1780  // Footer Page
1781  if ($this->getFooterPage() > 0)
1782  {
1783  $attrs = array("Name" => "FooterPage", "Value" =>
1784  "il_".IL_INST_ID."_pg_".$this->getFooterPage());
1785  $a_xml_writer->xmlElement("Property", $attrs);
1786  }
1787 
1788  $a_xml_writer->xmlEndTag("Properties");
1789  }
1790 
1794  function getExportFiles()
1795  {
1796  $file = array();
1797 
1798  $types = array("xml", "html", "scorm");
1799 
1800  foreach ($types as $type)
1801  {
1802  $dir = $this->getExportDirectory($type);
1803  // quit if import dir not available
1804  if (!@is_dir($dir) or
1805  !is_writeable($dir))
1806  {
1807  continue;
1808  }
1809 
1810  // open directory
1811  $cdir = dir($dir);
1812 
1813  // initialize array
1814 
1815  // get files and save the in the array
1816  while ($entry = $cdir->read())
1817  {
1818  if ($entry != "." and
1819  $entry != ".." and
1820  substr($entry, -4) == ".zip" and
1821  ereg("^[0-9]{10}_{2}[0-9]+_{2}(lm_)*[0-9]+\.zip\$", $entry))
1822  {
1823  $file[$entry.$type] = array("type" => $type, "file" => $entry,
1824  "size" => filesize($dir."/".$entry));
1825  }
1826  }
1827 
1828  // close import directory
1829  $cdir->close();
1830  }
1831 
1832  // sort files
1833  ksort ($file);
1834  reset ($file);
1835  return $file;
1836  }
1837 
1844  function setPublicExportFile($a_type, $a_file)
1845  {
1846  $this->public_export_file[$a_type] = $a_file;
1847  }
1848 
1856  function getPublicExportFile($a_type)
1857  {
1858  return $this->public_export_file[$a_type];
1859  }
1860 
1864  function getOfflineFiles($dir)
1865  {
1866  // quit if offline dir not available
1867  if (!@is_dir($dir) or
1868  !is_writeable($dir))
1869  {
1870  return array();
1871  }
1872 
1873  // open directory
1874  $dir = dir($dir);
1875 
1876  // initialize array
1877  $file = array();
1878 
1879  // get files and save the in the array
1880  while ($entry = $dir->read())
1881  {
1882  if ($entry != "." and
1883  $entry != ".." and
1884  substr($entry, -4) == ".pdf" and
1885  ereg("^[0-9]{10}_{2}[0-9]+_{2}(lm_)*[0-9]+\.pdf\$", $entry))
1886  {
1887  $file[] = $entry;
1888  }
1889  }
1890 
1891  // close import directory
1892  $dir->close();
1893 
1894  // sort files
1895  sort ($file);
1896  reset ($file);
1897 
1898  return $file;
1899  }
1900 
1904  function exportSCORM($a_target_dir, $log)
1905  {
1906  ilUtil::delDir($a_target_dir);
1907  ilUtil::makeDir($a_target_dir);
1908  //ilUtil::makeDir($a_target_dir."/res");
1909 
1910  // export everything to html
1911  $this->exportHTML($a_target_dir."/res", $log, false, "scorm");
1912 
1913  // build manifest file
1914  include("./Modules/LearningModule/classes/class.ilContObjectManifestBuilder.php");
1915  $man_builder = new ilContObjectManifestBuilder($this);
1916  $man_builder->buildManifest();
1917  $man_builder->dump($a_target_dir);
1918 
1919  // copy scorm 1.2 schema definitions
1920  copy("Modules/LearningModule/scorm_xsd/adlcp_rootv1p2.xsd", $a_target_dir."/adlcp_rootv1p2.xsd");
1921  copy("Modules/LearningModule/scorm_xsd/imscp_rootv1p1p2.xsd", $a_target_dir."/imscp_rootv1p1p2.xsd");
1922  copy("Modules/LearningModule/scorm_xsd/imsmd_rootv1p2p1.xsd", $a_target_dir."/imsmd_rootv1p2p1.xsd");
1923  copy("Modules/LearningModule/scorm_xsd/ims_xml.xsd", $a_target_dir."/ims_xml.xsd");
1924 
1925  // zip it all
1926  $date = time();
1927  $zip_file = $a_target_dir."/".$date."__".IL_INST_ID."__".
1928  $this->getType()."_".$this->getId().".zip";
1929  //echo "zip-".$a_target_dir."-to-".$zip_file;
1930  ilUtil::zip(array($a_target_dir."/res",
1931  $a_target_dir."/imsmanifest.xml",
1932  $a_target_dir."/adlcp_rootv1p2.xsd",
1933  $a_target_dir."/imscp_rootv1p1p2.xsd",
1934  $a_target_dir."/ims_xml.xsd",
1935  $a_target_dir."/imsmd_rootv1p2p1.xsd")
1936  , $zip_file);
1937 
1938  $dest_file = $this->getExportDirectory("scorm")."/".$date."__".IL_INST_ID."__".
1939  $this->getType()."_".$this->getId().".zip";
1940 
1941  rename($zip_file, $dest_file);
1942  ilUtil::delDir($a_target_dir);
1943 
1944  }
1945 
1946 
1950  function exportHTML($a_target_dir, $log, $a_zip_file = true, $a_export_format = "html", $a_lang = "")
1951  {
1952  global $tpl, $ilBench, $ilLocator, $ilUser, $ilObjDataCache, $ilias;
1953 
1954  $user_lang = $ilUser->getLanguage();
1955  if ($a_lang != "")
1956  {
1957  $ilUser->setLanguage($a_lang);
1958  $ilUser->setCurrentLanguage($a_lang);
1959  $ilObjDataCache->deleteCachedEntry($this->getId());
1960  }
1961 
1962  // initialize temporary target directory
1963  ilUtil::delDir($a_target_dir);
1964  ilUtil::makeDir($a_target_dir);
1965  $mob_dir = $a_target_dir."/mobs";
1966  ilUtil::makeDir($mob_dir);
1967  $file_dir = $a_target_dir."/files";
1968  ilUtil::makeDir($file_dir);
1969  $teximg_dir = $a_target_dir."/teximg";
1970  ilUtil::makeDir($teximg_dir);
1971  $style_dir = $a_target_dir."/style";
1972  ilUtil::makeDir($style_dir);
1973  $style_img_dir = $a_target_dir."/style/images";
1974  ilUtil::makeDir($style_img_dir);
1975  $content_style_dir = $a_target_dir."/content_style";
1976  ilUtil::makeDir($content_style_dir);
1977  $content_style_img_dir = $a_target_dir."/content_style/images";
1978  ilUtil::makeDir($content_style_img_dir);
1979  $GLOBALS["teximgcnt"] = 0;
1980 
1981  // export system style sheet
1982  $location_stylesheet = ilUtil::getStyleSheetLocation("filesystem");
1983  $style_name = $ilUser->prefs["style"].".css";
1984  copy($location_stylesheet, $style_dir."/".$style_name);
1985  $fh = fopen($location_stylesheet, "r");
1986  $css = fread($fh, filesize($location_stylesheet));
1987  preg_match_all("/url\(([^\)]*)\)/",$css,$files);
1988  foreach (array_unique($files[1]) as $fileref)
1989  {
1990  $fileref = dirname($location_stylesheet)."/".$fileref;
1991  if (is_file($fileref))
1992  {
1993  copy($fileref, $style_img_dir."/".basename($fileref));
1994  }
1995  }
1996  fclose($fh);
1997  $location_stylesheet = ilUtil::getStyleSheetLocation();
1998 
1999  // export content style sheet
2000  $ilBench->start("ExportHTML", "exportContentStyle");
2001  if ($this->getStyleSheetId() < 1)
2002  {
2003  $cont_stylesheet = "./Services/COPage/css/content.css";
2004 
2005  $css = fread(fopen($cont_stylesheet,'r'),filesize($cont_stylesheet));
2006  preg_match_all("/url\(([^\)]*)\)/",$css,$files);
2007  foreach (array_unique($files[1]) as $fileref)
2008  {
2009  if (is_file(str_replace("..", ".", $fileref)))
2010  {
2011  copy(str_replace("..", ".", $fileref), $content_style_img_dir."/".basename($fileref));
2012  }
2013  $css = str_replace($fileref, "images/".basename($fileref),$css);
2014  }
2015  fwrite(fopen($content_style_dir."/content.css",'w'),$css);
2016  }
2017  else
2018  {
2019  $style = new ilObjStyleSheet($this->getStyleSheetId());
2020  $style->writeCSSFile($content_style_dir."/content.css", "images");
2021  $style->copyImagesToDir($content_style_img_dir);
2022  }
2023  $ilBench->stop("ExportHTML", "exportContentStyle");
2024 
2025  // export syntax highlighting style
2026  $syn_stylesheet = ilObjStyleSheet::getSyntaxStylePath();
2027  copy($syn_stylesheet, $a_target_dir."/syntaxhighlight.css");
2028 
2029  // get learning module presentation gui class
2030  include_once("./Modules/LearningModule/classes/class.ilLMPresentationGUI.php");
2031  $_GET["cmd"] = "nop";
2032  $lm_gui =& new ilLMPresentationGUI();
2033  $lm_gui->setOfflineMode(true);
2034  $lm_gui->setOfflineDirectory($a_target_dir);
2035  $lm_gui->setExportFormat($a_export_format);
2036  $ot = ilObjectTranslation::getInstance($this->getId());
2037  if ($a_lang != "")
2038  {
2039  if ($a_lang == $ot->getMasterLanguage())
2040  {
2041  $lm_gui->lang = "";
2042  }
2043  else
2044  {
2045  $lm_gui->lang = $a_lang;
2046  }
2047  }
2048 
2049  // export pages
2050  $ilBench->start("ExportHTML", "exportHTMLPages");
2051  $this->exportHTMLPages($lm_gui, $a_target_dir, $lm_gui->lang);
2052  $ilBench->stop("ExportHTML", "exportHTMLPages");
2053 
2054  // export glossary terms
2055  $ilBench->start("ExportHTML", "exportHTMLGlossaryTerms");
2056  $this->exportHTMLGlossaryTerms($lm_gui, $a_target_dir);
2057  $ilBench->stop("ExportHTML", "exportHTMLGlossaryTerms");
2058 
2059  // export all media objects
2060  $ilBench->start("ExportHTML", "exportHTMLMediaObjects");
2061  $linked_mobs = array();
2062  foreach ($this->offline_mobs as $mob)
2063  {
2064  if (ilObject::_exists($mob) && ilObject::_lookupType($mob) == "mob")
2065  {
2066  $this->exportHTMLMOB($a_target_dir, $lm_gui, $mob, "_blank", $linked_mobs);
2067  }
2068  }
2069  $linked_mobs2 = array(); // mobs linked in link areas
2070  foreach ($linked_mobs as $mob)
2071  {
2072  if (ilObject::_exists($mob))
2073  {
2074  $this->exportHTMLMOB($a_target_dir, $lm_gui, $mob, "_blank", $linked_mobs2);
2075  }
2076  }
2077  $_GET["obj_type"] = "MediaObject";
2078  $_GET["obj_id"] = $a_mob_id;
2079  $_GET["cmd"] = "";
2080  $ilBench->stop("ExportHTML", "exportHTMLMediaObjects");
2081 
2082  // export all file objects
2083  $ilBench->start("ExportHTML", "exportHTMLFileObjects");
2084  foreach ($this->offline_files as $file)
2085  {
2086  $this->exportHTMLFile($a_target_dir, $file);
2087  }
2088  $ilBench->stop("ExportHTML", "exportHTMLFileObjects");
2089 
2090  // export questions (images)
2091  if (count($this->q_ids) > 0)
2092  {
2093  foreach ($this->q_ids as $q_id)
2094  {
2095  ilUtil::makeDirParents($a_target_dir."/assessment/0/".$q_id."/images");
2096  ilUtil::rCopy(ilUtil::getWebspaceDir()."/assessment/0/".$q_id."/images",
2097  $a_target_dir."/assessment/0/".$q_id."/images");
2098  }
2099  }
2100 
2101  // export table of contents
2102  $ilBench->start("ExportHTML", "exportHTMLTOC");
2103  $ilLocator->clearItems();
2104  if ($this->isActiveTOC())
2105  {
2106  $tpl = new ilTemplate("tpl.main.html", true, true);
2107  //$tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
2108  $content =& $lm_gui->showTableOfContents();
2109  $file = $a_target_dir."/table_of_contents.html";
2110 
2111  // open file
2112  if (!($fp = @fopen($file,"w+")))
2113  {
2114  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
2115  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
2116  }
2117  chmod($file, 0770);
2118  fwrite($fp, $content);
2119  fclose($fp);
2120  }
2121  $ilBench->stop("ExportHTML", "exportHTMLTOC");
2122 
2123  // export images
2124  $ilBench->start("ExportHTML", "exportHTMLImages");
2125  $image_dir = $a_target_dir."/images";
2126  ilUtil::makeDir($image_dir);
2127  ilUtil::makeDir($image_dir."/browser");
2128  copy(ilUtil::getImagePath("enlarge.png", false, "filesystem"),
2129  $image_dir."/enlarge.png");
2130  copy(ilUtil::getImagePath("browser/blank.png", false, "filesystem"),
2131  $image_dir."/browser/plus.png");
2132  copy(ilUtil::getImagePath("browser/blank.png", false, "filesystem"),
2133  $image_dir."/browser/minus.png");
2134  copy(ilUtil::getImagePath("browser/blank.png", false, "filesystem"),
2135  $image_dir."/browser/blank.png");
2136  copy(ilUtil::getImagePath("spacer.png", false, "filesystem"),
2137  $image_dir."/spacer.png");
2138  copy(ilUtil::getImagePath("icon_st.png", false, "filesystem"),
2139  $image_dir."/icon_st.png");
2140  copy(ilUtil::getImagePath("icon_pg.png", false, "filesystem"),
2141  $image_dir."/icon_pg.png");
2142  copy(ilUtil::getImagePath("icon_st_s.png", false, "filesystem"),
2143  $image_dir."/icon_st_s.png");
2144  copy(ilUtil::getImagePath("icon_pg_s.png", false, "filesystem"),
2145  $image_dir."/icon_pg_s.png");
2146  copy(ilUtil::getImagePath("icon_lm.png", false, "filesystem"),
2147  $image_dir."/icon_lm.png");
2148  copy(ilUtil::getImagePath("icon_lm_s.png", false, "filesystem"),
2149  $image_dir."/icon_lm_s.png");
2150  copy(ilUtil::getImagePath("nav_arr_L.png", false, "filesystem"),
2151  $image_dir."/nav_arr_L.png");
2152  copy(ilUtil::getImagePath("nav_arr_R.png", false, "filesystem"),
2153  $image_dir."/nav_arr_R.png");
2154  copy(ilUtil::getImagePath("browser/forceexp.png", false, "filesystem"),
2155  $image_dir."/browser/forceexp.png");
2156 
2157  copy(ilUtil::getImagePath("download.png", false, "filesystem"),
2158  $image_dir."/download.png");
2159  $ilBench->stop("ExportHTML", "exportHTMLImages");
2160 
2161  // export flv/mp3 player
2162  $services_dir = $a_target_dir."/Services";
2163  ilUtil::makeDir($services_dir);
2164  $media_service_dir = $services_dir."/MediaObjects";
2165  ilUtil::makeDir($media_service_dir);
2166  include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
2167  $flv_dir = $a_target_dir."/".ilPlayerUtil::getFlashVideoPlayerDirectory();
2168  ilUtil::makeDir($flv_dir);
2169  $mp3_dir = $media_service_dir."/flash_mp3_player";
2170  ilUtil::makeDir($mp3_dir);
2171 // copy(ilPlayerUtil::getFlashVideoPlayerFilename(true),
2172 // $flv_dir."/".ilPlayerUtil::getFlashVideoPlayerFilename());
2174  include_once("./Services/UIComponent/Explorer2/classes/class.ilExplorerBaseGUI.php");
2177 
2178  // js files
2179  ilUtil::makeDir($a_target_dir.'/js');
2180  ilUtil::makeDir($a_target_dir.'/js/yahoo');
2181  ilUtil::makeDir($a_target_dir.'/css');
2182  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
2183  foreach (self::getSupplyingExportFiles($a_target_dir) as $f)
2184  {
2185  if ($f["source"] != "")
2186  {
2187  copy($f["source"], $f["target"]);
2188  }
2189  }
2190 
2191  // template workaround: reset of template
2192  $tpl = new ilTemplate("tpl.main.html", true, true);
2193  $tpl->setVariable("LOCATION_STYLESHEET",$location_stylesheet);
2194  $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
2195 
2196  if ($a_lang != "")
2197  {
2198  $ilUser->setLanguage($user_lang);
2199  $ilUser->setCurrentLanguage($user_lang);
2200  }
2201 
2202  // zip everything
2203  if ($a_zip_file)
2204  {
2205  if ($a_lang == "")
2206  {
2207  $zip_target_dir = $this->getExportDirectory("html");
2208  }
2209  else
2210  {
2211  $zip_target_dir = $this->getExportDirectory("html_".$a_lang);
2212  ilUtil::makeDir($zip_target_dir);
2213  }
2214 
2215  // zip it all
2216  $date = time();
2217  $zip_file = $zip_target_dir."/".$date."__".IL_INST_ID."__".
2218  $this->getType()."_".$this->getId().".zip";
2219 //echo "-".$a_target_dir."-".$zip_file."-"; exit;
2220  ilUtil::zip($a_target_dir, $zip_file);
2221  ilUtil::delDir($a_target_dir);
2222  }
2223  }
2224 
2231  static function getSupplyingExportFiles($a_target_dir = ".")
2232  {
2233  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
2234  include_once("./Services/jQuery/classes/class.iljQueryUtil.php");
2235  include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
2236  include_once("./Services/UIComponent/Explorer2/classes/class.ilExplorerBaseGUI.php");
2237  $scripts = array(
2238  array("source" => ilYuiUtil::getLocalPath('yahoo/yahoo-min.js'),
2239  "target" => $a_target_dir.'/js/yahoo/yahoo-min.js',
2240  "type" => "js"),
2241  array("source" => ilYuiUtil::getLocalPath('yahoo-dom-event/yahoo-dom-event.js'),
2242  "target" => $a_target_dir.'/js/yahoo/yahoo-dom-event.js',
2243  "type" => "js"),
2244  array("source" => ilYuiUtil::getLocalPath('animation/animation-min.js'),
2245  "target" => $a_target_dir.'/js/yahoo/animation-min.js',
2246  "type" => "js"),
2247  array("source" => './Services/JavaScript/js/Basic.js',
2248  "target" => $a_target_dir.'/js/Basic.js',
2249  "type" => "js"),
2250  array("source" => './Services/Accordion/js/accordion.js',
2251  "target" => $a_target_dir.'/js/accordion.js',
2252  "type" => "js"),
2253  array("source" => './Services/Accordion/css/accordion.css',
2254  "target" => $a_target_dir.'/css/accordion.css',
2255  "type" => "css"),
2256  array("source" => iljQueryUtil::getLocaljQueryPath(),
2257  "target" => $a_target_dir.'/js/jquery.js',
2258  "type" => "js"),
2259  array("source" => iljQueryUtil::getLocalMaphilightPath(),
2260  "target" => $a_target_dir.'/js/maphilight.js',
2261  "type" => "js"),
2262  array("source" => iljQueryUtil::getLocaljQueryUIPath(),
2263  "target" => $a_target_dir.'/js/jquery-ui-min.js',
2264  "type" => "js"),
2265  array("source" => './Services/COPage/js/ilCOPagePres.js',
2266  "target" => $a_target_dir.'/js/ilCOPagePres.js',
2267  "type" => "js"),
2268  array("source" => './Modules/Scorm2004/scripts/questions/pure.js',
2269  "target" => $a_target_dir.'/js/pure.js',
2270  "type" => "js"),
2271  array("source" => './Modules/Scorm2004/scripts/questions/question_handling.js',
2272  "target" => $a_target_dir.'/js/question_handling.js',
2273  "type" => "js"),
2274  array("source" => './Modules/Scorm2004/templates/default/question_handling.css',
2275  "target" => $a_target_dir.'/css/question_handling.css',
2276  "type" => "css"),
2277  array("source" => ilPlayerUtil::getLocalMediaElementJsPath(),
2278  "target" => $a_target_dir."/".ilPlayerUtil::getLocalMediaElementJsPath(),
2279  "type" => "js"),
2280  array("source" => ilPlayerUtil::getLocalMediaElementCssPath(),
2281  "target" => $a_target_dir."/".ilPlayerUtil::getLocalMediaElementCssPath(),
2282  "type" => "css"),
2283  array("source" => ilExplorerBaseGUI::getLocalExplorerJsPath(),
2284  "target" => $a_target_dir."/".ilExplorerBaseGUI::getLocalExplorerJsPath(),
2285  "type" => "js"),
2286  array("source" => ilExplorerBaseGUI::getLocalJsTreeJsPath(),
2287  "target" => $a_target_dir."/".ilExplorerBaseGUI::getLocalJsTreeJsPath(),
2288  "type" => "js"),
2289  array("source" => './Modules/LearningModule/js/LearningModule.js',
2290  "target" => $a_target_dir.'/js/LearningModule.js',
2291  "type" => "js")
2292  );
2293 
2294  $mathJaxSetting = new ilSetting("MathJax");
2295  $use_mathjax = $mathJaxSetting->get("enable");
2296  if ($use_mathjax)
2297  {
2298  $scripts[] = array("source" => "",
2299  "target" => $mathJaxSetting->get("path_to_mathjax"),
2300  "type" => "js");
2301  }
2302 
2303  return $scripts;
2304 
2305  }
2306 
2310  function exportHTMLFile($a_target_dir, $a_file_id)
2311  {
2312  $file_dir = $a_target_dir."/files/file_".$a_file_id;
2313  ilUtil::makeDir($file_dir);
2314  include_once("./Modules/File/classes/class.ilObjFile.php");
2315  $file_obj = new ilObjFile($a_file_id, false);
2316  $source_file = $file_obj->getDirectory($file_obj->getVersion())."/".$file_obj->getFileName();
2317  if (!is_file($source_file))
2318  {
2319  $source_file = $file_obj->getDirectory()."/".$file_obj->getFileName();
2320  }
2321  if (is_file($source_file))
2322  {
2323  copy($source_file, $file_dir."/".$file_obj->getFileName());
2324  }
2325  }
2326 
2330  function exportHTMLMOB($a_target_dir, &$a_lm_gui, $a_mob_id, $a_frame, &$a_linked_mobs)
2331  {
2332  global $tpl;
2333 
2334  $mob_dir = $a_target_dir."/mobs";
2335 
2336  $source_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob_id;
2337  if (@is_dir($source_dir))
2338  {
2339  ilUtil::makeDir($mob_dir."/mm_".$a_mob_id);
2340  ilUtil::rCopy($source_dir, $mob_dir."/mm_".$a_mob_id);
2341  }
2342 
2343  $tpl = new ilTemplate("tpl.main.html", true, true);
2344  $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
2345  $_GET["obj_type"] = "MediaObject";
2346  $_GET["mob_id"] = $a_mob_id;
2347  $_GET["frame"] = $a_frame;
2348  $_GET["cmd"] = "";
2349  $content =& $a_lm_gui->media();
2350  $file = $a_target_dir."/media_".$a_mob_id.".html";
2351 
2352  // open file
2353  if (!($fp = @fopen($file,"w+")))
2354  {
2355  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
2356  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
2357  }
2358  chmod($file, 0770);
2359  fwrite($fp, $content);
2360  fclose($fp);
2361 
2362  // fullscreen
2363  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
2364  $mob_obj = new ilObjMediaObject($a_mob_id);
2365  if ($mob_obj->hasFullscreenItem())
2366  {
2367  $tpl = new ilTemplate("tpl.main.html", true, true);
2368  $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
2369  $_GET["obj_type"] = "";
2370  $_GET["frame"] = "";
2371  $_GET["mob_id"] = $a_mob_id;
2372  $_GET["cmd"] = "fullscreen";
2373  $content =& $a_lm_gui->fullscreen();
2374  $file = $a_target_dir."/fullscreen_".$a_mob_id.".html";
2375 
2376  // open file
2377  if (!($fp = @fopen($file,"w+")))
2378  {
2379  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
2380  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
2381  }
2382  chmod($file, 0770);
2383  fwrite($fp, $content);
2384  fclose($fp);
2385  }
2386  $linked_mobs = $mob_obj->getLinkedMediaObjects();
2387  $a_linked_mobs = array_merge($a_linked_mobs, $linked_mobs);
2388  }
2389 
2393  function exportHTMLGlossaryTerms(&$a_lm_gui, $a_target_dir)
2394  {
2395  global $ilLocator;
2396 
2397  foreach($this->offline_int_links as $int_link)
2398  {
2399  $ilLocator->clearItems();
2400  if ($int_link["type"] == "git")
2401  {
2402  $tpl = new ilTemplate("tpl.main.html", true, true);
2403  $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
2404 
2405  $_GET["obj_id"] = $int_link["id"];
2406  $_GET["frame"] = "_blank";
2407  $content =& $a_lm_gui->glossary();
2408  $file = $a_target_dir."/term_".$int_link["id"].".html";
2409 
2410  // open file
2411  if (!($fp = @fopen($file,"w+")))
2412  {
2413  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
2414  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
2415  }
2416  chmod($file, 0770);
2417  fwrite($fp, $content);
2418  fclose($fp);
2419 
2420  // store linked/embedded media objects of glosssary term
2421  include_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
2422  $defs = ilGlossaryDefinition::getDefinitionList($int_link["id"]);
2423  foreach($defs as $def)
2424  {
2425  $def_mobs = ilObjMediaObject::_getMobsOfObject("gdf:pg", $def["id"]);
2426  foreach($def_mobs as $def_mob)
2427  {
2428  $this->offline_mobs[$def_mob] = $def_mob;
2429  }
2430 
2431  // get all files of page
2432  $def_files = ilObjFile::_getFilesOfObject("gdf:pg", $page["obj_id"]);
2433  $this->offline_files = array_merge($this->offline_files, $def_files);
2434 
2435  }
2436 
2437  }
2438  }
2439  }
2440 
2444  function exportHTMLPages(&$a_lm_gui, $a_target_dir, $a_lang = "")
2445  {
2446  global $tpl, $ilBench, $ilLocator;
2447 
2448  $pages = ilLMPageObject::getPageList($this->getId());
2449 
2450  $lm_tree =& $this->getLMTree();
2451  $first_page = $lm_tree->fetchSuccessorNode($lm_tree->getRootId(), "pg");
2452  $this->first_page_id = $first_page["child"];
2453 
2454  // iterate all learning module pages
2455  $mobs = array();
2456  $int_links = array();
2457  $this->offline_files = array();
2458 
2459  include_once("./Services/COPage/classes/class.ilPageContentUsage.php");
2460  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
2461 
2462  // get html export id mapping
2463  $lm_set = new ilSetting("lm");
2464  $exp_id_map = array();
2465 
2466  if ($lm_set->get("html_export_ids"))
2467  {
2468  foreach ($pages as $page)
2469  {
2470  $exp_id = ilLMPageObject::getExportId($this->getId(), $page["obj_id"]);
2471  if (trim($exp_id) != "")
2472  {
2473  $exp_id_map[$page["obj_id"]] = trim($exp_id);
2474  }
2475  }
2476  }
2477 //exit;
2478  if ($a_lang == "")
2479  {
2480  $a_lang = "-";
2481  }
2482 
2483  reset($pages);
2484  foreach ($pages as $page)
2485  {
2486  if (ilLMPage::_exists($this->getType(), $page["obj_id"]))
2487  {
2488  $ilLocator->clearItems();
2489  $ilBench->start("ExportHTML", "exportHTMLPage");
2490  $ilBench->start("ExportHTML", "exportPageHTML");
2491  $this->exportPageHTML($a_lm_gui, $a_target_dir, $page["obj_id"],
2492  "", $exp_id_map);
2493  $ilBench->stop("ExportHTML", "exportPageHTML");
2494 
2495  // get all snippets of page
2496  $pcs = ilPageContentUsage::getUsagesOfPage($page["obj_id"], $this->getType().":pg", 0, false, $a_lang);
2497  foreach ($pcs as $pc)
2498  {
2499  if ($pc["type"] == "incl")
2500  {
2501  $incl_mobs = ilObjMediaObject::_getMobsOfObject("mep:pg", $pc["id"]);
2502  foreach($incl_mobs as $incl_mob)
2503  {
2504  $mobs[$incl_mob] = $incl_mob;
2505  }
2506  }
2507  }
2508 
2509  // get all media objects of page
2510  $pg_mobs = ilObjMediaObject::_getMobsOfObject($this->getType().":pg", $page["obj_id"], 0, $a_lang);
2511  foreach($pg_mobs as $pg_mob)
2512  {
2513  $mobs[$pg_mob] = $pg_mob;
2514  }
2515 
2516  // get all internal links of page
2517  $pg_links = ilInternalLink::_getTargetsOfSource($this->getType().":pg", $page["obj_id"], $a_lang);
2518  $int_links = array_merge($int_links, $pg_links);
2519 
2520  // get all files of page
2521  include_once("./Modules/File/classes/class.ilObjFile.php");
2522  $pg_files = ilObjFile::_getFilesOfObject($this->getType().":pg", $page["obj_id"], 0, $a_lang);
2523  $this->offline_files = array_merge($this->offline_files, $pg_files);
2524 
2525  // collect all questions
2526  include_once("./Services/COPage/classes/class.ilPCQuestion.php");
2527  $q_ids = ilPCQuestion::_getQuestionIdsForPage($this->getType(), $page["obj_id"], $a_lang);
2528  foreach($q_ids as $q_id)
2529  {
2530  $this->q_ids[$q_id] = $q_id;
2531  }
2532 
2533  $ilBench->stop("ExportHTML", "exportHTMLPage");
2534  }
2535  }
2536  $this->offline_mobs = $mobs;
2537  $this->offline_int_links = $int_links;
2538  }
2539 
2540 
2541 
2545  function exportPageHTML(&$a_lm_gui, $a_target_dir, $a_lm_page_id, $a_frame = "",
2546  $a_exp_id_map = array())
2547  {
2548  global $tpl, $ilBench;
2549 
2550 //echo "<br>B: export Page HTML ($a_lm_page_id)"; flush();
2551  // template workaround: reset of template
2552  $tpl = new ilTemplate("tpl.main.html", true, true);
2553  $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
2554 
2555  $_GET["obj_id"] = $a_lm_page_id;
2556  $_GET["frame"] = $a_frame;
2557 
2558  if ($a_frame == "")
2559  {
2560  //if ($nid = ilLMObject::_lookupNID($a_lm_gui->lm->getId(), $a_lm_page_id, "pg"))
2561  if (is_array($a_exp_id_map) && isset($a_exp_id_map[$a_lm_page_id]))
2562  {
2563  $file = $a_target_dir."/lm_pg_".$a_exp_id_map[$a_lm_page_id].".html";
2564  }
2565  else
2566  {
2567  $file = $a_target_dir."/lm_pg_".$a_lm_page_id.".html";
2568  }
2569  }
2570  else
2571  {
2572  if ($a_frame != "toc")
2573  {
2574  $file = $a_target_dir."/frame_".$a_lm_page_id."_".$a_frame.".html";
2575  }
2576  else
2577  {
2578  $file = $a_target_dir."/frame_".$a_frame.".html";
2579  }
2580  }
2581 
2582  // return if file is already existing
2583  if (@is_file($file))
2584  {
2585  return;
2586  }
2587 
2588  $content =& $a_lm_gui->layout("main.xml", false);
2589 
2590  // open file
2591  if (!($fp = @fopen($file,"w+")))
2592  {
2593  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
2594  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
2595  }
2596 
2597  // set file permissions
2598  chmod($file, 0770);
2599 
2600  // write xml data into the file
2601  fwrite($fp, $content);
2602 
2603  // close file
2604  fclose($fp);
2605 
2606  if ($this->first_page_id == $a_lm_page_id && $a_frame == "")
2607  {
2608  copy($file, $a_target_dir."/index.html");
2609  }
2610 
2611  // write frames of frameset
2612  $frameset = $a_lm_gui->getCurrentFrameSet();
2613 
2614  foreach ($frameset as $frame)
2615  {
2616  $this->exportPageHTML($a_lm_gui, $a_target_dir, $a_lm_page_id, $frame);
2617  }
2618 
2619  }
2620 
2627  function exportFO(&$a_xml_writer, $a_target_dir)
2628  {
2629  global $ilBench;
2630 
2631  // fo:root (start)
2632  $attrs = array();
2633  $attrs["xmlns:fo"] = "http://www.w3.org/1999/XSL/Format";
2634  $a_xml_writer->xmlStartTag("fo:root", $attrs);
2635 
2636  // fo:layout-master-set (start)
2637  $attrs = array();
2638  $a_xml_writer->xmlStartTag("fo:layout-master-set", $attrs);
2639 
2640  // fo:simple-page-master (start)
2641  $attrs = array();
2642  $attrs["master-name"] = "DinA4";
2643  $attrs["page-height"] = "29.7cm";
2644  $attrs["page-width"] = "21cm";
2645  $attrs["margin-top"] = "4cm";
2646  $attrs["margin-bottom"] = "1cm";
2647  $attrs["margin-left"] = "2.8cm";
2648  $attrs["margin-right"] = "7.3cm";
2649  $a_xml_writer->xmlStartTag("fo:simple-page-master", $attrs);
2650 
2651  // fo:region-body (complete)
2652  $attrs = array();
2653  $attrs["margin-top"] = "0cm";
2654  $attrs["margin-bottom"] = "1.25cm";
2655  $a_xml_writer->xmlElement("fo:region-body", $attrs);
2656 
2657  // fo:region-before (complete)
2658  $attrs = array();
2659  $attrs["extent"] = "1cm";
2660  $a_xml_writer->xmlElement("fo:region-before", $attrs);
2661 
2662  // fo:region-after (complete)
2663  $attrs = array();
2664  $attrs["extent"] = "1cm";
2665  $a_xml_writer->xmlElement("fo:region-after", $attrs);
2666 
2667  // fo:simple-page-master (end)
2668  $a_xml_writer->xmlEndTag("fo:simple-page-master");
2669 
2670  // fo:layout-master-set (end)
2671  $a_xml_writer->xmlEndTag("fo:layout-master-set");
2672 
2673  // fo:page-sequence (start)
2674  $attrs = array();
2675  $attrs["master-reference"] = "DinA4";
2676  $a_xml_writer->xmlStartTag("fo:page-sequence", $attrs);
2677 
2678  // fo:flow (start)
2679  $attrs = array();
2680  $attrs["flow-name"] = "xsl-region-body";
2681  $a_xml_writer->xmlStartTag("fo:flow", $attrs);
2682 
2683 
2684  // StructureObjects
2685  //$expLog->write(date("[y-m-d H:i:s] ")."Start Export Structure Objects");
2686  $ilBench->start("ContentObjectExport", "exportFOStructureObjects");
2687  $this->exportFOStructureObjects($a_xml_writer, $expLog);
2688  $ilBench->stop("ContentObjectExport", "exportFOStructureObjects");
2689  //$expLog->write(date("[y-m-d H:i:s] ")."Finished Export Structure Objects");*/
2690 
2691  // fo:flow (end)
2692  $a_xml_writer->xmlEndTag("fo:flow");
2693 
2694  // fo:page-sequence (end)
2695  $a_xml_writer->xmlEndTag("fo:page-sequence");
2696 
2697  // fo:root (end)
2698  $a_xml_writer->xmlEndTag("fo:root");
2699  }
2700 
2707  function exportFOStructureObjects(&$a_xml_writer)
2708  {
2709  $childs = $this->lm_tree->getChilds($this->lm_tree->getRootId());
2710  foreach ($childs as $child)
2711  {
2712  if($child["type"] != "st")
2713  {
2714  continue;
2715  }
2716 
2717  $structure_obj = new ilStructureObject($this, $child["obj_id"]);
2718  $structure_obj->exportFO($a_xml_writer, $expLog);
2719  unset($structure_obj);
2720  }
2721  }
2722 
2723  function getXMLZip()
2724  {
2725  include_once("./Modules/LearningModule/classes/class.ilContObjectExport.php");
2726 
2727  $cont_exp = new ilContObjectExport($this,'xml');
2728 
2729  $export_file = $cont_exp->buildExportFile();
2730  return $export_file;
2731  }
2732 
2741  function executeDragDrop($source_id, $target_id, $first_child, $as_subitem = false, $movecopy = "move")
2742  {
2743  $lmtree = new ilTree($this->getId());
2744  $lmtree->setTableNames('lm_tree','lm_data');
2745  $lmtree->setTreeTablePK("lm_id");
2746 //echo "-".$source_id."-".$target_id."-".$first_child."-".$as_subitem."-";
2747  $source_obj = ilLMObjectFactory::getInstance($this, $source_id, true);
2748  $source_obj->setLMId($this->getId());
2749 
2750  if (!$first_child)
2751  {
2752  $target_obj = ilLMObjectFactory::getInstance($this, $target_id, true);
2753  $target_obj->setLMId($this->getId());
2754  $target_parent = $lmtree->getParentId($target_id);
2755  }
2756 
2757  // handle pages
2758  if ($source_obj->getType() == "pg")
2759  {
2760 //echo "1";
2761  if ($lmtree->isInTree($source_obj->getId()))
2762  {
2763  $node_data = $lmtree->getNodeData($source_obj->getId());
2764 
2765  // cut on move
2766  if ($movecopy == "move")
2767  {
2768  $parent_id = $lmtree->getParentId($source_obj->getId());
2769  $lmtree->deleteTree($node_data);
2770 
2771  // write history entry
2772  require_once("./Services/History/classes/class.ilHistory.php");
2773  ilHistory::_createEntry($source_obj->getId(), "cut",
2774  array(ilLMObject::_lookupTitle($parent_id), $parent_id),
2775  $this->getType().":pg");
2776  ilHistory::_createEntry($parent_id, "cut_page",
2777  array(ilLMObject::_lookupTitle($source_obj->getId()), $source_obj->getId()),
2778  $this->getType().":st");
2779  }
2780  else
2781  {
2782  // copy page
2783  $new_page =& $source_obj->copy();
2784  $source_id = $new_page->getId();
2785  $source_obj =& $new_page;
2786  }
2787 
2788  // paste page
2789  if(!$lmtree->isInTree($source_obj->getId()))
2790  {
2791  if ($first_child) // as first child
2792  {
2793  $target_pos = IL_FIRST_NODE;
2794  $parent = $target_id;
2795  }
2796  else if ($as_subitem) // as last child
2797  {
2798  $parent = $target_id;
2799  $target_pos = IL_FIRST_NODE;
2800  $pg_childs =& $lmtree->getChildsByType($parent, "pg");
2801  if (count($pg_childs) != 0)
2802  {
2803  $target_pos = $pg_childs[count($pg_childs) - 1]["obj_id"];
2804  }
2805  }
2806  else // at position
2807  {
2808  $target_pos = $target_id;
2809  $parent = $target_parent;
2810  }
2811 
2812  // insert page into tree
2813  $lmtree->insertNode($source_obj->getId(),
2814  $parent, $target_pos);
2815 
2816  // write history entry
2817  if ($movecopy == "move")
2818  {
2819  // write history comments
2820  include_once("./Services/History/classes/class.ilHistory.php");
2821  ilHistory::_createEntry($source_obj->getId(), "paste",
2822  array(ilLMObject::_lookupTitle($parent), $parent),
2823  $this->getType().":pg");
2824  ilHistory::_createEntry($parent, "paste_page",
2825  array(ilLMObject::_lookupTitle($source_obj->getId()), $source_obj->getId()),
2826  $this->getType().":st");
2827  }
2828 
2829  }
2830  }
2831  }
2832 
2833  // handle chapters
2834  if ($source_obj->getType() == "st")
2835  {
2836 //echo "2";
2837  $source_node = $lmtree->getNodeData($source_id);
2838  $subnodes = $lmtree->getSubtree($source_node);
2839 
2840  // check, if target is within subtree
2841  foreach ($subnodes as $subnode)
2842  {
2843  if($subnode["obj_id"] == $target_id)
2844  {
2845  return;
2846  }
2847  }
2848 
2849  $target_pos = $target_id;
2850 
2851  if ($first_child) // as first subchapter
2852  {
2853  $target_pos = IL_FIRST_NODE;
2854  $target_parent = $target_id;
2855 
2856  $pg_childs =& $lmtree->getChildsByType($target_parent, "pg");
2857  if (count($pg_childs) != 0)
2858  {
2859  $target_pos = $pg_childs[count($pg_childs) - 1]["obj_id"];
2860  }
2861  }
2862  else if ($as_subitem) // as last subchapter
2863  {
2864  $target_parent = $target_id;
2865  $target_pos = IL_FIRST_NODE;
2866  $childs =& $lmtree->getChilds($target_parent);
2867  if (count($childs) != 0)
2868  {
2869  $target_pos = $childs[count($childs) - 1]["obj_id"];
2870  }
2871  }
2872 
2873  // insert into
2874 /*
2875  if ($position == "into")
2876  {
2877  $target_parent = $target_id;
2878  $target_pos = IL_FIRST_NODE;
2879 
2880  // if target_pos is still first node we must skip all pages
2881  if ($target_pos == IL_FIRST_NODE)
2882  {
2883  $pg_childs =& $lmtree->getChildsByType($target_parent, "pg");
2884  if (count($pg_childs) != 0)
2885  {
2886  $target_pos = $pg_childs[count($pg_childs) - 1]["obj_id"];
2887  }
2888  }
2889  }
2890 */
2891 
2892 
2893  // delete source tree
2894  if ($movecopy == "move")
2895  {
2896  $lmtree->deleteTree($source_node);
2897  }
2898  else
2899  {
2900  // copy chapter (incl. subcontents)
2901  $new_chapter =& $source_obj->copy($lmtree, $target_parent, $target_pos);
2902  }
2903 
2904  if (!$lmtree->isInTree($source_id))
2905  {
2906  $lmtree->insertNode($source_id, $target_parent, $target_pos);
2907 
2908  // insert moved tree
2909  if ($movecopy == "move")
2910  {
2911  foreach ($subnodes as $node)
2912  {
2913  if($node["obj_id"] != $source_id)
2914  {
2915  $lmtree->insertNode($node["obj_id"], $node["parent"]);
2916  }
2917  }
2918  }
2919  }
2920 
2921  // check the tree
2922  $this->checkTree();
2923  }
2924 
2925  $this->checkTree();
2926  }
2927 
2931  function validatePages()
2932  {
2933  include_once "./Modules/LearningModule/classes/class.ilLMPageObject.php";
2934  include_once "./Modules/LearningModule/classes/class.ilLMPage.php";
2935 
2936  $mess = "";
2937 
2938  $pages = ilLMPageObject::getPageList($this->getId());
2939  foreach ($pages as $page)
2940  {
2941  if (ilLMPage::_exists($this->getType(), $page["obj_id"]))
2942  {
2943  $cpage = new ilLMPage($page["obj_id"]);
2944  $cpage->buildDom();
2945  $error = @$cpage->validateDom();
2946 
2947  if ($error != "")
2948  {
2949  $this->lng->loadLanguageModule("content");
2950  ilUtil::sendInfo($this->lng->txt("cont_import_validation_errors"));
2951  $title = ilLMObject::_lookupTitle($page["obj_id"]);
2952  $page_obj = new ilLMPageObject($this, $page["obj_id"]);
2953  $mess.= $this->lng->txt("obj_pg").": ".$title;
2954  $mess.= '<div class="small">';
2955  foreach ($error as $e)
2956  {
2957  $err_mess = implode($e, " - ");
2958  if (!is_int(strpos($err_mess, ":0:")))
2959  {
2960  $mess.= htmlentities($err_mess)."<br />";
2961  }
2962  }
2963  $mess.= '</div>';
2964  $mess.= "<br />";
2965  }
2966  }
2967  }
2968 
2969  return $mess;
2970  }
2971 
2978  function importFromZipFile($a_tmp_file, $a_filename, $a_validate = true,
2979  $a_import_into_help_module = 0)
2980  {
2981  global $lng;
2982 
2983  // create import directory
2984  $this->createImportDirectory();
2985 
2986  // copy uploaded file to import directory
2987  $file = pathinfo($a_filename);
2988  $full_path = $this->getImportDirectory()."/".$a_filename;
2989 
2990  ilUtil::moveUploadedFile($a_tmp_file,
2991  $a_filename, $full_path);
2992 
2993  // unzip file
2994  ilUtil::unzip($full_path);
2995 
2996  $subdir = basename($file["basename"],".".$file["extension"]);
2997 
2998  $mess = $this->importFromDirectory(
2999  $this->getImportDirectory()."/".$subdir, $a_validate);
3000 
3001  // this should only be true for help modules
3002  if ($a_import_into_help_module > 0)
3003  {
3004  // search the zip file
3005  $dir = $this->getImportDirectory()."/".$subdir;
3006  $files = ilUtil::getDir($dir);
3007  foreach ($files as $file)
3008  {
3009  if (is_int(strpos($file["entry"], "__help_")) &&
3010  is_int(strpos($file["entry"], ".zip")))
3011  {
3012  include_once("./Services/Export/classes/class.ilImport.php");
3013  $imp = new ilImport();
3014  $imp->getMapping()->addMapping('Services/Help', 'help_module', 0, $a_import_into_help_module);
3015  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
3016  $chaps = ilLMObject::getObjectList($this->getId(), "st");
3017  foreach ($chaps as $chap)
3018  {
3019  $chap_arr = explode("_", $chap["import_id"]);
3020  $imp->getMapping()->addMapping('Services/Help', 'help_chap',
3021  $chap_arr[count($chap_arr) - 1], $chap["obj_id"]);
3022  }
3023  $imp->importEntity($dir."/".$file["entry"], $file["entry"],
3024  "help", "Services/Help", true);
3025  }
3026  }
3027  }
3028 
3029  // delete import directory
3031 
3032  return $mess;
3033  }
3034 
3035 
3042  function importFromDirectory($a_directory, $a_validate = true)
3043  {
3044  global $lng;
3045 
3046  // determine filename of xml file
3047  $subdir = basename($a_directory);
3048  $xml_file = $a_directory."/".$subdir.".xml";
3049 
3050  // check directory exists within zip file
3051  if (!is_dir($a_directory))
3052  {
3053  return sprintf($lng->txt("cont_no_subdir_in_zip"), $subdir);
3054  }
3055 
3056  // check whether xml file exists within zip file
3057  if (!is_file($xml_file))
3058  {
3059  return sprintf($lng->txt("cont_zip_file_invalid"), $subdir."/".$subdir.".xml");
3060  }
3061 
3062  // import questions
3063  $qti_file = $a_directory."/qti.xml";
3064  $qtis = array();
3065  if (is_file($qti_file))
3066  {
3067  include_once "./Services/QTI/classes/class.ilQTIParser.php";
3068  include_once("./Modules/Test/classes/class.ilObjTest.php");
3069  $qtiParser = new ilQTIParser ($qti_file,
3070  IL_MO_VERIFY_QTI, 0, "");
3071  $result = $qtiParser->startParsing ();
3072  $founditems = & $qtiParser->getFoundItems ();
3073  $testObj = new ilObjTest(0, true);
3074  if (count($founditems) > 0)
3075  {
3076  $qtiParser = new ilQTIParser($qti_file, IL_MO_PARSE_QTI, 0, "");
3077  $qtiParser->setTestObject($testObj);
3078  $result = $qtiParser->startParsing();
3079  $qtis = array_merge($qtis, $qtiParser->getImportMapping());
3080  }
3081  }
3082 
3083  include_once ("./Modules/LearningModule/classes/class.ilContObjParser.php");
3084  $contParser = new ilContObjParser($this, $xml_file, $subdir, $qmapping);
3085  $contParser->setQuestionMapping($qtis);
3086  $contParser->startParsing();
3087  ilObject::_writeImportId($this->getId(), $this->getImportId());
3088  $this->MDUpdateListener('General');
3089 
3090  // import style
3091  $style_file = $a_directory."/style.xml";
3092  $style_zip_file = $a_directory."/style.zip";
3093  if (is_file($style_zip_file)) // try to import style.zip first
3094  {
3095  require_once("./Services/Style/classes/class.ilObjStyleSheet.php");
3096  $style = new ilObjStyleSheet();
3097  $style->import($style_zip_file);
3098  $this->writeStyleSheetId($style->getId());
3099  }
3100  else if (is_file($style_file)) // try to import style.xml
3101  {
3102  require_once("./Services/Style/classes/class.ilObjStyleSheet.php");
3103  $style = new ilObjStyleSheet();
3104  $style->import($style_file);
3105  $this->writeStyleSheetId($style->getId());
3106  }
3107 
3108 // // validate
3109  if ($a_validate)
3110  {
3111  $mess = $this->validatePages();
3112  }
3113 
3114  if ($mess == "")
3115  {
3116  // handle internal links to this learning module
3117  include_once("./Modules/LearningModule/classes/class.ilLMPage.php");
3119  $this->getType(), $this->getRefId());
3120  }
3121 
3122  return $mess;
3123  }
3124 
3133  public function cloneObject($a_target_id,$a_copy_id = 0)
3134  {
3135  global $ilDB, $ilUser, $ilias;
3136 
3137  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
3138  $this->cloneMetaData($new_obj);
3139  //$new_obj->createProperties();
3140 
3141  $new_obj->setTitle($this->getTitle());
3142  $new_obj->setDescription($this->getDescription());
3143  $new_obj->setLayoutPerPage($this->getLayoutPerPage());
3144  $new_obj->setLayout($this->getLayout());
3145  $new_obj->setTOCMode($this->getTOCMode());
3146  $new_obj->setActiveLMMenu($this->isActiveLMMenu());
3147  $new_obj->setActiveTOC($this->isActiveTOC());
3148  $new_obj->setActiveNumbering($this->isActiveNumbering());
3149  $new_obj->setActivePrintView($this->isActivePrintView());
3150  $new_obj->setActivePreventGlossaryAppendix($this->isActivePreventGlossaryAppendix());
3151  $new_obj->setActiveDownloads($this->isActiveDownloads());
3152  $new_obj->setActiveDownloadsPublic($this->isActiveDownloadsPublic());
3153  $new_obj->setPublicNotes($this->publicNotes());
3154  $new_obj->setCleanFrames($this->cleanFrames());
3155  $new_obj->setHistoryUserComments($this->isActiveHistoryUserComments());
3156  $new_obj->setPublicAccessMode($this->getPublicAccessMode());
3157  $new_obj->setPageHeader($this->getPageHeader());
3158  $new_obj->setRating($this->hasRating());
3159  $new_obj->setRatingPages($this->hasRatingPages());
3160 
3161  $new_obj->update();
3162 
3163  $new_obj->createLMTree();
3164 
3165  // copy style
3166  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
3167  $style_id = $this->getStyleSheetId();
3168  if ($style_id > 0 &&
3170  {
3171  $style_obj = $ilias->obj_factory->getInstanceByObjId($style_id);
3172  $new_id = $style_obj->ilClone();
3173  $new_obj->setStyleSheetId($new_id);
3174  $new_obj->update();
3175  }
3176 
3177  // copy content
3178  $this->copyAllPagesAndChapters($new_obj);
3179 
3180  // Copy learning progress settings
3181  include_once('Services/Tracking/classes/class.ilLPObjSettings.php');
3182  $obj_settings = new ilLPObjSettings($this->getId());
3183  $obj_settings->cloneSettings($new_obj->getId());
3184  unset($obj_settings);
3185 
3186  // copy (page) multilang settings
3187  include_once("./Services/Object/classes/class.ilObjectTranslation.php");
3188  $ot = ilObjectTranslation::getInstance($this->getId());
3189  $ot->copy($new_obj->getId());
3190 
3191  return $new_obj;
3192  }
3193 
3199  function copyAllPagesAndChapters($a_target_obj)
3200  {
3201  $parent_id = $a_target_obj->lm_tree->readRootId();
3202 
3203  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
3204  include_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
3205 
3206  // get all chapters of root lm
3207  $chapters = $this->lm_tree->getChildsByType($this->lm_tree->readRootId(), "st");
3208  $copied_nodes = array();
3209  //$time = time();
3210  foreach ($chapters as $chap)
3211  {
3212  $cid = ilLMObject::pasteTree($a_target_obj, $chap["child"], $parent_id,
3213  IL_LAST_NODE, $time, $copied_nodes, true, $this);
3214  $target = $cid;
3215  }
3216 
3217  // copy free pages
3218  $pages = ilLMPageObject::getPageList($this->getId());
3219  foreach ($pages as $p)
3220  {
3221  if (!$this->lm_tree->isInTree($p["obj_id"]))
3222  {
3223  $item = new ilLMPageObject($this, $p["obj_id"]);
3224  $target_item = $item->copy($a_target_obj);
3225  $copied_nodes[$item->getId()] = $target_item->getId();
3226  }
3227  }
3228 
3229  ilLMObject::updateInternalLinks($copied_nodes);
3230 
3231  $a_target_obj->checkTree();
3232 
3233  }
3234 
3235 
3242  function lookupAutoGlossaries($a_lm_id)
3243  {
3244  global $ilDB;
3245 
3246  // read auto glossaries
3247  $set = $ilDB->query("SELECT * FROM lm_glossaries ".
3248  " WHERE lm_id = ".$ilDB->quote($a_lm_id, "integer")
3249  );
3250  $glos = array();
3251  while ($rec = $ilDB->fetchAssoc($set))
3252  {
3253  $glos[] = $rec["glo_id"];
3254  }
3255  return $glos;
3256  }
3257 
3264  function autoLinkGlossaryTerms($a_glo_id)
3265  {
3266  // get terms
3267  include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
3268  $terms = ilGlossaryTerm::getTermList($a_glo_id);
3269 
3270  // each get page: get content
3271  include_once("./Modules/LearningModule/classes/class.ilLMPage.php");
3272  $pages = ilLMPage::getAllPages($this->getType(), $this->getId());
3273 
3274  // determine terms that occur in the page
3275  $found_pages = array();
3276  foreach ($pages as $p)
3277  {
3278  $pg = new ilLMPage($p["id"]);
3279  $c = $pg->getXMLContent();
3280  foreach ($terms as $t)
3281  {
3282  if (is_int(stripos($c, $t["term"])))
3283  {
3284  $found_pages[$p["id"]]["terms"][] = $t;
3285  if (!is_object($found_pages[$p["id"]]["page"]))
3286  {
3287  $found_pages[$p["id"]]["page"] = $pg;
3288  }
3289  }
3290  }
3291  reset($terms);
3292  }
3293 
3294  // ilPCParagraph autoLinkGlossariesPage with page and terms
3295  include_once("./Services/COPage/classes/class.ilPCParagraph.php");
3296  foreach ($found_pages as $id => $fp)
3297  {
3298  ilPCParagraph::autoLinkGlossariesPage($fp["page"], $fp["terms"]);
3299  }
3300 
3301 
3302  }
3303 
3304 
3308 
3314  static function isOnlineHelpModule($a_id, $a_as_obj_id = false)
3315  {
3316  if (!$a_as_obj_id && $a_id > 0 && $a_id == OH_REF_ID)
3317  {
3318  return true;
3319  }
3320  if ($a_as_obj_id && $a_id > 0 && $a_id == ilObject::_lookupObjId(OH_REF_ID))
3321  {
3322  return true;
3323  }
3324  return false;
3325  }
3326 
3327  public function setRating($a_value)
3328  {
3329  $this->rating = (bool)$a_value;
3330  }
3331 
3332  public function hasRating()
3333  {
3334  return $this->rating;
3335  }
3336 
3337  public function setRatingPages($a_value)
3338  {
3339  $this->rating_pages = (bool)$a_value;
3340  }
3341 
3342  public function hasRatingPages()
3343  {
3344  return $this->rating_pages;
3345  }
3346 
3347 
3348 }
3349 ?>
getHideHeaderFooterPrint()
Get hide header footer in print mode.
static makeDirParents($a_dir)
Create a new directory and all parent directories.
static getTermList($a_glo_id, $searchterm="", $a_first_letter="", $a_def="", $a_tax_node=0, $a_add_amet_fields=false, $a_amet_filter="")
Get all terms for given set of glossary ids.
static tf2yn($a_tf)
convert true/false to "y"/"n"
ILIAS Setting Class.
static _lookupDisableDefaultFeedback($a_id)
Lookup disable default feedback.
print $file
exportHTMLGlossaryTerms(&$a_lm_gui, $a_target_dir)
export glossary terms
static updateInternalLinks($a_copied_nodes, $a_parent_type="lm")
Update internal links, after multiple pages have been copied.
Content Object Parser.
read()
read data of content object
Class NestedSetXML functions for storing XML-Data into nested-set-database-strcture.
getStyleSheetId()
get ID of assigned style sheet object
_checkPreconditionsOfPage($cont_ref_id, $cont_obj_id, $page_id)
checks wether the preconditions of a page are fulfilled or not
getExportDirectory($a_type="xml")
get export directory of lm
create($a_no_meta_data=false)
create content object
setPublicExportFile($a_type, $a_file)
specify public export file for type
static _getQuestionIdsForPage($a_parent_type, $a_page_id, $a_lang="-")
Get all questions of a page.
static _getConditionsOfTarget($a_target_ref_id, $a_target_obj_id, $a_target_type="")
get all conditions of target object
setTOCMode($a_toc_mode="chapters")
set toc mode
$result
exportFO(&$a_xml_writer, $a_target_dir)
export object to fo
getDefinitionList($a_term_id)
static
validatePages()
Validate all pages.
exportFileItems($a_target_dir, &$expLog)
export files of file itmes
setImportDirectory($a_import_dir)
Set import directory for further use in ilContObjParser.
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
exportHTML($a_target_dir, $log, $a_zip_file=true, $a_export_format="html", $a_lang="")
export html package
_lookupStyleSheetId($a_cont_obj_id)
lookup style sheet ID
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data
copyPlayerFilesToTargetDirectory($a_target_dir)
Copy css files to target dir.
exportXMLPageObjects(&$a_xml_writer, $a_inst, &$expLog)
export page objects to xml (see ilias_co.dtd)
static getStyleSheetLocation($mode="output", $a_css_name="", $a_css_location="")
get full style sheet file name (path inclusive) of current user
$_GET["client_id"]
getInstance(&$a_content_obj, $a_id=0, $a_halt=true)
getLayout()
get default page layout of content object (see directory layouts/)
getLocalMediaElementCssPath()
Get local path of jQuery file.
updateMetaData()
update meta data entry
Class ilObject Basic functions for all objects.
createLMTree()
create content object tree (that stores structure object hierarchie)
executeDragDrop($source_id, $target_id, $first_child, $as_subitem=false, $movecopy="move")
Execute Drag Drop Action.
getImportDirectory()
get import directory of lm
getExportFiles()
get export files
ilObjContentObject($a_id=0, $a_call_by_reference=true)
Constructor public.
setLayoutPerPage($a_val)
Set layout per page.
createMetaData()
create meta data entry
static pasteTree($a_target_lm, $a_item_id, $a_parent_id, $a_target, $a_insert_time, &$a_copied_nodes, $a_as_copy=false, $a_source_lm=null)
Paste item (tree) from clipboard to current lm.
static unzip($a_file, $overwrite=false, $a_flat=false)
unzip file
getOfflineFiles($dir)
get offline files
static getAllPages($a_parent_type, $a_parent_id, $a_lang="-")
Get all pages for parent object.
_lookupContObjIdByStyleId($a_style_id)
lookup style sheet ID
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
Import class.
$target_id
Definition: goto.php:88
getPublicExportFile($a_type)
get public export file
Export class for content objects.
exportHTMLFile($a_target_dir, $a_file_id)
export file object
setDisableDefaultFeedback($a_val)
Set disable default feedback for questions.
setStyleSheetId($a_style_id)
set ID of assigned style sheet object
getAvailableLayouts()
get all available lm layouts
getAutoGlossaries()
Get auto glossaries.
removeAutoGlossary($a_glo_id)
Remove auto glossary.
hasSuccessorPage($a_cont_obj_id, $a_page_id)
checks if page has a successor page
static _lookupTitle($a_obj_id)
Lookup title.
_getFilesOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_usage_lang="-")
get all files of an object
getSyntaxStylePath()
get syntax style path
writeStyleSheetId($a_style_id)
write ID of assigned style sheet object to db
getPublicAccessMode()
get public access mode ("complete" | "selected")
getLocalMediaElementJsPath()
Get local path of jQuery file.
ilObject($a_id=0, $a_reference=true)
Constructor public.
static getLocalJsTreeJsPath()
Get local path of jsTree js.
exportXMLMetaData(&$a_xml_writer)
export content objects meta data to xml (see ilias_co.dtd)
exportFOStructureObjects(&$a_xml_writer)
export structure objects to fo
$mobs
_checkAllConditionsOfTarget($a_target_ref_id, $a_target_id, $a_target_type="", $a_usr_id=0)
checks wether all conditions of a target object are fulfilled
getUsagesOfPage($a_usage_id, $a_usage_type, $a_hist_nr=0, $a_all_hist_nrs=false, $a_lang="-")
Get page content usages for page.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
Class ilLMPresentationGUI.
exportXMLMediaObjects(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
export media objects to xml (see ilias_co.dtd)
cloneObject($a_target_id, $a_copy_id=0)
Clone learning module.
static autoLinkGlossariesPage($a_page, $a_terms)
Auto link glossary of whole page.
setTitle($a_title)
set title of content object
createExportDirectory($a_type="xml")
creates data directory for export files (data_dir/lm_data/lm_<id>/export, depending on data directory...
addFirstChapterAndPage()
Add first chapter and page.
getLayoutPerPage()
Get layout per page.
_createEntry($a_obj_id, $a_action, $a_info_params="", $a_obj_type="", $a_user_comment="", $a_update_last=false)
Creates a new history entry for an object.
getLocaljQueryPath()
Get local path of jQuery file.
copyAllPagesAndChapters($a_target_obj)
Copy all pages and chapters.
update()
update complete object (meta data and properties)
static createHTMLExportDirs($a_target_dir)
Create html export directories.
_moveLMStyles($a_from_style, $a_to_style)
move learning modules from one style to another
_getMissingPreconditionsOfPage($cont_ref_id, $cont_obj_id, $page_id)
gets all missing preconditions of page
_writeImportId($a_obj_id, $a_import_id)
write import id to db (static)
Class ilLMPageObject.
importFromDirectory($a_directory, $a_validate=true)
Import lm from directory.
getPageHeader()
get page header mode (IL_CHAPTER_TITLE | IL_PAGE_TITLE | IL_NO_HEADER)
static _exists($a_parent_type, $a_id, $a_lang="")
Checks whether page exists.
getId()
get object id public
$GLOBALS['ct_recipient']
exportHTMLMOB($a_target_dir, &$a_lm_gui, $a_mob_id, $a_frame, &$a_linked_mobs)
export media object to html
const IL_MO_PARSE_QTI
updateAutoGlossaries()
Update auto glossaries.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
exportXMLStructureObjects(&$a_xml_writer, $a_inst, &$expLog)
export structure objects to xml (see ilias_co.dtd)
exportXMLProperties($a_xml_writer, &$expLog)
export properties of content object
readProperties()
read content object properties
static _lookupObjId($a_id)
static getLocalExplorerJsPath()
Get local path of explorer js.
getLocalMaphilightPath()
Get local path of maphilight file.
const IL_FIRST_NODE
Definition: class.ilTree.php:5
getTOCMode()
get toc mode ("chapters" | "pages")
special template class to simplify handling of ITX/PEAR
updateProperties()
Update content object properties.
setPageHeader($a_pg_header=IL_CHAPTER_TITLE)
set page header mode
Class ilObjFile.
static putInTree($a_obj, $a_parent_id="", $a_target_node_id="")
put this object into content object tree
& getLMTree()
get content object tree
_deleteStyleAssignments($a_style_id)
delete all style references to style
_getNrLMsIndividualStyles()
get number of learning modules with individual styles
static getFlashVideoPlayerDirectory()
Get flash video player directory.
putInTree($a_parent)
put content object in main tree
getPageList($lm_id)
static
redirection script todo: (a better solution should control the processing via a xml file) ...
cloneMetaData($target_obj)
Copy meta data.
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
Class ilObjMediaObject.
exportSCORM($a_target_dir, $log)
export scorm package
static getExportId($a_lm_id, $a_lmobj_id, $a_type="pg")
Get export ID.
static _handleImportRepositoryLinks($a_rep_import_id, $a_rep_type, $a_rep_ref_id)
Change targest of repository links.
getDisableDefaultFeedback()
Get disable default feedback for questions.
getDataDirectory()
get data directory
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
getType()
get object type public
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
static _lookupType($a_id, $a_reference=false)
lookup object type
createImportDirectory()
creates data directory for import files (data_dir/lm_data/lm_<id>/import, depending on data directory...
static getSupplyingExportFiles($a_target_dir=".")
Get supplying export files.
_getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static isOnlineHelpModule($a_id, $a_as_obj_id=false)
Is module an online module.
_lookupOnline($a_id)
check wether content object is online
static getLocalPath($a_name="")
Get local path of a YUI js file.
const IL_LAST_NODE
Definition: class.ilTree.php:4
_lookupStandard($a_id)
Lookup standard flag.
exportPageHTML(&$a_lm_gui, $a_target_dir, $a_lm_page_id, $a_frame="", $a_exp_id_map=array())
export page html
_checkCondition($a_id, $a_usr_id=0)
checks wether a single condition is fulfilled every trigger object type must implement a static metho...
Class ilStructreObject.
global $ilUser
Definition: imgupload.php:15
static getDataDir()
get data directory (outside webspace)
$lm_set
initDefaultRoles()
init default roles settings OBSOLETE.
importFromZipFile($a_tmp_file, $a_filename, $a_validate=true, $a_import_into_help_module=0)
Import lm from zip file.
setLayout($a_layout)
set default page layout
$path
Definition: index.php:22
autoLinkGlossaryTerms($a_glo_id)
Auto link glossary terms.
static getInstance($a_obj_id)
Get instance.
setHideHeaderFooterPrint($a_val)
Set hide header footer in print mode.
getObjectList($lm_id, $type="")
static
global $ilBench
Definition: ilias.php:18
Class ilObjStyleSheet.
_getMissingPreconditionsTopChapter($cont_obj_ref_id, $cont_obj_id, $page_id)
get top chapter of page for that any precondition is missing
getTitle()
get title of content object
notify($a_event, $a_ref_id, $a_parent_non_rbac_id, $a_node_id, $a_params=0)
notifys an object about an event occured Based on the event happend, each object may decide how it re...
getRefId()
get reference id public
deleteMetaData()
delete meta data entry
const IL_CHAPTER_TITLE
getLocaljQueryUIPath()
Get local path of jQuery UI file.
Class ilObjContentObject.
const IL_MO_VERIFY_QTI
createRoleFolder()
creates a local role folder
static yn2tf($a_yn)
convert "y"/"n" to true/false
setAutoGlossaries($a_val)
Set auto glossaries.
if(strpos($jquery_path, './')===0) else if(strpos($jquery_path, '.')===0) $mathJaxSetting
Definition: latex.php:34
_getNrLMsNoStyle()
get number of learning modules assigned no style
setDescription($a_description)
set description of content object
exportXML(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
export object to xml (see ilias_co.dtd)
_deleteAllObjectData(&$a_cobj)
delete all objects of content object (digi book / learning module)
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
getDescription()
get description of content object
static getWebspaceDir($mode="filesystem")
get webspace directory
createProperties()
create new properties record
Content Object (ILIAS native learning module / digilib book) Manifest export class.
_getNrOfAssignedLMs($a_style_id)
gets the number of learning modules assigned to a content style
Extension of ilPageObject for learning modules.
exportHTMLPages(&$a_lm_gui, $a_target_dir, $a_lang="")
export all pages of learning module to html file
lookupAutoGlossaries($a_lm_id)
Lookup auto glossaries.
MDUpdateListener($a_element)
Meta data update listener.