ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilObjMediaPoolGUI.php
Go to the documentation of this file.
1 <?php
2 
27 
39 {
40  protected \ILIAS\MediaPool\InternalDomainService $domain;
41  protected \ILIAS\COPage\Xsl\XslManager $xsl;
42  protected ?FormAdapterGUI $bulk_upload_form = null;
45  protected string $mode;
46  protected int $mep_item_id = 0;
48  protected ilTabsGUI $tabs;
49  protected ilHelpGUI $help;
51  protected FileUpload $upload;
52  protected ilLogger $mep_log;
53  public bool $output_prepared;
54 
55  public function __construct(
56  int $a_id = 0,
57  int $a_id_type = self::REPOSITORY_NODE_ID,
58  int $a_parent_node_id = 0
59  ) {
60  global $DIC;
61 
62  $this->mep_request = $DIC->mediaPool()
63  ->internal()
64  ->gui()
65  ->standardRequest();
66  $this->mep_item_id = $this->mep_request->getItemId();
67 
68  parent::__construct($a_id, $a_id_type, $a_parent_node_id);
69 
70  $this->tabs = $DIC->tabs();
71  $this->locator = $DIC["ilLocator"];
72  $this->help = $DIC["ilHelp"];
73 
74  $this->main_tpl = $DIC->ui()->mainTemplate();
75 
76  $this->upload = $DIC->upload();
77 
78  $this->mep_log = ilLoggerFactory::getLogger("mep");
79 
80 
81  $this->mode = ($this->mep_request->getMode() !== "")
82  ? $this->mep_request->getMode()
83  : "listMedia";
84  $this->gui = $DIC->mediaPool()->internal()->gui();
85  $this->domain = $DIC->mediaPool()->internal()->domain();
86  $this->xsl = $DIC->copage()->internal()->domain()->xsl();
87  }
88 
89  protected function getMediaPool(): ilObjMediaPool
90  {
92  $mp = $this->object;
93  return $mp;
94  }
95 
99  protected function afterConstructor(): void
100  {
101  $lng = $this->lng;
102  if ($this->mep_item_id == 0 && !$this->getCreationMode()) {
103  $tree = $this->object->getTree();
104  $this->mep_item_id = $tree->readRootId();
105  }
106 
107  $lng->loadLanguageModule("mep");
108 
109  if ($this->ctrl->getCmd() === "explorer") {
110  $this->ctrl->saveParameter($this, array("ref_id"));
111  } else {
112  $this->ctrl->saveParameter($this, array("ref_id", "mepitem_id"));
113  }
114  $this->ctrl->saveParameter($this, array("mep_mode"));
115 
116  $lng->loadLanguageModule("content");
117  }
118 
119  final public function getType(): string
120  {
121  return "mep";
122  }
123 
129  public function executeCommand(): void
130  {
131  $ilTabs = $this->tabs;
132  $lng = $this->lng;
133  $ilAccess = $this->access;
134  $tpl = $this->tpl;
135  $ilCtrl = $this->ctrl;
136 
137  $tree = null;
138  if ($this->object) {
139  $tree = $this->object->getTree();
140  }
141 
142  $next_class = $this->ctrl->getNextClass($this);
143  $cmd = $this->ctrl->getCmd();
144  $new_type = $this->mep_request->getNewType();
145 
146 
147 
148  if ($new_type !== "" && ($cmd !== "confirmRemove" && $cmd !== "copyToClipboard"
149  && $cmd !== "pasteFromClipboard")) {
150  $this->tpl->setPermanentLink("mep", $this->ref_id);
151  $this->setCreationMode(true);
152  }
153 
154  if ($cmd === "create") {
155  switch ($this->mep_request->getNewType()) {
156  case "mob":
157  $this->ctrl->redirectByClass("ilobjmediaobjectgui", "create");
158  break;
159 
160  case "fold":
161  $this->ctrl->redirectByClass("ilobjfoldergui", "create");
162  break;
163  }
164  }
165 
166  switch ($next_class) {
167  case 'ilobjectmetadatagui':
168  $this->checkPermission("write");
169 
170  $this->prepareOutput();
171  $this->addHeaderAction();
172 
173  $this->tabs_gui->activateTab('meta_data');
174  $md_gui = new ilObjectMetaDataGUI($this->object, ['mob', "mpg"]);
175  $this->ctrl->forwardCommand($md_gui);
176  $this->tpl->printToStdout();
177  break;
178 
179  case strtolower(ilRepoStandardUploadHandlerGUI::class):
180  $this->checkPermission("write");
181  $form = $this->getBulkUploadForm();
182  $gui = $form->getRepoStandardUploadHandlerGUI("media_files");
183  $this->ctrl->forwardCommand($gui);
184  break;
185 
186  case 'ilmediapoolpagegui':
187  $this->checkPermission("write");
188  $this->prepareOutput();
189  //$this->addHeaderAction();
190  $ilTabs->clearTargets();
191  $ilCtrl->setReturn($this, "returnFromItem");
192  $mep_page_gui = new ilMediaPoolPageGUI(
193  $this->mep_item_id,
194  $this->mep_request->getOldNr()
195  );
196  $mep_page_gui->setPoolGUI($this);
197  $mep_page_gui->setAdvMdRecordObject($this->object->getRefId(), "mep", "mpg");
198 
199  if (!$ilAccess->checkAccess("write", "", $this->object->getRefId())) {
200  $mep_page_gui->setEnableEditing(false);
201  }
202  $ret = $this->ctrl->forwardCommand($mep_page_gui);
203  if ($ret != "") {
204  $tpl->setContent($ret);
205  }
206  $this->tpl->printToStdout();
207  break;
208 
209  case "ilobjmediaobjectgui":
210  $this->checkPermission("write");
211  if ($cmd === "create" || $cmd === "save" || $cmd === "cancel") {
212  $ret_obj = $this->mep_item_id;
213  $ilObjMediaObjectGUI = new ilObjMediaObjectGUI("", 0, false, false);
214  $ilObjMediaObjectGUI->setWidthPreset((int) $this->getMediaPool()->getDefaultWidth());
215  $ilObjMediaObjectGUI->setHeightPreset((int) $this->getMediaPool()->getDefaultHeight());
216  } else {
217  $ret_obj = $tree->getParentId($this->mep_item_id);
218  $ilObjMediaObjectGUI = new ilObjMediaObjectGUI("", ilMediaPoolItem::lookupForeignId($this->mep_item_id), false, false);
219  $this->ctrl->setParameter($this, "mepitem_id", $this->getParentFolderId());
220  $ilTabs->setBackTarget(
221  $lng->txt("back"),
222  $this->ctrl->getLinkTarget(
223  $this,
224  $this->mode
225  )
226  );
227  }
228  if ($this->ctrl->getCmdClass() === "ilinternallinkgui") {
229  $this->ctrl->setReturn($this, "explorer");
230  } else {
231  $this->ctrl->setParameter($this, "mepitem_id", $ret_obj);
232  $this->ctrl->setReturn(
233  $this,
234  $this->mode
235  );
236  $this->ctrl->setParameter($this, "mepitem_id", $this->mep_item_id);
237  }
238  $this->getTemplate();
239  $ilObjMediaObjectGUI->setTabs();
240  $this->setLocator();
241 
242  // set adv metadata record dobject
243  $ilObjMediaObjectGUI->setAdvMdRecordObject($this->object->getRefId(), "mep", "mob");
244 
245  $ret = $this->ctrl->forwardCommand($ilObjMediaObjectGUI);
246  if ($cmd === "save") {
247  $object = $ilObjMediaObjectGUI->getObject();
248  if (!is_null($object)) {
249  $mep_item = new ilMediaPoolItem();
250  $mep_item->setTitle($object->getTitle());
251  $mep_item->setType("mob");
252  $mep_item->setForeignId($object->getId());
253  $mep_item->create();
254 
255  $parent = $this->mep_item_id;
256  $tree->insertNode($mep_item->getId(), $parent);
258  "ilias.php?baseClass=ilMediaPoolPresentationGUI&cmd=listMedia&ref_id=" .
259  $this->requested_ref_id . "&mepitem_id=" . $this->mep_item_id
260  );
261  }
262  }
263  $this->tpl->printToStdout();
264  break;
265 
266  case "ilmediacreationgui":
267  $this->checkPermission("write");
268  $this->prepareOutput();
269  $this->ctrl->setReturn($this, "listMedia");
270  //$ilTabs->activateTab("content");
271  //$this->addContentSubTabs("manage");
272  $med_type = [];
273  $creation = new ilMediaCreationGUI([ilMediaCreationGUI::TYPE_ALL], function ($mob_id) {
274  $this->afterUpload($mob_id);
275  }, function ($mob_id, $long_desc) {
276  $this->afterUrlSaving($mob_id, $long_desc);
277  }, function ($mob_ids) {
278  $this->afterPoolInsert($mob_ids);
279  }, function ($mob_id) {
280  $this->finishSingleUpload($mob_id);
281  }, function ($mob_id) {
282  $this->onMobUpdate($mob_id);
283  });
284  $this->ctrl->forwardCommand($creation);
285  $this->tpl->printToStdout();
286  break;
287 
288 
289  case "ilobjfoldergui":
290  $this->checkPermission("write");
291  $this->addHeaderAction();
292  $folder_gui = new ilObjFolderGUI("", 0, false, false);
293  $this->ctrl->setReturn($this, "listMedia");
294  $cmd .= "Object";
295  switch ($cmd) {
296  case "createObject":
297  $this->prepareOutput();
298  $folder_gui = new ilObjFolderGUI("", 0, false, false);
299  $folder_gui->setFormAction(
300  "save",
301  $this->ctrl->getFormActionByClass("ilobjfoldergui")
302  );
303  $folder_gui->createObject();
304  $this->tpl->printToStdout();
305  break;
306 
307  case "saveObject":
308  $parent = $this->mep_item_id;
309  $folder_gui->setFolderTree($tree);
310  $folder_gui->saveObject();
311  break;
312 
313  case "editObject":
314  $this->prepareOutput();
315  $folder_gui = new ilObjFolderGUI(
316  "",
317  ilMediaPoolItem::lookupForeignId($this->mep_item_id),
318  false,
319  false
320  );
321  $this->ctrl->setParameter($this, "foldereditmode", "1");
322  $folder_gui->setFormAction("update", $this->ctrl->getFormActionByClass("ilobjfoldergui"));
323  $folder_gui->editObject();
324  $this->tpl->printToStdout();
325  break;
326 
327  case "updateObject":
328  $folder_gui = new ilObjFolderGUI(
329  "",
330  ilMediaPoolItem::lookupForeignId($this->mep_item_id),
331  false,
332  false
333  );
334  $this->ctrl->setParameter($this, "mepitem_id", $this->getParentFolderId());
335  $this->ctrl->setReturn($this, "listMedia");
336  $folder_gui->updateObject(); // this returns to parent
337  break;
338 
339  case "cancelObject":
340  if ($this->mep_request->getFolderEditMode()) {
341  $this->ctrl->setParameter($this, "mepitem_id", $this->getParentFolderId());
342  }
343  $this->ctrl->redirect($this, "listMedia");
344  break;
345  }
346  break;
347 
348  case "ileditclipboardgui":
349  $this->prepareOutput();
350  $this->addHeaderAction();
351  $this->ctrl->setReturn($this, $this->mode);
352  $clip_gui = new ilEditClipboardGUI();
353  $clip_gui->setMultipleSelections(true);
354  $clip_gui->setInsertButtonTitle($lng->txt("mep_copy_to_mep"));
355  $ilTabs->setTabActive("clipboard");
356  $this->ctrl->forwardCommand($clip_gui);
357  $this->tpl->printToStdout();
358  break;
359 
360  case 'ilinfoscreengui':
361  $this->prepareOutput();
362  $this->addHeaderAction();
363  $this->infoScreen();
364  $this->tpl->printToStdout();
365  break;
366 
367  case 'ilpermissiongui':
368  $this->checkPermission("edit_permission");
369  $this->prepareOutput();
370  $this->addHeaderAction();
371  $perm_gui = new ilPermissionGUI($this);
372  $ilTabs->activateTab("perm_settings");
373  $this->ctrl->forwardCommand($perm_gui);
374  $this->tpl->printToStdout();
375  break;
376 
377  case "ilexportgui":
378  $this->checkPermission("write");
379  $this->prepareOutput();
380  $this->addHeaderAction();
381  $ilTabs->activateTab("export");
382  $exp_gui = new ilExportGUI($this);
383  $exp_gui->addFormat("xml");
384  $ot = ilObjectTranslation::getInstance($this->object->getId());
385  if ($ot->getContentActivated()) {
386  $exp_gui->addFormat("xml_master", "XML (" . $lng->txt("mep_master_language_only") . ")", $this, "export");
387  $exp_gui->addFormat("xml_masternomedia", "XML (" . $lng->txt("mep_master_language_only_no_media") . ")", $this, "export");
388  }
389  $this->ctrl->forwardCommand($exp_gui);
390  $this->tpl->printToStdout();
391  break;
392 
393  case "ilfilesystemgui":
394  $this->checkPermission("write");
395  $this->prepareOutput();
396  $this->addHeaderAction();
397  $ilTabs->clearTargets();
398  $ilTabs->setBackTarget(
399  $lng->txt("back"),
400  $ilCtrl->getLinkTarget($this, "listMedia")
401  );
402  $mset = new ilSetting("mobs");
403  $import_directory_factory = new ilImportDirectoryFactory();
404  $mob_import_directory = $import_directory_factory->getInstanceForComponent(ilImportDirectoryFactory::TYPE_MOB);
405  if ($mob_import_directory->exists()) {
406  $fs_gui = new ilFileSystemGUI($mob_import_directory->getAbsolutePath());
407  $fs_gui->setPostDirPath(true);
408  $fs_gui->setTableId("mepud" . $this->object->getId());
409  $fs_gui->setAllowFileCreation(false);
410  $fs_gui->setAllowDirectoryCreation(false);
411  $fs_gui->clearCommands();
412  $fs_gui->addCommand(
413  $this,
414  "selectUploadDirFiles",
415  $this->lng->txt("mep_sel_upload_dir_files"),
416  false,
417  true
418  );
419  $this->ctrl->forwardCommand($fs_gui);
420  }
421  $this->tpl->printToStdout();
422  break;
423 
424  case "ilcommonactiondispatchergui":
426  $this->ctrl->forwardCommand($gui);
427  break;
428 
429  case 'ilobjecttranslationgui':
430  $this->prepareOutput();
431  $this->addHeaderAction();
432  //$this->setTabs("settings");
433  $ilTabs->activateTab("settings");
434  $this->setSettingsSubTabs("obj_multilinguality");
435  $transgui = new ilObjectTranslationGUI($this);
436  $transgui->setTitleDescrOnlyMode(false);
437  $this->ctrl->forwardCommand($transgui);
438  $this->tpl->printToStdout();
439  break;
440 
441  case "ilmediapoolimportgui":
442  $this->prepareOutput();
443  $this->addHeaderAction();
444  $this->checkPermission("write");
445  $ilTabs->activateTab("import");
446  $gui = new ilMediaPoolImportGUI($this->getMediaPool());
447  $this->ctrl->forwardCommand($gui);
448  $this->tpl->printToStdout();
449  break;
450 
451  case "ilmobmultisrtuploadgui":
452  $this->checkPermission("write");
453  $this->prepareOutput();
454  $this->addHeaderAction();
455  $this->setContentSubTabs("srt_files");
456  $gui = new ilMobMultiSrtUploadGUI(new ilMepMultiSrt($this->getMediaPool()));
457  $this->ctrl->forwardCommand($gui);
458  $this->tpl->printToStdout();
459  break;
460 
461 
462  default:
463  $this->prepareOutput();
464  $this->addHeaderAction();
465  $cmd = $this->ctrl->getCmd("listMedia") ?: "listMedia";
466  $this->$cmd();
467  if (!$this->getCreationMode()) {
468  $this->tpl->printToStdout();
469  }
470  break;
471  }
472  }
473 
477  protected function returnFromItem(): void
478  {
479  $ctrl = $this->ctrl;
480 
481  $type = ilMediaPoolItem::lookupType($this->mep_item_id);
482  if ($type !== "fold") {
483  $tree = $this->object->getTree();
484  $fold_id = $tree->getParentId($this->mep_item_id);
485  if ($fold_id > 0) {
486  $ctrl->setParameter($this, "mepitem_id", $fold_id);
487  $ctrl->redirect($this, "listMedia");
488  }
489  }
490  $this->listMedia();
491  }
492 
493  public function createMediaObject(): void
494  {
495  $this->ctrl->redirectByClass("ilobjmediaobjectgui", "create");
496  }
497 
498  protected function initCreationForms(string $new_type): array
499  {
500  $forms = array(self::CFORM_NEW => $this->initCreateForm($new_type),
501  self::CFORM_IMPORT => $this->initImportForm($new_type));
502 
503  return $forms;
504  }
505 
506  protected function afterSave(ilObject $new_object): void
507  {
508  // always send a message
509  $this->main_tpl->setOnScreenMessage('success', $this->lng->txt("object_added"), true);
510 
511  //ilUtil::redirect($this->getReturnLocation("save","adm_object.php?".$this->link_params));
512  ilUtil::redirect("ilias.php?baseClass=ilMediaPoolPresentationGUI&ref_id=" . $new_object->getRefId() . "&cmd=listMedia");
513  }
514 
515  protected function initEditCustomForm(ilPropertyFormGUI $a_form): void
516  {
517  $obj_service = $this->object_service;
518 
519  // default width
520  $ni = new ilNumberInputGUI($this->lng->txt("mep_default_width"), "default_width");
521  $ni->setMinValue(0);
522  $ni->setSuffix("px");
523  $ni->setMaxLength(5);
524  $ni->setSize(5);
525  $a_form->addItem($ni);
526 
527  // default height
528  $ni = new ilNumberInputGUI($this->lng->txt("mep_default_height"), "default_height");
529  $ni->setSuffix("px");
530  $ni->setMinValue(0);
531  $ni->setMaxLength(5);
532  $ni->setSize(5);
533  $ni->setInfo($this->lng->txt("mep_default_width_height_info"));
534  $a_form->addItem($ni);
535 
536  // presentation
537  $pres = new ilFormSectionHeaderGUI();
538  $pres->setTitle($this->lng->txt('obj_presentation'));
539  $a_form->addItem($pres);
540 
541  // tile image
542  $obj_service->commonSettings()->legacyForm($a_form, $this->object)->addTileImage();
543 
544  // additional features
545  $feat = new ilFormSectionHeaderGUI();
546  $feat->setTitle($this->lng->txt('obj_features'));
547  $a_form->addItem($feat);
548 
550  $this->object->getId(),
551  $a_form,
552  array(
554  )
555  );
556  }
557 
561  public function edit(): void
562  {
563  $tpl = $this->tpl;
564  $ilTabs = $this->tabs_gui;
565 
566  $this->setSettingsSubTabs("settings");
567 
568  if (!$this->checkPermissionBool("write")) {
569  throw new ilPermissionException($this->lng->txt("msg_no_perm_write"));
570  }
571 
572  $ilTabs->activateTab("settings");
573 
574  $form = $this->initEditForm();
575  $values = $this->getEditFormValues();
576  if ($values) {
577  $form->setValuesByArray($values, true);
578  }
579 
580  $this->addExternalEditFormCustom($form);
581 
582  $tpl->setContent($form->getHTML());
583  }
584 
585 
586  protected function getEditFormCustomValues(array &$a_values): void
587  {
588  $ot = ilObjectTranslation::getInstance($this->getMediaPool()->getId());
589  if ($ot->getContentActivated()) {
590  $a_values["title"] = $ot->getDefaultTitle();
591  $a_values["desc"] = $ot->getDefaultDescription();
592  }
593  if ($this->getMediaPool()->getDefaultWidth() > 0) {
594  $a_values["default_width"] = $this->object->getDefaultWidth();
595  }
596  if ($this->getMediaPool()->getDefaultHeight() > 0) {
597  $a_values["default_height"] = $this->object->getDefaultHeight();
598  }
599  }
600 
601  protected function updateCustom(ilPropertyFormGUI $form): void
602  {
603  $obj_service = $this->object_service;
604 
605  $ot = ilObjectTranslation::getInstance($this->getMediaPool()->getId());
606  if ($ot->getContentActivated()) {
607  $ot->setDefaultTitle($form->getInput('title'));
608  $ot->setDefaultDescription($form->getInput('desc'));
609  $ot->save();
610  }
611 
612  $this->getMediaPool()->setDefaultWidth($form->getInput("default_width"));
613  $this->object->setDefaultHeight($form->getInput("default_height"));
614 
615  // additional features
617  $this->object->getId(),
618  $form,
619  array(
621  )
622  );
623 
624  // tile image
625  $obj_service->commonSettings()->legacyForm($form, $this->object)->saveTileImage();
626  }
627 
631  public function listMedia(): void
632  {
633  $ilAccess = $this->access;
634  $tpl = $this->tpl;
635  $ilTabs = $this->tabs;
636  $ilCtrl = $this->ctrl;
637  $ilToolbar = $this->toolbar;
638  $lng = $this->lng;
639 
640  $ilCtrl->setParameter($this, "mep_mode", "listMedia");
641 
642  $this->checkPermission("read");
643 
644  $ilTabs->setTabActive("content");
645  $this->setContentSubTabs("content");
646 
647  if ($ilAccess->checkAccess("write", "", $this->object->getRefId())) {
648  $ilToolbar->addButton(
649  $lng->txt("mep_create_mob"),
650  $ilCtrl->getLinkTargetByClass("ilMediaCreationGUI", "")
651  );
652 
653  $mset = new ilSetting("mobs");
654  if ($mset->get("mep_activate_pages")) {
655  $ilToolbar->addButton(
656  $lng->txt("mep_create_content_snippet"),
657  $ilCtrl->getLinkTargetByClass(["ilobjmediapoolgui", "ilmediapoolpagegui"], "createMediaPoolPage")
658  );
659  }
660 
661  $ilToolbar->addButton(
662  $lng->txt("mep_create_folder"),
663  $ilCtrl->getLinkTarget($this, "createFolderForm")
664  );
665 
666  $upload_factory = new ilImportDirectoryFactory();
667  $media_upload = $upload_factory->getInstanceForComponent(ilImportDirectoryFactory::TYPE_MOB);
668  if ($media_upload->exists() && $this->rbac_system->checkAccess("visible", SYSTEM_FOLDER_ID)) {
669  $ilToolbar->addButton(
670  $lng->txt("mep_create_from_upload_dir"),
671  $ilCtrl->getLinkTargetByClass("ilfilesystemgui", "listFiles")
672  );
673  }
674 
675  $ilToolbar->addButton(
676  $lng->txt("mep_bulk_upload"),
677  $ilCtrl->getLinkTarget($this, "bulkUpload")
678  );
679 
680  $move_ids = ilSession::get("mep_move_ids");
681  if (is_array($move_ids) && count($move_ids) > 0) {
682  $ilToolbar->addSeparator();
683  $ilToolbar->addButton(
684  $lng->txt("paste"),
685  $ilCtrl->getLinkTarget($this, "paste")
686  );
687  }
688  }
689 
690  $mep_table_gui = new ilMediaPoolTableGUI($this, "listMedia", $this->getMediaPool(), "mepitem_id");
691  $tpl->setContent($mep_table_gui->getHTML());
692  }
693 
694  protected function toggleExplorerNodeState(): void
695  {
696  $exp = new ilMediaPoolExplorerGUI($this, "listMedia", $this->getMediaPool());
697  $exp->toggleExplorerNodeState();
698  }
699 
703  public function allMedia(): void
704  {
705  $tpl = $this->tpl;
706  $ilTabs = $this->tabs;
707  $ilCtrl = $this->ctrl;
708  $ilUser = $this->user;
709 
710  $ilCtrl->setParameter($this, "mep_mode", "allMedia");
711 
712  $this->checkPermission("read");
713  $ilTabs->setTabActive("content");
714  $this->setContentSubTabs("mep_all_mobs");
715 
716  $mep_table_gui = new ilMediaPoolTableGUI(
717  $this,
718  "allMedia",
719  $this->getMediaPool(),
720  "mepitem_id",
722  true
723  );
724 
725  if ($this->mep_request->getForceFilter() > 0) {
726  $mep_table_gui->setTitleFilter(
727  ilMediaPoolItem::lookupTitle($this->mep_request->getForceFilter())
728  );
729 
730  // Read again
731  $mep_table_gui = new ilMediaPoolTableGUI(
732  $this,
733  "allMedia",
734  $this->getMediaPool(),
735  "mepitem_id",
737  true
738  );
739  }
740 
741  $tpl->setContent($mep_table_gui->getHTML());
742  }
743 
747  public function applyFilter(): void
748  {
749  $mtab = new ilMediaPoolTableGUI(
750  $this,
751  "allMedia",
752  $this->getMediaPool(),
753  "mepitem_id",
755  true
756  );
757  $mtab->writeFilterToSession();
758  $mtab->resetOffset();
759  $this->allMedia();
760  }
761 
762  public function resetFilter(): void
763  {
764  $mtab = new ilMediaPoolTableGUI(
765  $this,
766  "allMedia",
767  $this->getMediaPool(),
768  "mepitem_id",
770  true
771  );
772  $mtab->resetFilter();
773  $mtab->resetOffset();
774  $this->allMedia();
775  }
776 
780  public function getTemplate(): void
781  {
782  $this->tpl->loadStandardTemplate();
783  }
784 
785 
789  public function getParentFolderId(): ?int
790  {
791  if ($this->mep_item_id == 0) {
792  return null;
793  }
794  $par_id = $this->object->getPoolTree()->getParentId($this->mep_item_id);
795  if ($par_id != $this->object->getPoolTree()->getRootId()) {
796  return (int) $par_id;
797  }
798 
799  return null;
800  }
801 
805  protected function showMedia(): void
806  {
807  $this->checkPermission("read");
808  $link_xml = "";
809  $pg_frame = "";
810 
811  $item = new ilMediaPoolItem($this->mep_item_id);
812  $mob_id = $item->getForeignId();
813 
814  $this->tpl = new ilGlobalTemplate("tpl.fullscreen.html", true, true, "Services/COPage");
815  $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
816  $this->tpl->setVariable(
817  "LOCATION_CONTENT_STYLESHEET",
819  );
820 
821 
823  $media_obj = new ilObjMediaObject($mob_id);
824 
825 
826  $this->tpl->setVariable("TITLE", " - " . $media_obj->getTitle());
827 
828  $xml = "<dummy>";
829  // todo: we get always the first alias now (problem if mob is used multiple
830  // times in page)
831  $xml .= $media_obj->getXML(IL_MODE_ALIAS);
832  $xml .= $media_obj->getXML(IL_MODE_OUTPUT);
833  $xml .= $link_xml;
834  $xml .= "</dummy>";
835 
836  $wb_path = ilFileUtils::getWebspaceDir("output") . "/";
837 
838  $mode = ($this->ctrl->getCmd() !== "showPreview")
839  ? "fullscreen"
840  : "media";
841  $enlarge_path = ilUtil::getImagePath("media/enlarge.svg", false, "output");
842  $fullscreen_link =
843  $this->ctrl->getLinkTarget($this, "showFullscreen", "", false, false);
844  $params = array('mode' => $mode, 'enlarge_path' => $enlarge_path,
845  'link_params' => "ref_id=" . $this->requested_ref_id,'fullscreen_link' => $fullscreen_link,
846  'enable_html_mob' => ilObjMediaObject::isTypeAllowed("html") ? "y" : "n",
847  'ref_id' => $this->requested_ref_id, 'pg_frame' => $pg_frame, 'webspace_path' => $wb_path);
848  $output = $this->xsl->process($xml, $params);
849 
850  // unmask user html
851  $this->tpl->setVariable("MEDIA_CONTENT", $output);
852  }
853 
860  public function showPage(): void
861  {
862  //$tpl = new \ilGlobalPageTemplate($DIC->globalScreen(), $DIC->ui(), $DIC->http());
863  $tpl = new ilGlobalTemplate("tpl.fullscreen.html", true, true, "Services/COPage");
864 
868 
869  // get page object
870  $page_gui = $this->getMediaPoolPageGUI($this->mep_item_id);
871  $page_gui->setTemplate($tpl);
872 
873  $page_gui->setTemplateOutput(false);
874  $page_gui->setHeader("");
875  $ret = $page_gui->showPage(true);
876 
877  //$tpl->setBodyClass("ilMediaPoolPagePreviewBody");
878  $tpl->setVariable("MEDIA_CONTENT", "<div>" . $ret . "</div>");
879 
880 
881  $tpl->printToStdout();
882  exit;
883  }
884 
890  protected function getMediaPoolPageGUI($mep_item_id, $old_nr = 0)
891  {
892  include_once("./Modules/MediaPool/classes/class.ilMediaPoolPageGUI.php");
893  $page_gui = new ilMediaPoolPageGUI($mep_item_id, $old_nr);
894  $page_gui->setPoolGUI($this);
895 
896  return $page_gui;
897  }
898 
899 
903  public function showPreview(): void
904  {
905  $this->checkPermission("read");
906 
907  $item = new ilMediaPoolItem($this->mep_item_id);
908 
909  switch ($item->getType()) {
910  case "mob":
911  $this->showMedia();
912  break;
913 
914  case "pg":
915  $this->showPage();
916  break;
917  }
918  }
919 
920 
924  public function showFullscreen(): void
925  {
926  $this->showMedia();
927  }
928 
932  public function confirmRemove(): void
933  {
934  $ilCtrl = $this->ctrl;
935  $lng = $this->lng;
936 
937  $this->checkPermission("write");
938 
939  $ids = $this->mep_request->getItemIds();
940  if (count($ids) === 0) {
941  $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt("no_checkbox"), true);
942  $ilCtrl->redirect($this, "");
943  }
944 
945  // display confirmation message
946  $cgui = new ilConfirmationGUI();
947  $cgui->setFormAction($this->ctrl->getFormAction($this));
948  $cgui->setHeaderText($this->lng->txt("info_remove_sure"));
949  $cgui->setCancel($this->lng->txt("cancel"), "cancelRemove");
950  $cgui->setConfirm($this->lng->txt("confirm"), "remove");
951 
952  foreach ($ids as $obj_id) {
954  $title = ilMediaPoolItem::lookupTitle($obj_id);
955 
956  // check whether page can be removed
957  $add = "";
958  if ($type === "pg") {
959  $usages = ilPageContentUsage::getUsages("incl", $obj_id, false);
960  if (count($usages) > 0) {
961  $this->main_tpl->setOnScreenMessage('failure', sprintf($lng->txt("mep_content_snippet_in_use"), $title), true);
962  $ilCtrl->redirect($this, "listMedia");
963  } else {
964  // check whether the snippet is used in older versions of pages
965  $usages = ilPageContentUsage::getUsages("incl", $obj_id, true);
966  if (count($usages) > 0) {
967  $add = "<div class='small'>" . $lng->txt("mep_content_snippet_used_in_older_versions") . "</div>";
968  }
969  }
970  }
971 
972  $caption =
973  " " . $title . $add;
974 
975  $cgui->addItem("id[]", $obj_id, $caption);
976  }
977 
978  $this->tpl->setContent($cgui->getHTML());
979  }
980 
984  public function openClipboard(): void
985  {
986  $ilCtrl = $this->ctrl;
987 
988  $this->checkPermission("write");
989 
990  $ilCtrl->setParameterByClass(
991  "ileditclipboardgui",
992  "returnCommand",
993  rawurlencode($ilCtrl->getLinkTarget(
994  $this,
995  "insertFromClipboard",
996  "",
997  false,
998  false
999  ))
1000  );
1001  $ilCtrl->redirectByClass("ilEditClipboardGUI", "getObject");
1002  }
1003 
1004 
1008  public function insertFromClipboard(): void
1009  {
1010  $this->checkPermission("write");
1011 
1012  $this->domain->mediapool($this->object->getId())
1013  ->copySelectedFromEditClipboard($this->mep_item_id);
1014 
1015  /*
1016  if (count($not_inserted) > 0) {
1017  $this->main_tpl->setOnScreenMessage('info', $this->lng->txt("mep_not_insert_already_exist") . "<br>" .
1018  implode("<br>", $not_inserted), true);
1019  }*/
1020  $this->ctrl->redirect($this, $this->mode);
1021  }
1022 
1023 
1027  public function cancelRemove(): void
1028  {
1029  $this->ctrl->redirect($this, $this->mode);
1030  }
1031 
1032  public function remove(): void
1033  {
1034  $this->checkPermission("write");
1035 
1036  $ids = $this->mep_request->getItemIds();
1037  foreach ($ids as $obj_id) {
1038  $this->object->deleteChild($obj_id);
1039  }
1040 
1041  $this->main_tpl->setOnScreenMessage('success', $this->lng->txt("cont_obj_removed"), true);
1042  $this->ctrl->redirect($this, $this->mode);
1043  }
1044 
1045 
1049  public function copyToClipboard(): void
1050  {
1051  $ilUser = $this->user;
1052 
1053  $this->checkPermission("write");
1054 
1055  $ids = $this->mep_request->getItemIds();
1056  if (count($ids) === 0) {
1057  $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt("no_checkbox"), true);
1058  $this->ctrl->redirect($this, $this->mode);
1059  }
1060 
1061  foreach ($ids as $obj_id) {
1063  if ($type === "fold") {
1064  $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt("cont_cant_copy_folders"), true);
1065  $this->ctrl->redirect($this, $this->mode);
1066  }
1067  }
1068  foreach ($ids as $obj_id) {
1069  $fid = ilMediaPoolItem::lookupForeignId($obj_id);
1071  if ($type === "mob") {
1072  $ilUser->addObjectToClipboard($fid, "mob", "");
1073  }
1074  if ($type === "pg") {
1075  $ilUser->addObjectToClipboard($obj_id, "incl", "");
1076  }
1077  }
1078  $this->main_tpl->setOnScreenMessage('success', $this->lng->txt("copied_to_clipboard"), true);
1079  $this->ctrl->redirect($this, $this->mode);
1080  }
1081 
1085  protected function addLocatorItems(): void
1086  {
1087  $ilLocator = $this->locator;
1088  $ilAccess = $this->access;
1089  if (!$this->getCreationMode() && $this->ctrl->getCmd() !== "explorer") {
1090  $tree = $this->object->getTree();
1093  foreach ($path as $node) {
1094  if ($node["child"] == $tree->getRootId()) {
1095  $this->ctrl->setParameter($this, "mepitem_id", "");
1096  $link = "";
1097  if ($ilAccess->checkAccess("read", "", $this->object->getRefId())) {
1098  $link = $this->ctrl->getLinkTarget($this, "listMedia");
1099  } elseif ($ilAccess->checkAccess("visible", "", $this->object->getRefId())) {
1100  $link = $this->ctrl->getLinkTarget($this, "infoScreen");
1101  }
1102  $title = $this->object->getTitle();
1103  $this->ctrl->setParameter($this, "mepitem_id", $this->mep_item_id);
1104  $ilLocator->addItem($title, $link, "", $this->requested_ref_id);
1105  }
1106  }
1107  }
1108  }
1109 
1113 
1114  public function createFolderForm(): void
1115  {
1116  $tpl = $this->tpl;
1117 
1118  $this->checkPermission("write");
1119 
1120  $this->initFolderForm("create");
1121  $tpl->setContent($this->form->getHTML());
1122  }
1123 
1124  public function editFolder(): void
1125  {
1126  $tpl = $this->tpl;
1127 
1128  $this->checkPermission("write");
1129 
1130  $this->initFolderForm();
1131  $this->getFolderValues();
1132  $tpl->setContent($this->form->getHTML());
1133  }
1134 
1138  public function getFolderValues(): void
1139  {
1140  $values = array();
1141 
1142  $values["title"] = ilMediaPoolItem::lookupTitle($this->mep_item_id);
1143 
1144  $this->form->setValuesByArray($values);
1145  }
1146 
1150  public function saveFolder(): void
1151  {
1152  $tpl = $this->tpl;
1153  $lng = $this->lng;
1154  $ilCtrl = $this->ctrl;
1155 
1156  $this->checkPermission("write");
1157 
1158  $this->initFolderForm("create");
1159  if ($this->form->checkInput()) {
1160  if ($this->object->createFolder($this->form->getInput("title"), $this->mep_item_id)) {
1161  $this->main_tpl->setOnScreenMessage('success', $lng->txt("mep_folder_created"), true);
1162  }
1163  $ilCtrl->redirect($this, "listMedia");
1164  }
1165 
1166  $this->form->setValuesByPost();
1167  $tpl->setContent($this->form->getHTML());
1168  }
1169 
1170  public function updateFolder(): void
1171  {
1172  $lng = $this->lng;
1173  $ilCtrl = $this->ctrl;
1174  $tpl = $this->tpl;
1175 
1176  $this->checkPermission("write");
1177 
1178  $this->initFolderForm("edit");
1179  if ($this->form->checkInput()) {
1180  $item = new ilMediaPoolItem($this->mep_item_id);
1181  $item->setTitle($this->form->getInput("title"));
1182  $item->update();
1183  $this->main_tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
1184  $ilCtrl->setParameter(
1185  $this,
1186  "mepitem_id",
1187  $this->object->getTree()->getParentId($this->mep_item_id)
1188  );
1189  $ilCtrl->redirect($this, "listMedia");
1190  }
1191 
1192  $this->form->setValuesByPost();
1193  $tpl->setContent($this->form->getHTML());
1194  }
1195 
1200  public function initFolderForm(string $a_mode = "edit"): void
1201  {
1202  $lng = $this->lng;
1203  $ilCtrl = $this->ctrl;
1204 
1205  $this->form = new ilPropertyFormGUI();
1206 
1207  // desc
1208  $ti = new ilTextInputGUI($lng->txt("title"), "title");
1209  $ti->setMaxLength(128);
1210  $ti->setRequired(true);
1211  $this->form->addItem($ti);
1212 
1213  // save and cancel commands
1214  if ($a_mode === "create") {
1215  $this->form->addCommandButton("saveFolder", $lng->txt("save"));
1216  $this->form->addCommandButton("cancelSave", $lng->txt("cancel"));
1217  $this->form->setTitle($lng->txt("mep_new_folder"));
1218  } else {
1219  $this->form->addCommandButton("updateFolder", $lng->txt("save"));
1220  $this->form->addCommandButton("cancelFolderUpdate", $lng->txt("cancel"));
1221  $this->form->setTitle($lng->txt("mep_edit_folder"));
1222  }
1223 
1224  $this->form->setFormAction($ilCtrl->getFormAction($this));
1225  }
1226 
1227  public function cancelFolderUpdate(): void
1228  {
1229  $ilCtrl = $this->ctrl;
1230  $ilCtrl->setParameter(
1231  $this,
1232  "mepitem_id",
1233  $this->object->getTree()->getParentId($this->mep_item_id)
1234  );
1235  $ilCtrl->redirect($this, "listMedia");
1236  }
1237 
1238  public function cancelSave(): void
1239  {
1240  $ilCtrl = $this->ctrl;
1241  $ilCtrl->redirect($this, "listMedia");
1242  }
1243 
1247 
1251  public function setContentSubTabs(
1252  string $a_active
1253  ): void {
1254  $ilAccess = $this->access;
1255  $ilTabs = $this->tabs;
1256  $ilCtrl = $this->ctrl;
1257 
1258  $ilTabs->addSubTab("content", $this->lng->txt("objs_fold"), $this->ctrl->getLinkTarget($this, ""));
1259 
1260  $ilCtrl->setParameter($this, "mepitem_id", "");
1261  $ilTabs->addSubTab("mep_all_mobs", $this->lng->txt("mep_all_mobs"), $this->ctrl->getLinkTarget($this, "allMedia"));
1262  $ilCtrl->setParameter($this, "mepitem_id", $this->mep_item_id);
1263 
1264  if ($ilAccess->checkAccess('write', '', $this->ref_id)) {
1265  $ilTabs->addSubTab(
1266  "srt_files",
1267  $this->lng->txt("mep_media_subtitles"),
1268  $ilCtrl->getLinkTargetByClass("ilmobmultisrtuploadgui", "")
1269  );
1270  }
1271 
1272  $ilTabs->activateSubTab($a_active);
1273  }
1274 
1275  protected function setTabs(): void
1276  {
1277  $ilAccess = $this->access;
1278  $ilTabs = $this->tabs;
1279  $ilHelp = $this->help;
1280 
1281  $ilHelp->setScreenIdComponent("mep");
1282 
1283  if ($ilAccess->checkAccess('read', '', $this->ref_id) ||
1284  $ilAccess->checkAccess('write', '', $this->ref_id)) {
1285  $ilTabs->addTab("content", $this->lng->txt("mep_content"), $this->ctrl->getLinkTarget($this, ""));
1286  }
1287 
1288  // info tab
1289  if ($ilAccess->checkAccess('visible', '', $this->ref_id) ||
1290  $ilAccess->checkAccess('read', '', $this->ref_id) ||
1291  $ilAccess->checkAccess('write', '', $this->ref_id)) {
1292  $force_active = $this->ctrl->getNextClass() === "ilinfoscreengui"
1293  || strtolower($this->ctrl->getCmdClass()) === "ilnotegui";
1294  $ilTabs->addTarget(
1295  "info_short",
1296  $this->ctrl->getLinkTargetByClass(
1297  array("ilobjmediapoolgui", "ilinfoscreengui"),
1298  "showSummary"
1299  ),
1300  array("showSummary", "infoScreen"),
1301  "",
1302  "",
1303  $force_active
1304  );
1305  }
1306 
1307  if ($ilAccess->checkAccess("write", "", $this->object->getRefId())) {
1308  $ilTabs->addTarget(
1309  "settings",
1310  $this->ctrl->getLinkTarget($this, "edit"),
1311  "edit",
1312  array("", "ilobjmediapoolgui")
1313  );
1314  }
1315  if ($ilAccess->checkAccess("write", "", $this->object->getRefId())) {
1316  $ilTabs->addTarget(
1317  "clipboard",
1318  $this->ctrl->getLinkTarget($this, "openClipboard"),
1319  "view",
1320  "ileditclipboardgui"
1321  );
1322  }
1323 
1324  // properties
1325  if ($ilAccess->checkAccess("write", "", $this->object->getRefId())) {
1326  // meta data
1327  $mdgui = new ilObjectMetaDataGUI($this->object, ['mob', "mpg"]);
1328  $mdtab = $mdgui->getTab();
1329  if ($mdtab) {
1330  $ilTabs->addTarget(
1331  "meta_data",
1332  $mdtab,
1333  "",
1334  "ilobjectmetadatagui"
1335  );
1336  }
1337  }
1338 
1339  if ($ilAccess->checkAccess("write", "", $this->object->getRefId())) {
1340  $ilTabs->addTarget(
1341  "export",
1342  $this->ctrl->getLinkTargetByClass("ilexportgui", ""),
1343  "",
1344  "ilexportgui"
1345  );
1346 
1347  $ilTabs->addTarget(
1348  "import",
1349  $this->ctrl->getLinkTargetByClass("ilmediapoolimportgui", ""),
1350  "",
1351  "ilmediapoolimportgui"
1352  );
1353  }
1354 
1355  if ($ilAccess->checkAccess("edit_permission", "", $this->object->getRefId())) {
1356  $ilTabs->addTarget(
1357  "perm_settings",
1358  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"),
1359  array("perm","info","owner"),
1360  'ilpermissiongui'
1361  );
1362  }
1363  }
1364 
1365  public function setSettingsSubTabs(
1366  string $a_active
1367  ): void {
1368  $ilTabs = $this->tabs;
1369  $lng = $this->lng;
1370  $ilAccess = $this->access;
1371 
1372  if ($ilAccess->checkAccess("write", "", $this->object->getRefId())) {
1373  $ilTabs->addSubTab(
1374  "settings",
1375  $lng->txt("settings"),
1376  $this->ctrl->getLinkTarget($this, "edit")
1377  );
1378 
1379  $mset = new ilSetting("mobs");
1380  if ($mset->get("mep_activate_pages")) {
1381  $ilTabs->addSubTabTarget(
1382  "obj_multilinguality",
1383  $this->ctrl->getLinkTargetByClass("ilobjecttranslationgui", "")
1384  );
1385  }
1386  }
1387 
1388  $ilTabs->setSubTabActive($a_active);
1389  }
1390 
1391 
1392  public static function _goto(string $a_target): void
1393  {
1394  global $DIC;
1395  $main_tpl = $DIC->ui()->mainTemplate();
1396 
1397  $ilAccess = $DIC->access();
1398  $lng = $DIC->language();
1399  $ctrl = $DIC->ctrl();
1400 
1401  $subitem_id = "";
1402  $targets = explode('_', $a_target);
1403  $ref_id = $targets[0];
1404  if (count((array) $targets) > 1) {
1405  $subitem_id = $targets[1];
1406  }
1407 
1408  $ctrl->setParameterByClass("ilMediaPoolPresentationGUI", "ref_id", $ref_id);
1409  if ($ilAccess->checkAccess("read", "", $ref_id)) {
1410  $ctrl->setParameterByClass("ilMediaPoolPresentationGUI", "mepitem_id", $subitem_id);
1411  $ctrl->redirectByClass("ilMediaPoolPresentationGUI", "");
1412  } elseif ($ilAccess->checkAccess("visible", "", $ref_id)) {
1413  $ctrl->redirectByClass("ilMediaPoolPresentationGUI", "infoScreen");
1414  } elseif ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID)) {
1415  $main_tpl->setOnScreenMessage('failure', sprintf(
1416  $lng->txt("msg_no_perm_read_item"),
1418  ), true);
1420  }
1421 
1422  throw new ilPermissionException($lng->txt("msg_no_perm_read"));
1423  }
1424 
1428  public function infoScreenObject(): void
1429  {
1430  $this->ctrl->setCmd("showSummary");
1431  $this->ctrl->setCmdClass("ilinfoscreengui");
1432  $this->infoScreen();
1433  }
1434 
1440  public function infoScreen(): void
1441  {
1442  $this->tabs->activateTab("info_short");
1443  $ilAccess = $this->access;
1444 
1445  if (!$ilAccess->checkAccess("visible", "", $this->ref_id) &&
1446  !$ilAccess->checkAccess("read", "", $this->ref_id) &&
1447  !$ilAccess->checkAccess("write", "", $this->ref_id)) {
1448  throw new ilPermissionException($this->lng->txt("msg_no_perm_read"));
1449  }
1450 
1451  if ($this->ctrl->getCmd() === "infoScreen") {
1452  $this->ctrl->setCmd("showSummary");
1453  $this->ctrl->setCmdClass("ilinfoscreengui");
1454  }
1455 
1456  $info = new ilInfoScreenGUI($this);
1457 
1458  $info->enablePrivateNotes();
1459 
1460 
1461  // standard meta data
1462  $info->addMetaDataSections($this->object->getId(), 0, $this->object->getType());
1463 
1464  // forward the command
1465  $this->ctrl->forwardCommand($info);
1466  }
1467 
1468 
1472 
1476  public function selectUploadDirFiles(
1477  ?array $a_files = null
1478  ): void {
1479  $tpl = $this->tpl;
1480  $ilTabs = $this->tabs;
1481  $lng = $this->lng;
1482  $ilCtrl = $this->ctrl;
1483  $ilToolbar = $this->toolbar;
1484 
1485 
1486  if (!$a_files) {
1487  $a_files = $this->mep_request->getFiles();
1488  }
1489 
1490  $ilTabs->clearTargets();
1491  $ilTabs->setBackTarget(
1492  $lng->txt("back"),
1493  $ilCtrl->getLinkTarget($this, "listMedia")
1494  );
1495 
1496  $this->checkPermission("write");
1497 
1498  if ($this->rbac_system->checkAccess("visible", SYSTEM_FOLDER_ID)) {
1499  $tb = new ilToolbarGUI();
1500  // action type
1501  $options = array(
1502  "rename" => $lng->txt("mep_up_dir_move"),
1503  "copy" => $lng->txt("mep_up_dir_copy"),
1504  );
1505  $si = new ilSelectInputGUI("", "action");
1506  $si->setOptions($options);
1507  $tb->addInputItem($si);
1508  $tb->setCloseFormTag(false);
1509  $tb->setFormAction($ilCtrl->getFormAction($this));
1510  $tb->setFormName("mep_up_form");
1511 
1512  $tab = new ilUploadDirFilesTableGUI(
1513  $this,
1514  "selectUploadDirFiles",
1515  $a_files
1516  );
1517  $tab->setFormName("mep_up_form");
1518  $tpl->setContent($tb->getHTML() . $tab->getHTML());
1519  }
1520  }
1521 
1525  public function createMediaFromUploadDir(): void
1526  {
1527  $this->checkPermission("write");
1528 
1529  $import_directory_factory = new ilImportDirectoryFactory();
1530  $mob_import_directory = $import_directory_factory->getInstanceForComponent(ilImportDirectoryFactory::TYPE_MOB);
1531  $upload_dir = $mob_import_directory->getAbsolutePath();
1532 
1533  $files = $this->mep_request->getFiles();
1534  if ($this->rbac_system->checkAccess("visible", SYSTEM_FOLDER_ID)) {
1535  foreach ($files as $f) {
1536  $f = str_replace("..", "", $f);
1537  $fullpath = $upload_dir . "/" . $f;
1538  $mob = new ilObjMediaObject();
1539  $mob->setTitle(basename($fullpath));
1540  $mob->setDescription("");
1541  $mob->create();
1542 
1543  // determine and create mob directory, move uploaded file to directory
1544  //$mob_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob->getId();
1545  $mob->createDirectory();
1546  $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
1547 
1548  $media_item = new ilMediaItem();
1549  $mob->addMediaItem($media_item);
1550  $media_item->setPurpose("Standard");
1551 
1552  $file = $mob_dir . "/" . basename($fullpath);
1553 
1554  // virus handling
1555  $vir = ilVirusScanner::virusHandling($fullpath, basename($fullpath));
1556  if (!$vir[0]) {
1557  $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt("file_is_infected") . "<br />" . $vir[1], true);
1558  ilUtil::redirect("ilias.php?baseClass=ilMediaPoolPresentationGUI&cmd=listMedia&ref_id=" .
1559  $this->requested_ref_id . "&mepitem_id=" . $this->mep_item_id);
1560  }
1561 
1562  switch ($this->mep_request->getFileAction()) {
1563  case "rename":
1564  rename($fullpath, $file);
1565  break;
1566 
1567  case "copy":
1568  copy($fullpath, $file);
1569  break;
1570  }
1571 
1572  // get mime type
1573  $format = ilObjMediaObject::getMimeType($file);
1574  $location = basename($fullpath);
1575 
1576  // set real meta and object data
1577  $media_item->setFormat($format);
1578  $media_item->setLocation($location);
1579  $media_item->setLocationType("LocalFile");
1580 
1581  $mob->setDescription($format);
1582 
1583  // determine width and height of known image types
1585  $format,
1586  "File",
1587  $mob_dir . "/" . $location,
1588  $media_item->getLocation(),
1589  true,
1590  true,
1591  null,
1592  null
1593  );
1594  $media_item->setWidth($wh["width"]);
1595  $media_item->setHeight($wh["height"]);
1596 
1597  $media_item->setHAlign("Left");
1599  $mob->update();
1600 
1601 
1602  // put it into current folder
1603  $mep_item = new ilMediaPoolItem();
1604  $mep_item->setTitle($mob->getTitle());
1605  $mep_item->setType("mob");
1606  $mep_item->setForeignId($mob->getId());
1607  $mep_item->create();
1608 
1609  $tree = $this->object->getTree();
1610  $parent = $this->mep_item_id;
1611  $tree->insertNode($mep_item->getId(), $parent);
1612  }
1613  }
1614  ilUtil::redirect("ilias.php?baseClass=ilMediaPoolPresentationGUI&cmd=listMedia&ref_id=" .
1615  $this->requested_ref_id . "&mepitem_id=" . $this->mep_item_id);
1616  }
1617 
1621  public static function getPreviewModalHTML(
1622  int $a_mpool_ref_id,
1624  ): string {
1625  global $DIC;
1626 
1627  $tpl = $DIC["tpl"];
1628  $ilCtrl = $DIC->ctrl();
1629  $lng = $DIC->language();
1630  $request = $DIC->mediaPool()
1631  ->internal()
1632  ->gui()
1633  ->standardRequest();
1634 
1636 
1637  $tpl->addJavaScript("./Modules/MediaPool/js/ilMediaPool.js");
1638 
1639  $ilCtrl->setParameterByClass("ilobjmediapoolgui", "mepitem_id", "");
1640  $ilCtrl->setParameterByClass("ilobjmediapoolgui", "ref_id", $a_mpool_ref_id);
1641  $tpl->addOnloadCode("il.MediaPool.setPreviewUrl('" . $ilCtrl->getLinkTargetByClass(array("ilmediapoolpresentationgui", "ilobjmediapoolgui"), "showPreview", "", false, false) . "');");
1642  $ilCtrl->setParameterByClass("ilobjmediapoolgui", "mepitem_id", $request->getItemId());
1643  $ilCtrl->setParameterByClass(
1644  "ilobjmediapoolgui",
1645  "ref_id",
1646  $request->getRefId()
1647  );
1648 
1649  $modal = ilModalGUI::getInstance();
1650  $modal->setHeading($lng->txt("preview"));
1651  $modal->setId("ilMepPreview");
1652  $modal->setType(ilModalGUI::TYPE_LARGE);
1653  $modal->setBody("<iframe id='ilMepPreviewContent'></iframe>");
1654 
1655  return $modal->getHTML();
1656  }
1657 
1658  public function export(): void
1659  {
1660  $ot = ilObjectTranslation::getInstance($this->object->getId());
1661  $opt = "";
1662  if ($ot->getContentActivated()) {
1663  $format = explode("_", $this->mep_request->getExportFormat());
1664  $opt = ilUtil::stripSlashes($format[1]);
1665  }
1666 
1667  $this->object->exportXML($opt);
1668  }
1669 
1670  //
1671  // BULK UPLOAD
1672  //
1673 
1674  protected function bulkUpload(): void
1675  {
1676  $this->checkPermission("write");
1677 
1678  $main_tpl = $this->main_tpl;
1679 
1680  $form = $this->getBulkUploadForm();
1681  $main_tpl->setContent($form->render());
1682  }
1683 
1684  protected function getBulkUploadForm(): FormAdapterGUI
1685  {
1686  if (is_null($this->bulk_upload_form)) {
1687  $mep_hash = uniqid();
1688  $this->ctrl->setParameter($this, "mep_hash", $mep_hash);
1689  $this->bulk_upload_form = $this->gui
1690  ->form(self::class, 'performBulkUpload')
1691  ->section("props", $this->lng->txt('mep_bulk_upload'))
1692  ->file(
1693  "media_files",
1694  $this->lng->txt("mep_media_files"),
1695  \Closure::fromCallable([$this, 'handleUploadResult']),
1696  "mep_id",
1697  "",
1698  20
1699  );
1700  // ->meta()->text()->meta()->textarea()
1701  }
1702  return $this->bulk_upload_form;
1703  }
1704 
1705  protected function handleUploadResult(
1706  FileUpload $upload,
1707  UploadResult $result
1708  ): BasicHandlerResult {
1709  $title = $result->getName();
1710 
1711  $mob = new ilObjMediaObject();
1712  $mob->setTitle($title);
1713  $mob->setDescription("");
1714  $mob->create();
1715 
1716  $mob->createDirectory();
1717  $media_item = new ilMediaItem();
1718  $mob->addMediaItem($media_item);
1719  $media_item->setPurpose("Standard");
1720 
1721  $mob_dir = ilObjMediaObject::_getRelativeDirectory($mob->getId());
1722  $file_name = ilObjMediaObject::fixFilename($title);
1723  $file = $mob_dir . "/" . $file_name;
1724 
1725  $upload->moveOneFileTo(
1726  $result,
1727  $mob_dir,
1728  Location::WEB,
1729  $file_name,
1730  true
1731  );
1732 
1733  $mep_item = new ilMediaPoolItem();
1734  $mep_item->setTitle($title);
1735  $mep_item->setType("mob");
1736  $mep_item->setForeignId($mob->getId());
1737  $mep_item->create();
1738 
1739  $tree = $this->object->getTree();
1740  $parent = $this->mep_item_id;
1741  $tree->insertNode($mep_item->getId(), $parent);
1742 
1743  // get mime type
1744  $format = ilObjMediaObject::getMimeType($file);
1745  $location = $file_name;
1746 
1747  // set real meta and object data
1748  $media_item->setFormat($format);
1749  $media_item->setLocation($location);
1750  $media_item->setLocationType("LocalFile");
1751  $media_item->setUploadHash($this->mep_request->getUploadHash());
1752  $mob->update();
1753 
1754  $item_ids[] = $mob->getId();
1755 
1756  $mob = new ilObjMediaObject($mob->getId());
1757  $mob->generatePreviewPic(320, 240);
1758 
1759  // duration
1760  $med_item = $mob->getMediaItem("Standard");
1761  $med_item->determineDuration();
1762  $med_item->update();
1763 
1764  return new BasicHandlerResult(
1765  "mep_id",
1766  HandlerResult::STATUS_OK,
1767  $med_item->getId(),
1768  ''
1769  );
1770  }
1771 
1775  public function performBulkUpload(): void
1776  {
1777  $this->checkPermission("write");
1778  $this->ctrl->setParameter($this, "mep_hash", $this->mep_request->getUploadHash());
1779  $this->ctrl->redirect($this, "editTitlesAndDescriptions");
1780  }
1781 
1782  protected function editTitlesAndDescriptions(): void
1783  {
1784  $ctrl = $this->ctrl;
1785  $lng = $this->lng;
1786 
1787  $this->checkPermission("write");
1788  $ctrl->saveParameter($this, "mep_hash");
1789 
1790  $main_tpl = $this->main_tpl;
1791 
1793  $this->mep_request->getUploadHash()
1794  );
1795 
1796  $tb = new ilToolbarGUI();
1797  $tb->setFormAction($ctrl->getFormAction($this));
1798  $tb->addFormButton($lng->txt("save"), "saveTitlesAndDescriptions");
1799  $tb->setOpenFormTag(true);
1800  $tb->setCloseFormTag(false);
1801  $tb->setId("tb_top");
1802 
1803  $html = $tb->getHTML();
1804  foreach ($media_items as $mi) {
1805  $acc = new ilAccordionGUI();
1806  $acc->setBehaviour(ilAccordionGUI::ALL_CLOSED);
1807  $acc->setId("acc_" . $mi["mob_id"]);
1808 
1809  $mob = new ilObjMediaObject($mi["mob_id"]);
1810  $form = $this->initMediaBulkForm($mi["mob_id"], $mob->getTitle());
1811  $acc->addItem($mob->getTitle(), $form->getHTML());
1812 
1813  $html .= $acc->getHTML();
1814  }
1815 
1816  $html .= $tb->getHTML();
1817  $tb->setOpenFormTag(false);
1818  $tb->setCloseFormTag(true);
1819  $tb->setId("tb_bottom");
1820 
1821  $main_tpl->setContent($html);
1822  }
1823 
1827  public function initMediaBulkForm(
1828  int $a_id,
1829  string $a_title
1830  ): ilPropertyFormGUI {
1831  $lng = $this->lng;
1832 
1833  $form = new ilPropertyFormGUI();
1834  $form->setOpenTag(false);
1835  $form->setCloseTag(false);
1836 
1837  // title
1838  $ti = new ilTextInputGUI($lng->txt("title"), "title_" . $a_id);
1839  $ti->setValue($a_title);
1840  $form->addItem($ti);
1841 
1842  // description
1843  $ti = new ilTextAreaInputGUI($lng->txt("description"), "description_" . $a_id);
1844  $form->addItem($ti);
1845 
1846  return $form;
1847  }
1848 
1849  protected function saveTitlesAndDescriptions(): void
1850  {
1851  $lng = $this->lng;
1852  $ctrl = $this->ctrl;
1853 
1854  $this->checkPermission("write");
1856  $this->mep_request->getUploadHash()
1857  );
1858 
1859  foreach ($media_items as $mi) {
1860  $mob = new ilObjMediaObject($mi["mob_id"]);
1861  $form = $this->initMediaBulkForm($mi["mob_id"], $mob->getTitle());
1862  $form->checkInput();
1863  $title = $form->getInput("title_" . $mi["mob_id"]);
1864  $desc = $form->getInput("description_" . $mi["mob_id"]);
1865  if (trim($title) !== "") {
1866  $mob->setTitle($title);
1867  }
1868  $mob->setDescription($desc);
1869  $mob->update();
1870  }
1871  $this->main_tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
1872  $ctrl->redirect($this, "listMedia");
1873  }
1874 
1875  protected function move(): void
1876  {
1877  ilSession::set("mep_move_ids", $this->mep_request->getItemIds());
1878  $this->main_tpl->setOnScreenMessage('info', $this->lng->txt("mep_move_select_insert"), true);
1879  $this->ctrl->redirect($this, "listMedia");
1880  }
1881 
1882  protected function paste(): void
1883  {
1884  $target_folder_id = $this->mep_request->getItemId();
1885  $target_tree = $this->domain->tree($this->object->getId());
1886  if (ilMediaPoolItem::lookupType($target_folder_id) !== "fold") {
1887  $target_folder_id = $target_tree->readRootId();
1888  }
1889 
1890  try {
1891  $this->domain->mediapool($this->object->getId())->pasteFromClipboard($target_folder_id);
1892  } catch (Exception $e) {
1893  $this->main_tpl->setOnScreenMessage(
1894  'failure',
1895  $this->lng->txt("mep_target_in_source_not_allowed") . " " . $e->getMessage(),
1896  true
1897  );
1898  }
1899 
1900  $this->ctrl->redirect($this, "listMedia");
1901  }
1902 
1903  protected function afterUpload($mob_ids): void
1904  {
1905  $this->addMobsToPool($mob_ids, "", false);
1906  }
1907 
1908  protected function afterUrlSaving(int $mob_id, string $long_desc): void
1909  {
1910  $this->addMobsToPool([$mob_id], $long_desc);
1911  }
1912 
1913  protected function addMobsToPool(
1914  array $mob_ids,
1915  string $long_desc = "",
1916  bool $redirect = true,
1917  bool $extract = false
1918  ): void {
1919  $ctrl = $this->ctrl;
1920  $user = $this->user;
1921 
1922  $item_ids = [];
1923  foreach ($mob_ids as $mob_id) {
1924  $object = new ilObjMediaObject($mob_id);
1925  if (!is_null($object)) {
1926  $mep_item = new ilMediaPoolItem();
1927  $mep_item->setTitle($object->getTitle());
1928  $mep_item->setType("mob");
1929  $mep_item->setForeignId($object->getId());
1930  $mep_item->create();
1931 
1932  $parent = $this->mep_item_id;
1933  $tree = $this->object->getTree();
1934  $tree->insertNode($mep_item->getId(), $parent);
1935  }
1936  }
1937 
1938  if ($redirect) {
1939  $ctrl->redirect($this, "listMedia");
1940  }
1941  }
1942 
1943  protected function afterPoolInsert(array $mob_ids): void
1944  {
1945  $this->addMobsToPool($mob_ids, "", true, true);
1946  }
1947 
1948  public function finishSingleUpload(int $mob_id): void
1949  {
1950  $this->ctrl->redirect($this, "listMedia");
1951  }
1952 
1953  protected function onMobUpdate(int $mob_id): void
1954  {
1955  }
1956 
1957 }
showFullscreen()
show media fullscreen
getFolderValues()
Get current values for folder from.
printToStdout(string $part=self::DEFAULT_BLOCK, bool $has_tabs=true, bool $skip_main_menu=false)
static getWebspaceDir(string $mode="filesystem")
get webspace directory
setLocator()
set Locator
checkPermission(string $perm, string $cmd="", string $type="", int $ref_id=null)
static get(string $a_var)
initEditCustomForm(ilPropertyFormGUI $a_form)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObjFolderGUI.
exit
Definition: login.php:29
Class ilInfoScreenGUI.
redirectByClass( $a_class, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
initImportForm(string $new_type)
performBulkUpload()
Save bulk upload form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getLogger(string $a_component_id)
Get component logger.
This class represents a selection list property in a property form.
openClipboard()
paste from clipboard
static _getRelativeDirectory(int $a_mob_id)
Get relative (to webspace dir) directory.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
redirect(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
static _determineWidthHeight(string $a_format, string $a_type, string $a_file, string $a_reference, bool $a_constrain_proportions, bool $a_use_original, ?int $a_user_width=null, ?int $a_user_height=null)
New implementation of ilObjectGUI.
special template class to simplify handling of ITX/PEAR
const ROOT_FOLDER_ID
Definition: constants.php:32
setOnScreenMessage(string $type, string $a_txt, bool $a_keep=false)
Set a message to be displayed to the user.
$location
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: buildRTE.php:22
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33
infoScreen()
show information screen
returnFromItem()
Return from item editing.
static lookupForeignId(int $a_id)
setCloseTag(bool $a_val)
static includePresentationJS(ilGlobalTemplateInterface $a_tpl=null)
Include media object presentation JS.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
static virusHandling(string $a_file, string $a_orig_name='', bool $a_clean=true)
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
Help GUI class.
allMedia()
list all media objects
infoScreenObject()
this one is called from the info button in the repository
insertFromClipboard()
insert media object from clipboard
setParameterByClass(string $a_class, string $a_parameter, $a_value)
prepareOutput(bool $show_sub_objects=true)
__construct(int $a_id=0, int $a_id_type=self::REPOSITORY_NODE_ID, int $a_parent_node_id=0)
loadLanguageModule(string $a_module)
Load language module.
ILIAS MediaPool InternalDomainService $domain
setVariable(string $variable, $value='')
Sets the given variable to the given value.
static updateServiceSettingsForm(int $obj_id, ilPropertyFormGUI $form, array $services)
getTemplate()
Get standard template.
selectUploadDirFiles(?array $a_files=null)
Select files from upload directory.
ilGlobalTemplateInterface $main_tpl
createMediaFromUploadDir()
Create media object from upload directory.
static lookupTitle(int $a_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setOpenTag(bool $a_open)
static getStyleSheetLocation(string $mode="output", string $a_css_name="", string $a_css_location="")
get full style sheet file name (path inclusive) of current user
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
setSettingsSubTabs(string $a_active)
const SYSTEM_FOLDER_ID
Definition: constants.php:35
getPathFull(int $a_endnode_id, int $a_startnode_id=0)
get path from a given startnode to a given endnode if startnode is not given the rootnode is startnod...
$path
Definition: ltiservices.php:32
showPreview()
Show content snippet.
addExternalEditFormCustom(ilPropertyFormGUI $form)
static _lookupObjId(int $ref_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getEditFormCustomValues(array &$a_values)
global $DIC
Definition: feed.php:28
static renameExecutables(string $a_dir)
ilToolbarGUI $toolbar
Export User Interface Class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setAdvMdRecordObject(int $a_adv_ref_id, string $a_adv_type, string $a_adv_subtype="-")
Set object, that defines the adv md records being used.
afterSave(ilObject $new_object)
saveFolder()
Save folder form.
static _getDirectory(int $a_mob_id)
Get absolute directory.
__construct(VocabulariesInterface $vocabularies)
static getUsages(string $a_pc_type, int $a_pc_id, bool $a_incl_hist=true)
Get usages.
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $node_id=null)
static getMimeType(string $a_file, bool $a_external=false)
get mime type for file
static _lookupTitle(int $obj_id)
setContent(string $a_html)
Sets content for standard template.
FormAdapterGUI $bulk_upload_form
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static isTypeAllowed(string $a_type)
setCreationMode(bool $mode=true)
ServerRequestInterface $request
initCreationForms(string $new_type)
setScreenIdComponent(string $a_comp)
static getMediaItemsForUploadHash(string $a_hash)
Get media items for upload hash.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
afterUrlSaving(int $mob_id, string $long_desc)
moveOneFileTo(UploadResult $uploadResult, string $destination, int $location=Location::STORAGE, string $file_name='', bool $override_existing=false)
Moves a single File (the attributes, metadata and upload-status of which are contained in UploadResul...
static getInstance(int $obj_id)
getMediaItem(string $a_purpose)
get item for media purpose
cancelRemove()
cancel deletion of media objects/folders
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilGlobalTemplateInterface $tpl
listMedia()
list media objects
ilObjectService $object_service
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addJavaScript(string $a_js_file, bool $a_add_version_parameter=true, int $a_batch=2)
Add a javascript file that should be included in the header.
getMediaPoolPageGUI($mep_item_id, $old_nr=0)
Get media pool page.
getParentId(int $a_node_id)
get parent id of given node
Class FileUpload.
Definition: FileUpload.php:34
setValuesByArray(array $a_values, bool $a_restrict_to_value_keys=false)
static initServiceSettingsForm(int $obj_id, ilPropertyFormGUI $form, array $services)
copyToClipboard()
copy media objects to clipboard
handleUploadResult(FileUpload $upload, UploadResult $result)
const IL_MODE_ALIAS
static getContentStylePath(int $a_style_id, bool $add_random=true, bool $add_token=true)
get content style path static (to avoid full reading)
static fixFilename(string $a_name)
Fix filename of uploaded file.
initMediaBulkForm(int $a_id, string $a_title)
Init media bulk form.
static getPreviewModalHTML(int $a_mpool_ref_id, ilGlobalTemplateInterface $a_tpl)
Get preview modal html.
static redirect(string $a_script)
StandardGUIRequest $mep_request
static getInstance()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Editing User Interface for MediaObjects within LMs (see ILIAS DTD)
form( $class_path, string $cmd, string $submit_caption="")
InternalGUIService $gui
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getParentFolderId()
Get folder parent ID.
insertNode(int $a_node_id, int $a_parent_id, int $a_pos=self::POS_LAST_NODE, bool $a_reset_deletion_date=false)
insert new node with node_id under parent node with parent_id
addLocatorItems()
add locator items for media pool
User Interface class for media pool objects.
initCreateForm(string $new_type)
This class represents a text area property in a property form.
saveParameter(object $a_gui_obj, $a_parameter)
initFolderForm(string $a_mode="edit")
showMedia()
show media object
static lookupType(int $a_id)
ilLocatorGUI $locator
updateCustom(ilPropertyFormGUI $form)
const IL_MODE_OUTPUT
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
File System Explorer GUI class.
setParameter(object $a_gui_obj, string $a_parameter, $a_value)
addMobsToPool(array $mob_ids, string $long_desc="", bool $redirect=true, bool $extract=false)
getFormAction(object $a_gui_obj, string $a_fallback_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _goto(string $a_target)
addHeaderAction()
Add header action menu.
ILIAS COPage Xsl XslManager $xsl
Class ilMediaPoolPage GUI class.
static set(string $a_var, $a_val)
Set a value.
setContentSubTabs(string $a_active)
Set sub tabs for content tab.
static getInstanceFromAjaxCall()
(Re-)Build instance from ajax call
GUI class for object translation handling.
confirmRemove()
confirm remove of mobs
TableGUI class for recent changes in wiki.
static _gotoRepositoryRoot(bool $raise_error=false)
Goto repository root.
addCss(string $a_css_file, string $media="screen")
Add a css file that should be included in the header.
ilAccessHandler $access