00001 <?
00002
00003 require_once("content/classes/AICC/class.ilObjAICCTracking.php");
00004 require_once("content/classes/HACP/class.ilHACPResponse.php");
00005
00006
00007 class ilObjHACPTracking extends ilObjAICCTracking {
00008
00013 function ilObjHACPTracking($ref_id, $obj_id)
00014 {
00015 global $ilias, $HTTP_POST_VARS;
00016 global $ilDB, $ilUser;
00017
00018
00019
00020 $mainKeys=array("command", "version", "session_id", "aicc_data");
00021 $postVars=array_change_key_case($HTTP_POST_VARS, CASE_LOWER);
00022 foreach($mainKeys as $key) {
00023 $$key=$postVars[$key];
00024 }
00025
00026
00027 $command=strtolower($command);
00028 $allowedCommands=array("getparam", "putparam", "exitau");
00029 if (!in_array($command, $allowedCommands)) {
00030 exit;
00031 }
00032
00033
00034
00035
00036
00037 $this->$command($ref_id, $obj_id, $version, $aicc_data);
00038
00039 }
00040
00041 function getparam($ref_id, $obj_id, $version, $aicc_data) {
00042
00043
00044
00045
00046
00047 $response=new ilHACPResponse($ref_id, $obj_id);
00048 $response->sendParam();
00049
00050
00051
00052
00053
00054
00055 }
00056
00057 function putparam($ref_id, $obj_id, $version, $aicc_data) {
00058
00059
00060 $data=$this->parseAICCData($aicc_data);
00061
00062
00063 global $ilDB, $ilUser;
00064 $this->update=array();
00065 $this->insert=array();
00066 if (is_object($ilUser)) {
00067 $user_id = $ilUser->getId();
00068 foreach ($data as $key=>$value) {
00069 $stmt = "SELECT * FROM scorm_tracking WHERE user_id = ".$ilDB->quote($user_id).
00070 " AND sco_id = ".$ilDB->quote($obj_id)." AND lvalue = ".$ilDB->quote($key);
00071 $set = $ilDB->query($stmt);
00072 if ($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
00073 $this->update[] = array("left" => $key, "right" => $value);
00074 else
00075 $this->insert[] = array("left" => $key, "right" => $value);
00076 }
00077 }
00078
00079
00080 $this->store($ref_id, $obj_id, 0);
00081
00082 $response=new ilHACPResponse($ref_id, $obj_id);
00083 $response->sendOk();
00084 }
00085
00086 function exitau($ref_id, $obj_id, $version, $aicc_data) {
00087 $response=new ilHACPResponse($ref_id, $obj_id);
00088 $response->sendOk();
00089 }
00090
00091 function startau($ref_id, $obj_id, $version, $aicc_data) {
00092 $response=new ilHACPResponse($ref_id, $obj_id);
00093 $response->sendParam();
00094 }
00095
00096 function parseAICCData($string) {
00097 $data=array();
00098 if (!empty($string)) {
00099 $lines=explode("\n", $string);
00100 for($i=0;$i<count($lines);$i++) {
00101 $line=trim($lines[$i]);
00102 if (empty($line) || substr($line,0,1)==";" || substr($line,0,1)=="#"){
00103 continue;
00104 }
00105 if (substr($line,0,1)=="[") {
00106 $block=substr($line,1,-1);
00107 continue;
00108 }
00109 if (empty($block))
00110 continue;
00111
00112 if (substr_count($line, "=")==0)
00113 $data[strtolower("cmi.".$block)]=$line;
00114 else if (substr_count($line, "=")==1) {
00115 $line=explode("=", $line);
00116 $data[strtolower("cmi.".$block.".".$line[0])]=$line[1];
00117 }
00118 }
00119 }
00120 return $data;
00121 }
00122
00123 }
00124
00125 ?>