scorm_api.php 73 KB

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