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