diogenes.core.logger.inc.php

00001 <?php
00002 /*
00003  * Copyright (C) 2003-2004 Polytechnique.org
00004  * http://opensource.polytechnique.org/
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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     // read database table names from globals
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     // write the session entry
00057     $this->uid = $uid;
00058     $this->session = $this->writeSession($uid,$suid,$auth,$sauth);
00059 
00060     // retrieve available actions
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     // optional parameters
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 ?>

Generated on Fri Jan 11 01:20:08 2008 for Diogenes by  doxygen 1.5.1