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

Source for file aicc_hacp.php

Documentation is available at aicc_hacp.php

  1. <?php // $Id: $ 
  2. /**
  3. ============================================================================== 
  4. *    API event handler functions for AICC / CMIv4 in HACP 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 HACP messaging for AICC. The API messaging is
  22.  * made by another set of scripts.
  23.  * 
  24.  * Rules for HACP processing of one AU
  25.  * Rule #1 The first HACP message issued must be a GetParam
  26.  * Rule #2 The last HACP message issued must be an ExitAU
  27.  * Rule #3 At least one PutParam message must be issued prior to an ExitAU message
  28.  * Rule #4 No HACP messages can be issued after a successfully issued ExitAU message
  29.  * 
  30.  * Only suspend_data and core.lesson_location should be sent updated to a late GetParam
  31.  * request. All other params should be as when the AU was launched.
  32.  */
  33. /*
  34. ============================================================================== 
  35.        INIT SECTION
  36. ============================================================================== 
  37. */ 
  38. $debug 0;
  39.  
  40. //flag to allow for anonymous user - needs to be set before global.inc.php
  41. $use_anonymous true;
  42.  
  43. //Use session ID as provided by the request
  44. if(!empty($_REQUEST['aicc_sid']))
  45. {
  46.     session_id($_REQUEST['aicc_sid']);
  47.     if($debug>1){error_log('New LP - '.__FILE__.','.__LINE__.' - reusing session ID '.$_REQUEST['aicc_sid'],0);}
  48. }
  49. //Load common libraries using a compatibility script to bridge between 1.6 and 1.8
  50. require_once('back_compat.inc.php');  
  51. if($debug>2){error_log('New LP - '.__FILE__.','.__LINE__.' - Current session ID: '.session_id(),0);}
  52. //Load learning path libraries so we can use the objects to define the initial values
  53. //of the API
  54. require_once('learnpath.class.php');
  55. require_once('learnpathItem.class.php');
  56. require_once('aicc.class.php');
  57.  
  58. // Is this needed? This is probabaly done in the header file
  59. //$_user                            = $_SESSION['_user'];
  60. $file                            $_SESSION['file'];
  61. $oLP                            unserialize($_SESSION['lpobject']);
  62. $oItem                             =$oLP->items[$oLP->current];
  63. if(!is_object($oItem)){
  64.     error_log('New LP - aicc_hacp - Could not load oItem item',0);
  65.     exit;
  66. }
  67. $autocomplete_when_80pct 0;
  68.  
  69. $result array(
  70.     'core'=>array(),
  71.     'core_lesson'=>array(),
  72.     'core_vendor'=>array(),
  73.     'evaluation'=>array(),
  74.     'student_data'=>array(),
  75. );
  76. $convert_enc array('%25','%0D','%0A','%09','%20','%2D','%2F','%3B','%3F','%7B','%7D','%7C','%5C','%5E','%7E','%5B','%5D','%60','%23','%3E','%3C','%22');
  77. $convert_dec array('%',"\r","\n","\t",' ','-','/',';','?','{','}','|','\\','^','~','[',']','`','#','>','<','"');
  78. $crlf "\r\n";
  79. $tab "\t";
  80. $s_ec 'error='//string for error code
  81. $s_et 'error_text='//string for error text
  82. $s_ad 'aicc_data='//string for aicc_data
  83.  
  84. $errors array(0=>'Successful',1=>'Invalid Command',2=>'Invalid AU password',3=>'Invalid Session ID');
  85.  
  86. $error_code 0;
  87. $error_text '';
  88. $aicc_data '';
  89. $result '';
  90. //GET REQUEST
  91. if(!empty($_REQUEST['command']))
  92. {
  93.     //error_log('In '.__FILE__.', '.__LINE__.' - request is '.$_REQUEST['command'],0);
  94.     switch(strtolower($_REQUEST['command']))
  95.     {
  96.         case 'getparam':
  97.             //request for all available data to be printed out in the answer
  98.             if(!empty($_REQUEST['version'])){
  99.                 $hacp_version learnpath::escape_string($_REQUEST['version']);
  100.             }
  101.             if(!empty($_REQUEST['session_id'])){
  102.                 $hacp_session_id learnpath::escape_string($_REQUEST['session_id']);
  103.             }
  104.             $error_code 0;
  105.             $error_text $errors[$error_code];
  106.             $result $s_ec.$error_code.$crlf.$s_et.$error_text.$crlf.$s_ad.$crlf;
  107.             $result .= '[Core]'.$crlf;
  108.             $result .= $tab.'Student_ID='.$_user['user_id'].$crlf;
  109.             $result .= $tab.'Student_Name='.$_user['lastName'].', '.$_user['firstName'].$_user['user_id'].$crlf;
  110.             $result .= $tab.'Lesson_Location='.$oItem->get_lesson_location().$crlf;
  111.             $result .= $tab.'Credit='.$oItem->get_credit().$crlf;
  112.             $result .= $tab.'Lesson_Status='.$oItem->get_status().$crlf;
  113.             $result .= $tab.'Score='.$oItem->get_score().$crlf;
  114.             $result .= $tab.'Time='.$oItem->get_scorm_time('js').$crlf;
  115.             $result .= $tab.'Lesson_Mode='.$oItem->get_lesson_mode().$crlf;
  116.             $result .= '[Core_Lesson]'.$crlf;
  117.             $result .= $oItem->get_suspend_data().$crlf;
  118.             $result .= '[Core_Vendor]'.$crlf;
  119.             $result .= $oItem->get_launch_data.$crlf;
  120.             $result .= '[Comments]'.$crlf;
  121.             $result .= $crlf;
  122.             $result .= '[Evaluation]'.$crlf;
  123.             $result .= $tab.'Course_ID={'.api_get_course_id().'}'.$crlf;
  124.             //$result .= '[Objectives_Status]'.$crlf;
  125.             $result .= '[Student_Data]'.$crlf;
  126.             $result .= $tab.'Mastery_Score='.$oItem->masteryscore.$crlf;
  127.             //$result .= '[Student_Demographics]'.$crlf;
  128.             //$result .= '[Student_Preferences]'.$crlf;
  129.                         
  130.             //error_log('Returning message: '.$result,0);
  131.             $result str_replace($convert_dec,$convert_enc,$result);
  132.             //error_log('Returning message (encoded): '.$result,0);
  133.             break;
  134.         case 'putparam':
  135.             $hacp_version '';
  136.             $hacp_session_id '';
  137.             $hacp_aicc_data '';
  138.             foreach($_REQUEST as $name => $value)
  139.             {
  140.                 //escape the value as described in the AICC documentation p170
  141.                 switch(strtolower($name))
  142.                 {
  143.                     case 'version':
  144.                         $hacp_version $value;
  145.                         break;
  146.                     case 'session_id':
  147.                         $hacp_session_id $value;
  148.                         break;
  149.                     case 'aicc_data':
  150.                         //error_log('In '.__FILE__.', '.__LINE__.' - aicc data before translation is '.$value,0);
  151.                         $value str_replace('+',' ',$value);
  152.                         $value str_replace($convert_enc,$convert_dec,$value);
  153.                         $hacp_aicc_data $value;                        
  154.                         break;
  155.                 }
  156.             }
  157.             //error_log('In '.__FILE__.', '.__LINE__.' - aicc data is '.$hacp_aicc_data,0);
  158.             //treat the incoming request:
  159.             $msg_array aicc::parse_ini_string_quotes_safe($hacp_aicc_data,array('core_lesson','core_vendor'));
  160.             //error_log('Message is now in this form: '.print_r($msg_array,true),0);
  161.             foreach($msg_array as $key=>$dummy){
  162.                 switch (strtolower($key)){
  163.                     case 'core':
  164.                         foreach($msg_array[$keyas $subkey => $value){
  165.                             switch(strtolower($subkey)){
  166.                                 case 'lesson_location':
  167.                                     //error_log('Setting lesson_location to '.$value,0);
  168.                                     $oItem->set_lesson_location($value);
  169.                                     break;
  170.                                 case 'lesson_status':
  171.                                     //error_log('Setting lesson_status to '.$value,0);
  172.                                     $oItem->set_status($value);
  173.                                     break;
  174.                                 case 'score':
  175.                                     //error_log('Setting lesson_score to '.$value,0);
  176.                                     $oItem->set_score($value);
  177.                                     break;
  178.                                 case 'time':
  179.                                     //error_log('Setting lesson_time to '.$value,0);
  180.                                     $oItem->set_time($value);
  181.                                     break;
  182.                             }
  183.                         }
  184.                         break;
  185.                     case 'core_lesson':
  186.                         //error_log('Setting suspend_data to '.print_r($msg_array[$key],true),0);
  187.                         $oItem->current_data $msg_array[$key];
  188.                         break;
  189.                     case 'comments':
  190.                         break;
  191.                     case 'objectives_status':
  192.                         break;
  193.                     case 'student_data':
  194.                         break;
  195.                     case 'student_preferences':
  196.                         break;
  197.                 }
  198.             }
  199.             
  200.             $error_code 0;
  201.             $error_text $errors[$error_code];
  202.             $result $s_ec.$error_code.$crlf.$s_et.$error_text.$crlf.$s_ad.$crlf;
  203.             $oItem->save(false);
  204.             break;
  205.         case 'putcomments':
  206.             $error_code 0;
  207.             $error_text $errors[$error_code];
  208.             $result $s_ec.$error_code.$crlf.$s_et.$error_text.$crlf.$s_ad.$crlf;
  209.             break;
  210.         case 'putobjectives':
  211.             $error_code 0;
  212.             $error_text $errors[$error_code];
  213.             $result $s_ec.$error_code.$crlf.$s_et.$error_text.$crlf.$s_ad.$crlf;
  214.             break;
  215.         case 'putpath':
  216.             $error_code 0;
  217.             $error_text $errors[$error_code];
  218.             $result $s_ec.$error_code.$crlf.$s_et.$error_text.$crlf.$s_ad.$crlf;
  219.             break;
  220.         case 'putinteractions':
  221.             $error_code 0;
  222.             $error_text $errors[$error_code];
  223.             $result $s_ec.$error_code.$crlf.$s_et.$error_text.$crlf.$s_ad.$crlf;
  224.             break;
  225.         case 'putperformance':
  226.             $error_code 0;
  227.             $error_text $errors[$error_code];
  228.             $result $s_ec.$error_code.$crlf.$s_et.$error_text.$crlf.$s_ad.$crlf;
  229.             break;
  230.         case 'exitau':
  231.             $error_code 0;
  232.             $error_text $errors[$error_code];
  233.             $result $s_ec.$error_code.$crlf.$s_et.$error_text.$crlf.$s_ad.$crlf;
  234.             break;
  235.         default:
  236.             $error_code 1;
  237.             $error_text $errors[1];
  238.             $result $s_ec.$error_code.$crlf.$s_et.$error_text.$crlf;
  239.     }
  240. }
  241. $_SESSION['lpobject'serialize($oLP);
  242. //content type must be text/plain
  243. header('Content-type: text/plain');
  244. echo $result;
  245. ?>

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