scorm_api.php 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671
  1. <?php // $Id: scorm_api.php 21162 2009-06-01 16:18:46Z yannoo $
  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.scorm
  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. <?php
  164. if (api_get_setting('show_glossary_in_extra_tools') == 'true') {
  165. ?>
  166. if (lms_lp_type == 2) { //Only scorm
  167. attach_glossary_into_scorm();
  168. }
  169. <?php
  170. }
  171. ?>
  172. });
  173. });
  174. //Dokeos internal variables
  175. var saved_lesson_status = 'not attempted';
  176. var lms_lp_id = <?php echo $oLP->get_id();?>;
  177. var lms_item_id = <?php echo $oItem->get_id();?>;
  178. //var lms_new_item_id = 0; //temporary value (only there between a load_item() and a LMSInitialize())
  179. var lms_been_synchronized = 0;
  180. var lms_initialized = 0;
  181. var lms_total_lessons = <?php echo $oLP->get_total_items_count(); ?>;
  182. var lms_complete_lessons = <?php echo $oLP->get_complete_items_count();?>;
  183. var lms_progress_bar_mode = '<?php echo $oLP->progress_bar_mode;?>';
  184. if(lms_progress_bar_mode == ''){lms_progress_bar_mode='%';}
  185. var lms_view_id = '<?php echo $oLP->get_view();?>';
  186. if(lms_view_id == ''){ lms_view_id = 1;}
  187. var lms_user_id = '<?php echo $_user['user_id'];?>';
  188. var lms_next_item = '<?php echo $oLP->get_next_item_id();?>';
  189. var lms_previous_item = '<?php echo $oLP->get_previous_item_id();?>';
  190. var lms_lp_type = '<?php echo $oLP->get_type();?>';
  191. var lms_item_type = '<?php echo $oItem->get_type();?>';
  192. var lms_item_credit = '<?php echo $oItem->get_credit();?>';
  193. var lms_item_lesson_mode = '<?php echo $oItem->get_lesson_mode();?>';
  194. var lms_item_launch_data = '<?php echo $oItem->get_launch_data();?>';
  195. var lms_item_core_exit = '<?php echo $oItem->get_core_exit();?>';
  196. var asset_timer = 0;
  197. //Backup for old values
  198. var old_score = 0;
  199. var old_max = 0;
  200. var old_min = 0;
  201. var old_lesson_status = '';
  202. var old_session_time = '';
  203. var old_suspend_data = '';
  204. var lms_old_item_id = 0;
  205. var execute_stats='false';
  206. /**
  207. * Function called mandatorily by the SCORM content to start the SCORM communication
  208. */
  209. function LMSInitialize() { //this is the initialize function of all APIobjects
  210. /* load info for this new item by calling the js_api_refresh command in
  211. * the message frame. The message frame will update the JS variables by
  212. * itself, in JS, by doing things like top.lesson_status = 'not attempted'
  213. * and that kind of stuff, so when the content loads in the content frame
  214. * it will have all the correct variables set
  215. */
  216. G_LastError = G_NoError ;
  217. G_LastErrorMessage = 'No error';
  218. //reinit to list
  219. reinit_update_table_list ()
  220. lms_initialized=0;
  221. // if there are more parameters than ""
  222. if (arguments.length>1) {
  223. G_LastError = G_InvalidArgumentError;
  224. G_LastErrorMessage = G_InvalidArgumentErrorMessage;
  225. logit_scorm('Error '+ G_InvalidArgumentError + G_InvalidArgumentErrorMessage, 0);
  226. return('false');
  227. } else {
  228. logit_scorm('LMSInitialise()',0);
  229. lms_initialized=1;
  230. return('true');
  231. }
  232. }
  233. function Initialize()
  234. { //this is the initialize function of all APIobjects
  235. return LMSInitialize();
  236. }
  237. function LMSGetValue(param)
  238. {
  239. //logit_scorm("LMSGetValue('"+param+"')",1);
  240. G_LastError = G_NoError ;
  241. G_LastErrorMessage = 'No error';
  242. var result='';
  243. // the LMSInitialize is missing
  244. if (lms_initialized == 0) {
  245. G_LastError = G_NotInitialized;
  246. G_LastErrorMessage = G_NotInitializedMessage;
  247. logit_scorm('Error '+ G_NotInitialized + ' ' +G_NotInitializedMessage, 0);
  248. return '';
  249. }
  250. //Dokeos does not support this SCO object properties
  251. if (param == 'cmi.student_preference.text' ||
  252. param == 'cmi.student_preference.language' ||
  253. param == 'cmi.student_preference.speed' ||
  254. param == 'cmi.student_preference.audio' ||
  255. param == 'cmi.student_preference._children' ||
  256. param == 'cmi.student_data.time_limit_action' ||
  257. param == 'cmi.comments' ||
  258. param == 'cmi.comments_from_lms' ) {
  259. // the value is not supported
  260. G_lastError = G_NotImplementedError ;
  261. G_lastErrorString = G_NotImplementedErrorMessage;
  262. logit_scorm("LMSGetValue ('"+param+"') Error '"+G_NotImplementedErrorMessage+"'",1);
  263. result = '';
  264. return result;
  265. }
  266. // ---- cmi.core._children
  267. if(param=='cmi.core._children' || param=='cmi.core_children'){
  268. result='entry, exit, lesson_status, student_id, student_name, lesson_location, total_time, credit, lesson_mode, score, session_time';
  269. }else if(param == 'cmi.core.entry'){
  270. // ---- cmi.core.entry
  271. if(lms_item_core_exit=='none') {
  272. result='ab-initio';
  273. } else if(lms_item_core_exit=='suspend') {
  274. result='resume';
  275. } else {
  276. result='';
  277. }
  278. }else if(param == 'cmi.core.exit'){
  279. // ---- cmi.core.exit
  280. result='';
  281. G_LastError = G_ElementIsWriteOnly;
  282. }else if(param == 'cmi.core.session_time'){
  283. result='';
  284. G_LastError = G_ElementIsWriteOnly;
  285. }else if(param == 'cmi.core.lesson_status'){
  286. // ---- cmi.core.lesson_status
  287. if(lesson_status != '') {
  288. result=lesson_status;
  289. } else {
  290. //result='not attempted';
  291. }
  292. }else if(param == 'cmi.core.student_id'){
  293. // ---- cmi.core.student_id
  294. result='<?php echo $_user['user_id']; ?>';
  295. }else if(param == 'cmi.core.student_name'){
  296. // ---- cmi.core.student_name
  297. <?php
  298. $who=addslashes(api_get_person_name($_user['firstName'], $_user['lastName']));
  299. echo "result='$who';";
  300. ?>
  301. }else if(param == 'cmi.core.lesson_location'){
  302. // ---- cmi.core.lesson_location
  303. result=lesson_location;
  304. }else if(param == 'cmi.core.total_time'){
  305. // ---- cmi.core.total_time
  306. result=total_time;
  307. }else if(param == 'cmi.core.score._children'){
  308. // ---- cmi.core.score._children
  309. result='raw,min,max';
  310. }else if(param == 'cmi.core.score.raw'){
  311. // ---- cmi.core.score.raw
  312. result=score;
  313. }else if(param == 'cmi.core.score.max'){
  314. // ---- cmi.core.score.max
  315. result=max;
  316. }else if(param == 'cmi.core.score.min'){
  317. // ---- cmi.core.score.min
  318. result=min;
  319. }else if(param == 'cmi.core.score'){
  320. // ---- cmi.core.score -- non-standard item, provided as cmi.core.score.raw just in case
  321. result=score;
  322. }else if(param == 'cmi.core.credit'){
  323. // ---- cmi.core.credit
  324. result = lms_item_credit;
  325. }else if(param == 'cmi.core.lesson_mode'){
  326. // ---- cmi.core.lesson_mode
  327. result = lms_item_lesson_mode;
  328. }else if(param == 'cmi.suspend_data'){
  329. // ---- cmi.suspend_data
  330. result = suspend_data;
  331. }else if(param == 'cmi.launch_data'){
  332. // ---- cmi.launch_data
  333. result = lms_item_launch_data;
  334. }else if(param == 'cmi.objectives._children'){
  335. // ---- cmi.objectives._children
  336. result = 'id,score,status';
  337. }else if(param == 'cmi.objectives._count'){
  338. // ---- cmi.objectives._count
  339. //result='<?php echo $oItem->get_view_count();?>';
  340. result = item_objectives.length;
  341. }else if(param.substring(0,15)== 'cmi.objectives.'){
  342. var myres = '';
  343. if(myres = param.match(/cmi.objectives.(\d+).(id|score|status|_children)(.*)/))
  344. {
  345. var obj_id = myres[1];
  346. var req_type = myres[2];
  347. if(item_objectives[obj_id]==null)
  348. {
  349. if(req_type == 'id')
  350. {
  351. result = '';
  352. }else if(req_type == '_children'){
  353. result = 'id,score,status';
  354. }else if(req_type == 'score'){
  355. if(myres[3]==null)
  356. {
  357. result = '';
  358. G_lastError = G_NotImplementedError;
  359. G_lastErrorString = 'Not implemented yet';
  360. }else if (myres[3] == '._children'){
  361. result = 'raw,min,max'; //non-standard, added for NetG
  362. }else if (myres[3] == '.raw'){
  363. result = '';
  364. }else if (myres[3] == '.max'){
  365. result = '';
  366. }else if (myres[3] == '.min'){
  367. result = '';
  368. }else{
  369. result = '';
  370. G_lastError = G_NotImplementedError;
  371. G_lastErrorString = 'Not implemented yet';
  372. }
  373. }else if(req_type == 'status'){
  374. result = 'not attempted';
  375. }
  376. }
  377. else
  378. {
  379. //the object is not null
  380. if(req_type == 'id')
  381. {
  382. result = item_objectives[obj_id][0];
  383. }else if(req_type == '_children'){
  384. result = 'id,score,status';
  385. }else if(req_type == 'score'){
  386. if(myres[3]==null)
  387. {
  388. result = '';
  389. G_lastError = G_NotImplementedError;
  390. G_lastErrorString = 'Not implemented yet';
  391. }else if (myres[3] == '._children'){
  392. result = 'raw,min,max'; //non-standard, added for NetG
  393. }else if (myres[3] == '.raw'){
  394. if(item_objectives[obj_id][2] != null)
  395. {
  396. result = item_objectives[obj_id][2];
  397. }else{
  398. result = '';
  399. }
  400. }else if (myres[3] == '.max'){
  401. if(item_objectives[obj_id][3] != null)
  402. {
  403. result = item_objectives[obj_id][3];
  404. }else{
  405. result = '';
  406. }
  407. }else if (myres[3] == '.min'){
  408. if(item_objectives[obj_id][4] != null)
  409. {
  410. result = item_objectives[obj_id][4];
  411. }else{
  412. result = '';
  413. }
  414. }else{
  415. result = '';
  416. G_lastError = G_NotImplementedError;
  417. G_lastErrorString = 'Not implemented yet';
  418. }
  419. }else if(req_type == 'status'){
  420. if(item_objectives[obj_id][1] != null)
  421. {
  422. result = item_objectives[obj_id][1];
  423. }else{
  424. result = 'not attempted';
  425. }
  426. }
  427. }
  428. }
  429. }else if(param == 'cmi.student_data._children'){
  430. // ---- cmi.student_data._children
  431. result = 'mastery_score,max_time_allowed';
  432. }else if(param == 'cmi.student_data.mastery_score'){
  433. // ---- cmi.student_data.mastery_score
  434. result = mastery_score;
  435. }else if(param == 'cmi.student_data.max_time_allowed'){
  436. // ---- cmi.student_data.max_time_allowed
  437. result = max_time_allowed;
  438. }else if(param == 'cmi.interactions._count'){
  439. // ---- cmi.interactions._count
  440. result = interactions.length;
  441. }else if(param == 'cmi.interactions._children'){
  442. // ---- cmi.interactions._children
  443. result = 'id,time,type,correct_responses,weighting,student_response,result,latency';
  444. }else{
  445. // ---- anything else
  446. // Invalid argument error
  447. G_lastError = G_InvalidArgumentError ;
  448. G_lastErrorString = G_InvalidArgumentErrorMessage;
  449. logit_scorm("LMSGetValue ('"+param+"') Error '"+G_InvalidArgumentErrorMessage+"'",1);
  450. result = '';
  451. return result;
  452. }
  453. logit_scorm("LMSGetValue\n\t('"+param+"') returned '"+result+"'",1);
  454. return result;
  455. }
  456. function GetValue(param) {
  457. return LMSGetValue(param);
  458. }
  459. function LMSSetValue(param, val) {
  460. logit_scorm("LMSSetValue\n\t('"+param+"','"+val+"')",0);
  461. commit = true; //value has changed, need to re-commit
  462. G_LastError = G_NoError ;
  463. G_LastErrorMessage = 'No error';
  464. return_value = 'false';
  465. if( param == "cmi.core.score.raw" ) {
  466. score= val;
  467. updatetable_to_list['cmi.core.score.raw']='true';
  468. return_value='true';
  469. } else if ( param == "cmi.core.score.max" ) {
  470. max = val;
  471. updatetable_to_list['cmi.core.score.max']='true';
  472. return_value='true';
  473. } else if ( param == "cmi.core.score.min" ) {
  474. min = val;
  475. updatetable_to_list['cmi.core.score.min']='true';
  476. return_value='true';
  477. } else if ( param == "cmi.core.lesson_location" ) {
  478. lesson_location = val;
  479. updatetable_to_list['cmi.core.lesson_location']='true';
  480. return_value='true';
  481. } else if ( param == "cmi.core.lesson_status" ) {
  482. saved_lesson_status = lesson_status;
  483. lesson_status = val;
  484. updatetable_to_list['cmi.core.lesson_status']='true';
  485. return_value='true';
  486. } else if ( param == "cmi.completion_status" ) {
  487. lesson_status = val;
  488. updatetable_to_list['cmi.completion_status']='true';
  489. return_value='true'; //1.3
  490. } else if ( param == "cmi.core.session_time" ) {
  491. session_time = val;
  492. updatetable_to_list['cmi.core.session_time']='true';
  493. return_value='true';
  494. } else if ( param == "cmi.score.scaled") { //1.3
  495. if(val<=1 && val>=-1) {
  496. score = val ;
  497. updatetable_to_list['cmi.score.scaled']='true';
  498. return_value='true';
  499. } else {
  500. return_value='false';
  501. }
  502. } else if ( param == "cmi.success_status" ) {
  503. success_status = val;
  504. updatetable_to_list['cmi.success_status']='true';
  505. return_value='true'; //1.3
  506. } else if ( param == "cmi.suspend_data" ) {
  507. suspend_data = val;
  508. updatetable_to_list['cmi.suspend_data']='true';
  509. return_value='true';
  510. } else if ( param == "cmi.core.exit" ) {
  511. lms_item_core_exit = val;
  512. updatetable_to_list['cmi.core.exit']='true';
  513. return_value='true';
  514. } else if ( param == "cmi.core.student_id" ) {
  515. G_LastError = G_ElementIsReadOnly;
  516. } else if ( param == "cmi.core.student_name" ) {
  517. G_LastError = G_ElementIsReadOnly;
  518. } else if ( param == "cmi.core.credit" ) {
  519. G_LastError = G_ElementIsReadOnly;
  520. } else if ( param == "cmi.core.entry" ) {
  521. G_LastError = G_ElementIsReadOnly;
  522. } else if ( param == "cmi.core.total_time" ) {
  523. G_LastError = G_ElementIsReadOnly;
  524. } else if ( param == "cmi.core.lesson_mode" ) {
  525. G_LastError = G_ElementIsReadOnly;
  526. } else if ( param == "cmi.comments_from_lms" ) {
  527. G_LastError = G_ElementIsReadOnly;
  528. } else if ( param == "cmi.student_data.time_limit_action" ) {
  529. G_LastError = G_ElementIsReadOnly;
  530. } else if ( param == "cmi.student_data.mastery_score" ) {
  531. G_LastError = G_ElementIsReadOnly;
  532. } else if ( param == "cmi.student_data.max_time_allowed" ) {
  533. G_LastError = G_ElementIsReadOnly;
  534. } else if ( param == "cmi.student_preference._children" ) {
  535. G_LastError = G_ElementIsReadOnly;
  536. } else if ( param == "cmi.launch_data" ) {
  537. G_LastError = G_ElementIsReadOnly;
  538. } else {
  539. var myres = new Array();
  540. if(myres = param.match(/cmi.interactions.(\d+).(id|time|type|correct_responses|weighting|student_response|result|latency)(.*)/)) {
  541. updatetable_to_list['interactions']='true';
  542. elem_id = myres[1];
  543. if(elem_id > interactions.length) //interactions setting should start at 0
  544. {
  545. /*
  546. G_LastError = G_InvalidArgumentError;
  547. G_LastErrorString = 'Invalid argument (interactions)';
  548. return_value = false;
  549. */
  550. interactions[0] = ['0','','','','','','',''];
  551. }
  552. if(interactions[elem_id] == null){
  553. interactions[elem_id] = ['','','','','','','',''];
  554. //id(0), type(1), time(2), weighting(3),correct_responses(4),student_response(5),result(6),latency(7)
  555. interactions[elem_id][4] = new Array();
  556. }
  557. elem_attrib = myres[2];
  558. switch(elem_attrib) {
  559. case "id":
  560. interactions[elem_id][0] = val;
  561. logit_scorm("Interaction "+elem_id+"'s id updated",2);
  562. return_value='true';
  563. break;
  564. case "time":
  565. interactions[elem_id][2] = val;
  566. logit_scorm("Interaction "+elem_id+"'s time updated",2);
  567. return_value='true';
  568. break;
  569. case "type":
  570. interactions[elem_id][1] = val;
  571. logit_scorm("Interaction "+elem_id+"'s type updated",2);
  572. return_value='true';
  573. break;
  574. case "correct_responses":
  575. //do nothing yet
  576. interactions[elem_id][4].push(val);
  577. logit_scorm("Interaction "+elem_id+"'s correct_responses not updated",2);
  578. return_value='true';
  579. break;
  580. case "weighting":
  581. interactions[elem_id][3] = val;
  582. logit_scorm("Interaction "+elem_id+"'s weighting updated",2);
  583. return_value='true';
  584. break;
  585. case "student_response":
  586. interactions[elem_id][5] = ''+val;
  587. logit_scorm("Interaction "+elem_id+"'s student_response updated",2);
  588. return_value='true';
  589. break;
  590. case "result":
  591. interactions[elem_id][6] = val;
  592. logit_scorm("Interaction "+elem_id+"'s result updated",2);
  593. return_value='true';
  594. break;
  595. case "latency":
  596. interactions[elem_id][7] = val;
  597. logit_scorm("Interaction "+elem_id+"'s latency updated",2);
  598. return_value='true';
  599. break;
  600. default:
  601. G_lastError = G_NotImplementedError;
  602. G_lastErrorString = 'Not implemented yet';
  603. }
  604. }else if(param.substring(0,15)== 'cmi.objectives.'){
  605. var myres = '';
  606. updatetable_to_list['objectives']='true';
  607. if(myres = param.match(/cmi.objectives.(\d+).(id|score|status)(.*)/))
  608. {
  609. obj_id = myres[1];
  610. if(obj_id > item_objectives.length) //objectives setting should start at 0
  611. {
  612. G_LastError = G_InvalidArgumentError;
  613. G_LastErrorString = 'Invalid argument (objectives)';
  614. return_value = false;
  615. }
  616. else
  617. {
  618. req_type = myres[2];
  619. if(obj_id == null || obj_id == '')
  620. {
  621. ;//do nothing
  622. }
  623. else
  624. {
  625. if(item_objectives[obj_id]==null)
  626. {
  627. item_objectives[obj_id] = ['','','','',''];
  628. }
  629. if( req_type == "id" ) {
  630. //item_objectives[obj_id][0] = val.substring(51,57);
  631. item_objectives[obj_id][0] = val;
  632. logit_scorm("Objective "+obj_id+"'s id updated",2);
  633. return_value = 'true';
  634. } else if ( req_type == "score" ) {
  635. if (myres[3] == '._children'){
  636. return_value = '';
  637. G_lastError = G_InvalidSetValue;
  638. G_lastErrorString = 'Invalid set value, element is a keyword';
  639. }else if (myres[3] == '.raw'){
  640. item_objectives[obj_id][2] = val;
  641. logit_scorm("Objective "+obj_id+"'s score raw updated",2);
  642. return_value = 'true';
  643. }else if (myres[3] == '.max'){
  644. item_objectives[obj_id][3] = val;
  645. logit_scorm("Objective "+obj_id+"'s score max updated",2);
  646. return_value = 'true';
  647. }else if (myres[3] == '.min'){
  648. item_objectives[obj_id][4] = val;
  649. logit_scorm("Objective "+obj_id+"'s score min updated",2);
  650. return_value = 'true';
  651. }else{
  652. return_value = '';
  653. G_lastError = G_NotImplementedError;
  654. G_lastErrorString = 'Not implemented yet';
  655. }
  656. } else if ( req_type == "status" ) {
  657. item_objectives[obj_id][1] = val;
  658. logit_scorm("Objective "+obj_id+"'s status updated",2);
  659. return_value = 'true';
  660. } else {
  661. G_lastError = G_NotImplementedError;
  662. G_lastErrorString = 'Not implemented yet';
  663. }
  664. }
  665. }
  666. }
  667. }else{
  668. G_lastError = G_NotImplementedError;
  669. G_lastErrorString = G_NotImplementedErrorMessage;
  670. }
  671. }
  672. <?php
  673. if ($oLP->force_commit == 1){
  674. echo " var mycommit = LMSCommit('force');";
  675. }
  676. ?>
  677. return(return_value);
  678. }
  679. function SetValue(param, val) {
  680. return LMSSetValue(param, val);
  681. }
  682. function ProcessValueScorm () {
  683. for (i=0;i<variables_scorm.length;i++) {
  684. if (updatetable_to_list[variables_scorm[i]]=='true') {
  685. info_update_table=variables_scorm[i];
  686. variable_to_send.push(info_update_table);
  687. }
  688. }
  689. return variable_to_send;
  690. }
  691. function reinit_update_table_list () {
  692. for (i=0;i<variables_scorm.length;i++) {
  693. if (updatetable_to_list[variables_scorm[i]]=='true') {
  694. updatetable_to_list[variables_scorm[i]]='false';
  695. }
  696. }
  697. lesson_status='';
  698. }
  699. function savedata(origin) {
  700. //origin can be 'commit', 'finish' or 'terminate'
  701. if ((lesson_status != 'completed') && (lesson_status != 'passed') && (mastery_score >=0) && (score >= mastery_score)) {
  702. lesson_status = 'passed';
  703. updatetable_to_list['cmi.core.lesson_status']='true';
  704. } else if( (mastery_score < 0) && (lms_lp_type != '2') && ( lesson_status == 'incomplete') && (score >= (0.8*max) ) ) {
  705. //the status cannot be modified automatically by the LMS under SCORM 1.2's rules
  706. <?php if ($autocomplete_when_80pct){ ?>
  707. lesson_status = 'completed';
  708. updatetable_to_list['cmi.core.lesson_status']='true';
  709. <?php }?>
  710. ;
  711. } else {
  712. /*
  713. * See notes in switch_item for why this has been disabled
  714. if ((origin== 'finish' || origin == 'unload') && lesson_status != 'completed' && lesson_status != 'passed' && lesson_status != 'browsed' && lesson_status != 'failed' && lesson_status != 'incomplete') {
  715. // The SCORM1.2 Runtime object document says for the "cmi.core.lesson_status" variable:
  716. // Upon receiving the LMSFinish() call or the user navigates away,
  717. // the LMS should set the cmi.core.lesson_status for the SCO to 'completed'
  718. logit_lms('the LMS did saving data (status='+lesson_status+' - interactions: '+ interactions.length +')',1);
  719. if (mastery_score && mastery_score!= '' && score && score != '') {
  720. if (score >= mastery_score) {
  721. lesson_status = 'passed';
  722. } else {
  723. lesson_status = 'failed';
  724. }
  725. updatetable_to_list['cmi.core.lesson_status']='true';
  726. } else if (mastery_score && mastery_score!= '') {
  727. lesson_status = 'completed';
  728. updatetable_to_list['cmi.core.lesson_status']='true';
  729. }
  730. }
  731. */
  732. }
  733. my_get_value_scorm=new Array();
  734. my_get_value_scorm=ProcessValueScorm();
  735. logit_lms('saving data (status='+lesson_status+' - interactions: '+ interactions.length +')',1);
  736. old_item_id=info_lms_item[0];
  737. // xajax_save_item is replaced to xajax_save_item_scorm for scorm LP's
  738. //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);
  739. xajax_save_item_scorm(lms_lp_id, lms_user_id, lms_view_id, old_item_id,my_get_value_scorm);
  740. //info_lms_item[0] is old_item_id and info_lms_item[1] is current_item_id
  741. info_lms_item[0]=info_lms_item[0];
  742. info_lms_item[1]=lms_item_id;
  743. if(item_objectives.length>0) {
  744. xajax_save_objectives(lms_lp_id,lms_user_id,lms_view_id,old_item_id,item_objectives);
  745. }
  746. execute_stats='false';
  747. //clean array
  748. variable_to_send=new Array();
  749. my_get_value_scorm=new Array();
  750. }
  751. /*
  752. * See notes in switch_item for why this has been disabled
  753. function savedata_onunload() {
  754. savedata('unload');
  755. }
  756. */
  757. function LMSCommit(val) {
  758. logit_scorm('LMSCommit()',0);
  759. G_LastError = G_NoError ;
  760. G_LastErrorMessage = 'No error';
  761. savedata('commit');
  762. reinit_update_table_list();
  763. //commit = 'false' ; //now changes have been commited, no need to update until next SetValue()
  764. return('true');
  765. }
  766. function Commit(val) {
  767. return LMSCommit(val);
  768. }
  769. function LMSFinish(val) {
  770. G_LastError = G_NoError ;
  771. G_LastErrorMessage = 'No error';
  772. // why commit==false?
  773. if (( commit == false )) {
  774. logit_scorm('LMSFinish() (no LMSCommit())',1);
  775. }
  776. //if ( commit == true ) {
  777. logit_scorm('LMSFinish() called',1);
  778. savedata('finish');
  779. commit = 'false' ;
  780. //}
  781. //reinit to list
  782. reinit_update_table_list()
  783. return('true');
  784. }
  785. function Finish(val) {
  786. return LMSFinish(val);
  787. }
  788. function LMSGetLastError() {
  789. logit_scorm('LMSGetLastError()',1);
  790. return(G_LastError.toString());
  791. }
  792. function GetLastError() {
  793. return LMSGetLastError();
  794. }
  795. function LMSGetErrorString(errCode){
  796. logit_scorm('LMSGetErrorString()',1);
  797. return(G_LastErrorString);
  798. }
  799. function GetErrorString(errCode){
  800. return LMSGetErrorString(errCode);
  801. }
  802. function LMSGetDiagnostic(errCode){
  803. logit_scorm('LMSGetDiagnostic()',1);
  804. return(API.LMSGetLastError());
  805. }
  806. function GetDiagnostic(errCode){
  807. return LMSGetDiagnostic(errCode);
  808. }
  809. function Terminate()
  810. {
  811. if (lms_initialized == 0) {
  812. G_LastError = G_NotInitialized;
  813. G_LastErrorMessage = G_NotInitializedMessage;
  814. logit_scorm('Error '+ G_NotInitialized + G_NotInitializedMessage, 0);
  815. return('false');
  816. } else {
  817. logit_scorm('Terminate()',0);
  818. G_LastError = G_NoError ;
  819. G_LastErrorMessage = 'No error';
  820. commit = true;
  821. savedata('terminate');
  822. return (true);
  823. }
  824. }
  825. <?php
  826. //--------------------------------------------------------------------//
  827. /**
  828. * Dokeos-specific code that deals with event handling and inter-frames
  829. * messaging/refreshing.
  830. * Note that from now on, the Dokeos JS code in this library will act as
  831. * a controller, of the MVC pattern, and receive all requests for frame
  832. * updates, then redispatch to any frame concerned.
  833. */
  834. ?>
  835. /**
  836. * Defining the AJAX-object class to be made available from other frames
  837. */
  838. function XAJAXobject() {
  839. this.xajax_switch_item_details=xajax_switch_item_details;
  840. this.switch_item=switch_item;
  841. this.xajax_save_objectives=xajax_save_objectives;
  842. this.xajax_save_item = xajax_save_item;
  843. }
  844. //it is not sure that the scos use the above declarations
  845. oXAJAX = new XAJAXobject();
  846. oxajax = new XAJAXobject();
  847. /**
  848. * Cross-browser event handling by Scott Andrew
  849. * @param element Element that needs an event attached
  850. * @param string Event type (load, unload, click, keyDown, ...)
  851. * @param string Function name (the event handler)
  852. * @param string used in addEventListener
  853. */
  854. function addEvent(elm, evType, fn, useCapture){
  855. if(elm.addEventListener){
  856. elm.addEventListener(evType, fn, useCapture);
  857. return true;
  858. }else if (elm.attachEvent){
  859. var r = elm.attachEvent('on' + evType, fn);
  860. }else{
  861. elm['on'+evType] = fn;
  862. }
  863. }
  864. /**
  865. * Add listeners to the page objects. This has to be defined for
  866. * the current context as it acts on objects that should exist
  867. * on the page
  868. * possibly deprecated
  869. */
  870. function addListeners(){
  871. //exit if the browser doesn't support ID or tag retrieval
  872. logit_lms('Entering addListeners()',2);
  873. if(!document.getElementsByTagName){
  874. logit_lms("getElementsByTagName not available",2);
  875. return;
  876. }
  877. if(!document.getElementById){
  878. logit_lms("getElementById not available",2);
  879. return;
  880. }
  881. //assign event handlers to objects
  882. if(lms_lp_type==1 || lms_item_type=='asset'){
  883. logit_lms('Dokeos LP or asset',2);
  884. //if this path is a Dokeos learnpath, then start manual save
  885. //when something is loaded in there
  886. addEvent(window,'unload',dokeos_save_asset,false);
  887. logit_lms('Added event listener on content_id for unload',2);
  888. }
  889. /* See notes in switch_item() for why this has been disabled
  890. if (lms_lp_type==2) {
  891. addEvent(window,'unload',savedata_onunload,false);
  892. }
  893. */
  894. logit_lms('Quitting addListeners()',2);
  895. }
  896. /**
  897. * Load an item into the content frame:
  898. * - making sure the previous item status have been saved
  899. * - first updating the current item ID (to save the right item)
  900. * - updating the frame src
  901. * possibly deprecated
  902. */
  903. function load_item(item_id,url){
  904. if(document.getElementById('content_id')) {
  905. logit_lms('Loading item '+item_id,2);
  906. var cont_f = document.getElementById('content_id');
  907. if(cont_f.src){
  908. lms_old_item_id = lms_item_id;
  909. var lms_new_item_id = item_id;
  910. //load new content page into content frame
  911. if(lms_lp_type==1 || lms_item_type=='asset'){
  912. dokeos_save_asset();
  913. }
  914. cont_f.src = url;
  915. update_toc('unhighlight',lms_old_item_id);
  916. update_toc('highlight',lms_old_item_id);
  917. return true;
  918. }
  919. logit_lms('cont_f.src has no properties',0);
  920. }
  921. logit_lms('content_id has no properties',0);
  922. return false;
  923. }
  924. /**
  925. * Save a Dokeos learnpath item's time and mark as completed upon
  926. * leaving it
  927. */
  928. function dokeos_save_asset(){
  929. // only for dokeos lps
  930. if (execute_stats=='true') {
  931. execute_stats='false';
  932. } else {
  933. execute_stats='true';
  934. }
  935. if(lms_lp_type==1 || lms_item_type=='asset'){
  936. logit_lms('dokeos_save_asset',2);
  937. 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);
  938. if(item_objectives.length>0)
  939. {
  940. xajax_save_objectives(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,item_objectives);
  941. }
  942. }
  943. }
  944. /**
  945. * Save a Dokeos learnpath item's time and mark as completed upon leaving it.
  946. * Same function as dokeos_save_asset() but saves it with empty params
  947. * to use values set from another side in the database. Only used by Dokeos quizzes.
  948. * Also save the score locally because it hasn't been done through SetValue().
  949. * Saving the status will be dealt with by the XAJAX function.
  950. */
  951. function dokeos_void_save_asset(myscore,mymax)
  952. {
  953. logit_lms('dokeos_save_asset',2);
  954. score = myscore;
  955. if((mymax == null) || (mymax == '')){mymax = 100;} //assume a default of 100, otherwise the score will not get saved (see lpi->set_score())
  956. xajax_save_item(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, myscore, mymax);
  957. }
  958. /**
  959. * Logs information about SCORM messages into the log frame
  960. * @param string Message to log
  961. * @param integer Priority (0 for top priority, 3 for lowest)
  962. */
  963. function logit_scorm(message,priority){
  964. if(scorm_logs>=priority){
  965. if($("#lp_log_name") && $("#log_content")){
  966. $("#log_content").append("SCORM: " + message + "<br/>");
  967. }
  968. }
  969. }
  970. /**
  971. * Logs information about LMS activity into the log frame
  972. * @param string Message to log
  973. * @param integer Priority (0 for top priority, 3 for lowest)
  974. */
  975. function logit_lms(message,priority){
  976. if(lms_logs>=priority){
  977. if ($("#lp_log_name") && $("#log_content")) {
  978. $("#log_content").append("LMS: " + message + "<br />");
  979. }
  980. }
  981. }
  982. /**
  983. * update the Table Of Contents frame, by changing CSS styles, mostly
  984. * @param string Action to be taken
  985. * @param integer Item id to update
  986. */
  987. function update_toc(update_action,update_id,change_ids)
  988. {
  989. if (!change_ids || change_ids != 'no') {
  990. change_ids = 'yes';
  991. }
  992. var myelem = $("#toc_"+update_id);
  993. var myelemimg = $("#toc_img_"+update_id);
  994. logit_lms('update_toc("'+update_action+'",'+update_id+')',2);
  995. if(update_id != 0)
  996. {
  997. switch(update_action)
  998. {
  999. case 'unhighlight':
  1000. if (update_id%2==0)
  1001. {
  1002. myelem.attr('class',"scorm_item_2");
  1003. }
  1004. else
  1005. {
  1006. myelem.attr('class',"scorm_item_1");
  1007. }
  1008. break;
  1009. case 'highlight':
  1010. if (change_ids=='yes') {
  1011. lms_next_item = update_id;
  1012. lms_previous_item = update_id;
  1013. }
  1014. myelem.attr('class',"scorm_item_highlight");
  1015. break;
  1016. case 'not attempted':
  1017. if( myelemimg.attr('src') != '../img/notattempted.gif') {
  1018. myelemimg.attr('src','../img/notattempted.gif');
  1019. myelemimg.attr('alt','n');
  1020. }
  1021. break;
  1022. case 'incomplete':
  1023. if( myelemimg.attr('src') != '../img/incomplete.gif') {
  1024. myelemimg.attr('src','../img/incomplete.gif');
  1025. myelemimg.attr('alt','i');
  1026. }
  1027. break;
  1028. case 'completed':
  1029. if( myelemimg.attr('src') != '../img/completed.gif') {
  1030. myelemimg.attr('src','../img/completed.gif');
  1031. myelemimg.attr('alt','c');
  1032. }
  1033. break;
  1034. case 'failed':
  1035. if( myelemimg.attr('src') != '../img/failed.gif') {
  1036. myelemimg.attr('src','../img/failed.gif');
  1037. myelemimg.attr('alt','f');
  1038. }
  1039. break;
  1040. case 'passed':
  1041. if( myelemimg.attr('src') != '../img/completed.gif' && myelemimg.attr('alt') != 'passed') {
  1042. myelemimg.attr('src','../img/completed.gif');
  1043. myelemimg.attr('alt','p');
  1044. }
  1045. break;
  1046. case 'browsed':
  1047. if( myelemimg.attr('src') != '../img/completed.gif' && myelemimg.attr('alt') != 'browsed') {
  1048. myelemimg.attr('src','../img/completed.gif');
  1049. myelemimg.attr('alt','b');
  1050. }
  1051. break;
  1052. default:
  1053. logit_lms('Update action unknown',2);
  1054. break;
  1055. }
  1056. }
  1057. return true;
  1058. }
  1059. function update_stats() {
  1060. if (execute_stats=='true') {
  1061. try {
  1062. cont_f = document.getElementById('content_id');
  1063. cont_f.src="lp_controller.php?action=stats";
  1064. cont_f.reload();
  1065. } catch (e) {
  1066. return false;
  1067. }
  1068. }
  1069. execute_stats='false';
  1070. }
  1071. /**
  1072. * Updates the progress bar with the new status. Prevents the need of a page refresh and flickering
  1073. * @param integer Number of completed items
  1074. * @param integer Number of items in total
  1075. * @param string Display mode (absolute 'abs' or percentage '%').Defaults to %
  1076. */
  1077. function update_progress_bar(nbr_complete, nbr_total, mode)
  1078. {
  1079. logit_lms('update_progress_bar('+nbr_complete+','+nbr_total+','+mode+')',2);
  1080. logit_lms('could update with data: '+lms_lp_id+','+lms_view_id+','+lms_user_id,2);
  1081. if(mode == ''){mode='%';}
  1082. if(nbr_total == 0){nbr_total=1;}
  1083. var percentage = (nbr_complete/nbr_total)*100;
  1084. percentage = Math.round(percentage);
  1085. var pr_text = $("#progress_text");
  1086. var pr_full = $("#progress_img_full");
  1087. var pr_empty = $("#progress_img_empty");
  1088. pr_full.attr('width',percentage*1.2);
  1089. pr_empty.attr('width',(100-percentage)*1.2);
  1090. var mytext = '';
  1091. switch(mode){
  1092. case 'abs':
  1093. mytext = nbr_complete + '/' + nbr_total;
  1094. break;
  1095. case '%':
  1096. default:
  1097. mytext = percentage + '%';
  1098. break;
  1099. }
  1100. pr_text.html(mytext);
  1101. return true;
  1102. }
  1103. function update_stats_page()
  1104. {
  1105. var myframe = document.getElementById('content_id');
  1106. var mysrc = myframe.location.href;
  1107. if(mysrc == 'lp_controller.php?action=stats'){
  1108. if(myframe && myframe.src){
  1109. var mysrc = myframe.src;
  1110. myframe.src = mysrc;
  1111. }
  1112. // = mysrc; //refresh page
  1113. }
  1114. return true;
  1115. }
  1116. /**
  1117. * Updates the message frame with the given string
  1118. */
  1119. function update_message_frame(msg_msg)
  1120. {
  1121. if(msg_msg==null){msg_msg='';}
  1122. if(!($("#msg_div_id"))){
  1123. logit_lms('In update_message_frame() - message frame has no document property',0);
  1124. }else{
  1125. logit_lms('In update_message_frame() - updating frame',0);
  1126. $("#msg_div_id").html(msg_msg);
  1127. }
  1128. }
  1129. /**
  1130. * Function that handles the saving of an item and switching from an item to another.
  1131. * Once called, this function should be able to do the whole process of
  1132. * (1) saving the current item,
  1133. * (2) refresh all the values inside the SCORM API object,
  1134. * (3) open the new item into the content_id frame,
  1135. * (4) refresh the table of contents
  1136. * (5) refresh the progress bar (completion)
  1137. * (6) refresh the message frame
  1138. * @param integer Dokeos ID for the current item
  1139. * @param string This parameter can be a string specifying the next
  1140. * item (like 'next', 'previous', 'first' or 'last') or the id to the next item
  1141. */
  1142. function switch_item(current_item, next_item){
  1143. //backup these params
  1144. var orig_current_item = current_item;
  1145. var orig_next_item = next_item;
  1146. var orig_lesson_status = lesson_status;
  1147. //(1) save the current item
  1148. logit_lms('Called switch_item with params '+lms_item_id+' and '+next_item+'',0);
  1149. if(lms_lp_type==1 || lms_item_type=='asset' || session_time == '0' || session_time == '0:00:00'){
  1150. if (lms_lp_type==1) {
  1151. 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);
  1152. } else {
  1153. my_get_value_scorm=new Array();
  1154. my_get_value_scorm=ProcessValueScorm();
  1155. xajax_save_item_scorm(lms_lp_id, lms_user_id, lms_view_id, lms_item_id,my_get_value_scorm);
  1156. }
  1157. if(item_objectives.length>0) {
  1158. xajax_save_objectives(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,item_objectives);
  1159. }
  1160. }else{
  1161. /**
  1162. * Because of SCORM 1.2's special rule about unsent commits and the fact
  1163. * that a SCO should be SET TO 'completed' IF NO STATUS WAS SENT (and
  1164. * then some checks have to be done on score), we have to force a
  1165. * special commit here to avoid getting to the next element with a
  1166. * missing prerequisite. The 'onunload' event is treated with
  1167. * savedata_onunload(), and doesn't need to be triggered at any
  1168. * particular time, but here we are in the case of switching to another
  1169. * item, so this is particularly important to complete the element in
  1170. * time.
  1171. * However, this cannot be initiated from the JavaScript, mainly
  1172. * because another onunload event can be triggered by the SCO itself,
  1173. * which can set, for example, the status to incomplete while the
  1174. * status has already been set to "completed" by the hand-made
  1175. * savedata(unload) (and then the status cannot be "incompleted"
  1176. * anymore)
  1177. */
  1178. //if (lms_item_type=='sco' && lesson_status != 'completed' && lesson_status != 'passed' && lesson_status != 'browsed' && lesson_status != 'incomplete' && lesson_status != 'failed') {
  1179. /**
  1180. * savedata('finish') treats the special condition and saves the
  1181. * new status to the database, so switch_item_details() enjoys the
  1182. * new status
  1183. */
  1184. //savedata('finish');
  1185. //}
  1186. // 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);
  1187. }
  1188. execute_stats=false;
  1189. //(2) Refresh all the values inside this SCORM API object - use AJAX
  1190. xajax_switch_item_details(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,next_item);
  1191. status_info.push(lesson_status);
  1192. //current item
  1193. //old item
  1194. //info_lms_item[0]=next_item;
  1195. if (info_lms_item[1]==next_item && next_item!='next' && next_item!='previous') {
  1196. info_lms_item[0]=next_item;
  1197. info_lms_item[1]=next_item;
  1198. } else {
  1199. if (next_item!='next' && next_item!='previous') {
  1200. info_lms_item[0]=info_lms_item[1];
  1201. info_lms_item[1]=next_item;
  1202. }
  1203. }
  1204. if (info_lms_item[0]==next_item && next_item!='next' && next_item!='previous') {
  1205. info_lms_item[0]=next_item;
  1206. info_lms_item[1]=next_item;
  1207. } else {
  1208. if (next_item!='next' && next_item!='previous') {
  1209. info_lms_item[0]=info_lms_item[0];
  1210. info_lms_item[1]=next_item;
  1211. }
  1212. }
  1213. //(3) open the new item in the content_id frame
  1214. switch(next_item){
  1215. case 'next':
  1216. next_item = lms_next_item;
  1217. info_lms_item[0]=info_lms_item[1];
  1218. info_lms_item[1]=lms_next_item;
  1219. break;
  1220. case 'previous':
  1221. next_item = lms_previous_item;
  1222. info_lms_item[0]=info_lms_item[1];
  1223. info_lms_item[1]=lms_previous_item;
  1224. break;
  1225. default:
  1226. break;
  1227. }
  1228. var mysrc = 'lp_controller.php?action=content&lp_id='+lms_lp_id+'&item_id='+next_item;
  1229. var cont_f = $("#content_id");
  1230. <?php if($oLP->mode == 'fullscreen'){ ?>
  1231. cont_f = window.open(''+mysrc,'content_id','toolbar=0,location=0,status=0,scrollbars=1,resizable=1');
  1232. cont_f.onload=function(){
  1233. info_lms_item[0]=info_lms_item[1];
  1234. info_lms_item[1]= info_lms_item[1];
  1235. }
  1236. cont_f.onunload=function(){
  1237. info_lms_item[0]=info_lms_item[1];
  1238. info_lms_item[1]= info_lms_item[1];
  1239. }
  1240. <?php } else { ?>
  1241. cont_f.attr("src",mysrc);
  1242. <?php } ?>
  1243. if(lms_lp_type==1 || lms_item_type=='asset'){
  1244. xajax_start_timer();
  1245. }
  1246. //(4) refresh the audio player if needed
  1247. $.ajax({
  1248. type: "GET",
  1249. url: "lp_nav.php",
  1250. data: "",
  1251. success: function(tmp_data) {
  1252. $("#media").html(tmp_data);
  1253. }
  1254. });
  1255. /*
  1256. if ( lms_lp_type==2 && (orig_lesson_status == 'not attempted' || orig_lesson_status == '') && orig_current_item != orig_next_item) {
  1257. params = 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id+'&iid='+orig_current_item;
  1258. $.ajax({
  1259. type:"GET",
  1260. data: params,
  1261. url: "lp_ajax_last_update_status.php",
  1262. dataType: "script"
  1263. });
  1264. }
  1265. */
  1266. return true;
  1267. }
  1268. /**
  1269. * Save a specific item (with its interactions, if any) into the LMS through
  1270. * an AJAX call. Originally, we used the xajax library. Now we use jQuery.
  1271. * Because of the need to pass an array, we have to build the parameters
  1272. * manually into GET[]
  1273. */
  1274. 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) {
  1275. params='';
  1276. params += 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id;
  1277. params += '&iid='+lms_item_id+'&s='+score+'&max='+max+'&min='+min;
  1278. params += '&status='+lesson_status+'&t='+session_time;
  1279. params += '&suspend='+suspend_data+'&loc='+lesson_location;
  1280. params += '&core_exit='+lms_item_core_exit;
  1281. interact_string = '';
  1282. for (i in interactions){
  1283. interact_string += '&interact['+i+']=';
  1284. interact_temp = '[';
  1285. for (j in interactions[i]) {
  1286. interact_temp += interactions[i][j]+',';
  1287. }
  1288. interact_temp = interact_temp.substr(0,(interact_temp.length-2)) + ']';
  1289. interact_string += encodeURIComponent(interact_temp);
  1290. }
  1291. //interact_string = encodeURIComponent(interact_string.substr(0,(interact_string.length-1)));
  1292. params += interact_string;
  1293. /*params = {
  1294. 'lid': lms_lp_id,
  1295. 'uid': lms_user_id,
  1296. 'vid': lms_view_id,
  1297. 'iid': lms_item_id,
  1298. 's': score,
  1299. 'max': max,
  1300. 'min': min,
  1301. 'status': lesson_status,
  1302. 't': session_time,
  1303. 'suspend': suspend_data,
  1304. 'loc': lesson_location,
  1305. 'interact': interac_string,
  1306. 'core_exit': lms_item_core_exit
  1307. }
  1308. */
  1309. if ( lms_lp_type==1) {
  1310. $.ajax({
  1311. type:"GET",
  1312. data: params,
  1313. url: "lp_ajax_save_item.php",
  1314. dataType: "script",
  1315. async: false
  1316. }
  1317. );
  1318. }
  1319. }
  1320. function xajax_save_item_scorm(lms_lp_id, lms_user_id, lms_view_id, lms_item_id,info_get_lms) {
  1321. // var variables_scorm = new Array('cmi.core.score.raw','cmi.core.score.max','cmi.core.score.min','cmi.core.lesson_location',
  1322. //'cmi.core.lesson_status','cmi.completion_status','cmi.core.session_time','cmi.score.scaled','cmi.success_status',
  1323. //'cmi.suspend_data','cmi.core.exit','interactions');
  1324. var is_interactions='false';
  1325. var params='';
  1326. params += 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id+'&iid='+lms_item_id;
  1327. for (k=0;k<info_get_lms.length;k++) {
  1328. if (my_get_value_scorm[k]=='cmi.core.session_time') {
  1329. params += '&t='+session_time;
  1330. } else if (my_get_value_scorm[k]=='cmi.core.lesson_status' && lesson_status!='') {
  1331. params += '&status='+lesson_status;
  1332. } else if (my_get_value_scorm[k]=='cmi.core.score.raw') {
  1333. params += '&s='+score;
  1334. } else if (my_get_value_scorm[k]=='cmi.core.score.max') {
  1335. params += '&max='+max;
  1336. } else if (my_get_value_scorm[k]=='cmi.core.score.min') {
  1337. params += '&min='+min;
  1338. } else if (my_get_value_scorm[k]=='cmi.core.lesson_location') {
  1339. params += '&loc='+lesson_location;
  1340. } else if (my_get_value_scorm[k]=='cmi.completion_status') {
  1341. } else if (my_get_value_scorm[k]=='cmi.score.scaled') {
  1342. } else if (my_get_value_scorm[k]=='cmi.suspend_data') {
  1343. params += '&suspend='+suspend_data;
  1344. } else if (my_get_value_scorm[k]=='cmi.completion_status') {
  1345. } else if (my_get_value_scorm[k]=='cmi.core.exit') {
  1346. params += '&core_exit='+lms_item_core_exit;
  1347. }
  1348. if (my_get_value_scorm[k]=='interactions') {
  1349. is_interactions='true';
  1350. } else {
  1351. is_interactions='false';
  1352. }
  1353. }
  1354. if (is_interactions=='true') {
  1355. interact_string = '';
  1356. temp = '';
  1357. for (i in interactions){
  1358. interact_string += '&interact['+i+']=';
  1359. interact_temp = '[';
  1360. for (j in interactions[i]) {
  1361. temp = interactions[i][j];
  1362. temp = ''+temp; // if temp == 1 there are problems with indexOf and an integer number
  1363. //this fix when an interaction have ',' i.e: {a,b,c,d} is replace to {a@.|@b@.|@c@.|@d} see DT#4444
  1364. while(temp.indexOf(',') >= 0){
  1365. temp = temp.replace(',','@.|@');
  1366. };
  1367. interact_temp +=temp+',';
  1368. }
  1369. interact_temp = interact_temp.substr(0,(interact_temp.length-2)) + ']';
  1370. // interact_string += encodeURIComponent(interact_temp);
  1371. interact_string += interact_temp;
  1372. }
  1373. //interact_string = encodeURIComponent(interact_string.substr(0,(interact_string.length-1)));
  1374. params += interact_string;
  1375. is_interactions='false';
  1376. }
  1377. //alert("parameters : "+params);
  1378. /*params = {
  1379. 'lid': lms_lp_id,
  1380. 'uid': lms_user_id,
  1381. 'vid': lms_view_id,
  1382. 'iid': lms_item_id,
  1383. 's': score,
  1384. 'max': max,
  1385. 'min': min,
  1386. 'status': lesson_status,
  1387. 't': session_time,
  1388. 'suspend': suspend_data,
  1389. 'loc': lesson_location,
  1390. 'interact': interac_string,
  1391. 'core_exit': lms_item_core_exit
  1392. }*/
  1393. $.ajax({
  1394. type:"GET",
  1395. data: params,
  1396. url: "lp_ajax_save_item.php",
  1397. dataType: "script",
  1398. async: false
  1399. }
  1400. );
  1401. params='';
  1402. }
  1403. /**
  1404. * Starts the timer with the server clock time.
  1405. * Originally, we used the xajax library. Now we use jQuery
  1406. */
  1407. function xajax_start_timer() {
  1408. $.ajax({
  1409. type: "GET",
  1410. url: "lp_ajax_start_timer.php",
  1411. dataType: "script",
  1412. async: false
  1413. });
  1414. }
  1415. /**
  1416. * Save a specific item's objectives into the LMS through
  1417. * an AJAX call. Originally, we used the xajax library. Now we use jQuery
  1418. */
  1419. function xajax_save_objectives(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,item_objectives) {
  1420. params='';
  1421. params += 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id;
  1422. params += '&iid='+lms_item_id;
  1423. obj_string = '';
  1424. for (i in item_objectives){
  1425. obj_string += '&objectives['+i+']=';
  1426. obj_temp = '[';
  1427. for (j in item_objectives[i]) {
  1428. obj_temp += item_objectives[i][j]+',';
  1429. }
  1430. obj_temp = obj_temp.substr(0,(obj_temp.length-2)) + ']';
  1431. obj_string += encodeURIComponent(obj_temp);
  1432. }
  1433. params += obj_string;
  1434. $.ajax({
  1435. type: "GET",
  1436. data: params,
  1437. url: "lp_ajax_save_objectives.php",
  1438. dataType: "script",
  1439. async: false
  1440. });
  1441. }
  1442. /**
  1443. * Switch between two items through
  1444. * an AJAX call. Originally, we used the xajax library. Now we use jQuery
  1445. */
  1446. function xajax_switch_item_details(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,next_item) {
  1447. params = {
  1448. 'lid': lms_lp_id,
  1449. 'uid': lms_user_id,
  1450. 'vid': lms_view_id,
  1451. 'iid': lms_item_id,
  1452. 'next': next_item
  1453. }
  1454. $.ajax({
  1455. type: "GET",
  1456. data: params,
  1457. url: "lp_ajax_switch_item.php",
  1458. dataType: "script",
  1459. async: false
  1460. });
  1461. }
  1462. addEvent(window,'load',addListeners,false);
  1463. if(lms_lp_type==1 || lms_item_type=='asset'){
  1464. xajax_start_timer();
  1465. }
  1466. /**
  1467. *Allow attach the glossary terms into html document of scorm
  1468. *Added by Isaac flores
  1469. */
  1470. function attach_glossary_into_scorm() {
  1471. var f = $('#content_id')[0];
  1472. var doc = f.contentWindow ? f.contentWindow.document :
  1473. f.contentDocument ? f.contentDocument : f.document;
  1474. var $frame_content = $('body',doc);
  1475. var my_text=$frame_content.html();
  1476. my_protocol = location.protocol;
  1477. my_pathname=location.pathname;
  1478. work_path = my_pathname.substr(0,my_pathname.indexOf('/courses/'));
  1479. $.ajax({
  1480. contentType: "application/x-www-form-urlencoded",
  1481. beforeSend: function(objeto) {
  1482. },
  1483. type: "POST",
  1484. url: my_protocol+"//"+location.host+work_path+"/main/glossary/glossary_ajax_request.php",
  1485. data: "glossary_data=true",
  1486. success: function(datos) {
  1487. if (datos.length==0) {
  1488. return false;
  1489. }
  1490. data_terms=datos.split("[|.|_|.|-|.|]");
  1491. for(i=0;i<data_terms.length;i++) {
  1492. specific_terms=data_terms[i].split("__|__|");
  1493. var real_term = specific_terms[1];
  1494. var my_specific_terms = new RegExp('(^|)'+specific_terms[1]+'[^ ]?',"gi");
  1495. new_html=my_text.replace(my_specific_terms,function(m){return replace_complete_char(m)});
  1496. $frame_content.html(new_html);
  1497. my_text=$frame_content.html();
  1498. }
  1499. //mouse over event
  1500. $("iframe").contents().find('body').find('.glossary-ajax').mouseover(function(){
  1501. random_id=Math.round(Math.random()*100);
  1502. div_show_id="div_show_id"+random_id;
  1503. div_content_id="div_content_id"+random_id;
  1504. $(this).append("<div id="+div_show_id+" ><div id="+div_content_id+">&nbsp;</div></div>");
  1505. $("iframe").contents().find('body').find("div#"+div_show_id).attr("style","display:inline;float:left;position:absolute;background-color:#F5F6CE;border-bottom: 1px dashed #dddddd;border-right: 1px dashed #dddddd;border-left: 1px dashed #dddddd;border-top: 1px dashed #dddddd;color:#305582;margin-left:5px;margin-right:5px;");
  1506. $("iframe").contents().find('body').find("div#"+div_content_id).attr("style","background-color:#F5F6CE;color:#305582;margin-left:8px;margin-right:8px;margin-top:5px;margin-bottom:5px;");
  1507. notebook_id=$(this).attr("name");
  1508. data_notebook=notebook_id.split("link");
  1509. my_glossary_id=data_notebook[1];
  1510. $.ajax({
  1511. contentType: "application/x-www-form-urlencoded",
  1512. beforeSend: function(objeto) {
  1513. $("iframe").contents().find('body').find("div#"+div_content_id).html("<img src="+my_protocol+"//"+location.host+work_path+"/main/inc/lib/javascript/indicator.gif />"); },
  1514. type: "POST",
  1515. url: my_protocol+"//"+location.host+work_path+"/main/glossary/glossary_ajax_request.php",
  1516. data: "glossary_id="+my_glossary_id,
  1517. success: function(datos) {
  1518. $("iframe").contents().find('body').find("div#"+div_content_id).html(datos);
  1519. }
  1520. });
  1521. });
  1522. // mouse out event
  1523. $("iframe").contents().find('body').find('.glossary-ajax').mouseout(function(){
  1524. var current_element,
  1525. current_element=$(this);
  1526. div_show_id=current_element.find("div").attr("id");
  1527. $("iframe").contents().find('body').find("div#"+div_show_id).remove();
  1528. });
  1529. //Callback Helper
  1530. function replace_complete_char(m) {
  1531. var complete_term_pattern = new RegExp(real_term,"i");
  1532. var tag = m.replace(complete_term_pattern," <span class=\"glossary-ajax\" style='color:blue' name=\"link"+specific_terms[0]+"\">$&</span>");
  1533. return tag;
  1534. }
  1535. }
  1536. });
  1537. }