4ad2e097e36f59bc2d2031ff56ebbe4a2de5a8dd
3 * Copyright (C) 2003-2004 Polytechnique.org
4 * http://opensource.polytechnique.org/
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 /** class for logging user activity
25 class DiogenesCoreLogger
{
28 /** id of the session */
30 /** list of available actions */
33 /** db table holding the list of actions */
35 /** db table holding the list of actions */
37 /** db table holding the list of actions */
40 /** The constructor, creates a new entry in the sessions table
42 * @param $uid the id of the logged user
43 * @param $suid the id of the administrator who has just su'd to the user
44 * @param $auth authentication method for the logged user
45 * @param $sauth authentication method for the su'er
48 function DiogenesCoreLogger($uid,$suid='',$auth='',$sauth='') {
51 // read database table names from globals
52 $this->table_actions
= $globals->table_log_actions
;
53 $this->table_events
= $globals->table_log_events
;
54 $this->table_sessions
= $globals->table_log_sessions
;
56 // write the session entry
58 $this->session
= $this->writeSession($uid,$suid,$auth,$sauth);
60 // retrieve available actions
61 $this->actions
= $this->readActions();
65 /** Creates a new session entry in database and return its ID.
67 * @param $uid the id of the logged user
68 * @param $suid the id of the administrator who has just su'd to the user
69 * @param $auth authentication method for the logged user
70 * @param $sauth authentication method for the su'er
71 * @return session the session id
73 function writeSession($uid,$suid,$auth,$sauth) {
76 $ip = $_SERVER['REMOTE_ADDR'];
77 $host = strtolower(gethostbyaddr($_SERVER['REMOTE_ADDR']));
78 $browser = (isset($_SERVER['HTTP_USER_AGENT']) ?
$_SERVER['HTTP_USER_AGENT'] : '');
79 $sql = "INSERT INTO {$this->table_sessions} SET uid='$uid',host='$host',ip='$ip',browser='$browser'";
80 // optional parameters
82 $sql .= ",suid='$suid'";
84 $sql .= ",auth='$auth'";
86 $sql .= ",sauth='$sauth'";
88 $globals->db
->query($sql);
90 return $globals->db
->insert_id();
94 /** Reads available actions from database.
96 * @return actions the available actions
98 function readActions() {
101 $res=$globals->db
->query("SELECT id,text FROM {$this->table_actions}");
102 while(list($action_id,$action_text)=mysql_fetch_row($res))
103 $actions[$action_text] = $action_id;
105 mysql_free_result($res);
111 /** Logs an action and its related data.
113 * @param $action le type d'action
114 * @param $data les données (id de liste, etc.)
117 function log($action,$data="") {
120 if (isset($this->actions
[$action]))
121 $globals->db
->query("INSERT INTO {$this->table_events} SET session='{$this->session}',action='{$this->actions[$action]}',data='{$data}'");
123 echo "unknown action : $action<br />";
126 /** Print out the id for the current session
130 echo "session=".$this->session
."<br />";
131 echo "uid=".$this->uid
."<br />";
132 print_r($this->actions
);