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 $hacp_id = ilObject::_lookupObjId($ref_id);
00081 $this->store($hacp_id, $obj_id, 0);
00082
00083 $response=new ilHACPResponse($ref_id, $obj_id);
00084 $response->sendOk();
00085 }
00086
00087 function exitau($ref_id, $obj_id, $version, $aicc_data) {
00088 $response=new ilHACPResponse($ref_id, $obj_id);
00089 $response->sendOk();
00090 }
00091
00092 function startau($ref_id, $obj_id, $version, $aicc_data) {
00093 $response=new ilHACPResponse($ref_id, $obj_id);
00094 $response->sendParam();
00095 }
00096
00097 function parseAICCData($string) {
00098 $data=array();
00099 if (!empty($string)) {
00100 $lines=explode("\n", $string);
00101 for($i=0;$i<count($lines);$i++) {
00102 $line=trim($lines[$i]);
00103 if (empty($line) || substr($line,0,1)==";" || substr($line,0,1)=="#"){
00104 continue;
00105 }
00106 if (substr($line,0,1)=="[") {
00107 $block=substr($line,1,-1);
00108 continue;
00109 }
00110 if (empty($block))
00111 continue;
00112
00113 if (substr_count($line, "=")==0)
00114 $data[strtolower("cmi.".$block)]=$line;
00115 else if (substr_count($line, "=")==1) {
00116 $line=explode("=", $line);
00117 $data[strtolower("cmi.".$block.".".$line[0])]=$line[1];
00118 }
00119 }
00120 }
00121 return $data;
00122 }
00123
00124 }
00125
00126 ?>