<?php
session_start(); 
include("connect.php");
$memberLname = $_SESSION['membership'];
$memberPassword=$_POST[memberPassword];
$npwd=$_POST[npwd];
$npwd1=$_POST[npwd1];


if($_POST[submit]) {
if($npwd==$npwd1) {
	include ("connect.php");
	$query = "SELECT memberPassword FROM membership WHERE memberLname = '$memberLname'";
	$result = $db->query($query);
	$row = $result->fetch_array();
	$oldPass = $row["memberPassword"];
	$num_results = $result->num_rows;
	
	if($num_results==1){
	if($memberPassword==$oldPass){
	$query = "UPDATE membership SET memberPassword='$npwd' WHERE memberLname='$memberLname' and memberPassword='$memberPassword'";
	$result = $db->query($query);
	$db->close();
	 echo "<script>alert('Password Edit Success!')</script>";
	 echo "<script language='javascript'>window.location='password.php'</script>";
	}else{
	 echo "<script>alert('Incorrect Password!')</script>";
	 echo "<script language='javascript'>window.location='password.php'</script>";
	 }
	 }else{
	 echo "<script>alert('Invalid user!')</script>";
	 echo "<script language='javascript'>window.location='password.php'</script>";
	 }
	 }else{
     echo "<script>alert('New Password Confirm is Incorrect£¡')</script>";
     }
	 }
if($_SESSION['membership']!= null)
{ 
?>
<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("leftbanner.php");
?>
</div>
</div>

<br/>
<div id="main">
<center>
<h2>Change Password</h2>


<script language='javascript'>
    function checkpost() {
     if(myform.memLname.value=='') {
      alert('Please Enter Your User ID!');
      myform.memLname.focus();
      return false;
      }
     if(myform.memPassword.value=='') {
      alert('Please Enter Your Original Password!');
      myform.memPassword.focus();
      return false;
      }
     if(myform.npwd.value=='') {
      alert('Please Enter Your New Password!');
      myform.memLname.focus();
      return false;
      }
     if(myform.npwd1.value=='') {
      alert('Please Reenter Yout New Password!');
      myform.npwd1.focus();
      return false;
      }
}
</script>

<form action="" method="post" name="myform" onsubmit="return checkpost();">

<table align="center">
<tr>
<td>User ID£º</td>
<td>
<?php
$memberLname = $_SESSION['membership'];
if($_SESSION['membership']!= null)
{
echo "".$memberLname."</a>";
}
?>
</td>
</tr>

<tr>
<td>Original Password£º</td>
<td colspan="2"><input type="password" name="memberPassword"></td>
</tr>

<tr>
<td>New Password£º</td>
<td colspan="2"><input type="password" name="npwd"></td>
</tr>

<tr>
<td>Confirm Password£º</td>
<td><input type="password" name="npwd1"></td>
<td>Please Enter Your Password Again</td>
</tr>

<tr align="center">
<td></td>
<td><input type="submit" name="submit" value="Submit">
&nbsp;&nbsp;<input type="reset" name="reset" value="Reset">
&nbsp;&nbsp;<INPUT TYPE="button" VALUE="Back" name="Back" onClick="history.go(-1);return true;"/>
</td>
<td></td>
</tr>
</table>
</form>
</html>
<?php
}else{
	echo "<script language='javascript'>alert ('Please login or register!.')</script>";
	echo "<script language='javascript'>window.location='index.php'</script>";
}
?>
</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>