<?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 - Search Statistics";
$pagelink = $file;
include("../inc/inc_setonline.php");
$title = "$name1 Admin - $gfcookie[1]";
include ("../inc/inc_head.php");
include ("../inc/inc_body.php");
$title = "Search Statistics";
include ("../inc/inc_title.php");

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

print "<font size=$fontsizeb><br><center>";

$result=mysql_query("SELECT * FROM $searchtable");
$num_rows = mysql_num_rows( $result );
$count = 0;
while ( $a_row = mysql_fetch_object( $result ) )
{
    if ($a_row->intSuccess == 1)
    {
        $count ++;
    }
}
$result = $count / $num_rows;
$result = $result * 100;
$result = round($result, 2);
print "<b>$num_rows records are held on the system, $count have been successful ($result%).</b><br><br>
<font size=$fontsize>
<a href=\"admin_stats_search.php?action=delete\">Wipe All Search Statistics From The Database</a><br><br>
<a href=\"admin_stats_search.php\">Show All Searches</a><br><br>";

if ($action == "highlight")
{
    print "<a href=\"admin_stats_search.php\">Don't Highlight Unsuccessful Searches</a><br><br>";
}
else
{
    print "<a href=\"admin_stats_search.php?action=highlight\">Highlight Unsuccessful Searches</a><br><br>";
}


print "<form method=\"post\" action=\"admin_stats_search.php?action=track\">View User Searches&nbsp;<select name=\"userid\" size=\"1\">";
$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=\"View\"></form>";


$result=mysql_query("SELECT * FROM $searchtable ORDER BY intId DESC");

if ($action == "track")
{
    $result=mysql_query("SELECT * FROM $searchtable WHERE strName = '$userid' ORDER BY intId DESC");
}




$num_rows = mysql_num_rows( $result );

print "<font size=$fontsizeb><b>$num_rows records have been returned.</b><br><br><font size=$fontsize>";

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>Username</td>
<td align=\"center\"><b>Searching For</td>
<td align=\"center\"><b>Searching In</td>
<td align=\"center\"><b>Success?</td>
<td align=\"center\"><b>Time</td>
<td align=\"center\"><b>Date</td>
<td align=\"center\"><b>Search For This</td>
</tr>";

while ( $a_row = mysql_fetch_object( $result ) )
{
    $high = "";
    if ($a_row->intSuccess == 1)
    {
        $succ = "Yes";
    }
    else
    {
        $succ = "No";
        if ($action == "highlight")
        {
            $high = "bgcolor = \"WHITE\" ";
        }
    }
    print "<tr>
    <td $high align=\"center\">$a_row->strName</td>
    <td $high align=\"center\">$a_row->strSearch</td>
    <td $high align=\"center\">$a_row->strWhat</td>
    <td $high align=\"center\">$succ</td>
    <td $high align=\"center\">$a_row->strTime</td>
    <td $high align=\"center\">$a_row->strDate</td>
    <td $high align=\"center\"><a href=\"../search_go.php?search=$a_row->strSearch&where=All&what=$a_row->strWhat\" target=\"_blank\">Search</a></td></tr>    ";
}

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

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

?>