uid = $uid; $this->session = $this->writeSession($uid, $suid); // retrieve available actions $res = XDB::iterRow("SELECT id, text FROM logger.actions"); while (list($action_id, $action_text) = $res->next()) { $this->actions[$action_text] = $action_id; } } /** Creates a new session entry in database and return its ID. * * @param $uid the id of the logged user * @param $suid the id of the administrator who has just su'd to the user * @return session the session id */ function writeSession($uid, $suid = null) { $ip = $_SERVER['REMOTE_ADDR']; $host = strtolower(gethostbyaddr($_SERVER['REMOTE_ADDR'])); $browser = (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''); XDB::execute("INSERT INTO logger.sessions SET uid={?}, host={?}, ip={?}, browser={?}, suid={?}", $uid, $host, $ip, $browser, $suid); return XDB::insertId(); } /** Logs an action and its related data. * * @param $action le type d'action * @param $data les données (id de liste, etc.) * @return VOID */ function log($action, $data = null) { if (isset($this->actions[$action])) { XDB::execute("INSERT INTO logger.events SET session={?}, action={?}, data={?}", $this->session, $this->actions[$action], $data); } else { echo "unknown action : $action
"; } } } ?>