ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 {
26  protected $help;
27 
31  protected $error;
32 
33 
39  public $ctrl = null;
40 
41  public function __construct($a_slm_obj, $a_node_id = 0)
42  {
43  global $DIC;
44 
45  $this->ctrl = $DIC->ctrl();
46  $this->tpl = $DIC["tpl"];
47  $this->tabs = $DIC->tabs();
48  $this->lng = $DIC->language();
49  $this->help = $DIC["ilHelp"];
50  $this->error = $DIC["ilErr"];
51  $ilCtrl = $DIC->ctrl();
52 
53  $ilCtrl->saveParameter($this, "obj_id");
54  $this->ctrl = &$ilCtrl;
55 
56  parent::__construct($a_slm_obj, $a_node_id);
57  }
58 
62  public function getType()
63  {
64  return "sco";
65  }
66 
70  public function executeCommand()
71  {
72  $tpl = $this->tpl;
74  $ilTabs = $this->tabs;
75 
76  $tpl->getStandardTemplate();
77 
78  $next_class = $ilCtrl->getNextClass($this);
79  $cmd = $ilCtrl->getCmd();
80 
81  switch ($next_class) {
82  // notes
83  case "ilnotegui":
84  switch ($_GET["notes_mode"]) {
85  default:
86  $ilTabs->setTabActive("sahs_organization");
87  return $this->showOrganization();
88  }
89  break;
90 
91  case 'ilobjectmetadatagui':
92  $this->setTabs();
93  $this->setLocator();
94  include_once 'Services/Object/classes/class.ilObjectMetaDataGUI.php';
95  $md_gui = new ilObjectMetaDataGUI(
96  $this->slm_object,
97  $this->node_object->getType(),
98  $this->node_object->getId()
99  );
100  $md_gui->addMDObserver($this->node_object, 'MDUpdateListener', 'General');
101  $ilCtrl->forwardCommand($md_gui);
102  break;
103 
104  case 'ilscorm2004pagegui':
105  include_once("./Modules/Scorm2004/classes/class.ilSCORM2004PageGUI.php");
106  $page_obj = new ilSCORM2004PageGUI("sahs", $_GET["pg_id"]);
107  //$page_obj->setPresentationTitle($page["title"]);
108  $page_obj->setOutputMode(IL_PAGE_PREVIEW);
109  $ilCtrl->forwardCommand($page_obj);
110  break;
111 
112  // mainly to fix #21631
113  case "ilassgenfeedbackpagegui":
114  break;
115 
116  default:
117  $cmd = $ilCtrl->getCmd("showOrganization");
118  $ret = $this->$cmd();
119  break;
120  }
121  }
122 
126  public function showProperties()
127  {
128  $tpl = $this->tpl;
129  $lng = $this->lng;
130  $ilTabs = $this->tabs;
132 
133  $this->setTabs();
134  $this->setLocator();
135  $ilTabs->setTabActive("sahs_desc_objectives");
136 
137  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
138  $form = new ilPropertyFormGUI();
139 
140  // hide objectives page
141  $cb = new ilCheckboxInputGUI($lng->txt("sahs_hide_objectives_page"), "hide_objectives_page");
142  $cb->setInfo($lng->txt("sahs_hide_objectives_page_info"));
143  $form->addItem($cb);
144  $cb->setChecked($this->node_object->getHideObjectivePage());
145 
146  // description
147  $ta = new ilTextAreaInputGUI($lng->txt("description"), "desc");
148  $ta->setRows(4);
149  $ta->setCols(55);
150  $ta->setInfo($lng->txt("sahs_list_info"));
151  $form->setTitle($lng->txt("properties"));
152  $form->addItem($ta);
153  include_once "./Services/MetaData/classes/class.ilMD.php";
154  $meta = new ilMD($this->node_object->getSLMId(), $this->node_object->getId(), $this->node_object->getType());
155  $desc_ids = $meta->getGeneral()->getDescriptionIds();
156  $ta->setValue($meta->getGeneral()->getDescription($desc_ids[0])->getDescription());
157 
158  // objectives
159  $sh = new ilFormSectionHeaderGUI();
160  $sh->setTitle($lng->txt("sahs_learning_objectives"));
161  $form->addItem($sh);
162 
163  $objectives = $this->node_object->getObjectives();
164 
165  foreach ($objectives as $ob) {
166  // map info
167  $mappings = $ob->getMappings();
168  $mapinfo = null;
169  foreach ($mappings as $map) {
170  $mapinfo .= $map->getTargetObjectiveID();
171  }
172 
173  if ($mapinfo == null) {
174  $mapinfo = "local";
175  } else {
176  $mapinfo = "global to " . $mapinfo;
177  }
178 
179  // objective
180  $ta = new ilTextAreaInputGUI(
181  $mapinfo,
182  "obj_" . $ob->getId()
183  );
184  $ta->setCols(55);
185  $ta->setRows(4);
186  $ta->setInfo($lng->txt("sahs_list_info"));
187  $form->addItem($ta);
188  $ta->setValue($ob->getObjectiveID());
189  }
190  $form->setFormAction($ilCtrl->getFormAction($this));
191  $form->addCommandButton(
192  "updateProperties",
193  $lng->txt("save")
194  );
195  $tpl->setContent($form->getHTML());
196  }
197 
201  public function updateProperties()
202  {
203  $tpl = $this->tpl;
204  $lng = $this->lng;
205  $empty = false;
206 
207  foreach ($_POST as $key => $value) {
208  if (preg_match('/(obj_)(.+)/', $key, $match)) {
209  $objective = new ilScorm2004Objective($this->node_object->getId(), $match[2]);
210  // if (!$value)
211  // {
212  // $empty=true;
213  // } else {
214  $objective->setObjectiveID(ilUtil::stripSlashes($value));
215  $objective->updateObjective();
216  // }
217  }
218  }
219 
220  $this->node_object->setHideObjectivePage(ilUtil::stripSlashes($_POST["hide_objectives_page"]));
221  $this->node_object->update();
222 
223  include_once "./Services/MetaData/classes/class.ilMD.php";
224  $meta = new ilMD($this->node_object->getSLMId(), $this->node_object->getId(), $this->node_object->getType());
225  $gen = $meta->getGeneral();
226  $desc_ids = $gen->getDescriptionIds();
227  $des = $gen->getDescription($desc_ids[0]);
228  $des->setDescription(ilUtil::stripSlashes($_POST["desc"]));
229  $des->update();
230  $gen->update();
231 
232  if (!$empty) {
233  ilUtil::sendInfo($lng->txt("saved_successfully"), true);
234  } else {
235  ilUtil::sendFailure($lng->txt("sahs_empty_objectives_are_not_allowed"), true);
236  }
237  $this->showProperties();
238  }
239 
240  public function sahs_questions()
241  {
242  $tpl = $this->tpl;
243  $lng = $this->lng;
245 
246  $this->setTabs();
247  $this->setLocator();
248 
249  include_once "./Services/Table/classes/class.ilTableGUI.php";
250  include_once "./Modules/Scorm2004/classes/class.ilSCORM2004Page.php";
251  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
252  include_once("./Services/COPage/classes/class.ilPCQuestionGUI.php");
253 
254  // load template for table
255  $tpl->addBlockfile("ADM_CONTENT", "adm_content", "tpl.table.html");
256  $tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.scormeditor_sco_question.html", "Modules/Scorm2004");
257 
258  $tbl = new ilTableGUI();
259  $tbl->setTitle("Questions for " . $this->node_object->getTitle());
260  $tbl->setHeaderNames(array("Question","Page"));
261  $cols = array("question","page");
262  // $tbl->setHeaderVars($cols, $header_params);
263  $tbl->setHeaderVars($cols, 0);
264  $tbl->setColumnWidth(array("50%", "50%"));
265  $tbl->disable("sort");
266  $tbl->disable("footer");
267 
268  $tree = new ilTree($this->slm_object->getId());
269  $tree->setTableNames('sahs_sc13_tree', 'sahs_sc13_tree_node');
270  $tree->setTreeTablePK("slm_id");
271  $i = 0;
272 
273  foreach ($tree->getSubTree($tree->getNodeData($this->node_object->getId()), true, 'page') as $page) {
274  // get question ids
275  include_once("./Services/COPage/classes/class.ilPCQuestion.php");
276  $qids = ilPCQuestion::_getQuestionIdsForPage("sahs", $page["obj_id"]);
277  if (count($qids) > 0) {
278  // output questions
279  foreach ($qids as $qid) {
280  $tpl->setCurrentBlock("tbl_content");
281  $tpl->setVariable("TXT_PAGE_TITLE", $page["title"]);
282  $ilCtrl->setParameterByClass("ilscorm2004pagenodegui", "obj_id", $page["obj_id"]);
283  $tpl->setVariable("HREF_EDIT_PAGE", $ilCtrl->getLinkTargetByClass("ilscorm2004pagenodegui", "edit"));
284 
285  $qtitle = assQuestion::_getTitle($qid);
286  $tpl->setVariable("TXT_QUESTION", $qtitle);
287  $ilCtrl->setParameterByClass("ilscorm2004pagenodegui", "obj_id", $page["obj_id"]);
288  //$tpl->setVariable("HREF_EDIT_QUESTION", $ilCtrl->getLinkTargetByClass("ilscorm2004pagenodegui", "edit"));
289 
290  $tpl->setVariable("CSS_ROW", ilUtil::switchColor($i++, "tblrow1", "tblrow2"));
291  $tpl->parseCurrentBlock();
292  }
293  }
294  }
295  $tbl->render();
296  }
297 
298  public function getEditTree()
299  {
300  die("deprecated");
301  $slm_tree = new ilTree($this->node_object->getId(), $this->slm_object->getId());
302  $slm_tree->setTreeTablePK("slm_id");
303  $slm_tree->setTableNames('sahs_sc13_tree', 'sahs_sc13_tree_node');
304  return $slm_tree;
305  }
306 
310  public function setTabs()
311  {
312  $ilTabs = $this->tabs;
314  $tpl = $this->tpl;
315  $lng = $this->lng;
316  $ilHelp = $this->help;
317 
318  $ilHelp->setScreenIdComponent("sahsed");
319 
320  // subelements
321  $ilTabs->addTarget(
322  "sahs_organization",
323  $ilCtrl->getLinkTarget($this, 'showOrganization'),
324  "showOrganization",
325  get_class($this)
326  );
327 
328  // properties (named learning objectives, since here is currently
329  // no other property)
330  $ilTabs->addTarget(
331  "sahs_desc_objectives",
332  $ilCtrl->getLinkTarget($this, 'showProperties'),
333  "showProperties",
334  get_class($this)
335  );
336 
337  // questions
338  $ilTabs->addTarget(
339  "sahs_questions",
340  $ilCtrl->getLinkTarget($this, 'sahs_questions'),
341  "sahs_questions",
342  get_class($this)
343  );
344 
345  // resources
346  $ilTabs->addTarget(
347  "cont_files",
348  $ilCtrl->getLinkTarget($this, 'sco_resources'),
349  "sco_resources",
350  get_class($this)
351  );
352 
353  // metadata
354  include_once "Services/Object/classes/class.ilObjectMetaDataGUI.php";
355  $mdgui = new ilObjectMetaDataGUI(
356  $this->slm_object,
357  $this->node_object->getType(),
358  $this->node_object->getId()
359  );
360  $mdtab = $mdgui->getTab();
361  if ($mdtab) {
362  $ilTabs->addTarget(
363  "meta_data",
364  $mdtab,
365  "",
366  "ilmdeditorgui"
367  );
368  }
369 
370  // export
371  $ilTabs->addTarget(
372  "export",
373  $ilCtrl->getLinkTarget($this, "showExportList"),
374  "showExportList",
375  get_class($this)
376  );
377 
378  // import
379  $ilTabs->addTarget(
380  "import",
381  $ilCtrl->getLinkTarget($this, "import"),
382  "import",
383  get_class($this)
384  );
385 
386  // preview
387  $ilTabs->addNonTabbedLink(
388  "preview",
389  $lng->txt("cont_preview"),
390  $ilCtrl->getLinkTarget($this, 'sco_preview'),
391  "_blank"
392  );
393 
394  $tpl->setTitleIcon(ilUtil::getImagePath("icon_sco.svg"));
395  $tpl->setTitle(
396  $lng->txt("sahs_unit") . ": " . $this->node_object->getTitle()
397  );
398  }
399 
403  public function proceedDragDrop()
404  {
406 
407  //echo "-".$_POST["il_hform_source_id"]."-".$_POST["il_hform_target_id"]."-".$_POST["il_hform_fc"]."-";
408  $this->slm_object->executeDragDrop(
409  $_POST["il_hform_source_id"],
410  $_POST["il_hform_target_id"],
411  $_POST["il_hform_fc"],
412  $_POST["il_hform_as_subitem"]
413  );
414  $ilCtrl->redirect($this, "showOrganization");
415  }
416 
420  public function sco_preview()
421  {
422  global $DIC;
423  $tpl = $DIC['tpl'];
424 
426 
427  // init main template
428  $tpl = new ilTemplate("tpl.main.html", true, true);
429  include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
430  $tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
431  $tpl->setBodyClass("");
432  $tpl->setCurrentBlock("ContentStyle");
433  $tpl->setVariable(
434  "LOCATION_CONTENT_STYLESHEET",
435  ilObjStyleSheet::getContentStylePath($this->slm_object->getStyleSheetId())
436  );
437  $tpl->parseCurrentBlock();
438 
439  // get javascript
440  include_once("./Services/jQuery/classes/class.iljQueryUtil.php");
443  $tpl->addJavaScript("./Modules/Scorm2004/scripts/questions/pure.js");
444  $tpl->addJavaScript("./Modules/Scorm2004/scripts/pager.js");
445 
446  $tpl->addOnLoadCode("pager.Init();");
447 
448  $tree = new ilTree($this->slm_object->getId());
449  $tree->setTableNames('sahs_sc13_tree', 'sahs_sc13_tree_node');
450  $tree->setTreeTablePK("slm_id");
451  include_once "./Modules/Scorm2004/classes/class.ilSCORM2004PageGUI.php";
452  include_once "./Services/MetaData/classes/class.ilMD.php";
453 
454  $meta = new ilMD($this->node_object->getSLMId(), $this->node_object->getId(), $this->node_object->getType());
455  $desc_ids = $meta->getGeneral()->getDescriptionIds();
456  $sco_description = $meta->getGeneral()->getDescription($desc_ids[0])->getDescription();
457 
458  // get sco template
459  $sco_tpl = new ilTemplate("tpl.sco.html", true, true, "Modules/Scorm2004");
460 
461  // navigation
462  $lk = ilObjSAHSLearningModule::getAffectiveLocalization($this->node_object->getSLMId());
463  ilSCORM2004Asset::renderNavigation($sco_tpl, "", $lk);
464 
465  // meta page (description and objectives)
467  $sco_tpl,
468  $this->node_object,
469  $this->node_object->getType()
470  );
471 
472  // init export (this initialises glossary template)
474  $terms = $this->node_object->getGlossaryTermIds();
475 
476  // render page
477  foreach ($tree->getSubTree($tree->getNodeData($this->node_object->getId()), true, 'page') as $page) {
478  $page_obj = new ilSCORM2004PageGUI(
479  $this->node_object->getType(),
480  $page["obj_id"],
481  0,
482  $this->slm_object->getId()
483  );
484  $page_obj->setPresentationTitle($page["title"]);
485  $page_obj->setOutputMode(IL_PAGE_PREVIEW);
486  $page_obj->setStyleId($this->slm_object->getStyleSheetId());
487  if (count($terms) > 1) {
488  $page_obj->setGlossaryOverviewInfo(
490  $this->node_object
491  );
492  }
493  $sco_tpl->setCurrentBlock("page_preview");
494  $html = $ilCtrl->getHTML($page_obj);
495  //$sco_tpl->setVariable("PAGE_PRV", $page_obj->showPage("export"));
496  $sco_tpl->setVariable("PAGE_PRV", $html);
497  $sco_tpl->parseCurrentBlock();
498  }
499 
500  $output = $sco_tpl->get();
501 
502  // append glossary entries on the sco level
503  $output .= ilSCORM2004PageGUI::getGlossaryHTML($this->node_object);
504 
505  //insert questions
506  require_once './Modules/Scorm2004/classes/class.ilQuestionExporter.php';
507  $output = preg_replace_callback("/{{{{{(Question;)(il__qst_[0-9]+)}}}}}/", array(get_class($this), 'insertQuestion'), $output);
508  $output = "<script>var ScormApi=null;" . ilQuestionExporter::questionsJS() . "</script>" . $output;
509 
510  $lk = ilObjSAHSLearningModule::getAffectiveLocalization($this->node_object->getSLMId());
511 
512  $tpl->addJavaScript("./Modules/Scorm2004/scripts/questions/question_handling.js");
513  $tpl->addCss("./Modules/Scorm2004/templates/default/question_handling.css");
514 
515  include_once("./Services/UIComponent/Overlay/classes/class.ilOverlayGUI.php");
517 
518  //inline JS
519  $output .= '<script type="text/javascript" src="./Modules/Scorm2004/scripts/questions/question_handling.js"></script>';
520  $tpl->setVariable("CONTENT", $output);
521  $tpl->show();
522  exit;
523  }
524 
525  //callback function for question export
526  private static function insertQuestion($matches)
527  {
528  $q_exporter = new ilQuestionExporter(false);
529  return $q_exporter->exportQuestion($matches[2]);
530  }
531 
535  public function selectExport()
536  {
537  switch ($_POST['select_export']) {
538  case "exportScorm12":
539  case "exportScorm2004_3rd":
540  case "exportScorm2004_4th":
541  case "exportPDF":
542  case "exportHTML":
543  $this->ctrl->redirect($this, $_POST['select_export']);
544  break;
545  default:
546  $this->ctrl->redirect($this, 'showExportList');
547  break;
548  }
549  }
550 
551  public function showExportList()
552  {
553  $tpl = $this->tpl;
555  $lng = $this->lng;
556 
557  $this->setTabs();
558  $this->setLocator();
559 
560 
561  $template = new ilTemplate("tpl.scorm2004_export_buttons.html", true, true, 'Modules/Scorm2004');
562 
563  $buttons = array(
564  "exportScorm2004_3rd" => $lng->txt("scorm_create_export_file_scrom2004"),
565  "exportScorm2004_4th" => $lng->txt("scorm_create_export_file_scrom2004_4th"),
566  "exportScorm12" => $lng->txt("scorm_create_export_file_scrom12"),
567  "exportPDF" => $lng->txt("scorm_create_export_file_pdf"),
568  "exportHTML" => $lng->txt("scorm_create_export_file_html")
569  );
570  foreach ($buttons as $value => $text) {
571  $template->setCurrentBlock('option');
572  $template->setVariable('OPTION_VALUE', $value);
573  $template->setVariable('OPTION_TITLE', ilUtil::prepareFormOutput($text));
574  $template->parseCurrentBlock();
575  }
576  $template->setVariable('EXPORT_TITLE', $lng->txt('export'));
577  $template->setVariable('EXPORT_LABEL', $lng->txt('type'));
578  $template->setVariable('FORMACTION', $ilCtrl->getFormAction($this, 'selectExport'));
579 
580  $export_files = $this->node_object->getExportFiles();
581 
582  include_once "./Modules/Scorm2004/classes/class.ilSCORM2004ExportTableGUI.php";
583  $table_gui = new ilSCORM2004ExportTableGUI($this, 'showExportList');
584  $data = array();
585  foreach ($export_files as $exp_file) {
586  $filetype = $exp_file['type'];
587  $public_str = "";
588  // $public_str = ($exp_file["file"] == $this->object->getPublicExportFile($filetype))
589  // ? " <b>(".$this->lng->txt("public").")<b>"
590  // : "";
591  $file_arr = explode("__", $exp_file["file"]);
592  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));
593  }
594  $table_gui->setData($data);
595  $tpl->setVariable('ADM_CONTENT', $template->get() . "\n" . $table_gui->getHTML());
596  }
597 
598  public function exportScorm2004_4th()
599  {
600  $export = new ilScorm2004Export($this->node_object, 'SCORM 2004 4th');
601  $export->buildExportFile();
602  $this->ctrl->redirect($this, "showExportList");
603  }
604 
605 
606  public function exportScorm2004_3rd()
607  {
608  $export = new ilScorm2004Export($this->node_object, 'SCORM 2004 3rd');
609  $export->buildExportFile();
610  $this->ctrl->redirect($this, "showExportList");
611  }
612 
613  public function exportScorm12()
614  {
615  $export = new ilScorm2004Export($this->node_object, 'SCORM 1.2');
616  $export->buildExportFile();
617  $this->ctrl->redirect($this, "showExportList");
618  }
619 
620  public function exportHTML()
621  {
622  $export = new ilScorm2004Export($this->node_object, 'HTML');
623  $export->buildExportFile();
624  $this->ctrl->redirect($this, "showExportList");
625  }
626 
627  public function exportISO()
628  {
629  $export = new ilScorm2004Export($this->node_object, 'ISO');
630  $export->buildExportFile();
631  $this->ctrl->redirect($this, "showExportList");
632  }
633 
634  public function exportPDF()
635  {
636  $export = new ilScorm2004Export($this->node_object, 'PDF');
637  $export->buildExportFile();
638  $this->ctrl->redirect($this, "showExportList");
639  }
640 
641  public function downloadExportFile()
642  {
643  $file = str_replace("..", "", $_GET['file']);
644  $export = new ilSCORM2004Export($this->node_object);
645  $export_dir = $export->getExportDirectoryForType($_GET['type']);
646  ilUtil::deliverFile($export_dir . "/" . $file, $file);
647  }
648 
652  public function confirmDeleteExportFile()
653  {
654  $lng = $this->lng;
655  $tpl = $this->tpl;
656 
657  if (!isset($_POST["file"])) {
658  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
659  $this->ctrl->redirect($this, "showExportList");
660  }
661 
662  ilUtil::sendQuestion($lng->txt("info_delete_sure"));
663  $export_files = $this->node_object->getExportFiles();
664 
665  include_once "./Modules/Scorm2004/classes/class.ilSCORM2004ExportTableGUI.php";
666  $table_gui = new ilSCORM2004ExportTableGUI($this, 'showExportList', true);
667  $data = array();
668  foreach ($export_files as $exp_file) {
669  foreach ($_POST['file'] as $delete_file) {
670  if (strcmp($delete_file, $exp_file['file']) == 0) {
671  $public_str = "";
672  // $public_str = ($exp_file["file"] == $this->object->getPublicExportFile($exp_file["type"]))
673  // ? " <b>(".$this->lng->txt("public").")<b>"
674  // : "";
675  $file_arr = explode("__", $exp_file["file"]);
676  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));
677  }
678  }
679  }
680  $table_gui->setData($data);
681  $tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
682  }
683 
687  public function cancelDeleteExportFile()
688  {
689  ilSession::clear("ilExportFiles");
690  $this->ctrl->redirect($this, "showExportList");
691  }
692 
693 
697  public function deleteExportFile()
698  {
699  $lng = $this->lng;
700  include_once "./Services/Utilities/classes/class.ilUtil.php";
701  $export = new ilSCORM2004Export($this->node_object);
702  foreach ($_POST['file'] as $idx => $file) {
703  $export_dir = $export->getExportDirectoryForType($_POST['type'][$idx]);
704  $exp_file = $export_dir . "/" . $file;
705  if (@is_file($exp_file)) {
706  unlink($exp_file);
707  }
708  }
709  ilUtil::sendSuccess($lng->txt('msg_deleted_export_files'), true);
710  $this->ctrl->redirect($this, "showExportList");
711  }
712 
713  public function getExportResources()
714  {
715  $export_files = array();
716 
717  require_once "./Modules/Scorm2004/classes/class.ilSCORM2004Page.php";
718  include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
719  include_once "./Modules/File/classes/class.ilObjFile.php";
720  $tree = new ilTree($this->slm_object->getId());
721  $tree->setTableNames('sahs_sc13_tree', 'sahs_sc13_tree_node');
722  $tree->setTreeTablePK("slm_id");
723  $i = 0;
724  foreach ($tree->getSubTree($tree->getNodeData($this->node_object->getId()), true, 'page') as $page) {
725  $page_obj = new ilSCORM2004Page($page["obj_id"]);
726  $page_obj->buildDom();
727  $mob_ids = $page_obj->collectMediaObjects(false);
728  foreach ($mob_ids as $mob_id) {
729  if ($mob_id > 0 && ilObject::_exists($mob_id)) {
730  $path = ilObjMediaObject::_lookupStandardItemPath($mob_id, false, false);
731 
732  $media_obj = new ilObjMediaObject($mob_id);
733  $export_files[$i]["date"] = $media_obj->getCreateDate();
734  $export_files[$i]["size"] = @filesize($path); // could be remote, e.g. youtube video
735  $export_files[$i]["file"] = $media_obj->getTitle();
736  $export_files[$i]["type"] = $media_obj->getDescription();
737  $export_files[$i]["path"] = $path;
738  $this->ctrl->setParameter(
739  $this,
740  "resource",
741  rawurlencode(ilObjMediaObject::_lookupStandardItemPath($mob_id, false, false))
742  );
743  $export_files[$i]["link"] = $this->ctrl->getLinkTarget($this, "downloadResource");
744  $i++;
745  }
746  }
747  include_once("./Services/COPage/classes/class.ilPCFileList.php");
748  $file_ids = ilPCFileList::collectFileItems($page_obj, $page_obj->getDomDoc());
749  foreach ($file_ids as $file_id) {
750  $file_obj = new ilObjFile($file_id, false);
751  $export_files[$i]["date"] = $file_obj->getCreateDate();
752  $export_files[$i]["size"] = $file_obj->getFileSize();
753  $export_files[$i]["file"] = $file_obj->getFileName();
754  $export_files[$i]["type"] = $file_obj->getFileType();
755  $export_files[$i]["file_id"] = $file_id;
756  $this->ctrl->setParameter($this, "file_id", $file_id);
757  $export_files[$i]["link"] = $this->ctrl->getLinkTarget($this, "downloadFile", "");
758  $i++;
759  }
760  unset($page_obj);
761  }
762 
763  return $export_files;
764  }
765 
766  public function sco_resources()
767  {
768  $tpl = $this->tpl;
769  $lng = $this->lng;
771 
772  $this->setTabs();
773  $this->setLocator();
774  $i = 0;
775 
776  $export_files = $this->getExportResources();
777 
778  // create table
779  require_once("./Services/Table/classes/class.ilTableGUI.php");
780  $tbl = new ilTableGUI();
781 
782  // load files templates
783  $tpl->addBlockfile("ADM_CONTENT", "adm_content", "tpl.table.html");
784 
785  // load template for table content data
786  $tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.download_file_row.html", "Modules/LearningModule");
787 
788  $num = 0;
789 
790  $tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
791 
792  $tbl->setTitle($lng->txt("cont_files"));
793 
794  $tbl->setHeaderNames(array($lng->txt("cont_format"),
795  $lng->txt("cont_file"),
796  $lng->txt("size"), $lng->txt("date"),
797  ""));
798 
799  $cols = array("format", "file", "size", "date", "download");
800  $header_params = array("ref_id" => $_GET["ref_id"], "obj_id" => $_GET["obj_id"],
801  "cmd" => "sco_resources", "cmdClass" => strtolower(get_class($this)),
802  "cmdNode" => $_GET["cmdNode"], "baseClass" => $_GET["baseClass"]);
803  $tbl->setHeaderVars($cols, $header_params);
804  $tbl->setColumnWidth(array("10%", "30%", "20%", "20%","20%"));
805  $tbl->disable("sort");
806 
807  $tbl->setOrderColumn($_GET["sort_by"]);
808  $tbl->setOrderDirection($_GET["sort_order"]);
809  $tbl->setLimit($_GET["limit"]);
810  $tbl->setOffset($_GET["offset"]);
811  $tbl->setMaxCount($this->maxcount); // ???
812 
813 
814  $tbl->setMaxCount(count($export_files));
815 
816  // footer
817  $tbl->setFooter("tblfooter", $lng->txt("previous"), $lng->txt("next"));
818  //$tbl->disable("footer");
819 
820  $tbl->setMaxCount(count($export_files));
821  $export_files = array_slice($export_files, $_GET["offset"], $_GET["limit"]);
822 
823  $tbl->render();
824  if (count($export_files) > 0) {
825  $i = 0;
826  foreach ($export_files as $exp_file) {
827  /* remote files (youtube videos) have no size, so we allow them now
828  if (!$exp_file["size"] > 0)
829  {
830  continue;
831  }
832  */
833 
834  $tpl->setCurrentBlock("tbl_content");
835  $tpl->setVariable("TXT_FILENAME", $exp_file["file"]);
836 
837  $css_row = ilUtil::switchColor($i++, "tblrow1", "tblrow2");
838  $tpl->setVariable("CSS_ROW", $css_row);
839 
840  $tpl->setVariable("TXT_SIZE", $exp_file["size"]);
841  $tpl->setVariable("TXT_FORMAT", $exp_file["type"]);
842 
843  $tpl->setVariable("TXT_DATE", $exp_file["date"]);
844 
845  if ($exp_file["size"] > 0) {
846  $tpl->setVariable("TXT_DOWNLOAD", $lng->txt("download"));
847  $ilCtrl->setParameter($this, "resource", rawurlencode($exp_file["path"]));
848  $ilCtrl->setParameter($this, "file_id", rawurlencode($exp_file["file_id"]));
849  $tpl->setVariable(
850  "LINK_DOWNLOAD",
851  $ilCtrl->getLinkTarget($this, "downloadResource")
852  );
853  } else {
854  $tpl->setVariable("TXT_DOWNLOAD", $lng->txt("show"));
855  $tpl->setVariable("LINK_TARGET", " target=\"_blank\"");
856  $tpl->setVariable("LINK_DOWNLOAD", $exp_file["path"]);
857  }
858 
859  $tpl->parseCurrentBlock();
860  }
861  } //if is_array
862  /* not found in template?
863  else
864  {
865  $tpl->setCurrentBlock("notfound");
866  $tpl->setVariable("TXT_OBJECT_NOT_FOUND", $lng->txt("obj_not_found"));
867  $tpl->setVariable("NUM_COLS", 4);
868  $tpl->parseCurrentBlock();
869  }
870  */
871  // $tpl->parseCurrentBlock();
872  }
873 
874  public function downloadResource()
875  {
876  $export_files = $this->getExportResources();
877 
878  if ($_GET["file_id"] > 0) {
879  $file = new ilObjFile($_GET["file_id"], false);
880  }
881 
882  // check that file really belongs to SCORM module (security)
883  foreach ($export_files as $f) {
884  if (is_object($file)) {
885  if ($f["file"] == $file->getFileName()) {
886  $file->sendFile();
887  }
888  } else {
889  if ($f["path"] == $_GET["resource"]) {
890  if (is_file($f["path"])) {
891  ilUtil::deliverFile($f["path"], $f["file"]);
892  }
893  }
894  }
895  }
896  exit;
897  }
898 
899  public function downloadFile()
900  {
901  $file = explode("_", $_GET["file_id"]);
902  require_once("./Modules/File/classes/class.ilObjFile.php");
903  $fileObj = new ilObjFile($file[count($file) - 1], false);
904  $fileObj->sendFile();
905  exit;
906  }
907 
908  public function import()
909  {
910  $tpl = $this->tpl;
911  $lng = $this->lng;
912 
913  $this->setTabs();
914  $this->setLocator();
915 
916  $tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.scormeditor_sco_import.html", "Modules/Scorm2004");
917 
918  $tpl->setVariable("TYPE_IMG", ilUtil::getImagePath('icon_lm.svg'));
919  $tpl->setVariable("ALT_IMG", $lng->txt("obj_sahs"));
920 
921  $tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
922 
923  $tpl->setVariable("BTN_NAME", "importSave");
924 
925  // this leads to _top target which removes the left organization frame
926  //$tpl->setVariable("TARGET", ' target="'.ilFrameTargetInfo::_getFrame("MainContent").'" ');
927 
928  $tpl->setVariable("TXT_UPLOAD", $lng->txt("upload"));
929  $tpl->setVariable("TXT_CANCEL", $lng->txt("cancel"));
930  $tpl->setVariable("TXT_IMPORT_SCO", $lng->txt("import_sco_object"));
931  $tpl->setVariable("TXT_SELECT_FILE", $lng->txt("select_file"));
932  $tpl->setVariable("TXT_VALIDATE_FILE", $lng->txt("cont_validate_file"));
933 
934  // get the value for the maximal uploadable filesize from the php.ini (if available)
935  $umf = get_cfg_var("upload_max_filesize");
936  // get the value for the maximal post data from the php.ini (if available)
937  $pms = get_cfg_var("post_max_size");
938 
939  //convert from short-string representation to "real" bytes
940  $multiplier_a = array("K" => 1024, "M" => 1024 * 1024, "G" => 1024 * 1024 * 1024);
941 
942  $umf_parts = preg_split("/(\d+)([K|G|M])/", $umf, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
943  $pms_parts = preg_split("/(\d+)([K|G|M])/", $pms, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
944 
945  if (count($umf_parts) == 2) {
946  $umf = $umf_parts[0] * $multiplier_a[$umf_parts[1]];
947  }
948  if (count($pms_parts) == 2) {
949  $pms = $pms_parts[0] * $multiplier_a[$pms_parts[1]];
950  }
951 
952  // use the smaller one as limit
953  $max_filesize = min($umf, $pms);
954 
955  if (!$max_filesize) {
956  $max_filesize = max($umf, $pms);
957  }
958 
959  //format for display in mega-bytes
960  $max_filesize = sprintf("%.1f MB", $max_filesize / 1024 / 1024);
961 
962  // gives out the limit as a little notice
963  $tpl->setVariable("TXT_FILE_INFO", $lng->txt("file_notice") . " $max_filesize");
964  }
965 
966  public function importSave()
967  {
968  $lng = $this->lng;
970 
971  // check if file was uploaded
972  $source = $_FILES["scormfile"]["tmp_name"];
973  if (($source == 'none') || (!$source)) {
974  $ilErr->raiseError("No file selected!", $ilErr->MESSAGE);
975  }
976  // get_cfg_var("upload_max_filesize"); // get the may filesize form t he php.ini
977  switch ($_FILES["scormfile"]["error"]) {
978  case UPLOAD_ERR_INI_SIZE:
979  $ilErr->raiseError($lng->txt("err_max_file_size_exceeds"), $ilErr->MESSAGE);
980  break;
981 
982  case UPLOAD_ERR_FORM_SIZE:
983  $ilErr->raiseError($lng->txt("err_max_file_size_exceeds"), $ilErr->MESSAGE);
984  break;
985 
986  case UPLOAD_ERR_PARTIAL:
987  $ilErr->raiseError($lng->txt("err_partial_file_upload"), $ilErr->MESSAGE);
988  break;
989 
990  case UPLOAD_ERR_NO_FILE:
991  $ilErr->raiseError($lng->txt("err_no_file_uploaded"), $ilErr->MESSAGE);
992  break;
993  }
994 
995  $file = pathinfo($_FILES["scormfile"]["name"]);
996  $name = substr($file["basename"], 0, strlen($file["basename"]) - strlen($file["extension"]) - 1);
997  $file_path = $this->slm_object->getDataDirectory() . "/" . $this->node_object->getId() . "/" . $_FILES["scormfile"]["name"];
998  ilUtil::createDirectory($this->slm_object->getDataDirectory() . "/" . $this->node_object->getId());
999  ilUtil::moveUploadedFile($_FILES["scormfile"]["tmp_name"], $_FILES["scormfile"]["name"], $file_path);
1000  ilUtil::unzip($file_path);
1001  ilUtil::renameExecutables($this->slm_object->getDataDirectory() . "/" . $this->node_object->getId());
1002 
1003  include_once("./Modules/Scorm2004/classes/ilSCORM13Package.php");
1004  $newPack = new ilSCORM13Package();
1005  $newPack->il_importSco($this->slm_object->getId(), $this->node_object->getId(), $this->slm_object->getDataDirectory() . "/" . $this->node_object->getId());
1006 
1007  $this->ctrl->redirect($this, "showOrganization");
1008  }
1009 
1013  public function cancel()
1014  {
1015  $this->ctrl->redirect($this, "showOrganization");
1016  }
1017 
1024  public static function getGlossaryOverviewId()
1025  {
1026  return "sco_glo_ov";
1027  }
1028 
1035  public static function getGloOverviewOv($a_sco)
1036  {
1037  global $DIC;
1038 
1039  $lng = $DIC->language();
1040 
1041  $tpl = new ilTemplate("tpl.sco_glossary_overview.html", true, true, "Modules/Scorm2004");
1042 
1043  $terms = $a_sco->getGlossaryTermIds();
1044  $lk = ilObjSAHSLearningModule::getAffectiveLocalization($a_sco->getSLMId());
1045  foreach ($terms as $k => $t) {
1046  $tpl->setCurrentBlock("link");
1047  $tpl->setVariable("TXT_LINK", $t);
1048  $tpl->setVariable("ID_LINK", "glo_ov_t" . $k);
1049  $tpl->parseCurrentBlock();
1050  }
1051 
1052  $tpl->setVariable("DIV_ID", ilSCORM2004ScoGUI::getGlossaryOverviewId());
1053  $tpl->setVariable("TXT_SCO_GLOSSARY", $lng->txtlng("content", "cont_sco_glossary", $lk));
1054  $tpl->setVariable("TXT_CLOSE", $lng->txtlng("common", "close", $lk));
1055 
1056  if (count($terms) > 1) {
1057  return $tpl->get();
1058  } else {
1059  return "";
1060  }
1061  }
1062 }
__construct($a_slm_obj, $a_node_id=0)
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
Class ilObjectMetaDataGUI.
$path
Definition: aliased.php:25
Scorm 2004 Question Exporter.
const IL_PAGE_PREVIEW
static _getQuestionIdsForPage($a_parent_type, $a_page_id, $a_lang="-")
Get all questions of a page.
static _lookupStandardItemPath( $a_mob_id, $a_url_encode=false, $a_web=true)
Get path for standard item.
proceedDragDrop()
Perform drag and drop action.
$template
This class represents a property form user interface.
Class ilSCORM2004NodeGUI.
global $DIC
Definition: saml.php:7
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data
static getStyleSheetLocation($mode="output", $a_css_name="", $a_css_location="")
get full style sheet file name (path inclusive) of current user
$_GET["client_id"]
$tbl
Definition: example_048.php:81
This class represents a section header in a property form.
$ctrl
Constructor public.
static getGloOverviewOv($a_sco)
des
addMDObserver($a_class, $a_method, $a_section)
static unzip($a_file, $overwrite=false, $a_flat=false)
unzip file
static renderMetaPage($a_tpl, $a_sco, $a_asset_type="", $mode="")
Render meta page (description/objectives at beginning)
selectExport()
Select the export type of the SCORM 2004 module.
This class represents a checkbox property in a property form.
setLocator()
Set Locator Items.
Class ilTableGUI.
const IL_CAL_UNIX
static getGlossaryOverviewId()
Get sco glossary overlay id.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
$ilErr
Definition: raiseError.php:18
getTab($a_base_class=null)
Get tab link if available.
global $ilCtrl
Definition: ilias.php:18
cancelDeleteExportFile()
cancel deletion of export files
setInfo($a_info)
Set Information Text.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static insertQuestion($matches)
if(isset($_POST['submit'])) $form
Class ilSCORM2004Page.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
special template class to simplify handling of ITX/PEAR
static collectFileItems($a_page, $a_domdoc)
Get all file items that are used within the page.
$text
Definition: errorreport.php:18
& getGeneral()
Definition: class.ilMD.php:40
Date and time handling
setPresentationTitle($a_title="")
static createDirectory($a_dir, $a_mod=0755)
create directory
Export class for SCORM 2004 object.
Class ilObjMediaObject.
static clear($a_var)
Unset a value.
showOrganization()
put this object into content object tree
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static sendQuestion($a_info="", $a_keep=false)
Send Question to Screen.
static getContentStylePath($a_style_id, $add_random=true)
get content style path
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
setTreeTablePK($a_column_name)
set column containing primary key in tree table public
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static initjQueryUI($a_tpl=null)
inits and adds the jQuery-UI JS-File to the global template (see included_components.txt for included components)
updateProperties()
update Properties
exit
Definition: backend.php:16
static renderNavigation($a_tpl, $a_spacer_img="", $a_lang="")
Render navigation.
Class ilSCORM2004Page GUI class.
static renameExecutables($a_dir)
Rename uploaded executables for security reasons.
This class represents a text area property in a property form.
static switchColor($a_num, $a_css1, $a_css2)
switches style sheets for each even $a_num (used for changing colors of different result rows) ...
$ret
Definition: parser.php:6
$i
Definition: disco.tpl.php:19
static initjQuery($a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
Class ilSCORM2004ScoGUI.
static getGlossaryHTML($a_sco)
Get glossary html (only in export mode)
$source
Definition: linkback.php:22
static getAffectiveLocalization($a_id)
Get affective localization.
$key
Definition: croninfo.php:18
$cols
Definition: xhr_table.php:11
deleteExportFile()
delete export files
$_POST["username"]
$html
Definition: example_001.php:87
static _getTitle($a_q_id)
Returns the title of a question.
showProperties()
Show learning objectives.
executeCommand()
execute command
confirmDeleteExportFile()
confirmation screen for export file deletion
static questionsJS(array $a_qids=null)
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
$data
Definition: bench.php:6
static initExport()
Init export.
static initJavascript()
Init javascript.