<?
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Sections~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
//GENERAL # see below
//MISC # Misc ID" => "Pages" => "Hits" => "Bandwidth
//TIME # Hour" => "Pages" => "Hits" => "Bandwidth" => "Not viewed Pages" => "Not viewed Hits" => "Not viewed Bandwidth
//VISITOR # Host" => "Pages" => "Hits" => "Bandwidth" => "Last visit date" => "[Start date of last visit]" => "[Last page of last visit]
//DAY # Date" => "Pages" => "Hits" => "Bandwidth" => "Visits
//DOMAIN # Domain" => "Pages" => "Hits" => "Bandwidth
//ROBOT # Robot ID" => "Hits" => "Bandwidth" => "Last visit" => "Hits on robots.txt
//SESSION # Session range" => "Number of visits
//SIDER # URL" => "Pages" => "Bandwidth" => "Entry" => "Exit
//FILETYPES # Files type" => "Hits" => "Bandwidth" => "Bandwidth without compression" => "Bandwidth after compression
//OS # OS ID" => "Hits
//BROWSER # Browser ID" => "Hits
//UNKNOWNREFERER # Unknown referer OS" => "Last visit date
//UNKNOWNREFERERBROWSER # Unknown referer Browser" => "Last visit date
//ORIGIN # Origin" => "Pages" => "Hits
//PAGEREFS # External page referers" => "Pages" => "Hits
//ERRORS # Errors" => "Hits" => "Bandwidth
//SIDER_404  # URL with 404 errors" => "Hits" => "Last URL referer
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Sections~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~GENERAL~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
# LastLine    = Date of last record processed" => "Last record line number in last log" => "Last record offset in last log" => "Last record signature value
# FirstTime   = Date of first visit for history file
# LastTime    = Date of last visit for history file
# LastUpdate  = Date of last update" => "Nb of parsed records" => "Nb of parsed old records" => "Nb of parsed new records" => "Nb of parsed corrupted- Nb of parsed dropped
# TotalVisits = Number of visits
# TotalUnique = Number of unique visitors
# MonthHostsKnown   = Number of hosts known
# MonthHostsUnKnown = Number of hosts unknown
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~GENERAL~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
//USER CONFIG
$awstat_path = "/var/lib/awstats";
$config_domain = "www.colddot.nl";

//NAME CHANGERS
$os_array = array(
	"winxp" => "Windows XP",
	"winxbox" => "Xbox",
	"winnt" => "Windows NT",
	"winme" => "Windows ME",
	"winlong" => "Windows Longhorn",
	"wince" => "Windows CE",
	"win" => "Windows",
	"win2003" => "Windows 2003",
	"win2000" => "Windows 2000",
	"win98" => "Windows 98",
	"win95" => "Windows 95",
	"win16" => "Windows 16",
	"webtv" => "Web TV",
	"sunos" => "Sun OS",
	"psp" => "Playstation portable",
	"openbsd" => "Open BSD",
	"netbsd" => "Net BSD",
	"macosx" => "Mac OS X",
	"macintosh" => "Mac Intosh",
	"linuxubuntu" => "Ubuntu",
	"linuxsuse" => "SuSe",
	"linuxredhat" => "Red Hat",
	"linuxmandr" => "Mandrake",
	"linuxfedora" => "Fedora",
	"linuxdebian" => "Debian",
	"linuxcentos" => "Centos",
	"kfreebsd" => "kFree BSD",
	"freebsd" => "Free BSD",
	"bsdopenbsd" => "BSD Open BSD",
	"bsdnetbsd" => "BSD Net BSD",
	"bsdfreebsd" => "BSD Free BSD"
);

$bot_array = array(
	"googlebot" => "http://www.google.com/bot.html",
	"msnbot" => "http://search.msn.com/msnbot.htm",
	"slurp" => "http://help.yahoo.com/help/us/ysearch/slurp/",
	"girafabot" => "http://www.girafa.com/",
	"msiecrawler" => "http://msdn.microsoft.com/workshop/delivery/offline/linkrel.asp",
	"mj12bot" => "http://majestic12.co.uk/bot.php",
	"jeeves" => "http://sp.ask.com/docs/about/tech_crawling.html",
);

$error_array = array(
	"0" => "Onvolledig/Niet gedefinieerd",
	"201" => "Angemaakt",
	"202" => "Geaccepteerd",
	"204" => "Geen inhoud",
	"206" => "Gedeeltelijke inhoud",
	"301" => "Permanent verplaatst",
	"302" => "Verwijzen",
	"304" => "Niet veranderd",
	"400" => "Verkeerd syntax",
	"401" => "Niet geautoriseerd",
	"402" => "Niet in gebruik",
	"403" => "Verboden",
	"404" => "Bestand niet gevonden",
	"405" => "Methode niet toegestaan",
	"406" => "Niet acceptabel",
	"407" => "Proxy-autorisatie vereist",
	"408" => "Timeout voor dit verzoek",
	"500" => "Interne Server Fout",
	"501" => "Niet geimplemeteerd",
	"502" => "Server Overbelast",
	"503" => "Gateway Timeout",
);
//SCRIPT CONFIG
if(isset($_GET["config"])){
	$config_domain = $_GET["config"];
	$config_link = "?config=www.".$_GET["config"];
}

//READ CONFIG
$awstats_text = file_get_contents($awstat_path."/awstats".date("mY").".".$config_domain.".txt");

//FUNCTIONS
function os($name){
	global $os_array;
	$array = array_flip($os_array);
	if(in_array($name,$array)){
		return $os_array[$name];
	}else{
		return ucfirst($name);
	}
}

function file_size($size,$wat = true) {
    $bytes = array("B", "KB", "MB", "GB", "TB", "PB");
    $i = 0;
    while ($size >= 1024) {
        $size = $size/1024;
        $i++;
    }
    if ($i > 1) {
		if($wat == true){$extra = "&nbsp;".$bytes[$i];}else{$extra = NULL;}
        return round($size,2).$extra;
    } else {
		if($wat == true){$extra = "&nbsp;".$bytes[$i];}else{$extra = NULL;}
        return round($size,0).$extra;
    }
}

function bot($name){
	global $bot_array;
	$array = array_flip($bot_array);
	if(in_array($name,$array)){
		return "<a href=\"".$bot_array[$name]."\">".ucfirst($name)."</a>";
	}else{
		return ucfirst($name);
	}
}

function read_section($section) {
	global $awstats_text;
	if (preg_match('/\nBEGIN_'.$section.' \d+\n(.*)\nEND_'.$section.'\n/s', $awstats_text, $match)) {
		foreach (explode("\n", $match[1]) as $row) 
			$lines[] = split(' ', trim($row));
	}
	return $lines;
}
if (!function_exists('is_even')) {
	function is_even($getal){
		$iNum = ($getal / 2);
		$aNum = explode('.', $iNum); 
		if($aNum[1] == 5){
			return FALSE;
		}else{
			return TRUE;
		}
	} 
}

function procent($hits,$tot_hits){
	$deel = $hits / $tot_hits;
	return round($deel * 100,1);
}
?>
