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

$staffID=$_GET['staffID'];

if($_POST["Back"] == "Back")
{
	echo "<script language='javascript'>window.location='onlineorderlist.php'</script>"; 
}

if($_POST["Delete"] == "Delete")
{
include("connect.php");


$cartNo=$_GET['cartNo'];
	$query=mysql_query("delete from cart where cartNo='$cartNo'");
	$query2=mysql_query("delete from cartitem where cartNo='$cartNo'");
	echo "<script>alert('Sales Order $cartNo is deleted.')</script>";
	echo "<script language='javascript'>window.location='onlineorderlist.php'</script>"; 
}
	
if($_POST["Submit"] == "Sales Order")
{
include("connect.php");
include("salesorderID.php");
session_start();

$cartNo = $_POST["cartNo"];
$soNo = $index;
$soDate = date("Y-m-d");

$result1 = mysql_query("INSERT INTO salesorder (custName, soAddress, soTel, soEmail, soCode, soCity, soState, soTotal, soShip, soPay, cartNo) SELECT cartName, cartAddress, cartTel, cartEmail, cartCode, cartCity, cartState, cartTotal, cartShip, cartPay, cartNo FROM cart WHERE cartNo = '$cartNo'");


$result2 = mysql_query("UPDATE salesorder SET soNo = '$soNo', soDate= '$soDate' WHERE cartNo = '$cartNo'");


$result3 = mysql_query("INSERT INTO soitem (soItem, soQuantity, soPrice, cartNo) SELECT cartItem, cartQuantity, cartPrice, cartNo FROM cartitem WHERE cartNo = '$cartNo'");


$result4 = mysql_query("UPDATE soitem SET soNo = '$soNo' WHERE cartNo = '$cartNo'");


$query5=mysql_query("DELETE from cart WHERE cartNo='$cartNo'");
$query6=mysql_query("DELETE from cartitem WHERE cartNo='$cartNo'");

echo "<script>alert('Sales order for $cartNo is created.')</script>";
echo "<script language='javascript'>window.location='onlineorderlist.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");
?>

</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/leave.gif" width="30" height="30">Leave</legend>
<table>
<tr>
<td valign="top">
<a href="addleave.php"><img src="Picture/apply.gif" width="30" height="30" alt="apply"><a href="addleave.php">Apply Leave</a><br/>
<?php
if(($_SESSION['staff_level']=='IT Staff')||($_SESSION['staff_level']=='IT Staff')){;
?>
<br/>
<a href="leavemain.php"><img src="Picture/leave.gif" width="30" height="30" alt="leave"><a href="leavemain.php">New Leave List</a><br/>
<br/>
<a href="leaveoldlist.php"><img src="Picture/record.gif" width="30" height="30" alt="apply"><a href="leaveoldlist.php">Leave Record</a><br/>
<?php
}else{
}
?>
</td>
</tr>
</table>
</fieldset>
</td>
<td width="75%">
<?php
include ("connect.php");
$result = mysql_query("SELECT * FROM staffleave WHERE leaveApprove = '' ORDER BY leaveNo DESC");   


echo "<div id='mainpage'>";
echo "<table width='70%'>";
echo "<caption><img src='Picture/salary.gif' width='30' height='30' />Daily Bookstore Management System - Leave</caption>";

echo "<div>";

echo "<table border='1' cellspacing='0' cellpadding='5' bordercolor='white' align='center' width='80%'>";

echo "<tr bgcolor='gray' style='color:lightblue'>";
echo "<td width='3'>No.</td>";
echo "<td width='50'>Form ID</td>";
echo "<td width='150'>Staff Name</td>";
echo "<td width='150'>Start Date</td>";
echo "<td width='150'>End Date</td>";
echo "<td width='50'>Total Leave</td>";
echo "<td>View</td>";
echo "</tr>";

$num_results = mysql_num_rows($result);
if($num_results!=0){
	for($i=0;$i<$num_results;$i++){
	$row = mysql_fetch_array($result);
	echo "<tr>";
	echo "<td>".($i + 1)."</td>";
	echo "<td>".$row["leaveNo"]."</td>";
	echo "<td>".$row["staffName"]."</td>";
	echo "<td>".$row["leaveStartDate"]."</td>";
	echo "<td>".$row["leaveEndDate"]."</td>";
	echo "<td>".$row["totalLeave"]."</td>";
	echo "<td><a href='viewleave.php?leaveNo=".$row["leaveNo"]."'>View</a></td>";
	echo "</tr>";
	}
}else{
echo "<td colspan='8' align='center'>No New Leave Apply Here.</td>";
}

echo "</table>";
echo "</div>";

echo "<hr/>";
$db = mysql_close();
?>
</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>