table_actions = $globals->table_log_actions; $this->table_events = $globals->table_log_events; $this->table_sessions = $globals->table_log_sessions; // write the session entry $this->uid = $uid; $this->session = $this->writeSession($uid,$suid,$auth,$sauth); // retrieve available actions $this->actions = $this->readActions(); } /** 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 * @param $auth authentication method for the logged user * @param $sauth authentication method for the su'er * @return session the session id */ function writeSession($uid,$suid,$auth,$sauth) { global $globals; $ip = $_SERVER['REMOTE_ADDR']; $host = strtolower(gethostbyaddr($_SERVER['REMOTE_ADDR'])); $browser = (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''); $sql = "INSERT INTO {$this->table_sessions} SET uid='$uid',host='$host',ip='$ip',browser='$browser'"; // optional parameters if ($suid) $sql .= ",suid='$suid'"; if ($auth) $sql .= ",auth='$auth'"; if ($sauth) $sql .= ",sauth='$sauth'"; $globals->db->query($sql); return $globals->db->insert_id(); } /** Reads available actions from database. * * @return actions the available actions */ function readActions() { global $globals; $res=$globals->db->query("SELECT id,text FROM {$this->table_actions}"); while(list($action_id,$action_text)=mysql_fetch_row($res)) $actions[$action_text] = $action_id; mysql_free_result($res); return $actions; } /** 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="") { global $globals; if (isset($this->actions[$action])) $globals->db->query("INSERT INTO {$this->table_events} SET session='{$this->session}',action='{$this->actions[$action]}',data='{$data}'"); else echo "unknown action : $action
"; } /** Print out the id for the current session * @return VOID */ function debug() { echo "session=".$this->session."
"; echo "uid=".$this->uid."
"; print_r($this->actions); echo "
"; } } ?>