-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrental_form.php
414 lines (326 loc) · 11.3 KB
/
rental_form.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'];
if(isset($_POST["submit"]))
{
$m_name = mysqli_real_escape_string($conn, $_POST["m_name"]);
$query1 = "Select manufacturerid from manufacturer where mname = '$m_name'";
$ex1 = mysqli_query($conn, $query1);
$res1 = mysqli_fetch_assoc($ex1);
$m_id = $res1["manufacturerid"];
$rentamt = mysqli_real_escape_string($conn, $_POST["rentamt"]);
$licenseplateno = mysqli_real_escape_string($conn, $_POST["licenseplateno"]);
//prepared statement
$prepstat = "insert into car(name,cartype,mileage,color,status,fueltype,manufacturedate,licenseplateno,manufacturerid) values (?,'rental',?,?,'available',?,?,?,?)";
if($stmt = mysqli_prepare($conn, $prepstat))
{
//binding variables
$name = mysqli_real_escape_string($conn, $_POST["name"]);
$color = mysqli_real_escape_string($conn, $_POST["color"]);
$mileage = mysqli_real_escape_string($conn, $_POST["mileage"]);
$m_date = mysqli_real_escape_string($conn, $_POST["m_date"]);
$fueltype = mysqli_real_escape_string($conn, $_POST["fueltype"]);
//echo $name." ".$color." ".$mileage." ".$m_date." ".$fueltype." ".$price." ".$m_id;
mysqli_stmt_bind_param($stmt, "sssssss", $name, $mileage, $color, $fueltype, $m_date,$licenseplateno, $m_id);
if(mysqli_stmt_execute($stmt))
{
//echo "Inserted successfully into cars table";
$query2 = "Select carid from car where name = '$name' order by uploadedtime desc limit 1";
$ex2 = mysqli_query($conn, $query2);
$res2 = mysqli_fetch_assoc($ex2);
$car_id = $res2["carid"];
$ownsquery = "insert into owns values ($car_id,$dealerid)";
if(mysqli_query($conn, $ownsquery))
{
$priceinsertquery = "insert into rentalcar(rentalcarid,rentamount) values ($car_id,$rentamt)";
if(mysqli_query($conn, $priceinsertquery))
{
//echo "Inserted successfully into newcar table!";
$f1 = mysqli_real_escape_string($conn, $_POST["f1"]);
$f2 = mysqli_real_escape_string($conn, $_POST["f2"]);
$f3 = mysqli_real_escape_string($conn, $_POST["f3"]);
$f4 = mysqli_real_escape_string($conn, $_POST["f4"]);
$featuresarr = array($f1,$f2,$f3,$f4);
$i = 0;
while($i<4)
{
$featurequery = "insert into features values ($car_id,'$featuresarr[$i]')";
if(!mysqli_query($conn, $featurequery))
{
echo "Error while inserting feature into table!";
header("Location: error.php");
}
$i++;
}
if(isset($_FILES['carimage']))
{
$target_dir = "Images/";
$file_name = $_FILES['carimage']['name']; //original name of file in client's computer
$file_tmp = $_FILES['carimage']['tmp_name']; //temp name stored in server until processing
$imageFileType = strtolower(pathinfo($file_name,PATHINFO_EXTENSION));
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg")
{
//echo "Sorry only JPG, JPEG, PNG files are allowed.";
header("location:error.php");
}
else
{
if(!is_dir($target_dir. $car_id ."/")) { //creating a new directory for that car
mkdir($target_dir. $car_id ."/");
}
$target_dir = $target_dir. $car_id."/"; //changing the target directory
$newfilename="1.".$imageFileType;
move_uploaded_file($file_tmp, $target_dir.$newfilename); //uploading file to the given directory
$imgpath=$target_dir.$newfilename;
$imageinsert = "insert into images(carid,images) values ($car_id,'$imgpath')";
if($imageex= mysqli_query($conn, $imageinsert))
{
$_SESSION['newcaradded'] = true;
header("location:dealer_index.php");
}
else
{
echo "some error occured while inserting image path in database!";
header("Location: error.php");
}
}
}
$_SESSION['newcaradded'] = true;
header("location:dealer_index.php");
}
else
{
echo "Some error occurred while inserting data!" . mysqli_error($conn);
header("Location: error.php");
}
}
else
{
echo "Some error occurred while inserting data in owns table!";
header("Location: error.php");
}
}
else
{
echo "Error: Could not execute the query: " . mysqli_error($conn);
header("Location: error.php");
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8">
<link rel="icon" href="icon.ico">
<title>Add Rental Car - Rustom</title>
<link href="https://fonts.googleapis.com/css2?family=Rubik&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
<style>
html, body {
min-height: 100%;
background-color:#F2ECF5;
}
body, div, form, input, select, textarea, p {
padding: 0;
margin: 0;
outline: none;
font-family: 'Rubik', sans-serif;
font-size: 16px;
color: #000;
line-height: 30px;
}
h1 {
position: absolute;
margin: 0;
font-size: 36px;
color: #fff;
z-index: 2;
}
.testbox {
display: flex;
justify-content: center;
align-items: center;
height: inherit;
padding: 20px;
}
form {
width: 80%;
padding: 20px;
border-radius: 6px;
background: #fff;
box-shadow: 0 0 20px 0 #333;
}
.banner {
position: relative;
height: 210px;
display: flex;
justify-content: center;
align-items: center;
background-image:linear-gradient(to right, #5F396F, #C39BD3);
text-align: center;
margin-bottom:20px;
}
.banner::after {
content: "";
background-color: rgba(0, 0, 0, 0.4);
position: absolute;
width: 100%;
height: 100%;
}
input, select {
margin-bottom:15px;
margin-top:5px;
border: 1px solid #c0c0c0;
border-radius: 5px;
padding: 7.5px;
transition:all 0.15s ease-in-out;
}
input {
width: calc(100% - 15px);
}
select {
width: 100%;
padding: 10px 5px;
background: transparent;
}
.item:hover p, .item:hover i, .question:hover p, .question label:hover, input:hover::placeholder {
color: #333;
}
.item input:hover, .item select:hover,.name-item input:hover,.item input:focus, .item select:focus,.name-item input:focus {
border: 1px solid transparent;
box-shadow: 0 0 6px 0 #5F396F;
}
.item {
position: relative;
margin: 10px 0;
}
.btn-block {
margin-top: 10px;
text-align: center;
}
button {
width: 25%;
padding: 15px;
font-family: 'Rubik', sans-serif;
border: none;
border-radius: 5px;
background-color:#5F396F;
font-size: 18px;
color: #fff;
cursor: pointer;
transition:all 0.2s ease-in-out;
margin-bottom:15px;
}
button:hover {
background-color:#C39BD3;
}
@media (min-width: 568px) {
.name-item, .city-item {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.name-item input, .city-item input {
width: calc(50% - 20px);
}
.city-item select {
width: calc(50% - 8px);
}
}
@media screen and (max-width:769px)
{
form {
width: 100%;
}
button {
width: 100%;
}
}
</style>
</head>
<script type="text/javascript">
function back()
{
window.location.href="dealer_index.php";
}
</script>
<body>
<?php
$manuquery = "select mname from manufacturer";
$manuex = mysqli_query($conn, $manuquery);
?>
<div class="testbox">
<form action="" method="POST" enctype="multipart/form-data">
<div id="back" style="border-radius:5px;padding:10px;background-color:#D7BDE2;color:#512E5F;margin-bottom:10px;cursor:pointer;width:fit-content;font-size:18px" onclick="back()">< Go back</div>
<div class="banner">
<h1>Rental Car Form</h1>
</div>
<div class="item">
<b>Basic Car Details</b>
<div class="item">
<!--<input type="text" name="m_name" placeholder="Manufacturer Name" required/>-->
Manufacturer Name
<select name="m_name" required>
<?php
while($row=mysqli_fetch_assoc($manuex))
{
?>
<option value="<?php echo $row['mname']?>"><?php echo $row['mname']?></option>
<?php
}
?>
</select>
</div>
<div class="item">
<input type="text" name="name" placeholder="Car Name (along with manufacturer name | eg - Ford EcoSport)" required>
</div>
<div class="name-item">
<input type="text" name="color" placeholder="Color" required/>
<input type="number" name="mileage" placeholder="Mileage (km/l)" step="0.1" min="0" required>
</div>
</div>
<div class="item">
Manufacture Date
<input type="date" name="m_date" required>
</div>
<div class="item">
<input type="text" name="licenseplateno" placeholder="License Plate no" required>
</div>
<div class="item">
Fuel Type
<select name="fueltype" required>
<option value="petrol" selected>Petrol</option>
<option value="diesel">Diesel</option>
</select>
</div>
<div class="item">
<input type="number" name="rentamt" placeholder="Rent Amount per hour (in INR only)" min="0" required>
</div>
<b>FEATURES (required)</b>
<div class="name-item">
<input type="text" name="f1" placeholder="Car feature 1" required>
<input type="text" name="f2" placeholder="Car feature 2" required>
</div>
<div class="name-item">
<input type="text" name="f3" placeholder="Car feature 3" required>
<input type="text" name="f4" placeholder="Car feature 4" required>
</div>
<div class="item">
<b>Choose a car image (optional)</b>
<input type="file" name="carimage" style="display:flex;align-items:center">
</div>
<div class="btn-block">
<button type="submit" name="submit">ADD CAR</button>
</div>
</form>
</div>
</body>
</html>