-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcart.php
148 lines (136 loc) · 4.38 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
<?php
if(isset($_POST['delete'])){
include_once 'includes/config.php';
$sql = "DELETE FROM carts where pid={$_GET['pid']} AND quantity={$_GET['q']} LIMIT 1"; //sql query for deleting
$conn->query($sql); //executing sql query
header("Location:cart.php?itemRemovedSuccessfully");
}
?>
<?php
include_once('./includes/navbar.php');
//this restriction will secure the pages path injection
if(!(isset($_SESSION['id']))){
header("location:index.php?UnathorizedUser");
die();
}
include_once('./stripeConfig.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Book|Cart</title>
<style>
*{
margin:0;padding:0;
}
.facross{
color: #DC143C !important;
}
.text-end{
text-align:center
}
</style>
</head>
<body>
<div class='cart' >
<div class="container" >
<br><br>
<br><br>
<h1 style='float:left'>Cart</h1>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<div style=''>
<?php
$total=0;
$sql = "SELECT * FROM carts where uid={$_SESSION['id']} AND status='active'";
$result = $conn->query($sql) or die("Query Failed.");
if ($result->num_rows > 0) {
?>
<div style='margin-left:5%'>
<table class='cart-table' style="position:relative;">
<thead>
<thead >
<tr>
<th>Sn</th>
<th>Book</th>
<th>Rent Charge</th>
<th>Price</th>
<th>Quantity</th>
<th>Total</th>
<th>Return Date</th>
<th>Action</th>
</tr>
</thead>
</thead>
<tbody >
<?php
$sn=0;
while($row = $result->fetch_assoc()) {
$sn = $sn+1;
//by this way we can encode data and pass this data to anther page and use it after decoding
// $quantArray[$sn-1] = $row['quantity'];
// $dateArray[$sn-1] = $row['return_date'];
// $encodedQuantityData = urlencode(serialize($quantArray));
// $encodedReturnDateData = urlencode(serialize($dateArray));
$total = $total+ ($row["price"]*$row["quantity"]);
?>
<tr>
<td><?php echo $sn?></td>
<td><?php echo $row["product"] ?></td>
<td><?php echo $row["rent_charge"] ?>%
</td>
<td><?php echo $row["price"] ?></td>
<td>
<p><?php echo $row["quantity"] ?></p>
</td>
<td><?php echo ($row["price"]*$row["quantity"]) ?></td>
<td><?php echo $row["return_date"] ?></td>
<td>
<form action="<?php echo $_SERVER['PHP_SELF']?>?pid=<?php echo $row['pid']?>&q=<?php echo $row['quantity']?>" method="post">
<button name='delete' type='submit' ><i class="fa-solid fa-trash fa-lg facross"></i> </button>
</form>
</td>
</tr>
<?php }?>
</tbody>
<button class="btn" style="background:#11C9B6;border:none;"><a href="./products.php?type=new" style='color:white;text-decoration:none'>Continue Renting</a></button>
</table>
</div>
<div style="margin-top:5px;border-bottom:1px solid white;"></div>
<div style='margin-left:5%'>Total: <?php echo ($total)?> (<i style='color:grey' class="fa fa-motorcycle" aria-hidden="true">Free</i>)</div>
<div style="margin-top:5px;border-bottom:1px solid white;"></div>
<div style="margin-top:5px;border-bottom:1px solid white;"></div>
<div style="margin-top:5px;border-bottom:1px solid white;"></div>
<!-- <form class='cart-stripe-form' style='' action="message.php?id=<?php echo $encodedPidData?>&q=<?php echo $encodedQuantityData?>&rd=<?php echo $encodedReturnDateData?>" method="post"> -->
<form class='cart-stripe-form' style='' action="message.php?items=carts" method="post">
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="<?php echo $publishableKey?>"
data-amount="<?php echo ($total) ?>"
data-name="Book Rental"
data-description="Book For Everyone"
data-image="./images/logo.png"
data-currency="usd"
data-email="<?Php echo $_SESSION['customer_email']?>"
success="<?php //it will be created only when payment is made
$_SESSION['order_auth']=true;
?>"
>
//this form container will auto generate paynow button that comers form script form stripe
</script>
</form>
<?php }else { echo "0 Results <br> No Books in a Cart"; }
?>
</div>
</div>
</div>
</body>
</html>