-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathcart.php
executable file
·158 lines (153 loc) · 7.55 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
<?php
session_start();
$total = 0;
include("functions/functions.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Travel Bird : Cart</title>
<link rel="stylesheet" href="styles/style.css" media="all">
</head>
<body>
<!--Main container starts here-->
<div class="main_wrapper">
<!--Header starts here-->
<?php include 'includes/header.php'; ?>
<!--Header ends here-->
<!--Navbar starts here-->
<?php include 'includes/navbar.php'; ?>
<!--Navbar ends here-->
<!--Content starts here-->
<div class="content_wrapper">
<!--left-sidebar starts-->
<?php include "includes/left-sidebar.php"; ?>
<!--left-sidebar ends-->
<div id="content_area">
<?php cart(); ?>
<div id="shopping_cart">
<span style="float: right;font-size: 18px;padding: 5px;line-height: 40px;">
<?php
if (isset($_SESSION['customer_email'])) {
echo "<b>Welcome: </b>" . $_SESSION['customer_email'] . "<b style='color: yellow;'> Your</b>";
} else {
echo "<b>Welcome Guest:</b>";
}
?>
<b style="color: yellow;">Shopping Cart-</b> Total Items: <?php total_items(); ?>
Total Price: <?php total_price(); ?>
<a href="index.php" style="color: yellow;">Back to Shop</a>
<?php
if (!isset($_SESSION['customer_email'])) {
echo "<a href='checkout.php' style='color: orange;'>Login</a>";
} else {
echo "<a href='logout.php' style='color: orange;''>Logout</a>";
}
?>
</span>
</div>
<div id="packages_box">
<form action="" method="post" enctype="multipart/form-data">
<table align="center" width="700px" bgcolor="skyblue">
<tr align="center">
<th>Remove</th>
<th>Package(s)</th>
<th>Quantity</th>
<th>Total Cost</th>
</tr>
<?php
global $con;
$ip = getIp();
$sel_price = "SELECT * FROM cart WHERE ip_add='$ip'";
$run_price = mysqli_query($con, $sel_price);
while ($p_price = mysqli_fetch_array($run_price)) {
$pack_id = $p_price['p_id'];
$pack_price = "SELECT * FROM packages WHERE package_id='$pack_id'";
$run_pack_price = mysqli_query($con, $pack_price);
while ($pp_price = mysqli_fetch_array($run_pack_price)) {
$package_price = array($pp_price['package_price']);
$package_title = $pp_price['package_title'];
$package_image = $pp_price['package_image'];
$single_price = $pp_price['package_price'];
$values = array_sum($package_price);
$total += $values;
?>
<tr align="center">
<td><input type="checkbox" name="remove[]" value="<?php echo $pack_id; ?>"></td>
<td>
<?php echo $package_title; ?><br>
<img src="admin_area/package_images/<?php echo $package_image; ?>"
width="60px" height="60px">
</td>
<td><input type="text" size="4" name="qty" value="<?php
if (isset($_SESSION['qty'])) {
echo $_SESSION['qty'];
}
?>">
</td>
<?php
global $con;
if (isset($_POST['update_cart'])) {
$qty = $_POST['qty'];
$update_qty = "UPDATE cart SET qty='$qty'";
$run_qty = mysqli_query($con, $update_qty);
$_SESSION['qty'] = $qty;
$total = ($qty * $total);
}
?>
<td>
<?php echo "$" . $single_price; ?>
</td>
</tr>
<?php
}
}
?>
<tr align="right">
<td colspan="4"><b>Sub Total:</b></td>
<td>
<?php echo "$" . $total; ?>
</td>
</tr>
<tr align="center">
<td colspan="2"><input type="submit" name="update_cart" value="Update Cart"></td>
<td><input type="submit" name="continue" value="Continue Shopping"></td>
<td>
<button><a href="checkout.php"
style="text-decoration: none; color: black;">Checkout</a></button>
</td>
</tr>
</table>
</form>
<?php
function updatecart()
{
global $con;
$ip = getIp();
if (isset($_POST['update_cart'])) {
foreach ($_POST['remove'] as $remove_id) {
$delete_package = "DELETE FROM cart WHERE p_id='$remove_id' AND ip_add='$ip'";
$run_delete = mysqli_query($con, $delete_package);
if ($run_delete) {
echo "<script>window.open('cart.php','self')</script>";
}
}
}
if (isset($_POST['continue'])) {
echo "<script>window.open('index.php','self')</script>";
}
}
echo @$up_cart = updatecart();
?>
</div>
</div>
</div>
<!--Content ends here-->
<!--footer starts-->
<?php include "includes/footer.php";?>
<!--footer ends-->
</div>
<!--Main container ends here-->
</body>
</html>