<?php 
	include("includes/config.php");
	include("includes/func.php");
	
	if (($_SESSION['id'] == ""))
	{
		redirect("login");
	}
	
	include("templates/header.php");

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
?>
<script type="text/javascript">
 $(function() {
        $( "#datepicker" ).datepicker();
    });
function delete_check(id)
{
	if(confirm('Are you really want to delete!'))
	window.location.href = 'sales_listing.php?delete='+id;
	else
	return false;
}

function cancel_check()
{
	if(confirm('Are you really want to Cancel!'))
	window.location.href = 'sales_listing.php';
	else
	return false;
}

</script>
    <div id="mainPanel">
<h2>Add New Sale</h2>
<?php

$edit = "";
$update = "";
if(isset($_POST['sales']))
{
	$sold_date = $_POST['sold_date'];
	$d_m_y = explode("/", $sold_date);
	$m = $d_m_y[0];
	$d = $d_m_y[1];
	$y = $d_m_y[2];
	$sold_date = $y."-".$m."-".$d;
	$user_id = $_POST['user_id'];
	$product_id = $_POST['product_id'];
	$quantity_sold = $_POST['quantity_sold'];
/*	if($db->ConnectDB() == true)
	{
		$db->InsertSalesRow($sold_date, $user_id, $product_id, $quantity_sold);
		echo "<script type='text/javascript'>window.location.href='sales_listing.php'</script>";
	}*/
}
?>
<form name="sales_form" id="sales_form" action="" method="POST">
<table width="100%" cellpadding="0" cellspacing="0" border="0" id="tabling1">
<tr>
    <td nowrap width="34%" align="right"> <label>Sold Date:</label><span style="color:red">*</span></td>
    <td width="66%" nowrap><input type="text" name="sold_date" class="textfield1" id="datepicker" value="<?php echo date('m/d/Y');?>"/></td>
</tr>
<tr>
    <td nowrap width="34%" align="right"> <label>User Name:</label><span style="color:red">*</span></td>
    <td width="66%" nowrap>
    <select name="all_users" id="all_users" class="textfield1">
    <option value="">Select User*</option>
    	<?php
			$sql = "Select * from users";
			$results = mysql_query($sql);
			while($rows = mysql_fetch_array($results))
			{
				echo '<option value="'.$rows['id'].'">'.$rows['username'].'</option>';
			}
		?>
    </select>
    </td>
</tr>
<tr>
    <td nowrap width="34%" align="right"> <label>Product:</label><span style="color:red">*</span></td>
    <td width="66%" nowrap>
        <input type="text" readonly="true" name="product_id" id="product_id" value="" class="textfield1"/>
        <a href="category_product_thickbox.php?keepThis=true&TB_iframe=true&height=500&width=800" title="Order Managment" class="thickbox" ><span class="form_button">Select Product</span></a>
    </td>
</tr>
<tr>
    <td nowrap width="34%" align="right"> <label>Quantity Sold:</label><span style="color:red">*</span></td>
    <td width="66%" nowrap><input type="text" name="quantity_sold" id="quantity_sold" value="" class="textfield1"/></td>
</tr>
<tr>
    <td nowrap width="34%" align="right"></td>
    <td width="66%" nowrap><input type="submit" name="sales" id="sales" value="Add Sales" class="form_button"/><a href="#" onclick="cancel_check();" class="form_button">Cancel</a></td>
</tr>
</table>
</form> 
</body>
</html>