scorm_api.php 72 KB

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