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
21 class PlatalLogger
extends PlLogger
25 /** id of the session */
27 /** list of available actions */
35 /** The constructor, creates a new entry in the sessions table
37 * @param $uid the id of the logged user
38 * @param $suid the id of the administrator who has just su'd to the user
41 public function __construct($uid, $suid = 0)
43 // write the session entry
45 $this->session
= $this->writeSession($uid, $suid);
47 // retrieve available actions
48 $res = XDB
::iterRow("SELECT id, text FROM logger.actions");
50 while (list($action_id, $action_text) = $res->next()) {
51 $this->actions
[$action_text] = $action_id;
55 /** Creates a new session entry in database and return its ID.
57 * @param $uid the id of the logged user
58 * @param $suid the id of the administrator who has just su'd to the user
59 * @return session the session id
61 private function writeSession($uid, $suid = 0)
63 $ip = $_SERVER['REMOTE_ADDR'];
64 $host = strtolower(gethostbyaddr($_SERVER['REMOTE_ADDR']));
65 $browser = (isset($_SERVER['HTTP_USER_AGENT']) ?
$_SERVER['HTTP_USER_AGENT'] : '');
67 @list
($forward_ip,) = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
68 $forward_host = $forward_ip;
70 $forward_host = strtolower(gethostbyaddr($forward_host));
73 if ($forward_ip ||
@$_SERVER['HTTP_VIA']) {
77 XDB
::execute("INSERT INTO logger.sessions
78 SET uid={?}, host={?}, ip={?}, forward_ip={?}, forward_host={?}, browser={?}, suid={?}, flags={?}",
79 $uid, $host, ip_to_uint($ip), ip_to_uint($forward_ip), $forward_host, $browser, $suid, $proxy);
81 $this->proxy_ip
= $ip;
82 $this->proxy_host
= $host;
83 $this->ip
= $forward_ip;
84 $this->host
= $forward_host;
90 return XDB
::insertId();
93 public function saveLastSession() {
94 XDB
::execute('REPLACE INTO logger.last_sessions (uid, id)
96 $this->uid
, $this->session
);
100 /** Logs an action and its related data.
102 * @param $action le type d'action
103 * @param $data les données (id de liste, etc.)
106 public function log($action, $data = null
)
108 if (isset($this->actions
[$action])) {
109 XDB
::execute("INSERT INTO logger.events
110 SET session={?}, action={?}, data={?}",
111 $this->session
, $this->actions
[$action], $data);
113 trigger_error("PlLogger: unknown action, $action", E_USER_WARNING
);
118 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: