<?php
$z = "b";
include ("../config.php");
if (((($_GET['load'] == "help") or ($_GET['load'] == "chat") or ($_GET['load'] == "login") or ($_GET['load'] == "logout")))) {
if (($_GET['load'] == "help") && ($_GET['id'] == "list3")) {
eval (" ?>" . admin_header() . " <?php ");
}
} else {
eval (" ?>" . admin_header() . " <?php ");
echo '<SCRIPT LANGUAGE="JavaScript">var checkflag = "false";function check(field) {if (checkflag == "false") {for (i = 0; i < field.length; i++) {field[i].checked = true;}checkflag = "true";return "Uncheck All"; }else {for (i = 0; i < field.length; i++) {field[i].checked = false; }checkflag = "false";return "Check All"; }}</script>';
}
if ($ipbancheck3 == "0") {if ($numv == "0"){
	if ($warn == $naum) {
	echo "Looks Like Everything Checks Out, Go Ahea....Wait, You Don't Have Access to the Admin Panel!";
} else {

if(!isset($_GET['page'])){
    $page = 1;
} else {
    $page = $_GET['page'];
}
}
}
}

$from = (($page * $setting[max_results]) - $setting[max_results]);
$admin_page = "yes";
if(!isset($_GET['page2'])){
    $page2 = 1;
} else {
    $page2 = $_GET['page2'];
}
$from2 = (($page2 * $setting[max_results]) - $setting[max_results]);

if(!isset($_GET['page3'])){
    $page3 = 1;
} else {
    $page3 = $_GET['page3'];
}
$from3 = (($page3 * $setting[max_results]) - $setting[max_results]);

if(!isset($_GET['page4'])){
    $page4 = 1;
} else {
    $page4 = $_GET['page4'];
}
$from4 = (($page4 * $setting[max_results]) - $setting[max_results]);

if(!isset($_GET['page5'])){
    $page5 = 1;
} else {
    $page5 = $_GET['page5'];
}
$from5 = (($page5 * $setting[max_results]) - $setting[max_results]);

if(!isset($_GET['page6'])){
    $page6 = 1;
} else {
    $page6 = $_GET['page6'];
}
$from6 = (($page6 * $setting[max_results]) - $setting[max_results]);

if(!isset($_GET['page7'])){
    $page7 = 1;
} else {
    $page7 = $_GET['page7'];
}
$from7 = (($page7 * $setting[max_results]) - $setting[max_results]);

if(!isset($_GET['page8'])){
    $page8 = 1;
} else {
    $page8 = $_GET['page8'];
}
$from8 = (($page8 * $setting[max_results]) - $setting[max_results]);

if ($userlevel > "3") {
echo "Sorry ".$_COOKIE[$pre."username"].", but you do not have permission to view this page. You are only a $level.";
} else {

if ($_GET['view'] == "all") {
echo "<title>OneCMS - www.onecms.net > Stats</title>";
echo "<center><a href='stats.php?load=stats'><b>Specific Stats</b></a> <a href='#1'>*</a> | <a href='stats.php?load=stats&view=adv'><b>Advanced Stats</b></a> <a href='#2'>*</a></center>";
}
}

if ($_GET['view'] == "adv") {
echo "<center><a href='stats.php?load=stats'><b>Specific Stats</b></a> <a href='#1'>*</a> | <a href='#'><b>Advanced Stats</b></a> <a href='#2'>*</a></center><br><form action='stats.php?load=stats&view=adv' method='get'><center><input type='hidden' name='load' value='stats'><input type='hidden' name='view' value='adv'><b>Check:</b>&nbsp;<select name='day'>";
for($i = 1; $i <= 31; $i++){
if ($i < "10") {
$y = "0".$i;
} else {
$y = $i;
}
echo "<option value='".$y."'";
if ($_GET['day'] == $y) {
echo " selected";
} else {
if ($y == date("d")) {
echo " selected";
}
}
echo ">".$y."</option>";
}
echo "</select>&nbsp;<select name='month'><option value='01'";
if (date("F") == "January") {
echo " selected";
}
echo ">January</option><option value='02'";
if (date("F") == "February") {
echo " selected";
}
echo ">February</option><option value='03'";
if (date("F") == "March") {
echo " selected";
}
echo ">March</option><option value='04'";
if (date("F") == "April") {
echo " selected";
}
echo ">April</option><option value='05'";
if (date("F") == "May") {
echo " selected";
}
echo ">May</option><option value='06'";
if (date("F") == "June") {
echo " selected";
}
echo ">June</option><option value='07'";
if (date("F") == "July") {
echo " selected";
}
echo ">July</option><option value='08'";
if (date("F") == "August") {
echo " selected";
}
echo ">August</option><option value='09'";
if (date("F") == "September") {
echo " selected";
}
echo ">September</option><option value='10'";
if (date("F") == "October") {
echo " selected";
}
echo ">October</option><option value='11'";
if (date("F") == "November") {
echo " selected";
}
echo ">November</option><option value='12'";
if (date("F") == "December") {
echo " selected";
}
echo ">December</option></select>&nbsp;<select name='year'>";
for($i = 2006; $i <= 2020; $i++){
echo "<option value='".$i."'";
if ($i == date("Y")) {
echo " selected";
}
echo ">".$i."</option>";
}
echo "</select>&nbsp;&nbsp;<input type='submit' value='Search'></form></center><br />";

if (date("m") == "01") {
$lmonth = "12";
$lyear = date("Y") -1;
} else {
$lmonth = date("m") - 1;
$lyear = date("Y");
}

if (date("W") == "01") {
$lweek = "52";
} else {
$lweek = date("W") - 1;
}

if (date("z") == "0") {
if (date("L") == "1") {
$lday = "366";
} else {
$lday = "365";
}
$lyear = date("Y") -1;
} else {
$lday = date("z") - 1;
$lyear = date("Y");
}

if ($lweek < "10") {
$lweek = "0".$lweek;
} else {
$lweek = $lweek;
}

if ($lmonth < "10") {
$lmonth = "0".$lmonth;
} else {
$lmonth = $lmonth;
}

if ($_GET['year']) {
$views = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."stats WHERE type = 'view' AND year = '".$_GET['year']."' AND month = '".$_GET['month']."' AND day = '".$_GET['day']."'"));
$uniques = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."stats WHERE type = 'unique' AND year = '".$_GET['year']."' AND month = '".$_GET['month']."' AND day = '".$_GET['day']."'"));
echo "<table cellspacing='0' cellpadding='3' border='0' align='left'><tr><td><b>Unique Visitors:</b> ".$uniques."<br /><b>Views:</b> ".$views."<br /><br /><br /></td></tr>";
$var[] = "";
$var2[] = "";
$var3[] = "";

$sql = mysql_query("SELECT * FROM ".$pre."stats WHERE year = '".$_GET['year']."' AND month = '".$_GET['month']."' AND day = '".$_GET['day']."' AND type = 'unique'");
while($r = mysql_fetch_array($sql)) {
$ex = explode("|", $r[info]);

$tvar1[] .= $ex[0];
$tvar2[] .= $ex[1];
if ($r[referral]) {
$tvar3[] .= $r[referral];
}
$avar .= $ex[0];
$bvar .= $ex[1];
if ($r[referral]) {
$cvar .= $r[referral];
}

if (array_search($ex[0], $var)) {
} else {
if ($ex[0] == " ") {
} else {
$var[] .= $ex[0];
}
}
if (array_search($ex[1], $var2)) {
} else {
if ($ex[1] == " ") {
} else {
$var2[] .= $ex[1];
}
}
if (array_search($r[referral], $var3)) {
} else {
if ($r[referral] == " ") {
} else {
$var3[] .= $r[referral];
}
}
}
$total1 = count($tvar1);
$total2 = count($tvar2);
$total3 = count($tvar3);
$count1 = count($var);
$count2 = count($var2);
$count3 = count($var3);
sort($var);
sort($var2);
sort($var3);
echo "<tr><td><b>Operating Systems:</b><br />";

while (list($i) = each($var)) {
if (strlen($var[$i]) < "5") {
$char = " ";
foreach(count_chars($avar, 1) as $chr => $hit) {
$tcount = $hit;
}
} else {
$tcount = substr_count($avar, $var[$i]);
}
if (($tcount == "0") && ($total1 == "0")) {
$total_1 = "0";
} else {
@$total_1 = $tcount / $total1;
}
$total_1 = substr($total_1, 2, 2);
$total_1 = round($total_1, 1);

if ($total_1{0} == "0") {
$total_1 = str_replace("0", "", $total_1);
}

if (strlen($total_1) == "3") {
$total_1 = substr($total_1, 0, 2);
}

if (strlen($var[$i]) < "5") {
echo "Unknown ($total_1%)<br />";
} else {
echo $var[$i]." ($total_1%)<br />";
}
}
echo "<br /></td></tr><tr><td><b>Browsers:</b><br />";
while (list($ia) = each($var2)) {
if (strlen($var2[$ia]) < "5") {
$char = " ";
foreach(count_chars($bvar, 1) as $chr => $hit) {
$tcount2 = $hit;
}
} else {
$tcount2 = substr_count($bvar, $var2[$ia]);
}
if (($tcount2 == "0") && ($total2 == "0")) {
$total_2 = "0";
} else {
@$total_2 = $tcount2 / $total2;
}
$total_2 = substr($total_2, 2, 2);
$total_2 = round($total_2, 1);

if ($total_2{0} == "0") {
$total_2 = str_replace("0", "", $total_2);
}

if (strlen($total_2) == "3") {
$total_2 = substr($total_2, 0, 2);
}

if (strlen($var2[$ia]) < "5") {
echo "Unknown ($total_2%)<br />";
} else {
echo $var2[$ia]." ($total_2%)<br />";
}
}
echo "</td><br /></td></tr><tr><td><b>Referrals:</b><br />";
while (list($ic) = each($var3)) {
if ($var3[$ic] == "") {
} else {
if (strlen($var3[$ic]) < "5") {
$char = " ";
foreach(count_chars($cvar, 1) as $chr => $hit) {
$tcount3 = $hit;
}
} else {
$tcount3 = substr_count($cvar, $var3[$ic]);
}
if (($tcount3 == "0") && ($total3 == "0")) {
$total_3 = "0";
} else {
$total_3 = $tcount3 / $total3;
}
$total_3 = substr($total_3, 2, 2);
$total_3 = round($total_3, 1);

if ($total_3{0} == "0") {
$total_3 = str_replace("0", "", $total_3);
}

if (strlen($total_3) == "3") {
$total_3 = substr($total_3, 0, 2);
}

if (strlen($var3[$ic]) < "5") {
echo "Unknown ($total_3%)<br />";
} else {
echo "<a href='".$var3[$ic]."'>";
if (strlen($var3[$ic]) > 70) {
echo substr($var3[$ic], 0, 67)."...";
} else {
echo substr($var3[$ic], 0, 70);
}
echo " ($total_3%/$tcount3)<br />";
}
}
}
echo "</tr></table>";
} else {
$views = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."stats WHERE type = 'view'"));
$uniques = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."stats WHERE type = 'unique'"));
$viewsa9 = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."stats WHERE type = 'view' AND year = '".date("Y")."'"));
$uniquesa9 = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."stats WHERE type = 'unique' AND year = '".date("Y")."'"));

$viewsb9 = mysql_fetch_row(mysql_query("SELECT tday FROM ".$pre."stats WHERE type = 'view' AND year = '".date("Y")."' ORDER BY `id` DESC LIMIT 1"));
$viewsc9 = mysql_fetch_row(mysql_query("SELECT tday FROM ".$pre."stats WHERE type = 'view' ORDER BY `id` ASC LIMIT 1"));

$uniquesb9 = mysql_fetch_row(mysql_query("SELECT tday FROM ".$pre."stats WHERE type = 'unique' AND year = '".date("Y")."' ORDER BY `id` DESC LIMIT 1"));
$uniquesc9 = mysql_fetch_row(mysql_query("SELECT tday FROM ".$pre."stats WHERE type = 'unique' AND year = '".date("Y")."' ORDER BY `id` ASC LIMIT 1"));//total/avg this year
$abcv9 = $viewsb9[0] - $viewsc9[0] + 1;
$abcu9 = $uniquesb9[0] - $uniquesc9[0] + 1;
$views9 = $viewsa9 / $abcv9;
$uniques9 = $uniquesa9 / $abcu9;

$views1 = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."stats WHERE type = 'view' AND day = '".date("d")."' AND month = '".date("m")."' AND week = '".date("W")."' AND year = '".date("Y")."'"));
$uniques1 = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."stats WHERE type = 'unique' AND day = '".date("d")."' AND month = '".date("m")."' AND week = '".date("W")."' AND year = '".date("Y")."'"));
$views8 = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."stats WHERE type = 'view' AND tday = '".$lday."' AND year = '".$lyear."'"));
$uniques8 = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."stats WHERE type = 'unique' AND tday = '".$lday."' AND year = '".$lyear."'"));//today/yesterday

$views2 = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."stats WHERE type = 'view' AND week = '".date("W")."' AND year = '".date("Y")."'"));
$uniques2 = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."stats WHERE type = 'unique' AND week = '".date("W")."' AND year = '".date("Y")."'"));
$views7 = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."stats WHERE type = 'view' AND week = '".$lweek."' AND year = '".$lyear."'"));
$uniques7 = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."stats WHERE type = 'unique' AND week = '".$lweek."' AND year = '".$lyear."'"));//week

$views3 = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."stats WHERE type = 'view' AND month = '".date("m")."' AND year = '".date("Y")."'"));
$uniques3 = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."stats WHERE type = 'unique' AND month = '".date("m")."' AND year = '".date("Y")."'"));
$lmonths = $lmonth - 1;
$views4 = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."stats WHERE type = 'view' AND month = '".$lmonth."' AND year = '".$lyear."'"));
if ($views4 == 0) {
$lyears = $lyear - 1;
$views4 = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."stats WHERE type = 'view' AND month = '".$lmonths."' AND year = '".$lyears."'"));
}
$uniques4 = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."stats WHERE type = 'unique' AND month = '".$lmonth."' AND year = '".$lyear."'"));//month
if ($uniques4 == 0) {
$lyears = $lyear - 1;
$uniques4 = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."stats WHERE type = 'unique' AND month = '".$lmonths."' AND year = '".$lyears."'"));
}

$views5 = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."stats WHERE type = 'view' AND year = '".date("Y")."'"));
$uniques5 = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."stats WHERE type = 'unique' AND year = '".date("Y")."'"));
$lyear = $lyear - 1;
$views6 = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."stats WHERE type = 'view' AND year = '".$lyear."'"));
$uniques6 = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."stats WHERE type = 'unique' AND year = '".$lyear."'"));//year

echo "<SCRIPT LANGUAGE='JavaScript'>
function donline () {
alert ('Days site has been online - ".$abcv9."');
}
</SCRIPT>";

echo "<table cellspacing='0' cellpadding='0' border='0' align='center' width='98%'><tr><td>&nbsp;</td><td><b>Uniques</b></td><td><b>Views</b></td></tr>
<tr><td><b>Average:</b></td><td>".$uniques9."</td><td>".$views9."</td></tr>	
<tr><td><b>Today:</b></td><td>".$uniques1."</td><td>".$views1."</td></tr>
<tr><td><b>Yesterday:</b></td><td>".$uniques8."</td><td>".$views8."</td></tr>

<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>

<tr><td><b>This Week:</b></td><td>".$uniques2."</td><td>".$views2."</td></tr>
<tr><td><b>This Month:</b></td><td>".$uniques3."</td><td>".$views3."</td></tr>
<tr><td><b>Last Week:</b></td><td>".$uniques7."</td><td>".$views7."</td></tr>
<tr><td><b>Last Month:</b></td><td>".$uniques4."</td><td>".$views4."</td></tr>

<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>

<tr><td><b>Total:</b></td><td><a href='javascript:donline()'>".$uniques."</a></td><td><a href='javascript:donline()'>".$views."</a></td></tr>
<tr><td><b>This Year:</b></td><td>".$uniques5."</td><td>".$views5."</td></tr>
<tr><td><b>Last Year:</b></td><td>".$uniques6."</td><td>".$views6."</td></tr></table><br /><br />";
}
}

if ($_GET['view'] == "") {
echo "<title>OneCMS - www.onecms.net/onecms > Statistics 2.5</title><center><a href='#'><b>Specific Stats</b></a> <a href='#1'>*</a> | <a href='stats.php?load=stats&view=adv'><b>Advanced Stats</b></a> <a href='#2'>*</a></center><br><br><center><a href='#content'>Content</a> | <a href='#games'>Game</a> | <a href='#cat'>Categories</a> | <a href='#system'>Systems</a> | <a href='#af'>Affiliates</a> | <a href='#forums'>Forum</a> | <a href='#gallery'>Galleries</a> | <a href='#ads'>Ads</a><br><a href='#total'><b>Total Stats</b></a></center><br><br>";

	echo "<a name='content'><center><u>Content Stats</u></center><br><br><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>Name of Article</b></td><td><b>Views</b></td><td><b>Writer</b></td></tr>";

	$tstat = "0";

	$query="SELECT * FROM ".$pre."content ORDER BY `id` DESC LIMIT $from, $setting[max_results]";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
	$name = stripslashes($row[name]);
    $stats = "$row[stats]";

	$tstat = $stats + $tstat;

	echo "<tr><td><a href='".$part1.$row[id].fthrough($row[name], $row[cat]).$part2."'>$name</a></td><td>$stats</td><td><a href='".$elite1.$row[username].$elite2."'>".$row[username]."</a></td></tr>";

	}
	
	echo "</table><br>";

	$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM ".$pre."content"),0);

$total_pages = ceil($total_results / $setting[max_results]);
if ($total_pages > 1) {
echo "<center>";

// Build Previous Link
if($page > 1){
    $prev = ($page - 1);
    echo "<a href=\"stats.php?load=stats&page=$prev#content\"><<Previous</a>&nbsp;";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
        echo "$i&nbsp;";
        } else {
            echo "<a href=\"stats.php?load=stats&page=$i#content\">$i</a>&nbsp;";if (($i/25) == (int)($i/25)) {echo "<br>";}
    }
}

// Build Next Link
if($page < $total_pages){
    $next = ($page + 1);
    echo "<a href=\"stats.php?load=stats&page=$next#content\">Next>></a>";
}
echo "</center>";
}

	echo "<br><a name='forums'><center><u>Forum Stats</u></center><br><br><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>Subject</b></td><td><b>Views</b></td></tr>";

	$query="SELECT * FROM ".$pre."posts ORDER BY `id` DESC LIMIT $from5, $setting[max_results]";
	$result=mysql_query($query);
	while($r = mysql_fetch_array($result)) {
	
	$tstat = $r[stats] + $tstat;

    echo "<tr><td><a href='".$f2part1.$r[tid].$f2part2;
    
    if ($r[type] == "post") {
    echo "#".$r[id];
    }
    echo "'>".stripslashes($r[subject])."</a></td><td>".$r[stats]."</td></tr>";

	}
	
	echo "</table><br>";
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM ".$pre."posts"),0);

$total_pages = ceil($total_results / $setting[max_results]);
if ($total_pages > 1) {
echo "<center>";

// Build Previous Link
if($page5 > 1){
    $prev = ($page5 - 1);
    echo "<a href=\"stats.php?load=stats&page5=$prev#forums\"><<Previous</a>&nbsp;";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page5) == $i){
        echo "$i&nbsp;";
        } else {
            echo "<a href=\"stats.php?load=stats&page5=$i#forums\">$i</a>&nbsp;";if (($i/25) == (int)($i/25)) {echo "<br>";}
    }
}

// Build Next Link
if($page5 < $total_pages){
    $next = ($page5 + 1);
    echo "<a href=\"stats.php?load=stats&page5=$next#forums\">Next>></a>";
}
echo "</center>";
}

	echo "<br><a name='games'><center><u>Game Stats</u></center><br><br><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>Name of Game</b></td><td><b>Views</b></td></tr>";

	$query="SELECT * FROM ".$pre."games ORDER BY `id` DESC LIMIT $from2, $setting[max_results]";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
	$name = stripslashes($row[name]);

	$tstat = $row[stats] + $tstat;
    echo "<tr><td><a href='".$gamepart1.$row[id].fthrough($row[name], "").$gamepart2."'>$name</a></td><td>".$row[stats]."</td></tr>";

	}
	
	echo "</table><br>";
	$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM ".$pre."games"),0);

$total_pages = ceil($total_results / $setting[max_results]);
if ($total_pages > 1) {
echo "<center>";

// Build Previous Link
if($page2 > 1){
    $prev = ($page2 - 1);
    echo "<a href=\"stats.php?load=stats&page2=$prev#games\"><<Previous</a>&nbsp;";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page2) == $i){
        echo "$i&nbsp;";
        } else {
            echo "<a href=\"stats.php?load=stats&page2=$i#games\">$i</a>&nbsp;";if (($i/25) == (int)($i/25)) {echo "<br>";}
    }
}

// Build Next Link
if($page2 < $total_pages){
    $next = ($page2 + 1);
    echo "<a href=\"stats.php?load=stats&page2=$next#games\">Next>></a>";
}
echo "</center>";
}

	echo "<br><a name='af'><center><u>Affiliate Stats</u></center><br><br><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>Site Name</b></td><td><b>Clicks</b></td></tr>";

	$query="SELECT * FROM ".$pre."af WHERE verified = 'yes' ORDER BY `id` DESC LIMIT $from6, $setting[max_results]";
	$result=mysql_query($query);
	while($r = mysql_fetch_array($result)) {

    echo "<tr><td><a href='af.php?view=click&id=".$r[id]."'>".$r[sitename]."</a></td><td>".$r[clicks]."</td></tr>";

	}
	
	echo "</table><br>";
	$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM ".$pre."af"),0);

$total_pages = ceil($total_results / $setting[max_results]);
if ($total_pages > 1) {
echo "<center>";

// Build Previous Link
if($page6 > 1){
    $prev = ($page6 - 1);
    echo "<a href=\"stats.php?load=stats&page6=$prev#af\"><<Previous</a>&nbsp;";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page6) == $i){
        echo "$i&nbsp;";
        } else {
            echo "<a href=\"stats.php?load=stats&page6=$i#af\">$i</a>&nbsp;";if (($i/25) == (int)($i/25)) {echo "<br>";}
    }
}

// Build Next Link
if($page6 < $total_pages){
    $next = ($page6 + 1);
    echo "<a href=\"stats.php?load=stats&page6=$next#af\">Next>></a>";
}
echo "</center>";
}

	echo "<br><a name='cat'><center><u>Category Stats</u></center><br><br><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>Name of Category</b></td><td><b>Views</b></td></tr>";

	$query="SELECT * FROM ".$pre."cat ORDER BY `id` DESC LIMIT $from3, $setting[max_results]";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
	$name = stripslashes($row[name]);

    $viewsb = mysql_fetch_array(mysql_query("SELECT SUM(stats) AS stats FROM ".$pre."content WHERE cat = '".$name."'"));
	if ($viewsb[0]) {
	$views = $viewsb[0];
	} else {
	$views = "0";
	}

	$tstat = $views + $tstat;

	echo "<tr><td><a href='".$cpart1.$name.$cpart2."'>".$name."</a></td><td>".$views."</td></tr>";

	}
	
	echo "</table><br>";
	$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM ".$pre."cat"),0);

$total_pages = ceil($total_results / $setting[max_results]);
if ($total_pages > 1) {
echo "<center>";

// Build Previous Link
if($page3 > 1){
    $prev = ($page3 - 1);
    echo "<a href=\"stats.php?load=stats&page3=$prev#cat\"><<Previous</a>&nbsp;";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page3) == $i){
        echo "$i&nbsp;";
        } else {
            echo "<a href=\"stats.php?load=stats&page3=$i#cat\">$i</a>&nbsp;";if (($i/25) == (int)($i/25)) {echo "<br>";}
    }
}

// Build Next Link
if($page3 < $total_pages){
    $next = ($page3 + 1);
    echo "<a href=\"stats.php?load=stats&page3=$next#cat\">Next>></a>";
}
echo "</center>";
}

	echo "<br><a name='system'><center><u>System Stats</u></center><br><br><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>Name of Systems</b></td><td><b>Views</b></td></tr>";

	$query="SELECT * FROM ".$pre."systems ORDER BY `id` DESC LIMIT $from4, $setting[max_results]";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
	$id = "$row[id]";
    $name = stripslashes($row[name]);

    $viewsb = mysql_fetch_array(mysql_query("SELECT SUM(stats) AS stats FROM ".$pre."content WHERE systems = '".$id."'"));
	if ($viewsb[0]) {
	$views = $viewsb[0];
	} else {
	$views = "0";
	}

	$tstat = $views + $tstat;

	echo "<tr><td><a href='index.php?load=systems&sid=".$row[abr]."'>".$name."</a></td><td>".$views."</td></tr>";

	}
	
	echo "</table><br>";
	$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM ".$pre."systems"),0);

$total_pages = ceil($total_results / $setting[max_results]);
if ($total_pages > 1) {
echo "<center>";

// Build Previous Link
if($page4 > 1){
    $prev = ($page4 - 1);
    echo "<a href=\"stats.php?load=stats&page4=$prev#system\"><<Previous</a>&nbsp;";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page4) == $i){
        echo "$i&nbsp;";
        } else {
            echo "<a href=\"stats.php?load=stats&page4=$i#system\">$i</a>&nbsp;";if (($i/25) == (int)($i/25)) {echo "<br>";}
    }
}

// Build Next Link
if($page4 < $total_pages){
    $next = ($page4 + 1);
    echo "<a href=\"stats.php?load=stats&page4=$next#system\">Next>></a>";
}
echo "</center>";
}

	echo "<br><a name='gallery'><center><u>Gallery Stats</u></center><br><br><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>Gallery Name</b></td><td><b>Views</b></td></tr>";

	$query="SELECT * FROM ".$pre."albums ORDER BY `id` DESC LIMIT $from7, $setting[max_results]";
	$result=mysql_query($query);
	while($r = mysql_fetch_array($result)) {

	$tstat = $r[views] + $tstat;
    echo "<tr><td><a href='".$gpart1.$r[id].fthrough($r[name], "").$gpart2."'>".$r[name]."</a></td><td>".$r[views]."</td></tr>";

	}
	
	echo "</table><br>";
	$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM ".$pre."albums"),0);

$total_pages = ceil($total_results / $setting[max_results]);
if ($total_pages > 1) {
echo "<center>";

// Build Previous Link
if($page7 > 1){
    $prev = ($page7 - 1);
    echo "<a href=\"stats.php?load=stats&page=$prev#gallery\"><<Previous</a>&nbsp;";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page7) == $i){
        echo "$i&nbsp;";
        } else {
            echo "<a href=\"stats.php?load=stats&page7=$i#gallery\">$i</a>&nbsp;";if (($i/25) == (int)($i/25)) {echo "<br>";}
    }
}

// Build Next Link
if($page7 < $total_pages){
    $next = ($page7 + 1);
    echo "<a href=\"stats.php?load=stats&page7=$next#gallery\">Next>></a>";
}
echo "</center>";
}

	echo "<br><a name='ads'><center><u>Ad Stats</u></center><br><br><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><b>Name</b></td><td><b>Views</b></td></tr>";

	$query="SELECT * FROM ".$pre."ad ORDER BY `id` DESC LIMIT $from8, $setting[max_results]";
	$result=mysql_query($query);
	while($r = mysql_fetch_array($result)) {

    echo "<tr><td>".$r[name]." (".$r[type].")</td><td>".$r[views]."</td></tr>";

	}
	
	echo "</table><br>";
	$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM ".$pre."ad"),0);

$total_pages = ceil($total_results / $setting[max_results]);
if ($total_pages > 1) {
echo "<center>";

// Build Previous Link
if($page8 > 1){
    $prev = ($page8 - 1);
    echo "<a href=\"stats.php?load=stats&page8=$prev#ads\"><<Previous</a>&nbsp;";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page8) == $i){
        echo "$i&nbsp;";
        } else {
            echo "<a href=\"stats.php?load=stats&page8=$i#ads\">$i</a>&nbsp;";if (($i/25) == (int)($i/25)) {echo "<br>";}
    }
}

// Build Next Link
if($page8 < $total_pages){
    $next = ($page8 + 1);
    echo "<a href=\"stats.php?load=stats&page8=$next#ads\">Next>></a>";
}
}
echo "<br><br><a name='total'><b>Total Stats:</b> ".$tstat."</center>";
}

echo "<br><br><br><br><a name='1'></a><small>&nbsp;Specific Stats = Category stats, games, content (all views)</small><br><a name='2'></a><small>&nbsp;Advanced Stats = OS/Browser stats (uniques and views), Uniques and views tracked and viewable by a day-to-day basis</small>";
if (($_GET['load'] == "help") or ($_GET['load'] == "chat")) {
if (($_GET['load'] == "help") && ($_GET['id'] == "list3")) {
eval (" ?>" . admin_footer() . " <?php ");
}
} else {
eval (" ?>" . admin_footer() . " <?php ");
}
?>