aicc_api.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. <?php // $Id: $
  2. /**
  3. ==============================================================================
  4. * API event handler functions for AICC / CMIv4 in API communication mode
  5. *
  6. * @author Denes Nagy <darkden@freemail.hu>
  7. * @author Yannick Warnier <ywarnier@beeznest.org>
  8. * @version v 1.0
  9. * @access public
  10. * @package dokeos.learnpath
  11. * @license GNU/GPL - See Dokeos license directory for details
  12. ==============================================================================
  13. */
  14. /**
  15. * This script is divided into three sections.
  16. * The first section (below) is the initialisation part.
  17. * The second section is the AICC object part
  18. * The third section defines the event handlers for Dokeos' internal messaging
  19. * and frames refresh
  20. *
  21. * This script implements the API messaging for AICC. The HACP messaging is
  22. * made by another set of scripts.
  23. */
  24. /*
  25. ==============================================================================
  26. INIT SECTION
  27. ==============================================================================
  28. */
  29. //Load common libraries using a compatibility script to bridge between 1.6 and 1.8
  30. require_once('back_compat.inc.php');
  31. //Load learning path libraries so we can use the objects to define the initial values
  32. //of the API
  33. require_once('learnpath.class.php');
  34. require_once('learnpathItem.class.php');
  35. require_once('aicc.class.php');
  36. $_uid = $_SESSION['_uid'];
  37. $_user = $_SESSION['_user'];
  38. $file = $_SESSION['file'];
  39. $oLP = unserialize($_SESSION['lpobject']);
  40. $oItem = $oLP->items[$oLP->current];
  41. if(!is_object($oItem)){
  42. error_log('New LP - scorm_api - Could not load oItem item',0);
  43. exit;
  44. }
  45. $autocomplete_when_80pct = 0;
  46. /*
  47. ==============================================================================
  48. JavaScript Functions
  49. ==============================================================================
  50. */
  51. ?>var scorm_logs='<?php echo (empty($oLP->scorm_debug)?'0':'3');?>'; //debug log level for SCORM. 0 = none, 1=light, 2=a lot, 3=all - displays logs in log frame
  52. var lms_logs=0; //debug log level for LMS actions. 0=none, 1=light, 2=a lot, 3=all
  53. //logit_lms('scormfunctions.php included',0);
  54. function APIobject() {
  55. this.LMSInitialize=LMSInitialize; //for Scorm 1.2
  56. this.Initialize=LMSInitialize; //for Scorm 1.3
  57. this.LMSGetValue=LMSGetValue;
  58. this.GetValue=LMSGetValue;
  59. this.LMSSetValue=LMSSetValue;
  60. this.SetValue=LMSSetValue;
  61. this.LMSCommit=LMSCommit;
  62. this.Commit=LMSCommit;
  63. this.LMSFinish=LMSFinish;
  64. this.Finish=LMSFinish;
  65. this.LMSGetLastError=LMSGetLastError;
  66. this.GetLastError=LMSGetLastError;
  67. this.LMSGetErrorString=LMSGetErrorString;
  68. this.GetErrorString=LMSGetErrorString;
  69. this.LMSGetDiagnostic=LMSGetDiagnostic;
  70. this.GetDiagnostic=LMSGetDiagnostic;
  71. this.Terminate=Terminate; //only in Scorm 1.3
  72. }
  73. //it is not sure that the scos use the above declarations
  74. API = new APIobject(); //for scorm 1.2
  75. api = new APIobject(); //for scorm 1.2
  76. API_1484_11 = new APIobject(); //for scorm 1.3
  77. api_1484_11 = new APIobject(); //for scorm 1.3
  78. var G_NoError = 0;
  79. var G_GeneralException = 101;
  80. var G_ServerBusy = 102;
  81. var G_InvalidArgumentError = 201;
  82. var G_ElementCannotHaveChildren = 202;
  83. var G_ElementIsNotAnArray = 203;
  84. var G_NotInitialized = 301;
  85. var G_NotImplementedError = 401;
  86. var G_InvalidSetValue = 402;
  87. var G_ElementIsReadOnly = 403;
  88. var G_ElementIsWriteOnly = 404;
  89. var G_IncorrectDataType = 405;
  90. var G_LastError = G_NoError ;
  91. var commit = false ;
  92. //Strictly scorm variables
  93. var score=<?php echo $oItem->get_score();?>;
  94. var max=<?php echo $oItem->get_max();?>;
  95. var min=<?php echo $oItem->get_min();?>;
  96. var lesson_status='<?php echo $oItem->get_status();?>';
  97. var session_time='<?php echo $oItem->get_scorm_time('js');?>';
  98. var suspend_data = '<?php echo $oItem->get_suspend_data();?>';
  99. var lesson_location = '<?php echo $oItem->get_lesson_location();?>';
  100. var total_time = '<?php echo $oItem->get_scorm_time('js');?>';
  101. //Dokeos internal variables
  102. var saved_lesson_status = 'not attempted';
  103. var lms_lp_id = <?php echo $oLP->get_id();?>;
  104. var lms_item_id = <?php echo $oItem->get_id();?>;
  105. //var lms_new_item_id = 0; //temporary value (only there between a load_item() and a LMSInitialize())
  106. var lms_been_synchronized = 0;
  107. var lms_initialized = 0;
  108. var lms_total_lessons = <?php echo $oLP->get_total_items_count(); ?>;
  109. var lms_complete_lessons = <?php echo $oLP->get_complete_items_count();?>;
  110. var lms_progress_bar_mode = '<?php echo $oLP->progress_bar_mode;?>';
  111. if(lms_progress_bar_mode == ''){lms_progress_bar_mode='%';}
  112. var lms_view_id = '<?php echo $oLP->get_view();?>';
  113. if(lms_view_id == ''){ lms_view_id = 1;}
  114. var lms_user_id = '<?php echo $_uid;?>';
  115. var lms_next_item = '<?php echo $oLP->get_next_item_id();?>';
  116. var lms_previous_item = '<?php echo $oLP->get_previous_item_id();?>';
  117. var lms_lp_type = '<?php echo $oLP->get_type();?>';
  118. var lms_item_type = '<?php echo $oItem->get_type();?>';
  119. //Backup for old values
  120. var old_score = 0;
  121. var old_max = 0;
  122. var old_min = 0;
  123. var old_lesson_status = '';
  124. var old_session_time = '';
  125. var old_suspend_data = '';
  126. var lms_old_item_id = 0;
  127. /**
  128. * Function called mandatorily by the SCORM content to start the SCORM communication
  129. */
  130. function LMSInitialize() { //this is the initialize function of all APIobjects
  131. logit_scorm('LMSInitialise()',0);
  132. lms_initialized=1;
  133. return('true');
  134. }
  135. function Initialize() { //this is the initialize function of all APIobjects
  136. return LMSInitialize();
  137. }
  138. function LMSGetValue(param) {
  139. //logit_scorm("LMSGetValue('"+param+"')",1);
  140. var result='';
  141. if(param=='cmi.core._children' || param=='cmi.core_children'){
  142. result='entry, exit, lesson_status, student_id, student_name, lesson_location, total_time, credit, lesson_mode, score, session_time';
  143. }else if(param == 'cmi.core.entry'){
  144. result='';
  145. }else if(param == 'cmi.core.exit'){
  146. result='';
  147. }else if(param == 'cmi.core.lesson_status'){
  148. if(lesson_status != '') {
  149. result=lesson_status;
  150. }
  151. else{
  152. result='not attempted';
  153. }
  154. }else if(param == 'cmi.core.student_id'){
  155. result='<?php echo $_uid; ?>';
  156. }else if(param == 'cmi.core.student_name'){
  157. <?php
  158. $who=$_user['lastName'].", ".$_user['firstName'];
  159. echo "result='$who';";
  160. ?>
  161. }else if(param == 'cmi.core.lesson_location'){
  162. result=lesson_location;
  163. }else if(param == 'cmi.core.total_time'){
  164. result=total_time;
  165. }else if(param == 'cmi.core.score._children'){
  166. result='raw,min,max';
  167. }else if(param == 'cmi.core.score.raw'){
  168. result=score;
  169. }else if(param == 'cmi.core.score.max'){
  170. result=max;
  171. }else if(param == 'cmi.core.score.min'){
  172. result=min;
  173. }else if(param == 'cmi.core.score'){
  174. result=score;
  175. }else if(param == 'cmi.core.credit'){
  176. result='no-credit';
  177. }else if(param == 'cmi.core.lesson_mode'){
  178. result='normal';
  179. }else if(param == 'cmi.suspend_data'){
  180. result='<?php echo $oItem->get_suspend_data();?>';
  181. }else if(param == 'cmi.launch_data'){
  182. result='';
  183. }else if(param == 'cmi.objectives._count'){
  184. result='<?php echo $oItem->get_view_count();?>';
  185. }
  186. /*
  187. //Switch not working??? WTF???
  188. switch(param) {
  189. case 'cmi.core._children' :
  190. result='entry, exit, lesson_status, student_id, student_name, lesson_location, total_time, credit, lesson_mode, score, session_time';
  191. break;
  192. case 'cmi.core_children' :
  193. result='entry, exit, lesson_status, student_id, student_name, lesson_location, total_time, credit, lesson_mode, score, session_time';
  194. break;
  195. case 'cmi.core.entry' :
  196. result='';
  197. break;
  198. case 'cmi.core.exit' :
  199. result='';
  200. break;
  201. case 'cmi.core.lesson_status' :
  202. if(lesson_status != '') {
  203. result=lesson_status;
  204. }
  205. else{
  206. result='not attempted';
  207. }
  208. break;
  209. case 'cmi.core.student_id' :
  210. result='<?php echo $_uid; ?>';
  211. break;
  212. case 'cmi.core.student_name' :
  213. <?php
  214. $who=$_user['firstName'].",".$_user['lastName'];
  215. echo "result='$who';";
  216. ?> break;
  217. case 'cmi.core.lesson_location' :
  218. result='';
  219. break;
  220. case 'cmi.core.total_time' :
  221. result=total_time;
  222. break;
  223. case 'cmi.core.score._children' :
  224. result='raw,min,max';
  225. break;
  226. case 'cmi.core.score.raw' :
  227. result=score;
  228. break;
  229. case 'cmi.core.score.max' :
  230. result=max;
  231. break;
  232. case 'cmi.core.score.min' :
  233. result=min;
  234. break;
  235. case 'cmi.core.score' :
  236. result=score;
  237. break;
  238. case 'cmi.core.credit' :
  239. result='no-credit';
  240. break;
  241. case 'cmi.core.lesson_mode' :
  242. result='normal';
  243. break;
  244. case 'cmi.suspend_data' :
  245. result='<?php echo $oItem->get_suspend_data();?>';
  246. break;
  247. case 'cmi.launch_data' :
  248. result='';
  249. break;
  250. case 'cmi.objectives._count':
  251. result='<?php echo $oItem->get_view_count();?>';
  252. break;
  253. default :
  254. result='';
  255. break;
  256. }
  257. */
  258. logit_scorm("LMSGetValue('"+param+"') returned '"+result+"'",1);
  259. return result;
  260. }
  261. function GetValue(param) {
  262. return LMSGetValue(param);
  263. }
  264. function LMSSetValue(param, val) {
  265. logit_scorm("LMSSetValue('"+param+"','"+val+"')",0);
  266. switch(param) {
  267. case 'cmi.core.score.raw' : score= val ; break;
  268. case 'cmi.core.score.max' : max = val; break;
  269. case 'cmi.core.score.min' : min = val; break;
  270. case 'cmi.core.lesson_location' : lesson_location = val;break;
  271. case 'cmi.core.lesson_status' :
  272. saved_lesson_status = lesson_status;
  273. lesson_status = val;
  274. <?php if($oLP->mode != 'fullscreen'){ ?>
  275. //var update = update_toc(lesson_status,lms_item_id);
  276. <?php } ?>
  277. break;
  278. case 'cmi.completion_status' : lesson_status = val; break; //1.3
  279. case 'cmi.core.session_time' : session_time = val; break;
  280. case 'cmi.score.scaled' : score = val ; break; //1.3
  281. case 'cmi.success_status' : success_status = val; break; //1.3
  282. case 'cmi.suspend_data' : suspend_data = val; break;
  283. }
  284. //var update = update_toc();
  285. //var update_progress = update_progress_bar();
  286. <?php
  287. if ($oLP->force_commit == 1){
  288. echo " var mycommit = LMSCommit('force');";
  289. }
  290. ?>
  291. return(true);
  292. }
  293. function SetValue(param, val) {
  294. return LMSSetValue(param, val);
  295. }
  296. function savedata(origin) { //origin can be 'commit', 'finish' or 'terminate'
  297. <?php if ($autocomplete_when_80pct){ ?>
  298. if( ( lesson_status == 'incomplete') && (score >= (0.8*max) ) ){
  299. lesson_status = 'completed';
  300. }
  301. <?php }?>
  302. param = 'id='+lms_item_id+'&origin='+origin+'&score='+score+'&max='+max+'&min='+min+'&lesson_status='+lesson_status+'&time='+session_time+'&suspend_data='+suspend_data;
  303. url="http://<?php
  304. $self=$_SERVER['PHP_SELF'];
  305. $url=$_SERVER['HTTP_HOST'].$self;
  306. $url=substr($url,0,-14);//14 is the length of this file's name (/scorm_api.php)
  307. echo $url;
  308. ?>/lp_controller.php?cidReq=<?php echo api_get_course_id();?>&action=save&lp_id=<?php echo $oLP->get_id();?>&" + param + "";
  309. logit_lms('saving data (status='+lesson_status+')',1);
  310. 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);
  311. //xajax_update_pgs();
  312. //xajax_update_toc();
  313. }
  314. function LMSCommit(val) {
  315. logit_scorm('LMSCommit()',0);
  316. commit = true ;
  317. savedata('commit');
  318. return('true');
  319. }
  320. function Commit(val) {
  321. return LMSCommit(val);
  322. }
  323. function LMSFinish(val) {
  324. if (( commit == false )) {
  325. logit_scorm('LMSFinish() (no LMSCommit())',1);
  326. }
  327. if ( commit == true ) {
  328. logit_scorm('LMSFinish() called',1);
  329. savedata('finish');
  330. }
  331. return('true');
  332. }
  333. function Finish(val) {
  334. return LMSFinish(val);
  335. }
  336. function LMSGetLastError() {
  337. logit_scorm('LMSGetLastError()',1);
  338. return(G_LastError);
  339. }
  340. function GetLastError() {
  341. return LMSGetLastError();
  342. }
  343. function LMSGetErrorString(errCode){
  344. logit_scorm('LMSGetErrorString()',1);
  345. return('No error !');
  346. }
  347. function GetErrorString(errCode){
  348. return LMSGetErrorString(errCode);
  349. }
  350. function LMSGetDiagnostic(errCode){
  351. logit_scorm('LMSGetDiagnostic()',1);
  352. return(API.LMSGetLastError());
  353. }
  354. function GetDiagnostic(errCode){
  355. return LMSGetDiagnostic(errCode);
  356. }
  357. function Terminate(){
  358. logit_scorm('Terminate()',0);
  359. commit = true;
  360. savedata('terminate');
  361. return (true);
  362. }
  363. <?php
  364. //--------------------------------------------------------------------//
  365. /**
  366. * Dokeos-specific code that deals with event handling and inter-frames
  367. * messaging/refreshing.
  368. * Note that from now on, the Dokeos JS code in this library will act as
  369. * a controller, of the MVC pattern, and receive all requests for frame
  370. * updates, then redispatch to any frame concerned.
  371. */
  372. ?>
  373. /**
  374. * Defining the AJAX-object class to be made available from other frames
  375. */
  376. function XAJAXobject() {
  377. this.xajax_switch_item_details=xajax_switch_item_details;
  378. this.switch_item=switch_item;
  379. }
  380. //it is not sure that the scos use the above declarations
  381. oXAJAX = new XAJAXobject();
  382. oxajax = new XAJAXobject();
  383. /**
  384. * Cross-browser event handling by Scott Andrew
  385. * @param element Element that needs an event attached
  386. * @param string Event type (load, unload, click, keyDown, ...)
  387. * @param string Function name (the event handler)
  388. * @param string used in addEventListener
  389. */
  390. function addEvent(elm, evType, fn, useCapture){
  391. if(elm.addEventListener){
  392. elm.addEventListener(evType, fn, useCapture);
  393. return true;
  394. }else if (elm.attachEvent){
  395. var r = elm.attachEvent('on' + evType, fn);
  396. }else{
  397. elm['on'+evType] = fn;
  398. }
  399. }
  400. /**
  401. * Add listeners to the page objects. This has to be defined for
  402. * the current context as it acts on objects that should exist
  403. * on the page
  404. */
  405. function addListeners(){
  406. //exit if the browser doesn't support ID or tag retrieval
  407. logit_lms('Entering addListeners()',2);
  408. if(!document.getElementsByTagName){
  409. logit_lms("getElementsByTagName not available",2);
  410. return;
  411. }
  412. if(!document.getElementById){
  413. logit_lms("getElementById not available",2);
  414. return;
  415. }
  416. //assign event handlers to objects
  417. if(lms_lp_type==1 || lms_item_type=='asset'){
  418. logit_lms('Dokeos LP or asset',2);
  419. //if this path is a Dokeos learnpath, then start manual save
  420. //when something is loaded in there
  421. var myelem = document.getElementById('content_id');
  422. if(!myelem){logit_lms("Impossible to find content_id element in document",2);}
  423. addEvent(myelem,'unload',dokeos_save_asset,false);
  424. logit_lms('Added event listener on content_id for unload',2);
  425. }
  426. logit_lms('Quitting addListeners()',2);
  427. }
  428. /**
  429. * Load an item into the content frame:
  430. * - making sure the previous item status have been saved
  431. * - first updating the current item ID (to save the right item)
  432. * - updating the frame src
  433. */
  434. function load_item(item_id,url){
  435. if(document.getElementById('content_id'))
  436. {
  437. logit_lms('Loading item '+item_id,2);
  438. var cont_f = document.getElementById('content_id');
  439. if(cont_f.src){
  440. lms_old_item_id = lms_item_id;
  441. var lms_new_item_id = item_id;
  442. //load new content page into content frame
  443. if(lms_lp_type==1 || lms_item_type=='asset'){
  444. dokeos_save_asset();
  445. }
  446. cont_f.src = url;
  447. update_toc('unhighlight',lms_old_item_id);
  448. update_toc('highlight',item_id);
  449. /* legacy code
  450. lms_been_synchronized = 0;
  451. lms_initialized = 0;
  452. if(lms_lp_type==1 || lms_item_type=='asset'){
  453. lms_item_id = lms_new_item_id;
  454. }*/
  455. return true;
  456. }
  457. logit_lms('cont_f.src has no properties',0);
  458. }
  459. logit_lms('content_id has no properties',0);
  460. return false;
  461. }
  462. /**
  463. * Save a Dokeos learnpath item's time and mark as completed upon
  464. * leaving it
  465. */
  466. function dokeos_save_asset(){
  467. //var linkparams = 'id='+lms_item_id+'&score='+score+'&max='+max+'&min='+min+'&lesson_status='+lesson_status+'&time='+session_time+'&suspend_data='+suspend_data;
  468. //var url = "<?php echo api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php' ?>?action=save&" + linkparams + "";
  469. logit_lms('dokeos_save_asset: '+url,0);
  470. //frames["message_name"].src = url;
  471. 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);
  472. }
  473. /**
  474. * Logs information about SCORM messages into the log frame
  475. * @param string Message to log
  476. * @param integer Priority (0 for top priority, 3 for lowest)
  477. */
  478. function logit_scorm(message,priority){
  479. if(frames["lp_log_name"] && scorm_logs>priority){
  480. frames["lp_log_name"].document.getElementById("log_content").innerHTML += "SCORM: " + message + "<br/>";
  481. }
  482. }
  483. /**
  484. * Logs information about LMS activity into the log frame
  485. * @param string Message to log
  486. * @param integer Priority (0 for top priority, 3 for lowest)
  487. */
  488. function logit_lms(message,priority){
  489. if(frames["lp_log_name"] && lms_logs>priority){
  490. frames["lp_log_name"].document.getElementById("log_content").innerHTML += "LMS: " + message + "<br/>";
  491. }
  492. }
  493. /**
  494. * update the Table Of Contents frame, by changing CSS styles, mostly
  495. * @param string Action to be taken
  496. * @param integer Item id to update
  497. */
  498. function update_toc(update_action,update_id)
  499. {
  500. <?php if($oLP->mode != 'fullscreen'){ ?>
  501. var myframe = frames["toc_name"];
  502. var myelem = myframe.document.getElementById("toc_"+update_id);
  503. var myelemimg = myframe.document.getElementById("toc_img_"+update_id);
  504. logit_lms('update_toc('+update_action+','+update_id+')',2);
  505. if(update_id != 0){
  506. switch(update_action){
  507. case 'unhighlight':
  508. myelem.className = "scorm_item";
  509. break;
  510. case 'highlight':
  511. myelem.className = "scorm_item_highlight";
  512. break;
  513. case 'not attempted':
  514. if(myelemimg.src != 'notattempted.png'){
  515. myelemimg.src = "notattempted.png";
  516. myelemimg.alt = "not attempted";
  517. }
  518. break;
  519. case 'incomplete':
  520. if(myelemimg.src != 'incomplete.png'){
  521. myelemimg.src = "incomplete.png";
  522. myelemimg.alt = "incomplete";
  523. }
  524. break;
  525. case 'completed':
  526. if(myelemimg.src != 'completed.png'){
  527. myelemimg.src = "completed.png";
  528. myelemimg.alt = "completed";
  529. }
  530. break;
  531. case 'failed':
  532. if(myelemimg.src != 'failed.png'){
  533. myelemimg.src = "failed.png";
  534. myelemimg.alt = "failed";
  535. }
  536. break;
  537. case 'passed':
  538. if(myelemimg.src != 'completed.png' && myelemimg.alt != 'passed'){
  539. myelemimg.src = "completed.png";
  540. myelemimg.alt = "passed";
  541. }
  542. break;
  543. case 'browsed':
  544. if(myelemimg.src != 'completed.png' && myelemimg.alt != 'browsed'){
  545. myelemimg.src = "completed.png";
  546. myelemimg.alt = "browsed";
  547. }
  548. break;
  549. default:
  550. logit_lms('Update action unknown',2);
  551. break;
  552. }
  553. }
  554. return true;
  555. <?php } ?>
  556. return true;
  557. }
  558. /**
  559. * Updates the progress bar with the new status. Prevents the need of a page refresh and flickering
  560. * @param integer Number of completed items
  561. * @param integer Number of items in total
  562. * @param string Display mode (absolute 'abs' or percentage '%').Defaults to %
  563. */
  564. function update_progress_bar(nbr_complete, nbr_total, mode)
  565. {
  566. logit_lms('update_progress_bar('+nbr_complete+','+nbr_total+','+mode+')',2);
  567. logit_lms('could update with data: '+lms_lp_id+','+lms_view_id+','+lms_user_id,2);
  568. var myframe = frames["nav_name"];
  569. if(myframe){
  570. if(mode == ''){mode='%';}
  571. if(nbr_total == 0){nbr_total=1;}
  572. var percentage = (nbr_complete/nbr_total)*100;
  573. percentage = Math.round(percentage);
  574. var pr_text = myframe.document.getElementById('progress_text');
  575. var pr_full = myframe.document.getElementById('progress_img_full');
  576. var pr_empty = myframe.document.getElementById('progress_img_empty');
  577. pr_full.width = percentage;
  578. pr_empty.width = 100-percentage;
  579. var mytext = '';
  580. switch(mode){
  581. case 'abs':
  582. mytext = nbr_complete + '/' + nbr_total;
  583. break;
  584. case '%':
  585. default:
  586. mytext = percentage + '%';
  587. break;
  588. }
  589. pr_text.innerHTML = mytext;
  590. }
  591. return true;
  592. }
  593. function update_stats_page()
  594. {
  595. var myframe = document.getElementById('content_id');
  596. var mysrc = myframe.location.href;
  597. if(mysrc == 'lp_controller.php?action=stats'){
  598. if(myframe && myframe.src){
  599. var mysrc = myframe.src;
  600. myframe.src = mysrc;
  601. }
  602. // = mysrc; //refresh page
  603. }
  604. return true;
  605. }
  606. /**
  607. * Updates the message frame with the given string
  608. */
  609. function update_message_frame(msg_msg)
  610. {
  611. if(msg_msg==null){msg_msg='';}
  612. var msg_f = frames["message_name"];
  613. if(!msg_f.document || !msg_f.document.getElementById('msg_div_id')){
  614. logit_lms('In update_message_frame() - message frame has no document property',0);
  615. }else{
  616. logit_lms('In update_message_frame() - updating frame',0);
  617. msg_f.document.getElementById('msg_div_id').innerHTML= msg_msg;
  618. }
  619. }
  620. /**
  621. * Function that handles the saving of an item and switching from an item to another.
  622. * Once called, this function should be able to do the whole process of (1) saving the
  623. * current item, (2) refresh all the values inside the SCORM API object, (3) open the
  624. * new item into the content_id frame, (4) refresh the table of contents, (5) refresh
  625. * the progress bar (completion), (6) refresh the message frame
  626. * @param integer Dokeos ID for the current item
  627. * @param string This parameter can be a string specifying the next
  628. * item (like 'next', 'previous', 'first' or 'last') or the id to the next item
  629. */
  630. function switch_item(current_item, next_item){
  631. /*
  632. if(!current_item){
  633. logit_lms('In switch - no current_item defined',0);
  634. }
  635. if(!next_item){
  636. logit_lms('In switch - no next_item defined',0);
  637. }
  638. */
  639. if(lms_item_id == next_item){
  640. return; //nothing to switch
  641. }
  642. //(1) save the current item
  643. logit_lms('Called switch_item with params '+lms_item_id+' and '+next_item+'',0);
  644. 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);
  645. //(2) Refresh all the values inside this SCORM API object - use AJAX
  646. //xajax_backup_item_details(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, score, max, min, lesson_status, session_time, suspend_data);
  647. xajax_switch_item_details(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,next_item);
  648. //(3) open the new item in the content_id frame
  649. var cont_f = document.getElementById('content_id');
  650. if(!cont_f){logit_lms('In switch - content frame not found',0);return false;}
  651. switch(next_item){
  652. case 'next':
  653. next_item = lms_next_item;
  654. break;
  655. case 'previous':
  656. next_item = lms_previous_item;
  657. break;
  658. default:
  659. break;
  660. }
  661. cont_f.src = 'lp_controller.php?action=content&lp_id='+lms_lp_id+'&item_id='+next_item;
  662. //(4) refresh table of contents
  663. /*
  664. var toc_f = document.getElementById('toc_id');
  665. if(!toc_f){logit_lms('In switch - toc frame not found',0);return false;}
  666. var myrefresh = toc_f.src;
  667. toc_f.src = myrefresh;
  668. */
  669. //(5) refresh the progress bar
  670. /*
  671. var prg_f = document.getElementById('nav_id');
  672. if(!prg_f){logit_lms('In switch - navigation frame not found',0);return false;}
  673. var myrefresh = prg_f.src;
  674. prg_f.src = myrefresh;
  675. */
  676. //(6) refresh the message box (included in switch_item_details)
  677. return true;
  678. }
  679. addEvent(window,'load',addListeners,false);