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