• Main Page
  • Related Pages
  • 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         function ilTracking()
00053         {
00054                 global $ilias,$tpl,$lng;
00055 
00056                 $this->ilias    =& $ilias;
00057                 $this->tpl              =& $tpl;
00058                 $this->lng              =& $lng;
00059 
00060         }
00061 
00065         function _getLastAccess()
00066         {
00067                 global $ilUser, $ilDB;
00068 
00069                 $q = "SELECT * from ut_access "
00070                 ." WHERE "
00071                 ." user_id = ".$ilDB->quote($ilUser->getId())
00072                 ." order by acc_time desc limit 1 ";
00073                 $res = $ilDB->query($q);
00074                 return $res->fetchRow(DB_FETCHMODE_ASSOC);
00075         }
00076 
00086         function _trackAccess($a_obj_id, $a_obj_type,$a_sub_id = 0, $a_sub_type = "", $a_action_type = "read")
00087         {
00088                 global $ilUser, $ilDB;
00089 
00090 
00091                 include_once("Services/Tracking/classes/class.ilObjUserTracking.php");
00092                 if(!ilObjUserTracking::_enabledTracking() and !ilObjUserTracking::_enabledLearningProgress())
00093                 {
00094                         return false;
00095                 }
00096 
00097                 include_once 'Services/Tracking/classes/class.ilLearningProgress.php';
00098                 ilLearningProgress::_tracProgress($ilUser->getId(),$a_obj_id,$a_obj_type);
00099 
00100                 if (ilObjUserTracking::_enabledUserRelatedData())
00101                 {
00102                         $user_id = $ilUser->getId();
00103                 }
00104                 else
00105                 {
00106                         $user_id = 0;
00107                 }
00108 
00109                 $client_ip = getenv("REMOTE_ADDR");
00110                 $script = substr($_SERVER["SCRIPT_FILENAME"], strlen(IL_ABSOLUTE_PATH) - 1,
00111                         strlen($_SERVER["SCRIPT_FILENAME"]) - strlen(IL_ABSOLUTE_PATH) + 1);
00112                 $language = $ilUser->getLanguage();
00113                 $session_id = session_id();
00114 
00115                 $last_access = ilTracking::_getLastAccess();
00116                 if(($session_id == $last_access["session_id"]) &&
00117                         ($a_obj_id == $last_access["acc_obj_id"]) &&
00118                         ($a_obj_type == $last_access["acc_obj_type"]) &&
00119                         ($a_sub_id == $last_access["acc_sub_id"]) &&
00120                         ($a_sub_type == $last_access["acc_sub_type"])
00121                         )
00122                 {
00123                         return true;
00124                 }
00125                 else
00126                 {
00127                         $q = "INSERT INTO ut_access ("
00128                                 ."user_id, action_type, php_script, client_ip,"
00129                                 ."acc_obj_type, acc_obj_id, acc_sub_type, acc_sub_id,"
00130                                 ."language, browser, session_id, acc_time"
00131                                 .") VALUES ("
00132                                 .$ilDB->quote($user_id).","
00133                                 .$ilDB->quote($a_action_type).","
00134                                 .$ilDB->quote($script).","
00135                                 .$ilDB->quote($client_ip).","
00136                                 .$ilDB->quote($a_obj_type).","
00137                                 .$ilDB->quote($a_obj_id).","
00138                                 .$ilDB->quote($a_sub_type).","
00139                                 .$ilDB->quote($a_sub_id).","
00140                                 .$ilDB->quote($language).","
00141                                 .$ilDB->quote($_SERVER["HTTP_USER_AGENT"]).","
00142                                 .$ilDB->quote($session_id).", now()"
00143                                 .")";
00144                    $ilDB->query($q);
00145                 }
00146         }
00147         function TestTitle($user_id)
00148         {
00149                 $q = " SELECT title from object_data "
00150                         ." WHERE type = 'tst'"
00151                         ." AND owner = ".$user_id;
00152                 $res = $this->ilias->db->query($q);
00153                 for($i=0;$i<$res->numRows();$i++)
00154                 {
00155                         $result[$i]=$res->fetchRow();
00156                 }
00157                 return $result;
00158         }
00159 
00160         /*
00161         function searchTitle($user_id)
00162         {
00163                 $q = " SELECT title from object_data "
00164                         ." WHERE type = 'lm '"
00165                         ." AND owner = ".$user_id;
00166                 $res = $this->ilias->db->query($q);
00167                 for($i=0;$i<$res->numRows();$i++)
00168                 {
00169                         $result[$i]=$res->fetchRow();
00170                 }
00171                 return $result;
00172         }*/
00173 
00174 
00175         function numDay($from,$to)
00176         {
00177                 $from = strtotime($from);
00178                 $to = strtotime($to);
00179                 $dayf = date ("d",$from);
00180                 $dayt = date ("d",$to);
00181                 $yearf = date ("Y",$from); 
00182                 $yeart = date ("Y",$to); 
00183                 $montht = date ("m",$to); 
00184                 $monthf = date ("m",$from); 
00185                 $ret = ( mktime(0,0,0,$montht,$dayt,$yeart) - mktime(0,0,0,$monthf,$dayf,$yearf))/(3600*24); 
00186                 return $ret; 
00187         }
00188         function numHour($from,$to)
00189         {
00190                 $from = strtotime($from);
00191                 $to = strtotime($to);
00192                 $dayf = date ("d",$from); 
00193                 $dayt = date ("d",$to);
00194                 $yearf = date ("Y",$from); 
00195                 $yeart = date ("Y",$to); 
00196                 $montht = date ("m",$to); 
00197                 $monthf = date ("m",$from); 
00198                 $hourt = date ("h",$to);
00199                 $hourf = date ("h",$from);
00200                 $ret = (mktime($hourt,0,0,$montht,$dayt,$yeart)-mktime($hourf,0,0,$monthf,$dayf,$yearf))/3600; 
00201                 $ret = strftime($ret);
00202                 return $ret; 
00203         }
00204         function addHour($time)
00205         {
00206                 $time = strtotime($time);
00207                 $day = date("d",$time);
00208                 $month = date("m",$time);
00209                 $year = date("Y",$time);
00210                 $hour = date("H",$time);
00211                 $min = date("i",$time);
00212                 $sec = date("s",$time);
00213                 $hour = $hour+1;
00214                 $ret = date("H:i:s", mktime($hour,$min,$sec,$month,$day,$year));
00215                 return $ret;
00216         }
00217         function addDay($time)
00218         {
00219                 $time = strtotime($time);
00220                 $day = date("d",$time);
00221                 $month = date("m",$time);
00222                 $year = date("y",$time);
00223                 $min = date("i",$time);
00224                 $hour = date("h",$time);
00225                 $sec = date("s",$time);
00226                 $day = $day + 1;
00227                 $ret = date ("Y-m-d", mktime($hour,$min,$sec,$month,$day,$year));
00228                 return $ret;
00229         }
00230 
00231         function getSubId($id)
00232         {
00233                 $q = "SELECT obj_id from object_data "
00234                 ." WHERE type = 'lm' and "
00235                 ." owner = ".$id;
00236                 $res = $this->ilias->db->query($q);
00237                 for($i=0;$i<$res->numRows();$i++)
00238                 {
00239                         $result[$i]=$res->fetchRow();
00240                 }
00241                 return $result;
00242         }
00243         function getSubTest($id)
00244         {
00245                 $q = "SELECT obj_id from object_data "
00246                 ." WHERE type = 'tst' and "
00247                 ." owner = ".$id;
00248                 $res = $this->ilias->db->query($q);
00249                 for($i=0;$i<$res->numRows();$i++)
00250                 {
00251                         $result[$i]=$res->fetchRow();
00252                 }
00253                 return $result;
00254         }
00255         function getTestId($id)
00256         {
00257                 $q = "select obj_id from object_data "
00258                 ." where type = 'tst' and "
00259                 ." owner = ".$id;
00260                 $res = $this->ilias->db->query($q);
00261                 for ($i=0;$i<$res->numRows();$i++)
00262                 {
00263                         $result[$i]=$res->fetchRow();
00264                 }
00265                 return $result;
00266         }
00267         function countResults($condition)
00268         {
00269                 $q = "SELECT count(*) from ut_access "
00270                 ." WHERE "
00271                 .$condition;
00272                 $res = $this->ilias->db->query($q);
00273                 $result = $res->fetchRow();
00274                 return $result[0];
00275         }
00276         function searchResults($condition)
00277         {
00278                 $q = "SELECT a.login,b.acc_obj_type,b.language,b.client_ip,b.acc_time "
00279                         ." FROM usr_data as a,ut_access as b "
00280                         ." WHERE a.usr_id=b.user_id "
00281                         ." AND ".$condition;
00282 //echo $q;
00283                 $res = $this->ilias->db->query($q);
00284                 for($i=0;$i<$res->numRows();$i++)
00285                 {
00286                         $result[$i]=$res->fetchRow();
00287                 }
00288                 return $result;
00289         }
00290         function searchTestResults($condition)
00291         {
00292                 $q = "SELECT a.login,b.acc_obj_type,b.client_ip,b.acc_time "
00293                         ." FROM usr_data as a,ut_access as b "
00294                         ." WHERE a.usr_id=b.user_id "
00295                         ." AND ".$condition;
00296 //echo $q;
00297                 $res = $this->ilias->db->query($q);
00298                 for($i=0;$i<$res->numRows();$i++)
00299                 {
00300                         $result[$i]=$res->fetchRow();
00301                 }
00302                 return $result;
00303         }
00304         function searchUserId($condition)
00305         {
00306                 $q = "SELECT user_id from ut_access where ".$condition;
00307 //echo $q;
00308                 $res = $this->ilias->db->query($q);
00309                 for($i=0;$i<$res->numRows();$i++)
00310                 {
00311                         $result[$i]=$res->fetchRow();
00312                 }
00313                 return $result;
00314         }
00315         function searchTestId($condition)
00316         {
00317                 $q = "select user_fi from tst_active where ".$condition;
00318                 $res = $this->ilias->db->query($q);
00319                 for($i=0;$i<$res->numRows();$i++)
00320                 {
00321                         $result[$i]=$res->fetchRow();
00322                 }
00323                 return $result;
00324         }
00325         function getPerTestId($test)
00326         {
00327                 $q = "select obj_id from object_data where type = 'tst' and title = '".$test."'";
00328                 $res = $this->ilias->db->query($q);
00329                 $result = $res->fetchRow();
00330                 return $result[0];
00331         }
00332         function countNum($from,$from1,$condition)
00333         {
00334                 $q = "SELECT count(*) from ut_access "
00335                         ." WHERE (acc_time > '".$from
00336                         ."' AND acc_time <='".$from1."')"
00337                         ." AND ".$condition;
00338                         //echo $condition;echo "<br>";
00339 //echo $q;
00340                 $res = $this->ilias->db->query($q);
00341                 $result = $res->fetchRow();
00342                 return $result[0];
00343         }
00344         function selectTime($from,$to,$condition)
00345         {
00346                 $q = "SELECT acc_time from ut_access "
00347                         ." WHERE (acc_time >= '".$from
00348                         ."' AND acc_time <='".$to."')"
00349                         ." AND ".$condition;
00350 //echo $q;
00351 //echo "<br>";
00352                 $res = $this->ilias->db->query($q);
00353                 for($i=0;$i<$res->numRows();$i++)
00354                 {
00355                         $result[$i]=$res->fetchRow();
00356                 }
00357                 return $result;
00358         }
00359 
00360         function getTest($id)
00361         {
00362                 $q = "SELECT title from object_data "
00363                 ." WHERE "
00364                 ." type = 'tst' "
00365                 ." and "
00366                 ." owner = ".$id;
00367                 $res = $this->ilias->db->query($q);
00368                 for($i=0;$i<$res->numRows();$i++)
00369                 {
00370                         $result[$i]=$res->fetchRow();
00371                 }
00372                 return $result;
00373         }
00374 }
00375 ?>

Generated on Fri Dec 13 2013 11:57:59 for ILIAS Release_3_6_x_branch .rev 46809 by  doxygen 1.7.1