ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSCORM2004ScoGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2008 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22  */
23 
24 require_once("./Modules/Scorm2004/classes/class.ilSCORM2004NodeGUI.php");
25 require_once("./Modules/Scorm2004/classes/class.ilSCORM2004Sco.php");
26 require_once("./Modules/Scorm2004/classes/seq_editor/class.ilSCORM2004Objective.php");
27 
41 {
42 
48  var $ctrl = null;
49 
50  function ilSCORM2004ScoGUI($a_slm_obj, $a_node_id = 0)
51  {
52  global $ilCtrl;
53 
54  $ilCtrl->saveParameter($this, "obj_id");
55  $this->ctrl = &$ilCtrl;
56 
57  parent::ilSCORM2004NodeGUI($a_slm_obj, $a_node_id);
58  }
59 
63  function getType()
64  {
65  return "sco";
66  }
67 
71  function &executeCommand()
72  {
73  global $tpl, $ilCtrl, $ilTabs;
74 
75  $tpl->getStandardTemplate();
76 
77  $next_class = $ilCtrl->getNextClass($this);
78  $cmd = $ilCtrl->getCmd();
79 
80  switch($next_class)
81  {
82  // notes
83  case "ilnotegui":
84  switch($_GET["notes_mode"])
85  {
86  default:
87  $ilTabs->setTabActive("sahs_organization");
88  return $this->showOrganization();
89  }
90  break;
91 
92  case 'ilmdeditorgui':
93  $this->setTabs();
94  $this->setLocator();
95  include_once 'Services/MetaData/classes/class.ilMDEditorGUI.php';
96 
97  $md_gui =& new ilMDEditorGUI($this->slm_object->getID(),
98  $this->node_object->getId(), $this->node_object->getType());
99  $md_gui->addObserver($this->node_object,'MDUpdateListener','General');
100  $ilCtrl->forwardCommand($md_gui);
101  break;
102 
103  case 'ilscorm2004pagegui':
104  include_once("./Modules/Scorm2004/classes/class.ilSCORM2004PageGUI.php");
105  $page_obj = new ilSCORM2004PageGUI("sahs",$_GET["pg_id"]);
106  //$page_obj->setPresentationTitle($page["title"]);
107  $page_obj->setOutputMode(IL_PAGE_PREVIEW);
108  $ilCtrl->forwardCommand($page_obj);
109  break;
110 
111  default:
112  $ret =& $this->$cmd();
113  break;
114  }
115  }
116 
120  function showProperties()
121  {
122  global $tpl,$lng,$ilTabs;
123 
124 
125  $this->setTabs();
126  $this->setLocator();
127  $ilTabs->setTabActive("sahs_learning_objectives");
128  include_once "./Services/Table/classes/class.ilTableGUI.php";
129 
130  // load template for table
131  $tpl->addBlockfile("ADM_CONTENT", "adm_content", "tpl.table.html");
132 
133  // load template for table content data
134  $tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.scormeditor_sco_properties.html", "Modules/Scorm2004");
135 
136  $tbl = new ilTableGUI();
137  $tbl->enable("action");
138  $tbl->disable("sort");
139  $tbl->setTitle("Learning Objectives for ".$this->node_object->getTitle());
140  $tbl->setHeaderNames(array("", $lng->txt("title"),"Scope"));
141  $cols = array("", "title","scope");
142  $tbl->setHeaderVars($cols, $header_params);
143 
144  $tr_data = $this->node_object->getObjectives();
145 
146  $tpl->setVariable("COLUMN_COUNTS", 3);
147 
148  $tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
149 
150  $tpl->setCurrentBlock("tbl_action_btn");
151  $tpl->setVariable("BTN_NAME", "updateProperties");
152  $tpl->setVariable("BTN_VALUE", $lng->txt("save"));
153  $tpl->parseCurrentBlock();
154  $tbl->render();
155 
156  foreach ($tr_data as $data)
157  {
158  $tpl->setCurrentBlock("tbl_content");
159  $tpl->setVariable("TITLE", $data->getObjectiveID());
160  $tpl->setVariable("NODE_ID", "obj_".$data->getId());
161  $tpl->setVariable("ICON" , ilUtil::getImagePath("icon_lobj.gif"));
162 
163  $mappings = $data->getMappings();
164  $mapinfo = null;
165  foreach($mappings as $map) {
166  $mapinfo .= $map->getTargetObjectiveID();
167  }
168  if ($mapinfo == null) {
169  $mapinfo = "local";
170  } else {
171  $mapinfo = "global to ".$mapinfo;
172  }
173  $tpl->setVariable("REFERENCE", $mapinfo);
174  $css_row = ilUtil::switchColor($i++, "tblrow1", "tblrow2");
175  $tpl->setVariable("CSS_ROW", $css_row);
176  $tpl->parseCurrentBlock();
177  }
178  //block sequencing rules
179 
180 
181  //$tpl->touchBlock("adm_content");
182  }
183 
187  function updateProperties()
188  {
189  global $tpl,$lng;
190  $empty = false;
191 
192  foreach ($_POST as $key=>$value) {
193  if(preg_match('/(obj_)(.+)/', $key,$match)){
194  $objective = new ilScorm2004Objective($this->node_object->getId(),$match[2]);
195  if (!$value)
196  {
197  $empty=true;
198  } else {
199  $objective->setObjectiveID(ilUtil::stripSlashes($value));
200  $objective->updateObjective();
201  }
202  }
203  }
204  if (!$empty) {
205  ilUtil::sendInfo($lng->txt("saved_successfully"),true);
206  } else {
207  ilUtil::sendInfo("Objective titles can't be blank",true);
208  }
209  $this->showProperties();
210  }
211 
212  function sahs_questions()
213  {
214  global $tpl,$lng, $ilCtrl;
215 
216  $this->setTabs();
217  $this->setLocator();
218 
219  include_once "./Services/Table/classes/class.ilTableGUI.php";
220  include_once "./Modules/Scorm2004/classes/class.ilSCORM2004Page.php";
221  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
222  include_once("./Services/COPage/classes/class.ilPCQuestionGUI.php");
223 
224  // load template for table
225  $tpl->addBlockfile("ADM_CONTENT", "adm_content", "tpl.table.html");
226  $tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.scormeditor_sco_question.html", "Modules/Scorm2004");
227 
228  $tbl = new ilTableGUI();
229  $tbl->setTitle("Questions for ".$this->node_object->getTitle());
230  $tbl->setHeaderNames(array("Question","Page"));
231  $cols = array("question","page");
232  $tbl->setHeaderVars($cols, $header_params);
233  $tbl->setColumnWidth(array("50%", "50%"));
234  $tbl->disable("sort");
235  $tbl->disable("footer");
236 
237  $tree = new ilTree($this->slm_object->getId());
238  $tree->setTableNames('sahs_sc13_tree', 'sahs_sc13_tree_node');
239  $tree->setTreeTablePK("slm_id");
240 
241  foreach($tree->getSubTree($tree->getNodeData($this->node_object->getId()),true,'page') as $page)
242  {
243  // get question ids
244  $qids = ilSCORM2004Page::_getQuestionIdsForPage("sahs", $page["obj_id"]);
245  if (count($qids) > 0)
246  {
247  // output questions
248  foreach ($qids as $qid)
249  {
250  $tpl->setCurrentBlock("tbl_content");
251  $tpl->setVariable("TXT_PAGE_TITLE", $page["title"]);
252  $ilCtrl->setParameterByClass("ilscorm2004pagenodegui", "obj_id", $page["obj_id"]);
253  $tpl->setVariable("HREF_EDIT_PAGE", $ilCtrl->getLinkTargetByClass("ilscorm2004pagenodegui", "edit"));
254 
255  $qtitle = assQuestion::_getTitle($qid);
256  $tpl->setVariable("TXT_QUESTION", $qtitle);
257  $ilCtrl->setParameterByClass("ilscorm2004pagenodegui", "obj_id", $page["obj_id"]);
258  //$tpl->setVariable("HREF_EDIT_QUESTION", $ilCtrl->getLinkTargetByClass("ilscorm2004pagenodegui", "edit"));
259 
260  $tpl->setVariable("CSS_ROW", ilUtil::switchColor($i++, "tblrow1", "tblrow2"));
261  $tpl->parseCurrentBlock();
262  }
263  }
264  }
265  $tbl->render();
266  }
267 
268  function getEditTree()
269  {
270  $slm_tree = new ilTree($this->node_object->getId(),$this->slm_object->getId());
271  $slm_tree->setTreeTablePK("slm_id");
272  $slm_tree->setTableNames('sahs_sc13_tree', 'sahs_sc13_tree_node');
273  return $slm_tree;
274  }
275 
279  function setTabs()
280  {
281  global $ilTabs, $ilCtrl, $tpl, $lng;
282 
283  // subelements
284  $ilTabs->addTarget("sahs_organization",
285  $ilCtrl->getLinkTarget($this,'showOrganization'),
286  "showOrganization", get_class($this));
287 
288  // properties (named learning objectives, since here is currently
289  // no other property)
290  $ilTabs->addTarget("sahs_learning_objectives",
291  $ilCtrl->getLinkTarget($this,'showProperties'),
292  "showProperties", get_class($this));
293 
294  // questions
295  $ilTabs->addTarget("sahs_questions",
296  $ilCtrl->getLinkTarget($this,'sahs_questions'),
297  "sahs_questions", get_class($this));
298 
299  // resources
300  $ilTabs->addTarget("cont_files",
301  $ilCtrl->getLinkTarget($this,'sco_resources'),
302  "sco_resources", get_class($this));
303 
304  // metadata
305  $ilTabs->addTarget("meta_data",
306  $ilCtrl->getLinkTargetByClass("ilmdeditorgui",''),
307  "", "ilmdeditorgui");
308 
309  // export
310  $ilTabs->addTarget("export",
311  $ilCtrl->getLinkTarget($this, "showExportList"), "showExportList",
312  get_class($this));
313 
314  // import
315  $ilTabs->addTarget("import",
316  $ilCtrl->getLinkTarget($this, "import"), "import",
317  get_class($this));
318 
319  // preview
320  $ilTabs->addNonTabbedLink("preview",
321  $lng->txt("cont_preview"),
322  $ilCtrl->getLinkTarget($this,'sco_preview'), "_blank");
323 
324  $tpl->setTitleIcon(ilUtil::getImagePath("icon_sco_b.gif"));
325  $tpl->setTitle(
326  $lng->txt("sahs_unit").": ".$this->node_object->getTitle());
327  }
328 
332  function proceedDragDrop()
333  {
334  global $ilCtrl;
335 
336  //echo "-".$_POST["il_hform_source_id"]."-".$_POST["il_hform_target_id"]."-".$_POST["il_hform_fc"]."-";
337  $this->slm_object->executeDragDrop($_POST["il_hform_source_id"], $_POST["il_hform_target_id"],
338  $_POST["il_hform_fc"], $_POST["il_hform_as_subitem"]);
339  $ilCtrl->redirect($this, "showOrganization");
340  }
341 
342  function sco_preview()
343  {
344  global $tpl, $ilCtrl, $lng;
345 
346  $tpl = new ilTemplate("tpl.main.html", true, true);
347 
348  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
349  $tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
350  $tpl->setBodyClass("");
351  $tpl->setCurrentBlock("ContentStyle");
352  $tpl->setVariable("LOCATION_CONTENT_STYLESHEET",
353  ilObjStyleSheet::getContentStylePath($this->slm_object->getStyleSheetId()));
354  $tpl->parseCurrentBlock();
355 
356  $tpl->addJavaScript("./Modules/Scorm2004/scripts/questions/jquery.js");
357  $tpl->addJavaScript("./Modules/Scorm2004/scripts/questions/jquery-ui-min.js");
358  $tpl->addJavaScript("./Modules/Scorm2004/scripts/questions/pure.js");
359 
360  $tpl->addJavaScript("./Modules/Scorm2004/scripts/pager.js");
361 
362 // $this->setTabs();
363 // $this->setLocator();
364 
365  $tree = new ilTree($this->slm_object->getId());
366  $tree->setTableNames('sahs_sc13_tree', 'sahs_sc13_tree_node');
367  $tree->setTreeTablePK("slm_id");
368  include_once "./Modules/Scorm2004/classes/class.ilSCORM2004PageGUI.php";
369  include_once "./Services/MetaData/classes/class.ilMD.php";
370 
371  $meta = new ilMD($this->node_object->getSLMId(), $this->node_object->getId(), $this->node_object->getType());
372  $desc_ids = $meta->getGeneral()->getDescriptionIds();
373  $sco_description = $meta->getGeneral()->getDescription($desc_ids[0])->getDescription();
374 
375  // @todo
376  // Why is that much HTML code in an application class?
377  // Please extract all this HTML to a tpl.<t_name>.html file and use
378  // placeholders and the template engine to insert data.
379  //
380  // There copy/paste code residenting in ilSCORM2004Sco. This
381  // should be merged.
382  //
383  // alex, 4 Apr 09
384  //
385 
386  $output = '<!-- BEGIN ilLMNavigation -->
387  <div class="ilc_page_tnav_TopNavigation">
388  <!-- BEGIN ilLMNavigation_Prev -->
389  <div class="ilc_page_lnav_LeftNavigation">
390  <a class="ilc_page_lnavlink_LeftNavigationLink">
391  <img class="ilc_page_lnavimage_LeftNavigationImage" border="0" src="/templates/default/images/spacer.gif" alt="" title="" />&nbsp;'.$lng->txt('scplayer_previous').'</a>
392  </div>
393  <!-- END ilLMNavigation_Prev -->
394  <!-- BEGIN ilLMNavigation_Next -->
395  <div class="ilc_page_rnav_RightNavigation">
396  <a class="ilc_page_rnavlink_RightNavigationLink">'.$lng->txt('scplayer_next').'&nbsp;<img class="ilc_page_rnavimage_RightNavigationImage" border="0" src="/templates/default/images/spacer.gif" alt="" title="" /></a>
397  </div>
398  <!-- END ilLMNavigation_Next -->
399  <div style="clear:both;"></div>
400  </div>
401  <!-- END ilLMNavigation -->';
402 
403  $output .='<table class="ilc_page_cont_PageContainer" width="100%" cellspacing="0" cellpadding="0" style="display: table;"><tbody><tr><td><div class="ilc_page_Page"><div class="ilc_sco_title_Title">'.$this->node_object->getTitle().'</div>';
404 
405  // sco description
406  if (trim($sco_description) != "")
407  {
408  $output .='<div class="ilc_sco_desct_DescriptionTop">'.$lng->txt("description").'</div>';
409  $output .='<div class="ilc_sco_desc_Description">'.$sco_description.'</div>';
410  }
411 
412  // sco objective(s)
413  $objs = $this->node_object->getObjectives();
414  if (count($objs) > 0)
415  {
416  $output .='<div class="ilc_sco_objt_ObjectiveTop">'.$lng->txt("sahs_objectives").'</div>';
417  foreach ($objs as $objective)
418  {
419  $output .= '<div class="ilc_sco_obj_Objective">'.nl2br($objective->getObjectiveID()).'</div>';
420  }
421  $output .= "</div>";
422  }
423  $output .='</td></tr></table>';
424 
425  // init export (this initialises glossary template)
427  $terms = $this->node_object->getGlossaryTermIds();
428  foreach($tree->getSubTree($tree->getNodeData($this->node_object->getId()),true,'page') as $page)
429  {
430  $page_obj = new ilSCORM2004PageGUI($this->node_object->getType(),$page["obj_id"]);
431  $page_obj->setPresentationTitle($page["title"]);
432  $page_obj->setOutputMode(IL_PAGE_PREVIEW);
433  $page_obj->setStyleId($this->slm_object->getStyleSheetId());
434  if (count($terms) > 1)
435  {
436  $page_obj->setGlossaryOverviewInfo(
437  ilSCORM2004ScoGUI::getGlossaryOverviewId(), $this->node_object);
438  }
439  $output .= $page_obj->showPage("export");
440  }
441  $output .= '<!-- BEGIN ilLMNavigation2 -->
442  <div class="ilc_page_bnav_BottomNavigation">
443  <!-- BEGIN ilLMNavigation_Prev -->
444  <div class="ilc_page_lnav_LeftNavigation">
445  <a class="ilc_page_lnavlink_LeftNavigationLink">
446  <img class="ilc_page_lnavimage_LeftNavigationImage" border="0" src="/templates/default/images/spacer.gif" alt="" title="" />&nbsp;'.$lng->txt('scplayer_previous').'</a>
447  </div>
448  <!-- END ilLMNavigation_Prev -->
449  <!-- BEGIN ilLMNavigation_Next -->
450  <div class="ilc_page_rnav_RightNavigation">
451  <a class="ilc_page_rnavlink_RightNavigationLink">'.$lng->txt('scplayer_next').'&nbsp;<img class="ilc_page_rnavimage_RightNavigationImage" border="0" src="/templates/default/images/spacer.gif" alt="" title="" /></a>
452  </div>
453  <!-- END ilLMNavigation_Next -->
454  <div style="clear:both;"></div>
455  </div>
456  <!-- END ilLMNavigation2 -->';
457 
458  // append glossary entries on the sco level
459  $output.= ilSCORM2004PageGUI::getGlossaryHTML($this->node_object);
460 
461  //insert questions
462  require_once './Modules/Scorm2004/classes/class.ilQuestionExporter.php';
463  $output = preg_replace_callback("/(Question;)(il__qst_[0-9]+)/",array(get_class($this), 'insertQuestion'),$output);
464  $output = preg_replace("/&#123;/","",$output);
465  $output = preg_replace("/&#125;/","",$output);
466  $output = "<script>var ScormApi=null;".ilQuestionExporter::questionsJS()."</script>".$output;
467 
468  $tpl->addOnloadCode('
469  ilias.questions.txt.wrong_answers = "'.$lng->txt("cont_wrong_answers").'";
470  ilias.questions.txt.tries_remaining = "'.$lng->txt("cont_tries_remaining").'";
471  ilias.questions.txt.please_try_again = "'.$lng->txt("cont_please_try_again").'";
472  ilias.questions.txt.all_answers_correct = "'.$lng->txt("cont_all_answers_correct").'";
473  ilias.questions.txt.nr_of_tries_exceeded = "'.$lng->txt("cont_nr_of_tries_exceeded").'";
474  ilias.questions.txt.correct_answers_shown = "'.$lng->txt("cont_correct_answers_shown").'";
475  ');
476 
477 
478  $tpl->addJavaScript("./Modules/Scorm2004/scripts/questions/question_handling.js");
479  //inline JS
480  $output .='<script type="text/javascript" src="./Modules/Scorm2004/scripts/questions/question_handling.js"></script>';
481 // $tpl->setContent($output);
482  $tpl->setVariable("CONTENT", $output);
483  }
484 
485  //callback function for question export
486  private function insertQuestion($matches) {
487  $q_exporter = new ilQuestionExporter(false);
488  return $q_exporter->exportQuestion($matches[2]);
489  }
490 
491 
495  public function selectExport()
496  {
497  switch ($_POST['select_export'])
498  {
499  case "exportScorm12":
500  case "exportScorm2004_3rd":
501  case "exportScorm2004_4th":
502  case "exportPDF":
503  case "exportHTML":
504  $this->ctrl->redirect($this, $_POST['select_export']);
505  break;
506  default:
507  $this->ctrl->redirect($this, 'showExportList');
508  break;
509  }
510  }
511 
512  function showExportList()
513  {
514  global $tpl, $ilCtrl, $lng;
515 
516  $this->setTabs();
517  $this->setLocator();
518 
519 
520  $template = new ilTemplate("tpl.scorm2004_export_buttons.html", true, true, 'Modules/Scorm2004');
521 
522  $buttons = array(
523  "exportScorm2004_3rd" => $lng->txt("scorm_create_export_file_scrom2004"),
524  "exportScorm2004_4th" => $lng->txt("scorm_create_export_file_scrom2004_4th"),
525  "exportScorm12" => $lng->txt("scorm_create_export_file_scrom12"),
526  "exportPDF" => $lng->txt("scorm_create_export_file_pdf"),
527  "exportHTML" => $lng->txt("scorm_create_export_file_html")
528  );
529  foreach ($buttons as $value => $text)
530  {
531  $template->setCurrentBlock('option');
532  $template->setVariable('OPTION_VALUE', $value);
533  $template->setVariable('OPTION_TITLE', ilUtil::prepareFormOutput($text));
534  $template->parseCurrentBlock();
535  }
536  $template->setVariable('EXPORT_TITLE', $lng->txt('export'));
537  $template->setVariable('EXPORT_LABEL', $lng->txt('type'));
538  $template->setVariable('FORMACTION', $ilCtrl->getFormAction($this, 'selectExport'));
539 
540  $export_files = $this->node_object->getExportFiles();
541 
542  include_once "./Modules/Scorm2004/classes/class.ilSCORM2004ExportTableGUI.php";
543  $table_gui = new ilSCORM2004ExportTableGUI($this, 'showExportList');
544  $data = array();
545  foreach ($export_files as $exp_file)
546  {
547  $filetype = $exp_file['type'];
548  // $public_str = ($exp_file["file"] == $this->object->getPublicExportFile($filetype))
549  // ? " <b>(".$this->lng->txt("public").")<b>"
550  // : "";
551  $file_arr = explode("__", $exp_file["file"]);
552  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));
553  }
554  $table_gui->setData($data);
555  $tpl->setVariable('ADM_CONTENT', $template->get() . "\n" . $table_gui->getHTML());
556 
557 
558  }
559 
561  {
562  $export = new ilScorm2004Export($this->node_object,'SCORM 2004 4th');
563  $export->buildExportFile();
564  $this->ctrl->redirect($this, "showExportList");
565  }
566 
567 
569  {
570  $export = new ilScorm2004Export($this->node_object,'SCORM 2004 3rd');
571  $export->buildExportFile();
572  $this->ctrl->redirect($this, "showExportList");
573  }
574 
575  function exportScorm12()
576  {
577  $export = new ilScorm2004Export($this->node_object,'SCORM 1.2');
578  $export->buildExportFile();
579  $this->ctrl->redirect($this, "showExportList");
580  }
581 
582  function exportHTML()
583  {
584  $export = new ilScorm2004Export($this->node_object,'HTML');
585  $export->buildExportFile();
586  $this->ctrl->redirect($this, "showExportList");
587  }
588 
589  function exportISO()
590  {
591  $export = new ilScorm2004Export($this->node_object,'ISO');
592  $export->buildExportFile();
593  $this->ctrl->redirect($this, "showExportList");
594  }
595 
596  function exportPDF()
597  {
598  $export = new ilScorm2004Export($this->node_object,'PDF');
599  $export->buildExportFile();
600  $this->ctrl->redirect($this, "showExportList");
601  }
602 
604  {
605  if(!isset($_POST["file"]))
606  {
607  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
608  }
609 
610  if (count($_POST["file"]) > 1)
611  {
612  $this->ilias->raiseError($this->lng->txt("cont_select_max_one_item"),$this->ilias->error_obj->MESSAGE);
613  }
614  $export = new ilSCORM2004Export($this->node_object);
615  $export_dir = $export->getExportDirectoryForType($_POST['type'][$_POST['file'][0]]);
616  ilUtil::deliverFile($export_dir."/".$_POST['file'][0], $_POST['file'][0]);
617  }
618 
623  {
624  global $lng, $tpl;
625 
626  if(!isset($_POST["file"]))
627  {
628  ilUtil::sendInfo($lng->txt("no_checkbox"),true);
629  $this->ctrl->redirect($this, "showExportList");
630  }
631 
632  ilUtil::sendQuestion($lng->txt("info_delete_sure"));
633  $export_files = $this->node_object->getExportFiles();
634 
635  include_once "./Modules/Scorm2004/classes/class.ilSCORM2004ExportTableGUI.php";
636  $table_gui = new ilSCORM2004ExportTableGUI($this, 'showExportList', true);
637  $data = array();
638  foreach ($export_files as $exp_file)
639  {
640  foreach ($_POST['file'] as $delete_file)
641  {
642  if (strcmp($delete_file, $exp_file['file']) == 0)
643  {
644  // $public_str = ($exp_file["file"] == $this->object->getPublicExportFile($exp_file["type"]))
645  // ? " <b>(".$this->lng->txt("public").")<b>"
646  // : "";
647  $file_arr = explode("__", $exp_file["file"]);
648  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));
649  }
650  }
651  }
652  $table_gui->setData($data);
653  $tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
654  }
655 
660  {
661  session_unregister("ilExportFiles");
662  $this->ctrl->redirect($this, "showExportList");
663  }
664 
665 
669  function deleteExportFile()
670  {
671  global $lng;
672  include_once "./Services/Utilities/classes/class.ilUtil.php";
673  $export = new ilSCORM2004Export($this->node_object);
674  foreach($_POST['file'] as $idx => $file)
675  {
676  $export_dir = $export->getExportDirectoryForType($_POST['type'][$idx]);
677  $exp_file = $export_dir."/".$file;
678  if (@is_file($exp_file))
679  {
680  unlink($exp_file);
681  }
682  }
683  ilUtil::sendSuccess($lng->txt('msg_deleted_export_files'), true);
684  $this->ctrl->redirect($this, "showExportList");
685  }
686 
688  {
689  $export_files = array();
690 
691  require_once "./Modules/Scorm2004/classes/class.ilSCORM2004Page.php";
692  include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
693  include_once "./Modules/File/classes/class.ilObjFile.php";
694  $tree = new ilTree($this->slm_object->getId());
695  $tree->setTableNames('sahs_sc13_tree', 'sahs_sc13_tree_node');
696  $tree->setTreeTablePK("slm_id");
697  foreach($tree->getSubTree($tree->getNodeData($this->node_object->getId()),true,'page') as $page)
698  {
699  $page_obj = new ilSCORM2004Page($page["obj_id"]);
700  $page_obj->buildDom();
701  $mob_ids = $page_obj->collectMediaObjects(false);
702  foreach($mob_ids as $mob_id)
703  {
704  if ($mob_id > 0 && ilObject::_exists($mob_id))
705  {
706  $media_obj = new ilObjMediaObject($mob_id);
707  $export_files[$i]["date"] = $media_obj->getCreateDate();
708  $export_files[$i]["size"] = filesize(ilObjMediaObject::_lookupStandardItemPath($mob_id,false,false));
709  $export_files[$i]["file"] = $media_obj->getTitle();
710  $export_files[$i]["type"] = $media_obj->getDescription();
711  $export_files[$i]["path"] = ilObjMediaObject::_lookupStandardItemPath($mob_id,false,false);
712  $this->ctrl->setParameter($this, "resource",
713  rawurlencode(ilObjMediaObject::_lookupStandardItemPath($mob_id,false,false)));
714  $export_files[$i]["link"] = $this->ctrl->getLinkTarget($this,"downloadResource");
715  $i++;
716  }
717  }
718  $file_ids = $page_obj->collectFileItems();
719  foreach($file_ids as $file_id)
720  {
721  $file_obj = new ilObjFile($file_id, false);
722  $export_files[$i]["date"] = $file_obj->getCreateDate();
723  $export_files[$i]["size"] = $file_obj->getFileSize();
724  $export_files[$i]["file"] = $file_obj->getFileName();
725  $export_files[$i]["type"] = $file_obj->getFileType();
726  $export_files[$i]["file_id"] = $file_id;
727  $this->ctrl->setParameter($this, "file_id",$file_id);
728  $export_files[$i]["link"] = $this->ctrl->getLinkTarget($this,"downloadFile","");
729  $i++;
730  }
731  unset($page_obj);
732  }
733 
734  return $export_files;
735  }
736 
737  function sco_resources()
738  {
739  global $tpl, $lng, $ilCtrl;;
740 
741  $this->setTabs();
742  $this->setLocator();
743  $i = 0;
744 
745  $export_files = $this->getExportResources();
746 
747  // create table
748  require_once("./Services/Table/classes/class.ilTableGUI.php");
749  $tbl = new ilTableGUI();
750 
751  // load files templates
752  $tpl->addBlockfile("ADM_CONTENT", "adm_content", "tpl.table.html");
753 
754  // load template for table content data
755  $tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.download_file_row.html", "Modules/LearningModule");
756 
757  $num = 0;
758 
759  $tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
760 
761  $tbl->setTitle($lng->txt("cont_files"));
762 
763  $tbl->setHeaderNames(array($lng->txt("cont_format"),
764  $lng->txt("cont_file"),
765  $lng->txt("size"), $lng->txt("date"),
766  ""));
767 
768  $cols = array("format", "file", "size", "date", "download");
769  $header_params = array("ref_id" => $_GET["ref_id"], "obj_id" => $_GET["obj_id"],
770  "cmd" => "sco_resources", "cmdClass" => strtolower(get_class($this)),
771  "cmdNode" => $_GET["cmdNode"], "baseClass" => $_GET["baseClass"]);
772  $tbl->setHeaderVars($cols, $header_params);
773  $tbl->setColumnWidth(array("10%", "30%", "20%", "20%","20%"));
774  $tbl->disable("sort");
775 
776  $tbl->setOrderColumn($_GET["sort_by"]);
777  $tbl->setOrderDirection($_GET["sort_order"]);
778  $tbl->setLimit($_GET["limit"]);
779  $tbl->setOffset($_GET["offset"]);
780  $tbl->setMaxCount($this->maxcount); // ???
781 
782 
783  $tbl->setMaxCount(count($export_files));
784 
785  // footer
786  $tbl->setFooter("tblfooter",$lng->txt("previous"),$lng->txt("next"));
787  //$tbl->disable("footer");
788 
789  $tbl->setMaxCount(count($export_files));
790  $export_files = array_slice($export_files, $_GET["offset"], $_GET["limit"]);
791 
792  $tbl->render();
793  if(count($export_files) > 0)
794  {
795  $i=0;
796  foreach($export_files as $exp_file)
797  {
798  if (!$exp_file["size"] > 0)
799  {
800  continue;
801  }
802 
803  $tpl->setCurrentBlock("tbl_content");
804  $tpl->setVariable("TXT_FILENAME", $exp_file["file"]);
805 
806  $css_row = ilUtil::switchColor($i++, "tblrow1", "tblrow2");
807  $tpl->setVariable("CSS_ROW", $css_row);
808 
809  $tpl->setVariable("TXT_SIZE", $exp_file["size"]);
810  $tpl->setVariable("TXT_FORMAT", $exp_file["type"]);
811 
812  $tpl->setVariable("TXT_DATE", $exp_file["date"]);
813 
814  $tpl->setVariable("TXT_DOWNLOAD", $lng->txt("download"));
815  //$tpl->setVariable("LINK_DOWNLOAD",
816  // $exp_file["link"]);
817  $ilCtrl->setParameter($this, "resource", rawurlencode($exp_file["path"]));
818  $ilCtrl->setParameter($this, "file_id", rawurlencode($exp_file["file_id"]));
819  $tpl->setVariable("LINK_DOWNLOAD",
820  $ilCtrl->getLinkTarget($this, "downloadResource"));
821 
822  $tpl->parseCurrentBlock();
823  }
824  } //if is_array
825  else
826  {
827  $tpl->setCurrentBlock("notfound");
828  $tpl->setVariable("TXT_OBJECT_NOT_FOUND", $lng->txt("obj_not_found"));
829  $tpl->setVariable("NUM_COLS", 4);
830  $tpl->parseCurrentBlock();
831  }
832  $tpl->parseCurrentBlock();
833  }
834 
835  function downloadResource()
836  {
837  $export_files = $this->getExportResources();
838 
839  if ($_GET["file_id"] > 0)
840  {
841  $file = new ilObjFile($_GET["file_id"], false);
842  }
843 
844  // check that file really belongs to SCORM module (security)
845  foreach ($export_files as $f)
846  {
847  if (is_object($file))
848  {
849  if ($f["file"] == $file->getFileName())
850  {
851  $file->sendFile();
852  }
853  }
854  else
855  {
856  if ($f["path"] == $_GET["resource"])
857  {
858  if (is_file($f["path"]))
859  {
860  ilUtil::deliverFile($f["path"], $f["file"]);
861  }
862  }
863  }
864  }
865  exit;
866  }
867 
868  function downloadFile()
869  {
870  $file = explode("_", $_GET["file_id"]);
871  require_once("./Modules/File/classes/class.ilObjFile.php");
872  $fileObj =& new ilObjFile($file[count($file) - 1], false);
873  $fileObj->sendFile();
874  exit;
875  }
876 
877  function import()
878  {
879  global $tpl, $lng;
880 
881  $this->setTabs();
882  $this->setLocator();
883 
884  $tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.scormeditor_sco_import.html", "Modules/Scorm2004");
885 
886  $tpl->setVariable("TYPE_IMG",ilUtil::getImagePath('icon_slm.gif'));
887  $tpl->setVariable("ALT_IMG", $lng->txt("obj_sahs"));
888 
889  $tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
890 
891  $tpl->setVariable("BTN_NAME", "importSave");
892 
893  // this leads to _top target which removes the left organization frame
894  //$tpl->setVariable("TARGET", ' target="'.ilFrameTargetInfo::_getFrame("MainContent").'" ');
895 
896  $tpl->setVariable("TXT_UPLOAD", $lng->txt("upload"));
897  $tpl->setVariable("TXT_CANCEL", $lng->txt("cancel"));
898  $tpl->setVariable("TXT_IMPORT_SCO", $lng->txt("import_sco_object"));
899  $tpl->setVariable("TXT_SELECT_FILE", $lng->txt("select_file"));
900  $tpl->setVariable("TXT_VALIDATE_FILE", $lng->txt("cont_validate_file"));
901 
902  // get the value for the maximal uploadable filesize from the php.ini (if available)
903  $umf=get_cfg_var("upload_max_filesize");
904  // get the value for the maximal post data from the php.ini (if available)
905  $pms=get_cfg_var("post_max_size");
906 
907  //convert from short-string representation to "real" bytes
908  $multiplier_a=array("K"=>1024, "M"=>1024*1024, "G"=>1024*1024*1024);
909 
910  $umf_parts=preg_split("/(\d+)([K|G|M])/", $umf, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
911  $pms_parts=preg_split("/(\d+)([K|G|M])/", $pms, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
912 
913  if (count($umf_parts) == 2) { $umf = $umf_parts[0]*$multiplier_a[$umf_parts[1]]; }
914  if (count($pms_parts) == 2) { $pms = $pms_parts[0]*$multiplier_a[$pms_parts[1]]; }
915 
916  // use the smaller one as limit
917  $max_filesize=min($umf, $pms);
918 
919  if (!$max_filesize) $max_filesize=max($umf, $pms);
920 
921  //format for display in mega-bytes
922  $max_filesize=sprintf("%.1f MB",$max_filesize/1024/1024);
923 
924  // gives out the limit as a little notice
925  $tpl->setVariable("TXT_FILE_INFO", $lng->txt("file_notice")." $max_filesize");
926  }
927 
928  function importSave()
929  {
930  global $_FILES, $rbacsystem;
931  global $ilias, $lng;
932 
933  // check if file was uploaded
934  $source = $_FILES["scormfile"]["tmp_name"];
935  if (($source == 'none') || (!$source))
936  {
937  $ilias->raiseError("No file selected!",$ilias->error_obj->MESSAGE);
938  }
939  // check create permission
940  if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], "sahs"))
941  {
942  $ilias->raiseError($lng->txt("no_create_permission"), $ilias->error_obj->WARNING);
943  }
944  // get_cfg_var("upload_max_filesize"); // get the may filesize form t he php.ini
945  switch ($__FILES["scormfile"]["error"])
946  {
947  case UPLOAD_ERR_INI_SIZE:
948  $ilias->raiseError($lng->txt("err_max_file_size_exceeds"),$ilias->error_obj->MESSAGE);
949  break;
950 
951  case UPLOAD_ERR_FORM_SIZE:
952  $ilias->raiseError($lng->txt("err_max_file_size_exceeds"),$ilias->error_obj->MESSAGE);
953  break;
954 
955  case UPLOAD_ERR_PARTIAL:
956  $ilias->raiseError($lng->txt("err_partial_file_upload"),$ilias->error_obj->MESSAGE);
957  break;
958 
959  case UPLOAD_ERR_NO_FILE:
960  $ilias->raiseError($lng->txt("err_no_file_uploaded"),$ilias->error_obj->MESSAGE);
961  break;
962  }
963 
964  $file = pathinfo($_FILES["scormfile"]["name"]);
965  $name = substr($file["basename"], 0, strlen($file["basename"]) - strlen($file["extension"]) - 1);
966  $file_path = $this->slm_object->getDataDirectory()."/".$this->node_object->getId()."/".$_FILES["scormfile"]["name"];
967  ilUtil::createDirectory($this->slm_object->getDataDirectory()."/".$this->node_object->getId());
968  ilUtil::moveUploadedFile($_FILES["scormfile"]["tmp_name"], $_FILES["scormfile"]["name"], $file_path);
969  ilUtil::unzip($file_path);
970  ilUtil::renameExecutables($this->slm_object->getDataDirectory()."/".$this->node_object->getId());
971 
972  include_once ("./Modules/Scorm2004/classes/ilSCORM13Package.php");
973  $newPack = new ilSCORM13Package();
974  $newPack->il_importSco($this->slm_object->getId(),$this->node_object->getId(),$this->slm_object->getDataDirectory()."/".$this->node_object->getId());
975 
976  $this->ctrl->redirect($this, "showOrganization");
977  }
978 
982  function cancel()
983  {
984  $this->ctrl->redirect($this, "showOrganization");
985  }
986 
993  static function getGlossaryOverviewId()
994  {
995  return "sco_glo_ov";
996  }
997 
1004  static function getGloOverviewOv($a_sco)
1005  {
1006  global $lng;
1007 
1008  $tpl = new ilTemplate("tpl.sco_glossary_overview.html", true, true, "Modules/Scorm2004");
1009 
1010  $terms = $a_sco->getGlossaryTermIds();
1011  foreach ($terms as $k => $t)
1012  {
1013  $tpl->setCurrentBlock("link");
1014  $tpl->setVariable("TXT_LINK", $t);
1015  $tpl->setVariable("ID_LINK", "glo_ov_t".$k);
1016  $tpl->parseCurrentBlock();
1017  }
1018 
1019  $tpl->setVariable("DIV_ID", ilSCORM2004ScoGUI::getGlossaryOverviewId());
1020  $tpl->setVariable("TXT_SCO_GLOSSARY", $lng->txt("cont_sco_glossary"));
1021  $tpl->setVariable("TXT_CLOSE", $lng->txt("close"));
1022 
1023  if (count($terms) > 1)
1024  {
1025  return $tpl->get();
1026  }
1027  else
1028  {
1029  return "";
1030  }
1031  }
1032 
1033 }
1034 ?>