scorm_api.php 86 KB

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