00001 <?php
00036 class EventLog {
00037 private $areaid;
00038 private $enabled;
00039 private $uid;
00046 function __construct() {
00047 global $cfg, $session;
00048
00049 $this->areaid = $cfg->getAreaId();
00050 $this->enabled = ($cfg->getConfig("LOG_ENABLED") == "Y");
00051 $this->uid = $session->getValue("uid");
00052
00053
00054 if (!$session->getValue("gcdone")) {
00055 $lifetime = $cfg->getConfig("LOG_ENTRIES_LIFETIME");
00056 if ($lifetime > 0) {
00057 mysql_query("DELETE FROM eventlog WHERE (id_area = " . $this->areaid . ") " .
00058 "AND (`datetime` < " . (time() - ($lifetime * 86400)) . ")");
00059 }
00060 $session->setValue("gcdone", TRUE);
00061 }
00062 }
00063
00070 public function write($eventid, $notes = "") {
00071 if ($this->enabled) {
00072 $ip = $_SERVER['REMOTE_ADDR'];
00073 if (!$ip) { $ip = "127.0.0.1"; }
00074 mysql_query("INSERT INTO eventlog (id_area, datetime, userid, remote_ip, remote_host, eventid, notes) VALUES (" .
00075 $this->areaid . ", " .
00076 time() . ", '" .
00077 $this->uid . "', '" .
00078 $ip . "', '" .
00079 gethostbyaddr($ip) . "', '" .
00080 $eventid . "', '" .
00081 mysql_escape_string($notes) .
00082 "')");
00083 }
00084 }
00085
00094 public function clear($untildate = 0) {
00095 $sql = "DELETE FROM eventlog WHERE (id_area = " . $this->areaid . ")";
00096 if ($untildate > 0) {
00097 $sql .= " AND (datetime <= " . $untildate . ")";
00098 }
00099 mysql_query($sql);
00100 }
00101 }
00102 ?>