ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjMediaObjectGUI.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 require_once ("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
5 require_once("./Services/Link/classes/class.ilInternalLinkGUI.php");
6 require_once ("./Services/Object/classes/class.ilObjectGUI.php");
7 
20 {
21  var $ctrl;
22  var $header;
24  var $enabledmapareas = true;
25 
26  function ilObjMediaObjectGUI($a_data, $a_id = 0, $a_call_by_reference = false, $a_prepare_output = false)
27  {
28  global $lng, $ilCtrl;
29 
30  $this->ctrl =& $ilCtrl;
31  parent::ilObjectGUI($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
32  $this->lng =& $lng;
33  $this->back_title = "";
34  $this->type = "mob";
35 
36  $lng->loadLanguageModule("mob");
37  }
38 
39  function setHeader($a_title = "")
40  {
41  $this->header = $a_title;
42  }
43 
44  function getHeader()
45  {
46  return $this->header;
47  }
48 
54  function setEnabledMapAreas($a_enabledmapareas)
55  {
56  $this->enabledmapareas = $a_enabledmapareas;
57  }
58 
64  function getEnabledMapAreas()
65  {
67  }
68 
74  function setWidthPreset($a_val)
75  {
76  $this->width_preset = $a_val;
77  }
78 
84  function getWidthPreset()
85  {
86  return $this->width_preset;
87  }
88 
94  function setHeightPreset($a_val)
95  {
96  $this->height_preset = $a_val;
97  }
98 
104  function getHeightPreset()
105  {
106  return $this->height_preset;
107  }
108 
114  function getForm()
115  {
116  return $this->form_gui;
117  }
118 
119  function assignObject()
120  {
121  if ($this->id != 0)
122  {
123  $this->object =& new ilObjMediaObject($this->id);
124  }
125  }
126 
128  {
129  $this->ctrl->returnToParent($this);
130  }
131 
132 
136  function &executeCommand()
137  {
138  global $tpl, $ilAccess, $ilErr;
139 
140  $next_class = $this->ctrl->getNextClass($this);
141  $cmd = $this->ctrl->getCmd();
142 
143  switch($next_class)
144  {
145  case 'ilmdeditorgui':
146  include_once 'Services/MetaData/classes/class.ilMDEditorGUI.php';
147 
148  $md_gui =& new ilMDEditorGUI(0, $this->object->getId(), $this->object->getType());
149  $md_gui->addObserver($this->object,'MDUpdateListener','General');
150 
151  $this->ctrl->forwardCommand($md_gui);
152  break;
153 
154  case "ilimagemapeditorgui":
155  require_once("./Services/MediaObjects/classes/class.ilImageMapEditorGUI.php");
156  $image_map_edit = new ilImageMapEditorGUI($this->object);
157  $ret = $this->ctrl->forwardCommand($image_map_edit);
158  $tpl->setContent($ret);
159  break;
160 
161  case "ilfilesystemgui":
162  include_once("./Services/FileSystem/classes/class.ilFileSystemGUI.php");
163  $fs_gui =& new ilFileSystemGUI(ilUtil::getWebspaceDir()."/mobs/mm_".$this->object->getId());
164  $fs_gui->activateLabels(true, $this->lng->txt("cont_purpose"));
165  $fs_gui->setTableId("mobfs".$this->object->getId());
166  $fs_gui->labelFile($this->object->getMediaItem("Standard")->getLocation(),
167  $this->lng->txt("cont_std_view"));
168  if($this->object->hasFullscreenItem())
169  {
170  $fs_gui->labelFile($this->object->getMediaItem("Fullscreen")->getLocation(),
171  $this->lng->txt("cont_fullscreen"));
172  }
173  $fs_gui->addCommand($this, "assignStandardObject", $this->lng->txt("cont_assign_std"));
174  $fs_gui->addCommand($this, "assignFullscreenObject", $this->lng->txt("cont_assign_full"));
175  $ret =& $this->ctrl->forwardCommand($fs_gui);
176  break;
177 
178 
179  default:
180  if (isset($_POST["editImagemapForward"]) ||
181  isset($_POST["editImagemapForward_x"]) ||
182  isset($_POST["editImagemapForward_y"]))
183  {
184  $cmd = "editImagemapForward";
185  }
186  $cmd.= "Object";
187  $ret =& $this->$cmd();
188  break;
189  }
190 
191  return $ret;
192  }
193 
197  function setBackTitle($a_title)
198  {
199  $this->back_title = $a_title;
200  }
201 
205  function createObject()
206  {
207  global $tpl, $ilHelp;
208 
209  $ilHelp->setScreenId("create");
210  $this->initForm();
211  $tpl->setContent($this->form_gui->getHTML());
212  }
213 
217  function initForm($a_mode = "create")
218  {
219  global $lng, $ilCtrl;
220 
221  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
222 
223  if ($a_mode == "edit")
224  {
225  $std_item = $this->object->getMediaItem("Standard");
226  }
227 
228  $this->form_gui = new ilPropertyFormGUI();
229 
230  // standard view resource
231  $title = new ilTextInputGUI($lng->txt("title"), "standard_title");
232  $title->setSize(40);
233  $title->setMaxLength(120);
234  $this->form_gui->addItem($title);
235  $radio_prop = new ilRadioGroupInputGUI($lng->txt("cont_resource"), "standard_type");
236  $op1 = new ilRadioOption($lng->txt("cont_file"), "File");
237  $up = new ilFileInputGUI("", "standard_file");
238  $up->setSuffixes(ilObjMediaObject::getRestrictedFileTypes());
239  $up->setInfo("");
240  $op1->addSubItem($up);
241  $radio_prop->addOption($op1);
242  $op2 = new ilRadioOption($lng->txt("url"), "Reference");
243  $ref = new ilTextInputGUI("", "standard_reference");
244  $ref->setInfo($lng->txt("cont_ref_helptext"));
245  $op2->addSubItem($ref);
246  $radio_prop->addOption($op2);
247  $radio_prop->setValue("File");
248  $this->form_gui->addItem($radio_prop);
249 
250  // standard format
251  if ($a_mode == "edit")
252  {
253  $format = new ilNonEditableValueGUI($lng->txt("cont_format"), "standard_format");
254  $format->setValue($std_item->getFormat());
255  $this->form_gui->addItem($format);
256  }
257 
258  // standard size
259  $radio_size = new ilRadioGroupInputGUI($lng->txt("size"), "standard_size");
260  if ($a_mode == "edit")
261  {
262  if ($orig_size = $std_item->getOriginalSize())
263  {
264  $add_str = " (".$orig_size["width"]." x ".$orig_size["height"].")";
265  }
266  $op1 = new ilRadioOption($lng->txt("cont_resource_size").$add_str, "original");
267  $op2 = new ilRadioOption($lng->txt("cont_custom_size"), "selected");
268  }
269  else
270  {
271  $op1 = new ilRadioOption($lng->txt("cont_orig_size"), "original");
272  $op2 = new ilRadioOption($lng->txt("cont_adjust_size"), "selected");
273  }
274  $radio_size->addOption($op1);
275 
276  // width height
277  include_once("./Services/MediaObjects/classes/class.ilWidthHeightInputGUI.php");
278  $width_height = new ilWidthHeightInputGUI($lng->txt("cont_width").
279  " / ".$lng->txt("cont_height"), "standard_width_height");
280  $width_height->setConstrainProportions(true);
281  $op2->addSubItem($width_height);
282 
283  // resize image
284  if ($a_mode == "edit")
285  {
286  $std_item = $this->object->getMediaItem("Standard");
287  if (is_int(strpos($std_item->getFormat(), "image"))
288  && $std_item->getLocationType() == "LocalFile")
289  {
290  $resize = new ilCheckboxInputGUI($lng->txt("cont_resize_img")
291  , "standard_resize");
292  $op2->addSubItem($resize);
293  }
294  }
295 
296  $radio_size->setValue("original");
297  if ($a_mode == "create" && ($this->getHeightPreset() > 0 || $this->getWidthPreset() > 0))
298  {
299  $radio_size->setValue("selected");
300  $width_height->setWidth($this->getWidthPreset());
301  $width_height->setHeight($this->getHeightPreset());
302  }
303  $radio_size->addOption($op2);
304  $this->form_gui->addItem($radio_size);
305 
306  // standard caption
307  $caption = new ilTextAreaInputGUI($lng->txt("cont_caption"), "standard_caption");
308  $caption->setCols(30);
309  $caption->setRows(2);
310  $this->form_gui->addItem($caption);
311 
312  /*$caption = new ilTextInputGUI($lng->txt("cont_caption"), "standard_caption");
313  $caption->setSize(40);
314  $caption->setMaxLength(200);
315  $this->form_gui->addItem($caption);*/
316 
317  // text representation (alt text)
318  if ($a_mode == "edit" && is_int(strpos($std_item->getFormat(), "image")))
319  {
320  $ta = new ilTextAreaInputGUI($lng->txt("text_repr"), "text_representation");
321  $ta->setCols(30);
322  $ta->setRows(2);
323  $ta->setInfo($lng->txt("text_repr_info"));
324  $this->form_gui->addItem($ta);
325  }
326 
327  // standard parameters
328  if ($a_mode == "edit" &&
329  !in_array($std_item->getFormat(), ilObjMediaObject::_getSimpleMimeTypes()))
330  {
331  if (ilObjMediaObject::_useAutoStartParameterOnly($std_item->getLocation(),
332  $std_item->getFormat())) // autostart
333  {
334  $auto = new ilCheckboxInputGUI($lng->txt("cont_autostart"), "standard_autostart");
335  $this->form_gui->addItem($auto);
336  }
337  else // parameters
338  {
339  $par = new ilTextAreaInputGUI($lng->txt("cont_parameter"), "standard_parameters");
340  $par->setRows(5);
341  $par->setCols(50);
342  $this->form_gui->addItem($par);
343  }
344  }
345 
346  if ($a_mode == "edit")
347  {
348  $full_item = $this->object->getMediaItem("Fullscreen");
349  }
350 
351  // fullscreen view resource
352  $fs_sec = new ilFormSectionHeaderGUI();
353  $fs_sec->setTitle($lng->txt("cont_fullscreen"));
354  $this->form_gui->addItem($fs_sec);
355 
356  $radio_prop2 = new ilRadioGroupInputGUI($lng->txt("cont_resource"), "full_type");
357  $op1 = new ilRadioOption($lng->txt("cont_none"), "None");
358  $radio_prop2->addOption($op1);
359  $op4 = new ilRadioOption($lng->txt("cont_use_same_resource_as_above"), "Standard");
360  $radio_prop2->addOption($op4);
361  $op2 = new ilRadioOption($lng->txt("cont_file"), "File");
362  $up = new ilFileInputGUI("", "full_file");
363  $up->setSuffixes(ilObjMediaObject::getRestrictedFileTypes());
364  $up->setInfo("");
365  $op2->addSubItem($up);
366  $radio_prop2->addOption($op2);
367  $op3 = new ilRadioOption($lng->txt("url"), "Reference");
368  $ref = new ilTextInputGUI("", "full_reference");
369  $ref->setInfo($lng->txt("cont_ref_helptext"));
370  $op3->addSubItem($ref);
371  $radio_prop2->addOption($op3);
372  $radio_prop2->setValue("None");
373  $this->form_gui->addItem($radio_prop2);
374 
375  // fullscreen format
376  if ($a_mode == "edit")
377  {
378  if ($this->object->hasFullscreenItem())
379  {
380  $format = new ilNonEditableValueGUI($lng->txt("cont_format"), "full_format");
381  $format->setValue($full_item->getFormat());
382  $this->form_gui->addItem($format);
383  }
384  }
385 
386  // fullscreen size
387  $radio_size = new ilRadioGroupInputGUI($lng->txt("size"), "full_size");
388  if ($a_mode == "edit")
389  {
390  $add_str = "";
391  if ($this->object->hasFullscreenItem() && ($orig_size = $full_item->getOriginalSize()))
392  {
393  $add_str = " (".$orig_size["width"]." x ".$orig_size["height"].")";
394  }
395  $op1 = new ilRadioOption($lng->txt("cont_resource_size").$add_str, "original");
396  $op2 = new ilRadioOption($lng->txt("cont_custom_size"), "selected");
397  }
398  else
399  {
400  $op1 = new ilRadioOption($lng->txt("cont_orig_size"), "original");
401  $op2 = new ilRadioOption($lng->txt("cont_adjust_size"), "selected");
402  }
403  $radio_size->addOption($op1);
404 
405  // width/height
406  $width_height = new ilWidthHeightInputGUI($lng->txt("cont_width").
407  " / ".$lng->txt("cont_height"), "full_width_height");
408  $width_height->setConstrainProportions(true);
409  $op2->addSubItem($width_height);
410 
411  // resize image
412  if ($a_mode == "edit")
413  {
414  $full_item = $this->object->getMediaItem("Fullscreen");
415  if ($this->object->hasFullscreenItem() &&
416  is_int(strpos($full_item->getFormat(), "image")) &&
417  $full_item->getLocationType() == "LocalFile")
418  {
419  $resize = new ilCheckboxInputGUI($lng->txt("cont_resize_img"),
420  "full_resize");
421  $op2->addSubItem($resize);
422  }
423  }
424 
425  $radio_size->setValue("original");
426  $radio_size->addOption($op2);
427  $this->form_gui->addItem($radio_size);
428 
429  // fullscreen caption
430  $caption = new ilTextAreaInputGUI($lng->txt("cont_caption"), "full_caption");
431  $caption->setCols(30);
432  $caption->setRows(2);
433  $this->form_gui->addItem($caption);
434 
435  /*$caption = new ilTextInputGUI($lng->txt("cont_caption"), "full_caption");
436  $caption->setSize(40);
437  $caption->setMaxLength(200);
438  $this->form_gui->addItem($caption);*/
439 
440  // text representation (alt text)
441  if ($a_mode == "edit" && $this->object->hasFullscreenItem() && is_int(strpos($std_item->getFormat(), "image")))
442  {
443  $ta = new ilTextAreaInputGUI($lng->txt("text_repr"), "full_text_representation");
444  $ta->setCols(30);
445  $ta->setRows(2);
446  $ta->setInfo($lng->txt("text_repr_info"));
447  $this->form_gui->addItem($ta);
448  }
449 
450 
451  // fullscreen parameters
452  if ($a_mode == "edit" && $this->object->hasFullscreenItem() &&
453  !in_array($full_item->getFormat(), ilObjMediaObject::_getSimpleMimeTypes()))
454  {
455  if (ilObjMediaObject::_useAutoStartParameterOnly($full_item->getLocation(),
456  $full_item->getFormat()))
457  {
458  $auto = new ilCheckboxInputGUI($lng->txt("cont_autostart"), "full_autostart");
459  $this->form_gui->addItem($auto);
460  }
461  else
462  {
463  $par = new ilTextAreaInputGUI($lng->txt("cont_parameter"), "full_parameters");
464  $par->setRows(5);
465  $par->setCols(50);
466  $this->form_gui->addItem($par);
467  }
468  }
469 
470  $this->form_gui->setTitle($lng->txt("cont_insert_mob"));
471  if ($a_mode == "edit")
472  {
473  $this->form_gui->addCommandButton("saveProperties", $lng->txt("save"));
474  }
475  else
476  {
477  $this->form_gui->addCommandButton("save", $lng->txt("save"));
478  $this->form_gui->addCommandButton("cancel", $lng->txt("cancel"));
479  }
480  $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
481 
482  }
483 
488  public function getValues()
489  {
490  $values = array();
491 
492  $values["standard_title"] = $this->object->getTitle();
493 
494  $std_item = $this->object->getMediaItem("Standard");
495  if ($std_item->getLocationType() == "LocalFile")
496  {
497  $values["standard_type"] = "File";
498  $values["standard_file"] = $std_item->getLocation();
499  }
500  else
501  {
502  $values["standard_type"] = "Reference";
503  $values["standard_reference"] = $std_item->getLocation();
504  }
505  $values["standard_format"] = $std_item->getFormat();
506  $values["standard_width_height"]["width"] = $std_item->getWidth();
507  $values["standard_width_height"]["height"] = $std_item->getHeight();
508  $values["standard_width_height"]["constr_prop"] = true;
509 
510  $values["standard_size"] = "selected";
511 
512  if ($orig_size = $std_item->getOriginalSize())
513  {
514  if ($orig_size["width"] == $std_item->getWidth() &&
515  $orig_size["height"] == $std_item->getHeight())
516  {
517  $values["standard_size"] = "original";
518  }
519  }
520  $values["standard_caption"] = $std_item->getCaption();
521  $values["text_representation"] = $std_item->getTextRepresentation();
522  if (ilObjMediaObject::_useAutoStartParameterOnly($std_item->getLocation(),
523  $std_item->getFormat()))
524  {
525  $par = $std_item->getParameters();
526  if ($par["autostart"])
527  {
528  $values["standard_autostart"] = true;
529  }
530  }
531  else
532  {
533  $values["standard_parameters"] = $std_item->getParameterString();
534  }
535 
536  $values["full_type"] = "None";
537  $values["full_size"] = "original";
538  if ($this->object->hasFullScreenItem())
539  {
540  $full_item = $this->object->getMediaItem("Fullscreen");
541  if ($full_item->getLocationType() == "LocalFile")
542  {
543  $values["full_type"] = "File";
544  $values["full_file"] = $full_item->getLocation();
545  }
546  else
547  {
548  $values["full_type"] = "Reference";
549  $values["full_reference"] = $full_item->getLocation();
550  }
551  $values["full_format"] = $full_item->getFormat();
552  $values["full_width_height"]["width"] = $full_item->getWidth();
553  $values["full_width_height"]["height"] = $full_item->getHeight();
554  $values["full_width_height"]["constr_prop"] = true;
555 
556  $values["full_size"] = "selected";
557 
558  if ($orig_size = $full_item->getOriginalSize())
559  {
560  if ($orig_size["width"] == $full_item->getWidth() &&
561  $orig_size["height"] == $full_item->getHeight())
562  {
563  $values["full_size"] = "original";
564  }
565  }
566  $values["full_caption"] = $full_item->getCaption();
567  if (ilObjMediaObject::_useAutoStartParameterOnly($full_item->getLocation(),
568  $full_item->getFormat()))
569  {
570  $par = $full_item->getParameters();
571  if ($par["autostart"])
572  {
573  $values["full_autostart"] = true;
574  }
575  }
576  else
577  {
578  $values["full_parameters"] = $full_item->getParameterString();
579  }
580  $values["full_text_representation"] = $full_item->getTextRepresentation();
581  }
582 
583  $this->form_gui->setValuesByArray($values);
584  }
585 
589  function saveObject()
590  {
591  global $tpl, $lng;
592 
593  $this->initForm();
594  if ($this->form_gui->checkInput())
595  {
596  $this->object = new ilObjMediaObject();
598  ilUtil::sendSuccess($lng->txt("saved_media_object"), true);
599  return $this->object;
600  }
601  else
602  {
603  $this->form_gui->setValuesByPost();
604  $tpl->setContent($this->form_gui->getHTML());
605  return false;
606  }
607  }
608 
615  function checkFormInput()
616  {
617  if (!$this->form_gui->checkInput())
618  {
619  $this->form_gui->setValuesByPost();
620  return false;
621  }
622  return true;
623  }
624 
625 
629  static function setObjectPerCreationForm($a_mob)
630  {
631  // determinte title and format
632  if (trim($_POST["standard_title"]) != "")
633  {
634  $title = trim($_POST["standard_title"]);
635  }
636  else
637  {
638  if ($_POST["standard_type"] == "File")
639  {
640  $title = $_FILES['standard_file']['name'];
641  }
642  else
643  {
644  $title = ilUtil::stripSlashes($_POST["standard_reference"]);
645  }
646  }
647 
648  $a_mob->setTitle($title);
649  $a_mob->setDescription("");
650  $a_mob->create();
651 
652  // determine and create mob directory, move uploaded file to directory
653  //$mob_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob->getId();
654  $a_mob->createDirectory();
655  $mob_dir = ilObjMediaObject::_getDirectory($a_mob->getId());
656 
657  $media_item =& new ilMediaItem();
658  $a_mob->addMediaItem($media_item);
659  $media_item->setPurpose("Standard");
660 
661  if ($_POST["standard_type"] == "File")
662  {
663  $file_name = ilObjMediaObject::fixFilename($_FILES['standard_file']['name']);
664  $file = $mob_dir."/".$file_name;
665  ilUtil::moveUploadedFile($_FILES['standard_file']['tmp_name'],
666  $file_name, $file);
667 
668  // get mime type
670  $location = $file_name;
671 
672  // resize standard images
673  if ($_POST["standard_size"] != "original" &&
674  is_int(strpos($format, "image")))
675  {
676  $location = ilObjMediaObject::_resizeImage($file, (int) $_POST["standard_width_height"]["width"],
677  (int) $_POST["standard_width_height"]["height"], (boolean) $_POST["standard_width_height"]["contr_prop"]);
678  }
679 
680  // set real meta and object data
681  $media_item->setFormat($format);
682  $media_item->setLocation($location);
683  $media_item->setLocationType("LocalFile");
684  }
685  else // standard type: reference
686  {
687  $format = ilObjMediaObject::getMimeType(ilUtil::stripSlashes($_POST["standard_reference"]));
688  $media_item->setFormat($format);
689  $media_item->setLocation(ilUtil::secureLink(ilUtil::stripSlashes($_POST["standard_reference"])));
690  $media_item->setLocationType("Reference");
691  }
692  $a_mob->setDescription($format);
693 
694  // determine width and height of known image types
695  $wh = ilObjMediaObject::_determineWidthHeight(500, 400, $format,
696  $_POST["standard_type"], $mob_dir."/".$location, $media_item->getLocation(),
697  $_POST["standard_width_height"]["constr_prop"], ($_POST["standard_size"] == "original"),
698  $_POST["standard_width_height"]["width"], $_POST["standard_width_height"]["height"]);
699  $media_item->setWidth($wh["width"]);
700  $media_item->setHeight($wh["height"]);
701  if ($wh["info"] != "")
702  {
703  ilUtil::sendInfo($wh["info"], true);
704  }
705 
706  if ($_POST["standard_caption"] != "")
707  {
708  $media_item->setCaption(ilUtil::stripSlashes($_POST["standard_caption"]));
709  }
710 
711 
712  $media_item->setHAlign("Left");
713 
714  // fullscreen view
715  if ($_POST["full_type"] != "None")
716  {
717  $media_item2 = new ilMediaItem();
718  $a_mob->addMediaItem($media_item2);
719  $media_item2->setPurpose("Fullscreen");
720 
721  // move file / set format and location
722  if ($_POST["full_type"] == "File")
723  {
724  $format = $location = "";
725  if ($_FILES['full_file']['name'] != "")
726  {
727  $full_file_name = ilObjMediaObject::fixFilename($_FILES['full_file']['name']);
728  $file = $mob_dir."/".$full_file_name;
729  ilUtil::moveUploadedFile($_FILES['full_file']['tmp_name'],
730  $full_file_name, $file);
732  $location = $full_file_name;
733  }
734  }
735  else if ($_POST["full_type"] == "Standard" && $_POST["standard_type"] == "File")
736  {
737  $location = $file_name;
738  }
739 
740  // resize file
741  if ($_POST["full_type"] == "File" ||
742  ($_POST["full_type"] == "Standard" && $_POST["standard_type"] == "File"))
743  {
744  if (($_POST["full_size"] != "original" &&
745  is_int(strpos($format, "image")))
746  )
747  {
748  $location = ilObjMediaObject::_resizeImage($file, (int) $_POST["full_width_height"]["width"],
749  (int) $_POST["full_width_height"]["height"], (boolean) $_POST["full_width_height"]["constr_prop"]);
750  }
751 
752  $media_item2->setFormat($format);
753  $media_item2->setLocation($location);
754  $media_item2->setLocationType("LocalFile");
755  $type = "File";
756  }
757 
758  if ($_POST["full_type"] == "Reference")
759  {
760  $format = $location = "";
761  if ($_POST["full_reference"] != "")
762  {
763  $format = ilObjMediaObject::getMimeType($_POST["full_reference"]);
764  $location = ilUtil::stripSlashes($_POST["full_reference"]);
765  }
766  }
767 
768  if ($_POST["full_type"] == "Reference" ||
769  ($_POST["full_type"] == "Standard" && $_POST["standard_type"] == "Reference"))
770  {
771  $media_item2->setFormat($format);
772  $media_item2->setLocation($location);
773  $media_item2->setLocationType("Reference");
774  $type = "Reference";
775  }
776 
777  // determine width and height of known image types
778  $wh = ilObjMediaObject::_determineWidthHeight(500, 400, $format,
779  $type, $mob_dir."/".$location, $media_item2->getLocation(),
780  $_POST["full_width_height"]["constr_prop"], ($_POST["full_size"] == "original"),
781  $_POST["full_width_height"]["width"], $_POST["full_width_height"]["height"]);
782 
783  $media_item2->setWidth($wh["width"]);
784  $media_item2->setHeight($wh["height"]);
785 
786  if ($_POST["full_caption"] != "")
787  {
788  $media_item2->setCaption(ilUtil::stripSlashes($_POST["full_caption"]));
789  }
790 
791  }
792 
793  ilUtil::renameExecutables($mob_dir);
794  $a_mob->update();
795  }
796 
797 
801  function cancelObject()
802  {
803  $this->ctrl->returnToParent($this);
804  }
805 
809  function editObject()
810  {
811  global $tpl;
812 
813  $this->setPropertiesSubTabs("general");
814 
815  $this->initForm("edit");
816  $this->getValues();
817  $tpl->setContent($this->form_gui->getHTML());
818  }
819 
820 
825  {
826  // directory
827  $mob_dir = ilObjMediaObject::_getDirectory($this->object->getId());
828 
829  // standard item
830  $std_item =& $this->object->getMediaItem("Standard");
831  if ($std_item->getLocationType() == "LocalFile" &&
832  is_int(strpos($std_item->getFormat(), "image"))
833  )
834  {
835  $file = $mob_dir."/".$std_item->getLocation();
836  $location = ilObjMediaObject::_resizeImage($file, $std_item->getWidth(),
837  $std_item->getHeight());
838  $std_item->setLocation($location);
839  $std_item->update();
840  }
841 
842  // fullscreen item
843  if($this->object->hasFullScreenItem())
844  {
845  $full_item =& $this->object->getMediaItem("Fullscreen");
846  if ($full_item->getLocationType() == "LocalFile" &&
847  is_int(strpos($full_item->getFormat(), "image"))
848  )
849  {
850  $file = $mob_dir."/".$full_item->getLocation();
851  $location = ilObjMediaObject::_resizeImage($file, $full_item->getWidth(),
852  $full_item->getHeight());
853  $full_item->setLocation($location);
854  $full_item->update();
855  }
856  }
857 
858  $this->ctrl->redirect($this, "edit");
859  }
860 
861 
866  {
867  $std_item = $this->object->getMediaItem("Standard");
868  $mob_dir = ilObjMediaObject::_getDirectory($this->object->getId());
869 
870  if ($std_item->getLocationType() == "LocalFile")
871  {
872  $file = $mob_dir."/".$std_item->getLocation();
873  $size = getimagesize($file);
874  $std_item->setWidth($size[0]);
875  $std_item->setHeight($size[1]);
876  $this->object->update();
877  }
878  $this->ctrl->redirect($this, "edit");
879  }
880 
881 
886  {
887  $full_item =& $this->object->getMediaItem("Fullscreen");
888  $mob_dir = ilObjMediaObject::_getDirectory($this->object->getId());
889 
890  if ($full_item->getLocationType() == "LocalFile")
891  {
892  $file = $mob_dir."/".$full_item->getLocation();
893  $size = getimagesize($file);
894  $full_item->setWidth($size[0]);
895  $full_item->setHeight($size[1]);
896  $this->object->update();
897  }
898  $this->ctrl->redirect($this, "edit");
899  }
900 
905  {
906  global $lng, $tpl;
907 
908  $this->initForm("edit");
909  if ($this->form_gui->checkInput())
910  {
911  $title = trim($_POST["standard_title"]);
912  $this->object->setTitle($title);
913 
914  $std_item = $this->object->getMediaItem("Standard");
915  $location = $std_item->getLocation();
916  $format = $std_item->getFormat();
917  if ($_POST["standard_type"] == "Reference")
918  {
919  $format = ilObjMediaObject::getMimeType(ilUtil::stripSlashes($_POST["standard_reference"]));
920  $std_item->setFormat($format);
921  $std_item->setLocation(ilUtil::secureLink(ilUtil::stripSlashes($_POST["standard_reference"])));
922  $std_item->setLocationType("Reference");
923  }
924  $mob_dir = ilObjMediaObject::_getDirectory($this->object->getId());
925  if ($_POST["standard_type"] == "File")
926  {
927  $resize = false;
928  if ($_FILES['standard_file']['name'] != "")
929  {
930  $file_name = ilObjMediaObject::fixFilename($_FILES['standard_file']['name']);
931  $file = $mob_dir."/".$file_name;
932  ilUtil::moveUploadedFile($_FILES['standard_file']['tmp_name'],
933  $file_name, $file);
934 
935  // get mime type
937  $location = $file_name;
938 
939  $resize = true;
940  }
941  else if ($_POST["standard_resize"])
942  {
943  $file = $mob_dir."/".$location;
944  $resize = true;
945  }
946 
947  // resize
948  if ($resize)
949  {
950  if ($_POST["standard_size"] != "original" &&
951  is_int(strpos($format, "image")))
952  {
953  $location = ilObjMediaObject::_resizeImage($file, (int) $_POST["standard_width_height"]["width"],
954  (int) $_POST["standard_width_height"]["height"], (boolean) $_POST["standard_width_height"]["contr_prop"]);
955  }
956  $std_item->setFormat($format);
957  $std_item->setLocation($location);
958  }
959 
960  $std_item->setLocationType("LocalFile");
961  }
962  $this->object->setDescription($format);
963 
964  // determine width and height of known image types
965  $wh = ilObjMediaObject::_determineWidthHeight(500, 400, $format,
966  $_POST["standard_type"], $mob_dir."/".$location, $std_item->getLocation(),
967  $_POST["standard_width_height"]["constr_prop"], ($_POST["standard_size"] == "original"),
968  $_POST["standard_width_height"]["width"], $_POST["standard_width_height"]["height"]);
969  if ($wh["info"] != "")
970  {
971  ilUtil::sendInfo($wh["info"], true);
972  }
973 
974  $std_item->setWidth($wh["width"]);
975  $std_item->setHeight($wh["height"]);
976 
977  // set caption
978  $std_item->setCaption(ilUtil::stripSlashes($_POST["standard_caption"]));
979 
980  // text representation
981  $std_item->setTextRepresentation(ilUtil::stripSlashes($_POST["text_representation"]));
982 
983  // set parameters
984  if (!in_array($std_item->getFormat(), ilObjMediaObject::_getSimpleMimeTypes()))
985  {
986  if (ilObjMediaObject::_useAutoStartParameterOnly($std_item->getLocation(),
987  $std_item->getFormat()))
988  {
989  if ($_POST["standard_autostart"]) // save only autostart flag
990  {
991  $std_item->setParameters('autostart="true"');
992  }
993  else
994  {
995  $std_item->setParameters("");
996  }
997  }
998  else
999  {
1000  $std_item->setParameters(ilUtil::stripSlashes(utf8_decode($_POST["standard_parameters"])));
1001  }
1002  }
1003 
1004  // "None" selected
1005  if ($_POST["full_type"] == "None")
1006  {
1007  if ($this->object->hasFullscreenItem()) // delete existing
1008  {
1009  $this->object->removeMediaItem("Fullscreen");
1010  }
1011  }
1012  else // Not "None" -> we need one
1013  {
1014  if ($this->object->hasFullscreenItem()) // take existing one
1015  {
1016  $full_item = $this->object->getMediaItem("Fullscreen");
1017  }
1018  else // create one
1019  {
1020  $full_item = new ilMediaItem();
1021  $this->object->addMediaItem($full_item);
1022  $full_item->setPurpose("Fullscreen");
1023  }
1024  $location = $full_item->getLocation();
1025  $format = $full_item->getFormat();
1026  if ($_POST["full_type"] == "Reference")
1027  {
1028  $format = ilObjMediaObject::getMimeType(ilUtil::stripSlashes($_POST["full_reference"]));
1029  $full_item->setFormat($format);
1030  $full_item->setLocationType("Reference");
1031  $location = ilUtil::stripSlashes($_POST["full_reference"]);
1032  $type = "Reference";
1033  }
1034  $mob_dir = ilObjMediaObject::_getDirectory($this->object->getId());
1035  if ($_POST["full_type"] == "File")
1036  {
1037  $resize = false;
1038  if ($_FILES['full_file']['name'] != "")
1039  {
1040  $full_file_name = ilObjMediaObject::fixFilename($_FILES['full_file']['name']);
1041  $file = $mob_dir."/".$full_file_name;
1042  ilUtil::moveUploadedFile($_FILES['full_file']['tmp_name'],
1043  $full_file_name, $file);
1044 
1046  $location = $full_file_name;
1047 
1048  $resize = true;
1049  }
1050  else if ($_POST["full_resize"])
1051  {
1052  $file = $mob_dir."/".$location;
1053  $resize = true;
1054  }
1055 
1056  // resize
1057  if ($resize)
1058  {
1059  if ($_POST["full_size"] != "original" &&
1060  is_int(strpos($format, "image")))
1061  {
1062  $location = ilObjMediaObject::_resizeImage($file, (int) $_POST["full_width_height"]["width"],
1063  (int) $_POST["full_width_height"]["height"], (boolean) $_POST["full_width_height"]["contr_prop"]);
1064  }
1065  $full_item->setFormat($format);
1066  $full_item->setLocation($location);
1067  }
1068 
1069  $full_item->setLocationType("LocalFile");
1070  $type = "File";
1071  }
1072  if ($_POST["full_type"] == "Standard")
1073  {
1074  $format = $std_item->getFormat();
1075  $location = $std_item->getLocation();
1076  $full_item->setLocationType($std_item->getLocationType());
1077  $full_item->setFormat($format);
1078  $full_item->setLocation($location);
1079  $type = $std_item->getLocationType();
1080  if ($type == "LocalFile")
1081  {
1082  $type = "File";
1083  }
1084  // resize image
1085 //echo "-".$_POST["full_size"]."-".is_int(strpos($format, "image"))."-".$full_item->getLocationType()."-";
1086  if ($_POST["full_size"] != "original" &&
1087  is_int(strpos($format, "image")) &&
1088  $full_item->getLocationType() == "LocalFile")
1089  {
1090  $file = $mob_dir."/".$location;
1091  $location = ilObjMediaObject::_resizeImage($file, (int) $_POST["full_width_height"]["width"],
1092  (int) $_POST["full_width_height"]["height"], (boolean) $_POST["full_width_height"]["contr_prop"]);
1093  }
1094  }
1095 
1096  // determine width and height of known image types
1097  $wh = ilObjMediaObject::_determineWidthHeight(500, 400, $format,
1098  $type, $mob_dir."/".$location, $full_item->getLocation(),
1099  $_POST["full_width_height"]["constr_prop"], ($_POST["full_size"] == "original"),
1100  $_POST["full_width_height"]["width"], $_POST["full_width_height"]["height"]);
1101  if ($wh["info"] != "")
1102  {
1103  ilUtil::sendInfo($wh["info"], true);
1104  }
1105 
1106  $full_item->setWidth($wh["width"]);
1107  $full_item->setHeight($wh["height"]);
1108  $full_item->setLocation($location);
1109 
1110  $full_item->setCaption(ilUtil::stripSlashes($_POST["full_caption"]));
1111 
1112  // text representation
1113  $full_item->setTextRepresentation(ilUtil::stripSlashes($_POST["full_text_representation"]));
1114 
1115 
1116  // set parameters
1117  if (!in_array($std_item->getFormat(), ilObjMediaObject::_getSimpleMimeTypes()))
1118  {
1119  if (ilObjMediaObject::_useAutoStartParameterOnly($std_item->getLocation(),
1120  $std_item->getFormat()))
1121  {
1122  if ($_POST["full_autostart"]) // save only autostart flag
1123  {
1124  $full_item->setParameters('autostart="true"');
1125  }
1126  else
1127  {
1128  $full_item->setParameters("");
1129  }
1130  }
1131  else
1132  {
1133  $full_item->setParameters(ilUtil::stripSlashes(utf8_decode($_POST["full_parameters"])));
1134  }
1135  }
1136  }
1137 
1139 
1140  $this->object->update();
1141  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
1142  $this->ctrl->redirect($this, "edit");
1143  }
1144  else
1145  {
1146  $this->form_gui->setValuesByPost();
1147  $tpl->setContent($this->form_gui->getHTML());
1148  }
1149  }
1150 
1151 
1155  function editFilesObject()
1156  {
1157  // standard item
1158  $std_item =& $this->object->getMediaItem("Standard");
1159  if($this->object->hasFullscreenItem())
1160  {
1161  $full_item =& $this->object->getMediaItem("Fullscreen");
1162  }
1163 
1164  // create table
1165  require_once("./Services/Table/classes/class.ilTableGUI.php");
1166  $tbl = new ilTableGUI();
1167 
1168  // determine directory
1169  $cur_subdir = $_GET["cdir"];
1170  if($_GET["newdir"] == "..")
1171  {
1172  $cur_subdir = substr($cur_subdir, 0, strrpos($cur_subdir, "/"));
1173  }
1174  else
1175  {
1176  if (!empty($_GET["newdir"]))
1177  {
1178  if (!empty($cur_subdir))
1179  {
1180  $cur_subdir = $cur_subdir."/".$_GET["newdir"];
1181  }
1182  else
1183  {
1184  $cur_subdir = $_GET["newdir"];
1185  }
1186  }
1187  }
1188 
1189  $cur_subdir = str_replace(".", "", $cur_subdir);
1190  $mob_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$this->object->getId();
1191  $cur_dir = (!empty($cur_subdir))
1192  ? $mob_dir."/".$cur_subdir
1193  : $mob_dir;
1194 
1195  // load files templates
1196  $this->tpl->addBlockfile("ADM_CONTENT", "adm_content", "tpl.mob_files.html", "Services/MediaObjects");
1197 
1198  $this->ctrl->setParameter($this, "cdir", urlencode($cur_subdir));
1199  $this->tpl->setVariable("FORMACTION1", $this->ctrl->getFormAction($this));
1200 //echo "--".$this->getTargetScript().
1201  //"&hier_id=".$_GET["hier_id"]."&cdir=".$cur_subdir."&cmd=post"."--<br>";
1202  $this->tpl->setVariable("TXT_NEW_DIRECTORY", $this->lng->txt("cont_new_dir"));
1203  $this->tpl->setVariable("TXT_NEW_FILE", $this->lng->txt("cont_new_file"));
1204  $this->tpl->setVariable("CMD_NEW_DIR", "createDirectory");
1205  $this->tpl->setVariable("CMD_NEW_FILE", "uploadFile");
1206  $this->tpl->setVariable("BTN_NEW_DIR", $this->lng->txt("create"));
1207  $this->tpl->setVariable("BTN_NEW_FILE", $this->lng->txt("upload"));
1208 
1209  //
1210  $this->tpl->addBlockfile("FILE_TABLE", "files", "tpl.table.html");
1211 
1212  // load template for table content data
1213  $this->tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.mob_file_row.html", "Services/MediaObjects");
1214 
1215  $num = 0;
1216 
1217  $obj_str = ($this->call_by_reference) ? "" : "&obj_id=".$this->obj_id;
1218  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
1219 
1220  $tbl->setTitle($this->lng->txt("cont_files")." ".$cur_subdir);
1221  //$tbl->setHelp("tbl_help.php","icon_help.gif",$this->lng->txt("help"));
1222 
1223  $tbl->setHeaderNames(array("", "", $this->lng->txt("cont_dir_file"),
1224  $this->lng->txt("cont_size"), $this->lng->txt("cont_purpose")));
1225 
1226  $cols = array("", "", "dir_file", "size", "purpose");
1227  $header_params = array("ref_id" => $_GET["ref_id"], "obj_id" => $_GET["obj_id"],
1228  "cmd" => "editFiles", "hier_id" => $_GET["hier_id"], "item_id" => $_GET["item_id"]);
1229  $tbl->setHeaderVars($cols, $header_params);
1230  $tbl->setColumnWidth(array("1%", "1%", "33%", "33%", "32%"));
1231 
1232  // control
1233  $tbl->setOrderColumn($_GET["sort_by"]);
1234  $tbl->setOrderDirection($_GET["sort_order"]);
1235  $tbl->setLimit($_GET["limit"]);
1236  $tbl->setOffset($_GET["offset"]);
1237  $tbl->setMaxCount($this->maxcount); // ???
1238  //$tbl->setMaxCount(30); // ???
1239 
1240  $this->tpl->setVariable("COLUMN_COUNTS", 5);
1241 
1242  // delete button
1243  $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.svg"));
1244  $this->tpl->setCurrentBlock("tbl_action_btn");
1245  $this->tpl->setVariable("BTN_NAME", "deleteFile");
1246  $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("delete"));
1247  $this->tpl->parseCurrentBlock();
1248 
1249  $this->tpl->setCurrentBlock("tbl_action_btn");
1250  $this->tpl->setVariable("BTN_NAME", "assignStandard");
1251  $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("cont_assign_std"));
1252  $this->tpl->parseCurrentBlock();
1253 
1254  $this->tpl->setCurrentBlock("tbl_action_btn");
1255  $this->tpl->setVariable("BTN_NAME", "assignFullscreen");
1256  $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("cont_assign_full"));
1257  $this->tpl->parseCurrentBlock();
1258 
1259  // footer
1260  $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
1261  //$tbl->disable("footer");
1262 
1263  $entries = ilUtil::getDir($cur_dir);
1264 
1265  //$objs = ilUtil::sortArray($objs, $_GET["sort_by"], $_GET["sort_order"]);
1266  $tbl->setMaxCount(count($entries));
1267  $entries = array_slice($entries, $_GET["offset"], $_GET["limit"]);
1268 
1269  $tbl->render();
1270  if(count($entries) > 0)
1271  {
1272  $i=0;
1273  foreach($entries as $entry)
1274  {
1275  if(($entry["entry"] == ".") || ($entry["entry"] == ".." && empty($cur_subdir)))
1276  {
1277  continue;
1278  }
1279 
1280  //$this->tpl->setVariable("ICON", $obj["title"]);
1281  if($entry["type"] == "dir")
1282  {
1283  $this->tpl->setCurrentBlock("FileLink");
1284  $this->ctrl->setParameter($this, "cdir", $cur_subdir);
1285  $this->ctrl->setParameter($this, "newdir", rawurlencode($entry["entry"]));
1286  $this->tpl->setVariable("LINK_FILENAME", $this->ctrl->getLinkTarget($this, "editFiles"));
1287  $this->tpl->setVariable("TXT_FILENAME", $entry["entry"]);
1288  $this->tpl->parseCurrentBlock();
1289 
1290  $this->tpl->setVariable("ICON", "<img src=\"".
1291  ilUtil::getImagePath("icon_cat.svg")."\">");
1292  }
1293  else
1294  {
1295  $this->tpl->setCurrentBlock("File");
1296  $this->tpl->setVariable("TXT_FILENAME2", $entry["entry"]);
1297  $this->tpl->parseCurrentBlock();
1298  }
1299 
1300  $this->tpl->setCurrentBlock("tbl_content");
1301  $css_row = ilUtil::switchColor($i++, "tblrow1", "tblrow2");
1302  $this->tpl->setVariable("CSS_ROW", $css_row);
1303 
1304  $this->tpl->setVariable("TXT_SIZE", $entry["size"]);
1305  $this->tpl->setVariable("CHECKBOX_ID", $entry["entry"]);
1306  $compare = (!empty($cur_subdir))
1307  ? $cur_subdir."/".$entry["entry"]
1308  : $entry["entry"];
1309  $purpose = array();
1310  if ($std_item->getLocation() == $compare)
1311  {
1312  $purpose[] = $this->lng->txt("cont_std_view");
1313  }
1314  if($this->object->hasFullscreenItem())
1315  {
1316  if ($full_item->getLocation() == $compare)
1317  {
1318  $purpose[] = $this->lng->txt("cont_fullscreen");
1319  }
1320  }
1321  $this->tpl->setVariable("TXT_PURPOSE", implode($purpose, ", "));
1322 
1323  $this->tpl->parseCurrentBlock();
1324  }
1325  } //if is_array
1326  else
1327  {
1328  $this->tpl->setCurrentBlock("notfound");
1329  $this->tpl->setVariable("TXT_OBJECT_NOT_FOUND", $this->lng->txt("obj_not_found"));
1330  $this->tpl->setVariable("NUM_COLS", 4);
1331  $this->tpl->parseCurrentBlock();
1332  }
1333 
1334  $this->tpl->parseCurrentBlock();
1335  }
1336 
1337 
1342  {
1343 //echo "cdir:".$_GET["cdir"].":<br>";
1344  // determine directory
1345  $cur_subdir = str_replace(".", "", $_GET["cdir"]);
1346  $mob_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$this->object->getId();
1347  $cur_dir = (!empty($cur_subdir))
1348  ? $mob_dir."/".$cur_subdir
1349  : $mob_dir;
1350 
1351  $new_dir = str_replace(".", "", $_POST["new_dir"]);
1352  $new_dir = str_replace("/", "", $new_dir);
1353 
1354  if (!empty($new_dir))
1355  {
1356  ilUtil::makeDir($cur_dir."/".$new_dir);
1357  }
1358  $this->ctrl->saveParameter($this, "cdir");
1359  $this->ctrl->redirect($this, "editFiles");
1360  }
1361 
1365  function uploadFileObject()
1366  {
1367  // determine directory
1368  $cur_subdir = str_replace(".", "", $_GET["cdir"]);
1369  $mob_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$this->object->getId();
1370  $cur_dir = (!empty($cur_subdir))
1371  ? $mob_dir."/".$cur_subdir
1372  : $mob_dir;
1373  if (is_file($_FILES["new_file"]["tmp_name"]))
1374  {
1375  //move_uploaded_file($_FILES["new_file"]["tmp_name"],
1376  //$cur_dir."/".$_FILES["new_file"]["name"]);
1377  $file_name = ilObjMediaObject::fixFilename($_FILES["new_file"]["name"]);
1378  $file = $cur_dir."/".$file_name;
1379  ilUtil::moveUploadedFile($_FILES['new_file']['tmp_name'],
1380  $file_name, $file);
1381 
1382  }
1383  ilUtil::renameExecutables($mob_dir);
1384  $this->ctrl->saveParameter($this, "cdir");
1385  $this->ctrl->redirect($this, "editFiles");
1386  }
1387 
1392  {
1393  if (!isset($_POST["file"]))
1394  {
1395  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
1396  }
1397 
1398  if (count($_POST["file"]) > 1)
1399  {
1400  $this->ilias->raiseError($this->lng->txt("cont_select_max_one_item"),$this->ilias->error_obj->MESSAGE);
1401  }
1402 
1403  // determine directory
1404  $cur_subdir = str_replace(".", "", $_GET["cdir"]);
1405  $mob_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$this->object->getId();
1406  $cur_dir = (!empty($cur_subdir))
1407  ? $mob_dir."/".$cur_subdir
1408  : $mob_dir;
1409  $file = $cur_dir."/".$_POST["file"][0];
1410  $location = (!empty($cur_subdir))
1411  ? $cur_subdir."/".$_POST["file"][0]
1412  : $_POST["file"][0];
1413 
1414  if(!is_file($file))
1415  {
1416  $this->ilias->raiseError($this->lng->txt("cont_select_file"),$this->ilias->error_obj->MESSAGE);
1417  }
1418 
1419  $std_item =& $this->object->getMediaItem("Standard");
1420  $std_item->setLocationType("LocalFile");
1421  $std_item->setLocation($location);
1423  $std_item->setFormat($format);
1424  $this->object->update();
1425 // $this->ctrl->saveParameter($this, "cdir");
1426  $this->ctrl->redirectByClass("ilfilesystemgui", "listFiles");
1427  }
1428 
1429 
1434  {
1435  if (!isset($_POST["file"]))
1436  {
1437  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
1438  }
1439 
1440  if (count($_POST["file"]) > 1)
1441  {
1442  $this->ilias->raiseError($this->lng->txt("cont_select_max_one_item"),$this->ilias->error_obj->MESSAGE);
1443  }
1444 
1445  // determine directory
1446  $cur_subdir = str_replace(".", "", $_GET["cdir"]);
1447  $mob_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$this->object->getId();
1448  $cur_dir = (!empty($cur_subdir))
1449  ? $mob_dir."/".$cur_subdir
1450  : $mob_dir;
1451  $file = $cur_dir."/".$_POST["file"][0];
1452  $location = (!empty($cur_subdir))
1453  ? $cur_subdir."/".$_POST["file"][0]
1454  : $_POST["file"][0];
1455 
1456  if(!is_file($file))
1457  {
1458  $this->ilias->raiseError($this->lng->txt("cont_select_file"),$this->ilias->error_obj->MESSAGE);
1459  }
1460 
1461  if(!$this->object->hasFullScreenItem())
1462  { // create new fullscreen item
1463  $std_item =& $this->object->getMediaItem("Standard");
1464  $mob_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$this->object->getId();
1465  $file = $mob_dir."/".$location;
1466  $full_item =& new ilMediaItem();
1467  $full_item->setMobId($std_item->getMobId());
1468  $full_item->setLocation($location);
1469  $full_item->setLocationType("LocalFile");
1470  $full_item->setFormat(ilObjMediaObject::getMimeType($file));
1471  $full_item->setPurpose("Fullscreen");
1472  $this->object->addMediaItem($full_item);
1473  }
1474  else // alter existing fullscreen item
1475  {
1476  $full_item =& $this->object->getMediaItem("Fullscreen");
1477 
1478  $full_item->setLocationType("LocalFile");
1479  $full_item->setLocation($location);
1481  $full_item->setFormat($format);
1482  }
1483  $this->object->update();
1484 // $this->ctrl->saveParameter($this, "cdir");
1485  $this->ctrl->redirectByClass("ilfilesystemgui", "listFiles");
1486  }
1487 
1488 
1493  {
1494  $this->object->removeMediaItem("Fullscreen");
1495  $this->object->update();
1496 
1497  $this->ctrl->redirect($this, "edit");
1498  }
1499 
1500 
1505  {
1506  if (!$this->object->hasFullScreenItem())
1507  {
1508  $std_item =& $this->object->getMediaItem("Standard");
1509  $full_item =& new ilMediaItem();
1510  $full_item->setMobId($std_item->getMobId());
1511  $full_item->setLocation($std_item->getLocation());
1512  $full_item->setLocationType($std_item->getLocationType());
1513  $full_item->setFormat($std_item->getFormat());
1514  $full_item->setWidth($std_item->getWidth());
1515  $full_item->setHeight($std_item->getHeight());
1516  $full_item->setCaption($std_item->getCaption());
1517  $full_item->setTextRepresentation($std_item->getTextRepresentation());
1518  $full_item->setPurpose("Fullscreen");
1519  $this->object->addMediaItem($full_item);
1520 
1521  $this->object->update();
1522  }
1523 
1524  $this->ctrl->redirect($this, "edit");
1525  }
1526 
1527 
1531  function deleteFileObject()
1532  {
1533  if (!isset($_POST["file"]))
1534  {
1535  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
1536  }
1537 
1538  if (count($_POST["file"]) > 1)
1539  {
1540  $this->ilias->raiseError($this->lng->txt("cont_select_max_one_item"),$this->ilias->error_obj->MESSAGE);
1541  }
1542 
1543  if ($_POST["file"][0] == "..")
1544  {
1545  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
1546  }
1547 
1548  $cur_subdir = str_replace(".", "", $_GET["cdir"]);
1549  $mob_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$this->object->getId();
1550  $cur_dir = (!empty($cur_subdir))
1551  ? $mob_dir."/".$cur_subdir
1552  : $mob_dir;
1553  $file = $cur_dir."/".$_POST["file"][0];
1554  $location = (!empty($cur_subdir))
1555  ? $cur_subdir."/".$_POST["file"][0]
1556  : $_POST["file"][0];
1557 
1558  $full_item =& $this->object->getMediaItem("Fullscreen");
1559  $std_item =& $this->object->getMediaItem("Standard");
1560 
1561  if ($location == $std_item->getLocation())
1562  {
1563  $this->ilias->raiseError($this->lng->txt("cont_cant_del_std"),$this->ilias->error_obj->MESSAGE);
1564  }
1565 
1566  if($this->object->hasFullScreenItem())
1567  {
1568  if ($location == $full_item->getLocation())
1569  {
1570  $this->ilias->raiseError($this->lng->txt("cont_cant_del_full"),$this->ilias->error_obj->MESSAGE);
1571  }
1572  }
1573 
1574  if (@is_dir($file))
1575  {
1576  if (substr($std_item->getLocation(), 0 ,strlen($location)) == $location)
1577  {
1578  $this->ilias->raiseError($this->lng->txt("cont_std_is_in_dir"),$this->ilias->error_obj->MESSAGE);
1579  }
1580 
1581  if($this->object->hasFullScreenItem())
1582  {
1583  if (substr($full_item->getLocation(), 0 ,strlen($location)) == $location)
1584  {
1585  $this->ilias->raiseError($this->lng->txt("cont_full_is_in_dir"),$this->ilias->error_obj->MESSAGE);
1586  }
1587  }
1588  }
1589 
1590  if (@is_file($file))
1591  {
1592  unlink($file);
1593  }
1594 
1595  if (@is_dir($file))
1596  {
1598  }
1599 
1600  $this->ctrl->saveParameter($this, "cdir");
1601  $this->ctrl->redirect($this, "editFiles");
1602  }
1603 
1608  {
1609  $this->showUsagesObject(true);
1610  }
1611 
1612 
1616  function showUsagesObject($a_all = false)
1617  {
1618  global $tpl, $ilTabs, $ilTabs, $lng, $ilCtrl;
1619 
1620  $ilTabs->addSubTab("current_usages", $lng->txt("cont_current_usages"),
1621  $ilCtrl->getLinkTarget($this, "showUsages"));
1622 
1623  $ilTabs->addSubTab("all_usages", $lng->txt("cont_all_usages"),
1624  $ilCtrl->getLinkTarget($this, "showAllUsages"));
1625 
1626  if ($a_all)
1627  {
1628  $ilTabs->activateSubTab("all_usages");
1629  $cmd = "showAllUsages";
1630  }
1631  else
1632  {
1633  $ilTabs->activateSubTab("current_usages");
1634  $cmd = "showUsages";
1635  }
1636 
1637  include_once("./Services/MediaObjects/classes/class.ilMediaObjectUsagesTableGUI.php");
1638  $usages_table = new ilMediaObjectUsagesTableGUI($this, $cmd,
1639  $this->object, $a_all);
1640  $tpl->setContent($usages_table->getHTML());
1641  }
1642 
1646  function _getMediaInfoHTML(&$a_mob)
1647  {
1648  global $lng;
1649 
1650  $tpl =& new ilTemplate("tpl.media_info.html", true, true, "Services/MediaObjects");
1651  $types = array("Standard", "Fullscreen");
1652  foreach ($types as $type)
1653  {
1654  if($type == "Fullscreen" && !$a_mob->hasFullScreenItem())
1655  {
1656  continue;
1657  }
1658 
1659  $med = $a_mob->getMediaItem($type);
1660  if (!$med)
1661  {
1662  return "";
1663  }
1664 
1665  $tpl->setCurrentBlock("media_info");
1666  if ($type == "Standard")
1667  {
1668  $tpl->setVariable("TXT_PURPOSE", $lng->txt("cont_std_view"));
1669  }
1670  else
1671  {
1672  $tpl->setVariable("TXT_PURPOSE", $lng->txt("cont_fullscreen"));
1673  }
1674  $tpl->setVariable("TXT_TYPE", $lng->txt("cont_".strtolower($med->getLocationType())));
1675  $tpl->setVariable("VAL_LOCATION", $med->getLocation());
1676  if ($med->getLocationType() == "LocalFile")
1677  {
1678  $file = ilObjMediaObject::_getDirectory($med->getMobId())."/".$med->getLocation();
1679  if (is_file($file))
1680  {
1681  $size = filesize($file);
1682  }
1683  else
1684  {
1685  $size = 0;
1686  }
1687  $tpl->setVariable("VAL_FILE_SIZE", " ($size ".$lng->txt("bytes").")");
1688  }
1689  $tpl->setVariable("TXT_FORMAT", $lng->txt("cont_format"));
1690  $tpl->setVariable("VAL_FORMAT", $med->getFormat());
1691  if ($med->getWidth() != "" && $med->getHeight() != "")
1692  {
1693  $tpl->setCurrentBlock("size");
1694  $tpl->setVariable("TXT_SIZE", $lng->txt("size"));
1695  $tpl->setVariable("VAL_SIZE", $med->getWidth()."x".$med->getHeight());
1696  $tpl->parseCurrentBlock();
1697  }
1698 
1699  // original size
1700  if ($orig_size = $med->getOriginalSize())
1701  {
1702  if ($orig_size["width"] != $med->getWidth() ||
1703  $orig_size["height"] != $med->getHeight())
1704  {
1705  $tpl->setCurrentBlock("orig_size");
1706  $tpl->setVariable("TXT_ORIG_SIZE", $lng->txt("cont_orig_size"));
1707  $tpl->setVariable("ORIG_WIDTH", $orig_size["width"]);
1708  $tpl->setVariable("ORIG_HEIGHT", $orig_size["height"]);
1709  $tpl->parseCurrentBlock();
1710  }
1711  }
1712 
1713  // output caption
1714  if($med && strlen($med->getCaption()))
1715  {
1716  $tpl->setCurrentBlock('additional_info');
1717  $tpl->setVariable('ADD_INFO',$lng->txt('cont_caption').': '.$med->getCaption());
1718  $tpl->parseCurrentBlock();
1719  }
1720 
1721  // output keywords
1722  if ($type == "Standard")
1723  {
1724  include_once './Services/MetaData/classes/class.ilMDKeyword.php';
1725  if(count($kws = ilMDKeyword::lookupKeywords(0, $med->getMobId())))
1726  {
1727  $tpl->setCurrentBlock('additional_info');
1728  $tpl->setVariable('ADD_INFO',$lng->txt('keywords').': '.implode(', ',$kws));
1729  $tpl->parseCurrentBlock();
1730  }
1731  }
1732 
1733  $tpl->setCurrentBlock("media_info");
1734  $tpl->parseCurrentBlock();
1735  }
1736 
1737  return $tpl->get();
1738  }
1739 
1743  //function setAdminTabs()
1744  function setTabs()
1745  {
1746 //echo "setAdminTabs should not be called.";
1747 
1748  // catch feedback message
1749  $this->getTabs($this->tabs_gui);
1750 
1751  //$tabs_gui->setTargetScript($this->ctrl->getLinkTarget($this));
1752  $this->tpl->clearHeader();
1753  if (is_object($this->object) && strtolower(get_class($this->object)) == "ilobjmediaobject")
1754  {
1755  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_mob.svg"));
1756  $this->tpl->setTitle($this->object->getTitle());
1757  }
1758  else
1759  {
1760  //$title = $this->object->getTitle();
1761  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_mob.svg"));
1762  $this->tpl->setTitle($this->lng->txt("cont_create_mob"));
1763  }
1764  }
1765 
1766 
1770  function getTabs(&$tabs_gui)
1771  {
1772  global $ilTabs, $ilHelp;
1773 
1774  $ilHelp->setScreenIdComponent("mob");
1775 
1776  //$tabs_gui->setTargetScript($this->ctrl->getLinkTarget($this));
1777  if (is_object($this->object) && strtolower(get_class($this->object)) == "ilobjmediaobject"
1778  && $this->object->getId() > 0)
1779  {
1780  // object properties
1781  $ilTabs->addTarget("cont_mob_def_prop",
1782  $this->ctrl->getLinkTarget($this, "edit"), "edit",
1783  get_class($this));
1784 
1785  $st_item =& $this->object->getMediaItem("Standard");
1786 
1787  // video tools
1788  if (substr($st_item->getFormat(), 0, 6) == "video/" && DEVMODE)
1789  {
1790  $ilTabs->addTarget("mob_video_tools",
1791  $this->ctrl->getLinkTargetByClass("ilobjmediaobjectgui", "showVideoTool"),
1792  "showVideoTool", "ilobjmediaobjectgui");
1793  }
1794 
1795  // link areas
1796 
1797  if (is_object($st_item) && $this->getEnabledMapAreas())
1798  {
1799  $format = $st_item->getFormat();
1800  if (substr($format, 0, 5) == "image")
1801  {
1802  $ilTabs->addTarget("cont_def_map_areas",
1803  $this->ctrl->getLinkTargetByClass(
1804  array("ilobjmediaobjectgui", "ilimagemapeditorgui"), "editMapAreas"), "editMapAreas",
1805  "ilimagemapeditorgui");
1806  }
1807  }
1808 
1809  // object usages
1810  $ilTabs->addTarget("cont_mob_usages",
1811  $this->ctrl->getLinkTarget($this, "showUsages"), "showUsages",
1812  get_class($this));
1813 
1814  // object files
1815  $std_item = $this->object->getMediaItem("Standard");
1816  $full_item = $this->object->getMediaItem("Fullscreen");
1817  $mset = new ilSetting("mobs");
1818  if ($mset->get("file_manager_always") ||
1819  (!in_array($std_item->getFormat(), ilObjMediaObject::_getSimpleMimeTypes()) ||
1820  (is_object($full_item) && !in_array($full_item->getFormat(), ilObjMediaObject::_getSimpleMimeTypes())))
1821  )
1822  {
1823 // $ilTabs->addTarget("cont_files",
1824 // $this->ctrl->getLinkTarget($this, "editFiles"), "editFiles",
1825 // get_class($this));
1826 
1827  $ilTabs->addTarget("cont_files",
1828  $this->ctrl->getLinkTargetByClass(
1829  array("ilobjmediaobjectgui", "ilfilesystemgui"), "listFiles"), "",
1830  "ilfilesystemgui");
1831  }
1832 
1833  $ilTabs->addTarget("meta_data",
1834  $this->ctrl->getLinkTargetByClass(
1835  array("ilobjmediaobjectgui", "ilmdeditorgui"),'listSection'),
1836  "", "ilmdeditorgui");
1837 
1838  }
1839 
1840  // back to upper context
1841  if ($this->back_title != "")
1842  {
1843  $tabs_gui->setBackTarget($this->back_title,
1844  $this->ctrl->getParentReturn($this));
1845  }
1846  }
1847 
1855  {
1856  global $tpl;
1857 
1858  include_once("./Services/MediaObjects/classes/class.ilFFmpeg.php");
1859 
1860  /*$codecs = ilFFmpeg::getSupportedCodecsInfo();
1861  $codec_str = implode($codecs, "<br />");
1862  $tpl->setContent($codec_str);*/
1863 
1864  $formats = ilFFmpeg::getSupportedFormatsInfo();
1865  $formats_str = implode($formats, "<br />");
1866  $tpl->setContent($formats_str);
1867  }
1868 
1869 
1873  function includePresentationJS($a_tpl = null)
1874  {
1875  global $tpl;
1876 
1877  if ($a_tpl == null)
1878  {
1879  $a_tpl = $tpl;
1880  }
1881 
1882  include_once("./Services/jQuery/classes/class.iljQueryUtil.php");
1883  iljQueryUtil::initjQUery($a_tpl);
1884  include_once("./Services/jQuery/classes/class.iljQueryUtil.php");
1885  $a_tpl->addJavascript(iljQueryUtil::getLocalMaphilightPath());
1886  $a_tpl->addJavascript("./Services/COPage/js/ilCOPagePres.js");
1887 
1888  include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
1890  }
1891 
1897  function setPropertiesSubTabs($a_active)
1898  {
1899  global $ilTabs, $ilCtrl, $lng;
1900 
1901  $ilTabs->activateTab("cont_mob_def_prop");
1902 
1903  $ilTabs->addSubTab("general",
1904  $lng->txt("mob_general"),
1905  $ilCtrl->getLinkTarget($this, "edit"));
1906 
1907  if ($this->object->getMediaItem("Standard")->getFormat() == "video/webm" ||
1908  $this->object->getMediaItem("Standard")->getFormat() == "video/mp4")
1909  {
1910  $ilTabs->addSubTab("subtitles",
1911  $lng->txt("mob_subtitles"),
1912  $ilCtrl->getLinkTarget($this, "listSubtitleFiles"));
1913  }
1914 
1915  $ilTabs->activateSubTab($a_active);
1916  }
1917 
1925  {
1926  global $ilToolbar, $tpl, $ilCtrl, $lng, $ilUser;
1927 
1928  $this->setPropertiesSubTabs("subtitles");
1929 
1930  // upload file
1931  $ilToolbar->setFormAction($ilCtrl->getFormAction($this), true);
1932  include_once("./Services/Form/classes/class.ilFileInputGUI.php");
1933  $fi = new ilFileInputGUI($lng->txt("mob_subtitle_file")." (.srt)", "subtitle_file");
1934  $fi->setSuffixes(array("srt"));
1935  $ilToolbar->addInputItem($fi, true);
1936 
1937  // language
1938  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
1939  include_once("./Services/MetaData/classes/class.ilMDLanguageItem.php");
1941  $si = new ilSelectInputGUI($this->lng->txt("mob_language"), "language");
1942  $si->setOptions($options);
1943  $si->setValue($ilUser->getLanguage());
1944  $ilToolbar->addInputItem($si, true);
1945 
1946  $ilToolbar->addFormButton($lng->txt("upload"), "uploadSubtitleFile");
1947 
1948  include_once("./Services/MediaObjects/classes/class.ilMobSubtitleTableGUI.php");
1949  $tab = new ilMobSubtitleTableGUI($this, "listSubtitleFiles", $this->object);
1950 
1951  $tpl->setContent($tab->getHTML());
1952  }
1953 
1961  {
1962  global $lng, $ilCtrl;
1963 
1964  if ($this->object->uploadSrtFile($_FILES["subtitle_file"]["tmp_name"], ilUtil::stripSlashes($_POST["language"])))
1965  {
1966  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
1967  }
1968  $ilCtrl->redirect($this, "listSubtitleFiles");
1969  }
1970 
1975  {
1976  global $ilCtrl, $tpl, $lng;
1977 
1978  $lng->loadLanguageModule("meta");
1979 
1980  if (!is_array($_POST["srt"]) || count($_POST["srt"]) == 0)
1981  {
1982  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
1983  $ilCtrl->redirect($this, "listSubtitleFiles");
1984  }
1985  else
1986  {
1987  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
1988  $cgui = new ilConfirmationGUI();
1989  $cgui->setFormAction($ilCtrl->getFormAction($this));
1990  $cgui->setHeaderText($lng->txt("mob_really_delete_srt"));
1991  $cgui->setCancel($lng->txt("cancel"), "listSubtitleFiles");
1992  $cgui->setConfirm($lng->txt("delete"), "deleteSrtFiles");
1993 
1994  foreach ($_POST["srt"] as $i)
1995  {
1996  $cgui->addItem("srt[]", $i, "subtitle_".$i.".srt (".$lng->txt("meta_l_".$i).")");
1997  }
1998 
1999  $tpl->setContent($cgui->getHTML());
2000  }
2001  }
2002 
2007  {
2008  global $lng, $ilCtrl;
2009 
2010  foreach ($_POST["srt"] as $i)
2011  {
2012  if (strlen($i) == 2 && !is_int(strpos($i, ".")))
2013  {
2014  $this->object->removeAdditionalFile("srt/subtitle_".$i.".srt");
2015  }
2016  }
2017  ilUtil::sendSuccess($lng->txt("mob_srt_files_deleted"), true);
2018  $ilCtrl->redirect($this, "listSubtitleFiles");
2019  }
2020 }
2021 ?>