scorm_api.php 34 KB

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