Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
255 lines (220 sloc) 11.7 KB
<?php
require("../dbCon.php");
$sql = "SELECT * FROM customers WHERE CustomerID = '" . $_SESSION["CustomerID"] . "'";
//echo $sql;
if (!$result = $con->query($sql)) {}
$row = $result->fetch_assoc();
if ($row) {
$CompanyName = $row['CompanyName'];
$ContactName = $row['ContactName'];
$ContactTitle = $row['ContactTitle'];
$Address = $row['Address'];
$City = $row['City'];
$Region = $row['Region'];
$PostalCode = $row['PostalCode'];
$Country = $row['Country'];
$Phone = $row['Phone'];
$Fax = $row['Fax'];
}
//echo "Welcome " . $_SESSION["userName"] . "!";
?>
<html>
<head>
<link rel="stylesheet" href="../style.css">
</head>
<body>
<div id="header">
<ul id="menu" class="blue">
<li><a href="cDashboard.php">Home</a></li>
<li><a href="cEditProfile.php">Edit Profile</a></li>
<li><a href="cSearchProduct.php">Search Product</a></li>
<li class="active"><a href="cCreateOrder.php">Create Order</a></li>
<li><a href="cPayment.php">Payment</a></li>
<li><a href="cCart.php">Cart</a></li>
<li><a href="cPastOrders.php">Past Orders</a></li>
<li class='fRight'><a href="logout.php">Log Out</a></li>
</ul>
</div>
<?php
if(!isset($_SESSION['shoppingCart']) || $_SESSION['shoppingCart'] === ""){
?>
<div class='form-group'>
<h3>Please add at least one item first!</h3>
</div>
<?php
}else{
?>
<div id='contentwrapper' class="form-group">
<script>
function changeCartQuantity(quantityID) {
productID = quantityID.split("_")[1];
shoppingCart = document.getElementById('shoppingCart').value;
orders = shoppingCart.split(" ");
shoppingCart = "";
for (index = 0; index < orders.length; ++index) {
if(orders[index].split("_")[0] === productID){
shoppingCart = shoppingCart + productID + "_" + document.getElementById(quantityID).value + " ";
}else{
shoppingCart = shoppingCart + orders[index] + " ";
}
}
// shoppingCart = shoppingCart.replace(" " + productID + /_[0-9]+$/i, " " + productID + "_" + document.getElementById(quantityID).value);
document.getElementById('shoppingCart').value = shoppingCart.trim();
return 1;
}
/*
function getQuantityOfProductID(quantityID) {
if (empty($_SESSION['shoppingCart'])) {
return 1;
}else{
productID = quantityID.split("_")[1];
shoppingCart = $_SESSION['shoppingCart'];
orders = shoppingCart.split(" ");
shoppingCart = "";
for (index = 0; index < orders.length; ++index) {
if(orders[index].split("_")[0] === productID){
shoppingCart = shoppingCart + productID + "_" + document.getElementById(quantityID).value + " ";
}else{
shoppingCart = shoppingCart + orders[index] + " ";
}
}
// shoppingCart = shoppingCart.replace(" " + productID + /_[0-9]+$/i, " " + productID + "_" + document.getElementById(quantityID).value);
document.getElementById('shoppingCart').value = shoppingCart.trim();
return 1;
}
}
*/
</script>
<?php
// if (!empty($_SESSION)) {
$shoppingCart = $_SESSION['shoppingCart'];
$shoppingCart = explode(" ", $shoppingCart);
echo "<table id='niceTable'>
<tr>
<th>Product</th>
<th>Category</th>
<th>Company</th>
<th>Quantity</th>
<th>Price</th>
<th>Stock</th>
<th>Amount</th>
</tr>";
foreach ($shoppingCart as $productID_Quantity){
$productID = explode("_", $productID_Quantity)[0];
$quantity = explode("_", $productID_Quantity)[1];
$query ="SELECT * FROM
((products as p LEFT JOIN suppliers as s ON p.SupplierID = s.SupplierID)
LEFT JOIN categories c ON p.CategoryID = c.CategoryID)
LEFT JOIN company co ON s.CompanyId = co.CompanyID
WHERE
ProductID = " . $productID;
$stmt = $con->prepare($query);
$stmt ->execute();
$result = $stmt->get_result();
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['ProductName'] . "</td>";
echo "<td>" . $row['CategoryName'] . "</td>";
echo "<td>" . $row['CompanyName'] . "</td>";
echo "<td>" . $row['QuantityPerUnit'] . "</td>";
echo "<td>" . "$" . number_format($row['UnitPrice'], 2) . "</td>";
echo "<td>" . $row['UnitsInStock'] . "</td>";
echo "<td>"
. "<input type='text' value='" . $quantity . "' "
. "name='QProductID_" . $row['ProductID'] . "' "
. "id='QProductID_" . $row['ProductID'] . "' required "
. "onchange='changeCartQuantity(this.id)'>"
. "</td>";
}
echo "</tr>";
// echo $productID;
}
echo "</table>";
// }
?>
<hr>
<form action = "cCreateOrder_save.php" method = "GET">
<div id="contentwrapperLeft" class="form-group">
<label>Required By</label>
<input type='date' name='RequiredBy' id='RequiredBy' required value='<?php //Set default date to 1 week from today, not actually an error like NetBeans says it is
$nextWeek = mktime(0, 0, 0, date("m"), date("d")+7, date("Y"));
echo date("Y-m-d", $nextWeek);
?>'>
<label>Select Delivery Method</label>
<select name="DeliveryMethod" id="DeliveryMethod">
<?php
$query ="SELECT * FROM deliverytype";
$stmt = $con->prepare($query);
$stmt ->execute();
$result = $stmt->get_result();
while($row = mysqli_fetch_array($result))
{
echo "<option value='" . $row['DeliveryTypeId'] . "'>" . $row['DeliveryTypeName'] . " - " . $row['Description'] . "</option>";
}
?>
</select>
<label>Select Shipment Method</label>
<select name="ShipmentMethod" id="ShipmentMethod">
<?php
$query ="SELECT * FROM shipmenttype";
$stmt = $con->prepare($query);
$stmt ->execute();
$result = $stmt->get_result();
while($row = mysqli_fetch_array($result))
{
echo "<option value='" . $row['ShipmentTypeId'] . "'>" . $row['ShipmentTypeName'] . " - " . $row['Description'] . "</option>";
}
?>
</select>
<label>Select Shipment Company</label>
<select name="ShipmentCompany" id="ShipmentCompany">
<?php
$query ="SELECT * FROM shippers s LEFT JOIN company c ON s.CompanyId = c.CompanyID";
$stmt = $con->prepare($query);
$stmt ->execute();
$result = $stmt->get_result();
while($row = mysqli_fetch_array($result))
{
echo "<option value='" . $row['ShipperID'] . "'>" . $row['CompanyName'] . "</option>";
}
?>
</select>
</div>
<div id="contentwrapperRight" class="form-group">
<label>Name</label>
<input type="text" name='Name' id='Name' required value='<?php echo $ContactName;?>'/>
<label>Address</label>
<input type="text" name='Address' id='Address' required value='<?php echo $Address;?>'/>
<label>City</label>
<input type="text" name='City' id='City' required value='<?php echo $City;?>'/>
<label>Region</label>
<input type="text" name='Region' id='Region' value='<?php echo $Region;?>'/>
<label>Postal Code</label>
<input type="text" name='PostalCode' id='PostalCode' value='<?php echo $PostalCode;?>'/>
<label>Country</label>
<input type="text" name='Country' id='Country' value='<?php echo $Country;?>'/>
</div>
<!-- <input type="text" name='shoppingCart' id='shoppingCart' value="" style='display: none'/> -->
<input type="text" name='shoppingCart' id='shoppingCart' value='<?php
if (empty($_SESSION['shoppingCart'])) {
$shoppingCart = $_SESSION['shoppingCart'];
$shoppingCart = explode(" ", $shoppingCart);
$shoppingCart = "";
foreach ($shoppingCart as $productID_Quantity){
$productID = explode("_", $productID_Quantity)[0];
$quantity = explode("_", $productID_Quantity)[1];
$shoppingCart = $shoppingCart . $productID . "_" . $quantity . " ";
}
$shoppingCart = trim($shoppingCart);
echo $shoppingCart;
}else{
echo $_SESSION['shoppingCart'];
}
?>' style='display: none'/>
<input type="submit" value="Create Order">
</form>
</div>
</body>
</html>
<?php }
You can’t perform that action at this time.