ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjMediaPoolGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/Object/classes/class.ilObject2GUI.php");
5 include_once("./Modules/MediaPool/classes/class.ilObjMediaPool.php");
6 include_once("./Services/Table/classes/class.ilTableGUI.php");
7 include_once("./Modules/Folder/classes/class.ilObjFolderGUI.php");
8 include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
9 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
10 include_once("./Services/Clipboard/classes/class.ilEditClipboardGUI.php");
11 
26 {
28 
32  protected function afterConstructor()
33  {
34  global $lng;
35 
36  $lng->loadLanguageModule("mep");
37 
38  if ($this->ctrl->getCmd() == "explorer")
39  {
40  $this->ctrl->saveParameter($this, array("ref_id"));
41  }
42  else
43  {
44  $this->ctrl->saveParameter($this, array("ref_id", "mepitem_id"));
45  }
46  $this->ctrl->saveParameter($this, array("mep_mode"));
47 
48  $lng->loadLanguageModule("content");
49  }
50 
54  final function getType()
55  {
56  return "mep";
57  }
58 
62  function &executeCommand()
63  {
64  global $ilTabs, $lng, $ilAccess, $tpl, $ilCtrl;
65 
66  if ($this->ctrl->getRedirectSource() == "ilinternallinkgui")
67  {
68  $this->explorer();
69  return;
70  }
71 
72  $next_class = $this->ctrl->getNextClass($this);
73  $cmd = $this->ctrl->getCmd();
74  $new_type = $_POST["new_type"]
75  ? $_POST["new_type"]
76  : $_GET["new_type"];
77 
78  if ($new_type != "" && ($cmd != "confirmRemove" && $cmd != "copyToClipboard"
79  && $cmd != "pasteFromClipboard"))
80  {
81  $this->setCreationMode(true);
82  }
83 
84  if (!$this->getCreationMode())
85  {
86  $tree =& $this->object->getTree();
87  if ($_GET["mepitem_id"] == "")
88  {
89  $_GET["mepitem_id"] = $tree->getRootId();
90  }
91  }
92  if ($cmd == "create")
93  {
94  switch($_POST["new_type"])
95  {
96  case "mob":
97  $this->ctrl->redirectByClass("ilobjmediaobjectgui", "create");
98  break;
99 
100  case "fold":
101 // todo
102  $this->ctrl->redirectByClass("ilobjfoldergui", "create");
103  break;
104  }
105  }
106 
107  switch($next_class)
108  {
109  case 'ilmediapoolpagegui':
110  $this->prepareOutput();
111  $this->addHeaderAction();
112  $this->setMediaPoolPageTabs();
113  include_once("./Modules/MediaPool/classes/class.ilMediaPoolPageGUI.php");
114  $mep_page_gui = new ilMediaPoolPageGUI($_GET["mepitem_id"], $_GET["old_nr"]);
115 
116  if (!$ilAccess->checkAccess("write", "", $this->object->getRefId()))
117  {
118  $mep_page_gui->setEnableEditing(false);
119  }
120  $ret = $this->ctrl->forwardCommand($mep_page_gui);
121  if ($ret != "")
122  {
123  $tpl->setContent($ret);
124  }
125  $this->tpl->show();
126  break;
127 
128  case "ilobjmediaobjectgui":
129  //$cmd.="Object";
130  if ($cmd == "create" || $cmd == "save" || $cmd == "cancel")
131  {
132  $ret_obj = $_GET["mepitem_id"];
133  $ilObjMediaObjectGUI =& new ilObjMediaObjectGUI("", 0, false, false);
134  $ilObjMediaObjectGUI->setWidthPreset($this->object->getDefaultWidth());
135  $ilObjMediaObjectGUI->setHeightPreset($this->object->getDefaultHeight());
136  }
137  else
138  {
139  $ret_obj = $tree->getParentId($_GET["mepitem_id"]);
140  $ilObjMediaObjectGUI =& new ilObjMediaObjectGUI("", ilMediaPoolItem::lookupForeignId($_GET["mepitem_id"]), false, false);
141  $this->ctrl->setParameter($this, "mepitem_id", $this->getParentFolderId());
142  $ilTabs->setBackTarget($lng->txt("back"),
143  $this->ctrl->getLinkTarget($this,
144  $_GET["mep_mode"] ? $_GET["mep_mode"] : "listMedia"));
145  }
146  if ($this->ctrl->getCmdClass() == "ilinternallinkgui")
147  {
148  $this->ctrl->setReturn($this, "explorer");
149  }
150  else
151  {
152  $this->ctrl->setParameter($this, "mepitem_id", $ret_obj);
153  $this->ctrl->setReturn($this,
154  $_GET["mep_mode"] ? $_GET["mep_mode"] : "listMedia");
155  $this->ctrl->setParameter($this, "mepitem_id", $_GET["mepitem_id"]);
156  }
157  $this->getTemplate();
158  $ilObjMediaObjectGUI->setTabs();
159  $this->setLocator();
160 
161  //$ret =& $ilObjMediaObjectGUI->executeCommand();
162  $ret = $this->ctrl->forwardCommand($ilObjMediaObjectGUI);
163 
164  if ($cmd == "save" && $ret != false)
165  {
166  $mep_item = new ilMediaPoolItem();
167  $mep_item->setTitle($ret->getTitle());
168  $mep_item->setType("mob");
169  $mep_item->setForeignId($ret->getId());
170  $mep_item->create();
171 
172  $parent = ($_GET["mepitem_id"] == "")
173  ? $tree->getRootId()
174  : $_GET["mepitem_id"];
175  $tree->insertNode($mep_item->getId(), $parent);
176  ilUtil::redirect("ilias.php?baseClass=ilMediaPoolPresentationGUI&cmd=listMedia&ref_id=".
177  $_GET["ref_id"]."&mepitem_id=".$_GET["mepitem_id"]);
178  }
179  else
180  {
181  $this->tpl->show();
182  }
183  break;
184 
185  case "ilobjfoldergui":
186 // todo
187  $this->addHeaderAction();
188  $folder_gui = new ilObjFolderGUI("", 0, false, false);
189  $this->ctrl->setReturn($this, "listMedia");
190  $cmd.="Object";
191  switch($cmd)
192  {
193  case "createObject":
194  $this->prepareOutput();
195  $folder_gui =& new ilObjFolderGUI("", 0, false, false);
196  $folder_gui->setFormAction("save",
197  $this->ctrl->getFormActionByClass("ilobjfoldergui"));
198  $folder_gui->createObject();
199  $this->tpl->show();
200  break;
201 
202  case "saveObject":
203  //$folder_gui->setReturnLocation("save", $this->ctrl->getLinkTarget($this, "listMedia"));
204  $parent = ($_GET["mepitem_id"] == "")
205  ? $tree->getRootId()
206  : $_GET["mepitem_id"];
207  $folder_gui->setFolderTree($tree);
208  $folder_gui->saveObject($parent);
209  //$this->ctrl->redirect($this, "listMedia");
210  break;
211 
212  case "editObject":
213  $this->prepareOutput();
214  $folder_gui =& new ilObjFolderGUI("", ilMediaPoolItem::lookupForeignId($_GET["mepitem_id"]), false, false);
215  $this->ctrl->setParameter($this, "foldereditmode", "1");
216  $folder_gui->setFormAction("update", $this->ctrl->getFormActionByClass("ilobjfoldergui"));
217  $folder_gui->editObject();
218  $this->tpl->show();
219  break;
220 
221  case "updateObject":
222  $folder_gui =& new ilObjFolderGUI("", ilMediaPoolItem::lookupForeignId($_GET["mepitem_id"]), false, false);
223  $this->ctrl->setParameter($this, "mepitem_id", $this->getParentFolderId());
224  $this->ctrl->setReturn($this, "listMedia");
225  $folder_gui->updateObject(true); // this returns to parent
226  break;
227 
228  case "cancelObject":
229  if ($_GET["foldereditmode"])
230  {
231  $this->ctrl->setParameter($this, "mepitem_id", $this->getParentFolderId());
232  }
233  $this->ctrl->redirect($this, "listMedia");
234  break;
235  }
236  break;
237 
238  case "ileditclipboardgui":
239  $this->prepareOutput();
240  $this->addHeaderAction();
241  $this->ctrl->setReturn($this, $_GET["mep_mode"] ? $_GET["mep_mode"] : "listMedia");
242  $clip_gui = new ilEditClipboardGUI();
243  $clip_gui->setMultipleSelections(true);
244  $clip_gui->setInsertButtonTitle($lng->txt("mep_copy_to_mep"));
245  $ilTabs->setTabActive("clipboard");
246  //$ret =& $clip_gui->executeCommand();
247  $ret =& $this->ctrl->forwardCommand($clip_gui);
248  $this->tpl->show();
249  break;
250 
251  case 'ilinfoscreengui':
252  $this->prepareOutput();
253  $this->addHeaderAction();
254  $this->infoScreen();
255  $this->tpl->show();
256  break;
257 
258  case 'ilpermissiongui':
259  $this->prepareOutput();
260  $this->addHeaderAction();
261  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
262  $perm_gui =& new ilPermissionGUI($this);
263  $ret =& $this->ctrl->forwardCommand($perm_gui);
264  $this->tpl->show();
265  break;
266 
267  case "ilexportgui":
268  $this->prepareOutput();
269  $this->addHeaderAction();
270  include_once("./Services/Export/classes/class.ilExportGUI.php");
271  $exp_gui = new ilExportGUI($this);
272  $exp_gui->addFormat("xml");
273  $ret = $this->ctrl->forwardCommand($exp_gui);
274  $this->tpl->show();
275  break;
276 
277  case "ilfilesystemgui":
278  $this->prepareOutput();
279  $this->addHeaderAction();
280  $ilTabs->clearTargets();
281  $ilTabs->setBackTarget($lng->txt("back"),
282  $ilCtrl->getLinkTarget($this, "listMedia"));
283  $mset = new ilSetting("mobs");
284  if (trim($mset->get("upload_dir")) != "")
285  {
286  include_once("./Services/FileSystem/classes/class.ilFileSystemGUI.php");
287  $fs_gui = new ilFileSystemGUI($mset->get("upload_dir"));
288  $fs_gui->setPostDirPath(true);
289  $fs_gui->setTableId("mepud".$this->object->getId());
290  $fs_gui->setAllowFileCreation(false);
291  $fs_gui->setAllowDirectoryCreation(false);
292  $fs_gui->clearCommands();
293  $fs_gui->addCommand($this, "selectUploadDirFiles", $this->lng->txt("mep_sel_upload_dir_files"),
294  false, true);
295  //$fs_gui->addCommand($this, "assignFullscreenObject", $this->lng->txt("cont_assign_full"));
296  $ret =& $this->ctrl->forwardCommand($fs_gui);
297  }
298  $this->tpl->show();
299  break;
300 
301  case "ilcommonactiondispatchergui":
302  include_once("Services/Object/classes/class.ilCommonActionDispatcherGUI.php");
304  $this->ctrl->forwardCommand($gui);
305  break;
306 
307  default:
308  $this->prepareOutput();
309  $this->addHeaderAction();
310  $cmd = $this->ctrl->getCmd("listMedia");
311  $this->$cmd();
312  if (!$this->getCreationMode())
313  {
314  $this->tpl->show();
315  }
316  break;
317  }
318  }
319 
323  function createMediaObject()
324  {
325  $this->ctrl->redirectByClass("ilobjmediaobjectgui", "create");
326  }
327 
328  protected function initCreationForms($a_new_type)
329  {
330  $forms = array(self::CFORM_NEW => $this->initCreateForm($a_new_type),
331  self::CFORM_IMPORT => $this->initImportForm($a_new_type));
332 
333  return $forms;
334  }
335 
339  function afterSave($newObj)
340  {
341  // always send a message
342  ilUtil::sendSuccess($this->lng->txt("object_added"),true);
343 
344  //ilUtil::redirect($this->getReturnLocation("save","adm_object.php?".$this->link_params));
345  ilUtil::redirect("ilias.php?baseClass=ilMediaPoolPresentationGUI&ref_id=".$newObj->getRefId()."&cmd=edit");
346  }
347 
348  protected function initEditCustomForm(ilPropertyFormGUI $a_form)
349  {
350  // default width
351  $ni = new ilNumberInputGUI($this->lng->txt("mep_default_width"), "default_width");
352  $ni->setMinValue(0);
353  $ni->setMaxLength(5);
354  $ni->setSize(5);
355  $a_form->addItem($ni);
356 
357  // default height
358  $ni = new ilNumberInputGUI($this->lng->txt("mep_default_height"), "default_height");
359  $ni->setMinValue(0);
360  $ni->setMaxLength(5);
361  $ni->setSize(5);
362  $ni->setInfo($this->lng->txt("mep_default_width_height_info"));
363  $a_form->addItem($ni);
364  }
365 
366  protected function getEditFormCustomValues(array &$a_values)
367  {
368  if ($this->object->getDefaultWidth() > 0)
369  {
370  $a_values["default_width"] = $this->object->getDefaultWidth();
371  }
372  if ($this->object->getDefaultHeight() > 0)
373  {
374  $a_values["default_height"] = $this->object->getDefaultHeight();
375  }
376  }
377 
378  protected function updateCustom(ilPropertyFormGUI $a_form)
379  {
380  $this->object->setDefaultWidth($a_form->getInput("default_width"));
381  $this->object->setDefaultHeight($a_form->getInput("default_height"));
382  }
383 
387  function listMedia()
388  {
389  global $tree, $ilAccess, $tpl, $ilTabs, $ilCtrl, $ilToolbar, $lng;
390 
391  $ilCtrl->setParameter($this, "mep_mode", "listMedia");
392 
393  if (!$ilAccess->checkAccess("read", "", $this->object->getRefId()))
394  {
395  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
396  }
397  $ilTabs->setTabActive("objs_fold");
398 
399  if ($ilAccess->checkAccess("write", "", $this->object->getRefId()))
400  {
401  $ilToolbar->addButton($lng->txt("mep_create_mob"),
402  $ilCtrl->getLinkTarget($this, "createMediaObject"));
403 
404  $mset = new ilSetting("mobs");
405  if ($mset->get("mep_activate_pages"))
406  {
407  $ilToolbar->addButton($lng->txt("mep_create_content_snippet"),
408  $ilCtrl->getLinkTarget($this, "createMediaPoolPage"));
409  }
410 
411  $ilToolbar->addButton($lng->txt("mep_create_folder"),
412  $ilCtrl->getLinkTarget($this, "createFolderForm"));
413 
414  if (trim($mset->get("upload_dir")) != "" && ilMainMenuGUI::_checkAdministrationPermission())
415  {
416  $ilToolbar->addButton($lng->txt("mep_create_from_upload_dir"),
417  $ilCtrl->getLinkTargetByClass("ilfilesystemgui", "listFiles"));
418  }
419  }
420 
421  // tree
422  include_once("./Modules/MediaPool/classes/class.ilMediaPoolExplorerGUI.php");
423  $exp = new ilMediaPoolExplorerGUI($this, "listMedia", $this->object);
424  if (!$exp->handleCommand())
425  {
426  $this->tpl->setLeftNavContent($exp->getHTML());
427  }
428  else
429  {
430  return;
431  }
432 
433 
434  include_once("./Modules/MediaPool/classes/class.ilMediaPoolTableGUI.php");
435  $mep_table_gui = new ilMediaPoolTableGUI($this, "listMedia", $this->object, "mepitem_id");
436  $tpl->setContent($mep_table_gui->getHTML());
437 // $this->tpl->show();
438  }
439 
443  function allMedia()
444  {
445  global $tree, $ilAccess, $tpl, $ilTabs, $ilCtrl,$ilUser;
446 
447  $ilCtrl->setParameter($this, "mep_mode", "allMedia");
448 
449  if (!$ilAccess->checkAccess("read", "", $this->object->getRefId()))
450  {
451  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
452  }
453  $ilTabs->setTabActive("mep_all_mobs");
454 
455 
456  include_once("./Modules/MediaPool/classes/class.ilMediaPoolTableGUI.php");
457  $mep_table_gui = new ilMediaPoolTableGUI($this, "allMedia", $this->object,
458  "mepitem_id", ilMediaPoolTableGUI::IL_MEP_EDIT, true);
459 
460 
461  if(isset($_GET['force_filter']) and $_GET['force_filter'])
462  {
463  $_POST['title'] = ilMediaPoolItem::lookupTitle((int) $_GET['force_filter']);
464 
465  include_once("./Services/Table/classes/class.ilTablePropertiesStorage.php");
466  $tprop = new ilTablePropertiesStorage();
467  $tprop->storeProperty(
468  $mep_table_gui->getId(),
469  $ilUser->getId(),
470  'filter',
471  1
472  );
473  $mep_table_gui->resetFilter();
474  $mep_table_gui->resetOffset();
475  $mep_table_gui->writeFilterToSession();
476 
477  // Read again
478  $mep_table_gui = new ilMediaPoolTableGUI($this, "allMedia", $this->object,
479  "mepitem_id", ilMediaPoolTableGUI::IL_MEP_EDIT, true);
480  }
481 
482  $tpl->setContent($mep_table_gui->getHTML());
483 // $this->tpl->show();
484  }
485 
489  function applyFilter()
490  {
491  include_once("./Modules/MediaPool/classes/class.ilMediaPoolTableGUI.php");
492  $mtab = new ilMediaPoolTableGUI($this, "allMedia", $this->object,
493  "mepitem_id", ilMediaPoolTableGUI::IL_MEP_EDIT, true);
494  $mtab->writeFilterToSession();
495  $mtab->resetOffset();
496  $this->allMedia();
497  }
498 
502  function resetFilter()
503  {
504  include_once("./Modules/MediaPool/classes/class.ilMediaPoolTableGUI.php");
505  $mtab = new ilMediaPoolTableGUI($this, "allMedia", $this->object,
506  "mepitem_id", ilMediaPoolTableGUI::IL_MEP_EDIT, true);
507  $mtab->resetFilter();
508  $mtab->resetOffset();
509  $this->allMedia();
510  }
511 
515  function getTemplate()
516  {
517  $this->tpl->getStandardTemplate();
518  }
519 
520 
524  function getParentFolderId()
525  {
526  if ($_GET["mepitem_id"] == "")
527  {
528  return "";
529  }
530  $par_id = $this->object->tree->getParentId($_GET["mepitem_id"]);
531  if ($par_id != $this->object->tree->getRootId())
532  {
533  return $par_id;
534  }
535  else
536  {
537  return "";
538  }
539  }
540 
544  function showMedia()
545  {
546  global $ilAccess;
547 
548  if (!$ilAccess->checkAccess("read", "", $this->object->getRefId()))
549  {
550  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
551  }
552 
553  $this->tpl =& new ilTemplate("tpl.fullscreen.html", true, true, "Services/COPage");
554  include_once("Services/Style/classes/class.ilObjStyleSheet.php");
555  $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
556  $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET",
558 
559  //$int_links = $page_object->getInternalLinks();
560  $med_links = ilMediaItem::_getMapAreasIntLinks($_GET["mob_id"]);
561 
562  // later
563  //$link_xml = $this->getLinkXML($med_links, $this->getLayoutLinkTargets());
564 
565  $link_xlm = "";
566 
567  require_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
568  require_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
570  $media_obj =& new ilObjMediaObject($_GET["mob_id"]);
571 
572  $xml = "<dummy>";
573  // todo: we get always the first alias now (problem if mob is used multiple
574  // times in page)
575  $xml.= $media_obj->getXML(IL_MODE_ALIAS);
576  $xml.= $media_obj->getXML(IL_MODE_OUTPUT);
577  $xml.= $link_xml;
578  $xml.="</dummy>";
579 
580  $xsl = file_get_contents("./Services/COPage/xsl/page.xsl");
581  $args = array( '/_xml' => $xml, '/_xsl' => $xsl );
582  $xh = xslt_create();
583 
584  $wb_path = ilUtil::getWebspaceDir("output")."/";
585 
586  $mode = ($_GET["cmd"] != "showMedia")
587  ? "fullscreen"
588  : "media";
589  $enlarge_path = ilUtil::getImagePath("enlarge.png", false, "output");
590  $fullscreen_link =
591  $this->ctrl->getLinkTarget($this, "showFullscreen", "", false, false);
592  $params = array ('mode' => $mode, 'enlarge_path' => $enlarge_path,
593  'link_params' => "ref_id=".$_GET["ref_id"],'fullscreen_link' => $fullscreen_link,
594  'ref_id' => $_GET["ref_id"], 'pg_frame' => $pg_frame, 'webspace_path' => $wb_path);
595  $output = xslt_process($xh,"arg:/_xml","arg:/_xsl",NULL,$args, $params);
596  echo xslt_error($xh);
597  xslt_free($xh);
598  // unmask user html
599  $this->tpl->setVariable("MEDIA_CONTENT", $output);
600  }
601 
605  function showFullscreen()
606  {
607  $this->showMedia();
608  }
609 
613  function confirmRemove()
614  {
615  global $ilAccess, $ilCtrl, $lng;
616 
617  if (!$ilAccess->checkAccess("write", "", $this->object->getRefId()))
618  {
619  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
620  }
621 
622  if(!isset($_POST["id"]))
623  {
624  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
625  }
626 
627  // display confirmation message
628  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
629  $cgui = new ilConfirmationGUI();
630  $cgui->setFormAction($this->ctrl->getFormAction($this));
631  $cgui->setHeaderText($this->lng->txt("info_delete_sure"));
632  $cgui->setCancel($this->lng->txt("cancel"), "cancelRemove");
633  $cgui->setConfirm($this->lng->txt("confirm"), "remove");
634 
635  foreach($_POST["id"] as $obj_id)
636  {
637  $type = ilMediaPoolItem::lookupType($obj_id);
638  $title = ilMediaPoolItem::lookupTitle($obj_id);
639 
640  // check whether page can be removed
641  $add = "";
642  if ($type == "pg")
643  {
644  include_once("./Services/COPage/classes/class.ilPageContentUsage.php");
645  $usages = ilPageContentUsage::getUsages("incl", $obj_id, false);
646  if (count($usages) > 0)
647  {
648  ilUtil::sendFailure(sprintf($lng->txt("mep_content_snippet_in_use"), $title), true);
649  $ilCtrl->redirect($this, "listMedia");
650  }
651  else
652  {
653  // check whether the snippet is used in older versions of pages
654  $usages = ilPageContentUsage::getUsages("incl", $obj_id, true);
655  if (count($usages) > 0)
656  {
657  $add = "<div class='small'>".$lng->txt("mep_content_snippet_used_in_older_versions")."</div>";
658  }
659  }
660  }
661 
662  $caption = ilUtil::getImageTagByType($type, $this->tpl->tplPath).
663  " ".$title.$add;
664 
665  $cgui->addItem("id[]", $obj_id, $caption);
666  }
667 
668  $this->tpl->setContent($cgui->getHTML());
669  }
670 
674  function openClipboard()
675  {
676  global $ilCtrl, $ilAccess;
677 
678  if (!$ilAccess->checkAccess("write", "", $this->object->getRefId()))
679  {
680  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
681  }
682 
683  $ilCtrl->setParameterByClass("ileditclipboardgui", "returnCommand",
684  rawurlencode($ilCtrl->getLinkTarget($this,
685  "insertFromClipboard", "", false, false)));
686  $ilCtrl->redirectByClass("ilEditClipboardGUI", "getObject");
687  }
688 
689 
694  {
695  global $ilAccess;
696 
697  if (!$ilAccess->checkAccess("write", "", $this->object->getRefId()))
698  {
699  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
700  }
701 
702  include_once("./Services/Clipboard/classes/class.ilEditClipboardGUI.php");
704  $not_inserted = array();
705  if (is_array($ids))
706  {
707  foreach ($ids as $id2)
708  {
709  $id = explode(":", $id2);
710  $type = $id[0];
711  $id = $id[1];
712 
713  if ($type == "mob") // media object
714  {
715  if (ilObjMEdiaPool::isForeignIdInTree($this->object->getId(), $id))
716  {
717  $not_inserted[] = ilObject::_lookupTitle($id)." [".
718  $id."]";
719  }
720  else
721  {
722  $item = new ilMediaPoolItem();
723  $item->setType("mob");
724  $item->setForeignId($id);
725  $item->setTitle(ilObject::_lookupTitle($id));
726  $item->create();
727  if ($item->getId() > 0)
728  {
729  $this->object->insertInTree($item->getId(), $_GET["mepitem_id"]);
730  }
731  }
732  }
733  if ($type == "incl") // content snippet
734  {
735  include_once("./Modules/MediaPool/classes/class.ilMediaPoolPage.php");
736  include_once("./Modules/MediaPool/classes/class.ilMediaPoolItem.php");
737  if (ilObjMEdiaPool::isItemIdInTree($this->object->getId(), $id))
738  {
739  $not_inserted[] = ilMediaPoolPage::lookupTitle($id)." [".
740  $id."]";
741  }
742  else
743  {
744  $original = new ilMediaPoolPage($id);
745 
746  // copy the page into the pool
747  $item = new ilMediaPoolItem();
748  $item->setType("pg");
749  $item->setTitle(ilMediaPoolItem::lookupTitle($id));
750  $item->create();
751  if ($item->getId() > 0)
752  {
753  $this->object->insertInTree($item->getId(), $_GET["mepitem_id"]);
754 
755  // create page
756  include_once("./Modules/MediaPool/classes/class.ilMediaPoolPage.php");
757  $page = new ilMediaPoolPage();
758  $page->setId($item->getId());
759  $page->create();
760 
761  // copy content
762  $original->copy($page->getId(), $page->getParentType(), $page->getParentId(), true);
763 
764  //$page->setXMLContent($original->copyXMLContent());
765  //$page->buildDom();
766  //$page->update();
767  }
768  }
769  }
770  }
771  }
772  if (count($not_inserted) > 0)
773  {
774  ilUtil::sendInfo($this->lng->txt("mep_not_insert_already_exist")."<br>".
775  implode($not_inserted,"<br>"), true);
776  }
777  $this->ctrl->redirect($this, $_GET["mep_mode"] ? $_GET["mep_mode"] : "listMedia");
778  }
779 
780 
784  function cancelRemove()
785  {
786  $this->ctrl->redirect($this, $_GET["mep_mode"] ? $_GET["mep_mode"] : "listMedia");
787  }
788 
792  function remove()
793  {
794  global $ilAccess;
795 
796  if (!$ilAccess->checkAccess("write", "", $this->object->getRefId()))
797  {
798  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
799  }
800 
801  foreach($_POST["id"] as $obj_id)
802  {
803  $this->object->deleteChild($obj_id);
804  }
805 
806  ilUtil::sendSuccess($this->lng->txt("cont_obj_removed"),true);
807  $this->ctrl->redirect($this, $_GET["mep_mode"] ? $_GET["mep_mode"] : "listMedia");
808  }
809 
810 
814  function copyToClipboard()
815  {
816  global $ilUser, $ilAccess;
817 
818  $this->checkPermission("write");
819 
820  if(!isset($_POST["id"]))
821  {
822  ilUtil::sendFailure($this->lng->txt("no_checkbox"), true);
823  $this->ctrl->redirect($this, $_GET["mep_mode"] ? $_GET["mep_mode"] : "listMedia");
824  }
825 
826  foreach ($_POST["id"] as $obj_id)
827  {
828  $type = ilMediaPoolItem::lookupType($obj_id);
829  if ($type == "fold")
830  {
831  ilUtil::sendFailure($this->lng->txt("cont_cant_copy_folders"), true);
832  $this->ctrl->redirect($this, $_GET["mep_mode"] ? $_GET["mep_mode"] : "listMedia");
833  }
834  }
835  foreach ($_POST["id"] as $obj_id)
836  {
837  $fid = ilMediaPoolItem::lookupForeignId($obj_id);
838  $type = ilMediaPoolItem::lookupType($obj_id);
839  if ($type == "mob")
840  {
841  $ilUser->addObjectToClipboard($fid, "mob", "");
842  }
843  if ($type == "pg")
844  {
845  $ilUser->addObjectToClipboard($obj_id, "incl", "");
846  }
847  }
848  ilUtil::sendSuccess($this->lng->txt("copied_to_clipboard"),true);
849  $this->ctrl->redirect($this, $_GET["mep_mode"] ? $_GET["mep_mode"] : "listMedia");
850  }
851 
855  function addLocatorItems()
856  {
857  global $ilLocator;
858 
859  if (!$this->getCreationMode() && $this->ctrl->getCmd() != "explorer")
860  {
861  $tree =& $this->object->getTree();
862  $obj_id = ($_GET["mepitem_id"] == "")
863  ? $tree->getRootId()
864  : $_GET["mepitem_id"];
865  $path = $tree->getPathFull($obj_id);
866  foreach($path as $node)
867  {
868  if ($node["child"] == $tree->getRootId())
869  {
870  $this->ctrl->setParameter($this, "mepitem_id", "");
871  $link = $this->ctrl->getLinkTarget($this, "listMedia");
872  $title = $this->object->getTitle();
873  $this->ctrl->setParameter($this, "mepitem_id", $_GET["mepitem_id"]);
874  $ilLocator->addItem($title, $link, "", $_GET["ref_id"]);
875  }
876  else
877  {
878  $this->ctrl->setParameter($this, "mepitem_id", $node["child"]);
879  $link = $this->ctrl->getLinkTarget($this, "listMedia");
880  $title = $node["title"];
881  $this->ctrl->setParameter($this, "mepitem_id", $_GET["mepitem_id"]);
882  $ilLocator->addItem($title, $link);
883  }
884  }
885  }
886  }
887 
891 
895  function createFolderForm()
896  {
897  global $ilAccess, $tpl;
898 
899  if (!$ilAccess->checkAccess("write", "", $this->object->getRefId()))
900  {
901  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
902  }
903 
904  $this->initFolderForm("create");
905  $tpl->setContent($this->form->getHTML());
906 
907 /* $folder_gui =& new ilObjFolderGUI("", 0, false, false);
908  $this->ctrl->setParameterByClass("ilobjfoldergui", "obj_id", $_GET["obj_id"]);
909  $folder_gui->setFormAction("save",
910  $this->ctrl->getFormActionByClass("ilobjfoldergui"));
911  $folder_gui->createObject();*/
912 // $this->tpl->show();
913  }
914 
921  function editFolder()
922  {
923  global $tpl;
924 
925  $this->initFolderForm();
926  $this->getFolderValues();
927  $tpl->setContent($this->form->getHTML());
928  }
929 
933  public function getFolderValues()
934  {
935  $values = array();
936 
937  $values["title"] = ilMediaPoolItem::lookupTitle($_GET["mepitem_id"]);
938 
939  $this->form->setValuesByArray($values);
940  }
941 
945  public function saveFolder()
946  {
947  global $tpl, $lng, $ilCtrl;
948 
949  $this->initFolderForm("create");
950  if ($this->form->checkInput())
951  {
952  if ($this->object->createFolder($_POST["title"], (int) $_GET["mepitem_id"]))
953  {
954  ilUtil::sendSuccess($lng->txt("mep_folder_created"), true);
955  }
956  $ilCtrl->redirect($this, "listMedia");
957  }
958 
959  $this->form->setValuesByPost();
960  $tpl->setContent($this->form->getHtml());
961  }
962 
966  function updateFolder()
967  {
968  global $lng, $ilCtrl, $tpl;
969 
970  $this->initFolderForm("edit");
971  if ($this->form->checkInput())
972  {
973  $item = new ilMediaPoolItem($_GET["mepitem_id"]);
974  $item->setTitle($_POST["title"]);
975  $item->update();
976  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
977  $ilCtrl->setParameter($this, "mepitem_id",
978  $this->object->getTree()->getParentId($_GET["mepitem_id"]));
979  $ilCtrl->redirect($this, "listMedia");
980  }
981 
982  $this->form->setValuesByPost();
983  $tpl->setContent($this->form->getHtml());
984  }
985 
991  public function initFolderForm($a_mode = "edit")
992  {
993  global $lng, $ilCtrl;
994 
995  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
996  $this->form = new ilPropertyFormGUI();
997 
998  // desc
999  $ti = new ilTextInputGUI($lng->txt("title"), "title");
1000  $ti->setMaxLength(128);
1001  $ti->setRequired(true);
1002  $this->form->addItem($ti);
1003 
1004  // save and cancel commands
1005  if ($a_mode == "create")
1006  {
1007  $this->form->addCommandButton("saveFolder", $lng->txt("save"));
1008  $this->form->addCommandButton("cancelSave", $lng->txt("cancel"));
1009  $this->form->setTitle($lng->txt("mep_new_folder"));
1010  }
1011  else
1012  {
1013  $this->form->addCommandButton("updateFolder", $lng->txt("save"));
1014  $this->form->addCommandButton("cancelFolderUpdate", $lng->txt("cancel"));
1015  $this->form->setTitle($lng->txt("mep_edit_folder"));
1016  }
1017 
1018  $this->form->setFormAction($ilCtrl->getFormAction($this));
1019  }
1020 
1025  {
1026  global $ilCtrl;
1027  $ilCtrl->setParameter($this, "mepitem_id",
1028  $this->object->getTree()->getParentId($_GET["mepitem_id"]));
1029  $ilCtrl->redirect($this, "listMedia");
1030  }
1031 
1035  function cancelSave()
1036  {
1037  global $ilCtrl;
1038  $ilCtrl->redirect($this, "listMedia");
1039  }
1040 
1044 
1049  {
1050  global $tpl;
1051  $this->initMediaPoolPageForm("create");
1052  $tpl->setContent($this->form->getHTML());
1053  }
1054 
1062  {
1063  global $tpl;
1064 
1065  $this->setMediaPoolPageTabs();
1066 
1067  include_once("./Modules/MediaPool/classes/class.ilMediaPoolPageGUI.php");
1068  $mep_page_gui = new ilMediaPoolPageGUI($_GET["mepitem_id"], $_GET["old_nr"]);
1069  $mep_page_gui->getTabs();
1070 
1071  $this->initMediaPoolPageForm("edit");
1072  $this->getMediaPoolPageValues();
1073  $tpl->setContent($this->form->getHTML());
1074  }
1075 
1079  public function saveMediaPoolPage()
1080  {
1081  global $tpl, $lng, $ilCtrl;
1082 
1083  $this->initMediaPoolPageForm("create");
1084  if ($this->form->checkInput())
1085  {
1086  // create media pool item
1087  include_once("./Modules/MediaPool/classes/class.ilMediaPoolItem.php");
1088  $item = new ilMediaPoolItem();
1089  $item->setTitle($_POST["title"]);
1090  $item->setType("pg");
1091  $item->create();
1092 
1093  if ($item->getId() > 0)
1094  {
1095  // put in tree
1096  $tree = $this->object->getTree();
1097  $parent = $_GET["mepitem_id"] > 0
1098  ? $_GET["mepitem_id"]
1099  : $tree->getRootId();
1100  $this->object->insertInTree($item->getId(), $parent);
1101 
1102  // create page
1103  include_once("./Modules/MediaPool/classes/class.ilMediaPoolPage.php");
1104  $page = new ilMediaPoolPage();
1105  $page->setId($item->getId());
1106  $page->create();
1107 
1108  ilUtil::sendSuccess($lng->txt("mep_page_created"), true);
1109  }
1110  $ilCtrl->redirect($this, "listMedia");
1111  }
1112 
1113  $this->form->setValuesByPost();
1114  $tpl->setContent($this->form->getHtml());
1115  }
1116 
1121  {
1122  global $lng, $ilCtrl, $tpl;
1123 
1124  $this->initMediaPoolPageForm("edit");
1125  if ($this->form->checkInput())
1126  {
1127  $item = new ilMediaPoolItem($_GET["mepitem_id"]);
1128  $item->setTitle($_POST["title"]);
1129  $item->update();
1130  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
1131  $ilCtrl->redirect($this, "editMediaPoolPage");
1132  }
1133 
1134  $this->form->setValuesByPost();
1135  $tpl->setContent($this->form->getHtml());
1136  }
1142  public function initMediaPoolPageForm($a_mode = "edit")
1143  {
1144  global $lng, $ilCtrl;
1145 
1146  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
1147  $this->form = new ilPropertyFormGUI();
1148 
1149  // title
1150  $ti = new ilTextInputGUI($lng->txt("title"), "title");
1151  $ti->setMaxLength(128);
1152  $ti->setRequired(true);
1153  $this->form->addItem($ti);
1154 
1155  // save and cancel commands
1156  if ($a_mode == "create")
1157  {
1158  $this->form->addCommandButton("saveMediaPoolPage", $lng->txt("save"));
1159  $this->form->addCommandButton("cancelSave", $lng->txt("cancel"));
1160  $this->form->setTitle($lng->txt("mep_new_content_snippet"));
1161  }
1162  else
1163  {
1164  $this->form->addCommandButton("updateMediaPoolPage", $lng->txt("save"));
1165  $this->form->setTitle($lng->txt("mep_edit_content_snippet"));
1166  }
1167 
1168  $this->form->setFormAction($ilCtrl->getFormAction($this));
1169  }
1170 
1174  public function getMediaPoolPageValues()
1175  {
1176  $values = array();
1177 
1178  include_once("./Modules/MediaPool/classes/class.ilMediaPoolItem.php");
1179  $values["title"] = ilMediaPoolItem::lookupTitle($_GET["mepitem_id"]);
1180 
1181  $this->form->setValuesByArray($values);
1182  }
1183 
1191  {
1192  global $ilTabs, $ilCtrl, $lng;
1193 
1194  $ilTabs->clearTargets();
1195  //$ilTabs->addTab("mep_pg_prop", $lng->txt("mep_page_properties"),
1196  // $ilCtrl->getLinkTarget($this, "editMediaPoolPage"));
1197  $ilTabs->addTarget("mep_page_properties", $ilCtrl->getLinkTarget($this, "editMediaPoolPage"),
1198  "editMediaPoolPage", get_class($this));
1199  $ilTabs->addTarget("cont_usage", $ilCtrl->getLinkTarget($this, "showMediaPoolPageUsages"),
1200  array("showMediaPoolPageUsages", "showAllMediaPoolPageUsages"), get_class($this));
1201  $ilCtrl->setParameter($this, "mepitem_id", $this->object->tree->getParentId($_GET["mepitem_id"]));
1202  $ilTabs->setBackTarget($lng->txt("mep_folder"), $ilCtrl->getLinkTarget($this, "listMedia"));
1203  $ilCtrl->setParameter($this, "mepitem_id", $_GET["mepitem_id"]);
1204  }
1205 
1210  {
1211  $this->showMediaPoolPageUsages(true);
1212  }
1213 
1214 
1218  function showMediaPoolPageUsages($a_all = false)
1219  {
1220  global $ilTabs, $ilCtrl, $lng, $tpl;
1221 
1222  $this->setMediaPoolPageTabs();
1223 
1224  $ilTabs->addSubTab("current_usages", $lng->txt("cont_current_usages"),
1225  $ilCtrl->getLinkTarget($this, "showMediaPoolPageUsages"));
1226 
1227  $ilTabs->addSubTab("all_usages", $lng->txt("cont_all_usages"),
1228  $ilCtrl->getLinkTarget($this, "showAllMediaPoolPageUsages"));
1229 
1230  if ($a_all)
1231  {
1232  $ilTabs->activateSubTab("all_usages");
1233  $cmd = "showAllMediaPoolPageUsages";
1234  }
1235  else
1236  {
1237  $ilTabs->activateSubTab("current_usages");
1238  $cmd = "showMediaPoolPageUsages";
1239  }
1240 
1241 
1242  include_once("./Modules/MediaPool/classes/class.ilMediaPoolPageGUI.php");
1243  $mep_page_gui = new ilMediaPoolPageGUI($_GET["mepitem_id"], $_GET["old_nr"]);
1244  $mep_page_gui->getTabs();
1245 
1246  include_once("./Modules/MediaPool/classes/class.ilMediaPoolPage.php");
1247  $page = new ilMediaPoolPage((int) $_GET["mepitem_id"]);
1248 
1249  include_once("./Modules/MediaPool/classes/class.ilMediaPoolPageUsagesTableGUI.php");
1250  $table = new ilMediaPoolPageUsagesTableGUI($this, $cmd, $page, $a_all);
1251 
1252  $tpl->setContent($table->getHTML());
1253 
1254  }
1255 
1256 
1260 
1264  function setTabs()
1265  {
1266  global $ilAccess, $ilTabs, $ilCtrl, $ilHelp;
1267 
1268  $ilHelp->setScreenIdComponent("mep");
1269 
1270  if ($ilAccess->checkAccess('read', '', $this->ref_id) ||
1271  $ilAccess->checkAccess('write', '', $this->ref_id))
1272  {
1273  $ilTabs->addTarget("objs_fold", $this->ctrl->getLinkTarget($this, ""),
1274  "listMedia", "", "_top");
1275 
1276  $ilCtrl->setParameter($this, "mepitem_id", "");
1277  $ilTabs->addTarget("mep_all_mobs", $this->ctrl->getLinkTarget($this, "allMedia"),
1278  "allMedia", "", "_top");
1279  $ilCtrl->setParameter($this, "mepitem_id", $_GET["mepitem_id"]);
1280  }
1281 
1282  // info tab
1283  if ($ilAccess->checkAccess('visible', '', $this->ref_id))
1284  {
1285  $force_active = ($this->ctrl->getNextClass() == "ilinfoscreengui"
1286  || strtolower($_GET["cmdClass"]) == "ilnotegui")
1287  ? true
1288  : false;
1289  //echo "-$force_active-";
1290  $ilTabs->addTarget("info_short",
1291  $this->ctrl->getLinkTargetByClass(
1292  array("ilobjmediapoolgui", "ilinfoscreengui"), "showSummary"),
1293  array("showSummary", "infoScreen"),
1294  "", "", $force_active);
1295  }
1296 
1297  if ($ilAccess->checkAccess("write", "", $this->object->getRefId()))
1298  {
1299  $ilTabs->addTarget("settings", $this->ctrl->getLinkTarget($this, "edit"),
1300  "edit", array("", "ilobjmediapoolgui"));
1301  }
1302 
1303  if ($ilAccess->checkAccess("write", "", $this->object->getRefId()))
1304  {
1305  $ilTabs->addTarget("clipboard", $this->ctrl->getLinkTarget($this, "openClipboard"),
1306  "view", "ileditclipboardgui");
1307  }
1308 
1309  if ($ilAccess->checkAccess("write", "", $this->object->getRefId()))
1310  {
1311  $ilTabs->addTarget("export", $this->ctrl->getLinkTargetByClass("ilexportgui", ""),
1312  "", "ilexportgui");
1313  }
1314 
1315  if ($ilAccess->checkAccess("edit_permission", "", $this->object->getRefId()))
1316  {
1317  $ilTabs->addTarget("perm_settings",
1318  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), array("perm","info","owner"), 'ilpermissiongui');
1319  }
1320 
1321  }
1322 
1323 
1327  function _goto($a_target)
1328  {
1329  global $ilAccess, $ilErr, $lng;
1330 
1331  $targets = explode('_',$a_target);
1332  if(count((array) $targets) > 1)
1333  {
1334  $ref_id = $targets[0];
1335  $subitem_id = $targets[1];
1336  }
1337  else
1338  {
1339  $ref_id = $targets[0];
1340  }
1341 
1342  if ($ilAccess->checkAccess("read", "", $ref_id))
1343  {
1344  $_GET["baseClass"] = "ilMediaPoolPresentationGUI";
1345  $_GET["ref_id"] = $ref_id;
1346  $_GET['mepitem_id'] = $subitem_id;
1347  include("ilias.php");
1348  exit;
1349  }
1350  else if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
1351  {
1352  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
1353  ilObject::_lookupTitle(ilObject::_lookupObjId($a_target))), true);
1355  }
1356 
1357  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
1358  }
1359 
1365  function infoScreenObject()
1366  {
1367  $this->ctrl->setCmd("showSummary");
1368  $this->ctrl->setCmdClass("ilinfoscreengui");
1369  $this->infoScreen();
1370  }
1371 
1375  function infoScreen()
1376  {
1377  global $ilAccess;
1378 
1379  if (!$ilAccess->checkAccess("visible", "", $this->ref_id))
1380  {
1381  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
1382  }
1383 
1384  if ($this->ctrl->getCmd() == "infoScreen")
1385  {
1386  $this->ctrl->setCmd("showSummary");
1387  $this->ctrl->setCmdClass("ilinfoscreengui");
1388  }
1389 
1390  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
1391  $info = new ilInfoScreenGUI($this);
1392 
1393  $info->enablePrivateNotes();
1394 
1395  if ($ilAccess->checkAccess("read", "", $_GET["ref_id"]))
1396  {
1397  //$info->enableNews();
1398  }
1399 
1400  // no news editing for files, just notifications
1401 // $info->enableNewsEditing(false);
1402  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]))
1403  {
1404 // $news_set = new ilSetting("news");
1405 // $enable_internal_rss = $news_set->get("enable_rss_for_internal");
1406 
1407 // if ($enable_internal_rss)
1408 // {
1409 // $info->setBlockProperty("news", "settings", true);
1410 // $info->setBlockProperty("news", "public_notifications_option", true);
1411 // }
1412  }
1413 
1414 
1415  // standard meta data
1416  $info->addMetaDataSections($this->object->getId(),0, $this->object->getType());
1417 
1418  // forward the command
1419  $this->ctrl->forwardCommand($info);
1420 
1421 // $this->tpl->show();
1422  }
1423 
1424 
1428 
1433  {
1434  global $tpl, $ilTabs, $lng, $ilCtrl, $ilToolbar;
1435 
1436  $ilTabs->clearTargets();
1437  $ilTabs->setBackTarget($lng->txt("back"),
1438  $ilCtrl->getLinkTarget($this, "listMedia"));
1439 
1441  {
1442 
1443  // action type
1444  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
1445  $options = array(
1446  "rename" => $lng->txt("mep_up_dir_move"),
1447  "copy" => $lng->txt("mep_up_dir_copy"),
1448  );
1449  $si = new ilSelectInputGUI("", "action");
1450  $si->setOptions($options);
1451  $ilToolbar->addInputItem($si);
1452  $ilToolbar->setCloseFormTag(false);
1453  $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
1454  $ilToolbar->setFormName("mep_up_form");
1455 
1456  include_once("./Modules/MediaPool/classes/class.ilUploadDirFilesTableGUI.php");
1457  $tab = new ilUploadDirFilesTableGUI($this, "selectUploadDirFiles",
1458  $_POST["file"]);
1459  $tab->setFormName("mep_up_form");
1460  $tpl->setContent($tab->getHTML());
1461  }
1462  }
1463 
1468  {
1469  $mset = new ilSetting("mobs");
1470  $upload_dir = trim($mset->get("upload_dir"));
1471 
1472  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1473 
1474  if (is_array($_POST["file"]) && ilMainMenuGUI::_checkAdministrationPermission())
1475  {
1476  foreach ($_POST["file"] as $f)
1477  {
1478  $f = str_replace("..", "", $f);
1479  $fullpath = $upload_dir."/".$f;
1480  $mob = new ilObjMediaObject();
1481  $mob->setTitle(basename($fullpath));
1482  $mob->setDescription("");
1483  $mob->create();
1484 
1485  // determine and create mob directory, move uploaded file to directory
1486  //$mob_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob->getId();
1487  $mob->createDirectory();
1488  $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
1489 
1490  $media_item = new ilMediaItem();
1491  $mob->addMediaItem($media_item);
1492  $media_item->setPurpose("Standard");
1493 
1494  $file = $mob_dir."/".basename($fullpath);
1495  ilUtil::moveUploadedFile($fullpath,
1496  basename($fullpath), $file, false, $_POST["action"]);
1497 
1498  // get mime type
1500  $location = basename($fullpath);
1501 
1502  // set real meta and object data
1503  $media_item->setFormat($format);
1504  $media_item->setLocation($location);
1505  $media_item->setLocationType("LocalFile");
1506 
1507  $mob->setDescription($format);
1508 
1509  // determine width and height of known image types
1510  $wh = ilObjMediaObject::_determineWidthHeight(500, 400, $format,
1511  "File", $mob_dir."/".$location, $media_item->getLocation(),
1512  true, true, "", "");
1513  $media_item->setWidth($wh["width"]);
1514  $media_item->setHeight($wh["height"]);
1515  if ($wh["info"] != "")
1516  {
1517  // ilUtil::sendInfo($wh["info"], true);
1518  }
1519 
1520  $media_item->setHAlign("Left");
1521  ilUtil::renameExecutables($mob_dir);
1522  $mob->update();
1523 
1524 
1525  // put it into current folder
1526  $mep_item = new ilMediaPoolItem();
1527  $mep_item->setTitle($mob->getTitle());
1528  $mep_item->setType("mob");
1529  $mep_item->setForeignId($mob->getId());
1530  $mep_item->create();
1531 
1532  $tree = $this->object->getTree();
1533  $parent = ($_GET["mepitem_id"] == "")
1534  ? $tree->getRootId()
1535  : $_GET["mepitem_id"];
1536  $tree->insertNode($mep_item->getId(), $parent);
1537  }
1538  }
1539  ilUtil::redirect("ilias.php?baseClass=ilMediaPoolPresentationGUI&cmd=listMedia&ref_id=".
1540  $_GET["ref_id"]."&mepitem_id=".$_GET["mepitem_id"]);
1541 
1542  }
1543 }
1544 ?>