1. var exitState = "";
  2. var status = "";
  3. var entryVal = "";
  4. var courseTotalTime = 0;
  5.  
  6. /////////////////////////////////////////////////////////////////////////////
  7. //
  8. // Title: doinit()
  9. //
  10. // Description: This function is used to initialize the module including the
  11. // retrieval of key SCORM data elements from the LMS which are passed to the
  12. // controller.
  13. //
  14. /////////////////////////////////////////////////////////////////////////////
  15. function doinit(){
  16. //Initialize the LMS connection
  17. var result = LMSInitialize("");
  18. var lessonStatus = "";
  19. //Once communication is established get appropriate values
  20. if(result == "true" && result != null){
  21. entryVal = LMSGetValue("cmi.core.entry");
  22. status = LMSGetValue("cmi.core.lesson_status");
  23.  
  24. if (entryVal == "ab-initio" || entryVal == "resume")
  25. {
  26. status = "incomplete";
  27. exitState = "suspend";
  28. LMSSetValue("cmi.core.lesson_status",status);
  29. LMSCommit();
  30. }
  31. else if (entryVal == "")
  32. {
  33. status = "completed";
  34. exitState = "";
  35. }
  36.  
  37. document.igc_controller.SetVariable("cmi_entry", entryVal);
  38. document.igc_controller.SetVariable("cmi_temp_status", status);
  39. setTimeout("updateCourseTime()",1000);
  40.  
  41. } else {
  42. //Can't find the API. Present an error.
  43. alert("The API is not present. Attempting to connect...Click Ok to continue.");
  44. doinit();
  45. }
  46. }
  47.  
  48. /////////////////////////////////////////////////////////////////////////////
  49. //
  50. // Title: updateCourseTime()
  51. //
  52. // Description: This function is used to update the amount of time a user spends in the course.
  53. //
  54. /////////////////////////////////////////////////////////////////////////////
  55. function updateCourseTime(){
  56. courseTotalTime = courseTotalTime + 1000;
  57. setTimeout("updateCourseTime()",1000);
  58. }
  59.  
  60. /////////////////////////////////////////////////////////////////////////////
  61. //
  62. // Title: setBookmark(args)
  63. //
  64. // Description: This function is used to set a bookmark.
  65. //
  66. /////////////////////////////////////////////////////////////////////////////
  67. function setBookmark(args){
  68. LMSSetValue("cmi.core.lesson_location",args);
  69. LMSCommit();
  70. }
  71.  
  72. /////////////////////////////////////////////////////////////////////////////
  73. //
  74. // Title: setClassScore(args)
  75. //
  76. // Description: This function is used to set a class complete score.
  77. //
  78. /////////////////////////////////////////////////////////////////////////////
  79. function setClassScore(args){
  80. LMSSetValue("cmi.core.score.raw",args);
  81. LMSCommit();
  82. }
  83.  
  84. /////////////////////////////////////////////////////////////////////////////
  85. //
  86. // Title: getBookmark()
  87. //
  88. // Description: This function is used to get a bookmark.
  89. //
  90. /////////////////////////////////////////////////////////////////////////////
  91. function getBookmark(){
  92. lmsbookmark = LMSGetValue("cmi.core.lesson_location");
  93. document.igc_controller.SetVariable("cmi_temp_bkmrk", lmsbookmark);
  94. }
  95.  
  96. /////////////////////////////////////////////////////////////////////////////
  97. //
  98. // Title: getClassProgress()
  99. //
  100. // Description: This function is used to get the classProgress.
  101. //
  102. /////////////////////////////////////////////////////////////////////////////
  103. function getClassProgress(){
  104. //for our purposes cmi.suspend_data will be a text string comprised as follows
  105. //"l1e1-m1.c,m2.c,m3.c.93/l1e2-m1.c,m2.i,m3.x/" That breaks down as follows
  106. //l1 = lesson 1
  107. //e1 = exercise 1
  108. //m1 = lecture, m2 = interactive, m3 = quiz
  109. //m1.c = complete, m1.i = incomplete, m1.x = not present, m3.c.95 = quiz is complete and learner recieved a score of 93%
  110. //commas separate modes, forward slash separates exercises, heirarchy denotes the rest
  111. resumeD = LMSGetValue("cmi.suspend_data");
  112. document.igc_controller.SetVariable("resumeD",resumeD);
  113. }
  114.  
  115. /////////////////////////////////////////////////////////////////////////////
  116. //
  117. // Title: setClassProgress()
  118. //
  119. // Description: This function is used to set the classProgress.
  120. //
  121. /////////////////////////////////////////////////////////////////////////////
  122. function setClassProgress(args, courseScore, completeStatus){
  123. //for our purposes cmi.suspend_data will be a text string comprised as follows
  124. //"l1e1-m1.c,m2.c,m3.c.93/l1e2-m1.c,m2.i,m3.x/" That breaks down as follows
  125. //l1 = lesson 1
  126. //e1 = exercise 1
  127. //m1 = lecture, m2 = interactive, m3 = quiz
  128. //m1.c = complete, m1.i = incomplete, m1.x = not present, m3.c.95 = quiz is complete and learner recieved a score of 93%
  129. //commas separate modes, forward slash separates exercises, heirarchy denotes the rest
  130. LMSSetValue("cmi.suspend_data",args);
  131. LMSCommit();
  132.  
  133. if (completeStatus == "true"){
  134. if (courseScore >= 0){
  135. setClassScore(courseScore);
  136. }
  137. prepComplete();
  138. }
  139. }
  140.  
  141. /////////////////////////////////////////////////////////////////////////////
  142. //
  143. // Title: prepComplete()
  144. //
  145. // Description: This function is used to mark the course complete upon completion.
  146. // of all exercises by removing the bookmark and setting a global complete var.
  147. //
  148. /////////////////////////////////////////////////////////////////////////////
  149. function prepComplete(){
  150. status = "completed";
  151. exitState = "";
  152. LMSSetValue("cmi.core.lesson_location","");
  153. LMSCommit();
  154. }
  155.  
  156. /////////////////////////////////////////////////////////////////////////////
  157. //
  158. // Title: dofinish()
  159. //
  160. // Description: This function is used to set and commit the appropriate status
  161. // and exit state before closing the module. It is called on the onUnload event
  162. //
  163. /////////////////////////////////////////////////////////////////////////////
  164. function dofinish(){
  165. var seconds = "";
  166. var minutes = "";
  167. var hours = "";
  168.  
  169. seconds=Math.floor(courseTotalTime/1000);
  170. minutes=Math.floor(seconds/60);
  171. hours=Math.floor(minutes/60);
  172.  
  173. seconds = seconds % 60;
  174. minutes = minutes % 60;
  175.  
  176. //add leading zero to second
  177. if (seconds < 10){
  178. if (seconds == 0) {
  179. seconds = "00";
  180. } else {
  181. seconds = "0" + seconds;
  182. }
  183. }
  184.  
  185. //add leading zero to minutes
  186. if (minutes < 10){
  187. if (minutes == 0) {
  188. minutes = "00";
  189. } else {
  190. minutes = "0" + minutes;
  191. }
  192. }
  193.  
  194. //add leading zeros to hours
  195. if (hours < 10) {
  196. if (hours == 0) {
  197. hours = "0000";
  198. } else {
  199. hours = "000" + hours;
  200. }
  201. } else if (hours < 100) {
  202. hours = "00" + hours;
  203. } else if (hoursInt < 1000) {
  204. hours = "0" + hours;
  205. }
  206.  
  207. var session_time = "";
  208. session_time = hours + ":" + minutes + ":" + seconds;
  209. LMSSetValue("cmi.core.session_time", session_time);
  210. LMSSetValue("cmi.core.lesson_status",status);
  211. LMSSetValue("cmi.core.exit", exitState);
  212.  
  213. LMSCommit();
  214. LMSFinish();
  215. }