scorm_api.php 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521
  1. <?php // $Id: scorm_api.php 20394 2009-05-07 20:11:37Z iflorespaz $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2009 Dokeos SPRL
  6. Copyright (c) Denes Nagy (darkden@freemail.hu)
  7. For a full list of contributors, see "credits.txt".
  8. The full license can be read in "license.txt".
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. See the GNU General Public License for more details.
  14. Contact: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium, info@dokeos.com
  15. ==============================================================================
  16. */
  17. /**
  18. ==============================================================================
  19. * API event handler functions for Scorm 1.1 and 1.2 and 1.3
  20. *
  21. * @author Denes Nagy <darkden@freemail.hu>
  22. * @author Yannick Warnier <ywarnier@beeznest.org>
  23. * @version v 1.0
  24. * @access public
  25. * @package dokeos.learnpath
  26. ==============================================================================
  27. */
  28. /**
  29. * This script is divided into three sections.
  30. * The first section (below) is the initialisation part.
  31. * The second section is the SCORM object part
  32. * The third section defines the event handlers for Dokeos' internal messaging
  33. * and frames refresh
  34. */
  35. /*
  36. ==============================================================================
  37. INIT SECTION
  38. ==============================================================================
  39. */
  40. // if you open the imsmanifest.xml via local machine (f.ex.: file://c:/...), then the Apiwrapper.js
  41. // of Maritime Navigation when trying to execute this row
  42. // var result = api.LMSInitialize("");
  43. // get the error response : you are not authorized to call this function
  44. //flag to allow for anonymous user - needs to be set before global.inc.php
  45. $use_anonymous = true;
  46. require_once('back_compat.inc.php');
  47. require_once('learnpath.class.php');
  48. require_once('learnpathItem.class.php');
  49. require_once('scorm.class.php');
  50. // Is this needed? This is probabaly done in the header file
  51. //$_user = $_SESSION['_user'];
  52. $file = (empty($_SESSION['file'])?'':$_SESSION['file']);
  53. $oLP = unserialize($_SESSION['lpobject']);
  54. $oItem = $oLP->items[$oLP->current];
  55. if(!is_object($oItem)){
  56. error_log('New LP - scorm_api - Could not load oItem item',0);
  57. exit;
  58. }
  59. $autocomplete_when_80pct = 0;
  60. /*
  61. ==============================================================================
  62. JavaScript Functions
  63. ==============================================================================
  64. */
  65. ?>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
  66. var lms_logs=0; //debug log level for LMS actions. 0=none, 1=light, 2=a lot, 3=all
  67. //logit_lms('scormfunctions.php included',0);
  68. function APIobject() {
  69. this.LMSInitialize=LMSInitialize; //for Scorm 1.2
  70. this.Initialize=LMSInitialize; //for Scorm 1.3
  71. this.LMSGetValue=LMSGetValue;
  72. this.GetValue=LMSGetValue;
  73. this.LMSSetValue=LMSSetValue;
  74. this.SetValue=LMSSetValue;
  75. this.LMSCommit=LMSCommit;
  76. this.Commit=LMSCommit;
  77. this.LMSFinish=LMSFinish;
  78. this.Finish=LMSFinish;
  79. this.LMSGetLastError=LMSGetLastError;
  80. this.GetLastError=LMSGetLastError;
  81. this.LMSGetErrorString=LMSGetErrorString;
  82. this.GetErrorString=LMSGetErrorString;
  83. this.LMSGetDiagnostic=LMSGetDiagnostic;
  84. this.GetDiagnostic=LMSGetDiagnostic;
  85. this.Terminate=Terminate; //only in Scorm 1.3
  86. this.save_asset = dokeos_save_asset;
  87. this.void_save_asset = dokeos_void_save_asset;
  88. }
  89. //it is not sure that the scos use the above declarations
  90. API = new APIobject(); //for scorm 1.2
  91. api = API;
  92. //api = new APIobject(); //for scorm 1.2
  93. API_1484_11 = new APIobject(); //for scorm 1.3
  94. api_1484_11 = API_1484_11;
  95. //api_1484_11 = new APIobject(); //for scorm 1.3
  96. // Error codes
  97. var G_NoError = 0;
  98. var G_GeneralException = 101;
  99. var G_ServerBusy = 102; // this is not in the Scorm1.2_Runtime document
  100. var G_InvalidArgumentError = 201;
  101. var G_ElementCannotHaveChildren = 202;
  102. var G_ElementIsNotAnArray = 203;
  103. var G_NotInitialized = 301;
  104. var G_NotImplementedError = 401;
  105. var G_InvalidSetValue = 402;
  106. var G_ElementIsReadOnly = 403;
  107. var G_ElementIsWriteOnly = 404;
  108. var G_IncorrectDataType = 405;
  109. // Error messages
  110. var G_NoErrorMessage = '';
  111. var G_GeneralExceptionMessage = 'General Exception';
  112. var G_ServerBusyMessage = 'Server busy'; // this is not in the Scorm1.2_Runtime document
  113. var G_InvalidArgumentErrorMessage = 'Invalid argument error';
  114. var G_ElementCannotHaveChildrenMessage = 'Element cannot have children';
  115. var G_ElementIsNotAnArrayMessage = 'Element not an array. Cannot have count';
  116. var G_NotInitializedMessage = 'Not initialized';
  117. var G_NotImplementedErrorMessage = 'Not implemented error';
  118. var G_InvalidSetValueMessage = 'Invalid set value, element is a keyword';
  119. var G_ElementIsReadOnlyMessage = 'Element is read only';
  120. var G_ElementIsWriteOnlyMessage = 'Element is write only';
  121. var G_IncorrectDataTypeMessage = 'Incorrect Data Type';
  122. var G_LastError = G_NoError ;
  123. var G_LastErrorMessage = 'No error';
  124. //this is not necessary and is only provided to make bad Articulate contents shut up (and not trigger useless JS messages)
  125. var G_LastErrorString = 'No error';
  126. status_info=new Array();
  127. var commit = false ;
  128. var variables_scorm = new Array('cmi.core.score.raw','cmi.core.score.max','cmi.core.score.min','cmi.core.lesson_location',
  129. 'cmi.core.lesson_status','cmi.completion_status','cmi.core.session_time','cmi.score.scaled','cmi.success_status',
  130. 'cmi.suspend_data','cmi.core.exit','interactions');
  131. var variable_to_send=new Array();
  132. var updatetable_to_list=new Array();
  133. var info_of_variable_to_send=new Array();
  134. //Strictly scorm variables
  135. var score=<?php echo $oItem->get_score();?>;
  136. var max='<?php echo $oItem->get_max();?>';
  137. var min='<?php echo $oItem->get_min();?>';
  138. var lesson_status='<?php echo $oItem->get_status();?>';
  139. var session_time='<?php echo $oItem->get_scorm_time('js');?>';
  140. var suspend_data = '<?php echo $oItem->get_suspend_data();?>';
  141. var lesson_location = '<?php echo $oItem->get_lesson_location();?>';
  142. var total_time = '<?php echo $oItem->get_scorm_time('js');?>';
  143. var mastery_score = '<?php echo $oItem->get_mastery_score();?>';
  144. var launch_data = '<?php echo $oItem->get_launch_data();?>';
  145. var max_time_allowed = '<?php echo $oItem->get_max_time_allowed();?>';
  146. var interactions = new Array(<?php echo $oItem->get_interactions_js_array();?>);
  147. item_objectives = new Array();
  148. info_lms_item=new Array();
  149. $(document).ready( function() {
  150. info_lms_item[0]='<?php echo $oItem->get_id();?>';
  151. info_lms_item[1]='<?php echo $oItem->get_id();?>';
  152. $("#current_item_id").attr("value",<?php echo $oItem->get_id();?>);
  153. $("#old_item").attr("value",<?php echo $oItem->get_id();?>);
  154. //var myiframe=document.getElementById('content_id');
  155. //myiframe.Events.AttachEvent("onclick", update_lp_item_id);
  156. //myiframe.contentWindow.document.addEventListener("click", update_lp_item_id, false);
  157. } );
  158. $(document).ready( function() {
  159. $("iframe#content_id").load( function(){
  160. //alert("Document title: " + $("iframe#content_id").attr('src'));
  161. info_lms_item[0]=info_lms_item[1];
  162. info_lms_item[1]= info_lms_item[1];
  163. });
  164. });
  165. //Dokeos internal variables
  166. var saved_lesson_status = 'not attempted';
  167. var lms_lp_id = <?php echo $oLP->get_id();?>;
  168. var lms_item_id = <?php echo $oItem->get_id();?>;
  169. //var lms_new_item_id = 0; //temporary value (only there between a load_item() and a LMSInitialize())
  170. var lms_been_synchronized = 0;
  171. var lms_initialized = 0;
  172. var lms_total_lessons = <?php echo $oLP->get_total_items_count(); ?>;
  173. var lms_complete_lessons = <?php echo $oLP->get_complete_items_count();?>;
  174. var lms_progress_bar_mode = '<?php echo $oLP->progress_bar_mode;?>';
  175. if(lms_progress_bar_mode == ''){lms_progress_bar_mode='%';}
  176. var lms_view_id = '<?php echo $oLP->get_view();?>';
  177. if(lms_view_id == ''){ lms_view_id = 1;}
  178. var lms_user_id = '<?php echo $_user['user_id'];?>';
  179. var lms_next_item = '<?php echo $oLP->get_next_item_id();?>';
  180. var lms_previous_item = '<?php echo $oLP->get_previous_item_id();?>';
  181. var lms_lp_type = '<?php echo $oLP->get_type();?>';
  182. var lms_item_type = '<?php echo $oItem->get_type();?>';
  183. var lms_item_credit = '<?php echo $oItem->get_credit();?>';
  184. var lms_item_lesson_mode = '<?php echo $oItem->get_lesson_mode();?>';
  185. var lms_item_launch_data = '<?php echo $oItem->get_launch_data();?>';
  186. var lms_item_core_exit = '<?php echo $oItem->get_core_exit();?>';
  187. var asset_timer = 0;
  188. //Backup for old values
  189. var old_score = 0;
  190. var old_max = 0;
  191. var old_min = 0;
  192. var old_lesson_status = '';
  193. var old_session_time = '';
  194. var old_suspend_data = '';
  195. var lms_old_item_id = 0;
  196. var execute_stats='false';
  197. /**
  198. * Function called mandatorily by the SCORM content to start the SCORM communication
  199. */
  200. function LMSInitialize() { //this is the initialize function of all APIobjects
  201. /* load info for this new item by calling the js_api_refresh command in
  202. * the message frame. The message frame will update the JS variables by
  203. * itself, in JS, by doing things like top.lesson_status = 'not attempted'
  204. * and that kind of stuff, so when the content loads in the content frame
  205. * it will have all the correct variables set
  206. */
  207. G_LastError = G_NoError ;
  208. G_LastErrorMessage = 'No error';
  209. //reinit to list
  210. reinit_updatatetable_list ()
  211. lms_initialized=0;
  212. // if there are more parameters than ""
  213. if (arguments.length>1) {
  214. G_LastError = G_InvalidArgumentError;
  215. G_LastErrorMessage = G_InvalidArgumentErrorMessage;
  216. logit_scorm('Error '+ G_InvalidArgumentError + G_InvalidArgumentErrorMessage, 0);
  217. return('false');
  218. } else {
  219. logit_scorm('LMSInitialise()',0);
  220. lms_initialized=1;
  221. return('true');
  222. }
  223. }
  224. function Initialize()
  225. { //this is the initialize function of all APIobjects
  226. return LMSInitialize();
  227. }
  228. function LMSGetValue(param)
  229. {
  230. //logit_scorm("LMSGetValue('"+param+"')",1);
  231. G_LastError = G_NoError ;
  232. G_LastErrorMessage = 'No error';
  233. var result='';
  234. // the LMSInitialize is missing
  235. if (lms_initialized == 0) {
  236. G_LastError = G_NotInitialized;
  237. G_LastErrorMessage = G_NotInitializedMessage;
  238. logit_scorm('Error '+ G_NotInitialized + ' ' +G_NotInitializedMessage, 0);
  239. return '';
  240. }
  241. //Dokeos does not support this SCO object properties
  242. if (param == 'cmi.student_preference.text' ||
  243. param == 'cmi.student_preference.language' ||
  244. param == 'cmi.student_preference.speed' ||
  245. param == 'cmi.student_preference.audio' ||
  246. param == 'cmi.student_preference._children' ||
  247. param == 'cmi.student_data.time_limit_action' ||
  248. param == 'cmi.comments' ||
  249. param == 'cmi.comments_from_lms' ) {
  250. // the value is not supported
  251. G_lastError = G_NotImplementedError ;
  252. G_lastErrorString = G_NotImplementedErrorMessage;
  253. logit_scorm("LMSGetValue ('"+param+"') Error '"+G_NotImplementedErrorMessage+"'",1);
  254. result = '';
  255. return result;
  256. }
  257. // ---- cmi.core._children
  258. if(param=='cmi.core._children' || param=='cmi.core_children') {
  259. result='entry, exit, lesson_status, student_id, student_name, lesson_location, total_time, credit, lesson_mode, score, session_time';
  260. } else if(param == 'cmi.core.entry'){
  261. // ---- cmi.core.entry
  262. if(lms_item_core_exit=='none') {
  263. result='ab-initio';
  264. } else if(lms_item_core_exit=='suspend') {
  265. result='resume';
  266. } else {
  267. result='';
  268. }
  269. } else if(param == 'cmi.core.exit'){
  270. // ---- cmi.core.exit
  271. result='';
  272. G_LastError = G_ElementIsWriteOnly;
  273. }else if(param == 'cmi.core.session_time'){
  274. result='';
  275. G_LastError = G_ElementIsWriteOnly;
  276. }else if(param == 'cmi.core.lesson_status'){
  277. // ---- cmi.core.lesson_status
  278. if(lesson_status != '') {
  279. result=lesson_status;
  280. } else {
  281. //result='not attempted';
  282. }
  283. } else if(param == 'cmi.core.student_id'){
  284. // ---- cmi.core.student_id
  285. result='<?php echo $_user['user_id']; ?>';
  286. } else if(param == 'cmi.core.student_name'){
  287. // ---- cmi.core.student_name
  288. <?php
  289. $who=addslashes($_user['lastName'].", ".$_user['firstName']);
  290. echo "result='$who';";
  291. ?>
  292. } else if(param == 'cmi.core.lesson_location'){
  293. // ---- cmi.core.lesson_location
  294. result=lesson_location;
  295. } else if(param == 'cmi.core.total_time'){
  296. // ---- cmi.core.total_time
  297. result=total_time;
  298. } else if(param == 'cmi.core.score._children'){
  299. // ---- cmi.core.score._children
  300. result='raw,min,max';
  301. } else if(param == 'cmi.core.score.raw'){
  302. // ---- cmi.core.score.raw
  303. result=score;
  304. } else if(param == 'cmi.core.score.max'){
  305. // ---- cmi.core.score.max
  306. result=max;
  307. } else if(param == 'cmi.core.score.min'){
  308. // ---- cmi.core.score.min
  309. result=min;
  310. } else if(param == 'cmi.core.score'){
  311. // ---- cmi.core.score -- non-standard item, provided as cmi.core.score.raw just in case
  312. result=score;
  313. }else if(param == 'cmi.core.credit'){
  314. // ---- cmi.core.credit
  315. result = lms_item_credit;
  316. }else if(param == 'cmi.core.lesson_mode'){
  317. // ---- cmi.core.lesson_mode
  318. result = lms_item_lesson_mode;
  319. }else if(param == 'cmi.suspend_data'){
  320. // ---- cmi.suspend_data
  321. result = suspend_data;
  322. }else if(param == 'cmi.launch_data'){
  323. // ---- cmi.launch_data
  324. result = lms_item_launch_data;
  325. }else if(param == 'cmi.objectives._children'){
  326. // ---- cmi.objectives._children
  327. result = 'id,score,status';
  328. }else if(param == 'cmi.objectives._count'){
  329. // ---- cmi.objectives._count
  330. //result='<?php echo $oItem->get_view_count();?>';
  331. result = item_objectives.length;
  332. }else if(param.substring(0,15)== 'cmi.objectives.'){
  333. var myres = '';
  334. if(myres = param.match(/cmi.objectives.(\d+).(id|score|status|_children)(.*)/))
  335. {
  336. var obj_id = myres[1];
  337. var req_type = myres[2];
  338. if(item_objectives[obj_id]==null)
  339. {
  340. if(req_type == 'id')
  341. {
  342. result = '';
  343. }else if(req_type == '_children'){
  344. result = 'id,score,status';
  345. }else if(req_type == 'score'){
  346. if(myres[3]==null)
  347. {
  348. result = '';
  349. G_lastError = G_NotImplementedError;
  350. G_lastErrorString = 'Not implemented yet';
  351. }else if (myres[3] == '._children'){
  352. result = 'raw,min,max'; //non-standard, added for NetG
  353. }else if (myres[3] == '.raw'){
  354. result = '';
  355. }else if (myres[3] == '.max'){
  356. result = '';
  357. }else if (myres[3] == '.min'){
  358. result = '';
  359. }else{
  360. result = '';
  361. G_lastError = G_NotImplementedError;
  362. G_lastErrorString = 'Not implemented yet';
  363. }
  364. }else if(req_type == 'status'){
  365. result = 'not attempted';
  366. }
  367. }
  368. else
  369. {
  370. //the object is not null
  371. if(req_type == 'id')
  372. {
  373. result = item_objectives[obj_id][0];
  374. }else if(req_type == '_children'){
  375. result = 'id,score,status';
  376. }else if(req_type == 'score'){
  377. if(myres[3]==null)
  378. {
  379. result = '';
  380. G_lastError = G_NotImplementedError;
  381. G_lastErrorString = 'Not implemented yet';
  382. }else if (myres[3] == '._children'){
  383. result = 'raw,min,max'; //non-standard, added for NetG
  384. }else if (myres[3] == '.raw'){
  385. if(item_objectives[obj_id][2] != null)
  386. {
  387. result = item_objectives[obj_id][2];
  388. }else{
  389. result = '';
  390. }
  391. }else if (myres[3] == '.max'){
  392. if(item_objectives[obj_id][3] != null)
  393. {
  394. result = item_objectives[obj_id][3];
  395. }else{
  396. result = '';
  397. }
  398. }else if (myres[3] == '.min'){
  399. if(item_objectives[obj_id][4] != null)
  400. {
  401. result = item_objectives[obj_id][4];
  402. }else{
  403. result = '';
  404. }
  405. }else{
  406. result = '';
  407. G_lastError = G_NotImplementedError;
  408. G_lastErrorString = 'Not implemented yet';
  409. }
  410. }else if(req_type == 'status'){
  411. if(item_objectives[obj_id][1] != null)
  412. {
  413. result = item_objectives[obj_id][1];
  414. }else{
  415. result = 'not attempted';
  416. }
  417. }
  418. }
  419. }
  420. }else if(param == 'cmi.student_data._children'){
  421. // ---- cmi.student_data._children
  422. result = 'mastery_score,max_time_allowed';
  423. }else if(param == 'cmi.student_data.mastery_score'){
  424. // ---- cmi.student_data.mastery_score
  425. result = mastery_score;
  426. }else if(param == 'cmi.student_data.max_time_allowed'){
  427. // ---- cmi.student_data.max_time_allowed
  428. result = max_time_allowed;
  429. }else if(param == 'cmi.interactions._count'){
  430. // ---- cmi.interactions._count
  431. result = interactions.length;
  432. }else if(param == 'cmi.interactions._children'){
  433. // ---- cmi.interactions._children
  434. result = 'id,time,type,correct_responses,weighting,student_response,result,latency';
  435. } else {
  436. // ---- anything else
  437. // Invalid argument error
  438. G_lastError = G_InvalidArgumentError ;
  439. G_lastErrorString = G_InvalidArgumentErrorMessage;
  440. logit_scorm("LMSGetValue ('"+param+"') Error '"+G_InvalidArgumentErrorMessage+"'",1);
  441. result = '';
  442. return result;
  443. }
  444. logit_scorm("LMSGetValue\n\t('"+param+"') returned '"+result+"'",1);
  445. return result;
  446. }
  447. function GetValue(param) {
  448. return LMSGetValue(param);
  449. }
  450. function LMSSetValue(param, val) {
  451. logit_scorm("LMSSetValue\n\t('"+param+"','"+val+"')",0);
  452. commit = true; //value has changed, need to re-commit
  453. G_LastError = G_NoError ;
  454. G_LastErrorMessage = 'No error';
  455. return_value = 'false';
  456. if( param == "cmi.core.score.raw" ) {
  457. score= val;
  458. updatetable_to_list['cmi.core.score.raw']='true';
  459. return_value='true';
  460. } else if ( param == "cmi.core.score.max" ) {
  461. max = val;
  462. updatetable_to_list['cmi.core.score.max']='true';
  463. return_value='true';
  464. } else if ( param == "cmi.core.score.min" ) {
  465. min = val;
  466. updatetable_to_list['cmi.core.score.min']='true';
  467. return_value='true';
  468. } else if ( param == "cmi.core.lesson_location" ) {
  469. lesson_location = val;
  470. updatetable_to_list['cmi.core.lesson_location']='true';
  471. return_value='true';
  472. } else if ( param == "cmi.core.lesson_status" ) {
  473. saved_lesson_status = lesson_status;
  474. lesson_status = val;
  475. updatetable_to_list['cmi.core.lesson_status']='true';
  476. return_value='true';
  477. } else if ( param == "cmi.completion_status" ) {
  478. lesson_status = val;
  479. updatetable_to_list['cmi.completion_status']='true';
  480. return_value='true'; //1.3
  481. } else if ( param == "cmi.core.session_time" ) {
  482. session_time = val;
  483. updatetable_to_list['cmi.core.session_time']='true';
  484. return_value='true';
  485. } else if ( param == "cmi.score.scaled") { //1.3
  486. if(val<=1 && val>=-1) {
  487. score = val ;
  488. updatetable_to_list['cmi.score.scaled']='true';
  489. return_value='true';
  490. } else {
  491. return_value='false';
  492. }
  493. } else if ( param == "cmi.success_status" ) {
  494. success_status = val;
  495. updatetable_to_list['cmi.success_status']='true';
  496. return_value='true'; //1.3
  497. } else if ( param == "cmi.suspend_data" ) {
  498. suspend_data = val;
  499. updatetable_to_list['cmi.suspend_data']='true';
  500. return_value='true';
  501. } else if ( param == "cmi.core.exit" ) {
  502. lms_item_core_exit = val;
  503. updatetable_to_list['cmi.core.exit']='true';
  504. return_value='true';
  505. } else if ( param == "cmi.core.student_id" ) {
  506. G_LastError = G_ElementIsReadOnly;
  507. } else if ( param == "cmi.core.student_name" ) {
  508. G_LastError = G_ElementIsReadOnly;
  509. } else if ( param == "cmi.core.credit" ) {
  510. G_LastError = G_ElementIsReadOnly;
  511. } else if ( param == "cmi.core.entry" ) {
  512. G_LastError = G_ElementIsReadOnly;
  513. } else if ( param == "cmi.core.total_time" ) {
  514. G_LastError = G_ElementIsReadOnly;
  515. } else if ( param == "cmi.core.lesson_mode" ) {
  516. G_LastError = G_ElementIsReadOnly;
  517. } else if ( param == "cmi.comments_from_lms" ) {
  518. G_LastError = G_ElementIsReadOnly;
  519. } else if ( param == "cmi.student_data.time_limit_action" ) {
  520. G_LastError = G_ElementIsReadOnly;
  521. } else if ( param == "cmi.student_data.mastery_score" ) {
  522. G_LastError = G_ElementIsReadOnly;
  523. } else if ( param == "cmi.student_data.max_time_allowed" ) {
  524. G_LastError = G_ElementIsReadOnly;
  525. } else if ( param == "cmi.student_preference._children" ) {
  526. G_LastError = G_ElementIsReadOnly;
  527. } else if ( param == "cmi.launch_data" ) {
  528. G_LastError = G_ElementIsReadOnly;
  529. } else {
  530. var myres = new Array();
  531. if(myres = param.match(/cmi.interactions.(\d+).(id|time|type|correct_responses|weighting|student_response|result|latency)(.*)/)) {
  532. updatetable_to_list['interactions']='true';
  533. elem_id = myres[1];
  534. if(elem_id > interactions.length) //interactions setting should start at 0
  535. {
  536. /*
  537. G_LastError = G_InvalidArgumentError;
  538. G_LastErrorString = 'Invalid argument (interactions)';
  539. return_value = false;
  540. */
  541. interactions[0] = ['0','','','','','','',''];
  542. }
  543. if(interactions[elem_id] == null) {
  544. interactions[elem_id] = ['','','','','','','',''];
  545. //id(0), type(1), time(2), weighting(3),correct_responses(4),student_response(5),result(6),latency(7)
  546. interactions[elem_id][4] = new Array();
  547. }
  548. elem_attrib = myres[2];
  549. switch(elem_attrib) {
  550. case "id":
  551. interactions[elem_id][0] = val;
  552. logit_scorm("Interaction "+elem_id+"'s id updated",2);
  553. return_value='true';
  554. break;
  555. case "time":
  556. interactions[elem_id][2] = val;
  557. logit_scorm("Interaction "+elem_id+"'s time updated",2);
  558. return_value='true';
  559. break;
  560. case "type":
  561. interactions[elem_id][1] = val;
  562. logit_scorm("Interaction "+elem_id+"'s type updated",2);
  563. return_value='true';
  564. break;
  565. case "correct_responses":
  566. //do nothing yet
  567. interactions[elem_id][4].push(val);
  568. logit_scorm("Interaction "+elem_id+"'s correct_responses not updated",2);
  569. return_value='true';
  570. break;
  571. case "weighting":
  572. interactions[elem_id][3] = val;
  573. logit_scorm("Interaction "+elem_id+"'s weighting updated",2);
  574. return_value='true';
  575. break;
  576. case "student_response":
  577. interactions[elem_id][5] = val;
  578. logit_scorm("Interaction "+elem_id+"'s student_response updated",2);
  579. return_value='true';
  580. break;
  581. case "result":
  582. interactions[elem_id][6] = val;
  583. logit_scorm("Interaction "+elem_id+"'s result updated",2);
  584. return_value='true';
  585. break;
  586. case "latency":
  587. interactions[elem_id][7] = val;
  588. logit_scorm("Interaction "+elem_id+"'s latency updated",2);
  589. return_value='true';
  590. break;
  591. default:
  592. G_lastError = G_NotImplementedError;
  593. G_lastErrorString = 'Not implemented yet';
  594. }
  595. } else if(param.substring(0,15)== 'cmi.objectives.'){
  596. var myres = '';
  597. updatetable_to_list['objectives']='true';
  598. if(myres = param.match(/cmi.objectives.(\d+).(id|score|status)(.*)/))
  599. {
  600. obj_id = myres[1];
  601. if(obj_id > item_objectives.length) //objectives setting should start at 0
  602. {
  603. G_LastError = G_InvalidArgumentError;
  604. G_LastErrorString = 'Invalid argument (objectives)';
  605. return_value = false;
  606. }
  607. else
  608. {
  609. req_type = myres[2];
  610. if(obj_id == null || obj_id == '')
  611. {
  612. ;//do nothing
  613. }
  614. else
  615. {
  616. if(item_objectives[obj_id]==null)
  617. {
  618. item_objectives[obj_id] = ['','','','',''];
  619. }
  620. if( req_type == "id" ) {
  621. //item_objectives[obj_id][0] = val.substring(51,57);
  622. item_objectives[obj_id][0] = val;
  623. logit_scorm("Objective "+obj_id+"'s id updated",2);
  624. return_value = 'true';
  625. } else if ( req_type == "score" ) {
  626. if (myres[3] == '._children'){
  627. return_value = '';
  628. G_lastError = G_InvalidSetValue;
  629. G_lastErrorString = 'Invalid set value, element is a keyword';
  630. }else if (myres[3] == '.raw'){
  631. item_objectives[obj_id][2] = val;
  632. logit_scorm("Objective "+obj_id+"'s score raw updated",2);
  633. return_value = 'true';
  634. }else if (myres[3] == '.max'){
  635. item_objectives[obj_id][3] = val;
  636. logit_scorm("Objective "+obj_id+"'s score max updated",2);
  637. return_value = 'true';
  638. }else if (myres[3] == '.min'){
  639. item_objectives[obj_id][4] = val;
  640. logit_scorm("Objective "+obj_id+"'s score min updated",2);
  641. return_value = 'true';
  642. }else{
  643. return_value = '';
  644. G_lastError = G_NotImplementedError;
  645. G_lastErrorString = 'Not implemented yet';
  646. }
  647. } else if ( req_type == "status" ) {
  648. item_objectives[obj_id][1] = val;
  649. logit_scorm("Objective "+obj_id+"'s status updated",2);
  650. return_value = 'true';
  651. } else {
  652. G_lastError = G_NotImplementedError;
  653. G_lastErrorString = 'Not implemented yet';
  654. }
  655. }
  656. }
  657. }
  658. } else {
  659. G_lastError = G_NotImplementedError;
  660. G_lastErrorString = G_NotImplementedErrorMessage;
  661. }
  662. }
  663. <?php
  664. if ($oLP->force_commit == 1){
  665. echo " var mycommit = LMSCommit('force');";
  666. }
  667. ?>
  668. return(return_value);
  669. }
  670. function SetValue(param, val) {
  671. return LMSSetValue(param, val);
  672. }
  673. function ProcessValueScorm () {
  674. for (i=0;i<variables_scorm.length;i++) {
  675. if (updatetable_to_list[variables_scorm[i]]=='true') {
  676. info_update_table=variables_scorm[i];
  677. variable_to_send.push(info_update_table);
  678. }
  679. }
  680. return variable_to_send;
  681. }
  682. function reinit_updatatetable_list () {
  683. for (i=0;i<variables_scorm.length;i++) {
  684. if (updatetable_to_list[variables_scorm[i]]=='true') {
  685. updatetable_to_list[variables_scorm[i]]='false';
  686. }
  687. }
  688. lesson_status='';
  689. }
  690. function savedata(origin) {
  691. my_get_value_scorm=new Array();
  692. my_get_value_scorm=ProcessValueScorm();
  693. //origin can be 'commit', 'finish' or 'terminate'
  694. if ((lesson_status != 'completed') && (lesson_status != 'passed') && (mastery_score >=0) && (score >= mastery_score)) {
  695. lesson_status = 'passed';
  696. } else if( (mastery_score < 0) && (lms_lp_type != '2') && ( lesson_status == 'incomplete') && (score >= (0.8*max) ) ) {
  697. //the status cannot be modified automatically by the LMS under SCORM 1.2's rules
  698. <?php if ($autocomplete_when_80pct){ ?>
  699. lesson_status = 'completed';
  700. <?php }?>
  701. ;
  702. } else {
  703. if (origin== 'finish') {
  704. /*
  705. The SCORM1.2 Runtime object document says for the "cmi.core.lesson_status" variable:
  706. Upon receiving the LMSFinish() call or the user navigates away,
  707. the LMS should set the cmi.core.lesson_status for the SCO to 'completed'
  708. */
  709. /*
  710. if (mastery_score!= '' && score != '') {
  711. if (score >= mastery_score) {
  712. lesson_status = 'passed';
  713. } else {
  714. lesson_status = 'failed';
  715. }
  716. } else if (mastery_score!= '') {
  717. lesson_status = 'completed';
  718. }
  719. */
  720. }
  721. }
  722. logit_lms('saving data (status='+lesson_status+' - interactions: '+ interactions.length +')',1);
  723. old_item_id=info_lms_item[0];
  724. //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);
  725. xajax_save_item_scorm(lms_lp_id, lms_user_id, lms_view_id, old_item_id,my_get_value_scorm);
  726. //info_lms_item[0] is old_item_id and info_lms_item[1] is current_item_id
  727. info_lms_item[0]=info_lms_item[0];
  728. info_lms_item[1]=lms_item_id;
  729. if(item_objectives.length>0) {
  730. xajax_save_objectives(lms_lp_id,lms_user_id,lms_view_id,old_item_id,item_objectives);
  731. }
  732. execute_stats='false';
  733. //clean array
  734. variable_to_send=new Array();
  735. my_get_value_scorm=new Array();
  736. }
  737. function LMSCommit(val) {
  738. logit_scorm('LMSCommit()',0);
  739. G_LastError = G_NoError ;
  740. G_LastErrorMessage = 'No error';
  741. savedata('commit');
  742. reinit_updatatetable_list();
  743. //commit = 'false' ; //now changes have been commited, no need to update until next SetValue()
  744. return('true');
  745. }
  746. function Commit(val) {
  747. return LMSCommit(val);
  748. }
  749. function LMSFinish(val) {
  750. G_LastError = G_NoError ;
  751. G_LastErrorMessage = 'No error';
  752. // why commit==false?
  753. if (( commit == false )) {
  754. logit_scorm('LMSFinish() (no LMSCommit())',1);
  755. }
  756. //if ( commit == true ) {
  757. logit_scorm('LMSFinish() called',1);
  758. savedata('finish');
  759. commit = 'false' ;
  760. //}
  761. //reinit to list
  762. reinit_updatatetable_list()
  763. return('true');
  764. }
  765. function Finish(val) {
  766. return LMSFinish(val);
  767. }
  768. function LMSGetLastError() {
  769. logit_scorm('LMSGetLastError()',1);
  770. return(G_LastError.toString());
  771. }
  772. function GetLastError() {
  773. return LMSGetLastError();
  774. }
  775. function LMSGetErrorString(errCode){
  776. logit_scorm('LMSGetErrorString()',1);
  777. return(G_LastErrorString);
  778. }
  779. function GetErrorString(errCode){
  780. return LMSGetErrorString(errCode);
  781. }
  782. function LMSGetDiagnostic(errCode){
  783. logit_scorm('LMSGetDiagnostic()',1);
  784. return(API.LMSGetLastError());
  785. }
  786. function GetDiagnostic(errCode){
  787. return LMSGetDiagnostic(errCode);
  788. }
  789. function Terminate()
  790. {
  791. if (lms_initialized == 0) {
  792. G_LastError = G_NotInitialized;
  793. G_LastErrorMessage = G_NotInitializedMessage;
  794. logit_scorm('Error '+ G_NotInitialized + G_NotInitializedMessage, 0);
  795. return('false');
  796. } else {
  797. logit_scorm('Terminate()',0);
  798. G_LastError = G_NoError ;
  799. G_LastErrorMessage = 'No error';
  800. commit = true;
  801. savedata('terminate');
  802. return (true);
  803. }
  804. }
  805. <?php
  806. //--------------------------------------------------------------------//
  807. /**
  808. * Dokeos-specific code that deals with event handling and inter-frames
  809. * messaging/refreshing.
  810. * Note that from now on, the Dokeos JS code in this library will act as
  811. * a controller, of the MVC pattern, and receive all requests for frame
  812. * updates, then redispatch to any frame concerned.
  813. */
  814. ?>
  815. /**
  816. * Defining the AJAX-object class to be made available from other frames
  817. */
  818. function XAJAXobject() {
  819. this.xajax_switch_item_details=xajax_switch_item_details;
  820. this.switch_item=switch_item;
  821. this.xajax_save_objectives=xajax_save_objectives;
  822. this.xajax_save_item = xajax_save_item;
  823. }
  824. //it is not sure that the scos use the above declarations
  825. oXAJAX = new XAJAXobject();
  826. oxajax = new XAJAXobject();
  827. /**
  828. * Cross-browser event handling by Scott Andrew
  829. * @param element Element that needs an event attached
  830. * @param string Event type (load, unload, click, keyDown, ...)
  831. * @param string Function name (the event handler)
  832. * @param string used in addEventListener
  833. */
  834. function addEvent(elm, evType, fn, useCapture){
  835. if(elm.addEventListener){
  836. elm.addEventListener(evType, fn, useCapture);
  837. return true;
  838. }else if (elm.attachEvent){
  839. var r = elm.attachEvent('on' + evType, fn);
  840. }else{
  841. elm['on'+evType] = fn;
  842. }
  843. }
  844. /**
  845. * Add listeners to the page objects. This has to be defined for
  846. * the current context as it acts on objects that should exist
  847. * on the page
  848. * possibly deprecated
  849. */
  850. function addListeners(){
  851. //exit if the browser doesn't support ID or tag retrieval
  852. logit_lms('Entering addListeners()',2);
  853. if(!document.getElementsByTagName){
  854. logit_lms("getElementsByTagName not available",2);
  855. return;
  856. }
  857. if(!document.getElementById){
  858. logit_lms("getElementById not available",2);
  859. return;
  860. }
  861. //assign event handlers to objects
  862. if(lms_lp_type==1 || lms_item_type=='asset'){
  863. logit_lms('Dokeos LP or asset',2);
  864. //if this path is a Dokeos learnpath, then start manual save
  865. //when something is loaded in there
  866. addEvent(window,'unload',dokeos_save_asset,false);
  867. logit_lms('Added event listener on content_id for unload',2);
  868. }
  869. logit_lms('Quitting addListeners()',2);
  870. }
  871. /**
  872. * Load an item into the content frame:
  873. * - making sure the previous item status have been saved
  874. * - first updating the current item ID (to save the right item)
  875. * - updating the frame src
  876. * possibly deprecated
  877. */
  878. function load_item(item_id,url){
  879. if(document.getElementById('content_id')) {
  880. logit_lms('Loading item '+item_id,2);
  881. var cont_f = document.getElementById('content_id');
  882. if(cont_f.src){
  883. lms_old_item_id = lms_item_id;
  884. var lms_new_item_id = item_id;
  885. //load new content page into content frame
  886. if(lms_lp_type==1 || lms_item_type=='asset') {
  887. dokeos_save_asset();
  888. }
  889. cont_f.src = url;
  890. update_toc('unhighlight',lms_old_item_id);
  891. update_toc('highlight',lms_old_item_id);
  892. return true;
  893. }
  894. logit_lms('cont_f.src has no properties',0);
  895. }
  896. logit_lms('content_id has no properties',0);
  897. return false;
  898. }
  899. /**
  900. * Save a Dokeos learnpath item's time and mark as completed upon
  901. * leaving it
  902. */
  903. function dokeos_save_asset() {
  904. // only for dokeos lps
  905. if (execute_stats=='true') {
  906. execute_stats='false';
  907. } else {
  908. execute_stats='true';
  909. }
  910. if(lms_lp_type==1 || lms_item_type=='asset'){
  911. logit_lms('dokeos_save_asset',2);
  912. 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);
  913. if(item_objectives.length>0)
  914. {
  915. xajax_save_objectives(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,item_objectives);
  916. }
  917. }
  918. }
  919. /**
  920. * Save a Dokeos learnpath item's time and mark as completed upon leaving it.
  921. * Same function as dokeos_save_asset() but saves it with empty params
  922. * to use values set from another side in the database. Only used by Dokeos quizzes.
  923. * Also save the score locally because it hasn't been done through SetValue().
  924. * Saving the status will be dealt with by the XAJAX function.
  925. */
  926. function dokeos_void_save_asset(myscore,mymax)
  927. {
  928. logit_lms('dokeos_save_asset',2);
  929. score = myscore;
  930. if((mymax == null) || (mymax == '')){mymax = 100;} //assume a default of 100, otherwise the score will not get saved (see lpi->set_score())
  931. xajax_save_item(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, myscore, mymax);
  932. }
  933. /**
  934. * Logs information about SCORM messages into the log frame
  935. * @param string Message to log
  936. * @param integer Priority (0 for top priority, 3 for lowest)
  937. */
  938. function logit_scorm(message,priority){
  939. if(scorm_logs>priority){
  940. if($("#lp_log_name") && $("#log_content")){
  941. $("#log_content").append("SCORM: " + message + "<br/>");
  942. }
  943. }
  944. }
  945. /**
  946. * Logs information about LMS activity into the log frame
  947. * @param string Message to log
  948. * @param integer Priority (0 for top priority, 3 for lowest)
  949. */
  950. function logit_lms(message,priority){
  951. if(lms_logs>priority){
  952. if ($("#lp_log_name") && $("#log_content")) {
  953. $("#log_content").append("LMS: " + message + "<br />");
  954. }
  955. }
  956. }
  957. /**
  958. * update the Table Of Contents frame, by changing CSS styles, mostly
  959. * @param string Action to be taken
  960. * @param integer Item id to update
  961. */
  962. function update_toc(update_action,update_id)
  963. {
  964. <?php //if($oLP->mode != 'fullscreen'){ ?>
  965. //var myframe = frames["toc_name"];
  966. //var myelem = myframe.document.getElementById("toc_"+update_id);
  967. //var myelemimg = myframe.document.getElementById("toc_img_"+update_id);
  968. var myelem = $("#toc_"+update_id);
  969. var myelemimg = $("#toc_img_"+update_id);
  970. logit_lms('update_toc("'+update_action+'",'+update_id+')',2);
  971. if(update_id != 0)
  972. {
  973. switch(update_action)
  974. {
  975. case 'unhighlight':
  976. if (update_id%2==0)
  977. {
  978. myelem.attr('class',"scorm_item_2");
  979. }
  980. else
  981. {
  982. myelem.attr('class',"scorm_item_1");
  983. }
  984. break;
  985. case 'highlight':
  986. lms_next_item = update_id;
  987. lms_previous_item = update_id;
  988. myelem.attr('class',"scorm_item_highlight");
  989. break;
  990. case 'not attempted':
  991. if( myelemimg.attr('src') != '../img/notattempted.gif') {
  992. myelemimg.attr('src','../img/notattempted.gif');
  993. myelemimg.attr('alt','n');
  994. }
  995. break;
  996. case 'incomplete':
  997. if( myelemimg.attr('src') != '../img/incomplete.gif') {
  998. myelemimg.attr('src','../img/incomplete.gif');
  999. myelemimg.attr('alt','i');
  1000. }
  1001. break;
  1002. case 'completed':
  1003. if( myelemimg.attr('src') != '../img/completed.gif') {
  1004. myelemimg.attr('src','../img/completed.gif');
  1005. myelemimg.attr('alt','c');
  1006. }
  1007. break;
  1008. case 'failed':
  1009. if( myelemimg.attr('src') != '../img/failed.gif') {
  1010. myelemimg.attr('src','../img/failed.gif');
  1011. myelemimg.attr('alt','f');
  1012. }
  1013. break;
  1014. case 'passed':
  1015. if( myelemimg.attr('src') != '../img/completed.gif' && myelemimg.attr('alt') != 'passed') {
  1016. myelemimg.attr('src','../img/completed.gif');
  1017. myelemimg.attr('alt','p');
  1018. }
  1019. break;
  1020. case 'browsed':
  1021. if( myelemimg.attr('src') != '../img/completed.gif' && myelemimg.attr('alt') != 'browsed') {
  1022. myelemimg.attr('src','../img/completed.gif');
  1023. myelemimg.attr('alt','b');
  1024. }
  1025. break;
  1026. default:
  1027. logit_lms('Update action unknown',2);
  1028. break;
  1029. }
  1030. }
  1031. return true;
  1032. <?php //} ?>
  1033. //return true;
  1034. }
  1035. function update_stats() {
  1036. if (execute_stats=='true') {
  1037. try {
  1038. cont_f = document.getElementById('content_id');
  1039. cont_f.src="lp_controller.php?action=stats";
  1040. cont_f.reload();
  1041. } catch (e) {
  1042. return false;
  1043. }
  1044. }
  1045. execute_stats='false';
  1046. }
  1047. /**
  1048. * Updates the progress bar with the new status. Prevents the need of a page refresh and flickering
  1049. * @param integer Number of completed items
  1050. * @param integer Number of items in total
  1051. * @param string Display mode (absolute 'abs' or percentage '%').Defaults to %
  1052. */
  1053. function update_progress_bar(nbr_complete, nbr_total, mode)
  1054. {
  1055. logit_lms('update_progress_bar('+nbr_complete+','+nbr_total+','+mode+')',2);
  1056. logit_lms('could update with data: '+lms_lp_id+','+lms_view_id+','+lms_user_id,2);
  1057. if(mode == ''){mode='%';}
  1058. if(nbr_total == 0){nbr_total=1;}
  1059. var percentage = (nbr_complete/nbr_total)*100;
  1060. percentage = Math.round(percentage);
  1061. var pr_text = $("#progress_text");
  1062. var pr_full = $("#progress_img_full");
  1063. var pr_empty = $("#progress_img_empty");
  1064. pr_full.attr('width',percentage*1.2);
  1065. pr_empty.attr('width',(100-percentage)*1.2);
  1066. var mytext = '';
  1067. switch(mode){
  1068. case 'abs':
  1069. mytext = nbr_complete + '/' + nbr_total;
  1070. break;
  1071. case '%':
  1072. default:
  1073. mytext = percentage + '%';
  1074. break;
  1075. }
  1076. pr_text.html(mytext);
  1077. return true;
  1078. }
  1079. function update_stats_page()
  1080. {
  1081. var myframe = document.getElementById('content_id');
  1082. var mysrc = myframe.location.href;
  1083. if(mysrc == 'lp_controller.php?action=stats'){
  1084. if(myframe && myframe.src){
  1085. var mysrc = myframe.src;
  1086. myframe.src = mysrc;
  1087. }
  1088. // = mysrc; //refresh page
  1089. }
  1090. return true;
  1091. }
  1092. /**
  1093. * Updates the message frame with the given string
  1094. */
  1095. function update_message_frame(msg_msg)
  1096. {
  1097. if(msg_msg==null){msg_msg='';}
  1098. if(!($("#msg_div_id"))){
  1099. logit_lms('In update_message_frame() - message frame has no document property',0);
  1100. }else{
  1101. logit_lms('In update_message_frame() - updating frame',0);
  1102. $("#msg_div_id").html(msg_msg);
  1103. }
  1104. }
  1105. /**
  1106. * Function that handles the saving of an item and switching from an item to another.
  1107. * Once called, this function should be able to do the whole process of
  1108. * (1) saving the current item,
  1109. * (2) refresh all the values inside the SCORM API object,
  1110. * (3) open the new item into the content_id frame,
  1111. * (4) refresh the table of contents
  1112. * (5) refresh the progress bar (completion)
  1113. * (6) refresh the message frame
  1114. * @param integer Dokeos ID for the current item
  1115. * @param string This parameter can be a string specifying the next
  1116. * item (like 'next', 'previous', 'first' or 'last') or the id to the next item
  1117. */
  1118. function switch_item(current_item, next_item){
  1119. //(1) save the current item
  1120. logit_lms('Called switch_item with params '+lms_item_id+' and '+next_item+'',0);
  1121. if(lms_lp_type==1 || lms_item_type=='asset' || session_time == '0' || session_time == '0:00:00'){
  1122. xajax_save_item(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, score, max, min, lesson_status, asset_timer, suspend_data, lesson_location,interactions, lms_item_core_exit);
  1123. if(item_objectives.length>0) {
  1124. xajax_save_objectives(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,item_objectives);
  1125. }
  1126. }else{
  1127. // 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);
  1128. }
  1129. execute_stats=false;
  1130. //(2) Refresh all the values inside this SCORM API object - use AJAX
  1131. xajax_switch_item_details(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,next_item);
  1132. status_info.push(lesson_status);
  1133. /*$my_new_old_item=$("#old_item").val();
  1134. $my_new_current_item=$("#current_item_id").val();*/
  1135. $my_new_old_item=info_lms_item[0];
  1136. $my_new_current_item=info_lms_item[1];
  1137. //current item
  1138. //old item
  1139. //info_lms_item[0]=next_item;
  1140. if (info_lms_item[1]==next_item && next_item!='next' && next_item!='previous') {
  1141. info_lms_item[0]=next_item;
  1142. info_lms_item[1]=next_item;
  1143. } else {
  1144. if (next_item!='next' && next_item!='previous') {
  1145. info_lms_item[0]=info_lms_item[1];
  1146. info_lms_item[1]=next_item;
  1147. }
  1148. }
  1149. if (info_lms_item[0]==next_item && next_item!='next' && next_item!='previous') {
  1150. info_lms_item[0]=next_item;
  1151. info_lms_item[1]=next_item;
  1152. } else {
  1153. if (next_item!='next' && next_item!='previous') {
  1154. info_lms_item[0]=info_lms_item[0];
  1155. info_lms_item[1]=next_item;
  1156. }
  1157. }
  1158. //(3) open the new item in the content_id frame
  1159. switch(next_item){
  1160. case 'next':
  1161. next_item = lms_next_item;
  1162. info_lms_item[0]=info_lms_item[1];
  1163. info_lms_item[1]=lms_next_item;
  1164. break;
  1165. case 'previous':
  1166. next_item = lms_previous_item;
  1167. info_lms_item[0]=info_lms_item[1];
  1168. info_lms_item[1]=lms_previous_item;
  1169. break;
  1170. default:
  1171. break;
  1172. }
  1173. var mysrc = 'lp_controller.php?action=content&lp_id='+lms_lp_id+'&item_id='+next_item;
  1174. var cont_f = $("#content_id");
  1175. <?php if($oLP->mode == 'fullscreen'){ ?>
  1176. cont_f = window.open(''+mysrc,'content_id','toolbar=0,location=0,status=0,scrollbars=1,resizable=1');
  1177. cont_f.onload=function(){
  1178. info_lms_item[0]=info_lms_item[1];
  1179. info_lms_item[1]= info_lms_item[1];
  1180. }
  1181. cont_f.onunload=function(){
  1182. info_lms_item[0]=info_lms_item[1];
  1183. info_lms_item[1]= info_lms_item[1];
  1184. }
  1185. <?php } else { ?>
  1186. cont_f.attr("src",mysrc);
  1187. <?php } ?>
  1188. if(lms_lp_type==1 || lms_item_type=='asset'){
  1189. xajax_start_timer();
  1190. }
  1191. //(4) refresh the audio player if needed
  1192. $.ajax({
  1193. type: "GET",
  1194. url: "lp_nav.php",
  1195. data: "",
  1196. success: function(datos) {
  1197. $("#media").html(datos);
  1198. }
  1199. });
  1200. return true;
  1201. }
  1202. /**
  1203. * Save a specific item (with its interactions, if any) into the LMS through
  1204. * an AJAX call. Originally, we used the xajax library. Now we use jQuery.
  1205. * Because of the need to pass an array, we have to build the parameters
  1206. * manually into GET[]
  1207. */
  1208. 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) {
  1209. params='';
  1210. params += 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id;
  1211. params += '&iid='+lms_item_id+'&s='+score+'&max='+max+'&min='+min;
  1212. params += '&status='+lesson_status+'&t='+session_time;
  1213. params += '&suspend='+suspend_data+'&loc='+lesson_location;
  1214. params += '&core_exit='+lms_item_core_exit;
  1215. interact_string = '';
  1216. for (i in interactions){
  1217. interact_string += '&interact['+i+']=';
  1218. interact_temp = '[';
  1219. for (j in interactions[i]) {
  1220. interact_temp += interactions[i][j]+',';
  1221. }
  1222. interact_temp = interact_temp.substr(0,(interact_temp.length-2)) + ']';
  1223. interact_string += encodeURIComponent(interact_temp);
  1224. }
  1225. //interact_string = encodeURIComponent(interact_string.substr(0,(interact_string.length-1)));
  1226. params += interact_string;
  1227. /*params = {
  1228. 'lid': lms_lp_id,
  1229. 'uid': lms_user_id,
  1230. 'vid': lms_view_id,
  1231. 'iid': lms_item_id,
  1232. 's': score,
  1233. 'max': max,
  1234. 'min': min,
  1235. 'status': lesson_status,
  1236. 't': session_time,
  1237. 'suspend': suspend_data,
  1238. 'loc': lesson_location,
  1239. 'interact': interac_string,
  1240. 'core_exit': lms_item_core_exit
  1241. }
  1242. */
  1243. if ( lms_lp_type==1) {
  1244. $.ajax({
  1245. type:"GET",
  1246. data: params,
  1247. url: "lp_ajax_save_item.php",
  1248. dataType: "script",
  1249. async: false
  1250. }
  1251. );
  1252. }
  1253. }
  1254. function xajax_save_item_scorm(lms_lp_id, lms_user_id, lms_view_id, lms_item_id,info_get_lms) {
  1255. // var variables_scorm = new Array('cmi.core.score.raw','cmi.core.score.max','cmi.core.score.min','cmi.core.lesson_location',
  1256. //'cmi.core.lesson_status','cmi.completion_status','cmi.core.session_time','cmi.score.scaled','cmi.success_status',
  1257. //'cmi.suspend_data','cmi.core.exit','interactions');
  1258. params='';
  1259. params += 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id+'&iid='+lms_item_id;
  1260. for (k=0;k<info_get_lms.length;k++) {
  1261. if (my_get_value_scorm[k]=='cmi.core.session_time') {
  1262. params += '&t='+session_time;
  1263. } else if (my_get_value_scorm[k]=='cmi.core.lesson_status' && lesson_status!='') {
  1264. params += '&status='+lesson_status;
  1265. } else if (my_get_value_scorm[k]=='cmi.core.score.raw') {
  1266. params += '&s='+score;
  1267. } else if (my_get_value_scorm[k]=='cmi.core.score.max') {
  1268. params += '&max='+max;
  1269. } else if (my_get_value_scorm[k]=='cmi.core.score.min') {
  1270. params += '&min='+min;
  1271. } else if (my_get_value_scorm[k]=='cmi.core.lesson_location') {
  1272. params += '&loc='+lesson_location;
  1273. } else if (my_get_value_scorm[k]=='cmi.completion_status') {
  1274. } else if (my_get_value_scorm[k]=='cmi.score.scaled') {
  1275. } else if (my_get_value_scorm[k]=='cmi.suspend_data') {
  1276. params += '&suspend='+suspend_data;
  1277. } else if (my_get_value_scorm[k]=='cmi.completion_status') {
  1278. } else if (my_get_value_scorm[k]=='cmi.core.exit') {
  1279. params += '&core_exit='+lms_item_core_exit;
  1280. }
  1281. if (my_get_value_scorm[k]=='interactions') {
  1282. is_interactions='true';
  1283. } else {
  1284. is_interactions='false';
  1285. }
  1286. }
  1287. if (is_interactions=='true') {
  1288. interact_string = '';
  1289. for (i in interactions){
  1290. interact_string += '&interact['+i+']=';
  1291. interact_temp = '[';
  1292. for (j in interactions[i]) {
  1293. interact_temp += interactions[i][j]+',';
  1294. }
  1295. interact_temp = interact_temp.substr(0,(interact_temp.length-2)) + ']';
  1296. interact_string += encodeURIComponent(interact_temp);
  1297. }
  1298. //interact_string = encodeURIComponent(interact_string.substr(0,(interact_string.length-1)));
  1299. params += interact_string;
  1300. is_interactions='false';
  1301. }
  1302. //alert("parameters : "+params);
  1303. /*params = {
  1304. 'lid': lms_lp_id,
  1305. 'uid': lms_user_id,
  1306. 'vid': lms_view_id,
  1307. 'iid': lms_item_id,
  1308. 's': score,
  1309. 'max': max,
  1310. 'min': min,
  1311. 'status': lesson_status,
  1312. 't': session_time,
  1313. 'suspend': suspend_data,
  1314. 'loc': lesson_location,
  1315. 'interact': interac_string,
  1316. 'core_exit': lms_item_core_exit
  1317. }*/
  1318. $.ajax({
  1319. type:"GET",
  1320. data: params,
  1321. url: "lp_ajax_save_item.php",
  1322. dataType: "script",
  1323. async: false
  1324. }
  1325. );
  1326. params='';
  1327. }
  1328. /**
  1329. * Starts the timer with the server clock time.
  1330. * Originally, we used the xajax library. Now we use jQuery
  1331. */
  1332. function xajax_start_timer() {
  1333. $.ajax({
  1334. type: "GET",
  1335. url: "lp_ajax_start_timer.php",
  1336. dataType: "script",
  1337. async: false
  1338. });
  1339. }
  1340. /**
  1341. * Save a specific item's objectives into the LMS through
  1342. * an AJAX call. Originally, we used the xajax library. Now we use jQuery
  1343. */
  1344. function xajax_save_objectives(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,item_objectives) {
  1345. params='';
  1346. params += 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id;
  1347. params += '&iid='+lms_item_id;
  1348. obj_string = '';
  1349. for (i in item_objectives){
  1350. obj_string += '&objectives['+i+']=';
  1351. obj_temp = '[';
  1352. for (j in item_objectives[i]) {
  1353. obj_temp += item_objectives[i][j]+',';
  1354. }
  1355. obj_temp = obj_temp.substr(0,(obj_temp.length-2)) + ']';
  1356. obj_string += encodeURIComponent(obj_temp);
  1357. }
  1358. params += obj_string;
  1359. $.ajax({
  1360. type: "GET",
  1361. data: params,
  1362. url: "lp_ajax_save_objectives.php",
  1363. dataType: "script",
  1364. async: false
  1365. });
  1366. }
  1367. /**
  1368. * Switch between two items through
  1369. * an AJAX call. Originally, we used the xajax library. Now we use jQuery
  1370. */
  1371. function xajax_switch_item_details(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,next_item) {
  1372. params = {
  1373. 'lid': lms_lp_id,
  1374. 'uid': lms_user_id,
  1375. 'vid': lms_view_id,
  1376. 'iid': lms_item_id,
  1377. 'next': next_item
  1378. }
  1379. $.ajax({
  1380. type: "GET",
  1381. data: params,
  1382. url: "lp_ajax_switch_item.php",
  1383. dataType: "script",
  1384. async: false
  1385. });
  1386. }
  1387. addEvent(window,'load',addListeners,false);
  1388. if(lms_lp_type==1 || lms_item_type=='asset'){
  1389. xajax_start_timer();
  1390. }