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
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 CoreLogger($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) {
74 $ip = $_SERVER['REMOTE_ADDR'];
75 $host = strtolower(gethostbyaddr($_SERVER['REMOTE_ADDR']));
76 $browser = (isset($_SERVER['HTTP_USER_AGENT']) ?
$_SERVER['HTTP_USER_AGENT'] : '');
77 $sql = "insert into {$this->table_sessions} set uid='$uid', host='$host', ip='$ip', browser='$browser'";
78 // optional parameters
80 $sql .= ", suid='$suid'";
82 $sql .= ", auth='$auth'";
84 $sql .= ", sauth='$sauth'";
88 return XDB
::insertId();
92 /** Reads available actions from database.
94 * @return actions the available actions
96 function readActions() {
97 $res = XDB
::iterRow("select id, text from {$this->table_actions}");
99 while (list($action_id, $action_text) = $res->next()) {
100 $actions[$action_text] = $action_id;
107 /** Logs an action and its related data.
109 * @param $action le type d'action
110 * @param $data les données (id de liste, etc.)
113 function log($action, $data="") {
114 if (isset($this->actions
[$action])) {
115 XDB
::execute("insert into {$this->table_events}
116 set session={?}, action={?}, data={?}",
117 $this->session
, $this->actions
[$action], $data);
119 echo "unknown action : $action<br />";