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