<?php
include ("connect.php");
session_start();
session_register('staff');

$supID = $_POST["supID"];
$supName = $_POST["supName"];
$supAddress = $_POST["supAddress"];
$supPhone = $_POST["supPhone"];
$supEmail = $_POST["supEmail"];
$scontact = $_POST["scontact"];
$scontacttel = $_POST["scontacttel"];
$sfax = $_POST["sfax"];

if($_POST["Edit"] == "Edit")
{include ("connect.php");
	$result = mysql_query("UPDATE supplier SET
	supName = '$supName',
	supAddress = '$supAddress',
	supPhone = '$supPhone',
	supEmail = '$supEmail',
	scontact = '$scontact',
	scontacttel = '$scontacttel',
	sfax = '$sfax'
	WHERE supID = '$supID'");	
	
	
	$db = mysql_close();
	echo "<script language='javascript'>alert('Edit Supplier Information Success')</script>";
	echo "<script language='javascript'>window.location='supplierlist.php'</script>";

}

if($_SESSION['staff']!= null)
{
?>

<html>
<head>
<title>Daily Bookstore - Management System</title>
<!--include css file-->
<link href="bookstaff.css" rel="stylesheet" type="text/css"/>
</head>

<body>

<?php
include ("stafffunctionbar.php");
?>
</div>
</fieldset>
</td>
</tr>
</table>
<hr/>
<center>
<h2>Edit Supplier</h2>
</center>
<center>
<div id="mainpage">
<table width="90%">
<tr>
<td width="15%" valign="top">
<fieldset style="margin:0 5 0 0">
<legend><img src="Picture/bill.gif" width="30" height="30">Supplier</legend>
<table>
<tr>
<td valign="top">
<a href="supplier.php"><img src="Picture/add.gif" width="30" height="30" alt="add supplier"><a href="supplier.php">Add Supplier</a><br/>
<br/>
<a href="suppplierlist.php"><img src="Picture/list.gif" width="30" height="30" alt="supplier list"><a href="supplierlist.php">Supplier List</a><br/>
<br/>
</td>
</tr>
</table>
</fieldset>
</td>
<td width="75%">


<?php
include("connect.php");

$supID=$_GET['supID'];

$result = mysql_query("SELECT * FROM supplier WHERE supID='$supID'");


$num_results = mysql_num_rows($result);
$row = mysql_fetch_array($result);	

echo "<form name='editsupplier' method='post'>";
echo "<table width='100%'>";

echo "<tr>";
echo "<td valign='top' height='80'>Supplier ID</td>";
echo "<td valign='top' ><b><font style='color:red'>".$row['supID']."&nbsp;&nbsp;&nbsp;Supplier ID cannot edited.</font></b><input name='supID' type='hidden' value='".$row['supID']."'/><br/></td>";
echo "</tr>";


echo "<tr>";
echo "<td valign='top' height='80'>Supplier Name</td>";
echo "<td valign='top' ><input type='text' size='30' maxlength='50' name='supName' value='".$row['supName']."'><br/>(Chinese,Malay,English or other language are allow to edit)</td>";
echo "</tr>";


echo "<tr>";
echo "<td valign='top' height='150'>Supplier Address</td>";
echo "<td valign='top'><textarea name='supAddress'  rows='7' cols='35' maxlength='100' style='font-family:times new roman' >".$row['supAddress']." </textarea><br/>(Address length not more than 100 words)</td>";
echo "</tr>";


echo "<tr>";
echo "<td valign='top' height='80'>Supplier Phone</td>";
echo "<td valign='top' ><input type='int' size='30' maxlength='20' style='number' name='supPhone' value='".$row['supPhone']."'><br/>(Please Enter Supplier's Phone Number to Edit)</td>";
echo "</tr>";


echo "<tr>";
echo "<td valign='top' height='80'>Supplier Email</td>";
echo "<td valign='top' ><input type='text' size='30' maxlength='80' name='supEmail' value='".$row['supEmail']."'></td>";
echo "</tr>";


echo "<tr>";
echo "<td valign='top' height='80'>Contact</td>";
echo "<td valign='top' ><input type='text' size='30' maxlength='50' name='scontact' value='".$row['scontact']."'></td>";
echo "</tr>";

echo "<tr>";
echo "<td valign='top' height='80'>Contactor Tel</td>";
echo "<td valign='top' ><input type='text' size='30' maxlength='15' name='scontacttel' value='".$row['scontacttel']."'><br/></td>";
echo "</tr>";


echo "<tr>";
echo "<td valign='top' height='80'>Fax</td>";
echo "<td valign='top' ><input type='text' size='30' maxlength='50' name='sfax' value='".$row['sfax']."'></td>";
echo "</tr>";

echo "<tr>";
echo "<td></td>";
echo "<td><input type='submit' name='Edit' value='Edit'><input type='reset' name='Reset' value='Reset'></td>";
//$result->free();
$db = mysql_close();
?>	

</tr>
</table>
</fieldset>

</form>
</td>
</tr>
</table>
</div>
</center>

<?php
}else{
	echo "<script language='javascript'>alert ('Please login.')</script>";
	echo "<script language='javascript'>window.location='index.php'</script>";
}
?>
<hr/>

<center>
<div id="bottom">
<br/>
Copyright &#169; with Tian Tian Bookstore 2011. All Rights Reserved.
<br/>
Website:<a href="../bookstore" target="_blank">www.dailybook.com.my
</div>
</center>

</body>
</html>