-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpfle.php
301 lines (245 loc) · 12.5 KB
/
pfle.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
<?php require_once('inc/Connection.php'); ?>
<?php require_once('inc/functions.php'); ?>
<?php session_start(); ?>
<?php
//Checking if the user logged in
$_SESSION['has_logged'] ='';
if(!isset($_SESSION['user_id'])){
$_SESSION['has_logged'] = 'no';
header('Location: login.php');
}
$currentp = '';
if(isset($_POST['change'])){
$currentp = $_POST['currentp'];
$newp = $_POST['newp'];
$retypep = $_POST['retypep'];
$user_id = $_POST['user_id'];
$errors = array();
//Checking required fields
$req_fields =array('user_id','currentp', 'newp','retypep');
$errors = array_merge($errors, check_req_fields($req_fields));
if(empty($errors)){
$currentp = mysqli_real_escape_string($Connection, $_POST['currentp']);
$newp = mysqli_real_escape_string($Connection, $_POST['newp']);
$retypep = mysqli_real_escape_string($Connection, $_POST['retypep']);
$query = "SELECT password FROM user WHERE id = '{$user_id}' LIMIT 1";
$result = mysqli_query($Connection, $query);
if($result){
if(mysqli_num_rows($result) == 1){
$row = mysqli_fetch_assoc($result);
$cp = sha1($currentp);
if($cp == $row['password']){
if($newp == $retypep){
$np = sha1($newp);
$query = "UPDATE user SET password = '{$np}', re_password = '{$np}' WHERE id = '{$user_id}' LIMIT 1";
$result = mysqli_query($Connection, $query);
if($result){
}else{
echo "<b><h1>404</h1>Database sql query failed</b>";
die();
}
}else{
$errors[] = 'The new password and retyped password is different.';
}
}else{
$errors[] = 'The current password you entered is invalid.';
}
}else{
echo "<b><h1>404</h1>No such user</b>";
die();
}
}else{
echo "<b><h1>404</h1>Database query failed</b>";
die();
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Tripplin Car Rent</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.0-2/css/all.min.css" integrity="sha256-46r060N2LrChLLb5zowXQ72/iKKNiw/lAmygmHExk/o=" crossorigin="anonymous" />
<link rel="stylesheet" type="text/css" href="css/pfle.css">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>
</head>
<body>
<?php require_once('inc/hdr.php'); ?>
<div class="Profile">
<div class="Inside">
<h1>Profile</h1>
<div style="margin-left: 25%; color: red; font-family: sans-serif; margin-top: 30px;">
<?php if(!empty($errors)){
display_errors($errors);
}?>
</div>
<?php
if(isset($errors) && empty($errors)){
?><h3 style="font-family: sans-serif; background-color: #35aa58; padding: 10px 35px; text-align: center; width: 75%; margin: 0 auto;">You have changed your password successfully</h3><?php
}
?>
<div class="Information">
<?php
$qr = "SELECT * FROM user WHERE id = '{$_SESSION['user_id']}' LIMIT 1";
$re = mysqli_query($Connection, $qr);
if($re){
if(mysqli_num_rows($re) == 1){
$u_dat = mysqli_fetch_assoc($re);
}else{
echo "No user found";
}
}else{
echo "Database query failed";
}
?>
<h3 class="Topic">Name</h3><h3 class="Answer"><?php echo $u_dat['first_name']; ?> <?php echo $u_dat['last_name']; ?></h3><br>
<h3 class="Topic">Userame</h3><h3 class="Answer"><?php echo $u_dat['username']; ?></h3><br>
<h3 class="Topic">Address</h3><h3 class="Answer"><?php echo $u_dat['ad_line1']; ?> <?php echo $u_dat['ad_line2']; ?> <?php echo $u_dat['ad_line3']; ?></h3><br>
<h3 class="Topic">Phone</h3><h3 class="Answer"><?php echo $u_dat['phone_code']; ?> <?php echo $u_dat['phone_number']; ?></h3><br>
<h3 class="Topic">Nic</h3><h3 class="Answer"><?php echo $u_dat['nic']; ?></h3><br>
<h3 class="Topic">Email</h3><h3 class="Answer"><?php echo $u_dat['email']; ?></h3><br>
<h3 class="Topic">Gender</h3><h3 class="Answer"><?php echo $u_dat['gender']; ?></h3><br>
<h3 class="Topic">Password</h3><h3 class="Answer">*********</h3><br>
<h3 class="Topic"><a href="income.php?total_income=true" style="margin: 0; float: left;"><button style=" padding: 10px 30px; border-radius: 20px; background-color: orange; font-family: sans-serif; font-weight: bold; font-size: 16px; border: none;">Check Income <i class="fas fa-hand-holding-usd"></i></button></a></h3>
<h3 class="Answer changepre" id="changepre" style="border: none;"><!-- <a href="#" style="float: left;"> --><button>Change Password</button><!-- </a> --></h3>
<form action="pfle.php" method="post">
<div class="Changepassword" style="display: none;">
<p><input type="hidden" name="user_id" value="<?php echo($_SESSION['user_id']); ?>"></p>
<p><h3 class="subtopic">Current Password:</h3><input type="text" name="currentp" <?php echo 'value="' .$currentp. '"'; ?>></p>
<p><h3 class="subtopic">New Password:</h3><input type="password" name="newp"></p>
<p><h3 class="subtopic">Retype Password:</h3><input type="password" name="retypep"></p>
<button name="change" class="change">Change Password</button>
</div><!-- Changepassword -->
</form>
<script type="text/javascript">
document.getElementById('changepre').addEventListener('click',function(){
document.querySelector('.Changepassword').style.display = 'block';
document.querySelector('.changepre').style.display = 'none';
});
</script>
</div><!--Information-->
<div class="Usage">
<!-- <img src="img/White-Lamborghini-wallpapers-HD-for-desktop.jpg" alt="Immage"> -->
<h2>Booked Vehicles <i class="far fa-handshake"></i></h2>
<div class="Info clearfix">
<?php
$query = "SELECT * FROM booked_vehicles WHERE booked_user_id = '{$_SESSION['user_id']}' AND is_deleted_by_user != 1 /*AND status != 'deleted'*/";
$result = mysqli_query($Connection, $query);
if($result){
if(mysqli_num_rows($result) > 0){
while ($data = mysqli_fetch_assoc($result)) {
$sub_query = "SELECT * FROM rented_vehicles WHERE post_id = '{$data['rented_post_id']}' LIMIT 1";
$sub_result = mysqli_query($Connection, $sub_query);
// echo $sub_query;
// die();
if($sub_result){
if(mysqli_num_rows($sub_result) == 1){
$sub_data = mysqli_fetch_assoc($sub_result);
$kind = print_kind($sub_data['kind_of_vehicle']);
?><div class="Item">
<img src="web_img/<?php echo($kind); ?>/<?php echo($sub_data['kind_of_vehicle']); ?>/<?php echo($sub_data['post_id']); ?>/<?php echo($sub_data['front_side_img']); ?>" alt="Vehicle photo here" style="height: 250px;">
<h3><?php echo $data['vehicle_name']; ?></h3>
<p style="border-bottom: 1px solid #808080; padding-bottom: 10px; color: yellow; text-align: center; font-size: 20px;"><?php echo $sub_data['price']; ?> /= per day</p>
<h5 style="padding: 10px 0 0 0; font-weight: bold; color: #808080; ">@ <?php echo $data['booked_time']; ?></h5>
<h1 style="float: left; border:none; margin: 0;">|</h1>
<div class="datedata" style="float: left; padding-top: 5px;">
<h5 style="font-family: sans-serif; font-weight: bold;">Picking date:</h5>
<p style=" font-weight: bold; color: orange; padding-bottom: 20px;"><?php echo $data['picking_date']; ?></p>
</div>
<div class="datedata" style="float: right; padding-top: 5px;">
<h5 style="font-family: sans-serif; font-weight: bold;">Returning date:</h5>
<p style=" font-weight: bold; color: #00bc8c; padding-bottom: 20px;"><?php echo $data['returning_date']; ?></p>
</div>
<h1 style="float: right; text-align: right; border:none; margin: 0;">|</h1>
<?php
$bgc = status($data['status']);
switch ($data['status']) {
case 'pending':
?><h3 class="h3" style="padding-left: 15px; padding-right: 15px; background-color: <?php echo $bgc; ?>">Your booking is pending.</h3><?php
break;
case 'confirmed':
?><h3 class="h3" style="padding-left: 15px; padding-right: 15px; background-color: <?php echo $bgc; ?>">Your booking has been confirmed.</h3><?php
break;
case 'deleted':
?><h3 class="h3" style="padding-left: 15px; padding-right: 15px; background-color: <?php echo $bgc; ?>">Your booking has been deleted by admins.</h3><?php
break;
case 'returned':
?><h3 class="h3" style="padding-left: 15px; padding-right: 15px; background-color: <?php echo $bgc; ?>">Your have returned the vehicle.</h3><?php
break;
}
?>
<div class="empty"></div>
<div class="but">
<a href="singlevehicle.php?post_id=<?php echo($sub_data['post_id']); ?>"><button style="background-color: orange;">Check</button></a>
<?php
if($data['status'] == 'pending'){
?><a href="delete.php?post_id=<?php echo($data['post_id']); ?>&category=booked" onclick="return confirm('Are you sure you want to cancel this booking?');"><button style="background-color: red;">Cancel</button></a><?php
}
?>
</div>
</div><!-- car --><?php
}else{
echo "Something went wrong";
}
}else{
echo "Database sub query failed";
}
}
}else{
echo "<h3 style=\"padding: 10px 0 20px 0; text-align: center; color: #aaa; font-family: sans-serif;\">No booked vehicles found</h3>";
}
}else{
echo "Database query failed";
}
?>
</div><!--Info-->
<h2>Rented Vehicles <i class="far fa-window-restore"></i></h2>
<div class="Info clearfix">
<?php
$query = "SELECT * FROM rented_vehicles WHERE user_id = '{$_SESSION['user_id']}' AND is_deleted != 1";
$result = mysqli_query($Connection, $query);
if($result){
if(mysqli_num_rows($result) > 0){
while ($data = mysqli_fetch_assoc($result)) {
$kind = print_kind($data['kind_of_vehicle']);
?><div class="Item">
<img src="web_img/<?php echo($kind); ?>/<?php echo($data['kind_of_vehicle']); ?>/<?php echo($data['post_id']); ?>/<?php echo($data['front_side_img']); ?>" alt="Vehicle photo here" style="height: 250px;">
<h3><?php echo $data['vehical_name']; ?></h3>
<p style="text-align: center;"><?php echo $data['mnf_year']; ?></p>
<p style="text-align: center;"><?php echo $data['province']; ?> Province</p>
<p style="text-align: center;"><?php echo $data['district']; ?> District</p>
<h3 style="color: yellow"><?php echo $data['price']; ?> /=<br><span style="color: #808080;">LKR per day</span></h3>
<div class="but">
<a href="income.php?post_id=<?php echo($data['post_id']); ?>"><button style="background-color: green;">Income</button></a>
<a href="singlevehicle.php?post_id=<?php echo($data['post_id']); ?>"><button style="background-color: #00bc8c;">Look</button></a>
<?php
$sql = "SELECT * FROM booked_vehicles WHERE rented_post_id = '{$data['post_id']}' AND ( status != 'deleted' AND is_deleted_by_user != 1 )";
$res = mysqli_query($Connection, $sql);
if($res){
if(mysqli_num_rows($res) == 0){
?><a href="delete.php?post_id=<?php echo($data['post_id']); ?>&category=rented" onclick="return confirm('Are you sure you want to delete this renting?');"><button style="background-color: red;">Delete</button></a><?php
}
}else{
echo "Getting bookings databasex query failed";
}
?>
</div>
</div><!-- car --><?php
}
}else{
echo "<h3 style=\"padding: 10px 0 20px 0; text-align: center; color: #aaa; font-family: sans-serif;\">No rented vehicles found</h3>";
}
}else{
echo "Database query failed";
}
?>
</div><!--Info-->
</div><!--Usage-->
</div><!--Inside-->
</div><!--Profile-->
<?php require_once('inc/ftr.php'); ?>
<?php mysqli_close($Connection); ?>
</body>
</html>