-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrentalcar.php
637 lines (485 loc) · 15 KB
/
rentalcar.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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
<?php
session_start();
if(!isset($_SESSION['logged_in'])) //user not logged in
{
header('location:index.php');
}
include("dbconnect.php");
$carid = $_REQUEST["carid"];
$userid = $_SESSION['userid'];
$usertype = $_SESSION['usertype'];
//first query to select all car and its dealer details
$query1 = "select Name,Dname,Mname,status,dealer.phoneno as dph,d_email,rent.customerid as rentcustomerid,
dealer.website as dweb,mileage,color,status,fueltype,licenseplateno,rentamount from car left join rent on car.carid=rent.rentalcarid inner join rentalcar inner join manufacturer inner join owns inner join dealer where
car.manufacturerid=manufacturer.manufacturerid and owns.carid=car.carid and owns.dealerid=dealer.dealerid and car.carid=rentalcar.rentalcarid and car.carid=$carid order by startdate desc limit 1";
$result1 = mysqli_query($conn,$query1);
$firstquery = mysqli_fetch_assoc($result1);
//second query to get the features of the car
$query2 = "select features from features where carid=$carid";
$result2 = mysqli_query($conn,$query2);
//third query to get the images of the car
$query3 = "select images from images where carid=$carid";
$result3 = mysqli_query($conn,$query3);
?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo $firstquery["Name"]?> - Rustom</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8">
<link rel="icon" href="icon.ico">
<!--Google Fonts-->
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300&display=swap" rel="stylesheet">
<!--BOOTSTRAP CDN-->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<!-- jQuery UI library -->
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
</head>
<style>
#listicon
{
position:absolute;
left:20px;
margin-top:1px;
cursor:pointer;
}
#list
{
position:fixed;
top:0;
height:100%;
z-index:20;
left:0;
background-color:#C39BD3;
width:0;
overflow:hidden;
display:flex;
flex-direction:column;
align-items:center;
justify-content:center;
transition:width 0.15s ease-in-out;
}
#list a
{
font-weight:350;
text-align:center;
color:white;
font-size:1.5rem;
margin:5px 0;
transition:color 0.15s ease-in-out;
}
#list #active
{
cursor:default;
color:#76448A;
}
#list a:hover
{
color:#76448A;
text-decoration:none;
}
#list #closelist
{
cursor:pointer;
background-color:#76448A;
width:fit-content;
position:absolute;
top:10px;
padding:5px;
display:flex;
align-items:center;
right:10px;
}
#header #logout
{
position:absolute;
right:20px;
cursor:pointer;
}
#content
{
width:80%;
margin:auto;
}
.image
{
height:475px;
margin:0.5% 0.5%;
width:49%;
object-fit:cover;
overflow:hidden;
}
.image img
{
height:475px;
}
#overlay {
position: fixed;
display:flex;
flex-direction:column;
align-items: center;
justify-content:center;
height:100%;
opacity:0;
margin-top:50px;
width:100%;
top:0;
background-color:black;
z-index:-1;
}
#modal
{
height:475px;
min-width:80%;
max-width:80%;
overflow:hidden;
display:flex;
align-items:center;
justify-content:center;
}
#modal img {
height:475px;
}
.tile {
height:500px;
min-width:60%;
max-width:60%;
overflow: hidden;
display:flex;
align-items:center;
justify-content:center;
}
.photo {
overflow:hidden;
transition: transform .5s ease-in-out;
}
.photo img {
height:500px;
}
#rentholder
{
margin-top:15px;
height:0;
overflow:hidden;
display:flex;
flex-direction:column;
line-height:2rem;
width:100%;
}
@media screen and (max-width:1000px)
{
#carname
{
font-size:40px;
}
#modal,#modal img,.image,.image img
{
height:350px;
}
}
@media screen and (max-width:600px)
{
#modal,#modal img,.image,.image img
{
height:250px;
}
}
@media screen and (max-width:400px)
{
#modal,#modal img,.image,.image img
{
height:175px;
}
}
@media screen and (max-width:1200px)
{
.image
{
width:99%;
}
}
</style>
<script type="text/javascript">
var today = new Date();
$(function() {
$("#datepicker").datepicker({
dateFormat: 'dd-mm-yy',
changeMonth: true,
changeYear: true,
minDate: today,
maxDate :'+3d'
});
});
var rentisopen=0;
function openrent()
{
if(rentisopen===0)
{
$("#rentholder").css("height","fit-content");
rentisopen=1;
}
else
{
$("#rentholder").css("height","0");
rentisopen=0;
}
}
function rentcar(carid,event)
{
var xhttp;
if (window.XMLHttpRequest) {
// code for modern browsers
xhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
//xhttp is the ajax req obj
xhttp.onreadystatechange = function() {
if(this.readyState===4 && this.status===200)
{
if(this.responseText==="success")
{
window.location.href="cus_index.php";
}
else if(this.responseText==="rented")
{
alert("This car has already been rented!");
}
else
{
alert(this.responseText);
}
}
}
var date = document.getElementById("datepicker").value;
if(date==="")
{
alert("Select a start date!");
}
else
{
var param = "carid="+carid+"&date="+date+"&type=start";
xhttp.open("POST","rentcar.php",true);
xhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xhttp.send(param);
}
}
</script>
<body>
<div id="list">
<div id="closelist" onclick="openlist()">
<svg class="bi bi-chevron-left" width="1.5em" height="1.5em" viewBox="0 0 16 16" fill="white" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" d="M11.354 1.646a.5.5 0 010 .708L5.707 8l5.647 5.646a.5.5 0 01-.708.708l-6-6a.5.5 0 010-.708l6-6a.5.5 0 01.708 0z" clip-rule="evenodd"/>
</svg>
</div>
<?php if($usertype==="customer")
{
?>
<a href="cus_index.php">Home</a>
<a href="cus_profile.php">Profile</a>
<a href="cus_purchased.php">My Purchases</a>
<a href="cus_rented.php">Rented cars</a>
<?php }
else{
?>
<a href="dealer_index.php">Home</a>
<a href="dealer_profile.php">Profile</a>
<a href="dealer_sold.php">Cars Sold</a>
<a href="dealer_rented.php">Cars Rented</a>
<?php } ?>
</div>
<div id="overlay"></div>
<div class="container-fluid text-white py-3" id="header" style="background-color:black;position:fixed;z-index:5;top:0;display:flex;align-items:center">
<div id="listicon" onclick="openlist()">
<svg class="bi bi-list" width="2em" height="2em" viewBox="0 0 16 16" fill="white" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" d="M2.5 11.5A.5.5 0 013 11h10a.5.5 0 010 1H3a.5.5 0 01-.5-.5zm0-4A.5.5 0 013 7h10a.5.5 0 010 1H3a.5.5 0 01-.5-.5zm0-4A.5.5 0 013 3h10a.5.5 0 010 1H3a.5.5 0 01-.5-.5z" clip-rule="evenodd"/>
</svg>
</div>
<a id="logout" href="logout.php">
<svg id="person" class="bi bi-x-square" width="1.5em" height="1.5em" viewBox="0 0 16 16" fill="white" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" d="M14 1H2a1 1 0 00-1 1v12a1 1 0 001 1h12a1 1 0 001-1V2a1 1 0 00-1-1zM2 0a2 2 0 00-2 2v12a2 2 0 002 2h12a2 2 0 002-2V2a2 2 0 00-2-2H2z" clip-rule="evenodd"/>
<path fill-rule="evenodd" d="M11.854 4.146a.5.5 0 010 .708l-7 7a.5.5 0 01-.708-.708l7-7a.5.5 0 01.708 0z" clip-rule="evenodd"/>
<path fill-rule="evenodd" d="M4.146 4.146a.5.5 0 000 .708l7 7a.5.5 0 00.708-.708l-7-7a.5.5 0 00-.708 0z" clip-rule="evenodd"/>
</svg>
</a>
<img src="logow.png" onclick="gotodash(<?php echo '\''.$usertype.'\'' ?>)" height="50px" style="margin:auto;cursor:pointer">
</div>
<div class="jumbotron jumbotron-fluid" style="margin-top:80px">
<div class="container">
<h1 id="carname" class="display-4 text-center"><?php echo $firstquery["Name"] ?></h1>
<p class="lead text-center">Dealer - <a href="#"><?php echo $firstquery["Dname"] ?></a></p>
</div>
</div>
<div id="content">
<nav>
<div class="nav nav-tabs" id="myTab" role="tablist">
<a class="nav-item nav-link active" id="nav-details-tab" data-toggle="tab" href="#nav-details" role="tab" aria-controls="nav-details" aria-selected="true">Details</a>
<a class="nav-item nav-link" id="nav-features-tab" data-toggle="tab" href="#nav-features" role="tab" aria-controls="nav-features" aria-selected="false">Features</a>
<a class="nav-item nav-link" id="nav-gallery-tab" data-toggle="tab" href="#nav-gallery" role="tab" aria-controls="nav-gallery" aria-selected="false">Gallery</a>
</div>
</nav>
<div class="tab-content" id="nav-tabContent">
<div class="tab-pane fade show active" id="nav-details" role="tabpanel" aria-labelledby="nav-details-tab">
<div class="card bg-light mb-3" style="margin-top:15px">
<div class="card-header">Car Details</div>
<div class="card-body">
<p class="card-text"><b>Car Name - </b><?php echo $firstquery["Name"]?></p>
<p class="card-text"><b>Manufacturer - </b><?php echo $firstquery["Mname"]?></p>
<p class="card-text"><b>Type - </b><?php echo "Rental Car"?></p>
<p class="card-text"><b>Color - </b><?php echo $firstquery["color"]?></p>
<p class="card-text"><b>Mileage - </b><?php echo $firstquery["mileage"]." km/l" ?></p>
<p class="card-text"><b>Fuel Type - </b><?php echo $firstquery["fueltype"]?></p>
<p class="card-text"><b>License plate no</b>
<li class="list-group-item list-group-item-warning" style="text-align:center"><?php echo $firstquery["licenseplateno"]?></li>
</p>
<p class="card-text"><b>Rent amount - </b><?php echo "Rs ".$firstquery["rentamount"]. " per hour" ?></p>
<?php
if($usertype!=="dealer") //user type is not a dealer
{
if($firstquery["status"]==="available") //user has not rented the car yet
{?>
<button type="button" class="btn btn-primary" onclick="openrent()">Rent this car</button>
<!--<button type="button" class="btn btn-outline-info">Add to wishlist</button>-->
<?php
}
else if($firstquery["status"]==="rented"&&$firstquery["rentcustomerid"]===$userid&&$usertype==="customer")
{
?>
<div class="alert alert-success" role="alert" style="margin-bottom:0">
This car is currently being rented by you!
</div>
<?php
}
else
{
?>
<div class="alert alert-danger" role="alert" style="margin-bottom:0">
Sorry but this car is rented!
</div>
<?php }
}?>
<div id="rentholder">
Start date
<input type="text" id="datepicker" style="padding:0 5px" placeholder="Select start date of rent">
<div style="color:#76448A">Note - You can pre-rent a car now and start the rent within any 3 days from today.</div>
<button type="button" id="rentbutton" class="btn btn-info" style="margin-top:10px" onclick="rentcar(<?php echo $carid.',event' ?>)">Rent now</button>
</div>
</div>
</div>
<div class="card bg-light mb-3" style="margin-top:15px">
<div class="card-header">Dealer Details</div>
<div class="card-body">
<p class="card-text"><b>Dealer Name - </b><?php echo $firstquery["Dname"]?></p>
<p class="card-text"><b>Phone no - </b><?php echo $firstquery["dph"]?></p>
<p class="card-text"><b>Email - </b><?php echo $firstquery["d_email"]?></p>
<p class="card-text"><b>Website - </b><a href="<?php echo $firstquery["dweb"]?>" target="_blank"><?php echo $firstquery["dweb"]?></a></p>
</div>
</div>
</div>
<div class="tab-pane fade" id="nav-features" role="tabpanel" aria-labelledby="nav-features-tab">
<ul class="list-group" style="margin-top:15px">
<?php
while($features=mysqli_fetch_assoc($result2))
{
?>
<li class="list-group-item">
<h5 class="mb-1"><?php echo $features["features"]?></h5>
<p class="mb-1">Detailed descripton of the feature will go here. (Feature coming soon!)</p>
</li>
<?php
}
?>
</ul>
</div>
<div class="tab-pane fade" id="nav-gallery" role="tabpanel" aria-labelledby="nav-gallery-tab">
<div class="container" style="min-width:100%;margin:15px 0">
<div class="row">
<?php
if(mysqli_num_rows($result3)===0)
{
?>
No images to show! Please contact the dealer for more details!
<?php
}
while($images=mysqli_fetch_assoc($result3))
{
?>
<div class="image">
<img src="<?php echo $images["images"]?>" alt="car_image" onclick="showimage(event)">
</div>
<?php
}
?>
</div>
</div>
</div>
</div>
</div>
</body>
<script type="text/javascript">
function gotodash(usertype)
{
if(usertype==="customer")
{
window.location.href="cus_index.php";
}
else
{
window.location.href="dealer_index.php";
}
}
$('#myTab a').on('click', function (e) {
$(this).tab('show');
})
function showimage(event)
{
$('#overlay').css('opacity','1');
$('#overlay').css('z-index','5');
if($( window ).width() >= 1000)
{
var div = '<div class="tile" data-scale="2"><div class="photo"><img src="'+event.target.src+'"></div></div>' + '<button type="button" id="close" class="btn btn-danger" style="margin-top:5px" onclick="closeimage()">Close</button>';
$('#overlay').append(div);
$('.tile')
// tile mouse actions
.on('mouseover', function(){
$(this).children('.photo').css({'transform': 'scale('+ $(this).attr('data-scale') +')'});
})
.on('mouseout', function(){
$(this).children('.photo').css({'transform': 'scale(1)'});
})
.on('mousemove', function(e){
$(this).children('.photo').css({'transform-origin': ((e.pageX - $(this).offset().left) / $(this).width()) * 100 + '% ' + ((e.pageY - $(this).offset().top) / $(this).height()) * 100 +'%'});
})
}
else
{
var div = '<div id="modal" style="opacity:1"><img src="'+event.target.src+'"></div>'+'<button type="button" id="close" class="btn btn-danger" style="margin-top:5px" onclick="closeimage()">Close</button>';
$('#overlay').append(div);
}
}
function closeimage()
{
$('#overlay').css('opacity','0');
$('#overlay').css('z-index','-1');
if($( window ).width() >= 1000)
{
$('.tile').remove();
$('.photo').remove();
$('#close').remove();
}
else
{
$('#modal').remove();
$('#close').remove();
}
}
</script>
<script type="text/javascript" src="JS/list.js"></script>
</html>