ILIAS  Release_4_4_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 ("./Modules/LearningModule/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 = $mob_dir."/".$_FILES['standard_file']['name'];
664  ilUtil::moveUploadedFile($_FILES['standard_file']['tmp_name'],
665  $_FILES['standard_file']['name'], $file);
666 
667  // get mime type
669  $location = $_FILES['standard_file']['name'];
670 
671  // resize standard images
672  if ($_POST["standard_size"] != "original" &&
673  is_int(strpos($format, "image")))
674  {
675  $location = ilObjMediaObject::_resizeImage($file, (int) $_POST["standard_width_height"]["width"],
676  (int) $_POST["standard_width_height"]["height"], (boolean) $_POST["standard_width_height"]["contr_prop"]);
677  }
678 
679  // set real meta and object data
680  $media_item->setFormat($format);
681  $media_item->setLocation($location);
682  $media_item->setLocationType("LocalFile");
683  }
684  else // standard type: reference
685  {
686  $format = ilObjMediaObject::getMimeType(ilUtil::stripSlashes($_POST["standard_reference"]));
687  $media_item->setFormat($format);
688  $media_item->setLocation(ilUtil::secureLink(ilUtil::stripSlashes($_POST["standard_reference"])));
689  $media_item->setLocationType("Reference");
690  }
691  $a_mob->setDescription($format);
692 
693  // determine width and height of known image types
694  $wh = ilObjMediaObject::_determineWidthHeight(500, 400, $format,
695  $_POST["standard_type"], $mob_dir."/".$location, $media_item->getLocation(),
696  $_POST["standard_width_height"]["constr_prop"], ($_POST["standard_size"] == "original"),
697  $_POST["standard_width_height"]["width"], $_POST["standard_width_height"]["height"]);
698  $media_item->setWidth($wh["width"]);
699  $media_item->setHeight($wh["height"]);
700  if ($wh["info"] != "")
701  {
702  ilUtil::sendInfo($wh["info"], true);
703  }
704 
705  if ($_POST["standard_caption"] != "")
706  {
707  $media_item->setCaption(ilUtil::stripSlashes($_POST["standard_caption"]));
708  }
709 
710 
711  $media_item->setHAlign("Left");
712 
713  // fullscreen view
714  if ($_POST["full_type"] != "None")
715  {
716  $media_item2 = new ilMediaItem();
717  $a_mob->addMediaItem($media_item2);
718  $media_item2->setPurpose("Fullscreen");
719 
720  // move file / set format and location
721  if ($_POST["full_type"] == "File")
722  {
723  $format = $location = "";
724  if ($_FILES['full_file']['name'] != "")
725  {
726  $file = $mob_dir."/".$_FILES['full_file']['name'];
727  ilUtil::moveUploadedFile($_FILES['full_file']['tmp_name'],
728  $_FILES['full_file']['name'], $file);
730  $location = $_FILES['full_file']['name'];
731  }
732  }
733  else if ($_POST["full_type"] == "Standard" && $_POST["standard_type"] == "File")
734  {
735  $location = $_FILES['standard_file']['name'];
736  }
737 
738  // resize file
739  if ($_POST["full_type"] == "File" ||
740  ($_POST["full_type"] == "Standard" && $_POST["standard_type"] == "File"))
741  {
742  if (($_POST["full_size"] != "original" &&
743  is_int(strpos($format, "image")))
744  )
745  {
746  $location = ilObjMediaObject::_resizeImage($file, (int) $_POST["full_width_height"]["width"],
747  (int) $_POST["full_width_height"]["height"], (boolean) $_POST["full_width_height"]["constr_prop"]);
748  }
749 
750  $media_item2->setFormat($format);
751  $media_item2->setLocation($location);
752  $media_item2->setLocationType("LocalFile");
753  $type = "File";
754  }
755 
756  if ($_POST["full_type"] == "Reference")
757  {
758  $format = $location = "";
759  if ($_POST["full_reference"] != "")
760  {
761  $format = ilObjMediaObject::getMimeType($_POST["full_reference"]);
762  $location = ilUtil::stripSlashes($_POST["full_reference"]);
763  }
764  }
765 
766  if ($_POST["full_type"] == "Reference" ||
767  ($_POST["full_type"] == "Standard" && $_POST["standard_type"] == "Reference"))
768  {
769  $media_item2->setFormat($format);
770  $media_item2->setLocation($location);
771  $media_item2->setLocationType("Reference");
772  $type = "Reference";
773  }
774 
775  // determine width and height of known image types
776  $wh = ilObjMediaObject::_determineWidthHeight(500, 400, $format,
777  $type, $mob_dir."/".$location, $media_item2->getLocation(),
778  $_POST["full_width_height"]["constr_prop"], ($_POST["full_size"] == "original"),
779  $_POST["full_width_height"]["width"], $_POST["full_width_height"]["height"]);
780 
781  $media_item2->setWidth($wh["width"]);
782  $media_item2->setHeight($wh["height"]);
783 
784  if ($_POST["full_caption"] != "")
785  {
786  $media_item2->setCaption(ilUtil::stripSlashes($_POST["full_caption"]));
787  }
788 
789  }
790 
791  ilUtil::renameExecutables($mob_dir);
792  $a_mob->update();
793  }
794 
795 
799  function cancelObject()
800  {
801  $this->ctrl->returnToParent($this);
802  }
803 
807  function editObject()
808  {
809  global $tpl;
810 
811  $this->setPropertiesSubTabs("general");
812 
813  $this->initForm("edit");
814  $this->getValues();
815  $tpl->setContent($this->form_gui->getHTML());
816  }
817 
818 
823  {
824  // directory
825  $mob_dir = ilObjMediaObject::_getDirectory($this->object->getId());
826 
827  // standard item
828  $std_item =& $this->object->getMediaItem("Standard");
829  if ($std_item->getLocationType() == "LocalFile" &&
830  is_int(strpos($std_item->getFormat(), "image"))
831  )
832  {
833  $file = $mob_dir."/".$std_item->getLocation();
834  $location = ilObjMediaObject::_resizeImage($file, $std_item->getWidth(),
835  $std_item->getHeight());
836  $std_item->setLocation($location);
837  $std_item->update();
838  }
839 
840  // fullscreen item
841  if($this->object->hasFullScreenItem())
842  {
843  $full_item =& $this->object->getMediaItem("Fullscreen");
844  if ($full_item->getLocationType() == "LocalFile" &&
845  is_int(strpos($full_item->getFormat(), "image"))
846  )
847  {
848  $file = $mob_dir."/".$full_item->getLocation();
849  $location = ilObjMediaObject::_resizeImage($file, $full_item->getWidth(),
850  $full_item->getHeight());
851  $full_item->setLocation($location);
852  $full_item->update();
853  }
854  }
855 
856  $this->ctrl->redirect($this, "edit");
857  }
858 
859 
864  {
865  $std_item = $this->object->getMediaItem("Standard");
866  $mob_dir = ilObjMediaObject::_getDirectory($this->object->getId());
867 
868  if ($std_item->getLocationType() == "LocalFile")
869  {
870  $file = $mob_dir."/".$std_item->getLocation();
871  $size = getimagesize($file);
872  $std_item->setWidth($size[0]);
873  $std_item->setHeight($size[1]);
874  $this->object->update();
875  }
876  $this->ctrl->redirect($this, "edit");
877  }
878 
879 
884  {
885  $full_item =& $this->object->getMediaItem("Fullscreen");
886  $mob_dir = ilObjMediaObject::_getDirectory($this->object->getId());
887 
888  if ($full_item->getLocationType() == "LocalFile")
889  {
890  $file = $mob_dir."/".$full_item->getLocation();
891  $size = getimagesize($file);
892  $full_item->setWidth($size[0]);
893  $full_item->setHeight($size[1]);
894  $this->object->update();
895  }
896  $this->ctrl->redirect($this, "edit");
897  }
898 
903  {
904  global $lng, $tpl;
905 
906  $this->initForm("edit");
907  if ($this->form_gui->checkInput())
908  {
909  $title = trim($_POST["standard_title"]);
910  $this->object->setTitle($title);
911 
912  $std_item = $this->object->getMediaItem("Standard");
913  $location = $std_item->getLocation();
914  $format = $std_item->getFormat();
915  if ($_POST["standard_type"] == "Reference")
916  {
917  $format = ilObjMediaObject::getMimeType(ilUtil::stripSlashes($_POST["standard_reference"]));
918  $std_item->setFormat($format);
919  $std_item->setLocation(ilUtil::secureLink(ilUtil::stripSlashes($_POST["standard_reference"])));
920  $std_item->setLocationType("Reference");
921  }
922  $mob_dir = ilObjMediaObject::_getDirectory($this->object->getId());
923  if ($_POST["standard_type"] == "File")
924  {
925  $resize = false;
926  if ($_FILES['standard_file']['name'] != "")
927  {
928  $file = $mob_dir."/".$_FILES['standard_file']['name'];
929  ilUtil::moveUploadedFile($_FILES['standard_file']['tmp_name'],
930  $_FILES['standard_file']['name'], $file);
931 
932  // get mime type
934  $location = $_FILES['standard_file']['name'];
935 
936  $resize = true;
937  }
938  else if ($_POST["standard_resize"])
939  {
940  $file = $mob_dir."/".$location;
941  $resize = true;
942  }
943 
944  // resize
945  if ($resize)
946  {
947  if ($_POST["standard_size"] != "original" &&
948  is_int(strpos($format, "image")))
949  {
950  $location = ilObjMediaObject::_resizeImage($file, (int) $_POST["standard_width_height"]["width"],
951  (int) $_POST["standard_width_height"]["height"], (boolean) $_POST["standard_width_height"]["contr_prop"]);
952  }
953  $std_item->setFormat($format);
954  $std_item->setLocation($location);
955  }
956 
957  $std_item->setLocationType("LocalFile");
958  }
959  $this->object->setDescription($format);
960 
961  // determine width and height of known image types
962  $wh = ilObjMediaObject::_determineWidthHeight(500, 400, $format,
963  $_POST["standard_type"], $mob_dir."/".$location, $std_item->getLocation(),
964  $_POST["standard_width_height"]["constr_prop"], ($_POST["standard_size"] == "original"),
965  $_POST["standard_width_height"]["width"], $_POST["standard_width_height"]["height"]);
966  if ($wh["info"] != "")
967  {
968  ilUtil::sendInfo($wh["info"], true);
969  }
970 
971  $std_item->setWidth($wh["width"]);
972  $std_item->setHeight($wh["height"]);
973 
974  // set caption
975  $std_item->setCaption(ilUtil::stripSlashes($_POST["standard_caption"]));
976 
977  // text representation
978  $std_item->setTextRepresentation(ilUtil::stripSlashes($_POST["text_representation"]));
979 
980  // set parameters
981  if (!in_array($std_item->getFormat(), ilObjMediaObject::_getSimpleMimeTypes()))
982  {
983  if (ilObjMediaObject::_useAutoStartParameterOnly($std_item->getLocation(),
984  $std_item->getFormat()))
985  {
986  if ($_POST["standard_autostart"]) // save only autostart flag
987  {
988  $std_item->setParameters('autostart="true"');
989  }
990  else
991  {
992  $std_item->setParameters("");
993  }
994  }
995  else
996  {
997  $std_item->setParameters(ilUtil::stripSlashes(utf8_decode($_POST["standard_parameters"])));
998  }
999  }
1000 
1001  // "None" selected
1002  if ($_POST["full_type"] == "None")
1003  {
1004  if ($this->object->hasFullscreenItem()) // delete existing
1005  {
1006  $this->object->removeMediaItem("Fullscreen");
1007  }
1008  }
1009  else // Not "None" -> we need one
1010  {
1011  if ($this->object->hasFullscreenItem()) // take existing one
1012  {
1013  $full_item = $this->object->getMediaItem("Fullscreen");
1014  }
1015  else // create one
1016  {
1017  $full_item = new ilMediaItem();
1018  $this->object->addMediaItem($full_item);
1019  $full_item->setPurpose("Fullscreen");
1020  }
1021  $location = $full_item->getLocation();
1022  $format = $full_item->getFormat();
1023  if ($_POST["full_type"] == "Reference")
1024  {
1025  $format = ilObjMediaObject::getMimeType(ilUtil::stripSlashes($_POST["full_reference"]));
1026  $full_item->setFormat($format);
1027  $full_item->setLocationType("Reference");
1028  $location = ilUtil::stripSlashes($_POST["full_reference"]);
1029  $type = "Reference";
1030  }
1031  $mob_dir = ilObjMediaObject::_getDirectory($this->object->getId());
1032  if ($_POST["full_type"] == "File")
1033  {
1034  $resize = false;
1035  if ($_FILES['full_file']['name'] != "")
1036  {
1037  $file = $mob_dir."/".$_FILES['full_file']['name'];
1038  ilUtil::moveUploadedFile($_FILES['full_file']['tmp_name'],
1039  $_FILES['full_file']['name'], $file);
1040 
1042  $location = $_FILES['full_file']['name'];
1043 
1044  $resize = true;
1045  }
1046  else if ($_POST["full_resize"])
1047  {
1048  $file = $mob_dir."/".$location;
1049  $resize = true;
1050  }
1051 
1052  // resize
1053  if ($resize)
1054  {
1055  if ($_POST["full_size"] != "original" &&
1056  is_int(strpos($format, "image")))
1057  {
1058  $location = ilObjMediaObject::_resizeImage($file, (int) $_POST["full_width_height"]["width"],
1059  (int) $_POST["full_width_height"]["height"], (boolean) $_POST["full_width_height"]["contr_prop"]);
1060  }
1061  $full_item->setFormat($format);
1062  $full_item->setLocation($location);
1063  }
1064 
1065  $full_item->setLocationType("LocalFile");
1066  $type = "File";
1067  }
1068  if ($_POST["full_type"] == "Standard")
1069  {
1070  $format = $std_item->getFormat();
1071  $location = $std_item->getLocation();
1072  $full_item->setLocationType($std_item->getLocationType());
1073  $full_item->setFormat($format);
1074  $full_item->setLocation($location);
1075  $type = $std_item->getLocationType();
1076  if ($type == "LocalFile")
1077  {
1078  $type = "File";
1079  }
1080  // resize image
1081 //echo "-".$_POST["full_size"]."-".is_int(strpos($format, "image"))."-".$full_item->getLocationType()."-";
1082  if ($_POST["full_size"] != "original" &&
1083  is_int(strpos($format, "image")) &&
1084  $full_item->getLocationType() == "LocalFile")
1085  {
1086  $file = $mob_dir."/".$location;
1087  $location = ilObjMediaObject::_resizeImage($file, (int) $_POST["full_width_height"]["width"],
1088  (int) $_POST["full_width_height"]["height"], (boolean) $_POST["full_width_height"]["contr_prop"]);
1089  }
1090  }
1091 
1092  // determine width and height of known image types
1093  $wh = ilObjMediaObject::_determineWidthHeight(500, 400, $format,
1094  $type, $mob_dir."/".$location, $full_item->getLocation(),
1095  $_POST["full_width_height"]["constr_prop"], ($_POST["full_size"] == "original"),
1096  $_POST["full_width_height"]["width"], $_POST["full_width_height"]["height"]);
1097  if ($wh["info"] != "")
1098  {
1099  ilUtil::sendInfo($wh["info"], true);
1100  }
1101 
1102  $full_item->setWidth($wh["width"]);
1103  $full_item->setHeight($wh["height"]);
1104  $full_item->setLocation($location);
1105 
1106  $full_item->setCaption(ilUtil::stripSlashes($_POST["full_caption"]));
1107 
1108  // text representation
1109  $full_item->setTextRepresentation(ilUtil::stripSlashes($_POST["full_text_representation"]));
1110 
1111 
1112  // set parameters
1113  if (!in_array($std_item->getFormat(), ilObjMediaObject::_getSimpleMimeTypes()))
1114  {
1115  if (ilObjMediaObject::_useAutoStartParameterOnly($std_item->getLocation(),
1116  $std_item->getFormat()))
1117  {
1118  if ($_POST["full_autostart"]) // save only autostart flag
1119  {
1120  $full_item->setParameters('autostart="true"');
1121  }
1122  else
1123  {
1124  $full_item->setParameters("");
1125  }
1126  }
1127  else
1128  {
1129  $full_item->setParameters(ilUtil::stripSlashes(utf8_decode($_POST["full_parameters"])));
1130  }
1131  }
1132  }
1133 
1135 
1136  $this->object->update();
1137  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
1138  $this->ctrl->redirect($this, "edit");
1139  }
1140  else
1141  {
1142  $this->form_gui->setValuesByPost();
1143  $tpl->setContent($this->form_gui->getHTML());
1144  }
1145  }
1146 
1147 
1151  function editFilesObject()
1152  {
1153  // standard item
1154  $std_item =& $this->object->getMediaItem("Standard");
1155  if($this->object->hasFullscreenItem())
1156  {
1157  $full_item =& $this->object->getMediaItem("Fullscreen");
1158  }
1159 
1160  // create table
1161  require_once("./Services/Table/classes/class.ilTableGUI.php");
1162  $tbl = new ilTableGUI();
1163 
1164  // determine directory
1165  $cur_subdir = $_GET["cdir"];
1166  if($_GET["newdir"] == "..")
1167  {
1168  $cur_subdir = substr($cur_subdir, 0, strrpos($cur_subdir, "/"));
1169  }
1170  else
1171  {
1172  if (!empty($_GET["newdir"]))
1173  {
1174  if (!empty($cur_subdir))
1175  {
1176  $cur_subdir = $cur_subdir."/".$_GET["newdir"];
1177  }
1178  else
1179  {
1180  $cur_subdir = $_GET["newdir"];
1181  }
1182  }
1183  }
1184 
1185  $cur_subdir = str_replace(".", "", $cur_subdir);
1186  $mob_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$this->object->getId();
1187  $cur_dir = (!empty($cur_subdir))
1188  ? $mob_dir."/".$cur_subdir
1189  : $mob_dir;
1190 
1191  // load files templates
1192  $this->tpl->addBlockfile("ADM_CONTENT", "adm_content", "tpl.mob_files.html", "Services/MediaObjects");
1193 
1194  $this->ctrl->setParameter($this, "cdir", urlencode($cur_subdir));
1195  $this->tpl->setVariable("FORMACTION1", $this->ctrl->getFormAction($this));
1196 //echo "--".$this->getTargetScript().
1197  //"&hier_id=".$_GET["hier_id"]."&cdir=".$cur_subdir."&cmd=post"."--<br>";
1198  $this->tpl->setVariable("TXT_NEW_DIRECTORY", $this->lng->txt("cont_new_dir"));
1199  $this->tpl->setVariable("TXT_NEW_FILE", $this->lng->txt("cont_new_file"));
1200  $this->tpl->setVariable("CMD_NEW_DIR", "createDirectory");
1201  $this->tpl->setVariable("CMD_NEW_FILE", "uploadFile");
1202  $this->tpl->setVariable("BTN_NEW_DIR", $this->lng->txt("create"));
1203  $this->tpl->setVariable("BTN_NEW_FILE", $this->lng->txt("upload"));
1204 
1205  //
1206  $this->tpl->addBlockfile("FILE_TABLE", "files", "tpl.table.html");
1207 
1208  // load template for table content data
1209  $this->tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.mob_file_row.html", "Services/MediaObjects");
1210 
1211  $num = 0;
1212 
1213  $obj_str = ($this->call_by_reference) ? "" : "&obj_id=".$this->obj_id;
1214  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
1215 
1216  $tbl->setTitle($this->lng->txt("cont_files")." ".$cur_subdir);
1217  //$tbl->setHelp("tbl_help.php","icon_help.gif",$this->lng->txt("help"));
1218 
1219  $tbl->setHeaderNames(array("", "", $this->lng->txt("cont_dir_file"),
1220  $this->lng->txt("cont_size"), $this->lng->txt("cont_purpose")));
1221 
1222  $cols = array("", "", "dir_file", "size", "purpose");
1223  $header_params = array("ref_id" => $_GET["ref_id"], "obj_id" => $_GET["obj_id"],
1224  "cmd" => "editFiles", "hier_id" => $_GET["hier_id"], "item_id" => $_GET["item_id"]);
1225  $tbl->setHeaderVars($cols, $header_params);
1226  $tbl->setColumnWidth(array("1%", "1%", "33%", "33%", "32%"));
1227 
1228  // control
1229  $tbl->setOrderColumn($_GET["sort_by"]);
1230  $tbl->setOrderDirection($_GET["sort_order"]);
1231  $tbl->setLimit($_GET["limit"]);
1232  $tbl->setOffset($_GET["offset"]);
1233  $tbl->setMaxCount($this->maxcount); // ???
1234  //$tbl->setMaxCount(30); // ???
1235 
1236  $this->tpl->setVariable("COLUMN_COUNTS", 5);
1237 
1238  // delete button
1239  $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.png"));
1240  $this->tpl->setCurrentBlock("tbl_action_btn");
1241  $this->tpl->setVariable("BTN_NAME", "deleteFile");
1242  $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("delete"));
1243  $this->tpl->parseCurrentBlock();
1244 
1245  $this->tpl->setCurrentBlock("tbl_action_btn");
1246  $this->tpl->setVariable("BTN_NAME", "assignStandard");
1247  $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("cont_assign_std"));
1248  $this->tpl->parseCurrentBlock();
1249 
1250  $this->tpl->setCurrentBlock("tbl_action_btn");
1251  $this->tpl->setVariable("BTN_NAME", "assignFullscreen");
1252  $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("cont_assign_full"));
1253  $this->tpl->parseCurrentBlock();
1254 
1255  // footer
1256  $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
1257  //$tbl->disable("footer");
1258 
1259  $entries = ilUtil::getDir($cur_dir);
1260 
1261  //$objs = ilUtil::sortArray($objs, $_GET["sort_by"], $_GET["sort_order"]);
1262  $tbl->setMaxCount(count($entries));
1263  $entries = array_slice($entries, $_GET["offset"], $_GET["limit"]);
1264 
1265  $tbl->render();
1266  if(count($entries) > 0)
1267  {
1268  $i=0;
1269  foreach($entries as $entry)
1270  {
1271  if(($entry["entry"] == ".") || ($entry["entry"] == ".." && empty($cur_subdir)))
1272  {
1273  continue;
1274  }
1275 
1276  //$this->tpl->setVariable("ICON", $obj["title"]);
1277  if($entry["type"] == "dir")
1278  {
1279  $this->tpl->setCurrentBlock("FileLink");
1280  $this->ctrl->setParameter($this, "cdir", $cur_subdir);
1281  $this->ctrl->setParameter($this, "newdir", rawurlencode($entry["entry"]));
1282  $this->tpl->setVariable("LINK_FILENAME", $this->ctrl->getLinkTarget($this, "editFiles"));
1283  $this->tpl->setVariable("TXT_FILENAME", $entry["entry"]);
1284  $this->tpl->parseCurrentBlock();
1285 
1286  $this->tpl->setVariable("ICON", "<img src=\"".
1287  ilUtil::getImagePath("icon_cat.png")."\">");
1288  }
1289  else
1290  {
1291  $this->tpl->setCurrentBlock("File");
1292  $this->tpl->setVariable("TXT_FILENAME2", $entry["entry"]);
1293  $this->tpl->parseCurrentBlock();
1294  }
1295 
1296  $this->tpl->setCurrentBlock("tbl_content");
1297  $css_row = ilUtil::switchColor($i++, "tblrow1", "tblrow2");
1298  $this->tpl->setVariable("CSS_ROW", $css_row);
1299 
1300  $this->tpl->setVariable("TXT_SIZE", $entry["size"]);
1301  $this->tpl->setVariable("CHECKBOX_ID", $entry["entry"]);
1302  $compare = (!empty($cur_subdir))
1303  ? $cur_subdir."/".$entry["entry"]
1304  : $entry["entry"];
1305  $purpose = array();
1306  if ($std_item->getLocation() == $compare)
1307  {
1308  $purpose[] = $this->lng->txt("cont_std_view");
1309  }
1310  if($this->object->hasFullscreenItem())
1311  {
1312  if ($full_item->getLocation() == $compare)
1313  {
1314  $purpose[] = $this->lng->txt("cont_fullscreen");
1315  }
1316  }
1317  $this->tpl->setVariable("TXT_PURPOSE", implode($purpose, ", "));
1318 
1319  $this->tpl->parseCurrentBlock();
1320  }
1321  } //if is_array
1322  else
1323  {
1324  $this->tpl->setCurrentBlock("notfound");
1325  $this->tpl->setVariable("TXT_OBJECT_NOT_FOUND", $this->lng->txt("obj_not_found"));
1326  $this->tpl->setVariable("NUM_COLS", 4);
1327  $this->tpl->parseCurrentBlock();
1328  }
1329 
1330  $this->tpl->parseCurrentBlock();
1331  }
1332 
1333 
1338  {
1339 //echo "cdir:".$_GET["cdir"].":<br>";
1340  // determine directory
1341  $cur_subdir = str_replace(".", "", $_GET["cdir"]);
1342  $mob_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$this->object->getId();
1343  $cur_dir = (!empty($cur_subdir))
1344  ? $mob_dir."/".$cur_subdir
1345  : $mob_dir;
1346 
1347  $new_dir = str_replace(".", "", $_POST["new_dir"]);
1348  $new_dir = str_replace("/", "", $new_dir);
1349 
1350  if (!empty($new_dir))
1351  {
1352  ilUtil::makeDir($cur_dir."/".$new_dir);
1353  }
1354  $this->ctrl->saveParameter($this, "cdir");
1355  $this->ctrl->redirect($this, "editFiles");
1356  }
1357 
1361  function uploadFileObject()
1362  {
1363  // determine directory
1364  $cur_subdir = str_replace(".", "", $_GET["cdir"]);
1365  $mob_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$this->object->getId();
1366  $cur_dir = (!empty($cur_subdir))
1367  ? $mob_dir."/".$cur_subdir
1368  : $mob_dir;
1369  if (is_file($_FILES["new_file"]["tmp_name"]))
1370  {
1371  //move_uploaded_file($_FILES["new_file"]["tmp_name"],
1372  //$cur_dir."/".$_FILES["new_file"]["name"]);
1373  $file = $cur_dir."/".$_FILES["new_file"]["name"];
1374  ilUtil::moveUploadedFile($_FILES['new_file']['tmp_name'],
1375  $_FILES['new_file']['name'], $file);
1376 
1377  }
1378  ilUtil::renameExecutables($mob_dir);
1379  $this->ctrl->saveParameter($this, "cdir");
1380  $this->ctrl->redirect($this, "editFiles");
1381  }
1382 
1387  {
1388  if (!isset($_POST["file"]))
1389  {
1390  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
1391  }
1392 
1393  if (count($_POST["file"]) > 1)
1394  {
1395  $this->ilias->raiseError($this->lng->txt("cont_select_max_one_item"),$this->ilias->error_obj->MESSAGE);
1396  }
1397 
1398  // determine directory
1399  $cur_subdir = str_replace(".", "", $_GET["cdir"]);
1400  $mob_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$this->object->getId();
1401  $cur_dir = (!empty($cur_subdir))
1402  ? $mob_dir."/".$cur_subdir
1403  : $mob_dir;
1404  $file = $cur_dir."/".$_POST["file"][0];
1405  $location = (!empty($cur_subdir))
1406  ? $cur_subdir."/".$_POST["file"][0]
1407  : $_POST["file"][0];
1408 
1409  if(!is_file($file))
1410  {
1411  $this->ilias->raiseError($this->lng->txt("cont_select_file"),$this->ilias->error_obj->MESSAGE);
1412  }
1413 
1414  $std_item =& $this->object->getMediaItem("Standard");
1415  $std_item->setLocationType("LocalFile");
1416  $std_item->setLocation($location);
1418  $std_item->setFormat($format);
1419  $this->object->update();
1420 // $this->ctrl->saveParameter($this, "cdir");
1421  $this->ctrl->redirectByClass("ilfilesystemgui", "listFiles");
1422  }
1423 
1424 
1429  {
1430  if (!isset($_POST["file"]))
1431  {
1432  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
1433  }
1434 
1435  if (count($_POST["file"]) > 1)
1436  {
1437  $this->ilias->raiseError($this->lng->txt("cont_select_max_one_item"),$this->ilias->error_obj->MESSAGE);
1438  }
1439 
1440  // determine directory
1441  $cur_subdir = str_replace(".", "", $_GET["cdir"]);
1442  $mob_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$this->object->getId();
1443  $cur_dir = (!empty($cur_subdir))
1444  ? $mob_dir."/".$cur_subdir
1445  : $mob_dir;
1446  $file = $cur_dir."/".$_POST["file"][0];
1447  $location = (!empty($cur_subdir))
1448  ? $cur_subdir."/".$_POST["file"][0]
1449  : $_POST["file"][0];
1450 
1451  if(!is_file($file))
1452  {
1453  $this->ilias->raiseError($this->lng->txt("cont_select_file"),$this->ilias->error_obj->MESSAGE);
1454  }
1455 
1456  if(!$this->object->hasFullScreenItem())
1457  { // create new fullscreen item
1458  $std_item =& $this->object->getMediaItem("Standard");
1459  $mob_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$this->object->getId();
1460  $file = $mob_dir."/".$location;
1461  $full_item =& new ilMediaItem();
1462  $full_item->setMobId($std_item->getMobId());
1463  $full_item->setLocation($location);
1464  $full_item->setLocationType("LocalFile");
1465  $full_item->setFormat(ilObjMediaObject::getMimeType($file));
1466  $full_item->setPurpose("Fullscreen");
1467  $this->object->addMediaItem($full_item);
1468  }
1469  else // alter existing fullscreen item
1470  {
1471  $full_item =& $this->object->getMediaItem("Fullscreen");
1472 
1473  $full_item->setLocationType("LocalFile");
1474  $full_item->setLocation($location);
1476  $full_item->setFormat($format);
1477  }
1478  $this->object->update();
1479 // $this->ctrl->saveParameter($this, "cdir");
1480  $this->ctrl->redirectByClass("ilfilesystemgui", "listFiles");
1481  }
1482 
1483 
1488  {
1489  $this->object->removeMediaItem("Fullscreen");
1490  $this->object->update();
1491 
1492  $this->ctrl->redirect($this, "edit");
1493  }
1494 
1495 
1500  {
1501  if (!$this->object->hasFullScreenItem())
1502  {
1503  $std_item =& $this->object->getMediaItem("Standard");
1504  $full_item =& new ilMediaItem();
1505  $full_item->setMobId($std_item->getMobId());
1506  $full_item->setLocation($std_item->getLocation());
1507  $full_item->setLocationType($std_item->getLocationType());
1508  $full_item->setFormat($std_item->getFormat());
1509  $full_item->setWidth($std_item->getWidth());
1510  $full_item->setHeight($std_item->getHeight());
1511  $full_item->setCaption($std_item->getCaption());
1512  $full_item->setTextRepresentation($std_item->getTextRepresentation());
1513  $full_item->setPurpose("Fullscreen");
1514  $this->object->addMediaItem($full_item);
1515 
1516  $this->object->update();
1517  }
1518 
1519  $this->ctrl->redirect($this, "edit");
1520  }
1521 
1522 
1526  function deleteFileObject()
1527  {
1528  if (!isset($_POST["file"]))
1529  {
1530  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
1531  }
1532 
1533  if (count($_POST["file"]) > 1)
1534  {
1535  $this->ilias->raiseError($this->lng->txt("cont_select_max_one_item"),$this->ilias->error_obj->MESSAGE);
1536  }
1537 
1538  if ($_POST["file"][0] == "..")
1539  {
1540  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
1541  }
1542 
1543  $cur_subdir = str_replace(".", "", $_GET["cdir"]);
1544  $mob_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$this->object->getId();
1545  $cur_dir = (!empty($cur_subdir))
1546  ? $mob_dir."/".$cur_subdir
1547  : $mob_dir;
1548  $file = $cur_dir."/".$_POST["file"][0];
1549  $location = (!empty($cur_subdir))
1550  ? $cur_subdir."/".$_POST["file"][0]
1551  : $_POST["file"][0];
1552 
1553  $full_item =& $this->object->getMediaItem("Fullscreen");
1554  $std_item =& $this->object->getMediaItem("Standard");
1555 
1556  if ($location == $std_item->getLocation())
1557  {
1558  $this->ilias->raiseError($this->lng->txt("cont_cant_del_std"),$this->ilias->error_obj->MESSAGE);
1559  }
1560 
1561  if($this->object->hasFullScreenItem())
1562  {
1563  if ($location == $full_item->getLocation())
1564  {
1565  $this->ilias->raiseError($this->lng->txt("cont_cant_del_full"),$this->ilias->error_obj->MESSAGE);
1566  }
1567  }
1568 
1569  if (@is_dir($file))
1570  {
1571  if (substr($std_item->getLocation(), 0 ,strlen($location)) == $location)
1572  {
1573  $this->ilias->raiseError($this->lng->txt("cont_std_is_in_dir"),$this->ilias->error_obj->MESSAGE);
1574  }
1575 
1576  if($this->object->hasFullScreenItem())
1577  {
1578  if (substr($full_item->getLocation(), 0 ,strlen($location)) == $location)
1579  {
1580  $this->ilias->raiseError($this->lng->txt("cont_full_is_in_dir"),$this->ilias->error_obj->MESSAGE);
1581  }
1582  }
1583  }
1584 
1585  if (@is_file($file))
1586  {
1587  unlink($file);
1588  }
1589 
1590  if (@is_dir($file))
1591  {
1593  }
1594 
1595  $this->ctrl->saveParameter($this, "cdir");
1596  $this->ctrl->redirect($this, "editFiles");
1597  }
1598 
1603  {
1604  $this->showUsagesObject(true);
1605  }
1606 
1607 
1611  function showUsagesObject($a_all = false)
1612  {
1613  global $tpl, $ilTabs, $ilTabs, $lng, $ilCtrl;
1614 
1615  $ilTabs->addSubTab("current_usages", $lng->txt("cont_current_usages"),
1616  $ilCtrl->getLinkTarget($this, "showUsages"));
1617 
1618  $ilTabs->addSubTab("all_usages", $lng->txt("cont_all_usages"),
1619  $ilCtrl->getLinkTarget($this, "showAllUsages"));
1620 
1621  if ($a_all)
1622  {
1623  $ilTabs->activateSubTab("all_usages");
1624  $cmd = "showAllUsages";
1625  }
1626  else
1627  {
1628  $ilTabs->activateSubTab("current_usages");
1629  $cmd = "showUsages";
1630  }
1631 
1632  include_once("./Services/MediaObjects/classes/class.ilMediaObjectUsagesTableGUI.php");
1633  $usages_table = new ilMediaObjectUsagesTableGUI($this, $cmd,
1634  $this->object, $a_all);
1635  $tpl->setContent($usages_table->getHTML());
1636  }
1637 
1641  function _getMediaInfoHTML(&$a_mob)
1642  {
1643  global $lng;
1644 
1645  $tpl =& new ilTemplate("tpl.media_info.html", true, true, "Services/MediaObjects");
1646  $types = array("Standard", "Fullscreen");
1647  foreach ($types as $type)
1648  {
1649  if($type == "Fullscreen" && !$a_mob->hasFullScreenItem())
1650  {
1651  continue;
1652  }
1653 
1654  $med = $a_mob->getMediaItem($type);
1655  if (!$med)
1656  {
1657  return "";
1658  }
1659 
1660  $tpl->setCurrentBlock("media_info");
1661  if ($type == "Standard")
1662  {
1663  $tpl->setVariable("TXT_PURPOSE", $lng->txt("cont_std_view"));
1664  }
1665  else
1666  {
1667  $tpl->setVariable("TXT_PURPOSE", $lng->txt("cont_fullscreen"));
1668  }
1669  $tpl->setVariable("TXT_TYPE", $lng->txt("cont_".strtolower($med->getLocationType())));
1670  $tpl->setVariable("VAL_LOCATION", $med->getLocation());
1671  if ($med->getLocationType() == "LocalFile")
1672  {
1673  $file = ilObjMediaObject::_getDirectory($med->getMobId())."/".$med->getLocation();
1674  if (is_file($file))
1675  {
1676  $size = filesize($file);
1677  }
1678  else
1679  {
1680  $size = 0;
1681  }
1682  $tpl->setVariable("VAL_FILE_SIZE", " ($size ".$lng->txt("bytes").")");
1683  }
1684  $tpl->setVariable("TXT_FORMAT", $lng->txt("cont_format"));
1685  $tpl->setVariable("VAL_FORMAT", $med->getFormat());
1686  if ($med->getWidth() != "" && $med->getHeight() != "")
1687  {
1688  $tpl->setCurrentBlock("size");
1689  $tpl->setVariable("TXT_SIZE", $lng->txt("size"));
1690  $tpl->setVariable("VAL_SIZE", $med->getWidth()."x".$med->getHeight());
1691  $tpl->parseCurrentBlock();
1692  }
1693 
1694  // original size
1695  if ($orig_size = $med->getOriginalSize())
1696  {
1697  if ($orig_size["width"] != $med->getWidth() ||
1698  $orig_size["height"] != $med->getHeight())
1699  {
1700  $tpl->setCurrentBlock("orig_size");
1701  $tpl->setVariable("TXT_ORIG_SIZE", $lng->txt("cont_orig_size"));
1702  $tpl->setVariable("ORIG_WIDTH", $orig_size["width"]);
1703  $tpl->setVariable("ORIG_HEIGHT", $orig_size["height"]);
1704  $tpl->parseCurrentBlock();
1705  }
1706  }
1707  $tpl->setCurrentBlock("media_info");
1708  $tpl->parseCurrentBlock();
1709  }
1710 
1711  return $tpl->get();
1712  }
1713 
1717  //function setAdminTabs()
1718  function setTabs()
1719  {
1720 //echo "setAdminTabs should not be called.";
1721 
1722  // catch feedback message
1723  $this->getTabs($this->tabs_gui);
1724 
1725  //$tabs_gui->setTargetScript($this->ctrl->getLinkTarget($this));
1726  if (is_object($this->object) && strtolower(get_class($this->object)) == "ilobjmediaobject")
1727  {
1728  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_mob_b.png"));
1729  $this->tpl->setTitle($this->object->getTitle());
1730  }
1731  else
1732  {
1733  //$title = $this->object->getTitle();
1734  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_mob_b.png"));
1735  $this->tpl->setTitle($this->lng->txt("cont_create_mob"));
1736  }
1737  }
1738 
1739 
1743  function getTabs(&$tabs_gui)
1744  {
1745  global $ilTabs, $ilHelp;
1746 
1747  $ilHelp->setScreenIdComponent("mob");
1748 
1749  //$tabs_gui->setTargetScript($this->ctrl->getLinkTarget($this));
1750  if (is_object($this->object) && strtolower(get_class($this->object)) == "ilobjmediaobject"
1751  && $this->object->getId() > 0)
1752  {
1753  // object properties
1754  $ilTabs->addTarget("cont_mob_def_prop",
1755  $this->ctrl->getLinkTarget($this, "edit"), "edit",
1756  get_class($this));
1757 
1758  $st_item =& $this->object->getMediaItem("Standard");
1759 
1760  // video tools
1761  if (substr($st_item->getFormat(), 0, 6) == "video/" && DEVMODE)
1762  {
1763  $ilTabs->addTarget("mob_video_tools",
1764  $this->ctrl->getLinkTargetByClass("ilobjmediaobjectgui", "showVideoTool"),
1765  "showVideoTool", "ilobjmediaobjectgui");
1766  }
1767 
1768  // link areas
1769 
1770  if (is_object($st_item) && $this->getEnabledMapAreas())
1771  {
1772  $format = $st_item->getFormat();
1773  if (substr($format, 0, 5) == "image")
1774  {
1775  $ilTabs->addTarget("cont_def_map_areas",
1776  $this->ctrl->getLinkTargetByClass(
1777  array("ilobjmediaobjectgui", "ilimagemapeditorgui"), "editMapAreas"), "editMapAreas",
1778  "ilimagemapeditorgui");
1779  }
1780  }
1781 
1782  // object usages
1783  $ilTabs->addTarget("cont_mob_usages",
1784  $this->ctrl->getLinkTarget($this, "showUsages"), "showUsages",
1785  get_class($this));
1786 
1787  // object files
1788  $std_item = $this->object->getMediaItem("Standard");
1789  $full_item = $this->object->getMediaItem("Fullscreen");
1790  $mset = new ilSetting("mobs");
1791  if ($mset->get("file_manager_always") ||
1792  (!in_array($std_item->getFormat(), ilObjMediaObject::_getSimpleMimeTypes()) ||
1793  (is_object($full_item) && !in_array($full_item->getFormat(), ilObjMediaObject::_getSimpleMimeTypes())))
1794  )
1795  {
1796 // $ilTabs->addTarget("cont_files",
1797 // $this->ctrl->getLinkTarget($this, "editFiles"), "editFiles",
1798 // get_class($this));
1799 
1800  $ilTabs->addTarget("cont_files",
1801  $this->ctrl->getLinkTargetByClass(
1802  array("ilobjmediaobjectgui", "ilfilesystemgui"), "listFiles"), "",
1803  "ilfilesystemgui");
1804  }
1805 
1806  $ilTabs->addTarget("meta_data",
1807  $this->ctrl->getLinkTargetByClass(
1808  array("ilobjmediaobjectgui", "ilmdeditorgui"),'listSection'),
1809  "", "ilmdeditorgui");
1810 
1811  }
1812 
1813  // back to upper context
1814  if ($this->back_title != "")
1815  {
1816  $tabs_gui->setBackTarget($this->back_title,
1817  $this->ctrl->getParentReturn($this));
1818  }
1819  }
1820 
1828  {
1829  global $tpl;
1830 
1831  include_once("./Services/MediaObjects/classes/class.ilFFmpeg.php");
1832 
1833  /*$codecs = ilFFmpeg::getSupportedCodecsInfo();
1834  $codec_str = implode($codecs, "<br />");
1835  $tpl->setContent($codec_str);*/
1836 
1837  $formats = ilFFmpeg::getSupportedFormatsInfo();
1838  $formats_str = implode($formats, "<br />");
1839  $tpl->setContent($formats_str);
1840  }
1841 
1842 
1846  function includePresentationJS($a_tpl = null)
1847  {
1848  global $tpl;
1849 
1850  if ($a_tpl == null)
1851  {
1852  $a_tpl = $tpl;
1853  }
1854 
1855  include_once("./Services/jQuery/classes/class.iljQueryUtil.php");
1856  iljQueryUtil::initjQUery($a_tpl);
1857  include_once("./Services/jQuery/classes/class.iljQueryUtil.php");
1858  $a_tpl->addJavascript(iljQueryUtil::getLocalMaphilightPath());
1859  $a_tpl->addJavascript("./Services/COPage/js/ilCOPagePres.js");
1860 
1861  include_once("./Services/MediaObjects/classes/class.ilPlayerUtil.php");
1863  }
1864 
1870  function setPropertiesSubTabs($a_active)
1871  {
1872  global $ilTabs, $ilCtrl, $lng;
1873 
1874  $ilTabs->activateTab("cont_mob_def_prop");
1875 
1876  $ilTabs->addSubTab("general",
1877  $lng->txt("mob_general"),
1878  $ilCtrl->getLinkTarget($this, "edit"));
1879 
1880  if ($this->object->getMediaItem("Standard")->getFormat() == "video/webm" ||
1881  $this->object->getMediaItem("Standard")->getFormat() == "video/mp4")
1882  {
1883  $ilTabs->addSubTab("subtitles",
1884  $lng->txt("mob_subtitles"),
1885  $ilCtrl->getLinkTarget($this, "listSubtitleFiles"));
1886  }
1887 
1888  $ilTabs->activateSubTab($a_active);
1889  }
1890 
1898  {
1899  global $ilToolbar, $tpl, $ilCtrl, $lng, $ilUser;
1900 
1901  $this->setPropertiesSubTabs("subtitles");
1902 
1903  // upload file
1904  $ilToolbar->setFormAction($ilCtrl->getFormAction($this), true);
1905  include_once("./Services/Form/classes/class.ilFileInputGUI.php");
1906  $fi = new ilFileInputGUI($lng->txt("mob_subtitle_file")." (.srt)", "subtitle_file");
1907  $fi->setSuffixes(array("srt"));
1908  $ilToolbar->addInputItem($fi, true);
1909 
1910  // language
1911  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
1912  include_once("./Services/MetaData/classes/class.ilMDLanguageItem.php");
1914  $si = new ilSelectInputGUI($this->lng->txt("mob_language"), "language");
1915  $si->setOptions($options);
1916  $si->setValue($ilUser->getLanguage());
1917  $ilToolbar->addInputItem($si, true);
1918 
1919  $ilToolbar->addFormButton($lng->txt("upload"), "uploadSubtitleFile");
1920 
1921  include_once("./Services/MediaObjects/classes/class.ilMobSubtitleTableGUI.php");
1922  $tab = new ilMobSubtitleTableGUI($this, "listSubtitleFiles", $this->object);
1923 
1924  $tpl->setContent($tab->getHTML());
1925  }
1926 
1934  {
1935  global $lng, $ilCtrl;
1936 
1937  if ($this->object->uploadSrtFile($_FILES["subtitle_file"]["tmp_name"], ilUtil::stripSlashes($_POST["language"])))
1938  {
1939  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
1940  }
1941  $ilCtrl->redirect($this, "listSubtitleFiles");
1942  }
1943 
1948  {
1949  global $ilCtrl, $tpl, $lng;
1950 
1951  $lng->loadLanguageModule("meta");
1952 
1953  if (!is_array($_POST["srt"]) || count($_POST["srt"]) == 0)
1954  {
1955  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
1956  $ilCtrl->redirect($this, "listSubtitleFiles");
1957  }
1958  else
1959  {
1960  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
1961  $cgui = new ilConfirmationGUI();
1962  $cgui->setFormAction($ilCtrl->getFormAction($this));
1963  $cgui->setHeaderText($lng->txt("mob_really_delete_srt"));
1964  $cgui->setCancel($lng->txt("cancel"), "listSubtitleFiles");
1965  $cgui->setConfirm($lng->txt("delete"), "deleteSrtFiles");
1966 
1967  foreach ($_POST["srt"] as $i)
1968  {
1969  $cgui->addItem("srt[]", $i, "subtitle_".$i.".srt (".$lng->txt("meta_l_".$i).")");
1970  }
1971 
1972  $tpl->setContent($cgui->getHTML());
1973  }
1974  }
1975 
1980  {
1981  global $lng, $ilCtrl;
1982 
1983  foreach ($_POST["srt"] as $i)
1984  {
1985  if (strlen($i) == 2 && !is_int(strpos($i, ".")))
1986  {
1987  $this->object->removeAdditionalFile("srt/subtitle_".$i.".srt");
1988  }
1989  }
1990  ilUtil::sendSuccess($lng->txt("mob_srt_files_deleted"), true);
1991  $ilCtrl->redirect($this, "listSubtitleFiles");
1992  }
1993 }
1994 ?>