scormfunctions.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  6. Copyright (c) Denes Nagy (darkden@freemail.hu)
  7. For a full list of contributors, see "credits.txt".
  8. The full license can be read in "license.txt".
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. See the GNU General Public License for more details.
  14. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  15. ==============================================================================
  16. */
  17. /**
  18. ==============================================================================
  19. * API event handler functions for Scorm 1.1 and 1.2 and 1.3
  20. *
  21. * @author Denes Nagy <darkden@freemail.hu>
  22. * @version v 1.0
  23. * @access public
  24. * @package dokeos.scorm
  25. ==============================================================================
  26. */
  27. /*
  28. ==============================================================================
  29. INIT SECTION
  30. ==============================================================================
  31. */
  32. // if you open the imsmanifest.xml via local machine (f.ex.: file://c:/...), then the Apiwrapper.js
  33. // of Maritime Navigation when trying to execute this row
  34. // var result = api.LMSInitialize("");
  35. // get the error response : you are not authorized to call this function
  36. include('../inc/global.inc.php');
  37. $this_section=SECTION_COURSES;
  38. $TBL_SCORM_SCO_DATA=$scormDbName.".scorm_sco_data";
  39. $_uid = $_SESSION['_uid'];
  40. $_user = $_SESSION['_user'];
  41. $old_s_identifier = $_SESSION['old_sco_identifier'];
  42. $my_s_identifier = $_SESSION['s_identifier'];
  43. $file = $_SESSION['file'];
  44. //in some cases (manual clicks), there is no "old" s_identifier because there is no "new" one.
  45. if(empty($old_s_identifier)){
  46. $old_s_identifier = $my_s_identifier;
  47. }
  48. /*
  49. ==============================================================================
  50. JavaScript Functions
  51. ==============================================================================
  52. */
  53. ?>
  54. <html><head><script type='text/javascript'>
  55. /* <![CDATA[ */
  56. var alerts=0; //debug output level. 0 = none, 1=light, 2=a lot, 3(not implemented)=all
  57. if (alerts>1) { alert('scormfunctions.php included'); }
  58. function APIobject() {
  59. this.LMSInitialize=LMSInitialize; //for Scorm 1.2
  60. this.Initialize=LMSInitialize; //for Scorm 1.3
  61. this.LMSGetValue=LMSGetValue;
  62. this.GetValue=LMSGetValue;
  63. this.LMSSetValue=LMSSetValue;
  64. this.SetValue=LMSSetValue;
  65. this.LMSCommit=LMSCommit;
  66. this.Commit=LMSCommit;
  67. this.LMSFinish=LMSFinish;
  68. this.Finish=LMSFinish;
  69. this.LMSGetLastError=LMSGetLastError;
  70. this.GetLastError=LMSGetLastError;
  71. this.LMSGetErrorString=LMSGetErrorString;
  72. this.GetErrorString=LMSGetErrorString;
  73. this.LMSGetDiagnostic=LMSGetDiagnostic;
  74. this.GetDiagnostic=LMSGetDiagnostic;
  75. this.Terminate=Terminate; //only in Scorm 1.3
  76. }
  77. //it is not sure that the scos use the above declarations
  78. API = new APIobject(); //for scrom 1.2
  79. api = new APIobject(); //for scrom 1.2
  80. API_1484_11 = new APIobject(); //for scrom 1.3
  81. api_1484_11 = new APIobject(); //for scrom 1.3
  82. var G_NoError = 0;
  83. var G_GeneralException = 101;
  84. var G_ServerBusy = 102;
  85. var G_InvalidArgumentError = 201;
  86. var G_ElementCannotHaveChildren = 202;
  87. var G_ElementIsNotAnArray = 203;
  88. var G_NotInitialized = 301;
  89. var G_NotImplementedError = 401;
  90. var G_InvalidSetValue = 402;
  91. var G_ElementIsReadOnly = 403;
  92. var G_ElementIsWriteOnly = 404;
  93. var G_IncorrectDataType = 405;
  94. var G_LastError = G_NoError ;
  95. var commit = false ;
  96. var score=0;
  97. var max=0;
  98. var min=0;
  99. var lesson_status='';
  100. var session_time=0;
  101. function LMSInitialize() { //this is the initialize function of all APIobjects
  102. if (alerts>0) { alert('LMSInitialise() called (by SCORM content)'); }
  103. //initialise the lesson status between two lessons, to avoid status override
  104. lesson_status = '';
  105. return('true');
  106. }
  107. function Initialize() { //this is the initialize function of all APIobjects
  108. return LMSInitialize();
  109. }
  110. function LMSGetValue(param) {
  111. var result;
  112. switch(param) {
  113. case 'cmi.core._children' :
  114. case 'cmi.core_children' :
  115. result='entry, exit, lesson_status, student_id, student_name, lesson_location, total_time, credit, lesson_mode, score, session_time'; break;
  116. case 'cmi.core.entry' : result=''; break;
  117. case 'cmi.core.exit' : result=''; break;
  118. case 'cmi.core.lesson_status' :
  119. if(lesson_status != '') {result=lesson_status;}
  120. else{<?php
  121. $result = api_sql_query("SELECT status FROM $TBL_SCORM_SCO_DATA WHERE (studentId='$_uid' and scoIdentifier='$my_s_identifier')");
  122. $ar=mysql_fetch_array($result);
  123. $status=$ar['status'];
  124. if(empty($ar['status'])){$status = "not attempted";}
  125. #echo "{ if (alerts>1) { alert('Status of $s_identifier : $status'); }
  126. # TODO: implement this better thanks to the runtime environment doc of SCORM
  127. echo " result='$status';";?>
  128. }
  129. break;
  130. case 'cmi.core.student_id' : <?php echo "result='$_uid';"; ?> break;
  131. case 'cmi.core.student_name' :
  132. <?php
  133. $who=$_user ['firstName']." ".$_user ['lastName'];
  134. echo "{ result='$who'; }";
  135. ?> break;
  136. case 'cmi.core.lesson_location' : result=''; break;
  137. case 'cmi.core.total_time' : result='0000:00:00.00';break;
  138. case 'cmi.core.score._children' : result='raw,min,max'; break;
  139. case 'cmi.core.score.raw' : result=score; break;
  140. case 'cmi.core.score.max' : result='100'; break;
  141. case 'cmi.core.score.min' : result='0'; break;
  142. case 'cmi.core.score' : result='0'; break;
  143. case 'cmi.core.credit' : result='credit'; break;
  144. case 'cmi.core.lesson_mode' : result='normal'; break;
  145. case 'cmi.suspend_data' : result=''; break;
  146. case 'cmi.launch_data' : result=''; break;
  147. case 'cmi.objectives._count' : result='0'; break;
  148. default : result=''; break;
  149. }
  150. if (alerts>0) { alert("SCORM calls LMSGetValue('"+param+"')\nReturned '"+result+"'"); }
  151. return result;
  152. }
  153. function GetValue(param) {
  154. return LMSGetValue(param);
  155. }
  156. function LMSSetValue(param, val) {
  157. if (alerts>0) { alert("SCORM calls LMSSetValue('"+param+"','"+val+"')"); }
  158. switch(param) {
  159. case 'cmi.core.score.raw' : score= val ; break;
  160. case 'cmi.core.score.max' : max = val; break;
  161. case 'cmi.core.score.min' : min = val; break;
  162. case 'cmi.core.lesson_status' : lesson_status = val; break;
  163. case 'cmi.completion_status' : lesson_status = val; break; //1.3
  164. case 'cmi.core.session_time' : session_time = val; break;
  165. case 'cmi.score.scaled' : score = val ; break; //1.3
  166. case 'cmi.success_status' : success_status = val; break; //1.3
  167. }
  168. return(true);
  169. }
  170. function SetValue(param, val) {
  171. return LMSSetValue(param, val);
  172. }
  173. function savedata(origin) { //origin can be 'commit', 'finish' or 'terminate'
  174. //if( ( lesson_status == 'incomplete') && (score >= (0.8*max) ) ){
  175. // lesson_status = 'completed';
  176. //}
  177. param = 'origin='+origin+'&score='+score+'&max='+max+'&min='+min+'&lesson_status='+lesson_status+'&time='+session_time;
  178. url="http://<?php
  179. $self=$_SERVER['PHP_SELF'];
  180. $url=$_SERVER['HTTP_HOST'].$self;
  181. $url=substr($url,0,-19);//19 is the length of this file's name (/scormfunctions.php)
  182. echo $url;
  183. ?>/closesco.php?<?php echo "sco_identifier=$old_s_identifier&file=$file&"; ?>" + param + "";
  184. scowindow=open(url,'message');
  185. //the window.location command does not work here !!!!
  186. //and for some reason if I just call closesco.php without http//..., it does not work either
  187. if (alerts>1) { alert('saving data : '+url); }
  188. }
  189. function LMSCommit(val) {
  190. if (alerts>0) { alert('LMSCommit() called'); }
  191. commit = true ;
  192. savedata('commit');
  193. return('true');
  194. }
  195. function Commit(val) {
  196. return LMSCommit(val);
  197. }
  198. function LMSFinish(val) {
  199. if (( commit == false ) && (alerts>0)) { alert('LMSFinish() called without LMSCommit()'); }
  200. if ( commit == true ) {
  201. if(alerts>0) { alert('LMSFinish() called');}
  202. savedata('finish');
  203. }
  204. return('true');
  205. }
  206. function Finish(val) {
  207. return LMSFinish(val);
  208. }
  209. function LMSGetLastError() {
  210. if (alerts>1) { alert('LMSGetLastError() called'); }
  211. return(G_LastError);
  212. }
  213. function GetLastError() {
  214. return LMSGetLastError();
  215. }
  216. function LMSGetErrorString(errCode){
  217. if (alerts>1) { alert('LMSGetErrorString() called'); }
  218. return('No error !');
  219. }
  220. function GetErrorString(errCode){
  221. return LMSGetErrorString(errCode);
  222. }
  223. function LMSGetDiagnostic(errCode){
  224. if (alerts>1) { alert('LMSGetDiagnostic() called'); }
  225. return(API.LMSGetLastError());
  226. }
  227. function GetDiagnostic(errCode){
  228. return LMSGetDiagnostic(errCode);
  229. }
  230. function Terminate(){
  231. if (alerts>0) { alert('Terminate() called'); }
  232. commit = true;
  233. savedata('terminate');
  234. return (true);
  235. }
  236. /* ]]> */
  237. </script>
  238. </head>
  239. <body><i><b>This is an API / API_1484_11 system window. Nothing to be worried about!</b></i></body></html>