forked from Saipavan0910/FarmFlow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcatalog.php
318 lines (276 loc) · 11.1 KB
/
catalog.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
<!DOCTYPE html>
<html lang="en">
<?php
session_start();
$farmer_id = $_SESSION['farmer_id'];
$user_id = $_SESSION['user_id'];
?>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Catalog Page</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.bundle.min.js"></script>
<script src="https://kit.fontawesome.com/4e97f0f302.js" crossorigin="anonymous"></script>
<style>
body {
background: #eee;
}
.custom-header {
display: flex;
align-items: center;
justify-content: space-between;
background-color: darkcyan;
padding: 0px;
margin: 0px;
}
.logo {
margin: 10px 10px 10px 25px;
max-width: 90px;
border-radius: 50%;
}
header img {
height: 70px;
border-radius: 50%;
}
.ratings i {
font-size: 16px;
color: red;
}
.strike {
color: red;
text-decoration: line-through;
}
.icon a {
margin-bottom: 10px;
text-decoration: none;
color: white;
font-size: 20px;
border: 1px solid black;
padding: 10px;
border-radius: 5px;
margin-right: 20px;
}
.product-img {
width: 100%;
}
.dot {
height: 7px;
width: 7px;
margin-left: 6px;
margin-right: 6px;
margin-top: 3px;
background-color: darkcyan;
border-radius: 50%;
display: inline-block;
}
.spec {
color: #938787;
font-size: 15px;
}
h5 {
font-weight: 400;
}
.description {
font-size: 16px;
}
p{
overflow: revert !important;
white-space: normal !important;
}
#zoom {
display: flex;
transition: transform .4s;
width: 90%;
margin: auto;
flex-direction: column;
}
.single-catalog{
transition: transform ease-in-out 120ms;
}
.single-catalog:hover {
-ms-transform: scale(1.1);
-webkit-transform: scale(1.1);
transform: scale(1.1);
transition-duration: 200ms;
align-content: center;
transform-origin: center;
-webkit-transform-origin: center;
-ms-transform-origin: center;
}
#cart {
display: flex;
align-items: center;
justify-content: space-evenly;
height: 15vh;
width: 100%;
}
#cart button {
background-color: darkcyan;
border: 1.5px solid black;
border-radius: 5px;
height: 35px;
width: 110px;
color: #fff;
}
.prod-img {
width: 100%;
height: 100%;
object-fit: cover;
object-position: center;
}
</style>
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'en'}, 'google_translate_element');
}
</script>
<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
</head>
<body>
<?php
include_once "connection.php";
$product_id = $_GET['product_id'];
$status = mysqli_query($conn, "SELECT name FROM product WHERE product_id = '$product_id'");
$row = mysqli_fetch_array($status);
?>
<div class="custom-header">
<img src="./images/equipment/logo.png" alt="Company Logo" class="logo">
<h1 class="mb-4" style="text-align:center; color: white; margin-top: 20px;"><strong><?php echo $row['name']; ?></strong></h1>
<div id="google_translate_element" style="margin-top: 5px !important;margin-left: 600px;"></div>
<div class="icon">
<a href="cart_test.php"><i class="fa-solid fa-cart-shopping"></i></a>
<a href="profile.php"><i class="fa-solid fa-user"></i></a>
</div>
</div>
<div class="container mt-5 mb-5" style="margin-left: 65px !important;" id ="zoom">
<?php
$result = mysqli_query($conn, "SELECT
v.description,
v.price,
v.vehicle_id,
v.model,
v.startdate,
v.enddate,
v.image
FROM
vehicle AS v
INNER JOIN OWNER AS o
ON
v.owner_id = o.owner_id
INNER JOIN user_details AS u
ON
o.user_id = u.user_id
WHERE
v.product_id = $product_id
AND u.location IN(SELECT location FROM user_details WHERE user_id = $user_id);");
while($row = mysqli_fetch_array($result))
{
$vehicleId = $row['vehicle_id'];
$vehicle_enddate = mysqli_query($conn, "SELECT vehicle_id, MAX(end_date) AS latest_end_date
FROM line_item
WHERE vehicle_id = $vehicleId
GROUP BY vehicle_id");
$row2 = mysqli_fetch_assoc($vehicle_enddate);
date_default_timezone_set('Asia/Kolkata');
if($row2 == null){
if(date('Y-m-d') > $row['startdate'] ){
$new_enddate = date('Y-m-d');
}
else{
echo "<script>console.log('date: " . json_encode(date('Y-m-d')) . "');</script>";
echo "<script>console.log('time: " . json_encode(date('h:i:s A')) . "');</script>";
echo "<script>console.log('start date: " . json_encode($row['startdate']) . "');</script>";
$new_enddate = $row['startdate'];
}
}
else{
$new_enddate = $row2['latest_end_date'];
$temp_date = new DateTime($new_enddate);
$temp_date->modify('+1 day');
$new_enddate = $temp_date->format('Y-m-d');
}
$owner_enddate = $row['enddate'];
?>
<div class="d-flex justify-content-center row; single-catalog" style="width:100%; margin-right: auto; margin-top: 45px;">
<div class="col-md-10">
<div class="row p-2 bg-white border rounded">
<div class="col-md-3 mt-1" style="margin-bottom: 0px !important; padding-top: 15px !important; padding-bottom: 15px !important; margin-top: 0px !important; overflow: hidden !important;">
<img class="img-fluid img-responsive rounded product-image prod-img" src="<?php echo $row['image']; ?>">
</div>
<div class="col-md-6 mt-1">
<h4><?php echo $row['model']; ?></h4>
<div class="d-flex flex-row">
<div class="ratings mr-2"><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i></div><span>310</span>
</div>
<div>
<p class="text-justify text-truncate para mb-0"><?php echo $row['description']; ?><br><br></p>
</div>
</div>
<div class="align-items-center align-content-center col-md-3 border-left mt-1">
<div class="d-flex flex-row align-items-center">
<h3 class="mr-1" id="price-<?php echo $row['vehicle_id']; ?>"><?php echo $row['price']; ?>/Per Day</h3>
</div>
<div class="d-flex flex-column mt-4" style="margin-top: 0px !important;">
<h6>Start date:</h6>
<input type="date" placeholder="Start Date" id="startdate-<?php echo $row['vehicle_id']; ?>" class="mb-2" min="<?php echo $new_enddate; ?>" max="<?php echo $row['enddate']; ?>" onchange="dateValidate(<?php echo $row['vehicle_id']; ?>)">
<h6>End date:</h6>
<input type="date" placeholder="End Date" id="enddate-<?php echo $row['vehicle_id']; ?>" class="mb-2" max="<?php echo $row['enddate']; ?>">
<?php
if($new_enddate > $owner_enddate) {
echo '<h4 style="font-size: 15px; text-align: center; border: 1px solid black; border-radius: 5px; height: 25px; margin-top: 10px; background-color: #d9d9d9;">OUT OF STOCK</h4>';
} else {
?>
<button class="btn btn-primary btn-sm" type="button" onclick="addToCart(<?php echo $row['vehicle_id']; ?>)" style="margin-top: 15px !important;">Add to Cart</button>
<?php
}
?>
</div>
</div>
</div>
</div>
</div>
<?php
}
?>
</div>
<div id="cart">
<button id="backToEquip" onclick="backToEquip()">Back</button>
<button id="goToCartButton" onclick="redirectToCart()">Go to Cart</button>
</div>
<script>
function dateValidate(vehicleId){
const date = document.getElementById('startdate-' + vehicleId).value;
document.getElementById('enddate-' + vehicleId).setAttribute('min', date);
}
function addToCart(vehicleId)
{
var startdate = document.getElementById('startdate-' + vehicleId).value;
var enddate = document.getElementById('enddate-' + vehicleId).value;
var price = document.getElementById('price-' + vehicleId).innerText;
if (startdate === "" || enddate === "") {
alert("Please select start date and end date.");
} else {
$.post("addToCart.php",
{
vehicle_id: vehicleId,
start_date: startdate,
end_date: enddate,
price: price
},
function(data, status){
alert("Item added to the cart!");
});
}
}
function redirectToCart() {
window.location.href = './cart_test.php';
}
function backToEquip() {
window.location.href = 'Equip.html';
}
</script>
</body>
</html>