Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Finished up employee pages (customer dems advanced search doesn't rea…
…lly work but it would be a ton of work to fix it so I'm ok with that)
  • Loading branch information
Josh authored and Josh committed Dec 4, 2016
1 parent 20a01d2 commit 662d9f2
Show file tree
Hide file tree
Showing 6 changed files with 688 additions and 4 deletions.
78 changes: 78 additions & 0 deletions employeePages/eEditCategories.php
@@ -0,0 +1,78 @@
<?php
require("../dbCon.php");
require("../commonFunctions.php");

if (isset($_GET['NewCatName'])){ //Add new category
$query = "INSERT INTO categories (CategoryName, Description) VALUES (?, ?)";
$stmt = $con->prepare($query);
$stmt ->bind_param("ss", $_GET['NewCatName'], $_GET['NewCatDesc']);
$stmt ->execute();
}elseif (isset($_GET['NewName'])){ //Update old category
$query = "UPDATE categories SET CategoryName = ?, Description = ? WHERE CategoryID = ?";
$stmt = $con->prepare($query);
$stmt ->bind_param("ssd", $_GET['NewName'], $_GET['NewDesc'], $_GET['Category']);
$stmt ->execute();
}

?>

<html>
<head>
<link rel="stylesheet" href="../style.css">
</head>
<body>
<div id="header">
<?php writeMenuEmp(basename($_SERVER['PHP_SELF'])); ?>
</div>

<div id="contentwrapper">
<div id="contentwrapperLeft">

<form action = "eEditCategories.php" method = "get">
<h1>Add Category</h1>
<div class="form-group">
<label>Name</label>
<input type="text" name="NewCatName" id="NewCatName" required>

<label>Description</label>
<input type="text" name="NewCatDesc" id="NewCatDesc" required>

<input type="submit" value="Create Category">
</div>
</form>
</div>

<div id="contentwrapperRight">
<form action = "eEditCategories.php" method = "get">
<h1>Edit Category</h1>
<div class="form-group">
<label>Category to Edit</label>
<select name="Category" id="Category" onchange="updateCatNameDesc()">
<?php
$query ="SELECT * FROM categories";
$stmt = $con->prepare($query);

$stmt ->execute();
$result = $stmt->get_result();
while($row = mysqli_fetch_array($result)) {
echo "<option value='" . $row['CategoryID'] . "'>" . $row['CategoryName'] . "</option>";
}
?>
</select>

<label>New Name</label>
<input type="text" name="NewName" id="NewName" required>

<label>New Description</label>
<input type="text" name="NewDesc" id="NewDesc" required>

<input type="submit" value="Update Category">
</div>
</form>
</div>
</div>
</body>



</html>
168 changes: 168 additions & 0 deletions employeePages/eEditProducts.php
@@ -0,0 +1,168 @@
<?php
require("../dbCon.php");
require("../commonFunctions.php");

$sql = "SELECT * FROM employees WHERE EmployeeID = '" . $_SESSION["EmployeeID"] . "'";
//echo $sql;
if (!$result = $con->query($sql)) {}

$row = $result->fetch_assoc();
if ($row) {
$FirstName = $row['FirstName'];
$Photo = $row['Photo'];

}

//echo "Welcome " . $_SESSION["userName"] . "!";
?>

<html>
<head>
<link rel="stylesheet" href="../style.css">
</head>
<body>
<div id="header">
<?php writeMenuEmp(basename($_SERVER['PHP_SELF'])); ?>
</div>
<form action = "eNewProduct.php" class="form-group" style='display: block; margin: auto; width: 960px;'>
<input type="submit" value="New Product">
</form>

<hr>
<div id="contentwrapper">
<div id='contentwrapperLeft'>

<form action = "eEditProducts.php" method = "get">
<h1>Simple Search</h1>
<div class="form-group">
<input type="text" name="SimpleSearch" id="SimpleSearch" required value="<?php
if(isset($_GET['SimpleSearch'])){echo $_GET['SimpleSearch'];}?>">
<input type="submit" value="Search">

</div>
</form>
</div>
<div id="contentwrapperRight">

<form action = "eEditProducts.php" method = "get">
<h1>Advanced Search</h1>
<div class="form-group">
<label>Product Name</label>
<input type="text" name="ProductName" id="ProductName" value="<?php
if(isset($_GET['ProductName'])){echo $_GET['ProductName'];}?>">
<label>Category</label>
<select name="Category" id="Category">
<option value=""></option>
<?php
$category = "";
if(isset($_GET['Category'])){
$category = $_GET['Category'];
}

$query ="SELECT * FROM categories";
$stmt = $con->prepare($query);

$stmt ->execute();
$result = $stmt->get_result();
while($row = mysqli_fetch_array($result))
{
echo "<option ";
if($row['CategoryName'] === $category){
echo "selected='selected'";
}
echo "value='" . $row['CategoryName'] . "'>" . $row['CategoryName'] . "</option>";
}
?>
</select>
<label>Company Name</label>
<input type="text" name="CompanyName" id="CompanyName" value="<?php
if(isset($_GET['CompanyName'])){echo $_GET['CompanyName'];}?>">
<label>Unit Price Greater Than</label>
<input type="text" name="UnitPriceLow" id="UnitPriceLow" value="<?php
if(isset($_GET['UnitPriceLow'])){echo $_GET['UnitPriceLow'];}?>">
<label>Unit Price Less Than</label>
<input type="text" name="UnitPriceHigh" id="UnitPriceHigh" value="<?php
if(isset($_GET['UnitPriceHigh'])){echo $_GET['UnitPriceHigh'];}?>">

<input type="submit" value="Search">
</div>
</form>
</div>
</div>
<div id='contentwrapper'>
<?php
if (empty($_GET)) { //Show all products by default
$query ="SELECT 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
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";

$stmt = $con->prepare($query);

}elseif (isset($_GET["SimpleSearch"]) && !empty($_GET["SimpleSearch"])) { //Simple search
$query ="SELECT 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
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
CategoryName LIKE ? OR
ProductName LIKE ? OR
CompanyName LIKE ?";

$SimpleSearch = "%" . $_GET['SimpleSearch'] . "%";
$stmt = $con->prepare($query);
$stmt ->bind_param("sss", $SimpleSearch, $SimpleSearch, $SimpleSearch);

}else{ //Advanced search

$query ="SELECT 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
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
ProductName LIKE ? AND
CompanyName LIKE ? AND
CategoryName LIKE ? AND
UnitPrice > ? AND
UnitPrice < ?";

$ProductName = "%" . $_GET['ProductName'] . "%";
$CompanyName = "%" . $_GET['CompanyName'] . "%";
$Category = "%" . $_GET['Category'] . "%";
if (empty($_GET["UnitPriceLow"])){
$UnitPriceLow = 0.00;
}else{
$UnitPriceLow = number_format($_GET['UnitPriceLow'], 2);
}
if (empty($_GET["UnitPriceHigh"])){
$UnitPriceHigh = 10000000.00;
}else{
$UnitPriceHigh = number_format($_GET['UnitPriceHigh'], 2);
}
$stmt = $con->prepare($query);
$stmt ->bind_param("sssdd", $ProductName, $CompanyName, $Category, $UnitPriceLow, $UnitPriceHigh);

}

$stmt ->execute();
$result = $stmt->get_result();

$trArgs = array("onclick=\"window.document.location='eViewProduct.php?productID=%ProductID%'\"",
array('%ProductID%' => '_ProductID')
);
makeTable($result, $trArgs);


?>
</div>
</body>



</html>
77 changes: 77 additions & 0 deletions employeePages/eNewProduct.php
@@ -0,0 +1,77 @@
<?php
require("../dbCon.php");
require("../commonFunctions.php");

if (isset($_GET['ProductName'])){
$query = "INSERT INTO products (ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued)
VALUES(?,?,?,?,?,?,?,?,?)";
$zero = 0;
$stmt = $con->prepare($query);
$stmt ->bind_param("sddsddddd", $_GET['ProductName'], $_GET['SupplierID'], $_GET['CategoryID'], $_GET['QuantityPerUnit'], $_GET['UnitPrice'], $zero, $zero, $_GET['ReorderLevel'], $zero);

$stmt ->execute();

header("Location:cEditProducts.php");
// $con->query($query);
}
?>

<html>
<head>
<link rel="stylesheet" href="../style.css">
</head>
<body>
<div id="header">
<?php writeMenuEmp("eEditProducts.php"); ?>
</div>
<div id="contentwrapper">
<form action = "eNewProduct.php" method = "get">
<h1>New Product</h1>
<div class="form-group">
<label>Product Name</label>
<input type="text" name="ProductName" id="ProductName" required>

<label>Supplier</label>
<select name="SupplierID" id="SupplierID">
<?php
$query ="SELECT * FROM suppliers 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['SupplierID'] . "'>" . $row['CompanyName'] . "</option>";
}
?>
</select>

<label>Category</label>
<select name="CategoryID" id="CategoryID">
<?php
$query ="SELECT * FROM categories";
$stmt = $con->prepare($query);
$stmt ->execute();
$result = $stmt->get_result();
while($row = mysqli_fetch_array($result)){
echo "<option value='" . $row['CategoryID'] . "'>" . $row['CategoryName'] . "</option>";
}
?>
</select>

<label>Quantity Per Unit</label>
<input type="text" name="QuantityPerUnit" id="QuantityPerUnit" required>

<label>Unit Price</label>
<input type="text" name="UnitPrice" id="UnitPrice" required>

<label>Reorder Level</label>
<input type="text" name="ReorderLevel" id="ReorderLevel" required>

<input type="submit" value="Add Product">
</div>
</form>
</div>
</body>



</html>

0 comments on commit 662d9f2

Please sign in to comment.