<html>
<head><title>Viewing your users i.e customers.....</title>

<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>
</head>
<body>
<?php

#***************************************************************************
#                          customers.php			           *
#                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~	                   *
#   File Info:		  Lists customers/users info	                   *
#   Copyright:       Copyright 2003 http://www.128concepts.com             *
#						                           *	
# ***************************************************************************/

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


if ($_SESSION['admin'] != "admin" or $_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();
}

echo "<center><img src=images/searching.gif border=0><br><font face=verdana size=3 color=#000080>List all users (i.e customers) and view information</font></center>";

$page = getenv("QUERY_STRING");

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

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

echo "<br><img src=images/line.gif border=0 width=100%><font face = Verdana size = 2>Please select number of users (i.e customers) you wish to view:- ";
$form = "<form action =customers.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=submit value = 'View Records'></form><br>";
echo $form;

echo "<font face = Verdana size = 2>Please input the lastname you wish to search by:-";
$form = "<form action = customers.php method = POST>";
$form.= "<font face=verdana size=2>Search by Last Name:</font> <input type = text name = search size = 30 maxlength = 50>";
$form.= "<input type =submit value='Search'>";
echo $form;

$table = "users";
$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.");

######################### display information search only ###################################

if ($search != NULL)
{
if (empty($page))
$page = 1;
$limitv = $page * $limit - ($limit);
$query_count = "SELECT * from $table where (lastname like '%$search%') order by lastname";
$res_count = mysql_query($query_count,$conn);
$totalrows = mysql_num_rows($res_count);
$query = "SELECT * from $table  where (lastname like '%$search%')  order by lastname 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><img src=images/computer.gif border=0><b>Found $totalrows</b> result(s) for username = '$search' - Listing $limit users per page.</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"Showing item(s): $from to $to</td><td width=\"50%\" bgcolor=\"$backcolor\" align=\"right\"><b>Go to page:</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"Showing item(s): $from to $to</td><td width=\"50%\" bgcolor=\"$backcolor\" align=\"right\"><b>Go to page:</b> ";} 
}
if($page != 1){ 
$pageprev = $page - 1; 
echo("<a href=\"$PHP_SELF?$pageprev\"><img src = ./images/back.gif  width = 20 height = 16 border = 0></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=\".\customers.php?$i\">$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?$pagenext\"><img src = ./images/next.gif width = 20 height = 16 border = 0></a>"); 
}
echo "</td><tr></table><br>";

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

echo"<table align=\"center\" valign=\"top\" width=\"100%\" 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>Last Name</font></b></td>
					<td background=\"images/bevel_bg.gif\" height=\"20\"><b><font face=verdana size=2>First...</font></b></td>
					<td background=\"images/bevel_bg.gif\" height=\"20\"><b><font face=verdana size=2>User Name</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>Date</font></b></td>
					

<td background=\"images/bevel_bg.gif\" height=\"20\"><b><font face=verdana size=2>Information</font></b></td></tr>";

	while($row = mysql_fetch_array($result))
	{
	$lastname = $row["lastname"];
	$firstname = $row["firstname"];
	$username = $row["username"];
	$email = $row["email"];
	$date_added = $row["date_added"];
	echo"<tr bgcolor=\"#FFFFFF\">
            <td><font face=verdana size=2>$lastname</font></td>
            <td><font face=verdana size=2>$firstname</font></td>
            <td><font face=verdana size=2>$username</font></td>
             <td><font face=verdana size=2>$email</font></td>
	<td><font face=verdana size=2>$date_added</font></td>
            <td><img src =\"images\web1.gif\" width = 32 height = 24><a href = javascript:newWindow('./view-user-info.php?$username','acePopup',770,500,'scrollbars=yes')><font face=verdana size=2>View Info.</font></a></td>
             </tr>";
	}
 echo "</table></tr></td></table><br><img src=images/line.gif border=0 width=100%>";
 echo "<br><font face = Verdana size = 2><p align = justify>NOTE TO USERS: Please click on the MORE INFO button to view more details regarding a customer/user.<em>N.B The date added information, the date and time is dependent on the server's time.</em</p></font><br>";
echo "<br><center><a href=javascript:history.back()><img src=images/back.gif border = 0 alt=Back></a></center>";
include("./your-footer.inc");
}

######################## display information no search #####################################

if ($search == NULL)
{

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

$query_count = "SELECT * from $table order by lastname";
$res_count = mysql_query($query_count,$conn);
$totalrows = mysql_num_rows($res_count);
$query = "SELECT * from $table order by lastname 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><img src=images/computer.gif border=0><b>Found $totalrows</b> result(s)  - Listing $limit users per page.</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"Showing item(s): $from to $to</td><td width=\"50%\" bgcolor=\"$backcolor\" align=\"right\"><b>Go to page:</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"Showing item(s): $from to $to</td><td width=\"50%\" bgcolor=\"$backcolor\" align=\"right\"><b>Go to page:</b> ";} 
}
if($page != 1){ 
$pageprev = $page - 1; 
echo("<a href=\"$PHP_SELF?$pageprev\"><img src = ./images/back.gif  width = 16 height = 20 border = 0></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=\".\customers.php?$i\">$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?$pagenext\"><img src = ./images/next.gif width = 16 height = 20 border = 0></a>"); 
}
echo "</td><tr></table><br>";

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

echo"<table align=\"center\" valign=\"top\" width=\"100%\" 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>Last Name</font></b></td>
					<td background=\"images/bevel_bg.gif\" height=\"20\"><b><font face=verdana size=2>FirstName</font></b></td>
					<td background=\"images/bevel_bg.gif\" height=\"20\"><b><font face=verdana size=2>User</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>Date</font></b></td>
					<td background=\"images/bevel_bg.gif\" height=\"20\"><b><font face=verdana size=2>Information</font></b></td></tr>";

	while($row = mysql_fetch_array($result))
	{
	$lastname = $row["lastname"];
	$firstname = $row["firstname"];
	$username = $row["username"];
	$email = $row["email"];
	$date_added = $row["date_added"];
	$usernames = str_replace(" ","%20",$username);
	echo"<tr bgcolor=\"#FFFFFF\">
            <td><font face=verdana size=2>$lastname</font></td>
            <td><font face=verdana size=2>$firstname</font></td>
            <td><font face=verdana size=2>$username</font></td>
             <td><font face=verdana size=2>????????</font></td>
	<td><font face=verdana size=2>$date_added</font></td>
            <td><img src =\"images\web1.gif\" width = 32 height = 24><a href = javascript:newWindow('./view-user-info.php?=$usernames','acePopup',770,500,'scrollbars=yes')><font face=verdana size=2>View Info.</font></a></td>
             </tr>";
	}
 echo "</table></tr></td></table><br><img src=images/line.gif border=0 width=100%>";
 echo "<br><font face = Verdana size = 2><p align = justify>NOTE TO USERS: Please click on the View Info button to view more details regarding a customer/user.<em> N.B The date added information, the date and time is dependent on the server's time.</em></p></font><br>";
echo "<br><center><a href=javascript:history.back()><img src=images/back.gif border = 0 alt=Back></a></center>";
include("./your-footer.inc");
}

?>
</body>
</html>