Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
DatabasesPhase2_GroupE/commonFunctions.php
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
247 lines (215 sloc)
8.7 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function writeMenuEmp($curPage){ | |
$menuItems = array( | |
"eDashboard.php" => array("Home",""), | |
"eOrdersToFill.php" => array("Active Orders",""), | |
"eEditProducts.php" => array("Search/Edit Products",""), | |
"eEditCategories.php" => array("Edit Categories",""), | |
"eReviewCustomerDemographics.php" => array("Review Customer Information",""), | |
"logout.php" => array("Log Out","class='fRight'") | |
); | |
$menuItems[$curPage][1] = "class='active'"; | |
echo "<ul id='menu' class='blue'>"; | |
foreach($menuItems as $page => $pageArgs) { | |
echo "<li " . $pageArgs[1] . "><a href='" . $page . "'>" . $pageArgs[0] . "</a></li>"; | |
} | |
echo "</ul>"; | |
/* echo " | |
<ul id='menu' class='blue'> | |
<li><a href='eDashboard.php'>Home</a></li> | |
<li class='active'><a href='eOrdersToFill.php'>Active Orders</a></li> | |
<li><a href='eEditProducts.php'>Search/Edit Products</a></li> | |
<li><a href='eEditCategories.php'>Edit Categories</a></li> | |
<li><a href='eReviewCustomerDemographics.php'>Review Customer Information</a></li> | |
<li class='fRight'><a href='logout.php'>Log Out</a></li> | |
</ul> | |
"; | |
*/ | |
} | |
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=array("",array("" => ""))) { | |
$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>'; | |
// onclick=\"window.document.location='cViewOrder.php?orderID=" . $row['orderID'] | |
// onclick=\"window.document.location='cViewOrder.php?orderID=%orderID% | |
foreach ($result as $x) { | |
$trArgsS = $trArgs[0]; | |
if ($trArgsS <> ""){ | |
foreach($trArgs[1] as $sString => $varID) { //Replace each search string given in $trArgs with actual value | |
$trArgsS = str_replace($sString, $x[$varID], $trArgsS); | |
} | |
} | |
echo $trArgsS . " "; | |
echo '<tr ' . $trArgsS . '>'; | |
foreach ($x as $y) { | |
echo '<td>' . $y . '</td>'; | |
} | |
echo '</tr>'; | |
} | |
echo '</tbody>'; | |
} | |
?> | |
<script> | |
function goBack() { | |
window.history.back(); | |
} | |
</script> |