<?php

//hmm - this isn't working the way I want yet...

$file = __FILE__;
include ("../inc/inc_common.php");
include ("../inc/inc_connect.php");
include ("../inc/inc_admincheck.php");
if ($cAdminLevel < 6)
{
    exit;
}

include ("../inc/inc_getdate.php");
include ("../inc/inc_forumname.php");
$page = "Admin - Referrer Stats";
$pagelink = $file;
include("../inc/inc_setonline.php");
$title = "$name1 Admin - $gfcookie[1]";
include ("../inc/inc_head.php");
include ("../inc/inc_body.php");
$title = "Referrers";
include ("../inc/inc_title.php");

print "<font size=$fontsizeb><br><center>";
$counter = 1;
$oldref = "12345";
$bg = 1;

$result=mysql_query("SELECT * FROM $statstable ORDER BY strRefer");
$num_rows = mysql_num_rows( $result );
print "<b>$num_rows referrals are held on the system.</b><br><br><font size=$fontsize><br><br><table border=1 cellpadding=5 cellspacing=0 style=\"border-collapse: collapse\" bordercolor=\"$bordercolor\" style=\"font-family: $font; font-size: $fontpoint\" bgcolor=\"$fgcolour\">";

if (!isset($detail))
{
    while ( $a_row = mysql_fetch_object( $result ) )
    {
        $ref = explode(".", $a_row->strRefer);
        $lastref = explode("/", $ref[2]);
        $refa = "$ref[0].$ref[1].$lastref[0]";
        if ($refa == "..")
        {
            continue;
        }
        /*
        if ($oldref == "12345")
        {
            $oldref = $refa;
            continue;
        }

        if ($refa == $oldref)
        {
            $counter ++;
            $oldref = $refa;
            continue;
        } */
        if ($bg == 1)
        {
            print "<tr><td>$refa</td><td>$counter Referrals</td><td><a href=\"admin_stats_ref.php?detail=$refa\">Details</a></td></tr>";
            $bg = 0;
        }
        else
        {
            print "<tr bgcolor=\"$afgcolour\"><td>$refa</td><td>$counter Referrals</td><td><a href=\"admin_stats_ref.php?detail=$refa\">Details</a></td></tr>";
            $bg = 1;
        }

       // $counter = 1;
       // $oldref = $refa;
    }
    /* if ($counter < 1)
    {
        print "<tr><td>$refa</td><td>$counter Referrals</td><td><a href=\"admin_stats_ref.php?detail=$refa\">Details</a></td></tr>";
    } */
    print "</table>";
}
else
{
    while ( $a_row = mysql_fetch_object( $result ) )
    {
        $ref = explode(".", $a_row->strRefer);
        $lastref = explode("/", $ref[2]);
        $refa = "$ref[0].$ref[1].$lastref[0]";
        if ($refa != $detail)
        {
            continue;
        }

        if ($a_row->strRefer == "$olda")
        {
            $counter ++;
            $olda = $a_row->strRefer;
            continue;
        }

        if ($bg == 1)
        {
            print "<tr><td><a href=\"$a_row->strRefer\" target=\"_blank\">$a_row->strRefer</a></td><td>$counter Referrals</td></tr>";
            $bg = 0;
        }
        else
        {
            print "<tr bgcolor=\"$afgcolour\"><td><a href=\"$a_row->strRefer\" target=\"_blank\">$a_row->strRefer</a></td><td>$counter Referrals</td></tr>";
            $bg = 1;
        }


        $counter = 1;
    }

    if ($counter > 1)
    {
        print "<tr><td><a href=\"$a_row->strRefer\" target=\"_blank\">$a_row->strRefer</a></td><td>$counter Referrals</td></tr>";
    }
    print "</table><br><a href=\"admin_stats_ref.php\">Go back to the list of Referrers</a>";
}

include ("../inc/inc_footer.php");

?>