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

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

Generated on Fri Dec 13 2013 09:06:40 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1