<?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);
$row9 = 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='1' width='100%'>";
echo "<tr>";
echo "<td width='70%' valign='top'>";

echo "<table border='1' width='100%'>";
echo "<tr>";
echo "<th colspan='2'>";
echo "$ID's Article";
echo "<th align='right' width='30%'><a href='personalspace.php?membername=$ID'><img src='back.gif' border='0' width='25' height='25'>Back To Space</a></th>";
echo "</th>";
echo "</tr>";

if($ID==$_SESSION['membership']){
echo "<tr>";
echo "<td colspan='3' align='right'>";
echo "<a href='addarticle.php?membername=$ID'><img src='add.gif' width='20' height='20' border='0'>Add New Article</a>";
echo "</td>";
echo "</tr>";
}else{
echo "<tr>";
echo "<td colspan='3' align='right'>";
echo "</td>";
echo "</tr>";
}

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

$records_per_page = 5;
if(isset($_GET["Pages"])){
	$pages = intval($_GET["Pages"]);
	}else{
	$pages = 1;
}

$total_records = mysql_num_rows($result12);
$total_pages;

if($total_records){
   if($total_records<$records_per_page){
   $total_pages = 1;
   }
   else if($total_records%$records_per_page){
   $total_pages = (int)($total_records/$records_per_page) + 1;
   }else{
   $total_pages = $total_records/$records_per_page;                     
   }
}
else{
   $total_pages = 0;
}

$offset = ($pages - 1)*$records_per_page;
@mysql_data_seek($result12, $offset);


if($num_results12>0){
$o = 1;
if($o<$records_per_page);{
for($j=0; $j<$records_per_page; $j++){
$row12 = mysql_fetch_array($result12);
echo "<tr>";
if($row12['articleNo']!=""){
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($ID = $username){
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>";
}
echo "<a href='spacearticle.php?saTitle=".$row12["articleNo"]."&&membername=$ID'><font size='2'>View more...</font></a></td>";
echo "</tr>";
}
}
}
$o++;

echo "<tr>";
echo "<td colspan='3'>";
echo"<center>";
if($pages>1){
if(($keyword=="")||($searchBy=="")){
echo "<a href='allarticle.php?membername=$ID&Pages=".($pages-1)."'>&nbsp;[Previous]&nbsp;</a>|";
}else{
echo "<a href='allarticle.php?membername=$ID&keyword=".$keyword."&searchBy=".$searchBy."&search=Search&Pages=".($pages-1)."'>&nbsp;[Previous]&nbsp;</a>|";
}
}

for($o=1; $o<=$total_pages; $o++){
	if($o!=$pages){
	if(($keyword=="")||($searchBy=="")){
	echo "<a href=\"allarticle.php?membername=$ID&Pages=".$o."\">&nbsp;[".$o."]&nbsp;</a>";
	}else{
	echo "<a href=\"allarticle.php?membername=$ID&keyword=".$keyword."&searchBy=".$searchBy."&search=Search&Pages=".$o."\">&nbsp;[".$o."]&nbsp;</a>";
	}
	}else
	{
	echo "&nbsp;[$o]&nbsp;"."";
	}
}

if($pages<$total_pages){
if(($keyword=="")||($searchBy=="")){
echo "|<a href='allarticle.php?membername=$ID&Pages=".($pages+1)."'>&nbsp;[Next]&nbsp;</a>";
}else{
echo "|<a href='allarticle.php?membername=$ID&keyword=".$keyword."&searchBy=".$searchBy."&search=Search&Pages=".($pages+1)."'>&nbsp;[Next]&nbsp;</a>";
}
}
echo "</center>";
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: $ID</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%'>";

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 "</td>";
echo "</tr>";

echo "</table>";
?>
</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>