00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 require_once "classes/class.ilObject.php";
00026 require_once "classes/class.ilMetaData.php";
00027 require_once("classes/class.ilNestedSetXML.php");
00028
00042 class ilObjContentObject extends ilObject
00043 {
00044 var $lm_tree;
00045 var $meta_data;
00046 var $layout;
00047 var $style_id;
00048 var $pg_header;
00049 var $online;
00050
00057 function ilObjContentObject($a_id = 0,$a_call_by_reference = true)
00058 {
00059
00060 $this->ilObject($a_id,$a_call_by_reference);
00061
00062 $this->mob_ids = array();
00063 $this->file_ids = array();
00064 }
00065
00069 function create($a_upload = false)
00070 {
00071 global $ilUser;
00072
00073 parent::create();
00074
00075
00076
00077 if (!$a_upload)
00078 {
00079 $this->createMetaData();
00080 }
00081
00082 $this->createProperties();
00083 if (!$a_upload)
00084 {
00085 if (is_object($ilUser))
00086 {
00087
00088 }
00089 }
00090 }
00091
00098 function initDefaultRoles()
00099 {
00100 return array();
00101
00102 global $rbacadmin, $rbacreview;
00103
00104
00105 $rfoldObj = $this->createRoleFolder("Local roles","Role Folder of content object ".$this->getId());
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 unset($rfoldObj);
00123
00124
00125 return $roles ? $roles : array();
00126 }
00127
00128
00132 function read()
00133 {
00134 parent::read();
00135 # echo "Content<br>\n";
00136
00137 $this->lm_tree = new ilTree($this->getId());
00138 $this->lm_tree->setTableNames('lm_tree','lm_data');
00139 $this->lm_tree->setTreeTablePK("lm_id");
00140
00141 $this->readProperties();
00142
00143 }
00144
00150 function getTitle()
00151 {
00152 return parent::getTitle();
00153 }
00154
00158 function setTitle($a_title)
00159 {
00160 parent::setTitle($a_title);
00161
00162 }
00163
00169 function getDescription()
00170 {
00171 return parent::getDescription();
00172 }
00173
00177 function setDescription($a_description)
00178 {
00179 parent::setDescription($a_description);
00180
00181 }
00182
00183
00184 function getImportId()
00185 {
00186 return $this->import_id;
00187 }
00188
00189 function setImportId($a_id)
00190 {
00191 $this->import_id = $a_id;
00192 }
00193
00194 function &getTree()
00195 {
00196 return $this->lm_tree;
00197 }
00198
00202 function update()
00203 {
00204 $this->updateMetaData();
00205 parent::update();
00206 $this->updateProperties();
00207 }
00208
00209
00213 function import()
00214 {
00215
00216 return;
00217 }
00218
00219
00224 function putInTree($a_parent)
00225 {
00226 global $tree;
00227
00228
00229 parent::putInTree($a_parent);
00230
00231
00232
00233 }
00234
00235
00241 function createLMTree()
00242 {
00243 $this->lm_tree =& new ilTree($this->getId());
00244 $this->lm_tree->setTreeTablePK("lm_id");
00245 $this->lm_tree->setTableNames('lm_tree','lm_data');
00246 $this->lm_tree->addTree($this->getId(), 1);
00247 }
00248
00249
00253 function &getLMTree()
00254 {
00255 return $this->lm_tree;
00256 }
00257
00258
00264 function createImportDirectory()
00265 {
00266 $lm_data_dir = ilUtil::getDataDir()."/lm_data";
00267 if(!is_writable($lm_data_dir))
00268 {
00269 $this->ilias->raiseError("Content object Data Directory (".$lm_data_dir
00270 .") not writeable.",$this->ilias->error_obj->FATAL);
00271 }
00272
00273
00274 $lm_dir = $lm_data_dir."/lm_".$this->getId();
00275 ilUtil::makeDir($lm_dir);
00276 if(!@is_dir($lm_dir))
00277 {
00278 $this->ilias->raiseError("Creation of Learning Module Directory failed.",$this->ilias->error_obj->FATAL);
00279 }
00280
00281
00282 $import_dir = $lm_dir."/import";
00283 ilUtil::makeDir($import_dir);
00284 if(!@is_dir($import_dir))
00285 {
00286 $this->ilias->raiseError("Creation of Import Directory failed.",$this->ilias->error_obj->FATAL);
00287 }
00288 }
00289
00293 function getDataDirectory()
00294 {
00295 return ilUtil::getDataDir()."/lm_data".
00296 "/lm_".$this->getId();
00297 }
00298
00302 function getImportDirectory()
00303 {
00304 $import_dir = ilUtil::getDataDir()."/lm_data".
00305 "/lm_".$this->getId()."/import";
00306 if(@is_dir($import_dir))
00307 {
00308 return $import_dir;
00309 }
00310 else
00311 {
00312 return false;
00313 }
00314 }
00315
00316
00322 function createExportDirectory($a_type = "xml")
00323 {
00324 $lm_data_dir = ilUtil::getDataDir()."/lm_data";
00325 if(!is_writable($lm_data_dir))
00326 {
00327 $this->ilias->raiseError("Content object Data Directory (".$lm_data_dir
00328 .") not writeable.",$this->ilias->error_obj->FATAL);
00329 }
00330
00331 $lm_dir = $lm_data_dir."/lm_".$this->getId();
00332 ilUtil::makeDir($lm_dir);
00333 if(!@is_dir($lm_dir))
00334 {
00335 $this->ilias->raiseError("Creation of Learning Module Directory failed.",$this->ilias->error_obj->FATAL);
00336 }
00337
00338 switch ($a_type)
00339 {
00340
00341 case "html":
00342 $export_dir = $lm_dir."/export_html";
00343 break;
00344
00345
00346 case "scorm":
00347 $export_dir = $lm_dir."/export_scorm";
00348 break;
00349
00350 default:
00351 $export_dir = $lm_dir."/export";
00352 break;
00353 }
00354 ilUtil::makeDir($export_dir);
00355
00356 if(!@is_dir($export_dir))
00357 {
00358 $this->ilias->raiseError("Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
00359 }
00360 }
00361
00365 function getExportDirectory($a_type = "xml")
00366 {
00367 switch ($a_type)
00368 {
00369 case "html":
00370 $export_dir = ilUtil::getDataDir()."/lm_data"."/lm_".$this->getId()."/export_html";
00371 break;
00372
00373 case "scorm":
00374 $export_dir = ilUtil::getDataDir()."/lm_data"."/lm_".$this->getId()."/export_scorm";
00375 break;
00376
00377 default:
00378 $export_dir = ilUtil::getDataDir()."/lm_data"."/lm_".$this->getId()."/export";
00379 break;
00380 }
00381 return $export_dir;
00382 }
00383
00390 function ilClone($a_parent_ref)
00391 {
00392 global $rbacadmin;
00393
00394
00395 $new_ref_id = parent::ilClone($a_parent_ref);
00396
00397
00398
00399
00400 return $new_ref_id;
00401 }
00402
00413 function delete()
00414 {
00415 global $ilDB;
00416
00417 global $ilBench;
00418
00419
00420 if (!parent::delete())
00421 {
00422 return false;
00423 }
00424
00425
00426 include_once("content/classes/class.ilLMObject.php");
00427 ilLMObject::_deleteAllObjectData($this);
00428
00429
00430 $this->deleteMetaData();
00431
00432
00433 $nested = new ilNestedSetXML();
00434 $nested->init($this->getId(), "bib");
00435 $nested->deleteAllDBData();
00436
00437
00438
00439 $this->lm_tree->removeTree($this->lm_tree->getTreeId());
00440
00441
00442 ilUtil::delDir($this->getDataDirectory());
00443
00444
00445 $q = "DELETE FROM content_object WHERE id = ".$ilDB->quote($this->getId());
00446 $this->ilias->db->query($q);
00447
00448
00449 $q = "DELETE FROM lm_menu WHERE lm_id = ".$ilDB->quote($this->getId());
00450 $this->ilias->db->query($q);
00451
00452 return true;
00453 }
00454
00455
00461 function getLayout()
00462 {
00463 return $this->layout;
00464 }
00465
00471 function setLayout($a_layout)
00472 {
00473 $this->layout = $a_layout;
00474 }
00475
00479 function getStyleSheetId()
00480 {
00481 return $this->style_id;
00482 }
00483
00487 function setStyleSheetId($a_style_id)
00488 {
00489 $this->style_id = $a_style_id;
00490 }
00491
00495 function writeStyleSheetId($a_style_id)
00496 {
00497 global $ilDB;
00498
00499 $q = "UPDATE content_object SET ".
00500 " stylesheet = ".$ilDB->quote($a_style_id).
00501 " WHERE id = '".$this->getId()."'";
00502 $ilDB->query($q);
00503
00504 $this->style_id = $a_style_id;
00505 }
00506
00510 function _moveLMStyles($a_from_style, $a_to_style)
00511 {
00512 global $ilDB, $ilias;
00513
00514 if ($a_from_style < 0)
00515 {
00516 $q = "SELECT stylesheet FROM content_object, style_data ".
00517 " WHERE content_object.stylesheet = style_data.id ".
00518 " AND style_data.standard = 0 ".
00519 " AND content_object.stylesheet > 0";
00520 $style_set = $ilDB->query($q);
00521 while($style_rec = $style_set->fetchRow(DB_FETCHMODE_ASSOC))
00522 {
00523
00524 $q = "UPDATE content_object SET ".
00525 " stylesheet = ".$ilDB->quote($a_to_style).
00526 " WHERE stylesheet = ".$ilDB->quote($style_rec["stylesheet"]);
00527 $ilDB->query($q);
00528
00529
00530 $style_obj =& $ilias->obj_factory->getInstanceByObjId($style_rec["stylesheet"]);
00531 $style_obj->delete();
00532 }
00533 }
00534 else
00535 {
00536 $q = "UPDATE content_object SET ".
00537 " stylesheet = ".$ilDB->quote($a_to_style).
00538 " WHERE stylesheet = ".$ilDB->quote($a_from_style);
00539 $ilDB->query($q);
00540 }
00541 }
00542
00546 function _lookupStyleSheetId($a_cont_obj_id)
00547 {
00548 global $ilDB;
00549
00550 $q = "SELECT stylesheet FROM content_object ".
00551 " WHERE id = '".$a_cont_obj_id."'";
00552 $res = $ilDB->query($q);
00553 $sheet = $res->fetchRow(DB_FETCHMODE_ASSOC);
00554
00555 return $sheet["stylesheet"];
00556 }
00557
00561 function _lookupContObjIdByStyleId($a_style_id)
00562 {
00563 global $ilDB;
00564
00565 $q = "SELECT id FROM content_object ".
00566 " WHERE stylesheet = ".$ilDB->quote($a_style_id);
00567 $res = $ilDB->query($q);
00568 $obj_ids = array();
00569 while($cont = $res->fetchRow(DB_FETCHMODE_ASSOC))
00570 {
00571 $obj_ids[] = $cont["id"];
00572 }
00573 return $obj_ids;
00574 }
00575
00581 function _getNrOfAssignedLMs($a_style_id)
00582 {
00583 global $ilDB;
00584
00585 $q = "SELECT count(*) as cnt FROM content_object ".
00586 " WHERE stylesheet = ".$ilDB->quote($a_style_id);
00587 $cset = $ilDB->query($q);
00588 $crow = $cset->fetchRow(DB_FETCHMODE_ASSOC);
00589
00590 return (int) $crow["cnt"];
00591 }
00592
00593
00597 function _getNrLMsIndividualStyles()
00598 {
00599 global $ilDB;
00600
00601
00602 $q = "SELECT count(*) as cnt FROM content_object, style_data ".
00603 " WHERE stylesheet = style_data.id ".
00604 " AND standard = 0";
00605 $cset = $ilDB->query($q);
00606 $crow = $cset->fetchRow(DB_FETCHMODE_ASSOC);
00607
00608 return (int) $crow["cnt"];
00609 }
00610
00614 function _getNrLMsNoStyle()
00615 {
00616 global $ilDB;
00617
00618 $q = "SELECT count(*) as cnt FROM content_object ".
00619 " WHERE stylesheet = 0";
00620 $cset = $ilDB->query($q);
00621 $crow = $cset->fetchRow(DB_FETCHMODE_ASSOC);
00622
00623 return (int) $crow["cnt"];
00624 }
00625
00631 function _deleteStyleAssignments($a_style_id)
00632 {
00633 global $ilDB;
00634
00635 $q = "UPDATE content_object SET ".
00636 " stylesheet = ".$ilDB->quote("0").
00637 " WHERE stylesheet = ".$this->getId($a_style_id);
00638
00639 $ilDB->query($q);
00640 }
00641
00645 function getPageHeader()
00646 {
00647 return $this->pg_header;
00648 }
00649
00655 function setPageHeader($a_pg_header = IL_CHAPTER_TITLE)
00656 {
00657 $this->pg_header = $a_pg_header;
00658 }
00659
00663 function getTOCMode()
00664 {
00665 return $this->toc_mode;
00666 }
00667
00671 function getPublicAccessMode()
00672 {
00673 return $this->public_access_mode;
00674 }
00675
00681 function setTOCMode($a_toc_mode = "chapters")
00682 {
00683 $this->toc_mode = $a_toc_mode;
00684 }
00685
00686 function setOnline($a_online)
00687 {
00688 $this->online = $a_online;
00689 }
00690
00691 function getOnline()
00692 {
00693 return $this->online;
00694 }
00695
00696 function setActiveLMMenu($a_act_lm_menu)
00697 {
00698 $this->lm_menu_active = $a_act_lm_menu;
00699 }
00700
00701 function isActiveLMMenu()
00702 {
00703 return $this->lm_menu_active;
00704 }
00705
00706 function setActiveTOC($a_toc)
00707 {
00708 $this->toc_active = $a_toc;
00709 }
00710
00711 function isActiveTOC()
00712 {
00713 return $this->toc_active;
00714 }
00715
00716 function setActiveNumbering($a_num)
00717 {
00718 $this->numbering = $a_num;
00719 }
00720
00721 function isActiveNumbering()
00722 {
00723 return $this->numbering;
00724 }
00725
00726 function setActivePrintView($a_print)
00727 {
00728 $this->print_view_active = $a_print;
00729 }
00730
00731 function isActivePrintView()
00732 {
00733 return $this->print_view_active;
00734 }
00735
00736 function setActiveDownloads($a_down)
00737 {
00738 $this->downloads_active = $a_down;
00739 }
00740
00741 function isActiveDownloads()
00742 {
00743 return $this->downloads_active;
00744 }
00745
00746 function setActiveDownloadsPublic($a_down)
00747 {
00748 $this->downloads_public_active = $a_down;
00749 }
00750
00751 function isActiveDownloadsPublic()
00752 {
00753 return $this->downloads_public_active;
00754 }
00755
00756 function setPublicNotes($a_pub_notes)
00757 {
00758 $this->pub_notes = $a_pub_notes;
00759 }
00760
00761 function publicNotes()
00762 {
00763 return $this->pub_notes;
00764 }
00765
00766 function setCleanFrames($a_clean)
00767 {
00768 $this->clean_frames = $a_clean;
00769 }
00770
00771 function cleanFrames()
00772 {
00773 return $this->clean_frames;
00774 }
00775
00776 function setHistoryUserComments($a_comm)
00777 {
00778 $this->user_comments = $a_comm;
00779 }
00780
00781 function setPublicAccessMode($a_mode)
00782 {
00783 $this->public_access_mode = $a_mode;
00784 }
00785
00786 function isActiveHistoryUserComments()
00787 {
00788 return $this->user_comments;
00789 }
00790
00791 function setHeaderPage($a_pg)
00792 {
00793 $this->header_page = $a_pg;
00794 }
00795
00796 function getHeaderPage()
00797 {
00798 return $this->header_page;
00799 }
00800
00801 function setFooterPage($a_pg)
00802 {
00803 $this->footer_page = $a_pg;
00804 }
00805
00806 function getFooterPage()
00807 {
00808 return $this->footer_page;
00809 }
00810
00814 function readProperties()
00815 {
00816 $q = "SELECT * FROM content_object WHERE id = '".$this->getId()."'";
00817 $lm_set = $this->ilias->db->query($q);
00818 $lm_rec = $lm_set->fetchRow(DB_FETCHMODE_ASSOC);
00819 $this->setLayout($lm_rec["default_layout"]);
00820 $this->setStyleSheetId($lm_rec["stylesheet"]);
00821 $this->setPageHeader($lm_rec["page_header"]);
00822 $this->setTOCMode($lm_rec["toc_mode"]);
00823 $this->setOnline(ilUtil::yn2tf($lm_rec["online"]));
00824 $this->setActiveTOC(ilUtil::yn2tf($lm_rec["toc_active"]));
00825 $this->setActiveNumbering(ilUtil::yn2tf($lm_rec["numbering"]));
00826 $this->setActivePrintView(ilUtil::yn2tf($lm_rec["print_view_active"]));
00827 $this->setActiveDownloads(ilUtil::yn2tf($lm_rec["downloads_active"]));
00828 $this->setActiveDownloadsPublic(ilUtil::yn2tf($lm_rec["downloads_public_active"]));
00829 $this->setActiveLMMenu(ilUtil::yn2tf($lm_rec["lm_menu_active"]));
00830 $this->setCleanFrames(ilUtil::yn2tf($lm_rec["clean_frames"]));
00831 $this->setPublicNotes(ilUtil::yn2tf($lm_rec["pub_notes"]));
00832 $this->setHeaderPage($lm_rec["header_page"]);
00833 $this->setFooterPage($lm_rec["footer_page"]);
00834 $this->setHistoryUserComments(ilUtil::yn2tf($lm_rec["hist_user_comments"]));
00835 $this->setPublicAccessMode($lm_rec["public_access_mode"]);
00836 $this->setPublicExportFile("xml", $lm_rec["public_xml_file"]);
00837 $this->setPublicExportFile("html", $lm_rec["public_html_file"]);
00838 }
00839
00843 function updateProperties()
00844 {
00845 $q = "UPDATE content_object SET ".
00846 " default_layout = '".$this->getLayout()."', ".
00847 " stylesheet = '".$this->getStyleSheetId()."',".
00848 " page_header = '".$this->getPageHeader()."',".
00849 " toc_mode = '".$this->getTOCMode()."',".
00850 " online = '".ilUtil::tf2yn($this->getOnline())."',".
00851 " toc_active = '".ilUtil::tf2yn($this->isActiveTOC())."',".
00852 " numbering = '".ilUtil::tf2yn($this->isActiveNumbering())."',".
00853 " print_view_active = '".ilUtil::tf2yn($this->isActivePrintView())."',".
00854 " downloads_active = '".ilUtil::tf2yn($this->isActiveDownloads())."',".
00855 " downloads_public_active = '".ilUtil::tf2yn($this->isActiveDownloadsPublic())."',".
00856 " clean_frames = '".ilUtil::tf2yn($this->cleanFrames())."',".
00857 " pub_notes = '".ilUtil::tf2yn($this->publicNotes())."',".
00858 " hist_user_comments = '".ilUtil::tf2yn($this->isActiveHistoryUserComments())."',".
00859 " public_access_mode = '".$this->getPublicAccessMode()."',".
00860 " public_xml_file = '".$this->getPublicExportFile("xml")."',".
00861 " public_html_file = '".$this->getPublicExportFile("html")."',".
00862 " header_page = '".$this->getHeaderPage()."',".
00863 " footer_page = '".$this->getFooterPage()."',".
00864 " lm_menu_active = '".ilUtil::tf2yn($this->isActiveLMMenu())."'".
00865 " WHERE id = '".$this->getId()."'";
00866 $this->ilias->db->query($q);
00867 }
00868
00872 function createProperties()
00873 {
00874 $q = "INSERT INTO content_object (id) VALUES ('".$this->getId()."')";
00875 $this->ilias->db->query($q);
00876 $this->readProperties();
00877 }
00878
00882 function _lookupOnline($a_id)
00883 {
00884
00885
00886 $q = "SELECT * FROM content_object WHERE id = '".$a_id."'";
00887 $lm_set = $this->ilias->db->query($q);
00888 $lm_rec = $lm_set->fetchRow(DB_FETCHMODE_ASSOC);
00889
00890 return ilUtil::yn2tf($lm_rec["online"]);
00891 }
00892
00898 function getAvailableLayouts()
00899 {
00900
00901 $dir = opendir("./layouts/lm");
00902
00903 $layouts = array();
00904
00905 while($file = readdir($dir))
00906 {
00907 if ($file != "." && $file != ".." && $file != "CVS" && $file != ".svn")
00908 {
00909
00910 if (@is_dir("./layouts/lm/".$file))
00911 {
00912 $layouts[$file] = $file;
00913 }
00914 }
00915 }
00916 asort($layouts);
00917 return $layouts;
00918 }
00919
00923 function _checkPreconditionsOfPage($cont_obj_id, $page_id)
00924 {
00925 global $ilias,$ilUser,$ilErr;
00926
00927 $lm_tree = new ilTree($cont_obj_id);
00928 $lm_tree->setTableNames('lm_tree','lm_data');
00929 $lm_tree->setTreeTablePK("lm_id");
00930
00931 if ($lm_tree->isInTree($page_id))
00932 {
00933 $path = $lm_tree->getPathFull($page_id, $lm_tree->readRootId());
00934 foreach ($path as $node)
00935 {
00936 if ($node["type"] == "st")
00937 {
00938 if (!ilConditionHandler::_checkAllConditionsOfTarget($node["child"], "st"))
00939 {
00940 return false;
00941 }
00942 }
00943 }
00944 }
00945
00946 return true;
00947 }
00948
00952 function _getMissingPreconditionsOfPage($cont_obj_id, $page_id)
00953 {
00954 $lm_tree = new ilTree($cont_obj_id);
00955 $lm_tree->setTableNames('lm_tree','lm_data');
00956 $lm_tree->setTreeTablePK("lm_id");
00957
00958 $conds = array();
00959 if ($lm_tree->isInTree($page_id))
00960 {
00961
00962 $path = $lm_tree->getPathFull($page_id, $lm_tree->readRootId());
00963 foreach ($path as $node)
00964 {
00965 if ($node["type"] == "st")
00966 {
00967
00968 $tconds = ilConditionHandler::_getConditionsOfTarget($node["child"], "st");
00969 foreach ($tconds as $tcond)
00970 {
00971
00972 if (!ilConditionHandler::_checkCondition($tcond["id"]))
00973 {
00974 $conds[] = $tcond;
00975 }
00976 }
00977 }
00978 }
00979 }
00980
00981 return $conds;
00982 }
00983
00987 function _getMissingPreconditionsTopChapter($cont_obj_id, $page_id)
00988 {
00989 $lm_tree = new ilTree($cont_obj_id);
00990 $lm_tree->setTableNames('lm_tree','lm_data');
00991 $lm_tree->setTreeTablePK("lm_id");
00992
00993 $conds = array();
00994 if ($lm_tree->isInTree($page_id))
00995 {
00996
00997 $path = $lm_tree->getPathFull($page_id, $lm_tree->readRootId());
00998 foreach ($path as $node)
00999 {
01000 if ($node["type"] == "st")
01001 {
01002
01003 $tconds = ilConditionHandler::_getConditionsOfTarget($node["child"], "st");
01004 foreach ($tconds as $tcond)
01005 {
01006
01007 if (!ilConditionHandler::_checkCondition($tcond["id"]))
01008 {
01009 return $node["child"];
01010 }
01011 }
01012 }
01013 }
01014 }
01015
01016 return "";
01017 }
01018
01029 function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
01030 {
01031 global $tree;
01032
01033 switch ($a_event)
01034 {
01035 case "link":
01036
01037
01038
01039
01040 break;
01041
01042 case "cut":
01043
01044
01045
01046 break;
01047
01048 case "copy":
01049
01050
01051
01052
01053 break;
01054
01055 case "paste":
01056
01057
01058
01059 break;
01060
01061 case "new":
01062
01063
01064
01065 break;
01066 }
01067
01068
01069 if ($a_node_id==$_GET["ref_id"])
01070 {
01071 $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
01072 $parent_type = $parent_obj->getType();
01073 if($parent_type == $this->getType())
01074 {
01075 $a_node_id = (int) $tree->getParentId($a_node_id);
01076 }
01077 }
01078
01079 parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
01080 }
01081
01089 function _search(&$search_obj,$a_search_in)
01090 {
01091 global $ilBench;
01092
01093 switch($a_search_in)
01094 {
01095 case 'meta':
01096
01097 $in = $search_obj->getInStatement("r.ref_id");
01098 $where = $search_obj->getWhereCondition("fulltext",array("xv.tag_value"));
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108
01109
01110 $query1 = "SELECT DISTINCT(r.ref_id) FROM object_reference AS r,object_data AS o, ".
01111 "xmlnestedset AS xm,xmlvalue AS xv ".
01112 $where.
01113 $in.
01114 "AND r.obj_id=o.obj_id AND ( ".
01115 "(o.obj_id=xm.ns_book_fk AND xm.ns_type IN ('lm','bib'))) ".
01116 "AND xm.ns_tag_fk=xv.tag_fk ".
01117 "AND o.type= 'lm'";
01118
01119
01120 $query1 = "SELECT DISTINCT(r.ref_id) as ref_id FROM xmlvalue AS xv ".
01121 "LEFT JOIN xmlnestedset AS xm ON xm.ns_tag_fk=xv.tag_fk ".
01122 "LEFT JOIN object_data AS o ON o.obj_id = xm.ns_book_fk ".
01123 "LEFT JOIN object_reference AS r ON o.obj_id = r.obj_id ".
01124 $where.
01125 $in.
01126 " AND o.type = 'lm' AND xm.ns_type IN ('lm','bib')";
01127
01128 $query2 = "SELECT DISTINCT(r.ref_id) FROM object_reference AS r,object_data AS o, ".
01129 "lm_data AS l,xmlnestedset AS xm,xmlvalue AS xv ".
01130 $where.
01131 $in.
01132 "AND r.obj_id=o.obj_id AND ((o.obj_id=l.lm_id AND xm.ns_book_fk=l.obj_id)".
01133 ") ".
01134 "AND xm.ns_tag_fk=xv.tag_fk ".
01135 "AND o.type= 'lm'";
01136
01137 $query2 = "SELECT DISTINCT(r.ref_id) as ref_id FROM xmlvalue AS xv ".
01138 "LEFT JOIN xmlnestedset AS xm ON xm.ns_tag_fk = xv.tag_fk ".
01139 "LEFT JOIN lm_data AS l ON l.obj_id = xm.ns_book_fk ".
01140 "LEFT JOIN object_data AS o ON o.obj_id = l.lm_id ".
01141 "LEFT JOIN object_reference AS r ON r.obj_id = o.obj_id ".
01142 $where.
01143 $in.
01144 "AND o.type = 'lm'";
01145
01146 $ilBench->start("Search", "ilObjContentObject_search_meta");
01147 $res1 = $search_obj->ilias->db->query($query1);
01148 $res2 = $search_obj->ilias->db->query($query2);
01149 $ilBench->stop("Search", "ilObjContentObject_search_meta");
01150
01151 $counter = 0;
01152 $ids = array();
01153 while($row = $res1->fetchRow(DB_FETCHMODE_OBJECT))
01154 {
01155 $ids[] = $row->ref_id;
01156 $result[$counter]["id"] = $row->ref_id;
01157 ++$counter;
01158 }
01159 while($row = $res2->fetchRow(DB_FETCHMODE_OBJECT))
01160 {
01161 if(in_array($row->ref_id,$ids))
01162 {
01163 continue;
01164 }
01165 $result[$counter]["id"] = $row->ref_id;
01166 ++$counter;
01167 }
01168 break;
01169
01170 case 'content':
01171 $in = $search_obj->getInStatement("r.ref_id");
01172 $where = $search_obj->getWhereCondition("fulltext",array("pg.content"));
01173
01174
01175
01176
01177
01178
01179
01180
01181
01182 $query = "SELECT DISTINCT(r.ref_id) AS ref_id ,pg.page_id AS page_id FROM page_object AS pg ".
01183 ", object_reference AS r ".
01184 $where.
01185 " AND pg.parent_id = r.obj_id ".
01186 $in.
01187 " AND pg.parent_type = 'lm' ";
01188
01189 $query = "SELECT DISTINCT(r.ref_id) AS ref_id ,pg.page_id AS page_id FROM page_object AS pg ".
01190 "LEFT JOIN object_data AS o ON o.obj_id = pg.parent_id ".
01191 "LEFT JOIN object_reference AS r ON o.obj_id = r.obj_id ".
01192 $where.
01193 $in.
01194 " AND pg.parent_type = 'lm'";
01195
01196 $ilBench->start("Search", "ilObjContentObject_search_content");
01197 $res = $search_obj->ilias->db->query($query);
01198 $ilBench->stop("Search", "ilObjContentObject_search_content");
01199
01200 $counter = 0;
01201 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
01202 {
01203 $result[$counter]["id"] = $row->ref_id;
01204 $result[$counter]["page_id"] = $row->page_id;
01205
01206
01207
01208
01209 ++$counter;
01210 }
01211 break;
01212 }
01213 return $result ? $result : array();
01214 }
01215
01226
01227
01228
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238
01239
01243 function hasSuccessorPage($a_cont_obj_id, $a_page_id)
01244 {
01245 $tree = new ilTree($a_cont_obj_id);
01246 $tree->setTableNames('lm_tree','lm_data');
01247 $tree->setTreeTablePK("lm_id");
01248 if ($tree->isInTree($a_page_id))
01249 {
01250 $succ = $tree->fetchSuccessorNode($a_page_id, "pg");
01251 if ($succ > 0)
01252 {
01253 return true;
01254 }
01255 }
01256 return false;
01257 }
01258
01259
01260 function checkTree()
01261 {
01262 $tree = new ilTree($this->getId());
01263 $tree->setTableNames('lm_tree','lm_data');
01264 $tree->setTreeTablePK("lm_id");
01265 $tree->checkTree();
01266 $tree->checkTreeChilds();
01267
01268 }
01269
01273 function fixTree()
01274 {
01275 global $ilDB;
01276
01277 $tree =& $this->getLMTree();
01278
01279
01280 $nodes = $tree->getSubtree($tree->getNodeData($tree->getRootId()));
01281 foreach ($nodes as $node)
01282 {
01283 $q = "SELECT * FROM lm_data WHERE obj_id = ".$ilDB->quote($node["child"]);
01284 $obj_set = $ilDB->query($q);
01285 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
01286 if (!$obj_rec)
01287 {
01288 $node_data = $tree->getNodeData($node["child"]);
01289 $tree->deleteTree($node_data);
01290 }
01291 }
01292
01293
01294 $nodes = $tree->getSubtree($tree->getNodeData($tree->getRootId()));
01295 foreach ($nodes as $node)
01296 {
01297 $q = "SELECT * FROM lm_data WHERE obj_id = ".$ilDB->quote($node["parent"]);
01298 $obj_set = $ilDB->query($q);
01299 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
01300 if ($obj_rec["type"] == "pg")
01301 {
01302 $node_data = $tree->getNodeData($node["child"]);
01303 if ($tree->isInTree($node["child"]))
01304 {
01305 $tree->deleteTree($node_data);
01306 }
01307 }
01308 }
01309
01310 }
01311
01312
01319 function exportXML(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
01320 {
01321 global $ilBench;
01322
01323 $attrs = array();
01324 switch($this->getType())
01325 {
01326 case "lm":
01327 $attrs["Type"] = "LearningModule";
01328 break;
01329
01330 case "dbk":
01331 $attrs["Type"] = "LibObject";
01332 break;
01333 }
01334 $a_xml_writer->xmlStartTag("ContentObject", $attrs);
01335
01336
01337 $this->exportXMLMetaData($a_xml_writer);
01338
01339
01340
01341 $expLog->write(date("[y-m-d H:i:s] ")."Start Export Structure Objects");
01342 $ilBench->start("ContentObjectExport", "exportStructureObjects");
01343 $this->exportXMLStructureObjects($a_xml_writer, $a_inst, $expLog);
01344 $ilBench->stop("ContentObjectExport", "exportStructureObjects");
01345 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Structure Objects");
01346
01347
01348 $expLog->write(date("[y-m-d H:i:s] ")."Start Export Page Objects");
01349 $ilBench->start("ContentObjectExport", "exportPageObjects");
01350 $this->exportXMLPageObjects($a_xml_writer, $a_inst, $expLog);
01351 $ilBench->stop("ContentObjectExport", "exportPageObjects");
01352 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Page Objects");
01353
01354
01355 $expLog->write(date("[y-m-d H:i:s] ")."Start Export Media Objects");
01356 $ilBench->start("ContentObjectExport", "exportMediaObjects");
01357 $this->exportXMLMediaObjects($a_xml_writer, $a_inst, $a_target_dir, $expLog);
01358 $ilBench->stop("ContentObjectExport", "exportMediaObjects");
01359 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Media Objects");
01360
01361
01362 $expLog->write(date("[y-m-d H:i:s] ")."Start Export File Items");
01363 $ilBench->start("ContentObjectExport", "exportFileItems");
01364 $this->exportFileItems($a_target_dir, $expLog);
01365 $ilBench->stop("ContentObjectExport", "exportFileItems");
01366 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export File Items");
01367
01368
01369
01370 $expLog->write(date("[y-m-d H:i:s] ")."Start Export Properties");
01371 $this->exportXMLProperties($a_xml_writer, $expLog);
01372 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Properties");
01373
01374
01375
01376
01377
01378
01379
01380
01381
01382
01383 $a_xml_writer->xmlEndTag("ContentObject");
01384 }
01385
01392 function exportXMLMetaData(&$a_xml_writer)
01393 {
01394 include_once("Services/MetaData/classes/class.ilMD2XML.php");
01395 $md2xml = new ilMD2XML($this->getId(), 0, $this->getType());
01396 $md2xml->setExportMode(true);
01397 $md2xml->startExport();
01398 $a_xml_writer->appendXML($md2xml->getXML());
01399 }
01400
01407 function exportXMLStructureObjects(&$a_xml_writer, $a_inst, &$expLog)
01408 {
01409 include_once './content/classes/class.ilStructureObject.php';
01410
01411 $childs = $this->lm_tree->getChilds($this->lm_tree->getRootId());
01412 foreach ($childs as $child)
01413 {
01414 if($child["type"] != "st")
01415 {
01416 continue;
01417 }
01418
01419 $structure_obj = new ilStructureObject($this, $child["obj_id"]);
01420 $structure_obj->exportXML($a_xml_writer, $a_inst, $expLog);
01421 unset($structure_obj);
01422 }
01423 }
01424
01425
01432 function exportXMLPageObjects(&$a_xml_writer, $a_inst, &$expLog)
01433 {
01434 global $ilBench;
01435
01436 include_once "./content/classes/class.ilLMPageObject.php";
01437
01438 $pages = ilLMPageObject::getPageList($this->getId());
01439 foreach ($pages as $page)
01440 {
01441 $ilBench->start("ContentObjectExport", "exportPageObject");
01442 $expLog->write(date("[y-m-d H:i:s] ")."Page Object ".$page["obj_id"]);
01443
01444
01445 $ilBench->start("ContentObjectExport", "exportPageObject_getLMPageObject");
01446 $page_obj = new ilLMPageObject($this, $page["obj_id"]);
01447 $ilBench->stop("ContentObjectExport", "exportPageObject_getLMPageObject");
01448 $ilBench->start("ContentObjectExport", "exportPageObject_XML");
01449 $page_obj->exportXML($a_xml_writer, "normal", $a_inst);
01450 $ilBench->stop("ContentObjectExport", "exportPageObject_XML");
01451
01452
01453 $ilBench->start("ContentObjectExport", "exportPageObject_CollectMedia");
01454 $mob_ids = $page_obj->getMediaObjectIDs();
01455 foreach($mob_ids as $mob_id)
01456 {
01457 $this->mob_ids[$mob_id] = $mob_id;
01458 }
01459 $ilBench->stop("ContentObjectExport", "exportPageObject_CollectMedia");
01460
01461
01462 $ilBench->start("ContentObjectExport", "exportPageObject_CollectFileItems");
01463 $file_ids = $page_obj->getFileItemIds();
01464 foreach($file_ids as $file_id)
01465 {
01466 $this->file_ids[$file_id] = $file_id;
01467 }
01468 $ilBench->stop("ContentObjectExport", "exportPageObject_CollectFileItems");
01469
01470 unset($page_obj);
01471
01472 $ilBench->stop("ContentObjectExport", "exportPageObject");
01473 }
01474 }
01475
01482 function exportXMLMediaObjects(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
01483 {
01484 include_once("content/classes/Media/class.ilObjMediaObject.php");
01485
01486 $linked_mobs = array();
01487
01488
01489 foreach ($this->mob_ids as $mob_id)
01490 {
01491 if ($mob_id > 0)
01492 {
01493 $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
01494 $media_obj = new ilObjMediaObject($mob_id);
01495 $media_obj->exportXML($a_xml_writer, $a_inst);
01496 $media_obj->exportFiles($a_target_dir);
01497
01498
01499 $med_items = $media_obj->getMediaItems();
01500 foreach($med_items as $med_item)
01501 {
01502 $int_links = ilMapArea::_getIntLinks($med_item->getId());
01503 foreach ($int_links as $k => $int_link)
01504 {
01505 if ($int_link["Type"] == "MediaObject")
01506 {
01507 include_once("./content/classes/Pages/class.ilInternalLink.php");
01508 $l_id = ilInternalLink::_extractObjIdOfTarget($int_link["Target"]);
01509 if (ilObject::_exists($l_id))
01510 {
01511 if (!in_array($l_id, $linked_mobs) &&
01512 !in_array($l_id, $this->mob_ids))
01513 {
01514 $linked_mobs[] = $l_id;
01515 }
01516 }
01517 }
01518 }
01519 }
01520
01521 unset($media_obj);
01522 }
01523 }
01524
01525
01526 foreach ($linked_mobs as $mob_id)
01527 {
01528 if ($mob_id > 0)
01529 {
01530 $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
01531 $media_obj = new ilObjMediaObject($mob_id);
01532 $media_obj->exportXML($a_xml_writer, $a_inst);
01533 $media_obj->exportFiles($a_target_dir);
01534 unset($media_obj);
01535 }
01536 }
01537
01538 }
01539
01544 function exportFileItems($a_target_dir, &$expLog)
01545 {
01546 include_once("classes/class.ilObjFile.php");
01547
01548 foreach ($this->file_ids as $file_id)
01549 {
01550 $expLog->write(date("[y-m-d H:i:s] ")."File Item ".$file_id);
01551 $file_obj = new ilObjFile($file_id, false);
01552 $file_obj->export($a_target_dir);
01553 unset($file_obj);
01554 }
01555 }
01556
01561 function exportXMLProperties($a_xml_writer, &$expLog)
01562 {
01563 $attrs = array();
01564 $a_xml_writer->xmlStartTag("Properties", $attrs);
01565
01566
01567 $attrs = array("Name" => "Layout", "Value" => $this->getLayout());
01568 $a_xml_writer->xmlElement("Property", $attrs);
01569
01570
01571 $attrs = array("Name" => "PageHeader", "Value" => $this->getPageHeader());
01572 $a_xml_writer->xmlElement("Property", $attrs);
01573
01574
01575 $attrs = array("Name" => "TOCMode", "Value" => $this->getTOCMode());
01576 $a_xml_writer->xmlElement("Property", $attrs);
01577
01578
01579 $attrs = array("Name" => "ActiveLMMenu", "Value" =>
01580 ilUtil::tf2yn($this->isActiveLMMenu()));
01581 $a_xml_writer->xmlElement("Property", $attrs);
01582
01583
01584 $attrs = array("Name" => "ActiveNumbering", "Value" =>
01585 ilUtil::tf2yn($this->isActiveNumbering()));
01586 $a_xml_writer->xmlElement("Property", $attrs);
01587
01588
01589 $attrs = array("Name" => "ActiveTOC", "Value" =>
01590 ilUtil::tf2yn($this->isActiveTOC()));
01591 $a_xml_writer->xmlElement("Property", $attrs);
01592
01593
01594 $attrs = array("Name" => "ActivePrintView", "Value" =>
01595 ilUtil::tf2yn($this->isActivePrintView()));
01596 $a_xml_writer->xmlElement("Property", $attrs);
01597
01598
01599
01600
01601
01602 $attrs = array("Name" => "CleanFrames", "Value" =>
01603 ilUtil::tf2yn($this->cleanFrames()));
01604 $a_xml_writer->xmlElement("Property", $attrs);
01605
01606
01607 $attrs = array("Name" => "PublicNotes", "Value" =>
01608 ilUtil::tf2yn($this->publicNotes()));
01609 $a_xml_writer->xmlElement("Property", $attrs);
01610
01611
01612 $attrs = array("Name" => "HistoryUserComments", "Value" =>
01613 ilUtil::tf2yn($this->isActiveHistoryUserComments()));
01614 $a_xml_writer->xmlElement("Property", $attrs);
01615
01616
01617 if ($this->getHeaderPage() > 0)
01618 {
01619 $attrs = array("Name" => "HeaderPage", "Value" =>
01620 "il_".IL_INST_ID."_pg_".$this->getHeaderPage());
01621 $a_xml_writer->xmlElement("Property", $attrs);
01622 }
01623
01624
01625 if ($this->getFooterPage() > 0)
01626 {
01627 $attrs = array("Name" => "FooterPage", "Value" =>
01628 "il_".IL_INST_ID."_pg_".$this->getFooterPage());
01629 $a_xml_writer->xmlElement("Property", $attrs);
01630 }
01631
01632 $a_xml_writer->xmlEndTag("Properties");
01633 }
01634
01638 function getExportFiles()
01639 {
01640 $file = array();
01641
01642 $types = array("xml", "html", "scorm");
01643
01644 foreach ($types as $type)
01645 {
01646 $dir = $this->getExportDirectory($type);
01647
01648 if (!@is_dir($dir) or
01649 !is_writeable($dir))
01650 {
01651 continue;
01652 }
01653
01654
01655 $cdir = dir($dir);
01656
01657
01658
01659
01660 while ($entry = $cdir->read())
01661 {
01662 if ($entry != "." and
01663 $entry != ".." and
01664 substr($entry, -4) == ".zip" and
01665 ereg("^[0-9]{10}_{2}[0-9]+_{2}(lm_)*[0-9]+\.zip\$", $entry))
01666 {
01667 $file[$entry.$type] = array("type" => $type, "file" => $entry,
01668 "size" => filesize($dir."/".$entry));
01669 }
01670 }
01671
01672
01673 $cdir->close();
01674 }
01675
01676
01677 ksort ($file);
01678 reset ($file);
01679 return $file;
01680 }
01681
01688 function setPublicExportFile($a_type, $a_file)
01689 {
01690 $this->public_export_file[$a_type] = $a_file;
01691 }
01692
01700 function getPublicExportFile($a_type)
01701 {
01702 return $this->public_export_file[$a_type];
01703 }
01704
01708 function getOfflineFiles($dir)
01709 {
01710
01711 if (!@is_dir($dir) or
01712 !is_writeable($dir))
01713 {
01714 return array();
01715 }
01716
01717
01718 $dir = dir($dir);
01719
01720
01721 $file = array();
01722
01723
01724 while ($entry = $dir->read())
01725 {
01726 if ($entry != "." and
01727 $entry != ".." and
01728 substr($entry, -4) == ".pdf" and
01729 ereg("^[0-9]{10}_{2}[0-9]+_{2}(lm_)*[0-9]+\.pdf\$", $entry))
01730 {
01731 $file[] = $entry;
01732 }
01733 }
01734
01735
01736 $dir->close();
01737
01738
01739 sort ($file);
01740 reset ($file);
01741
01742 return $file;
01743 }
01744
01748 function exportSCORM($a_target_dir, $log)
01749 {
01750 ilUtil::delDir($a_target_dir);
01751 ilUtil::makeDir($a_target_dir);
01752
01753
01754
01755 $this->exportHTML($a_target_dir."/res", $log, false, "scorm");
01756
01757
01758 include("content/classes/class.ilContObjectManifestBuilder.php");
01759 $man_builder = new ilContObjectManifestBuilder($this);
01760 $man_builder->buildManifest();
01761 $man_builder->dump($a_target_dir);
01762
01763
01764 copy("content/scorm_xsd/adlcp_rootv1p2.xsd", $a_target_dir."/adlcp_rootv1p2.xsd");
01765 copy("content/scorm_xsd/imscp_rootv1p1p2.xsd", $a_target_dir."/imscp_rootv1p1p2.xsd");
01766 copy("content/scorm_xsd/imsmd_rootv1p2p1.xsd", $a_target_dir."/imsmd_rootv1p2p1.xsd");
01767 copy("content/scorm_xsd/ims_xml.xsd", $a_target_dir."/ims_xml.xsd");
01768
01769
01770 $date = time();
01771 $zip_file = $a_target_dir."/".$date."__".IL_INST_ID."__".
01772 $this->getType()."_".$this->getId().".zip";
01773
01774 ilUtil::zip(array($a_target_dir."/res",
01775 $a_target_dir."/imsmanifest.xml",
01776 $a_target_dir."/adlcp_rootv1p2.xsd",
01777 $a_target_dir."/imscp_rootv1p1p2.xsd",
01778 $a_target_dir."/ims_xml.xsd",
01779 $a_target_dir."/imsmd_rootv1p2p1.xsd")
01780 , $zip_file);
01781
01782 $dest_file = $this->getExportDirectory("scorm")."/".$date."__".IL_INST_ID."__".
01783 $this->getType()."_".$this->getId().".zip";
01784
01785 rename($zip_file, $dest_file);
01786 ilUtil::delDir($a_target_dir);
01787
01788 }
01789
01790
01794 function exportHTML($a_target_dir, $log, $a_zip_file = true, $a_export_format = "html")
01795 {
01796 global $ilias, $tpl, $ilBench, $ilLocator;
01797
01798
01799 ilUtil::delDir($a_target_dir);
01800 ilUtil::makeDir($a_target_dir);
01801 $mob_dir = $a_target_dir."/mobs";
01802 ilUtil::makeDir($mob_dir);
01803 $file_dir = $a_target_dir."/files";
01804 ilUtil::makeDir($file_dir);
01805 $teximg_dir = $a_target_dir."/teximg";
01806 ilUtil::makeDir($teximg_dir);
01807 $GLOBALS["teximgcnt"] = 0;
01808
01809
01810 $location_stylesheet = ilUtil::getStyleSheetLocation("filesystem");
01811 $style_name = $ilias->account->prefs["style"].".css";
01812 copy($location_stylesheet, $a_target_dir."/".$style_name);
01813 $location_stylesheet = ilUtil::getStyleSheetLocation();
01814
01815
01816 $ilBench->start("ExportHTML", "exportContentStyle");
01817 if ($this->getStyleSheetId() < 1)
01818 {
01819 $cont_stylesheet = "content/content.css";
01820 copy($cont_stylesheet, $a_target_dir."/content.css");
01821 }
01822 else
01823 {
01824 $style = new ilObjStyleSheet($this->getStyleSheetId());
01825 $style->writeCSSFile($a_target_dir."/content.css");
01826 }
01827 $ilBench->stop("ExportHTML", "exportContentStyle");
01828
01829
01830 $syn_stylesheet = "content/syntaxhighlight.css";
01831 copy($syn_stylesheet, $a_target_dir."/syntaxhighlight.css");
01832
01833
01834 include_once("content/classes/class.ilLMPresentationGUI.php");
01835 $_GET["cmd"] = "nop";
01836 $lm_gui =& new ilLMPresentationGUI();
01837 $lm_gui->setOfflineMode(true);
01838 $lm_gui->setOfflineDirectory($a_target_dir);
01839 $lm_gui->setExportFormat($a_export_format);
01840
01841
01842 $ilBench->start("ExportHTML", "exportHTMLPages");
01843 $this->exportHTMLPages($lm_gui, $a_target_dir);
01844 $ilBench->stop("ExportHTML", "exportHTMLPages");
01845
01846
01847 $ilBench->start("ExportHTML", "exportHTMLGlossaryTerms");
01848 $this->exportHTMLGlossaryTerms($lm_gui, $a_target_dir);
01849 $ilBench->stop("ExportHTML", "exportHTMLGlossaryTerms");
01850
01851
01852 $ilBench->start("ExportHTML", "exportHTMLMediaObjects");
01853 foreach ($this->offline_mobs as $mob)
01854 {
01855 if (ilObject::_exists($mob))
01856 {
01857 $this->exportHTMLMOB($a_target_dir, $lm_gui, $mob, "_blank");
01858 }
01859 }
01860 $_GET["obj_type"] = "MediaObject";
01861 $_GET["obj_id"] = $a_mob_id;
01862 $_GET["cmd"] = "";
01863 $ilBench->stop("ExportHTML", "exportHTMLMediaObjects");
01864
01865
01866 $ilBench->start("ExportHTML", "exportHTMLFileObjects");
01867 foreach ($this->offline_files as $file)
01868 {
01869 $this->exportHTMLFile($a_target_dir, $file);
01870 }
01871 $ilBench->stop("ExportHTML", "exportHTMLFileObjects");
01872
01873
01874 $ilBench->start("ExportHTML", "exportHTMLTOC");
01875 $ilLocator->clearItems();
01876 if ($this->isActiveTOC())
01877 {
01878 $tpl = new ilTemplate("tpl.main.html", true, true);
01879
01880 $content =& $lm_gui->showTableOfContents();
01881 $file = $a_target_dir."/table_of_contents.html";
01882
01883
01884 if (!($fp = @fopen($file,"w+")))
01885 {
01886 die ("<b>Error</b>: Could not open \"".$file."\" for writing".
01887 " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
01888 }
01889 chmod($file, 0770);
01890 fwrite($fp, $content);
01891 fclose($fp);
01892 }
01893 $ilBench->stop("ExportHTML", "exportHTMLTOC");
01894
01895
01896 $ilBench->start("ExportHTML", "exportHTMLImages");
01897 $image_dir = $a_target_dir."/images";
01898 ilUtil::makeDir($image_dir);
01899 ilUtil::makeDir($image_dir."/browser");
01900 copy(ilUtil::getImagePath("enlarge.gif", false, "filesystem"),
01901 $image_dir."/enlarge.gif");
01902 copy(ilUtil::getImagePath("browser/blank.gif", false, "filesystem"),
01903 $image_dir."/browser/plus.gif");
01904 copy(ilUtil::getImagePath("browser/blank.gif", false, "filesystem"),
01905 $image_dir."/browser/minus.gif");
01906 copy(ilUtil::getImagePath("browser/blank.gif", false, "filesystem"),
01907 $image_dir."/browser/blank.gif");
01908 copy(ilUtil::getImagePath("icon_st.gif", false, "filesystem"),
01909 $image_dir."/icon_st.gif");
01910 copy(ilUtil::getImagePath("icon_pg.gif", false, "filesystem"),
01911 $image_dir."/icon_pg.gif");
01912 copy(ilUtil::getImagePath("icon_lm.gif", false, "filesystem"),
01913 $image_dir."/icon_lm.gif");
01914 copy(ilUtil::getImagePath("nav_arr_L.gif", false, "filesystem"),
01915 $image_dir."/nav_arr_L.gif");
01916 copy(ilUtil::getImagePath("nav_arr_R.gif", false, "filesystem"),
01917 $image_dir."/nav_arr_R.gif");
01918
01919 copy(ilUtil::getImagePath("download.gif", false, "filesystem"),
01920 $image_dir."/download.gif");
01921 $ilBench->stop("ExportHTML", "exportHTMLImages");
01922
01923
01924 $tpl = new ilTemplate("tpl.main.html", true, true);
01925 $tpl->setVariable("LOCATION_STYLESHEET",$location_stylesheet);
01926 $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
01927
01928
01929 $ilBench->start("ExportHTML", "zip");
01930 if (true)
01931 {
01932 if ($a_zip_file)
01933 {
01934
01935 $date = time();
01936 $zip_file = $this->getExportDirectory("html")."/".$date."__".IL_INST_ID."__".
01937 $this->getType()."_".$this->getId().".zip";
01938 ilUtil::zip($a_target_dir, $zip_file);
01939 ilUtil::delDir($a_target_dir);
01940 }
01941 }
01942 $ilBench->stop("ExportHTML", "zip");
01943
01944 }
01945
01949 function exportHTMLFile($a_target_dir, $a_file_id)
01950 {
01951 $file_dir = $a_target_dir."/files/file_".$a_file_id;
01952 ilUtil::makeDir($file_dir);
01953 include_once("classes/class.ilObjFile.php");
01954 $file_obj = new ilObjFile($a_file_id, false);
01955 $source_file = $file_obj->getDirectory($file_obj->getVersion())."/".$file_obj->getFileName();
01956 if (!is_file($source_file))
01957 {
01958 $source_file = $file_obj->getDirectory()."/".$file_obj->getFileName();
01959 }
01960 copy($source_file, $file_dir."/".$file_obj->getFileName());
01961 }
01962
01966 function exportHTMLMOB($a_target_dir, &$a_lm_gui, $a_mob_id, $a_frame = "")
01967 {
01968 global $tpl;
01969
01970 $mob_dir = $a_target_dir."/mobs";
01971
01972 $source_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob_id;
01973 if (@is_dir($source_dir))
01974 {
01975 ilUtil::makeDir($mob_dir."/mm_".$a_mob_id);
01976 ilUtil::rCopy($source_dir, $mob_dir."/mm_".$a_mob_id);
01977 }
01978
01979 $tpl = new ilTemplate("tpl.main.html", true, true);
01980 $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
01981 $_GET["obj_type"] = "MediaObject";
01982 $_GET["mob_id"] = $a_mob_id;
01983 $_GET["frame"] = $a_frame;
01984 $_GET["cmd"] = "";
01985 $content =& $a_lm_gui->media();
01986 $file = $a_target_dir."/media_".$a_mob_id.".html";
01987
01988
01989 if (!($fp = @fopen($file,"w+")))
01990 {
01991 die ("<b>Error</b>: Could not open \"".$file."\" for writing".
01992 " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
01993 }
01994 chmod($file, 0770);
01995 fwrite($fp, $content);
01996 fclose($fp);
01997
01998
01999 include_once("content/classes/Media/class.ilObjMediaObject.php");
02000 $mob_obj = new ilObjMediaObject($a_mob_id);
02001 if ($mob_obj->hasFullscreenItem())
02002 {
02003 $tpl = new ilTemplate("tpl.main.html", true, true);
02004 $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
02005 $_GET["obj_type"] = "";
02006 $_GET["frame"] = "";
02007 $_GET["mob_id"] = $a_mob_id;
02008 $_GET["cmd"] = "fullscreen";
02009 $content =& $a_lm_gui->fullscreen();
02010 $file = $a_target_dir."/fullscreen_".$a_mob_id.".html";
02011
02012
02013 if (!($fp = @fopen($file,"w+")))
02014 {
02015 die ("<b>Error</b>: Could not open \"".$file."\" for writing".
02016 " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
02017 }
02018 chmod($file, 0770);
02019 fwrite($fp, $content);
02020 fclose($fp);
02021 }
02022 }
02023
02027 function exportHTMLGlossaryTerms(&$a_lm_gui, $a_target_dir)
02028 {
02029 global $ilLocator;
02030
02031 foreach($this->offline_int_links as $int_link)
02032 {
02033 $ilLocator->clearItems();
02034 if ($int_link["type"] == "git")
02035 {
02036 $tpl = new ilTemplate("tpl.main.html", true, true);
02037 $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
02038
02039 $_GET["obj_id"] = $int_link["id"];
02040 $_GET["frame"] = "_blank";
02041 $content =& $a_lm_gui->glossary();
02042 $file = $a_target_dir."/term_".$int_link["id"].".html";
02043
02044
02045 if (!($fp = @fopen($file,"w+")))
02046 {
02047 die ("<b>Error</b>: Could not open \"".$file."\" for writing".
02048 " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
02049 }
02050 chmod($file, 0770);
02051 fwrite($fp, $content);
02052 fclose($fp);
02053
02054
02055 include_once("content/classes/class.ilGlossaryDefinition.php");
02056 $defs = ilGlossaryDefinition::getDefinitionList($int_link["id"]);
02057 foreach($defs as $def)
02058 {
02059 $def_mobs = ilObjMediaObject::_getMobsOfObject("gdf:pg", $def["id"]);
02060 foreach($def_mobs as $def_mob)
02061 {
02062 $this->offline_mobs[$def_mob] = $def_mob;
02063 }
02064
02065
02066 $def_files = ilObjFile::_getFilesOfObject("gdf:pg", $page["obj_id"]);
02067 $this->offline_files = array_merge($this->offline_files, $def_files);
02068
02069 }
02070
02071 }
02072 }
02073 }
02074
02078 function exportHTMLPages(&$a_lm_gui, $a_target_dir)
02079 {
02080 global $tpl, $ilBench, $ilLocator;
02081
02082 $pages = ilLMPageObject::getPageList($this->getId());
02083
02084 $lm_tree =& $this->getLMTree();
02085 $first_page = $lm_tree->fetchSuccessorNode($lm_tree->getRootId(), "pg");
02086 $this->first_page_id = $first_page["child"];
02087
02088
02089 $mobs = array();
02090 $int_links = array();
02091 $this->offline_files = array();
02092
02093 foreach ($pages as $page)
02094 {
02095 $ilLocator->clearItems();
02096 $ilBench->start("ExportHTML", "exportHTMLPage");
02097 $ilBench->start("ExportHTML", "exportPageHTML");
02098 $this->exportPageHTML($a_lm_gui, $a_target_dir, $page["obj_id"]);
02099 $ilBench->stop("ExportHTML", "exportPageHTML");
02100
02101
02102 include_once("content/classes/Media/class.ilObjMediaObject.php");
02103 $pg_mobs = ilObjMediaObject::_getMobsOfObject($this->getType().":pg", $page["obj_id"]);
02104 foreach($pg_mobs as $pg_mob)
02105 {
02106 $mobs[$pg_mob] = $pg_mob;
02107 }
02108
02109
02110 $pg_links = ilInternalLink::_getTargetsOfSource($this->getType().":pg", $page["obj_id"]);
02111 $int_links = array_merge($int_links, $pg_links);
02112
02113
02114 include_once("classes/class.ilObjFile.php");
02115 $pg_files = ilObjFile::_getFilesOfObject($this->getType().":pg", $page["obj_id"]);
02116 $this->offline_files = array_merge($this->offline_files, $pg_files);
02117
02118 $ilBench->stop("ExportHTML", "exportHTMLPage");
02119 }
02120 $this->offline_mobs = $mobs;
02121 $this->offline_int_links = $int_links;
02122
02123
02124 }
02125
02129 function exportPageHTML(&$a_lm_gui, $a_target_dir, $a_lm_page_id, $a_frame = "")
02130 {
02131 global $ilias, $tpl, $ilBench;
02132
02133
02134
02135 $tpl = new ilTemplate("tpl.main.html", true, true);
02136 $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
02137
02138 $_GET["obj_id"] = $a_lm_page_id;
02139 $_GET["frame"] = $a_frame;
02140
02141 if ($a_frame == "")
02142 {
02143 if ($nid = ilLMObject::_lookupNID($a_lm_gui->lm->getId(), $a_lm_page_id, "pg"))
02144 {
02145 $file = $a_target_dir."/lm_pg_".$nid.".html";
02146 }
02147 else
02148 {
02149 $file = $a_target_dir."/lm_pg_".$a_lm_page_id.".html";
02150 }
02151 }
02152 else
02153 {
02154 if ($a_frame != "toc")
02155 {
02156 $file = $a_target_dir."/frame_".$a_lm_page_id."_".$a_frame.".html";
02157 }
02158 else
02159 {
02160 $file = $a_target_dir."/frame_".$a_frame.".html";
02161 }
02162 }
02163
02164
02165 if (@is_file($file))
02166 {
02167 return;
02168 }
02169
02170 $ilBench->start("ExportHTML", "layout");
02171 $ilBench->start("ExportHTML", "layout_".$a_frame);
02172 $content =& $a_lm_gui->layout("main.xml", false);
02173 $ilBench->stop("ExportHTML", "layout_".$a_frame);
02174 $ilBench->stop("ExportHTML", "layout");
02175
02176
02177 if (!($fp = @fopen($file,"w+")))
02178 {
02179 die ("<b>Error</b>: Could not open \"".$file."\" for writing".
02180 " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
02181 }
02182
02183
02184 chmod($file, 0770);
02185
02186
02187 fwrite($fp, $content);
02188
02189
02190 fclose($fp);
02191
02192 if ($this->first_page_id == $a_lm_page_id && $a_frame == "")
02193 {
02194 copy($file, $a_target_dir."/index.html");
02195 }
02196
02197
02198 $ilBench->start("ExportHTML", "getCurrentFrameSet");
02199 $frameset = $a_lm_gui->getCurrentFrameSet();
02200 $ilBench->stop("ExportHTML", "getCurrentFrameSet");
02201
02202 foreach ($frameset as $frame)
02203 {
02204 $this->exportPageHTML($a_lm_gui, $a_target_dir, $a_lm_page_id, $frame);
02205 }
02206
02207 }
02208
02215 function exportFO(&$a_xml_writer, $a_target_dir)
02216 {
02217 global $ilBench;
02218
02219
02220 $attrs = array();
02221 $attrs["xmlns:fo"] = "http://www.w3.org/1999/XSL/Format";
02222 $a_xml_writer->xmlStartTag("fo:root", $attrs);
02223
02224
02225 $attrs = array();
02226 $a_xml_writer->xmlStartTag("fo:layout-master-set", $attrs);
02227
02228
02229 $attrs = array();
02230 $attrs["master-name"] = "DinA4";
02231 $attrs["page-height"] = "29.7cm";
02232 $attrs["page-width"] = "21cm";
02233 $attrs["margin-top"] = "4cm";
02234 $attrs["margin-bottom"] = "1cm";
02235 $attrs["margin-left"] = "2.8cm";
02236 $attrs["margin-right"] = "7.3cm";
02237 $a_xml_writer->xmlStartTag("fo:simple-page-master", $attrs);
02238
02239
02240 $attrs = array();
02241 $attrs["margin-top"] = "0cm";
02242 $attrs["margin-bottom"] = "1.25cm";
02243 $a_xml_writer->xmlElement("fo:region-body", $attrs);
02244
02245
02246 $attrs = array();
02247 $attrs["extent"] = "1cm";
02248 $a_xml_writer->xmlElement("fo:region-before", $attrs);
02249
02250
02251 $attrs = array();
02252 $attrs["extent"] = "1cm";
02253 $a_xml_writer->xmlElement("fo:region-after", $attrs);
02254
02255
02256 $a_xml_writer->xmlEndTag("fo:simple-page-master");
02257
02258
02259 $a_xml_writer->xmlEndTag("fo:layout-master-set");
02260
02261
02262 $attrs = array();
02263 $attrs["master-reference"] = "DinA4";
02264 $a_xml_writer->xmlStartTag("fo:page-sequence", $attrs);
02265
02266
02267 $attrs = array();
02268 $attrs["flow-name"] = "xsl-region-body";
02269 $a_xml_writer->xmlStartTag("fo:flow", $attrs);
02270
02271
02272
02273
02274 $ilBench->start("ContentObjectExport", "exportFOStructureObjects");
02275 $this->exportFOStructureObjects($a_xml_writer, $expLog);
02276 $ilBench->stop("ContentObjectExport", "exportFOStructureObjects");
02277
02278
02279
02280 $a_xml_writer->xmlEndTag("fo:flow");
02281
02282
02283 $a_xml_writer->xmlEndTag("fo:page-sequence");
02284
02285
02286 $a_xml_writer->xmlEndTag("fo:root");
02287 }
02288
02295 function exportFOStructureObjects(&$a_xml_writer)
02296 {
02297 $childs = $this->lm_tree->getChilds($this->lm_tree->getRootId());
02298 foreach ($childs as $child)
02299 {
02300 if($child["type"] != "st")
02301 {
02302 continue;
02303 }
02304
02305 $structure_obj = new ilStructureObject($this, $child["obj_id"]);
02306 $structure_obj->exportFO($a_xml_writer, $expLog);
02307 unset($structure_obj);
02308 }
02309 }
02310
02311 function getXMLZip()
02312 {
02313 include_once("./content/classes/class.ilContObjectExport.php");
02314
02315 $cont_exp = new ilContObjectExport($this,'xml');
02316
02317 $export_file = $cont_exp->buildExportFile();
02318 return $export_file;
02319 }
02320
02321
02322 }
02323 ?>