<html>
<head><title>Viewing Customer/User Information</title></head>
<script language="JavaScript">
function newWindow(mypage,myname,w,h,features) {
  if(screen.width){
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  }else{winl = 0;wint =0;}
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += features;
  win = window.open(mypage,myname,settings);
  win.window.focus();
}</script>
<body>
<?php
#***************************************************************************
#                          view-user-info.php			           *
#                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~	                   *
#   File Info:		  Lists users information	                   *
#   Copyright:       Copyright 2003 http://www.128concepts.com             *
#						                           *	
# **************************************************************************/

include ("./config.php");
include ("./tests.php");
include ("./header-only.inc");

 if ((session_is_registered("admin")) and ($_SESSION['admin'] != "admin"))
{
	
 echo "<br><br><center><img src=images/line.gif border=0 height=1 width=400></center><p align=\"center\"><img src=images/keybord1.gif border=0><b><strong><font face = Verdana size = 3>   Sorry you are not the administrator!</strong></font></b><br>Click here to return to log in screen  <a href='shop_showall.php'>here.</a>
<br><br><img src=images/line.gif border=0 height=1 width=400><br><br><br><br></p>";
	include("./your-footer.inc");  
	exit();
}
$email = getenv("QUERY_STRING");
$post = strpos($email,"=");

if ($email[0] == "=")
	$username = substr($email,$post+1);

if ($_SERVER['REQUEST_METHOD'] == "POST") 
  {
        # escape data and set variables
        $username= addslashes($_POST["username"]);
        $page = addslashes($_POST["page"]);
}

$username = str_replace("%20"," ",$username);
echo "<br><center><img src=images/view-cust.gif border=0><font face=verdana size=2 color=darkred>  List all user's information records</font></center>";

echo("<br><center><a href = javascript:window.close('acePopup')><img src=images/exit.gif border=0 alt=Exit></a></center>");




if ($_SERVER['REQUEST_METHOD'] == "POST") 
  {
        # escape data and set variables
        $limit= addslashes($_POST["limit"]);
}

if ($limit == NULL)
	$limit = 5;

echo "<img src=images/line.gif border=0 width=100% height=1><font face = Verdana size = 3>Please select number of user's information records you wish to view:- ";
$form = "<form action =view-user-info.php method = POST>";
$form.= "<select name = limit><option value = 5>5 records</option><option value = 10>10 records</option><option value = 25>25 records</option><option value = 50>50 records</option></select>";
$form.="<input type = hidden name = page value = $page>";
$form.="<input type = hidden name = username value = '$username'>";
$form.= "<input type=submit value = 'View Records'></form><br>";
echo $form;

$table = "history";
$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...Please press 'Create Database' to create new database.");

if (empty($page))
$page = 1;
$limitv = $page * $limit - ($limit);

$query_count = "SELECT * from $table where (username like '$username')";

$res_count = mysql_query($query_count,$conn);
$totalrows = mysql_num_rows($res_count);
$query = "SELECT * from $table where (username like '$username') LIMIT $limitv,$limit";
$result = mysql_query($query,$conn)
	or die("SQL command fail ".mysql_error());
$count_result = mysql_num_rows($result);

$numpages = ceil($totalrows / $limit);


echo "<p><center><b><font face=verdana size=2>Found $totalrows</b> result(s)  - Listing $limit user's records per page.</font></center></p>";
$from = $limit*$page-$limit+1;
$to = $from+$count_result-1;
if ($style == 1) #style 1
{
echo "<table align=\"center\" width=\"90%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
            <tr><td width=\"50%\" bgcolor=\"$backcolor\" align=\"left\">";if($numpages>1){echo"<font face=verdana size=2>Showing item(s): $from to $to</font></td><td width=\"50%\" bgcolor=\"$backcolor\" align=\"right\"><b><font face=verdana size=2>Go to page:</font></b> ";} 
}
if ($style == 2) #style 2
{
echo "<table align=\"center\" width=\"60%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
            <tr><td width=\"50%\" bgcolor=\"$backcolor\" align=\"left\">";if($numpages>1){echo"<font face=verdana size=2>Showing item(s): $from to $to</font></td><td width=\"50%\" bgcolor=\"$backcolor\" align=\"right\"><b><font face=verdana size=2>Go to page:</font></b> ";} 
}
if($page != 1){ 
$pageprev = $page - 1; 
echo("<a href=\"$PHP_SELF?page=$pageprev&username=$username\"><img src = ./images/back.gif  width = 20 height = 16 border = 0 alt=Back></a>&nbsp;"); 

} 

// display page nos if not 1 
for($i = 1; $i <= $numpages; $i++){ 
if($numpages>1){
if($i == $page) 
echo("&nbsp;".$i."&nbsp;"); 
else
echo("&nbsp;<a href=\".\view-user-info.php?page=$i&username=$username\">$i</a>&nbsp;"); 
}}

// display next page link if there is more than one
if(($totalrows - ($limit * $page)) > 0){ 
$pagenext = $page + 1; 
echo("<a href=\"$PHP_SELF?page=$pagenext&username=$username\"><img src = ./images/next.gif width = 20 height = 16 border = 0 alt=Next></a>"); 
}
echo "</td><tr></table><br>";

######################### display part ##############################

echo"<table align=\"center\" valign=\"top\" width=\"95%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr bgcolor=\"$backcolor\"><td>
			<table cellpadding=\"2\" border=\"0\" cellspacing=\"1\" valign=\"top\" width=\"100%\" align=\"center\">
				<tr bgcolor=\"#FFFFFF\">
					<td background=\"images/bevel_bg.gif\" height=\"20\"><b><font face=verdana size=2>ID<font></b></td>
					<td background=\"images/bevel_bg.gif\" height=\"20\"><b><font face=verdana size=2>Name<font></b></td>
					<td background=\"images/bevel_bg.gif\" height=\"20\"><b><font face=verdana size=2>Add. #1<font></b></td>
					<td background=\"images/bevel_bg.gif\" height=\"20\"><b><font face=verdana size=2>Add. #2<font></b></td>
					<td background=\"images/bevel_bg.gif\" height=\"20\"><b><font face=verdana size=2>City<font></b></td>
					<td background=\"images/bevel_bg.gif\" height=\"20\"><b><font face=verdana size=2>P.Code<font></b></td>
					<td background=\"images/bevel_bg.gif\" height=\"20\"><b><font face=verdana size=2>Email<font></b></td>
					<td background=\"images/bevel_bg.gif\" height=\"20\"><b><font face=verdana size=2>Info<font></b></td></tr>";

	while($row = mysql_fetch_array($result))
	{
	$orderid = $row["orderid"];
	$fullname = $row["fullname"];
	$address1 = $row["address1"];
	$address2 = $row["address2"];
	$city = $row["city"];
	$postcode = $row["postcode"];
	$email = $row["email"];
	echo"<tr bgcolor=\"#FFFFFF\">
             <td><font face=verdana size=2>$orderid</font></td>
            <td><font face=verdana size=2>$fullname</font></td>
            <td><font face=verdana size=2>$address1</font></td>
            <td><font face=verdana size=2>$address2</font></td>
            <td><font face=verdana size=2>$city</font></td>
            <td><font face=verdana size=2>$postcode</font></td>		
             <td><font face=verdana size=2>$email</font></td>
           <td><img src =\"images\search.gif\" width = 20 height = 20><a href = javascript:newWindow('./view_order-info.php?$orderid','acePopup',600,600,'')>View<a></td>
             </tr>";
	}
 echo "</table></tr></td></table><br><img src=images/line.gif border=0 width=100% height=1>";
if ($totalrows == 0)
	echo "<center><b><font face=verdana size=2 color=navy>User has not made any orders !!! therefore no customer information.</font></b></center>";
echo "<br><center><b><font face=verdana size=2>Legend:-</b>ID = Order Id Add.#1 = Address #1 Add.#2 = Address #2 P.Code = Post Code</font></center><br>";

include_once("./your-footer.inc");
?>
</body>
</html>