-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdealer_rented.php
414 lines (308 loc) · 9.16 KB
/
dealer_rented.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
<?php
session_start();
if(!isset($_SESSION['logged_in'])||(isset($_SESSION['logged_in'])&&$_SESSION['usertype']==="customer")) //user not logged in or user logged in is a customer
{
header('location:index.php');
}
include("dbconnect.php");
$dealerid = $_SESSION['userid']; //getting the dealer id
$dealername = $_SESSION['username'];
?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo $dealername."'s " ?> rented cars - 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">
</head>
<style>
.card{
margin-bottom:10px;
margin-top:15px;
}
.card-img-top
{
min-height:250px;
max-height:250px;
object-fit:cover;
}
#listicon
{
position:absolute;
left:20px;
margin-top:1px;
cursor:pointer;
}
#title
{
font-family: 'Open Sans', sans-serif;
margin:auto;
margin-bottom:0.5px;
text-align:center;
font-weight:300;
font-size:1.5rem;
}
#header #logout
{
position:absolute;
right:20px;
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;
}
.row
{
align-items:flex-start;
}
li
{
text-align:left;
overflow:hidden;
text-overflow:ellipsis;
white-space:nowrap;
margin-bottom:1px;
max-width:100%;
}
.card-subtitle
{
color:#884EA0;
}
@media screen and (max-width:1000px)
{
#carname
{
font-size:40px;
}
}
@media screen and (max-width:1200px)
{
.row
{
flex-direction:row;
min-width:80%;
}
.col-sm-3
{
min-width:50%;
}
}
@media screen and (max-width:769px)
{
.row
{
justify-content:center;
}
.col-sm-3
{
min-width:80%;
}
#explore
{
text-align:center;
padding:20px 0;
border-bottom:1px solid #C39BD3;
}
}
</style>
<script>
function endrent(carid,customerid,startdate)
{
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")
{
location.reload();
}
else
{
alert(this.responseText);
}
}
}
var param = "carid="+carid+"&customerid="+customerid+"&startdate="+startdate+"&type=end";
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>
<a href="dealer_index.php">Home</a>
<a href="dealer_profile.php">Profile</a>
<a href="dealer_sold.php">Cars Sold</a>
<a id="active">Cars Rented</a>
</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 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>
<!--<h3 id="title">Rustom</h3>-->
<img src="logow.png" height="50px" style="margin:auto">
</div>
<div class="container" style="width:80%;margin:auto;margin-top:135px">
<h2 id="carname" class="display-4 text-center">Cars you have rented</h2>
</div>
<div class="container-fluid py-3" style="width:80%">
<?php if(isset($_SESSION['finishedrent'])&&$_SESSION['finishedrent']===true)
{
?>
<div class="alert alert-info" role="alert">
Ended rent for rental car!
</div>
<?php
unset($_SESSION['finishedrent']);
} ?>
<h3 id="explore" style="font-weight:lighter">Ongoing</h3>
<div class="row">
<?php
$rentedcarsquery1 = "
select rentalcarid,rent.customerid,customername,name,DATE_FORMAT(rentdate,'%d %M %Y') as rentdate,DATE_FORMAT(startdate,'%d %M %Y') as startdate,startdate as orgstartdate
from rent inner join owns inner join customer inner join car where rentalcarid=car.carid and rent.customerid=customer.customerid and
rentalcarid=owns.carid and enddate is null and owns.dealerid=$dealerid order by startdate desc";
$ex = mysqli_query($conn,$rentedcarsquery1);
if(mysqli_num_rows($ex)===0)
{
?>
<div style="width:100%;border:1px solid #C39BD3;margin-top:15px;padding:10px 0;text-align:center;font-size:1.2rem;font-weight:lighter;color:black">No ongoing rents!</div>
<?php
}
while($row=mysqli_fetch_assoc($ex))
{
?>
<div class="col-sm-3">
<div class="card" style="overflow:hidden">
<div class="card-body">
<h5 class="card-title"><?php echo $row["name"] ?></h5>
<h6 class="card-subtitle mb-2">Rented on <?php echo $row["rentdate"]." by ".$row["customername"]?></h6>
<hr>
<h6 class="card-subtitle mb-2" style="color:black">Start date - <?php echo $row["startdate"]?></h6>
<a href="<?php echo "rentalcar.php?carid=".$row["rentalcarid"]?>" class="card-link">Car Details</a>
</div>
<?php
$today = date("Y-m-d");
$dateTimestamp1 = strtotime($row["startdate"]);
$dateTimestamp2 = strtotime($today);
if($dateTimestamp1<=$dateTimestamp2) //start date is greater than today
{
?>
<button type="button" class="btn btn-danger" style="border-radius:0" onclick="endrent(<?php echo $row['rentalcarid'].','.$row['customerid'].',\''.$row['orgstartdate'].'\'' ?>)">End Rent</button>
<?php }
else
{?>
<button type="button" class="btn btn-light" style="border-radius:0" onclick="alert('You can end the rent of a car only once it has started!')">End Rent</button>
<?php } ?>
</div>
</div>
<?php
}
?>
</div>
<h3 id="explore" style="font-weight:lighter;margin-top:50px">Finished</h3>
<div class="row">
<?php
$rentedcarsquery2 = "
select rentalcarid,customername,name,DATE_FORMAT(rentdate,'%d %M %Y') as rentdate,DATE_FORMAT(startdate,'%d %M %Y') as startdate,DATE_FORMAT(enddate,'%d %M %Y') as enddate
from rent inner join owns inner join customer
inner join car where rentalcarid=car.carid and rent.customerid=customer.customerid and
rentalcarid=owns.carid and enddate is not null and owns.dealerid=$dealerid order by startdate desc";
$ex2 = mysqli_query($conn,$rentedcarsquery2);
if(mysqli_num_rows($ex2)===0)
{
?>
<div style="width:100%;border:1px solid #C39BD3;margin-top:15px;padding:10px 0;text-align:center;font-size:1.2rem;font-weight:300;color:black">No finished rents!</div>
<?php
}
while($row=mysqli_fetch_assoc($ex2))
{
?>
<div class="col-sm-3">
<div class="card">
<div class="card-body">
<h5 class="card-title"><?php echo $row["name"] ?></h5>
<h6 class="card-subtitle mb-2">Rented on <?php echo $row["rentdate"]." by ".$row["customername"]?></h6>
<hr>
<h6 class="card-subtitle mb-2" style="color:black">Started on <?php echo $row["startdate"]?></h6>
<h6 class="card-subtitle mb-2" style="color:black">Ended on <?php echo $row["enddate"]?></h6>
<a href="<?php echo "rentalcar.php?carid=".$row["rentalcarid"]?>" class="card-link">Car Details</a>
</div>
</div>
</div>
<?php } ?>
</div>
</body>
<script type="text/javascript" src="JS/list.js"></script>
</html>