ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjHACPTracking.php
Go to the documentation of this file.
1 <?
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 require_once("./Modules/ScormAicc/classes/AICC/class.ilObjAICCTracking.php");
25 require_once("./Modules/ScormAicc/classes/HACP/class.ilHACPResponse.php");
26 
27 
32 
37  function ilObjHACPTracking($ref_id, $obj_id)
38  {
39  global $ilias, $HTTP_POST_VARS;
40  global $ilDB, $ilUser;
41 
42 
43  //just to make sure to extract only this parameter
44  $mainKeys=array("command", "version", "session_id", "aicc_data");
45  $postVars=array_change_key_case($HTTP_POST_VARS, CASE_LOWER);
46  foreach($mainKeys as $key) {
47  $$key=$postVars[$key];
48  }
49 
50  //only allowed commands
51  $command=strtolower($command);
52  $allowedCommands=array("getparam", "putparam", "exitau");
53  if (!in_array($command, $allowedCommands)) {
54  exit;
55  }
56 /*
57  $fp=fopen("././Modules/ScormAicc/log/hacp.log", "a+");
58  fputs($fp, "$command ref_id=$ref_id, obj_id=$obj_id\n");
59  fclose($fp);
60 */
61  $this->$command($ref_id, $obj_id, $version, $aicc_data);
62 
63  }
64 
65  function getparam($ref_id, $obj_id, $version, $aicc_data) {
66  //if (empty($aicc_data)) {
67  // $this->startau($ref_id, $obj_id, $version, $aicc_data);
68  // return;
69  //}
70 
71  $response=new ilHACPResponse($ref_id, $obj_id);
72  $response->sendParam();
73 
74 /*
75  $fp=fopen("././Modules/ScormAicc/log/hacp.log", "a+");
76  fputs($fp, "getparam ref_id=$ref_id, obj_id=$obj_id, aicc_data=$aicc_data\n");
77  fclose($fp);
78 */
79  }
80 
81  function putparam($ref_id, $obj_id, $version, $aicc_data) {
82  //aiccdata is a non standard ini format
83  //$data=parse_ini_file($tmpFilename, TRUE);
84  $data=$this->parseAICCData($aicc_data);
85 
86  $hacp_id = ilObject::_lookupObjId($ref_id);
87 
88  //choose either insert or update to be able to inherit superclass
89  global $ilDB, $ilUser, $ilLog;
90  $this->update=array();
91  $this->insert=array();
92  if (is_object($ilUser)) {
93  $user_id = $ilUser->getId();
94  foreach ($data as $key=>$value)
95  {
96 
97  $set = $ilDB->queryF('
98  SELECT * FROM scorm_tracking WHERE user_id = %s
99  AND sco_id = %s
100  AND lvalue = %s
101  AND obj_id = %s',
102  array('integer','integer','text','integer'),
103  array($user_id,$obj_id,$key,$hacp_id));
104 
105  if ($rec = $ilDB->fetchAssoc($set))
106  $this->update[] = array("left" => $key, "right" => $value);
107  else
108  $this->insert[] = array("left" => $key, "right" => $value);
109  }
110  }
111 
112  //store
113  $this->store($hacp_id, $obj_id, 0);
114 
115  $response=new ilHACPResponse($ref_id, $obj_id);
116  $response->sendOk();
117  }
118 
119  function exitau($ref_id, $obj_id, $version, $aicc_data) {
120  $response=new ilHACPResponse($ref_id, $obj_id);
121  $response->sendOk();
122  }
123 
124  function startau($ref_id, $obj_id, $version, $aicc_data) {
125  $response=new ilHACPResponse($ref_id, $obj_id);
126  $response->sendParam();
127  }
128 
129  function parseAICCData($string) {
130  $data=array();
131  if (!empty($string)) {
132  $lines=explode("\n", $string);
133  for($i=0;$i<count($lines);$i++) {
134  $line=trim($lines[$i]);
135  if (empty($line) || substr($line,0,1)==";" || substr($line,0,1)=="#"){
136  continue;
137  }
138  if (substr($line,0,1)=="[") {
139  $block=substr($line,1,-1);
140  continue;
141  }
142  if (empty($block))
143  continue;
144 
145  if (substr_count($line, "=")==0)
146  $data[strtolower("cmi.".$block)]=$line;
147  else if (substr_count($line, "=")==1) {
148  $line=explode("=", $line);
149  $data[strtolower("cmi.".$block.".".$line[0])]=$line[1];
150  }
151  }
152  }
153  return $data;
154  }
155 
156 }
157 
158 ?>