-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
73 lines (67 loc) · 2.89 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>Store</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="images/favicon.ico">
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/main.css">
</head>
<?php
session_start();
require_once("inc/open_db.php");
include("inc/functions.php");
$inventory = get_inventory($db);
if (isset($_SESSION['user'])) {
if (isset($_POST['submit'])){
if (!add_to_cart($db, $_POST['itemNum'], $_SESSION['user'])) {
$unavailable = $_POST['itemNum'];
}
}
}
?>
<body>
<header>
<h1>Ducks</h1>
</header>
<main>
<?php
if (isset($_SESSION['user'])) {
echo '<a href="login_files/logout.php">logout</a>';
} else {
echo '<a href="login_files/login_start.php">sign in/create account</a>';
}
?>
<a href="shoppingCart.php"><img alt="shopping cart" src="images/cart.png"/></a>
<div>
<?php
foreach($inventory as $product) {
$msg = !isset($_SESSION['user']) ? 'disabled title="please login before purchasing items"' : '';
echo '<section>';
echo '<img src="images/'.$product['itemNumber'].'.jpg" alt="image of '.$product['description'].'"/>';
echo '<p>'.$product['description'].'</p>';
echo '<p>Currently Available: '.$product['quantity'].'</p>';
echo '<p>$'.number_format($product['price'], 2).'</p>';
echo '<form method="post" action="index.php">';
echo '<input type="hidden" name="itemNum" value="'.$product['itemNumber'].'">';
echo '<input type="hidden" name="description" value="'.$product['description'].'">';
echo '<input type="hidden" name="price" value="'.$product['price'].'">';
echo '<input '.$msg.' type="submit" value="add to cart" name="submit">';
if (isset($unavailable) && $unavailable == $product['itemNumber']) {
echo '<p>quantity unavailable</p>';
}
echo '</form>';
echo '</section>';
}
?>
</div>
</main>
<?php include('inc/footer.php') ?>
</body>
</html>