• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/Tracking/classes/class.ilTracking.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
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                 // We query for the session_id since it is more unique than the user_id. 
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                 if(($session_id == $last_access["session_id"]) &&
00161                         ($a_obj_id == $last_access["acc_obj_id"]) &&
00162                         ($a_obj_type == $last_access["acc_obj_type"]) &&
00163                         ($a_sub_id == $last_access["acc_sub_id"]) &&
00164                         ($a_sub_type == $last_access["acc_sub_type"])
00165                         )
00166                 {
00167                         return true;
00168                 }
00169                 else
00170                 {
00171                         $q = "INSERT INTO ut_access ("
00172                                 ."user_id, action_type, php_script, client_ip,"
00173                                 ."acc_obj_type, acc_obj_id, acc_sub_type, acc_sub_id,"
00174                                 ."language, browser, session_id, acc_time"
00175                                 .") VALUES ("
00176                                 .$ilDB->quote($user_id).","
00177                                 .$ilDB->quote($a_action_type).","
00178                                 .$ilDB->quote($script).","
00179                                 .$ilDB->quote($client_ip).","
00180                                 .$ilDB->quote($a_obj_type).","
00181                                 .$ilDB->quote($a_obj_id).","
00182                                 .$ilDB->quote($a_sub_type).","
00183                                 .$ilDB->quote($a_sub_id).","
00184                                 .$ilDB->quote($language).","
00185                                 .$ilDB->quote($_SERVER["HTTP_USER_AGENT"]).","
00186                                 .$ilDB->quote($session_id).", now()"
00187                                 .")";
00188                    $ilDB->query($q);
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         function searchTitle($user_id)
00207         {
00208                 $q = " SELECT title from object_data "
00209                         ." WHERE type = 'lm '"
00210                         ." AND owner = ".$user_id;
00211                 $res = $this->ilias->db->query($q);
00212                 for($i=0;$i<$res->numRows();$i++)
00213                 {
00214                         $result[$i]=$res->fetchRow();
00215                 }
00216                 return $result;
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 //echo $q;
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 //echo $q;
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 //echo $q;
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                         //echo $condition;echo "<br>";
00384 //echo $q;
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 //echo $q;
00396 //echo "<br>";
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 ?>

Generated on Fri Dec 13 2013 17:57:01 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1