scorm_api.php 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118
  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. $showGlossary = in_array($glossaryExtraTools, array('true', 'lp', 'exercise_and_lp'));
  298. if ($showGlossary) {
  299. if (api_get_setting('show_glossary_in_documents') == 'ismanual') {
  300. ?>
  301. if (olms.lms_item_type == 'sco') {
  302. attach_glossary_into_scorm('automatic');
  303. } else {
  304. attach_glossary_into_scorm('manual');
  305. }
  306. <?php } elseif (api_get_setting('show_glossary_in_documents') == 'isautomatic') { ?>
  307. attach_glossary_into_scorm('automatic');
  308. <?php } ?>
  309. <?php } ?>
  310. return('true');
  311. }
  312. }
  313. /**
  314. * Twin sister of LMSInitialize(). Only provided for backwards compatibility.
  315. * this is the initialize function of all APIobjects
  316. */
  317. function Initialize() {
  318. return LMSInitialize();
  319. }
  320. /**
  321. * Gets a value in the current SCORM context and returns it to the calling SCO
  322. * @param string The name of the value we want
  323. * @return string All return values must be string (see SCORM)
  324. */
  325. function LMSGetValue(param) {
  326. olms.G_LastError = G_NoError ;
  327. olms.G_LastErrorMessage = 'No error';
  328. var result='';
  329. // the LMSInitialize is missing
  330. if (olms.lms_initialized == 0) {
  331. if (param == 'cmi.core.score.raw') {
  332. return '';
  333. }
  334. olms.G_LastError = G_NotInitialized;
  335. olms.G_LastErrorMessage = G_NotInitializedMessage;
  336. logit_scorm('LMSGetValue('+param+') on item id '+olms.lms_item_id+':<br />=> Error '+ G_NotInitialized + ' ' +G_NotInitializedMessage, 0);
  337. return '';
  338. }
  339. //Chamilo does not support these SCO object properties
  340. if (param == 'cmi.student_preference.text' ||
  341. param == 'cmi.student_preference.language' ||
  342. param == 'cmi.student_preference.speed' ||
  343. param == 'cmi.student_preference.audio' ||
  344. param == 'cmi.student_preference._children' ||
  345. param == 'cmi.student_data.time_limit_action' ||
  346. param == 'cmi.comments' ||
  347. param == 'cmi.comments_from_lms' ||
  348. /* The following properties were part of SCORM 1.0 or never implemented at all
  349. but seem to react badly to Captivate content producer when not defined */
  350. param == 'cmi.student_demographics._children' ||
  351. param == 'cmi.student_demographics.city' ||
  352. param == 'cmi.student_demographics.class' ||
  353. param == 'cmi.student_demographics.company' ||
  354. param == 'cmi.student_demographics.country' ||
  355. param == 'cmi.student_demographics.experience' ||
  356. param == 'cmi.student_demographics.familiar_name' ||
  357. param == 'cmi.student_demographics.instructor_name' ||
  358. param == 'cmi.student_demographics.title' ||
  359. param == 'cmi.student_demographics.native_language' ||
  360. param == 'cmi.student_demographics.state' ||
  361. param == 'cmi.student_demographics.street_address' ||
  362. param == 'cmi.student_demographics.telephone' ||
  363. param == 'cmi.student_demographics.years_experience' ) {
  364. // the value is not supported
  365. olms.G_LastError = G_NotImplementedError ;
  366. olms.G_LastErrorString = G_NotImplementedErrorMessage;
  367. logit_scorm("LMSGetValue ('"+param+"') Error '"+G_NotImplementedErrorMessage+"'",1);
  368. result = '';
  369. return result;
  370. }
  371. if (param=='cmi.student_demographics.first_name') {
  372. result=olms.userfname;
  373. } else if(param=='cmi.student_demographics.last_name') {
  374. result=olms.userlname;
  375. // ---- cmi.core._children
  376. } else if(param=='cmi.core._children' || param=='cmi.core_children'){
  377. result='entry, exit, lesson_status, student_id, student_name, lesson_location, total_time, credit, lesson_mode, score, session_time';
  378. } else if(param == 'cmi.core.entry'){
  379. // ---- cmi.core.entry
  380. if(olms.lms_item_core_exit=='none') {
  381. result='ab-initio';
  382. } else if(olms.lms_item_core_exit=='suspend') {
  383. result='resume';
  384. } else {
  385. result='';
  386. }
  387. } else if(param == 'cmi.core.exit'){
  388. // ---- cmi.core.exit
  389. result='';
  390. olms.G_LastError = G_ElementIsWriteOnly;
  391. } else if(param == 'cmi.core.session_time'){
  392. result='';
  393. olms.G_LastError = G_ElementIsWriteOnly;
  394. } else if(param == 'cmi.core.lesson_status'){
  395. // ---- cmi.core.lesson_status
  396. if(olms.lesson_status != '') {
  397. result=olms.lesson_status;
  398. } else {
  399. //result='not attempted';
  400. }
  401. } else if(param == 'cmi.core.student_id'){
  402. // ---- cmi.core.student_id
  403. result='<?php echo $userId; ?>';
  404. } else if(param == 'cmi.core.student_name'){
  405. // ---- cmi.core.student_name
  406. <?php
  407. $who = addslashes($user['complete_name']);
  408. echo "result='$who';";
  409. ?>
  410. } else if(param == 'cmi.core.lesson_location'){
  411. // ---- cmi.core.lesson_location
  412. result=olms.lesson_location;
  413. } else if(param == 'cmi.core.total_time'){
  414. // ---- cmi.core.total_time
  415. result=olms.total_time;
  416. } else if(param == 'cmi.core.score._children'){
  417. // ---- cmi.core.score._children
  418. result='raw,min,max';
  419. } else if(param == 'cmi.core.score.raw'){
  420. // ---- cmi.core.score.raw
  421. result=olms.score;
  422. } else if(param == 'cmi.core.score.max'){
  423. // ---- cmi.core.score.max
  424. result=olms.max;
  425. } else if(param == 'cmi.core.score.min'){
  426. // ---- cmi.core.score.min
  427. result=olms.min;
  428. } else if(param == 'cmi.core.score'){
  429. // ---- cmi.core.score -- non-standard item, provided as cmi.core.score.raw just in case
  430. result=olms.score;
  431. } else if(param == 'cmi.core.credit'){
  432. // ---- cmi.core.credit
  433. result = olms.lms_item_credit;
  434. } else if(param == 'cmi.core.lesson_mode'){
  435. // ---- cmi.core.lesson_mode
  436. result = olms.lms_item_lesson_mode;
  437. } else if(param == 'cmi.suspend_data'){
  438. // ---- cmi.suspend_data
  439. result = olms.suspend_data;
  440. } else if(param == 'cmi.launch_data'){
  441. // ---- cmi.launch_data
  442. result = olms.lms_item_launch_data;
  443. } else if(param == 'cmi.objectives._children'){
  444. // ---- cmi.objectives._children
  445. result = 'id,score,status';
  446. } else if(param == 'cmi.objectives._count'){
  447. // ---- cmi.objectives._count
  448. //result='<?php echo $oItem->get_view_count();?>';
  449. result = olms.item_objectives.length;
  450. } else if(param.substring(0,15)== 'cmi.objectives.'){
  451. var myres = '';
  452. if(myres = param.match(/cmi.objectives.(\d+).(id|score|status|_children)(.*)/)) {
  453. var obj_id = myres[1];
  454. var req_type = myres[2];
  455. if(olms.item_objectives[obj_id]==null) {
  456. if(req_type == 'id') {
  457. result = '';
  458. } else if(req_type == '_children'){
  459. result = 'id,score,status';
  460. } else if(req_type == 'score'){
  461. if(myres[3]==null) {
  462. result = '';
  463. olms.G_LastError = G_NotImplementedError;
  464. olms.G_LastErrorString = 'Not implemented yet';
  465. }else if (myres[3] == '._children'){
  466. result = 'raw,min,max'; //non-standard, added for NetG
  467. }else if (myres[3] == '.raw'){
  468. result = '';
  469. }else if (myres[3] == '.max'){
  470. result = '';
  471. }else if (myres[3] == '.min'){
  472. result = '';
  473. }else{
  474. result = '';
  475. olms.G_LastError = G_NotImplementedError;
  476. olms.G_LastErrorString = 'Not implemented yet';
  477. }
  478. }else if(req_type == 'status'){
  479. result = 'not attempted';
  480. }
  481. } else {
  482. //the object is not null
  483. if(req_type == 'id') {
  484. result = olms.item_objectives[obj_id][0];
  485. } else if(req_type == '_children'){
  486. result = 'id,score,status';
  487. } else if(req_type == 'score'){
  488. if(myres[3]==null) {
  489. result = '';
  490. olms.G_LastError = G_NotImplementedError;
  491. olms.G_LastErrorString = 'Not implemented yet';
  492. } else if (myres[3] == '._children'){
  493. result = 'raw,min,max'; //non-standard, added for NetG
  494. } else if (myres[3] == '.raw'){
  495. if(olms.item_objectives[obj_id][2] != null)
  496. {
  497. result = olms.item_objectives[obj_id][2];
  498. }else{
  499. result = '';
  500. }
  501. } else if (myres[3] == '.max'){
  502. if(olms.item_objectives[obj_id][3] != null) {
  503. result = olms.item_objectives[obj_id][3];
  504. }else{
  505. result = '';
  506. }
  507. } else if (myres[3] == '.min') {
  508. if(olms.item_objectives[obj_id][4] != null) {
  509. result = olms.item_objectives[obj_id][4];
  510. } else {
  511. result = '';
  512. }
  513. } else{
  514. result = '';
  515. olms.G_LastError = G_NotImplementedError;
  516. olms.G_LastErrorString = 'Not implemented yet';
  517. }
  518. } else if(req_type == 'status'){
  519. if(olms.item_objectives[obj_id][1] != null) {
  520. result = olms.item_objectives[obj_id][1];
  521. } else {
  522. result = 'not attempted';
  523. }
  524. }
  525. }
  526. }
  527. } else if(param == 'cmi.student_data._children'){
  528. // ---- cmi.student_data._children
  529. result = 'mastery_score,max_time_allowed';
  530. } else if(param == 'cmi.student_data.mastery_score'){
  531. // ---- cmi.student_data.mastery_score
  532. result = olms.mastery_score;
  533. } else if(param == 'cmi.student_data.max_time_allowed'){
  534. // ---- cmi.student_data.max_time_allowed
  535. result = olms.max_time_allowed;
  536. } else if(param == 'cmi.interactions._count'){
  537. // ---- cmi.interactions._count
  538. result = olms.interactions.length;
  539. } else if(param == 'cmi.interactions._children'){
  540. // ---- cmi.interactions._children
  541. result = 'id,time,type,correct_responses,weighting,student_response,result,latency';
  542. } else{
  543. // ---- anything else
  544. // Invalid argument error
  545. olms.G_LastError = G_InvalidArgumentError ;
  546. olms.G_LastErrorString = G_InvalidArgumentErrorMessage;
  547. logit_scorm("LMSGetValue ('"+param+"') Error '"+G_InvalidArgumentErrorMessage+"'",1);
  548. result = '';
  549. return result;
  550. }
  551. logit_scorm("LMSGetValue\n\t('"+param+"') returned '"+result+"'",1);
  552. return result;
  553. }
  554. /**
  555. * Twin sister of LMSGetValue(). Only provided for backwards compatibility.
  556. */
  557. function GetValue(param) {
  558. return LMSGetValue(param);
  559. }
  560. /**
  561. * Sets a SCORM variable's value through a call from the SCO.
  562. * @param string The SCORM variable's name
  563. * @param string The SCORM variable's new value
  564. * @param string 'true','false' or an error code
  565. */
  566. function LMSSetValue(param, val) {
  567. logit_scorm("LMSSetValue ('"+param+"','"+val+"')",0);
  568. logit_scorm("Checking olms.lms_item_id " + olms.lms_item_id);
  569. olms.commit = true; //value has changed, need to re-commit
  570. olms.G_LastError = G_NoError ;
  571. olms.G_LastErrorMessage = 'No error';
  572. return_value = 'false';
  573. if ( param == "cmi.core.score.raw" ) {
  574. olms.score= val;
  575. olms.updatable_vars_list['cmi.core.score.raw']=true;
  576. return_value='true';
  577. } else if ( param == "cmi.core.score.max" ) {
  578. olms.max = val;
  579. olms.updatable_vars_list['cmi.core.score.max']=true;
  580. return_value='true';
  581. } else if ( param == "cmi.core.score.min" ) {
  582. olms.min = val;
  583. olms.updatable_vars_list['cmi.core.score.min']=true;
  584. return_value='true';
  585. } else if ( param == "cmi.core.lesson_location" ) {
  586. olms.lesson_location = val;
  587. olms.updatable_vars_list['cmi.core.lesson_location']=true;
  588. return_value='true';
  589. } else if ( param == "cmi.core.lesson_status" ) {
  590. olms.lesson_status = val;
  591. olms.updatable_vars_list['cmi.core.lesson_status'] = true;
  592. olms.statusSignalReceived = 1;
  593. return_value='true';
  594. } else if ( param == "cmi.completion_status" ) {
  595. olms.lesson_status = val;
  596. olms.updatable_vars_list['cmi.completion_status']=true;
  597. return_value='true'; //1.3
  598. } else if ( param == "cmi.core.session_time" ) {
  599. olms.session_time = val;
  600. olms.updatable_vars_list['cmi.core.session_time']=true;
  601. return_value='true';
  602. } else if ( param == "cmi.score.scaled") { //1.3
  603. if (val<=1 && val>=-1) {
  604. olms.score = val ;
  605. olms.updatable_vars_list['cmi.score.scaled']=true;
  606. return_value='true';
  607. } else {
  608. return_value='false';
  609. }
  610. } else if ( param == "cmi.success_status" ) {
  611. success_status = val;
  612. olms.updatable_vars_list['cmi.success_status']=true;
  613. return_value='true'; //1.3
  614. } else if ( param == "cmi.suspend_data" ) {
  615. olms.suspend_data = val;
  616. olms.updatable_vars_list['cmi.suspend_data']=true;
  617. return_value='true';
  618. } else if ( param == "cmi.core.exit" ) {
  619. olms.lms_item_core_exit = val;
  620. olms.updatable_vars_list['cmi.core.exit']=true;
  621. return_value='true';
  622. } else if ( param == "cmi.core.student_id" ) {
  623. olms.G_LastError = G_ElementIsReadOnly;
  624. } else if ( param == "cmi.core.student_name" ) {
  625. olms.G_LastError = G_ElementIsReadOnly;
  626. } else if ( param == "cmi.core.credit" ) {
  627. olms.G_LastError = G_ElementIsReadOnly;
  628. } else if ( param == "cmi.core.entry" ) {
  629. olms.G_LastError = G_ElementIsReadOnly;
  630. } else if ( param == "cmi.core.total_time" ) {
  631. olms.G_LastError = G_ElementIsReadOnly;
  632. } else if ( param == "cmi.core.lesson_mode" ) {
  633. olms.G_LastError = G_ElementIsReadOnly;
  634. } else if ( param == "cmi.comments_from_lms" ) {
  635. olms.G_LastError = G_ElementIsReadOnly;
  636. } else if ( param == "cmi.student_data.time_limit_action" ) {
  637. olms.G_LastError = G_ElementIsReadOnly;
  638. } else if ( param == "cmi.student_data.mastery_score" ) {
  639. olms.G_LastError = G_ElementIsReadOnly;
  640. } else if ( param == "cmi.student_data.max_time_allowed" ) {
  641. olms.G_LastError = G_ElementIsReadOnly;
  642. } else if ( param == "cmi.student_preference._children" ) {
  643. olms.G_LastError = G_ElementIsReadOnly;
  644. } else if ( param == "cmi.launch_data" ) {
  645. olms.G_LastError = G_ElementIsReadOnly;
  646. } else {
  647. var myres = new Array();
  648. if(myres = param.match(/cmi.interactions.(\d+).(id|time|type|correct_responses|weighting|student_response|result|latency)(.*)/)) {
  649. olms.updatable_vars_list['interactions']=true;
  650. elem_id = myres[1];
  651. //interactions setting should start at 0
  652. if(elem_id > olms.interactions.length) {
  653. /*
  654. olms.G_LastError = G_InvalidArgumentError;
  655. olms.G_LastErrorString = 'Invalid argument (interactions)';
  656. return_value = false;
  657. */
  658. olms.interactions[0] = ['0','','','','','','',''];
  659. }
  660. if(olms.interactions[elem_id] == null) {
  661. olms.interactions[elem_id] = ['','','','','','','',''];
  662. //id(0), type(1), time(2), weighting(3),correct_responses(4),student_response(5),result(6),latency(7)
  663. olms.interactions[elem_id][4] = new Array();
  664. }
  665. elem_attrib = myres[2];
  666. switch (elem_attrib) {
  667. case "id":
  668. olms.interactions[elem_id][0] = val;
  669. logit_scorm("Interaction "+elem_id+"'s id updated",2);
  670. return_value='true';
  671. break;
  672. case "time":
  673. olms.interactions[elem_id][2] = val;
  674. logit_scorm("Interaction "+elem_id+"'s time updated",2);
  675. return_value='true';
  676. break;
  677. case "type":
  678. olms.interactions[elem_id][1] = val;
  679. logit_scorm("Interaction "+elem_id+"'s type updated",2);
  680. return_value='true';
  681. break;
  682. case "correct_responses":
  683. // Add at the end of the array
  684. olms.interactions[elem_id][4][olms.interactions[elem_id][4].length] = val;
  685. logit_scorm("Interaction "+elem_id+"'s correct_responses not updated",2);
  686. return_value='true';
  687. break;
  688. case "weighting":
  689. olms.interactions[elem_id][3] = val;
  690. logit_scorm("Interaction "+elem_id+"'s weighting updated",2);
  691. return_value='true';
  692. break;
  693. case "student_response":
  694. olms.interactions[elem_id][5] = ''+val;
  695. logit_scorm("Interaction "+elem_id+"'s student_response updated",2);
  696. return_value='true';
  697. break;
  698. case "result":
  699. olms.interactions[elem_id][6] = val;
  700. logit_scorm("Interaction "+elem_id+"'s result updated",2);
  701. return_value='true';
  702. break;
  703. case "latency":
  704. olms.interactions[elem_id][7] = val;
  705. logit_scorm("Interaction "+elem_id+"'s latency updated",2);
  706. return_value='true';
  707. break;
  708. default:
  709. olms.G_LastError = G_NotImplementedError;
  710. olms.G_LastErrorString = 'Not implemented yet';
  711. }
  712. } else if(param.substring(0,15)== 'cmi.objectives.') {
  713. var myres = '';
  714. olms.updatable_vars_list['objectives']=true;
  715. if(myres = param.match(/cmi.objectives.(\d+).(id|score|status)(.*)/)) {
  716. obj_id = myres[1];
  717. //objectives setting should start at 0
  718. if(obj_id > olms.item_objectives.length) {
  719. olms.G_LastError = G_InvalidArgumentError;
  720. olms.G_LastErrorString = 'Invalid argument (objectives)';
  721. return_value = false;
  722. } else {
  723. req_type = myres[2];
  724. if(obj_id == null || obj_id == '') {
  725. ;//do nothing
  726. } else {
  727. if(olms.item_objectives[obj_id]==null) {
  728. olms.item_objectives[obj_id] = ['','','','',''];
  729. }
  730. if( req_type == "id" ) {
  731. //olms.item_objectives[obj_id][0] = val.substring(51,57);
  732. olms.item_objectives[obj_id][0] = val;
  733. logit_scorm("Objective "+obj_id+"'s id updated",2);
  734. return_value = 'true';
  735. } else if ( req_type == "score" ) {
  736. if (myres[3] == '._children'){
  737. return_value = '';
  738. olms.G_LastError = G_InvalidSetValue;
  739. olms.G_LastErrorString = 'Invalid set value, element is a keyword';
  740. } else if (myres[3] == '.raw'){
  741. olms.item_objectives[obj_id][2] = val;
  742. logit_scorm("Objective "+obj_id+"'s score raw updated",2);
  743. return_value = 'true';
  744. } else if (myres[3] == '.max'){
  745. olms.item_objectives[obj_id][3] = val;
  746. logit_scorm("Objective "+obj_id+"'s score max updated",2);
  747. return_value = 'true';
  748. } else if (myres[3] == '.min'){
  749. olms.item_objectives[obj_id][4] = val;
  750. logit_scorm("Objective "+obj_id+"'s score min updated",2);
  751. return_value = 'true';
  752. } else{
  753. return_value = '';
  754. olms.G_LastError = G_NotImplementedError;
  755. olms.G_LastErrorString = 'Not implemented yet';
  756. }
  757. } else if ( req_type == "status" ) {
  758. olms.item_objectives[obj_id][1] = val;
  759. logit_scorm("Objective "+obj_id+"'s status updated",2);
  760. return_value = 'true';
  761. } else {
  762. olms.G_LastError = G_NotImplementedError;
  763. olms.G_LastErrorString = 'Not implemented yet';
  764. }
  765. }
  766. }
  767. }
  768. } else {
  769. olms.G_LastError = G_NotImplementedError;
  770. olms.G_LastErrorString = G_NotImplementedErrorMessage;
  771. }
  772. }
  773. <?php
  774. if ($oLP->force_commit == 1) {
  775. echo " var mycommit = LMSCommit('force');";
  776. }
  777. ?>
  778. return(return_value);
  779. }
  780. /**
  781. * Twin sister of LMSSetValue(). Only provided for backwards compatibility.
  782. */
  783. function SetValue(param, val) {
  784. return LMSSetValue(param, val);
  785. }
  786. /**
  787. * Saves the current data from JS memory to the LMS database
  788. */
  789. function savedata(item_id) {
  790. // Origin can be 'commit', 'finish' or 'terminate' (depending on the calling function)
  791. logit_lms('function savedata(' + item_id + ')', 3);
  792. // Status is NOT modified here see the lp_ajax_save_item.php file
  793. if (olms.lesson_status != '') {
  794. olms.updatable_vars_list['cmi.core.lesson_status'] = true;
  795. }
  796. old_item_id = olms.info_lms_item[0];
  797. var item_to_save = olms.lms_item_id;
  798. logit_lms('item_to_save (original value): ' + item_to_save, 3);
  799. // If saving session_time value, we assume that all the new info is about
  800. // the old item, not the current one
  801. // if (olms.session_time != '' && olms.session_time != '0') {
  802. if (olms.switch_finished == 0) {
  803. logit_lms('item_to_save (changed to): ' + old_item_id, 3);
  804. item_to_save = old_item_id;
  805. }
  806. //Original behaviour
  807. // xajax_save_item_scorm(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, old_item_id);
  808. // Modified version
  809. xajax_save_item_scorm(
  810. olms.lms_lp_id,
  811. olms.lms_user_id,
  812. olms.lms_view_id,
  813. item_to_save,
  814. olms.lms_session_id,
  815. olms.lms_course_id,
  816. olms.finishSignalReceived,
  817. olms.userNavigatesAway,
  818. olms.statusSignalReceived
  819. );
  820. olms.info_lms_item[1] = olms.lms_item_id;
  821. if (olms.item_objectives.length > 0) {
  822. xajax_save_objectives(
  823. olms.lms_lp_id,
  824. olms.lms_user_id,
  825. olms.lms_view_id,
  826. old_item_id,
  827. olms.item_objectives
  828. );
  829. }
  830. olms.execute_stats = false;
  831. // Clean array
  832. olms.variable_to_send = new Array();
  833. }
  834. /**
  835. * Send the Commit signal to the LMS (save the data for this element without
  836. * closing the current process)
  837. * From SCORM 1.2 RTE: If the API Adapter is caching values received from the
  838. * SCO via an LMSSetValue(), this call requires that any values not yet
  839. * persisted by the LMS be persisted.
  840. * @param string Must be empty string for conformance with SCORM 1.2
  841. */
  842. function LMSCommit(val) {
  843. logit_scorm('LMSCommit() + val');
  844. olms.G_LastError = G_NoError ;
  845. olms.G_LastErrorMessage = 'No error';
  846. savedata(olms.lms_item_id);
  847. reinit_updatable_vars_list();
  848. //now changes have been commited, no need to update until next SetValue()
  849. //commit = 'false' ;
  850. return('true');
  851. }
  852. /**
  853. * Twin sister of LMSCommit(). Only provided for backwards compatibility.
  854. */
  855. function Commit(val) {
  856. return LMSCommit(val);
  857. }
  858. /**
  859. * Send the closure signal to the LMS. This saves the data and closes the current SCO.
  860. * From SCORM 1.2 RTE: The SCO must call this when it has determined that it no
  861. * longer needs to communicate with the LMS, if it successfully called
  862. * LMSInitialize at any previous point. This call signifies two things:
  863. * 1.The SCO can be assured that any data set using LMSSetValue() calls has been persisted by the LMS.
  864. * 2.The SCO has finished communicating with the LMS.
  865. * @param string
  866. */
  867. function LMSFinish(val) {
  868. olms.G_LastError = G_NoError ;
  869. olms.G_LastErrorMessage = 'No error';
  870. olms.finishSignalReceived = 1;
  871. // if olms.commit == false, then the SCORM didn't ask for a commit, so we
  872. // should at least report that
  873. if ( !olms.commit ) {
  874. logit_scorm('LMSFinish() (no LMSCommit())',1);
  875. }
  876. logit_scorm('LMSFinish() called on item ' + olms.lms_item_id, 0);
  877. savedata(olms.lms_item_id);
  878. //reinit the commit detector flag
  879. olms.commit = false;
  880. //reinit the list of modified variables
  881. reinit_updatable_vars_list();
  882. return('true');
  883. }
  884. /**
  885. * Twin sister of LMSFinish(). Only provided for backwards compatibility.
  886. */
  887. function Finish(val) {
  888. return LMSFinish(val);
  889. }
  890. /**
  891. * Returns the last error code as a string
  892. * @return string Error code
  893. */
  894. function LMSGetLastError() {
  895. logit_scorm('LMSGetLastError()',1);
  896. return(olms.G_LastError.toString());
  897. }
  898. /**
  899. * Twin sister of LMSGetLastError(). Only provided for backwards compatibility.
  900. */
  901. function GetLastError() {
  902. return LMSGetLastError();
  903. }
  904. /**
  905. * Returns the last error code literal for a given error code
  906. * @param int Error code
  907. * @return string Last error
  908. */
  909. function LMSGetErrorString(errCode){
  910. logit_scorm('LMSGetErrorString()',1);
  911. return(olms.G_LastErrorString);
  912. }
  913. /**
  914. * Twin sister of LMSGetErrorString(). Only provided for backwards compatibility.
  915. */
  916. function GetErrorString(errCode){
  917. return LMSGetErrorString(errCode);
  918. }
  919. /**
  920. * Returns a more explanatory, full English, error message
  921. * @param int Error code
  922. * @return string Diagnostic
  923. */
  924. function LMSGetDiagnostic(errCode){
  925. logit_scorm('LMSGetDiagnostic()',1);
  926. return(API.LMSGetLastError());
  927. }
  928. /**
  929. * Twin sister of LMSGetDiagnostic(). Only provided for backwards compatibility.
  930. */
  931. function GetDiagnostic(errCode){
  932. return LMSGetDiagnostic(errCode);
  933. }
  934. /**
  935. * Acts as a "commit"
  936. * This function is not standard SCORM 1.2 and is probably deprecated in all
  937. * meanings of the term.
  938. * @return string 'true' or 'false', depening on whether the LMS has initialized the SCORM process or not
  939. */
  940. function Terminate() {
  941. if (olms.lms_initialized == 0) {
  942. olms.G_LastError = G_NotInitialized;
  943. olms.G_LastErrorMessage = G_NotInitializedMessage;
  944. logit_scorm('Error '+ G_NotInitialized + G_NotInitializedMessage, 0);
  945. return('false');
  946. } else {
  947. logit_scorm('Terminate()',0);
  948. olms.G_LastError = G_NoError ;
  949. olms.G_LastErrorMessage = 'No error';
  950. olms.commit = true;
  951. savedata(olms.lms_item_id);
  952. return ('true');
  953. }
  954. }
  955. /**
  956. * LMS-specific code that deals with event handling and inter-frames
  957. * messaging/refreshing.
  958. * Note that from now on, the LMS JS code in this library will act as
  959. * a controller, of the MVC pattern, and receive all requests for frame
  960. * updates, then redispatch to any frame concerned.
  961. */
  962. /**
  963. * Defining the AJAX-object class to be made available from other frames
  964. */
  965. function XAJAXobject() {
  966. this.xajax_switch_item_details = xajax_switch_item_details;
  967. this.switch_item = switch_item;
  968. this.xajax_save_objectives = xajax_save_objectives;
  969. this.xajax_save_item = xajax_save_item;
  970. }
  971. /**
  972. * Cross-browser event handling by Scott Andrew
  973. * @param element Element that needs an event attached
  974. * @param string Event type (load, unload, click, keyDown, ...)
  975. * @param string Function name (the event handler)
  976. * @param string used in addEventListener
  977. */
  978. function addEvent(elm, evType, fn, useCapture){
  979. if (elm.addEventListener){
  980. elm.addEventListener(evType, fn, useCapture);
  981. return true;
  982. } else if (elm.attachEvent) {
  983. var r = elm.attachEvent('on' + evType, fn);
  984. } else{
  985. elm['on'+evType] = fn;
  986. }
  987. }
  988. /**
  989. * Add listeners to the page objects. This has to be defined for
  990. * the current context as it acts on objects that should exist
  991. * on the page
  992. * possibly deprecated
  993. * @todo Try to use $(document).unload(lms_save_asset()) instead of the addEvent() method
  994. */
  995. function addListeners(){
  996. //exit if the browser doesn't support ID or tag retrieval
  997. logit_lms('Entering addListeners()', 3);
  998. if (!document.getElementsByTagName){
  999. logit_lms("getElementsByTagName not available", 2);
  1000. return;
  1001. }
  1002. if (!document.getElementById){
  1003. logit_lms("getElementById not available", 2);
  1004. return;
  1005. }
  1006. //assign event handlers to objects
  1007. if (olms.lms_lp_type==1 || olms.lms_item_type=='asset' || olms.lms_item_type == 'document') {
  1008. logit_lms('Chamilo LP or asset');
  1009. //if this path is a Chamilo learnpath, then start manual save
  1010. //when something is loaded in there
  1011. addEvent(window, 'unload', lms_save_asset,false);
  1012. logit_lms('Added event listener lms_save_asset() on window unload', 3);
  1013. }
  1014. logit_lms('Quitting addListeners()');
  1015. }
  1016. /**
  1017. * Save a Chamilo learnpath item's time and mark as completed upon
  1018. * leaving it
  1019. */
  1020. function lms_save_asset() {
  1021. // only for Chamilo lps
  1022. if (olms.execute_stats) {
  1023. olms.execute_stats = false;
  1024. } else {
  1025. olms.execute_stats = true;
  1026. }
  1027. //For scorms do not show stats
  1028. if (olms.lms_lp_type == 2 && olms.lms_lp_item_type != 'document') {
  1029. olms.execute_stats = false;
  1030. }
  1031. if (olms.lms_item_type == 'quiz') {
  1032. olms.execute_stats = true;
  1033. }
  1034. if (olms.lms_lp_type == 1 || olms.lms_item_type == 'asset' || olms.lms_item_type == 'document') {
  1035. logit_lms('lms_save_asset');
  1036. logit_lms('execute_stats :'+ olms.execute_stats);
  1037. xajax_save_item(
  1038. olms.lms_lp_id,
  1039. olms.lms_user_id,
  1040. olms.lms_view_id,
  1041. olms.lms_item_id,
  1042. olms.score,
  1043. olms.max,
  1044. olms.min,
  1045. olms.lesson_status,
  1046. olms.session_time,
  1047. olms.suspend_data,
  1048. olms.lesson_location,
  1049. olms.interactions,
  1050. olms.lms_item_core_exit,
  1051. olms.lms_item_type,
  1052. olms.session_id,
  1053. olms.course_id
  1054. );
  1055. if (olms.item_objectives.length>0) {
  1056. xajax_save_objectives(
  1057. olms.lms_lp_id,
  1058. olms.lms_user_id,
  1059. olms.lms_view_id,
  1060. olms.lms_item_id,
  1061. olms.item_objectives
  1062. );
  1063. }
  1064. }
  1065. }
  1066. /**
  1067. * Save a Chamilo learnpath item's time and mark as completed upon leaving it.
  1068. * Same function as lms_save_asset() but saves it with empty params
  1069. * to use values set from another side in the database. Only used by Chamilo quizzes.
  1070. * Also save the score locally because it hasn't been done through SetValue().
  1071. * Saving the status will be dealt with by the XAJAX function.
  1072. */
  1073. function chamilo_void_save_asset(score, max, min, status) {
  1074. logit_lms('chamilo_void_save_asset('+score+','+max+','+min+','+status+')', 3);
  1075. olms.score = score;
  1076. if ((max == null) || (max == '')){
  1077. max = 100;
  1078. }
  1079. if ((min == null) || (min == '')){
  1080. min = 0;
  1081. }
  1082. //assume a default of 100, otherwise the score will not get saved (see lpi->set_score())
  1083. xajax_save_item(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, olms.lms_item_id, score, max, min, status);
  1084. }
  1085. /**
  1086. * Logs information about SCORM messages into the log frame
  1087. * @param string Message to log
  1088. * @param integer Priority (0 for top priority, 3 for lowest)
  1089. */
  1090. function logit_scorm(message, priority) {
  1091. if (scorm_logs) {
  1092. log_in_log("SCORM: " + message, priority);
  1093. }
  1094. return false;
  1095. }
  1096. function log_in_log(message, priority) {
  1097. // Colorize a little
  1098. var color = "color: black";
  1099. switch (priority) {
  1100. case 0:
  1101. color = "color:red;font-weight:bold";
  1102. break;
  1103. case 1:
  1104. color = "color:orange";
  1105. break;
  1106. case 2:
  1107. color = "color:green";
  1108. break;
  1109. case 3:
  1110. color = "color:blue";
  1111. break;
  1112. }
  1113. if (this.console) {
  1114. // Log in console with syntax colouring
  1115. console.log("%c"+message, color);
  1116. } else {
  1117. window.console.log(message);
  1118. }
  1119. }
  1120. /**
  1121. * Logs information about LMS activity into the log frame
  1122. * @param string Message to log
  1123. * @param integer Priority (0 for top priority, 3 for lowest)
  1124. */
  1125. function logit_lms(message, priority){
  1126. if (scorm_logs) {
  1127. log_in_log("LMS: " + message + ' (# lms_item_id = '+olms.lms_item_id+')', priority);
  1128. }
  1129. return false;
  1130. }
  1131. /**
  1132. * Update the Table Of Contents frame, by changing CSS styles, mostly
  1133. * @param string Action to be taken
  1134. * @param integer Item id to update
  1135. */
  1136. function update_toc(update_action, update_id, change_ids) {
  1137. if (!change_ids || change_ids != 'no') {
  1138. change_ids = 'yes';
  1139. }
  1140. var myelem = $("#toc_"+update_id);
  1141. logit_lms('update_toc("'+update_action+'", '+update_id+')',2);
  1142. if (update_id != 0) {
  1143. // Switch function is broken
  1144. if (update_action == "unhighlight" || update_action == "highlight") {
  1145. if (update_action == "unhighlight") {
  1146. myelem.removeClass('scorm_highlight');
  1147. } else {
  1148. if (change_ids=='yes') {
  1149. olms.lms_next_item = update_id;
  1150. olms.lms_previous_item = update_id;
  1151. }
  1152. myelem.addClass('scorm_highlight');
  1153. }
  1154. } else {
  1155. myelem.removeClass("scorm_not_attempted scorm_incomplete scorm_completed scorm_failed scorm_passed");
  1156. if (update_action == "not attempted") {
  1157. myelem.addClass('scorm_not_attempted');
  1158. } else if (update_action == "incomplete") {
  1159. myelem.addClass('scorm_not_attempted');
  1160. } else if (update_action == "completed") {
  1161. myelem.addClass('scorm_completed');
  1162. } else if (update_action == "failed") {
  1163. myelem.addClass('scorm_failed');
  1164. } else if (update_action == "passed") {
  1165. myelem.addClass('scorm_completed');
  1166. } else if (update_action == "browsed") {
  1167. myelem.addClass('scorm_completed');
  1168. } else {
  1169. logit_lms('Update action unknown',1);
  1170. }
  1171. }
  1172. }
  1173. return true;
  1174. }
  1175. /**
  1176. * Update the stats frame using a reload of the frame to avoid unsynched data
  1177. */
  1178. function update_stats() {
  1179. logit_lms('update_stats()');
  1180. if (olms.execute_stats) {
  1181. try {
  1182. cont_f = document.getElementById('content_id');
  1183. cont_f.src = "lp_controller.php?action=stats";
  1184. cont_f.reload();
  1185. } catch (e) {
  1186. return false;
  1187. }
  1188. }
  1189. olms.execute_stats = false;
  1190. }
  1191. /**
  1192. * Update the stats frame using a reload of the frame to avoid unsynched data
  1193. */
  1194. function update_stats_page() {
  1195. logit_lms('update_stats_page',3);
  1196. var myframe = document.getElementById('content_id');
  1197. var mysrc = myframe.location.href;
  1198. if(mysrc == 'lp_controller.php?action=stats'){
  1199. if(myframe && myframe.src){
  1200. var mysrc = myframe.src;
  1201. myframe.src = mysrc;
  1202. }
  1203. // = mysrc; //refresh page
  1204. }
  1205. return true;
  1206. }
  1207. /**
  1208. * Updates the progress bar with the new status. Prevents the need of a page refresh and flickering
  1209. * @param integer Number of completed items
  1210. * @param integer Number of items in total
  1211. * @param string Display mode (absolute 'abs' or percentage '%').Defaults to %
  1212. */
  1213. function update_progress_bar(nbr_complete, nbr_total, mode) {
  1214. logit_lms('update_progress_bar('+nbr_complete+', '+nbr_total+', '+mode+')',3);
  1215. logit_lms(
  1216. 'update_progress_bar with params: lms_lp_id= ' + olms.lms_lp_id +
  1217. ', lms_view_id= '+ olms.lms_view_id + ' lms_user_id= '+ olms.lms_user_id,
  1218. 3
  1219. );
  1220. if (mode == '') {
  1221. mode='%';
  1222. }
  1223. if (nbr_total == 0) {
  1224. nbr_total=1;
  1225. }
  1226. var percentage = (nbr_complete/nbr_total)*100;
  1227. percentage = Math.round(percentage);
  1228. var progress_bar = $("#progress_bar_value");
  1229. progress_bar.css('width', percentage + "%");
  1230. var mytext = '';
  1231. switch(mode){
  1232. case 'abs':
  1233. mytext = nbr_complete + '/' + nbr_total;
  1234. break;
  1235. case '%':
  1236. default:
  1237. mytext = percentage + '%';
  1238. break;
  1239. }
  1240. progress_bar.html(mytext);
  1241. return true;
  1242. }
  1243. /**
  1244. * Analyses the variables that have been modified through this SCO's life and
  1245. * put them into an array for later shipping to lp_ajax_save_item.php
  1246. * @return array Array of SCO variables
  1247. */
  1248. function process_scorm_values() {
  1249. logit_scorm('process_scorm_values()');
  1250. for (i=0; i < olms.scorm_variables.length; i++) {
  1251. if (olms.updatable_vars_list[olms.scorm_variables[i]]) {
  1252. olms.variable_to_send.push(olms.scorm_variables[i]);
  1253. }
  1254. }
  1255. return olms.variable_to_send;
  1256. }
  1257. /**
  1258. * Reinitializes the SCO's modified variables to an empty list.
  1259. * @return void
  1260. * @uses The global updatable_vars_list array to register this
  1261. */
  1262. function reinit_updatable_vars_list() {
  1263. logit_scorm('Cleaning updatable_vars_list: reinit_updatable_vars_list');
  1264. for (i=0;i < olms.scorm_variables.length;i++) {
  1265. if (olms.updatable_vars_list[olms.scorm_variables[i]]) {
  1266. olms.updatable_vars_list[olms.scorm_variables[i]]=false;
  1267. }
  1268. }
  1269. olms.lesson_status='';
  1270. }
  1271. /**
  1272. * Function that handles the saving of an item and switching from an item to another.
  1273. * Once called, this function should be able to do the whole process of
  1274. * (1) saving the current item,
  1275. * (2) refresh all the values inside the SCORM API object,
  1276. * (3) open the new item into the content_id frame,
  1277. * (4) refresh the table of contents
  1278. * (5) refresh the progress bar (completion)
  1279. * (6) refresh the message frame
  1280. * @param integer Chamilo ID for the current item
  1281. * @param string This parameter can be a string specifying the next
  1282. * item (like 'next', 'previous', 'first' or 'last') or the id to the next item
  1283. */
  1284. function switch_item(current_item, next_item){
  1285. // backup these params
  1286. var orig_current_item = current_item;
  1287. var orig_next_item = next_item;
  1288. var orig_lesson_status = olms.lesson_status;
  1289. var orig_item_type = olms.lms_item_types['i'+current_item];
  1290. var next_item_type = olms.lms_item_types['i'+next_item];
  1291. if (olms.statusSignalReceived == 0 && olms.lesson_status != 'not attempted') {
  1292. // In this situation, the status can be considered set as it was clearly
  1293. // set in a previous stage
  1294. olms.statusSignalReceived = 1;
  1295. }
  1296. logit_lms('switch_item() called with params '+olms.lms_item_id+' and '+next_item+'',2);
  1297. /*
  1298. There are four "cases" for switching items:
  1299. (1) asset switching to asset
  1300. We need to save, then switch
  1301. (2) asset switching to sco
  1302. We need to save, switching not necessary (LMSInitialize does the job)
  1303. (3) sco switching to asset
  1304. We need to switch the document in the content frame, but we cannot
  1305. switch the item details, otherwise the LMSFinish() call (that *must*
  1306. be triggered by the SCO when it unloads) will use bad values. However,
  1307. we need to load the new asset's context once the SCO has unloaded
  1308. (4) sco switching to sco
  1309. We don't neet to switch nor commit, LMSFinish() on unload and
  1310. LMSInitialize on load will do the job
  1311. In any case, we need to change the current document frame.
  1312. These cases, although clear here, are however very difficult to implement
  1313. */
  1314. if (orig_item_type != 'sco') {
  1315. if (next_item_type != 'sco' ) {
  1316. logit_lms('Case 1 - current != sco and next != sco');
  1317. } else {
  1318. logit_lms('Case 2 - current != sco but next == sco');
  1319. }
  1320. xajax_save_item(
  1321. olms.lms_lp_id,
  1322. olms.lms_user_id,
  1323. olms.lms_view_id,
  1324. olms.lms_item_id,
  1325. olms.score,
  1326. olms.max,
  1327. olms.min,
  1328. olms.lesson_status,
  1329. olms.asset_timer,
  1330. olms.suspend_data,
  1331. olms.lesson_location,
  1332. olms.interactions,
  1333. olms.lms_item_core_exit,
  1334. olms.session_id,
  1335. olms.course_id,
  1336. olms.finishSignalReceived,
  1337. 1,
  1338. olms.statusSignalReceived
  1339. );
  1340. xajax_switch_item_details(
  1341. olms.lms_lp_id,
  1342. olms.lms_user_id,
  1343. olms.lms_view_id,
  1344. olms.lms_item_id,
  1345. next_item
  1346. );
  1347. } else {
  1348. if (next_item_type != 'sco') {
  1349. logit_lms('Case 3 - current == sco but next != sco');
  1350. } else {
  1351. logit_lms('Case 4 - current == sco and next == sco');
  1352. }
  1353. xajax_save_item_scorm(
  1354. olms.lms_lp_id,
  1355. olms.lms_user_id,
  1356. olms.lms_view_id,
  1357. olms.lms_item_id,
  1358. olms.lms_session_id,
  1359. olms.lms_course_id,
  1360. olms.finishSignalReceived,
  1361. 1,
  1362. olms.statusSignalReceived
  1363. );
  1364. reinit_updatable_vars_list();
  1365. xajax_switch_item_toc(
  1366. olms.lms_lp_id,
  1367. olms.lms_user_id,
  1368. olms.lms_view_id,
  1369. olms.lms_item_id,
  1370. next_item
  1371. );
  1372. if (olms.item_objectives.length>0) {
  1373. xajax_save_objectives(
  1374. olms.lms_lp_id,
  1375. olms.lms_user_id,
  1376. olms.lms_view_id,
  1377. olms.lms_item_id,
  1378. olms.item_objectives
  1379. );
  1380. }
  1381. }
  1382. /**
  1383. * Because of SCORM 1.2's special rule about unsent commits and the fact
  1384. * that a SCO should be SET TO 'completed' IF NO STATUS WAS SENT (and
  1385. * then some checks have to be done on score), we have to force a
  1386. * special commit here to avoid getting to the next element with a
  1387. * missing prerequisite. The 'onunload' event is treated with
  1388. * savedata_onunload(), and doesn't need to be triggered at any
  1389. * particular time, but here we are in the case of switching to another
  1390. * item, so this is particularly important to complete the element in
  1391. * time.
  1392. * However, this cannot be initiated from the JavaScript, mainly
  1393. * because another onunload event can be triggered by the SCO itself,
  1394. * which can set, for example, the status to incomplete while the
  1395. * status has already been set to "completed" by the hand-made
  1396. * savedata() (and then the status cannot be "incompleted"
  1397. * anymore)
  1398. */
  1399. /*
  1400. if (olms.lms_item_type=='sco' &&
  1401. olms.lesson_status != 'completed' &&
  1402. olms.lesson_status != 'passed' &&
  1403. olms.lesson_status != 'browsed' &&
  1404. olms.lesson_status != 'incomplete' &&
  1405. olms.lesson_status != 'failed'
  1406. ) {
  1407. // savedata() with olms.finishSignalReceived == 1 treats the special
  1408. // condition and saves the new status to the database, so
  1409. // switch_item_details() enjoys the new status
  1410. savedata(olms.lms_item_id);
  1411. }
  1412. xajax_save_item(
  1413. olms.lms_lp_id,
  1414. olms.lms_user_id,
  1415. olms.lms_view_id,
  1416. olms.lms_item_id,
  1417. olms.score, olms.max,
  1418. olms.min,
  1419. olms.lesson_status,
  1420. olms.session_time,
  1421. olms.suspend_data,
  1422. olms.lesson_location,
  1423. olms.interactions,
  1424. olms.lms_item_core_exit,
  1425. olms.session_id,
  1426. olms.course_id,
  1427. olms.finishSignalReceived,
  1428. 1,
  1429. olms.statusSignalReceived
  1430. );
  1431. */
  1432. olms.execute_stats = false;
  1433. // Considering info_lms_item[0] is initially the oldest and info_lms_item[1]
  1434. // is the newest item, and considering we are done switching the items now,
  1435. // we need to update these markers so that the new item is loaded when
  1436. // changing the document in the content frame
  1437. if (olms.info_lms_item[1]==next_item && next_item!='next' && next_item!='previous') {
  1438. olms.info_lms_item[0]=next_item;
  1439. olms.info_lms_item[1]=next_item;
  1440. } else {
  1441. if (next_item!='next' && next_item!='previous') {
  1442. olms.info_lms_item[0]=olms.info_lms_item[1];
  1443. olms.info_lms_item[1]=next_item;
  1444. }
  1445. }
  1446. if (olms.info_lms_item[0]==next_item && next_item!='next' && next_item!='previous') {
  1447. olms.info_lms_item[0]=next_item;
  1448. olms.info_lms_item[1]=next_item;
  1449. } else {
  1450. if (next_item!='next' && next_item!='previous') {
  1451. olms.info_lms_item[0]=olms.info_lms_item[0];
  1452. olms.info_lms_item[1]=next_item;
  1453. }
  1454. }
  1455. //(3) open the new item in the content_id frame
  1456. switch (next_item){
  1457. case 'next':
  1458. next_item = olms.lms_next_item;
  1459. olms.info_lms_item[0] = olms.info_lms_item[1];
  1460. olms.info_lms_item[1] = olms.lms_next_item;
  1461. break;
  1462. case 'previous':
  1463. next_item = olms.lms_previous_item;
  1464. olms.info_lms_item[0] = olms.info_lms_item[1];
  1465. olms.info_lms_item[1] = olms.lms_previous_item;
  1466. break;
  1467. default:
  1468. break;
  1469. }
  1470. var mysrc = 'lp_controller.php?action=content&lp_id=' + olms.lms_lp_id +
  1471. '&item_id=' + next_item + '&cidReq=' + olms.lms_course_code + '&id_session=' + olms.lms_session_id;
  1472. var cont_f = $("#content_id");
  1473. <?php if ($oLP->mode == 'fullscreen') { ?>
  1474. cont_f = window.open('' + mysrc, 'content_id', 'toolbar=0,location=0,status=0,scrollbars=1,resizable=1');
  1475. cont_f.onload=function(){
  1476. olms.info_lms_item[0]=olms.info_lms_item[1];
  1477. }
  1478. cont_f.onunload=function(){
  1479. olms.info_lms_item[0]=olms.info_lms_item[1];
  1480. }
  1481. <?php } else { ?>
  1482. log_in_log('loading '+mysrc+' in frame');
  1483. cont_f.attr("src",mysrc);
  1484. <?php } ?>
  1485. if (olms.lms_lp_type==1 || olms.lms_item_type == 'asset' || olms.lms_item_type == 'document') {
  1486. xajax_start_timer();
  1487. }
  1488. //(4) refresh the audio player if needed
  1489. $.ajax({
  1490. type: "POST",
  1491. url: "lp_nav.php",
  1492. data: "",
  1493. beforeSend: function() {
  1494. $.each($('audio'), function () {
  1495. var player = new MediaElementPlayer($(this));
  1496. player.pause();
  1497. });
  1498. },
  1499. success: function(tmp_data) {
  1500. if ($("#lp_media_file").length != 0) {
  1501. $("#lp_media_file").html(tmp_data);
  1502. }
  1503. }
  1504. });
  1505. olms.switch_finished = 0; //only changed back once LMSInitialize() happens
  1506. return true;
  1507. }
  1508. /**
  1509. * Save a specific item (with its interactions, if any) into the LMS through
  1510. * an AJAX call to lp_ajax_save_item.php.
  1511. * Because of the need to pass an array, we have to build the parameters
  1512. * manually into GET[].
  1513. * This function has a twin sister for SCO elements (xajax_save_item_scorm)
  1514. * which takes into account the interactions.
  1515. * @param int ID of the learning path (for the LMS)
  1516. * @param int ID of the user
  1517. * @param int ID of the view of this learning path
  1518. * @param int ID of the item currently looked at
  1519. * @param float Score
  1520. * @param float Max score
  1521. * @param float Min score
  1522. * @param string Lesson status
  1523. * @param string Current session time (in 'xxxx:xx:xx.xx' format)
  1524. * @param string Suspend data (maximum 255 chars)
  1525. * @param string Lesson location (which page we've reached in the SCO)
  1526. * @param array Interactions
  1527. * @param string Core exit value (up to 4096 chars)
  1528. * @return void
  1529. * @uses lp_ajax_save_item.php through an AJAX call
  1530. */
  1531. function xajax_save_item(
  1532. lms_lp_id,
  1533. lms_user_id,
  1534. lms_view_id,
  1535. lms_item_id,
  1536. score,
  1537. max,
  1538. min,
  1539. lesson_status,
  1540. session_time,
  1541. suspend_data,
  1542. lesson_location,
  1543. interactions,
  1544. lms_item_core_exit,
  1545. item_type,
  1546. session_id,
  1547. course_id,
  1548. finishSignalReceived,
  1549. userNavigatesAway,
  1550. statusSignalReceived
  1551. ) {
  1552. var params = '';
  1553. if (typeof(finishSignalReceived) == 'undefined') {
  1554. finishSignalReceived = 0;
  1555. }
  1556. if (typeof(userNavigatesAway) == 'undefined') {
  1557. userNavigatesAway = 0;
  1558. }
  1559. if (typeof(statusSignalReceived) == 'undefined') {
  1560. statusSignalReceived = 0;
  1561. }
  1562. params += 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id;
  1563. params += '&iid='+lms_item_id+'&s='+score+'&max='+max+'&min='+min;
  1564. params += '&status='+lesson_status+'&t='+session_time;
  1565. params += '&suspend='+suspend_data+'&loc='+lesson_location;
  1566. params += '&core_exit='+lms_item_core_exit;
  1567. params += '&session_id='+session_id;
  1568. params += '&course_id='+course_id;
  1569. params += '&finishSignalReceived='+finishSignalReceived;
  1570. params += '&userNavigatesAway='+userNavigatesAway;
  1571. params += '&statusSignalReceived='+statusSignalReceived;
  1572. // console.info(session_time);
  1573. if (olms.lms_lp_type == 1 || item_type == 'document') {
  1574. logit_lms('xajax_save_item with params:' + params,3);
  1575. $.ajax({
  1576. type:"POST",
  1577. data: params,
  1578. url: "lp_ajax_save_item.php",
  1579. dataType: "script",
  1580. async: false
  1581. });
  1582. }
  1583. }
  1584. /**
  1585. * Save a SCORM item's variables, getting its SCORM values from
  1586. * updatable_vars_list. Takes interactions into account and considers whether
  1587. * variables have been modified or not.
  1588. * @param int ID of the learning path
  1589. * @param int ID of the user
  1590. * @param int ID of the view
  1591. * @param int ID of the item
  1592. * @param bool 1 if this call comes from a "LMSFinish()" call, 0 or nothing otherwise
  1593. * @return void
  1594. * @uses olms.updatable_vars_list
  1595. * @uses lp_ajax_save_item.php through an AJAX call
  1596. */
  1597. function xajax_save_item_scorm(
  1598. lms_lp_id,
  1599. lms_user_id,
  1600. lms_view_id,
  1601. lms_item_id,
  1602. session_id,
  1603. course_id,
  1604. finishSignalReceived,
  1605. userNavigatesAway,
  1606. statusSignalReceived
  1607. )
  1608. {
  1609. if (typeof(finishSignalReceived) == 'undefined') {
  1610. finishSignalReceived = 0;
  1611. }
  1612. if (typeof(userNavigatesAway) == 'undefined') {
  1613. userNavigatesAway = 0;
  1614. }
  1615. if (typeof(statusSignalReceived) == 'undefined') {
  1616. statusSignalReceived = 0;
  1617. }
  1618. var is_interactions='false';
  1619. var params = 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id+'&iid='+lms_item_id;
  1620. // The missing arguments will be ignored by lp_ajax_save_item.php
  1621. //params += '&s=&max=&min=&status=&t=&suspend=&loc=&interact=&core_exit=';
  1622. params += '&session_id='+session_id;
  1623. params += '&course_id='+course_id;
  1624. params += '&finishSignalReceived='+finishSignalReceived;
  1625. params += '&userNavigatesAway='+userNavigatesAway;
  1626. params += '&statusSignalReceived='+statusSignalReceived;
  1627. var my_scorm_values = new Array();
  1628. my_scorm_values = process_scorm_values();
  1629. for (k=0; k < my_scorm_values.length; k++) {
  1630. if (my_scorm_values[k]=='cmi.core.session_time') {
  1631. params += '&t='+olms.session_time;
  1632. } else if (my_scorm_values[k]=='cmi.core.lesson_status' && olms.lesson_status!='') {
  1633. params += '&status='+olms.lesson_status;
  1634. } else if (my_scorm_values[k]=='cmi.core.score.raw') {
  1635. params += '&s='+olms.score;
  1636. } else if (my_scorm_values[k]=='cmi.core.score.max') {
  1637. params += '&max='+olms.max;
  1638. } else if (my_scorm_values[k]=='cmi.core.score.min') {
  1639. params += '&min='+olms.min;
  1640. } else if (my_scorm_values[k]=='cmi.core.lesson_location') {
  1641. params += '&loc='+olms.lesson_location;
  1642. } else if (my_scorm_values[k]=='cmi.completion_status') {
  1643. } else if (my_scorm_values[k]=='cmi.score.scaled') {
  1644. } else if (my_scorm_values[k]=='cmi.suspend_data') {
  1645. params += '&suspend='+olms.suspend_data;
  1646. } else if (my_scorm_values[k]=='cmi.completion_status') {
  1647. } else if (my_scorm_values[k]=='cmi.core.exit') {
  1648. params += '&core_exit='+olms.lms_item_core_exit;
  1649. }
  1650. if (my_scorm_values[k]=='interactions') {
  1651. is_interactions='true';
  1652. } else {
  1653. is_interactions='false';
  1654. }
  1655. }
  1656. if (is_interactions == 'true') {
  1657. interact_string = '';
  1658. temp = '';
  1659. for (i in olms.interactions) {
  1660. interact_string += '&interact['+i+']=';
  1661. interact_temp = '[';
  1662. for (j in olms.interactions[i]) {
  1663. temp = olms.interactions[i][j];
  1664. temp = ''+temp; // if temp == 1 there are problems with indexOf and an integer number
  1665. //this fix when an interaction have ',' i.e: {a,b,c,d} is replace to {a@.|@b@.|@c@.|@d} see DT#4444
  1666. while(temp.indexOf(',') >= 0){
  1667. temp = temp.replace(',','@.|@');
  1668. };
  1669. interact_temp +=temp+',';
  1670. }
  1671. interact_temp = interact_temp.substr(0,(interact_temp.length-2)) + ']';
  1672. // interact_string += encodeURIComponent(interact_temp);
  1673. interact_string += interact_temp;
  1674. }
  1675. //interact_string = encodeURIComponent(interact_string.substr(0,(interact_string.length-1)));
  1676. params += interact_string;
  1677. is_interactions='false';
  1678. }
  1679. logit_lms('xajax_save_item_scorm with params:' + params, 3);
  1680. $.ajax({
  1681. type:"POST",
  1682. data: params,
  1683. url: "lp_ajax_save_item.php",
  1684. dataType: "script",
  1685. async: false
  1686. });
  1687. params = '';
  1688. my_scorm_values = null;
  1689. }
  1690. /**
  1691. * Starts the timer with the server clock time.
  1692. * @return void
  1693. * @todo check the timer stuff really works and rename function to startTimer()
  1694. * @uses lp_ajax_start_timer.php
  1695. */
  1696. function xajax_start_timer() {
  1697. logit_lms('xajax_start_timer() called',3);
  1698. $.ajax({
  1699. type: "GET",
  1700. url: "lp_ajax_start_timer.php",
  1701. dataType: "script",
  1702. async: false,
  1703. success: function(time) {
  1704. olms.asset_timer = time;
  1705. olms.asset_timer_total = 0;
  1706. logit_lms('xajax_start_timer result: ' + time,3);
  1707. var date = new Date(time * 1000);
  1708. logit_lms('xajax_start_timer result: ' + date.toString(),3);
  1709. }
  1710. });
  1711. }
  1712. /**
  1713. * Save a specific item's objectives into the LMS through an Synch JAX call
  1714. * @param int ID of the learning path
  1715. * @param int ID of the user
  1716. * @param int ID of the view
  1717. * @param int ID of the item
  1718. * @param array SCO's recorded objectives
  1719. * @uses lp_ajax_save_objectives.php
  1720. */
  1721. function xajax_save_objectives(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,item_objectives) {
  1722. var params = '';
  1723. params += 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id;
  1724. params += '&iid='+lms_item_id;
  1725. obj_string = '';
  1726. logit_lms('xajax_save_objectives with params:' + params, 3);
  1727. for (i in item_objectives){
  1728. obj_string += '&objectives['+i+']=';
  1729. obj_temp = '[';
  1730. for (j in item_objectives[i]) {
  1731. obj_temp += item_objectives[i][j]+',';
  1732. }
  1733. obj_temp = obj_temp.substr(0,(obj_temp.length-2)) + ']';
  1734. obj_string += encodeURIComponent(obj_temp);
  1735. }
  1736. params += obj_string;
  1737. $.ajax({
  1738. type: "POST",
  1739. data: params,
  1740. url: "lp_ajax_save_objectives.php",
  1741. dataType: "script",
  1742. async: false
  1743. });
  1744. }
  1745. /**
  1746. * Switch between two items through an AJAX call.
  1747. * @param int ID of the learning path
  1748. * @param int ID of the user
  1749. * @param int ID of the view
  1750. * @param int ID of the item
  1751. * @param int ID of the next item
  1752. * @uses lp_ajax_switch_item.php
  1753. */
  1754. function xajax_switch_item_details(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,next_item) {
  1755. var params = {
  1756. 'lid': lms_lp_id,
  1757. 'uid': lms_user_id,
  1758. 'vid': lms_view_id,
  1759. 'iid': lms_item_id,
  1760. 'next': next_item
  1761. };
  1762. logit_lms('xajax_switch_item_details with params:' + params, 3);
  1763. $.ajax({
  1764. type: "POST",
  1765. data: params,
  1766. url: "lp_ajax_switch_item.php",
  1767. dataType: "script",
  1768. async: false
  1769. });
  1770. }
  1771. /**
  1772. * Switch between two items through an AJAX call, but only update the TOC and
  1773. * progress bar.
  1774. * @param int ID of the learning path
  1775. * @param int ID of the user
  1776. * @param int ID of the view
  1777. * @param int ID of the item
  1778. * @param int ID of the next item
  1779. * @uses lp_ajax_switch_toc.php
  1780. */
  1781. function xajax_switch_item_toc(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, next_item) {
  1782. var params = {
  1783. 'lid': lms_lp_id,
  1784. 'uid': lms_user_id,
  1785. 'vid': lms_view_id,
  1786. 'iid': lms_item_id,
  1787. 'next': next_item
  1788. };
  1789. logit_lms('xajax_switch_item_toc');
  1790. $.ajax({
  1791. type: "POST",
  1792. data: params,
  1793. url: "lp_ajax_switch_item_toc.php",
  1794. dataType: "script",
  1795. async: false
  1796. });
  1797. }
  1798. /**
  1799. * Allow attach the glossary terms into html document of scorm. This has
  1800. * nothing to do with SCORM itself, and should not interfere w/ SCORM either.
  1801. * @param string automatic or manual values are allowed
  1802. */
  1803. function attach_glossary_into_scorm(type) {
  1804. var f = $('#content_id')[0];
  1805. //Prevents "f is undefined" javascript error
  1806. if (f == null) {
  1807. logit_lms('attach_glossary_into_scorm failed', 0);
  1808. return false;
  1809. }
  1810. try {
  1811. var doc = f.contentWindow ? f.contentWindow.document : f.contentDocument ? f.contentDocument : f.document;
  1812. } catch (ex) { }
  1813. var $frame_content = $('body',doc);
  1814. var my_text=$frame_content.html();
  1815. my_protocol = location.protocol;
  1816. my_pathname=location.pathname;
  1817. work_path = my_pathname.substr(0,my_pathname.indexOf('/courses/'));
  1818. var ajaxRequestUrl = '<?php echo api_get_path(WEB_CODE_PATH).'glossary/glossary_ajax_request.php'; ?>';
  1819. if (type == 'automatic') {
  1820. $.ajax({
  1821. contentType: "application/x-www-form-urlencoded",
  1822. beforeSend: function(object) {
  1823. },
  1824. type: "POST",
  1825. url: ajaxRequestUrl,
  1826. data: "glossary_data=true",
  1827. success: function(datas) {
  1828. if (datas.length==0) {
  1829. return false;
  1830. }
  1831. // glossary terms
  1832. data_terms=datas.split("[|.|_|.|-|.|]");
  1833. var complex_array = new Array();
  1834. var cp_complex_array = new Array();
  1835. for(i=0;i < data_terms.length;i++) {
  1836. specific_terms= data_terms[i].split("__|__|");
  1837. var real_term = specific_terms[1]; // glossary term
  1838. var real_code = specific_terms[0]; // glossary id
  1839. complex_array[real_code] = real_term;
  1840. cp_complex_array[real_code] = real_term;
  1841. }
  1842. complex_array.reverse();
  1843. for (var my_index in complex_array) {
  1844. n = complex_array[my_index];
  1845. if (n == null) {
  1846. n = '';
  1847. } else {
  1848. for (var cp_my_index in cp_complex_array) {
  1849. cp_data = cp_complex_array[cp_my_index];
  1850. if (cp_data == null) {
  1851. cp_data = '';
  1852. } else {
  1853. if (cp_data == n) {
  1854. my_index = cp_my_index;
  1855. }
  1856. }
  1857. }
  1858. //alert(n + ' ' + my_index);
  1859. $("iframe").contents().find('body').removeHighlight().highlight(n,my_index)
  1860. }
  1861. }
  1862. var complex_array = new Array();
  1863. $("iframe").contents().find("body").on("click", ".glossary-ajax", function() {
  1864. div_show_id="div_show_id";
  1865. div_content_id="div_content_id";
  1866. $("iframe").contents().find("body").
  1867. append('<div id="div_show_id"><div id="div_content_id">&nbsp;</div></div>');
  1868. show_dialog = $("iframe").contents().find("div#"+div_show_id);
  1869. show_description = $("iframe").contents().find("div#"+div_content_id);
  1870. var $target = $(this);
  1871. if ($("#learning_path_left_zone").is(':visible') ) {
  1872. var extra_left = $("#learning_path_left_zone").width() + 20;
  1873. } else {
  1874. var extra_left = 0;
  1875. }
  1876. show_dialog.dialog({
  1877. autoOpen: false,
  1878. width: 600,
  1879. height: 200,
  1880. position: { my: 'left top', at: 'right top', of: $target, offset: extra_left+", 0"},
  1881. close: function(){
  1882. show_dialog.remove();
  1883. show_description.remove();
  1884. }
  1885. });
  1886. notebook_id=$(this).attr("name");
  1887. data_notebook=notebook_id.split("link");
  1888. my_glossary_id=data_notebook[1];
  1889. $.ajax({
  1890. contentType: "application/x-www-form-urlencoded",
  1891. type: "POST",
  1892. url: ajaxRequestUrl,
  1893. data: "glossary_id="+my_glossary_id,
  1894. success: function(data) {
  1895. show_description.html(data);
  1896. show_dialog.dialog("open");
  1897. }
  1898. });
  1899. });
  1900. }
  1901. });
  1902. } else {
  1903. if ('manual') {
  1904. $("iframe").contents().find("body").on("click", ".glossary", function() {
  1905. is_glossary_name = $(this).html();
  1906. div_show_id="div_show_id";
  1907. div_content_id="div_content_id";
  1908. $("iframe").contents().find("body").
  1909. append('<div id="div_show_id"><div id="div_content_id">&nbsp;</div></div>');
  1910. show_dialog = $("iframe").contents().find("div#"+div_show_id);
  1911. show_description = $("iframe").contents().find("div#"+div_content_id);
  1912. var $target = $(this);
  1913. if ($("#learning_path_left_zone").is(':visible') ) {
  1914. var extra_left = $("#learning_path_left_zone").width() + 20;
  1915. } else {
  1916. var extra_left = 0;
  1917. }
  1918. //$("#"+div_show_id).dialog("destroy");
  1919. show_dialog.dialog({
  1920. autoOpen: false,
  1921. width: 600,
  1922. height: 200,
  1923. position: { my: 'left top', at: 'right top', of: $target, offset: extra_left+", 0"},
  1924. close: function(){
  1925. show_dialog.remove();
  1926. show_description.remove();
  1927. }
  1928. });
  1929. $.ajax({
  1930. contentType: "application/x-www-form-urlencoded",
  1931. type: "POST",
  1932. url: ajaxRequestUrl,
  1933. data: "glossary_name="+is_glossary_name,
  1934. success: function(data) {
  1935. show_description.html(data);
  1936. show_dialog.dialog("open");
  1937. }
  1938. });
  1939. });
  1940. }
  1941. }
  1942. }