ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTracking.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
12 class ilTracking {
13 
14  var $objId;
15  var $userId;
18  var $clientIp;
20  var $accObjId;
22  var $accSubId;
23  var $lanugage;
24  var $browser;
26  var $acc_time;
27 
28  var $db;
29 
30  function ilTracking()
31  {
32  global $ilias,$tpl,$lng,$ilDB;
33 die ("class ilTracking is deprecated");
34  $this->ilias =& $ilias;
35  $this->tpl =& $tpl;
36  $this->lng =& $lng;
37  $this->db = $ilDB;
38 
39  }
40 
44  function _getLastAccess()
45  {
46  global $ilUser, $ilDB;
47 
48  $ilDB->setLimit(1);
49  $q = "SELECT * from ut_access "
50  ." WHERE "
51  ." user_id = ".$ilDB->quote($ilUser->getId(),'integer')
52  ." ORDER BY acc_time DESC";
53  $res = $ilDB->query($q);
54  return $res->fetchRow(DB_FETCHMODE_ASSOC);
55  }
56 
57  function _hasEntry($a_obj_id, $a_obj_type,$a_sub_id = 0, $a_sub_type = "")
58  {
59  global $ilDB;
60 
61  // We query for the session_id since it is more unique than the user_id.
62 
63  $query = "SELECT COUNT(id) as num_entries FROM ut_access ".
64  "WHERE session_id = ".$ilDB->quote(session_id(), "text")." ".
65  "AND acc_obj_id = ".$ilDB->quote($a_obj_id, "integer")." ".
66  "AND acc_sub_id = ".$ilDB->quote($a_sub_id, "text")." ";
67  $res = $ilDB->query($query);
68  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
69 
70  return $row->num_entries ? true : false;
71  }
72 
82  function _trackAccess($a_obj_id, $a_ref_id, $a_obj_type, $a_sub_id = 0, $a_sub_type = "", $a_action_type = "read")
83  {
84  global $ilUser, $ilDB;
85 
86  include_once("Services/Tracking/classes/class.ilObjUserTracking.php");
88  {
89  return false;
90  }
91 
92  include_once 'Services/Tracking/classes/class.ilLearningProgress.php';
93  ilLearningProgress::_tracProgress($ilUser->getId(),$a_obj_id, $a_ref_id, $a_obj_type);
94 
96  {
97  $user_id = $ilUser->getId();
98  }
99  else
100  {
101  $user_id = 0;
102  }
103 
104  $client_ip = getenv("REMOTE_ADDR");
105  $script = substr($_SERVER["SCRIPT_FILENAME"], strlen(IL_ABSOLUTE_PATH) - 1,
106  strlen($_SERVER["SCRIPT_FILENAME"]) - strlen(IL_ABSOLUTE_PATH) + 1);
107  $language = $ilUser->getLanguage();
108  $session_id = session_id();
109 
110  #$last_access = ilTracking::_getLastAccess();
111 
112 
113  if(ilTracking::_hasEntry($a_obj_id, $a_obj_type,$a_sub_id, $a_sub_type))
114  {
115  return true;
116  }
117  $q = "INSERT INTO ut_access ("
118  ."id,"
119  ."user_id, action_type, php_script, client_ip,"
120  ."acc_obj_type, acc_obj_id, acc_sub_type, acc_sub_id,"
121  ."language, browser, session_id, acc_time, ut_month"
122  .") VALUES ("
123  .$ilDB->quote($ilDB->nextId('ut_access'),'integer').','
124  .$ilDB->quote($user_id, "integer").","
125  .$ilDB->quote($a_action_type, "text").","
126  .$ilDB->quote($script, "text").","
127  .$ilDB->quote($client_ip, "text").","
128  .$ilDB->quote($a_obj_type, "text").","
129  .$ilDB->quote($a_obj_id, "integer").","
130  .$ilDB->quote($a_sub_type, "text").","
131  .$ilDB->quote($a_sub_id, "integer").","
132  .$ilDB->quote($language, "text").","
133  .$ilDB->quote(substr($_SERVER["HTTP_USER_AGENT"],0.255)).","
134  .$ilDB->quote($session_id, "text").", "
135  .$ilDB->quote(ilUtil::now(), "timestamp").", "
136  .$ilDB->quote(substr(ilUtil::now(), 0, 7), "text")
137  .")";
138  $ilDB->manipulate($q);
139 
140  /*
141  if(($session_id == $last_access["session_id"]) &&
142  ($a_obj_id == $last_access["acc_obj_id"]) &&
143  ($a_obj_type == $last_access["acc_obj_type"]) &&
144  ($a_sub_id == $last_access["acc_sub_id"]) &&
145  ($a_sub_type == $last_access["acc_sub_type"])
146  )
147  {
148  return true;
149  }
150  else
151  {
152  $q = "INSERT INTO ut_access ("
153  ."user_id, action_type, php_script, client_ip,"
154  ."acc_obj_type, acc_obj_id, acc_sub_type, acc_sub_id,"
155  ."language, browser, session_id, acc_time"
156  .") VALUES ("
157  .$ilDB->quote($user_id).","
158  .$ilDB->quote($a_action_type).","
159  .$ilDB->quote($script).","
160  .$ilDB->quote($client_ip).","
161  .$ilDB->quote($a_obj_type).","
162  .$ilDB->quote($a_obj_id).","
163  .$ilDB->quote($a_sub_type).","
164  .$ilDB->quote($a_sub_id).","
165  .$ilDB->quote($language).","
166  .$ilDB->quote($_SERVER["HTTP_USER_AGENT"]).","
167  .$ilDB->quote($session_id).", now()"
168  .")";
169  $ilDB->query($q);
170  }
171  */
172  }
173  function TestTitle($user_id)
174  {
175  global $ilDB;
176 
177  $q = " SELECT title from object_data "
178  ." WHERE type = ".$ilDB->quote("tst", "text")
179  ." AND owner = ".$ilDB->quote($user_id ,'integer');
180  $res = $this->ilias->db->query($q);
181  for($i=0;$i<$res->numRows();$i++)
182  {
183  $result[$i]=$res->fetchRow();
184  }
185  return $result;
186  }
187 
188 
189 
190  function numDay($from,$to)
191  {
192  $from = strtotime($from);
193  $to = strtotime($to);
194  $dayf = date ("d",$from);
195  $dayt = date ("d",$to);
196  $yearf = date ("Y",$from);
197  $yeart = date ("Y",$to);
198  $montht = date ("m",$to);
199  $monthf = date ("m",$from);
200  $ret = ( mktime(0,0,0,$montht,$dayt,$yeart) - mktime(0,0,0,$monthf,$dayf,$yearf))/(3600*24);
201  return $ret;
202  }
203  function numHour($from,$to)
204  {
205  $from = strtotime($from);
206  $to = strtotime($to);
207  $dayf = date ("d",$from);
208  $dayt = date ("d",$to);
209  $yearf = date ("Y",$from);
210  $yeart = date ("Y",$to);
211  $montht = date ("m",$to);
212  $monthf = date ("m",$from);
213  $hourt = date ("h",$to);
214  $hourf = date ("h",$from);
215  $ret = (mktime($hourt,0,0,$montht,$dayt,$yeart)-mktime($hourf,0,0,$monthf,$dayf,$yearf))/3600;
216  $ret = strftime($ret);
217  return $ret;
218  }
219  function addHour($time)
220  {
221  $time = strtotime($time);
222  $day = date("d",$time);
223  $month = date("m",$time);
224  $year = date("Y",$time);
225  $hour = date("H",$time);
226  $min = date("i",$time);
227  $sec = date("s",$time);
228  $hour = $hour+1;
229  $ret = date("H:i:s", mktime($hour,$min,$sec,$month,$day,$year));
230  return $ret;
231  }
232  function addDay($time)
233  {
234  $time = strtotime($time);
235  $day = date("d",$time);
236  $month = date("m",$time);
237  $year = date("y",$time);
238  $min = date("i",$time);
239  $hour = date("h",$time);
240  $sec = date("s",$time);
241  $day = $day + 1;
242  $ret = date ("Y-m-d", mktime($hour,$min,$sec,$month,$day,$year));
243  return $ret;
244  }
245 
246  function getSubId($id)
247  {
248  global $ilDB;
249 
250  $q = "SELECT obj_id from object_data "
251  ." where type = ".$ilDB->quote("lm", "text")." and "
252  ." owner = ".$ilDB->quote($id, "integer");
253  $res = $this->ilias->db->query($q);
254  for($i=0;$i<$res->numRows();$i++)
255  {
256  $result[$i]=$res->fetchRow();
257  }
258  return $result;
259  }
260  function getSubTest($id)
261  {
262  global $ilDB;
263 
264  $q = "SELECT obj_id from object_data "
265  ." where type = ".$ilDB->quote("tst", "text")." and "
266  ." owner = ".$ilDB->quote($id, "integer");
267  $res = $this->ilias->db->query($q);
268  for($i=0;$i<$res->numRows();$i++)
269  {
270  $result[$i]=$res->fetchRow();
271  }
272  return $result;
273  }
274 
275  function getTestId($id)
276  {
277  global $ilDB;
278 
279  $q = "select obj_id from object_data "
280  ." where type = ".$ilDB->quote("tst", "text")." and "
281  ." owner = ".$ilDB->quote($id, "integer");
282  $res = $this->ilias->db->query($q);
283  for ($i=0;$i<$res->numRows();$i++)
284  {
285  $result[$i]=$res->fetchRow();
286  }
287  return $result;
288  }
289 
290  function countResults($condition)
291  {
292  global $ilDB;
293 
294  $q = "SELECT count(*) from ut_access "
295  ." WHERE "
296  .$condition;
297  $res = $this->ilias->db->query($q);
298  $result = $res->fetchRow();
299  return $result[0];
300  }
301 
302  function searchResults($condition)
303  {
304  global $ilDB;
305 
306  $q = "SELECT a.login,b.acc_obj_type,b.language,b.client_ip,b.acc_time "
307  ." FROM usr_data a,ut_access b "
308  ." WHERE a.usr_id=b.user_id "
309  ." AND ".$condition;
310 //echo $q;
311  $res = $this->ilias->db->query($q);
312  for($i=0;$i<$res->numRows();$i++)
313  {
314  $result[$i]=$res->fetchRow();
315  }
316  return $result;
317  }
318 
319  function searchTestResults($condition)
320  {
321  global $ilDB;
322 
323  $q = "SELECT a.login,b.acc_obj_type,b.client_ip,b.acc_time "
324  ." FROM usr_data a,ut_access b "
325  ." WHERE a.usr_id=b.user_id "
326  ." AND ".$condition;
327 //echo $q;
328  $res = $this->ilias->db->query($q);
329  for($i=0;$i<$res->numRows();$i++)
330  {
331  $result[$i]=$res->fetchRow();
332  }
333  return $result;
334  }
335 
336  function searchUserId($condition)
337  {
338  global $ilDB;
339 
340  $q = "SELECT user_id from ut_access where ".$condition;
341 //echo $q;
342  $res = $this->ilias->db->query($q);
343  for($i=0;$i<$res->numRows();$i++)
344  {
345  $result[$i]=$res->fetchRow();
346  }
347  return $result;
348  }
349 
350  function searchTestId($condition)
351  {
352  global $ilDB;
353 
354  $q = "select user_fi from tst_active where ".$condition;
355  $res = $this->ilias->db->query($q);
356  for($i=0;$i<$res->numRows();$i++)
357  {
358  $result[$i]=$res->fetchRow();
359  }
360  return $result;
361  }
362 
363  function getPerTestId($test)
364  {
365  global $ilDB;
366 
367  $q = "select obj_id from object_data where type = ".
368  $ilDB->quote("tst", "text")." and title = ".$ilDB->quote($test, "text");
369  $res = $this->ilias->db->query($q);
370  $result = $res->fetchRow();
371  return $result[0];
372  }
373 
374  function countNum($from,$from1,$condition)
375  {
376  global $ilDB;
377 
378  $q = "SELECT count(*) from ut_access "
379  ." WHERE (acc_time > ".$ilDB->quote($from, "timestamp")
380  ." AND acc_time <= ".$ilDB->quote($from1, "integer").")"
381  ." AND ".$condition;
382  //echo $condition;echo "<br>";
383 //echo $q;
384  $res = $this->ilias->db->query($q);
385  $result = $res->fetchRow();
386  return $result[0];
387  }
388 
389  function selectTime($from,$to,$condition)
390  {
391  global $ilDB;
392 
393  $q = "SELECT acc_time from ut_access "
394  ." WHERE (acc_time > ".$ilDB->quote($from, "timestamp")
395  ." AND acc_time <= ".$ilDB->quote($to, "integer").")"
396  ." AND ".$condition;
397 //echo $q;
398 //echo "<br>";
399  $res = $this->ilias->db->query($q);
400  for($i=0;$i<$res->numRows();$i++)
401  {
402  $result[$i]=$res->fetchRow();
403  }
404  return $result;
405  }
406 
407  function getTest($id)
408  {
409  global $ilDB;
410 
411  $q = "SELECT title from object_data "
412  ." WHERE "
413  ." type = ".$ilDB->quote("tst", "text")
414  ." and "
415  ." owner = ".$ilDB->quote($id, "integer");
416  $res = $this->ilias->db->query($q);
417  for($i=0;$i<$res->numRows();$i++)
418  {
419  $result[$i]=$res->fetchRow();
420  }
421  return $result;
422  }
423 }
424 ?>