• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

content/classes/class.ilObjContentObject.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 
00037 require_once "classes/class.ilObject.php";
00038 require_once "classes/class.ilMetaData.php";
00039 require_once("classes/class.ilNestedSetXML.php");
00040 //require_once("content/classes/class.ilPageObject.php");
00041 
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                 // this also calls read() method! (if $a_id is set)
00060                 $this->ilObject($a_id,$a_call_by_reference);
00061 
00062                 if ($a_id == 0)
00063                 {
00064                         $this->initMeta();
00065                 }
00066 
00067                 $this->mob_ids = array();
00068                 $this->file_ids = array();
00069         }
00070 
00074         function initMeta()
00075         {
00076                 if (!is_object($this->meta_data))
00077                 {
00078                         if ($this->getId())
00079                         {
00080                                 $new_meta =& new ilMetaData($this->getType(), $this->getId());
00081                         }
00082                         else
00083                         {
00084                                 $new_meta =& new ilMetaData();
00085                         }
00086                         $this->assignMetaData($new_meta);
00087                 }
00088         }
00089 
00093         function create($a_upload = false)
00094         {
00095                 global $ilUser;
00096 
00097                 parent::create();
00098                 $this->createProperties();
00099                 if (!$a_upload)
00100                 {
00101                         if (is_object($ilUser))
00102                         {
00103                                 //$this->meta_data->setLanguage($ilUser->getLanguage());
00104                         }
00105                         $this->initMeta();
00106                         $this->meta_data->setId($this->getId());
00107                         $this->meta_data->setType($this->getType());
00108                         $this->meta_data->setTitle($this->getTitle());
00109                         $this->meta_data->setDescription($this->getDescription());
00110                         $this->meta_data->setObject($this);
00111                         $this->meta_data->create();
00112                 }
00113         }
00114 
00121         function initDefaultRoles()
00122         {
00123                 return array();
00124 
00125                 global $rbacadmin, $rbacreview;
00126 
00127                 // create a local role folder
00128                 $rfoldObj = $this->createRoleFolder("Local roles","Role Folder of content object ".$this->getId());
00129 
00130                 // note: we don't need any roles here, local "author" roles must
00131                 // be created manually. subscription roles have been abandoned.
00132                 /*
00133                 // create author role and assign role to rolefolder...
00134                 $roleObj = $rfoldObj->createRole("author object ".$this->getRefId(),"author of content object ref id ".$this->getRefId());
00135                 $roles[] = $roleObj->getId();
00136 
00137                 // copy permissions from author template to new role
00138                 $rbacadmin->copyRolePermission($this->getAuthorRoleTemplateId(), 8, $rfoldObj->getRefId(), $roleObj->getId());
00139 
00140                 // grant all allowed operations of role to current learning module
00141                 $rbacadmin->grantPermission($roleObj->getId(),
00142                         $rbacreview->getOperationsOfRole($roleObj->getId(), "lm", $rfoldObj->getRefId()),
00143                         $this->getRefId());*/
00144 
00145                 unset($rfoldObj);
00146                 //unset($roleObj);
00147 
00148                 return $roles ? $roles : array();
00149         }
00150 
00151 
00155         function read()
00156         {
00157                 parent::read();
00158 #               echo "Content<br>\n";
00159 
00160                 $this->lm_tree = new ilTree($this->getId());
00161                 $this->lm_tree->setTableNames('lm_tree','lm_data');
00162                 $this->lm_tree->setTreeTablePK("lm_id");
00163 
00164                 $this->readProperties();
00165                 //parent::read();
00166         }
00167 
00173         function getTitle()
00174         {
00175                 return parent::getTitle();
00176         }
00177 
00181         function setTitle($a_title)
00182         {
00183                 parent::setTitle($a_title);
00184                 $this->meta_data->setTitle($a_title);
00185         }
00186 
00192         function getDescription()
00193         {
00194                 return parent::getDescription();
00195         }
00196 
00200         function setDescription($a_description)
00201         {
00202                 parent::setDescription($a_description);
00203                 $this->meta_data->setDescription($a_description);
00204         }
00205 
00211         function assignMetaData(&$a_meta_data)
00212         {
00213                 $this->meta_data =& $a_meta_data;
00214         }
00215 
00221         function &getMetaData()
00222         {
00223                 $this->initMeta();
00224                 return $this->meta_data;
00225         }
00226 
00227 
00231         function updateMetaData()
00232         {
00233                 $this->initMeta();
00234                 $this->meta_data->update();
00235                 if ($this->meta_data->section != "General")
00236                 {
00237                         $meta = $this->meta_data->getElement("Title", "General");
00238                         $this->meta_data->setTitle($meta[0]["value"]);
00239                         $meta = $this->meta_data->getElement("Description", "General");
00240                         $this->meta_data->setDescription($meta[0]["value"]);
00241                 }
00242                 else
00243                 {
00244                         $this->setTitle($this->meta_data->getTitle());
00245                         $this->setDescription($this->meta_data->getDescription());
00246                 }
00247                 parent::update();
00248         }
00249 
00250         function getImportId()
00251         {
00252                 $this->initMeta();
00253                 return $this->meta_data->getImportIdentifierEntryID();
00254         }
00255 
00256         function setImportId($a_id)
00257         {
00258                 $this->initMeta();
00259                 $this->meta_data->setImportIdentifierEntryID($a_id);
00260         }
00261 
00262         function &getTree()
00263         {
00264                 return $this->lm_tree;
00265         }
00266 
00270         function update()
00271         {
00272                 $this->updateMetaData();
00273                 $this->updateProperties();
00274         }
00275 
00276 
00280         function import()
00281         {
00282                 // nothing to do. just display the dialogue in Out
00283                 return;
00284         }
00285 
00286 
00291         function putInTree($a_parent)
00292         {
00293                 global $tree;
00294 
00295                 // put this object in tree under $a_parent
00296                 parent::putInTree($a_parent);
00297 
00298                 // make new tree for this object
00299                 //$tree->addTree($this->getId());
00300         }
00301 
00302 
00308         function createLMTree()
00309         {
00310                 $this->lm_tree =& new ilTree($this->getId());
00311                 $this->lm_tree->setTreeTablePK("lm_id");
00312                 $this->lm_tree->setTableNames('lm_tree','lm_data');
00313                 $this->lm_tree->addTree($this->getId(), 1);
00314         }
00315 
00316 
00320         function &getLMTree()
00321         {
00322                 return $this->lm_tree;
00323         }
00324 
00325 
00331         function createImportDirectory()
00332         {
00333                 $lm_data_dir = ilUtil::getDataDir()."/lm_data";
00334                 if(!is_writable($lm_data_dir))
00335                 {
00336                         $this->ilias->raiseError("Content object Data Directory (".$lm_data_dir
00337                                 .") not writeable.",$this->ilias->error_obj->FATAL);
00338                 }
00339 
00340                 // create learning module directory (data_dir/lm_data/lm_<id>)
00341                 $lm_dir = $lm_data_dir."/lm_".$this->getId();
00342                 ilUtil::makeDir($lm_dir);
00343                 if(!@is_dir($lm_dir))
00344                 {
00345                         $this->ilias->raiseError("Creation of Learning Module Directory failed.",$this->ilias->error_obj->FATAL);
00346                 }
00347 
00348                 // create import subdirectory (data_dir/lm_data/lm_<id>/import)
00349                 $import_dir = $lm_dir."/import";
00350                 ilUtil::makeDir($import_dir);
00351                 if(!@is_dir($import_dir))
00352                 {
00353                         $this->ilias->raiseError("Creation of Import Directory failed.",$this->ilias->error_obj->FATAL);
00354                 }
00355         }
00356 
00360         function getDataDirectory()
00361         {
00362                 return ilUtil::getDataDir()."/lm_data".
00363                         "/lm_".$this->getId();
00364         }
00365 
00369         function getImportDirectory()
00370         {
00371                 $import_dir = ilUtil::getDataDir()."/lm_data".
00372                         "/lm_".$this->getId()."/import";
00373                 if(@is_dir($import_dir))
00374                 {
00375                         return $import_dir;
00376                 }
00377                 else
00378                 {
00379                         return false;
00380                 }
00381         }
00382 
00383 
00389         function createExportDirectory($a_type = "xml")
00390         {
00391                 $lm_data_dir = ilUtil::getDataDir()."/lm_data";
00392                 if(!is_writable($lm_data_dir))
00393                 {
00394                         $this->ilias->raiseError("Content object Data Directory (".$lm_data_dir
00395                                 .") not writeable.",$this->ilias->error_obj->FATAL);
00396                 }
00397                 // create learning module directory (data_dir/lm_data/lm_<id>)
00398                 $lm_dir = $lm_data_dir."/lm_".$this->getId();
00399                 ilUtil::makeDir($lm_dir);
00400                 if(!@is_dir($lm_dir))
00401                 {
00402                         $this->ilias->raiseError("Creation of Learning Module Directory failed.",$this->ilias->error_obj->FATAL);
00403                 }
00404                 // create Export subdirectory (data_dir/lm_data/lm_<id>/Export)
00405                 switch ($a_type)
00406                 {
00407                         // html
00408                         case "html":
00409                                 $export_dir = $lm_dir."/export_html";
00410                                 break;
00411 
00412                         // scorm
00413                         case "scorm":
00414                                 $export_dir = $lm_dir."/export_scorm";
00415                                 break;
00416                                 
00417                         default:                // = xml
00418                                 $export_dir = $lm_dir."/export";
00419                                 break;
00420                 }
00421                 ilUtil::makeDir($export_dir);
00422                                 
00423                 if(!@is_dir($export_dir))
00424                 {
00425                         $this->ilias->raiseError("Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
00426                 }
00427         }
00428 
00432         function getExportDirectory($a_type = "xml")
00433         {
00434                 switch  ($a_type)
00435                 {
00436                         case "html":
00437                                 $export_dir = ilUtil::getDataDir()."/lm_data"."/lm_".$this->getId()."/export_html";
00438                                 break;
00439 
00440                         case "scorm":
00441                                 $export_dir = ilUtil::getDataDir()."/lm_data"."/lm_".$this->getId()."/export_scorm";
00442                                 break;
00443                                 
00444                         default:                        // = xml
00445                                 $export_dir = ilUtil::getDataDir()."/lm_data"."/lm_".$this->getId()."/export";
00446                                 break;
00447                 }
00448                 return $export_dir;
00449         }
00450 
00457         function ilClone($a_parent_ref)
00458         {
00459                 global $rbacadmin;
00460 
00461                 // always call parent ilClone function first!!
00462                 $new_ref_id = parent::ilClone($a_parent_ref);
00463 
00464                 // todo: put here lm specific stuff
00465 
00466                 // ... and finally always return new reference ID!!
00467                 return $new_ref_id;
00468         }
00469 
00480         function delete()
00481         {
00482                 global $ilDB;
00483 
00484                 global $ilBench;
00485 
00486                 #$ilBench->start('NestedSet','lm_delete');
00487 
00488                 // always call parent delete function first!!
00489                 if (!parent::delete())
00490                 {
00491                         return false;
00492                 }
00493 
00494                 #$ilBench->start('NestedSet','delete_all_object_data');
00495                 // delete lm object data
00496                 include_once("content/classes/class.ilLMObject.php");
00497                 ilLMObject::_deleteAllObjectData($this);
00498                 #$ilBench->stop('NestedSet','delete_all_object_data');
00499 
00500 
00501                 // delete meta data of content object
00502                 $nested = new ilNestedSetXML();
00503                 $nested->init($this->getId(), $this->getType());
00504                 $nested->deleteAllDBData();
00505                 
00506 
00507                 // delete bibitem data
00508                 $nested = new ilNestedSetXML();
00509                 $nested->init($this->getId(), "bib");
00510                 $nested->deleteAllDBData();
00511 
00512                 
00513                 // delete learning module tree
00514                 $this->lm_tree->removeTree($this->lm_tree->getTreeId());
00515 
00516                 // delete data directory
00517                 ilUtil::delDir($this->getDataDirectory());
00518 
00519                 // delete content object record
00520                 $q = "DELETE FROM content_object WHERE id = ".$ilDB->quote($this->getId());
00521                 $this->ilias->db->query($q);
00522 
00523                 // delete lm menu entries
00524                 $q = "DELETE FROM lm_menu WHERE lm_id = ".$ilDB->quote($this->getId());
00525                 $this->ilias->db->query($q);
00526 
00527                 #$ilBench->stop('NestedSet','lm_delete');
00528                 #$ilBench->save();
00529         
00530                 return true;
00531         }
00532 
00538         function getLayout()
00539         {
00540                 return $this->layout;
00541         }
00542 
00548         function setLayout($a_layout)
00549         {
00550                 $this->layout = $a_layout;
00551         }
00552 
00556         function getStyleSheetId()
00557         {
00558                 return $this->style_id;
00559         }
00560 
00564         function setStyleSheetId($a_style_id)
00565         {
00566                 $this->style_id = $a_style_id;
00567         }
00568 
00572         function writeStyleSheetId($a_style_id)
00573         {
00574                 global $ilDB;
00575                 
00576                 $q = "UPDATE content_object SET ".
00577                         " stylesheet = ".$ilDB->quote($a_style_id).
00578                         " WHERE id = '".$this->getId()."'";
00579                 $ilDB->query($q);
00580 
00581                 $this->style_id = $a_style_id;
00582         }
00583 
00587         function _lookupStyleSheetId($a_cont_obj_id)
00588         {
00589                 global $ilDB;
00590                 
00591                 $q = "SELECT stylesheet FROM content_object ".
00592                         " WHERE id = '".$a_cont_obj_id."'";
00593                 $res = $ilDB->query($q);
00594                 $sheet = $res->fetchRow(DB_FETCHMODE_ASSOC);
00595 
00596                 return $sheet["stylesheet"];
00597         }
00598         
00599         
00605         function _deleteStyleAssignments($a_style_id)
00606         {
00607                 global $ilDB;
00608                 
00609                 $q = "UPDATE content_object SET ".
00610                         " stylesheet = ".$ilDB->quote("0").
00611                         " WHERE stylesheet = ".$this->getId($a_style_id);
00612 
00613                 $ilDB->query($q);
00614         }
00615 
00619         function getPageHeader()
00620         {
00621                 return $this->pg_header;
00622         }
00623 
00629         function setPageHeader($a_pg_header = IL_CHAPTER_TITLE)
00630         {
00631                 $this->pg_header = $a_pg_header;
00632         }
00633 
00637         function getTOCMode()
00638         {
00639                 return $this->toc_mode;
00640         }
00641         
00645         function getPublicAccessMode()
00646         {
00647                 return $this->public_access_mode;
00648         }
00649 
00655         function setTOCMode($a_toc_mode = "chapters")
00656         {
00657                 $this->toc_mode = $a_toc_mode;
00658         }
00659 
00660         function setOnline($a_online)
00661         {
00662                 $this->online = $a_online;
00663         }
00664 
00665         function getOnline()
00666         {
00667                 return $this->online;
00668         }
00669 
00670         function setActiveLMMenu($a_act_lm_menu)
00671         {
00672                 $this->lm_menu_active = $a_act_lm_menu;
00673         }
00674 
00675         function isActiveLMMenu()
00676         {
00677                 return $this->lm_menu_active;
00678         }
00679 
00680         function setActiveTOC($a_toc)
00681         {
00682                 $this->toc_active = $a_toc;
00683         }
00684 
00685         function isActiveTOC()
00686         {
00687                 return $this->toc_active;
00688         }
00689 
00690         function setActiveNumbering($a_num)
00691         {
00692                 $this->numbering = $a_num;
00693         }
00694 
00695         function isActiveNumbering()
00696         {
00697                 return $this->numbering;
00698         }
00699 
00700         function setActivePrintView($a_print)
00701         {
00702                 $this->print_view_active = $a_print;
00703         }
00704 
00705         function isActivePrintView()
00706         {
00707                 return $this->print_view_active;
00708         }
00709 
00710         function setActiveDownloads($a_down)
00711         {
00712                 $this->downloads_active = $a_down;
00713         }
00714 
00715         function isActiveDownloads()
00716         {
00717                 return $this->downloads_active;
00718         }
00719 
00720         function setCleanFrames($a_clean)
00721         {
00722                 $this->clean_frames = $a_clean;
00723         }
00724 
00725         function cleanFrames()
00726         {
00727                 return $this->clean_frames;
00728         }
00729         
00730         function setHistoryUserComments($a_comm)
00731         {
00732                 $this->user_comments = $a_comm;
00733         }
00734 
00735         function setPublicAccessMode($a_mode)
00736         {
00737                 $this->public_access_mode = $a_mode;
00738         }
00739 
00740         function isActiveHistoryUserComments()
00741         {
00742                 return $this->user_comments;
00743         }
00744 
00748         function readProperties()
00749         {
00750                 $q = "SELECT * FROM content_object WHERE id = '".$this->getId()."'";
00751                 $lm_set = $this->ilias->db->query($q);
00752                 $lm_rec = $lm_set->fetchRow(DB_FETCHMODE_ASSOC);
00753                 $this->setLayout($lm_rec["default_layout"]);
00754                 $this->setStyleSheetId($lm_rec["stylesheet"]);
00755                 $this->setPageHeader($lm_rec["page_header"]);
00756                 $this->setTOCMode($lm_rec["toc_mode"]);
00757                 $this->setOnline(ilUtil::yn2tf($lm_rec["online"]));
00758                 $this->setActiveTOC(ilUtil::yn2tf($lm_rec["toc_active"]));
00759                 $this->setActiveNumbering(ilUtil::yn2tf($lm_rec["numbering"]));
00760                 $this->setActivePrintView(ilUtil::yn2tf($lm_rec["print_view_active"]));
00761                 $this->setActiveDownloads(ilUtil::yn2tf($lm_rec["downloads_active"]));
00762                 $this->setActiveLMMenu(ilUtil::yn2tf($lm_rec["lm_menu_active"]));
00763                 $this->setCleanFrames(ilUtil::yn2tf($lm_rec["clean_frames"]));
00764                 $this->setHistoryUserComments(ilUtil::yn2tf($lm_rec["hist_user_comments"]));
00765                 $this->setPublicAccessMode($lm_rec["public_access_mode"]);
00766                 $this->setPublicExportFile("xml", $lm_rec["public_xml_file"]);
00767                 $this->setPublicExportFile("html", $lm_rec["public_html_file"]);
00768         }
00769 
00773         function updateProperties()
00774         {
00775                 $q = "UPDATE content_object SET ".
00776                         " default_layout = '".$this->getLayout()."', ".
00777                         " stylesheet = '".$this->getStyleSheetId()."',".
00778                         " page_header = '".$this->getPageHeader()."',".
00779                         " toc_mode = '".$this->getTOCMode()."',".
00780                         " online = '".ilUtil::tf2yn($this->getOnline())."',".
00781                         " toc_active = '".ilUtil::tf2yn($this->isActiveTOC())."',".
00782                         " numbering = '".ilUtil::tf2yn($this->isActiveNumbering())."',".
00783                         " print_view_active = '".ilUtil::tf2yn($this->isActivePrintView())."',".
00784                         " downloads_active = '".ilUtil::tf2yn($this->isActiveDownloads())."',".
00785                         " clean_frames = '".ilUtil::tf2yn($this->cleanFrames())."',".
00786                         " hist_user_comments = '".ilUtil::tf2yn($this->isActiveHistoryUserComments())."',".
00787                         " public_access_mode = '".$this->getPublicAccessMode()."',".
00788                         " public_xml_file = '".$this->getPublicExportFile("xml")."',".
00789                         " public_html_file = '".$this->getPublicExportFile("html")."',".
00790                         " lm_menu_active = '".ilUtil::tf2yn($this->isActiveLMMenu())."'".
00791                         " WHERE id = '".$this->getId()."'";
00792                 $this->ilias->db->query($q);
00793         }
00794 
00798         function createProperties()
00799         {
00800                 $q = "INSERT INTO content_object (id) VALUES ('".$this->getId()."')";
00801                 $this->ilias->db->query($q);
00802                 $this->readProperties();                // to get db default values
00803         }
00804 
00808         function _lookupOnline($a_id)
00809         {
00810                 $q = "SELECT * FROM content_object WHERE id = '".$a_id."'";
00811                 $lm_set = $this->ilias->db->query($q);
00812                 $lm_rec = $lm_set->fetchRow(DB_FETCHMODE_ASSOC);
00813 
00814                 return ilUtil::yn2tf($lm_rec["online"]);
00815         }
00816 
00822         function getAvailableLayouts()
00823         {
00824                 // read sdir, copy files and copy directories recursively
00825                 $dir = opendir("./layouts/lm");
00826 
00827                 $layouts = array();
00828 
00829                 while($file = readdir($dir))
00830                 {
00831                         if ($file != "." && $file != ".." && $file != "CVS")
00832                         {
00833                                 // directories
00834                                 if (@is_dir("./layouts/lm/".$file))
00835                                 {
00836                                         $layouts[$file] = $file;
00837                                 }
00838                         }
00839                 }
00840                 asort($layouts);
00841                 return $layouts;
00842         }
00843 
00847         function _checkPreconditionsOfPage($cont_obj_id, $page_id)
00848         {
00849                 global $ilias,$ilUser,$ilErr;
00850 
00851                 $lm_tree = new ilTree($cont_obj_id);
00852                 $lm_tree->setTableNames('lm_tree','lm_data');
00853                 $lm_tree->setTreeTablePK("lm_id");
00854 
00855                 if ($lm_tree->isInTree($page_id))
00856                 {
00857                         $path = $lm_tree->getPathFull($page_id, $lm_tree->readRootId());
00858                         foreach ($path as $node)
00859                         {
00860                                 if ($node["type"] == "st")
00861                                 {
00862                                         if (!ilConditionHandler::_checkAllConditionsOfTarget($node["child"], "st"))
00863                                         {
00864                                                 return false;
00865                                         }
00866                                 }
00867                         }
00868                 }
00869                 
00870                 return true;
00871         }
00872 
00876         function _getMissingPreconditionsOfPage($cont_obj_id, $page_id)
00877         {
00878                 $lm_tree = new ilTree($cont_obj_id);
00879                 $lm_tree->setTableNames('lm_tree','lm_data');
00880                 $lm_tree->setTreeTablePK("lm_id");
00881 
00882                 $conds = array();
00883                 if ($lm_tree->isInTree($page_id))
00884                 {
00885                         // get full path of page
00886                         $path = $lm_tree->getPathFull($page_id, $lm_tree->readRootId());
00887                         foreach ($path as $node)
00888                         {
00889                                 if ($node["type"] == "st")
00890                                 {
00891                                         // get all preconditions of upper chapters
00892                                         $tconds = ilConditionHandler::_getConditionsOfTarget($node["child"], "st");
00893                                         foreach ($tconds as $tcond)
00894                                         {
00895                                                 // store all missing preconditions
00896                                                 if (!ilConditionHandler::_checkCondition($tcond["id"]))
00897                                                 {
00898                                                         $conds[] = $tcond;
00899                                                 }
00900                                         }
00901                                 }
00902                         }
00903                 }
00904                 
00905                 return $conds;
00906         }
00907 
00911         function _getMissingPreconditionsTopChapter($cont_obj_id, $page_id)
00912         {
00913                 $lm_tree = new ilTree($cont_obj_id);
00914                 $lm_tree->setTableNames('lm_tree','lm_data');
00915                 $lm_tree->setTreeTablePK("lm_id");
00916 
00917                 $conds = array();
00918                 if ($lm_tree->isInTree($page_id))
00919                 {
00920                         // get full path of page
00921                         $path = $lm_tree->getPathFull($page_id, $lm_tree->readRootId());
00922                         foreach ($path as $node)
00923                         {
00924                                 if ($node["type"] == "st")
00925                                 {
00926                                         // get all preconditions of upper chapters
00927                                         $tconds = ilConditionHandler::_getConditionsOfTarget($node["child"], "st");
00928                                         foreach ($tconds as $tcond)
00929                                         {
00930                                                 // look for missing precondition
00931                                                 if (!ilConditionHandler::_checkCondition($tcond["id"]))
00932                                                 {
00933                                                         return $node["child"];
00934                                                 }
00935                                         }
00936                                 }
00937                         }
00938                 }
00939                 
00940                 return "";
00941         }
00942 
00953         function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
00954         {
00955                 global $tree;
00956                 
00957                 switch ($a_event)
00958                 {
00959                         case "link":
00960 
00961                                 //var_dump("<pre>",$a_params,"</pre>");
00962                                 //echo "Content Object ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
00963                                 //exit;
00964                                 break;
00965                         
00966                         case "cut":
00967                                 
00968                                 //echo "Content Object ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
00969                                 //exit;
00970                                 break;
00971                                 
00972                         case "copy":
00973                         
00974                                 //var_dump("<pre>",$a_params,"</pre>");
00975                                 //echo "Content Object ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
00976                                 //exit;
00977                                 break;
00978 
00979                         case "paste":
00980                                 
00981                                 //echo "Content Object ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
00982                                 //exit;
00983                                 break;
00984                         
00985                         case "new":
00986                                 
00987                                 //echo "Content Object ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
00988                                 //exit;
00989                                 break;
00990                 }
00991 
00992                 // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
00993                 if ($a_node_id==$_GET["ref_id"])
00994                 {       
00995                         $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
00996                         $parent_type = $parent_obj->getType();
00997                         if($parent_type == $this->getType())
00998                         {
00999                                 $a_node_id = (int) $tree->getParentId($a_node_id);
01000                         }
01001                 }
01002                 
01003                 parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
01004         }
01005 
01013         function _search(&$search_obj,$a_search_in)
01014         {
01015                 global $ilBench;
01016 
01017                 switch($a_search_in)
01018                 {
01019                         case 'meta':
01020                                 // FILTER ALL DBK OBJECTS
01021                                 $in             = $search_obj->getInStatement("r.ref_id");
01022                                 $where  = $search_obj->getWhereCondition("fulltext",array("xv.tag_value"));
01023 
01024                                 /* very slow on mysql < 4.0.18 (? or everytime ?)
01025                                 $query = "SELECT DISTINCT(r.ref_id) FROM object_reference AS r,object_data AS o, ".
01026                                         "lm_data AS l,xmlnestedset AS xm,xmlvalue AS xv ".
01027                                         $where.
01028                                         $in.
01029                                         "AND r.obj_id=o.obj_id AND ((o.obj_id=l.lm_id AND xm.ns_book_fk=l.obj_id) OR ".
01030                                         "(o.obj_id=xm.ns_book_fk AND xm.ns_type IN ('lm','bib'))) ".
01031                                         "AND xm.ns_tag_fk=xv.tag_fk ".
01032                                         "AND o.type= 'lm'";*/
01033 
01034                                 $query1 = "SELECT DISTINCT(r.ref_id) FROM object_reference AS r,object_data AS o, ".
01035                                         "xmlnestedset AS xm,xmlvalue AS xv ".
01036                                         $where.
01037                                         $in.
01038                                         "AND r.obj_id=o.obj_id AND ( ".
01039                                         "(o.obj_id=xm.ns_book_fk AND xm.ns_type IN ('lm','bib'))) ".
01040                                         "AND xm.ns_tag_fk=xv.tag_fk ".
01041                                         "AND o.type= 'lm'";
01042 
01043                                 // BEGINNING SELECT WITH SEARCH RESULTS IS MUCH FASTER
01044                                 $query1 = "SELECT DISTINCT(r.ref_id) as ref_id FROM xmlvalue AS xv ".
01045                                         "LEFT JOIN xmlnestedset AS xm ON xm.ns_tag_fk=xv.tag_fk ".
01046                                         "LEFT JOIN object_data AS o ON o.obj_id = xm.ns_book_fk ".
01047                                         "LEFT JOIN object_reference AS r ON o.obj_id = r.obj_id ".
01048                                         $where.
01049                                         $in.
01050                                         " AND o.type = 'lm' AND xm.ns_type IN ('lm','bib')";
01051 
01052                                 $query2 = "SELECT DISTINCT(r.ref_id) FROM object_reference AS r,object_data AS o, ".
01053                                         "lm_data AS l,xmlnestedset AS xm,xmlvalue AS xv ".
01054                                         $where.
01055                                         $in.
01056                                         "AND r.obj_id=o.obj_id AND ((o.obj_id=l.lm_id AND xm.ns_book_fk=l.obj_id)".
01057                                         ") ".
01058                                         "AND xm.ns_tag_fk=xv.tag_fk ".
01059                                         "AND o.type= 'lm'";
01060 
01061                                 $query2 = "SELECT DISTINCT(r.ref_id) as ref_id FROM xmlvalue AS xv ".
01062                                         "LEFT JOIN xmlnestedset AS xm ON xm.ns_tag_fk = xv.tag_fk ".
01063                                         "LEFT JOIN lm_data AS l ON l.obj_id = xm.ns_book_fk ".
01064                                         "LEFT JOIN object_data AS o ON o.obj_id = l.lm_id ".
01065                                         "LEFT JOIN object_reference AS r ON r.obj_id = o.obj_id ".
01066                                         $where.
01067                                         $in.
01068                                         "AND o.type = 'lm'";
01069 
01070                                 $ilBench->start("Search", "ilObjContentObject_search_meta");
01071                                 $res1 = $search_obj->ilias->db->query($query1);
01072                                 $res2 = $search_obj->ilias->db->query($query2);
01073                                 $ilBench->stop("Search", "ilObjContentObject_search_meta");
01074 
01075                                 $counter = 0;
01076                                 $ids = array();
01077                                 while($row = $res1->fetchRow(DB_FETCHMODE_OBJECT))
01078                                 {
01079                                         $ids[] = $row->ref_id;
01080                                         $result[$counter]["id"]         =  $row->ref_id;
01081                                         ++$counter;
01082                                 }
01083                                 while($row = $res2->fetchRow(DB_FETCHMODE_OBJECT))
01084                                 {
01085                                         if(in_array($row->ref_id,$ids))
01086                                         {
01087                                                 continue;
01088                                         }
01089                                         $result[$counter]["id"]         =  $row->ref_id;
01090                                         ++$counter;
01091                                 }
01092                                 break;
01093 
01094                         case 'content':
01095                                 $in             = $search_obj->getInStatement("r.ref_id");
01096                                 $where  = $search_obj->getWhereCondition("fulltext",array("pg.content"));
01097 
01098                                 // slow on mysql < 4.0.18 (join bug)
01099                                 /*
01100                                 $query = "SELECT DISTINCT(r.ref_id) AS ref_id ,pg.page_id AS page_id FROM page_object AS pg ".
01101                                         "INNER JOIN object_reference AS r ON pg.parent_id = r.obj_id ".
01102                                         $where.
01103                                         $in.
01104                                         "AND pg.parent_type = 'lm' ";*/
01105 
01106                                 $query = "SELECT DISTINCT(r.ref_id) AS ref_id ,pg.page_id AS page_id FROM page_object AS pg ".
01107                                         ", object_reference AS r ".
01108                                         $where.
01109                                         " AND pg.parent_id = r.obj_id ".
01110                                         $in.
01111                                         " AND pg.parent_type = 'lm' ";
01112 
01113                                 $query = "SELECT DISTINCT(r.ref_id) AS ref_id ,pg.page_id AS page_id FROM page_object AS pg ".
01114                                         "LEFT JOIN object_data AS o ON o.obj_id = pg.parent_id ".
01115                                         "LEFT JOIN object_reference AS r ON o.obj_id = r.obj_id ".
01116                                         $where.
01117                                         $in.
01118                                         " AND pg.parent_type = 'lm'";
01119 
01120                                 $ilBench->start("Search", "ilObjContentObject_search_content");
01121                                 $res = $search_obj->ilias->db->query($query);
01122                                 $ilBench->stop("Search", "ilObjContentObject_search_content");
01123 
01124                                 $counter = 0;
01125                                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
01126                                 {
01127                                         $result[$counter]["id"]         = $row->ref_id;
01128                                         $result[$counter]["page_id"] = $row->page_id;
01129                                         /*
01130                                         $result[$counter]["link"]       = "content/lm_presentation.php?ref_id=".$row->ref_id;
01131                                         $result[$counter]["target"]     = "_top";
01132                                         */
01133                                         ++$counter;
01134                                 }
01135                                 break;
01136                 }
01137                 return $result ? $result : array();
01138         }
01139 
01150         function _getLinkToObject($a_ref_id,$a_type,$a_obj_id = 0)
01151         {
01152                 switch($a_type)
01153                 {
01154                         case "content":
01155                                 return array("content/lm_presentation.php?ref_id=".$a_ref_id."&obj_id=".$a_obj_id,"_blank");
01156                                 
01157                         case "meta":
01158                                 return array("content/lm_presentation.php?ref_id=".$a_ref_id,"_blank");
01159                 }
01160         }
01161 
01167         function _goto($a_target)
01168         {
01169                 global $rbacsystem, $ilErr, $lng;
01170 
01171                 include_once 'classes/class.ilSearch.php';
01172 
01173                 // Added this additional check (ParentConditions) to avoid calls of objects inside e.g courses.
01174                 // Will be replaced in future releases by ilAccess::checkAccess()
01175                 if ($rbacsystem->checkAccess("read", $a_target) and ilSearch::_checkParentConditions($a_target))
01176                 {
01177                         ilUtil::redirect("content/lm_presentation.php?ref_id=$a_target");
01178                 }
01179                 else
01180                 {
01181                         $ilErr->raiseError($lng->txt("msg_no_perm_read_lm"), $ilErr->FATAL);
01182                 }
01183         }
01184         
01188         function hasSuccessorPage($a_cont_obj_id, $a_page_id)
01189         {
01190                 $tree = new ilTree($a_cont_obj_id);
01191                 $tree->setTableNames('lm_tree','lm_data');
01192                 $tree->setTreeTablePK("lm_id");
01193                 if ($tree->isInTree($a_page_id))
01194                 {
01195                         $succ = $tree->fetchSuccessorNode($a_page_id, "pg");
01196                         if ($succ > 0)
01197                         {
01198                                 return true;
01199                         }
01200                 }
01201                 return false;
01202         }
01203 
01204         
01205         function checkTree()
01206         {
01207                 $tree = new ilTree($this->getId());
01208                 $tree->setTableNames('lm_tree','lm_data');
01209                 $tree->setTreeTablePK("lm_id");
01210                 $tree->checkTree();
01211                 $tree->checkTreeChilds();
01212 //echo "checked";
01213         }
01214 
01218         function fixTree()
01219         {
01220                 global $ilDB;
01221 
01222                 $tree =& $this->getLMTree();
01223 
01224                 // delete subtrees that have no lm_data records
01225                 $nodes = $tree->getSubtree($tree->getNodeData($tree->getRootId()));
01226                 foreach ($nodes as $node)
01227                 {
01228                         $q = "SELECT * FROM lm_data WHERE obj_id = ".$ilDB->quote($node["child"]);
01229                         $obj_set = $ilDB->query($q);
01230                         $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
01231                         if (!$obj_rec)
01232                         {
01233                                 $node_data = $tree->getNodeData($node["child"]);
01234                                 $tree->deleteTree($node_data);
01235                         }
01236                 }
01237 
01238                 // delete subtrees that have pages as parent
01239                 $nodes = $tree->getSubtree($tree->getNodeData($tree->getRootId()));
01240                 foreach ($nodes as $node)
01241                 {
01242                         $q = "SELECT * FROM lm_data WHERE obj_id = ".$ilDB->quote($node["parent"]);
01243                         $obj_set = $ilDB->query($q);
01244                         $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
01245                         if ($obj_rec["type"] == "pg")
01246                         {
01247                                 $node_data = $tree->getNodeData($node["child"]);
01248                                 if ($tree->isInTree($node["child"]))
01249                                 {
01250                                         $tree->deleteTree($node_data);
01251                                 }
01252                         }
01253                 }
01254 
01255         }
01256 
01257 
01264         function exportXML(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
01265         {
01266                 global $ilBench;
01267 
01268                 $attrs = array();
01269                 switch($this->getType())
01270                 {
01271                         case "lm":
01272                                 $attrs["Type"] = "LearningModule";
01273                                 break;
01274 
01275                         case "dbk":
01276                                 $attrs["Type"] = "LibObject";
01277                                 break;
01278                 }
01279                 $a_xml_writer->xmlStartTag("ContentObject", $attrs);
01280 
01281                 // MetaData
01282                 $this->exportXMLMetaData($a_xml_writer);
01283 
01284                 // StructureObjects
01285 //echo "ContObj:".$a_inst.":<br>";
01286                 $expLog->write(date("[y-m-d H:i:s] ")."Start Export Structure Objects");
01287                 $ilBench->start("ContentObjectExport", "exportStructureObjects");
01288                 $this->exportXMLStructureObjects($a_xml_writer, $a_inst, $expLog);
01289                 $ilBench->stop("ContentObjectExport", "exportStructureObjects");
01290                 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Structure Objects");
01291 
01292                 // PageObjects
01293                 $expLog->write(date("[y-m-d H:i:s] ")."Start Export Page Objects");
01294                 $ilBench->start("ContentObjectExport", "exportPageObjects");
01295                 $this->exportXMLPageObjects($a_xml_writer, $a_inst, $expLog);
01296                 $ilBench->stop("ContentObjectExport", "exportPageObjects");
01297                 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Page Objects");
01298 
01299                 // MediaObjects
01300                 $expLog->write(date("[y-m-d H:i:s] ")."Start Export Media Objects");
01301                 $ilBench->start("ContentObjectExport", "exportMediaObjects");
01302                 $this->exportXMLMediaObjects($a_xml_writer, $a_inst, $a_target_dir, $expLog);
01303                 $ilBench->stop("ContentObjectExport", "exportMediaObjects");
01304                 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Media Objects");
01305 
01306                 // FileItems
01307                 $expLog->write(date("[y-m-d H:i:s] ")."Start Export File Items");
01308                 $ilBench->start("ContentObjectExport", "exportFileItems");
01309                 $this->exportFileItems($a_target_dir, $expLog);
01310                 $ilBench->stop("ContentObjectExport", "exportFileItems");
01311                 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export File Items");
01312 
01313                 // Glossary
01314                 // not implemented
01315 
01316                 // Bibliography
01317                 // not implemented
01318 
01319                 // Layout
01320                 // not implemented
01321 
01322                 $a_xml_writer->xmlEndTag("ContentObject");
01323         }
01324 
01331         function exportXMLMetaData(&$a_xml_writer)
01332         {
01333                 $nested = new ilNestedSetXML();
01334                 $nested->setParameterModifier($this, "modifyExportIdentifier");
01335                 $a_xml_writer->appendXML($nested->export($this->getId(),
01336                         $this->getType()));
01337         }
01338 
01339         function modifyExportIdentifier($a_tag, $a_param, $a_value)
01340         {
01341                 if ($a_tag == "Identifier" && $a_param == "Entry")
01342                 {
01343                         $a_value = ilUtil::insertInstIntoID($a_value);
01344                 }
01345 
01346                 return $a_value;
01347         }
01348 
01355         function exportXMLStructureObjects(&$a_xml_writer, $a_inst, &$expLog)
01356         {
01357                 include_once './content/classes/class.ilStructureObject.php';
01358 
01359                 $childs = $this->lm_tree->getChilds($this->lm_tree->getRootId());
01360                 foreach ($childs as $child)
01361                 {
01362                         if($child["type"] != "st")
01363                         {
01364                                 continue;
01365                         }
01366 
01367                         $structure_obj = new ilStructureObject($this, $child["obj_id"]);
01368                         $structure_obj->exportXML($a_xml_writer, $a_inst, $expLog);
01369                         unset($structure_obj);
01370                 }
01371         }
01372 
01373 
01380         function exportXMLPageObjects(&$a_xml_writer, $a_inst, &$expLog)
01381         {
01382                 global $ilBench;
01383 
01384                 include_once "./content/classes/class.ilLMPageObject.php";
01385 
01386                 $pages = ilLMPageObject::getPageList($this->getId());
01387                 foreach ($pages as $page)
01388                 {
01389                         $ilBench->start("ContentObjectExport", "exportPageObject");
01390                         $expLog->write(date("[y-m-d H:i:s] ")."Page Object ".$page["obj_id"]);
01391 
01392                         // export xml to writer object
01393                         $ilBench->start("ContentObjectExport", "exportPageObject_getLMPageObject");
01394                         $page_obj = new ilLMPageObject($this, $page["obj_id"]);
01395                         $ilBench->stop("ContentObjectExport", "exportPageObject_getLMPageObject");
01396                         $ilBench->start("ContentObjectExport", "exportPageObject_XML");
01397                         $page_obj->exportXML($a_xml_writer, "normal", $a_inst);
01398                         $ilBench->stop("ContentObjectExport", "exportPageObject_XML");
01399 
01400                         // collect media objects
01401                         $ilBench->start("ContentObjectExport", "exportPageObject_CollectMedia");
01402                         $mob_ids = $page_obj->getMediaObjectIDs();
01403                         foreach($mob_ids as $mob_id)
01404                         {
01405                                 $this->mob_ids[$mob_id] = $mob_id;
01406                         }
01407                         $ilBench->stop("ContentObjectExport", "exportPageObject_CollectMedia");
01408 
01409                         // collect all file items
01410                         $ilBench->start("ContentObjectExport", "exportPageObject_CollectFileItems");
01411                         $file_ids = $page_obj->getFileItemIds();
01412                         foreach($file_ids as $file_id)
01413                         {
01414                                 $this->file_ids[$file_id] = $file_id;
01415                         }
01416                         $ilBench->stop("ContentObjectExport", "exportPageObject_CollectFileItems");
01417 
01418                         unset($page_obj);
01419 
01420                         $ilBench->stop("ContentObjectExport", "exportPageObject");
01421                 }
01422         }
01423 
01430         function exportXMLMediaObjects(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
01431         {
01432                 include_once("content/classes/Media/class.ilObjMediaObject.php");
01433 
01434                 foreach ($this->mob_ids as $mob_id)
01435                 {
01436                         $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
01437                         $media_obj = new ilObjMediaObject($mob_id);
01438                         $media_obj->exportXML($a_xml_writer, $a_inst);
01439                         $media_obj->exportFiles($a_target_dir);
01440                         unset($media_obj);
01441                 }
01442         }
01443 
01448         function exportFileItems($a_target_dir, &$expLog)
01449         {
01450                 include_once("classes/class.ilObjFile.php");
01451 
01452                 foreach ($this->file_ids as $file_id)
01453                 {
01454                         $expLog->write(date("[y-m-d H:i:s] ")."File Item ".$file_id);
01455                         $file_obj = new ilObjFile($file_id, false);
01456                         $file_obj->export($a_target_dir);
01457                         unset($file_obj);
01458                 }
01459         }
01460 
01464         function getExportFiles()
01465         {
01466                 $file = array();
01467                 
01468                 $types = array("xml", "html", "scorm");
01469                 
01470                 foreach ($types as $type)
01471                 {
01472                         $dir = $this->getExportDirectory($type);
01473                         // quit if import dir not available
01474                         if (!@is_dir($dir) or
01475                                 !is_writeable($dir))
01476                         {
01477                                 continue;
01478                         }
01479         
01480                         // open directory
01481                         $cdir = dir($dir);
01482         
01483                         // initialize array
01484         
01485                         // get files and save the in the array
01486                         while ($entry = $cdir->read())
01487                         {
01488                                 if ($entry != "." and
01489                                         $entry != ".." and
01490                                         substr($entry, -4) == ".zip" and
01491                                         ereg("^[0-9]{10}_{2}[0-9]+_{2}(lm_)*[0-9]+\.zip\$", $entry))
01492                                 {
01493                                         $file[$entry.$type] = array("type" => $type, "file" => $entry,
01494                                                 "size" => filesize($dir."/".$entry));
01495                                 }
01496                         }
01497         
01498                         // close import directory
01499                         $cdir->close();
01500                 }
01501 
01502                 // sort files
01503                 ksort ($file);
01504                 reset ($file);
01505                 return $file;
01506         }
01507         
01514         function setPublicExportFile($a_type, $a_file)
01515         {
01516                 $this->public_export_file[$a_type] = $a_file;
01517         }
01518 
01526         function getPublicExportFile($a_type)
01527         {
01528                 return $this->public_export_file[$a_type];
01529         }
01530 
01534         function getOfflineFiles($dir)
01535         {
01536                 // quit if offline dir not available
01537                 if (!@is_dir($dir) or
01538                         !is_writeable($dir))
01539                 {
01540                         return array();
01541                 }
01542 
01543                 // open directory
01544                 $dir = dir($dir);
01545 
01546                 // initialize array
01547                 $file = array();
01548 
01549                 // get files and save the in the array
01550                 while ($entry = $dir->read())
01551                 {
01552                         if ($entry != "." and
01553                                 $entry != ".." and
01554                                 substr($entry, -4) == ".pdf" and
01555                                 ereg("^[0-9]{10}_{2}[0-9]+_{2}(lm_)*[0-9]+\.pdf\$", $entry))
01556                         {
01557                                 $file[] = $entry;
01558                         }
01559                 }
01560 
01561                 // close import directory
01562                 $dir->close();
01563 
01564                 // sort files
01565                 sort ($file);
01566                 reset ($file);
01567 
01568                 return $file;
01569         }
01570         
01574         function exportSCORM($a_target_dir, $log)
01575         {
01576                 ilUtil::delDir($a_target_dir);
01577                 ilUtil::makeDir($a_target_dir);
01578                 //ilUtil::makeDir($a_target_dir."/res");
01579                 
01580                 // export everything to html
01581                 $this->exportHTML($a_target_dir."/res", $log, false, "scorm");
01582                 
01583                 // build manifest file
01584                 include("content/classes/class.ilContObjectManifestBuilder.php");
01585                 $man_builder = new ilContObjectManifestBuilder($this);
01586                 $man_builder->buildManifest();
01587                 $man_builder->dump($a_target_dir);
01588                 
01589                 // copy scorm 1.2 schema definitions
01590                 copy("content/scorm_xsd/adlcp_rootv1p2.xsd", $a_target_dir."/adlcp_rootv1p2.xsd");
01591                 copy("content/scorm_xsd/imscp_rootv1p1p2.xsd", $a_target_dir."/imscp_rootv1p1p2.xsd");
01592                 copy("content/scorm_xsd/imsmd_rootv1p2p1.xsd", $a_target_dir."/imsmd_rootv1p2p1.xsd");
01593                 copy("content/scorm_xsd/ims_xml.xsd", $a_target_dir."/ims_xml.xsd");
01594 
01595                 // zip it all
01596                 $date = time();
01597                 $zip_file = $a_target_dir."/".$date."__".IL_INST_ID."__".
01598                         $this->getType()."_".$this->getId().".zip";
01599         //echo "zip-".$a_target_dir."-to-".$zip_file;
01600                 ilUtil::zip(array($a_target_dir."/res",
01601                         $a_target_dir."/imsmanifest.xml",
01602                         $a_target_dir."/adlcp_rootv1p2.xsd",
01603                         $a_target_dir."/imscp_rootv1p1p2.xsd",
01604                         $a_target_dir."/ims_xml.xsd",
01605                         $a_target_dir."/imsmd_rootv1p2p1.xsd")
01606                         , $zip_file);
01607 
01608                 $dest_file = $this->getExportDirectory("scorm")."/".$date."__".IL_INST_ID."__".
01609                         $this->getType()."_".$this->getId().".zip";
01610                 
01611                 rename($zip_file, $dest_file);
01612                 ilUtil::delDir($a_target_dir);
01613 
01614         }
01615 
01616         
01620         function exportHTML($a_target_dir, $log, $a_zip_file = true, $a_export_format = "html")
01621         {
01622                 global $ilias, $tpl;
01623 
01624                 // initialize temporary target directory
01625                 ilUtil::delDir($a_target_dir);
01626                 ilUtil::makeDir($a_target_dir);
01627                 $mob_dir = $a_target_dir."/mobs";
01628                 ilUtil::makeDir($mob_dir);
01629                 $file_dir = $a_target_dir."/files";
01630                 ilUtil::makeDir($file_dir);
01631 
01632                 // export system style sheet
01633                 $location_stylesheet = ilUtil::getStyleSheetLocation("filesystem");
01634                 $style_name = $ilias->account->prefs["style"].".css";
01635                 copy($location_stylesheet, $a_target_dir."/".$style_name);
01636                 $location_stylesheet = ilUtil::getStyleSheetLocation();
01637                 
01638                 // export content style sheet
01639                 if ($this->getStyleSheetId() < 1)
01640                 {
01641                         $cont_stylesheet = "content/content.css";
01642                         copy($cont_stylesheet, $a_target_dir."/content.css");
01643                 }
01644                 else
01645                 {
01646                         $style = new ilObjStyleSheet($this->getStyleSheetId());
01647                         $style->writeCSSFile($a_target_dir."/content.css");
01648                 }
01649                 
01650                 // export syntax highlighting style
01651                 $syn_stylesheet = "content/syntaxhighlight.css";
01652                 copy($syn_stylesheet, $a_target_dir."/syntaxhighlight.css");
01653 
01654                 // get learning module presentation gui class
01655                 include_once("content/classes/class.ilLMPresentationGUI.php");
01656                 $_GET["cmd"] = "nop";
01657                 $lm_gui =& new ilLMPresentationGUI();
01658                 $lm_gui->setOfflineMode(true);
01659                 $lm_gui->setExportFormat($a_export_format);
01660 
01661                 // export pages
01662                 $this->exportHTMLPages($lm_gui, $a_target_dir);
01663                 
01664                 // export glossary terms
01665                 $this->exportHTMLGlossaryTerms($lm_gui, $a_target_dir);
01666                 
01667                 // export all media objects
01668                 foreach ($this->offline_mobs as $mob)
01669                 {
01670                         $this->exportHTMLMOB($a_target_dir, $lm_gui, $mob, "_new");
01671                 }
01672                 $_GET["obj_type"]  = "MediaObject";
01673                 $_GET["obj_id"]  = $a_mob_id;
01674                 $_GET["cmd"] = "";
01675                 
01676                 // export all file objects
01677                 foreach ($this->offline_files as $file)
01678                 {
01679                         $this->exportHTMLFile($a_target_dir, $file);
01680                 }
01681                 
01682                 // export table of contents
01683                 if ($this->isActiveTOC())
01684                 {
01685                         $tpl = new ilTemplate("tpl.main.html", true, true);
01686                         //$tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
01687                         $content =& $lm_gui->showTableOfContents();
01688                         $file = $a_target_dir."/table_of_contents.html";
01689                                 
01690                         // open file
01691                         if (!($fp = @fopen($file,"w+")))
01692                         {
01693                                 die ("<b>Error</b>: Could not open \"".$file."\" for writing".
01694                                         " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
01695                         }
01696                         chmod($file, 0770);
01697                         fwrite($fp, $content);
01698                         fclose($fp);
01699                 }
01700 
01701                 // export images
01702                 $image_dir = $a_target_dir."/images";
01703                 ilUtil::makeDir($image_dir);
01704                 ilUtil::makeDir($image_dir."/browser");
01705                 copy(ilUtil::getImagePath("enlarge.gif", false, "filesystem"),
01706                         $image_dir."/enlarge.gif");
01707                 copy(ilUtil::getImagePath("browser/blank.gif", false, "filesystem"),
01708                         $image_dir."/browser/plus.gif");
01709                 copy(ilUtil::getImagePath("browser/blank.gif", false, "filesystem"),
01710                         $image_dir."/browser/minus.gif");
01711                 copy(ilUtil::getImagePath("browser/blank.gif", false, "filesystem"),
01712                         $image_dir."/browser/blank.gif");
01713                 copy(ilUtil::getImagePath("icon_st.gif", false, "filesystem"),
01714                         $image_dir."/icon_st.gif");
01715                 copy(ilUtil::getImagePath("icon_pg.gif", false, "filesystem"),
01716                         $image_dir."/icon_pg.gif");
01717                 copy(ilUtil::getImagePath("nav_arr_L.gif", false, "filesystem"),
01718                         $image_dir."/nav_arr_L.gif");
01719                 copy(ilUtil::getImagePath("nav_arr_R.gif", false, "filesystem"),
01720                         $image_dir."/nav_arr_R.gif");
01721                         
01722                 // template workaround: reset of template 
01723                 $tpl = new ilTemplate("tpl.main.html", true, true);
01724                 $tpl->setVariable("LOCATION_STYLESHEET",$location_stylesheet);
01725                 $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
01726                 
01727                 // zip everything
01728                 if ($a_zip_file)
01729                 {
01730                         // zip it all
01731                         $date = time();
01732                         $zip_file = $this->getExportDirectory("html")."/".$date."__".IL_INST_ID."__".
01733                                 $this->getType()."_".$this->getId().".zip";
01734 //echo "zip-".$a_target_dir."-to-".$zip_file;
01735                         ilUtil::zip($a_target_dir, $zip_file);
01736                         ilUtil::delDir($a_target_dir);
01737                 }
01738         }
01739         
01743         function exportHTMLFile($a_target_dir, $a_file_id)
01744         {
01745                 $file_dir = $a_target_dir."/files/file_".$a_file_id;
01746                 ilUtil::makeDir($file_dir);
01747                 include_once("classes/class.ilObjFile.php");
01748                 $file_obj = new ilObjFile($a_file_id, false);
01749                 $source_file = $file_obj->getDirectory($file_obj->getVersion())."/".$file_obj->getFileName();
01750                 if (!is_file($source_file))
01751                 {
01752                         $source_file = $file_obj->getDirectory()."/".$file_obj->getFileName();
01753                 }
01754                 copy($source_file, $file_dir."/".$file_obj->getFileName());
01755         }
01756 
01760         function exportHTMLMOB($a_target_dir, &$a_lm_gui, $a_mob_id, $a_frame = "")
01761         {
01762                 global $tpl;
01763 
01764                 $mob_dir = $a_target_dir."/mobs";
01765 
01766                 $source_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob_id;
01767                 if (@is_dir($source_dir))
01768                 {
01769                         ilUtil::makeDir($mob_dir."/mm_".$a_mob_id);
01770                         ilUtil::rCopy($source_dir, $mob_dir."/mm_".$a_mob_id);
01771                 }
01772                 
01773                 $tpl = new ilTemplate("tpl.main.html", true, true);
01774                 $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
01775                 $_GET["obj_type"]  = "MediaObject";
01776                 $_GET["mob_id"]  = $a_mob_id;
01777                 $_GET["frame"] = $a_frame;
01778                 $_GET["cmd"] = "";
01779                 $content =& $a_lm_gui->media();
01780                 $file = $a_target_dir."/media_".$a_mob_id.".html";
01781 
01782                 // open file
01783                 if (!($fp = @fopen($file,"w+")))
01784                 {
01785                         die ("<b>Error</b>: Could not open \"".$file."\" for writing".
01786                                 " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
01787                 }
01788                 chmod($file, 0770);
01789                 fwrite($fp, $content);
01790                 fclose($fp);
01791                 
01792                 // fullscreen
01793                 include_once("content/classes/Media/class.ilObjMediaObject.php");
01794                 $mob_obj = new ilObjMediaObject($a_mob_id);
01795                 if ($mob_obj->hasFullscreenItem())
01796                 {
01797                         $tpl = new ilTemplate("tpl.main.html", true, true);
01798                         $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
01799                         $_GET["obj_type"]  = "";
01800                         $_GET["frame"]  = "";
01801                         $_GET["mob_id"]  = $a_mob_id;
01802                         $_GET["cmd"] = "fullscreen";
01803                         $content =& $a_lm_gui->fullscreen();
01804                         $file = $a_target_dir."/fullscreen_".$a_mob_id.".html";
01805         
01806                         // open file
01807                         if (!($fp = @fopen($file,"w+")))
01808                         {
01809                                 die ("<b>Error</b>: Could not open \"".$file."\" for writing".
01810                                         " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
01811                         }
01812                         chmod($file, 0770);
01813                         fwrite($fp, $content);
01814                         fclose($fp);
01815                 }
01816         }
01817         
01821         function exportHTMLGlossaryTerms(&$a_lm_gui, $a_target_dir)
01822         {
01823                 foreach($this->offline_int_links as $int_link)
01824                 {
01825                         if ($int_link["type"] == "git")
01826                         {
01827                                 $tpl = new ilTemplate("tpl.main.html", true, true);
01828                                 $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
01829 
01830                                 $_GET["obj_id"] = $int_link["id"];
01831                                 $_GET["frame"] = "_new";
01832                                 $content =& $a_lm_gui->glossary();
01833                                 $file = $a_target_dir."/term_".$int_link["id"].".html";
01834                                         
01835                                 // open file
01836                                 if (!($fp = @fopen($file,"w+")))
01837                                 {
01838                                         die ("<b>Error</b>: Could not open \"".$file."\" for writing".
01839                                                         " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
01840                                 }
01841                                 chmod($file, 0770);
01842                                 fwrite($fp, $content);
01843                                 fclose($fp);
01844 
01845                                 // store linked/embedded media objects of glosssary term
01846                                 include_once("content/classes/class.ilGlossaryDefinition.php");
01847                                 $defs = ilGlossaryDefinition::getDefinitionList($int_link["id"]);
01848                                 foreach($defs as $def)
01849                                 {
01850                                         $def_mobs = ilObjMediaObject::_getMobsOfObject("gdf:pg", $def["id"]);
01851                                         foreach($def_mobs as $def_mob)
01852                                         {
01853                                                 $this->offline_mobs[$def_mob] = $def_mob;
01854                                         }
01855                                         
01856                                         // get all files of page
01857                                         $def_files = ilObjFile::_getFilesOfObject("gdf:pg", $page["obj_id"]);
01858                                         $this->offline_files = array_merge($this->offline_files, $def_files);
01859 
01860                                 }
01861                                 
01862                         }
01863                 }
01864         }
01865         
01869         function exportHTMLPages(&$a_lm_gui, $a_target_dir)
01870         {
01871                 global $tpl;
01872                                 
01873                 $pages = ilLMPageObject::getPageList($this->getId());
01874                 
01875                 $lm_tree =& $this->getLMTree();
01876                 $first_page = $lm_tree->fetchSuccessorNode($lm_tree->getRootId(), "pg");
01877                 $this->first_page_id = $first_page["child"];
01878 
01879                 // iterate all learning module pages
01880                 $mobs = array();
01881                 $int_links = array();
01882                 $this->offline_files = array();
01883                 foreach ($pages as $page)
01884                 {
01885                         $this->exportPageHTML($a_lm_gui, $a_target_dir, $page["obj_id"]);
01886                         
01887                         // get all media objects of page
01888                         include_once("content/classes/Media/class.ilObjMediaObject.php");
01889                         $pg_mobs = ilObjMediaObject::_getMobsOfObject($this->getType().":pg", $page["obj_id"]);
01890                         foreach($pg_mobs as $pg_mob)
01891                         {
01892                                 $mobs[$pg_mob] = $pg_mob;
01893                         }
01894                         
01895                         // get all internal links of page
01896                         $pg_links = ilInternalLink::_getTargetsOfSource($this->getType().":pg", $page["obj_id"]);
01897                         $int_links = array_merge($int_links, $pg_links);
01898                         
01899                         // get all files of page
01900                         include_once("classes/class.ilObjFile.php");
01901                         $pg_files = ilObjFile::_getFilesOfObject($this->getType().":pg", $page["obj_id"]);
01902                         $this->offline_files = array_merge($this->offline_files, $pg_files);
01903                         
01904                 }
01905                 $this->offline_mobs = $mobs;
01906                 $this->offline_int_links = $int_links;
01907                 
01908         }
01909 
01913         function exportPageHTML(&$a_lm_gui, $a_target_dir, $a_lm_page_id, $a_frame = "")
01914         {
01915                 global $ilias, $tpl;
01916 //echo "<br>B: export Page HTML ($a_lm_page_id)"; flush();
01917                 // template workaround: reset of template 
01918                 $tpl = new ilTemplate("tpl.main.html", true, true);
01919                 $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
01920 
01921                 $_GET["obj_id"] = $a_lm_page_id;
01922                 $_GET["frame"] = $a_frame;
01923                 $content =& $a_lm_gui->layout("main.xml", false);
01924                 
01925                 if ($a_frame == "")
01926                 {
01927                         $file = $a_target_dir."/lm_pg_".$a_lm_page_id.".html";
01928                 }
01929                 else
01930                 {
01931                         if ($a_frame != "toc")
01932                         {
01933                                 $file = $a_target_dir."/frame_".$a_lm_page_id."_".$a_frame.".html";
01934                         }
01935                         else
01936                         {
01937                                 $file = $a_target_dir."/frame_".$a_frame.".html";
01938                         }
01939                 }
01940                 
01941                 // return if file is already existing
01942                 if (@is_file($file))
01943                 {
01944                         return;
01945                 }
01946                 
01947                 // open file
01948                 if (!($fp = @fopen($file,"w+")))
01949                 {
01950                         die ("<b>Error</b>: Could not open \"".$file."\" for writing".
01951                                         " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
01952                 }
01953         
01954                 // set file permissions
01955                 chmod($file, 0770);
01956                         
01957                 // write xml data into the file
01958                 fwrite($fp, $content);
01959                 
01960                 // close file
01961                 fclose($fp);
01962 
01963                 if ($this->first_page_id == $a_lm_page_id && $a_frame == "")
01964                 {
01965                         copy($file, $a_target_dir."/index.html");
01966                 }
01967 
01968                 // write frames of frameset
01969                 $frameset = $a_lm_gui->getCurrentFrameSet();
01970                 foreach ($frameset as $frame)
01971                 {                               
01972                         $this->exportPageHTML($a_lm_gui, $a_target_dir, $a_lm_page_id, $frame);
01973                 }
01974 
01975         }
01976 
01983         function exportFO(&$a_xml_writer, $a_target_dir)
01984         {
01985                 global $ilBench;
01986 
01987                 // fo:root (start)
01988                 $attrs = array();
01989                 $attrs["xmlns:fo"] = "http://www.w3.org/1999/XSL/Format";
01990                 $a_xml_writer->xmlStartTag("fo:root", $attrs);
01991 
01992                 // fo:layout-master-set (start)
01993                 $attrs = array();
01994                 $a_xml_writer->xmlStartTag("fo:layout-master-set", $attrs);
01995 
01996                 // fo:simple-page-master (start)
01997                 $attrs = array();
01998                 $attrs["master-name"] = "DinA4";
01999                 $attrs["page-height"] = "29.7cm";
02000                 $attrs["page-width"] = "21cm";
02001                 $attrs["margin-top"] = "4cm";
02002                 $attrs["margin-bottom"] = "1cm";
02003                 $attrs["margin-left"] = "2.8cm";
02004                 $attrs["margin-right"] = "7.3cm";
02005                 $a_xml_writer->xmlStartTag("fo:simple-page-master", $attrs);
02006 
02007                 // fo:region-body (complete)
02008                 $attrs = array();
02009                 $attrs["margin-top"] = "0cm";
02010                 $attrs["margin-bottom"] = "1.25cm";
02011                 $a_xml_writer->xmlElement("fo:region-body", $attrs);
02012 
02013                 // fo:region-before (complete)
02014                 $attrs = array();
02015                 $attrs["extent"] = "1cm";
02016                 $a_xml_writer->xmlElement("fo:region-before", $attrs);
02017 
02018                 // fo:region-after (complete)
02019                 $attrs = array();
02020                 $attrs["extent"] = "1cm";
02021                 $a_xml_writer->xmlElement("fo:region-after", $attrs);
02022 
02023                 // fo:simple-page-master (end)
02024                 $a_xml_writer->xmlEndTag("fo:simple-page-master");
02025 
02026                 // fo:layout-master-set (end)
02027                 $a_xml_writer->xmlEndTag("fo:layout-master-set");
02028 
02029                 // fo:page-sequence (start)
02030                 $attrs = array();
02031                 $attrs["master-reference"] = "DinA4";
02032                 $a_xml_writer->xmlStartTag("fo:page-sequence", $attrs);
02033 
02034                 // fo:flow (start)
02035                 $attrs = array();
02036                 $attrs["flow-name"] = "xsl-region-body";
02037                 $a_xml_writer->xmlStartTag("fo:flow", $attrs);
02038 
02039 
02040                 // StructureObjects
02041                 //$expLog->write(date("[y-m-d H:i:s] ")."Start Export Structure Objects");
02042                 $ilBench->start("ContentObjectExport", "exportFOStructureObjects");
02043                 $this->exportFOStructureObjects($a_xml_writer, $expLog);
02044                 $ilBench->stop("ContentObjectExport", "exportFOStructureObjects");
02045                 //$expLog->write(date("[y-m-d H:i:s] ")."Finished Export Structure Objects");*/
02046 
02047                 // fo:flow (end)
02048                 $a_xml_writer->xmlEndTag("fo:flow");
02049 
02050                 // fo:page-sequence (end)
02051                 $a_xml_writer->xmlEndTag("fo:page-sequence");
02052 
02053                 // fo:root (end)
02054                 $a_xml_writer->xmlEndTag("fo:root");
02055         }
02056 
02063         function exportFOStructureObjects(&$a_xml_writer)
02064         {
02065                 $childs = $this->lm_tree->getChilds($this->lm_tree->getRootId());
02066                 foreach ($childs as $child)
02067                 {
02068                         if($child["type"] != "st")
02069                         {
02070                                 continue;
02071                         }
02072 
02073                         $structure_obj = new ilStructureObject($this, $child["obj_id"]);
02074                         $structure_obj->exportFO($a_xml_writer, $expLog);
02075                         unset($structure_obj);
02076                 }
02077         }
02078 
02079         function getXMLZip()
02080         {
02081                 include_once("./content/classes/class.ilContObjectExport.php");
02082 
02083                 $cont_exp = new ilContObjectExport($this,'xml');
02084 
02085                 $export_file = $cont_exp->buildExportFile();
02086                 return $export_file;
02087         }               
02088 
02089 
02090 }
02091 ?>

Generated on Fri Dec 13 2013 09:06:36 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1