ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjMediaCastGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once "./classes/class.ilObjectGUI.php";
6 
17 {
18 
19  private $additionalPurposes = array ("VideoPortable", "AudioPortable");
20  private $purposeSuffixes = array ();
21  private $mimeTypes = array();
22 
27  function ilObjMediaCastGUI($a_data, $a_id, $a_call_by_reference, $a_prepare_output = true)
28  {
29  global $ilCtrl, $lng;
30 
31  $this->type = "mcst";
32  $this->ilObjectGUI($a_data,$a_id,$a_call_by_reference,$a_prepare_output);
33  $lng->loadLanguageModule("mcst");
34  $lng->loadLanguageModule("news");
35 
36  $ilCtrl->saveParameter($this, "item_id");
37 
38  include_once ("./Modules/MediaCast/classes/class.ilMediaCastSettings.php");
40  $this->purposeSuffixes = $settings->getPurposeSuffixes();
41  $this->mimeTypes = $settings->getMimeTypes();
42  }
43 
44  function &executeCommand()
45  {
46  global $ilUser;
47 
48  $next_class = $this->ctrl->getNextClass($this);
49  $cmd = $this->ctrl->getCmd();
50  $this->prepareOutput();
51 
52  switch($next_class)
53  {
54  case "ilinfoscreengui":
55  $this->checkPermission("visible");
56  $this->infoScreen(); // forwards command
57  break;
58 
59  case 'ilpermissiongui':
60  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
61  $perm_gui =& new ilPermissionGUI($this);
62  $ret =& $this->ctrl->forwardCommand($perm_gui);
63  break;
64 
65  default:
66  if(!$cmd)
67  {
68  $cmd = "infoScreen";
69  }
70  $cmd .= "Object";
71  if ($cmd != "infoScreenObject")
72  {
73  $this->checkPermission("read");
74  }
75  else
76  {
77  $this->checkPermission("visible");
78  }
79  $this->$cmd();
80 
81  break;
82  }
83 
84  return true;
85  }
86 
91  function saveObject()
92  {
93  global $rbacadmin;
94 
95  // create and insert forum in objecttree
96  $newObj = parent::saveObject();
97 
98  // setup rolefolder & default local roles
99  //$roles = $newObj->initDefaultRoles();
100 
101  // ...finally assign role to creator of object
102  //$rbacadmin->assignUser($roles[0], $newObj->getOwner(), "y");
103 
104  // put here object specific stuff
105 
106  // always send a message
107  ilUtil::sendSuccess($this->lng->txt("object_added"),true);
108 
109  ilUtil::redirect("ilias.php?baseClass=ilMediaCastHandlerGUI&ref_id=".$newObj->getRefId()."&cmd=editSettings");
110  }
111 
112 
116  function listItemsObject()
117  {
118  global $tpl, $lng, $ilAccess;
119 
120  $this->checkPermission("read");
121 
122  $med_items = $this->object->getItemsArray();
123 
124  include_once("./Modules/MediaCast/classes/class.ilMediaCastTableGUI.php");
125  $table_gui = new ilMediaCastTableGUI($this, "listItems");
126 
127  $table_gui->setTitle($lng->txt("mcst_media_cast"));
128  $table_gui->setData($med_items);
129 
130  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]))
131  {
132  $table_gui->addCommandButton("addCastItem", $lng->txt("add"));
133  $table_gui->addMultiCommand("confirmDeletionItems", $lng->txt("delete"));
134  $table_gui->setSelectAllCheckbox("item_id");
135  }
136 
137  include_once("./Services/Block/classes/class.ilBlockSetting.php");
138  $public_feed = ilBlockSetting::_lookup("news", "public_feed",
139  0, $this->object->getId());
140 
141  // rss icon/link
142  if ($public_feed)
143  {
144  $news_set = new ilSetting("news");
145  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
146 
147 
148  if ($enable_internal_rss)
149  {
150  // create dummy object in db (we need an id)
151  $items = $this->object->getItemsArray();
152  include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
153  $html = "";
154  foreach (ilObjMediaCast::$purposes as $purpose)
155  {
156 
157  foreach ($items as $id => $item)
158  {
159  $mob = new ilObjMediaObject($item["mob_id"]);
160  $mob->read();
161  if ($mob->hasPurposeItem($purpose))
162  {
163  if ($html == "") {
164  //$html = "<TABLE cellpadding='1' cellspacing='0'><TR>";
165  $html = " ";
166  }
167  $url = ILIAS_HTTP_PATH."/feed.php?client_id=".rawurlencode(CLIENT_ID)."&"."ref_id=".$_GET["ref_id"]."&purpose=$purpose";
168  $title = $lng->txt("news_feed_url");
169  $icon = ilUtil::getImagePath("rss_icon_".strtolower($purpose).".gif");
170  $target = "_blank";
171 
172  //$row1 .= "<TD><A href='$url' target='$target'><img src='$icon' alt='$title'/></A></TD>";
173  $row1 .= "<A href='$url' target='$target'><img src='$icon' alt='$title'/></A>";
174  if ($this->object->getPublicFiles())
175  {
176  $url = preg_replace("/https?/i","itpc",$url);
177  $title = $lng->txt("news_feed_url");
178  $icon = ilUtil::getImagePath("itunes_icon.gif");
179  //$row2 .= "<TD><A href='$url' target='$target'><img src='$icon' alt='$title'/></A></TD>";
180  $row2 .= "<A href='$url' target='$target'><img src='$icon' alt='$title'/></A>";
181  }
182  break;
183  }
184 
185  }
186  }
187  if ($html != "") {
188  //$html .= $row1."</TR>";
189  $html .= $row1;
190  if ($row2 != "")
191  {
192  $html .= "&nbsp;&nbsp;".$row2;
193  //$html .= "<TR>".$row2."</TR>";
194  }
195  //$html .= "</TABLE>";
196  $table_gui->setHeaderHTML($html);
197  }
198  }
199  }
200 
201  $tpl->setContent($table_gui->getHTML());
202 
203  $tpl->setPermanentLink($this->object->getType(), $this->object->getRefId());
204  }
205 
209  function addCastItemObject()
210  {
211  global $tpl;
212 
213  $this->checkPermission("write");
214 
215  $this->initAddCastItemForm();
216  $tpl->setContent($this->form_gui->getHTML());
217  }
218 
223  {
224  global $tpl;
225  $this->checkPermission("write");
226  $this->initAddCastItemForm("edit");
227  $this->getCastItemValues();
228  $tpl->setContent($this->form_gui->getHTML());
229  }
230 
234  function initAddCastItemForm($a_mode = "create")
235  {
236  global $lng, $ilCtrl;
237 
238  $this->checkPermission("write");
239 
240  $lng->loadLanguageModule("mcst");
241 
242  $news_set = new ilSetting("news");
243  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
244 
245  include("Services/Form/classes/class.ilPropertyFormGUI.php");
246  $this->form_gui = new ilPropertyFormGUI();
247  $this->form_gui->setMultipart(true);
248 
249  // Property Title
250  $text_input = new ilTextInputGUI($lng->txt("title"), "title");
251  $text_input->setMaxLength(200);
252  $this->form_gui->addItem($text_input);
253 
254  // Property Content
255  $text_area = new ilTextAreaInputGUI($lng->txt("description"), "description");
256  $text_area->setRequired(false);
257  $this->form_gui->addItem($text_area);
258 
259  // Property Visibility
260  if ($enable_internal_rss)
261  {
262  $radio_group = new ilRadioGroupInputGUI($lng->txt("access_scope"), "visibility");
263  $radio_option = new ilRadioOption($lng->txt("access_users"), "users");
264  $radio_group->addOption($radio_option);
265  $radio_option = new ilRadioOption($lng->txt("access_public"), "public");
266  $radio_group->addOption($radio_option);
267  $radio_group->setInfo($lng->txt("mcst_visibility_info"));
268  $radio_group->setRequired(true);
269  $radio_group->setValue($this->object->getDefaultAccess() == 0 ? "users" : "public");
270  $this->form_gui->addItem($radio_group);
271  }
272 
273  // Duration
274  $dur = new ilDurationInputGUI($lng->txt("mcst_duration"), "duration");
275  $dur->setInfo($lng->txt("mcst_duration_info"));
276  $dur->setShowDays(false);
277  $dur->setShowHours(true);
278  $dur->setShowSeconds(true);
279  $this->form_gui->addItem($dur);
280 
281  foreach (ilObjMediaCast::$purposes as $purpose)
282  {
284  $section->setTitle($lng->txt("mcst_".strtolower($purpose)."_title"));
285  $this->form_gui->addItem($section);
286  if ($a_mode != "create")
287  {
288  $value = new ilHiddenInputGUI("value_".$purpose);
289  $label = new ilNonEditableValueGUI($lng->txt("value"));
290  $label->setPostVar("label_value_".$purpose);
291  $label->setInfo($lng->txt("mcst_current_value_info"));
292  $this->form_gui->addItem($label);
293  $this->form_gui->addItem($value);
294 
295  }
296  $file = new ilFileInputGUI($lng->txt("file"), "file_".$purpose);
297  $file->setSuffixes($this->purposeSuffixes[$purpose]);
298  $this->form_gui->addItem($file);
299  $text_input = new ilRegExpInputGUI($lng->txt("url"), "url_".$purpose);
300  $text_input->setPattern("/https?\:\/\/.+/i");
301  $text_input->setInfo($lng->txt("mcst_reference_info"));
302  $this->form_gui->addItem($text_input);
303  if ($purpose != "Standard")
304  {
305  $clearCheckBox = new ilCheckboxInputGUI();
306  $clearCheckBox->setPostVar("delete_".$purpose);
307  $clearCheckBox->setTitle($lng->txt("mcst_clear_purpose_title"));
308  $this->form_gui->addItem($clearCheckBox);
309  } else {
310  $mimeTypeSelection = new ilSelectInputGUI();
311  $mimeTypeSelection->setPostVar("mimetype_".$purpose);
312  $mimeTypeSelection->setTitle($lng->txt("mcst_mimetype"));
313  $mimeTypeSelection->setInfo($lng->txt("mcst_mimetype_info"));
314  $options = array($lng->txt("mcst_automatic_detection"));
315  $options = array_merge($options, $this->mimeTypes);
316  $mimeTypeSelection->setOptions($options);
317  $this->form_gui->addItem($mimeTypeSelection);
318  }
319 
320  }
321 
322  // save/cancel button
323  if ($a_mode == "create")
324  {
325  $this->form_gui->setTitle($lng->txt("mcst_add_new_item"));
326  $this->form_gui->addCommandButton("saveCastItem", $lng->txt("save"));
327  }
328  else
329  {
330  $this->form_gui->setTitle($lng->txt("mcst_edit_item"));
331  $this->form_gui->addCommandButton("updateCastItem", $lng->txt("save"));
332  }
333  $this->form_gui->addCommandButton("listItems", $lng->txt("cancel"));
334  $this->form_gui->setFormAction($ilCtrl->getFormAction($this, "saveCastItem"));
335 
336  }
337 
341  public function getCastItemValues()
342  {
343  global $lng;
344  $values = array();
345  $mediaItems = $this->getMediaItems($_GET["item_id"]);
346  if (count ($mediaItems) > 0)
347  {
348  foreach ($mediaItems as $med)
349  {
350  if (!isset ($values["title"]))
351  {
352  // first item, so set title, description, ...
353  $values["title"] = $this->mcst_item->getTitle();
354  $values["description"] = $this->mcst_item->getContent();
355  $values["visibility"] = $this->mcst_item->getVisibility();
356  $length = explode(":", $this->mcst_item->getPlaytime());
357  $values["duration"] = array("hh" => $length[0], "mm" => $length[1], "ss" => $length[2]);
358  }
359 
360  $values["value_".$med->getPurpose()] = (strlen($med->getLocation())> 100) ? "...".substr($med->getLocation(), strlen($med->getLocation()) - 100) : $med->getLocation();
361  $values["label_value_".$med->getPurpose()] = (strlen($med->getLocation())> 100) ? "...".substr($med->getLocation(), strlen($med->getLocation()) - 100) : $med->getLocation();
362  $mimeTypesValuesAsKey = array_flip($this->mimeTypes);
363  if (array_key_exists($med->getFormat(), $mimeTypesValuesAsKey))
364  $values["mimetype_".$med->getPurpose()] = $mimeTypesValuesAsKey[$med->getFormat()]+1;
365  }
366  }
367  foreach (ilObjMediaCast::$purposes as $purpose) {
368  if (!isset ($values["value_".$purpose]))
369  {
370  $values["label_value_".$purpose] = $lng->txt("none");
371  $values["value_".$purpose] = $lng->txt("none");
372  }
373  }
374  $this->form_gui->setValuesByArray($values);
375  }
376 
381  {
382  global $tpl, $ilCtrl, $ilUser, $lng;
383 
384  $this->checkPermission("write");
385 
386  $this->initAddCastItemForm();
387 
388  if ($_POST["url_Standard"] == "" && !$_FILES['file_Standard']['tmp_name']) {
389  ilUtil::sendFailure($lng->txt("msg_input_either_file_or_url"));
390  $this->populateFormFromPost();
391  } else if ($this->form_gui->checkInput())
392  {
393 
394  // create dummy object in db (we need an id)
395  include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
396  $mob = new ilObjMediaObject();
397  $mob->create();
398 
399  //handle standard purpose
400  $file = $this->createMediaItemForPurpose($mob, "Standard");
401 
402  // set title and description
403  // set title to basename of file if left empty
404  $title = $this->form_gui->getInput("title") != "" ? $this->form_gui->getInput("title") : basename($file);
405  $description = $this->form_gui->getInput("description");
406  $mob->setTitle($title);
407  $mob->setDescription($description);
408 
409 
410  // determine duration for standard purpose
411  $duration = $this->getDuration($file);
412 
413  // handle other purposes
414  foreach ($this->additionalPurposes as $purpose)
415  {
416  // check if some purpose has been uploaded
417  $file_gui = $this->form_gui->getInput("file_".$purpose);
418  $url_gui = $this->form_gui->getInput("url_".$purpose);
419  if ($url_gui || $file_gui["size"] > 0)
420  {
421  $this->createMediaItemForPurpose ($mob, $purpose);
422  }
423  }
424 
425  $mob->update();
426 
427  //
428  // @todo: save usage
429  //
430 
431  $news_set = new ilSetting("news");
432  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
433 
434  // create new media cast item
435  include_once("./Services/News/classes/class.ilNewsItem.php");
436  $mc_item = new ilNewsItem();
437  $mc_item->setMobId($mob->getId());
438  $mc_item->setContentType(NEWS_AUDIO);
439  $mc_item->setContextObjId($this->object->getId());
440  $mc_item->setContextObjType($this->object->getType());
441  $mc_item->setUserId($ilUser->getId());
442  $mc_item->setPlaytime($duration);
443  $mc_item->setTitle($title);
444  $mc_item->setContent($description);
445  $mc_item->setLimitation(false);
446  if ($enable_internal_rss)
447  {
448  $mc_item->setVisibility($this->form_gui->getInput("visibility"));
449  }
450  else
451  {
452  $mc_item->setVisibility("users");
453  }
454  $mc_item->create();
455 
456  $ilCtrl->redirect($this, "listItems");
457  }
458  else
459  {
460  $this->populateFormFromPost();
461  }
462  }
463 
470  private function getDuration($file)
471  {
472  $duration = isset($this->form_gui) ? $this->form_gui->getInput("duration") : "";
473  if ($duration["hh"] == 0 && $duration["mm"] == 0 && $duration["ss"] == 0 && is_file($file))
474  {
475  include_once("./Services/MediaObjects/classes/class.ilMediaAnalyzer.php");
476  $ana = new ilMediaAnalyzer();
477  $ana->setFile($file);
478  $ana->analyzeFile();
479  $dur = $ana->getPlaytimeString();
480  $dur = explode(":", $dur);
481  $duration["mm"] = $dur[0];
482  $duration["ss"] = $dur[1];
483  }
484  $duration = str_pad($duration["hh"], 2 , "0", STR_PAD_LEFT).":".
485  str_pad($duration["mm"], 2 , "0", STR_PAD_LEFT).":".
486  str_pad($duration["ss"], 2 , "0", STR_PAD_LEFT);
487  return $duration;
488  }
489 
496  private function createMediaItemForPurpose ($mob, $purpose)
497  {
498  $mediaItem = new ilMediaItem();
499  $mob->addMediaItem($mediaItem);
500  $mediaItem->setPurpose($purpose);
501  return $this->updateMediaItem($mob, $mediaItem);
502  }
503 
511  private function updateMediaItem ($mob, & $mediaItem) {
512  $purpose = $mediaItem->getPurpose();
513  $url_gui = $this->form_gui->getInput ("url_".$purpose);
514  $file_gui = $this->form_gui->getInput ("file_".$purpose);
515  if ($url_gui)
516  {
517  // http
518  $file = $this->form_gui->getInput ("url_".$purpose);
519  $title = basename ($file);
520  $location = $this->form_gui->getInput ("url_".$purpose);
521  $locationType = "Reference";
522  } elseif ($file_gui["size"] > 0){
523  // lokal
524  // determine and create mob directory, move uploaded file to directory
525  $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
526  if (!is_dir($mob_dir))
527  $mob->createDirectory();
528 
529  $file_name = ilUtil::getASCIIFilename($_FILES['file_'.$purpose]['name']);
530  $file_name = str_replace(" ", "_", $file_name);
531 
532  $file = $mob_dir."/".$file_name;
533  $title = $file_name;
534  $locationType = "LocalFile";
535  $location = $title;
536  ilUtil::moveUploadedFile($_FILES['file_'.$purpose]['tmp_name'], $file_name, $file);
537  ilUtil::renameExecutables($mob_dir);
538  }
539 
540  // check if not automatic mimetype detection
541  if ((int) $_POST["mimetype_".$purpose] != 0) {
542  // check if deleted or changed to prevent array index out of bounds!
543  // keep in mind, that first entry was automatic selection!
544  if ((int) $_POST["mimetype_".$purpose]-1 < count ($this->mimeTypes))
545  {
546  $format = $this->mimeTypes[(int) $_POST["mimetype_".$purpose] - 1];
547  $mediaItem->setFormat($format);
548  }
549  } elseif ($mediaItem->getLocation () != "") {
550  $format = ilObjMediaObject::getMimeType($mediaItem->getLocation());
551  $mediaItem->setFormat($format);
552  }
553 
554  if (isset($file))
555  {
556  // get mime type, if not already set!
557  if (!isset($format))
558  {
560  }
561 
562  // set real meta and object data
563  $mediaItem->setFormat($format);
564  $mediaItem->setLocation($location);
565  $mediaItem->setLocationType($locationType);
566  $mediaItem->setHAlign("Left");
567  $mediaItem->setHeight(self::isAudio($format)?0:180);
568  }
569 
570  if ($purpose == "Standard")
571  {
572  if (isset($title))
573  $mob->setTitle ($title);
574  if (isset($format))
575  $mob->setDescription($format);
576  }
577 
578  return $file;
579  }
580 
585  {
586  global $tpl, $lng, $ilCtrl, $ilUser, $log;
587 
588  $this->checkPermission("write");
589 
590  $this->initAddCastItemForm("edit");
591 
592  if ($this->form_gui->checkInput())
593  {
594  // create new media cast item
595  include_once("./Services/News/classes/class.ilNewsItem.php");
596  $mc_item = new ilNewsItem($_GET["item_id"]);
597  $mob_id = $mc_item->getMobId();
598 
599  // create dummy object in db (we need an id)
600  include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
601  $mob = new ilObjMediaObject($mob_id);
602 
603 
604  foreach (ilObjMediaCast::$purposes as $purpose)
605  {
606  if ($this->form_gui->getInput("delete_".$purpose))
607  {
608  $mob->removeMediaItem($purpose);
609  $log->write ("Mcst: deleting purpose $purpose");
610  continue;
611  }
612  $media_item = $mob->getMediaItem($purpose);
613  $url_gui = $this->form_gui->getInput("url_".$purpose);
614  $file_gui = $this->form_gui->getInput("file_".$purpose);
615 
616  if ($media_item == null)
617  {
618  if ($purpose != "Standard" &&
619  ($url_gui || $file_gui["size"]>0))
620  {
621  // check if we added an additional purpose when updating
622  // either by url or by file
623  $file = $this->createMediaItemForPurpose($mob, $purpose);
624  }
625  } else
626  {
627  $file = $this->updateMediaItem($mob, $media_item);
628  }
629 
630  if ($purpose == "Standard")
631  {
632  $duration = $this->getDuration($file);
633  $title = $this->form_gui->getInput("title") != "" ? $this->form_gui->getInput("title") : basename($file);
634  $description = $this->form_gui->getInput("description");
635 
636  $mob->setTitle($title);
637  $mob->setDescription($description);
638 
639  }
640  }
641 
642  // set real meta and object data
643  $mob->update();
644 
645  //
646  // @todo: save usage
647  //
648 
649  $news_set = new ilSetting("news");
650  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
651 
652  $mc_item->setUserId($ilUser->getId());
653  if (isset($duration))
654  {
655  $mc_item->setPlaytime($duration);
656  }
657  $mc_item->setTitle($title);
658  $mc_item->setContent($description);
659  if ($enable_internal_rss)
660  {
661  $mc_item->setVisibility($this->form_gui->getInput("visibility"));
662  }
663  $mc_item->update();
664 
665  $ilCtrl->redirect($this, "listItems");
666  }
667  else
668  {
669  $this->populateFormFromPost();
670  }
671  }
672 
677  {
678  global $ilCtrl, $lng, $tpl;
679 
680  $this->checkPermission("write");
681 
682  if (!is_array($_POST["item_id"]))
683  {
684  $this->listItemsObject();
685  return;
686  }
687 
688  include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
689  $c_gui = new ilConfirmationGUI();
690 
691  // set confirm/cancel commands
692  $c_gui->setFormAction($ilCtrl->getFormAction($this, "deleteItems"));
693  $c_gui->setHeaderText($lng->txt("info_delete_sure"));
694  $c_gui->setCancel($lng->txt("cancel"), "listItems");
695  $c_gui->setConfirm($lng->txt("confirm"), "deleteItems");
696 
697  // add items to delete
698  include_once("./Services/News/classes/class.ilNewsItem.php");
699  foreach($_POST["item_id"] as $item_id)
700  {
701  $item = new ilNewsItem($item_id);
702  $c_gui->addItem("item_id[]", $item_id, $item->getTitle(),
703  ilUtil::getImagePath("icon_mcst.gif"));
704  }
705 
706  $tpl->setContent($c_gui->getHTML());
707  }
708 
712  function deleteItemsObject()
713  {
714  global $ilCtrl;
715 
716  $this->checkPermission("write");
717 
718  // delete all selected news items
719  foreach($_POST["item_id"] as $item_id)
720  {
721  $mc_item = new ilNewsItem($item_id);
722  $mc_item->delete();
723  }
724 
725  $ilCtrl->redirect($this, "listItems");
726  }
727 
732  {
733  global $ilCtrl;
734  $this->checkPermission("read");
735 
736  $mc_item = new ilNewsItem($_GET["item_id"]);
737  $mob = $mc_item->getMobId();
738  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
739  $mob = new ilObjMediaObject($mob);
740  $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
741  $purpose = $_GET["purpose"];
742  $m_item = $mob->getMediaItem($purpose);
743  if ($m_item->getLocationType() != "Reference")
744  {
745  $file = $mob_dir."/".$m_item->getLocation();
746  if (file_exists($file) && is_file($file))
747  {
748  ilUtil::deliverFile($file, $m_item->getLocation());
749  }
750  else {
751  ilUtil::sendFailure("File not found!",true);
752  $ilCtrl->redirect($this, "listItems");
753  }
754  }
755  else
756  {
757  ilUtil::redirect($m_item->getLocation());
758  }
759  exit;
760  }
761 
766  {
767  global $ilCtrl, $lng;
768 
769  $mc_item = new ilNewsItem($_GET["item_id"]);
770  $mob = $mc_item->getMobId();
771  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
772  $mob = new ilObjMediaObject($mob);
773  $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
774  $m_item = $mob->getMediaItem("Standard");
775  $file = $mob_dir."/".$m_item->getLocation();
776  $duration = $this->getDuration($file);
777  if ($duration != "00:00:00")
778  {
779  $mc_item->setPlaytime($duration);
780  $mc_item->update();
781  ilUtil::sendSuccess($lng->txt("mcst_set_playtime"), true);
782  }
783  else
784  {
785  ilUtil::sendFailure($lng->txt("mcst_unable_to_determin_playtime"), true);
786  }
787 
788  $ilCtrl->redirect($this, "listItems");
789  }
790 
796  function infoScreenObject()
797  {
798  $this->checkPermission("visible");
799  $this->ctrl->setCmd("showSummary");
800  $this->ctrl->setCmdClass("ilinfoscreengui");
801  $this->infoScreen();
802  }
803 
807  function infoScreen()
808  {
809  global $ilAccess, $ilUser;
810 
811  if (!$ilAccess->checkAccess("visible", "", $this->object->getRefId()))
812  {
813  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
814  }
815 
816  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
817  $info = new ilInfoScreenGUI($this);
818 
819  $info->enablePrivateNotes();
820 
821  /*
822  $info->enableNews();
823  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]))
824  {
825  //$info->enableNewsEditing();
826  $info->setBlockProperty("news", "settings", true);
827  }*/
828 
829  // general information
830  $this->lng->loadLanguageModule("meta");
831  $this->lng->loadLanguageModule("mcst");
832  $med_items = $this->object->getItemsArray();
833  $info->addSection($this->lng->txt("meta_general"));
834  $info->addProperty($this->lng->txt("mcst_nr_items"),
835  (int) count($med_items));
836 
837  if (count($med_items) > 0)
838  {
839  $cur = current($med_items);
840  $last = ilDatePresentation::formatDate(new ilDateTime($cur["creation_date"], IL_CAL_DATETIME));
841  }
842  else
843  {
844  $last = "-";
845  }
846 
847  $info->addProperty($this->lng->txt("mcst_last_submission"), $last);
848 
849  // forward the command
850  $this->ctrl->forwardCommand($info);
851  }
852 
858  function getTabs(&$tabs_gui)
859  {
860  global $ilCtrl, $ilAccess;
861 
862  // list items
863  if ($ilAccess->checkAccess('read', "", $this->object->getRefId()))
864  {
865  $tabs_gui->addTarget("view_content",
866  $this->ctrl->getLinkTarget($this, "listItems"), array("", "listItems"),
867  array(strtolower(get_class($this)), ""));
868  }
869 
870  // info screen
871  if ($ilAccess->checkAccess('visible', "", $this->object->getRefId()))
872  {
873  $force_active = ($ilCtrl->getNextClass() == "ilinfoscreengui"
874  || $_GET["cmd"] == "infoScreen")
875  ? true
876  : false;
877  $tabs_gui->addTarget("info_short",
878  $this->ctrl->getLinkTargetByClass(
879  "ilinfoscreengui", "showSummary"),
880  "showSummary",
881  "", "", $force_active);
882  }
883 
884  // settings
885  if ($ilAccess->checkAccess('write', "", $this->object->getRefId()))
886  {
887  $tabs_gui->addTarget("settings",
888  $this->ctrl->getLinkTarget($this, "editSettings"), array("editSettings"),
889  array(strtolower(get_class($this)), ""));
890  }
891 
892  // edit permissions
893  if ($ilAccess->checkAccess('edit_permission', "", $this->object->getRefId()))
894  {
895  $tabs_gui->addTarget("perm_settings",
896  $this->ctrl->getLinkTargetByClass("ilpermissiongui", "perm"), array("perm","info","owner"), 'ilpermissiongui');
897  }
898  }
899 
904  {
905  global $tpl;
906 
907  $this->checkPermission("write");
908 
909  $this->initSettingsForm();
910  $tpl->setContent($this->form_gui->getHtml());
911  }
912 
916  function initSettingsForm()
917  {
918  global $tpl, $lng, $ilCtrl;
919 
920  $lng->loadLanguageModule("mcst");
921 
922  include("Services/Form/classes/class.ilPropertyFormGUI.php");
923  $this->form_gui = new ilPropertyFormGUI();
924  $this->form_gui->setTitle($lng->txt("mcst_settings"));
925 
926  // Title
927  $tit = new ilTextInputGUI($lng->txt("title"), "title");
928  $tit->setValue($this->object->getTitle());
929  $tit->setRequired(true);
930  $this->form_gui->addItem($tit);
931 
932  // description
933  $des = new ilTextAreaInputGUI($lng->txt("description"), "description");
934  $des->setValue($this->object->getLongDescription());
935  $this->form_gui->addItem($des);
936 
937  // Online
938  $online = new ilCheckboxInputGUI($lng->txt("online"), "online");
939  $online->setChecked($this->object->getOnline());
940  $this->form_gui->addItem($online);
941 
942  // Downloadable
943  $downloadable = new ilCheckboxInputGUI($lng->txt("mcst_downloadable"), "downloadable");
944  $downloadable->setChecked($this->object->getDownloadable());
945  $downloadable->setInfo($lng->txt("mcst_downloadable_info"));
946  $this->form_gui->addItem($downloadable);
947 
948  $news_set = new ilSetting("news");
949  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
950 
951  //Default Visibility
952  if ($enable_internal_rss)
953  {
954  $radio_group = new ilRadioGroupInputGUI($lng->txt("news_default_visibility"), "defaultaccess");
955  $radio_option = new ilRadioOption($lng->txt("news_visibility_users"), "0");
956  $radio_group->addOption($radio_option);
957  $radio_option = new ilRadioOption($lng->txt("news_visibility_public"), "1");
958  $radio_group->addOption($radio_option);
959  $radio_group->setInfo($lng->txt("news_news_item_visibility_info"));
960  $radio_group->setRequired(false);
961  $radio_group->setValue($this->object->getDefaultAccess());
962  #$ch->addSubItem($radio_group);
963  $this->form_gui->addItem($radio_group);
964 
965  //Extra Feed
966  include_once("./Services/Block/classes/class.ilBlockSetting.php");
967  $public_feed = ilBlockSetting::_lookup("news", "public_feed", 0, $this->object->getId());
968  $ch = new ilCheckboxInputGUI($lng->txt("news_public_feed"), "extra_feed");
969  $ch->setInfo($lng->txt("news_public_feed_info"));
970  $ch->setChecked($public_feed);
971  $this->form_gui->addItem($ch);
972 
973  // Include Files in Pubic Items
974  $incl_files = new ilCheckboxInputGUI($lng->txt("mcst_incl_files_in_rss"), "public_files");
975  $incl_files->setChecked($this->object->getPublicFiles());
976  $incl_files->setInfo($lng->txt("mcst_incl_files_in_rss_info"));
977  #$ch->addSubItem($incl_files);
978  $this->form_gui->addItem($incl_files);
979  }
980 
981  // Form action and save button
982  $this->form_gui->addCommandButton("saveSettings", $lng->txt("save"));
983  $this->form_gui->setFormAction($ilCtrl->getFormAction($this, "saveSettings"));
984  }
985 
990  {
991  global $ilCtrl;
992 
993  $this->checkPermission("write");
994 
995  $this->initSettingsForm();
996  if ($this->form_gui->checkInput())
997  {
998  $news_set = new ilSetting("news");
999  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
1000 
1001  $this->object->setTitle($this->form_gui->getInput("title"));
1002  $this->object->setDescription($this->form_gui->getInput("description"));
1003  $this->object->setOnline($this->form_gui->getInput("online"));
1004  $this->object->setDownloadable($this->form_gui->getInput("downloadable"));
1005 
1006  if ($enable_internal_rss)
1007  {
1008  $this->object->setPublicFiles($this->form_gui->getInput("public_files"));
1009  $this->object->setDefaultAccess($this->form_gui->getInput("defaultaccess"));
1010  }
1011  $this->object->update();
1012 
1013  if ($enable_internal_rss)
1014  {
1015  include_once("./Services/Block/classes/class.ilBlockSetting.php");
1016  ilBlockSetting::_write("news", "public_feed",
1017  $this->form_gui->getInput("extra_feed"),
1018  0, $this->object->getId());
1019  }
1020 
1021  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"),true);
1022  $ilCtrl->redirect($this, "editSettings");
1023  }
1024  else
1025  {
1026  $this->form_gui->setValuesByPost();
1027  $this->tpl->setContent($this->form_gui->getHTML());
1028  }
1029  }
1030 
1031  // add media cast to locator
1032  function addLocatorItems()
1033  {
1034  global $ilLocator;
1035 
1036  if (is_object($this->object))
1037  {
1038  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "listItems"), "", $_GET["ref_id"]);
1039  }
1040  }
1041 
1042  function _goto($a_target)
1043  {
1044  global $ilAccess, $ilErr, $lng;
1045 
1046  if ($ilAccess->checkAccess("read", "", $a_target))
1047  {
1048  $_GET["cmd"] = "listItems";
1049  $_GET["ref_id"] = $a_target;
1050  $_GET["baseClass"] = "ilmediacasthandlergui";
1051  $_GET["cmdClass"] = "ilobjmediacastgui";
1052  include("ilias.php");
1053  exit;
1054  }
1055  else if ($ilAccess->checkAccess("visible", "", $a_target))
1056  {
1057  $_GET["cmd"] = "infoScreen";
1058  $_GET["ref_id"] = $a_target;
1059  include("repository.php");
1060  exit;
1061  }
1062  else if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
1063  {
1064  $_GET["cmd"] = "frameset";
1065  $_GET["target"] = "";
1066  $_GET["ref_id"] = ROOT_FOLDER_ID;
1067  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
1069  include("repository.php");
1070  exit;
1071  }
1072 
1073  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
1074 
1075  }
1076 
1083  protected static function isAudio($extension) {
1084  return strpos($extension,"audio") !== false;
1085  }
1086 
1093  protected function getMediaItem ($id) {
1094  include_once("./Services/News/classes/class.ilNewsItem.php");
1095  $this->mcst_item = new ilNewsItem($id);
1096  // create dummy object in db (we need an id)
1097  include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
1098  $mob = new ilObjMediaObject($this->mcst_item->getMobId());
1099  return $mob->getMediaItem("Standard");
1100  }
1101 
1108  protected function getMediaItems ($id) {
1109  include_once("./Services/News/classes/class.ilNewsItem.php");
1110  $this->mcst_item = new ilNewsItem($id);
1111  // create dummy object in db (we need an id)
1112  include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
1113  $mob = new ilObjMediaObject($this->mcst_item->getMobId());
1114  return $mob->getMediaItems();
1115  }
1116 
1117  private function populateFormFromPost()
1118  {
1119  global $tpl;
1120  //issue: we have to display the current settings
1121  // problem: POST does not contain values of disabled textfields
1122  // solution: use hidden field and label to display-> here we need to synchronize the labels
1123  // with the values from the hidden fields.
1124  foreach (ilObjMediaCast::$purposes as $purpose)
1125  {
1126  if ($_POST["value_".$purpose])
1127  {
1128  $_POST["label_value_".$purpose] = $_POST["value_".$purpose];
1129  }
1130  }
1131 
1132  $this->form_gui->setValuesByPost();
1133  $tpl->setContent($this->form_gui->getHTML());
1134  }
1135 }
1136 ?>