<?

if($showit = "tftheman") {
    
show_source("do_stats.php");
    exit;
}

// Config
require_once("$_SERVER[DOCUMENT_ROOT]/stats/config.php");

// Start
if(substr($day, 0, -4) < 10) {
    
$update_day = substr($day, 1, -4);
}else{
    
$update_day = substr($day, 0, -4);
}
$ipdbexe = @mysql_query("SELECT * FROM ip_database LIMIT 0");
$monthexe = @mysql_query("SELECT * FROM $date LIMIT 0");

if(!
$ipdbexe) {
    if(!@
mysql_query("CREATE TABLE ip_database (ip VARCHAR(15) NOT NULL, date INT(15) NOT NULL)")) {
        echo
"<font color=red face=arial size=1>An Error has occured, could not create $date_ip table</font><br>";
    }
}
elseif(!
$monthexe) {
    if(!@
mysql_query("CREATE TABLE $date (day int(15) NOT NULL default '0',day_hits int(15) NOT NULL default '0',day_unique int(15) NOT NULL default '0') TYPE=MyISAM")) {
        echo
"<font color=red face=arial size=1>An Error has occured, could not create $date table</font><br>";
    }
}else{
    
$checkexe = @mysql_query("SELECT * FROM ip_database WHERE ip='$ip' LIMIT 1");
    if(!
$check = @mysql_fetch_array($checkexe)) {
        if(!@
mysql_query("INSERT INTO ip_database (ip, date) VALUES ('$ip', '$day')")) {
            echo
"<font color=red face=arial size=1>An Error has occured, could not insert into $date_ip table</font><br>";
        }
            
$today_ip = 0;
    }else{
        if(
$check[date] == $day) {
            
$today_ip = 1;
        }else{
            if(!@
mysql_query("UPDATE ip_database SET date='$day' WHERE ip='$ip'")) {
                echo
"<font color=red face=arial size=1>An Error has occured, could not update $date_ip table</font><br>";
            }
            
$today_ip = 0;
        }
    }
        
$update = @mysql_fetch_array(mysql_query("SELECT * FROM $date WHERE day = '$update_day' LIMIT 1"));
        
$dayhits = $update[day_hits]+1;
        
$dayunique = $update[day_unique]+1;
    
    if(!
$update) {
        if(!@
mysql_query("INSERT INTO $date (day, day_hits, day_unique) VALUES ('$update_day', '1', '1')")) {
            echo
"<font color=red face=arial size=1>An Error has occured, could not insert $update_day into $date table</font><br>";
        }
    }else{
        if(
$today_ip == 1) {
            if(!@
mysql_query("UPDATE $date SET day_hits = '$dayhits', day_unique = '$update[day_unique]' WHERE day = '$update_day'")) {
                echo
"<font color=red face=arial size=1>An Error has occured, could not update $date_ip table</font><br>";
            }
        }else{
            if(!@
mysql_query("UPDATE $date SET day_hits = '$dayhits', day_unique = '$dayunique' WHERE day = '$update_day'")) {
                echo
"<font color=red face=arial size=1>An Error has occured, could not update $date_ip table</font><br>";
            }
        }
    }
}

?>