<?php
session_start();
$username = $_SESSION['staff'];

include ("connect.php");
	$giftname = $_POST["giftname"];
	$giftquantity = $_POST["giftquantity"];
	$redeempoint = $_POST["redeempoint"];
	
	if($_POST["Save"] == "Save")
	{
	$result = mysql_query("UPDATE gift SET giftquantity = '$giftquantity', redeempoint = '$redeempoint' WHERE giftname = '$giftname'");
	
	
	$tmp_file_name = $_FILES['file']['tmp_name']; 
	$file_name = $_FILES['file']['name']; 
	$file_dir = './bookimage/'.$_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!="./bookimage//"){
	$result = mysql_query("UPDATE gift SET giftimage = '$img_url' WHERE giftname = '$giftname'");
	
	}
	}
	$db = mysql_close();
	echo "<script language='javascript'>alert('Gift Edit Success.')</script>";
	echo "<script language='javascript'>window.location='giftlist.php'</script>";
}
	
if($_POST["Cancel"] == "Cancel"){
	echo "<script language='javascript'>window.location='giftlist.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"/>
<script type="text/javascript" src="calendar.js"></script>
<script type="text/javascript" src="calendar-setup.js"></script>
<script type="text/javascript" src="calendar-en.js"></script>
<style type="text/css"> @import url("calendar-win2k-cold-1.css"); </style>
<script language="Javascript">
	function showPreview(ele)
	{
		document.addbook.imgAvatar.src=ele.value;
	}
</script>
</head>
</head>

<body>

<?php
include ("stafffunctionbar.php");
?>

<center>
<h2>Daily Bookstore Management - Gift</h2>
</center>

<div id="mainpage">
<?php
include("bookfunction.php")
?>
</fieldset>
</td>

<td width="75%">
<center>
<form name="addbook" method="post" enctype="multipart/form-data">
<fieldset style="width:80%">
<legend><img src="Picture/add.gif" width="30" height="30">Edit Gift</legend>

<table align="center">

<?php
include("connect.php");
$giftname=$_GET['giftname'];
$result = mysql_query("SELECT * FROM gift WHERE giftname = '$giftname'");


$row = mysql_fetch_array($result);

echo "<tr>";
echo "<td>Gift Name: </td>";
echo "<td><input type='hidden' name='giftname' value='$row[giftname]'>$row[giftname]";
echo "<font color='red'>&nbsp;&nbsp;&nbsp;Gift name cannot edited.</font>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td>Gift Image: </td>";
echo "<td><input type='file' name='file' OnChange='showPreview(this)'>";
echo "</td>";

echo "<td width='200' rowspan='5'><img id='imgAvatar' img src='$row[giftimage]'></td>";

echo "</tr>";


echo "<tr>";
echo "<td>Gift Quantity: </td>";
echo "<td><input type='text' name='giftquantity' size='5' maxlength='3' value='$row[giftquantity]'></td>";
echo "</tr>";

echo "<tr>";
echo "<td>Redeem Point: </td>";
echo "<td><input type='text' name='redeempoint' size='10' maxlength='5' value='$row[redeempoint]'></td>";
echo "</tr>";

echo "<tr>";
echo "<td colspan='4' align='center'><input type='submit' name='Save' value='Save'><input type='submit' name='Cancel' value='Cancel'></td>";
echo "</tr>";
echo "</table>";
?>
</fieldset>
</form>
</center>
</body>
</html>
<?php
}else{
	echo "<script language='javascript'>alert ('Please login.')</script>";
	echo "<script language='javascript'>window.location='index.php'</script>";
}
?>