ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSCORMPresentationGUI.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/ScormAicc/classes/class.ilObjSCORMLearningModule.php");
6 require_once("./Modules/ScormAicc/classes/SCORM/class.ilSCORMObjectGUI.php");
7 //require_once("./classes/class.ilMainMenuGUI.php");
8 //require_once("./classes/class.ilObjStyleSheet.php");
9 
21 {
22  var $ilias;
23  var $slm;
24  var $tpl;
25  var $lng;
26 
28  {
29  global $ilias, $tpl, $lng, $ilCtrl;
30 
31  $this->ilias =& $ilias;
32  $this->tpl =& $tpl;
33  $this->lng =& $lng;
34  $this->ctrl =& $ilCtrl;
35 
36  // Todo: check lm id
37  $this->slm =& new ilObjSCORMLearningModule($_GET["ref_id"], true);
38  }
39 
43  function &executeCommand()
44  {
45  global $ilAccess, $ilLog, $ilias, $lng;
46 
47  $next_class = $this->ctrl->getNextClass($this);
48  $cmd = $this->ctrl->getCmd("frameset");
49 
50  if (!$ilAccess->checkAccess("write", "", $_GET["ref_id"]) &&
51  (!$ilAccess->checkAccess("read", "", $_GET["ref_id"]) ||
52  !$this->slm->getOnline()))
53  {
54  $ilias->raiseError($lng->txt("permission_denied"), $ilias->error_obj->WARNING);
55  }
56 
57  switch($next_class)
58  {
59  default:
60  $this->$cmd();
61  }
62  }
63 
64 
65  function attrib2arr(&$a_attributes)
66  {
67  $attr = array();
68 
69  if(!is_array($a_attributes))
70  {
71  return $attr;
72  }
73  foreach ($a_attributes as $attribute)
74  {
75  $attr[$attribute->name()] = $attribute->value();
76  }
77 
78  return $attr;
79  }
80 
81 
86  function frameset() {
87  global $lng;
88  $javascriptAPI = true;
89  include_once("./Modules/ScormAicc/classes/SCORM/class.ilSCORMObject.php");
90  $items = ilSCORMObject::_lookupPresentableItems($this->slm->getId());
91 
92  //check for max_attempts and raise error if max_attempts is exceeded
93  if ($this->get_max_attempts()!=0) {
94  if ($this->get_actual_attempts() >= $this->get_max_attempts()) {
95  header('Content-Type: text/html; charset=utf-8');
96  echo($lng->txt("cont_sc_max_attempt_exceed"));
97  exit;
98  }
99  }
100 
101  //count attempt
102  //Cause there is no way to check if the Java-Applet is sucessfully loaded, an attempt equals opening the SCORM player
103 
104  $this->increase_attempt();
105  $this->save_module_version();
106 
107  if ($javascriptAPI == false) {
108  if (count($items) > 1
109  || strtolower(get_class($this->slm)) == "ilobjaicclearningmodule"
110  || strtolower(get_class($this->slm)) == "ilobjhacplearningmodule")
111  {
112  $this->ctrl->setParameter($this, "expand", "1");
113  $exp_link = $this->ctrl->getLinkTarget($this, "explorer");
114  $this->tpl = new ilTemplate("tpl.sahs_pres_frameset.html", false, false, "Modules/ScormAicc");
115  $this->tpl->setVariable("EXPLORER_LINK", $exp_link);
116  $api_link = $this->ctrl->getLinkTarget($this, "api");
117  $this->tpl->setVariable("API_LINK", $api_link);
118  $pres_link = $this->ctrl->getLinkTarget($this, "view");
119  $this->tpl->setVariable("PRESENTATION_LINK", $pres_link);
120  $this->tpl->show("DEFAULT", false);
121  }
122  else if (count($items) == 1)
123  {
124  $this->tpl = new ilTemplate("tpl.sahs_pres_frameset_one_page.html", false, false, "Modules/ScormAicc");
125  $this->ctrl->setParameter($this, "autolaunch", $items[0]);
126  $api_link = $this->ctrl->getLinkTarget($this, "api");
127  $this->tpl->setVariable("API_LINK", $api_link);
128  $pres_link = $this->ctrl->getLinkTarget($this, "view");
129  $this->tpl->setVariable("PRESENTATION_LINK", $pres_link);
130  $this->tpl->show("DEFAULT", false);
131  }
132  } else {
133  $debug = $this->slm->getDebug();
134  $template = "tpl.sahs_pres_frameset_js";
135  if ($debug) $template .= "_debug";
136  if (count($items) > 1
137  || strtolower(get_class($this->slm)) == "ilobjaicclearningmodule"
138  || strtolower(get_class($this->slm)) == "ilobjhacplearningmodule")
139  {
140  $template .= ".html";
141  $this->ctrl->setParameter($this, "expand", "1");
142  $this->ctrl->setParameter($this, "jsApi", "1");
143  $exp_link = $this->ctrl->getLinkTarget($this, "explorer");
144  $this->tpl = new ilTemplate($template, false, false, "Modules/ScormAicc");
145  $this->tpl->setVariable("EXPLORER_LINK", $exp_link);
146  $pres_link = $this->ctrl->getLinkTarget($this, "contentSelect");
147  $this->tpl->setVariable("PRESENTATION_LINK", $pres_link);
148  } else {
149  $template .= "_one_page.html";
150  $this->tpl = new ilTemplate($template, false, false, "Modules/ScormAicc");
151  $this->ctrl->setParameter($this, "autolaunch", $items[0]);
152  }
153  $api_link = $this->ctrl->getLinkTarget($this, "apiInitData");
154  $this->tpl->setVariable("API_LINK", $api_link);
155  $this->tpl->show("DEFAULT", false);
156  }
157 
158  exit;
159 
160  }
161 
165  function get_max_attempts() {
166 
167  global $ilDB;
168 
169  $val_set = $ilDB->queryF('SELECT * FROM sahs_lm WHERE id = %s',
170  array('integer'), array($this->slm->getId()));
171  $val_rec = $ilDB->fetchAssoc($val_set);
172 
173  return $val_rec["max_attempt"];
174  }
175 
179  function get_actual_attempts() {
180  global $ilDB, $ilUser;
181 
182  $val_set = $ilDB->queryF('
183  SELECT * FROM scorm_tracking
184  WHERE user_id = %s
185  AND sco_id = %s
186  AND lvalue= %s
187  AND obj_id = %s',
188  array('integer','integer','text','integer'),
189  array($ilUser->getId(),0,'package_attempts',$this->slm->getId())
190  );
191  $val_rec = $ilDB->fetchAssoc($val_set);
192 
193  $val_rec["rvalue"] = str_replace("\r\n", "\n", $val_rec["rvalue"]);
194  if ($val_rec["rvalue"] == null) {
195  $val_rec["rvalue"]=0;
196  }
197 
198  return $val_rec["rvalue"];
199  }
200 
204  function increase_attempt() {
205  global $ilDB, $ilUser;
206 
207  //get existing account - sco id is always 0
208  $val_set = $ilDB->queryF('
209  SELECT * FROM scorm_tracking
210  WHERE user_id = %s
211  AND sco_id = %s
212  AND lvalue= %s
213  AND obj_id = %s',
214  array('integer','integer','text','integer'),
215  array($ilUser->getId(),0,'package_attempts',$this->slm->getId())
216  );
217 
218  $val_rec = $ilDB->fetchAssoc($val_set);
219 
220  $val_rec["rvalue"] = str_replace("\r\n", "\n", $val_rec["rvalue"]);
221  if ($val_rec["rvalue"] == null) {
222  $val_rec["rvalue"]=0;
223  }
224  $new_rec = $val_rec["rvalue"]+1;
225  //increase attempt by 1
226  if($ilDB->numRows($val_set) > 0)
227  {
228  $ilDB->update('scorm_tracking',
229  array(
230  'rvalue' => array('clob', $new_rec),
231  'c_timestamp' => array('timestamp', ilUtil::now())
232  ),
233  array(
234  'user_id' => array('integer', $ilUser->getId()),
235  'sco_id' => array('integer', 0),
236  'lvalue' => array('text', 'package_attempts'),
237  'obj_id' => array('integer', $this->slm->getId())
238  )
239  );
240  }
241  else
242  {
243  $ilDB->insert('scorm_tracking', array(
244  'obj_id' => array('integer', $this->slm->getId()),
245  'user_id' => array('integer', $ilUser->getId()),
246  'sco_id' => array('integer', 0),
247  'lvalue' => array('text', 'package_attempts'),
248  'rvalue' => array('clob', $new_rec),
249  'c_timestamp' => array('timestamp', ilUtil::now())
250  ));
251  }
252 
253  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
254  ilLPStatusWrapper::_updateStatus($this->slm->getId(), $ilUser->getId());
255 
256  }
257 
261  function save_module_version() {
262  global $ilDB, $ilUser;
263 
264  $val_set = $ilDB->queryF('
265  SELECT * FROM scorm_tracking
266  WHERE user_id = %s
267  AND sco_id = %s
268  AND lvalue= %s
269  AND obj_id = %s',
270  array('integer','integer','text','integer'),
271  array($ilUser->getId(),0,'module_version',$this->slm->getId())
272 
273  );
274 
275  if($ilDB->numRows($val_set) > 0)
276  {
277  $ilDB->update('scorm_tracking',
278  array(
279  'rvalue' => array('clob', $this->slm->getModuleVersion()),
280  'c_timestamp' => array('timestamp', ilUtil::now())
281  ),
282  array(
283  'user_id' => array('integer', $ilUser->getId()),
284  'sco_id' => array('integer', 0),
285  'lvalue' => array('text', 'module_version'),
286  'obj_id' => array('integer', $this->slm->getId())
287  )
288  );
289  }
290  else
291  {
292  $ilDB->insert('scorm_tracking', array(
293  'obj_id' => array('integer', $this->slm->getId()),
294  'user_id' => array('integer', $ilUser->getId()),
295  'sco_id' => array('integer', 0),
296  'lvalue' => array('text', 'module_version'),
297  'rvalue' => array('clob', $this->slm->getModuleVersion()),
298  'c_timestamp' => array('timestamp', ilUtil::now())
299  ));
300  }
301 
302  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
303  ilLPStatusWrapper::_updateStatus($this->slm->getId(), $ilUser->getId());
304 
305  }
306 
310  function explorer($a_target = "sahs_content")
311  {
312  global $ilBench, $ilLog;
313 
314  $ilBench->start("SCORMExplorer", "initExplorer");
315 
316  $this->tpl = new ilTemplate("tpl.sahs_exp_main.html", true, true, "Modules/ScormAicc");
317 
318  require_once("./Modules/ScormAicc/classes/SCORM/class.ilSCORMExplorer.php");
319  $exp = new ilSCORMExplorer($this->ctrl->getLinkTarget($this, "view"), $this->slm);
320  $exp->setTargetGet("obj_id");
321  $exp->setFrameTarget($a_target);
322 
323  //$exp->setFiltered(true);
324  $jsApi=false;
325  if ($_GET["jsApi"] == "1") $jsApi=true;
326 
327  if ($_GET["scexpand"] == "")
328  {
329  $mtree = new ilSCORMTree($this->slm->getId());
330  $expanded = $mtree->readRootId();
331  }
332  else
333  {
334  $expanded = $_GET["scexpand"];
335  }
336  $exp->setExpand($expanded);
337 
338  $exp->forceExpandAll(true, false);
339  $ilBench->stop("SCORMExplorer", "initExplorer");
340 
341  // build html-output
342  $ilBench->start("SCORMExplorer", "setOutput");
343  $exp->setOutput(0);
344  $ilBench->stop("SCORMExplorer", "setOutput");
345 
346  $ilBench->start("SCORMExplorer", "getOutput");
347  $output = $exp->getOutput($jsApi);
348  $ilBench->stop("SCORMExplorer", "getOutput");
349 
350  $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
351  $this->tpl->addBlockFile("CONTENT", "content", "tpl.sahs_explorer.html", "Modules/ScormAicc");
352  //$this->tpl->setVariable("TXT_EXPLORER_HEADER", $this->lng->txt("cont_content"));
353  $this->tpl->setVariable("EXP_REFRESH", $this->lng->txt("refresh"));
354  $this->tpl->setVariable("EXPLORER",$output);
355  $this->tpl->setVariable("ACTION", "ilias.php?baseClass=ilSAHSPresentationGUI&cmd=".$_GET["cmd"]."&frame=".$_GET["frame"].
356  "&ref_id=".$this->slm->getRefId()."&scexpand=".$_GET["scexpand"]);
357  $this->tpl->parseCurrentBlock();
358  $this->tpl->show();
359  }
360 
361 
365  function view()
366  {
367  $sc_gui_object =& ilSCORMObjectGUI::getInstance($_GET["obj_id"]);
368 
369  if(is_object($sc_gui_object))
370  {
371  $sc_gui_object->view();
372  }
373 
374  $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
375  $this->tpl->show(false);
376  }
377 
378  function contentSelect() {
379  global $lng;
380  $this->tpl = new ilTemplate("tpl.scorm_content_select.html", true, true, "Modules/ScormAicc");
381  $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
382  $this->tpl->setVariable('TXT_SPECIALPAGE',$lng->txt("seq_toc"));
383  $this->tpl->show();
384  }
385 
389  function apiInitData() {
390  global $ilias, $ilLog, $ilUser, $lng, $ilDB;
391 
392  function encodeURIComponent($str) {
393  $revert = array('%21'=>'!', '%2A'=>'*', '%27'=>"'", '%28'=>'(', '%29'=>')', '%7E'=>'~');
394  return strtr(rawurlencode($str), $revert);
395  }
396 
397  if ($_GET["ref_id"] == "") {
398  print ('alert("no start without ref_id");');
399  die;
400  }
401  $slm_obj =& new ilObjSCORMLearningModule($_GET["ref_id"]);
402 
403  header('Content-Type: text/javascript; charset=UTF-8');
404  print("function iliasApi() {\r\n");
405  $js_data = file_get_contents("./Modules/ScormAicc/scripts/basisAPI.js");
406  echo $js_data;
407  $js_data = file_get_contents("./Modules/ScormAicc/scripts/SCORM1_2standard.js");//want to give opportunities to different files (Uwe Kohnle)
408  echo $js_data;
409  print("}\r\n");
410 
411  //variables to set in administration interface
412  $b_checkSetValues='true';
413  $b_storeObjectives='true';
414  $b_storeInteractions='true';
415  $b_readInteractions='false';
416  $c_storeSessionTime='s';//n=no, s=sco, i=ilias
417  $i_lessonScoreMax='-1';
418  $i_lessonMasteryScore='-1';
419 
420  //other variables
421  $b_messageLog='false';
422  if ($ilLog->current_log_level == 30) $b_messageLog='true';
423  $launchId='0';
424  if ($_GET["autolaunch"] != "") $launchId=$_GET["autolaunch"];
425  $session_timeout = 0; //unlimited sessions
426  if ($slm_obj->getSession()) {
427  $session_timeout = (int)($ilias->ini->readVariable("session","expire"))/2;
428  }
429  $b_autoReview='false';
430  if ($this->slm->getAutoReview()) $b_autoReview='true';
431  $b_debug='false';
432  if ($this->slm->getDebug()) $b_debug='true';
433  $b_autoContinue='false';
434  if ($this->slm->getAutoContinue()) $b_autoContinue='true';
435 
436  $s_out='IliasScormVars={'
437  .'refId:'.$_GET["ref_id"].','
438  .'objId:'.$this->slm->getId().','
439  .'launchId:'.$launchId.','
440  .'launchNr:0,'
441  .'pingSession:'. $session_timeout.','
442  .'studentId:'.$ilias->account->getId().','
443  .'studentName:"'.encodeURIComponent($ilias->account->getLastname().', '.$ilias->account->getFirstname()).'",'
444  .'studentLogin:"'.encodeURIComponent($ilias->account->getLogin()).'",'
445  .'studentOu:"'.encodeURIComponent($ilias->account->getDepartment()).'",'
446  .'credit:"'.str_replace("_", "-", $this->slm->getCreditMode()).'",'
447  .'lesson_mode:"'.$this->slm->getDefaultLessonMode().'",'
448  .'b_autoReview:'.$b_autoReview.','
449  .'b_messageLog:'.$b_messageLog.','
450  .'b_checkSetValues:'.$b_checkSetValues.','
451  .'b_storeObjectives:'.$b_storeObjectives.','
452  .'b_storeInteractions:'.$b_storeInteractions.','
453  .'b_readInteractions:'.$b_readInteractions.','
454  .'c_storeSessionTime:"'.$c_storeSessionTime.'",'
455  .'b_autoContinue:'.$b_autoContinue.','
456  .'i_lessonScoreMax:'.$i_lessonScoreMax.','
457  .'i_lessonMasteryScore:'.$i_lessonMasteryScore.','
458  .'b_debug:'.$b_debug.','
459  .'dataDirectory:"'.encodeURIComponent($this->slm->getDataDirectory("output").'/').'",'
460  .'img:{'
461  .'asset:"'.encodeURIComponent(ilUtil::getImagePath('scorm/asset.gif')).'",'
462  .'browsed:"'.encodeURIComponent(ilUtil::getImagePath('scorm/browsed.gif')).'",'
463  .'completed:"'.encodeURIComponent(ilUtil::getImagePath('scorm/completed.gif')).'",'
464  .'failed:"'.encodeURIComponent(ilUtil::getImagePath('scorm/failed.gif')).'",'
465  .'incomplete:"'.encodeURIComponent(ilUtil::getImagePath('scorm/incomplete.gif')).'",'
466  .'not_attempted:"'.encodeURIComponent(ilUtil::getImagePath('scorm/not_attempted.gif')).'",'
467  .'passed:"'.encodeURIComponent(ilUtil::getImagePath('scorm/passed.gif')).'",'
468  .'running:"'.encodeURIComponent(ilUtil::getImagePath('scorm/running.gif')).'"'
469  .'},'
470  .'statusTxt:{'
471  .'wait:"'.encodeURIComponent($lng->txt("please_wait")).'",'
472  .'status:"'.encodeURIComponent($lng->txt("cont_status")).'",'
473  .'browsed:"'.encodeURIComponent($lng->txt("cont_sc_stat_browsed")).'",'
474  .'completed:"'.encodeURIComponent($lng->txt("cont_sc_stat_completed")).'",'
475  .'failed:"'.encodeURIComponent($lng->txt("cont_sc_stat_failed")).'",'
476  .'incomplete:"'.encodeURIComponent($lng->txt("cont_sc_stat_incomplete")).'",'
477  .'not_attempted:"'.encodeURIComponent($lng->txt("cont_sc_stat_not_attempted")).'",'
478  .'passed:"'.encodeURIComponent($lng->txt("cont_sc_stat_passed")).'",'
479  .'running:"'.encodeURIComponent($lng->txt("cont_sc_stat_running")).'"'
480  .'}'
481  .'};';
482 
483 // header('Content-Type: text/javascript; charset=UTF-8');
484  print($s_out."\r\n");
485  //prevdata
486  $s_out = 'IliasScormData=[';
487  $tquery = 'SELECT sco_id,lvalue,rvalue FROM scorm_tracking '
488  .'WHERE user_id = %s AND obj_id = %s '
489  ."AND sco_id > 0 AND lvalue <> 'cmi.core.entry' AND lvalue <> 'cmi.core.session_time'";
490  if ($b_readInteractions == 'false') $tquery.=" AND LEFT(lvalue,16) <> 'cmi.interactions'";
491  $val_set = $ilDB->queryF($tquery,
492  array('integer','integer'),
493  array($ilUser->getId(),$this->slm->getId())
494  );
495  while($val_rec = $ilDB->fetchAssoc($val_set)) {
496  if (!strpos($val_rec["lvalue"],"._count"))
497  $s_out.='['.$val_rec["sco_id"].',"'.$val_rec["lvalue"].'","'.encodeURIComponent($val_rec["rvalue"]).'"],';
498  }
499  //manifestData
500  $val_set = $ilDB->queryF('
501  SELECT sc_item.obj_id,maxtimeallowed,timelimitaction,datafromlms,masteryscore
502  FROM sc_item, scorm_object
503  WHERE scorm_object.obj_id=sc_item.obj_id
504  AND scorm_object.c_type = %s
505  AND scorm_object.slm_id = %s',
506  array('text','integer'),
507  array('sit',$this->slm->getId())
508  );
509  while($val_rec = $ilDB->fetchAssoc($val_set)) {
510  if($val_rec["maxtimeallowed"]!=null)
511  $s_out.='['.$val_rec["obj_id"].',"cmi.student_data.max_time_allowed","'.encodeURIComponent($val_rec["maxtimeallowed"]).'"],';
512  if($val_rec["timelimitaction"]!=null)
513  $s_out.='['.$val_rec["obj_id"].',"cmi.student_data.time_limit_action","'.encodeURIComponent($val_rec["timelimitaction"]).'"],';
514  if($val_rec["datafromlms"]!=null)
515  $s_out.='['.$val_rec["obj_id"].',"cmi.launch_data","'.encodeURIComponent($val_rec["datafromlms"]).'"],';
516  if($val_rec["masteryscore"]!=null)
517  $s_out.='['.$val_rec["obj_id"].',"cmi.student_data.mastery_score","'.encodeURIComponent($val_rec["masteryscore"]).'"],';
518  }
519  if(substr($s_out,(strlen($s_out)-1))==",") $s_out=substr($s_out,0,(strlen($s_out)-1));
520  $s_out.='];';
521  print($s_out."\r\n");
522 
523  //URLs
524  $s_out='IliasScormResources=[';
525  $val_set = $ilDB->queryF("
526  SELECT scorm_tree.lft, scorm_tree.child,
527  CASE WHEN sc_resource.scormtype = 'asset' THEN 1 ELSE 0 END AS asset,
528  sc_resource.href
529  FROM scorm_tree, sc_resource, sc_item
530  WHERE scorm_tree.slm_id=%s
531  AND sc_item.obj_id=scorm_tree.child
532  AND sc_resource.import_id=sc_item.identifierref
533  ORDER BY scorm_tree.lft",
534  array('integer'),
535  array($this->slm->getId())
536  );
537  while($val_rec = $ilDB->fetchAssoc($val_set)) {
538  $s_out.='['.$val_rec["lft"].','.$val_rec["child"].','.$val_rec["asset"].',"'.encodeURIComponent($val_rec["href"]).'"],';
539  }
540  if(substr($s_out,(strlen($s_out)-1))==",") $s_out=substr($s_out,0,(strlen($s_out)-1));
541  $s_out.="];\r\n";
542  // set alternative API name
543  if ($this->slm->getAPIAdapterName() != "API") $s_out.='var '.$this->slm->getAPIAdapterName().'=new iliasApi();';
544  else $s_out.='var API=new iliasApi();';
545 
546  print($s_out);
547 
548  }
549 
550 
551  function api()
552  {
553  global $ilias;
554 
555  $slm_obj =& new ilObjSCORMLearningModule($_GET["ref_id"]);
556 
557  $this->tpl = new ilTemplate("tpl.sahs_api.html", true, true, "Modules/ScormAicc");
558 
559  // for scorm modules with only one presentable item: launch item
560  if ($_GET["autolaunch"] != "")
561  {
562  $this->tpl->setCurrentBlock("auto_launch");
563  include_once("./Modules/ScormAicc/classes/SCORM/class.ilSCORMItem.php");
564  include_once("./Modules/ScormAicc/classes/SCORM/class.ilSCORMResource.php");
565  $sc_object =& new ilSCORMItem($_GET["autolaunch"]);
566  $id_ref = $sc_object->getIdentifierRef();
567  $sc_res_id = ilSCORMResource::_lookupIdByIdRef($id_ref, $sc_object->getSLMId());
568  $scormtype = strtolower(ilSCORMResource::_lookupScormType($sc_res_id));
569 
570  if ($scormtype == "asset")
571  {
572  $item_command = "IliasLaunchAsset";
573  }
574  else
575  {
576  $item_command = "IliasLaunchSahs";
577  }
578  $this->tpl->setVariable("AUTO_LAUNCH_ID", $_GET["autolaunch"]);
579  $this->tpl->setVariable("AUTO_LAUNCH_CMD", "this.autoLaunch();");
580  $this->tpl->setVariable("AUTO_LAUNCH_ITEM_CMD", $item_command);
581  $this->tpl->parseCurrentBlock();
582  }
583 
584  //unlimited sessions
585  if ($slm_obj->getSession()) {
586  $session_timeout = (int)($ilias->ini->readVariable("session","expire"))/2;
587  } else {
588  $session_timeout = 0;
589  }
590  $this->tpl->setVariable("PING_SESSION",$session_timeout);
591 
592  $this->tpl->setVariable("USER_ID",$ilias->account->getId());
593  $this->tpl->setVariable("USER_FIRSTNAME",$ilias->account->getFirstname());
594  $this->tpl->setVariable("USER_LASTNAME",$ilias->account->getLastname());
595  $this->tpl->setVariable("USER_LOGIN",$ilias->account->getLogin());
596  $this->tpl->setVariable("USER_OU",$ilias->account->getDepartment());
597  $this->tpl->setVariable("REF_ID",$_GET["ref_id"]);
598  $this->tpl->setVariable("SESSION_ID",session_id());
599  $this->tpl->setVariable("CODE_BASE", "http://".$_SERVER['SERVER_NAME'].substr($_SERVER['PHP_SELF'], 0, strpos ($_SERVER['PHP_SELF'], "/ilias.php")));
600 
601  $this->tpl->parseCurrentBlock();
602  $this->tpl->show(false);
603  exit;
604  }
605 
610  function launchSahs()
611  {
612  global $ilUser, $ilDB;
613 
614  $sco_id = ($_GET["sahs_id"] == "")
615  ? $_POST["sahs_id"]
616  : $_GET["sahs_id"];
617  $ref_id = ($_GET["ref_id"] == "")
618  ? $_POST["ref_id"]
619  : $_GET["ref_id"];
620 
621  $this->slm =& new ilObjSCORMLearningModule($ref_id, true);
622 
623  include_once("./Modules/ScormAicc/classes/SCORM/class.ilSCORMItem.php");
624  include_once("./Modules/ScormAicc/classes/SCORM/class.ilSCORMResource.php");
625  $item =& new ilSCORMItem($sco_id);
626 
627  $id_ref = $item->getIdentifierRef();
628  $resource =& new ilSCORMResource();
629  $resource->readByIdRef($id_ref, $item->getSLMId());
630  //$slm_obj =& new ilObjSCORMLearningModule($_GET["ref_id"]);
631  $href = $resource->getHref();
632  $this->tpl = new ilTemplate("tpl.sahs_launch_cbt.html", true, true, "Modules/ScormAicc");
633  $this->tpl->setVariable("HREF", $this->slm->getDataDirectory("output")."/".$href);
634 
635  // set item data
636  $this->tpl->setVariable("LAUNCH_DATA", $item->getDataFromLms());
637  $this->tpl->setVariable("MAST_SCORE", $item->getMasteryScore());
638  $this->tpl->setVariable("MAX_TIME", $item->getMaxTimeAllowed());
639  $this->tpl->setVariable("LIMIT_ACT", $item->getTimeLimitAction());
640 
641  // set alternative API name
642  if ($this->slm->getAPIAdapterName() != "API")
643  {
644  $this->tpl->setCurrentBlock("alt_api_ref");
645  $this->tpl->setVariable("API_NAME", $this->slm->getAPIAdapterName());
646  $this->tpl->parseCurrentBlock();
647  }
648 
649  $val_set = $ilDB->queryF('
650  SELECT * FROM scorm_tracking
651  WHERE user_id = %s
652  AND sco_id = %s
653  AND obj_id = %s',
654  array('integer','integer','integer'),
655  array($ilUser->getId(),$sco_id,$this->slm->getId())
656  );
657  $re_value = array();
658  while($val_rec = $ilDB->fetchAssoc($val_set))
659  {
660  $val_rec["rvalue"] = str_replace("\r\n", "\n", $val_rec["rvalue"]);
661  $val_rec["rvalue"] = str_replace("\r", "\n", $val_rec["rvalue"]);
662  $val_rec["rvalue"] = str_replace("\n", "\\n", $val_rec["rvalue"]);
663  $re_value[$val_rec["lvalue"]] = $val_rec["rvalue"];
664  }
665 
666  foreach($re_value as $var => $value)
667  {
668  switch ($var)
669  {
670  case "cmi.core.lesson_location":
671  case "cmi.core.lesson_status":
672  case "cmi.core.entry":
673  case "cmi.core.score.raw":
674  case "cmi.core.score.max":
675  case "cmi.core.score.min":
676  case "cmi.core.total_time":
677  case "cmi.core.exit":
678  case "cmi.suspend_data":
679  case "cmi.comments":
680  case "cmi.student_preference.audio":
681  case "cmi.student_preference.language":
682  case "cmi.student_preference.speed":
683  case "cmi.student_preference.text":
684  $this->setSingleVariable($var, $value);
685  break;
686 
687  case "cmi.objectives._count":
688  $this->setSingleVariable($var, $value);
689  $this->setArray("cmi.objectives", $value, "id", $re_value);
690  $this->setArray("cmi.objectives", $value, "score.raw", $re_value);
691  $this->setArray("cmi.objectives", $value, "score.max", $re_value);
692  $this->setArray("cmi.objectives", $value, "score.min", $re_value);
693  $this->setArray("cmi.objectives", $value, "status", $re_value);
694  break;
695 
696  case "cmi.interactions._count":
697  $this->setSingleVariable($var, $value);
698  $this->setArray("cmi.interactions", $value, "id", $re_value);
699  for($i=0; $i<$value; $i++)
700  {
701  $var2 = "cmi.interactions.".$i.".objectives._count";
702  if (isset($v_array[$var2]))
703  {
704  $cnt = $v_array[$var2];
705  $this->setArray("cmi.interactions.".$i.".objectives",
706  $cnt, "id", $re_value);
707  /*
708  $this->setArray("cmi.interactions.".$i.".objectives",
709  $cnt, "score.raw", $re_value);
710  $this->setArray("cmi.interactions.".$i.".objectives",
711  $cnt, "score.max", $re_value);
712  $this->setArray("cmi.interactions.".$i.".objectives",
713  $cnt, "score.min", $re_value);
714  $this->setArray("cmi.interactions.".$i.".objectives",
715  $cnt, "status", $re_value);*/
716  }
717  }
718  $this->setArray("cmi.interactions", $value, "time", $re_value);
719  $this->setArray("cmi.interactions", $value, "type", $re_value);
720  for($i=0; $i<$value; $i++)
721  {
722  $var2 = "cmi.interactions.".$i.".correct_responses._count";
723  if (isset($v_array[$var2]))
724  {
725  $cnt = $v_array[$var2];
726  $this->setArray("cmi.interactions.".$i.".correct_responses",
727  $cnt, "pattern", $re_value);
728  $this->setArray("cmi.interactions.".$i.".correct_responses",
729  $cnt, "weighting", $re_value);
730  }
731  }
732  $this->setArray("cmi.interactions", $value, "student_response", $re_value);
733  $this->setArray("cmi.interactions", $value, "result", $re_value);
734  $this->setArray("cmi.interactions", $value, "latency", $re_value);
735  break;
736  }
737  }
738 
739  global $lng;
740  $this->tpl->setCurrentBlock("switch_icon");
741  $this->tpl->setVariable("SCO_ID", $_GET["sahs_id"]);
742  $this->tpl->setVariable("SCO_ICO", ilUtil::getImagePath("scorm/running.gif"));
743  $this->tpl->setVariable("SCO_ALT",
744  $lng->txt("cont_status").": "
745  .$lng->txt("cont_sc_stat_running")
746  );
747  $this->tpl->parseCurrentBlock();
748 
749  // set icon, if more than one SCO/Asset is presented
750  $items = ilSCORMObject::_lookupPresentableItems($this->slm->getId());
751  if (count($items) > 1
752  || strtolower(get_class($this->slm)) == "ilobjaicclearningmodule"
753  || strtolower(get_class($this->slm)) == "ilobjhacplearningmodule")
754  {
755  $this->tpl->setVariable("SWITCH_ICON_CMD", "switch_icon();");
756  }
757 
758 
759  // lesson mode
760  $lesson_mode = $this->slm->getDefaultLessonMode();
761  if ($this->slm->getAutoReview())
762  {
763  if ($re_value["cmi.core.lesson_status"] == "completed" ||
764  $re_value["cmi.core.lesson_status"] == "passed" ||
765  $re_value["cmi.core.lesson_status"] == "failed")
766  {
767  $lesson_mode = "review";
768  }
769  }
770  $this->tpl->setVariable("LESSON_MODE", $lesson_mode);
771 
772  // credit mode
773  if ($lesson_mode == "normal")
774  {
775  $this->tpl->setVariable("CREDIT_MODE",
776  str_replace("_", "-", $this->slm->getCreditMode()));
777  }
778  else
779  {
780  $this->tpl->setVariable("CREDIT_MODE", "no-credit");
781  }
782 
783  // init cmi.core.total_time, cmi.core.lesson_status and cmi.core.entry
784  $sahs_obj_id = ilObject::_lookupObjId($_GET["ref_id"]);
785  if (!isset($re_value["cmi.core.total_time"]))
786  {
787  $item->insertTrackData("cmi.core.total_time", "0000:00:00", $sahs_obj_id);
788  }
789  if (!isset($re_value["cmi.core.lesson_status"]))
790  {
791  $item->insertTrackData("cmi.core.lesson_status", "not attempted", $sahs_obj_id);
792  }
793  if (!isset($re_value["cmi.core.entry"]))
794  {
795  $item->insertTrackData("cmi.core.entry", "", $sahs_obj_id);
796  }
797 
798  $this->tpl->show();
799  //echo htmlentities($this->tpl->get()); exit;
800  }
801 
802  function finishSahs ()
803  {
804  global $lng;
805  $this->tpl = new ilTemplate("tpl.sahs_finish_cbt.html", true, true, "Modules/ScormAicc");
806  $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
807 
808  // block not in template
809  // $this->tpl->setCurrentBlock("switch_icon");
810  $this->tpl->setVariable("SCO_ID", $_GET["sahs_id"]);
811  $this->tpl->setVariable("SCO_ICO", ilUtil::getImagePath(
812  "scorm/".str_replace(" ", "_", $_GET["status"]).'.gif')
813  );
814  $this->tpl->setVariable("SCO_ALT",
815  $lng->txt("cont_status").": "
816  .$lng->txt("cont_sc_stat_".str_replace(" ", "_", $_GET["status"])).", "
817  .$lng->txt("cont_total_time"). ": "
818  .$_GET["totime"]
819  );
820  // BEGIN Partial fix for SCO sequencing:
821  // With this partial fix, ILIAS can now proceed to the next
822  // SCO, if it is a sibling of the current SCO.
823  // This fix doesn't fix the case, if the next SCO has a
824  // different parent item.
825  //$this->tpl->setVariable("SCO_LAUNCH_ID", $_GET["launch"]);
826 
827  $launch_id = $_GET['launch'];
828  if ($launch_id == 'null' || $launch_id == null) {
829  require_once("./Modules/ScormAicc/classes/SCORM/class.ilSCORMTree.php");
830  $mtree = new ilSCORMTree($this->slm->getId());
831  $node_data = $mtree->fetchSuccessorNode($_GET['sahs_id']);
832  if ($node_data && $node_data[type] == 'sit')
833  {
834  $launch_id = $node_data['child'];
835  }
836  }
837  // END Partial fix for SCO sequencing
838  $this->tpl->setVariable("SCO_LAUNCH_ID", $launch_id);
839  // $this->tpl->parseCurrentBlock();
840  $this->tpl->show();
841  }
842 
843  function unloadSahs ()
844  {
845  $this->tpl = new ilTemplate("tpl.sahs_unload_cbt.html", true, true, "Modules/ScormAicc");
846  $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
847  $this->tpl->setVariable("SCO_ID", $_GET["sahs_id"]);
848  $this->tpl->show();
849  }
850 
851 
852  function launchAsset()
853  {
854  global $ilUser, $ilDB;
855 
856  $sco_id = ($_GET["asset_id"] == "")
857  ? $_POST["asset_id"]
858  : $_GET["asset_id"];
859  $ref_id = ($_GET["ref_id"] == "")
860  ? $_POST["ref_id"]
861  : $_GET["ref_id"];
862 
863  $this->slm =& new ilObjSCORMLearningModule($ref_id, true);
864 
865  include_once("./Modules/ScormAicc/classes/SCORM/class.ilSCORMItem.php");
866  include_once("./Modules/ScormAicc/classes/SCORM/class.ilSCORMResource.php");
867  $item =& new ilSCORMItem($sco_id);
868 
869  $id_ref = $item->getIdentifierRef();
870  $resource =& new ilSCORMResource();
871  $resource->readByIdRef($id_ref, $item->getSLMId());
872  $href = $resource->getHref();
873  $this->tpl->setVariable("HREF", $this->slm->getDataDirectory("output")."/".$href);
874  $this->tpl = new ilTemplate("tpl.scorm_launch_asset.html", true, true, "Modules/ScormAicc");
875  $this->tpl->setVariable("HREF", $this->slm->getDataDirectory("output")."/".$href);
876  $this->tpl->show();
877  }
878 
879  function pingSession()
880  {
881  return true;
882  }
883 
884  function logMessage() {
885  global $ilLog;
886  $logString = file_get_contents('php://input');
887  $ilLog->write("ScormAicc: ApiLog: Message: ".$logString);
888  }
889 
890  function logWarning() {
891  global $ilLog;
892  $logString = file_get_contents('php://input');
893  $ilLog->write("ScormAicc: ApiLog: Warning: ".$logString,20);
894  }
895 
899  function setSingleVariable($a_var, $a_value)
900  {
901  $this->tpl->setCurrentBlock("set_value");
902  $this->tpl->setVariable("VAR", $a_var);
903  $this->tpl->setVariable("VALUE", $a_value);
904  $this->tpl->parseCurrentBlock();
905  }
906 
910  function setArray($a_left, $a_value, $a_name, &$v_array)
911  {
912  for($i=0; $i<$a_value; $i++)
913  {
914  $var = $a_left.".".$i.".".$a_name;
915  if (isset($v_array[$var]))
916  {
917  $this->tpl->setCurrentBlock("set_value");
918  $this->tpl->setVariable("VAR", $var);
919  $this->tpl->setVariable("VALUE", $v_array[$var]);
920  $this->tpl->parseCurrentBlock();
921  }
922  }
923  }
924 
928  public function downloadCertificate()
929  {
930  global $ilUser, $tree;
931 
932  $allowed = false;
933  $last_access = 0;
934  $obj_id = ilObject::_lookupObjId($_GET["ref_id"]);
935  include_once "./Modules/ScormAicc/classes/class.ilObjSAHSLearningModuleAccess.php";
937  {
938  include_once "./Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php";
940  switch ($type)
941  {
942  case "scorm":
943  include_once "./Modules/ScormAicc/classes/class.ilObjSCORMLearningModule.php";
944  $allowed = true;
945  $last_access = ilObjSCORMLearningModule::_lookupLastAccess($obj_id, $ilUser->getId());
946  break;
947  case "scorm2004":
948  include_once "./Modules/Scorm2004/classes/class.ilObjSCORM2004LearningModule.php";
949  $allowed = true;
950  $last_access = ilObjSCORM2004LearningModule::_lookupLastAccess($obj_id, $ilUser->getId());
951  break;
952  default:
953  break;
954  }
955  }
956 
957  if ($allowed)
958  {
959  include_once "./Services/Certificate/classes/class.ilCertificate.php";
960  include_once "./Modules/ScormAicc/classes/class.ilSCORMCertificateAdapter.php";
961  $certificate = new ilCertificate(new ilSCORMCertificateAdapter($this->slm));
962  $params = array(
963  "user_data" => ilObjUser::_lookupFields($ilUser->getId()),
964  "last_access" => $last_access
965  );
966  $certificate->outCertificate($params, true);
967  exit;
968  }
969  // redirect to parent category if certificate is not accessible
970  $parent = $tree->getParentId($_GET["ref_id"]);
971  $cmd_link = "repository.php?ref_id=".$parent;
972  ilUtil::redirect($cmd_link);
973  }
974 }
975 ?>