<?php
$admin = 2;
$file = __FILE__;
include ("../inc/inc_common.php");
include ("../inc/inc_connect.php");
include ("../inc/inc_admincheck.php");
include ("../inc/inc_getdate.php");
include ("../inc/inc_forumname.php");
$page = "Admin - User Tracking";
$pagelink = $file;
include("../inc/inc_setonline.php");
$title = "$name1 Admin - $gfcookie[1]";
include ("../inc/inc_head.php");
include ("../inc/inc_body.php");
$title = "User Tracking";
include ("../inc/inc_title.php");

if ($action == "delete")
{
    $query = "DELETE FROM $statstable WHERE intId != '0'";
    mysql_query( $query, $link ) or die ( "Error! : ".mysql_error() );
}

if ($action == "delone")
{
    $query = "DELETE FROM $statstable WHERE intId = '$id'";
    mysql_query( $query, $link ) or die ( "Error! : ".mysql_error() );
    $action = $subaction;
}
print "<font size=$fontsizeb><br><center>";

$result=mysql_query("SELECT * FROM $statstable");
$num_rows = mysql_num_rows( $result );
print "<b>$num_rows records are held on the system.</b><br><br>
<font size=$fontsize>
<a href=\"admin_stats_user.php?action=delete\">Wipe All Statistics From The Database</a><br><br>
<a href=\"admin_stats_user.php?action=five\">Show All Users Online In The Last Five Minutes</a><br><br>
<a href=\"admin_stats_user.php?action=30\">Show All Users Online In The Last Half Hour</a><br><br>
<a href=\"admin_stats_user.php?action=ever\">Show All Users Online Ever</a><br><br>
<a href=\"admin_stats_user.php?action=alllast\">Show All Users Last Viewed Page</a><br><br>
<form method=\"post\" action=\"admin_stats_user.php?action=track\">Track user &nbsp;<select name=\"userid\" size=\"1\"><option value=\"Not Logged In\" selected>Guests</option>";
$result=mysql_query("SELECT * FROM $userstable ORDER BY strName");
$num_rows = mysql_num_rows( $result );
while ( $a_row = mysql_fetch_object( $result ) )
{
    print "<option>$a_row->strName</option>/n";
}
print "</select>&nbsp; <input type=\"submit\" value=\"Track\"></form>";

if ($action == "track")
{
    $result=mysql_query("SELECT * FROM $statstable WHERE strName = '$userid' ORDER BY intId DESC");
}
if ($action == "alllast")
{
    $result=mysql_query("SELECT * FROM $statstable ORDER BY strName, intId DESC");
}
if ($action == "five")
{
    $now = $epoch - 301;
    $result=mysql_query("SELECT * FROM $statstable WHERE intEpochTime > '$now' AND intEpochTime < '$epoch' ORDER BY intId DESC");
}
if ($action == "30")
{
    $now = $epoch - 1801;
    $result=mysql_query("SELECT * FROM $statstable WHERE intEpochTime > '$now' AND intEpochTime < '$epoch' ORDER BY intId DESC");
}
if ($action == "ever")
{
    $result=mysql_query("SELECT * FROM $statstable ORDER BY intId DESC");
}

$num_rows = mysql_num_rows( $result );

if (isset($action) AND $action !="alllast" and $action !="delete" and $action != "delone")
{
    print "<font size=$fontsizeb><b>$num_rows records have been returned.</b><br><br><font size=$fontsize>";
}


if (isset($action) AND $action != "delete")
{
    print "<table border=1 cellpadding=0 cellspacing=0 style=\"border-collapse: collapse\" bordercolor=\"$bordercolor\" width=90% style=\"font-family: $font; font-size: $fontpoint\" bgcolor=\"$fgcolour\"><tr><td align=\"center\"><table border=1 cellpadding=3 cellspacing=0 style=\"border-collapse: collapse\" bordercolor=\"$afgcolour\" width=100% style=\"font-family: $font; font-size: $fontpoint\" bgcolor=\"$fgcolour\"><tr>
    <td align=\"center\"><b>Delete</td>
    <td align=\"center\"><b>Username</td>
    <td align=\"center\"><b>Viewing Page</td>
    <td align=\"center\"><b>Time</td>
    <td align=\"center\"><b>Date</td>
    <td align=\"center\"><b>Referred From</td>
    <td align=\"center\"><b>IP</td>";

//  print "<td align=\"center\"><b>Epoch</td><td align=\"center\"><b>Now</td>";


    print "</tr>";
}



while ( $a_row = mysql_fetch_object( $result ) )
{
    $poch = substr($a_row->intEpochTime, -4);
    $snow = substr($now, -4);
    $exp = str_replace("/", "!", "$a_row->strRefer");
    $ex = explode("!", "$exp");
    $num = sizeof($ex);
    $num -= 1;
    $subref = $ex[$num];
    if ($name == "$a_row->strName" AND $action == "alllast")
    {
        continue;
    }
    $name = "$a_row->strName";

    print "<td align=\"center\"><a href=\"admin_stats_user.php?action=delone&id=$a_row->intId&subaction=track&userid=$userid\">Delete</a></td>
    <td align=\"center\">$a_row->strName</td>
    <td align=\"center\"><a href=\"$a_row->strPageLink\" target=\"_blank\">$a_row->strPage</a></td>
    <td align=\"center\">$a_row->strTime</td>
    <td align=\"center\">$a_row->strDate</td>
    <td align=\"center\"><a href=\"$a_row->strRefer\" target=\"_blank\">&nbsp;$subref</a></td>
    <td align=\"center\">$a_row->strIp</td>";
 // print "<td align=\"center\">$poch</td><td align=\"center\">$snow</td>";

    print "</tr>";
}

print "</table></td></tr></table>";




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

?>