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