<?php session_start();
$previous = $_SESSION['previous'];
echo $previous.'<br>';
  
if( !isset($_SESSION['userid']))
{ 
	echo "username is not set <br>";
	$temp2 = $_SESSION['error'];
	session_unset();
	$_SESSION['error'] = $temp2;

}
else
{ 
	echo "username is set : ".$_SESSION['userid']."<br>";	
	$temp = $_SESSION['userid'];
	$temp2 = $_SESSION['error'];
	session_unset();
	$_SESSION['userid'] = $temp;
	$_SESSION['error'] = $temp2;
}
$_SESSION['previous'] = "home";
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> HOME -- BOOKS DATABASEE </title>

<style type="text/css">
body {
	background-image:url(b1.jpg);
	background-position:left;
	background-repeat:repeat-x;
	background-repeat: repeat;
}
.style1 {font-family:"Comic Sans MS";
          font-size:16px}
.style2 {color: #FF0000}
</style>
</head>

<body>

<h1 align="center"><strong> HOME PAGE : BOOK MANAGEMENT SYSTEM </strong></h1>


<?php
if(!isset($_SESSION['userid']))
{	
	 // error session variable to indicate what is the error in username or password. 
	 // if set then display the error and unset otherwise ignore
	 $s1=" USER ID ";
	 $s2=" PASSWORD ";
	 if (isset($_SESSION['error']))
	 {
		if ($_SESSION['error']=="userid")
		{ 
		 $s1 = $s1."(invalid username)";
		 unset($_SESSION['error']);
		}
		else	 
		if ($_SESSION['error']=="password")
		{ 
			$s2 = $s2." (invalid password)";
			unset($_SESSION['error']);
		}
	 }
	 echo
	  '<form id="form1" name="form1" method="post" action="login.php">
	   <fieldset >
	   <legend class="style1"> Login To Enter </span></legend>
	   <br></br>
	  <label>'.$s1.'
	  <input type="text" name="userid" id="userid" value="ashgupta" />
	  </label>
	  <br>
	  <label>'.$s2.'
	  <input type="text" name="password" id="password" value="great" />
	  </label>
	  <br>
	  <p>
		<input type="submit" name="button" id="button" value="Submit" />
	  </p>
	  </form>
	  
	  <br><br> Do not have an id, then <a href="register.php">Register</a> <br><br>
	  </fieldset>';
	  
	  
	  echo '
	  <form id="form1" name="form1" method="post" action="search_display.php">

	  <table>
		<tr> 
			<td> <label> SEARCH </label><input type="radio" name="RadioGroup1" value="Search" id="RadioGroup1_0"/> </label> </td>
			<td> <label> BUY <input type="radio" name="RadioGroup1" value="Buy" id="RadioGroup1_1" /> </label> </td>
		</tr>
	  </table>

	  <label>isbn
	  <input type="text" name="isbn" id="isbn" />
	  </label>
	  <br>
	  <label> title
	  <input type="text" name="title" id="title" />
	  </label>
	  <br>
	  <label>language
	  <input type="text" name="language" id="language" />
	  </label>
	  <br>
	  <label>publisher
	  <input type="text" name="publisher" id="publisher" />
	  </label>
	  <br>
	  <label>author
	  <input type="text" name="author" id="author"/>
	  </label>
	  <br>
	  <label>library reference number
	  <input type="text" name="libref" id="libref"/>
	  </label>
	  <p>
		<input type="submit" onClick="validate(this.form)" name="button" id="button" value="Submit" />
		<input name="b" type="button" onClick="re(this.form)" id="b" value="Clear" />
	  </p>
	  </form>';
}
else
{
	    echo "RECENT TRANSACTIONS".'<br>';
	    
		echo '<br><br> userid:'.$_SESSION['userid'].'<br>';
		echo '<br><br>  <a href="sell.php">SELL</a> <br><br>';
		echo '<br><br>  <a href="search.php">BUY/SEARCH</a> <br><br>';
		echo '<br><br>  <a href="recommendation.php">COURSE BOOKS RECOMMENDATION</a> <br><br>';
		echo '<br><br>  <a href="thistory.php">TRANSACTION HISTORY</a></a> <br><br>';
		echo '<br> <a href="logout.php"> Logout </a> <br>';
}
?>
</body>
</html>
