• 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                         default:                // = xml
00413                                 $export_dir = $lm_dir."/export";
00414                                 break;
00415                 }
00416                 ilUtil::makeDir($export_dir);
00417                 if(!@is_dir($export_dir))
00418                 {
00419                         $this->ilias->raiseError("Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
00420                 }
00421         }
00422 
00426         function getExportDirectory($a_type = "xml")
00427         {
00428                 switch  ($a_type)
00429                 {
00430                         case "html":
00431                                 $export_dir = ilUtil::getDataDir()."/lm_data"."/lm_".$this->getId()."/export_html";
00432                                 break;
00433                                 
00434                         default:                        // = xml
00435                                 $export_dir = ilUtil::getDataDir()."/lm_data"."/lm_".$this->getId()."/export";
00436                                 break;
00437                 }
00438                 return $export_dir;
00439         }
00440 
00447         function ilClone($a_parent_ref)
00448         {
00449                 global $rbacadmin;
00450 
00451                 // always call parent ilClone function first!!
00452                 $new_ref_id = parent::ilClone($a_parent_ref);
00453 
00454                 // todo: put here lm specific stuff
00455 
00456                 // ... and finally always return new reference ID!!
00457                 return $new_ref_id;
00458         }
00459 
00470         function delete()
00471         {
00472                 global $ilDB;
00473 
00474                 global $ilBench;
00475 
00476                 #$ilBench->start('NestedSet','lm_delete');
00477 
00478                 // always call parent delete function first!!
00479                 if (!parent::delete())
00480                 {
00481                         return false;
00482                 }
00483 
00484                 #$ilBench->start('NestedSet','delete_all_object_data');
00485                 // delete lm object data
00486                 include_once("content/classes/class.ilLMObject.php");
00487                 ilLMObject::_deleteAllObjectData($this);
00488                 #$ilBench->stop('NestedSet','delete_all_object_data');
00489 
00490 
00491                 // delete meta data of content object
00492                 $nested = new ilNestedSetXML();
00493                 $nested->init($this->getId(), $this->getType());
00494                 $nested->deleteAllDBData();
00495                 
00496 
00497                 // delete bibitem data
00498                 $nested = new ilNestedSetXML();
00499                 $nested->init($this->getId(), "bib");
00500                 $nested->deleteAllDBData();
00501 
00502                 
00503                 // delete learning module tree
00504                 $this->lm_tree->removeTree($this->lm_tree->getTreeId());
00505 
00506                 // delete data directory
00507                 ilUtil::delDir($this->getDataDirectory());
00508 
00509                 // delete content object record
00510                 $q = "DELETE FROM content_object WHERE id = ".$ilDB->quote($this->getId());
00511                 $this->ilias->db->query($q);
00512 
00513                 // delete lm menu entries
00514                 $q = "DELETE FROM lm_menu WHERE lm_id = ".$ilDB->quote($this->getId());
00515                 $this->ilias->db->query($q);
00516 
00517                 #$ilBench->stop('NestedSet','lm_delete');
00518                 #$ilBench->save();
00519         
00520                 return true;
00521         }
00522 
00528         function getLayout()
00529         {
00530                 return $this->layout;
00531         }
00532 
00538         function setLayout($a_layout)
00539         {
00540                 $this->layout = $a_layout;
00541         }
00542 
00546         function getStyleSheetId()
00547         {
00548                 return $this->style_id;
00549         }
00550 
00554         function setStyleSheetId($a_style_id)
00555         {
00556                 $this->style_id = $a_style_id;
00557         }
00558 
00562         function writeStyleSheetId($a_style_id)
00563         {
00564                 global $ilDB;
00565                 
00566                 $q = "UPDATE content_object SET ".
00567                         " stylesheet = ".$ilDB->quote($a_style_id).
00568                         " WHERE id = '".$this->getId()."'";
00569                 $ilDB->query($q);
00570 
00571                 $this->style_id = $a_style_id;
00572         }
00573 
00577         function _lookupStyleSheetId($a_cont_obj_id)
00578         {
00579                 global $ilDB;
00580                 
00581                 $q = "SELECT stylesheet FROM content_object ".
00582                         " WHERE id = '".$a_cont_obj_id."'";
00583                 $res = $ilDB->query($q);
00584                 $sheet = $res->fetchRow(DB_FETCHMODE_ASSOC);
00585 
00586                 return $sheet["stylesheet"];
00587         }
00588 
00592         function getPageHeader()
00593         {
00594                 return $this->pg_header;
00595         }
00596 
00602         function setPageHeader($a_pg_header = IL_CHAPTER_TITLE)
00603         {
00604                 $this->pg_header = $a_pg_header;
00605         }
00606 
00610         function getTOCMode()
00611         {
00612                 return $this->toc_mode;
00613         }
00614         
00618         function getPublicAccessMode()
00619         {
00620                 return $this->public_access_mode;
00621         }
00622 
00628         function setTOCMode($a_toc_mode = "chapters")
00629         {
00630                 $this->toc_mode = $a_toc_mode;
00631         }
00632 
00633         function setOnline($a_online)
00634         {
00635                 $this->online = $a_online;
00636         }
00637 
00638         function getOnline()
00639         {
00640                 return $this->online;
00641         }
00642 
00643         function setActiveLMMenu($a_act_lm_menu)
00644         {
00645                 $this->lm_menu_active = $a_act_lm_menu;
00646         }
00647 
00648         function isActiveLMMenu()
00649         {
00650                 return $this->lm_menu_active;
00651         }
00652 
00653         function setActiveTOC($a_toc)
00654         {
00655                 $this->toc_active = $a_toc;
00656         }
00657 
00658         function isActiveTOC()
00659         {
00660                 return $this->toc_active;
00661         }
00662 
00663         function setActiveNumbering($a_num)
00664         {
00665                 $this->numbering = $a_num;
00666         }
00667 
00668         function isActiveNumbering()
00669         {
00670                 return $this->numbering;
00671         }
00672 
00673         function setActivePrintView($a_print)
00674         {
00675                 $this->print_view_active = $a_print;
00676         }
00677 
00678         function isActivePrintView()
00679         {
00680                 return $this->print_view_active;
00681         }
00682 
00683         function setActiveDownloads($a_down)
00684         {
00685                 $this->downloads_active = $a_down;
00686         }
00687 
00688         function isActiveDownloads()
00689         {
00690                 return $this->downloads_active;
00691         }
00692 
00693         function setCleanFrames($a_clean)
00694         {
00695                 $this->clean_frames = $a_clean;
00696         }
00697 
00698         function cleanFrames()
00699         {
00700                 return $this->clean_frames;
00701         }
00702         
00703         function setHistoryUserComments($a_comm)
00704         {
00705                 $this->user_comments = $a_comm;
00706         }
00707 
00708         function setPublicAccessMode($a_mode)
00709         {
00710                 $this->public_access_mode = $a_mode;
00711         }
00712 
00713         function isActiveHistoryUserComments()
00714         {
00715                 return $this->user_comments;
00716         }
00717 
00721         function readProperties()
00722         {
00723                 $q = "SELECT * FROM content_object WHERE id = '".$this->getId()."'";
00724                 $lm_set = $this->ilias->db->query($q);
00725                 $lm_rec = $lm_set->fetchRow(DB_FETCHMODE_ASSOC);
00726                 $this->setLayout($lm_rec["default_layout"]);
00727                 $this->setStyleSheetId($lm_rec["stylesheet"]);
00728                 $this->setPageHeader($lm_rec["page_header"]);
00729                 $this->setTOCMode($lm_rec["toc_mode"]);
00730                 $this->setOnline(ilUtil::yn2tf($lm_rec["online"]));
00731                 $this->setActiveTOC(ilUtil::yn2tf($lm_rec["toc_active"]));
00732                 $this->setActiveNumbering(ilUtil::yn2tf($lm_rec["numbering"]));
00733                 $this->setActivePrintView(ilUtil::yn2tf($lm_rec["print_view_active"]));
00734                 $this->setActiveDownloads(ilUtil::yn2tf($lm_rec["downloads_active"]));
00735                 $this->setActiveLMMenu(ilUtil::yn2tf($lm_rec["lm_menu_active"]));
00736                 $this->setCleanFrames(ilUtil::yn2tf($lm_rec["clean_frames"]));
00737                 $this->setHistoryUserComments(ilUtil::yn2tf($lm_rec["hist_user_comments"]));
00738                 $this->setPublicAccessMode($lm_rec["public_access_mode"]);
00739                 $this->setPublicExportFile("xml", $lm_rec["public_xml_file"]);
00740                 $this->setPublicExportFile("html", $lm_rec["public_html_file"]);
00741         }
00742 
00746         function updateProperties()
00747         {
00748                 $q = "UPDATE content_object SET ".
00749                         " default_layout = '".$this->getLayout()."', ".
00750                         " stylesheet = '".$this->getStyleSheetId()."',".
00751                         " page_header = '".$this->getPageHeader()."',".
00752                         " toc_mode = '".$this->getTOCMode()."',".
00753                         " online = '".ilUtil::tf2yn($this->getOnline())."',".
00754                         " toc_active = '".ilUtil::tf2yn($this->isActiveTOC())."',".
00755                         " numbering = '".ilUtil::tf2yn($this->isActiveNumbering())."',".
00756                         " print_view_active = '".ilUtil::tf2yn($this->isActivePrintView())."',".
00757                         " downloads_active = '".ilUtil::tf2yn($this->isActiveDownloads())."',".
00758                         " clean_frames = '".ilUtil::tf2yn($this->cleanFrames())."',".
00759                         " hist_user_comments = '".ilUtil::tf2yn($this->isActiveHistoryUserComments())."',".
00760                         " public_access_mode = '".$this->getPublicAccessMode()."',".
00761                         " public_xml_file = '".$this->getPublicExportFile("xml")."',".
00762                         " public_html_file = '".$this->getPublicExportFile("html")."',".
00763                         " lm_menu_active = '".ilUtil::tf2yn($this->isActiveLMMenu())."'".
00764                         " WHERE id = '".$this->getId()."'";
00765                 $this->ilias->db->query($q);
00766         }
00767 
00771         function createProperties()
00772         {
00773                 $q = "INSERT INTO content_object (id) VALUES ('".$this->getId()."')";
00774                 $this->ilias->db->query($q);
00775                 $this->readProperties();                // to get db default values
00776         }
00777 
00781         function _lookupOnline($a_id)
00782         {
00783                 $q = "SELECT * FROM content_object WHERE id = '".$a_id."'";
00784                 $lm_set = $this->ilias->db->query($q);
00785                 $lm_rec = $lm_set->fetchRow(DB_FETCHMODE_ASSOC);
00786 
00787                 return ilUtil::yn2tf($lm_rec["online"]);
00788         }
00789 
00795         function getAvailableLayouts()
00796         {
00797                 // read sdir, copy files and copy directories recursively
00798                 $dir = opendir("./layouts/lm");
00799 
00800                 $layouts = array();
00801 
00802                 while($file = readdir($dir))
00803                 {
00804                         if ($file != "." && $file != ".." && $file != "CVS")
00805                         {
00806                                 // directories
00807                                 if (@is_dir("./layouts/lm/".$file))
00808                                 {
00809                                         $layouts[$file] = $file;
00810                                 }
00811                         }
00812                 }
00813                 asort($layouts);
00814                 return $layouts;
00815         }
00816 
00820         function _checkPreconditionsOfPage($cont_obj_id, $page_id)
00821         {
00822                 global $ilias,$ilUser,$ilErr;
00823 
00824                 $lm_tree = new ilTree($cont_obj_id);
00825                 $lm_tree->setTableNames('lm_tree','lm_data');
00826                 $lm_tree->setTreeTablePK("lm_id");
00827 
00828                 if ($lm_tree->isInTree($page_id))
00829                 {
00830                         $path = $lm_tree->getPathFull($page_id, $lm_tree->readRootId());
00831                         foreach ($path as $node)
00832                         {
00833                                 if ($node["type"] == "st")
00834                                 {
00835                                         if (!ilConditionHandler::_checkAllConditionsOfTarget($node["child"], "st"))
00836                                         {
00837                                                 return false;
00838                                         }
00839                                 }
00840                         }
00841                 }
00842                 
00843                 return true;
00844         }
00845 
00849         function _getMissingPreconditionsOfPage($cont_obj_id, $page_id)
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                 $conds = array();
00856                 if ($lm_tree->isInTree($page_id))
00857                 {
00858                         // get full path of page
00859                         $path = $lm_tree->getPathFull($page_id, $lm_tree->readRootId());
00860                         foreach ($path as $node)
00861                         {
00862                                 if ($node["type"] == "st")
00863                                 {
00864                                         // get all preconditions of upper chapters
00865                                         $tconds = ilConditionHandler::_getConditionsOfTarget($node["child"], "st");
00866                                         foreach ($tconds as $tcond)
00867                                         {
00868                                                 // store all missing preconditions
00869                                                 if (!ilConditionHandler::_checkCondition($tcond["id"]))
00870                                                 {
00871                                                         $conds[] = $tcond;
00872                                                 }
00873                                         }
00874                                 }
00875                         }
00876                 }
00877                 
00878                 return $conds;
00879         }
00880 
00884         function _getMissingPreconditionsTopChapter($cont_obj_id, $page_id)
00885         {
00886                 $lm_tree = new ilTree($cont_obj_id);
00887                 $lm_tree->setTableNames('lm_tree','lm_data');
00888                 $lm_tree->setTreeTablePK("lm_id");
00889 
00890                 $conds = array();
00891                 if ($lm_tree->isInTree($page_id))
00892                 {
00893                         // get full path of page
00894                         $path = $lm_tree->getPathFull($page_id, $lm_tree->readRootId());
00895                         foreach ($path as $node)
00896                         {
00897                                 if ($node["type"] == "st")
00898                                 {
00899                                         // get all preconditions of upper chapters
00900                                         $tconds = ilConditionHandler::_getConditionsOfTarget($node["child"], "st");
00901                                         foreach ($tconds as $tcond)
00902                                         {
00903                                                 // look for missing precondition
00904                                                 if (!ilConditionHandler::_checkCondition($tcond["id"]))
00905                                                 {
00906                                                         return $node["child"];
00907                                                 }
00908                                         }
00909                                 }
00910                         }
00911                 }
00912                 
00913                 return "";
00914         }
00915 
00926         function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
00927         {
00928                 global $tree;
00929                 
00930                 switch ($a_event)
00931                 {
00932                         case "link":
00933 
00934                                 //var_dump("<pre>",$a_params,"</pre>");
00935                                 //echo "Content Object ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
00936                                 //exit;
00937                                 break;
00938                         
00939                         case "cut":
00940                                 
00941                                 //echo "Content Object ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
00942                                 //exit;
00943                                 break;
00944                                 
00945                         case "copy":
00946                         
00947                                 //var_dump("<pre>",$a_params,"</pre>");
00948                                 //echo "Content Object ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
00949                                 //exit;
00950                                 break;
00951 
00952                         case "paste":
00953                                 
00954                                 //echo "Content Object ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
00955                                 //exit;
00956                                 break;
00957                         
00958                         case "new":
00959                                 
00960                                 //echo "Content Object ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
00961                                 //exit;
00962                                 break;
00963                 }
00964 
00965                 // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
00966                 if ($a_node_id==$_GET["ref_id"])
00967                 {       
00968                         $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
00969                         $parent_type = $parent_obj->getType();
00970                         if($parent_type == $this->getType())
00971                         {
00972                                 $a_node_id = (int) $tree->getParentId($a_node_id);
00973                         }
00974                 }
00975                 
00976                 parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
00977         }
00978 
00986         function _search(&$search_obj,$a_search_in)
00987         {
00988                 global $ilBench;
00989 
00990                 switch($a_search_in)
00991                 {
00992                         case 'meta':
00993                                 // FILTER ALL DBK OBJECTS
00994                                 $in             = $search_obj->getInStatement("r.ref_id");
00995                                 $where  = $search_obj->getWhereCondition("fulltext",array("xv.tag_value"));
00996 
00997                                 /* very slow on mysql < 4.0.18 (? or everytime ?)
00998                                 $query = "SELECT DISTINCT(r.ref_id) FROM object_reference AS r,object_data AS o, ".
00999                                         "lm_data AS l,xmlnestedset AS xm,xmlvalue AS xv ".
01000                                         $where.
01001                                         $in.
01002                                         "AND r.obj_id=o.obj_id AND ((o.obj_id=l.lm_id AND xm.ns_book_fk=l.obj_id) OR ".
01003                                         "(o.obj_id=xm.ns_book_fk AND xm.ns_type IN ('lm','bib'))) ".
01004                                         "AND xm.ns_tag_fk=xv.tag_fk ".
01005                                         "AND o.type= 'lm'";*/
01006 
01007                                 $query1 = "SELECT DISTINCT(r.ref_id) FROM object_reference AS r,object_data AS o, ".
01008                                         "xmlnestedset AS xm,xmlvalue AS xv ".
01009                                         $where.
01010                                         $in.
01011                                         "AND r.obj_id=o.obj_id AND ( ".
01012                                         "(o.obj_id=xm.ns_book_fk AND xm.ns_type IN ('lm','bib'))) ".
01013                                         "AND xm.ns_tag_fk=xv.tag_fk ".
01014                                         "AND o.type= 'lm'";
01015 
01016                                 // BEGINNING SELECT WITH SEARCH RESULTS IS MUCH FASTER
01017                                 $query1 = "SELECT DISTINCT(r.ref_id) as ref_id FROM xmlvalue AS xv ".
01018                                         "LEFT JOIN xmlnestedset AS xm ON xm.ns_tag_fk=xv.tag_fk ".
01019                                         "LEFT JOIN object_data AS o ON o.obj_id = xm.ns_book_fk ".
01020                                         "LEFT JOIN object_reference AS r ON o.obj_id = r.obj_id ".
01021                                         $where.
01022                                         $in.
01023                                         " AND o.type = 'lm' AND xm.ns_type IN ('lm','bib')";
01024 
01025                                 $query2 = "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)".
01030                                         ") ".
01031                                         "AND xm.ns_tag_fk=xv.tag_fk ".
01032                                         "AND o.type= 'lm'";
01033 
01034                                 $query2 = "SELECT DISTINCT(r.ref_id) as ref_id FROM xmlvalue AS xv ".
01035                                         "LEFT JOIN xmlnestedset AS xm ON xm.ns_tag_fk = xv.tag_fk ".
01036                                         "LEFT JOIN lm_data AS l ON l.obj_id = xm.ns_book_fk ".
01037                                         "LEFT JOIN object_data AS o ON o.obj_id = l.lm_id ".
01038                                         "LEFT JOIN object_reference AS r ON r.obj_id = o.obj_id ".
01039                                         $where.
01040                                         $in.
01041                                         "AND o.type = 'lm'";
01042 
01043                                 $ilBench->start("Search", "ilObjContentObject_search_meta");
01044                                 $res1 = $search_obj->ilias->db->query($query1);
01045                                 $res2 = $search_obj->ilias->db->query($query2);
01046                                 $ilBench->stop("Search", "ilObjContentObject_search_meta");
01047 
01048                                 $counter = 0;
01049                                 $ids = array();
01050                                 while($row = $res1->fetchRow(DB_FETCHMODE_OBJECT))
01051                                 {
01052                                         $ids[] = $row->ref_id;
01053                                         $result[$counter]["id"]         =  $row->ref_id;
01054                                         ++$counter;
01055                                 }
01056                                 while($row = $res2->fetchRow(DB_FETCHMODE_OBJECT))
01057                                 {
01058                                         if(in_array($row->ref_id,$ids))
01059                                         {
01060                                                 continue;
01061                                         }
01062                                         $result[$counter]["id"]         =  $row->ref_id;
01063                                         ++$counter;
01064                                 }
01065                                 break;
01066 
01067                         case 'content':
01068                                 $in             = $search_obj->getInStatement("r.ref_id");
01069                                 $where  = $search_obj->getWhereCondition("fulltext",array("pg.content"));
01070 
01071                                 // slow on mysql < 4.0.18 (join bug)
01072                                 /*
01073                                 $query = "SELECT DISTINCT(r.ref_id) AS ref_id ,pg.page_id AS page_id FROM page_object AS pg ".
01074                                         "INNER JOIN object_reference AS r ON pg.parent_id = r.obj_id ".
01075                                         $where.
01076                                         $in.
01077                                         "AND pg.parent_type = 'lm' ";*/
01078 
01079                                 $query = "SELECT DISTINCT(r.ref_id) AS ref_id ,pg.page_id AS page_id FROM page_object AS pg ".
01080                                         ", object_reference AS r ".
01081                                         $where.
01082                                         " AND pg.parent_id = r.obj_id ".
01083                                         $in.
01084                                         " AND pg.parent_type = 'lm' ";
01085 
01086                                 $query = "SELECT DISTINCT(r.ref_id) AS ref_id ,pg.page_id AS page_id FROM page_object AS pg ".
01087                                         "LEFT JOIN object_data AS o ON o.obj_id = pg.parent_id ".
01088                                         "LEFT JOIN object_reference AS r ON o.obj_id = r.obj_id ".
01089                                         $where.
01090                                         $in.
01091                                         " AND pg.parent_type = 'lm'";
01092 
01093                                 $ilBench->start("Search", "ilObjContentObject_search_content");
01094                                 $res = $search_obj->ilias->db->query($query);
01095                                 $ilBench->stop("Search", "ilObjContentObject_search_content");
01096 
01097                                 $counter = 0;
01098                                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
01099                                 {
01100                                         $result[$counter]["id"]         = $row->ref_id;
01101                                         $result[$counter]["page_id"] = $row->page_id;
01102                                         /*
01103                                         $result[$counter]["link"]       = "content/lm_presentation.php?ref_id=".$row->ref_id;
01104                                         $result[$counter]["target"]     = "_top";
01105                                         */
01106                                         ++$counter;
01107                                 }
01108                                 break;
01109                 }
01110                 return $result ? $result : array();
01111         }
01112 
01123         function _getLinkToObject($a_ref_id,$a_type,$a_obj_id = 0)
01124         {
01125                 switch($a_type)
01126                 {
01127                         case "content":
01128                                 return array("content/lm_presentation.php?ref_id=".$a_ref_id."&obj_id=".$a_obj_id,"_blank");
01129                                 
01130                         case "meta":
01131                                 return array("content/lm_presentation.php?ref_id=".$a_ref_id,"_blank");
01132                 }
01133         }
01134 
01140         function _goto($a_target)
01141         {
01142                 global $rbacsystem, $ilErr, $lng;
01143 
01144                 if ($rbacsystem->checkAccess("read", $a_target))
01145                 {
01146                         ilUtil::redirect("content/lm_presentation.php?ref_id=$a_target");
01147                 }
01148                 else
01149                 {
01150                         $ilErr->raiseError($lng->txt("msg_no_perm_read_lm"), $ilErr->FATAL);
01151                 }
01152         }
01153         
01157         function hasSuccessorPage($a_cont_obj_id, $a_page_id)
01158         {
01159                 $tree = new ilTree($a_cont_obj_id);
01160                 $tree->setTableNames('lm_tree','lm_data');
01161                 $tree->setTreeTablePK("lm_id");
01162                 if ($tree->isInTree($a_page_id))
01163                 {
01164                         $succ = $tree->fetchSuccessorNode($a_page_id, "pg");
01165                         if ($succ > 0)
01166                         {
01167                                 return true;
01168                         }
01169                 }
01170                 return false;
01171         }
01172 
01173         
01174         function checkTree()
01175         {
01176                 $tree = new ilTree($this->getId());
01177                 $tree->setTableNames('lm_tree','lm_data');
01178                 $tree->setTreeTablePK("lm_id");
01179                 $tree->checkTree();
01180                 $tree->checkTreeChilds();
01181 //echo "checked";
01182         }
01183 
01187         function fixTree()
01188         {
01189                 global $ilDB;
01190 
01191                 $tree =& $this->getLMTree();
01192 
01193                 $nodes = $tree->getSubtree($tree->getNodeData($tree->getRootId()));
01194                 foreach ($nodes as $node)
01195                 {
01196                         $q = "SELECT * FROM lm_data WHERE obj_id = ".$ilDB->quote($node["child"]);
01197                         $obj_set = $ilDB->query($q);
01198                         $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
01199                         if (!$obj_rec)
01200                         {
01201                                 $node_data = $tree->getNodeData($node["child"]);
01202                                 $tree->deleteTree($node_data);
01203                         }
01204                 }
01205         }
01206 
01207 
01214         function exportXML(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
01215         {
01216                 global $ilBench;
01217 
01218                 $attrs = array();
01219                 switch($this->getType())
01220                 {
01221                         case "lm":
01222                                 $attrs["Type"] = "LearningModule";
01223                                 break;
01224 
01225                         case "dbk":
01226                                 $attrs["Type"] = "LibObject";
01227                                 break;
01228                 }
01229                 $a_xml_writer->xmlStartTag("ContentObject", $attrs);
01230 
01231                 // MetaData
01232                 $this->exportXMLMetaData($a_xml_writer);
01233 
01234                 // StructureObjects
01235 //echo "ContObj:".$a_inst.":<br>";
01236                 $expLog->write(date("[y-m-d H:i:s] ")."Start Export Structure Objects");
01237                 $ilBench->start("ContentObjectExport", "exportStructureObjects");
01238                 $this->exportXMLStructureObjects($a_xml_writer, $a_inst, $expLog);
01239                 $ilBench->stop("ContentObjectExport", "exportStructureObjects");
01240                 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Structure Objects");
01241 
01242                 // PageObjects
01243                 $expLog->write(date("[y-m-d H:i:s] ")."Start Export Page Objects");
01244                 $ilBench->start("ContentObjectExport", "exportPageObjects");
01245                 $this->exportXMLPageObjects($a_xml_writer, $a_inst, $expLog);
01246                 $ilBench->stop("ContentObjectExport", "exportPageObjects");
01247                 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Page Objects");
01248 
01249                 // MediaObjects
01250                 $expLog->write(date("[y-m-d H:i:s] ")."Start Export Media Objects");
01251                 $ilBench->start("ContentObjectExport", "exportMediaObjects");
01252                 $this->exportXMLMediaObjects($a_xml_writer, $a_inst, $a_target_dir, $expLog);
01253                 $ilBench->stop("ContentObjectExport", "exportMediaObjects");
01254                 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Media Objects");
01255 
01256                 // FileItems
01257                 $expLog->write(date("[y-m-d H:i:s] ")."Start Export File Items");
01258                 $ilBench->start("ContentObjectExport", "exportFileItems");
01259                 $this->exportFileItems($a_target_dir, $expLog);
01260                 $ilBench->stop("ContentObjectExport", "exportFileItems");
01261                 $expLog->write(date("[y-m-d H:i:s] ")."Finished Export File Items");
01262 
01263                 // Glossary
01264                 // not implemented
01265 
01266                 // Bibliography
01267                 // not implemented
01268 
01269                 // Layout
01270                 // not implemented
01271 
01272                 $a_xml_writer->xmlEndTag("ContentObject");
01273         }
01274 
01281         function exportXMLMetaData(&$a_xml_writer)
01282         {
01283                 $nested = new ilNestedSetXML();
01284                 $nested->setParameterModifier($this, "modifyExportIdentifier");
01285                 $a_xml_writer->appendXML($nested->export($this->getId(),
01286                         $this->getType()));
01287         }
01288 
01289         function modifyExportIdentifier($a_tag, $a_param, $a_value)
01290         {
01291                 if ($a_tag == "Identifier" && $a_param == "Entry")
01292                 {
01293                         $a_value = ilUtil::insertInstIntoID($a_value);
01294                 }
01295 
01296                 return $a_value;
01297         }
01298 
01305         function exportXMLStructureObjects(&$a_xml_writer, $a_inst, &$expLog)
01306         {
01307                 include_once './content/classes/class.ilStructureObject.php';
01308 
01309                 $childs = $this->lm_tree->getChilds($this->lm_tree->getRootId());
01310                 foreach ($childs as $child)
01311                 {
01312                         if($child["type"] != "st")
01313                         {
01314                                 continue;
01315                         }
01316 
01317                         $structure_obj = new ilStructureObject($this, $child["obj_id"]);
01318                         $structure_obj->exportXML($a_xml_writer, $a_inst, $expLog);
01319                         unset($structure_obj);
01320                 }
01321         }
01322 
01323 
01330         function exportXMLPageObjects(&$a_xml_writer, $a_inst, &$expLog)
01331         {
01332                 global $ilBench;
01333 
01334                 include_once "./content/classes/class.ilLMPageObject.php";
01335 
01336                 $pages = ilLMPageObject::getPageList($this->getId());
01337                 foreach ($pages as $page)
01338                 {
01339                         $ilBench->start("ContentObjectExport", "exportPageObject");
01340                         $expLog->write(date("[y-m-d H:i:s] ")."Page Object ".$page["obj_id"]);
01341 
01342                         // export xml to writer object
01343                         $ilBench->start("ContentObjectExport", "exportPageObject_getLMPageObject");
01344                         $page_obj = new ilLMPageObject($this, $page["obj_id"]);
01345                         $ilBench->stop("ContentObjectExport", "exportPageObject_getLMPageObject");
01346                         $ilBench->start("ContentObjectExport", "exportPageObject_XML");
01347                         $page_obj->exportXML($a_xml_writer, "normal", $a_inst);
01348                         $ilBench->stop("ContentObjectExport", "exportPageObject_XML");
01349 
01350                         // collect media objects
01351                         $ilBench->start("ContentObjectExport", "exportPageObject_CollectMedia");
01352                         $mob_ids = $page_obj->getMediaObjectIDs();
01353                         foreach($mob_ids as $mob_id)
01354                         {
01355                                 $this->mob_ids[$mob_id] = $mob_id;
01356                         }
01357                         $ilBench->stop("ContentObjectExport", "exportPageObject_CollectMedia");
01358 
01359                         // collect all file items
01360                         $ilBench->start("ContentObjectExport", "exportPageObject_CollectFileItems");
01361                         $file_ids = $page_obj->getFileItemIds();
01362                         foreach($file_ids as $file_id)
01363                         {
01364                                 $this->file_ids[$file_id] = $file_id;
01365                         }
01366                         $ilBench->stop("ContentObjectExport", "exportPageObject_CollectFileItems");
01367 
01368                         unset($page_obj);
01369 
01370                         $ilBench->stop("ContentObjectExport", "exportPageObject");
01371                 }
01372         }
01373 
01380         function exportXMLMediaObjects(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
01381         {
01382                 include_once("content/classes/Media/class.ilObjMediaObject.php");
01383 
01384                 foreach ($this->mob_ids as $mob_id)
01385                 {
01386                         $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
01387                         $media_obj = new ilObjMediaObject($mob_id);
01388                         $media_obj->exportXML($a_xml_writer, $a_inst);
01389                         $media_obj->exportFiles($a_target_dir);
01390                         unset($media_obj);
01391                 }
01392         }
01393 
01398         function exportFileItems($a_target_dir, &$expLog)
01399         {
01400                 include_once("classes/class.ilObjFile.php");
01401 
01402                 foreach ($this->file_ids as $file_id)
01403                 {
01404                         $expLog->write(date("[y-m-d H:i:s] ")."File Item ".$file_id);
01405                         $file_obj = new ilObjFile($file_id, false);
01406                         $file_obj->export($a_target_dir);
01407                         unset($file_obj);
01408                 }
01409         }
01410 
01414         function getExportFiles()
01415         {
01416                 $file = array();
01417                 
01418                 $types = array("xml", "html");
01419                 
01420                 foreach ($types as $type)
01421                 {
01422                         $dir = $this->getExportDirectory($type);
01423                         // quit if import dir not available
01424                         if (!@is_dir($dir) or
01425                                 !is_writeable($dir))
01426                         {
01427                                 continue;
01428                         }
01429         
01430                         // open directory
01431                         $cdir = dir($dir);
01432         
01433                         // initialize array
01434         
01435                         // get files and save the in the array
01436                         while ($entry = $cdir->read())
01437                         {
01438                                 if ($entry != "." and
01439                                         $entry != ".." and
01440                                         substr($entry, -4) == ".zip" and
01441                                         ereg("^[0-9]{10}_{2}[0-9]+_{2}(lm_)*[0-9]+\.zip\$", $entry))
01442                                 {
01443                                         $file[$entry.$type] = array("type" => $type, "file" => $entry,
01444                                                 "size" => filesize($dir."/".$entry));
01445                                 }
01446                         }
01447         
01448                         // close import directory
01449                         $cdir->close();
01450                 }
01451 
01452                 // sort files
01453                 ksort ($file);
01454                 reset ($file);
01455 
01456                 return $file;
01457         }
01458         
01465         function setPublicExportFile($a_type, $a_file)
01466         {
01467                 $this->public_export_file[$a_type] = $a_file;
01468         }
01469 
01477         function getPublicExportFile($a_type)
01478         {
01479                 return $this->public_export_file[$a_type];
01480         }
01481 
01485         function getOfflineFiles($dir)
01486         {
01487                 // quit if offline dir not available
01488                 if (!@is_dir($dir) or
01489                         !is_writeable($dir))
01490                 {
01491                         return array();
01492                 }
01493 
01494                 // open directory
01495                 $dir = dir($dir);
01496 
01497                 // initialize array
01498                 $file = array();
01499 
01500                 // get files and save the in the array
01501                 while ($entry = $dir->read())
01502                 {
01503                         if ($entry != "." and
01504                                 $entry != ".." and
01505                                 substr($entry, -4) == ".pdf" and
01506                                 ereg("^[0-9]{10}_{2}[0-9]+_{2}(lm_)*[0-9]+\.pdf\$", $entry))
01507                         {
01508                                 $file[] = $entry;
01509                         }
01510                 }
01511 
01512                 // close import directory
01513                 $dir->close();
01514 
01515                 // sort files
01516                 sort ($file);
01517                 reset ($file);
01518 
01519                 return $file;
01520         }
01521         
01525         function exportHTML($a_target_dir, $log)
01526         {
01527                 global $ilias, $tpl;
01528 
01529                 // initialize temporary target directory
01530                 ilUtil::delDir($a_target_dir);
01531                 ilUtil::makeDir($a_target_dir);
01532                 $mob_dir = $a_target_dir."/mobs";
01533                 ilUtil::makeDir($mob_dir);
01534                 $file_dir = $a_target_dir."/files";
01535                 ilUtil::makeDir($file_dir);
01536 
01537                 // export system style sheet
01538                 $location_stylesheet = ilUtil::getStyleSheetLocation("filesystem");
01539                 $style_name = $ilias->account->prefs["style"].".css";
01540                 copy($location_stylesheet, $a_target_dir."/".$style_name);
01541                 $location_stylesheet = ilUtil::getStyleSheetLocation();
01542                 
01543                 // export content style sheet
01544                 if ($this->getStyleSheetId() < 1)
01545                 {
01546                         $cont_stylesheet = "content/content.css";
01547                         copy($cont_stylesheet, $a_target_dir."/content.css");
01548                 }
01549                 else
01550                 {
01551                         $style = new ilObjStyleSheet($this->getStyleSheetId());
01552                         $style->writeCSSFile($a_target_dir."/content.css");
01553                 }
01554                 
01555                 // export syntax highlighting style
01556                 $syn_stylesheet = "content/syntaxhighlight.css";
01557                 copy($syn_stylesheet, $a_target_dir."/syntaxhighlight.css");
01558 
01559                 // get learning module presentation gui class
01560                 include_once("content/classes/class.ilLMPresentationGUI.php");
01561                 $_GET["cmd"] = "nop";
01562                 $lm_gui =& new ilLMPresentationGUI();
01563                 $lm_gui->setOfflineMode(true);
01564 
01565                 // export pages
01566                 $this->exportHTMLPages($lm_gui, $a_target_dir);
01567                 
01568                 // export glossary terms
01569                 $this->exportHTMLGlossaryTerms($lm_gui, $a_target_dir);
01570                 
01571                 // export all media objects
01572                 foreach ($this->offline_mobs as $mob)
01573                 {
01574                         $this->exportHTMLMOB($a_target_dir, $lm_gui, $mob, "_new");
01575                 }
01576                 $_GET["obj_type"]  = "MediaObject";
01577                 $_GET["obj_id"]  = $a_mob_id;
01578                 $_GET["cmd"] = "";
01579                 
01580                 // export all file objects
01581                 foreach ($this->offline_files as $file)
01582                 {
01583                         $this->exportHTMLFile($a_target_dir, $file);
01584                 }
01585                 
01586                 // export table of contents
01587                 if ($this->isActiveTOC())
01588                 {
01589                         $tpl = new ilTemplate("tpl.main.html", true, true);
01590                         //$tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
01591                         $content =& $lm_gui->showTableOfContents();
01592                         $file = $a_target_dir."/table_of_contents.html";
01593                                 
01594                         // open file
01595                         if (!($fp = @fopen($file,"w+")))
01596                         {
01597                                 die ("<b>Error</b>: Could not open \"".$file."\" for writing".
01598                                         " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
01599                         }
01600                         chmod($file, 0770);
01601                         fwrite($fp, $content);
01602                         fclose($fp);
01603                 }
01604 
01605                 // export images
01606                 $image_dir = $a_target_dir."/images";
01607                 ilUtil::makeDir($image_dir);
01608                 ilUtil::makeDir($image_dir."/browser");
01609                 copy(ilUtil::getImagePath("enlarge.gif", false, "filesystem"),
01610                         $image_dir."/enlarge.gif");
01611                 copy(ilUtil::getImagePath("browser/blank.gif", false, "filesystem"),
01612                         $image_dir."/browser/plus.gif");
01613                 copy(ilUtil::getImagePath("browser/blank.gif", false, "filesystem"),
01614                         $image_dir."/browser/minus.gif");
01615                 copy(ilUtil::getImagePath("browser/blank.gif", false, "filesystem"),
01616                         $image_dir."/browser/blank.gif");
01617                 copy(ilUtil::getImagePath("icon_st.gif", false, "filesystem"),
01618                         $image_dir."/icon_st.gif");
01619                 copy(ilUtil::getImagePath("icon_pg.gif", false, "filesystem"),
01620                         $image_dir."/icon_pg.gif");
01621                 copy(ilUtil::getImagePath("nav_arr_L.gif", false, "filesystem"),
01622                         $image_dir."/nav_arr_L.gif");
01623                 copy(ilUtil::getImagePath("nav_arr_R.gif", false, "filesystem"),
01624                         $image_dir."/nav_arr_R.gif");
01625                         
01626                 // template workaround: reset of template 
01627                 $tpl = new ilTemplate("tpl.main.html", true, true);
01628                 $tpl->setVariable("LOCATION_STYLESHEET",$location_stylesheet);
01629                 $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
01630                 
01631                 // zip it all
01632                 $date = time();
01633                 $zip_file = $this->getExportDirectory("html")."/".$date."__".IL_INST_ID."__".
01634                         $this->getType()."_".$this->getId().".zip";
01635 //echo "zip-".$a_target_dir."-to-".$zip_file;
01636                 ilUtil::zip($a_target_dir, $zip_file);
01637                 ilUtil::delDir($a_target_dir);
01638         }
01639         
01643         function exportHTMLFile($a_target_dir, $a_file_id)
01644         {
01645                 $file_dir = $a_target_dir."/files/file_".$a_file_id;
01646                 ilUtil::makeDir($file_dir);
01647                 include_once("classes/class.ilObjFile.php");
01648                 $file_obj = new ilObjFile($a_file_id, false);
01649                 $source_file = $file_obj->getDirectory($file_obj->getVersion())."/".$file_obj->getFileName();
01650                 if (!is_file($source_file))
01651                 {
01652                         $source_file = $file_obj->getDirectory()."/".$file_obj->getFileName();
01653                 }
01654                 copy($source_file, $file_dir."/".$file_obj->getFileName());
01655         }
01656 
01660         function exportHTMLMOB($a_target_dir, &$a_lm_gui, $a_mob_id, $a_frame = "")
01661         {
01662                 global $tpl;
01663 
01664                 $mob_dir = $a_target_dir."/mobs";
01665 
01666                 $source_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob_id;
01667                 if (@is_dir($source_dir))
01668                 {
01669                         ilUtil::makeDir($mob_dir."/mm_".$a_mob_id);
01670                         ilUtil::rCopy($source_dir, $mob_dir."/mm_".$a_mob_id);
01671                 }
01672                 
01673                 $tpl = new ilTemplate("tpl.main.html", true, true);
01674                 $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
01675                 $_GET["obj_type"]  = "MediaObject";
01676                 $_GET["mob_id"]  = $a_mob_id;
01677                 $_GET["frame"] = $a_frame;
01678                 $_GET["cmd"] = "";
01679                 $content =& $a_lm_gui->media();
01680                 $file = $a_target_dir."/media_".$a_mob_id.".html";
01681 
01682                 // open file
01683                 if (!($fp = @fopen($file,"w+")))
01684                 {
01685                         die ("<b>Error</b>: Could not open \"".$file."\" for writing".
01686                                 " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
01687                 }
01688                 chmod($file, 0770);
01689                 fwrite($fp, $content);
01690                 fclose($fp);
01691                 
01692                 // fullscreen
01693                 include_once("content/classes/Media/class.ilObjMediaObject.php");
01694                 $mob_obj = new ilObjMediaObject($a_mob_id);
01695                 if ($mob_obj->hasFullscreenItem())
01696                 {
01697                         $tpl = new ilTemplate("tpl.main.html", true, true);
01698                         $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
01699                         $_GET["obj_type"]  = "";
01700                         $_GET["frame"]  = "";
01701                         $_GET["mob_id"]  = $a_mob_id;
01702                         $_GET["cmd"] = "fullscreen";
01703                         $content =& $a_lm_gui->fullscreen();
01704                         $file = $a_target_dir."/fullscreen_".$a_mob_id.".html";
01705         
01706                         // open file
01707                         if (!($fp = @fopen($file,"w+")))
01708                         {
01709                                 die ("<b>Error</b>: Could not open \"".$file."\" for writing".
01710                                         " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
01711                         }
01712                         chmod($file, 0770);
01713                         fwrite($fp, $content);
01714                         fclose($fp);
01715                 }
01716         }
01717         
01721         function exportHTMLGlossaryTerms(&$a_lm_gui, $a_target_dir)
01722         {
01723                 foreach($this->offline_int_links as $int_link)
01724                 {
01725                         if ($int_link["type"] == "git")
01726                         {
01727                                 $tpl = new ilTemplate("tpl.main.html", true, true);
01728                                 $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
01729 
01730                                 $_GET["obj_id"] = $int_link["id"];
01731                                 $_GET["frame"] = "_new";
01732                                 $content =& $a_lm_gui->glossary();
01733                                 $file = $a_target_dir."/term_".$int_link["id"].".html";
01734                                         
01735                                 // open file
01736                                 if (!($fp = @fopen($file,"w+")))
01737                                 {
01738                                         die ("<b>Error</b>: Could not open \"".$file."\" for writing".
01739                                                         " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
01740                                 }
01741                                 chmod($file, 0770);
01742                                 fwrite($fp, $content);
01743                                 fclose($fp);
01744 
01745                                 // store linked/embedded media objects of glosssary term
01746                                 include_once("content/classes/class.ilGlossaryDefinition.php");
01747                                 $defs = ilGlossaryDefinition::getDefinitionList($int_link["id"]);
01748                                 foreach($defs as $def)
01749                                 {
01750                                         $def_mobs = ilObjMediaObject::_getMobsOfObject("gdf:pg", $def["id"]);
01751                                         foreach($def_mobs as $def_mob)
01752                                         {
01753                                                 $this->offline_mobs[$def_mob] = $def_mob;
01754                                         }
01755                                         
01756                                         // get all files of page
01757                                         $def_files = ilObjFile::_getFilesOfObject("gdf:pg", $page["obj_id"]);
01758                                         $this->offline_files = array_merge($this->offline_files, $def_files);
01759 
01760                                 }
01761                                 
01762                         }
01763                 }
01764         }
01765         
01769         function exportHTMLPages(&$a_lm_gui, $a_target_dir)
01770         {
01771                 global $tpl;
01772                                 
01773                 $pages = ilLMPageObject::getPageList($this->getId());
01774                 
01775                 $lm_tree =& $this->getLMTree();
01776                 $first_page = $lm_tree->fetchSuccessorNode($lm_tree->getRootId(), "pg");
01777                 $this->first_page_id = $first_page["child"];
01778 
01779                 // iterate all learning module pages
01780                 $mobs = array();
01781                 $int_links = array();
01782                 $this->offline_files = array();
01783                 foreach ($pages as $page)
01784                 {
01785                         $this->exportPageHTML($a_lm_gui, $a_target_dir, $page["obj_id"]);
01786                         
01787                         // get all media objects of page
01788                         include_once("content/classes/Media/class.ilObjMediaObject.php");
01789                         $pg_mobs = ilObjMediaObject::_getMobsOfObject($this->getType().":pg", $page["obj_id"]);
01790                         foreach($pg_mobs as $pg_mob)
01791                         {
01792                                 $mobs[$pg_mob] = $pg_mob;
01793                         }
01794                         
01795                         // get all internal links of page
01796                         $pg_links = ilInternalLink::_getTargetsOfSource($this->getType().":pg", $page["obj_id"]);
01797                         $int_links = array_merge($int_links, $pg_links);
01798                         
01799                         // get all files of page
01800                         include_once("classes/class.ilObjFile.php");
01801                         $pg_files = ilObjFile::_getFilesOfObject($this->getType().":pg", $page["obj_id"]);
01802                         $this->offline_files = array_merge($this->offline_files, $pg_files);
01803                         
01804                 }
01805                 $this->offline_mobs = $mobs;
01806                 $this->offline_int_links = $int_links;
01807                 
01808         }
01809 
01813         function exportPageHTML(&$a_lm_gui, $a_target_dir, $a_lm_page_id, $a_frame = "")
01814         {
01815                 global $ilias, $tpl;
01816 //echo "<br>B: export Page HTML ($a_lm_page_id)"; flush();
01817                 // template workaround: reset of template 
01818                 $tpl = new ilTemplate("tpl.main.html", true, true);
01819                 $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
01820 
01821                 $_GET["obj_id"] = $a_lm_page_id;
01822                 $_GET["frame"] = $a_frame;
01823                 $content =& $a_lm_gui->layout("main.xml", false);
01824                 
01825                 if ($a_frame == "")
01826                 {
01827                         $file = $a_target_dir."/lm_pg_".$a_lm_page_id.".html";
01828                 }
01829                 else
01830                 {
01831                         if ($a_frame != "toc")
01832                         {
01833                                 $file = $a_target_dir."/frame_".$a_lm_page_id."_".$a_frame.".html";
01834                         }
01835                         else
01836                         {
01837                                 $file = $a_target_dir."/frame_".$a_frame.".html";
01838                         }
01839                 }
01840                 
01841                 // return if file is already existing
01842                 if (@is_file($file))
01843                 {
01844                         return;
01845                 }
01846                 
01847                 // open file
01848                 if (!($fp = @fopen($file,"w+")))
01849                 {
01850                         die ("<b>Error</b>: Could not open \"".$file."\" for writing".
01851                                         " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
01852                 }
01853         
01854                 // set file permissions
01855                 chmod($file, 0770);
01856                         
01857                 // write xml data into the file
01858                 fwrite($fp, $content);
01859                 
01860                 // close file
01861                 fclose($fp);
01862 
01863                 if ($this->first_page_id == $a_lm_page_id && $a_frame == "")
01864                 {
01865                         copy($file, $a_target_dir."/index.html");
01866                 }
01867 
01868                 // write frames of frameset
01869                 $frameset = $a_lm_gui->getCurrentFrameSet();
01870                 foreach ($frameset as $frame)
01871                 {                               
01872                         $this->exportPageHTML($a_lm_gui, $a_target_dir, $a_lm_page_id, $frame);
01873                 }
01874 
01875         }
01876 
01883         function exportFO(&$a_xml_writer, $a_target_dir)
01884         {
01885                 global $ilBench;
01886 
01887                 // fo:root (start)
01888                 $attrs = array();
01889                 $attrs["xmlns:fo"] = "http://www.w3.org/1999/XSL/Format";
01890                 $a_xml_writer->xmlStartTag("fo:root", $attrs);
01891 
01892                 // fo:layout-master-set (start)
01893                 $attrs = array();
01894                 $a_xml_writer->xmlStartTag("fo:layout-master-set", $attrs);
01895 
01896                 // fo:simple-page-master (start)
01897                 $attrs = array();
01898                 $attrs["master-name"] = "DinA4";
01899                 $attrs["page-height"] = "29.7cm";
01900                 $attrs["page-width"] = "21cm";
01901                 $attrs["margin-top"] = "4cm";
01902                 $attrs["margin-bottom"] = "1cm";
01903                 $attrs["margin-left"] = "2.8cm";
01904                 $attrs["margin-right"] = "7.3cm";
01905                 $a_xml_writer->xmlStartTag("fo:simple-page-master", $attrs);
01906 
01907                 // fo:region-body (complete)
01908                 $attrs = array();
01909                 $attrs["margin-top"] = "0cm";
01910                 $attrs["margin-bottom"] = "1.25cm";
01911                 $a_xml_writer->xmlElement("fo:region-body", $attrs);
01912 
01913                 // fo:region-before (complete)
01914                 $attrs = array();
01915                 $attrs["extent"] = "1cm";
01916                 $a_xml_writer->xmlElement("fo:region-before", $attrs);
01917 
01918                 // fo:region-after (complete)
01919                 $attrs = array();
01920                 $attrs["extent"] = "1cm";
01921                 $a_xml_writer->xmlElement("fo:region-after", $attrs);
01922 
01923                 // fo:simple-page-master (end)
01924                 $a_xml_writer->xmlEndTag("fo:simple-page-master");
01925 
01926                 // fo:layout-master-set (end)
01927                 $a_xml_writer->xmlEndTag("fo:layout-master-set");
01928 
01929                 // fo:page-sequence (start)
01930                 $attrs = array();
01931                 $attrs["master-reference"] = "DinA4";
01932                 $a_xml_writer->xmlStartTag("fo:page-sequence", $attrs);
01933 
01934                 // fo:flow (start)
01935                 $attrs = array();
01936                 $attrs["flow-name"] = "xsl-region-body";
01937                 $a_xml_writer->xmlStartTag("fo:flow", $attrs);
01938 
01939 
01940                 // StructureObjects
01941                 //$expLog->write(date("[y-m-d H:i:s] ")."Start Export Structure Objects");
01942                 $ilBench->start("ContentObjectExport", "exportFOStructureObjects");
01943                 $this->exportFOStructureObjects($a_xml_writer, $expLog);
01944                 $ilBench->stop("ContentObjectExport", "exportFOStructureObjects");
01945                 //$expLog->write(date("[y-m-d H:i:s] ")."Finished Export Structure Objects");*/
01946 
01947                 // fo:flow (end)
01948                 $a_xml_writer->xmlEndTag("fo:flow");
01949 
01950                 // fo:page-sequence (end)
01951                 $a_xml_writer->xmlEndTag("fo:page-sequence");
01952 
01953                 // fo:root (end)
01954                 $a_xml_writer->xmlEndTag("fo:root");
01955         }
01956 
01963         function exportFOStructureObjects(&$a_xml_writer)
01964         {
01965                 $childs = $this->lm_tree->getChilds($this->lm_tree->getRootId());
01966                 foreach ($childs as $child)
01967                 {
01968                         if($child["type"] != "st")
01969                         {
01970                                 continue;
01971                         }
01972 
01973                         $structure_obj = new ilStructureObject($this, $child["obj_id"]);
01974                         $structure_obj->exportFO($a_xml_writer, $expLog);
01975                         unset($structure_obj);
01976                 }
01977         }
01978 
01979         function getXMLZip()
01980         {
01981                 include_once("./content/classes/class.ilContObjectExport.php");
01982 
01983                 $cont_exp = new ilContObjectExport($this,'xml');
01984 
01985                 $export_file = $cont_exp->buildExportFile();
01986                 return $export_file;
01987         }               
01988 
01989 
01990 }
01991 ?>

Generated on Fri Dec 13 2013 08:00:16 for ILIAS Release_3_3_x_branch .rev 46803 by  doxygen 1.7.1