00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00025 class DiogenesCoreLogger {
00027 var $uid;
00029 var $session;
00031 var $actions;
00032
00034 var $table_actions;
00036 var $table_events;
00038 var $table_sessions;
00039
00048 function DiogenesCoreLogger($uid,$suid='',$auth='',$sauth='') {
00049 global $globals;
00050
00051
00052 $this->table_actions = $globals->table_log_actions;
00053 $this->table_events = $globals->table_log_events;
00054 $this->table_sessions = $globals->table_log_sessions;
00055
00056
00057 $this->uid = $uid;
00058 $this->session = $this->writeSession($uid,$suid,$auth,$sauth);
00059
00060
00061 $this->actions = $this->readActions();
00062 }
00063
00064
00073 function writeSession($uid,$suid,$auth,$sauth) {
00074 global $globals;
00075
00076 $ip = $_SERVER['REMOTE_ADDR'];
00077 $host = strtolower(gethostbyaddr($_SERVER['REMOTE_ADDR']));
00078 $browser = (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '');
00079 $sql = "INSERT INTO {$this->table_sessions} SET uid='$uid',host='$host',ip='$ip',browser='$browser'";
00080
00081 if ($suid)
00082 $sql .= ",suid='$suid'";
00083 if ($auth)
00084 $sql .= ",auth='$auth'";
00085 if ($sauth)
00086 $sql .= ",sauth='$sauth'";
00087
00088 $globals->db->query($sql);
00089
00090 return $globals->db->insert_id();
00091 }
00092
00093
00098 function readActions() {
00099 global $globals;
00100
00101 $res=$globals->db->query("SELECT id,text FROM {$this->table_actions}");
00102 while(list($action_id,$action_text)=mysql_fetch_row($res))
00103 $actions[$action_text] = $action_id;
00104
00105 mysql_free_result($res);
00106
00107 return $actions;
00108 }
00109
00110
00117 function log($action,$data="") {
00118 global $globals;
00119
00120 if (isset($this->actions[$action]))
00121 $globals->db->query("INSERT INTO {$this->table_events} SET session='{$this->session}',action='{$this->actions[$action]}',data='{$data}'");
00122 else
00123 echo "unknown action : $action<br />";
00124 }
00125
00129 function debug() {
00130 echo "session=".$this->session."<br />";
00131 echo "uid=".$this->uid."<br />";
00132 print_r($this->actions);
00133 echo "<br />";
00134 }
00135 }
00136
00137 ?>