scorm_api.php 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * API event handler functions for Scorm 1.1 and 1.2 and 1.3
  5. *
  6. * @author Denes Nagy <darkden@freemail.hu>
  7. * @author Yannick Warnier <ywarnier@beeznest.org>
  8. * @version v 1.0
  9. * @access public
  10. * @package chamilo.learnpath.scorm
  11. */
  12. /**
  13. * This script is divided into three sections.
  14. * The first section (below) is the initialisation part.
  15. * The second section is the SCORM object part
  16. * The third section defines the event handlers for Chamilo's internal messaging
  17. * and frames refresh
  18. */
  19. /* INIT SECTION */
  20. // If you open the imsmanifest.xml via local machine (f.ex.: file://c:/...), then the Apiwrapper.js
  21. // of Maritime Navigation when trying to execute this row
  22. // var result = api.LMSInitialize("");
  23. // get the error response : you are not authorized to call this function
  24. // Flag to allow for anonymous user - needs to be set before global.inc.php.
  25. $use_anonymous = true;
  26. require_once 'back_compat.inc.php';
  27. require_once 'learnpath.class.php';
  28. require_once 'learnpathItem.class.php';
  29. require_once 'scorm.class.php';
  30. $file = (empty($_SESSION['file'])?'':$_SESSION['file']);
  31. $oLP = unserialize($_SESSION['lpobject']);
  32. $oItem = $oLP->items[$oLP->current];
  33. if (!is_object($oItem)) {
  34. error_log('New LP - scorm_api - Could not load oItem item',0);
  35. exit;
  36. }
  37. $autocomplete_when_80pct = 0;
  38. $user = api_get_user_info();
  39. header('Content-type: text/javascript');
  40. /*
  41. * JavaScript Functions
  42. */
  43. ?>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
  44. var lms_logs=0; //debug log level for LMS actions. 0=none, 1=light, 2=a lot, 3=all
  45. //logit_lms('scormfunctions.php included',0);
  46. // API Object initialization (eases access later on)
  47. function APIobject() {
  48. this.LMSInitialize=LMSInitialize; //for Scorm 1.2
  49. this.Initialize=LMSInitialize; //for Scorm 1.3
  50. this.LMSGetValue=LMSGetValue;
  51. this.GetValue=LMSGetValue;
  52. this.LMSSetValue=LMSSetValue;
  53. this.SetValue=LMSSetValue;
  54. this.LMSCommit=LMSCommit;
  55. this.Commit=LMSCommit;
  56. this.LMSFinish=LMSFinish;
  57. this.Finish=LMSFinish;
  58. this.LMSGetLastError=LMSGetLastError;
  59. this.GetLastError=LMSGetLastError;
  60. this.LMSGetErrorString=LMSGetErrorString;
  61. this.GetErrorString=LMSGetErrorString;
  62. this.LMSGetDiagnostic=LMSGetDiagnostic;
  63. this.GetDiagnostic=LMSGetDiagnostic;
  64. this.Terminate=Terminate; //only in Scorm 1.3
  65. this.save_asset = lms_save_asset;
  66. this.void_save_asset = chamilo_void_save_asset;
  67. }
  68. // it is not sure that the scos use the above declarations. The following
  69. // multiple declarations are to make sure we have an API object for each type of
  70. // SCORM
  71. var API = new APIobject(); //for scorm 1.2
  72. var api = API;
  73. var API_1484_11 = new APIobject(); //for scorm 1.3
  74. var api_1484_11 = API_1484_11;
  75. // SCORM-specific Error codes
  76. var G_NoError = 0;
  77. var G_GeneralException = 101;
  78. var G_ServerBusy = 102; // this is not in the Scorm1.2_Runtime document
  79. var G_InvalidArgumentError = 201;
  80. var G_ElementCannotHaveChildren = 202;
  81. var G_ElementIsNotAnArray = 203;
  82. var G_NotInitialized = 301;
  83. var G_NotImplementedError = 401;
  84. var G_InvalidSetValue = 402;
  85. var G_ElementIsReadOnly = 403;
  86. var G_ElementIsWriteOnly = 404;
  87. var G_IncorrectDataType = 405;
  88. // SCORM-specific Error messages
  89. var G_NoErrorMessage = '';
  90. var G_GeneralExceptionMessage = 'General Exception';
  91. var G_ServerBusyMessage = 'Server busy'; // this is not in the Scorm1.2_Runtime document
  92. var G_InvalidArgumentErrorMessage = 'Invalid argument error';
  93. var G_ElementCannotHaveChildrenMessage = 'Element cannot have children';
  94. var G_ElementIsNotAnArrayMessage = 'Element not an array. Cannot have count';
  95. var G_NotInitializedMessage = 'Not initialized';
  96. var G_NotImplementedErrorMessage = 'Not implemented error';
  97. var G_InvalidSetValueMessage = 'Invalid set value, element is a keyword';
  98. var G_ElementIsReadOnlyMessage = 'Element is read only';
  99. var G_ElementIsWriteOnlyMessage = 'Element is write only';
  100. var G_IncorrectDataTypeMessage = 'Incorrect Data Type';
  101. var olms = new Object();
  102. //the last recorded error message was:
  103. olms.G_LastError = G_NoError ;
  104. olms.G_LastErrorMessage = 'No error';
  105. //this is not necessary and is only provided to make bad Articulate contents shut up (and not trigger useless JS messages)
  106. olms.G_LastErrorString = 'No error';
  107. //these variables are provided for better control of the current status in the
  108. // SCORM exchange
  109. olms.commit = false;
  110. // informative array helping to select variables to save, later on
  111. olms.scorm_variables = new Array(
  112. 'cmi.core.score.raw',
  113. 'cmi.core.score.max',
  114. 'cmi.core.score.min',
  115. 'cmi.core.lesson_location',
  116. 'cmi.core.lesson_status',
  117. 'cmi.completion_status',
  118. 'cmi.core.session_time',
  119. 'cmi.score.scaled',
  120. 'cmi.success_status',
  121. 'cmi.suspend_data',
  122. 'cmi.core.exit',
  123. 'interactions'
  124. );
  125. // manage variables to save or not
  126. olms.variable_to_send=new Array();
  127. // temporary list of variables (gets set to true when set through LMSSetValue)
  128. olms.updatable_vars_list=new Array();
  129. // Strictly scorm variables
  130. olms.score=<?php echo $oItem->get_score();?>;
  131. olms.max='<?php echo $oItem->get_max();?>';
  132. olms.min='<?php echo $oItem->get_min();?>';
  133. olms.lesson_status='<?php echo $oItem->get_status();?>';
  134. olms.session_time='<?php echo $oItem->get_scorm_time('js');?>';
  135. olms.suspend_data = '<?php echo $oItem->get_suspend_data();?>';
  136. olms.lesson_location = '<?php echo $oItem->get_lesson_location();?>';
  137. olms.total_time = '<?php echo $oItem->get_scorm_time('js');?>';
  138. olms.mastery_score = '<?php echo $oItem->get_mastery_score();?>';
  139. olms.launch_data = '<?php echo $oItem->get_launch_data();?>';
  140. olms.max_time_allowed = '<?php echo $oItem->get_max_time_allowed();?>';
  141. olms.interactions = new Array(<?php echo $oItem->get_interactions_js_array();?>);
  142. olms.item_objectives = new Array();
  143. olms.info_lms_item=new Array();
  144. // Chamilo internal variables (not SCORM)
  145. // olms.saved_lesson_status = 'not attempted';
  146. olms.lms_lp_id = <?php echo $oLP->get_id();?>;
  147. olms.lms_item_id = <?php echo $oItem->get_id();?>;
  148. olms.lms_initialized = 0;
  149. //olms.lms_total_lessons = <?php echo $oLP->get_total_items_count(); ?>;
  150. //olms.lms_complete_lessons = <?php echo $oLP->get_complete_items_count();?>;
  151. //olms.lms_progress_bar_mode = '<?php echo $oLP->progress_bar_mode;?>';
  152. //if(lms_progress_bar_mode == ''){lms_progress_bar_mode='%';}
  153. olms.lms_view_id = '<?php echo $oLP->get_view();?>';
  154. if(olms.lms_view_id == ''){ olms.lms_view_id = 1;}
  155. olms.lms_user_id = '<?php echo $_user['user_id'];?>';
  156. olms.lms_next_item = '<?php echo $oLP->get_next_item_id();?>';
  157. olms.lms_previous_item = '<?php echo $oLP->get_previous_item_id();?>';
  158. olms.lms_lp_type = '<?php echo $oLP->get_type();?>';
  159. olms.lms_item_type = '<?php echo $oItem->get_type();?>';
  160. olms.lms_item_credit = '<?php echo $oItem->get_credit();?>';
  161. olms.lms_item_lesson_mode = '<?php echo $oItem->get_lesson_mode();?>';
  162. olms.lms_item_launch_data = '<?php echo $oItem->get_launch_data();?>';
  163. olms.lms_item_core_exit = '<?php echo $oItem->get_core_exit();?>';
  164. <?php echo $oLP->get_items_details_as_js('olms.lms_item_types');?>
  165. olms.asset_timer = 0;
  166. olms.userfname = '<?php echo str_replace("'","\\'",$user['firstname']); ?>';
  167. olms.userlname = '<?php echo str_replace("'","\\'",$user['lastname']); ?>';
  168. //Backup for old values
  169. //var olms.old_score = 0;
  170. //var old_max = 0;
  171. //var old_min = 0;
  172. //var old_lesson_status = '';
  173. //var old_session_time = '';
  174. //var old_suspend_data = '';
  175. //var olms.lms_old_item_id = 0;
  176. olms.execute_stats = false;
  177. // Initialize stuff when the page is loaded
  178. $(document).ready( function() {
  179. olms.info_lms_item[0]='<?php echo $oItem->get_id();?>';
  180. olms.info_lms_item[1]='<?php echo $oItem->get_id();?>';
  181. $("#content_id").load( function() {
  182. // Add a right margin see BT#1607
  183. /*if (frames['content_name']) {
  184. // See the task #2558: try-catch block has been added for suppressing "Access denied" error that may occur on IE.
  185. try {
  186. frames['content_name'].document.body.style.margin="0 12px 0px 5px";
  187. } catch (ex) { }
  188. }*/
  189. olms.info_lms_item[0]=olms.info_lms_item[1];
  190. if (olms.lms_item_types['i'+olms.info_lms_item[1]] != 'sco') {
  191. LMSInitialize();
  192. }
  193. });
  194. });
  195. /**
  196. * The following section represents a set of mandatory functions for SCORM
  197. */
  198. /**
  199. * Function called mandatorily by the SCORM content to start the SCORM comm
  200. * This is the initialize function of all APIobjects
  201. * @return string 'true' or 'false'. Returning a string is mandatory (SCORM).
  202. */
  203. function LMSInitialize() {
  204. /* load info for this new item by calling the js_api_refresh command in
  205. * the message frame. The message frame will update the JS variables by
  206. * itself, in JS, by doing things like top.lesson_status = 'not attempted'
  207. * and that kind of stuff, so when the content loads in the content frame
  208. * it will have all the correct variables set
  209. */
  210. olms.G_LastError = G_NoError ;
  211. olms.G_LastErrorMessage = 'No error';
  212. olms.lms_initialized=0;
  213. // if there are more parameters than ""
  214. if (arguments.length>1) {
  215. olms.G_LastError = G_InvalidArgumentError;
  216. olms.G_LastErrorMessage = G_InvalidArgumentErrorMessage;
  217. logit_scorm('Error '+ G_InvalidArgumentError + G_InvalidArgumentErrorMessage, 0);
  218. return('false');
  219. } else {
  220. //reinit the list of modified variables
  221. reinit_updatable_vars_list();
  222. // Get LMS values for this item
  223. params = {
  224. 'lid': olms.lms_lp_id,
  225. 'uid': olms.lms_user_id,
  226. 'vid': olms.lms_view_id,
  227. 'iid': olms.lms_item_id
  228. };
  229. $.ajax({
  230. type: "POST",
  231. url: "lp_ajax_initialize.php",
  232. data: params,
  233. dataType: 'script',
  234. async: false
  235. });
  236. // log a more complete object dump when initializing, so we know what data hasn't been cleaned
  237. var log = '<br />item : '+ olms.lms_item_id
  238. + '<br />item_type : '+ olms.lms_item_type
  239. + '<br />score : '+ olms.score
  240. + '<br />max : '+ olms.max
  241. + '<br />min : '+ olms.min
  242. + '<br />lesson_status : '+ olms.lesson_status
  243. + '<br />session_time : '+ olms.session_time
  244. + '<br />lesson_location : '+ olms.lesson_location
  245. + '<br />suspend_data : '+ olms.suspend_data
  246. + '<br />total_time : '+ olms.total_time
  247. + '<br />mastery_score : '+ olms.mastery_score
  248. + '<br />max_time_allowed: '+ olms.max_time_allowed
  249. + '<br />lms_lp_id : '+olms.lms_lp_id
  250. + '<br />lms_user_id: '+olms.lms_user_id
  251. + '<br />lms_view_id: '+olms.lms_view_id
  252. ;
  253. logit_scorm('LMSInitialize()'+log,0);
  254. olms.lms_initialized=1;
  255. <?php if (api_get_setting('show_glossary_in_documents') == 'ismanual') { ?>
  256. if (olms.lms_item_type == 'sco') {
  257. attach_glossary_into_scorm('automatic');
  258. } else {
  259. attach_glossary_into_scorm('manual');
  260. }
  261. <?php } elseif (api_get_setting('show_glossary_in_documents') == 'isautomatic') { ?>
  262. attach_glossary_into_scorm('automatic');
  263. <?php } ?>
  264. return('true');
  265. }
  266. }
  267. /**
  268. * Twin sister of LMSInitialize(). Only provided for backwards compatibility.
  269. * this is the initialize function of all APIobjects
  270. */
  271. function Initialize() {
  272. return LMSInitialize();
  273. }
  274. /**
  275. * Gets a value in the current SCORM context and returns it to the calling SCO
  276. * @param string The name of the value we want
  277. * @return string All return values must be string (see SCORM)
  278. */
  279. function LMSGetValue(param)
  280. {
  281. //logit_scorm("LMSGetValue('"+param+"')",1);
  282. olms.G_LastError = G_NoError ;
  283. olms.G_LastErrorMessage = 'No error';
  284. var result='';
  285. // the LMSInitialize is missing
  286. if (olms.lms_initialized == 0) {
  287. olms.G_LastError = G_NotInitialized;
  288. olms.G_LastErrorMessage = G_NotInitializedMessage;
  289. logit_scorm('LMSGetValue('+param+'):<br />=> Error '+ G_NotInitialized + ' ' +G_NotInitializedMessage, 0);
  290. return '';
  291. }
  292. //Chamilo does not support these SCO object properties
  293. if (param == 'cmi.student_preference.text' ||
  294. param == 'cmi.student_preference.language' ||
  295. param == 'cmi.student_preference.speed' ||
  296. param == 'cmi.student_preference.audio' ||
  297. param == 'cmi.student_preference._children' ||
  298. param == 'cmi.student_data.time_limit_action' ||
  299. param == 'cmi.comments' ||
  300. param == 'cmi.comments_from_lms' ||
  301. /* The following properties were part of SCORM 1.0 or never implemented at all
  302. but seem to react badly to Captivate content producer when not defined */
  303. param == 'cmi.student_demographics._children' ||
  304. param == 'cmi.student_demographics.city' ||
  305. param == 'cmi.student_demographics.class' ||
  306. param == 'cmi.student_demographics.company' ||
  307. param == 'cmi.student_demographics.country' ||
  308. param == 'cmi.student_demographics.experience' ||
  309. param == 'cmi.student_demographics.familiar_name' ||
  310. param == 'cmi.student_demographics.instructor_name' ||
  311. param == 'cmi.student_demographics.title' ||
  312. param == 'cmi.student_demographics.native_language' ||
  313. param == 'cmi.student_demographics.state' ||
  314. param == 'cmi.student_demographics.street_address' ||
  315. param == 'cmi.student_demographics.telephone' ||
  316. param == 'cmi.student_demographics.years_experience' ) {
  317. // the value is not supported
  318. olms.G_LastError = G_NotImplementedError ;
  319. olms.G_LastErrorString = G_NotImplementedErrorMessage;
  320. logit_scorm("LMSGetValue ('"+param+"') Error '"+G_NotImplementedErrorMessage+"'",1);
  321. result = '';
  322. return result;
  323. }
  324. if(param=='cmi.student_demographics.first_name') {
  325. result=olms.userfname;
  326. }else if(param=='cmi.student_demographics.last_name') {
  327. result=olms.userlname;
  328. // ---- cmi.core._children
  329. }else if(param=='cmi.core._children' || param=='cmi.core_children'){
  330. result='entry, exit, lesson_status, student_id, student_name, lesson_location, total_time, credit, lesson_mode, score, session_time';
  331. }else if(param == 'cmi.core.entry'){
  332. // ---- cmi.core.entry
  333. if(olms.lms_item_core_exit=='none') {
  334. result='ab-initio';
  335. } else if(olms.lms_item_core_exit=='suspend') {
  336. result='resume';
  337. } else {
  338. result='';
  339. }
  340. }else if(param == 'cmi.core.exit'){
  341. // ---- cmi.core.exit
  342. result='';
  343. olms.G_LastError = G_ElementIsWriteOnly;
  344. }else if(param == 'cmi.core.session_time'){
  345. result='';
  346. olms.G_LastError = G_ElementIsWriteOnly;
  347. }else if(param == 'cmi.core.lesson_status'){
  348. // ---- cmi.core.lesson_status
  349. if(olms.lesson_status != '') {
  350. result=olms.lesson_status;
  351. } else {
  352. //result='not attempted';
  353. }
  354. }else if(param == 'cmi.core.student_id'){
  355. // ---- cmi.core.student_id
  356. result='<?php echo $_user['user_id']; ?>';
  357. }else if(param == 'cmi.core.student_name'){
  358. // ---- cmi.core.student_name
  359. <?php
  360. $who=addslashes(api_get_person_name($_user['firstName'], $_user['lastName']));
  361. echo "result='$who';";
  362. ?>
  363. }else if(param == 'cmi.core.lesson_location'){
  364. // ---- cmi.core.lesson_location
  365. result=olms.lesson_location;
  366. }else if(param == 'cmi.core.total_time'){
  367. // ---- cmi.core.total_time
  368. result=olms.total_time;
  369. }else if(param == 'cmi.core.score._children'){
  370. // ---- cmi.core.score._children
  371. result='raw,min,max';
  372. }else if(param == 'cmi.core.score.raw'){
  373. // ---- cmi.core.score.raw
  374. result=olms.score;
  375. }else if(param == 'cmi.core.score.max'){
  376. // ---- cmi.core.score.max
  377. result=olms.max;
  378. }else if(param == 'cmi.core.score.min'){
  379. // ---- cmi.core.score.min
  380. result=olms.min;
  381. }else if(param == 'cmi.core.score'){
  382. // ---- cmi.core.score -- non-standard item, provided as cmi.core.score.raw just in case
  383. result=olms.score;
  384. }else if(param == 'cmi.core.credit'){
  385. // ---- cmi.core.credit
  386. result = olms.lms_item_credit;
  387. }else if(param == 'cmi.core.lesson_mode'){
  388. // ---- cmi.core.lesson_mode
  389. result = olms.lms_item_lesson_mode;
  390. }else if(param == 'cmi.suspend_data'){
  391. // ---- cmi.suspend_data
  392. result = olms.suspend_data;
  393. }else if(param == 'cmi.launch_data'){
  394. // ---- cmi.launch_data
  395. result = olms.lms_item_launch_data;
  396. }else if(param == 'cmi.objectives._children'){
  397. // ---- cmi.objectives._children
  398. result = 'id,score,status';
  399. }else if(param == 'cmi.objectives._count'){
  400. // ---- cmi.objectives._count
  401. //result='<?php echo $oItem->get_view_count();?>';
  402. result = olms.item_objectives.length;
  403. }else if(param.substring(0,15)== 'cmi.objectives.'){
  404. var myres = '';
  405. if(myres = param.match(/cmi.objectives.(\d+).(id|score|status|_children)(.*)/))
  406. {
  407. var obj_id = myres[1];
  408. var req_type = myres[2];
  409. if(olms.item_objectives[obj_id]==null)
  410. {
  411. if(req_type == 'id')
  412. {
  413. result = '';
  414. }else if(req_type == '_children'){
  415. result = 'id,score,status';
  416. }else if(req_type == 'score'){
  417. if(myres[3]==null)
  418. {
  419. result = '';
  420. olms.G_LastError = G_NotImplementedError;
  421. olms.G_LastErrorString = 'Not implemented yet';
  422. }else if (myres[3] == '._children'){
  423. result = 'raw,min,max'; //non-standard, added for NetG
  424. }else if (myres[3] == '.raw'){
  425. result = '';
  426. }else if (myres[3] == '.max'){
  427. result = '';
  428. }else if (myres[3] == '.min'){
  429. result = '';
  430. }else{
  431. result = '';
  432. olms.G_LastError = G_NotImplementedError;
  433. olms.G_LastErrorString = 'Not implemented yet';
  434. }
  435. }else if(req_type == 'status'){
  436. result = 'not attempted';
  437. }
  438. } else {
  439. //the object is not null
  440. if(req_type == 'id')
  441. {
  442. result = olms.item_objectives[obj_id][0];
  443. }else if(req_type == '_children'){
  444. result = 'id,score,status';
  445. }else if(req_type == 'score'){
  446. if(myres[3]==null)
  447. {
  448. result = '';
  449. olms.G_LastError = G_NotImplementedError;
  450. olms.G_LastErrorString = 'Not implemented yet';
  451. }else if (myres[3] == '._children'){
  452. result = 'raw,min,max'; //non-standard, added for NetG
  453. }else if (myres[3] == '.raw'){
  454. if(olms.item_objectives[obj_id][2] != null)
  455. {
  456. result = olms.item_objectives[obj_id][2];
  457. }else{
  458. result = '';
  459. }
  460. }else if (myres[3] == '.max'){
  461. if(olms.item_objectives[obj_id][3] != null)
  462. {
  463. result = olms.item_objectives[obj_id][3];
  464. }else{
  465. result = '';
  466. }
  467. }else if (myres[3] == '.min'){
  468. if(olms.item_objectives[obj_id][4] != null)
  469. {
  470. result = olms.item_objectives[obj_id][4];
  471. }else{
  472. result = '';
  473. }
  474. }else{
  475. result = '';
  476. olms.G_LastError = G_NotImplementedError;
  477. olms.G_LastErrorString = 'Not implemented yet';
  478. }
  479. }else if(req_type == 'status'){
  480. if(olms.item_objectives[obj_id][1] != null)
  481. {
  482. result = olms.item_objectives[obj_id][1];
  483. }else{
  484. result = 'not attempted';
  485. }
  486. }
  487. }
  488. }
  489. }else if(param == 'cmi.student_data._children'){
  490. // ---- cmi.student_data._children
  491. result = 'mastery_score,max_time_allowed';
  492. }else if(param == 'cmi.student_data.mastery_score'){
  493. // ---- cmi.student_data.mastery_score
  494. result = olms.mastery_score;
  495. }else if(param == 'cmi.student_data.max_time_allowed'){
  496. // ---- cmi.student_data.max_time_allowed
  497. result = olms.max_time_allowed;
  498. }else if(param == 'cmi.interactions._count'){
  499. // ---- cmi.interactions._count
  500. result = olms.interactions.length;
  501. }else if(param == 'cmi.interactions._children'){
  502. // ---- cmi.interactions._children
  503. result = 'id,time,type,correct_responses,weighting,student_response,result,latency';
  504. }else{
  505. // ---- anything else
  506. // Invalid argument error
  507. olms.G_LastError = G_InvalidArgumentError ;
  508. olms.G_LastErrorString = G_InvalidArgumentErrorMessage;
  509. logit_scorm("LMSGetValue ('"+param+"') Error '"+G_InvalidArgumentErrorMessage+"'",1);
  510. result = '';
  511. return result;
  512. }
  513. logit_scorm("LMSGetValue\n\t('"+param+"') returned '"+result+"'",1);
  514. return result;
  515. }
  516. /**
  517. * Twin sister of LMSGetValue(). Only provided for backwards compatibility.
  518. */
  519. function GetValue(param) {
  520. return LMSGetValue(param);
  521. }
  522. /**
  523. * Sets a SCORM variable's value through a call from the SCO.
  524. * @param string The SCORM variable's name
  525. * @param string The SCORM variable's new value
  526. * @param string 'true','false' or an error code
  527. */
  528. function LMSSetValue(param, val) {
  529. logit_scorm("LMSSetValue\n\t('"+param+"','"+val+"')",0);
  530. olms.commit = true; //value has changed, need to re-commit
  531. olms.G_LastError = G_NoError ;
  532. olms.G_LastErrorMessage = 'No error';
  533. return_value = 'false';
  534. if( param == "cmi.core.score.raw" ) {
  535. olms.score= val;
  536. olms.updatable_vars_list['cmi.core.score.raw']=true;
  537. return_value='true';
  538. } else if ( param == "cmi.core.score.max" ) {
  539. olms.max = val;
  540. olms.updatable_vars_list['cmi.core.score.max']=true;
  541. return_value='true';
  542. } else if ( param == "cmi.core.score.min" ) {
  543. olms.min = val;
  544. olms.updatable_vars_list['cmi.core.score.min']=true;
  545. return_value='true';
  546. } else if ( param == "cmi.core.lesson_location" ) {
  547. olms.lesson_location = val;
  548. olms.updatable_vars_list['cmi.core.lesson_location']=true;
  549. return_value='true';
  550. } else if ( param == "cmi.core.lesson_status" ) {
  551. olms.lesson_status = val;
  552. olms.updatable_vars_list['cmi.core.lesson_status']=true;
  553. return_value='true';
  554. } else if ( param == "cmi.completion_status" ) {
  555. olms.lesson_status = val;
  556. olms.updatable_vars_list['cmi.completion_status']=true;
  557. return_value='true'; //1.3
  558. } else if ( param == "cmi.core.session_time" ) {
  559. olms.session_time = val;
  560. olms.updatable_vars_list['cmi.core.session_time']=true;
  561. return_value='true';
  562. } else if ( param == "cmi.score.scaled") { //1.3
  563. if(val<=1 && val>=-1) {
  564. olms.score = val ;
  565. olms.updatable_vars_list['cmi.score.scaled']=true;
  566. return_value='true';
  567. } else {
  568. return_value='false';
  569. }
  570. } else if ( param == "cmi.success_status" ) {
  571. success_status = val;
  572. olms.updatable_vars_list['cmi.success_status']=true;
  573. return_value='true'; //1.3
  574. } else if ( param == "cmi.suspend_data" ) {
  575. olms.suspend_data = val;
  576. olms.updatable_vars_list['cmi.suspend_data']=true;
  577. return_value='true';
  578. } else if ( param == "cmi.core.exit" ) {
  579. olms.lms_item_core_exit = val;
  580. olms.updatable_vars_list['cmi.core.exit']=true;
  581. return_value='true';
  582. } else if ( param == "cmi.core.student_id" ) {
  583. olms.G_LastError = G_ElementIsReadOnly;
  584. } else if ( param == "cmi.core.student_name" ) {
  585. olms.G_LastError = G_ElementIsReadOnly;
  586. } else if ( param == "cmi.core.credit" ) {
  587. olms.G_LastError = G_ElementIsReadOnly;
  588. } else if ( param == "cmi.core.entry" ) {
  589. olms.G_LastError = G_ElementIsReadOnly;
  590. } else if ( param == "cmi.core.total_time" ) {
  591. olms.G_LastError = G_ElementIsReadOnly;
  592. } else if ( param == "cmi.core.lesson_mode" ) {
  593. olms.G_LastError = G_ElementIsReadOnly;
  594. } else if ( param == "cmi.comments_from_lms" ) {
  595. olms.G_LastError = G_ElementIsReadOnly;
  596. } else if ( param == "cmi.student_data.time_limit_action" ) {
  597. olms.G_LastError = G_ElementIsReadOnly;
  598. } else if ( param == "cmi.student_data.mastery_score" ) {
  599. olms.G_LastError = G_ElementIsReadOnly;
  600. } else if ( param == "cmi.student_data.max_time_allowed" ) {
  601. olms.G_LastError = G_ElementIsReadOnly;
  602. } else if ( param == "cmi.student_preference._children" ) {
  603. olms.G_LastError = G_ElementIsReadOnly;
  604. } else if ( param == "cmi.launch_data" ) {
  605. olms.G_LastError = G_ElementIsReadOnly;
  606. } else {
  607. var myres = new Array();
  608. if(myres = param.match(/cmi.interactions.(\d+).(id|time|type|correct_responses|weighting|student_response|result|latency)(.*)/)) {
  609. olms.updatable_vars_list['interactions']=true;
  610. elem_id = myres[1];
  611. if(elem_id > olms.interactions.length) //interactions setting should start at 0
  612. {
  613. /*
  614. olms.G_LastError = G_InvalidArgumentError;
  615. olms.G_LastErrorString = 'Invalid argument (interactions)';
  616. return_value = false;
  617. */
  618. olms.interactions[0] = ['0','','','','','','',''];
  619. }
  620. if(olms.interactions[elem_id] == null){
  621. olms.interactions[elem_id] = ['','','','','','','',''];
  622. //id(0), type(1), time(2), weighting(3),correct_responses(4),student_response(5),result(6),latency(7)
  623. olms.interactions[elem_id][4] = new Array();
  624. }
  625. elem_attrib = myres[2];
  626. switch(elem_attrib) {
  627. case "id":
  628. olms.interactions[elem_id][0] = val;
  629. logit_scorm("Interaction "+elem_id+"'s id updated",2);
  630. return_value='true';
  631. break;
  632. case "time":
  633. olms.interactions[elem_id][2] = val;
  634. logit_scorm("Interaction "+elem_id+"'s time updated",2);
  635. return_value='true';
  636. break;
  637. case "type":
  638. olms.interactions[elem_id][1] = val;
  639. logit_scorm("Interaction "+elem_id+"'s type updated",2);
  640. return_value='true';
  641. break;
  642. case "correct_responses":
  643. //do nothing yet
  644. olms.interactions[elem_id][4].push(val);
  645. logit_scorm("Interaction "+elem_id+"'s correct_responses not updated",2);
  646. return_value='true';
  647. break;
  648. case "weighting":
  649. olms.interactions[elem_id][3] = val;
  650. logit_scorm("Interaction "+elem_id+"'s weighting updated",2);
  651. return_value='true';
  652. break;
  653. case "student_response":
  654. olms.interactions[elem_id][5] = ''+val;
  655. logit_scorm("Interaction "+elem_id+"'s student_response updated",2);
  656. return_value='true';
  657. break;
  658. case "result":
  659. olms.interactions[elem_id][6] = val;
  660. logit_scorm("Interaction "+elem_id+"'s result updated",2);
  661. return_value='true';
  662. break;
  663. case "latency":
  664. olms.interactions[elem_id][7] = val;
  665. logit_scorm("Interaction "+elem_id+"'s latency updated",2);
  666. return_value='true';
  667. break;
  668. default:
  669. olms.G_LastError = G_NotImplementedError;
  670. olms.G_LastErrorString = 'Not implemented yet';
  671. }
  672. }else if(param.substring(0,15)== 'cmi.objectives.'){
  673. var myres = '';
  674. olms.updatable_vars_list['objectives']=true;
  675. if(myres = param.match(/cmi.objectives.(\d+).(id|score|status)(.*)/))
  676. {
  677. obj_id = myres[1];
  678. if(obj_id > olms.item_objectives.length) //objectives setting should start at 0
  679. {
  680. olms.G_LastError = G_InvalidArgumentError;
  681. olms.G_LastErrorString = 'Invalid argument (objectives)';
  682. return_value = false;
  683. }
  684. else
  685. {
  686. req_type = myres[2];
  687. if(obj_id == null || obj_id == '')
  688. {
  689. ;//do nothing
  690. }
  691. else
  692. {
  693. if(olms.item_objectives[obj_id]==null)
  694. {
  695. olms.item_objectives[obj_id] = ['','','','',''];
  696. }
  697. if( req_type == "id" ) {
  698. //olms.item_objectives[obj_id][0] = val.substring(51,57);
  699. olms.item_objectives[obj_id][0] = val;
  700. logit_scorm("Objective "+obj_id+"'s id updated",2);
  701. return_value = 'true';
  702. } else if ( req_type == "score" ) {
  703. if (myres[3] == '._children'){
  704. return_value = '';
  705. olms.G_LastError = G_InvalidSetValue;
  706. olms.G_LastErrorString = 'Invalid set value, element is a keyword';
  707. }else if (myres[3] == '.raw'){
  708. olms.item_objectives[obj_id][2] = val;
  709. logit_scorm("Objective "+obj_id+"'s score raw updated",2);
  710. return_value = 'true';
  711. }else if (myres[3] == '.max'){
  712. olms.item_objectives[obj_id][3] = val;
  713. logit_scorm("Objective "+obj_id+"'s score max updated",2);
  714. return_value = 'true';
  715. }else if (myres[3] == '.min'){
  716. olms.item_objectives[obj_id][4] = val;
  717. logit_scorm("Objective "+obj_id+"'s score min updated",2);
  718. return_value = 'true';
  719. }else{
  720. return_value = '';
  721. olms.G_LastError = G_NotImplementedError;
  722. olms.G_LastErrorString = 'Not implemented yet';
  723. }
  724. } else if ( req_type == "status" ) {
  725. olms.item_objectives[obj_id][1] = val;
  726. logit_scorm("Objective "+obj_id+"'s status updated",2);
  727. return_value = 'true';
  728. } else {
  729. olms.G_LastError = G_NotImplementedError;
  730. olms.G_LastErrorString = 'Not implemented yet';
  731. }
  732. }
  733. }
  734. }
  735. } else {
  736. olms.G_LastError = G_NotImplementedError;
  737. olms.G_LastErrorString = G_NotImplementedErrorMessage;
  738. }
  739. }
  740. <?php
  741. if ($oLP->force_commit == 1){
  742. echo " var mycommit = LMSCommit('force');";
  743. }
  744. ?>
  745. return(return_value);
  746. }
  747. /**
  748. * Twin sister of LMSSetValue(). Only provided for backwards compatibility.
  749. */
  750. function SetValue(param, val) {
  751. return LMSSetValue(param, val);
  752. }
  753. /**
  754. * Saves the current data from JS memory to the LMS database
  755. * @param string The origin of the call to save the data ('commit','finish', 'unload' or 'terminate')
  756. * @note origin actually seems deprecated now
  757. */
  758. function savedata(origin) {
  759. //origin can be 'commit', 'finish' or 'terminate' (depending on the calling function)
  760. /* console.log('savedata');
  761. console.log(olms.lesson_status);
  762. console.log(olms.mastery_score);
  763. console.log(olms.score);
  764. */
  765. if (olms.lesson_status != '') {
  766. olms.updatable_vars_list['cmi.core.lesson_status']=true;
  767. }
  768. //If lesson_status is empty we left the status like that
  769. if (olms.lesson_status != '' && olms.lesson_status != 'completed' && olms.lesson_status != 'passed' && olms.mastery_score >=0 && olms.score >= olms.mastery_score) {
  770. //olms.lesson_status = 'passed';
  771. //olms.updatable_vars_list['cmi.core.lesson_status']=true;
  772. } else if( (olms.mastery_score < 0) && (olms.lms_lp_type != '2') && ( olms.lesson_status == 'incomplete') && (olms.score >= (0.8*olms.max) ) ) {
  773. //the status cannot be modified automatically by the LMS under SCORM 1.2's rules
  774. <?php if ($autocomplete_when_80pct){ ?>
  775. //olms.lesson_status = 'completed';
  776. //olms.updatable_vars_list['cmi.core.lesson_status']=true;
  777. <?php } ?>
  778. } else {
  779. /* DEPRECATED
  780. * See notes in switch_item for why this has been disabled
  781. if ((origin== 'finish' || origin == 'unload') && olms.lesson_status != 'completed' && olms.lesson_status != 'passed' && olms.lesson_status != 'browsed' && olms.lesson_status != 'failed' && olms.lesson_status != 'incomplete') {
  782. // The SCORM1.2 Runtime object document says for the "cmi.core.lesson_status" variable:
  783. // Upon receiving the LMSFinish() call or the user navigates away,
  784. // the LMS should set the cmi.core.lesson_status for the SCO to 'completed'
  785. logit_lms('the LMS did saving data (status='+olms.lesson_status+' - interactions: '+ olms.interactions.length +')',1);
  786. if (olms.mastery_score && olms.mastery_score!= '' && olms.score && olms.score != '') {
  787. if (olms.score >= olms.mastery_score) {
  788. olms.lesson_status = 'passed';
  789. } else {
  790. olms.lesson_status = 'failed';
  791. }
  792. olms.updatable_vars_list['cmi.core.lesson_status']=true;
  793. } else if (olms.mastery_score && olms.mastery_score!= '') {
  794. olms.lesson_status = 'completed';
  795. olms.updatable_vars_list['cmi.core.lesson_status']=true;
  796. }
  797. }
  798. */
  799. }
  800. //console.log(olms.lesson_status);
  801. logit_lms('saving data (status='+olms.lesson_status+' - interactions: '+ olms.interactions.length +')',1);
  802. old_item_id=olms.info_lms_item[0];
  803. xajax_save_item_scorm(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, old_item_id);
  804. olms.info_lms_item[1]=olms.lms_item_id;
  805. if (olms.item_objectives.length>0) {
  806. xajax_save_objectives(olms.lms_lp_id,olms.lms_user_id,olms.lms_view_id,old_item_id,olms.item_objectives);
  807. }
  808. olms.execute_stats = false;
  809. //clean array
  810. olms.variable_to_send=new Array();
  811. }
  812. /**
  813. * Send the Commit signal to the LMS (save the data for this element without
  814. * closing the current process)
  815. * From SCORM 1.2 RTE: If the API Adapter is caching values received from the
  816. * SCO via an LMSSetValue(), this call requires that any values not yet
  817. * persisted by the LMS be persisted.
  818. * @param string Must be empty string for conformance with SCORM 1.2
  819. */
  820. function LMSCommit(val) {
  821. logit_scorm('LMSCommit()',0);
  822. olms.G_LastError = G_NoError ;
  823. olms.G_LastErrorMessage = 'No error';
  824. savedata('commit');
  825. reinit_updatable_vars_list();
  826. //commit = 'false' ; //now changes have been commited, no need to update until next SetValue()
  827. return('true');
  828. }
  829. /**
  830. * Twin sister of LMSCommit(). Only provided for backwards compatibility.
  831. */
  832. function Commit(val) {
  833. return LMSCommit(val);
  834. }
  835. /**
  836. * Send the closure signal to the LMS. This saves the data and closes the current SCO.
  837. * From SCORM 1.2 RTE: The SCO must call this when it has determined that it no
  838. * longer needs to communicate with the LMS, if it successfully called
  839. * LMSInitialize at any previous point. This call signifies two things:
  840. * 1.The SCO can be assured that any data set using LMSSetValue() calls has been persisted by the LMS.
  841. * 2.The SCO has finished communicating with the LMS.
  842. * @param string
  843. */
  844. function LMSFinish(val) {
  845. olms.G_LastError = G_NoError ;
  846. olms.G_LastErrorMessage = 'No error';
  847. // if olms.commit == false, then the SCORM didn't ask for a commit, so we
  848. // should at least report that
  849. if ( !olms.commit ) {
  850. logit_scorm('LMSFinish() (no LMSCommit())',1);
  851. }
  852. //if ( olms.commit ) {
  853. logit_scorm('LMSFinish() called',1);
  854. savedata('finish');
  855. olms.commit = false;
  856. //}
  857. //reinit the list of modified variables
  858. reinit_updatable_vars_list()
  859. return('true');
  860. }
  861. /**
  862. * Twin sister of LMSFinish(). Only provided for backwards compatibility.
  863. */
  864. function Finish(val) {
  865. return LMSFinish(val);
  866. }
  867. /**
  868. * Returns the last error code as a string
  869. * @return string Error code
  870. */
  871. function LMSGetLastError() {
  872. logit_scorm('LMSGetLastError()',1);
  873. return(olms.G_LastError.toString());
  874. }
  875. /**
  876. * Twin sister of LMSGetLastError(). Only provided for backwards compatibility.
  877. */
  878. function GetLastError() {
  879. return LMSGetLastError();
  880. }
  881. /**
  882. * Returns the last error code literal for a given error code
  883. * @param int Error code
  884. * @return string Last error
  885. */
  886. function LMSGetErrorString(errCode){
  887. logit_scorm('LMSGetErrorString()',1);
  888. return(olms.G_LastErrorString);
  889. }
  890. /**
  891. * Twin sister of LMSGetErrorString(). Only provided for backwards compatibility.
  892. */
  893. function GetErrorString(errCode){
  894. return LMSGetErrorString(errCode);
  895. }
  896. /**
  897. * Returns a more explanatory, full English, error message
  898. * @param int Error code
  899. * @return string Diagnostic
  900. */
  901. function LMSGetDiagnostic(errCode){
  902. logit_scorm('LMSGetDiagnostic()',1);
  903. return(API.LMSGetLastError());
  904. }
  905. /**
  906. * Twin sister of LMSGetDiagnostic(). Only provided for backwards compatibility.
  907. */
  908. function GetDiagnostic(errCode){
  909. return LMSGetDiagnostic(errCode);
  910. }
  911. /**
  912. * Acts as a "commit"
  913. * This function is not standard SCORM 1.2 and is probably deprecated in all
  914. * meanings of the term.
  915. * @return string 'true' or 'false', depening on whether the LMS has initialized the SCORM process or not
  916. */
  917. function Terminate()
  918. {
  919. if (olms.lms_initialized == 0) {
  920. olms.G_LastError = G_NotInitialized;
  921. olms.G_LastErrorMessage = G_NotInitializedMessage;
  922. logit_scorm('Error '+ G_NotInitialized + G_NotInitializedMessage, 0);
  923. return('false');
  924. } else {
  925. logit_scorm('Terminate()',0);
  926. olms.G_LastError = G_NoError ;
  927. olms.G_LastErrorMessage = 'No error';
  928. olms.commit = true;
  929. savedata('terminate');
  930. return ('true');
  931. }
  932. }
  933. /**
  934. * LMS-specific code that deals with event handling and inter-frames
  935. * messaging/refreshing.
  936. * Note that from now on, the LMS JS code in this library will act as
  937. * a controller, of the MVC pattern, and receive all requests for frame
  938. * updates, then redispatch to any frame concerned.
  939. */
  940. /**
  941. * Defining the AJAX-object class to be made available from other frames
  942. */
  943. function XAJAXobject() {
  944. this.xajax_switch_item_details=xajax_switch_item_details;
  945. this.switch_item=switch_item;
  946. this.xajax_save_objectives=xajax_save_objectives;
  947. this.xajax_save_item = xajax_save_item;
  948. }
  949. /**
  950. * It is not sure that the SCOs use the above declarations
  951. */
  952. oXAJAX = new XAJAXobject();
  953. oxajax = new XAJAXobject();
  954. /**
  955. * Cross-browser event handling by Scott Andrew
  956. * @param element Element that needs an event attached
  957. * @param string Event type (load, unload, click, keyDown, ...)
  958. * @param string Function name (the event handler)
  959. * @param string used in addEventListener
  960. */
  961. function addEvent(elm, evType, fn, useCapture){
  962. if(elm.addEventListener){
  963. elm.addEventListener(evType, fn, useCapture);
  964. return true;
  965. }else if (elm.attachEvent){
  966. var r = elm.attachEvent('on' + evType, fn);
  967. }else{
  968. elm['on'+evType] = fn;
  969. }
  970. }
  971. /**
  972. * Add listeners to the page objects. This has to be defined for
  973. * the current context as it acts on objects that should exist
  974. * on the page
  975. * possibly deprecated
  976. * @todo Try to use $(document).unload(lms_save_asset()) instead of the addEvent() method
  977. */
  978. function addListeners(){
  979. //exit if the browser doesn't support ID or tag retrieval
  980. logit_lms('Entering addListeners()',2);
  981. if(!document.getElementsByTagName){
  982. logit_lms("getElementsByTagName not available",2);
  983. return;
  984. }
  985. if(!document.getElementById){
  986. logit_lms("getElementById not available",2);
  987. return;
  988. }
  989. //assign event handlers to objects
  990. if(olms.lms_lp_type==1 || olms.lms_item_type=='asset'){
  991. logit_lms('Chamilo LP or asset',2);
  992. //if this path is a Chamilo learnpath, then start manual save
  993. //when something is loaded in there
  994. addEvent(window,'unload',lms_save_asset,false);
  995. logit_lms('Added event listener on content_id for unload',2);
  996. }
  997. logit_lms('Quitting addListeners()',2);
  998. }
  999. /**
  1000. * Save a Chamilo learnpath item's time and mark as completed upon
  1001. * leaving it
  1002. */
  1003. function lms_save_asset() {
  1004. // only for Chamilo lps
  1005. if (olms.execute_stats) {
  1006. olms.execute_stats = false;
  1007. } else {
  1008. olms.execute_stats = true;
  1009. }
  1010. //For scorms do not show stats
  1011. if (olms.lms_lp_type == 2) {
  1012. olms.execute_stats = false;
  1013. }
  1014. if (olms.lms_lp_type == 1 || olms.lms_item_type == 'asset') {
  1015. logit_lms('lms_save_asset', 2);
  1016. xajax_save_item(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, olms.lms_item_id, olms.score, olms.max, olms.min, olms.lesson_status, olms.session_time, olms.suspend_data, olms.lesson_location,olms.interactions, olms.lms_item_core_exit);
  1017. if (olms.item_objectives.length>0) {
  1018. xajax_save_objectives(olms.lms_lp_id,olms.lms_user_id,olms.lms_view_id,olms.lms_item_id,olms.item_objectives);
  1019. }
  1020. }
  1021. }
  1022. /**
  1023. * Save a Chamilo learnpath item's time and mark as completed upon leaving it.
  1024. * Same function as lms_save_asset() but saves it with empty params
  1025. * to use values set from another side in the database. Only used by Chamilo quizzes.
  1026. * Also save the score locally because it hasn't been done through SetValue().
  1027. * Saving the status will be dealt with by the XAJAX function.
  1028. */
  1029. function chamilo_void_save_asset(myscore,mymax)
  1030. {
  1031. logit_lms('lms_save_asset',2);
  1032. olms.score = myscore;
  1033. if((mymax == null) || (mymax == '')){mymax = 100;} //assume a default of 100, otherwise the score will not get saved (see lpi->set_score())
  1034. xajax_save_item(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, olms.lms_item_id, myscore, mymax);
  1035. }
  1036. /**
  1037. * Logs information about SCORM messages into the log frame
  1038. * @param string Message to log
  1039. * @param integer Priority (0 for top priority, 3 for lowest)
  1040. */
  1041. function logit_scorm(message,priority) {
  1042. if (scorm_logs == 0) { return false; }
  1043. if (scorm_logs > priority) {
  1044. /* fixed see http://support.chamilo.org/issues/370 */
  1045. if ($("#lp_log_name") && $("#log_content")){
  1046. $("#log_content").append("SCORM: " + message + "<br/>");
  1047. }
  1048. }
  1049. params = {
  1050. msg: "SCORM: " + message,
  1051. debug: scorm_logs
  1052. };
  1053. $.ajax({
  1054. type: "POST",
  1055. data: params,
  1056. url: "lp_ajax_log.php",
  1057. dataType: "script",
  1058. async: true
  1059. });
  1060. }
  1061. /**
  1062. * Logs information about LMS activity into the log frame
  1063. * @param string Message to log
  1064. * @param integer Priority (0 for top priority, 3 for lowest)
  1065. */
  1066. function logit_lms(message, priority){
  1067. if (lms_logs >= priority) {
  1068. if ($("#lp_log_name") && $("#log_content")) {
  1069. $("#log_content").append("LMS: " + message + "<br />");
  1070. }
  1071. }
  1072. params = {
  1073. msg: "LMS: " + message,
  1074. debug: lms_logs
  1075. };
  1076. $.ajax({
  1077. type: "POST",
  1078. data: params,
  1079. url: "lp_ajax_log.php",
  1080. dataType: "script",
  1081. async: true
  1082. });
  1083. //console.log(message);
  1084. }
  1085. /**
  1086. * Update the Table Of Contents frame, by changing CSS styles, mostly
  1087. * @param string Action to be taken
  1088. * @param integer Item id to update
  1089. */
  1090. function update_toc(update_action, update_id, change_ids) {
  1091. if (!change_ids || change_ids != 'no') {
  1092. change_ids = 'yes';
  1093. }
  1094. var myelem = $("#toc_"+update_id);
  1095. var myelemimg = $("#toc_img_"+update_id);
  1096. logit_lms('update_toc("'+update_action+'",'+update_id+')',2);
  1097. if(update_id != 0) {
  1098. switch(update_action) {
  1099. case 'unhighlight':
  1100. if (update_id%2==0) {
  1101. myelem.attr('class',"scorm_item_2");
  1102. } else {
  1103. myelem.attr('class',"scorm_item_1");
  1104. }
  1105. break;
  1106. case 'highlight':
  1107. if (change_ids=='yes') {
  1108. olms.lms_next_item = update_id;
  1109. olms.lms_previous_item = update_id;
  1110. }
  1111. myelem.attr('class',"scorm_item_highlight");
  1112. break;
  1113. case 'not attempted':
  1114. if( myelemimg.attr('src') != '../img/notattempted.gif') {
  1115. myelemimg.attr('src','../img/notattempted.gif');
  1116. myelemimg.attr('alt','n');
  1117. }
  1118. break;
  1119. case 'incomplete':
  1120. if( myelemimg.attr('src') != '../img/incomplete.png') {
  1121. myelemimg.attr('src','../img/incomplete.png');
  1122. myelemimg.attr('alt','i');
  1123. }
  1124. break;
  1125. case 'completed':
  1126. if( myelemimg.attr('src') != '../img/completed.png') {
  1127. myelemimg.attr('src','../img/completed.png');
  1128. myelemimg.attr('alt','c');
  1129. }
  1130. break;
  1131. case 'failed':
  1132. if( myelemimg.attr('src') != '../img/delete.png') {
  1133. myelemimg.attr('src','../img/delete.png');
  1134. myelemimg.attr('alt','f');
  1135. }
  1136. break;
  1137. case 'passed':
  1138. if( myelemimg.attr('src') != '../img/completed.png' && myelemimg.attr('alt') != 'passed') {
  1139. myelemimg.attr('src','../img/completed.png');
  1140. myelemimg.attr('alt','p');
  1141. }
  1142. break;
  1143. case 'browsed':
  1144. if( myelemimg.attr('src') != '../img/completed.png' && myelemimg.attr('alt') != 'browsed') {
  1145. myelemimg.attr('src','../img/completed.png');
  1146. myelemimg.attr('alt','b');
  1147. }
  1148. break;
  1149. default:
  1150. logit_lms('Update action unknown',2);
  1151. break;
  1152. }
  1153. }
  1154. return true;
  1155. }
  1156. /**
  1157. * Update the stats frame using a reload of the frame to avoid unsynched data
  1158. */
  1159. function update_stats() {
  1160. if (olms.execute_stats) {
  1161. try {
  1162. cont_f = document.getElementById('content_id');
  1163. cont_f.src = "lp_controller.php?action=stats";
  1164. cont_f.reload();
  1165. } catch (e) {
  1166. return false;
  1167. }
  1168. }
  1169. olms.execute_stats = false;
  1170. }
  1171. /**
  1172. * Update the stats frame using a reload of the frame to avoid unsynched data
  1173. */
  1174. function update_stats_page() {
  1175. var myframe = document.getElementById('content_id');
  1176. var mysrc = myframe.location.href;
  1177. if(mysrc == 'lp_controller.php?action=stats'){
  1178. if(myframe && myframe.src){
  1179. var mysrc = myframe.src;
  1180. myframe.src = mysrc;
  1181. }
  1182. // = mysrc; //refresh page
  1183. }
  1184. return true;
  1185. }
  1186. /**
  1187. * Updates the progress bar with the new status. Prevents the need of a page refresh and flickering
  1188. * @param integer Number of completed items
  1189. * @param integer Number of items in total
  1190. * @param string Display mode (absolute 'abs' or percentage '%').Defaults to %
  1191. */
  1192. function update_progress_bar(nbr_complete, nbr_total, mode) {
  1193. logit_lms('update_progress_bar('+nbr_complete+','+nbr_total+','+mode+')',2);
  1194. logit_lms('could update with data: '+olms.lms_lp_id+','+olms.lms_view_id+','+olms.lms_user_id,2);
  1195. if (mode == '') {
  1196. mode='%';
  1197. }
  1198. if (nbr_total == 0) {
  1199. nbr_total=1;
  1200. }
  1201. var percentage = (nbr_complete/nbr_total)*100;
  1202. percentage = Math.round(percentage);
  1203. var pr_text = $("#progress_text");
  1204. var progress_bar = $("#progress_bar_value");
  1205. progress_bar.css('width', percentage + "%");
  1206. /*
  1207. var pr_full = $("#progress_img_full");
  1208. var pr_empty = $("#progress_img_empty");
  1209. pr_full.attr('width',percentage*1.2);
  1210. pr_empty.attr('width',(100-percentage)*1.2);
  1211. */
  1212. var mytext = '';
  1213. switch(mode){
  1214. case 'abs':
  1215. mytext = nbr_complete + '/' + nbr_total;
  1216. break;
  1217. case '%':
  1218. default:
  1219. mytext = percentage + '%';
  1220. break;
  1221. }
  1222. pr_text.html(mytext);
  1223. return true;
  1224. }
  1225. /**
  1226. * Analyses the variables that have been modified through this SCO's life and
  1227. * put them into an array for later shipping to lp_ajax_save_item.php
  1228. * @return array Array of SCO variables
  1229. */
  1230. function process_scorm_values () {
  1231. for (i=0;i<olms.scorm_variables.length;i++) {
  1232. if (olms.updatable_vars_list[olms.scorm_variables[i]]) {
  1233. olms.variable_to_send.push(olms.scorm_variables[i]);
  1234. }
  1235. }
  1236. return olms.variable_to_send;
  1237. }
  1238. /**
  1239. * Reinitializes the SCO's modified variables to an empty list.
  1240. * @return void
  1241. * @uses The global updatable_vars_list array to register this
  1242. */
  1243. function reinit_updatable_vars_list () {
  1244. for (i=0;i<olms.scorm_variables.length;i++) {
  1245. if (olms.updatable_vars_list[olms.scorm_variables[i]]) {
  1246. olms.updatable_vars_list[olms.scorm_variables[i]]=false;
  1247. }
  1248. }
  1249. olms.lesson_status='';
  1250. }
  1251. /**
  1252. * Function that handles the saving of an item and switching from an item to another.
  1253. * Once called, this function should be able to do the whole process of
  1254. * (1) saving the current item,
  1255. * (2) refresh all the values inside the SCORM API object,
  1256. * (3) open the new item into the content_id frame,
  1257. * (4) refresh the table of contents
  1258. * (5) refresh the progress bar (completion)
  1259. * (6) refresh the message frame
  1260. * @param integer Chamilo ID for the current item
  1261. * @param string This parameter can be a string specifying the next
  1262. * item (like 'next', 'previous', 'first' or 'last') or the id to the next item
  1263. */
  1264. function switch_item(current_item, next_item){
  1265. // backup these params
  1266. var orig_current_item = current_item;
  1267. var orig_next_item = next_item;
  1268. var orig_lesson_status = olms.lesson_status;
  1269. var orig_item_type = olms.lms_item_types['i'+current_item];
  1270. var next_item_type = olms.lms_item_types['i'+next_item];
  1271. /*
  1272. There are four "cases" for switching items:
  1273. (1) asset switching to asset
  1274. We need to save, then switch
  1275. (2) asset switching to sco
  1276. We need to save, switching not necessary (LMSInitialize does the job)
  1277. (3) sco switching to asset
  1278. We need to switch the document in the content frame, but we cannot
  1279. switch the item details, otherwise the LMSFinish() call (that *must*
  1280. be triggered by the SCO when it unloads) will use bad values. However,
  1281. we need to load the new asset's context once the SCO has unloaded
  1282. (4) sco switching to sco
  1283. We don't neet to switch nor commit, LMSFinish() on unload and
  1284. LMSInitialize on load will do the job
  1285. In any case, we need to change the current document frame.
  1286. These cases, although clear here, are however very difficult to implement
  1287. */
  1288. logit_lms('Called switch_item with params '+olms.lms_item_id+' and '+next_item+'',0);
  1289. if (orig_item_type != 'sco') {
  1290. if (next_item_type != 'sco' ) {
  1291. //case 1
  1292. xajax_save_item(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, olms.lms_item_id, olms.score, olms.max, olms.min, olms.lesson_status, olms.asset_timer, olms.suspend_data, olms.lesson_location,olms.interactions, olms.lms_item_core_exit);
  1293. xajax_switch_item_details(olms.lms_lp_id,olms.lms_user_id,olms.lms_view_id,olms.lms_item_id,next_item);
  1294. } else {
  1295. //case 2
  1296. xajax_save_item(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, olms.lms_item_id, olms.score, olms.max, olms.min, olms.lesson_status, olms.asset_timer, olms.suspend_data, olms.lesson_location,olms.interactions, olms.lms_item_core_exit);
  1297. xajax_switch_item_details(olms.lms_lp_id,olms.lms_user_id,olms.lms_view_id,olms.lms_item_id,next_item);
  1298. }
  1299. } else {
  1300. if (next_item_type != 'sco') {
  1301. //case 3
  1302. xajax_save_item_scorm(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, olms.lms_item_id);
  1303. reinit_updatable_vars_list();
  1304. xajax_switch_item_toc(olms.lms_lp_id,olms.lms_user_id,olms.lms_view_id,olms.lms_item_id,next_item);
  1305. } else {
  1306. //case 4
  1307. xajax_save_item_scorm(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, olms.lms_item_id);
  1308. reinit_updatable_vars_list();
  1309. xajax_switch_item_toc(olms.lms_lp_id,olms.lms_user_id,olms.lms_view_id,olms.lms_item_id,next_item);
  1310. }
  1311. if (olms.item_objectives.length>0) {
  1312. xajax_save_objectives(olms.lms_lp_id,olms.lms_user_id,olms.lms_view_id,olms.lms_item_id,olms.item_objectives);
  1313. }
  1314. }
  1315. /*
  1316. //(1) save the current item
  1317. if (olms.lms_lp_type==1 || olms.lms_item_type=='asset' || olms.session_time == '0' || olms.session_time == '0:00:00') {
  1318. if (olms.lms_lp_type==1) {
  1319. xajax_save_item(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, olms.lms_item_id, olms.score, olms.max, olms.min, olms.lesson_status, olms.asset_timer, olms.suspend_data, olms.lesson_location,olms.interactions, olms.lms_item_core_exit);
  1320. } else {
  1321. xajax_save_item_scorm(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, olms.lms_item_id);
  1322. }
  1323. if (olms.item_objectives.length>0) {
  1324. xajax_save_objectives(olms.lms_lp_id,olms.lms_user_id,olms.lms_view_id,olms.lms_item_id,olms.item_objectives);
  1325. }
  1326. }else{
  1327. */
  1328. /**
  1329. * Because of SCORM 1.2's special rule about unsent commits and the fact
  1330. * that a SCO should be SET TO 'completed' IF NO STATUS WAS SENT (and
  1331. * then some checks have to be done on score), we have to force a
  1332. * special commit here to avoid getting to the next element with a
  1333. * missing prerequisite. The 'onunload' event is treated with
  1334. * savedata_onunload(), and doesn't need to be triggered at any
  1335. * particular time, but here we are in the case of switching to another
  1336. * item, so this is particularly important to complete the element in
  1337. * time.
  1338. * However, this cannot be initiated from the JavaScript, mainly
  1339. * because another onunload event can be triggered by the SCO itself,
  1340. * which can set, for example, the status to incomplete while the
  1341. * status has already been set to "completed" by the hand-made
  1342. * savedata(unload) (and then the status cannot be "incompleted"
  1343. * anymore)
  1344. */
  1345. /*
  1346. if (olms.lms_item_type=='sco' && olms.lesson_status != 'completed' && olms.lesson_status != 'passed' && olms.lesson_status != 'browsed' && olms.lesson_status != 'incomplete' && olms.lesson_status != 'failed') {
  1347. // savedata('finish') treats the special condition and saves the
  1348. // new status to the database, so switch_item_details() enjoys the
  1349. // new status
  1350. savedata('finish');
  1351. }
  1352. xajax_save_item(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, olms.lms_item_id, olms.score, olms.max, olms.min, olms.lesson_status, olms.session_time, olms.suspend_data, olms.lesson_location,olms.interactions, olms.lms_item_core_exit);
  1353. */
  1354. /*
  1355. }
  1356. //(2) Refresh all the values inside this SCORM API object - use AJAX
  1357. xajax_switch_item_details(olms.lms_lp_id,olms.lms_user_id,olms.lms_view_id,olms.lms_item_id,next_item);
  1358. */
  1359. olms.execute_stats=false;
  1360. // Considering info_lms_item[0] is initially the oldest and info_lms_item[1]
  1361. // is the newest item, and considering we are done switching the items now,
  1362. // we need to update these markers so that the new item is loaded when
  1363. // changing the document in the content frame
  1364. if (olms.info_lms_item[1]==next_item && next_item!='next' && next_item!='previous') {
  1365. olms.info_lms_item[0]=next_item;
  1366. olms.info_lms_item[1]=next_item;
  1367. } else {
  1368. if (next_item!='next' && next_item!='previous') {
  1369. olms.info_lms_item[0]=olms.info_lms_item[1];
  1370. olms.info_lms_item[1]=next_item;
  1371. }
  1372. }
  1373. if (olms.info_lms_item[0]==next_item && next_item!='next' && next_item!='previous') {
  1374. olms.info_lms_item[0]=next_item;
  1375. olms.info_lms_item[1]=next_item;
  1376. } else {
  1377. if (next_item!='next' && next_item!='previous') {
  1378. olms.info_lms_item[0]=olms.info_lms_item[0];
  1379. olms.info_lms_item[1]=next_item;
  1380. }
  1381. }
  1382. //(3) open the new item in the content_id frame
  1383. switch(next_item){
  1384. case 'next':
  1385. next_item = olms.lms_next_item;
  1386. olms.info_lms_item[0]=olms.info_lms_item[1];
  1387. olms.info_lms_item[1]=olms.lms_next_item;
  1388. break;
  1389. case 'previous':
  1390. next_item = olms.lms_previous_item;
  1391. olms.info_lms_item[0]=olms.info_lms_item[1];
  1392. olms.info_lms_item[1]=olms.lms_previous_item;
  1393. break;
  1394. default:
  1395. break;
  1396. }
  1397. var mysrc = 'lp_controller.php?action=content&lp_id='+olms.lms_lp_id+'&item_id='+next_item;
  1398. var cont_f = $("#content_id");
  1399. <?php if($oLP->mode == 'fullscreen'){ ?>
  1400. cont_f = window.open(''+mysrc,'content_id','toolbar=0,location=0,status=0,scrollbars=1,resizable=1');
  1401. cont_f.onload=function(){
  1402. olms.info_lms_item[0]=olms.info_lms_item[1];
  1403. }
  1404. cont_f.onunload=function(){
  1405. olms.info_lms_item[0]=olms.info_lms_item[1];
  1406. }
  1407. <?php } else { ?>
  1408. cont_f.attr("src",mysrc);
  1409. <?php } ?>
  1410. if(olms.lms_lp_type==1 || olms.lms_item_type=='asset'){
  1411. xajax_start_timer();
  1412. }
  1413. //(4) refresh the audio player if needed
  1414. $.ajax({
  1415. type: "POST",
  1416. url: "lp_nav.php",
  1417. data: "",
  1418. success: function(tmp_data) {
  1419. if ($("#lp_media_file").length != 0) {
  1420. $("#lp_media_file").html(tmp_data);
  1421. }
  1422. }
  1423. });
  1424. return true;
  1425. }
  1426. /**
  1427. * Save a specific item (with its interactions, if any) into the LMS through
  1428. * an AJAX call to lp_ajax_save_item.php.
  1429. * Because of the need to pass an array, we have to build the parameters
  1430. * manually into GET[].
  1431. * This function has a twin sister for SCO elements (xajax_save_item_scorm)
  1432. * which takes into account the interactions.
  1433. * @param int ID of the learning path (for the LMS)
  1434. * @param int ID of the user
  1435. * @param int ID of the view of this learning path
  1436. * @param int ID of the item currently looked at
  1437. * @param float Score
  1438. * @param float Max score
  1439. * @param float Min score
  1440. * @param string Lesson status
  1441. * @param string Current session time (in 'xxxx:xx:xx.xx' format)
  1442. * @param string Suspend data (maximum 255 chars)
  1443. * @param string Lesson location (which page we've reached in the SCO)
  1444. * @param array Interactions
  1445. * @param string Core exit value (up to 4096 chars)
  1446. * @return void
  1447. * @uses lp_ajax_save_item.php through an AJAX call
  1448. */
  1449. 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) {
  1450. params='';
  1451. params += 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id;
  1452. params += '&iid='+lms_item_id+'&s='+score+'&max='+max+'&min='+min;
  1453. params += '&status='+lesson_status+'&t='+session_time;
  1454. params += '&suspend='+suspend_data+'&loc='+lesson_location;
  1455. params += '&core_exit='+lms_item_core_exit;
  1456. if ( olms.lms_lp_type == 1) {
  1457. $.ajax({
  1458. type:"POST",
  1459. data: params,
  1460. url: "lp_ajax_save_item.php",
  1461. dataType: "script",
  1462. async: false
  1463. });
  1464. }
  1465. }
  1466. /**
  1467. * Save a SCORM item's variables, getting its SCORM values from
  1468. * updatable_vars_list. Takes interactions into account and considers whether
  1469. * variables have been modified or not.
  1470. * @param int ID of the learning path
  1471. * @param int ID of the user
  1472. * @param int ID of the view
  1473. * @param int ID of the item
  1474. * @return void
  1475. * @uses olms.updatable_vars_list
  1476. * @uses lp_ajax_save_item.php through an AJAX call
  1477. */
  1478. function xajax_save_item_scorm(lms_lp_id, lms_user_id, lms_view_id, lms_item_id) {
  1479. var is_interactions='false';
  1480. var params='';
  1481. params += 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id+'&iid='+lms_item_id;
  1482. var my_scorm_values=new Array();
  1483. my_scorm_values=process_scorm_values();
  1484. for (k=0;k<my_scorm_values.length;k++) {
  1485. if (my_scorm_values[k]=='cmi.core.session_time') {
  1486. params += '&t='+olms.session_time;
  1487. } else if (my_scorm_values[k]=='cmi.core.lesson_status' && olms.lesson_status!='') {
  1488. params += '&status='+olms.lesson_status;
  1489. } else if (my_scorm_values[k]=='cmi.core.score.raw') {
  1490. params += '&s='+olms.score;
  1491. } else if (my_scorm_values[k]=='cmi.core.score.max') {
  1492. params += '&max='+olms.max;
  1493. } else if (my_scorm_values[k]=='cmi.core.score.min') {
  1494. params += '&min='+olms.min;
  1495. } else if (my_scorm_values[k]=='cmi.core.lesson_location') {
  1496. params += '&loc='+olms.lesson_location;
  1497. } else if (my_scorm_values[k]=='cmi.completion_status') {
  1498. } else if (my_scorm_values[k]=='cmi.score.scaled') {
  1499. } else if (my_scorm_values[k]=='cmi.suspend_data') {
  1500. params += '&suspend='+olms.suspend_data;
  1501. } else if (my_scorm_values[k]=='cmi.completion_status') {
  1502. } else if (my_scorm_values[k]=='cmi.core.exit') {
  1503. params += '&core_exit='+olms.lms_item_core_exit;
  1504. }
  1505. if (my_scorm_values[k]=='interactions') {
  1506. is_interactions='true';
  1507. } else {
  1508. is_interactions='false';
  1509. }
  1510. }
  1511. if (is_interactions=='true') {
  1512. interact_string = '';
  1513. temp = '';
  1514. for (i in olms.interactions) {
  1515. interact_string += '&interact['+i+']=';
  1516. interact_temp = '[';
  1517. for (j in olms.interactions[i]) {
  1518. temp = olms.interactions[i][j];
  1519. temp = ''+temp; // if temp == 1 there are problems with indexOf and an integer number
  1520. //this fix when an interaction have ',' i.e: {a,b,c,d} is replace to {a@.|@b@.|@c@.|@d} see DT#4444
  1521. while(temp.indexOf(',') >= 0){
  1522. temp = temp.replace(',','@.|@');
  1523. };
  1524. interact_temp +=temp+',';
  1525. }
  1526. interact_temp = interact_temp.substr(0,(interact_temp.length-2)) + ']';
  1527. // interact_string += encodeURIComponent(interact_temp);
  1528. interact_string += interact_temp;
  1529. }
  1530. //interact_string = encodeURIComponent(interact_string.substr(0,(interact_string.length-1)));
  1531. params += interact_string;
  1532. is_interactions='false';
  1533. }
  1534. $.ajax({
  1535. type:"POST",
  1536. data: params,
  1537. url: "lp_ajax_save_item.php",
  1538. dataType: "script",
  1539. async: false
  1540. });
  1541. params='';
  1542. my_scorm_values = null;
  1543. }
  1544. /**
  1545. * Starts the timer with the server clock time.
  1546. * @return void
  1547. * @todo check the timer stuff really works
  1548. * @uses lp_ajax_start_timer.php
  1549. */
  1550. function xajax_start_timer() {
  1551. $.ajax({
  1552. type: "GET",
  1553. url: "lp_ajax_start_timer.php",
  1554. dataType: "script",
  1555. async: false
  1556. });
  1557. }
  1558. /**
  1559. * Save a specific item's objectives into the LMS through an Synch JAX call
  1560. * @param int ID of the learning path
  1561. * @param int ID of the user
  1562. * @param int ID of the view
  1563. * @param int ID of the item
  1564. * @param array SCO's recorded objectives
  1565. * @uses lp_ajax_save_objectives.php
  1566. */
  1567. function xajax_save_objectives(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,item_objectives) {
  1568. params='';
  1569. params += 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id;
  1570. params += '&iid='+lms_item_id;
  1571. obj_string = '';
  1572. for (i in item_objectives){
  1573. obj_string += '&objectives['+i+']=';
  1574. obj_temp = '[';
  1575. for (j in item_objectives[i]) {
  1576. obj_temp += item_objectives[i][j]+',';
  1577. }
  1578. obj_temp = obj_temp.substr(0,(obj_temp.length-2)) + ']';
  1579. obj_string += encodeURIComponent(obj_temp);
  1580. }
  1581. params += obj_string;
  1582. $.ajax({
  1583. type: "POST",
  1584. data: params,
  1585. url: "lp_ajax_save_objectives.php",
  1586. dataType: "script",
  1587. async: false
  1588. });
  1589. }
  1590. /**
  1591. * Switch between two items through an AJAX call.
  1592. * @param int ID of the learning path
  1593. * @param int ID of the user
  1594. * @param int ID of the view
  1595. * @param int ID of the item
  1596. * @param int ID of the next item
  1597. * @uses lp_ajax_switch_item.php
  1598. */
  1599. function xajax_switch_item_details(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,next_item) {
  1600. params = {
  1601. 'lid': lms_lp_id,
  1602. 'uid': lms_user_id,
  1603. 'vid': lms_view_id,
  1604. 'iid': lms_item_id,
  1605. 'next': next_item
  1606. };
  1607. $.ajax({
  1608. type: "POST",
  1609. data: params,
  1610. url: "lp_ajax_switch_item.php",
  1611. dataType: "script",
  1612. async: false
  1613. });
  1614. }
  1615. /**
  1616. * Switch between two items through an AJAX call, but only update the TOC and
  1617. * progress bar.
  1618. * @param int ID of the learning path
  1619. * @param int ID of the user
  1620. * @param int ID of the view
  1621. * @param int ID of the item
  1622. * @param int ID of the next item
  1623. * @uses lp_ajax_switch_toc.php
  1624. */
  1625. function xajax_switch_item_toc(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,next_item) {
  1626. params = {
  1627. 'lid': lms_lp_id,
  1628. 'uid': lms_user_id,
  1629. 'vid': lms_view_id,
  1630. 'iid': lms_item_id,
  1631. 'next': next_item
  1632. };
  1633. $.ajax({
  1634. type: "POST",
  1635. data: params,
  1636. url: "lp_ajax_switch_item_toc.php",
  1637. dataType: "script",
  1638. async: false
  1639. });
  1640. }
  1641. /**
  1642. * Add the "addListeners" function to the "onload" event of the window and
  1643. * start the timer if necessary (asset)
  1644. */
  1645. addEvent(window,'load',addListeners,false);
  1646. if(olms.lms_lp_type==1 || olms.lms_item_type=='asset'){
  1647. xajax_start_timer();
  1648. }
  1649. /**
  1650. * Allow attach the glossary terms into html document of scorm. This has
  1651. * nothing to do with SCORM itself, and should not interfere w/ SCORM either.
  1652. * @param string automatic or manual values are allowed
  1653. */
  1654. function attach_glossary_into_scorm(type) {
  1655. var f = $('#content_id')[0];
  1656. //Prevents "f is undefined" javascript error
  1657. if (f == null) {
  1658. logit_lms('attach_glossary_into_scorm failed', 0);
  1659. return false;
  1660. }
  1661. //logit_lms('attach_glossary_into_scorm', 0);
  1662. try {
  1663. var doc = f.contentWindow ? f.contentWindow.document : f.contentDocument ? f.contentDocument : f.document;
  1664. } catch (ex) { }
  1665. var $frame_content = $('body',doc);
  1666. var my_text=$frame_content.html();
  1667. my_protocol = location.protocol;
  1668. my_pathname=location.pathname;
  1669. work_path = my_pathname.substr(0,my_pathname.indexOf('/courses/'));
  1670. if (type == 'automatic') {
  1671. $.ajax({
  1672. contentType: "application/x-www-form-urlencoded",
  1673. beforeSend: function(object) {
  1674. },
  1675. type: "POST",
  1676. url: my_protocol+"//"+location.host+work_path+"/main/glossary/glossary_ajax_request.php",
  1677. data: "glossary_data=true",
  1678. success: function(datas) {
  1679. if (datas.length==0) {
  1680. return false;
  1681. }
  1682. // glossary terms
  1683. data_terms=datas.split("[|.|_|.|-|.|]");
  1684. var complex_array = new Array();
  1685. var cp_complex_array = new Array();
  1686. for(i=0;i<data_terms.length;i++) {
  1687. specific_terms=data_terms[i].split("__|__|");
  1688. var real_term = specific_terms[1]; // glossary term
  1689. var real_code = specific_terms[0]; // glossary id
  1690. complex_array[real_code] = real_term;
  1691. cp_complex_array[real_code] = real_term;
  1692. }
  1693. complex_array.reverse();
  1694. for (var my_index in complex_array) {
  1695. n = complex_array[my_index];
  1696. if (n == null) {
  1697. n = '';
  1698. } else {
  1699. for (var cp_my_index in cp_complex_array) {
  1700. cp_data = cp_complex_array[cp_my_index];
  1701. if (cp_data == null) {
  1702. cp_data = '';
  1703. } else {
  1704. if (cp_data == n) {
  1705. my_index = cp_my_index;
  1706. }
  1707. }
  1708. }
  1709. //alert(n + ' ' + my_index);
  1710. $("iframe").contents().find('body').removeHighlight().highlight(n,my_index)
  1711. //logit_lms(n+ ' - '+my_index, 0);
  1712. }
  1713. }
  1714. var complex_array = new Array();
  1715. //$("iframe").contents().find("body .glossary-ajax").on("click", ".glossary-ajax", function() {
  1716. $("iframe").contents().find("body").on("click", ".glossary-ajax", function() {
  1717. div_show_id="div_show_id";
  1718. div_content_id="div_content_id";
  1719. $("iframe").contents().find("body").append('<div id="div_show_id"><div id="div_content_id">&nbsp;</div></div>');
  1720. show_dialog = $("iframe").contents().find("div#"+div_show_id);
  1721. show_description = $("iframe").contents().find("div#"+div_content_id);
  1722. var $target = $(this);
  1723. if ($("#learning_path_left_zone").is(':visible') ) {
  1724. var extra_left = $("#learning_path_left_zone").width() + 20;
  1725. } else {
  1726. var extra_left = 0;
  1727. }
  1728. //$("#"+div_show_id).dialog("destroy");
  1729. show_dialog.dialog({
  1730. autoOpen: false,
  1731. width: 600,
  1732. height: 200,
  1733. position: { my: 'left top', at: 'right top', of: $target, offset: extra_left+", 0"},
  1734. close: function(){
  1735. show_dialog.remove();
  1736. show_description.remove();
  1737. }
  1738. });
  1739. notebook_id=$(this).attr("name");
  1740. data_notebook=notebook_id.split("link");
  1741. my_glossary_id=data_notebook[1];
  1742. $.ajax({
  1743. contentType: "application/x-www-form-urlencoded",
  1744. type: "POST",
  1745. url: "<?php echo api_get_path(WEB_PATH); ?>main/glossary/glossary_ajax_request.php",
  1746. data: "glossary_id="+my_glossary_id,
  1747. success: function(data) {
  1748. show_description.html(data);
  1749. show_dialog.dialog("open");
  1750. }
  1751. });
  1752. });
  1753. }
  1754. });
  1755. } else {
  1756. if ('manual') {
  1757. $("iframe").contents().find("body").on("click", ".glossary", function() {
  1758. is_glossary_name = $(this).html();
  1759. div_show_id="div_show_id";
  1760. div_content_id="div_content_id";
  1761. $("iframe").contents().find("body").append('<div id="div_show_id"><div id="div_content_id">&nbsp;</div></div>');
  1762. show_dialog = $("iframe").contents().find("div#"+div_show_id);
  1763. show_description = $("iframe").contents().find("div#"+div_content_id);
  1764. var $target = $(this);
  1765. if ($("#learning_path_left_zone").is(':visible') ) {
  1766. var extra_left = $("#learning_path_left_zone").width() + 20;
  1767. } else {
  1768. var extra_left = 0;
  1769. }
  1770. //$("#"+div_show_id).dialog("destroy");
  1771. show_dialog.dialog({
  1772. autoOpen: false,
  1773. width: 600,
  1774. height: 200,
  1775. position: { my: 'left top', at: 'right top', of: $target, offset: extra_left+", 0"},
  1776. close: function(){
  1777. show_dialog.remove();
  1778. show_description.remove();
  1779. }
  1780. });
  1781. //$("iframe").contents().find("div#"+div_show_id).attr("style","display:inline;float:left;position:absolute;background-color:#F2F2F2;border-bottom: 1px solid #2E2E2E;border-right: 1px solid #2E2E2E;border-left: 1px solid #2E2E2E;border-top: 1px solid #2E2E2E;color:#305582;margin-left:5px;margin-right:5px;");
  1782. //$("iframe").contents().find("div#"+div_content_id).attr("style","background-color:#F2F2F2;color:#0B3861;margin-left:8px;margin-right:8px;margin-top:5px;margin-bottom:5px;");
  1783. $.ajax({
  1784. contentType: "application/x-www-form-urlencoded",
  1785. type: "POST",
  1786. url: "<?php echo api_get_path(WEB_PATH); ?>main/glossary/glossary_ajax_request.php",
  1787. data: "glossary_name="+is_glossary_name,
  1788. success: function(data) {
  1789. show_description.html(data);
  1790. show_dialog.dialog("open");
  1791. }
  1792. });
  1793. });
  1794. }
  1795. }
  1796. }