<?php
session_start();
$username = $_SESSION['membership'];
include("connect.php");

$ID = $_GET['membername'];
$vtime = date("Y-m-d H:m:s");
$result9 = mysql_query("SELECT * FROM spacevisitor WHERE memLname = '$username' && sowner = '$ID'");
$num_results9 = mysql_num_rows($result9);
$row = mysql_fetch_array($result9);

if(($ID!=$username)&&($_SESSION['membership']!= null)){
if($num_results9>0){
	$result11 = mysql_query("UPDATE spacevisitor SET vtime = '$vtime' WHERE memLname = '$username' && sowner = '$ID'");
}else{
	$result10 = mysql_query("INSERT INTO spacevisitor(sowner,memLname,vtime)
	VALUES
	('$ID','$username','$vtime')");
	echo "<script language='javascript'>alert('$ID $username $vtime')</script>";
}	
}

$result = mysql_query("SELECT * FROM membership WHERE memberLname = '$ID'");
$row = mysql_fetch_array($result);

if($row['membercolor']!=""){
$color = $row['membercolor'];
}else{
$color = "#FFFFE0";
}

if($row['memberfcolor']!=""){
$fcolor = $row['memberfcolor'];
}else{
$fcolor = "#A52A2A";
}

if($row['memberthcolor']!=""){
$thcolor = $row['memberthcolor'];
}else{
$thcolor = "#919c86";
}

if($row['memberfont']!=""){
$font = $row['memberfont'];
}else{
$font = "arial";
}
?>
<html>
<head>
<title>Online Bookshop - Welcome</title>
<link href="bookstore.css" rel="stylesheet" type="text/css"/>
<style type="text/css">
div.user
{
font-family:<?php print "$font"; ?>;
}
div.user th
{
text-align:left;
color:white;
background-color:<?php print "$thcolor"; ?>;
}
</style>
</head>
<body style="background:<?php print "$color"; ?>;color:<?php print "$fcolor"; ?>";>
<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 class="user">
<?php
echo "<table border='0' width='100%'>";
if($ID==$_SESSION['membership']){
echo "<tr>";
echo "<th width='100%' colspan='2'><img src='gear.gif' width='20' height='20' border='0'>Control Panel</th>";
echo "</tr>";

echo "<tr>";
echo "<td width='100%' colspan='2'>Welcome back, $ID. You can edit your space information at here!</td>";
echo "</tr>";

echo "<tr>";
echo "<td colspan='2'>";
echo "<a href='addarticle.php?membername=$ID'><img src='add.gif' width='20' height='20' border='0'>Add New Article</a>";
echo "<a href='controlpanel.php?membername=$ID'><img src='gear.gif' width='20' height='20' border='0'>Space Setting</a>";
echo "</td>";
echo "</tr>";
}

echo "<tr>";
echo "<td width='70%' valign='top'>";

echo "<table border='0' width='100%'>";
echo "<tr>";
echo "<th colspan='3'>";
echo "$ID's Recent Activity";
echo "</th>";
echo "</tr>";

$result12 = mysql_query("SELECT * FROM spacearticle WHERE saOwner = '$ID'");
$num_results12 = mysql_num_rows($result12);

if($num_results12>0){
for($j=0;$j<$num_results12;$j++){
$row12 = mysql_fetch_array($result12);
echo "<tr>";
if($row12['saImage']==""){
echo "<td height='100pt' width='100pt' rowspan='3'><a href='spacearticle.php?saTitle=".$row12["articleNo"]."&&membername=$ID'><img src='nophoto.jpg' border='1' width='120' height='140'></a></td>";
}else{
echo "<td height='100pt' width='100pt' rowspan='3'><a href='spacearticle.php?saTitle=".$row12["articleNo"]."&&membername=$ID'><img src=".$row12['saImage']." border='1' width='100' height='140'></a></td>";
}
echo "<td colspan='2'><a href='spacearticle.php?saTitle=".$row12["articleNo"]."&&membername=$ID'>".$row12['saTitle']."</a></td>";
echo "</tr>";

include_once("functioncut.php");

echo "<tr>";
echo "<td colspan='2'>";
echo cutstr($row12['sarticle'],100);echo ("...");
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td><font size='1'>Post at ".$row12['saTime']."</font></td>";
echo "<td align='right'>";
if(($username == $ID)||($username == 'admin')){
echo "<font size='2'><a href='deletearticle.php?membername=$ID&&articleNo=".$row12["articleNo"]."'>Delete</a> | <a href='spacearticleedit.php?saTitle=".$row12["articleNo"]."&&membername=$ID'>Edit</a> | </font>";
}else{
}
echo "<a href='spacearticle.php?saTitle=".$row12["articleNo"]."&&membername=$ID'><font size='2'>View more...</font></a></td>";
echo "</tr>";

echo "<tr>";
echo "<td colspan='3'><hr/></td>";
echo "</tr>";

}
echo "<tr>";
echo "<td colspan='3' align='right'>";
echo "<a href='allarticle.php?membername=$ID'>View More Article</a>";
echo "</td>";
echo "</tr>";
}else{
echo "<tr>";
echo "<td height='500pt'><center>Currently $ID don't has article here.</center></td>";
echo "</tr>";
}
echo "</table>";

echo "</td>";
echo "<td width='30%' valign='top'>";

echo "<table border='0'>";

echo "<tr>";
echo "<th colspan='2'>Space Owner</th>";
echo "</tr>";

echo "<tr>";
if($row['memberImage']!=""){
echo "<td rowspan='5'><img src=".$row['memberImage']." width='100' height='100'></td>";
}else{
echo "<td rowspan='5'><img src='avatar.gif' width='100' height='100'></td>";
}
echo "</tr>";

echo "<tr>";
echo "<td width='100%'>Owner: ";
echo "".$row['memberLname']."";
echo "</td>";
echo "</tr>";

$datey = date('Y',strtotime($row['memberBdate']));
$year = date("Y");
$age = $year - $datey;

echo "<tr>";
echo "<td>Age: $age</td>";
echo "</tr>";

echo "<tr>";
echo "<td>Sex: ".$row['memberSex']."</td>";
echo "</tr>";

echo "<tr>";
echo "<td>About Me: ".$row['memberAbout']."</td>";
echo "</tr>";
echo "</table>";

$result3 = mysql_query("SELECT * FROM bookmessage WHERE memLname = '$ID'");
$num_results3 = mysql_num_rows($result3);

echo "<table border='0' width='100%'>";

echo "<tr>";
echo "<th colspan='2'>$ID's Comment</th>";
echo "</tr>";

for($d=0;$d<$num_results3;$d++){
$row3 = mysql_fetch_array($result3);
$book = $row3['ISBN'];

$result4 = mysql_query("SELECT itemName,itemImage,ISBN FROM item WHERE ISBN = '$book'");
$row4 = mysql_fetch_array($result4);
echo "<tr>";
echo "<td rowspan='2'><a href='bookviewpage.php?ISBN=".$row4["ISBN"]."'><img src=/bookstore/bookstaff/".$row4['itemImage']." border='1' width='100' height='140'></a></td>";
echo "<td><a href='bookviewpage.php?ISBN=".$row4["ISBN"]."'>".$row4['itemName']."</a></td>";
echo "</tr>";

echo "<tr>";
echo "<td>".$row3['comment']."<br/><font size='1'>Commented at ".$row3['time']."</font></td>";
echo "</tr>";
}

echo "</table>";

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

echo "<tr>";
echo "<th colspan='2'>Recently Buy</th>";
echo "</tr>";

echo "<tr>";
echo "<td colspan='2'>";
echo "<table border='0' width='100%'>";
echo "<tr>";

$result1 = mysql_query("SELECT cartitem FROM cartitem WHERE cartName = '$ID' ORDER BY cartNo DESC");

$num_results = mysql_num_rows($result1);

if($num_results>5){
$num_results = 5;
}

if($num_results>0){
for($k=0; $k<$num_results; $k++)
{
$row1 = mysql_fetch_array($result1);

$b0 = "$row1[0]";
$b1 = "$row1[1]";
$b2 = "$row1[2]";
$b3 = "$row1[3]";
$b4 = "$row1[4]";

$ISBN = $row1['cartitem'];
$result2 = mysql_query("SELECT * FROM item WHERE ISBN = '$ISBN'");
$row2 = mysql_fetch_array($result2);

echo "<td width='20%'>";

echo "<table border='0' width='100%'>";
echo "<tr>";
echo "<td align='center' height='100pt'>";
echo "<a href='bookviewpage.php?ISBN=".$row2["ISBN"]."'><img src=/bookstore/bookstaff/".$row2["itemImage"]." border='0' width='100' height='140'></a>";
echo "</td>";
echo "</tr>";

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

echo "</table>";

echo "</td>";
}
}else{
echo "<td height='100pt'><center>$ID hasn't purchase any book yet.</center></td>";
}
echo "</tr>";

echo "<tr>";
echo "<th colspan='5'>Visitor</th>";
echo "</tr>";

$p = $row['memberLname'];

$result7 = mysql_query("SELECT * FROM spacevisitor WHERE sowner = '$p' ORDER BY vtime DESC");
$num_results7 = mysql_num_rows($result7);

echo "<tr>";
echo "<td colspan='5'>";
echo "<table border='0' width='100%'>";
echo "<tr>";
if($num_results7>0){
if($num_results7>10){
$num_results7 = 10;
}
for ($f=0; $f<$num_results7; $f++)
{
echo "<td width='10%'>";
echo "<table border='0'>";
$row7 = mysql_fetch_array($result7);

$VID = $row7['memLname'];
$result8 = mysql_query("SELECT memberImage FROM membership WHERE memberLname = '$VID'");
$row8 = mysql_fetch_array($result8);

$pic = $row8['memberImage'];
echo "<center>";
if($row8['memberImage']!=""){
echo "<tr><td width='10%'><a href='personalspace.php?membername=$VID'><img src=".$row8['memberImage']." width='80' height='80'></a></td></tr>";
}else{
echo "<tr><td width='10%'><a href='personalspace.php?membername=$VID'><img src='avatar.gif' width='80' height='80'></a></td></tr>";
}
echo "<tr>";
echo "<td width='10%'>";
echo "<center><a href='personalspace.php?membername=$VID'>".$row7['memLname']." </a></center></td>";
echo "</tr>";
echo "</center>";
echo "</table>";
echo "</td>";
}
}else{
echo "<tr>";
echo "<td colspan='5' height='100pt'><center>Currently no visitor visit me.</center></td>";
echo "</tr>";
}

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

echo "<tr>";
echo "<td colspan='5'>";
echo "<table border='0' width='100%'>";
echo "<tr>";
echo "<td colspan='5'></td>";
echo "</tr>";
echo "</table>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<th colspan='5'>Visitor's Comment</th>";
echo "</tr>";

$result5 = mysql_query("SELECT * FROM spacecomment WHERE sowner = '$ID'");
$num_results5 = mysql_num_rows($result5);

echo "<tr>";
echo "<td colspan='5'>";
echo "<table border='0' cellspacing='0' cellpadding='5' width='100%' align='center'>";

if($num_results5>0){
for ($c=0; $c<$num_results5; $c++)
{
$row5 = mysql_fetch_array($result5);

$SID = $row5['memLname'];
$result6 = mysql_query("SELECT memberImage FROM membership WHERE memberLname = '$SID'");
$row6 = mysql_fetch_array($result6);

echo "<tr>";
echo "<td width='5%'>".($c+1)."</td>";

$pic = $row6['memberImage'];

if($row6['memberImage']!=""){
echo "<td width='5%'><a href='personalspace.php?membername=$SID'><img src=".$row6['memberImage']." width='50' height='50'></a></td>";
}else{
echo "<td width='5%'><a href='personalspace.php?membername=$SID'><img src='avatar.gif' width='50' height='50'></a></td>";
}
echo "<td width='70%'>".$row5['scomment']."<br/>";
echo "<font size='1'>Commented By <a href='personalspace.php?membername=$SID'> ".$row5['memLname']." </a>, ".$row5['stime']."</font></td>";

if(($username == $ID)||($username == 'admin')){
echo "<form method='POST' action='deletespacecomment.php'>";
echo "<td align='left'><input type='hidden' name='memLname' value='".$row5['memLname']."'><input type='hidden' name='membername' value='$ID'><input type='hidden' name='stime' value='".$row5['stime']."'><input type='submit' name='Delete' value='Delete'>";
}else{
echo "<td></td>";
}
echo "</form>";
echo "</tr>";

echo "<tr>";
echo "<td align='right' colspan='4'><font size='2'>Total $num_results7 Comment(s).</font></td>";
echo "</tr>";
}
}else{
echo "<tr>";
echo "<td height='100pt'><center>Currently no comment here.</center></td>";
echo "</tr>";

echo "<tr>";
echo "<td align='right' colspan='4'><font size='2'>Total 0 Comment(s).</font></td>";
echo "</tr>";
}

if($_SESSION['membership']!= null)
{
echo "<form name='form' method='post' action='spacecomment.php'>";

echo "<tr>";
echo "<th colspan='5'>";
echo "Leave comment to $ID!";
echo "</th>";
echo "</tr>";

echo "<tr>";
echo "<td colspan='5'><center><textarea name='scomment' rows='5' cols='150' maxlength='10000'></textarea></center></td>";
echo "</tr>";

echo "<tr>";
echo "<td align='right' colspan='5'><input type='hidden' name='memLname' value='$username'><input type='hidden' name='ID' value='$ID'><center><input type='button' name='Submit' value='Submit' onclick='submitcheck(scomment.value)'></td>";
echo "</tr>";
echo "</form>";
}else{
echo "<tr colspan='4'>";
echo "<td></td>";
echo "</tr>";
}

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

echo "</table>";
?>

<script language="Javascript">
	function submitcheck(a){
	if(a==""){
	alert("Please check your comment!");
	}else{
	this.form.submit();
	}
}
</script>

</div>
<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>