Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zhen Fu Final Project #7

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.DS_Store
*sftp-config.json
*auth.php
Binary file added fu.zhen/.DS_Store
Binary file not shown.
12 changes: 12 additions & 0 deletions fu.zhen/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Zhen Fu

## Relevant Links
- https://ariellands.com
- https://ariellands.com/aau/ixd608/fu.zhen
- https://ariellands.com/aau/ixd608/fu.zhen/styleguide
- http://ariellands.com/aau/ixd608/fu.zhen/admin

## Extra Links
- http://ariellands.com/aau/ixd608/fu.zhen/admin/users.php
- http://ariellands.com/aau/ixd608/fu.zhen/notes
- http://ariellands.com/aau/ixd608/fu.zhen/notes/reading_data.php
29 changes: 29 additions & 0 deletions fu.zhen/about.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>About</title>
<?php include "parts/meta.php"; ?>
</head>
<body>

<?php include "parts/navbar.php"; ?>
<div class="content">
<div class="container">
<div class="card soft">
<h2>About Us</h2>
<img src="img/zhen.JPG" class="about_img">
<p>Finding Jewelry provides different kinds of Jewelry that Zhen found. Zhen is passinoate about finding and
collecting jewelry. She would like to share her favorite jewelry with love to everyone. You will also find your favorite jewelry here. </p>



</div>
</div>
</div>

<?php include "parts/footer.php"; ?>

</body>
</html>
273 changes: 273 additions & 0 deletions fu.zhen/admin/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
<?php

include "../lib/php/functions.php";

$empty_product = (object) [
"name"=>"White Pearl Earring",
"category"=>"earring",
"price"=>"80",
"description"=>"Very white pearl earring!",
"thumbnail"=>"white_pearl_earring_thumbnail.jpg",
"images"=>"white_pearl_earring_thumbnail.jpg,white_pearl_earring_1.JPG,white_pearl_earring_2.jpg,white_pearl_earring_3.JPG,white_pearl_earring_4.JPG",
"quantity"=>"18"
];








// LOGIC
try {
$conn = makePDOConn();
switch($_GET['action']) {
case "update":
$statement = $conn->prepare("UPDATE
`products`
SET
`name` =?,
`price` =?,
`quantity` =?,
`category` =?,
`description` =?,
`thumbnail` =?,
`images` =?,
`date_modify` =NOW()
WHERE `id`=?
");
$statement->execute([
$_POST['product-name'],
$_POST['product-price'],
$_POST['product-quantity'],
$_POST['product-category'],
$_POST['product-description'],
$_POST['product-thumbnail'],
$_POST['product-images'],
$_GET['id']
]);
header("location:{$_SERVER['PHP_SELF']}?id={$_GET['id']}");
break;
case "create":
$statement = $conn->prepare("INSERT INTO
`products`
(
`name`,
`price`,
`quantity`,
`category`,
`description`,
`thumbnail`,
`images`,
`date_create`,
`date_modify`
)
VALUES (?,?,?,?,?,?,?,NOW(),NOW())
");
$statement->execute([
$_POST['product-name'],
$_POST['product-price'],
$_POST['product-quantity'],
$_POST['product-category'],
$_POST['product-description'],
$_POST['product-thumbnail'],
$_POST['product-images']
]);
$id = $conn->lastInsertId();
header("location:{$_SERVER['PHP_SELF']}?id=$id");
break;
case "delete":
$statement = $conn->prepare("DELETE FROM `products` WHERE id=?");
$statement->execute([$_GET['id']]);
header("location:{$_SERVER['PHP_SELF']}");
break;
}
} catch(PDOException $e) {
die($e->getMessage());
}









// TEMPLATES
function productListItem($r,$o) {
return $r.<<<HTML
<div class="card soft">
<div class="display-flex">
<div class="flex-none images-thumbs"><img src='img/$o->thumbnail'></div>
<div class="flex-stretch" sytle="padding:1em">$o->name</div>
<div class="flex-none"><a href="{$_SERVER['PHP_SELF']}?id=$o->id" class="form-button">Edit</a></div>
</div>
</div>
HTML;
}



function showProductPage($o) {


$id = $_GET['id'];
$addoredit = $id == "new" ? "Add" : "Edit";
$createorupdate = $id == "new" ? "create" : "update";
$images = array_reduce(explode(",", $o->images),function($r,$o){return $r."<img src='img/$o'>";});

// hereddoc
$display = <<<HTML
<div>
<h2>$o->name</h2>
<div class="form-control">
<label class="form-label">Price</label>
<span>&dollar;$o->price</span>
</div>
<div class="form-control">
<label class="form-label">Quantity</label>
<span>$o->quantity</span>
</div>
<div class="form-control">
<label class="form-label">Category</label>
<span>$o->category</span>
</div>
<div class="form-control">
<label class="form-label">Description</label>
<span>$o->description</span>
</div>
<div class="form-control">
<label class="form-label">Thumbnail</label>
<span class="images-thumbs"><img src='img/$o->thumbnail'></span>
</div>
<div class="form-control">
<label class="form-label">Other Images</label>
<span class="images-thumbs">$images</span>
</div>
</div>
HTML;

$form = <<<HTML
<form method="post" action="{$_SERVER['PHP_SELF']}?id=$id&action=$createorupdate">
<h2>$addoredit Product</h2>
<div class="form-control">
<label class="form-label" for="product-name">Name</label>
<input class="form-input" name="product-name" id="product-name" type="text" value="$o->name" placeholder="Enter the Product Name">
</div>
<div class="form-control">
<label class="form-label" for="product-price">Price</label>
<input class="form-input" name="product-price" id="product-price" type="Number" min="0" max="1000" step="0.01" value="$o->price" placeholder="Enter the Product Price">
</div>
<div class="form-control">
<label class="form-label" for="product-quantity">Quantity</label>
<input class="form-input" name="product-quantity" id="product-quantity" type="Number" min="0" max="1000" step="1" value="$o->quantity" placeholder="Enter the Product Quantity">
</div>
<div class="form-control">
<label class="form-label" for="product-category">Category</label>
<input class="form-input" name="product-category" id="product-category" type="text" value="$o->category" placeholder="Enter the Product Category">
</div>
<div class="form-control">
<label class="form-label" for="product-description">Description</label>
<textarea class="form-input" name="product-description" id="product-description" type="text" placeholder="Enter the Product Description">$o->description</textarea>
</div>
<div class="form-control">
<label class="form-label" for="product-thumbnail">Thumbnail</label>
<input class="form-input" name="product-thumbnail" id="product-thumbnail" type="text" value="$o->thumbnail" placeholder="Enter the Product Thumbnail">
</div>
<div class="form-control">
<label class="form-label" for="product-images">Images</label>
<input class="form-input" name="product-images" id="product-images" type="text" value="$o->images" placeholder="Enter the Product Images">
</div>
<div class="form-control">
<input class="form-button" type="submit" value="Save Changes">
</div>
</form>
HTML;

$output = $id == "new" ? "<div class='card soft'>$form</div>" :
"<div class='grid gap'>
<div class='col-xs-12 col-md-7'><div class='card soft'>$display</div></div>
<div class='col-xs-12 col-md-5'><div class='card soft'>$form</div></div>
</div>
";

$delete = $id == "new" ? "" : "<a href='{$_SERVER['PHP_SELF']}?id=$id&action=delete'>Delete</a>";

echo <<<HTML
<div class="card soft">
<nav class="display-flex">
<div class="flex-stretch"><a href="{$_SERVER['PHP_SELF']}">Back</a></div>
<div class="flex-none">$delete</div>
</nav>
</div>
$output
HTML;
}







?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<!-- <meta name="viewport" content="width=device-width, initial-scale=1.0"> -->
<title>Product Admin Page</title>
<?php include "../parts/meta.php"; ?>
</head>
<body>

<header class="navbar">
<div class="container display-flex">
<div class="flex-none">
<h1>Product Admin</h1>
</div>
<div class="flex-stretch"></div>
<nav class="nav nav-flex flex-none">
<ul>
<li><a href="<?= $_SERVER['PHP_SELF'] ?>">Product List</a></li>
<li><a href="<?= $_SERVER['PHP_SELF'] ?>?id=new">Add New Product</a></li>
</ul>
</nav>
</div>
</header>
<div class="content">
<div class="container display">


<?php

if(isset($_GET['id'])) {
showProductPage(
$_GET['id']=="new" ?
$empty_product :
makeQuery(makeConn(), "SELECT * FROM `products` WHERE `id`=".$_GET['id'])[0]
);
} else {

?>
<h2>Product List</h2>

<?php

$result = makeQuery(makeConn(), "SELECT * FROM `products` ORDER BY `date_create` DESC");

echo array_reduce($result, 'productListItem');

?>


<?php } ?>

</div>
</div>

<?php include "../parts/footer.php"; ?>

</body>
</html>
Loading