<?php
session_start();
session_register('membership');


include ("connect.php");

	$memberLname = $_POST["username"];
	$memberName = $_POST["memberName"];
	$memberICDate = $_POST["memberICDate"];
	$memberICState = $_POST["memberICState"];
	$memberICNo = $_POST["memberICNo"];
	$memberBdate= $_POST["memberBdate"];
	$memberSex = $_POST["memberSex"];
	$memberRace = $_POST["memberRace"];
	$memberAddress = $_POST["memberAddress"];
	$memberPcode = $_POST["memberPcode"];
	$memberCity = $_POST["memberCity"];
	$memberState = $_POST["memberState"];
	$memberHnum1 = $_POST["memberHnum1"];
	$memberHnum2 = $_POST["memberHnum2"];
	$memberHpnum1 = $_POST["memberHpnum1"];
	$memberHpnum2 = $_POST["memberHpnum2"];
	$memberEmail = $_POST["memberEmail"];

if($_POST["Edit"] == "Edit")
{include ("connect.php");
	$query = "UPDATE membership SET 
	memberName = '$memberName',
	memberICDate = '$memberICDate',
	memberICState = '$memberICState',
	memberICNo = '$memberICNo',
	memberBdate= '$memberBdate',
	memberSex = '$memberSex',
	memberRace = '$memberRace',
	memberAddress = '$memberAddress',
	memberPcode = '$memberPcode',
	memberCity = '$memberCity',
	memberState = '$memberState',
	memberHnum1 = '$memberHnum1',
	memberHnum2 = '$memberHnum2',
	memberHpnum1 = '$memberHpnum1',
	memberHpnum2 = '$memberHpnum2',
	memberEmail = '$memberEmail'
	WHERE memberLname = '$memberLname'";
	$result = $db->query($query);
	
	$db->close();
	echo "<script language='javascript'>alert('Update success')</script>";
	echo "<script language='javascript'>window.location='profile.php'</script>";
}

?>
<html>
<head>
<title>Online Bookshop - Welcome</title>
<link href="bookstore.css" rel="stylesheet" type="text/css"/>
</head>
<body style="background:lightyellow">
<center>
<div id="whole">
<div id="title">
<table width="100%" border="0">
<tr>
<td width="60%"><img src="Picture/Logo.gif" width="450" height="100"></td>
<td>
<form method="GET" action="http://www.google.com/search">
<input type="hidden" name="ie" value="UTF-8" >
<input type="hidden" name="oe" value="UTF-8" target="_blank">
<a href="http://www.google.com">
<img src="Picture/GoogleLogo.png" border="0" alt="Google" align="absmiddle" title="Google" >
</a>
<input type="text" name="q" size="20" maxlength="255" value="">
<input type="submit" name="btnG" value="Google Search">
</form>
</td>
</tr>
</table>
</div>
<div id="top">
<table border="0" width="100%">
<tr>

<?php
session_start();
$username = $_SESSION['membership'];
if($_SESSION['membership']!= null)
{
echo "<td align='left' width='75%'>";
echo "<a href='index.php'>Home Page</a>&nbsp;|&nbsp;<a href='bookmenu.php'>Our Book</a>&nbsp;|&nbsp;<a href='companyevent.php'>Event</a>&nbsp;|&nbsp;<a href='companyprofile.php'>About Us</a>&nbsp;|&nbsp;<a href='sitemap.php'>Site Map</a>&nbsp;|&nbsp;<a href='subtemcart.php'>Cart</a>&nbsp;|&nbsp;<a href='history.php'>Order History</a>&nbsp;|";
echo "</td>";

echo "<td align='right' width='25%'>";

echo "<b>You login as: </b><a href='profile.php'>".$username."</a>";
echo "&nbsp;<a href='logout.php'>(Logout)</a>";
echo "</td>";

}else{

echo "<td align='left' width='75%'>";
echo "<a href='index.php'>Home Page</a>&nbsp;|&nbsp;<a href='bookmenu.php'>Our Book</a>&nbsp;|&nbsp;<a href='companyevent.php'>Event</a>&nbsp;|&nbsp;<a href='companyprofile.php'>About Us</a>&nbsp;|&nbsp;<a href='sitemap.php'>Site Map</a>&nbsp;|&nbsp;<a href='Addmem.php'>Join Us</a>&nbsp;|&nbsp;<a href='login.php'>Member Login</a>&nbsp;|";
echo "</td>";

echo "<td align='right' width='25%'>";
echo "<b>You haven't login.</b>";
echo "&nbsp;<a href='login.php'>(Login)</a>";
echo "</td>";
}
?>
</tr>
</table>
</div>

<br/>
<div id="search">
<form action="bookmenu.php" name="searchform" method="GET">
<fieldset style="width:100%">
<legend>Find Your Books Here!</legend>
Search:<input type="text" size="100" name="keyword" value=""/>

<select name="searchBy" value="">
	<option value="itemName">Book Name</option>
	<option value="itemAuthor">Author</option>
	<option value="itemPublisher">Publisher</option>
	<option value="itemCategory">Category</option>
	</select>

<input type="submit" name="search" value="Search"/>
</fieldset>
</form>
</div>

<div id="links">
<h2>Category</h2>
<a href="bookmenu.php?keyword=Humanities&searchBy=itemCategory&search=Search">Humanities</a>
<a href="bookmenu.php?keyword=Business&searchBy=itemCategory&search=Search">Business & Management</a>
<a href="bookmenu.php?keyword=Engineering&searchBy=itemCategory&search=Search">Engineering</a>
<a href="bookmenu.php?keyword=Finance&searchBy=itemCategory&search=Search">Finance</a>
<a href="bookmenu.php?keyword=Sport&searchBy=itemCategory&search=Search">Sport</a>
<a href="bookmenu.php?keyword=Language&searchBy=itemCategory&search=Search">Language</a>
<a href="bookmenu.php?keyword=School&searchBy=itemCategory&search=Search">School Reference</a>
<a href="bookmenu.php?keyword=General&searchBy=itemCategory&search=Search">General</a>
<a href="bookmenu.php?keyword=Magazine&searchBy=itemCategory&search=Search">Magazine</a>
<a href="bookmenu.php?keyword=Children&searchBy=itemCategory&search=Search">Children</a>
<a href="bookmenu.php?keyword=Mandarin&searchBy=itemCategory&search=Search">Mandarin</a>
<a href="bookmenu.php?keyword=Malay&searchBy=itemCategory&search=Search">Malay</a>
<br/>
<a href='bookmenu.php?sort=itemSales DESC'>Top Sales</a>
<a href='bookmenu.php?sort=itemDate DESC'>New Item</a>

<br/><br/>
<hr/>
<div id="main">
<table>
<tr>
<td><center><h2>HOT Title</h2></center></td>
</tr>
<?php
include("connect.php");
$query = "SELECT * FROM item ORDER BY itemDate DESC";   
$result = $db->query($query);
echo "<tr>";
for($i=0; $i<1; $i++)
{
$row = $result->fetch_array();
echo "<td width='20%'>";
echo "<table width='100%'>";
echo "<form name='qform' method='GET' action='indexaddcart.php'>";
echo "<tr>";
echo "<td align='center' height='100pt'>";
echo "<a href='bookviewpage.php?ISBN=".$row["ISBN"]."'><center><img src=/bookstore/bookstaff/".$row["itemImage"]." border='0' width='80' height='120'></center></a>";echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td height='40pt' valign='top' align='center'>";
echo "<input type='hidden' name='itemName' value='".$row["itemName"]."'><a href='bookviewpage.php?ISBN=".$row["ISBN"]."'><center>".$row["itemName"]."</center></a><br/>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td height='40pt' valign='top' align='center'>";
echo "<div id='length'>";
echo "<font maxlength='300pt'>$row[itemSummary]</font>";
echo "</div>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td align='center'><b>Price: RM ";
printf("%10.2f",$row["itemPrice"]);
echo "</b></td>";
echo "</tr>";

echo "<tr>";
echo "<td><br/></td>";
echo "</tr>";

echo "<tr>";
echo "<td align='center'>";
echo "<a href='bookviewpage.php?ISBN=".$row["ISBN"]."'><font size='3pt' color='red'><center>View Details</center></font></a>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td align='center'><br/>";
	$tem = $row[itemQuantity];
	echo "<name='temQuantity'>";
	echo "<select name='temQuantity'>";
	for($j=1; $j<=$tem; $j++)
	{
	echo "<option value='$j'>".$j;
	echo "</option>";
	}
	echo "</select>";
	echo "<input type='hidden' name='ISBN' value='$row[ISBN]'>";
	echo "<input type='hidden' name='itemPrice' value='$row[itemPrice]'>";
	echo "<input type='submit' name='add' value='Add Cart'>";
echo "</td>";
echo "</tr>";
echo "</form>";
echo "</table>";	
echo "</td>";
}
echo "</tr>";
echo "</table>";
?>
</div>
</div>

<br/>
<div id="main">
<center>
<h2>Member Information Edit</h2>

<?php

echo "<form name='memprofile' method='post'>";
include ("connect.php");
$query = "SELECT * FROM membership WHERE memberLname = '$username'";
$result = $db->query($query);
$row = $result->fetch_array();

echo "<fieldset>";
echo "<legend>New Member Registration Form</legend>";

echo "<table width='100%' cellspacing='0' cellpadding='5' border='0'>";
echo "<tr>";
echo "<td colspan='3' class='contents'>Please field up all the information</td>"; 
echo "</tr>"; 
			
echo "<tr>";
echo "<td valign='top'></td>"; 
echo "<td valign='top'>Login Name</td>"; 
echo "<td>".$row["memberLname"]."<input type='hidden' name='username' value='".$row["memberLname"]."'>";
echo "<br/><font color='red'>Login name cannot be edit</font></td>";
echo "</tr>";
		
echo "<tr>"; 
echo "<td valign='top'></td>";
echo "<td valign='top'>Name</td>"; 
echo "<td><input type='text' name='memberName' size='55' maxlength='15' value='".$row["memberName"]."'/></td>"; 
echo "</tr>";

echo "<tr>";
echo "<td valign='top'></td>";
echo "<td valign='top'>NRIC</td>";
echo "<td><input type='text' name='memberICDate' maxlength='6' size='6' value='".$row["memberICDate"]."'/>-";
echo "<input type='text' name='memberICState' maxlength='2' size='2' value='".$row["memberICState"]."'/>-";
echo "<input type='text' name='memberICNo' maxlength='4' size='4' value='".$row["memberICNo"]."'/></td>";
echo "</tr>";
		
echo "<tr>";
echo "<td></td>";
echo "<td valign='top'>Date of Birth<br/>(DD/MM/YYYY):	</td>";
echo "<td>"; 
echo "<input type='text' size='12' name='memberBdate' id='memberBdate' value='".$row["memberBdate"]."'/></td>";
echo "</tr>";
		
echo "<tr>";
echo "<td></td>";
echo "<td>Gender:</td>";
echo "<td><table border='0'>";
echo "<tr><td><input type='radio' name='memberSex' value='Male'";
if($row["memberSex"]=="Male")
{
echo "checked";
}else{
echo "";
}
echo "/>Male";

echo "<input type='radio' name='memberSex' value='Female'";
if($row["memberSex"]=="Female")
{
echo "checked";
}else{
echo "";
}
echo "/>Female</td></tr>";



echo "</td></table>";
echo "</tr>";
			
echo "<tr>";
echo "<td valign='top'></td>";
echo "<td valign='top'>Race:</td>";
echo "<td><select name='memberRace'>",
$raceArray = array("Chinese","Malay","Indian","Others");
for($i = 0; $i < 4 ; $i++)
{if($row["memberRace"] == $raceArray[$i])
	{echo "<option selected>".$raceArray[$i];
	}else
	{echo "<option>".$raceArray[$i];
	}
}
echo "</select>";
echo "</td>";
echo "</tr>";
			
echo "<tr>";
echo "<td valign='top'></td>";
echo "<td valign='top'>Address :</td>";
echo "<td valign='top'><textarea name='memberAddress' rows='5' cols='34'>".$row["memberAddress"]."</textarea></td>";
echo "</tr>";
			
echo "<tr>";
echo "<td valign='top'></td>";
echo "<td valign='top'>Post Code :</td>";
echo "<td><input name='memberPcode' type='text' maxlength='6' size='6' value='".$row["memberPcode"]."'/></td>";
echo "</tr>";

echo "<tr>";
echo "<td valign='top'></td>";
echo "<td valign='top'>City :</td>";
echo "<td><input name='memberCity' type='text' maxlength='20' size='20' value='".$row["memberCity"]."'/></td>";
echo "</tr>";

echo "<tr>";
echo "<td valign='top'></td>";
echo "<td valign='top'>State :</td>";
echo "<td><select name='memberState'>";
$stateArray = array("Johor","Kedah","Kelantan","Kuala Lumpur","Melaka","Negeri Sembilan","Pahang","Penang","Perak","Perlis","Sabah","Sarawak","Selangor","Terengganu");
for($i = 0; $i < 14 ; $i++)
{if($row["memberState"] == $stateArray[$i])
	{echo "<option selected>".$stateArray[$i];
	}else
	{echo "<option>".$stateArray[$i];
	}
}
echo "</select>";
echo "</td>";
echo "</tr>";
		
echo "<tr>";
echo "<td valign='top'></td>";
echo "<td valign='top'>Contact :</td>";
echo "<td><table>";
echo "<tr><td>Home :</td>";
echo "<td><input name='memberHnum1' type='text' maxlength='3' size='3' value='".$row["memberHnum1"]."'/>&nbsp;-&nbsp;";
echo "<input name='memberHnum2' type='text' maxlength='10' size='10' value='".$row["memberHnum2"]."'/></td>";
echo "</tr>";
echo "<tr>";
echo "<td>Handphone :</td>";
echo "<td><select name='memberHpnum1'>";
$hpnumArray = array("010","012","013","014","016","017","019");
for($i = 0; $i < 7 ; $i++)
{if($row["memberHpnum1"] == $hpnumArray[$i])
	{echo "<option selected>".$hpnumArray[$i];
	}else
	{echo "<option>".$hpnumArray[$i];
	}
}
echo "</select>&nbsp;-&nbsp;";
echo "<input name='memberHpnum2' type='text' maxlength='10' size='10' value='".$row["memberHpnum2"]."'/>";
echo "</td>";
echo "</table></td>";
echo "</tr>";
echo "</tr>";
echo "<tr>";
echo "<td></td>";
echo "<td valign='top'>Email :</td>";
echo "<td><input name='memberEmail' type='text' maxlength='50' size='50' value='".$row["memberEmail"]."'/>";
echo "</tr>";
		
		
echo "<tr>";
echo "<td></td>";
echo "<td></td>";
echo "<td><br>";
echo "<input type='submit' name='Edit' value='Edit'/>";
echo "<input type='reset' value='Reset'/>";
echo "<INPUT TYPE='button' VALUE='Back' name='Back' onClick='history.go(-1);return true;'/>";
echo "</td>";
echo "</tr>";
	
echo "</table>";
echo "</fieldset>";
echo "</form>";
echo "</center>";
?>

</div>
</center>
<hr/>
<div id="bottomlink">
<br/>
<a href="index.php">Home Page</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="bookmenu.php">Our Book</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="Addmem.php"> Membership</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="companyevent.php">Event</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="companyprofile.php">About Us</a><br/><a href="sitemap.php">Site Map</a>
</div>

<div id="bottom">
<br/>
Copyright &#169; with Tian Tian Bookstore 2011. All Rights Reserved. 
</div>

</div>
</center>
</body>
</html>