This commit is contained in:
2025-05-01 14:37:08 -06:00
parent b6008d462e
commit 5cd4571a92
91 changed files with 1009 additions and 36 deletions
+20
View File
@@ -0,0 +1,20 @@
<?php
function cart_item($item)
{
$item = '
<div class="row">
<div class="square img_container">
</div>
<div class="row space_between">
<p>' . $item['description'] . '</p>
<select>
<input type="number">
</select>
</div>
</div>
';
return $item;
}
+18
View File
@@ -0,0 +1,18 @@
</body>
<footer>
<?php
$scripts = '';
switch ($_SERVER['SCRIPT_NAME']) {
case '/index.php':
$scripts .= '<script src="js/login.js"></script>';
break;
}
echo $scripts;
?>
</footer>
</html>
+21
View File
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="css/base.css">
<link rel="stylesheet" href="css/colors.css">
<?php
switch ($_SERVER['SCRIPT_NAME']) {
case '/create-account.php':
echo '<script src="js/create-account.js" defer></script>';
break;
case '/product.php':
if (!isset($_SESSION['id']))
echo '<script src="js/login-modal.js" defer></script>';
break;
}
?>
</head>
<body>
<?php include_once 'nav.php'; ?>
+25
View File
@@ -0,0 +1,25 @@
<?php
$nav = '
<nav>
<ul>
<div class="row space_between">
<div>
<li><a href="catalog.php">Products</a></li>
</div>
<div class="absolute_h_center">
<a href="index.php"><h4>ACME Store</h4></a>
</div>
<div>
' . (isset($_SESSION['id']) ? '<li><a href="cart.php">Cart</a></li>' : '') . '
' . (isset($_SESSION['id']) ? '<li><a href="logout.php">Logout</a></li>' : '') . '
' . (!isset($_SESSION['id']) ? '<li><a href="index.php">Login</a></li>' : '') . '
' . (!isset($_SESSION['id']) ? '<li><a href="create-account.php">Signup</a></li>' : '') . '
</div>
</div>
</ul>
</nav>
';
echo $nav;
+19
View File
@@ -0,0 +1,19 @@
<?php
function product_card($product)
{
$card = '
<a class="card column center full_width padding" href="product.php?id=' . $product['id'] . '">
<div class="img_container">
<img src="img/' . $product['image'] . '">
</div>
<div class="row">
<h4>' . $product['name'] . '</h4>
<h5>' . $product['price'] . '</h5>
</div>
</a>
';
return $card;
}
+16
View File
@@ -0,0 +1,16 @@
<?php
function catalog_grid($products)
{
$grid = '
<div class="grid center">
';
foreach ($products as $p)
$grid .= product_card($p);
$grid .= '
</div>
';
return $grid;
}
+36
View File
@@ -0,0 +1,36 @@
<?php
function product_page($product)
{
$page = '
<div class="product_page_card column center full_width padding">
<div class="img_container">
<img src="img/' . $product['image'] . '">
</div>
<div class="column">
<div class="row space_between">
<h3>' . $product['name'] . '</h3>
<h3>' . $product['price'] . '</h3>
</div>
<p>' . $product['description'] . '</p>
<form class="row" id="add_to_cart">
<input type="hidden" name="is_logged_in" value="' . (isset($_SESSION['id']) ? 'true' : 'false') . '">
<div class="column margin">
<label for="quantity">Quantity:</label>
<input type="number" value="1" id="quantity" name="quantity" min="1">
</div>
<input type="submit" value="Add to Cart" class="margin">
</form>
</div>
</div>
<div class="modal">
<div class="modal_content">
' . login_form() . '
</div>
</div>
';
return $page;
}
View File
+27
View File
@@ -0,0 +1,27 @@
<?php
function login_form()
{
$form = '
<div class="card center">
<form method="post" id="login_form">
<div class="column center">
<div class="column">
<label for="username">Username:</label>
<input id="username" name="username" autofocus required>
</div>
<div class="column">
<label for="password">Password:</label>
<input id="password" type="password" name="password" required>
</div>
<a href="create-account.php">Signup Instead</a>
<input type="submit" class="button submit" id="login_submit">
</div>
</form>
</div>
';
return $form;
}
+40
View File
@@ -0,0 +1,40 @@
<?php
function signup_form()
{
$form = '
<div class="card center">
<form method="post" class="column center">
<div class="column">
<label for="username">Username:</label>
<input id="username" name="username" autofocus required>
</div>
<div class="column">
<label for="password">Password:</label>
<input id="password" type="password" name="password" required>
</div>
<div class="column">
<label for="v_password">Verify Password:</label>
<input id="v_password" type="password" name="v_password" required>
</div>
<a href="index.php">Login Instead</a>
<div class="row full_width">
<input type="submit" class="button submit">
<input type="reset" class="button">
</div>
<div class="column center error">
<p id="err_username"></p>
<p id="err_match"></p>
<p id="err_length"></p>
<p id="err_num"></p>
</div>
</form>
</div>
';
return $form;
}