<?php
	$login=mysql_connect('localhost', 'wauhaha_karaoke', 'cross123','wauhaha_karaoke');
	
	mysql_selectDB("wauhaha_karaoke",$login);
	$result =mysql_query('select * from admin');
	$r = mysql_fetch_array($result);
	$id = $r['Username']

?>
<html>
<head>
<title>
Admin View Member
</title>
<script src="lib/jquery.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" media="screen" href="screen.css" />
<link rel="stylesheet" type="text/css" media="screen" href="paginate.css" />
<script src="jquery.validate.js" type="text/javascript"></script>
<script language="javascript"> 
$().ready(function() {
$("#signupForm").validate({
		rules: {
			mems: {
				required: true,
				
			},
			},
				messages: {
			
			mems: {
				required: "Please enter IC",
				
			},
			}
			
			});
			});
</script>


</head>
<body style="background-color: #ffffff;background-image:url(rail.jpg);background-repeat: repeat-y">
<center>
<?php
include('link.php');

?>
</center>
<?php
	$login=mysql_connect('localhost', 'wauhaha_karaoke', 'cross123','wauhaha_karaoke');
	
	mysql_selectDB("wauhaha_karaoke",$login);
?>
<h2 align=center><i>Admin view Member</i></h2>


<script type="text/javascript" src="js/jquery-1.4.2.js"></script>
<script type='text/javascript' src="js/jquery.autocomplete.js"></script>
<link rel="stylesheet" type="text/css" href="js/jquery.autocomplete.css" />
<script language="javascript"> 
$().ready(function() {
	$("#mems").autocomplete("mems.php", {
		width: 260,
		matchContains: true,
		//mustMatch: true,
		//minChars: 0,
		//multiple: true,
		//highlight: false,
		//multipleSeparator: ",",
		selectFirst: false
	});
});
</script>
<?php


echo "<center><a href=adminaccount.php title=Back><img src=back.jpg width=40 height=40></a> &nbsp; <a href=adminaddmem.php title=Register&nbsp;Member><img src=adds.jpg height=40 width=40></a></center>";  
echo"
<form  method='post' target='_window' class='cmxform' id='signupForm' action='http://www.wauhaha.com/karaoke/smem.php' >
<table border='1' cellspacing='0' cellpadding='5' bordercolorlight='tan' align=center>
<tr>
	<td>Search by &nbsp;&nbsp;: &nbsp;
	IC
	</td>
	<td>Keywords:</td>
	<td><input type='text' name='mems' id='mems'></td>
	<td rowspan='2'><input type='submit' name='search' value='Search'>&nbsp;&nbsp;&nbsp;&nbsp;
</tr>
</table>

</form>";
?>


<?php
$result = mysql_query("select * From regmember");  
$total_records = mysql_num_rows($result);
$records_per_page = 10;
$page   = intval($_GET['page']);

$adjacents  = intval($_GET['adjacents']);
if($adjacents<=0) $adjacents = 4;

if($page<=0)  $page  = 1;
//$tpages = ($_GET['tpages']) ? intval($_GET['tpages']) : 20; // 20 by default

if($total_records){
   if($total_records<$records_per_page){
   $tpages = 1;
   }
   else if($total_records%$records_per_page){
   $tpages = (int)($total_records/$records_per_page) + 1;
   }else{
   $tpages = $total_records/$records_per_page;                     
   }
}
else{
   $tpages = 0;
}

//if(isset($_GET["Pages"])){
//	$page = intval($_GET["Pages"]);
//	}else{
//	$page = 1;
//}

$offset = ($page - 1)*$records_per_page;
@mysql_data_seek($result, $offset);




echo "<table border=1 align=center style ='font-family:Arial, Helvetica, sans-serif;font-size:1em' color='blue' bordercolorlight='tan' cellspacing=0 cellpadding=4>
 <tr bgcolor=lightblue ><th>Member ID</th>	
						<th>Username</th>
						<th>Credit</th>
						<th>Name</th>
						<th>Password</th>
						<th>Gender</th>
						<th>DOB</th>
					
						<th>IC</th>
						<th>Email</th>
						<th>Phone</th>
				
						<th>Add</th>
						<th>Edit</th>
						<th>Delete</th>
						</tr>";


while($row2 = mysql_fetch_array($result)){
  $MemID=$row2['MemID'];
  
  echo"<tr align='center' border=1>";

  echo "<td border=1>".$row2['MemID']."</td>";
  echo "<td border=1>".$row2['Username']."</td>";
  echo "<td border=1>".$row2['Credit']."</td>";
  echo "<td border=1>".$row2['Name']."</td>";
 	
  echo "<td border=1>".$row2['Password']."</td>";
  echo "<td border=1>".$row2['Gender']."</td>";
  echo "<td border=1>".$row2['BDay']."</td>";


  echo "<td border=1>".$row2['IC']."</td>";
  echo "<td border=1>".$row2['Email']."</td>";
  echo "<td border=1>".$row2['Phone']."</td>";

   echo "<td border=1><a href=http://www.wauhaha.com/karaoke/adminaddcredit.php?MemID=$MemID /><img src=add.jpg width=20 height=20></a></td>";

  echo "<td border=1><a href=http://www.wauhaha.com/karaoke/admineditmem.php?MemID=$MemID /><img src=edit.jpg width=20 height=20></a></td>";
   echo "<td border=1><a href=http://www.wauhaha.com/karaoke/admindelmem.php?MemID=$MemID /><img src=delete.png width=20 height=20></a></td>";

  echo "</tr>";
  }
  echo "<center>";
$reload = $_SERVER['PHP_SELF'] . "?tpages=" . $tpages . "&amp;adjacents=" . $adjacents;
function paginate_three($reload, $page, $tpages, $adjacents) {
	
	$prevlabel = "&lsaquo; Prev";
	$nextlabel = "Next &rsaquo;";
	
	$out = "<div class=\"pagin\">\n";
	
	// previous
	if($page==1) {
		$out.= "<span>" . $prevlabel . "</span>\n";
	}
	elseif($page==2) {
		$out.= "<a href=\"" . $reload . "\">" . $prevlabel . "</a>\n";
	}
	else {
		$out.= "<a href=\"" . $reload . "&amp;page=" . ($page-1) . "\">" . $prevlabel . "</a>\n";
	}
	
	// first
	if($page>($adjacents+1)) {
		$out.= "<a href=\"" . $reload . "\">1</a>\n";
	}
	
	// interval
	if($page>($adjacents+2)) {
		$out.= "...\n";
	}
	
	// pages
	$pmin = ($page>$adjacents) ? ($page-$adjacents) : 1;
	$pmax = ($page<($tpages-$adjacents)) ? ($page+$adjacents) : $tpages;
	for($i=$pmin; $i<=$pmax; $i++) {
		if($i==$page) {
			$out.= "<span class=\"current\">" . $i . "</span>\n";
		}
		elseif($i==1) {
			$out.= "<a href=\"" . $reload . "\">" . $i . "</a>\n";
		}
		else {
			$out.= "<a href=\"" . $reload . "&amp;page=" . $i . "\">" . $i . "</a>\n";
		}
	}
	
	// interval
	if($page<($tpages-$adjacents-1)) {
		$out.= "...\n";
	}
	
	// last
	if($page<($tpages-$adjacents)) {
		$out.= "<a href=\"" . $reload . "&amp;page=" . $tpages . "\">" . $tpages . "</a>\n";
	}
	
	// next
	if($page<$tpages) {
		$out.= "<a href=\"" . $reload . "&amp;page=" . ($page+1) . "\">" . $nextlabel . "</a>\n";
	}
	else {
		$out.= "<span>" . $nextlabel . "</span>\n";
	}
	
	$out.= "</div>";
	
	return $out;
}
echo paginate_three($reload, $page, $tpages, $adjacents);

echo "</center><br>";

$db = mysql_close();
echo "</center>";
  
  echo "</table>";

mysql_close($login);


?>

	</body>
</html>	