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
25 /** id of the session */
27 /** list of available actions */
30 /** The constructor, creates a new entry in the sessions table
32 * @param $uid the id of the logged user
33 * @param $suid the id of the administrator who has just su'd to the user
36 function CoreLogger($uid, $suid='') {
37 // write the session entry
39 $this->session
= $this->writeSession($uid, $suid);
41 // retrieve available actions
42 $res = XDB
::iterRow("SELECT id, text FROM logger.actions");
44 while (list($action_id, $action_text) = $res->next()) {
45 $this->actions
[$action_text] = $action_id;
49 /** Creates a new session entry in database and return its ID.
51 * @param $uid the id of the logged user
52 * @param $suid the id of the administrator who has just su'd to the user
53 * @return session the session id
55 function writeSession($uid, $suid = null
) {
56 $ip = $_SERVER['REMOTE_ADDR'];
57 $host = strtolower(gethostbyaddr($_SERVER['REMOTE_ADDR']));
58 $browser = (isset($_SERVER['HTTP_USER_AGENT']) ?
$_SERVER['HTTP_USER_AGENT'] : '');
60 XDB
::execute("INSERT INTO logger.sessions
61 SET uid={?}, host={?}, ip={?}, browser={?}, suid={?}",
62 $uid, $Host, $ip, $browser, $suid);
64 return XDB
::insertId();
68 /** Logs an action and its related data.
70 * @param $action le type d'action
71 * @param $data les données (id de liste, etc.)
74 function log($action, $data = null
) {
75 if (isset($this->actions
[$action])) {
76 XDB
::execute("INSERT INTO logger.events
77 SET session={?}, action={?}, data={?}",
78 $this->session
, $this->actions
[$action], $data);
80 echo "unknown action : $action<br />";