scorm_api.php 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579
  1. <?php // $Id: scorm_api.php 21162 2009-06-01 16:18:46Z yannoo $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2009 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.scorm
  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 = (empty($_SESSION['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. // Error codes
  97. var G_NoError = 0;
  98. var G_GeneralException = 101;
  99. var G_ServerBusy = 102; // this is not in the Scorm1.2_Runtime document
  100. var G_InvalidArgumentError = 201;
  101. var G_ElementCannotHaveChildren = 202;
  102. var G_ElementIsNotAnArray = 203;
  103. var G_NotInitialized = 301;
  104. var G_NotImplementedError = 401;
  105. var G_InvalidSetValue = 402;
  106. var G_ElementIsReadOnly = 403;
  107. var G_ElementIsWriteOnly = 404;
  108. var G_IncorrectDataType = 405;
  109. // Error messages
  110. var G_NoErrorMessage = '';
  111. var G_GeneralExceptionMessage = 'General Exception';
  112. var G_ServerBusyMessage = 'Server busy'; // this is not in the Scorm1.2_Runtime document
  113. var G_InvalidArgumentErrorMessage = 'Invalid argument error';
  114. var G_ElementCannotHaveChildrenMessage = 'Element cannot have children';
  115. var G_ElementIsNotAnArrayMessage = 'Element not an array. Cannot have count';
  116. var G_NotInitializedMessage = 'Not initialized';
  117. var G_NotImplementedErrorMessage = 'Not implemented error';
  118. var G_InvalidSetValueMessage = 'Invalid set value, element is a keyword';
  119. var G_ElementIsReadOnlyMessage = 'Element is read only';
  120. var G_ElementIsWriteOnlyMessage = 'Element is write only';
  121. var G_IncorrectDataTypeMessage = 'Incorrect Data Type';
  122. var G_LastError = G_NoError ;
  123. var G_LastErrorMessage = 'No error';
  124. //this is not necessary and is only provided to make bad Articulate contents shut up (and not trigger useless JS messages)
  125. var G_LastErrorString = 'No error';
  126. status_info=new Array();
  127. var commit = false ;
  128. var variables_scorm = new Array('cmi.core.score.raw','cmi.core.score.max','cmi.core.score.min','cmi.core.lesson_location',
  129. 'cmi.core.lesson_status','cmi.completion_status','cmi.core.session_time','cmi.score.scaled','cmi.success_status',
  130. 'cmi.suspend_data','cmi.core.exit','interactions');
  131. var variable_to_send=new Array();
  132. var updatetable_to_list=new Array();
  133. var info_of_variable_to_send=new Array();
  134. //Strictly scorm variables
  135. var score=<?php echo $oItem->get_score();?>;
  136. var max='<?php echo $oItem->get_max();?>';
  137. var min='<?php echo $oItem->get_min();?>';
  138. var lesson_status='<?php echo $oItem->get_status();?>';
  139. var session_time='<?php echo $oItem->get_scorm_time('js');?>';
  140. var suspend_data = '<?php echo $oItem->get_suspend_data();?>';
  141. var lesson_location = '<?php echo $oItem->get_lesson_location();?>';
  142. var total_time = '<?php echo $oItem->get_scorm_time('js');?>';
  143. var mastery_score = '<?php echo $oItem->get_mastery_score();?>';
  144. var launch_data = '<?php echo $oItem->get_launch_data();?>';
  145. var max_time_allowed = '<?php echo $oItem->get_max_time_allowed();?>';
  146. var interactions = new Array(<?php echo $oItem->get_interactions_js_array();?>);
  147. item_objectives = new Array();
  148. info_lms_item=new Array();
  149. $(document).ready( function() {
  150. info_lms_item[0]='<?php echo $oItem->get_id();?>';
  151. info_lms_item[1]='<?php echo $oItem->get_id();?>';
  152. $("#current_item_id").attr("value",<?php echo $oItem->get_id();?>);
  153. $("#old_item").attr("value",<?php echo $oItem->get_id();?>);
  154. //var myiframe=document.getElementById('content_id');
  155. //myiframe.Events.AttachEvent("onclick", update_lp_item_id);
  156. //myiframe.contentWindow.document.addEventListener("click", update_lp_item_id, false);
  157. } );
  158. $(document).ready( function() {
  159. $("iframe#content_id").load( function(){
  160. //alert("Document title: " + $("iframe#content_id").attr('src'));
  161. info_lms_item[0]=info_lms_item[1];
  162. info_lms_item[1]= info_lms_item[1];
  163. });
  164. });
  165. //Dokeos internal variables
  166. var saved_lesson_status = 'not attempted';
  167. var lms_lp_id = <?php echo $oLP->get_id();?>;
  168. var lms_item_id = <?php echo $oItem->get_id();?>;
  169. //var lms_new_item_id = 0; //temporary value (only there between a load_item() and a LMSInitialize())
  170. var lms_been_synchronized = 0;
  171. var lms_initialized = 0;
  172. var lms_total_lessons = <?php echo $oLP->get_total_items_count(); ?>;
  173. var lms_complete_lessons = <?php echo $oLP->get_complete_items_count();?>;
  174. var lms_progress_bar_mode = '<?php echo $oLP->progress_bar_mode;?>';
  175. if(lms_progress_bar_mode == ''){lms_progress_bar_mode='%';}
  176. var lms_view_id = '<?php echo $oLP->get_view();?>';
  177. if(lms_view_id == ''){ lms_view_id = 1;}
  178. var lms_user_id = '<?php echo $_user['user_id'];?>';
  179. var lms_next_item = '<?php echo $oLP->get_next_item_id();?>';
  180. var lms_previous_item = '<?php echo $oLP->get_previous_item_id();?>';
  181. var lms_lp_type = '<?php echo $oLP->get_type();?>';
  182. var lms_item_type = '<?php echo $oItem->get_type();?>';
  183. var lms_item_credit = '<?php echo $oItem->get_credit();?>';
  184. var lms_item_lesson_mode = '<?php echo $oItem->get_lesson_mode();?>';
  185. var lms_item_launch_data = '<?php echo $oItem->get_launch_data();?>';
  186. var lms_item_core_exit = '<?php echo $oItem->get_core_exit();?>';
  187. var asset_timer = 0;
  188. //Backup for old values
  189. var old_score = 0;
  190. var old_max = 0;
  191. var old_min = 0;
  192. var old_lesson_status = '';
  193. var old_session_time = '';
  194. var old_suspend_data = '';
  195. var lms_old_item_id = 0;
  196. var execute_stats='false';
  197. /**
  198. * Function called mandatorily by the SCORM content to start the SCORM communication
  199. */
  200. function LMSInitialize() { //this is the initialize function of all APIobjects
  201. /* load info for this new item by calling the js_api_refresh command in
  202. * the message frame. The message frame will update the JS variables by
  203. * itself, in JS, by doing things like top.lesson_status = 'not attempted'
  204. * and that kind of stuff, so when the content loads in the content frame
  205. * it will have all the correct variables set
  206. */
  207. G_LastError = G_NoError ;
  208. G_LastErrorMessage = 'No error';
  209. //reinit to list
  210. reinit_update_table_list ()
  211. lms_initialized=0;
  212. // if there are more parameters than ""
  213. if (arguments.length>1) {
  214. G_LastError = G_InvalidArgumentError;
  215. G_LastErrorMessage = G_InvalidArgumentErrorMessage;
  216. logit_scorm('Error '+ G_InvalidArgumentError + G_InvalidArgumentErrorMessage, 0);
  217. return('false');
  218. } else {
  219. logit_scorm('LMSInitialise()',0);
  220. lms_initialized=1;
  221. return('true');
  222. }
  223. }
  224. function Initialize()
  225. { //this is the initialize function of all APIobjects
  226. return LMSInitialize();
  227. }
  228. function LMSGetValue(param)
  229. {
  230. //logit_scorm("LMSGetValue('"+param+"')",1);
  231. G_LastError = G_NoError ;
  232. G_LastErrorMessage = 'No error';
  233. var result='';
  234. // the LMSInitialize is missing
  235. if (lms_initialized == 0) {
  236. G_LastError = G_NotInitialized;
  237. G_LastErrorMessage = G_NotInitializedMessage;
  238. logit_scorm('Error '+ G_NotInitialized + ' ' +G_NotInitializedMessage, 0);
  239. return '';
  240. }
  241. //Dokeos does not support this SCO object properties
  242. if (param == 'cmi.student_preference.text' ||
  243. param == 'cmi.student_preference.language' ||
  244. param == 'cmi.student_preference.speed' ||
  245. param == 'cmi.student_preference.audio' ||
  246. param == 'cmi.student_preference._children' ||
  247. param == 'cmi.student_data.time_limit_action' ||
  248. param == 'cmi.comments' ||
  249. param == 'cmi.comments_from_lms' ) {
  250. // the value is not supported
  251. G_lastError = G_NotImplementedError ;
  252. G_lastErrorString = G_NotImplementedErrorMessage;
  253. logit_scorm("LMSGetValue ('"+param+"') Error '"+G_NotImplementedErrorMessage+"'",1);
  254. result = '';
  255. return result;
  256. }
  257. // ---- cmi.core._children
  258. if(param=='cmi.core._children' || param=='cmi.core_children'){
  259. result='entry, exit, lesson_status, student_id, student_name, lesson_location, total_time, credit, lesson_mode, score, session_time';
  260. }else if(param == 'cmi.core.entry'){
  261. // ---- cmi.core.entry
  262. if(lms_item_core_exit=='none') {
  263. result='ab-initio';
  264. } else if(lms_item_core_exit=='suspend') {
  265. result='resume';
  266. } else {
  267. result='';
  268. }
  269. }else if(param == 'cmi.core.exit'){
  270. // ---- cmi.core.exit
  271. result='';
  272. G_LastError = G_ElementIsWriteOnly;
  273. }else if(param == 'cmi.core.session_time'){
  274. result='';
  275. G_LastError = G_ElementIsWriteOnly;
  276. }else if(param == 'cmi.core.lesson_status'){
  277. // ---- cmi.core.lesson_status
  278. if(lesson_status != '') {
  279. result=lesson_status;
  280. } else {
  281. //result='not attempted';
  282. }
  283. }else if(param == 'cmi.core.student_id'){
  284. // ---- cmi.core.student_id
  285. result='<?php echo $_user['user_id']; ?>';
  286. }else if(param == 'cmi.core.student_name'){
  287. // ---- cmi.core.student_name
  288. <?php
  289. $who=addslashes(api_get_person_name($_user['firstName'], $_user['lastName']));
  290. echo "result='$who';";
  291. ?>
  292. }else if(param == 'cmi.core.lesson_location'){
  293. // ---- cmi.core.lesson_location
  294. result=lesson_location;
  295. }else if(param == 'cmi.core.total_time'){
  296. // ---- cmi.core.total_time
  297. result=total_time;
  298. }else if(param == 'cmi.core.score._children'){
  299. // ---- cmi.core.score._children
  300. result='raw,min,max';
  301. }else if(param == 'cmi.core.score.raw'){
  302. // ---- cmi.core.score.raw
  303. result=score;
  304. }else if(param == 'cmi.core.score.max'){
  305. // ---- cmi.core.score.max
  306. result=max;
  307. }else if(param == 'cmi.core.score.min'){
  308. // ---- cmi.core.score.min
  309. result=min;
  310. }else if(param == 'cmi.core.score'){
  311. // ---- cmi.core.score -- non-standard item, provided as cmi.core.score.raw just in case
  312. result=score;
  313. }else if(param == 'cmi.core.credit'){
  314. // ---- cmi.core.credit
  315. result = lms_item_credit;
  316. }else if(param == 'cmi.core.lesson_mode'){
  317. // ---- cmi.core.lesson_mode
  318. result = lms_item_lesson_mode;
  319. }else if(param == 'cmi.suspend_data'){
  320. // ---- cmi.suspend_data
  321. result = suspend_data;
  322. }else if(param == 'cmi.launch_data'){
  323. // ---- cmi.launch_data
  324. result = lms_item_launch_data;
  325. }else if(param == 'cmi.objectives._children'){
  326. // ---- cmi.objectives._children
  327. result = 'id,score,status';
  328. }else if(param == 'cmi.objectives._count'){
  329. // ---- cmi.objectives._count
  330. //result='<?php echo $oItem->get_view_count();?>';
  331. result = item_objectives.length;
  332. }else if(param.substring(0,15)== 'cmi.objectives.'){
  333. var myres = '';
  334. if(myres = param.match(/cmi.objectives.(\d+).(id|score|status|_children)(.*)/))
  335. {
  336. var obj_id = myres[1];
  337. var req_type = myres[2];
  338. if(item_objectives[obj_id]==null)
  339. {
  340. if(req_type == 'id')
  341. {
  342. result = '';
  343. }else if(req_type == '_children'){
  344. result = 'id,score,status';
  345. }else if(req_type == 'score'){
  346. if(myres[3]==null)
  347. {
  348. result = '';
  349. G_lastError = G_NotImplementedError;
  350. G_lastErrorString = 'Not implemented yet';
  351. }else if (myres[3] == '._children'){
  352. result = 'raw,min,max'; //non-standard, added for NetG
  353. }else if (myres[3] == '.raw'){
  354. result = '';
  355. }else if (myres[3] == '.max'){
  356. result = '';
  357. }else if (myres[3] == '.min'){
  358. result = '';
  359. }else{
  360. result = '';
  361. G_lastError = G_NotImplementedError;
  362. G_lastErrorString = 'Not implemented yet';
  363. }
  364. }else if(req_type == 'status'){
  365. result = 'not attempted';
  366. }
  367. }
  368. else
  369. {
  370. //the object is not null
  371. if(req_type == 'id')
  372. {
  373. result = item_objectives[obj_id][0];
  374. }else if(req_type == '_children'){
  375. result = 'id,score,status';
  376. }else if(req_type == 'score'){
  377. if(myres[3]==null)
  378. {
  379. result = '';
  380. G_lastError = G_NotImplementedError;
  381. G_lastErrorString = 'Not implemented yet';
  382. }else if (myres[3] == '._children'){
  383. result = 'raw,min,max'; //non-standard, added for NetG
  384. }else if (myres[3] == '.raw'){
  385. if(item_objectives[obj_id][2] != null)
  386. {
  387. result = item_objectives[obj_id][2];
  388. }else{
  389. result = '';
  390. }
  391. }else if (myres[3] == '.max'){
  392. if(item_objectives[obj_id][3] != null)
  393. {
  394. result = item_objectives[obj_id][3];
  395. }else{
  396. result = '';
  397. }
  398. }else if (myres[3] == '.min'){
  399. if(item_objectives[obj_id][4] != null)
  400. {
  401. result = item_objectives[obj_id][4];
  402. }else{
  403. result = '';
  404. }
  405. }else{
  406. result = '';
  407. G_lastError = G_NotImplementedError;
  408. G_lastErrorString = 'Not implemented yet';
  409. }
  410. }else if(req_type == 'status'){
  411. if(item_objectives[obj_id][1] != null)
  412. {
  413. result = item_objectives[obj_id][1];
  414. }else{
  415. result = 'not attempted';
  416. }
  417. }
  418. }
  419. }
  420. }else if(param == 'cmi.student_data._children'){
  421. // ---- cmi.student_data._children
  422. result = 'mastery_score,max_time_allowed';
  423. }else if(param == 'cmi.student_data.mastery_score'){
  424. // ---- cmi.student_data.mastery_score
  425. result = mastery_score;
  426. }else if(param == 'cmi.student_data.max_time_allowed'){
  427. // ---- cmi.student_data.max_time_allowed
  428. result = max_time_allowed;
  429. }else if(param == 'cmi.interactions._count'){
  430. // ---- cmi.interactions._count
  431. result = interactions.length;
  432. }else if(param == 'cmi.interactions._children'){
  433. // ---- cmi.interactions._children
  434. result = 'id,time,type,correct_responses,weighting,student_response,result,latency';
  435. }else{
  436. // ---- anything else
  437. // Invalid argument error
  438. G_lastError = G_InvalidArgumentError ;
  439. G_lastErrorString = G_InvalidArgumentErrorMessage;
  440. logit_scorm("LMSGetValue ('"+param+"') Error '"+G_InvalidArgumentErrorMessage+"'",1);
  441. result = '';
  442. return result;
  443. }
  444. logit_scorm("LMSGetValue\n\t('"+param+"') returned '"+result+"'",1);
  445. return result;
  446. }
  447. function GetValue(param) {
  448. return LMSGetValue(param);
  449. }
  450. function LMSSetValue(param, val) {
  451. logit_scorm("LMSSetValue\n\t('"+param+"','"+val+"')",0);
  452. commit = true; //value has changed, need to re-commit
  453. G_LastError = G_NoError ;
  454. G_LastErrorMessage = 'No error';
  455. return_value = 'false';
  456. if( param == "cmi.core.score.raw" ) {
  457. score= val;
  458. updatetable_to_list['cmi.core.score.raw']='true';
  459. return_value='true';
  460. } else if ( param == "cmi.core.score.max" ) {
  461. max = val;
  462. updatetable_to_list['cmi.core.score.max']='true';
  463. return_value='true';
  464. } else if ( param == "cmi.core.score.min" ) {
  465. min = val;
  466. updatetable_to_list['cmi.core.score.min']='true';
  467. return_value='true';
  468. } else if ( param == "cmi.core.lesson_location" ) {
  469. lesson_location = val;
  470. updatetable_to_list['cmi.core.lesson_location']='true';
  471. return_value='true';
  472. } else if ( param == "cmi.core.lesson_status" ) {
  473. saved_lesson_status = lesson_status;
  474. lesson_status = val;
  475. updatetable_to_list['cmi.core.lesson_status']='true';
  476. return_value='true';
  477. } else if ( param == "cmi.completion_status" ) {
  478. lesson_status = val;
  479. updatetable_to_list['cmi.completion_status']='true';
  480. return_value='true'; //1.3
  481. } else if ( param == "cmi.core.session_time" ) {
  482. session_time = val;
  483. updatetable_to_list['cmi.core.session_time']='true';
  484. return_value='true';
  485. } else if ( param == "cmi.score.scaled") { //1.3
  486. if(val<=1 && val>=-1) {
  487. score = val ;
  488. updatetable_to_list['cmi.score.scaled']='true';
  489. return_value='true';
  490. } else {
  491. return_value='false';
  492. }
  493. } else if ( param == "cmi.success_status" ) {
  494. success_status = val;
  495. updatetable_to_list['cmi.success_status']='true';
  496. return_value='true'; //1.3
  497. } else if ( param == "cmi.suspend_data" ) {
  498. suspend_data = val;
  499. updatetable_to_list['cmi.suspend_data']='true';
  500. return_value='true';
  501. } else if ( param == "cmi.core.exit" ) {
  502. lms_item_core_exit = val;
  503. updatetable_to_list['cmi.core.exit']='true';
  504. return_value='true';
  505. } else if ( param == "cmi.core.student_id" ) {
  506. G_LastError = G_ElementIsReadOnly;
  507. } else if ( param == "cmi.core.student_name" ) {
  508. G_LastError = G_ElementIsReadOnly;
  509. } else if ( param == "cmi.core.credit" ) {
  510. G_LastError = G_ElementIsReadOnly;
  511. } else if ( param == "cmi.core.entry" ) {
  512. G_LastError = G_ElementIsReadOnly;
  513. } else if ( param == "cmi.core.total_time" ) {
  514. G_LastError = G_ElementIsReadOnly;
  515. } else if ( param == "cmi.core.lesson_mode" ) {
  516. G_LastError = G_ElementIsReadOnly;
  517. } else if ( param == "cmi.comments_from_lms" ) {
  518. G_LastError = G_ElementIsReadOnly;
  519. } else if ( param == "cmi.student_data.time_limit_action" ) {
  520. G_LastError = G_ElementIsReadOnly;
  521. } else if ( param == "cmi.student_data.mastery_score" ) {
  522. G_LastError = G_ElementIsReadOnly;
  523. } else if ( param == "cmi.student_data.max_time_allowed" ) {
  524. G_LastError = G_ElementIsReadOnly;
  525. } else if ( param == "cmi.student_preference._children" ) {
  526. G_LastError = G_ElementIsReadOnly;
  527. } else if ( param == "cmi.launch_data" ) {
  528. G_LastError = G_ElementIsReadOnly;
  529. } else {
  530. var myres = new Array();
  531. if(myres = param.match(/cmi.interactions.(\d+).(id|time|type|correct_responses|weighting|student_response|result|latency)(.*)/)) {
  532. updatetable_to_list['interactions']='true';
  533. elem_id = myres[1];
  534. if(elem_id > interactions.length) //interactions setting should start at 0
  535. {
  536. /*
  537. G_LastError = G_InvalidArgumentError;
  538. G_LastErrorString = 'Invalid argument (interactions)';
  539. return_value = false;
  540. */
  541. interactions[0] = ['0','','','','','','',''];
  542. }
  543. if(interactions[elem_id] == null){
  544. interactions[elem_id] = ['','','','','','','',''];
  545. //id(0), type(1), time(2), weighting(3),correct_responses(4),student_response(5),result(6),latency(7)
  546. interactions[elem_id][4] = new Array();
  547. }
  548. elem_attrib = myres[2];
  549. switch(elem_attrib) {
  550. case "id":
  551. interactions[elem_id][0] = val;
  552. logit_scorm("Interaction "+elem_id+"'s id updated",2);
  553. return_value='true';
  554. break;
  555. case "time":
  556. interactions[elem_id][2] = val;
  557. logit_scorm("Interaction "+elem_id+"'s time updated",2);
  558. return_value='true';
  559. break;
  560. case "type":
  561. interactions[elem_id][1] = val;
  562. logit_scorm("Interaction "+elem_id+"'s type updated",2);
  563. return_value='true';
  564. break;
  565. case "correct_responses":
  566. //do nothing yet
  567. interactions[elem_id][4].push(val);
  568. logit_scorm("Interaction "+elem_id+"'s correct_responses not updated",2);
  569. return_value='true';
  570. break;
  571. case "weighting":
  572. interactions[elem_id][3] = val;
  573. logit_scorm("Interaction "+elem_id+"'s weighting updated",2);
  574. return_value='true';
  575. break;
  576. case "student_response":
  577. interactions[elem_id][5] = ''+val;
  578. logit_scorm("Interaction "+elem_id+"'s student_response updated",2);
  579. return_value='true';
  580. break;
  581. case "result":
  582. interactions[elem_id][6] = val;
  583. logit_scorm("Interaction "+elem_id+"'s result updated",2);
  584. return_value='true';
  585. break;
  586. case "latency":
  587. interactions[elem_id][7] = val;
  588. logit_scorm("Interaction "+elem_id+"'s latency updated",2);
  589. return_value='true';
  590. break;
  591. default:
  592. G_lastError = G_NotImplementedError;
  593. G_lastErrorString = 'Not implemented yet';
  594. }
  595. }else if(param.substring(0,15)== 'cmi.objectives.'){
  596. var myres = '';
  597. updatetable_to_list['objectives']='true';
  598. if(myres = param.match(/cmi.objectives.(\d+).(id|score|status)(.*)/))
  599. {
  600. obj_id = myres[1];
  601. if(obj_id > item_objectives.length) //objectives setting should start at 0
  602. {
  603. G_LastError = G_InvalidArgumentError;
  604. G_LastErrorString = 'Invalid argument (objectives)';
  605. return_value = false;
  606. }
  607. else
  608. {
  609. req_type = myres[2];
  610. if(obj_id == null || obj_id == '')
  611. {
  612. ;//do nothing
  613. }
  614. else
  615. {
  616. if(item_objectives[obj_id]==null)
  617. {
  618. item_objectives[obj_id] = ['','','','',''];
  619. }
  620. if( req_type == "id" ) {
  621. //item_objectives[obj_id][0] = val.substring(51,57);
  622. item_objectives[obj_id][0] = val;
  623. logit_scorm("Objective "+obj_id+"'s id updated",2);
  624. return_value = 'true';
  625. } else if ( req_type == "score" ) {
  626. if (myres[3] == '._children'){
  627. return_value = '';
  628. G_lastError = G_InvalidSetValue;
  629. G_lastErrorString = 'Invalid set value, element is a keyword';
  630. }else if (myres[3] == '.raw'){
  631. item_objectives[obj_id][2] = val;
  632. logit_scorm("Objective "+obj_id+"'s score raw updated",2);
  633. return_value = 'true';
  634. }else if (myres[3] == '.max'){
  635. item_objectives[obj_id][3] = val;
  636. logit_scorm("Objective "+obj_id+"'s score max updated",2);
  637. return_value = 'true';
  638. }else if (myres[3] == '.min'){
  639. item_objectives[obj_id][4] = val;
  640. logit_scorm("Objective "+obj_id+"'s score min updated",2);
  641. return_value = 'true';
  642. }else{
  643. return_value = '';
  644. G_lastError = G_NotImplementedError;
  645. G_lastErrorString = 'Not implemented yet';
  646. }
  647. } else if ( req_type == "status" ) {
  648. item_objectives[obj_id][1] = val;
  649. logit_scorm("Objective "+obj_id+"'s status updated",2);
  650. return_value = 'true';
  651. } else {
  652. G_lastError = G_NotImplementedError;
  653. G_lastErrorString = 'Not implemented yet';
  654. }
  655. }
  656. }
  657. }
  658. }else{
  659. G_lastError = G_NotImplementedError;
  660. G_lastErrorString = G_NotImplementedErrorMessage;
  661. }
  662. }
  663. <?php
  664. if ($oLP->force_commit == 1){
  665. echo " var mycommit = LMSCommit('force');";
  666. }
  667. ?>
  668. return(return_value);
  669. }
  670. function SetValue(param, val) {
  671. return LMSSetValue(param, val);
  672. }
  673. function ProcessValueScorm () {
  674. for (i=0;i<variables_scorm.length;i++) {
  675. if (updatetable_to_list[variables_scorm[i]]=='true') {
  676. info_update_table=variables_scorm[i];
  677. variable_to_send.push(info_update_table);
  678. }
  679. }
  680. return variable_to_send;
  681. }
  682. function reinit_update_table_list () {
  683. for (i=0;i<variables_scorm.length;i++) {
  684. if (updatetable_to_list[variables_scorm[i]]=='true') {
  685. updatetable_to_list[variables_scorm[i]]='false';
  686. }
  687. }
  688. lesson_status='';
  689. }
  690. function savedata(origin) {
  691. //origin can be 'commit', 'finish' or 'terminate'
  692. if ((lesson_status != 'completed') && (lesson_status != 'passed') && (mastery_score >=0) && (score >= mastery_score)) {
  693. lesson_status = 'passed';
  694. updatetable_to_list['cmi.core.lesson_status']='true';
  695. } else if( (mastery_score < 0) && (lms_lp_type != '2') && ( lesson_status == 'incomplete') && (score >= (0.8*max) ) ) {
  696. //the status cannot be modified automatically by the LMS under SCORM 1.2's rules
  697. <?php if ($autocomplete_when_80pct){ ?>
  698. lesson_status = 'completed';
  699. updatetable_to_list['cmi.core.lesson_status']='true';
  700. <?php }?>
  701. ;
  702. } else {
  703. /*
  704. * See notes in switch_item for why this has been disabled
  705. if ((origin== 'finish' || origin == 'unload') && lesson_status != 'completed' && lesson_status != 'passed' && lesson_status != 'browsed' && lesson_status != 'failed' && lesson_status != 'incomplete') {
  706. // The SCORM1.2 Runtime object document says for the "cmi.core.lesson_status" variable:
  707. // Upon receiving the LMSFinish() call or the user navigates away,
  708. // the LMS should set the cmi.core.lesson_status for the SCO to 'completed'
  709. logit_lms('the LMS did saving data (status='+lesson_status+' - interactions: '+ interactions.length +')',1);
  710. if (mastery_score && mastery_score!= '' && score && score != '') {
  711. if (score >= mastery_score) {
  712. lesson_status = 'passed';
  713. } else {
  714. lesson_status = 'failed';
  715. }
  716. updatetable_to_list['cmi.core.lesson_status']='true';
  717. } else if (mastery_score && mastery_score!= '') {
  718. lesson_status = 'completed';
  719. updatetable_to_list['cmi.core.lesson_status']='true';
  720. }
  721. }
  722. */
  723. }
  724. my_get_value_scorm=new Array();
  725. my_get_value_scorm=ProcessValueScorm();
  726. logit_lms('saving data (status='+lesson_status+' - interactions: '+ interactions.length +')',1);
  727. old_item_id=info_lms_item[0];
  728. // xajax_save_item is replaced to xajax_save_item_scorm for scorm LP's
  729. //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);
  730. xajax_save_item_scorm(lms_lp_id, lms_user_id, lms_view_id, old_item_id,my_get_value_scorm);
  731. //info_lms_item[0] is old_item_id and info_lms_item[1] is current_item_id
  732. info_lms_item[0]=info_lms_item[0];
  733. info_lms_item[1]=lms_item_id;
  734. if(item_objectives.length>0) {
  735. xajax_save_objectives(lms_lp_id,lms_user_id,lms_view_id,old_item_id,item_objectives);
  736. }
  737. execute_stats='false';
  738. //clean array
  739. variable_to_send=new Array();
  740. my_get_value_scorm=new Array();
  741. }
  742. /*
  743. * See notes in switch_item for why this has been disabled
  744. function savedata_onunload() {
  745. savedata('unload');
  746. }
  747. */
  748. function LMSCommit(val) {
  749. logit_scorm('LMSCommit()',0);
  750. G_LastError = G_NoError ;
  751. G_LastErrorMessage = 'No error';
  752. savedata('commit');
  753. reinit_update_table_list();
  754. //commit = 'false' ; //now changes have been commited, no need to update until next SetValue()
  755. return('true');
  756. }
  757. function Commit(val) {
  758. return LMSCommit(val);
  759. }
  760. function LMSFinish(val) {
  761. G_LastError = G_NoError ;
  762. G_LastErrorMessage = 'No error';
  763. // why commit==false?
  764. if (( commit == false )) {
  765. logit_scorm('LMSFinish() (no LMSCommit())',1);
  766. }
  767. //if ( commit == true ) {
  768. logit_scorm('LMSFinish() called',1);
  769. savedata('finish');
  770. commit = 'false' ;
  771. //}
  772. //reinit to list
  773. reinit_update_table_list()
  774. return('true');
  775. }
  776. function Finish(val) {
  777. return LMSFinish(val);
  778. }
  779. function LMSGetLastError() {
  780. logit_scorm('LMSGetLastError()',1);
  781. return(G_LastError.toString());
  782. }
  783. function GetLastError() {
  784. return LMSGetLastError();
  785. }
  786. function LMSGetErrorString(errCode){
  787. logit_scorm('LMSGetErrorString()',1);
  788. return(G_LastErrorString);
  789. }
  790. function GetErrorString(errCode){
  791. return LMSGetErrorString(errCode);
  792. }
  793. function LMSGetDiagnostic(errCode){
  794. logit_scorm('LMSGetDiagnostic()',1);
  795. return(API.LMSGetLastError());
  796. }
  797. function GetDiagnostic(errCode){
  798. return LMSGetDiagnostic(errCode);
  799. }
  800. function Terminate()
  801. {
  802. if (lms_initialized == 0) {
  803. G_LastError = G_NotInitialized;
  804. G_LastErrorMessage = G_NotInitializedMessage;
  805. logit_scorm('Error '+ G_NotInitialized + G_NotInitializedMessage, 0);
  806. return('false');
  807. } else {
  808. logit_scorm('Terminate()',0);
  809. G_LastError = G_NoError ;
  810. G_LastErrorMessage = 'No error';
  811. commit = true;
  812. savedata('terminate');
  813. return (true);
  814. }
  815. }
  816. <?php
  817. //--------------------------------------------------------------------//
  818. /**
  819. * Dokeos-specific code that deals with event handling and inter-frames
  820. * messaging/refreshing.
  821. * Note that from now on, the Dokeos JS code in this library will act as
  822. * a controller, of the MVC pattern, and receive all requests for frame
  823. * updates, then redispatch to any frame concerned.
  824. */
  825. ?>
  826. /**
  827. * Defining the AJAX-object class to be made available from other frames
  828. */
  829. function XAJAXobject() {
  830. this.xajax_switch_item_details=xajax_switch_item_details;
  831. this.switch_item=switch_item;
  832. this.xajax_save_objectives=xajax_save_objectives;
  833. this.xajax_save_item = xajax_save_item;
  834. }
  835. //it is not sure that the scos use the above declarations
  836. oXAJAX = new XAJAXobject();
  837. oxajax = new XAJAXobject();
  838. /**
  839. * Cross-browser event handling by Scott Andrew
  840. * @param element Element that needs an event attached
  841. * @param string Event type (load, unload, click, keyDown, ...)
  842. * @param string Function name (the event handler)
  843. * @param string used in addEventListener
  844. */
  845. function addEvent(elm, evType, fn, useCapture){
  846. if(elm.addEventListener){
  847. elm.addEventListener(evType, fn, useCapture);
  848. return true;
  849. }else if (elm.attachEvent){
  850. var r = elm.attachEvent('on' + evType, fn);
  851. }else{
  852. elm['on'+evType] = fn;
  853. }
  854. }
  855. /**
  856. * Add listeners to the page objects. This has to be defined for
  857. * the current context as it acts on objects that should exist
  858. * on the page
  859. * possibly deprecated
  860. */
  861. function addListeners(){
  862. //exit if the browser doesn't support ID or tag retrieval
  863. logit_lms('Entering addListeners()',2);
  864. if(!document.getElementsByTagName){
  865. logit_lms("getElementsByTagName not available",2);
  866. return;
  867. }
  868. if(!document.getElementById){
  869. logit_lms("getElementById not available",2);
  870. return;
  871. }
  872. //assign event handlers to objects
  873. if(lms_lp_type==1 || lms_item_type=='asset'){
  874. logit_lms('Dokeos LP or asset',2);
  875. //if this path is a Dokeos learnpath, then start manual save
  876. //when something is loaded in there
  877. addEvent(window,'unload',dokeos_save_asset,false);
  878. logit_lms('Added event listener on content_id for unload',2);
  879. }
  880. /* See notes in switch_item() for why this has been disabled
  881. if (lms_lp_type==2) {
  882. addEvent(window,'unload',savedata_onunload,false);
  883. }
  884. */
  885. logit_lms('Quitting addListeners()',2);
  886. }
  887. /**
  888. * Load an item into the content frame:
  889. * - making sure the previous item status have been saved
  890. * - first updating the current item ID (to save the right item)
  891. * - updating the frame src
  892. * possibly deprecated
  893. */
  894. function load_item(item_id,url){
  895. if(document.getElementById('content_id')) {
  896. logit_lms('Loading item '+item_id,2);
  897. var cont_f = document.getElementById('content_id');
  898. if(cont_f.src){
  899. lms_old_item_id = lms_item_id;
  900. var lms_new_item_id = item_id;
  901. //load new content page into content frame
  902. if(lms_lp_type==1 || lms_item_type=='asset'){
  903. dokeos_save_asset();
  904. }
  905. cont_f.src = url;
  906. update_toc('unhighlight',lms_old_item_id);
  907. update_toc('highlight',lms_old_item_id);
  908. return true;
  909. }
  910. logit_lms('cont_f.src has no properties',0);
  911. }
  912. logit_lms('content_id has no properties',0);
  913. return false;
  914. }
  915. /**
  916. * Save a Dokeos learnpath item's time and mark as completed upon
  917. * leaving it
  918. */
  919. function dokeos_save_asset(){
  920. // only for dokeos lps
  921. if (execute_stats=='true') {
  922. execute_stats='false';
  923. } else {
  924. execute_stats='true';
  925. }
  926. if(lms_lp_type==1 || lms_item_type=='asset'){
  927. logit_lms('dokeos_save_asset',2);
  928. 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);
  929. if(item_objectives.length>0)
  930. {
  931. xajax_save_objectives(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,item_objectives);
  932. }
  933. }
  934. }
  935. /**
  936. * Save a Dokeos learnpath item's time and mark as completed upon leaving it.
  937. * Same function as dokeos_save_asset() but saves it with empty params
  938. * to use values set from another side in the database. Only used by Dokeos quizzes.
  939. * Also save the score locally because it hasn't been done through SetValue().
  940. * Saving the status will be dealt with by the XAJAX function.
  941. */
  942. function dokeos_void_save_asset(myscore,mymax)
  943. {
  944. logit_lms('dokeos_save_asset',2);
  945. score = myscore;
  946. if((mymax == null) || (mymax == '')){mymax = 100;} //assume a default of 100, otherwise the score will not get saved (see lpi->set_score())
  947. xajax_save_item(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, myscore, mymax);
  948. }
  949. /**
  950. * Logs information about SCORM messages into the log frame
  951. * @param string Message to log
  952. * @param integer Priority (0 for top priority, 3 for lowest)
  953. */
  954. function logit_scorm(message,priority){
  955. if(scorm_logs>priority){
  956. if($("#lp_log_name") && $("#log_content")){
  957. $("#log_content").append("SCORM: " + message + "<br/>");
  958. }
  959. }
  960. }
  961. /**
  962. * Logs information about LMS activity into the log frame
  963. * @param string Message to log
  964. * @param integer Priority (0 for top priority, 3 for lowest)
  965. */
  966. function logit_lms(message,priority){
  967. if(lms_logs>priority){
  968. if ($("#lp_log_name") && $("#log_content")) {
  969. $("#log_content").append("LMS: " + message + "<br />");
  970. }
  971. }
  972. }
  973. /**
  974. * update the Table Of Contents frame, by changing CSS styles, mostly
  975. * @param string Action to be taken
  976. * @param integer Item id to update
  977. */
  978. function update_toc(update_action,update_id,change_ids)
  979. {
  980. if (!change_ids || change_ids != 'no') {
  981. change_ids = 'yes';
  982. }
  983. var myelem = $("#toc_"+update_id);
  984. var myelemimg = $("#toc_img_"+update_id);
  985. logit_lms('update_toc("'+update_action+'",'+update_id+')',2);
  986. if(update_id != 0)
  987. {
  988. switch(update_action)
  989. {
  990. case 'unhighlight':
  991. if (update_id%2==0)
  992. {
  993. myelem.attr('class',"scorm_item_2");
  994. }
  995. else
  996. {
  997. myelem.attr('class',"scorm_item_1");
  998. }
  999. break;
  1000. case 'highlight':
  1001. if (change_ids=='yes') {
  1002. lms_next_item = update_id;
  1003. lms_previous_item = update_id;
  1004. }
  1005. myelem.attr('class',"scorm_item_highlight");
  1006. break;
  1007. case 'not attempted':
  1008. if( myelemimg.attr('src') != '../img/notattempted.gif') {
  1009. myelemimg.attr('src','../img/notattempted.gif');
  1010. myelemimg.attr('alt','n');
  1011. }
  1012. break;
  1013. case 'incomplete':
  1014. if( myelemimg.attr('src') != '../img/incomplete.gif') {
  1015. myelemimg.attr('src','../img/incomplete.gif');
  1016. myelemimg.attr('alt','i');
  1017. }
  1018. break;
  1019. case 'completed':
  1020. if( myelemimg.attr('src') != '../img/completed.gif') {
  1021. myelemimg.attr('src','../img/completed.gif');
  1022. myelemimg.attr('alt','c');
  1023. }
  1024. break;
  1025. case 'failed':
  1026. if( myelemimg.attr('src') != '../img/failed.gif') {
  1027. myelemimg.attr('src','../img/failed.gif');
  1028. myelemimg.attr('alt','f');
  1029. }
  1030. break;
  1031. case 'passed':
  1032. if( myelemimg.attr('src') != '../img/completed.gif' && myelemimg.attr('alt') != 'passed') {
  1033. myelemimg.attr('src','../img/completed.gif');
  1034. myelemimg.attr('alt','p');
  1035. }
  1036. break;
  1037. case 'browsed':
  1038. if( myelemimg.attr('src') != '../img/completed.gif' && myelemimg.attr('alt') != 'browsed') {
  1039. myelemimg.attr('src','../img/completed.gif');
  1040. myelemimg.attr('alt','b');
  1041. }
  1042. break;
  1043. default:
  1044. logit_lms('Update action unknown',2);
  1045. break;
  1046. }
  1047. }
  1048. return true;
  1049. }
  1050. function update_stats() {
  1051. if (execute_stats=='true') {
  1052. try {
  1053. cont_f = document.getElementById('content_id');
  1054. cont_f.src="lp_controller.php?action=stats";
  1055. cont_f.reload();
  1056. } catch (e) {
  1057. return false;
  1058. }
  1059. }
  1060. execute_stats='false';
  1061. }
  1062. /**
  1063. * Updates the progress bar with the new status. Prevents the need of a page refresh and flickering
  1064. * @param integer Number of completed items
  1065. * @param integer Number of items in total
  1066. * @param string Display mode (absolute 'abs' or percentage '%').Defaults to %
  1067. */
  1068. function update_progress_bar(nbr_complete, nbr_total, mode)
  1069. {
  1070. logit_lms('update_progress_bar('+nbr_complete+','+nbr_total+','+mode+')',2);
  1071. logit_lms('could update with data: '+lms_lp_id+','+lms_view_id+','+lms_user_id,2);
  1072. if(mode == ''){mode='%';}
  1073. if(nbr_total == 0){nbr_total=1;}
  1074. var percentage = (nbr_complete/nbr_total)*100;
  1075. percentage = Math.round(percentage);
  1076. var pr_text = $("#progress_text");
  1077. var pr_full = $("#progress_img_full");
  1078. var pr_empty = $("#progress_img_empty");
  1079. pr_full.attr('width',percentage*1.2);
  1080. pr_empty.attr('width',(100-percentage)*1.2);
  1081. var mytext = '';
  1082. switch(mode){
  1083. case 'abs':
  1084. mytext = nbr_complete + '/' + nbr_total;
  1085. break;
  1086. case '%':
  1087. default:
  1088. mytext = percentage + '%';
  1089. break;
  1090. }
  1091. pr_text.html(mytext);
  1092. return true;
  1093. }
  1094. function update_stats_page()
  1095. {
  1096. var myframe = document.getElementById('content_id');
  1097. var mysrc = myframe.location.href;
  1098. if(mysrc == 'lp_controller.php?action=stats'){
  1099. if(myframe && myframe.src){
  1100. var mysrc = myframe.src;
  1101. myframe.src = mysrc;
  1102. }
  1103. // = mysrc; //refresh page
  1104. }
  1105. return true;
  1106. }
  1107. /**
  1108. * Updates the message frame with the given string
  1109. */
  1110. function update_message_frame(msg_msg)
  1111. {
  1112. if(msg_msg==null){msg_msg='';}
  1113. if(!($("#msg_div_id"))){
  1114. logit_lms('In update_message_frame() - message frame has no document property',0);
  1115. }else{
  1116. logit_lms('In update_message_frame() - updating frame',0);
  1117. $("#msg_div_id").html(msg_msg);
  1118. }
  1119. }
  1120. /**
  1121. * Function that handles the saving of an item and switching from an item to another.
  1122. * Once called, this function should be able to do the whole process of
  1123. * (1) saving the current item,
  1124. * (2) refresh all the values inside the SCORM API object,
  1125. * (3) open the new item into the content_id frame,
  1126. * (4) refresh the table of contents
  1127. * (5) refresh the progress bar (completion)
  1128. * (6) refresh the message frame
  1129. * @param integer Dokeos ID for the current item
  1130. * @param string This parameter can be a string specifying the next
  1131. * item (like 'next', 'previous', 'first' or 'last') or the id to the next item
  1132. */
  1133. function switch_item(current_item, next_item){
  1134. //backup these params
  1135. var orig_current_item = current_item;
  1136. var orig_next_item = next_item;
  1137. var orig_lesson_status = lesson_status;
  1138. //(1) save the current item
  1139. logit_lms('Called switch_item with params '+lms_item_id+' and '+next_item+'',0);
  1140. if(lms_lp_type==1 || lms_item_type=='asset' || session_time == '0' || session_time == '0:00:00'){
  1141. if (lms_lp_type==1) {
  1142. 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);
  1143. } else {
  1144. my_get_value_scorm=new Array();
  1145. my_get_value_scorm=ProcessValueScorm();
  1146. xajax_save_item_scorm(lms_lp_id, lms_user_id, lms_view_id, lms_item_id,my_get_value_scorm);
  1147. }
  1148. if(item_objectives.length>0) {
  1149. xajax_save_objectives(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,item_objectives);
  1150. }
  1151. }else{
  1152. /**
  1153. * Because of SCORM 1.2's special rule about unsent commits and the fact
  1154. * that a SCO should be SET TO 'completed' IF NO STATUS WAS SENT (and
  1155. * then some checks have to be done on score), we have to force a
  1156. * special commit here to avoid getting to the next element with a
  1157. * missing prerequisite. The 'onunload' event is treated with
  1158. * savedata_onunload(), and doesn't need to be triggered at any
  1159. * particular time, but here we are in the case of switching to another
  1160. * item, so this is particularly important to complete the element in
  1161. * time.
  1162. * However, this cannot be initiated from the JavaScript, mainly
  1163. * because another onunload event can be triggered by the SCO itself,
  1164. * which can set, for example, the status to incomplete while the
  1165. * status has already been set to "completed" by the hand-made
  1166. * savedata(unload) (and then the status cannot be "incompleted"
  1167. * anymore)
  1168. */
  1169. //if (lms_item_type=='sco' && lesson_status != 'completed' && lesson_status != 'passed' && lesson_status != 'browsed' && lesson_status != 'incomplete' && lesson_status != 'failed') {
  1170. /**
  1171. * savedata('finish') treats the special condition and saves the
  1172. * new status to the database, so switch_item_details() enjoys the
  1173. * new status
  1174. */
  1175. //savedata('finish');
  1176. //}
  1177. // 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);
  1178. }
  1179. execute_stats=false;
  1180. //(2) Refresh all the values inside this SCORM API object - use AJAX
  1181. xajax_switch_item_details(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,next_item);
  1182. status_info.push(lesson_status);
  1183. //current item
  1184. //old item
  1185. //info_lms_item[0]=next_item;
  1186. if (info_lms_item[1]==next_item && next_item!='next' && next_item!='previous') {
  1187. info_lms_item[0]=next_item;
  1188. info_lms_item[1]=next_item;
  1189. } else {
  1190. if (next_item!='next' && next_item!='previous') {
  1191. info_lms_item[0]=info_lms_item[1];
  1192. info_lms_item[1]=next_item;
  1193. }
  1194. }
  1195. if (info_lms_item[0]==next_item && next_item!='next' && next_item!='previous') {
  1196. info_lms_item[0]=next_item;
  1197. info_lms_item[1]=next_item;
  1198. } else {
  1199. if (next_item!='next' && next_item!='previous') {
  1200. info_lms_item[0]=info_lms_item[0];
  1201. info_lms_item[1]=next_item;
  1202. }
  1203. }
  1204. //(3) open the new item in the content_id frame
  1205. switch(next_item){
  1206. case 'next':
  1207. next_item = lms_next_item;
  1208. info_lms_item[0]=info_lms_item[1];
  1209. info_lms_item[1]=lms_next_item;
  1210. break;
  1211. case 'previous':
  1212. next_item = lms_previous_item;
  1213. info_lms_item[0]=info_lms_item[1];
  1214. info_lms_item[1]=lms_previous_item;
  1215. break;
  1216. default:
  1217. break;
  1218. }
  1219. var mysrc = 'lp_controller.php?action=content&lp_id='+lms_lp_id+'&item_id='+next_item;
  1220. var cont_f = $("#content_id");
  1221. <?php if($oLP->mode == 'fullscreen'){ ?>
  1222. cont_f = window.open(''+mysrc,'content_id','toolbar=0,location=0,status=0,scrollbars=1,resizable=1');
  1223. cont_f.onload=function(){
  1224. info_lms_item[0]=info_lms_item[1];
  1225. info_lms_item[1]= info_lms_item[1];
  1226. }
  1227. cont_f.onunload=function(){
  1228. info_lms_item[0]=info_lms_item[1];
  1229. info_lms_item[1]= info_lms_item[1];
  1230. }
  1231. <?php } else { ?>
  1232. cont_f.attr("src",mysrc);
  1233. <?php } ?>
  1234. if(lms_lp_type==1 || lms_item_type=='asset'){
  1235. xajax_start_timer();
  1236. }
  1237. //(4) refresh the audio player if needed
  1238. $.ajax({
  1239. type: "GET",
  1240. url: "lp_nav.php",
  1241. data: "",
  1242. success: function(tmp_data) {
  1243. $("#media").html(tmp_data);
  1244. }
  1245. });
  1246. /*
  1247. if ( lms_lp_type==2 && (orig_lesson_status == 'not attempted' || orig_lesson_status == '') && orig_current_item != orig_next_item) {
  1248. params = 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id+'&iid='+orig_current_item;
  1249. $.ajax({
  1250. type:"GET",
  1251. data: params,
  1252. url: "lp_ajax_last_update_status.php",
  1253. dataType: "script"
  1254. });
  1255. }
  1256. */
  1257. return true;
  1258. }
  1259. /**
  1260. * Save a specific item (with its interactions, if any) into the LMS through
  1261. * an AJAX call. Originally, we used the xajax library. Now we use jQuery.
  1262. * Because of the need to pass an array, we have to build the parameters
  1263. * manually into GET[]
  1264. */
  1265. function 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) {
  1266. params='';
  1267. params += 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id;
  1268. params += '&iid='+lms_item_id+'&s='+score+'&max='+max+'&min='+min;
  1269. params += '&status='+lesson_status+'&t='+session_time;
  1270. params += '&suspend='+suspend_data+'&loc='+lesson_location;
  1271. params += '&core_exit='+lms_item_core_exit;
  1272. interact_string = '';
  1273. for (i in interactions){
  1274. interact_string += '&interact['+i+']=';
  1275. interact_temp = '[';
  1276. for (j in interactions[i]) {
  1277. interact_temp += interactions[i][j]+',';
  1278. }
  1279. interact_temp = interact_temp.substr(0,(interact_temp.length-2)) + ']';
  1280. interact_string += encodeURIComponent(interact_temp);
  1281. }
  1282. //interact_string = encodeURIComponent(interact_string.substr(0,(interact_string.length-1)));
  1283. params += interact_string;
  1284. /*params = {
  1285. 'lid': lms_lp_id,
  1286. 'uid': lms_user_id,
  1287. 'vid': lms_view_id,
  1288. 'iid': lms_item_id,
  1289. 's': score,
  1290. 'max': max,
  1291. 'min': min,
  1292. 'status': lesson_status,
  1293. 't': session_time,
  1294. 'suspend': suspend_data,
  1295. 'loc': lesson_location,
  1296. 'interact': interac_string,
  1297. 'core_exit': lms_item_core_exit
  1298. }
  1299. */
  1300. if ( lms_lp_type==1) {
  1301. $.ajax({
  1302. type:"GET",
  1303. data: params,
  1304. url: "lp_ajax_save_item.php",
  1305. dataType: "script",
  1306. async: false
  1307. }
  1308. );
  1309. }
  1310. }
  1311. function xajax_save_item_scorm(lms_lp_id, lms_user_id, lms_view_id, lms_item_id,info_get_lms) {
  1312. // var variables_scorm = new Array('cmi.core.score.raw','cmi.core.score.max','cmi.core.score.min','cmi.core.lesson_location',
  1313. //'cmi.core.lesson_status','cmi.completion_status','cmi.core.session_time','cmi.score.scaled','cmi.success_status',
  1314. //'cmi.suspend_data','cmi.core.exit','interactions');
  1315. params='';
  1316. params += 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id+'&iid='+lms_item_id;
  1317. for (k=0;k<info_get_lms.length;k++) {
  1318. if (my_get_value_scorm[k]=='cmi.core.session_time') {
  1319. params += '&t='+session_time;
  1320. } else if (my_get_value_scorm[k]=='cmi.core.lesson_status' && lesson_status!='') {
  1321. params += '&status='+lesson_status;
  1322. } else if (my_get_value_scorm[k]=='cmi.core.score.raw') {
  1323. params += '&s='+score;
  1324. } else if (my_get_value_scorm[k]=='cmi.core.score.max') {
  1325. params += '&max='+max;
  1326. } else if (my_get_value_scorm[k]=='cmi.core.score.min') {
  1327. params += '&min='+min;
  1328. } else if (my_get_value_scorm[k]=='cmi.core.lesson_location') {
  1329. params += '&loc='+lesson_location;
  1330. } else if (my_get_value_scorm[k]=='cmi.completion_status') {
  1331. } else if (my_get_value_scorm[k]=='cmi.score.scaled') {
  1332. } else if (my_get_value_scorm[k]=='cmi.suspend_data') {
  1333. params += '&suspend='+suspend_data;
  1334. } else if (my_get_value_scorm[k]=='cmi.completion_status') {
  1335. } else if (my_get_value_scorm[k]=='cmi.core.exit') {
  1336. params += '&core_exit='+lms_item_core_exit;
  1337. }
  1338. if (my_get_value_scorm[k]=='interactions') {
  1339. is_interactions='true';
  1340. } else {
  1341. is_interactions='false';
  1342. }
  1343. }
  1344. if (is_interactions=='true') {
  1345. interact_string = '';
  1346. temp = '';
  1347. for (i in interactions){
  1348. interact_string += '&interact['+i+']=';
  1349. interact_temp = '[';
  1350. for (j in interactions[i]) {
  1351. temp = interactions[i][j];
  1352. temp = ''+temp; // if temp == 1 there are problems with indexOf and an integer number
  1353. //this fix when an interaction have ',' i.e: {a,b,c,d} is replace to {a@.|@b@.|@c@.|@d} see DT#4444
  1354. while(temp.indexOf(',') >= 0){
  1355. temp = temp.replace(',','@.|@');
  1356. };
  1357. interact_temp +=temp+',';
  1358. }
  1359. interact_temp = interact_temp.substr(0,(interact_temp.length-2)) + ']';
  1360. // interact_string += encodeURIComponent(interact_temp);
  1361. interact_string += interact_temp;
  1362. }
  1363. //interact_string = encodeURIComponent(interact_string.substr(0,(interact_string.length-1)));
  1364. params += interact_string;
  1365. is_interactions='false';
  1366. }
  1367. //alert("parameters : "+params);
  1368. /*params = {
  1369. 'lid': lms_lp_id,
  1370. 'uid': lms_user_id,
  1371. 'vid': lms_view_id,
  1372. 'iid': lms_item_id,
  1373. 's': score,
  1374. 'max': max,
  1375. 'min': min,
  1376. 'status': lesson_status,
  1377. 't': session_time,
  1378. 'suspend': suspend_data,
  1379. 'loc': lesson_location,
  1380. 'interact': interac_string,
  1381. 'core_exit': lms_item_core_exit
  1382. }*/
  1383. $.ajax({
  1384. type:"GET",
  1385. data: params,
  1386. url: "lp_ajax_save_item.php",
  1387. dataType: "script",
  1388. async: false
  1389. }
  1390. );
  1391. params='';
  1392. }
  1393. /**
  1394. * Starts the timer with the server clock time.
  1395. * Originally, we used the xajax library. Now we use jQuery
  1396. */
  1397. function xajax_start_timer() {
  1398. $.ajax({
  1399. type: "GET",
  1400. url: "lp_ajax_start_timer.php",
  1401. dataType: "script",
  1402. async: false
  1403. });
  1404. }
  1405. /**
  1406. * Save a specific item's objectives into the LMS through
  1407. * an AJAX call. Originally, we used the xajax library. Now we use jQuery
  1408. */
  1409. function xajax_save_objectives(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,item_objectives) {
  1410. params='';
  1411. params += 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id;
  1412. params += '&iid='+lms_item_id;
  1413. obj_string = '';
  1414. for (i in item_objectives){
  1415. obj_string += '&objectives['+i+']=';
  1416. obj_temp = '[';
  1417. for (j in item_objectives[i]) {
  1418. obj_temp += item_objectives[i][j]+',';
  1419. }
  1420. obj_temp = obj_temp.substr(0,(obj_temp.length-2)) + ']';
  1421. obj_string += encodeURIComponent(obj_temp);
  1422. }
  1423. params += obj_string;
  1424. $.ajax({
  1425. type: "GET",
  1426. data: params,
  1427. url: "lp_ajax_save_objectives.php",
  1428. dataType: "script",
  1429. async: false
  1430. });
  1431. }
  1432. /**
  1433. * Switch between two items through
  1434. * an AJAX call. Originally, we used the xajax library. Now we use jQuery
  1435. */
  1436. function xajax_switch_item_details(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,next_item) {
  1437. params = {
  1438. 'lid': lms_lp_id,
  1439. 'uid': lms_user_id,
  1440. 'vid': lms_view_id,
  1441. 'iid': lms_item_id,
  1442. 'next': next_item
  1443. }
  1444. $.ajax({
  1445. type: "GET",
  1446. data: params,
  1447. url: "lp_ajax_switch_item.php",
  1448. dataType: "script",
  1449. async: false
  1450. });
  1451. }
  1452. addEvent(window,'load',addListeners,false);
  1453. if(lms_lp_type==1 || lms_item_type=='asset'){
  1454. xajax_start_timer();
  1455. }