scorm_api.php 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034
  1. <?php // $Id: scorm_api.php 15386 2008-05-24 05:13:09Z 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) //interactions setting should start at 0
  428. {
  429. G_LastError = G_InvalidArgumentError;
  430. G_LastErrorString = 'Invalid argument (interactions)';
  431. return_value = false;
  432. }
  433. else
  434. {
  435. if(interactions[elem_id] == null){
  436. interactions[elem_id] = ['','','','','','','',''];
  437. //id(0), type(1), time(2), weighting(3),correct_responses(4),student_response(5),result(6),latency(7)
  438. interactions[elem_id][4] = new Array();
  439. }
  440. elem_attrib = myres[2];
  441. switch(elem_attrib) {
  442. case "id":
  443. interactions[elem_id][0] = val;
  444. logit_scorm("Interaction "+elem_id+"'s id updated",2);
  445. return_value='true';
  446. break;
  447. case "time":
  448. interactions[elem_id][2] = val;
  449. logit_scorm("Interaction "+elem_id+"'s time updated",2);
  450. return_value='true';
  451. break;
  452. case "type":
  453. interactions[elem_id][1] = val;
  454. logit_scorm("Interaction "+elem_id+"'s type updated",2);
  455. return_value='true';
  456. break;
  457. case "correct_responses":
  458. //do nothing yet
  459. interactions[elem_id][4].push(val);
  460. logit_scorm("Interaction "+elem_id+"'s correct_responses not updated",2);
  461. return_value='true';
  462. break;
  463. case "weighting":
  464. interactions[elem_id][3] = val;
  465. logit_scorm("Interaction "+elem_id+"'s weighting updated",2);
  466. return_value='true';
  467. break;
  468. case "student_response":
  469. interactions[elem_id][5] = val;
  470. logit_scorm("Interaction "+elem_id+"'s student_response updated",2);
  471. return_value='true';
  472. break;
  473. case "result":
  474. interactions[elem_id][6] = val;
  475. logit_scorm("Interaction "+elem_id+"'s result updated",2);
  476. return_value='true';
  477. break;
  478. case "latency":
  479. interactions[elem_id][7] = val;
  480. logit_scorm("Interaction "+elem_id+"'s latency updated",2);
  481. return_value='true';
  482. break;
  483. default:
  484. G_lastError = G_NotImplementedError;
  485. G_lastErrorString = 'Not implemented yet';
  486. }
  487. }
  488. }else if(param.substring(0,15)== 'cmi.objectives.'){
  489. var myres = '';
  490. if(myres = param.match(/cmi.objectives.(\d+).(id|score|status)(.*)/))
  491. {
  492. obj_id = myres[1];
  493. if(obj_id > item_objectives.length) //objectives setting should start at 0
  494. {
  495. G_LastError = G_InvalidArgumentError;
  496. G_LastErrorString = 'Invalid argument (objectives)';
  497. return_value = false;
  498. }
  499. else
  500. {
  501. req_type = myres[2];
  502. if(obj_id == null || obj_id == '')
  503. {
  504. ;//do nothing
  505. }
  506. else
  507. {
  508. if(item_objectives[obj_id]==null)
  509. {
  510. item_objectives[obj_id] = ['','','','',''];
  511. }
  512. if( req_type == "id" ) {
  513. //item_objectives[obj_id][0] = val.substring(51,57);
  514. item_objectives[obj_id][0] = val;
  515. logit_scorm("Objective "+obj_id+"'s id updated",2);
  516. return_value = 'true';
  517. } else if ( req_type == "score" ) {
  518. if (myres[3] == '._children'){
  519. return_value = '';
  520. G_lastError = G_InvalidSetValue;
  521. G_lastErrorString = 'Invalid set value, element is a keyword';
  522. }else if (myres[3] == '.raw'){
  523. item_objectives[obj_id][2] = val;
  524. logit_scorm("Objective "+obj_id+"'s score raw updated",2);
  525. return_value = 'true';
  526. }else if (myres[3] == '.max'){
  527. item_objectives[obj_id][3] = val;
  528. logit_scorm("Objective "+obj_id+"'s score max updated",2);
  529. return_value = 'true';
  530. }else if (myres[3] == '.min'){
  531. item_objectives[obj_id][4] = val;
  532. logit_scorm("Objective "+obj_id+"'s score min updated",2);
  533. return_value = 'true';
  534. }else{
  535. return_value = '';
  536. G_lastError = G_NotImplementedError;
  537. G_lastErrorString = 'Not implemented yet';
  538. }
  539. } else if ( req_type == "status" ) {
  540. item_objectives[obj_id][1] = val;
  541. logit_scorm("Objective "+obj_id+"'s status updated",2);
  542. return_value = 'true';
  543. } else {
  544. G_lastError = G_NotImplementedError;
  545. G_lastErrorString = 'Not implemented yet';
  546. }
  547. }
  548. }
  549. }
  550. }else{
  551. G_lastError = G_NotImplementedError;
  552. G_lastErrorString = 'Not implemented yet';
  553. }
  554. }
  555. <?php
  556. if ($oLP->force_commit == 1){
  557. echo " var mycommit = LMSCommit('force');";
  558. }
  559. ?>
  560. return(return_value);
  561. }
  562. function SetValue(param, val) {
  563. return LMSSetValue(param, val);
  564. }
  565. function savedata(origin) { //origin can be 'commit', 'finish' or 'terminate'
  566. if ((lesson_status != 'completed') && (lesson_status != 'passed')
  567. && (mastery_score >=0) && (score >= mastery_score))
  568. {
  569. lesson_status = 'passed';
  570. }
  571. else if( (mastery_score < 0) && (lms_lp_type != '2') && ( lesson_status == 'incomplete') && (score >= (0.8*max) ) )
  572. { //the status cannot be modified automatically by the LMS under SCORM 1.2's rules
  573. <?php if ($autocomplete_when_80pct){ ?>
  574. lesson_status = 'completed';
  575. <?php }?>
  576. ;
  577. }
  578. logit_lms('saving data (status='+lesson_status+' - interactions: '+ interactions.length +')',1);
  579. 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);
  580. if(item_objectives.length>0)
  581. {
  582. xajax_save_objectives(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,item_objectives);
  583. }
  584. }
  585. function LMSCommit(val) {
  586. logit_scorm('LMSCommit()',0);
  587. G_LastError = G_NoError ;
  588. G_LastErrorMessage = 'No error';
  589. savedata('commit');
  590. commit = false ; //now changes have been commited, no need to update until next SetValue()
  591. return('true');
  592. }
  593. function Commit(val) {
  594. return LMSCommit(val);
  595. }
  596. function LMSFinish(val) {
  597. G_LastError = G_NoError ;
  598. G_LastErrorMessage = 'No error';
  599. if (( commit == false )) {
  600. logit_scorm('LMSFinish() (no LMSCommit())',1);
  601. }
  602. if ( commit == true ) {
  603. logit_scorm('LMSFinish() called',1);
  604. savedata('finish');
  605. commit = false ;
  606. }
  607. return('true');
  608. }
  609. function Finish(val) {
  610. return LMSFinish(val);
  611. }
  612. function LMSGetLastError() {
  613. logit_scorm('LMSGetLastError()',1);
  614. return(G_LastError.toString());
  615. }
  616. function GetLastError() {
  617. return LMSGetLastError();
  618. }
  619. function LMSGetErrorString(errCode){
  620. logit_scorm('LMSGetErrorString()',1);
  621. return(G_LastErrorString);
  622. }
  623. function GetErrorString(errCode){
  624. return LMSGetErrorString(errCode);
  625. }
  626. function LMSGetDiagnostic(errCode){
  627. logit_scorm('LMSGetDiagnostic()',1);
  628. return(API.LMSGetLastError());
  629. }
  630. function GetDiagnostic(errCode){
  631. return LMSGetDiagnostic(errCode);
  632. }
  633. function Terminate(){
  634. logit_scorm('Terminate()',0);
  635. G_LastError = G_NoError ;
  636. G_LastErrorMessage = 'No error';
  637. commit = true;
  638. savedata('terminate');
  639. return (true);
  640. }
  641. <?php
  642. //--------------------------------------------------------------------//
  643. /**
  644. * Dokeos-specific code that deals with event handling and inter-frames
  645. * messaging/refreshing.
  646. * Note that from now on, the Dokeos JS code in this library will act as
  647. * a controller, of the MVC pattern, and receive all requests for frame
  648. * updates, then redispatch to any frame concerned.
  649. */
  650. ?>
  651. /**
  652. * Defining the AJAX-object class to be made available from other frames
  653. */
  654. function XAJAXobject() {
  655. this.xajax_switch_item_details=xajax_switch_item_details;
  656. this.switch_item=switch_item;
  657. this.xajax_save_objectives=xajax_save_objectives;
  658. this.xajax_save_item = xajax_save_item;
  659. }
  660. //it is not sure that the scos use the above declarations
  661. oXAJAX = new XAJAXobject();
  662. oxajax = new XAJAXobject();
  663. /**
  664. * Cross-browser event handling by Scott Andrew
  665. * @param element Element that needs an event attached
  666. * @param string Event type (load, unload, click, keyDown, ...)
  667. * @param string Function name (the event handler)
  668. * @param string used in addEventListener
  669. */
  670. function addEvent(elm, evType, fn, useCapture){
  671. if(elm.addEventListener){
  672. elm.addEventListener(evType, fn, useCapture);
  673. return true;
  674. }else if (elm.attachEvent){
  675. var r = elm.attachEvent('on' + evType, fn);
  676. }else{
  677. elm['on'+evType] = fn;
  678. }
  679. }
  680. /**
  681. * Add listeners to the page objects. This has to be defined for
  682. * the current context as it acts on objects that should exist
  683. * on the page
  684. * possibly deprecated
  685. */
  686. function addListeners(){
  687. //exit if the browser doesn't support ID or tag retrieval
  688. logit_lms('Entering addListeners()',2);
  689. if(!document.getElementsByTagName){
  690. logit_lms("getElementsByTagName not available",2);
  691. return;
  692. }
  693. if(!document.getElementById){
  694. logit_lms("getElementById not available",2);
  695. return;
  696. }
  697. //assign event handlers to objects
  698. if(lms_lp_type==1 || lms_item_type=='asset'){
  699. logit_lms('Dokeos LP or asset',2);
  700. //if this path is a Dokeos learnpath, then start manual save
  701. //when something is loaded in there
  702. addEvent(window,'unload',dokeos_save_asset,false);
  703. logit_lms('Added event listener on content_id for unload',2);
  704. }
  705. logit_lms('Quitting addListeners()',2);
  706. }
  707. /**
  708. * Load an item into the content frame:
  709. * - making sure the previous item status have been saved
  710. * - first updating the current item ID (to save the right item)
  711. * - updating the frame src
  712. * possibly deprecated
  713. */
  714. function load_item(item_id,url){
  715. if(document.getElementById('content_id'))
  716. {
  717. logit_lms('Loading item '+item_id,2);
  718. var cont_f = document.getElementById('content_id');
  719. if(cont_f.src){
  720. lms_old_item_id = lms_item_id;
  721. var lms_new_item_id = item_id;
  722. //load new content page into content frame
  723. if(lms_lp_type==1 || lms_item_type=='asset'){
  724. dokeos_save_asset();
  725. }
  726. cont_f.src = url;
  727. update_toc('unhighlight',lms_old_item_id);
  728. update_toc('highlight',item_id);
  729. return true;
  730. }
  731. logit_lms('cont_f.src has no properties',0);
  732. }
  733. logit_lms('content_id has no properties',0);
  734. return false;
  735. }
  736. /**
  737. * Save a Dokeos learnpath item's time and mark as completed upon
  738. * leaving it
  739. */
  740. function dokeos_save_asset(){
  741. logit_lms('dokeos_save_asset',2);
  742. 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);
  743. if(item_objectives.length>0)
  744. {
  745. xajax_save_objectives(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,item_objectives);
  746. }
  747. }
  748. /**
  749. * Save a Dokeos learnpath item's time and mark as completed upon leaving it.
  750. * Same function as dokeos_save_asset() but saves it with empty params
  751. * to use values set from another side in the database. Only used by Dokeos quizzes.
  752. * Also save the score locally because it hasn't been done through SetValue().
  753. * Saving the status will be dealt with by the XAJAX function.
  754. */
  755. function dokeos_void_save_asset(myscore,mymax)
  756. {
  757. logit_lms('dokeos_save_asset',2);
  758. score = myscore;
  759. if((mymax == null) || (mymax == '')){mymax = 100;} //assume a default of 100, otherwise the score will not get saved (see lpi->set_score())
  760. xajax_save_item(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, myscore, mymax);
  761. }
  762. /**
  763. * Logs information about SCORM messages into the log frame
  764. * @param string Message to log
  765. * @param integer Priority (0 for top priority, 3 for lowest)
  766. */
  767. function logit_scorm(message,priority){
  768. if(scorm_logs>priority){
  769. if(frames["lp_log_name"] && frames["lp_log_name"].document && frames["lp_log_name"].document.getElementById && frames["lp_log_name"].document.getElementById('log_content')){
  770. frames["lp_log_name"].document.getElementById("log_content").innerHTML += "SCORM: " + message + "<br/>";
  771. }
  772. }
  773. }
  774. /**
  775. * Logs information about LMS activity into the log frame
  776. * @param string Message to log
  777. * @param integer Priority (0 for top priority, 3 for lowest)
  778. */
  779. function logit_lms(message,priority){
  780. if(lms_logs>priority){
  781. if(frames["lp_log_name"] && frames["lp_log_name"].document && frames["lp_log_name"].document.getElementById && frames["lp_log_name"].document.getElementById('log_content')){
  782. frames["lp_log_name"].document.getElementById("log_content").innerHTML += "LMS: " + message + "<br/>";
  783. }
  784. }
  785. }
  786. /**
  787. * update the Table Of Contents frame, by changing CSS styles, mostly
  788. * @param string Action to be taken
  789. * @param integer Item id to update
  790. */
  791. function update_toc(update_action,update_id)
  792. {
  793. <?php //if($oLP->mode != 'fullscreen'){ ?>
  794. var myframe = frames["toc_name"];
  795. var myelem = myframe.document.getElementById("toc_"+update_id);
  796. var myelemimg = myframe.document.getElementById("toc_img_"+update_id);
  797. logit_lms('update_toc("'+update_action+'",'+update_id+')',2);
  798. if(update_id != 0)
  799. {
  800. switch(update_action)
  801. {
  802. case 'unhighlight':
  803. if (update_id%2==0)
  804. {
  805. myelem.className = "scorm_item_2";
  806. }
  807. else
  808. {
  809. myelem.className = "scorm_item_1";
  810. }
  811. break;
  812. case 'highlight':
  813. myelem.className = "scorm_item_highlight";
  814. break;
  815. case 'not attempted':
  816. if(myelemimg.src != '../img/notattempted.gif'){
  817. myelemimg.src = "../img/notattempted.gif";
  818. myelemimg.alt = "n";
  819. }
  820. break;
  821. case 'incomplete':
  822. if(myelemimg.src != '../img/incomplete.gif'){
  823. myelemimg.src = "../img/incomplete.gif";
  824. myelemimg.alt = "i";
  825. }
  826. break;
  827. case 'completed':
  828. if(myelemimg.src != '../img/completed.gif'){
  829. myelemimg.src = "../img/completed.gif";
  830. myelemimg.alt = "c";
  831. }
  832. break;
  833. case 'failed':
  834. if(myelemimg.src != '../img/failed.gif'){
  835. myelemimg.src = "../img/failed.gif";
  836. myelemimg.alt = "f";
  837. }
  838. break;
  839. case 'passed':
  840. if(myelemimg.src != '../img/completed.gif' && myelemimg.alt != 'passed'){
  841. myelemimg.src = "../img/completed.gif";
  842. myelemimg.alt = "p";
  843. }
  844. break;
  845. case 'browsed':
  846. if(myelemimg.src != '../img/completed.gif' && myelemimg.alt != 'browsed'){
  847. myelemimg.src = "../img/completed.gif";
  848. myelemimg.alt = "b";
  849. }
  850. break;
  851. default:
  852. logit_lms('Update action unknown',2);
  853. break;
  854. }
  855. }
  856. return true;
  857. <?php //} ?>
  858. return true;
  859. }
  860. /**
  861. * Updates the progress bar with the new status. Prevents the need of a page refresh and flickering
  862. * @param integer Number of completed items
  863. * @param integer Number of items in total
  864. * @param string Display mode (absolute 'abs' or percentage '%').Defaults to %
  865. */
  866. function update_progress_bar(nbr_complete, nbr_total, mode)
  867. {
  868. logit_lms('update_progress_bar('+nbr_complete+','+nbr_total+','+mode+')',2);
  869. logit_lms('could update with data: '+lms_lp_id+','+lms_view_id+','+lms_user_id,2);
  870. var myframe = frames["nav_name"];
  871. if(myframe){
  872. if(mode == ''){mode='%';}
  873. if(nbr_total == 0){nbr_total=1;}
  874. var percentage = (nbr_complete/nbr_total)*100;
  875. percentage = Math.round(percentage);
  876. var pr_text = myframe.document.getElementById('progress_text');
  877. var pr_full = myframe.document.getElementById('progress_img_full');
  878. var pr_empty = myframe.document.getElementById('progress_img_empty');
  879. pr_full.width = percentage;
  880. pr_empty.width = 100-percentage;
  881. var mytext = '';
  882. switch(mode){
  883. case 'abs':
  884. mytext = nbr_complete + '/' + nbr_total;
  885. break;
  886. case '%':
  887. default:
  888. mytext = percentage + '%';
  889. break;
  890. }
  891. pr_text.innerHTML = mytext;
  892. }
  893. return true;
  894. }
  895. function update_stats_page()
  896. {
  897. var myframe = document.getElementById('content_id');
  898. var mysrc = myframe.location.href;
  899. if(mysrc == 'lp_controller.php?action=stats'){
  900. if(myframe && myframe.src){
  901. var mysrc = myframe.src;
  902. myframe.src = mysrc;
  903. }
  904. // = mysrc; //refresh page
  905. }
  906. return true;
  907. }
  908. /**
  909. * Updates the message frame with the given string
  910. */
  911. function update_message_frame(msg_msg)
  912. {
  913. if(msg_msg==null){msg_msg='';}
  914. var msg_f = frames["message_name"];
  915. if(!msg_f.document || !msg_f.document.getElementById('msg_div_id')){
  916. logit_lms('In update_message_frame() - message frame has no document property',0);
  917. }else{
  918. logit_lms('In update_message_frame() - updating frame',0);
  919. msg_f.document.getElementById('msg_div_id').innerHTML= msg_msg;
  920. }
  921. }
  922. /**
  923. * Function that handles the saving of an item and switching from an item to another.
  924. * Once called, this function should be able to do the whole process of (1) saving the
  925. * current item, (2) refresh all the values inside the SCORM API object, (3) open the
  926. * new item into the content_id frame, (4) refresh the table of contents, (5) refresh
  927. * the progress bar (completion), (6) refresh the message frame
  928. * @param integer Dokeos ID for the current item
  929. * @param string This parameter can be a string specifying the next
  930. * item (like 'next', 'previous', 'first' or 'last') or the id to the next item
  931. */
  932. function switch_item(current_item, next_item){
  933. //(1) save the current item
  934. logit_lms('Called switch_item with params '+lms_item_id+' and '+next_item+'',0);
  935. if(lms_lp_type==1 || lms_item_type=='asset' || session_time == '0' || session_time == '0:00:00'){
  936. 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);
  937. }else{
  938. 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);
  939. }
  940. if(item_objectives.length>0)
  941. {
  942. xajax_save_objectives(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,item_objectives);
  943. }
  944. //(2) Refresh all the values inside this SCORM API object - use AJAX
  945. //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);
  946. xajax_switch_item_details(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,next_item);
  947. //(3) open the new item in the content_id frame
  948. switch(next_item){
  949. case 'next':
  950. next_item = lms_next_item;
  951. break;
  952. case 'previous':
  953. next_item = lms_previous_item;
  954. break;
  955. default:
  956. break;
  957. }
  958. var mysrc = 'lp_controller.php?action=content&lp_id='+lms_lp_id+'&item_id='+next_item;
  959. var cont_f = document.getElementById('content_id');
  960. if(!cont_f){
  961. logit_lms('In switch - content frame not found',0);
  962. <?php if($oLP->mode = 'fullscreen'){ ?>
  963. cont_f = window.open(''+mysrc,'content_name','toolbar=0,location=0,status=0,scrollbars=1,resizable=1');
  964. <?php } else { ?>
  965. return false;
  966. <?php } ?>
  967. }
  968. else
  969. {
  970. cont_f.src = mysrc;
  971. }
  972. if(lms_lp_type==1 || lms_item_type=='asset'){
  973. xajax_start_timer();
  974. }
  975. //(4) refresh the audiorecorder if needed
  976. if(frames['audiorecorder_name']){
  977. frames['audiorecorder_name'].location.reload();
  978. }
  979. return true;
  980. }
  981. addEvent(window,'load',addListeners,false);
  982. if(lms_lp_type==1 || lms_item_type=='asset'){
  983. xajax_start_timer();
  984. }