dokeos-learnpath
[ class tree: dokeos-learnpath ] [ index: dokeos-learnpath ] [ all elements ]

Source for file aicc_api.php

Documentation is available at aicc_api.php

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

Documentation generated on Thu, 12 Jun 2008 12:57:25 -0500 by phpDocumentor 1.4.1