ILIAS  Release_3_10_x_branch Revision 61812
 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  $stmt = "SELECT * FROM scorm_tracking WHERE user_id = ".$ilDB->quote($user_id).
96  " AND sco_id = ".$ilDB->quote($obj_id)." AND lvalue = ".$ilDB->quote($key).
97  " AND obj_id = ".$ilDB->quote($hacp_id);
98  $set = $ilDB->query($stmt);
99  if ($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
100  $this->update[] = array("left" => $key, "right" => $value);
101  else
102  $this->insert[] = array("left" => $key, "right" => $value);
103  }
104  }
105 
106  //store
107  $this->store($hacp_id, $obj_id, 0);
108 
109  $response=new ilHACPResponse($ref_id, $obj_id);
110  $response->sendOk();
111  }
112 
113  function exitau($ref_id, $obj_id, $version, $aicc_data) {
114  $response=new ilHACPResponse($ref_id, $obj_id);
115  $response->sendOk();
116  }
117 
118  function startau($ref_id, $obj_id, $version, $aicc_data) {
119  $response=new ilHACPResponse($ref_id, $obj_id);
120  $response->sendParam();
121  }
122 
123  function parseAICCData($string) {
124  $data=array();
125  if (!empty($string)) {
126  $lines=explode("\n", $string);
127  for($i=0;$i<count($lines);$i++) {
128  $line=trim($lines[$i]);
129  if (empty($line) || substr($line,0,1)==";" || substr($line,0,1)=="#"){
130  continue;
131  }
132  if (substr($line,0,1)=="[") {
133  $block=substr($line,1,-1);
134  continue;
135  }
136  if (empty($block))
137  continue;
138 
139  if (substr_count($line, "=")==0)
140  $data[strtolower("cmi.".$block)]=$line;
141  else if (substr_count($line, "=")==1) {
142  $line=explode("=", $line);
143  $data[strtolower("cmi.".$block.".".$line[0])]=$line[1];
144  }
145  }
146  }
147  return $data;
148  }
149 
150 }
151 
152 ?>