Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
No commit message
  • Loading branch information
Josh authored and Josh committed Nov 27, 2016
0 parents commit 8740ed6
Show file tree
Hide file tree
Showing 27 changed files with 2,400 additions and 0 deletions.
206 changes: 206 additions & 0 deletions commonFunctions.php
@@ -0,0 +1,206 @@
<?php
function orderCustomer($orderID) { //Get the customerID of the whomever placed this order
global $con;
$sql = "SELECT CustomerID from orders WHERE OrderID=" . $orderID;
$result = $con->query($sql);
$row = $result->fetch_assoc();
return $row['CustomerID'];
}
function displayOrder($orderID) {
global $con;
$sql = "SELECT o.orderID, customerID, OrderDate, s.RequiredDate, CONCAT(e.FirstName, ' ', e.LastName) as employeeName, s.*, p.*, pt.Name as ptName
FROM
((((orders o LEFT JOIN employees e ON o.EmployeeID = e.EmployeeID)
LEFT JOIN shipments sh ON o.OrderID = sh.OrderID)
LEFT JOIN shipaddresses s ON sh.ShipmentsID = s.ShipAddrID)
LEFT JOIN payment p ON o.orderID = p.orderID)
LEFT JOIN paymenttype pt ON pt.paymenttypeid = p.paymenttypeid
WHERE o.orderID =" . $orderID;
// echo $sql;
$result = $con->query($sql);
$row = $result->fetch_assoc();
if ($row) {
$address = $row['ShipAddress'] . ", " . $row['ShipCity'] . "<br>" . $row['ShipRegion'] . " " . $row['ShipPostalCode'] . ", " . $row['ShipCountry'];

echo "<tr onclick=\"window.document.location='cViewOrder.php?orderID=" . $row['orderID'] . "'\">
<td>" . $row['employeeName'] . "</td>
<td>" . explode(" ", $row['OrderDate'])[0] . "</td>
<td>" . explode(" ", $row['RequiredDate'])[0] . "</td>
<td>" . explode(" ", $row['ShippedDate'])[0] . "</td>
<td>" . $row['Freight'] . "</td>
<td>" . $row['ShipName'] . "</td>
<td>" . $address . "</td>
<td>" . "$" . number_format($row['Total'], 2) . "</td>
<td>" . $row['ptName'] . "</td>
</tr>";
}
}

function displayOrders($customerID, $orderID = 0) {
global $con;

if($orderID <> 0){
$sql = "SELECT OrderID FROM orders WHERE OrderID=" . $orderID;
}else{
$sql = "SELECT OrderID FROM orders WHERE customerID='" . $customerID . "'
ORDER BY OrderDate DESC";
}
$result = $con->query($sql);

/*
$stmt = $con->prepare($query);
$stmt ->execute();
$result = $stmt->get_result();
*/
if ($result->num_rows > 0) {

echo "<table id='niceTable'>
<tr>
<th>Assigned to</th>
<th>Ordered on</th>
<th>Required by</th>
<th>Shipped on</th>
<th>Freight</th>
<th>Ship to</th>
<th>Ship address</th>
<th>Total Paid</th>
<th>Paid Via</th>
</tr>";

while($row = $result->fetch_assoc()) {
echo displayOrder($row['OrderID']);

}

echo "</table>";
}
}

function displayOrderDetails($orderID) {
global $con;

$sql = "SELECT * FROM
(((`order details` od LEFT JOIN products p ON od.ProductID = p.ProductID)
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 orderid = " . $orderID . "
order by od.ProductID ASC";

$result = $con->query($sql);

if ($result->num_rows > 0) {

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 Ordered</th>
<th>Sub-total</th>
</tr>";

while($row = $result->fetch_assoc()) {
echo "<tr onclick=\"window.document.location='cViewProduct.php?productID=" . $row['ProductID'] . "'\">
<td>" . $row['ProductName'] . "</td>
<td>" . $row['CategoryName'] . "</td>
<td>" . $row['CompanyName'] . "</td>
<td>" . $row['QuantityPerUnit'] . "</td>
<td>" . "$" . number_format($row['UnitPrice'], 2) . "</td>
<td>" . $row['UnitsInStock'] . "</td>
<td>" . $row['Quantity'] . "</td>
<td>" . "$" . number_format($row['Quantity'] * $row['UnitPrice'],2) . "</td>
</tr>";

}

echo "</table>";
}
}

function displayProduct($productID) {
global $con;

$sql = "SELECT * FROM
((products 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 . "
order by ProductID ASC";

$result = $con->query($sql);
$row = $result->fetch_assoc();
if ($row) {
echo "<table id='niceTable'>
<tr>
<th>Product</th>
<th>Category</th>
<th>Company</th>
<th>Quantity</th>
<th>Price</th>
<th>Stock</th>
</tr>";

echo "<tr onclick=\"window.document.location='cViewProduct.php?productID=" . $row['ProductID'] . "'\">
<td>" . $row['ProductName'] . "</td>
<td>" . $row['CategoryName'] . "</td>
<td>" . $row['CompanyName'] . "</td>
<td>" . $row['QuantityPerUnit'] . "</td>
<td>" . "$" . number_format($row['UnitPrice'], 2) . "</td>
<td>" . $row['UnitsInStock'] . "</td>
</tr>";

echo "</table>";

echo "<hr>";
loadPicture($row['Picture']);
}
}
function loadPicture($blob, $widthPercent=100){
echo '<img src="data:image/jpeg;base64,'.base64_encode($blob).'" width=' . $widthPercent . '%/>';
}

function makeTable($result, $trArgs="") {
$result->fetch_array( MYSQLI_ASSOC );
echo "<table id='niceTable'>";
tableHead( $result );
tableBody( $result, $trArgs="" );
echo '</table>';
}

function tableHead($result) {
echo '<thead>';
foreach ($result as $x) {
echo '<tr>';
foreach ($x as $k => $y) {
echo '<th>' . ucfirst($k) . '</th>';
}
echo '</tr>';
break;
}
echo '</thead>';
}

function tableBody($result, $trArgs="") {
echo '<tbody>';
foreach ($result as $x) {
echo '<tr ' . $trArgs . '>';
foreach ($x as $y) {
echo '<td>' . $y . '</td>';
}
echo '</tr>';
}
echo '</tbody>';
}

?>

<script>
function goBack() {
window.history.back();
}
</script>
190 changes: 190 additions & 0 deletions customerPages/cCart.php
@@ -0,0 +1,190 @@
<?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'];
}

//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><a href="cCreateOrder.php">Create Order</a></li>
<li><a href="cPayment.php">Payment</a></li>
<li class="active"><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['RequiredBy']) || !isset($_SESSION['PaymentType'])){
?>
<div class='form-group'>
<h3>Please complete payment options first!</h3>

</div>

<?php
}else{
?>
<div id='contentwrapperShort' class='form-group'>

<h1>Shipping Summary</h1>
<div id='contentwrapperRight'>
<table id='niceTable'>
<tr><td>Required By</td><td><?php echo $_SESSION['RequiredBy'];?></td></tr>

<tr><td>Delivery Type</td><td><?php
$query ="SELECT * FROM DeliveryType WHERE DeliveryTypeID = " . $_SESSION['DeliveryMethod'];
$stmt = $con->prepare($query);
$stmt ->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();
echo $row['DeliveryTypeName'] . " - " . $row['Description'];
?></td></tr>

<tr><td>Shipment Type</td><td><?php
$query ="SELECT * FROM ShipmentType WHERE ShipmentTypeID = " . $_SESSION['ShipmentMethod'];
$stmt = $con->prepare($query);
$stmt ->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();
echo $row['ShipmentTypeName'] . " - " . $row['Description'];
?></td></tr>

<tr><td>Shipped By</td><td><?php
$query ="SELECT * FROM shippers s LEFT JOIN company c ON s.CompanyId = c.CompanyID WHERE c.CompanyId = " . $_SESSION['ShipmentCompany'];
$stmt = $con->prepare($query);
$stmt ->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();
echo $row['CompanyName'];
?></td></tr>
</table>

</div>
<div id='contentwrapperLeft'>
<table id='niceTable'>
<tr><td>Ship to</td><td><?php echo $_SESSION['Name'];?></td></tr>
<tr><td>Address</td><td><?php echo $_SESSION['Address'];?></td></tr>
<tr><td>City</td><td><?php echo $_SESSION['City'];?></td></tr>
<tr><td>Region</td><td><?php echo $_SESSION['Region'];?></td></tr>
<tr><td>Postal Code</td><td><?php echo $_SESSION['PostalCode'];?></td></tr>
<tr><td>Country</td><td><?php echo $_SESSION['Country'];?></td></tr>
</table>

</div>
</div>
<hr>
<div id='contentwrapper' class='form-group'>
<h1>Order Summary</h1>
<form action = "cCart_save.php" method = "POST">
<?php
// echo "Welcome " . EXPLODE(" ",$ContactName)[0] . "!";
$_SESSION['confirmationCode'] = $random_hash = substr(md5(uniqid(rand(), true)), 8, 24);
$_SESSION['fqPayment'] = " INSERT INTO payment (OrderID, Total, PaymentTypeID, ConfNum) VALUES (" .
"(SELECT MAX(OrderID) FROM orders), " .
$_SESSION['TotalDue'] . ", " .
$_SESSION['PaymentType'] . ", " .
"'" . $_SESSION['confirmationCode'] . "');";
$_SESSION['finInsert'] = $_SESSION['fqOrder'] . $_SESSION['fqOrderDetailsInsert'] . $_SESSION['fqShipments'] . $_SESSION['fqShipAddresses'] . $_SESSION['fqPayment'];
// echo $_SESSION['fqOrder'] . $_SESSION['fqOrderDetailsInsert'] . $_SESSION['fqShipments'] . $_SESSION['fqShipAddresses'] . $fqPayment;
// echo $_SESSION['finInsert'];
// echo $_SESSION['fqOrderDetailsInsert'];

// 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>
<th>Sub-total</th>
</tr>";
foreach ($shoppingCart as $productID_Quantity){
$productID = explode("_", $productID_Quantity)[0];
$productQuantity = 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>" . $productQuantity . "</td>";
echo "<td>" . "$" . number_format($productQuantity * $row['UnitPrice'],2) . "</td>";
}

echo "</tr>";

// echo $productID;
}
echo "</table>";
// }

$query ="SELECT * FROM paymenttype WHERE PaymentTypeID = " . $_SESSION['PaymentType'];
$stmt = $con->prepare($query);
$stmt ->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();

echo "<hr><h1>A total of $" . number_format($_SESSION['TotalDue'],2) . " will be deducted from your " . $row['Name'] . "</h1>";
// echo $fqOrder . "<hr>" . $fqOrderDetailsInsert . "<hr>" . $fqShipments . "<hr>" . $fqShipAddresses;
?>


<hr>


<div class="form-group">


<!-- <input type='text' name='finalQuery' id='finalQuery' value='<?php
// echo $fqOrder . $fqOrderDetailsInsert . $fqShipments . $fqShipAddresses; ?>' style='display: none'/> -->
<input type="submit" value="Place Order">
</div>
</form>
</div>
</body>



</html>
<?php
}
?>

0 comments on commit 8740ed6

Please sign in to comment.