<?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("INSERT INTO gift(giftname, giftquantity, redeempoint)
	VALUES
	('$giftname', '$giftquantity', '$redeempoint')");
	
	
	$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; 
	

	$result = mysql_query("UPDATE gift SET giftimage = '$img_url' WHERE giftname = '$giftname'");
	
	
	$db = mysql_close();
	echo "<script language='javascript'>alert('Gift Insert Success.')</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.addgift.imgAvatar.src=ele.value;
	}
</script>
</head>

<body>

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

<center>
<h2>Daily Bookstore Management - Manage Book</h2>
</center>

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

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

<table align="center">
<tr>
<td width='200' rowspan="5"><img id="imgAvatar" img src="bookimage/bookcover.jpg" max-width="200" max-height="200"></td>
</tr>

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

<tr>
<td>Gift Name: </td>
<td><input type="text" name="giftname" size="40" maxlength="255"></td>
</tr>

<tr>
<td>Quantity: </td>
<td><input type="text" name="giftquantity" size="3" maxlength="3" value="0"></td>
</tr>

<tr>
<td>Redeem Point: </td>
<td><input type="text" name="redeempoint" size="3" maxlength="3" value="0"></td>
</tr>


<tr>
<td colspan="4" align="center"><input type="submit" name="Save" value="Save"></td>
</tr>
</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>";
}
?>