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