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.
320 lines (281 sloc)
12.6 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 writeMenuCust($activePage){ | |
//Menu items given in form (Page, (display name, class args)) | |
$menuItems = array( | |
"cDashboard.php" => array("Home", ""), | |
"cEditProfile.php" => array("Edit Profile", ""), | |
"cSearchProduct.php" => array("Search Product", ""), | |
"cCreateOrder.php" => array("Create Order", ""), | |
"cPayment.php" => array("Payment", ""), | |
"cCart.php" => array("Cart", ""), | |
"cPastOrders.php" => array("Past Orders", ""), | |
"logout.php" => array("Log Out", "class='fRight'") | |
); | |
$menuItems[$activePage][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>"; | |
} | |
function writeMenuEmp($activePage){ | |
//Menu items given in form (Page, (display name, class args)) | |
$menuItems = array( | |
"Dashboard.php" => array("Home", ""), | |
"OrdersToFill.php" => array("Active Orders", ""), | |
"AllOrders.php" => array("All Orders", ""), | |
"EditProducts.php" => array("Search/Edit Products", ""), | |
"EditCategories.php" => array("Edit Categories", ""), | |
"ReviewCustomerDemographics.php" => array("View Customers", ""), | |
"logout.php" => array("Log Out", "class='fRight'") | |
); | |
$menuItems[$activePage][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>"; | |
} | |
function writeMenuAdm($activePage){ | |
//Menu items given in form (Page, (display name, class args)) | |
$menuItems = array( | |
"Dashboard.php" => array("Home", ""), | |
"AllOrders.php" => array("All Orders", ""), | |
"EditProducts.php" => array("Search/Edit Products", ""), | |
"EditCategories.php" => array("Edit Categories", ""), | |
"ReviewCustomerDemographics.php" => array("View Customers", ""), | |
"Employees.php" => array("View Employees", ""), | |
"Reports.php" => array("Reports", ""), | |
"logout.php" => array("Log Out", "class='fRight'") | |
); | |
$menuItems[$activePage][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>"; | |
} | |
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 displayOrders($customerID, $orderID = 0) { | |
global $con; | |
if($orderID <> 0){ | |
$where = " WHERE o.OrderID=" . $orderID . " "; | |
}else{ | |
$where = " WHERE customerID='" . $customerID . "' "; | |
} | |
$sql = "SELECT | |
o.OrderID as _OrderID, | |
CONCAT(e.FirstName, ' ', e.LastName) as Employee, | |
DATE_FORMAT(OrderDate, '%m-%d-%Y') as `Order Date`, DATE_FORMAT(s.RequiredDate, '%m-%d-%Y') as `Required Date`, DATE_FORMAT(ShippedDate, '%m-%d-%Y') as `Shipped Date`, | |
Freight, ShipName as `Ship To`, | |
CONCAT(ShipAddress, ', ', ShipCity, '<br>', ShipRegion, ' ', ShipPostalCode, ', ', ShipCountry) as `Ship Address`, | |
CONCAT('$', FORMAT(Total,2)) as Total, pt.Name as `Paid Via` | |
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 . " ORDER BY OrderDate DESC"; | |
$result = $con->query($sql); | |
$trArgs = array("onclick=\"window.document.location='cViewOrder.php?orderID=%OrderID%'\"", | |
array('%OrderID%' => '_OrderID') | |
); | |
makeTable($result, $trArgs); | |
} | |
/* | |
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); | |
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 | |
p.ProductID as _ProductID, | |
ProductName as Product, | |
CategoryName as Category, | |
CompanyName as Company, | |
QuantityPerUnit as Quantity, | |
CONCAT('$', FORMAT(p.UnitPrice,2)) as Price, | |
UnitsInStock as Stock, | |
Quantity as `Amount Ordered`, | |
CONCAT('$', FORMAT(Quantity*p.UnitPrice,2)) as `Sub-total` | |
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); | |
$trArgs = array("onclick=\"window.document.location='cViewProduct.php?productID=%ProductID%'\"", | |
array('%ProductID%' => '_ProductID') | |
); | |
makeTable($result, $trArgs); | |
} | |
function displayProduct($productID) { | |
global $con; | |
$sql = "SELECT | |
ProductName as Product, | |
CategoryName as Category, | |
CompanyName as Company, | |
QuantityPerUnit as Quantity, | |
CONCAT('$', FORMAT(p.UnitPrice,2)) as Price, | |
UnitsInStock as Stock, | |
Picture as _Picture | |
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); | |
$trArgs = array("onclick=\"window.document.location='cViewProduct.php?productID=%ProductID%'\"", | |
array('%ProductID%' => '_ProductID') | |
); | |
makeTable($result); | |
/* | |
$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) { | |
if (substr(ucfirst($k),0,1) <> "_"){ //Underscore as first character indicates it shouldn't be displayed in table | |
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 $k => $y) { | |
if (substr(ucfirst($k),0,1) <> "_"){ //Underscore as first character indicates it shouldn't be displayed in table | |
echo '<td>' . $y . '</td>'; | |
} | |
} | |
echo '</tr>'; | |
} | |
echo '</tbody>'; | |
} | |
function getResult($query) { | |
global $con; | |
$stmt = $con->prepare($query); | |
$stmt ->execute(); | |
return $stmt->get_result(); | |
} | |
?> | |
<script> | |
function goBack() { | |
window.history.back(); | |
} | |
</script> |