ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSCORM2004ScoGUI.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("./Modules/Scorm2004/classes/class.ilSCORM2004NodeGUI.php");
6 require_once("./Modules/Scorm2004/classes/class.ilSCORM2004Sco.php");
7 require_once("./Modules/Scorm2004/classes/seq_editor/class.ilSCORM2004Objective.php");
8 
22 {
23 
29  var $ctrl = null;
30 
31  function ilSCORM2004ScoGUI($a_slm_obj, $a_node_id = 0)
32  {
33  global $ilCtrl;
34 
35  $ilCtrl->saveParameter($this, "obj_id");
36  $this->ctrl = &$ilCtrl;
37 
38  parent::ilSCORM2004NodeGUI($a_slm_obj, $a_node_id);
39  }
40 
44  function getType()
45  {
46  return "sco";
47  }
48 
52  function &executeCommand()
53  {
54  global $tpl, $ilCtrl, $ilTabs;
55 
56  $tpl->getStandardTemplate();
57 
58  $next_class = $ilCtrl->getNextClass($this);
59  $cmd = $ilCtrl->getCmd();
60 
61  switch($next_class)
62  {
63  // notes
64  case "ilnotegui":
65  switch($_GET["notes_mode"])
66  {
67  default:
68  $ilTabs->setTabActive("sahs_organization");
69  return $this->showOrganization();
70  }
71  break;
72 
73  case 'ilmdeditorgui':
74  $this->setTabs();
75  $this->setLocator();
76  include_once 'Services/MetaData/classes/class.ilMDEditorGUI.php';
77 
78  $md_gui =& new ilMDEditorGUI($this->slm_object->getID(),
79  $this->node_object->getId(), $this->node_object->getType());
80  $md_gui->addObserver($this->node_object,'MDUpdateListener','General');
81  $ilCtrl->forwardCommand($md_gui);
82  break;
83 
84  case 'ilscorm2004pagegui':
85  include_once("./Modules/Scorm2004/classes/class.ilSCORM2004PageGUI.php");
86  $page_obj = new ilSCORM2004PageGUI("sahs",$_GET["pg_id"]);
87  //$page_obj->setPresentationTitle($page["title"]);
88  $page_obj->setOutputMode(IL_PAGE_PREVIEW);
89  $ilCtrl->forwardCommand($page_obj);
90  break;
91 
92  default:
93  $cmd = $ilCtrl->getCmd("showOrganization");
94  $ret =& $this->$cmd();
95  break;
96  }
97  }
98 
102  function showProperties()
103  {
104  global $tpl, $lng, $ilTabs, $ilCtrl;
105 
106  $this->setTabs();
107  $this->setLocator();
108  $ilTabs->setTabActive("sahs_desc_objectives");
109 
110  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
111  $form = new ilPropertyFormGUI();
112 
113  // hide objectives page
114  $cb = new ilCheckboxInputGUI($lng->txt("sahs_hide_objectives_page"), "hide_objectives_page");
115  $cb->setInfo($lng->txt("sahs_hide_objectives_page_info"));
116  $form->addItem($cb);
117  $cb->setChecked($this->node_object->getHideObjectivePage());
118 
119  // description
120  $ta = new ilTextAreaInputGUI($lng->txt("description"), "desc");
121  $ta->setRows(4);
122  $ta->setCols(55);
123  $ta->setInfo($lng->txt("sahs_list_info"));
124  $form->setTitle($lng->txt("properties"));
125  $form->addItem($ta);
126  include_once "./Services/MetaData/classes/class.ilMD.php";
127  $meta = new ilMD($this->node_object->getSLMId(), $this->node_object->getId(), $this->node_object->getType());
128  $desc_ids = $meta->getGeneral()->getDescriptionIds();
129  $ta->setValue($meta->getGeneral()->getDescription($desc_ids[0])->getDescription());
130 
131  // objectives
132  $sh = new ilFormSectionHeaderGUI();
133  $sh->setTitle($lng->txt("sahs_learning_objectives"));
134  $form->addItem($sh);
135 
136  $objectives = $this->node_object->getObjectives();
137 
138  foreach ($objectives as $ob)
139  {
140  // map info
141  $mappings = $ob->getMappings();
142  $mapinfo = null;
143  foreach($mappings as $map)
144  {
145  $mapinfo .= $map->getTargetObjectiveID();
146  }
147 
148  if ($mapinfo == null)
149  {
150  $mapinfo = "local";
151  }
152  else
153  {
154  $mapinfo = "global to ".$mapinfo;
155  }
156 
157  // objective
158  $ta = new ilTextAreaInputGUI($mapinfo,
159  "obj_".$ob->getId());
160  $ta->setCols(55);
161  $ta->setRows(4);
162  $ta->setInfo($lng->txt("sahs_list_info"));
163  $form->addItem($ta);
164  $ta->setValue($ob->getObjectiveID());
165  }
166  $form->setFormAction($ilCtrl->getFormAction($this));
167  $form->addCommandButton("updateProperties",
168  $lng->txt("save"));
169  $tpl->setContent($form->getHTML());
170  }
171 
175  function updateProperties()
176  {
177  global $tpl,$lng;
178  $empty = false;
179 
180  foreach ($_POST as $key=>$value) {
181  if(preg_match('/(obj_)(.+)/', $key,$match)){
182  $objective = new ilScorm2004Objective($this->node_object->getId(),$match[2]);
183 // if (!$value)
184 // {
185 // $empty=true;
186 // } else {
187  $objective->setObjectiveID(ilUtil::stripSlashes($value));
188  $objective->updateObjective();
189 // }
190  }
191  }
192 
193  $this->node_object->setHideObjectivePage(ilUtil::stripSlashes($_POST["hide_objectives_page"]));
194  $this->node_object->update();
195 
196  include_once "./Services/MetaData/classes/class.ilMD.php";
197  $meta = new ilMD($this->node_object->getSLMId(), $this->node_object->getId(), $this->node_object->getType());
198  $gen = $meta->getGeneral();
199  $desc_ids = $gen->getDescriptionIds();
200  $des = $gen->getDescription($desc_ids[0]);
201  $des->setDescription(ilUtil::stripSlashes($_POST["desc"]));
202  $des->update();
203  $gen->update();
204 
205  if (!$empty)
206  {
207  ilUtil::sendInfo($lng->txt("saved_successfully"),true);
208  }
209  else
210  {
211  ilUtil::sendFailure($lng->txt("sahs_empty_objectives_are_not_allowed"), true);
212  }
213  $this->showProperties();
214  }
215 
216  function sahs_questions()
217  {
218  global $tpl,$lng, $ilCtrl;
219 
220  $this->setTabs();
221  $this->setLocator();
222 
223  include_once "./Services/Table/classes/class.ilTableGUI.php";
224  include_once "./Modules/Scorm2004/classes/class.ilSCORM2004Page.php";
225  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
226  include_once("./Services/COPage/classes/class.ilPCQuestionGUI.php");
227 
228  // load template for table
229  $tpl->addBlockfile("ADM_CONTENT", "adm_content", "tpl.table.html");
230  $tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.scormeditor_sco_question.html", "Modules/Scorm2004");
231 
232  $tbl = new ilTableGUI();
233  $tbl->setTitle("Questions for ".$this->node_object->getTitle());
234  $tbl->setHeaderNames(array("Question","Page"));
235  $cols = array("question","page");
236  $tbl->setHeaderVars($cols, $header_params);
237  $tbl->setColumnWidth(array("50%", "50%"));
238  $tbl->disable("sort");
239  $tbl->disable("footer");
240 
241  $tree = new ilTree($this->slm_object->getId());
242  $tree->setTableNames('sahs_sc13_tree', 'sahs_sc13_tree_node');
243  $tree->setTreeTablePK("slm_id");
244 
245  foreach($tree->getSubTree($tree->getNodeData($this->node_object->getId()),true,'page') as $page)
246  {
247  // get question ids
248  $qids = ilSCORM2004Page::_getQuestionIdsForPage("sahs", $page["obj_id"]);
249  if (count($qids) > 0)
250  {
251  // output questions
252  foreach ($qids as $qid)
253  {
254  $tpl->setCurrentBlock("tbl_content");
255  $tpl->setVariable("TXT_PAGE_TITLE", $page["title"]);
256  $ilCtrl->setParameterByClass("ilscorm2004pagenodegui", "obj_id", $page["obj_id"]);
257  $tpl->setVariable("HREF_EDIT_PAGE", $ilCtrl->getLinkTargetByClass("ilscorm2004pagenodegui", "edit"));
258 
259  $qtitle = assQuestion::_getTitle($qid);
260  $tpl->setVariable("TXT_QUESTION", $qtitle);
261  $ilCtrl->setParameterByClass("ilscorm2004pagenodegui", "obj_id", $page["obj_id"]);
262  //$tpl->setVariable("HREF_EDIT_QUESTION", $ilCtrl->getLinkTargetByClass("ilscorm2004pagenodegui", "edit"));
263 
264  $tpl->setVariable("CSS_ROW", ilUtil::switchColor($i++, "tblrow1", "tblrow2"));
265  $tpl->parseCurrentBlock();
266  }
267  }
268  }
269  $tbl->render();
270  }
271 
272  function getEditTree()
273  {
274 die("deprecated");
275  $slm_tree = new ilTree($this->node_object->getId(),$this->slm_object->getId());
276  $slm_tree->setTreeTablePK("slm_id");
277  $slm_tree->setTableNames('sahs_sc13_tree', 'sahs_sc13_tree_node');
278  return $slm_tree;
279  }
280 
284  function setTabs()
285  {
286  global $ilTabs, $ilCtrl, $tpl, $lng;
287 
288  // subelements
289  $ilTabs->addTarget("sahs_organization",
290  $ilCtrl->getLinkTarget($this,'showOrganization'),
291  "showOrganization", get_class($this));
292 
293  // properties (named learning objectives, since here is currently
294  // no other property)
295  $ilTabs->addTarget("sahs_desc_objectives",
296  $ilCtrl->getLinkTarget($this,'showProperties'),
297  "showProperties", get_class($this));
298 
299  // questions
300  $ilTabs->addTarget("sahs_questions",
301  $ilCtrl->getLinkTarget($this,'sahs_questions'),
302  "sahs_questions", get_class($this));
303 
304  // resources
305  $ilTabs->addTarget("cont_files",
306  $ilCtrl->getLinkTarget($this,'sco_resources'),
307  "sco_resources", get_class($this));
308 
309  // metadata
310  $ilTabs->addTarget("meta_data",
311  $ilCtrl->getLinkTargetByClass("ilmdeditorgui",''),
312  "", "ilmdeditorgui");
313 
314  // export
315  $ilTabs->addTarget("export",
316  $ilCtrl->getLinkTarget($this, "showExportList"), "showExportList",
317  get_class($this));
318 
319  // import
320  $ilTabs->addTarget("import",
321  $ilCtrl->getLinkTarget($this, "import"), "import",
322  get_class($this));
323 
324  // preview
325  $ilTabs->addNonTabbedLink("preview",
326  $lng->txt("cont_preview"),
327  $ilCtrl->getLinkTarget($this,'sco_preview'), "_blank");
328 
329  $tpl->setTitleIcon(ilUtil::getImagePath("icon_sco_b.png"));
330  $tpl->setTitle(
331  $lng->txt("sahs_unit").": ".$this->node_object->getTitle());
332  }
333 
337  function proceedDragDrop()
338  {
339  global $ilCtrl;
340 
341  //echo "-".$_POST["il_hform_source_id"]."-".$_POST["il_hform_target_id"]."-".$_POST["il_hform_fc"]."-";
342  $this->slm_object->executeDragDrop($_POST["il_hform_source_id"], $_POST["il_hform_target_id"],
343  $_POST["il_hform_fc"], $_POST["il_hform_as_subitem"]);
344  $ilCtrl->redirect($this, "showOrganization");
345  }
346 
350  function sco_preview()
351  {
352  global $tpl, $ilCtrl, $lng;
353 
354  // init main template
355  $tpl = new ilTemplate("tpl.main.html", true, true);
356  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
357  $tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
358  $tpl->setBodyClass("");
359  $tpl->setCurrentBlock("ContentStyle");
360  $tpl->setVariable("LOCATION_CONTENT_STYLESHEET",
361  ilObjStyleSheet::getContentStylePath($this->slm_object->getStyleSheetId()));
362  $tpl->parseCurrentBlock();
363 
364  // get javascript
365  include_once("./Services/jQuery/classes/class.iljQueryUtil.php");
368  $tpl->addJavaScript("./Modules/Scorm2004/scripts/questions/pure.js");
369  $tpl->addJavaScript("./Modules/Scorm2004/scripts/pager.js");
370 
371  $tpl->addOnLoadCode("pager.Init();");
372 
373  $tree = new ilTree($this->slm_object->getId());
374  $tree->setTableNames('sahs_sc13_tree', 'sahs_sc13_tree_node');
375  $tree->setTreeTablePK("slm_id");
376  include_once "./Modules/Scorm2004/classes/class.ilSCORM2004PageGUI.php";
377  include_once "./Services/MetaData/classes/class.ilMD.php";
378 
379  $meta = new ilMD($this->node_object->getSLMId(), $this->node_object->getId(), $this->node_object->getType());
380  $desc_ids = $meta->getGeneral()->getDescriptionIds();
381  $sco_description = $meta->getGeneral()->getDescription($desc_ids[0])->getDescription();
382 
383  // get sco template
384  $sco_tpl = new ilTemplate("tpl.sco.html", true, true, "Modules/Scorm2004");
385 
386  // navigation
387  $lk = ilObjSAHSLearningModule::getAffectiveLocalization($this->node_object->getSLMId());
388  ilSCORM2004Asset::renderNavigation($sco_tpl, "", $lk);
389 
390  // meta page (description and objectives)
391  ilSCORM2004Asset::renderMetaPage($sco_tpl, $this->node_object,
392  $this->node_object->getType());
393 
394  // init export (this initialises glossary template)
396  $terms = $this->node_object->getGlossaryTermIds();
397 
398  // render page
399  foreach($tree->getSubTree($tree->getNodeData($this->node_object->getId()),true,'page') as $page)
400  {
401  $page_obj = new ilSCORM2004PageGUI($this->node_object->getType(),$page["obj_id"],
402  0, $this->slm_object->getId());
403  $page_obj->setPresentationTitle($page["title"]);
404  $page_obj->setOutputMode(IL_PAGE_PREVIEW);
405  $page_obj->setStyleId($this->slm_object->getStyleSheetId());
406  if (count($terms) > 1)
407  {
408  $page_obj->setGlossaryOverviewInfo(
409  ilSCORM2004ScoGUI::getGlossaryOverviewId(), $this->node_object);
410  }
411  $sco_tpl->setCurrentBlock("page_preview");
412  $html = $ilCtrl->getHTML($page_obj);
413  //$sco_tpl->setVariable("PAGE_PRV", $page_obj->showPage("export"));
414  $sco_tpl->setVariable("PAGE_PRV", $html);
415  $sco_tpl->parseCurrentBlock();
416  }
417 
418  $output = $sco_tpl->get();
419 
420  // append glossary entries on the sco level
421  $output.= ilSCORM2004PageGUI::getGlossaryHTML($this->node_object);
422 
423  //insert questions
424  require_once './Modules/Scorm2004/classes/class.ilQuestionExporter.php';
425  $output = preg_replace_callback("/{{{{{(Question;)(il__qst_[0-9]+)}}}}}/",array(get_class($this), 'insertQuestion'),$output);
426 // $output = preg_replace("/&#123;/","",$output);
427 // $output = preg_replace("/&#125;/","",$output);
428  $output = "<script>var ScormApi=null;".ilQuestionExporter::questionsJS()."</script>".$output;
429 
430  $lk = ilObjSAHSLearningModule::getAffectiveLocalization($this->node_object->getSLMId());
432 
433  $tpl->addJavaScript("./Modules/Scorm2004/scripts/questions/question_handling.js");
434  $tpl->addCss("./Modules/Scorm2004/templates/default/question_handling.css");
435 
436  include_once("./Services/UIComponent/Overlay/classes/class.ilOverlayGUI.php");
438 
439  //inline JS
440  $output .='<script type="text/javascript" src="./Modules/Scorm2004/scripts/questions/question_handling.js"></script>';
441  $tpl->setVariable("CONTENT", $output);
442  }
443 
444  //callback function for question export
445  private function insertQuestion($matches)
446  {
447  $q_exporter = new ilQuestionExporter(false);
448  return $q_exporter->exportQuestion($matches[2]);
449  }
450 
454  public function selectExport()
455  {
456  switch ($_POST['select_export'])
457  {
458  case "exportScorm12":
459  case "exportScorm2004_3rd":
460  case "exportScorm2004_4th":
461  case "exportPDF":
462  case "exportHTML":
463  $this->ctrl->redirect($this, $_POST['select_export']);
464  break;
465  default:
466  $this->ctrl->redirect($this, 'showExportList');
467  break;
468  }
469  }
470 
471  function showExportList()
472  {
473  global $tpl, $ilCtrl, $lng;
474 
475  $this->setTabs();
476  $this->setLocator();
477 
478 
479  $template = new ilTemplate("tpl.scorm2004_export_buttons.html", true, true, 'Modules/Scorm2004');
480 
481  $buttons = array(
482  "exportScorm2004_3rd" => $lng->txt("scorm_create_export_file_scrom2004"),
483  "exportScorm2004_4th" => $lng->txt("scorm_create_export_file_scrom2004_4th"),
484  "exportScorm12" => $lng->txt("scorm_create_export_file_scrom12"),
485  "exportPDF" => $lng->txt("scorm_create_export_file_pdf"),
486  "exportHTML" => $lng->txt("scorm_create_export_file_html")
487  );
488  foreach ($buttons as $value => $text)
489  {
490  $template->setCurrentBlock('option');
491  $template->setVariable('OPTION_VALUE', $value);
492  $template->setVariable('OPTION_TITLE', ilUtil::prepareFormOutput($text));
493  $template->parseCurrentBlock();
494  }
495  $template->setVariable('EXPORT_TITLE', $lng->txt('export'));
496  $template->setVariable('EXPORT_LABEL', $lng->txt('type'));
497  $template->setVariable('FORMACTION', $ilCtrl->getFormAction($this, 'selectExport'));
498 
499  $export_files = $this->node_object->getExportFiles();
500 
501  include_once "./Modules/Scorm2004/classes/class.ilSCORM2004ExportTableGUI.php";
502  $table_gui = new ilSCORM2004ExportTableGUI($this, 'showExportList');
503  $data = array();
504  foreach ($export_files as $exp_file)
505  {
506  $filetype = $exp_file['type'];
507  // $public_str = ($exp_file["file"] == $this->object->getPublicExportFile($filetype))
508  // ? " <b>(".$this->lng->txt("public").")<b>"
509  // : "";
510  $file_arr = explode("__", $exp_file["file"]);
511  array_push($data, array('file' => $exp_file['file'], 'filetype' => $filetype, 'date' => ilDatePresentation::formatDate(new ilDateTime($file_arr[0], IL_CAL_UNIX)), 'size' => $exp_file['size'], 'type' => $exp_file['type'].$public_str));
512  }
513  $table_gui->setData($data);
514  $tpl->setVariable('ADM_CONTENT', $template->get() . "\n" . $table_gui->getHTML());
515 
516 
517  }
518 
520  {
521  $export = new ilScorm2004Export($this->node_object,'SCORM 2004 4th');
522  $export->buildExportFile();
523  $this->ctrl->redirect($this, "showExportList");
524  }
525 
526 
528  {
529  $export = new ilScorm2004Export($this->node_object,'SCORM 2004 3rd');
530  $export->buildExportFile();
531  $this->ctrl->redirect($this, "showExportList");
532  }
533 
534  function exportScorm12()
535  {
536  $export = new ilScorm2004Export($this->node_object,'SCORM 1.2');
537  $export->buildExportFile();
538  $this->ctrl->redirect($this, "showExportList");
539  }
540 
541  function exportHTML()
542  {
543  $export = new ilScorm2004Export($this->node_object,'HTML');
544  $export->buildExportFile();
545  $this->ctrl->redirect($this, "showExportList");
546  }
547 
548  function exportISO()
549  {
550  $export = new ilScorm2004Export($this->node_object,'ISO');
551  $export->buildExportFile();
552  $this->ctrl->redirect($this, "showExportList");
553  }
554 
555  function exportPDF()
556  {
557  $export = new ilScorm2004Export($this->node_object,'PDF');
558  $export->buildExportFile();
559  $this->ctrl->redirect($this, "showExportList");
560  }
561 
563  {
564  if(!isset($_POST["file"]))
565  {
566  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
567  }
568 
569  if (count($_POST["file"]) > 1)
570  {
571  $this->ilias->raiseError($this->lng->txt("cont_select_max_one_item"),$this->ilias->error_obj->MESSAGE);
572  }
573  $export = new ilSCORM2004Export($this->node_object);
574  $export_dir = $export->getExportDirectoryForType($_POST['type'][$_POST['file'][0]]);
575  ilUtil::deliverFile($export_dir."/".$_POST['file'][0], $_POST['file'][0]);
576  }
577 
582  {
583  global $lng, $tpl;
584 
585  if(!isset($_POST["file"]))
586  {
587  ilUtil::sendInfo($lng->txt("no_checkbox"),true);
588  $this->ctrl->redirect($this, "showExportList");
589  }
590 
591  ilUtil::sendQuestion($lng->txt("info_delete_sure"));
592  $export_files = $this->node_object->getExportFiles();
593 
594  include_once "./Modules/Scorm2004/classes/class.ilSCORM2004ExportTableGUI.php";
595  $table_gui = new ilSCORM2004ExportTableGUI($this, 'showExportList', true);
596  $data = array();
597  foreach ($export_files as $exp_file)
598  {
599  foreach ($_POST['file'] as $delete_file)
600  {
601  if (strcmp($delete_file, $exp_file['file']) == 0)
602  {
603  // $public_str = ($exp_file["file"] == $this->object->getPublicExportFile($exp_file["type"]))
604  // ? " <b>(".$this->lng->txt("public").")<b>"
605  // : "";
606  $file_arr = explode("__", $exp_file["file"]);
607  array_push($data, array('file' => $exp_file['file'], 'date' => ilDatePresentation::formatDate(new ilDateTime($file_arr[0], IL_CAL_UNIX)), 'size' => $exp_file['size'], 'type' => $exp_file['type'].$public_str));
608  }
609  }
610  }
611  $table_gui->setData($data);
612  $tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
613  }
614 
619  {
620  ilSession::clear("ilExportFiles");
621  $this->ctrl->redirect($this, "showExportList");
622  }
623 
624 
628  function deleteExportFile()
629  {
630  global $lng;
631  include_once "./Services/Utilities/classes/class.ilUtil.php";
632  $export = new ilSCORM2004Export($this->node_object);
633  foreach($_POST['file'] as $idx => $file)
634  {
635  $export_dir = $export->getExportDirectoryForType($_POST['type'][$idx]);
636  $exp_file = $export_dir."/".$file;
637  if (@is_file($exp_file))
638  {
639  unlink($exp_file);
640  }
641  }
642  ilUtil::sendSuccess($lng->txt('msg_deleted_export_files'), true);
643  $this->ctrl->redirect($this, "showExportList");
644  }
645 
647  {
648  $export_files = array();
649 
650  require_once "./Modules/Scorm2004/classes/class.ilSCORM2004Page.php";
651  include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
652  include_once "./Modules/File/classes/class.ilObjFile.php";
653  $tree = new ilTree($this->slm_object->getId());
654  $tree->setTableNames('sahs_sc13_tree', 'sahs_sc13_tree_node');
655  $tree->setTreeTablePK("slm_id");
656  foreach($tree->getSubTree($tree->getNodeData($this->node_object->getId()),true,'page') as $page)
657  {
658  $page_obj = new ilSCORM2004Page($page["obj_id"]);
659  $page_obj->buildDom();
660  $mob_ids = $page_obj->collectMediaObjects(false);
661  foreach($mob_ids as $mob_id)
662  {
663  if ($mob_id > 0 && ilObject::_exists($mob_id))
664  {
665  $path = ilObjMediaObject::_lookupStandardItemPath($mob_id,false,false);
666 
667  $media_obj = new ilObjMediaObject($mob_id);
668  $export_files[$i]["date"] = $media_obj->getCreateDate();
669  $export_files[$i]["size"] = @filesize($path); // could be remote, e.g. youtube video
670  $export_files[$i]["file"] = $media_obj->getTitle();
671  $export_files[$i]["type"] = $media_obj->getDescription();
672  $export_files[$i]["path"] = $path;
673  $this->ctrl->setParameter($this, "resource",
674  rawurlencode(ilObjMediaObject::_lookupStandardItemPath($mob_id,false,false)));
675  $export_files[$i]["link"] = $this->ctrl->getLinkTarget($this,"downloadResource");
676  $i++;
677  }
678  }
679  $file_ids = $page_obj->collectFileItems();
680  foreach($file_ids as $file_id)
681  {
682  $file_obj = new ilObjFile($file_id, false);
683  $export_files[$i]["date"] = $file_obj->getCreateDate();
684  $export_files[$i]["size"] = $file_obj->getFileSize();
685  $export_files[$i]["file"] = $file_obj->getFileName();
686  $export_files[$i]["type"] = $file_obj->getFileType();
687  $export_files[$i]["file_id"] = $file_id;
688  $this->ctrl->setParameter($this, "file_id",$file_id);
689  $export_files[$i]["link"] = $this->ctrl->getLinkTarget($this,"downloadFile","");
690  $i++;
691  }
692  unset($page_obj);
693  }
694 
695  return $export_files;
696  }
697 
698  function sco_resources()
699  {
700  global $tpl, $lng, $ilCtrl;;
701 
702  $this->setTabs();
703  $this->setLocator();
704  $i = 0;
705 
706  $export_files = $this->getExportResources();
707 
708  // create table
709  require_once("./Services/Table/classes/class.ilTableGUI.php");
710  $tbl = new ilTableGUI();
711 
712  // load files templates
713  $tpl->addBlockfile("ADM_CONTENT", "adm_content", "tpl.table.html");
714 
715  // load template for table content data
716  $tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.download_file_row.html", "Modules/LearningModule");
717 
718  $num = 0;
719 
720  $tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
721 
722  $tbl->setTitle($lng->txt("cont_files"));
723 
724  $tbl->setHeaderNames(array($lng->txt("cont_format"),
725  $lng->txt("cont_file"),
726  $lng->txt("size"), $lng->txt("date"),
727  ""));
728 
729  $cols = array("format", "file", "size", "date", "download");
730  $header_params = array("ref_id" => $_GET["ref_id"], "obj_id" => $_GET["obj_id"],
731  "cmd" => "sco_resources", "cmdClass" => strtolower(get_class($this)),
732  "cmdNode" => $_GET["cmdNode"], "baseClass" => $_GET["baseClass"]);
733  $tbl->setHeaderVars($cols, $header_params);
734  $tbl->setColumnWidth(array("10%", "30%", "20%", "20%","20%"));
735  $tbl->disable("sort");
736 
737  $tbl->setOrderColumn($_GET["sort_by"]);
738  $tbl->setOrderDirection($_GET["sort_order"]);
739  $tbl->setLimit($_GET["limit"]);
740  $tbl->setOffset($_GET["offset"]);
741  $tbl->setMaxCount($this->maxcount); // ???
742 
743 
744  $tbl->setMaxCount(count($export_files));
745 
746  // footer
747  $tbl->setFooter("tblfooter",$lng->txt("previous"),$lng->txt("next"));
748  //$tbl->disable("footer");
749 
750  $tbl->setMaxCount(count($export_files));
751  $export_files = array_slice($export_files, $_GET["offset"], $_GET["limit"]);
752 
753  $tbl->render();
754  if(count($export_files) > 0)
755  {
756  $i=0;
757  foreach($export_files as $exp_file)
758  {
759  /* remote files (youtube videos) have no size, so we allow them now
760  if (!$exp_file["size"] > 0)
761  {
762  continue;
763  }
764  */
765 
766  $tpl->setCurrentBlock("tbl_content");
767  $tpl->setVariable("TXT_FILENAME", $exp_file["file"]);
768 
769  $css_row = ilUtil::switchColor($i++, "tblrow1", "tblrow2");
770  $tpl->setVariable("CSS_ROW", $css_row);
771 
772  $tpl->setVariable("TXT_SIZE", $exp_file["size"]);
773  $tpl->setVariable("TXT_FORMAT", $exp_file["type"]);
774 
775  $tpl->setVariable("TXT_DATE", $exp_file["date"]);
776 
777  if($exp_file["size"] > 0)
778  {
779  $tpl->setVariable("TXT_DOWNLOAD", $lng->txt("download"));
780  $ilCtrl->setParameter($this, "resource", rawurlencode($exp_file["path"]));
781  $ilCtrl->setParameter($this, "file_id", rawurlencode($exp_file["file_id"]));
782  $tpl->setVariable("LINK_DOWNLOAD",
783  $ilCtrl->getLinkTarget($this, "downloadResource"));
784  }
785  else
786  {
787  $tpl->setVariable("TXT_DOWNLOAD", $lng->txt("show"));
788  $tpl->setVariable("LINK_TARGET", " target=\"_blank\"");
789  $tpl->setVariable("LINK_DOWNLOAD", $exp_file["path"]);
790  }
791 
792  $tpl->parseCurrentBlock();
793  }
794  } //if is_array
795  /* not found in template?
796  else
797  {
798  $tpl->setCurrentBlock("notfound");
799  $tpl->setVariable("TXT_OBJECT_NOT_FOUND", $lng->txt("obj_not_found"));
800  $tpl->setVariable("NUM_COLS", 4);
801  $tpl->parseCurrentBlock();
802  }
803  */
804  // $tpl->parseCurrentBlock();
805  }
806 
807  function downloadResource()
808  {
809  $export_files = $this->getExportResources();
810 
811  if ($_GET["file_id"] > 0)
812  {
813  $file = new ilObjFile($_GET["file_id"], false);
814  }
815 
816  // check that file really belongs to SCORM module (security)
817  foreach ($export_files as $f)
818  {
819  if (is_object($file))
820  {
821  if ($f["file"] == $file->getFileName())
822  {
823  $file->sendFile();
824  }
825  }
826  else
827  {
828  if ($f["path"] == $_GET["resource"])
829  {
830  if (is_file($f["path"]))
831  {
832  ilUtil::deliverFile($f["path"], $f["file"]);
833  }
834  }
835  }
836  }
837  exit;
838  }
839 
840  function downloadFile()
841  {
842  $file = explode("_", $_GET["file_id"]);
843  require_once("./Modules/File/classes/class.ilObjFile.php");
844  $fileObj =& new ilObjFile($file[count($file) - 1], false);
845  $fileObj->sendFile();
846  exit;
847  }
848 
849  function import()
850  {
851  global $tpl, $lng;
852 
853  $this->setTabs();
854  $this->setLocator();
855 
856  $tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.scormeditor_sco_import.html", "Modules/Scorm2004");
857 
858  $tpl->setVariable("TYPE_IMG",ilUtil::getImagePath('icon_slm.png'));
859  $tpl->setVariable("ALT_IMG", $lng->txt("obj_sahs"));
860 
861  $tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
862 
863  $tpl->setVariable("BTN_NAME", "importSave");
864 
865  // this leads to _top target which removes the left organization frame
866  //$tpl->setVariable("TARGET", ' target="'.ilFrameTargetInfo::_getFrame("MainContent").'" ');
867 
868  $tpl->setVariable("TXT_UPLOAD", $lng->txt("upload"));
869  $tpl->setVariable("TXT_CANCEL", $lng->txt("cancel"));
870  $tpl->setVariable("TXT_IMPORT_SCO", $lng->txt("import_sco_object"));
871  $tpl->setVariable("TXT_SELECT_FILE", $lng->txt("select_file"));
872  $tpl->setVariable("TXT_VALIDATE_FILE", $lng->txt("cont_validate_file"));
873 
874  // get the value for the maximal uploadable filesize from the php.ini (if available)
875  $umf=get_cfg_var("upload_max_filesize");
876  // get the value for the maximal post data from the php.ini (if available)
877  $pms=get_cfg_var("post_max_size");
878 
879  //convert from short-string representation to "real" bytes
880  $multiplier_a=array("K"=>1024, "M"=>1024*1024, "G"=>1024*1024*1024);
881 
882  $umf_parts=preg_split("/(\d+)([K|G|M])/", $umf, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
883  $pms_parts=preg_split("/(\d+)([K|G|M])/", $pms, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
884 
885  if (count($umf_parts) == 2) { $umf = $umf_parts[0]*$multiplier_a[$umf_parts[1]]; }
886  if (count($pms_parts) == 2) { $pms = $pms_parts[0]*$multiplier_a[$pms_parts[1]]; }
887 
888  // use the smaller one as limit
889  $max_filesize=min($umf, $pms);
890 
891  if (!$max_filesize) $max_filesize=max($umf, $pms);
892 
893  //format for display in mega-bytes
894  $max_filesize=sprintf("%.1f MB",$max_filesize/1024/1024);
895 
896  // gives out the limit as a little notice
897  $tpl->setVariable("TXT_FILE_INFO", $lng->txt("file_notice")." $max_filesize");
898  }
899 
900  function importSave()
901  {
902  global $_FILES, $rbacsystem;
903  global $ilias, $lng;
904 
905  // check if file was uploaded
906  $source = $_FILES["scormfile"]["tmp_name"];
907  if (($source == 'none') || (!$source))
908  {
909  $ilias->raiseError("No file selected!",$ilias->error_obj->MESSAGE);
910  }
911  // check create permission
912  if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], "sahs"))
913  {
914  $ilias->raiseError($lng->txt("no_create_permission"), $ilias->error_obj->WARNING);
915  }
916  // get_cfg_var("upload_max_filesize"); // get the may filesize form t he php.ini
917  switch ($__FILES["scormfile"]["error"])
918  {
919  case UPLOAD_ERR_INI_SIZE:
920  $ilias->raiseError($lng->txt("err_max_file_size_exceeds"),$ilias->error_obj->MESSAGE);
921  break;
922 
923  case UPLOAD_ERR_FORM_SIZE:
924  $ilias->raiseError($lng->txt("err_max_file_size_exceeds"),$ilias->error_obj->MESSAGE);
925  break;
926 
927  case UPLOAD_ERR_PARTIAL:
928  $ilias->raiseError($lng->txt("err_partial_file_upload"),$ilias->error_obj->MESSAGE);
929  break;
930 
931  case UPLOAD_ERR_NO_FILE:
932  $ilias->raiseError($lng->txt("err_no_file_uploaded"),$ilias->error_obj->MESSAGE);
933  break;
934  }
935 
936  $file = pathinfo($_FILES["scormfile"]["name"]);
937  $name = substr($file["basename"], 0, strlen($file["basename"]) - strlen($file["extension"]) - 1);
938  $file_path = $this->slm_object->getDataDirectory()."/".$this->node_object->getId()."/".$_FILES["scormfile"]["name"];
939  ilUtil::createDirectory($this->slm_object->getDataDirectory()."/".$this->node_object->getId());
940  ilUtil::moveUploadedFile($_FILES["scormfile"]["tmp_name"], $_FILES["scormfile"]["name"], $file_path);
941  ilUtil::unzip($file_path);
942  ilUtil::renameExecutables($this->slm_object->getDataDirectory()."/".$this->node_object->getId());
943 
944  include_once ("./Modules/Scorm2004/classes/ilSCORM13Package.php");
945  $newPack = new ilSCORM13Package();
946  $newPack->il_importSco($this->slm_object->getId(),$this->node_object->getId(),$this->slm_object->getDataDirectory()."/".$this->node_object->getId());
947 
948  $this->ctrl->redirect($this, "showOrganization");
949  }
950 
954  function cancel()
955  {
956  $this->ctrl->redirect($this, "showOrganization");
957  }
958 
965  static function getGlossaryOverviewId()
966  {
967  return "sco_glo_ov";
968  }
969 
976  static function getGloOverviewOv($a_sco)
977  {
978  global $lng;
979 
980  $tpl = new ilTemplate("tpl.sco_glossary_overview.html", true, true, "Modules/Scorm2004");
981 
982  $terms = $a_sco->getGlossaryTermIds();
983  $lk = ilObjSAHSLearningModule::getAffectiveLocalization($a_sco->getSLMId());
984  foreach ($terms as $k => $t)
985  {
986  $tpl->setCurrentBlock("link");
987  $tpl->setVariable("TXT_LINK", $t);
988  $tpl->setVariable("ID_LINK", "glo_ov_t".$k);
989  $tpl->parseCurrentBlock();
990  }
991 
992  $tpl->setVariable("DIV_ID", ilSCORM2004ScoGUI::getGlossaryOverviewId());
993  $tpl->setVariable("TXT_SCO_GLOSSARY", $lng->txtlng("content", "cont_sco_glossary", $lk));
994  $tpl->setVariable("TXT_CLOSE", $lng->txtlng("common", "close", $lk));
995 
996  if (count($terms) > 1)
997  {
998  return $tpl->get();
999  }
1000  else
1001  {
1002  return "";
1003  }
1004  }
1005 
1006 }
1007 ?>