scorm_api.php 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019
  1. <?php // $Id: scorm_api.php,v 1.30 2006/09/12 13:42:18 yannoo Exp $
  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. * @author Yannick Warnier <ywarnier@beeznest.org>
  23. * @version v 1.0
  24. * @access public
  25. * @package dokeos.learnpath
  26. ==============================================================================
  27. */
  28. /**
  29. * This script is divided into three sections.
  30. * The first section (below) is the initialisation part.
  31. * The second section is the SCORM object part
  32. * The third section defines the event handlers for Dokeos' internal messaging
  33. * and frames refresh
  34. */
  35. /*
  36. ==============================================================================
  37. INIT SECTION
  38. ==============================================================================
  39. */
  40. // if you open the imsmanifest.xml via local machine (f.ex.: file://c:/...), then the Apiwrapper.js
  41. // of Maritime Navigation when trying to execute this row
  42. // var result = api.LMSInitialize("");
  43. // get the error response : you are not authorized to call this function
  44. //flag to allow for anonymous user - needs to be set before global.inc.php
  45. $use_anonymous = true;
  46. require_once('back_compat.inc.php');
  47. require_once('learnpath.class.php');
  48. require_once('learnpathItem.class.php');
  49. require_once('scorm.class.php');
  50. // Is this needed? This is probabaly done in the header file
  51. //$_user = $_SESSION['_user'];
  52. $file = $_SESSION['file'];
  53. $oLP = unserialize($_SESSION['lpobject']);
  54. $oItem = $oLP->items[$oLP->current];
  55. if(!is_object($oItem)){
  56. error_log('New LP - scorm_api - Could not load oItem item',0);
  57. exit;
  58. }
  59. $autocomplete_when_80pct = 0;
  60. /*
  61. ==============================================================================
  62. JavaScript Functions
  63. ==============================================================================
  64. */
  65. ?>var scorm_logs='<?php echo ((empty($oLP->scorm_debug) or !api_is_course_admin())?'0':'3');?>'; //debug log level for SCORM. 0 = none, 1=light, 2=a lot, 3=all - displays logs in log frame
  66. var lms_logs=0; //debug log level for LMS actions. 0=none, 1=light, 2=a lot, 3=all
  67. //logit_lms('scormfunctions.php included',0);
  68. function APIobject() {
  69. this.LMSInitialize=LMSInitialize; //for Scorm 1.2
  70. this.Initialize=LMSInitialize; //for Scorm 1.3
  71. this.LMSGetValue=LMSGetValue;
  72. this.GetValue=LMSGetValue;
  73. this.LMSSetValue=LMSSetValue;
  74. this.SetValue=LMSSetValue;
  75. this.LMSCommit=LMSCommit;
  76. this.Commit=LMSCommit;
  77. this.LMSFinish=LMSFinish;
  78. this.Finish=LMSFinish;
  79. this.LMSGetLastError=LMSGetLastError;
  80. this.GetLastError=LMSGetLastError;
  81. this.LMSGetErrorString=LMSGetErrorString;
  82. this.GetErrorString=LMSGetErrorString;
  83. this.LMSGetDiagnostic=LMSGetDiagnostic;
  84. this.GetDiagnostic=LMSGetDiagnostic;
  85. this.Terminate=Terminate; //only in Scorm 1.3
  86. this.save_asset = dokeos_save_asset;
  87. this.void_save_asset = dokeos_void_save_asset;
  88. }
  89. //it is not sure that the scos use the above declarations
  90. API = new APIobject(); //for scorm 1.2
  91. api = API;
  92. //api = new APIobject(); //for scorm 1.2
  93. API_1484_11 = new APIobject(); //for scorm 1.3
  94. api_1484_11 = API_1484_11;
  95. //api_1484_11 = new APIobject(); //for scorm 1.3
  96. var G_NoError = 0;
  97. var G_GeneralException = 101;
  98. var G_ServerBusy = 102;
  99. var G_InvalidArgumentError = 201;
  100. var G_ElementCannotHaveChildren = 202;
  101. var G_ElementIsNotAnArray = 203;
  102. var G_NotInitialized = 301;
  103. var G_NotImplementedError = 401;
  104. var G_InvalidSetValue = 402;
  105. var G_ElementIsReadOnly = 403;
  106. var G_ElementIsWriteOnly = 404;
  107. var G_IncorrectDataType = 405;
  108. var G_LastError = G_NoError ;
  109. var G_LastErrorMessage = 'No error';
  110. var commit = false ;
  111. //Strictly scorm variables
  112. var score=<?php echo $oItem->get_score();?>;
  113. var max='<?php echo $oItem->get_max();?>';
  114. var min='<?php echo $oItem->get_min();?>';
  115. var lesson_status='<?php echo $oItem->get_status();?>';
  116. var session_time='<?php echo $oItem->get_scorm_time('js');?>';
  117. var suspend_data = '<?php echo $oItem->get_suspend_data();?>';
  118. var lesson_location = '<?php echo $oItem->get_lesson_location();?>';
  119. var total_time = '<?php echo $oItem->get_scorm_time('js');?>';
  120. var mastery_score = '<?php echo $oItem->get_mastery_score();?>';
  121. var launch_data = '<?php echo $oItem->get_launch_data();?>';
  122. var max_time_allowed = '<?php echo $oItem->get_max_time_allowed();?>';
  123. var interactions = new Array();
  124. item_objectives = new Array();
  125. //Dokeos internal variables
  126. var saved_lesson_status = 'not attempted';
  127. var lms_lp_id = <?php echo $oLP->get_id();?>;
  128. var lms_item_id = <?php echo $oItem->get_id();?>;
  129. //var lms_new_item_id = 0; //temporary value (only there between a load_item() and a LMSInitialize())
  130. var lms_been_synchronized = 0;
  131. var lms_initialized = 0;
  132. var lms_total_lessons = <?php echo $oLP->get_total_items_count(); ?>;
  133. var lms_complete_lessons = <?php echo $oLP->get_complete_items_count();?>;
  134. var lms_progress_bar_mode = '<?php echo $oLP->progress_bar_mode;?>';
  135. if(lms_progress_bar_mode == ''){lms_progress_bar_mode='%';}
  136. var lms_view_id = '<?php echo $oLP->get_view();?>';
  137. if(lms_view_id == ''){ lms_view_id = 1;}
  138. var lms_user_id = '<?php echo $_user['user_id'];?>';
  139. var lms_next_item = '<?php echo $oLP->get_next_item_id();?>';
  140. var lms_previous_item = '<?php echo $oLP->get_previous_item_id();?>';
  141. var lms_lp_type = '<?php echo $oLP->get_type();?>';
  142. var lms_item_type = '<?php echo $oItem->get_type();?>';
  143. var lms_item_credit = '<?php echo $oItem->get_credit();?>';
  144. var lms_item_lesson_mode = '<?php echo $oItem->get_lesson_mode();?>';
  145. var lms_item_launch_data = '<?php echo $oItem->get_launch_data();?>';
  146. var lms_item_core_exit = '<?php echo $oItem->get_core_exit();?>';
  147. var asset_timer = 0;
  148. //Backup for old values
  149. var old_score = 0;
  150. var old_max = 0;
  151. var old_min = 0;
  152. var old_lesson_status = '';
  153. var old_session_time = '';
  154. var old_suspend_data = '';
  155. var lms_old_item_id = 0;
  156. /**
  157. * Function called mandatorily by the SCORM content to start the SCORM communication
  158. */
  159. function LMSInitialize() { //this is the initialize function of all APIobjects
  160. logit_scorm('LMSInitialise()',0);
  161. /* load info for this new item by calling the js_api_refresh command in
  162. * the message frame. The message frame will update the JS variables by
  163. * itself, in JS, by doing things like top.lesson_status = 'not attempted'
  164. * and that kind of stuff, so when the content loads in the content frame
  165. * it will have all the correct variables set
  166. */
  167. G_LastError = G_NoError ;
  168. G_LastErrorMessage = 'No error';
  169. lms_initialized=1;
  170. return('true');
  171. }
  172. function Initialize() { //this is the initialize function of all APIobjects
  173. return LMSInitialize();
  174. }
  175. function LMSGetValue(param) {
  176. //logit_scorm("LMSGetValue('"+param+"')",1);
  177. G_LastError = G_NoError ;
  178. G_LastErrorMessage = 'No error';
  179. var result='';
  180. // ---- cmi.core._children
  181. if(param=='cmi.core._children' || param=='cmi.core_children'){
  182. result='entry, exit, lesson_status, student_id, student_name, lesson_location, total_time, credit, lesson_mode, score, session_time';
  183. }else if(param == 'cmi.core.entry'){
  184. // ---- cmi.core.entry
  185. if(lms_item_core_exit=='none')
  186. {
  187. result='ab-initio';
  188. }
  189. else if(lms_item_core_exit=='suspend')
  190. {
  191. result='resume';
  192. }
  193. else
  194. {
  195. result='';
  196. }
  197. }else if(param == 'cmi.core.exit'){
  198. // ---- cmi.core.exit
  199. result='';
  200. G_LastError = G_ElementIsWriteOnly;
  201. }else if(param == 'cmi.core.lesson_status'){
  202. // ---- cmi.core.lesson_status
  203. if(lesson_status != '') {
  204. result=lesson_status;
  205. }
  206. else{
  207. result='not attempted';
  208. }
  209. }else if(param == 'cmi.core.student_id'){
  210. // ---- cmi.core.student_id
  211. result='<?php echo $_user['user_id']; ?>';
  212. }else if(param == 'cmi.core.student_name'){
  213. // ---- cmi.core.student_name
  214. <?php
  215. $who=addslashes($_user['lastName'].", ".$_user['firstName']);
  216. echo "result='$who';";
  217. ?>
  218. }else if(param == 'cmi.core.lesson_location'){
  219. // ---- cmi.core.lesson_location
  220. result=lesson_location;
  221. }else if(param == 'cmi.core.total_time'){
  222. // ---- cmi.core.total_time
  223. result=total_time;
  224. }else if(param == 'cmi.core.score._children'){
  225. // ---- cmi.core.score._children
  226. result='raw,min,max';
  227. }else if(param == 'cmi.core.score.raw'){
  228. // ---- cmi.core.score.raw
  229. result=score;
  230. }else if(param == 'cmi.core.score.max'){
  231. // ---- cmi.core.score.max
  232. result=max;
  233. }else if(param == 'cmi.core.score.min'){
  234. // ---- cmi.core.score.min
  235. result=min;
  236. }else if(param == 'cmi.core.score'){
  237. // ---- cmi.core.score -- non-standard item, provided as cmi.core.score.raw just in case
  238. result=score;
  239. }else if(param == 'cmi.core.credit'){
  240. // ---- cmi.core.credit
  241. result = lms_item_credit;
  242. }else if(param == 'cmi.core.lesson_mode'){
  243. // ---- cmi.core.lesson_mode
  244. result = lms_item_lesson_mode;
  245. }else if(param == 'cmi.suspend_data'){
  246. // ---- cmi.suspend_data
  247. result = suspend_data;
  248. }else if(param == 'cmi.launch_data'){
  249. // ---- cmi.launch_data
  250. result = lms_item_launch_data;
  251. }else if(param == 'cmi.objectives._children'){
  252. // ---- cmi.objectives._children
  253. result = 'id,score,status';
  254. }else if(param == 'cmi.objectives._count'){
  255. // ---- cmi.objectives._count
  256. //result='<?php echo $oItem->get_view_count();?>';
  257. result = item_objectives.length;
  258. }else if(param.substring(0,15)== 'cmi.objectives.'){
  259. var myres = '';
  260. if(myres = param.match(/cmi.objectives.(\d+).(id|score|status|_children)(.*)/))
  261. {
  262. var obj_id = myres[1];
  263. var req_type = myres[2];
  264. if(item_objectives[obj_id]==null)
  265. {
  266. if(req_type == 'id')
  267. {
  268. result = '';
  269. }else if(req_type == '_children'){
  270. result = 'id,score,status';
  271. }else if(req_type == 'score'){
  272. if(myres[3]==null)
  273. {
  274. result = '';
  275. G_lastError = G_NotImplementedError;
  276. G_lastErrorString = 'Not implemented yet';
  277. }else if (myres[3] == '._children'){
  278. result = 'raw,min,max'; //non-standard, added for NetG
  279. }else if (myres[3] == '.raw'){
  280. result = '';
  281. }else if (myres[3] == '.max'){
  282. result = '';
  283. }else if (myres[3] == '.min'){
  284. result = '';
  285. }else{
  286. result = '';
  287. G_lastError = G_NotImplementedError;
  288. G_lastErrorString = 'Not implemented yet';
  289. }
  290. }else if(req_type == 'status'){
  291. result = 'not attempted';
  292. }
  293. }
  294. else
  295. {
  296. //the object is not null
  297. if(req_type == 'id')
  298. {
  299. result = item_objectives[obj_id][0];
  300. }else if(req_type == '_children'){
  301. result = 'id,score,status';
  302. }else if(req_type == 'score'){
  303. if(myres[3]==null)
  304. {
  305. result = '';
  306. G_lastError = G_NotImplementedError;
  307. G_lastErrorString = 'Not implemented yet';
  308. }else if (myres[3] == '._children'){
  309. result = 'raw,min,max'; //non-standard, added for NetG
  310. }else if (myres[3] == '.raw'){
  311. if(item_objectives[obj_id][2] != null)
  312. {
  313. result = item_objectives[obj_id][2];
  314. }else{
  315. result = '';
  316. }
  317. }else if (myres[3] == '.max'){
  318. if(item_objectives[obj_id][3] != null)
  319. {
  320. result = item_objectives[obj_id][3];
  321. }else{
  322. result = '';
  323. }
  324. }else if (myres[3] == '.min'){
  325. if(item_objectives[obj_id][4] != null)
  326. {
  327. result = item_objectives[obj_id][4];
  328. }else{
  329. result = '';
  330. }
  331. }else{
  332. result = '';
  333. G_lastError = G_NotImplementedError;
  334. G_lastErrorString = 'Not implemented yet';
  335. }
  336. }else if(req_type == 'status'){
  337. if(item_objectives[obj_id][1] != null)
  338. {
  339. result = item_objectives[obj_id][1];
  340. }else{
  341. result = 'not attempted';
  342. }
  343. }
  344. }
  345. }
  346. }else if(param == 'cmi.student_data._children'){
  347. // ---- cmi.student_data._children
  348. result = 'mastery_score,max_time_allowed';
  349. }else if(param == 'cmi.student_data.mastery_score'){
  350. // ---- cmi.student_data.mastery_score
  351. result = mastery_score;
  352. }else if(param == 'cmi.student_data.max_time_allowed'){
  353. // ---- cmi.student_data.max_time_allowed
  354. result = max_time_allowed;
  355. }else if(param == 'cmi.interactions._count'){
  356. // ---- cmi.interactions._count
  357. result = interactions.length;
  358. }else if(param == 'cmi.interactions._children'){
  359. // ---- cmi.interactions._children
  360. result = 'id,time,type,correct_responses,weighting,student_response,result,latency';
  361. }else{
  362. // ---- anything else
  363. result = '';
  364. G_lastError = G_NotImplementedError;
  365. G_lastErrorString = 'Not implemented yet';
  366. }
  367. logit_scorm("LMSGetValue\n\t('"+param+"') returned '"+result+"'",1);
  368. return result;
  369. }
  370. function GetValue(param) {
  371. return LMSGetValue(param);
  372. }
  373. function LMSSetValue(param, val) {
  374. logit_scorm("LMSSetValue\n\t('"+param+"','"+val+"')",0);
  375. commit = true; //value has changed, need to re-commit
  376. G_LastError = G_NoError ;
  377. G_LastErrorMessage = 'No error';
  378. return_value = 'false';
  379. if( param == "cmi.core.score.raw" )
  380. {
  381. score= val; return_value='true';
  382. } else if ( param == "cmi.core.score.max" ) {
  383. max = val;return_value='true';
  384. } else if ( param == "cmi.core.score.min" ) {
  385. min = val;return_value='true';
  386. } else if ( param == "cmi.core.lesson_location" ) {
  387. lesson_location = val;return_value='true';
  388. } else if ( param == "cmi.core.lesson_status" ) {
  389. saved_lesson_status = lesson_status;
  390. lesson_status = val;
  391. return_value='true';
  392. } else if ( param == "cmi.completion_status" ) {
  393. lesson_status = val;return_value='true'; //1.3
  394. } else if ( param == "cmi.core.session_time" ) {
  395. session_time = val;return_value='true';
  396. } else if ( param == "cmi.score.scaled") { //1.3
  397. if(val<=1 && val>=-1)
  398. {
  399. score = val ;
  400. return_value='true';
  401. }
  402. else
  403. {
  404. return_value='false';
  405. }
  406. } else if ( param == "cmi.success_status" ) {
  407. success_status = val;return_value='true'; //1.3
  408. } else if ( param == "cmi.suspend_data" ) {
  409. suspend_data = val;return_value='true';
  410. } else if ( param == "cmi.core.exit" ) {
  411. lms_item_core_exit = val;return_value='true';
  412. } else if ( param == "cmi.core.entry" ) {
  413. G_LastError = G_ElementIsReadOnly
  414. } else if ( param == "cmi.student_data.mastery_score" ) {
  415. G_LastError = G_ElementIsReadOnly;
  416. } else if ( param == "cmi.student_data.max_time_allowed" ) {
  417. G_LastError = G_ElementIsReadOnly;
  418. } else if ( param == "cmi.launch_data" ) {
  419. G_LastError = G_ElementIsReadOnly;
  420. } else {
  421. var myres = new Array();
  422. if(myres = param.match(/cmi.interactions.(\d+).(id|time|type|correct_responses|weighting|student_response|result|latency)(.*)/))
  423. {
  424. elem_id = myres[1];
  425. if(elem_id > interactions.length)
  426. {
  427. G_LastError = G_InvalidArgumentError;
  428. return_value = false;
  429. }
  430. else
  431. {
  432. if(interactions[elem_id] == null){
  433. interactions[elem_id] = ['','','','','','','',''];
  434. //id(0), type(1), time(2), weighting(3),correct_responses(4),student_response(5),result(6),latency(7)
  435. interactions[elem_id][4] = new Array();
  436. }
  437. elem_attrib = myres[2];
  438. switch(elem_attrib) {
  439. case "id":
  440. interactions[elem_id][0] = val;
  441. logit_scorm("Interaction "+elem_id+"'s id updated",2);
  442. return_value='true';
  443. break;
  444. case "time":
  445. interactions[elem_id][2] = val;
  446. logit_scorm("Interaction "+elem_id+"'s time updated",2);
  447. return_value='true';
  448. break;
  449. case "type":
  450. interactions[elem_id][1] = val;
  451. logit_scorm("Interaction "+elem_id+"'s type updated",2);
  452. return_value='true';
  453. break;
  454. case "correct_responses":
  455. //do nothing yet
  456. interactions[elem_id][4].push(val);
  457. logit_scorm("Interaction "+elem_id+"'s correct_responses not updated",2);
  458. return_value='true';
  459. break;
  460. case "weighting":
  461. interactions[elem_id][3] = val;
  462. logit_scorm("Interaction "+elem_id+"'s weighting updated",2);
  463. return_value='true';
  464. break;
  465. case "student_response":
  466. interactions[elem_id][5] = val;
  467. logit_scorm("Interaction "+elem_id+"'s student_response updated",2);
  468. return_value='true';
  469. break;
  470. case "result":
  471. interactions[elem_id][6] = val;
  472. logit_scorm("Interaction "+elem_id+"'s result updated",2);
  473. return_value='true';
  474. break;
  475. case "latency":
  476. interactions[elem_id][7] = val;
  477. logit_scorm("Interaction "+elem_id+"'s latency updated",2);
  478. return_value='true';
  479. break;
  480. default:
  481. G_lastError = G_NotImplementedError;
  482. G_lastErrorString = 'Not implemented yet';
  483. }
  484. }
  485. }else if(param.substring(0,15)== 'cmi.objectives.'){
  486. var myres = '';
  487. if(myres = param.match(/cmi.objectives.(\d+).(id|score|status)(.*)/))
  488. {
  489. obj_id = myres[1];
  490. if(obj_id > item_objectives.length)
  491. {
  492. G_LastError = G_InvalidArgumentError;
  493. return_value = false;
  494. }
  495. else
  496. {
  497. req_type = myres[2];
  498. if(obj_id == null || obj_id == '')
  499. {
  500. ;//do nothing
  501. }
  502. else
  503. {
  504. if(item_objectives[obj_id]==null)
  505. {
  506. item_objectives[obj_id] = ['','','','',''];
  507. }
  508. if( req_type == "id" ) {
  509. //item_objectives[obj_id][0] = val.substring(51,57);
  510. item_objectives[obj_id][0] = val;
  511. logit_scorm("Objective "+obj_id+"'s id updated",2);
  512. return_value = 'true';
  513. } else if ( req_type == "score" ) {
  514. if (myres[3] == '._children'){
  515. return_value = '';
  516. G_lastError = G_InvalidSetValue;
  517. G_lastErrorString = 'Invalid set value, element is a keyword';
  518. }else if (myres[3] == '.raw'){
  519. item_objectives[obj_id][2] = val;
  520. logit_scorm("Objective "+obj_id+"'s score raw updated",2);
  521. return_value = 'true';
  522. }else if (myres[3] == '.max'){
  523. item_objectives[obj_id][3] = val;
  524. logit_scorm("Objective "+obj_id+"'s score max updated",2);
  525. return_value = 'true';
  526. }else if (myres[3] == '.min'){
  527. item_objectives[obj_id][4] = val;
  528. logit_scorm("Objective "+obj_id+"'s score min updated",2);
  529. return_value = 'true';
  530. }else{
  531. return_value = '';
  532. G_lastError = G_NotImplementedError;
  533. G_lastErrorString = 'Not implemented yet';
  534. }
  535. } else if ( req_type == "status" ) {
  536. item_objectives[obj_id][1] = val;
  537. logit_scorm("Objective "+obj_id+"'s status updated",2);
  538. return_value = 'true';
  539. } else {
  540. G_lastError = G_NotImplementedError;
  541. G_lastErrorString = 'Not implemented yet';
  542. }
  543. }
  544. }
  545. }
  546. }else{
  547. G_lastError = G_NotImplementedError;
  548. G_lastErrorString = 'Not implemented yet';
  549. }
  550. }
  551. <?php
  552. if ($oLP->force_commit == 1){
  553. echo " var mycommit = LMSCommit('force');";
  554. }
  555. ?>
  556. return(return_value);
  557. }
  558. function SetValue(param, val) {
  559. return LMSSetValue(param, val);
  560. }
  561. function savedata(origin) { //origin can be 'commit', 'finish' or 'terminate'
  562. if ((lesson_status != 'completed') && (lesson_status != 'passed')
  563. && (mastery_score >=0) && (score >= mastery_score))
  564. {
  565. lesson_status = 'passed';
  566. }
  567. else if( (mastery_score < 0) && (lms_lp_type != '2') && ( lesson_status == 'incomplete') && (score >= (0.8*max) ) )
  568. { //the status cannot be modified automatically by the LMS under SCORM 1.2's rules
  569. <?php if ($autocomplete_when_80pct){ ?>
  570. lesson_status = 'completed';
  571. <?php }?>
  572. ;
  573. }
  574. logit_lms('saving data (status='+lesson_status+' - interactions: '+ interactions.length +')',1);
  575. xajax_save_item(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, score, max, min, lesson_status, session_time, suspend_data, lesson_location, interactions, lms_item_core_exit);
  576. if(item_objectives.length>0)
  577. {
  578. xajax_save_objectives(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,item_objectives);
  579. }
  580. }
  581. function LMSCommit(val) {
  582. logit_scorm('LMSCommit()',0);
  583. G_LastError = G_NoError ;
  584. G_LastErrorMessage = 'No error';
  585. savedata('commit');
  586. commit = false ; //now changes have been commited, no need to update until next SetValue()
  587. return('true');
  588. }
  589. function Commit(val) {
  590. return LMSCommit(val);
  591. }
  592. function LMSFinish(val) {
  593. G_LastError = G_NoError ;
  594. G_LastErrorMessage = 'No error';
  595. if (( commit == false )) {
  596. logit_scorm('LMSFinish() (no LMSCommit())',1);
  597. }
  598. if ( commit == true ) {
  599. logit_scorm('LMSFinish() called',1);
  600. savedata('finish');
  601. commit = false ;
  602. }
  603. return('true');
  604. }
  605. function Finish(val) {
  606. return LMSFinish(val);
  607. }
  608. function LMSGetLastError() {
  609. logit_scorm('LMSGetLastError()',1);
  610. return(G_LastError.toString());
  611. }
  612. function GetLastError() {
  613. return LMSGetLastError();
  614. }
  615. function LMSGetErrorString(errCode){
  616. logit_scorm('LMSGetErrorString()',1);
  617. return(G_LastErrorString);
  618. }
  619. function GetErrorString(errCode){
  620. return LMSGetErrorString(errCode);
  621. }
  622. function LMSGetDiagnostic(errCode){
  623. logit_scorm('LMSGetDiagnostic()',1);
  624. return(API.LMSGetLastError());
  625. }
  626. function GetDiagnostic(errCode){
  627. return LMSGetDiagnostic(errCode);
  628. }
  629. function Terminate(){
  630. logit_scorm('Terminate()',0);
  631. G_LastError = G_NoError ;
  632. G_LastErrorMessage = 'No error';
  633. commit = true;
  634. savedata('terminate');
  635. return (true);
  636. }
  637. <?php
  638. //--------------------------------------------------------------------//
  639. /**
  640. * Dokeos-specific code that deals with event handling and inter-frames
  641. * messaging/refreshing.
  642. * Note that from now on, the Dokeos JS code in this library will act as
  643. * a controller, of the MVC pattern, and receive all requests for frame
  644. * updates, then redispatch to any frame concerned.
  645. */
  646. ?>
  647. /**
  648. * Defining the AJAX-object class to be made available from other frames
  649. */
  650. function XAJAXobject() {
  651. this.xajax_switch_item_details=xajax_switch_item_details;
  652. this.switch_item=switch_item;
  653. this.xajax_save_objectives=xajax_save_objectives;
  654. this.xajax_save_item = xajax_save_item;
  655. }
  656. //it is not sure that the scos use the above declarations
  657. oXAJAX = new XAJAXobject();
  658. oxajax = new XAJAXobject();
  659. /**
  660. * Cross-browser event handling by Scott Andrew
  661. * @param element Element that needs an event attached
  662. * @param string Event type (load, unload, click, keyDown, ...)
  663. * @param string Function name (the event handler)
  664. * @param string used in addEventListener
  665. */
  666. function addEvent(elm, evType, fn, useCapture){
  667. if(elm.addEventListener){
  668. elm.addEventListener(evType, fn, useCapture);
  669. return true;
  670. }else if (elm.attachEvent){
  671. var r = elm.attachEvent('on' + evType, fn);
  672. }else{
  673. elm['on'+evType] = fn;
  674. }
  675. }
  676. /**
  677. * Add listeners to the page objects. This has to be defined for
  678. * the current context as it acts on objects that should exist
  679. * on the page
  680. * possibly deprecated
  681. */
  682. function addListeners(){
  683. //exit if the browser doesn't support ID or tag retrieval
  684. logit_lms('Entering addListeners()',2);
  685. if(!document.getElementsByTagName){
  686. logit_lms("getElementsByTagName not available",2);
  687. return;
  688. }
  689. if(!document.getElementById){
  690. logit_lms("getElementById not available",2);
  691. return;
  692. }
  693. //assign event handlers to objects
  694. if(lms_lp_type==1 || lms_item_type=='asset'){
  695. logit_lms('Dokeos LP or asset',2);
  696. //if this path is a Dokeos learnpath, then start manual save
  697. //when something is loaded in there
  698. addEvent(window,'unload',dokeos_save_asset,false);
  699. logit_lms('Added event listener on content_id for unload',2);
  700. }
  701. logit_lms('Quitting addListeners()',2);
  702. }
  703. /**
  704. * Load an item into the content frame:
  705. * - making sure the previous item status have been saved
  706. * - first updating the current item ID (to save the right item)
  707. * - updating the frame src
  708. * possibly deprecated
  709. */
  710. function load_item(item_id,url){
  711. if(document.getElementById('content_id'))
  712. {
  713. logit_lms('Loading item '+item_id,2);
  714. var cont_f = document.getElementById('content_id');
  715. if(cont_f.src){
  716. lms_old_item_id = lms_item_id;
  717. var lms_new_item_id = item_id;
  718. //load new content page into content frame
  719. if(lms_lp_type==1 || lms_item_type=='asset'){
  720. dokeos_save_asset();
  721. }
  722. cont_f.src = url;
  723. update_toc('unhighlight',lms_old_item_id);
  724. update_toc('highlight',item_id);
  725. return true;
  726. }
  727. logit_lms('cont_f.src has no properties',0);
  728. }
  729. logit_lms('content_id has no properties',0);
  730. return false;
  731. }
  732. /**
  733. * Save a Dokeos learnpath item's time and mark as completed upon
  734. * leaving it
  735. */
  736. function dokeos_save_asset(){
  737. logit_lms('dokeos_save_asset',2);
  738. xajax_save_item(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, score, max, min, lesson_status, session_time, suspend_data, lesson_location,interactions, lms_item_core_exit);
  739. if(item_objectives.length>0)
  740. {
  741. xajax_save_objectives(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,item_objectives);
  742. }
  743. }
  744. /**
  745. * Save a Dokeos learnpath item's time and mark as completed upon leaving it.
  746. * Same function as dokeos_save_asset() but saves it with empty params
  747. * to use values set from another side in the database. Only used by Dokeos quizzes.
  748. * Also save the score locally because it hasn't been done through SetValue().
  749. * Saving the status will be dealt with by the XAJAX function.
  750. */
  751. function dokeos_void_save_asset(myscore)
  752. {
  753. logit_lms('dokeos_save_asset',2);
  754. score = myscore;
  755. xajax_save_item(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, myscore);
  756. }
  757. /**
  758. * Logs information about SCORM messages into the log frame
  759. * @param string Message to log
  760. * @param integer Priority (0 for top priority, 3 for lowest)
  761. */
  762. function logit_scorm(message,priority){
  763. if(scorm_logs>priority){
  764. if(frames["lp_log_name"] && frames["lp_log_name"].document && frames["lp_log_name"].document.getElementById && frames["lp_log_name"].document.getElementById('log_content')){
  765. frames["lp_log_name"].document.getElementById("log_content").innerHTML += "SCORM: " + message + "<br/>";
  766. }
  767. }
  768. }
  769. /**
  770. * Logs information about LMS activity into the log frame
  771. * @param string Message to log
  772. * @param integer Priority (0 for top priority, 3 for lowest)
  773. */
  774. function logit_lms(message,priority){
  775. if(lms_logs>priority){
  776. if(frames["lp_log_name"] && frames["lp_log_name"].document && frames["lp_log_name"].document.getElementById && frames["lp_log_name"].document.getElementById('log_content')){
  777. frames["lp_log_name"].document.getElementById("log_content").innerHTML += "LMS: " + message + "<br/>";
  778. }
  779. }
  780. }
  781. /**
  782. * update the Table Of Contents frame, by changing CSS styles, mostly
  783. * @param string Action to be taken
  784. * @param integer Item id to update
  785. */
  786. function update_toc(update_action,update_id)
  787. {
  788. <?php //if($oLP->mode != 'fullscreen'){ ?>
  789. var myframe = frames["toc_name"];
  790. var myelem = myframe.document.getElementById("toc_"+update_id);
  791. var myelemimg = myframe.document.getElementById("toc_img_"+update_id);
  792. logit_lms('update_toc("'+update_action+'",'+update_id+')',2);
  793. if(update_id != 0){
  794. switch(update_action){
  795. case 'unhighlight':
  796. myelem.className = "scorm_item";
  797. break;
  798. case 'highlight':
  799. myelem.className = "scorm_item_highlight";
  800. break;
  801. case 'not attempted':
  802. if(myelemimg.src != 'notattempted.png'){
  803. myelemimg.src = "notattempted.png";
  804. myelemimg.alt = "n";
  805. }
  806. break;
  807. case 'incomplete':
  808. if(myelemimg.src != 'incomplete.png'){
  809. myelemimg.src = "incomplete.png";
  810. myelemimg.alt = "i";
  811. }
  812. break;
  813. case 'completed':
  814. if(myelemimg.src != 'completed.png'){
  815. myelemimg.src = "completed.png";
  816. myelemimg.alt = "c";
  817. }
  818. break;
  819. case 'failed':
  820. if(myelemimg.src != 'failed.png'){
  821. myelemimg.src = "failed.png";
  822. myelemimg.alt = "f";
  823. }
  824. break;
  825. case 'passed':
  826. if(myelemimg.src != 'completed.png' && myelemimg.alt != 'passed'){
  827. myelemimg.src = "completed.png";
  828. myelemimg.alt = "p";
  829. }
  830. break;
  831. case 'browsed':
  832. if(myelemimg.src != 'completed.png' && myelemimg.alt != 'browsed'){
  833. myelemimg.src = "completed.png";
  834. myelemimg.alt = "b";
  835. }
  836. break;
  837. default:
  838. logit_lms('Update action unknown',2);
  839. break;
  840. }
  841. }
  842. return true;
  843. <?php //} ?>
  844. return true;
  845. }
  846. /**
  847. * Updates the progress bar with the new status. Prevents the need of a page refresh and flickering
  848. * @param integer Number of completed items
  849. * @param integer Number of items in total
  850. * @param string Display mode (absolute 'abs' or percentage '%').Defaults to %
  851. */
  852. function update_progress_bar(nbr_complete, nbr_total, mode)
  853. {
  854. logit_lms('update_progress_bar('+nbr_complete+','+nbr_total+','+mode+')',2);
  855. logit_lms('could update with data: '+lms_lp_id+','+lms_view_id+','+lms_user_id,2);
  856. var myframe = frames["nav_name"];
  857. if(myframe){
  858. if(mode == ''){mode='%';}
  859. if(nbr_total == 0){nbr_total=1;}
  860. var percentage = (nbr_complete/nbr_total)*100;
  861. percentage = Math.round(percentage);
  862. var pr_text = myframe.document.getElementById('progress_text');
  863. var pr_full = myframe.document.getElementById('progress_img_full');
  864. var pr_empty = myframe.document.getElementById('progress_img_empty');
  865. pr_full.width = percentage;
  866. pr_empty.width = 100-percentage;
  867. var mytext = '';
  868. switch(mode){
  869. case 'abs':
  870. mytext = nbr_complete + '/' + nbr_total;
  871. break;
  872. case '%':
  873. default:
  874. mytext = percentage + '%';
  875. break;
  876. }
  877. pr_text.innerHTML = mytext;
  878. }
  879. return true;
  880. }
  881. function update_stats_page()
  882. {
  883. var myframe = document.getElementById('content_id');
  884. var mysrc = myframe.location.href;
  885. if(mysrc == 'lp_controller.php?action=stats'){
  886. if(myframe && myframe.src){
  887. var mysrc = myframe.src;
  888. myframe.src = mysrc;
  889. }
  890. // = mysrc; //refresh page
  891. }
  892. return true;
  893. }
  894. /**
  895. * Updates the message frame with the given string
  896. */
  897. function update_message_frame(msg_msg)
  898. {
  899. if(msg_msg==null){msg_msg='';}
  900. var msg_f = frames["message_name"];
  901. if(!msg_f.document || !msg_f.document.getElementById('msg_div_id')){
  902. logit_lms('In update_message_frame() - message frame has no document property',0);
  903. }else{
  904. logit_lms('In update_message_frame() - updating frame',0);
  905. msg_f.document.getElementById('msg_div_id').innerHTML= msg_msg;
  906. }
  907. }
  908. /**
  909. * Function that handles the saving of an item and switching from an item to another.
  910. * Once called, this function should be able to do the whole process of (1) saving the
  911. * current item, (2) refresh all the values inside the SCORM API object, (3) open the
  912. * new item into the content_id frame, (4) refresh the table of contents, (5) refresh
  913. * the progress bar (completion), (6) refresh the message frame
  914. * @param integer Dokeos ID for the current item
  915. * @param string This parameter can be a string specifying the next
  916. * item (like 'next', 'previous', 'first' or 'last') or the id to the next item
  917. */
  918. function switch_item(current_item, next_item){
  919. //(1) save the current item
  920. logit_lms('Called switch_item with params '+lms_item_id+' and '+next_item+'',0);
  921. if(lms_lp_type==1 || lms_item_type=='asset' || session_time == '0' || session_time == '0:00:00'){
  922. xajax_save_item(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, score, max, min, lesson_status, asset_timer, suspend_data, lesson_location,interactions, lms_item_core_exit);
  923. }else{
  924. xajax_save_item(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, score, max, min, lesson_status, session_time, suspend_data, lesson_location,interactions, lms_item_core_exit);
  925. }
  926. if(item_objectives.length>0)
  927. {
  928. xajax_save_objectives(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,item_objectives);
  929. }
  930. //(2) Refresh all the values inside this SCORM API object - use AJAX
  931. //xajax_backup_item_details(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, score, max, min, lesson_status, session_time, suspend_data);
  932. xajax_switch_item_details(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,next_item);
  933. //(3) open the new item in the content_id frame
  934. switch(next_item){
  935. case 'next':
  936. next_item = lms_next_item;
  937. break;
  938. case 'previous':
  939. next_item = lms_previous_item;
  940. break;
  941. default:
  942. break;
  943. }
  944. var mysrc = 'lp_controller.php?action=content&lp_id='+lms_lp_id+'&item_id='+next_item;
  945. var cont_f = document.getElementById('content_id');
  946. if(!cont_f){
  947. logit_lms('In switch - content frame not found',0);
  948. <?php if($oLP->mode = 'fullscreen'){ ?>
  949. cont_f = window.open(''+mysrc,'content_name','toolbar=0,location=0,status=0,scrollbars=1,resizable=1');
  950. <?php } else { ?>
  951. return false;
  952. <?php } ?>
  953. }
  954. else
  955. {
  956. cont_f.src = mysrc;
  957. }
  958. if(lms_lp_type==1 || lms_item_type=='asset'){
  959. xajax_start_timer();
  960. }
  961. //(4) refresh the audiorecorder if needed
  962. if(frames['audiorecorder_name']){
  963. frames['audiorecorder_name'].location.reload();
  964. }
  965. return true;
  966. }
  967. addEvent(window,'load',addListeners,false);
  968. if(lms_lp_type==1 || lms_item_type=='asset'){
  969. xajax_start_timer();
  970. }