-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcart.php
190 lines (165 loc) · 7.47 KB
/
cart.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<!-- CART PAGE
WEBTECH FINAL
WRITTEN BY ADAM POHL -->
<!-- Cart uses sessions to properly store data
Whenever a user adds an item, that items id
gets appended to the cart array in the $_SESSION
superglobal -->
<?php
include 'config.inc.php';
//Create a session if one was not already created
include 'create_session.inc.php';
//Set values in the data base entry for session specefic data
include 'retrieve_user_session_data.inc.php';
// Connect to database
try{
$pdo = new PDO(DBCONNSTRING, DBUSER, DBPASS);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e){
die($e -> getMessage());
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Atlas Corporation</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<link rel="stylesheet" href="css/navbar.css">
<link rel="stylesheet" href="css/cart.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<script type="text/javascript" src="javascript/cart.js"></script>
</head>
<body>
<div class="container">
<!-- Navbar -->
<nav class="navbar navbar-expand-sm navbar-dark fixed-top" id="navigation">
<!-- Brand/Logo -->
<a class="navbar-brand" href="index.php">
<img src="images/Company-Logo.png" alt="Atlas Corporation" title="Atlas Corporation">
</a>
<!-- Pages -->
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="index.php">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="about.html">About Us</a>
</li>
<li class="nav-item">
<a class="nav-link" href="catalog.php">Products</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="cart.php">Cart</a>
</li>
<li class="nav-item">
<a class="nav-link" href="weather.php">Weather</a>
</li>
<li class="nav-item">
<a class="nav-link" href="contact_us.html">Contact Us</a>
</li>
<li class="nav-item">
<a class="nav-link" href="log_in.html">Log In</a>
</li>
</ul>
</nav> <!-- End Navbar -->
<h2 class="jumbotron"><b>Checkout</b></h2>
<div class="row">
<div class="col-md-12">
<div class="items">
<!-- PHP loop to print out each product in cart -->
<?php
if(isset($GLOBALS['g_ProductsInCart'])){
foreach($GLOBALS['g_ProductsInCart'] as $id){
$sql = "SELECT * FROM products WHERE ID='" . $id . "'"; // Prepare sql query
$product = $pdo -> query($sql);
$row = $product -> fetch(); // Get product row
// Prepare variables
$name = $row["Name"];
$price = $row["Price"];
$imgSrc = "images/products/" . $id . "-main.jpg";
$output = '<div class="product-box">';
$output .= '<img src="' . $imgSrc . '" class="product-image">';
$output .= '<h2 class="product-name">' . $name . '</h2>';
$output .= '<h2 class="product-price"> $' . $price . '</h2>';
$output .= '</div>';
echo $output;
}
}
else{
echo "Cart is currently empty";
}
?>
</div> <!-- End items -->
</div> <!-- End Column -->
<button type="button" class="btn btn-primary pay_info" data-toggle="modal" data-target="#purchase_modal">Payment Information</button>
</div> <!-- End row -->
<!-- Modal -->
<div id="purchase_modal" class="modal fade" role="dialog">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Purchase Form</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Checkout Modal -->
<div class="modal-body">
<!-- Container for Modal Content -->
<div class="container">
<!-- Form to collect to input -->
<form class="checkout_form" method="POST">
<label class="checkout_info_label">Personal Information</label>
<!-- Name -->
<div class=row>
<div class="col">
<input type="text" name="firstName" class="form-control" placeholder="First Name" required>
</div>
<div class="col">
<input type="text" name="lastName" class="form-control" placeholder="Last Name" required>
</div>
</div>
<!-- Address -->
<div class=row>
<input type="text" name="streetAddress" class="form-control" placeholder="Street Address" required><br>
<input type="text" name="optionalAddress" class="form-control" placeholder="Apt, Suite, or Building (Optional)">
</div>
<div class=row>
<div class="col">
<input type="text" name="location" class="form-control" placeholder="City, State" required>
</div>
<div class="col">
<input type="text" name="zipcode" class="form-control" placeholder="Zip Code" required>
</div>
</div>
<label class="checkout_info_label">Billing Information</label>
<!-- Credit Card -->
<div class="row">
<input type="text" name="creditCard" class="form-control" placeholder="Card Number (No Spaces)" required>
</div>
<div class=row>
<div class="col">
<input type="date" name="expiration" class="form-control" required>
</div>
<div class="col">
<input type="password" name="cvv" class="form-control" placeholder="CVV" required>
</div>
</div>
</form>
</div>
</div>
<!-- Modal Footer -->
<form action="delete_user_session.inc.php" method="POST">
<div class="modal-footer">
<input type="text" name="delete" style="display:none;" value="DeleteSession">
<button type="submit" class="btn btn-primary place_order_button" data-dismiss="">Place Order</button>
</div>
</form>
</div>
</div>
</div>
</div> <!-- End container -->
</body>
</html>