<? 
session_start();
include("functions/conexion.php");
include("functions/divs.php");

$query = "SELECT * FROM User WHERE login ='".$_SESSION['login']."'";
$result = mysql_query($query, $conexion);
$row = mysql_fetch_array($result);
?>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title><? echo $_SESSION['login']?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="css/style.css" media="screen" />
</head>

<body>
	<div id="title">
	<div id="header">
	<img src="images/money.png" alt="Money" align="left"/>
	</div>
	<div id="virtualtrade">
	<h1>      
    	<a href="index.php"><img src="images/title.png" alt="Virtual Trade"/></a>
    </h1>
	</div>
	<div id="signin">
	<?
	if(isset($_SESSION['login'])) {
		echo "<a href='/infouser.php'>".$_SESSION['login']."</a>";
		echo "&nbsp;&nbsp;";
		echo "<a href='/functions/logout.php'>Sign out</a>";
	}
	else{
	?>
	<a href="/register.php">Register</a>
	<a href="/loginindex.php">Sign in</a>
	<?
	}
	?>
	<br/>
	</div>
</div>
<div id="general">
<div id="user">
<h3><? echo $_SESSION['login']?></h3>

<form name="register" method="post" action="infouser2.php">
<table id="register">
<tr>
<td align="left">Password:</td><td><input type="password" name="password" value="<? echo $row["pass"]?>"/></td>
</tr>
<tr>
<td align="left">Name:</td><td><input type="text" name="name" value="<? echo $row["name"]?>"/></td>
</tr>
<tr>
<td align="left">Address:</td><td><input type="text" name="address" value="<? echo $row["address"]?>"/></td>
</tr>
<tr>
<td align="left">Age:</td><td><input type="text" name="age" value="<? echo $row["age"]?>"/></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Save" onClick="return check()"/>
</tr>
</table>
<input type="hidden" name="ownerid" value="<? echo $ownerid; ?>"/>
<input type="hidden" name="stock" value="<? echo $stock; ?>"/>
</form>
<?
printuser();
printsellbuyuser();
?>
<a href="functions/generatepdftables.php">Generate PDF</a>
<br/><br/>
<a href="index.php">Back to index</a>
</div>
<div id="transactionhistory">
<h3>Transaction history</h3>
<div id="transactionhistorybuy">
Purchases
<?
$query = "SELECT * FROM History, Stock WHERE History.stock = Stock.id AND buyer =".$row["id"];
$answer = mysql_query($query);
echo "<table border='1'>";
echo "<tr><td>Ticker</td><td>Price</td><td>Volume</td><td>Time</td></tr>";
while($rowbuy = mysql_fetch_array($answer)){
	echo "<tr>";
	echo "<td>";
	echo "<a href='details.php?idticker=".$rowbuy["stock"]."&ticker=".$rowbuy["ticker"]."'>".$rowbuy["ticker"]."</a>"; 	
	echo "</td>";
	echo "<td>";
	echo $rowbuy["price"];
	echo "</td>";	
	echo "<td>";
	echo $rowbuy["volume"];
	echo "</td>";		
	echo "<td>";
	echo $rowbuy["time"];
	echo "</td>";
	echo "</tr>";	
}
echo "</table>";
echo "</div>";
echo "<div id='transactionhistorysell'>";
echo "Sales";
$query = "SELECT * FROM History, Stock WHERE History.stock = Stock.id AND seller =".$row["id"];
$answer = mysql_query($query);
echo "<table border='1'>";
echo "<tr><td>Ticker</td><td>Price</td><td>Volume</td><td>Time</td></tr>";
while($rowsell = mysql_fetch_array($answer)){
	echo "<tr>";
	echo "<td>";
	echo "<a href='details.php?idticker=".$rowsell["stock"]."&ticker=".$rowsell["ticker"]."'>".$rowsell["ticker"]."</a>"; 	
	echo "</td>";
	echo "<td>";
	echo $rowsell["price"];
	echo "</td>";	
	echo "<td>";
	echo $rowsell["volume"];
	echo "</td>";		
	echo "<td>";
	echo $rowsell["time"];
	echo "</td>";
	echo "</tr>";	
}
echo "</table>";

?>
</div>
</div>
</div>
</body>
</html>
