scorm_api.php 65 KB

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