/**
  * get html 
  * @return
  */
 public function getHTML()
 {
     global $lng;
     $lng->loadLanguageModule('content');
     foreach ($this->getSubItemIds(true) as $sub_item) {
         if (is_object($this->getHighlighter()) and strlen($this->getHighlighter()->getContent($this->getObjId(), $sub_item))) {
             $this->tpl->setCurrentBlock('sea_fragment');
             $this->tpl->setVariable('TXT_FRAGMENT', $this->getHighlighter()->getContent($this->getObjId(), $sub_item));
             $this->tpl->parseCurrentBlock();
         }
         $this->tpl->setCurrentBlock('subitem');
         $this->tpl->setVariable('SEPERATOR', ':');
         include_once './Modules/MediaPool/classes/class.ilMediaPoolItem.php';
         switch (ilMediaPoolItem::lookupType($sub_item)) {
             case 'fold':
                 $this->tpl->setVariable('LINK', ilLink::_getLink($this->getRefId(), 'mep', array(), '_' . $sub_item));
                 $this->tpl->setVariable('TARGET', $this->getItemListGUI()->getCommandFrame(''));
                 break;
             case 'mob':
                 $this->tpl->setVariable('LINK', $this->getItemListGUI()->getCommandLink('allMedia') . '&force_filter=' . $sub_item);
                 $this->tpl->setVariable('TARGET', $this->getItemListGUI()->getCommandFrame(''));
                 break;
             default:
         }
         $this->tpl->setVariable('SUBITEM_TYPE', $lng->txt('obj_' . ilMediaPoolItem::lookupType($sub_item)));
         $this->tpl->setVariable('TITLE', ilMediaPoolItem::lookupTitle($sub_item));
         $this->tpl->parseCurrentBlock();
     }
     $this->showDetailsLink();
     return $this->tpl->get();
 }
 protected function parseImage($a_sub_id)
 {
     include_once './Modules/MediaPool/classes/class.ilMediaPoolItem.php';
     $sub_id = ilMediaPoolItem::lookupForeignId($a_sub_id);
     // output thumbnail (or mob icon)
     if (ilObject::_lookupType($sub_id) == "mob") {
         include_once "./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php";
         $mob = new ilObjMediaObject($sub_id);
         $med = $mob->getMediaItem("Standard");
         $target = $med->getThumbnailTarget();
         if ($target != "") {
             // begin-patch mime_filter
             $this->tpl->setVariable('LINKED_LINK', ilLink::_getLink($this->getRefId(), 'mep', array('action' => 'showMedia', 'mob_id' => $sub_id, 'mepitem_id' => $a_sub_id)));
             $this->tpl->setVariable('LINKED_TARGET', '_blank');
             $this->tpl->setVariable("LINKED_IMAGE", ilUtil::img($target));
             // end-patch mime_filter
         } else {
             $this->tpl->setVariable("SUB_ITEM_IMAGE", ilUtil::img(ilUtil::getImagePath("icon_" . $a_set["type"] . ".gif")));
         }
         if (ilUtil::deducibleSize($med->getFormat()) && $med->getLocationType() == "Reference") {
             $size = @getimagesize($med->getLocation());
             if ($size[0] > 0 && $size[1] > 0) {
                 $wr = $size[0] / 80;
                 $hr = $size[1] / 80;
                 $r = max($wr, hr);
                 $w = (int) ($size[0] / $r);
                 $h = (int) ($size[1] / $r);
                 $this->tpl->setVariable("SUB_ITEM_IMAGE", ilUtil::img($med->getLocation(), "", $w, $h));
                 return true;
             }
         }
     }
     return false;
 }
 /**
  * Handle an event in a listener.
  *
  * @param	string	$a_component	component, e.g. "Modules/Forum" or "Services/User"
  * @param	string	$a_event		event e.g. "createUser", "updateUser", "deleteUser", ...
  * @param	array	$a_parameter	parameter array (assoc), array("name" => ..., "phone_office" => ...)
  */
 static function handleEvent($a_component, $a_event, $a_parameter)
 {
     include_once "./Services/Tagging/classes/class.ilTagging.php";
     switch ($a_component) {
         case "Services/Object":
             switch ($a_event) {
                 case "update":
                     if ($a_parameter["obj_type"] == "mob") {
                         include_once "./Modules/MediaPool/classes/class.ilMediaPoolItem.php";
                         ilMediaPoolItem::updateObjectTitle($a_parameter["obj_id"]);
                     }
                     break;
             }
             break;
     }
 }
 /**
  * Show link help list
  */
 function showLinkHelp()
 {
     global $ilUser, $ilCtrl;
     // filter link types
     if (!$this->filter_white_list) {
         foreach ($this->filter_link_types as $link_type) {
             unset($this->ltypes[$link_type]);
         }
     } else {
         $ltypes = array();
         foreach ($this->ltypes as $k => $l) {
             if (in_array($k, $this->filter_link_types)) {
                 $ltypes[$k] = $l;
             }
         }
         $this->ltypes = $ltypes;
     }
     // determine link type and target
     $this->determineLinkType();
     $ltype = $this->link_target != "" ? $this->link_type . "_" . $this->link_target : $this->link_type;
     $def_type = ilObject::_lookupType($this->default_obj, true);
     // determine content object id
     switch ($this->link_type) {
         case "PageObject":
         case "StructureObject":
             if (empty($_SESSION["il_link_cont_obj"]) && ($def_type != "mep" && $def_type != "glo")) {
                 $_SESSION["il_link_cont_obj"] = $this->default_obj;
             }
             break;
         case "GlossaryItem":
             if (empty($_SESSION["il_link_glossary"]) && $def_type == "glo") {
                 $_SESSION["il_link_glossary"] = $this->default_obj;
             }
             break;
         case "Media":
             if (empty($_SESSION["il_link_mep"]) && $def_type == "mep") {
                 $_SESSION["il_link_mep"] = $this->default_obj;
             }
             break;
     }
     /*
     		$target_str = ($link_target == "")
     			? ""
     			: " target=\"".$link_target."\" ";*/
     $target_str = $this->link_target == "" ? "" : " target=\"" . $this->link_target . "\"";
     //echo "-".$this->link_type."-";
     if ($this->link_type == "GlossaryItem" && (empty($_SESSION["il_link_glossary"]) || !in_array(ilObject::_lookupType($_SESSION["il_link_glossary"], true), array("glo")))) {
         $this->changeTargetObject("glo");
     }
     if (($this->link_type == "PageObject" || $this->link_type == "StructureObject") && (empty($_SESSION["il_link_cont_obj"]) || !in_array(ilObject::_lookupType($_SESSION["il_link_cont_obj"], true), array("lm", "dbk")))) {
         $this->changeTargetObject("cont_obj");
     }
     if ($ilCtrl->isAsynch()) {
         $tpl = new ilTemplate("tpl.link_help_asynch.html", true, true, "Modules/LearningModule");
     } else {
         $tpl =& new ilTemplate("tpl.link_help.html", true, true, "Modules/LearningModule");
         $tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
     }
     switch ($this->link_type) {
         case "GlossaryItem":
             $this->ctrl->setParameter($this, "target_type", "glo");
             break;
         case "PageObject":
         case "StructureObject":
             $this->ctrl->setParameter($this, "target_type", "cont_obj");
             break;
         case "Media":
             $this->ctrl->setParameter($this, "target_type", "mep");
             break;
         default:
             break;
     }
     //echo "<br><br>:".$this->ctrl->getFormAction($this).":";
     //echo "<br>link_type:".$this->link_type;
     //echo "<br>cont_obj:".$_SESSION["il_link_cont_obj"];
     //echo "<br>link_mep".$_SESSION["il_link_mep"];
     //echo $this->ctrl->getFormAction($this, "", "", true);
     $tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "changeLinkType", "", true));
     $tpl->setVariable("FORMACTION2", $this->ctrl->getFormAction($this));
     $tpl->setVariable("TXT_HELP_HEADER", $this->lng->txt("cont_link_select"));
     $tpl->setVariable("TXT_TYPE", $this->lng->txt("cont_link_type"));
     //echo "<br><br>".$ltype;
     $select_ltype = ilUtil::formSelect($ltype, "ltype", $this->ltypes, false, true, "0", "", array("id" => "ilIntLinkTypeSelector"));
     $tpl->setVariable("SELECT_TYPE", $select_ltype);
     $tpl->setVariable("CMD_CHANGETYPE", "changeLinkType");
     $tpl->setVariable("BTN_CHANGETYPE", $this->lng->txt("cont_change_type"));
     /*		if ($this->isEnabledJavaScript())
     		{
     			$tpl->setVariable("BTN_CLOSE_JS", $this->lng->txt("close"));
     		}
     		else 
     		{*/
     $tpl->setVariable("CMD_CLOSE", "closeLinkHelp");
     $tpl->setVariable("BTN_CLOSE", $this->lng->txt("close"));
     //		}
     $chapterRowBlock = "chapter_row";
     $anchor_row_block = "anchor_link";
     if ($this->isEnabledJavaScript()) {
         $chapterRowBlock .= "_js";
         $anchor_row_block .= "_js";
     }
     $obj_id = ilObject::_lookupObjId($_SESSION["il_link_cont_obj"]);
     $type = ilObject::_lookupType($obj_id);
     // switch link type
     switch ($this->link_type) {
         // page link
         case "PageObject":
             require_once "./Modules/LearningModule/classes/class.ilObjLearningModule.php";
             include_once "./Modules/LearningModule/classes/class.ilLMPage.php";
             $cont_obj = new ilObjLearningModule($_SESSION["il_link_cont_obj"], true);
             // get all chapters
             $ctree = $cont_obj->getLMTree();
             $nodes = $ctree->getSubtree($ctree->getNodeData($ctree->getRootId()));
             $tpl->setCurrentBlock("chapter_list");
             $tpl->setVariable("TXT_CONTENT_OBJECT", $this->lng->txt("cont_content_obj"));
             $tpl->setVariable("TXT_CONT_TITLE", $cont_obj->getTitle());
             $tpl->setCurrentBlock("change_cont_obj");
             $tpl->setVariable("CMD_CHANGE_CONT_OBJ", "changeTargetObject");
             $tpl->setVariable("BTN_CHANGE_CONT_OBJ", $this->lng->txt("change"));
             $tpl->parseCurrentBlock();
             foreach ($nodes as $node) {
                 if ($node["type"] == "st") {
                     $tpl->setCurrentBlock("chapter_row");
                     $tpl->setVariable("TXT_CHAPTER", $node["title"]);
                     $tpl->setVariable("ROWCLASS", "tblrow1");
                     //$tpl->setVariable("LINK_CHAPTER",
                     //	"[iln chap=\"".$node["obj_id"]."\"".$target_str."] [/iln]");
                     $tpl->parseCurrentBlock();
                     $tpl->setCurrentBlock("row");
                     $tpl->parseCurrentBlock();
                 }
                 if ($node["type"] == "pg") {
                     include_once "./Services/COPage/classes/class.ilPCParagraph.php";
                     $this->renderLink($tpl, $node["title"], $node["obj_id"], "PageObject", "pg", "page", ilPCParagraph::_readAnchors($type, $node["obj_id"], ""));
                 }
             }
             // get all free pages
             $pages = ilLMPageObject::getPageList($cont_obj->getId());
             $free_pages = array();
             foreach ($pages as $page) {
                 if (!$ctree->isInTree($page["obj_id"])) {
                     $free_pages[] = $page;
                 }
             }
             if (count($free_pages) > 0) {
                 $tpl->setCurrentBlock(str_replace("_js", "", $chapterRowBlock));
                 $tpl->setVariable("TXT_CHAPTER", $this->lng->txt("cont_free_pages"));
                 $tpl->setVariable("ROWCLASS", "tblrow1");
                 $tpl->parseCurrentBlock();
                 foreach ($free_pages as $node) {
                     include_once "./Services/COPage/classes/class.ilPCParagraph.php";
                     $this->renderLink($tpl, $node["title"], $node["obj_id"], "PageObject", "pg", "page", ilPCParagraph::_readAnchors($type, $node["obj_id"], ""));
                 }
             }
             $tpl->setCurrentBlock("chapter_list");
             $tpl->parseCurrentBlock();
             break;
             // chapter link
         // chapter link
         case "StructureObject":
             // check whether current object matchs to type
             if (!in_array(ilObject::_lookupType($_SESSION["il_link_cont_obj"], true), array("lm", "dbk"))) {
                 $this->changeTargetObject("lm");
             }
             if ($type == "lm") {
                 require_once "./Modules/LearningModule/classes/class.ilObjLearningModule.php";
                 $cont_obj = new ilObjLearningModule($_SESSION["il_link_cont_obj"], true);
             } else {
                 if ($type == "dbk") {
                     require_once "./Modules/LearningModule/classes/class.ilObjDlBook.php";
                     $cont_obj = new ilObjDlBook($_SESSION["il_link_cont_obj"], true);
                 }
             }
             // get all chapters
             $ctree =& $cont_obj->getLMTree();
             $nodes = $ctree->getSubtree($ctree->getNodeData($ctree->getRootId()));
             $tpl->setCurrentBlock("chapter_list");
             $tpl->setVariable("TXT_CONTENT_OBJECT", $this->lng->txt("cont_content_obj"));
             $tpl->setVariable("TXT_CONT_TITLE", $cont_obj->getTitle());
             $tpl->setCurrentBlock("change_cont_obj");
             $tpl->setVariable("CMD_CHANGE_CONT_OBJ", "changeTargetObject");
             $tpl->setVariable("BTN_CHANGE_CONT_OBJ", $this->lng->txt("change"));
             $tpl->parseCurrentBlock();
             foreach ($nodes as $node) {
                 if ($node["type"] == "st") {
                     $this->renderLink($tpl, $node["title"], $node["obj_id"], "StructureObject", "st", "chap");
                 }
             }
             $tpl->setCurrentBlock("chapter_list");
             $tpl->parseCurrentBlock();
             break;
             // glossary item link
         // glossary item link
         case "GlossaryItem":
             require_once "./Modules/Glossary/classes/class.ilObjGlossary.php";
             $glossary =& new ilObjGlossary($_SESSION["il_link_glossary"], true);
             // get all glossary items
             $terms = $glossary->getTermList();
             $tpl->setCurrentBlock("chapter_list");
             $tpl->setVariable("TXT_CONTENT_OBJECT", $this->lng->txt("glossary"));
             $tpl->setVariable("TXT_CONT_TITLE", $glossary->getTitle());
             $tpl->setCurrentBlock("change_cont_obj");
             $tpl->setVariable("CMD_CHANGE_CONT_OBJ", "changeTargetObject");
             $tpl->setVariable("BTN_CHANGE_CONT_OBJ", $this->lng->txt("change"));
             $tpl->parseCurrentBlock();
             foreach ($terms as $term) {
                 $this->renderLink($tpl, $term["term"], $term["id"], "GlossaryItem", "git", "term");
             }
             $tpl->setCurrentBlock("chapter_list");
             $tpl->parseCurrentBlock();
             break;
             // media object
         // media object
         case "Media":
             include_once "./Modules/MediaPool/classes/class.ilMediaPoolItem.php";
             //$tpl->setVariable("TARGET2", " target=\"content\" ");
             // content object id = 0 --> get clipboard objects
             if ($_SESSION["il_link_mep"] == 0) {
                 $tpl->setCurrentBlock("change_cont_obj");
                 $tpl->setVariable("CMD_CHANGE_CONT_OBJ", "changeTargetObject");
                 $tpl->setVariable("BTN_CHANGE_CONT_OBJ", $this->lng->txt("change"));
                 $tpl->parseCurrentBlock();
                 $mobjs = $this->ilias->account->getClipboardObjects("mob");
                 // sort by name
                 $objs = array();
                 foreach ($mobjs as $obj) {
                     $objs[$obj["title"] . ":" . $obj["id"]] = $obj;
                 }
                 ksort($objs);
                 $tpl->setCurrentBlock("chapter_list");
                 $tpl->setVariable("TXT_CONTENT_OBJECT", $this->lng->txt("cont_media_source"));
                 $tpl->setVariable("TXT_CONT_TITLE", $this->lng->txt("cont_personal_clipboard"));
                 $tpl->setVariable("COLSPAN", "2");
                 foreach ($objs as $obj) {
                     $this->renderLink($tpl, $obj["title"], $obj["id"], "MediaObject", "mob", "media");
                 }
                 $tpl->setCurrentBlock("chapter_list");
                 $tpl->parseCurrentBlock();
             } else {
                 require_once "./Modules/MediaPool/classes/class.ilObjMediaPool.php";
                 $med_pool =& new ilObjMediaPool($_SESSION["il_link_mep"], true);
                 // get current folders
                 $fobjs = $med_pool->getChilds($_SESSION["il_link_mep_obj"], "fold");
                 $f2objs = array();
                 foreach ($fobjs as $obj) {
                     $f2objs[$obj["title"] . ":" . $obj["child"]] = $obj;
                 }
                 ksort($f2objs);
                 // get current media objects
                 $mobjs = $med_pool->getChilds($_SESSION["il_link_mep_obj"], "mob");
                 $m2objs = array();
                 foreach ($mobjs as $obj) {
                     $m2objs[$obj["title"] . ":" . $obj["child"]] = $obj;
                 }
                 ksort($m2objs);
                 // merge everything together
                 $objs = array_merge($f2objs, $m2objs);
                 $tpl->setCurrentBlock("chapter_list");
                 $tpl->setVariable("TXT_CONTENT_OBJECT", $this->lng->txt("mep"));
                 $tpl->setVariable("TXT_CONT_TITLE", $med_pool->getTitle());
                 $tpl->setCurrentBlock("change_cont_obj");
                 $tpl->setVariable("CMD_CHANGE_CONT_OBJ", "changeTargetObject");
                 $tpl->setVariable("BTN_CHANGE_CONT_OBJ", $this->lng->txt("change"));
                 $tpl->setVariable("COLSPAN", "2");
                 $tpl->parseCurrentBlock();
                 if ($parent_id = $med_pool->getParentId($_SESSION["il_link_mep_obj"])) {
                     $css_row = "tblrow1";
                     $tpl->setCurrentBlock("icon");
                     $tpl->setVariable("ICON_SRC", ilUtil::getImagePath("icon_fold.png"));
                     $tpl->parseCurrentBlock();
                     $tpl->setCurrentBlock("link_row");
                     $tpl->setVariable("ROWCLASS", $css_row);
                     $tpl->setVariable("TXT_CHAPTER", "..");
                     $this->ctrl->setParameter($this, "mep_fold", $parent_id);
                     if ($ilCtrl->isAsynch()) {
                         $tpl->setVariable("LINK", "#");
                         $tpl->setVariable("LR_ONCLICK", " onclick=\"return il.IntLink.setMepPoolFolder('" . $parent_id . "');\" ");
                     } else {
                         $tpl->setVariable("LINK", $this->ctrl->getLinkTarget($this, "setMedPoolFolder"));
                     }
                     $tpl->parseCurrentBlock();
                     $tpl->setCurrentBlock("row");
                     $tpl->parseCurrentBlock();
                 }
                 foreach ($objs as $obj) {
                     if ($obj["type"] == "fold") {
                         $css_row = $css_row == "tblrow2" ? "tblrow1" : "tblrow2";
                         $tpl->setCurrentBlock("icon");
                         $tpl->setVariable("ICON_SRC", ilUtil::getImagePath("icon_fold.png"));
                         $tpl->parseCurrentBlock();
                         $tpl->setCurrentBlock("link_row");
                         $tpl->setVariable("ROWCLASS", $css_row);
                         $tpl->setVariable("TXT_CHAPTER", $obj["title"]);
                         $this->ctrl->setParameter($this, "mep_fold", $obj["child"]);
                         if ($ilCtrl->isAsynch()) {
                             $tpl->setVariable("LINK", "#");
                             $tpl->setVariable("LR_ONCLICK", " onclick=\"return il.IntLink.setMepPoolFolder('" . $obj["child"] . "');\" ");
                         } else {
                             $tpl->setVariable("LINK", $this->ctrl->getLinkTarget($this, "setMedPoolFolder"));
                         }
                         $tpl->parseCurrentBlock();
                     } else {
                         $fid = ilMediaPoolItem::lookupForeignId($obj["child"]);
                         if (ilObject::_lookupType($fid) == "mob") {
                             $this->renderLink($tpl, $obj["title"], $fid, "MediaObject", "mob", "media");
                         }
                     }
                     $tpl->setCurrentBlock("row");
                     $tpl->parseCurrentBlock();
                 }
                 $tpl->setCurrentBlock("chapter_list");
                 $tpl->parseCurrentBlock();
             }
             break;
             // repository item
         // repository item
         case "RepositoryItem":
             $tpl->setVariable("LINK_HELP_CONTENT", $this->selectRepositoryItem());
             break;
             // file download link
         // file download link
         case "File":
             if (!is_object($this->uploaded_file)) {
                 $tpl->setVariable("LINK_HELP_CONTENT", $this->getFileLinkHTML());
             } else {
                 echo $this->getFileLinkHTML();
                 exit;
             }
             break;
     }
     if ($ilCtrl->isAsynch()) {
         echo $tpl->get();
         exit;
     }
     exit;
 }
 /**
  * Show snippet info
  */
 function showSnippetInfo()
 {
     global $tpl, $lng, $ilAccess, $ilCtrl;
     $stpl = new ilTemplate("tpl.snippet_info.html", true, true, "Services/COPage");
     include_once "./Modules/MediaPool/classes/class.ilMediaPoolItem.php";
     $mep_pools = ilMediaPoolItem::getPoolForItemId($_POST["ci_id"]);
     foreach ($mep_pools as $mep_id) {
         $ref_ids = ilObject::_getAllReferences($mep_id);
         $edit_link = false;
         foreach ($ref_ids as $rid) {
             if (!$edit_link && $ilAccess->checkAccess("write", "", $rid)) {
                 $stpl->setCurrentBlock("edit_link");
                 $stpl->setVariable("TXT_EDIT", $lng->txt("edit"));
                 $stpl->setVariable("HREF_EDIT", "./goto.php?target=mep_" . $rid);
                 $stpl->parseCurrentBlock();
             }
         }
         $stpl->setCurrentBlock("pool");
         $stpl->setVariable("TXT_MEDIA_POOL", $lng->txt("obj_mep"));
         $stpl->setVariable("VAL_MEDIA_POOL", ilObject::_lookupTitle($mep_id));
         $stpl->parseCurrentBlock();
     }
     include_once "./Modules/MediaPool/classes/class.ilMediaPoolPage.php";
     $stpl->setVariable("TXT_TITLE", $lng->txt("title"));
     $stpl->setVariable("VAL_TITLE", ilMediaPoolPage::lookupTitle($_POST["ci_id"]));
     $stpl->setVariable("TXT_BACK", $lng->txt("back"));
     $stpl->setVariable("HREF_BACK", $ilCtrl->getLinkTarget($this->page_gui, "edit"));
     $tpl->setContent($stpl->get());
 }
 /**
  * Show page 
  */
 function showPage($a_no_title = false)
 {
     global $tpl, $ilCtrl;
     $this->setTemplateOutput(false);
     if (!$a_no_title) {
         $this->setPresentationTitle(ilMediaPoolItem::lookupTitle($this->getMediaPoolPage()->getId()));
     }
     $output = parent::showPage();
     return $output;
 }
 /**
  * Lookup title
  */
 static function lookupTitle($a_page_id)
 {
     global $ilDB;
     include_once "./Modules/MediaPool/classes/class.ilMediaPoolItem.php";
     return ilMediaPoolItem::lookupTitle($a_page_id);
 }
 /**
  * Copy tree content
  *
  * @param
  * @return
  */
 function copyTreeContent($a_new_obj, $a_target_parent, $a_source_parent)
 {
     include_once "./Modules/MediaPool/classes/class.ilMediaPoolItem.php";
     include_once "./Modules/MediaPool/classes/class.ilMediaPoolPage.php";
     include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
     // get all chapters of root lm
     $nodes = $this->getTree()->getChilds($a_source_parent);
     foreach ($nodes as $node) {
         $item = new ilMediaPoolItem();
         $item->setType($node["type"]);
         switch ($node["type"]) {
             case "mob":
                 $mob_id = ilMediaPoolItem::lookupForeignId($node["child"]);
                 $mob = new ilObjMediaObject($mob_id);
                 $new_mob = $mob->duplicate();
                 $item->setForeignId($new_mob->getId());
                 $item->setTitle($new_mob->getTitle());
                 $item->create();
                 break;
             case "pg":
                 $item->setTitle($node["title"]);
                 $item->create();
                 $page = new ilMediaPoolPage($node["child"]);
                 $new_page = new ilMediaPoolPage();
                 $new_page->setId($item->getId());
                 $new_page->create();
                 // todo: make mobs being copied
                 $new_page->setXMLContent($page->copyXMLContent(true));
                 $new_page->buildDom();
                 $new_page->update();
                 break;
             case "fold":
                 $item->setTitle($node["title"]);
                 $item->create();
                 break;
         }
         // insert item into tree
         $a_new_obj->insertInTree($item->getId(), $a_target_parent);
         // handle childs
         $this->copyTreeContent($a_new_obj, $item->getId(), $node["child"]);
     }
 }
 /**
  * create new media object in dom and update page in db
  */
 function &create($a_create_alias = true, $a_change_obj_ref = false)
 {
     global $ilCtrl, $lng;
     if ($_GET["subCmd"] == "insertFromPool") {
         if (is_array($_POST["id"])) {
             for ($i = count($_POST["id"]) - 1; $i >= 0; $i--) {
                 include_once "./Modules/MediaPool/classes/class.ilMediaPoolItem.php";
                 $fid = ilMediaPoolItem::lookupForeignId($_POST["id"][$i]);
                 include_once "./Services/COPage/classes/class.ilPCMediaObject.php";
                 $this->content_obj = new ilPCMediaObject($this->getPage());
                 $this->content_obj->readMediaObject($fid);
                 $this->content_obj->createAlias($this->pg_obj, $_GET["hier_id"], $this->pc_id);
             }
             $this->updated = $this->pg_obj->update();
         }
         $ilCtrl->returnToParent($this);
     }
     // check form input
     $mob_gui = new ilObjMediaObjectGUI("");
     $mob_gui->initForm("create");
     if (!$mob_gui->checkFormInput()) {
         $this->form = $mob_gui->getForm();
         $this->insert("edpost", "create_mob", true);
         return;
     }
     // create dummy object in db (we need an id)
     include_once "./Services/COPage/classes/class.ilPCMediaObject.php";
     if ($a_change_obj_ref != true) {
         $this->content_obj = new ilPCMediaObject($this->getPage());
     }
     $this->content_obj->createMediaObject();
     $media_obj = $this->content_obj->getMediaObject();
     include_once "./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php";
     ilObjMediaObjectGUI::setObjectPerCreationForm($media_obj);
     if ($a_create_alias) {
         // need a pcmediaobject here
         //$this->node = $this->createPageContentNode();
         $this->content_obj->createAlias($this->pg_obj, $this->hier_id, $this->pc_id);
         $this->updated = $this->pg_obj->update();
         if ($this->updated === true) {
             $this->pg_obj->stripHierIDs();
             $this->pg_obj->addHierIDs();
             $ilCtrl->setParameter($this, "hier_id", $this->content_obj->readHierId());
             $ilCtrl->setParameter($this, "pc_id", $this->content_obj->readPCId());
             $this->content_obj->setHierId($this->content_obj->readHierId());
             $this->setHierId($this->content_obj->readHierId());
             $this->content_obj->setPCId($this->content_obj->readPCId());
             ilUtil::sendSuccess($lng->txt("saved_media_object"), true);
             $this->ctrl->redirectByClass("ilobjmediaobjectgui", "edit");
             //$this->ctrl->returnToParent($this, "jump".$this->hier_id);
         } else {
             $this->insert();
         }
     } else {
         if ($a_change_obj_ref == true) {
             $this->content_obj->updateObjectReference();
             $this->updated = $this->pg_obj->update();
             $this->ctrl->redirect($this, "editAlias");
         }
         return $this->content_obj;
     }
 }
 /**
  * Create media object from upload directory
  */
 function createMediaFromUploadDir()
 {
     $mset = new ilSetting("mobs");
     $upload_dir = trim($mset->get("upload_dir"));
     include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
     if (is_array($_POST["file"]) && ilMainMenuGUI::_checkAdministrationPermission()) {
         foreach ($_POST["file"] as $f) {
             $f = str_replace("..", "", $f);
             $fullpath = $upload_dir . "/" . $f;
             $mob = new ilObjMediaObject();
             $mob->setTitle(basename($fullpath));
             $mob->setDescription("");
             $mob->create();
             // determine and create mob directory, move uploaded file to directory
             //$mob_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob->getId();
             $mob->createDirectory();
             $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
             $media_item = new ilMediaItem();
             $mob->addMediaItem($media_item);
             $media_item->setPurpose("Standard");
             $file = $mob_dir . "/" . basename($fullpath);
             ilUtil::moveUploadedFile($fullpath, basename($fullpath), $file, false, $_POST["action"]);
             // get mime type
             $format = ilObjMediaObject::getMimeType($file);
             $location = basename($fullpath);
             // set real meta and object data
             $media_item->setFormat($format);
             $media_item->setLocation($location);
             $media_item->setLocationType("LocalFile");
             $mob->setDescription($format);
             // determine width and height of known image types
             $wh = ilObjMediaObject::_determineWidthHeight(500, 400, $format, "File", $mob_dir . "/" . $location, $media_item->getLocation(), true, true, "", "");
             $media_item->setWidth($wh["width"]);
             $media_item->setHeight($wh["height"]);
             if ($wh["info"] != "") {
                 //				ilUtil::sendInfo($wh["info"], true);
             }
             $media_item->setHAlign("Left");
             ilUtil::renameExecutables($mob_dir);
             $mob->update();
             // put it into current folder
             $mep_item = new ilMediaPoolItem();
             $mep_item->setTitle($mob->getTitle());
             $mep_item->setType("mob");
             $mep_item->setForeignId($mob->getId());
             $mep_item->create();
             $tree = $this->object->getTree();
             $parent = $_GET["mepitem_id"] == "" ? $tree->getRootId() : $_GET["mepitem_id"];
             $tree->insertNode($mep_item->getId(), $parent);
         }
     }
     ilUtil::redirect("ilias.php?baseClass=ilMediaPoolPresentationGUI&cmd=listMedia&ref_id=" . $_GET["ref_id"] . "&mepitem_id=" . $_GET["mepitem_id"]);
 }
 /**
  * Import record
  *
  * @param
  * @return
  */
 function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
 {
     //echo $a_entity;
     //var_dump($a_rec);
     switch ($a_entity) {
         case "mep":
             include_once "./Modules/MediaPool/classes/class.ilObjMediaPool.php";
             if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['Id'])) {
                 $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
             } else {
                 $newObj = new ilObjMediaPool();
                 $newObj->setType("mep");
                 $newObj->create(true);
             }
             $newObj->setTitle($a_rec["Title"]);
             $newObj->setDescription($a_rec["Description"]);
             $newObj->setDefaultWidth($a_rec["DefaultWidth"]);
             $newObj->setDefaultHeight($a_rec["DefaultHeight"]);
             $newObj->update();
             $this->current_obj = $newObj;
             $a_mapping->addMapping("Modules/MediaPool", "mep", $a_rec["Id"], $newObj->getId());
             break;
         case "mep_tree":
             switch ($a_rec["Type"]) {
                 case "fold":
                     $parent = (int) $a_mapping->getMapping("Modules/MediaPool", "mep_tree", $a_rec["Parent"]);
                     $fold_id = $this->current_obj->createFolder($a_rec["Title"], $parent);
                     $a_mapping->addMapping("Modules/MediaPool", "mep_tree", $a_rec["Child"], $fold_id);
                     break;
                 case "mob":
                     $parent = (int) $a_mapping->getMapping("Modules/MediaPool", "mep_tree", $a_rec["Parent"]);
                     $mob_id = (int) $a_mapping->getMapping("Services/MediaObjects", "mob", $a_rec["ForeignId"]);
                     $item = new ilMediaPoolItem();
                     $item->setType("mob");
                     $item->setForeignId($mob_id);
                     $item->setTitle($a_rec["Title"]);
                     $item->create();
                     if ($item->getId() > 0) {
                         $this->current_obj->insertInTree($item->getId(), $parent);
                     }
                     break;
                 case "pg":
                     $parent = (int) $a_mapping->getMapping("Modules/MediaPool", "mep_tree", $a_rec["Parent"]);
                     $item = new ilMediaPoolItem();
                     $item->setType("pg");
                     $item->setTitle($a_rec["Title"]);
                     $item->create();
                     $a_mapping->addMapping("Services/COPage", "pg", "mep:" . $a_rec["Child"], "mep:" . $item->getId());
                     if ($item->getId() > 0) {
                         $this->current_obj->insertInTree($item->getId(), $parent);
                     }
                     break;
             }
     }
 }