ILIAS  eassessment Revision 61809
 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, $ilTabs;
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 "ilexportgui":
60 // $this->prepareOutput();
61  $ilTabs->activateTab("export");
62  include_once("./Services/Export/classes/class.ilExportGUI.php");
63  $exp_gui = new ilExportGUI($this);
64  $exp_gui->addFormat("xml");
65  $ret = $this->ctrl->forwardCommand($exp_gui);
66 // $this->tpl->show();
67  break;
68 
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  default:
78  if(!$cmd)
79  {
80  $cmd = "infoScreen";
81  }
82  $cmd .= "Object";
83  if ($cmd != "infoScreenObject")
84  {
85  $this->checkPermission("read");
86  }
87  else
88  {
89  $this->checkPermission("visible");
90  }
91  $this->$cmd();
92 
93  break;
94  }
95 
96  return true;
97  }
98 
103  function createObject()
104  {
105  global $rbacsystem;
106 
107  $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
108 
109  if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type))
110  {
111  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
112  }
113  else
114  {
115  global $tpl;
116 
117  $this->initCreationForm();
118  $html1 = $this->form->getHtml();
119 
120  $this->initImportForm("mcst");
121  $html2 = $this->form->getHTML();
122 
123  $tpl->setContent($html1."<br/>".$html2);
124  }
125  }
126 
130  function initCreationForm()
131  {
132  global $tpl, $lng, $ilCtrl, $ilTabs;
133 
134  $lng->loadLanguageModule("mcst");
135  $ilTabs->activateTab("settings");
136 
137  include("Services/Form/classes/class.ilPropertyFormGUI.php");
138  $this->form = new ilPropertyFormGUI();
139 
140  // Title
141  $tit = new ilTextInputGUI($lng->txt("title"), "title");
142  $tit->setRequired(true);
143  $this->form->addItem($tit);
144 
145  // Description
146  $des = new ilTextAreaInputGUI($lng->txt("description"), "description");
147  $this->form->addItem($des);
148 
149  $this->form->setTitle($lng->txt("mcst_new"));
150  $this->form->addCommandButton("save", $lng->txt("mcst_add"));
151  $this->form->addCommandButton("cancel", $lng->txt("cancel"));
152 
153  // set values
154  $ilCtrl->setParameter($this, "new_type", "mcst");
155 
156  $this->form->setFormAction($ilCtrl->getFormAction($this, "save"));
157  }
158 
159 
165  public function initImportForm($a_new_type = "")
166  {
167  global $lng, $ilCtrl;
168 
169  $lng->loadLanguageModule("mcst");
170 
171  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
172  $this->form = new ilPropertyFormGUI();
173  $this->form->setTarget("_top");
174 
175  // Import file
176  include_once("./Services/Form/classes/class.ilFileInputGUI.php");
177  $fi = new ilFileInputGUI($lng->txt("import_file"), "importfile");
178  $fi->setSuffixes(array("zip"));
179  $fi->setRequired(true);
180  $this->form->addItem($fi);
181 
182  $this->form->addCommandButton("importFile", $lng->txt("import"));
183  $this->form->addCommandButton("cancel", $lng->txt("cancel"));
184  $this->form->setTitle($lng->txt($a_new_type."_import"));
185 
186  $this->form->setFormAction($ilCtrl->getFormAction($this));
187  }
188 
194  function importFileObject()
195  {
196  global $rbacsystem, $objDefinition, $tpl, $lng;
197 
198  $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
199 
200  // create permission is already checked in createObject. This check here is done to prevent hacking attempts
201  if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type))
202  {
203  $this->ilias->raiseError($this->lng->txt("no_create_permission"), $this->ilias->error_obj->MESSAGE);
204  }
205  $this->ctrl->setParameter($this, "new_type", $new_type);
206  $this->initImportForm($new_type);
207  if ($this->form->checkInput())
208  {
209  // todo: make some check on manifest file
210  include_once("./Services/Export/classes/class.ilImport.php");
211  $imp = new ilImport((int) $_GET['ref_id']);
212  $new_id = $imp->importObject($newObj, $_FILES["importfile"]["tmp_name"],
213  $_FILES["importfile"]["name"], $new_type);
214 
215  // put new object id into tree
216  if ($new_id > 0)
217  {
218  $newObj = ilObjectFactory::getInstanceByObjId($new_id);
219  $newObj->createReference();
220  $newObj->putInTree($_GET["ref_id"]);
221  $newObj->setPermissions($_GET["ref_id"]);
222  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
223  $this->afterSave($newObj);
224  }
225  return;
226  }
227 
228  $this->form->setValuesByPost();
229  $tpl->setContent($this->form->getHtml());
230  }
231 
236  function afterSave($newObj)
237  {
238  // always send a message
239  ilUtil::sendSuccess($this->lng->txt("object_added"),true);
240 
241  ilUtil::redirect("ilias.php?baseClass=ilMediaCastHandlerGUI&ref_id=".$newObj->getRefId()."&cmd=editSettings");
242  }
243 
244 
249  function saveObject()
250  {
251  global $tpl;
252 
253  $this->initCreationForm();
254  if ($this->form->checkInput())
255  {
256  $_POST["Fobject"]["title"] = $_POST["title"];
257  $_POST["Fobject"]["desc"] = $_POST["description"];
258 
259  // create and insert forum in objecttree
260  $newObj = parent::saveObject();
261 
262  // put here object specific stuff
263 
264  // always send a message
265  ilUtil::sendSuccess($this->lng->txt("object_added"),true);
266 
267  ilUtil::redirect("ilias.php?baseClass=ilMediaCastHandlerGUI&ref_id=".$newObj->getRefId()."&cmd=editSettings");
268  }
269  $this->form->setValuesByPost();
270  $tpl->setContent($this->form->getHtml());
271  }
272 
273 
277  function listItemsObject()
278  {
279  global $tpl, $lng, $ilAccess, $ilTabs;
280 
281  $this->checkPermission("read");
282  $ilTabs->activateTab("id_content");
283 
284  $med_items = $this->object->getItemsArray();
285 
286  include_once("./Modules/MediaCast/classes/class.ilMediaCastTableGUI.php");
287  $table_gui = new ilMediaCastTableGUI($this, "listItems");
288 
289  $table_gui->setTitle($lng->txt("mcst_media_cast"));
290  $table_gui->setData($med_items);
291 
292  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]))
293  {
294  $table_gui->addCommandButton("addCastItem", $lng->txt("add"));
295  $table_gui->addMultiCommand("confirmDeletionItems", $lng->txt("delete"));
296  $table_gui->setSelectAllCheckbox("item_id");
297  }
298 
299  include_once("./Services/Block/classes/class.ilBlockSetting.php");
300  $public_feed = ilBlockSetting::_lookup("news", "public_feed",
301  0, $this->object->getId());
302 
303  // rss icon/link
304  if ($public_feed)
305  {
306  $news_set = new ilSetting("news");
307  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
308 
309 
310  if ($enable_internal_rss)
311  {
312  // create dummy object in db (we need an id)
313  $items = $this->object->getItemsArray();
314  include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
315  $html = "";
316  foreach (ilObjMediaCast::$purposes as $purpose)
317  {
318 
319  foreach ($items as $id => $item)
320  {
321  $mob = new ilObjMediaObject($item["mob_id"]);
322  $mob->read();
323  if ($mob->hasPurposeItem($purpose))
324  {
325  if ($html == "") {
326  //$html = "<TABLE cellpadding='1' cellspacing='0'><TR>";
327  $html = " ";
328  }
329  $url = ILIAS_HTTP_PATH."/feed.php?client_id=".rawurlencode(CLIENT_ID)."&"."ref_id=".$_GET["ref_id"]."&purpose=$purpose";
330  $title = $lng->txt("news_feed_url");
331  $icon = ilUtil::getImagePath("rss_icon_".strtolower($purpose).".gif");
332  $target = "_blank";
333 
334  //$row1 .= "<TD><A href='$url' target='$target'><img src='$icon' alt='$title'/></A></TD>";
335  $row1 .= "<A href='$url' target='$target'><img src='$icon' alt='$title'/></A>";
336  if ($this->object->getPublicFiles())
337  {
338  $url = preg_replace("/https?/i","itpc",$url);
339  $title = $lng->txt("news_feed_url");
340  $icon = ilUtil::getImagePath("itunes_icon.gif");
341  //$row2 .= "<TD><A href='$url' target='$target'><img src='$icon' alt='$title'/></A></TD>";
342  $row2 .= "<A href='$url' target='$target'><img src='$icon' alt='$title'/></A>";
343  }
344  break;
345  }
346 
347  }
348  }
349  if ($html != "") {
350  //$html .= $row1."</TR>";
351  $html .= $row1;
352  if ($row2 != "")
353  {
354  $html .= "&nbsp;&nbsp;".$row2;
355  //$html .= "<TR>".$row2."</TR>";
356  }
357  //$html .= "</TABLE>";
358  $table_gui->setHeaderHTML($html);
359  }
360  }
361  }
362 
363  $tpl->setContent($table_gui->getHTML());
364 
365  $tpl->setPermanentLink($this->object->getType(), $this->object->getRefId());
366  }
367 
371  function addCastItemObject()
372  {
373  global $tpl;
374 
375  $this->checkPermission("write");
376 
377  $this->initAddCastItemForm();
378  $tpl->setContent($this->form_gui->getHTML());
379  }
380 
385  {
386  global $tpl;
387  $this->checkPermission("write");
388  $this->initAddCastItemForm("edit");
389  $this->getCastItemValues();
390  $tpl->setContent($this->form_gui->getHTML());
391  }
392 
396  function initAddCastItemForm($a_mode = "create")
397  {
398  global $lng, $ilCtrl, $ilTabs;
399 
400  $this->checkPermission("write");
401  $ilTabs->activateTab("id_content");
402 
403  $lng->loadLanguageModule("mcst");
404 
405  $news_set = new ilSetting("news");
406  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
407 
408  include("Services/Form/classes/class.ilPropertyFormGUI.php");
409  $this->form_gui = new ilPropertyFormGUI();
410  $this->form_gui->setMultipart(true);
411 
412  // Property Title
413  $text_input = new ilTextInputGUI($lng->txt("title"), "title");
414  $text_input->setMaxLength(200);
415  $this->form_gui->addItem($text_input);
416 
417  // Property Content
418  $text_area = new ilTextAreaInputGUI($lng->txt("description"), "description");
419  $text_area->setRequired(false);
420  $this->form_gui->addItem($text_area);
421 
422  // Property Visibility
423  if ($enable_internal_rss)
424  {
425  $radio_group = new ilRadioGroupInputGUI($lng->txt("access_scope"), "visibility");
426  $radio_option = new ilRadioOption($lng->txt("access_users"), "users");
427  $radio_group->addOption($radio_option);
428  $radio_option = new ilRadioOption($lng->txt("access_public"), "public");
429  $radio_group->addOption($radio_option);
430  $radio_group->setInfo($lng->txt("mcst_visibility_info"));
431  $radio_group->setRequired(true);
432  $radio_group->setValue($this->object->getDefaultAccess() == 0 ? "users" : "public");
433  $this->form_gui->addItem($radio_group);
434  }
435 
436  // Duration
437  $dur = new ilDurationInputGUI($lng->txt("mcst_duration"), "duration");
438  $dur->setInfo($lng->txt("mcst_duration_info"));
439  $dur->setShowDays(false);
440  $dur->setShowHours(true);
441  $dur->setShowSeconds(true);
442  $this->form_gui->addItem($dur);
443 
444  foreach (ilObjMediaCast::$purposes as $purpose)
445  {
446  $section = new ilFormSectionHeaderGUI();
447  $section->setTitle($lng->txt("mcst_".strtolower($purpose)."_title"));
448  $this->form_gui->addItem($section);
449  if ($a_mode != "create")
450  {
451  $value = new ilHiddenInputGUI("value_".$purpose);
452  $label = new ilNonEditableValueGUI($lng->txt("value"));
453  $label->setPostVar("label_value_".$purpose);
454  $label->setInfo($lng->txt("mcst_current_value_info"));
455  $this->form_gui->addItem($label);
456  $this->form_gui->addItem($value);
457 
458  }
459  $file = new ilFileInputGUI($lng->txt("file"), "file_".$purpose);
460  $file->setSuffixes($this->purposeSuffixes[$purpose]);
461  $this->form_gui->addItem($file);
462  $text_input = new ilRegExpInputGUI($lng->txt("url"), "url_".$purpose);
463  $text_input->setPattern("/https?\:\/\/.+/i");
464  $text_input->setInfo($lng->txt("mcst_reference_info"));
465  $this->form_gui->addItem($text_input);
466  if ($purpose != "Standard")
467  {
468  $clearCheckBox = new ilCheckboxInputGUI();
469  $clearCheckBox->setPostVar("delete_".$purpose);
470  $clearCheckBox->setTitle($lng->txt("mcst_clear_purpose_title"));
471  $this->form_gui->addItem($clearCheckBox);
472  } else {
473  $mimeTypeSelection = new ilSelectInputGUI();
474  $mimeTypeSelection->setPostVar("mimetype_".$purpose);
475  $mimeTypeSelection->setTitle($lng->txt("mcst_mimetype"));
476  $mimeTypeSelection->setInfo($lng->txt("mcst_mimetype_info"));
477  $options = array($lng->txt("mcst_automatic_detection"));
478  $options = array_merge($options, $this->mimeTypes);
479  $mimeTypeSelection->setOptions($options);
480  $this->form_gui->addItem($mimeTypeSelection);
481  }
482 
483  }
484 
485  // save/cancel button
486  if ($a_mode == "create")
487  {
488  $this->form_gui->setTitle($lng->txt("mcst_add_new_item"));
489  $this->form_gui->addCommandButton("saveCastItem", $lng->txt("save"));
490  }
491  else
492  {
493  $this->form_gui->setTitle($lng->txt("mcst_edit_item"));
494  $this->form_gui->addCommandButton("updateCastItem", $lng->txt("save"));
495  }
496  $this->form_gui->addCommandButton("listItems", $lng->txt("cancel"));
497  $this->form_gui->setFormAction($ilCtrl->getFormAction($this, "saveCastItem"));
498 
499  }
500 
504  public function getCastItemValues()
505  {
506  global $lng;
507  $values = array();
508  $mediaItems = $this->getMediaItems($_GET["item_id"]);
509  if (count ($mediaItems) > 0)
510  {
511  foreach ($mediaItems as $med)
512  {
513  if (!isset ($values["title"]))
514  {
515  // first item, so set title, description, ...
516  $values["title"] = $this->mcst_item->getTitle();
517  $values["description"] = $this->mcst_item->getContent();
518  $values["visibility"] = $this->mcst_item->getVisibility();
519  $length = explode(":", $this->mcst_item->getPlaytime());
520  $values["duration"] = array("hh" => $length[0], "mm" => $length[1], "ss" => $length[2]);
521  }
522 
523  $values["value_".$med->getPurpose()] = (strlen($med->getLocation())> 100) ? "...".substr($med->getLocation(), strlen($med->getLocation()) - 100) : $med->getLocation();
524  $values["label_value_".$med->getPurpose()] = (strlen($med->getLocation())> 100) ? "...".substr($med->getLocation(), strlen($med->getLocation()) - 100) : $med->getLocation();
525  $mimeTypesValuesAsKey = array_flip($this->mimeTypes);
526  if (array_key_exists($med->getFormat(), $mimeTypesValuesAsKey))
527  $values["mimetype_".$med->getPurpose()] = $mimeTypesValuesAsKey[$med->getFormat()]+1;
528  }
529  }
530  foreach (ilObjMediaCast::$purposes as $purpose) {
531  if (!isset ($values["value_".$purpose]))
532  {
533  $values["label_value_".$purpose] = $lng->txt("none");
534  $values["value_".$purpose] = $lng->txt("none");
535  }
536  }
537  $this->form_gui->setValuesByArray($values);
538  }
539 
544  {
545  global $tpl, $ilCtrl, $ilUser, $lng, $ilTabs;
546 
547  $this->checkPermission("write");
548  $ilTabs->activateTab("id_content");
549 
550  $this->initAddCastItemForm();
551 
552  if ($_POST["url_Standard"] == "" && !$_FILES['file_Standard']['tmp_name']) {
553  ilUtil::sendFailure($lng->txt("msg_input_either_file_or_url"));
554  $this->populateFormFromPost();
555  } else if ($this->form_gui->checkInput())
556  {
557 
558  // create dummy object in db (we need an id)
559  include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
560  $mob = new ilObjMediaObject();
561  $mob->create();
562 
563  //handle standard purpose
564  $file = $this->createMediaItemForPurpose($mob, "Standard");
565 
566  // set title and description
567  // set title to basename of file if left empty
568  $title = $this->form_gui->getInput("title") != "" ? $this->form_gui->getInput("title") : basename($file);
569  $description = $this->form_gui->getInput("description");
570  $mob->setTitle($title);
571  $mob->setDescription($description);
572 
573 
574  // determine duration for standard purpose
575  $duration = $this->getDuration($file);
576 
577  // handle other purposes
578  foreach ($this->additionalPurposes as $purpose)
579  {
580  // check if some purpose has been uploaded
581  $file_gui = $this->form_gui->getInput("file_".$purpose);
582  $url_gui = $this->form_gui->getInput("url_".$purpose);
583  if ($url_gui || $file_gui["size"] > 0)
584  {
585  $this->createMediaItemForPurpose ($mob, $purpose);
586  }
587  }
588 
589  $mob->update();
590 
591  //
592  // @todo: save usage
593  //
594 
595  $news_set = new ilSetting("news");
596  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
597 
598  // create new media cast item
599  include_once("./Services/News/classes/class.ilNewsItem.php");
600  $mc_item = new ilNewsItem();
601  $mc_item->setMobId($mob->getId());
602  $mc_item->setContentType(NEWS_AUDIO);
603  $mc_item->setContextObjId($this->object->getId());
604  $mc_item->setContextObjType($this->object->getType());
605  $mc_item->setUserId($ilUser->getId());
606  $mc_item->setPlaytime($duration);
607  $mc_item->setTitle($title);
608  $mc_item->setContent($description);
609  $mc_item->setLimitation(false);
610  if ($enable_internal_rss)
611  {
612  $mc_item->setVisibility($this->form_gui->getInput("visibility"));
613  }
614  else
615  {
616  $mc_item->setVisibility("users");
617  }
618  $mc_item->create();
619 
620  $ilCtrl->redirect($this, "listItems");
621  }
622  else
623  {
624  $this->populateFormFromPost();
625  }
626  }
627 
634  private function getDuration($file)
635  {
636  $duration = isset($this->form_gui) ? $this->form_gui->getInput("duration") : "";
637  if ($duration["hh"] == 0 && $duration["mm"] == 0 && $duration["ss"] == 0 && is_file($file))
638  {
639  include_once("./Services/MediaObjects/classes/class.ilMediaAnalyzer.php");
640  $ana = new ilMediaAnalyzer();
641  $ana->setFile($file);
642  $ana->analyzeFile();
643  $dur = $ana->getPlaytimeString();
644  $dur = explode(":", $dur);
645  $duration["mm"] = $dur[0];
646  $duration["ss"] = $dur[1];
647  }
648  $duration = str_pad($duration["hh"], 2 , "0", STR_PAD_LEFT).":".
649  str_pad($duration["mm"], 2 , "0", STR_PAD_LEFT).":".
650  str_pad($duration["ss"], 2 , "0", STR_PAD_LEFT);
651  return $duration;
652  }
653 
660  private function createMediaItemForPurpose ($mob, $purpose)
661  {
662  $mediaItem = new ilMediaItem();
663  $mob->addMediaItem($mediaItem);
664  $mediaItem->setPurpose($purpose);
665  return $this->updateMediaItem($mob, $mediaItem);
666  }
667 
675  private function updateMediaItem ($mob, & $mediaItem) {
676  $purpose = $mediaItem->getPurpose();
677  $url_gui = $this->form_gui->getInput ("url_".$purpose);
678  $file_gui = $this->form_gui->getInput ("file_".$purpose);
679  if ($url_gui)
680  {
681  // http
682  $file = $this->form_gui->getInput ("url_".$purpose);
683  $title = basename ($file);
684  $location = $this->form_gui->getInput ("url_".$purpose);
685  $locationType = "Reference";
686  } elseif ($file_gui["size"] > 0){
687  // lokal
688  // determine and create mob directory, move uploaded file to directory
689  $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
690  if (!is_dir($mob_dir))
691  $mob->createDirectory();
692 
693  $file_name = ilUtil::getASCIIFilename($_FILES['file_'.$purpose]['name']);
694  $file_name = str_replace(" ", "_", $file_name);
695 
696  $file = $mob_dir."/".$file_name;
697  $title = $file_name;
698  $locationType = "LocalFile";
699  $location = $title;
700  ilUtil::moveUploadedFile($_FILES['file_'.$purpose]['tmp_name'], $file_name, $file);
701  ilUtil::renameExecutables($mob_dir);
702  }
703 
704  // check if not automatic mimetype detection
705  if ((int) $_POST["mimetype_".$purpose] != 0) {
706  // check if deleted or changed to prevent array index out of bounds!
707  // keep in mind, that first entry was automatic selection!
708  if ((int) $_POST["mimetype_".$purpose]-1 < count ($this->mimeTypes))
709  {
710  $format = $this->mimeTypes[(int) $_POST["mimetype_".$purpose] - 1];
711  $mediaItem->setFormat($format);
712  }
713  } elseif ($mediaItem->getLocation () != "") {
714  $format = ilObjMediaObject::getMimeType($mediaItem->getLocation());
715  $mediaItem->setFormat($format);
716  }
717 
718  if (isset($file))
719  {
720  // get mime type, if not already set!
721  if (!isset($format))
722  {
724  }
725 
726  // set real meta and object data
727  $mediaItem->setFormat($format);
728  $mediaItem->setLocation($location);
729  $mediaItem->setLocationType($locationType);
730  $mediaItem->setHAlign("Left");
731  $mediaItem->setHeight(self::isAudio($format)?0:180);
732  }
733 
734  if ($purpose == "Standard")
735  {
736  if (isset($title))
737  $mob->setTitle ($title);
738  if (isset($format))
739  $mob->setDescription($format);
740  }
741 
742  return $file;
743  }
744 
749  {
750  global $tpl, $lng, $ilCtrl, $ilUser, $log;
751 
752  $this->checkPermission("write");
753 
754  $this->initAddCastItemForm("edit");
755 
756  if ($this->form_gui->checkInput())
757  {
758  // create new media cast item
759  include_once("./Services/News/classes/class.ilNewsItem.php");
760  $mc_item = new ilNewsItem($_GET["item_id"]);
761  $mob_id = $mc_item->getMobId();
762 
763  // create dummy object in db (we need an id)
764  include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
765  $mob = new ilObjMediaObject($mob_id);
766 
767 
768  foreach (ilObjMediaCast::$purposes as $purpose)
769  {
770  if ($this->form_gui->getInput("delete_".$purpose))
771  {
772  $mob->removeMediaItem($purpose);
773  $log->write ("Mcst: deleting purpose $purpose");
774  continue;
775  }
776  $media_item = $mob->getMediaItem($purpose);
777  $url_gui = $this->form_gui->getInput("url_".$purpose);
778  $file_gui = $this->form_gui->getInput("file_".$purpose);
779 
780  if ($media_item == null)
781  {
782  if ($purpose != "Standard" &&
783  ($url_gui || $file_gui["size"]>0))
784  {
785  // check if we added an additional purpose when updating
786  // either by url or by file
787  $file = $this->createMediaItemForPurpose($mob, $purpose);
788  }
789  } else
790  {
791  $file = $this->updateMediaItem($mob, $media_item);
792  }
793 
794  if ($purpose == "Standard")
795  {
796  $duration = $this->getDuration($file);
797  $title = $this->form_gui->getInput("title") != "" ? $this->form_gui->getInput("title") : basename($file);
798  $description = $this->form_gui->getInput("description");
799 
800  $mob->setTitle($title);
801  $mob->setDescription($description);
802 
803  }
804  }
805 
806  // set real meta and object data
807  $mob->update();
808 
809  //
810  // @todo: save usage
811  //
812 
813  $news_set = new ilSetting("news");
814  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
815 
816  $mc_item->setUserId($ilUser->getId());
817  if (isset($duration))
818  {
819  $mc_item->setPlaytime($duration);
820  }
821  $mc_item->setTitle($title);
822  $mc_item->setContent($description);
823  if ($enable_internal_rss)
824  {
825  $mc_item->setVisibility($this->form_gui->getInput("visibility"));
826  }
827  $mc_item->update();
828 
829  $ilCtrl->redirect($this, "listItems");
830  }
831  else
832  {
833  $this->populateFormFromPost();
834  }
835  }
836 
841  {
842  global $ilCtrl, $lng, $tpl, $ilTabs;
843 
844  $this->checkPermission("write");
845  $ilTabs->activateTab("id_content");
846 
847  if (!is_array($_POST["item_id"]))
848  {
849  $this->listItemsObject();
850  return;
851  }
852 
853  include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
854  $c_gui = new ilConfirmationGUI();
855 
856  // set confirm/cancel commands
857  $c_gui->setFormAction($ilCtrl->getFormAction($this, "deleteItems"));
858  $c_gui->setHeaderText($lng->txt("info_delete_sure"));
859  $c_gui->setCancel($lng->txt("cancel"), "listItems");
860  $c_gui->setConfirm($lng->txt("confirm"), "deleteItems");
861 
862  // add items to delete
863  include_once("./Services/News/classes/class.ilNewsItem.php");
864  foreach($_POST["item_id"] as $item_id)
865  {
866  $item = new ilNewsItem($item_id);
867  $c_gui->addItem("item_id[]", $item_id, $item->getTitle(),
868  ilUtil::getImagePath("icon_mcst.gif"));
869  }
870 
871  $tpl->setContent($c_gui->getHTML());
872  }
873 
877  function deleteItemsObject()
878  {
879  global $ilCtrl;
880 
881  $this->checkPermission("write");
882 
883  // delete all selected news items
884  foreach($_POST["item_id"] as $item_id)
885  {
886  $mc_item = new ilNewsItem($item_id);
887  $mc_item->delete();
888  }
889 
890  $ilCtrl->redirect($this, "listItems");
891  }
892 
897  {
898  global $ilCtrl;
899  $this->checkPermission("read");
900 
901  $mc_item = new ilNewsItem($_GET["item_id"]);
902  $mob = $mc_item->getMobId();
903  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
904  $mob = new ilObjMediaObject($mob);
905  $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
906  $purpose = $_GET["purpose"];
907  $m_item = $mob->getMediaItem($purpose);
908  if ($m_item->getLocationType() != "Reference")
909  {
910  $file = $mob_dir."/".$m_item->getLocation();
911  if (file_exists($file) && is_file($file))
912  {
913  ilUtil::deliverFile($file, $m_item->getLocation());
914  }
915  else {
916  ilUtil::sendFailure("File not found!",true);
917  $ilCtrl->redirect($this, "listItems");
918  }
919  }
920  else
921  {
922  ilUtil::redirect($m_item->getLocation());
923  }
924  exit;
925  }
926 
931  {
932  global $ilCtrl, $lng;
933 
934  $mc_item = new ilNewsItem($_GET["item_id"]);
935  $mob = $mc_item->getMobId();
936  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
937  $mob = new ilObjMediaObject($mob);
938  $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
939  $m_item = $mob->getMediaItem("Standard");
940  $file = $mob_dir."/".$m_item->getLocation();
941  $duration = $this->getDuration($file);
942  if ($duration != "00:00:00")
943  {
944  $mc_item->setPlaytime($duration);
945  $mc_item->update();
946  ilUtil::sendSuccess($lng->txt("mcst_set_playtime"), true);
947  }
948  else
949  {
950  ilUtil::sendFailure($lng->txt("mcst_unable_to_determin_playtime"), true);
951  }
952 
953  $ilCtrl->redirect($this, "listItems");
954  }
955 
961  function infoScreenObject()
962  {
963  $this->checkPermission("visible");
964  $this->ctrl->setCmd("showSummary");
965  $this->ctrl->setCmdClass("ilinfoscreengui");
966  $this->infoScreen();
967  }
968 
972  function infoScreen()
973  {
974  global $ilAccess, $ilUser, $ilTabs;
975 
976  $ilTabs->activateTab("id_info");
977 
978  if (!$ilAccess->checkAccess("visible", "", $this->object->getRefId()))
979  {
980  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
981  }
982 
983  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
984  $info = new ilInfoScreenGUI($this);
985 
986  $info->enablePrivateNotes();
987 
988  /*
989  $info->enableNews();
990  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]))
991  {
992  //$info->enableNewsEditing();
993  $info->setBlockProperty("news", "settings", true);
994  }*/
995 
996  // general information
997  $this->lng->loadLanguageModule("meta");
998  $this->lng->loadLanguageModule("mcst");
999  $med_items = $this->object->getItemsArray();
1000  $info->addSection($this->lng->txt("meta_general"));
1001  $info->addProperty($this->lng->txt("mcst_nr_items"),
1002  (int) count($med_items));
1003 
1004  if (count($med_items) > 0)
1005  {
1006  $cur = current($med_items);
1007  $last = ilDatePresentation::formatDate(new ilDateTime($cur["creation_date"], IL_CAL_DATETIME));
1008  }
1009  else
1010  {
1011  $last = "-";
1012  }
1013 
1014  $info->addProperty($this->lng->txt("mcst_last_submission"), $last);
1015 
1016  // forward the command
1017  $this->ctrl->forwardCommand($info);
1018  }
1019 
1024  function setTabs()
1025  {
1026  global $ilAccess, $ilTabs, $lng;
1027 
1028  // list items
1029  if ($ilAccess->checkAccess('read', "", $this->object->getRefId()))
1030  {
1031  $ilTabs->addTab("id_content",
1032  $lng->txt("content"),
1033  $this->ctrl->getLinkTarget($this, "listItems"));
1034  }
1035 
1036  // info screen
1037  if ($ilAccess->checkAccess('visible', "", $this->object->getRefId()))
1038  {
1039  $ilTabs->addTab("id_info",
1040  $lng->txt("info_short"),
1041  $this->ctrl->getLinkTargetByClass("ilinfoscreengui", "showSummary"));
1042  }
1043 
1044  // settings
1045  if ($ilAccess->checkAccess('write', "", $this->object->getRefId()))
1046  {
1047  $ilTabs->addTab("id_settings",
1048  $lng->txt("settings"),
1049  $this->ctrl->getLinkTarget($this, "editSettings"));
1050  }
1051 
1052  // export
1053  if ($ilAccess->checkAccess("write", "", $this->object->getRefId()))
1054  {
1055  $ilTabs->addTab("export",
1056  $lng->txt("export"),
1057  $this->ctrl->getLinkTargetByClass("ilexportgui", ""));
1058  }
1059 
1060  // edit permissions
1061  if ($ilAccess->checkAccess('edit_permission', "", $this->object->getRefId()))
1062  {
1063  $ilTabs->addTab("id_permissions",
1064  $lng->txt("perm_settings"),
1065  $this->ctrl->getLinkTargetByClass("ilpermissiongui", "perm"));
1066  }
1067  }
1068 
1073  {
1074  global $tpl, $ilTabs;
1075 
1076  $this->checkPermission("write");
1077  $ilTabs->activateTab("id_settings");
1078 
1079  $this->initSettingsForm();
1080  $tpl->setContent($this->form_gui->getHtml());
1081  }
1082 
1086  function initSettingsForm()
1087  {
1088  global $tpl, $lng, $ilCtrl;
1089 
1090  $lng->loadLanguageModule("mcst");
1091 
1092  include("Services/Form/classes/class.ilPropertyFormGUI.php");
1093  $this->form_gui = new ilPropertyFormGUI();
1094  $this->form_gui->setTitle($lng->txt("mcst_settings"));
1095 
1096  // Title
1097  $tit = new ilTextInputGUI($lng->txt("title"), "title");
1098  $tit->setValue($this->object->getTitle());
1099  $tit->setRequired(true);
1100  $this->form_gui->addItem($tit);
1101 
1102  // description
1103  $des = new ilTextAreaInputGUI($lng->txt("description"), "description");
1104  $des->setValue($this->object->getLongDescription());
1105  $this->form_gui->addItem($des);
1106 
1107  // Online
1108  $online = new ilCheckboxInputGUI($lng->txt("online"), "online");
1109  $online->setChecked($this->object->getOnline());
1110  $this->form_gui->addItem($online);
1111 
1112  // Downloadable
1113  $downloadable = new ilCheckboxInputGUI($lng->txt("mcst_downloadable"), "downloadable");
1114  $downloadable->setChecked($this->object->getDownloadable());
1115  $downloadable->setInfo($lng->txt("mcst_downloadable_info"));
1116  $this->form_gui->addItem($downloadable);
1117 
1118  $news_set = new ilSetting("news");
1119  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
1120 
1121  //Default Visibility
1122  if ($enable_internal_rss)
1123  {
1124  $radio_group = new ilRadioGroupInputGUI($lng->txt("news_default_visibility"), "defaultaccess");
1125  $radio_option = new ilRadioOption($lng->txt("news_visibility_users"), "0");
1126  $radio_group->addOption($radio_option);
1127  $radio_option = new ilRadioOption($lng->txt("news_visibility_public"), "1");
1128  $radio_group->addOption($radio_option);
1129  $radio_group->setInfo($lng->txt("news_news_item_visibility_info"));
1130  $radio_group->setRequired(false);
1131  $radio_group->setValue($this->object->getDefaultAccess());
1132  #$ch->addSubItem($radio_group);
1133  $this->form_gui->addItem($radio_group);
1134 
1135  //Extra Feed
1136  include_once("./Services/Block/classes/class.ilBlockSetting.php");
1137  $public_feed = ilBlockSetting::_lookup("news", "public_feed", 0, $this->object->getId());
1138  $ch = new ilCheckboxInputGUI($lng->txt("news_public_feed"), "extra_feed");
1139  $ch->setInfo($lng->txt("news_public_feed_info"));
1140  $ch->setChecked($public_feed);
1141  $this->form_gui->addItem($ch);
1142 
1143  // Include Files in Pubic Items
1144  $incl_files = new ilCheckboxInputGUI($lng->txt("mcst_incl_files_in_rss"), "public_files");
1145  $incl_files->setChecked($this->object->getPublicFiles());
1146  $incl_files->setInfo($lng->txt("mcst_incl_files_in_rss_info"));
1147  #$ch->addSubItem($incl_files);
1148  $this->form_gui->addItem($incl_files);
1149  }
1150 
1151  // Form action and save button
1152  $this->form_gui->addCommandButton("saveSettings", $lng->txt("save"));
1153  $this->form_gui->setFormAction($ilCtrl->getFormAction($this, "saveSettings"));
1154  }
1155 
1160  {
1161  global $ilCtrl, $ilTabs;
1162 
1163  $this->checkPermission("write");
1164  $ilTabs->activateTab("id_settings");
1165 
1166  $this->initSettingsForm();
1167  if ($this->form_gui->checkInput())
1168  {
1169  $news_set = new ilSetting("news");
1170  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
1171 
1172  $this->object->setTitle($this->form_gui->getInput("title"));
1173  $this->object->setDescription($this->form_gui->getInput("description"));
1174  $this->object->setOnline($this->form_gui->getInput("online"));
1175  $this->object->setDownloadable($this->form_gui->getInput("downloadable"));
1176 
1177  if ($enable_internal_rss)
1178  {
1179  $this->object->setPublicFiles($this->form_gui->getInput("public_files"));
1180  $this->object->setDefaultAccess($this->form_gui->getInput("defaultaccess"));
1181  }
1182  $this->object->update();
1183 
1184  if ($enable_internal_rss)
1185  {
1186  include_once("./Services/Block/classes/class.ilBlockSetting.php");
1187  ilBlockSetting::_write("news", "public_feed",
1188  $this->form_gui->getInput("extra_feed"),
1189  0, $this->object->getId());
1190  }
1191 
1192  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"),true);
1193  $ilCtrl->redirect($this, "editSettings");
1194  }
1195  else
1196  {
1197  $this->form_gui->setValuesByPost();
1198  $this->tpl->setContent($this->form_gui->getHTML());
1199  }
1200  }
1201 
1202  // add media cast to locator
1203  function addLocatorItems()
1204  {
1205  global $ilLocator;
1206 
1207  if (is_object($this->object))
1208  {
1209  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "listItems"), "", $_GET["ref_id"]);
1210  }
1211  }
1212 
1213  function _goto($a_target)
1214  {
1215  global $ilAccess, $ilErr, $lng;
1216 
1217  if ($ilAccess->checkAccess("read", "", $a_target))
1218  {
1219  $_GET["cmd"] = "listItems";
1220  $_GET["ref_id"] = $a_target;
1221  $_GET["baseClass"] = "ilmediacasthandlergui";
1222  $_GET["cmdClass"] = "ilobjmediacastgui";
1223  include("ilias.php");
1224  exit;
1225  }
1226  else if ($ilAccess->checkAccess("visible", "", $a_target))
1227  {
1228  $_GET["cmd"] = "infoScreen";
1229  $_GET["ref_id"] = $a_target;
1230  include("repository.php");
1231  exit;
1232  }
1233  else if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
1234  {
1235  $_GET["cmd"] = "frameset";
1236  $_GET["target"] = "";
1237  $_GET["ref_id"] = ROOT_FOLDER_ID;
1238  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
1240  include("repository.php");
1241  exit;
1242  }
1243 
1244  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
1245 
1246  }
1247 
1254  protected static function isAudio($extension) {
1255  return strpos($extension,"audio") !== false;
1256  }
1257 
1264  protected function getMediaItem ($id) {
1265  include_once("./Services/News/classes/class.ilNewsItem.php");
1266  $this->mcst_item = new ilNewsItem($id);
1267  // create dummy object in db (we need an id)
1268  include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
1269  $mob = new ilObjMediaObject($this->mcst_item->getMobId());
1270  return $mob->getMediaItem("Standard");
1271  }
1272 
1279  protected function getMediaItems ($id) {
1280  include_once("./Services/News/classes/class.ilNewsItem.php");
1281  $this->mcst_item = new ilNewsItem($id);
1282  // create dummy object in db (we need an id)
1283  include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
1284  $mob = new ilObjMediaObject($this->mcst_item->getMobId());
1285  return $mob->getMediaItems();
1286  }
1287 
1288  private function populateFormFromPost()
1289  {
1290  global $tpl;
1291  //issue: we have to display the current settings
1292  // problem: POST does not contain values of disabled textfields
1293  // solution: use hidden field and label to display-> here we need to synchronize the labels
1294  // with the values from the hidden fields.
1295  foreach (ilObjMediaCast::$purposes as $purpose)
1296  {
1297  if ($_POST["value_".$purpose])
1298  {
1299  $_POST["label_value_".$purpose] = $_POST["value_".$purpose];
1300  }
1301  }
1302 
1303  $this->form_gui->setValuesByPost();
1304  $tpl->setContent($this->form_gui->getHTML());
1305  }
1306 }
1307 ?>