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

$ID = $_GET['membername'];
$articleNo = $_GET['saTitle'];

$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";
}

$membercolor = $_POST["membercolor"];
$memberthcolor = $_POST["memberthcolor"];
$memberfcolor = $_POST["memberfcolor"];
$memberAbout = $_POST["memberAbout"];
$memberfont = $_POST["memberfont"];
if($_POST["Cancel"] == "Cancel")
{
echo "<script language='javascript'>window.location='personalspace.php?membername=$ID'</script>";
}
if($_POST["Submit"] == "Submit")
	{
	if($memberAbout == "")
	{
	echo "<script>alert('Please fill in all the information for Submit')</script>";
	echo "<script language='javascript'>window.location='spacearticleedit.php?saTitle=$articleNo&&membername=$ID'</script>";
	}
else{
	$result = mysql_query("UPDATE membership SET membercolor = '$membercolor', memberfcolor = '$memberfcolor', memberthcolor = '$memberthcolor', memberfont = '$memberfont', memberAbout = '$memberAbout' WHERE memberLname = '$ID'");
	
	$tmp_file_name = $_FILES['file']['tmp_name']; 
	$file_name = $_FILES['file']['name']; 
	$file_dir = './member/'.$_POST['title'].'/';  
	if(is_dir($file_dir)) 
	{ 
	move_uploaded_file(@$tmp_file_name,@$file_dir.$file_name); 
	$img_url = $file_dir.$file_name; 
	if($img_url!="./member//"){
	$result = mysql_query("UPDATE membership SET memberImage = '$img_url' WHERE memberLname = '$ID'");
	}
	}
	$db = mysql_close();
	echo "<script language='javascript'>alert('Your setting is update successfully.')</script>";
	echo "<script language='javascript'>window.location='personalspace.php?membername=$ID'</script>";
	}
	}
?>

<html>
<head>
<title>Online Bookshop - Welcome</title>
<link href="bookstore.css" rel="stylesheet" type="text/css"/>

<script language="Javascript">
	function showPreview(ele)
	{
		document.setting.imgAvatar.src=ele.value;
	}
</script>

<script type="text/javascript" src="jquery.1.4.2.js"></script>
 <script type="text/javascript" src="farbtastic.js"></script>
 <link rel="stylesheet" href="farbtastic.css" type="text/css" />
 <script type="text/javascript" charset="utf-8">
  $(document).ready(function() {
    $('#demo').hide();
    $('#picker').farbtastic('#color');
  });
 </script>
 
 <script type="text/javascript" charset="utf-8">
  $(document).ready(function() {
    $('#demo').hide();
    $('#picker1').farbtastic('#color1');
  });
 </script>
 
  <script type="text/javascript" charset="utf-8">
  $(document).ready(function() {
    $('#demo').hide();
    $('#picker2').farbtastic('#color2');
  });
 </script>
 
<style type="text/css">
div.user
{
font-family:<?php print "$font"; ?>;
}
div.user h2
{
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>

<hr/>
<div class="user">
<center>
<h2>Space Setting</h2>
</center>

<div id="mainpage">
<table width="90%">
<tr>
<td width="75%">
<!--1st table-->
<table border="0" width="90%" align="center">
<tr>

<td>
<form name='setting' method="POST" enctype="multipart/form-data">
	
<table width="100%" border='1'>

<tr>
<br/>
<th valign="top">Avatar</th>
<td valign="top">
<input type="file" name="file" OnChange='showPreview(this)' size="40"/></td>

<?php
include("connect.php");
$result12 = mysql_query("SELECT * FROM membership WHERE memberLname = '$ID'");
$num_results12 = mysql_num_rows($result12);

$row12 = mysql_fetch_array($result12);

if($row12['memberImage']!=""){
echo "<td width='200' rowspan='3' align='center'><img id='imgAvatar' img src='$row12[memberImage]' width='100' height='100'></td>";
}else{
echo "<td width='200' rowspan='3' align='center'><img id='imgAvatar' img src='avatar.gif' width='100' height='100'></td>";
}
echo "</tr>";

if($row12['membercolor']==""){
$row12['membercolor'] = "#123456";
}
if($row12['memberfcolor']==""){
$row12['memberfcolor'] = "#123456";
}
if($row12['memberthcolor']==""){
$row12['memberthcolor'] = "#123456";
}

echo "<tr>";
echo "<th>Background Color</th>";
echo "<td>";
//echo "<select name='membercolor'>";
//	$colorArray = array("None", "Lightyellow", "LightBlue", "Lightgreen", "Red", "Blue", "Yellow", "Pink", "Orange", "Purple", "Black");
//	for($j = 0; $j < 11 ; $j++)
//	{if($row12["membercolor"] == $colorArray[$j])
//	{echo "<option selected>".$colorArray[$j];
//	}else
//	{echo "<option>".$colorArray[$j];
//	}
//	}
//	echo "</select>";

//echo "<div id='demo' style='color: red; font-size: 1.4em'>jQuery.js is not present. You must install jQuery in this folder for the demo to work.</div>";
echo "<div class='form-item'><label for='color'>Color:</label><input type='text' id='color' name='membercolor' value='$row12[membercolor]'/></div>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td></td>";
echo "<td>";
echo "<div id='picker'></div>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<th>Font Color</th>";
echo "<td>";
echo "<div class='form-item'><label for='color'>Color:</label><input type='text' id='color1' name='memberfcolor' value='$row12[memberfcolor]'/></div>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td></td>";
echo "<td>";
echo "<div id='picker1'></div>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<th>Font Style</th>";
echo "<td>";
echo "<select name='memberfont'>";
	$fontArray = array("Arial", "Sans-serif", "Times New Roman", "Calibri", "Comic Sans MS", "Verdana");
	for($j = 0; $j < 6 ; $j++)
	{if($row12["memberfont"] == $fontArray[$j])
	{echo "<option selected>".$fontArray[$j];
	}else
	{echo "<option>".$fontArray[$j];
	}
	}
	echo "</select>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<th>Border Color</th>";
echo "<td>";
echo "<div class='form-item'><label for='color'>Color:</label><input type='text' id='color2' name='memberthcolor' value='$row12[memberthcolor]'/></div>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td></td>";
echo "<td>";
echo "<div id='picker2'></div>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<th>Say something about you!</th>";
echo "<td><input type='text' name='memberAbout' value='$row12[memberAbout]' size='60'></td>";
echo "</tr>";

echo "<tr>";
echo "<td colspan='2' align='center'><input type='Submit' name='Submit' value='Submit'><input type='Reset' name='Reset'><input type='Submit' name='Cancel' value='Cancel'></td></tr>";
?>
</table>
</fieldset>
</form>
</td>
</tr>
</table>
</div>
</td>
</tr>
</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>