00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00036 class ilTracking {
00037
00038 var $objId;
00039 var $userId;
00040 var $actionType;
00041 var $phpScript;
00042 var $clientIp;
00043 var $accObjType;
00044 var $accObjId;
00045 var $accSubType;
00046 var $accSubId;
00047 var $lanugage;
00048 var $browser;
00049 var $sessionId;
00050 var $acc_time;
00051
00052 var $db;
00053
00054 function ilTracking()
00055 {
00056 global $ilias,$tpl,$lng,$ilDB;
00057
00058 $this->ilias =& $ilias;
00059 $this->tpl =& $tpl;
00060 $this->lng =& $lng;
00061 $this->db = $ilDB;
00062
00063 }
00064
00068 function _getLastAccess()
00069 {
00070 global $ilUser, $ilDB;
00071
00072 $q = "SELECT * from ut_access "
00073 ." WHERE "
00074 ." user_id = ".$ilDB->quote($ilUser->getId())
00075 ." order by acc_time desc limit 1 ";
00076 $res = $ilDB->query($q);
00077 return $res->fetchRow(DB_FETCHMODE_ASSOC);
00078 }
00079
00080 function _hasEntry($a_obj_id, $a_obj_type,$a_sub_id = 0, $a_sub_type = "")
00081 {
00082 global $ilDB;
00083
00084
00085
00086 $query = "SELECT COUNT(id) as num_entries FROM ut_access ".
00087 "WHERE session_id = ".$ilDB->quote(session_id())." ".
00088 "AND acc_obj_id = ".$ilDB->quote($a_obj_id)." ".
00089 "AND acc_sub_id = ".$ilDB->quote($a_sub_id);
00090 $res = $ilDB->query($query);
00091 $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
00092
00093 return $row->num_entries ? true : false;
00094 }
00095
00105 function _trackAccess($a_obj_id, $a_obj_type,$a_sub_id = 0, $a_sub_type = "", $a_action_type = "read")
00106 {
00107 global $ilUser, $ilDB;
00108
00109
00110 include_once("Services/Tracking/classes/class.ilObjUserTracking.php");
00111 if(!ilObjUserTracking::_enabledTracking() and !ilObjUserTracking::_enabledLearningProgress())
00112 {
00113 return false;
00114 }
00115
00116 include_once 'Services/Tracking/classes/class.ilLearningProgress.php';
00117 ilLearningProgress::_tracProgress($ilUser->getId(),$a_obj_id,$a_obj_type);
00118
00119 if (ilObjUserTracking::_enabledUserRelatedData())
00120 {
00121 $user_id = $ilUser->getId();
00122 }
00123 else
00124 {
00125 $user_id = 0;
00126 }
00127
00128 $client_ip = getenv("REMOTE_ADDR");
00129 $script = substr($_SERVER["SCRIPT_FILENAME"], strlen(IL_ABSOLUTE_PATH) - 1,
00130 strlen($_SERVER["SCRIPT_FILENAME"]) - strlen(IL_ABSOLUTE_PATH) + 1);
00131 $language = $ilUser->getLanguage();
00132 $session_id = session_id();
00133
00134 #$last_access = ilTracking::_getLastAccess();
00135
00136 if(ilTracking::_hasEntry($a_obj_id, $a_obj_type,$a_sub_id, $a_sub_type))
00137 {
00138 return true;
00139 }
00140 $q = "INSERT INTO ut_access ("
00141 ."user_id, action_type, php_script, client_ip,"
00142 ."acc_obj_type, acc_obj_id, acc_sub_type, acc_sub_id,"
00143 ."language, browser, session_id, acc_time"
00144 .") VALUES ("
00145 .$ilDB->quote($user_id).","
00146 .$ilDB->quote($a_action_type).","
00147 .$ilDB->quote($script).","
00148 .$ilDB->quote($client_ip).","
00149 .$ilDB->quote($a_obj_type).","
00150 .$ilDB->quote($a_obj_id).","
00151 .$ilDB->quote($a_sub_type).","
00152 .$ilDB->quote($a_sub_id).","
00153 .$ilDB->quote($language).","
00154 .$ilDB->quote($_SERVER["HTTP_USER_AGENT"]).","
00155 .$ilDB->quote($session_id).", now()"
00156 .")";
00157 $ilDB->query($q);
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191 }
00192 function TestTitle($user_id)
00193 {
00194 $q = " SELECT title from object_data "
00195 ." WHERE type = 'tst'"
00196 ." AND owner = ".$user_id;
00197 $res = $this->ilias->db->query($q);
00198 for($i=0;$i<$res->numRows();$i++)
00199 {
00200 $result[$i]=$res->fetchRow();
00201 }
00202 return $result;
00203 }
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220 function numDay($from,$to)
00221 {
00222 $from = strtotime($from);
00223 $to = strtotime($to);
00224 $dayf = date ("d",$from);
00225 $dayt = date ("d",$to);
00226 $yearf = date ("Y",$from);
00227 $yeart = date ("Y",$to);
00228 $montht = date ("m",$to);
00229 $monthf = date ("m",$from);
00230 $ret = ( mktime(0,0,0,$montht,$dayt,$yeart) - mktime(0,0,0,$monthf,$dayf,$yearf))/(3600*24);
00231 return $ret;
00232 }
00233 function numHour($from,$to)
00234 {
00235 $from = strtotime($from);
00236 $to = strtotime($to);
00237 $dayf = date ("d",$from);
00238 $dayt = date ("d",$to);
00239 $yearf = date ("Y",$from);
00240 $yeart = date ("Y",$to);
00241 $montht = date ("m",$to);
00242 $monthf = date ("m",$from);
00243 $hourt = date ("h",$to);
00244 $hourf = date ("h",$from);
00245 $ret = (mktime($hourt,0,0,$montht,$dayt,$yeart)-mktime($hourf,0,0,$monthf,$dayf,$yearf))/3600;
00246 $ret = strftime($ret);
00247 return $ret;
00248 }
00249 function addHour($time)
00250 {
00251 $time = strtotime($time);
00252 $day = date("d",$time);
00253 $month = date("m",$time);
00254 $year = date("Y",$time);
00255 $hour = date("H",$time);
00256 $min = date("i",$time);
00257 $sec = date("s",$time);
00258 $hour = $hour+1;
00259 $ret = date("H:i:s", mktime($hour,$min,$sec,$month,$day,$year));
00260 return $ret;
00261 }
00262 function addDay($time)
00263 {
00264 $time = strtotime($time);
00265 $day = date("d",$time);
00266 $month = date("m",$time);
00267 $year = date("y",$time);
00268 $min = date("i",$time);
00269 $hour = date("h",$time);
00270 $sec = date("s",$time);
00271 $day = $day + 1;
00272 $ret = date ("Y-m-d", mktime($hour,$min,$sec,$month,$day,$year));
00273 return $ret;
00274 }
00275
00276 function getSubId($id)
00277 {
00278 $q = "SELECT obj_id from object_data "
00279 ." WHERE type = 'lm' and "
00280 ." owner = ".$id;
00281 $res = $this->ilias->db->query($q);
00282 for($i=0;$i<$res->numRows();$i++)
00283 {
00284 $result[$i]=$res->fetchRow();
00285 }
00286 return $result;
00287 }
00288 function getSubTest($id)
00289 {
00290 $q = "SELECT obj_id from object_data "
00291 ." WHERE type = 'tst' and "
00292 ." owner = ".$id;
00293 $res = $this->ilias->db->query($q);
00294 for($i=0;$i<$res->numRows();$i++)
00295 {
00296 $result[$i]=$res->fetchRow();
00297 }
00298 return $result;
00299 }
00300 function getTestId($id)
00301 {
00302 $q = "select obj_id from object_data "
00303 ." where type = 'tst' and "
00304 ." owner = ".$id;
00305 $res = $this->ilias->db->query($q);
00306 for ($i=0;$i<$res->numRows();$i++)
00307 {
00308 $result[$i]=$res->fetchRow();
00309 }
00310 return $result;
00311 }
00312 function countResults($condition)
00313 {
00314 $q = "SELECT count(*) from ut_access "
00315 ." WHERE "
00316 .$condition;
00317 $res = $this->ilias->db->query($q);
00318 $result = $res->fetchRow();
00319 return $result[0];
00320 }
00321 function searchResults($condition)
00322 {
00323 $q = "SELECT a.login,b.acc_obj_type,b.language,b.client_ip,b.acc_time "
00324 ." FROM usr_data as a,ut_access as b "
00325 ." WHERE a.usr_id=b.user_id "
00326 ." AND ".$condition;
00327
00328 $res = $this->ilias->db->query($q);
00329 for($i=0;$i<$res->numRows();$i++)
00330 {
00331 $result[$i]=$res->fetchRow();
00332 }
00333 return $result;
00334 }
00335 function searchTestResults($condition)
00336 {
00337 $q = "SELECT a.login,b.acc_obj_type,b.client_ip,b.acc_time "
00338 ." FROM usr_data as a,ut_access as b "
00339 ." WHERE a.usr_id=b.user_id "
00340 ." AND ".$condition;
00341
00342 $res = $this->ilias->db->query($q);
00343 for($i=0;$i<$res->numRows();$i++)
00344 {
00345 $result[$i]=$res->fetchRow();
00346 }
00347 return $result;
00348 }
00349 function searchUserId($condition)
00350 {
00351 $q = "SELECT user_id from ut_access where ".$condition;
00352
00353 $res = $this->ilias->db->query($q);
00354 for($i=0;$i<$res->numRows();$i++)
00355 {
00356 $result[$i]=$res->fetchRow();
00357 }
00358 return $result;
00359 }
00360 function searchTestId($condition)
00361 {
00362 $q = "select user_fi from tst_active where ".$condition;
00363 $res = $this->ilias->db->query($q);
00364 for($i=0;$i<$res->numRows();$i++)
00365 {
00366 $result[$i]=$res->fetchRow();
00367 }
00368 return $result;
00369 }
00370 function getPerTestId($test)
00371 {
00372 $q = "select obj_id from object_data where type = 'tst' and title = '".$test."'";
00373 $res = $this->ilias->db->query($q);
00374 $result = $res->fetchRow();
00375 return $result[0];
00376 }
00377 function countNum($from,$from1,$condition)
00378 {
00379 $q = "SELECT count(*) from ut_access "
00380 ." WHERE (acc_time > '".$from
00381 ."' AND acc_time <='".$from1."')"
00382 ." AND ".$condition;
00383
00384
00385 $res = $this->ilias->db->query($q);
00386 $result = $res->fetchRow();
00387 return $result[0];
00388 }
00389 function selectTime($from,$to,$condition)
00390 {
00391 $q = "SELECT acc_time from ut_access "
00392 ." WHERE (acc_time >= '".$from
00393 ."' AND acc_time <='".$to."')"
00394 ." AND ".$condition;
00395
00396
00397 $res = $this->ilias->db->query($q);
00398 for($i=0;$i<$res->numRows();$i++)
00399 {
00400 $result[$i]=$res->fetchRow();
00401 }
00402 return $result;
00403 }
00404
00405 function getTest($id)
00406 {
00407 $q = "SELECT title from object_data "
00408 ." WHERE "
00409 ." type = 'tst' "
00410 ." and "
00411 ." owner = ".$id;
00412 $res = $this->ilias->db->query($q);
00413 for($i=0;$i<$res->numRows();$i++)
00414 {
00415 $result[$i]=$res->fetchRow();
00416 }
00417 return $result;
00418 }
00419 }
00420 ?>