<html>
<head>
<title>Show statistics for administrator</title>
</head>
<body bgcolor ="#ffffff">
<?php
/***************************************************************************
 *		admin/site-stats.php		                           *
 *                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~	                   *
 *   File Info:		  Utility to show site stastistics                 *
 *   Copyright:       Copyright 2003 http://www.128concepts.com            *
 *						                           *
***************************************************************************/
include ("./tests.php");

?>
<?php
include ("./config.php");
if ($_SESSION['admin'] == NULL)
{
 	echo "<p align=\"center\"><b><strong><font face = Verdana size = 5>Sorry you not the administrator!</strong></font></b><br>Click here to return to log in screen <a href='shop_showall.php'>here.</a><br><br><br><br><br><br></p>";
	include("./your-footer.inc");  
	exit();
}
 if ((session_is_registered("admin")) and ($_SESSION['admin'] != "admin"))
{
	 echo "<p align=\"center\"><b><strong><font face = Verdana size = 5>Sorry you not the administrator!</strong></font></b><br>Click here to return to log in screen <a href='shop_showall.php'>here.</a><br><br><br><br><br><br></p>";
	include("./your-footer.inc");  
	exit();
}
if ($usecat == "YES")
	include_once("./sidebars.php");
else
	include_once ("./sidebar.php");
echo "<center><img src=images/site-stats.gif border=0><font face=verdana size=3 color= #000080>  Site Statistics  </font><a href=javascript:history.back()><img src=images/exit.gif border = 0 alt=Exit></a><br><img src=images/line.gif width =500></center>";

# process data ready for display
$php = phpversion();
$mysqlver = mysql_get_server_info();

# get no. of products added/exist in sql database

$table= "products";
$sel_item_totalprice = $sel_item_qty * $sel_item_price;
$conn = @mysql_connect($server,$user,$password)
	or die("Unable to connect to SQL database...");
$rs = @mysql_select_db($database,$conn) 
	or die("Unable to select the database 'mydata'...Please press 'Create Database' to create new database.");
$itemcount = "SELECT pid FROM $table";
$res = mysql_query($itemcount,$conn);
$nprods = mysql_num_rows($res);
$categories = 29;

# get number of contacts records added
$table= "contacts";
$itemcount1 = "SELECT *FROM $table";
$res1 = mysql_query($itemcount1,$conn);
$contacts = mysql_num_rows($res1);

# get number of stocks records added
$table= "stocks";
$itemcount2 = "SELECT *FROM $table";
$res2 = mysql_query($itemcount2,$conn);
$stocks = mysql_num_rows($res2);

# get number of user records added
$table= "users";
$itemcount3 = "SELECT *FROM $table";
$res3 = mysql_query($itemcount3,$conn);
$users = mysql_num_rows($res3);

#get total number of orders i.e from history table
$table= "history";
$itemcount4 = "SELECT * FROM $table where orderid <> '' ";
$res4 = mysql_query($itemcount4,$conn);
$total_orders = mysql_num_rows($res4);

#get number of orders awaiting payment
$itemcount5 = "SELECT * FROM $table where orderid <> '' and stat = 'awaiting payment' ";
$res5 = mysql_query($itemcount5,$conn);
$orders_wait = mysql_num_rows($res5);

#get number of orders payment received
$itemcount6 = "SELECT * FROM $table where orderid <> '' and stat = 'payment received' ";
$res6 = mysql_query($itemcount6,$conn);
$orders_recv = mysql_num_rows($res6);

#get number of orders rejected
$itemcount7 = "SELECT * FROM $table where orderid <> '' and stat = 'order rejected' ";
$res7 = mysql_query($itemcount7,$conn);
$orders_rej= mysql_num_rows($res7);

#get number of users online
$table = "setting";
$usql = "SELECT online from $table";
$rest = @mysql_query($usql,$conn)
	or die("Unable to extract number of online users....");
while ($row = mysql_fetch_array($rest))
{
	$userson = $row["online"];
}
$date_added = date("jS M, Y");

$src_added = date("jS M, Y");

# get number of users log today !!!

$table = "userlogs";
$xsql = "SELECT date_added from $table where date_added = '$src_date'";
$getres = @mysql_query($xsql,$conn);
$online = @mysql_num_rows($getres);

$deletes = "NO";
if ($online == 0)
{
$newon = 0;
$deletes = "YES";
}
else
{
	$newon = ($useron - $online);
}
$table = "setting";
$zsql = "UPDATE $table set online = $newon";
$doupd = @mysql_query($zsql,$conn);
echo"<br><center><font face=verdana size=2 color=#0000FF>$date_added</font></center>";

echo "<br><br><center><img src = images/php.gif width = 82 height = 24><strong><font face=verdana size=2>PHP Version          :</strong> $php</font></center>";
echo "<center><strong><font face=verdana size=2>MYSQL Version          :</strong> $mysqlver</font></center>";
echo "<center><strong><font face=verdana size=2>Product Records            :</strong> $nprods</font></center>";
echo "<center><strong><font face=verdana size=2>Contact Records         :</strong> $contacts</font></center>";
echo "<center><strong><font face=verdana size=2>Stocks Records          :</strong> $stocks</font></center>";
echo "<center><strong><font face=verdana size=2>User Records             :</strong> $users</font></center>";
echo "<center><strong><font face=verdana size=2>User Online               :</strong> $userson</font></center>";
echo "<br><center><strong><font face=verdana size=2>Total Orders        :</strong> $total_orders</font></center>";
echo "<center><strong><font face=verdana size=2>Orders Waiting          :</strong> $orders_wait</font></center>";
echo "<center><strong><font face=verdana size=2>Orders Completed      :</strong> $orders_recv</font></center>";
echo "<center><strong><font face=verdana size=2>Orders Rejected          :</strong> $orders_rej</font></center>";

########################## Show sales/orders statistics ##################################

$table = "history";
$search = "payment received";
$query_count = "SELECT * from $table where stat = '$search'";
$results = @mysql_query($query_count,$conn);
$comp_sales = 0;

while ($rows =  mysql_fetch_array($results))
{
	$comp_saless = $rows["total"];
	$comp_sales = $comp_sales + $comp_saless;
}
if ($wcurrency == "NO")
echo "<center><strong><font face=verdana size=2>Completed Sales          ($currency):</strong> $comp_sales</font></center>";
if ($wcurrency != "NO")
echo "<center><strong><font face=verdana size=2>Completed Sales          ($wcurrency):</strong> $comp_sales</font></center>";

$search = "Awaiting payment";
$query_count = "SELECT * from $table where stat = '$search'";
$results = @mysql_query($query_count,$conn);
$awt_sales = 0;

while ($rows =  mysql_fetch_array($results))
{
	$awt_saless = $rows["total"];
	$awt_sales = $awt_sales + $awt_saless;
}
if ($wcurrency == "NO")
echo "<center><strong><font face=verdana size=2>Awaiting Sales          ($currency):</strong> $awt_sales</font></center>";
if ($wcurrency != "NO")
echo "<center><strong><font face=verdana size=2>Awaiting Sales          ($wcurrency):</strong> $awt_sales</font></center>";

$search = "order rejected";
$query_count = "SELECT * from $table where stat = '$search'";
$results = @mysql_query($query_count,$conn);
$ord_sales = 0;

while ($rows =  mysql_fetch_array($results))
{
	$ord_saless = $rows["total"];
	$ord_sales = $ord_sales + $ord_saless;
}
if ($wcurrency == "NO")
echo "<center><strong><font face=verdana size=2>Rejected Sales          ($currency):</strong> $ord_sales</font></center>";
if ($wcurrency != "NO")
echo "<center><strong><font face=verdana size=2>Rejected Sales          ($wcurrency):</strong> $ord_sales</font></center>";

echo "<br><center><img src=images/line.gif border=0 width=500></center>";



if ($deletes == "YES")
echo "<br><center><img src=images/gth.gif border=0><font face=verdana size=2>Have successfully update the number for users online.</font></center>";
echo "<br><center><font face = Verdana size =2 color = $color>The above information has been retrieved from your server and are up to date.</font></center>";
echo "<table border=0 width=100% align = middle><tr align=center class=subtitle><td><a href=./shop_showall.php><img src =./images/our-prods.gif border=0 height=60></a></td><td><a href = ./shop_viewcart.php><img src =./images/carts.gif height=18 border=0><font face=arial size=1 color=#0F0F0F><b>VIEW CART     </b></font></a></td><td><a href = ./shop_delcart.php><img src =./images/trashcan.gif height=18 border=0><font face=arial size=1 color=#0F0F0F><b>EMPTY CART</b></font></a></td><td><a href = ./shop_updcart.php><img src = ./images/upd-cart.gif border=0 width=27 height=27><font face=arial size=1 color=#0F0F0F><b>UPDATE CART</b></font></a></td></tr></table><br><center><img src=images/line.gif border=0 width=500></center>";
	
?>

</body>
</html>