ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjContentObject.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once "classes/class.ilObject.php";
5 require_once "Services/MetaData/classes/class.ilMDLanguageItem.php";
6 require_once("classes/class.ilNestedSetXML.php");
7 
22 {
23  var $lm_tree;
25  var $layout;
26  var $style_id;
28  var $online;
29 
36  function ilObjContentObject($a_id = 0,$a_call_by_reference = true)
37  {
38  // this also calls read() method! (if $a_id is set)
39  $this->ilObject($a_id,$a_call_by_reference);
40 
41  $this->mob_ids = array();
42  $this->file_ids = array();
43  }
44 
48  function create($a_upload = false)
49  {
50  global $ilUser;
51 
53 
54  // meta data will be created by
55  // import parser
56  if (!$a_upload)
57  {
58  $this->createMetaData();
59  }
60 
61  $this->createProperties();
62  if (!$a_upload)
63  {
64  if (is_object($ilUser))
65  {
66  //$this->meta_data->setLanguage($ilUser->getLanguage());
67  }
68  }
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  parent::read();
114 # echo "Content<br>\n";
115 
116  $this->lm_tree = new ilTree($this->getId());
117  $this->lm_tree->setTableNames('lm_tree','lm_data');
118  $this->lm_tree->setTreeTablePK("lm_id");
119 
120  $this->readProperties();
121  //parent::read();
122  }
123 
129  function getTitle()
130  {
131  return parent::getTitle();
132  }
133 
137  function setTitle($a_title)
138  {
139  parent::setTitle($a_title);
140 // $this->meta_data->setTitle($a_title);
141  }
142 
148  function getDescription()
149  {
150  return parent::getDescription();
151  }
152 
156  function setDescription($a_description)
157  {
158  parent::setDescription($a_description);
159 // $this->meta_data->setDescription($a_description);
160  }
161 
162 
163  function getImportId()
164  {
165  return $this->import_id;
166  }
167 
168  function setImportId($a_id)
169  {
170  $this->import_id = $a_id;
171  }
172 
178  function setLayoutPerPage($a_val)
179  {
180  $this->layout_per_page = $a_val;
181  }
182 
188  function getLayoutPerPage()
189  {
190  return $this->layout_per_page;
191  }
192 
193  function &getTree()
194  {
195  return $this->lm_tree;
196  }
197 
201  function update()
202  {
203  $this->updateMetaData();
204  parent::update();
205  $this->updateProperties();
206  }
207 
208 
212  function import()
213  {
214  // nothing to do. just display the dialogue in Out
215  return;
216  }
217 
218 
223  function putInTree($a_parent)
224  {
225  global $tree;
226 
227  // put this object in tree under $a_parent
228  parent::putInTree($a_parent);
229 
230  // make new tree for this object
231  //$tree->addTree($this->getId());
232  }
233 
234 
240  function createLMTree()
241  {
242  $this->lm_tree =& new ilTree($this->getId());
243  $this->lm_tree->setTreeTablePK("lm_id");
244  $this->lm_tree->setTableNames('lm_tree','lm_data');
245  $this->lm_tree->addTree($this->getId(), 1);
246  }
247 
248 
252  function &getLMTree()
253  {
254  return $this->lm_tree;
255  }
256 
257 
264  {
265  $lm_data_dir = ilUtil::getDataDir()."/lm_data";
266  if(!is_writable($lm_data_dir))
267  {
268  $this->ilias->raiseError("Content object Data Directory (".$lm_data_dir
269  .") not writeable.",$this->ilias->error_obj->FATAL);
270  }
271 
272  // create learning module directory (data_dir/lm_data/lm_<id>)
273  $lm_dir = $lm_data_dir."/lm_".$this->getId();
274  ilUtil::makeDir($lm_dir);
275  if(!@is_dir($lm_dir))
276  {
277  $this->ilias->raiseError("Creation of Learning Module Directory failed.",$this->ilias->error_obj->FATAL);
278  }
279 
280  // create import subdirectory (data_dir/lm_data/lm_<id>/import)
281  $import_dir = $lm_dir."/import";
282  ilUtil::makeDir($import_dir);
283  if(!@is_dir($import_dir))
284  {
285  $this->ilias->raiseError("Creation of Import Directory failed.",$this->ilias->error_obj->FATAL);
286  }
287  }
288 
292  function getDataDirectory()
293  {
294  return ilUtil::getDataDir()."/lm_data".
295  "/lm_".$this->getId();
296  }
297 
302  {
303  $import_dir = ilUtil::getDataDir()."/lm_data".
304  "/lm_".$this->getId()."/import";
305  if(@is_dir($import_dir))
306  {
307  return $import_dir;
308  }
309  else
310  {
311  return false;
312  }
313  }
314 
315 
321  function createExportDirectory($a_type = "xml")
322  {
323  $lm_data_dir = ilUtil::getDataDir()."/lm_data";
324  if(!is_writable($lm_data_dir))
325  {
326  $this->ilias->raiseError("Content object Data Directory (".$lm_data_dir
327  .") not writeable.",$this->ilias->error_obj->FATAL);
328  }
329  // create learning module directory (data_dir/lm_data/lm_<id>)
330  $lm_dir = $lm_data_dir."/lm_".$this->getId();
331  ilUtil::makeDir($lm_dir);
332  if(!@is_dir($lm_dir))
333  {
334  $this->ilias->raiseError("Creation of Learning Module Directory failed.",$this->ilias->error_obj->FATAL);
335  }
336  // create Export subdirectory (data_dir/lm_data/lm_<id>/Export)
337  switch ($a_type)
338  {
339  // html
340  case "html":
341  $export_dir = $lm_dir."/export_html";
342  break;
343 
344  // scorm
345  case "scorm":
346  $export_dir = $lm_dir."/export_scorm";
347  break;
348 
349  default: // = xml
350  $export_dir = $lm_dir."/export";
351  break;
352  }
353  ilUtil::makeDir($export_dir);
354 
355  if(!@is_dir($export_dir))
356  {
357  $this->ilias->raiseError("Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
358  }
359  }
360 
364  function getExportDirectory($a_type = "xml")
365  {
366  switch ($a_type)
367  {
368  case "html":
369  $export_dir = ilUtil::getDataDir()."/lm_data"."/lm_".$this->getId()."/export_html";
370  break;
371 
372  case "scorm":
373  $export_dir = ilUtil::getDataDir()."/lm_data"."/lm_".$this->getId()."/export_scorm";
374  break;
375 
376  default: // = xml
377  $export_dir = ilUtil::getDataDir()."/lm_data"."/lm_".$this->getId()."/export";
378  break;
379  }
380  return $export_dir;
381  }
382 
383 
394  function delete()
395  {
396  global $ilDB;
397 
398  global $ilBench;
399 
400  // always call parent delete function first!!
401  if (!parent::delete())
402  {
403  return false;
404  }
405 
406  // delete lm object data
407  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
409 
410  // delete meta data of content object
411  $this->deleteMetaData();
412 
413  // delete bibitem data
414  $nested = new ilNestedSetXML();
415  $nested->init($this->getId(), "bib");
416  $nested->deleteAllDBData();
417 
418 
419  // delete learning module tree
420  $this->lm_tree->removeTree($this->lm_tree->getTreeId());
421 
422  // delete data directory
424 
425  // delete content object record
426  $q = "DELETE FROM content_object WHERE id = ".
427  $ilDB->quote($this->getId(), "integer");
428  $ilDB->manipulate($q);
429 
430  // delete lm menu entries
431  $q = "DELETE FROM lm_menu WHERE lm_id = ".
432  $ilDB->quote($this->getId(), "integer");
433  $ilDB->manipulate($q);
434 
435  return true;
436  }
437 
438 
444  function getLayout()
445  {
446  return $this->layout;
447  }
448 
454  function setLayout($a_layout)
455  {
456  $this->layout = $a_layout;
457  }
458 
462  function getStyleSheetId()
463  {
464  return $this->style_id;
465  }
466 
470  function setStyleSheetId($a_style_id)
471  {
472  $this->style_id = $a_style_id;
473  }
474 
478  function writeStyleSheetId($a_style_id)
479  {
480  global $ilDB;
481 
482  $q = "UPDATE content_object SET ".
483  " stylesheet = ".$ilDB->quote((int) $a_style_id, "integer").
484  " WHERE id = ".$ilDB->quote($this->getId(), "integer");
485  $ilDB->manipulate($q);
486 
487  $this->style_id = $a_style_id;
488  }
489 
493  function _moveLMStyles($a_from_style, $a_to_style)
494  {
495  global $ilDB, $ilias;
496 
497  if ($a_from_style < 0) // change / delete all individual styles
498  {
499  $q = "SELECT stylesheet FROM content_object, style_data ".
500  " WHERE content_object.stylesheet = style_data.id ".
501  " AND style_data.standard = ".$ilDB->quote(0, "integer").
502  " AND content_object.stylesheet > ".$ilDB->quote(0, "integer");
503  $style_set = $ilDB->query($q);
504  while($style_rec = $ilDB->fetchAssoc($style_set))
505  {
506  // assign learning modules to new style
507  $q = "UPDATE content_object SET ".
508  " stylesheet = ".$ilDB->quote((int) $a_to_style, "integer").
509  " WHERE stylesheet = ".$ilDB->quote($style_rec["stylesheet"], "integer");
510  $ilDB->manipulate($q);
511 
512  // delete style
513  $style_obj =& $ilias->obj_factory->getInstanceByObjId($style_rec["stylesheet"]);
514  $style_obj->delete();
515  }
516  }
517  else
518  {
519  $q = "UPDATE content_object SET ".
520  " stylesheet = ".$ilDB->quote((int) $a_to_style, "integer").
521  " WHERE stylesheet = ".$ilDB->quote($a_from_style, "integer");
522  $ilDB->manipulate($q);
523  }
524  }
525 
529  function _lookupStyleSheetId($a_cont_obj_id)
530  {
531  global $ilDB;
532 
533  $q = "SELECT stylesheet FROM content_object ".
534  " WHERE id = ".$ilDB->quote($a_cont_obj_id, "integer");
535  $res = $ilDB->query($q);
536  $sheet = $ilDB->fetchAssoc($res);
537 
538  return $sheet["stylesheet"];
539  }
540 
544  function _lookupContObjIdByStyleId($a_style_id)
545  {
546  global $ilDB;
547 
548  $q = "SELECT id FROM content_object ".
549  " WHERE stylesheet = ".$ilDB->quote($a_style_id, "integer");
550  $res = $ilDB->query($q);
551  $obj_ids = array();
552  while($cont = $ilDB->fetchAssoc($res))
553  {
554  $obj_ids[] = $cont["id"];
555  }
556  return $obj_ids;
557  }
558 
564  function _getNrOfAssignedLMs($a_style_id)
565  {
566  global $ilDB;
567 
568  $q = "SELECT count(*) as cnt FROM content_object ".
569  " WHERE stylesheet = ".$ilDB->quote($a_style_id, "integer");
570  $cset = $ilDB->query($q);
571  $crow = $ilDB->fetchAssoc($cset);
572 
573  return (int) $crow["cnt"];
574  }
575 
576 
581  {
582  global $ilDB;
583 
584  // joining with style table (not perfectly nice)
585  $q = "SELECT count(*) as cnt FROM content_object, style_data ".
586  " WHERE stylesheet = style_data.id ".
587  " AND standard = ".$ilDB->quote(0, "integer");
588  $cset = $ilDB->query($q);
589  $crow = $ilDB->fetchAssoc($cset);
590 
591  return (int) $crow["cnt"];
592  }
593 
597  function _getNrLMsNoStyle()
598  {
599  global $ilDB;
600 
601  $q = "SELECT count(*) as cnt FROM content_object ".
602  " WHERE stylesheet = ".$ilDB->quote(0, "integer");
603  $cset = $ilDB->query($q);
604  $crow = $ilDB->fetchAssoc($cset);
605 
606  return (int) $crow["cnt"];
607  }
608 
614  function _deleteStyleAssignments($a_style_id)
615  {
616  global $ilDB;
617 
618  $q = "UPDATE content_object SET ".
619  " stylesheet = ".$ilDB->quote(0, "integer").
620  " WHERE stylesheet = ".$ilDB->quote((int) $this->getId($a_style_id), "integer");
621 
622  $ilDB->manipulate($q);
623  }
624 
628  function getPageHeader()
629  {
630  return $this->pg_header;
631  }
632 
638  function setPageHeader($a_pg_header = IL_CHAPTER_TITLE)
639  {
640  $this->pg_header = $a_pg_header;
641  }
642 
646  function getTOCMode()
647  {
648  return $this->toc_mode;
649  }
650 
655  {
656  return $this->public_access_mode;
657  }
658 
664  function setTOCMode($a_toc_mode = "chapters")
665  {
666  $this->toc_mode = $a_toc_mode;
667  }
668 
669  function setOnline($a_online)
670  {
671  $this->online = $a_online;
672  }
673 
674  function getOnline()
675  {
676  return $this->online;
677  }
678 
679  function setActiveLMMenu($a_act_lm_menu)
680  {
681  $this->lm_menu_active = $a_act_lm_menu;
682  }
683 
684  function isActiveLMMenu()
685  {
686  return $this->lm_menu_active;
687  }
688 
689  function setActiveTOC($a_toc)
690  {
691  $this->toc_active = $a_toc;
692  }
693 
694  function isActiveTOC()
695  {
696  return $this->toc_active;
697  }
698 
699  function setActiveNumbering($a_num)
700  {
701  $this->numbering = $a_num;
702  }
703 
704  function isActiveNumbering()
705  {
706  return $this->numbering;
707  }
708 
709  function setActivePrintView($a_print)
710  {
711  $this->print_view_active = $a_print;
712  }
713 
714  function isActivePrintView()
715  {
716  return $this->print_view_active;
717  }
718 
720  {
721  $this->prevent_glossary_appendix_active = $a_print;
722  }
723 
725  {
726  return $this->prevent_glossary_appendix_active;
727  }
728 
729  function setActiveDownloads($a_down)
730  {
731  $this->downloads_active = $a_down;
732  }
733 
734  function isActiveDownloads()
735  {
736  return $this->downloads_active;
737  }
738 
739  function setActiveDownloadsPublic($a_down)
740  {
741  $this->downloads_public_active = $a_down;
742  }
743 
745  {
746  return $this->downloads_public_active;
747  }
748 
749  function setPublicNotes($a_pub_notes)
750  {
751  $this->pub_notes = $a_pub_notes;
752  }
753 
754  function publicNotes()
755  {
756  return $this->pub_notes;
757  }
758 
759  function setCleanFrames($a_clean)
760  {
761  $this->clean_frames = $a_clean;
762  }
763 
764  function cleanFrames()
765  {
766  return $this->clean_frames;
767  }
768 
769  function setHistoryUserComments($a_comm)
770  {
771  $this->user_comments = $a_comm;
772  }
773 
774  function setPublicAccessMode($a_mode)
775  {
776  $this->public_access_mode = $a_mode;
777  }
778 
780  {
781  return $this->user_comments;
782  }
783 
784  function setHeaderPage($a_pg)
785  {
786  $this->header_page = $a_pg;
787  }
788 
789  function getHeaderPage()
790  {
791  return $this->header_page;
792  }
793 
794  function setFooterPage($a_pg)
795  {
796  $this->footer_page = $a_pg;
797  }
798 
799  function getFooterPage()
800  {
801  return $this->footer_page;
802  }
803 
807  function readProperties()
808  {
809  global $ilDB;
810 
811  $q = "SELECT * FROM content_object WHERE id = ".
812  $ilDB->quote($this->getId(), "integer");
813  $lm_set = $ilDB->query($q);
814  $lm_rec = $ilDB->fetchAssoc($lm_set);
815  $this->setLayout($lm_rec["default_layout"]);
816  $this->setStyleSheetId((int) $lm_rec["stylesheet"]);
817  $this->setPageHeader($lm_rec["page_header"]);
818  $this->setTOCMode($lm_rec["toc_mode"]);
819  $this->setOnline(ilUtil::yn2tf($lm_rec["is_online"]));
820  $this->setActiveTOC(ilUtil::yn2tf($lm_rec["toc_active"]));
821  $this->setActiveNumbering(ilUtil::yn2tf($lm_rec["numbering"]));
822  $this->setActivePrintView(ilUtil::yn2tf($lm_rec["print_view_active"]));
823  $this->setActivePreventGlossaryAppendix(ilUtil::yn2tf($lm_rec["no_glo_appendix"]));
824  $this->setActiveDownloads(ilUtil::yn2tf($lm_rec["downloads_active"]));
825  $this->setActiveDownloadsPublic(ilUtil::yn2tf($lm_rec["downloads_public_active"]));
826  $this->setActiveLMMenu(ilUtil::yn2tf($lm_rec["lm_menu_active"]));
827  $this->setCleanFrames(ilUtil::yn2tf($lm_rec["clean_frames"]));
828  $this->setPublicNotes(ilUtil::yn2tf($lm_rec["pub_notes"]));
829  $this->setHeaderPage((int) $lm_rec["header_page"]);
830  $this->setFooterPage((int) $lm_rec["footer_page"]);
831  $this->setHistoryUserComments(ilUtil::yn2tf($lm_rec["hist_user_comments"]));
832  $this->setPublicAccessMode($lm_rec["public_access_mode"]);
833  $this->setPublicExportFile("xml", $lm_rec["public_xml_file"]);
834  $this->setPublicExportFile("html", $lm_rec["public_html_file"]);
835  $this->setLayoutPerPage($lm_rec["layout_per_page"]);
836  }
837 
841  function updateProperties()
842  {
843  global $ilDB;
844 
845  // force clean_frames to be set, if layout per page is activated
846  if ($this->getLayoutPerPage())
847  {
848  $this->setCleanFrames(true);
849  }
850 
851  $q = "UPDATE content_object SET ".
852  " default_layout = ".$ilDB->quote($this->getLayout(), "text").", ".
853  " stylesheet = ".$ilDB->quote($this->getStyleSheetId(), "integer").",".
854  " page_header = ".$ilDB->quote($this->getPageHeader(), "text").",".
855  " toc_mode = ".$ilDB->quote($this->getTOCMode(), "text").",".
856  " is_online = ".$ilDB->quote(ilUtil::tf2yn($this->getOnline()), "text").",".
857  " toc_active = ".$ilDB->quote(ilUtil::tf2yn($this->isActiveTOC()), "text").",".
858  " numbering = ".$ilDB->quote(ilUtil::tf2yn($this->isActiveNumbering()), "text").",".
859  " print_view_active = ".$ilDB->quote(ilUtil::tf2yn($this->isActivePrintView()), "text").",".
860  " no_glo_appendix = ".$ilDB->quote(ilUtil::tf2yn($this->isActivePreventGlossaryAppendix()), "text").",".
861  " downloads_active = ".$ilDB->quote(ilUtil::tf2yn($this->isActiveDownloads()), "text").",".
862  " downloads_public_active = ".$ilDB->quote(ilUtil::tf2yn($this->isActiveDownloadsPublic()), "text").",".
863  " clean_frames = ".$ilDB->quote(ilUtil::tf2yn($this->cleanFrames()), "text").",".
864  " pub_notes = ".$ilDB->quote(ilUtil::tf2yn($this->publicNotes()), "text").",".
865  " hist_user_comments = ".$ilDB->quote(ilUtil::tf2yn($this->isActiveHistoryUserComments()), "text").",".
866  " public_access_mode = ".$ilDB->quote($this->getPublicAccessMode(), "text").",".
867  " public_xml_file = ".$ilDB->quote($this->getPublicExportFile("xml"), "text").",".
868  " public_html_file = ".$ilDB->quote($this->getPublicExportFile("html"), "text").",".
869  " header_page = ".$ilDB->quote($this->getHeaderPage(), "integer").",".
870  " footer_page = ".$ilDB->quote($this->getFooterPage(), "integer").",".
871  " lm_menu_active = ".$ilDB->quote(ilUtil::tf2yn($this->isActiveLMMenu()), "text").", ".
872  " layout_per_page = ".$ilDB->quote($this->getLayoutPerPage(), "integer")." ".
873  " WHERE id = ".$ilDB->quote($this->getId(), "integer");
874  $ilDB->manipulate($q);
875  }
876 
880  function createProperties()
881  {
882  global $ilDB;
883 
884  $q = "INSERT INTO content_object (id) VALUES (".$ilDB->quote($this->getId(), "integer").")";
885  $ilDB->manipulate($q);
886  $this->readProperties(); // to get db default values
887  }
888 
892  function _lookupOnline($a_id)
893  {
894  global $ilDB;
895 
896 //echo "class ilObjContentObject::_lookupOnline($a_id) called. Use Access class instead.";
897 
898  $q = "SELECT is_online FROM content_object WHERE id = ".$ilDB->quote($a_id, "integer");
899  $lm_set = $ilDB->query($q);
900  $lm_rec = $ilDB->fetchAssoc($lm_set);
901 
902  return ilUtil::yn2tf($lm_rec["is_online"]);
903  }
904 
911  {
912  // read sdir, copy files and copy directories recursively
913  $dir = opendir("./Modules/LearningModule/layouts/lm");
914 
915  $layouts = array();
916 
917  while($file = readdir($dir))
918  {
919  if ($file != "." && $file != ".." && $file != "CVS" && $file != ".svn")
920  {
921  // directories
922  if (@is_dir("./Modules/LearningModule/layouts/lm/".$file))
923  {
924  $layouts[$file] = $file;
925  }
926  }
927  }
928  asort($layouts);
929  return $layouts;
930  }
931 
935  function _checkPreconditionsOfPage($cont_ref_id,$cont_obj_id, $page_id)
936  {
937  global $ilUser,$ilErr;
938 
939  $lm_tree = new ilTree($cont_obj_id);
940  $lm_tree->setTableNames('lm_tree','lm_data');
941  $lm_tree->setTreeTablePK("lm_id");
942 
943  if ($lm_tree->isInTree($page_id))
944  {
945  $path = $lm_tree->getPathFull($page_id, $lm_tree->readRootId());
946  foreach ($path as $node)
947  {
948  if ($node["type"] == "st")
949  {
950  if (!ilConditionHandler::_checkAllConditionsOfTarget($cont_ref_id,$node["child"], "st"))
951  {
952  return false;
953  }
954  }
955  }
956  }
957 
958  return true;
959  }
960 
964  function _getMissingPreconditionsOfPage($cont_ref_id,$cont_obj_id, $page_id)
965  {
966  $lm_tree = new ilTree($cont_obj_id);
967  $lm_tree->setTableNames('lm_tree','lm_data');
968  $lm_tree->setTreeTablePK("lm_id");
969 
970  $conds = array();
971  if ($lm_tree->isInTree($page_id))
972  {
973  // get full path of page
974  $path = $lm_tree->getPathFull($page_id, $lm_tree->readRootId());
975  foreach ($path as $node)
976  {
977  if ($node["type"] == "st")
978  {
979  // get all preconditions of upper chapters
980  $tconds = ilConditionHandler::_getConditionsOfTarget($cont_ref_id,$node["child"], "st");
981  foreach ($tconds as $tcond)
982  {
983  // store all missing preconditions
984  if (!ilConditionHandler::_checkCondition($tcond["id"]))
985  {
986  $conds[] = $tcond;
987  }
988  }
989  }
990  }
991  }
992 
993  return $conds;
994  }
995 
999  function _getMissingPreconditionsTopChapter($cont_obj_ref_id,$cont_obj_id, $page_id)
1000  {
1001  $lm_tree = new ilTree($cont_obj_id);
1002  $lm_tree->setTableNames('lm_tree','lm_data');
1003  $lm_tree->setTreeTablePK("lm_id");
1004 
1005  $conds = array();
1006  if ($lm_tree->isInTree($page_id))
1007  {
1008  // get full path of page
1009  $path = $lm_tree->getPathFull($page_id, $lm_tree->readRootId());
1010  foreach ($path as $node)
1011  {
1012  if ($node["type"] == "st")
1013  {
1014  // get all preconditions of upper chapters
1015  $tconds = ilConditionHandler::_getConditionsOfTarget($cont_obj_ref_id,$node["child"], "st");
1016  foreach ($tconds as $tcond)
1017  {
1018  // look for missing precondition
1019  if (!ilConditionHandler::_checkCondition($tcond["id"]))
1020  {
1021  return $node["child"];
1022  }
1023  }
1024  }
1025  }
1026  }
1027 
1028  return "";
1029  }
1030 
1041  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
1042  {
1043  global $tree;
1044 
1045  switch ($a_event)
1046  {
1047  case "link":
1048 
1049  //var_dump("<pre>",$a_params,"</pre>");
1050  //echo "Content Object ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
1051  //exit;
1052  break;
1053 
1054  case "cut":
1055 
1056  //echo "Content Object ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
1057  //exit;
1058  break;
1059 
1060  case "copy":
1061 
1062  //var_dump("<pre>",$a_params,"</pre>");
1063  //echo "Content Object ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
1064  //exit;
1065  break;
1066 
1067  case "paste":
1068 
1069  //echo "Content Object ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
1070  //exit;
1071  break;
1072 
1073  case "new":
1074 
1075  //echo "Content Object ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
1076  //exit;
1077  break;
1078  }
1079 
1080  // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
1081  if ($a_node_id==$_GET["ref_id"])
1082  {
1083  $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
1084  $parent_type = $parent_obj->getType();
1085  if($parent_type == $this->getType())
1086  {
1087  $a_node_id = (int) $tree->getParentId($a_node_id);
1088  }
1089  }
1090 
1091  parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
1092  }
1093 
1094 
1098  function hasSuccessorPage($a_cont_obj_id, $a_page_id)
1099  {
1100  $tree = new ilTree($a_cont_obj_id);
1101  $tree->setTableNames('lm_tree','lm_data');
1102  $tree->setTreeTablePK("lm_id");
1103  if ($tree->isInTree($a_page_id))
1104  {
1105  $succ = $tree->fetchSuccessorNode($a_page_id, "pg");
1106  if ($succ > 0)
1107  {
1108  return true;
1109  }
1110  }
1111  return false;
1112  }
1113 
1114 
1115  function checkTree()
1116  {
1117  $tree = new ilTree($this->getId());
1118  $tree->setTableNames('lm_tree','lm_data');
1119  $tree->setTreeTablePK("lm_id");
1120  $tree->checkTree();
1121  $tree->checkTreeChilds();
1122 //echo "checked";
1123  }
1124 
1128  function fixTree()
1129  {
1130  global $ilDB;
1131 
1132  $tree =& $this->getLMTree();
1133 
1134  // delete subtrees that have no lm_data records
1135  $nodes = $tree->getSubtree($tree->getNodeData($tree->getRootId()));
1136  foreach ($nodes as $node)
1137  {
1138  $q = "SELECT * FROM lm_data WHERE obj_id = ".
1139  $ilDB->quote($node["child"], "integer");
1140  $obj_set = $ilDB->query($q);
1141  $obj_rec = $ilDB->fetchAssoc($obj_set);
1142  if (!$obj_rec)
1143  {
1144  $node_data = $tree->getNodeData($node["child"]);
1145  $tree->deleteTree($node_data);
1146  }
1147  }
1148 
1149  // delete subtrees that have pages as parent
1150  $nodes = $tree->getSubtree($tree->getNodeData($tree->getRootId()));
1151  foreach ($nodes as $node)
1152  {
1153  $q = "SELECT * FROM lm_data WHERE obj_id = ".
1154  $ilDB->quote($node["parent"], "integer");
1155  $obj_set = $ilDB->query($q);
1156  $obj_rec = $ilDB->fetchAssoc($obj_set);
1157  if ($obj_rec["type"] == "pg")
1158  {
1159  $node_data = $tree->getNodeData($node["child"]);
1160  if ($tree->isInTree($node["child"]))
1161  {
1162  $tree->deleteTree($node_data);
1163  }
1164  }
1165  }
1166 
1167  }
1168 
1169 
1176  function exportXML(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
1177  {
1178  global $ilBench;
1179 
1180  $attrs = array();
1181  switch($this->getType())
1182  {
1183  case "lm":
1184  $attrs["Type"] = "LearningModule";
1185  break;
1186 
1187  case "dbk":
1188  $attrs["Type"] = "LibObject";
1189  break;
1190  }
1191  $a_xml_writer->xmlStartTag("ContentObject", $attrs);
1192 
1193  // MetaData
1194  $this->exportXMLMetaData($a_xml_writer);
1195 
1196  // StructureObjects
1197 //echo "ContObj:".$a_inst.":<br>";
1198  $expLog->write(date("[y-m-d H:i:s] ")."Start Export Structure Objects");
1199  $ilBench->start("ContentObjectExport", "exportStructureObjects");
1200  $this->exportXMLStructureObjects($a_xml_writer, $a_inst, $expLog);
1201  $ilBench->stop("ContentObjectExport", "exportStructureObjects");
1202  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Structure Objects");
1203 
1204  // PageObjects
1205  $expLog->write(date("[y-m-d H:i:s] ")."Start Export Page Objects");
1206  $ilBench->start("ContentObjectExport", "exportPageObjects");
1207  $this->exportXMLPageObjects($a_xml_writer, $a_inst, $expLog);
1208  $ilBench->stop("ContentObjectExport", "exportPageObjects");
1209  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Page Objects");
1210 
1211  // MediaObjects
1212  $expLog->write(date("[y-m-d H:i:s] ")."Start Export Media Objects");
1213  $ilBench->start("ContentObjectExport", "exportMediaObjects");
1214  $this->exportXMLMediaObjects($a_xml_writer, $a_inst, $a_target_dir, $expLog);
1215  $ilBench->stop("ContentObjectExport", "exportMediaObjects");
1216  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Media Objects");
1217 
1218  // FileItems
1219  $expLog->write(date("[y-m-d H:i:s] ")."Start Export File Items");
1220  $ilBench->start("ContentObjectExport", "exportFileItems");
1221  $this->exportFileItems($a_target_dir, $expLog);
1222  $ilBench->stop("ContentObjectExport", "exportFileItems");
1223  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export File Items");
1224 
1225  // To do: implement version selection/detection
1226  // Properties
1227  $expLog->write(date("[y-m-d H:i:s] ")."Start Export Properties");
1228  $this->exportXMLProperties($a_xml_writer, $expLog);
1229  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Properties");
1230 
1231  // Glossary
1232  // not implemented
1233 
1234  // Bibliography
1235  // not implemented
1236 
1237  // Layout
1238  // not implemented
1239 
1240  $a_xml_writer->xmlEndTag("ContentObject");
1241  }
1242 
1249  function exportXMLMetaData(&$a_xml_writer)
1250  {
1251  include_once("Services/MetaData/classes/class.ilMD2XML.php");
1252  $md2xml = new ilMD2XML($this->getId(), 0, $this->getType());
1253  $md2xml->setExportMode(true);
1254  $md2xml->startExport();
1255  $a_xml_writer->appendXML($md2xml->getXML());
1256  }
1257 
1264  function exportXMLStructureObjects(&$a_xml_writer, $a_inst, &$expLog)
1265  {
1266  include_once './Modules/LearningModule/classes/class.ilStructureObject.php';
1267 
1268  $childs = $this->lm_tree->getChilds($this->lm_tree->getRootId());
1269  foreach ($childs as $child)
1270  {
1271  if($child["type"] != "st")
1272  {
1273  continue;
1274  }
1275 
1276  $structure_obj = new ilStructureObject($this, $child["obj_id"]);
1277  $structure_obj->exportXML($a_xml_writer, $a_inst, $expLog);
1278  unset($structure_obj);
1279  }
1280  }
1281 
1282 
1289  function exportXMLPageObjects(&$a_xml_writer, $a_inst, &$expLog)
1290  {
1291  global $ilBench;
1292 
1293  include_once "./Modules/LearningModule/classes/class.ilLMPageObject.php";
1294 
1295  $pages = ilLMPageObject::getPageList($this->getId());
1296  foreach ($pages as $page)
1297  {
1298  if (ilPageObject::_exists($this->getType(), $page["obj_id"]))
1299  {
1300  $ilBench->start("ContentObjectExport", "exportPageObject");
1301  $expLog->write(date("[y-m-d H:i:s] ")."Page Object ".$page["obj_id"]);
1302 
1303  // export xml to writer object
1304  $ilBench->start("ContentObjectExport", "exportPageObject_getLMPageObject");
1305  $page_obj = new ilLMPageObject($this, $page["obj_id"]);
1306  $ilBench->stop("ContentObjectExport", "exportPageObject_getLMPageObject");
1307  $ilBench->start("ContentObjectExport", "exportPageObject_XML");
1308  $page_obj->exportXML($a_xml_writer, "normal", $a_inst);
1309  $ilBench->stop("ContentObjectExport", "exportPageObject_XML");
1310 
1311  // collect media objects
1312  $ilBench->start("ContentObjectExport", "exportPageObject_CollectMedia");
1313  $mob_ids = $page_obj->getMediaObjectIDs();
1314  foreach($mob_ids as $mob_id)
1315  {
1316  $this->mob_ids[$mob_id] = $mob_id;
1317  }
1318  $ilBench->stop("ContentObjectExport", "exportPageObject_CollectMedia");
1319 
1320  // collect all file items
1321  $ilBench->start("ContentObjectExport", "exportPageObject_CollectFileItems");
1322  $file_ids = $page_obj->getFileItemIds();
1323  foreach($file_ids as $file_id)
1324  {
1325  $this->file_ids[$file_id] = $file_id;
1326  }
1327  $ilBench->stop("ContentObjectExport", "exportPageObject_CollectFileItems");
1328 
1329  unset($page_obj);
1330 
1331  $ilBench->stop("ContentObjectExport", "exportPageObject");
1332  }
1333  }
1334  }
1335 
1342  function exportXMLMediaObjects(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
1343  {
1344  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1345 
1346  $linked_mobs = array();
1347 
1348  // mobs directly embedded into pages
1349  foreach ($this->mob_ids as $mob_id)
1350  {
1351  if ($mob_id > 0 && ilObject::_lookupType($mob_id) == "mob")
1352  {
1353  $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
1354  $media_obj = new ilObjMediaObject($mob_id);
1355  $media_obj->exportXML($a_xml_writer, $a_inst);
1356  $media_obj->exportFiles($a_target_dir);
1357 
1358  $lmobs = $media_obj->getLinkedMediaObjects($this->mob_ids);
1359  $linked_mobs = array_merge($linked_mobs, $lmobs);
1360 
1361  unset($media_obj);
1362  }
1363  }
1364 
1365  // linked mobs (in map areas)
1366  foreach ($linked_mobs as $mob_id)
1367  {
1368  if ($mob_id > 0)
1369  {
1370  $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
1371  $media_obj = new ilObjMediaObject($mob_id);
1372  $media_obj->exportXML($a_xml_writer, $a_inst);
1373  $media_obj->exportFiles($a_target_dir);
1374  unset($media_obj);
1375  }
1376  }
1377 
1378  }
1379 
1384  function exportFileItems($a_target_dir, &$expLog)
1385  {
1386  include_once("./Modules/File/classes/class.ilObjFile.php");
1387 
1388  foreach ($this->file_ids as $file_id)
1389  {
1390  $expLog->write(date("[y-m-d H:i:s] ")."File Item ".$file_id);
1391  $file_obj = new ilObjFile($file_id, false);
1392  $file_obj->export($a_target_dir);
1393  unset($file_obj);
1394  }
1395  }
1396 
1401  function exportXMLProperties($a_xml_writer, &$expLog)
1402  {
1403  $attrs = array();
1404  $a_xml_writer->xmlStartTag("Properties", $attrs);
1405 
1406  // Layout
1407  $attrs = array("Name" => "Layout", "Value" => $this->getLayout());
1408  $a_xml_writer->xmlElement("Property", $attrs);
1409 
1410  // Page Header
1411  $attrs = array("Name" => "PageHeader", "Value" => $this->getPageHeader());
1412  $a_xml_writer->xmlElement("Property", $attrs);
1413 
1414  // TOC Mode
1415  $attrs = array("Name" => "TOCMode", "Value" => $this->getTOCMode());
1416  $a_xml_writer->xmlElement("Property", $attrs);
1417 
1418  // LM Menu Activation
1419  $attrs = array("Name" => "ActiveLMMenu", "Value" =>
1420  ilUtil::tf2yn($this->isActiveLMMenu()));
1421  $a_xml_writer->xmlElement("Property", $attrs);
1422 
1423  // Numbering Activation
1424  $attrs = array("Name" => "ActiveNumbering", "Value" =>
1425  ilUtil::tf2yn($this->isActiveNumbering()));
1426  $a_xml_writer->xmlElement("Property", $attrs);
1427 
1428  // Table of contents button activation
1429  $attrs = array("Name" => "ActiveTOC", "Value" =>
1430  ilUtil::tf2yn($this->isActiveTOC()));
1431  $a_xml_writer->xmlElement("Property", $attrs);
1432 
1433  // Print view button activation
1434  $attrs = array("Name" => "ActivePrintView", "Value" =>
1435  ilUtil::tf2yn($this->isActivePrintView()));
1436  $a_xml_writer->xmlElement("Property", $attrs);
1437 
1438  // Note that download button is not saved, because
1439  // download files do not exist after import
1440 
1441  // Clean frames
1442  $attrs = array("Name" => "CleanFrames", "Value" =>
1443  ilUtil::tf2yn($this->cleanFrames()));
1444  $a_xml_writer->xmlElement("Property", $attrs);
1445 
1446  // Public notes activation
1447  $attrs = array("Name" => "PublicNotes", "Value" =>
1448  ilUtil::tf2yn($this->publicNotes()));
1449  $a_xml_writer->xmlElement("Property", $attrs);
1450 
1451  // History comments for authors activation
1452  $attrs = array("Name" => "HistoryUserComments", "Value" =>
1454  $a_xml_writer->xmlElement("Property", $attrs);
1455 
1456  // Header Page
1457  if ($this->getHeaderPage() > 0)
1458  {
1459  $attrs = array("Name" => "HeaderPage", "Value" =>
1460  "il_".IL_INST_ID."_pg_".$this->getHeaderPage());
1461  $a_xml_writer->xmlElement("Property", $attrs);
1462  }
1463 
1464  // Footer Page
1465  if ($this->getFooterPage() > 0)
1466  {
1467  $attrs = array("Name" => "FooterPage", "Value" =>
1468  "il_".IL_INST_ID."_pg_".$this->getFooterPage());
1469  $a_xml_writer->xmlElement("Property", $attrs);
1470  }
1471 
1472  $a_xml_writer->xmlEndTag("Properties");
1473  }
1474 
1478  function getExportFiles()
1479  {
1480  $file = array();
1481 
1482  $types = array("xml", "html", "scorm");
1483 
1484  foreach ($types as $type)
1485  {
1486  $dir = $this->getExportDirectory($type);
1487  // quit if import dir not available
1488  if (!@is_dir($dir) or
1489  !is_writeable($dir))
1490  {
1491  continue;
1492  }
1493 
1494  // open directory
1495  $cdir = dir($dir);
1496 
1497  // initialize array
1498 
1499  // get files and save the in the array
1500  while ($entry = $cdir->read())
1501  {
1502  if ($entry != "." and
1503  $entry != ".." and
1504  substr($entry, -4) == ".zip" and
1505  ereg("^[0-9]{10}_{2}[0-9]+_{2}(lm_)*[0-9]+\.zip\$", $entry))
1506  {
1507  $file[$entry.$type] = array("type" => $type, "file" => $entry,
1508  "size" => filesize($dir."/".$entry));
1509  }
1510  }
1511 
1512  // close import directory
1513  $cdir->close();
1514  }
1515 
1516  // sort files
1517  ksort ($file);
1518  reset ($file);
1519  return $file;
1520  }
1521 
1528  function setPublicExportFile($a_type, $a_file)
1529  {
1530  $this->public_export_file[$a_type] = $a_file;
1531  }
1532 
1540  function getPublicExportFile($a_type)
1541  {
1542  return $this->public_export_file[$a_type];
1543  }
1544 
1549  {
1550  // quit if offline dir not available
1551  if (!@is_dir($dir) or
1552  !is_writeable($dir))
1553  {
1554  return array();
1555  }
1556 
1557  // open directory
1558  $dir = dir($dir);
1559 
1560  // initialize array
1561  $file = array();
1562 
1563  // get files and save the in the array
1564  while ($entry = $dir->read())
1565  {
1566  if ($entry != "." and
1567  $entry != ".." and
1568  substr($entry, -4) == ".pdf" and
1569  ereg("^[0-9]{10}_{2}[0-9]+_{2}(lm_)*[0-9]+\.pdf\$", $entry))
1570  {
1571  $file[] = $entry;
1572  }
1573  }
1574 
1575  // close import directory
1576  $dir->close();
1577 
1578  // sort files
1579  sort ($file);
1580  reset ($file);
1581 
1582  return $file;
1583  }
1584 
1588  function exportSCORM($a_target_dir, $log)
1589  {
1590  ilUtil::delDir($a_target_dir);
1591  ilUtil::makeDir($a_target_dir);
1592  //ilUtil::makeDir($a_target_dir."/res");
1593 
1594  // export everything to html
1595  $this->exportHTML($a_target_dir."/res", $log, false, "scorm");
1596 
1597  // build manifest file
1598  include("./Modules/LearningModule/classes/class.ilContObjectManifestBuilder.php");
1599  $man_builder = new ilContObjectManifestBuilder($this);
1600  $man_builder->buildManifest();
1601  $man_builder->dump($a_target_dir);
1602 
1603  // copy scorm 1.2 schema definitions
1604  copy("Modules/LearningModule/scorm_xsd/adlcp_rootv1p2.xsd", $a_target_dir."/adlcp_rootv1p2.xsd");
1605  copy("Modules/LearningModule/scorm_xsd/imscp_rootv1p1p2.xsd", $a_target_dir."/imscp_rootv1p1p2.xsd");
1606  copy("Modules/LearningModule/scorm_xsd/imsmd_rootv1p2p1.xsd", $a_target_dir."/imsmd_rootv1p2p1.xsd");
1607  copy("Modules/LearningModule/scorm_xsd/ims_xml.xsd", $a_target_dir."/ims_xml.xsd");
1608 
1609  // zip it all
1610  $date = time();
1611  $zip_file = $a_target_dir."/".$date."__".IL_INST_ID."__".
1612  $this->getType()."_".$this->getId().".zip";
1613  //echo "zip-".$a_target_dir."-to-".$zip_file;
1614  ilUtil::zip(array($a_target_dir."/res",
1615  $a_target_dir."/imsmanifest.xml",
1616  $a_target_dir."/adlcp_rootv1p2.xsd",
1617  $a_target_dir."/imscp_rootv1p1p2.xsd",
1618  $a_target_dir."/ims_xml.xsd",
1619  $a_target_dir."/imsmd_rootv1p2p1.xsd")
1620  , $zip_file);
1621 
1622  $dest_file = $this->getExportDirectory("scorm")."/".$date."__".IL_INST_ID."__".
1623  $this->getType()."_".$this->getId().".zip";
1624 
1625  rename($zip_file, $dest_file);
1626  ilUtil::delDir($a_target_dir);
1627 
1628  }
1629 
1630 
1634  function exportHTML($a_target_dir, $log, $a_zip_file = true, $a_export_format = "html")
1635  {
1636  global $tpl, $ilBench, $ilLocator, $ilUser;
1637 
1638  // initialize temporary target directory
1639  ilUtil::delDir($a_target_dir);
1640  ilUtil::makeDir($a_target_dir);
1641  $mob_dir = $a_target_dir."/mobs";
1642  ilUtil::makeDir($mob_dir);
1643  $file_dir = $a_target_dir."/files";
1644  ilUtil::makeDir($file_dir);
1645  $teximg_dir = $a_target_dir."/teximg";
1646  ilUtil::makeDir($teximg_dir);
1647  $style_dir = $a_target_dir."/style";
1648  ilUtil::makeDir($style_dir);
1649  $style_img_dir = $a_target_dir."/style/images";
1650  ilUtil::makeDir($style_img_dir);
1651  $content_style_dir = $a_target_dir."/content_style";
1652  ilUtil::makeDir($content_style_dir);
1653  $content_style_img_dir = $a_target_dir."/content_style/images";
1654  ilUtil::makeDir($content_style_img_dir);
1655  $GLOBALS["teximgcnt"] = 0;
1656 
1657  // export system style sheet
1658  $location_stylesheet = ilUtil::getStyleSheetLocation("filesystem");
1659  $style_name = $ilUser->prefs["style"].".css";
1660  copy($location_stylesheet, $style_dir."/".$style_name);
1661  $fh = fopen($location_stylesheet, "r");
1662  $css = fread($fh, filesize($location_stylesheet));
1663  preg_match_all("/url\(([^\)]*)\)/",$css,$files);
1664  foreach (array_unique($files[1]) as $fileref)
1665  {
1666  $fileref = dirname($location_stylesheet)."/".$fileref;
1667  if (is_file($fileref))
1668  {
1669  copy($fileref, $style_img_dir."/".basename($fileref));
1670  }
1671  }
1672  fclose($fh);
1673  $location_stylesheet = ilUtil::getStyleSheetLocation();
1674 
1675  // export content style sheet
1676  $ilBench->start("ExportHTML", "exportContentStyle");
1677  if ($this->getStyleSheetId() < 1)
1678  {
1679  $cont_stylesheet = "./Services/COPage/css/content.css";
1680 
1681  $css = fread(fopen($cont_stylesheet,'r'),filesize($cont_stylesheet));
1682  preg_match_all("/url\(([^\)]*)\)/",$css,$files);
1683  foreach (array_unique($files[1]) as $fileref)
1684  {
1685  if (is_file(str_replace("..", ".", $fileref)))
1686  {
1687  copy(str_replace("..", ".", $fileref), $content_style_img_dir."/".basename($fileref));
1688  }
1689  $css = str_replace($fileref, "images/".basename($fileref),$css);
1690  }
1691  fwrite(fopen($content_style_dir."/content.css",'w'),$css);
1692  }
1693  else
1694  {
1695  $style = new ilObjStyleSheet($this->getStyleSheetId());
1696  $style->writeCSSFile($content_style_dir."/content.css", "images");
1697  $style->copyImagesToDir($content_style_img_dir);
1698  }
1699  $ilBench->stop("ExportHTML", "exportContentStyle");
1700 
1701  // export syntax highlighting style
1702  $syn_stylesheet = ilObjStyleSheet::getSyntaxStylePath();
1703  copy($syn_stylesheet, $a_target_dir."/syntaxhighlight.css");
1704 
1705  // get learning module presentation gui class
1706  include_once("./Modules/LearningModule/classes/class.ilLMPresentationGUI.php");
1707  $_GET["cmd"] = "nop";
1708  $lm_gui =& new ilLMPresentationGUI();
1709  $lm_gui->setOfflineMode(true);
1710  $lm_gui->setOfflineDirectory($a_target_dir);
1711  $lm_gui->setExportFormat($a_export_format);
1712 
1713  // export pages
1714  $ilBench->start("ExportHTML", "exportHTMLPages");
1715  $this->exportHTMLPages($lm_gui, $a_target_dir);
1716  $ilBench->stop("ExportHTML", "exportHTMLPages");
1717 
1718  // export glossary terms
1719  $ilBench->start("ExportHTML", "exportHTMLGlossaryTerms");
1720  $this->exportHTMLGlossaryTerms($lm_gui, $a_target_dir);
1721  $ilBench->stop("ExportHTML", "exportHTMLGlossaryTerms");
1722 
1723  // export all media objects
1724  $ilBench->start("ExportHTML", "exportHTMLMediaObjects");
1725  $linked_mobs = array();
1726  foreach ($this->offline_mobs as $mob)
1727  {
1728  if (ilObject::_exists($mob) && ilObject::_lookupType($mob) == "mob")
1729  {
1730  $this->exportHTMLMOB($a_target_dir, $lm_gui, $mob, "_blank", $linked_mobs);
1731  }
1732  }
1733  $linked_mobs2 = array(); // mobs linked in link areas
1734  foreach ($linked_mobs as $mob)
1735  {
1736  if (ilObject::_exists($mob))
1737  {
1738  $this->exportHTMLMOB($a_target_dir, $lm_gui, $mob, "_blank", $linked_mobs2);
1739  }
1740  }
1741  $_GET["obj_type"] = "MediaObject";
1742  $_GET["obj_id"] = $a_mob_id;
1743  $_GET["cmd"] = "";
1744  $ilBench->stop("ExportHTML", "exportHTMLMediaObjects");
1745 
1746  // export all file objects
1747  $ilBench->start("ExportHTML", "exportHTMLFileObjects");
1748  foreach ($this->offline_files as $file)
1749  {
1750  $this->exportHTMLFile($a_target_dir, $file);
1751  }
1752  $ilBench->stop("ExportHTML", "exportHTMLFileObjects");
1753 
1754  // export table of contents
1755  $ilBench->start("ExportHTML", "exportHTMLTOC");
1756  $ilLocator->clearItems();
1757  if ($this->isActiveTOC())
1758  {
1759  $tpl = new ilTemplate("tpl.main.html", true, true);
1760  //$tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
1761  $content =& $lm_gui->showTableOfContents();
1762  $file = $a_target_dir."/table_of_contents.html";
1763 
1764  // open file
1765  if (!($fp = @fopen($file,"w+")))
1766  {
1767  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
1768  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
1769  }
1770  chmod($file, 0770);
1771  fwrite($fp, $content);
1772  fclose($fp);
1773  }
1774  $ilBench->stop("ExportHTML", "exportHTMLTOC");
1775 
1776  // export images
1777  $ilBench->start("ExportHTML", "exportHTMLImages");
1778  $image_dir = $a_target_dir."/images";
1779  ilUtil::makeDir($image_dir);
1780  ilUtil::makeDir($image_dir."/browser");
1781  copy(ilUtil::getImagePath("enlarge.gif", false, "filesystem"),
1782  $image_dir."/enlarge.gif");
1783  copy(ilUtil::getImagePath("browser/blank.gif", false, "filesystem"),
1784  $image_dir."/browser/plus.gif");
1785  copy(ilUtil::getImagePath("browser/blank.gif", false, "filesystem"),
1786  $image_dir."/browser/minus.gif");
1787  copy(ilUtil::getImagePath("browser/blank.gif", false, "filesystem"),
1788  $image_dir."/browser/blank.gif");
1789  copy(ilUtil::getImagePath("spacer.gif", false, "filesystem"),
1790  $image_dir."/spacer.gif");
1791  copy(ilUtil::getImagePath("icon_st.gif", false, "filesystem"),
1792  $image_dir."/icon_st.gif");
1793  copy(ilUtil::getImagePath("icon_pg.gif", false, "filesystem"),
1794  $image_dir."/icon_pg.gif");
1795  copy(ilUtil::getImagePath("icon_st_s.gif", false, "filesystem"),
1796  $image_dir."/icon_st_s.gif");
1797  copy(ilUtil::getImagePath("icon_pg_s.gif", false, "filesystem"),
1798  $image_dir."/icon_pg_s.gif");
1799  copy(ilUtil::getImagePath("icon_lm.gif", false, "filesystem"),
1800  $image_dir."/icon_lm.gif");
1801  copy(ilUtil::getImagePath("icon_lm_s.gif", false, "filesystem"),
1802  $image_dir."/icon_lm_s.gif");
1803  copy(ilUtil::getImagePath("nav_arr_L.gif", false, "filesystem"),
1804  $image_dir."/nav_arr_L.gif");
1805  copy(ilUtil::getImagePath("nav_arr_R.gif", false, "filesystem"),
1806  $image_dir."/nav_arr_R.gif");
1807  copy(ilUtil::getImagePath("browser/forceexp.gif", false, "filesystem"),
1808  $image_dir."/browser/forceexp.gif");
1809 
1810  copy(ilUtil::getImagePath("download.gif", false, "filesystem"),
1811  $image_dir."/download.gif");
1812  $ilBench->stop("ExportHTML", "exportHTMLImages");
1813 
1814  // export flv/mp3 player
1815  $services_dir = $a_target_dir."/Services";
1816  ilUtil::makeDir($services_dir);
1817  $media_service_dir = $services_dir."/MediaObjects";
1818  ilUtil::makeDir($media_service_dir);
1819  $flv_dir = $media_service_dir."/flash_flv_player";
1820  ilUtil::makeDir($flv_dir);
1821  $mp3_dir = $media_service_dir."/flash_mp3_player";
1822  ilUtil::makeDir($mp3_dir);
1823  copy("./Services/MediaObjects/flash_flv_player/flvplayer.swf",
1824  $flv_dir."/flvplayer.swf");
1825  copy("./Services/MediaObjects/flash_mp3_player/mp3player.swf",
1826  $mp3_dir."/mp3player.swf");
1827 
1828  // accordion stuff
1829  ilUtil::makeDir($a_target_dir.'/js');
1830  ilUtil::makeDir($a_target_dir.'/js/yahoo');
1831  ilUtil::makeDir($a_target_dir.'/css');
1832  include_once("./Services/YUI/classes/class.ilYuiUtil.php");
1833  copy(ilYuiUtil::getLocalPath('yahoo/yahoo-min.js'), $a_target_dir.'/js/yahoo/yahoo-min.js');
1834  copy(ilYuiUtil::getLocalPath('yahoo-dom-event/yahoo-dom-event.js'), $a_target_dir.'/js/yahoo/yahoo-dom-event.js');
1835  copy(ilYuiUtil::getLocalPath('animation/animation-min.js'), $a_target_dir.'/js/yahoo/animation-min.js');
1836  copy('./Services/Accordion/js/accordion.js',$a_target_dir.'/js/accordion.js');
1837  copy('./Services/Accordion/css/accordion.css',$a_target_dir.'/css/accordion.css');
1838 
1839  // template workaround: reset of template
1840  $tpl = new ilTemplate("tpl.main.html", true, true);
1841  $tpl->setVariable("LOCATION_STYLESHEET",$location_stylesheet);
1842  $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
1843 
1844  // zip everything
1845  $ilBench->start("ExportHTML", "zip");
1846  if (true)
1847  {
1848  if ($a_zip_file)
1849  {
1850  // zip it all
1851  $date = time();
1852  $zip_file = $this->getExportDirectory("html")."/".$date."__".IL_INST_ID."__".
1853  $this->getType()."_".$this->getId().".zip";
1854  ilUtil::zip($a_target_dir, $zip_file);
1855  ilUtil::delDir($a_target_dir);
1856  }
1857  }
1858  $ilBench->stop("ExportHTML", "zip");
1859 
1860  }
1861 
1865  function exportHTMLFile($a_target_dir, $a_file_id)
1866  {
1867  $file_dir = $a_target_dir."/files/file_".$a_file_id;
1868  ilUtil::makeDir($file_dir);
1869  include_once("./Modules/File/classes/class.ilObjFile.php");
1870  $file_obj = new ilObjFile($a_file_id, false);
1871  $source_file = $file_obj->getDirectory($file_obj->getVersion())."/".$file_obj->getFileName();
1872  if (!is_file($source_file))
1873  {
1874  $source_file = $file_obj->getDirectory()."/".$file_obj->getFileName();
1875  }
1876  if (is_file($source_file))
1877  {
1878  copy($source_file, $file_dir."/".$file_obj->getFileName());
1879  }
1880  }
1881 
1885  function exportHTMLMOB($a_target_dir, &$a_lm_gui, $a_mob_id, $a_frame, &$a_linked_mobs)
1886  {
1887  global $tpl;
1888 
1889  $mob_dir = $a_target_dir."/mobs";
1890 
1891  $source_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob_id;
1892  if (@is_dir($source_dir))
1893  {
1894  ilUtil::makeDir($mob_dir."/mm_".$a_mob_id);
1895  ilUtil::rCopy($source_dir, $mob_dir."/mm_".$a_mob_id);
1896  }
1897 
1898  $tpl = new ilTemplate("tpl.main.html", true, true);
1899  $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
1900  $_GET["obj_type"] = "MediaObject";
1901  $_GET["mob_id"] = $a_mob_id;
1902  $_GET["frame"] = $a_frame;
1903  $_GET["cmd"] = "";
1904  $content =& $a_lm_gui->media();
1905  $file = $a_target_dir."/media_".$a_mob_id.".html";
1906 
1907  // open file
1908  if (!($fp = @fopen($file,"w+")))
1909  {
1910  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
1911  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
1912  }
1913  chmod($file, 0770);
1914  fwrite($fp, $content);
1915  fclose($fp);
1916 
1917  // fullscreen
1918  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1919  $mob_obj = new ilObjMediaObject($a_mob_id);
1920  if ($mob_obj->hasFullscreenItem())
1921  {
1922  $tpl = new ilTemplate("tpl.main.html", true, true);
1923  $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
1924  $_GET["obj_type"] = "";
1925  $_GET["frame"] = "";
1926  $_GET["mob_id"] = $a_mob_id;
1927  $_GET["cmd"] = "fullscreen";
1928  $content =& $a_lm_gui->fullscreen();
1929  $file = $a_target_dir."/fullscreen_".$a_mob_id.".html";
1930 
1931  // open file
1932  if (!($fp = @fopen($file,"w+")))
1933  {
1934  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
1935  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
1936  }
1937  chmod($file, 0770);
1938  fwrite($fp, $content);
1939  fclose($fp);
1940  }
1941  $linked_mobs = $mob_obj->getLinkedMediaObjects();
1942  $a_linked_mobs = array_merge($a_linked_mobs, $linked_mobs);
1943  }
1944 
1948  function exportHTMLGlossaryTerms(&$a_lm_gui, $a_target_dir)
1949  {
1950  global $ilLocator;
1951 
1952  foreach($this->offline_int_links as $int_link)
1953  {
1954  $ilLocator->clearItems();
1955  if ($int_link["type"] == "git")
1956  {
1957  $tpl = new ilTemplate("tpl.main.html", true, true);
1958  $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
1959 
1960  $_GET["obj_id"] = $int_link["id"];
1961  $_GET["frame"] = "_blank";
1962  $content =& $a_lm_gui->glossary();
1963  $file = $a_target_dir."/term_".$int_link["id"].".html";
1964 
1965  // open file
1966  if (!($fp = @fopen($file,"w+")))
1967  {
1968  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
1969  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
1970  }
1971  chmod($file, 0770);
1972  fwrite($fp, $content);
1973  fclose($fp);
1974 
1975  // store linked/embedded media objects of glosssary term
1976  include_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
1977  $defs = ilGlossaryDefinition::getDefinitionList($int_link["id"]);
1978  foreach($defs as $def)
1979  {
1980  $def_mobs = ilObjMediaObject::_getMobsOfObject("gdf:pg", $def["id"]);
1981  foreach($def_mobs as $def_mob)
1982  {
1983  $this->offline_mobs[$def_mob] = $def_mob;
1984  }
1985 
1986  // get all files of page
1987  $def_files = ilObjFile::_getFilesOfObject("gdf:pg", $page["obj_id"]);
1988  $this->offline_files = array_merge($this->offline_files, $def_files);
1989 
1990  }
1991 
1992  }
1993  }
1994  }
1995 
1999  function exportHTMLPages(&$a_lm_gui, $a_target_dir)
2000  {
2001  global $tpl, $ilBench, $ilLocator;
2002 
2003  $pages = ilLMPageObject::getPageList($this->getId());
2004 
2005  $lm_tree =& $this->getLMTree();
2006  $first_page = $lm_tree->fetchSuccessorNode($lm_tree->getRootId(), "pg");
2007  $this->first_page_id = $first_page["child"];
2008 
2009  // iterate all learning module pages
2010  $mobs = array();
2011  $int_links = array();
2012  $this->offline_files = array();
2013 
2014  include_once("./Services/COPage/classes/class.ilPageContentUsage.php");
2015  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
2016 
2017  foreach ($pages as $page)
2018  {
2019  if (ilPageObject::_exists($this->getType(), $page["obj_id"]))
2020  {
2021  $ilLocator->clearItems();
2022  $ilBench->start("ExportHTML", "exportHTMLPage");
2023  $ilBench->start("ExportHTML", "exportPageHTML");
2024  $this->exportPageHTML($a_lm_gui, $a_target_dir, $page["obj_id"]);
2025  $ilBench->stop("ExportHTML", "exportPageHTML");
2026 
2027  // get all snippets of page
2028  $pcs = ilPageContentUsage::getUsagesOfPage($page["obj_id"], $this->getType().":pg");
2029  foreach ($pcs as $pc)
2030  {
2031  if ($pc["type"] == "incl")
2032  {
2033  $incl_mobs = ilObjMediaObject::_getMobsOfObject("mep:pg", $pc["id"]);
2034  foreach($incl_mobs as $incl_mob)
2035  {
2036  $mobs[$incl_mob] = $incl_mob;
2037  }
2038  }
2039  }
2040 
2041  // get all media objects of page
2042  $pg_mobs = ilObjMediaObject::_getMobsOfObject($this->getType().":pg", $page["obj_id"]);
2043  foreach($pg_mobs as $pg_mob)
2044  {
2045  $mobs[$pg_mob] = $pg_mob;
2046  }
2047 
2048  // get all internal links of page
2049  $pg_links = ilInternalLink::_getTargetsOfSource($this->getType().":pg", $page["obj_id"]);
2050  $int_links = array_merge($int_links, $pg_links);
2051 
2052  // get all files of page
2053  include_once("./Modules/File/classes/class.ilObjFile.php");
2054  $pg_files = ilObjFile::_getFilesOfObject($this->getType().":pg", $page["obj_id"]);
2055  $this->offline_files = array_merge($this->offline_files, $pg_files);
2056 
2057  $ilBench->stop("ExportHTML", "exportHTMLPage");
2058  }
2059  }
2060  $this->offline_mobs = $mobs;
2061  $this->offline_int_links = $int_links;
2062 
2063 
2064  }
2065 
2066 
2067 
2071  function exportPageHTML(&$a_lm_gui, $a_target_dir, $a_lm_page_id, $a_frame = "")
2072  {
2073  global $tpl, $ilBench;
2074 
2075 //echo "<br>B: export Page HTML ($a_lm_page_id)"; flush();
2076  // template workaround: reset of template
2077  $tpl = new ilTemplate("tpl.main.html", true, true);
2078  $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
2079 
2080  $_GET["obj_id"] = $a_lm_page_id;
2081  $_GET["frame"] = $a_frame;
2082 
2083  if ($a_frame == "")
2084  {
2085  if ($nid = ilLMObject::_lookupNID($a_lm_gui->lm->getId(), $a_lm_page_id, "pg"))
2086  {
2087  $file = $a_target_dir."/lm_pg_".$nid.".html";
2088  }
2089  else
2090  {
2091  $file = $a_target_dir."/lm_pg_".$a_lm_page_id.".html";
2092  }
2093  }
2094  else
2095  {
2096  if ($a_frame != "toc")
2097  {
2098  $file = $a_target_dir."/frame_".$a_lm_page_id."_".$a_frame.".html";
2099  }
2100  else
2101  {
2102  $file = $a_target_dir."/frame_".$a_frame.".html";
2103  }
2104  }
2105 
2106  // return if file is already existing
2107  if (@is_file($file))
2108  {
2109  return;
2110  }
2111 
2112  $ilBench->start("ExportHTML", "layout");
2113  $ilBench->start("ExportHTML", "layout_".$a_frame);
2114  $content =& $a_lm_gui->layout("main.xml", false);
2115  $ilBench->stop("ExportHTML", "layout_".$a_frame);
2116  $ilBench->stop("ExportHTML", "layout");
2117 
2118  // open file
2119  if (!($fp = @fopen($file,"w+")))
2120  {
2121  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
2122  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
2123  }
2124 
2125  // set file permissions
2126  chmod($file, 0770);
2127 
2128  // write xml data into the file
2129  fwrite($fp, $content);
2130 
2131  // close file
2132  fclose($fp);
2133 
2134  if ($this->first_page_id == $a_lm_page_id && $a_frame == "")
2135  {
2136  copy($file, $a_target_dir."/index.html");
2137  }
2138 
2139  // write frames of frameset
2140  $ilBench->start("ExportHTML", "getCurrentFrameSet");
2141  $frameset = $a_lm_gui->getCurrentFrameSet();
2142  $ilBench->stop("ExportHTML", "getCurrentFrameSet");
2143 
2144  foreach ($frameset as $frame)
2145  {
2146  $this->exportPageHTML($a_lm_gui, $a_target_dir, $a_lm_page_id, $frame);
2147  }
2148 
2149  }
2150 
2157  function exportFO(&$a_xml_writer, $a_target_dir)
2158  {
2159  global $ilBench;
2160 
2161  // fo:root (start)
2162  $attrs = array();
2163  $attrs["xmlns:fo"] = "http://www.w3.org/1999/XSL/Format";
2164  $a_xml_writer->xmlStartTag("fo:root", $attrs);
2165 
2166  // fo:layout-master-set (start)
2167  $attrs = array();
2168  $a_xml_writer->xmlStartTag("fo:layout-master-set", $attrs);
2169 
2170  // fo:simple-page-master (start)
2171  $attrs = array();
2172  $attrs["master-name"] = "DinA4";
2173  $attrs["page-height"] = "29.7cm";
2174  $attrs["page-width"] = "21cm";
2175  $attrs["margin-top"] = "4cm";
2176  $attrs["margin-bottom"] = "1cm";
2177  $attrs["margin-left"] = "2.8cm";
2178  $attrs["margin-right"] = "7.3cm";
2179  $a_xml_writer->xmlStartTag("fo:simple-page-master", $attrs);
2180 
2181  // fo:region-body (complete)
2182  $attrs = array();
2183  $attrs["margin-top"] = "0cm";
2184  $attrs["margin-bottom"] = "1.25cm";
2185  $a_xml_writer->xmlElement("fo:region-body", $attrs);
2186 
2187  // fo:region-before (complete)
2188  $attrs = array();
2189  $attrs["extent"] = "1cm";
2190  $a_xml_writer->xmlElement("fo:region-before", $attrs);
2191 
2192  // fo:region-after (complete)
2193  $attrs = array();
2194  $attrs["extent"] = "1cm";
2195  $a_xml_writer->xmlElement("fo:region-after", $attrs);
2196 
2197  // fo:simple-page-master (end)
2198  $a_xml_writer->xmlEndTag("fo:simple-page-master");
2199 
2200  // fo:layout-master-set (end)
2201  $a_xml_writer->xmlEndTag("fo:layout-master-set");
2202 
2203  // fo:page-sequence (start)
2204  $attrs = array();
2205  $attrs["master-reference"] = "DinA4";
2206  $a_xml_writer->xmlStartTag("fo:page-sequence", $attrs);
2207 
2208  // fo:flow (start)
2209  $attrs = array();
2210  $attrs["flow-name"] = "xsl-region-body";
2211  $a_xml_writer->xmlStartTag("fo:flow", $attrs);
2212 
2213 
2214  // StructureObjects
2215  //$expLog->write(date("[y-m-d H:i:s] ")."Start Export Structure Objects");
2216  $ilBench->start("ContentObjectExport", "exportFOStructureObjects");
2217  $this->exportFOStructureObjects($a_xml_writer, $expLog);
2218  $ilBench->stop("ContentObjectExport", "exportFOStructureObjects");
2219  //$expLog->write(date("[y-m-d H:i:s] ")."Finished Export Structure Objects");*/
2220 
2221  // fo:flow (end)
2222  $a_xml_writer->xmlEndTag("fo:flow");
2223 
2224  // fo:page-sequence (end)
2225  $a_xml_writer->xmlEndTag("fo:page-sequence");
2226 
2227  // fo:root (end)
2228  $a_xml_writer->xmlEndTag("fo:root");
2229  }
2230 
2237  function exportFOStructureObjects(&$a_xml_writer)
2238  {
2239  $childs = $this->lm_tree->getChilds($this->lm_tree->getRootId());
2240  foreach ($childs as $child)
2241  {
2242  if($child["type"] != "st")
2243  {
2244  continue;
2245  }
2246 
2247  $structure_obj = new ilStructureObject($this, $child["obj_id"]);
2248  $structure_obj->exportFO($a_xml_writer, $expLog);
2249  unset($structure_obj);
2250  }
2251  }
2252 
2253  function getXMLZip()
2254  {
2255  include_once("./Modules/LearningModule/classes/class.ilContObjectExport.php");
2256 
2257  $cont_exp = new ilContObjectExport($this,'xml');
2258 
2259  $export_file = $cont_exp->buildExportFile();
2260  return $export_file;
2261  }
2262 
2271  function executeDragDrop($source_id, $target_id, $first_child, $as_subitem = false, $movecopy = "move")
2272  {
2273  $lmtree = new ilTree($this->getId());
2274  $lmtree->setTableNames('lm_tree','lm_data');
2275  $lmtree->setTreeTablePK("lm_id");
2276 //echo "-".$source_id."-".$target_id."-".$first_child."-".$as_subitem."-";
2277  $source_obj = ilLMObjectFactory::getInstance($this, $source_id, true);
2278  $source_obj->setLMId($this->getId());
2279 
2280  if (!$first_child)
2281  {
2282  $target_obj = ilLMObjectFactory::getInstance($this, $target_id, true);
2283  $target_obj->setLMId($this->getId());
2284  $target_parent = $lmtree->getParentId($target_id);
2285  }
2286 
2287  // handle pages
2288  if ($source_obj->getType() == "pg")
2289  {
2290 //echo "1";
2291  if ($lmtree->isInTree($source_obj->getId()))
2292  {
2293  $node_data = $lmtree->getNodeData($source_obj->getId());
2294 
2295  // cut on move
2296  if ($movecopy == "move")
2297  {
2298  $parent_id = $lmtree->getParentId($source_obj->getId());
2299  $lmtree->deleteTree($node_data);
2300 
2301  // write history entry
2302  require_once("classes/class.ilHistory.php");
2303  ilHistory::_createEntry($source_obj->getId(), "cut",
2304  array(ilLMObject::_lookupTitle($parent_id), $parent_id),
2305  $this->getType().":pg");
2306  ilHistory::_createEntry($parent_id, "cut_page",
2307  array(ilLMObject::_lookupTitle($source_obj->getId()), $source_obj->getId()),
2308  $this->getType().":st");
2309  }
2310  else
2311  {
2312  // copy page
2313  $new_page =& $source_obj->copy();
2314  $source_id = $new_page->getId();
2315  $source_obj =& $new_page;
2316  }
2317 
2318  // paste page
2319  if(!$lmtree->isInTree($source_obj->getId()))
2320  {
2321  if ($first_child) // as first child
2322  {
2323  $target_pos = IL_FIRST_NODE;
2324  $parent = $target_id;
2325  }
2326  else if ($as_subitem) // as last child
2327  {
2328  $parent = $target_id;
2329  $target_pos = IL_FIRST_NODE;
2330  $pg_childs =& $lmtree->getChildsByType($parent, "pg");
2331  if (count($pg_childs) != 0)
2332  {
2333  $target_pos = $pg_childs[count($pg_childs) - 1]["obj_id"];
2334  }
2335  }
2336  else // at position
2337  {
2338  $target_pos = $target_id;
2339  $parent = $target_parent;
2340  }
2341 
2342  // insert page into tree
2343  $lmtree->insertNode($source_obj->getId(),
2344  $parent, $target_pos);
2345 
2346  // write history entry
2347  if ($movecopy == "move")
2348  {
2349  // write history comments
2350  include_once("classes/class.ilHistory.php");
2351  ilHistory::_createEntry($source_obj->getId(), "paste",
2352  array(ilLMObject::_lookupTitle($parent), $parent),
2353  $this->getType().":pg");
2354  ilHistory::_createEntry($parent, "paste_page",
2355  array(ilLMObject::_lookupTitle($source_obj->getId()), $source_obj->getId()),
2356  $this->getType().":st");
2357  }
2358 
2359  }
2360  }
2361  }
2362 
2363  // handle chapters
2364  if ($source_obj->getType() == "st")
2365  {
2366 //echo "2";
2367  $source_node = $lmtree->getNodeData($source_id);
2368  $subnodes = $lmtree->getSubtree($source_node);
2369 
2370  // check, if target is within subtree
2371  foreach ($subnodes as $subnode)
2372  {
2373  if($subnode["obj_id"] == $target_id)
2374  {
2375  return;
2376  }
2377  }
2378 
2379  $target_pos = $target_id;
2380 
2381  if ($first_child) // as first subchapter
2382  {
2383  $target_pos = IL_FIRST_NODE;
2384  $target_parent = $target_id;
2385 
2386  $pg_childs =& $lmtree->getChildsByType($target_parent, "pg");
2387  if (count($pg_childs) != 0)
2388  {
2389  $target_pos = $pg_childs[count($pg_childs) - 1]["obj_id"];
2390  }
2391  }
2392  else if ($as_subitem) // as last subchapter
2393  {
2394  $target_parent = $target_id;
2395  $target_pos = IL_FIRST_NODE;
2396  $childs =& $lmtree->getChilds($target_parent);
2397  if (count($childs) != 0)
2398  {
2399  $target_pos = $childs[count($childs) - 1]["obj_id"];
2400  }
2401  }
2402 
2403  // insert into
2404 /*
2405  if ($position == "into")
2406  {
2407  $target_parent = $target_id;
2408  $target_pos = IL_FIRST_NODE;
2409 
2410  // if target_pos is still first node we must skip all pages
2411  if ($target_pos == IL_FIRST_NODE)
2412  {
2413  $pg_childs =& $lmtree->getChildsByType($target_parent, "pg");
2414  if (count($pg_childs) != 0)
2415  {
2416  $target_pos = $pg_childs[count($pg_childs) - 1]["obj_id"];
2417  }
2418  }
2419  }
2420 */
2421 
2422 
2423  // delete source tree
2424  if ($movecopy == "move")
2425  {
2426  $lmtree->deleteTree($source_node);
2427  }
2428  else
2429  {
2430  // copy chapter (incl. subcontents)
2431  $new_chapter =& $source_obj->copy($lmtree, $target_parent, $target_pos);
2432  }
2433 
2434  if (!$lmtree->isInTree($source_id))
2435  {
2436  $lmtree->insertNode($source_id, $target_parent, $target_pos);
2437 
2438  // insert moved tree
2439  if ($movecopy == "move")
2440  {
2441  foreach ($subnodes as $node)
2442  {
2443  if($node["obj_id"] != $source_id)
2444  {
2445  $lmtree->insertNode($node["obj_id"], $node["parent"]);
2446  }
2447  }
2448  }
2449  }
2450 
2451  // check the tree
2452  $this->checkTree();
2453  }
2454 
2455  $this->checkTree();
2456  }
2457 
2461  function validatePages()
2462  {
2463  include_once "./Modules/LearningModule/classes/class.ilLMPageObject.php";
2464  include_once "./Services/COPage/classes/class.ilPageObject.php";
2465 
2466  $mess = "";
2467 
2468  $pages = ilLMPageObject::getPageList($this->getId());
2469  foreach ($pages as $page)
2470  {
2471  if (ilPageObject::_exists($this->getType(), $page["obj_id"]))
2472  {
2473  $cpage = new ilPageObject($this->getType(), $page["obj_id"]);
2474  $cpage->buildDom();
2475  $error = @$cpage->validateDom();
2476 
2477  if ($error != "")
2478  {
2479  $this->lng->loadLanguageModule("content");
2480  ilUtil::sendInfo($this->lng->txt("cont_import_validation_errors"));
2481  $title = ilLMObject::_lookupTitle($page["obj_id"]);
2482  $page_obj = new ilLMPageObject($this, $page["obj_id"]);
2483  $mess.= $this->lng->txt("obj_pg").": ".$title;
2484  $mess.= '<div class="small">';
2485  foreach ($error as $e)
2486  {
2487  $err_mess = implode($e, " - ");
2488  if (!is_int(strpos($err_mess, ":0:")))
2489  {
2490  $mess.= htmlentities($err_mess)."<br />";
2491  }
2492  }
2493  $mess.= '</div>';
2494  $mess.= "<br />";
2495  }
2496  }
2497  }
2498 
2499  return $mess;
2500  }
2501 
2502 }
2503 ?>