-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathprofile.php
352 lines (318 loc) · 12.8 KB
/
profile.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
<?php
//today date
$today_date = date("Y/n/j/");
session_start();
include './includes/config.php';
//deleting returned items
if(isset($_POST['deleteReturned'])){
session_start();
include_once './includes/config.php';
$sql = "DELETE FROM rentorders where cid={$_SESSION['id']} AND delivered_status='delivered' AND returned_status='returned'"; //sql query for deleting
$sql1 = "DELETE FROM return_request where customer_id={$_SESSION['id']} AND returned_status='returned'"; //sql query for deleting
$conn->query($sql); //executing sql query
$conn->query($sql1); //executing sql query
header("Location:./profile.php?action=ReturnedBookDeletedSuccessfully");
}
//sending return request
if(isset($_POST['send_request'])){
$sql = "SELECT * FROM return_request where customer_id='{$_SESSION['id']}'
AND book_id = '{$_GET['bid']}' AND return_date='{$_POST['r_date']}' AND quantity='{$_POST['quant']}'";
$result = $conn->query($sql);
if ($result->num_rows === 0) {
$sql = "INSERT INTO return_request (
customer_id,
book_id,
return_date,
requested_date,
quantity
) VALUES(
{$_SESSION['id']},
{$_GET['bid']},
'{$_POST['r_date']}',
'{$today_date}',
{$_POST['quant']}
)";
$conn->query($sql);
$conn->close();
echo "<script type='text/javascript'>
alert('Your request has sent to our admin');
window.location.href = './profile.php?id=" . $_SESSION['id'] . "';
</script>";
}else{
echo "<script type='text/javascript'>
alert('Your request has been already sent to admin wait for our call');
window.location.href = './profile.php?id=" . $_SESSION['id'] . "';
</script>";
}
}
?>
<?php
include_once './includes/navbar.php';
//restriction for unauthorized access
if(!(isset($_SESSION['id']))){
header("location:login.php?Unathorized");
die();
}
if(isset($_POST['update'])){
$sql6 = "UPDATE customer
SET customer_name= '{$_POST['name']}' ,
customer_email= '{$_POST['email']}' ,
customer_pwd= '{$_POST['pwd']}' ,
customer_phone= '{$_POST['phone']}' ,
customer_address= '{$_POST['address']}'
WHERE customer_id= '{$_SESSION['id']}' ";
$conn->query($sql6);
echo "<h3 style='text-align:center;position:absolute;top:70px;left:11%;padding:0'>Your Profile Updated Successfully</h3>";
}
$sql ="SELECT * FROM customer WHERE customer_id='{$_SESSION['id']}';";
$result = $conn->query($sql);
$row = $result->fetch_assoc();
$_SESSION['role'] = $row['customer_role'];
$conn->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Account</title>
<style>
*{
margin:0;padding:0;
}
/* .fa {
color: grey !important;
} */
.facross{
color: #DC143C !important;
}
.fadeliver{
color: green !important;
}
.profileCont{
display:flex;
align-items:center;
justify-content:center;
flex-direction:column;
gap:10px;
}
input {
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 16px;
width: 300px;
box-sizing: border-box;
transition: border-color 0.3s ease;
}
input:focus {
outline: none;
border-color:skyblue;
}
</style>
</head>
<body>
<div class='profileCont'>
<?php
if(isset($_GET['id']) || isset($_GET['action'])){
?>
<div style="margin-top:60px;position:relative">
<div style='text-align:center'>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<div>
<div style='border:1px solid skyblue;width:100%;text-align:center'></div>
<h2 >Ordered History</h2>
<span style='margin-right:5px'><b>Delete Returned Books</b>
</span>
<div style='text-align:center;margin:20px;display:flex;justify-content:center'><input name='deleteReturned' type='submit' value='Delete' class="btn btn-danger" style="background:#DC143C;"></input>
</div>
<div style='border:1px solid skyblue;width:100%;text-align:center'></div>
</div>
</form>
<div style='display:flex;flex-direction:column;justify-content:center;flex-wrap:wrap;align-items:center'>
<table style="border-collapse: collapse; text-align: center; ">
<thead>
<tr>
<th style="background-color: skyblue; padding: 10px; font-size: 18px; text-align: center;">
S.N
</th>
<th style="background-color: skyblue; padding: 10px; font-size: 18px; text-align: center;">
Image
</th>
<th style="background-color: skyblue; padding: 10px; font-size: 18px; text-align: center;">
Name
</th>
<th style="background-color: skyblue; padding: 10px; font-size: 18px; text-align: center;">
Quantity
</th>
<th style="background-color: skyblue; padding: 10px; font-size: 18px; text-align: center;">
Total Price
</th>
<th style="background-color: skyblue; padding: 10px; font-size: 18px; text-align: center;">
Orders Date
</th>
<th style="background-color: skyblue; padding: 10px; font-size: 18px; text-align: center;">
Return Date
</th>
<th style="background-color: skyblue; padding: 10px; font-size: 18px; text-align: center;">
Day Left
</th>
<th style="background-color: skyblue; padding: 10px; font-size: 18px; text-align: center;">
Delivered
Status
</th>
<th style="background-color: skyblue; padding: 10px; font-size: 18px; text-align: center;">
Return Settlement </th>
<th style='background-color: skyblue; padding: 10px; font-size: 18px; text-align: center'>Returned Status</th>
</tr>
</thead>
<tbody>
<?php
//this will dynamically fetch data from a database and show all the rented books
include "includes/config.php";
$sql10 = "SELECT * FROM rentorders where cid='{$_SESSION['id']}'";
$result10 = $conn->query($sql10);
$sn=0;
if ($result10->num_rows > 0) {
while($row10 = $result10->fetch_assoc()) {
$sn++;
$sql11 = "SELECT * FROM books where book_id='{$row10['bid']}' ";
$result11 = $conn->query($sql11);
$row11 = $result11->fetch_assoc();
?>
<tr>
<form action='<?php echo $_SERVER['PHP_SELF']?>?bid=<?php echo $row10['bid']?>' method='post'>
<td style="padding: 10px; width:30%; font-weight: bold;"><h5><?php echo $sn ?></h5></td>
<td style="padding: 10px; width:30%; font-weight: bold;"><img class='image' style="height:50px;width:50px" src="admin/upload/<?php echo $row11['book_img'] ?>" alt="book-img"></td>
<td style="padding: 10px; width:30%; font-weight: bold;"><h5><?php echo $row11['book_title'] ?></h5></td>
<td style="padding: 10px; width:30%; font-weight: bold;"><input type="text" name='quant' value='<?php echo $row10['quantity'] ?>' readonly style='outline:none;border:none;width:100%;background:none'></td>
<td style="padding: 10px; width:30%; font-weight: bold;"><h5>Rs <?php echo $row10['price']*$row10['quantity'] ?></h5></td>
<td style="padding: 10px; width:30%; font-weight: bold;"><h5><?php echo $row10['date'] ?></h5></td>
<td style="padding: 10px; width:30%; font-weight: bold;"><input type='date' name='r_date' value='<?php echo $row10['return_date'] ?>' readonly style='outline:none;border:none;width:100%;background:none'></td>
<td style="padding: 10px; width:30%; font-weight: bold;"><h5><?php
$dayToReturn = dateDiffInDays($row10['return_date'],$today_date);
echo $dayToReturn-19559;
?></h5></td>
<td style="padding: 10px; width:30%; font-weight: bold;"><h5><?php echo $row10['delivered_status'] ?>
<?php echo ($row10['delivered_status']=='pending'?'<i class="fa fa-clock-o fa-lg" aria-hidden="true"></i>':'<i class="fa fa-lg fa-check-circle fadeliver" aria-hidden="true"></i>')?>
</h5></td>
<td style="padding: 10px; width:30%; font-weight: bold;"><h5>
<?php if($row10['delivered_status']==='delivered' AND $row10['returned_status']==='pending') echo "<button name='send_request' type='submit' style='background:grey;border:none;font-size:12px' class='btn'>return request</button>"?>
<?php echo($row10['returned_status'])==='returned'?"<p style='background:grey;border:none;font-size:12px;cursor:pointer' class='btn' readonly>success <i class='fa-solid fa-check'></i></p>":' '?>
</h5></td>
<td style="padding: 10px; width:30%; font-weight: bold;"><h5>
<?php echo ($row10['returned_status']=='pending'?'<i class="fa-solid fa-circle-xmark fa-lg facross"></i>
':'<i class="fa-solid fa-check-double fadeliver fa-lg"></i>
')?>
</h5>
</td>
</form>
</tr>
<?php }}else { echo "No Results Found";
}
$conn->close();
?>
</tbody>
</table>
</div>
</div>
<?php
}else{
?>
<table style="border-collapse: collapse; text-align: left;margin-top:60px ">
<thead>
<tr>
<th colspan="2" style="background-color: skyblue; padding: 10px; font-size: 18px; text-align: center;">
Personal Details
</th>
</tr>
</thead>
<tbody>
<form action="<?php echo $_SERVER["PHP_SELF"] ?>" method="POST">
<tr>
<td style="padding: 10px; width:30%; font-weight: bold;"><h5> Name:</h5></td>
<td style="padding: 10px; width:50%;"><input type='text' name='name' value="<?php echo $row['customer_name'] ?>" style="margin: 0;position:relative">
<?php
if($_SESSION['role'] ==='admin') {
echo "<span class='btn btn-medium' style='background:aliceblue'>"."<a id='admin' href='./admin/index.php'>"."Admin"."</a>"."</span>";
}
?>
</input></td>
</tr>
<tr>
<td style="padding: 10px; width:30%; font-weight: bold;"><h5> Email:</h5></td>
<td style="padding: 10px; width:50%;"><input type='email' name='email' value="<?php echo $row['customer_email'] ?>" style="margin: 0;"></input></td>
</tr>
<tr>
<td style="padding: 10px; width:30%; font-weight: bold;"><h5> Password:</h5></td>
<td style="padding: 10px; width:50%;"><input type='text' name='pwd' value="<?php echo $row['customer_pwd'] ?>" style="margin: 0;"></input></td>
</tr>
<tr>
<td style="padding: 10px; width:30%; font-weight: bold;"><h5>Phone:</h5></td>
<td style="padding: 10px; width:50%;"><input type='number' maxlength='10' name='phone' value="<?php echo $row['customer_phone'] ?>" style="margin: 0;"></input></td>
<tr>
<td style="padding: 10px; width:30%; font-weight: bold;"><h5>Address:</h5></td>
<td style="padding: 10px; width:50%;"><input type='text' name='address' value="<?php echo $row['customer_address'] ?>" style="margin: 0;"></input></td>
</tr>
</tr>
<tr>
<td style="padding: 10px; width:30%; font-weight: bold;"><h5> Action:</h5></td>
<td style="padding: 10px; width:50%;"><input name='update' type='submit' value='Update'></input></td>
</tr>
</form>
</tbody>
</table>
<div style='border:1px solid skyblue;width:50%;text-align:center'></div>
<h3 style='text-align:center'> <a style='' href="./profile.php?id=<?php echo $_SESSION['id']?>">Book Rented History</a> </h3>
<div style='border:1px solid skyblue;width:50%;text-align:center'></div>
<?php
}?>
</div>
</body>
</html>
<?php
//calculate day between two date
function dateDiffInDays($date1, $date2) {
$oneDay = 60 * 60 * 24; // 1 day in seconds
// Convert date strings to timestamps
$timestamp1 = strtotime($date1);
$timestamp2 = strtotime($date2);
// Calculate the difference in seconds
$diffInSeconds = abs($timestamp1 - $timestamp2);
// Convert the difference to days
$diffInDays = round($diffInSeconds / $oneDay);
return $diffInDays;
}
//rent charge calculating ()
function rentRate($day){
switch ($day) {
case $day>0 && $day<=25:
return 23;
break;
case $day>25 && $day<=30:
return 25;
break;
case $day>30 && $day<=80:
return 32;
break;
case $day>80 && $day<=90:
return 35;
break;
case $day>90 && $day<=160:
return 42;
break;
case $day>160 && $day<=180:
return 45;
break;
case $day>180 && $day<=300:
return 48;
break;
case $day>300 && $day<=366:
return 50;
break;
default:
return 80;
break;
}
}
?>