-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaundry_request.php
153 lines (131 loc) · 5.48 KB
/
laundry_request.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
<?php
require 'config.php';
if(!isset($_SESSION["login"])){
header("Location: login.php");
}
if(isset($_POST["submit"])){
$user_id = $_SESSION["id"];
$user_id = $_POST["selected_user"]; // Get the selected user id from dropdown
$pickup_date = $_POST["pickup_date"];
$pickup_time = $_POST["pickup_time"];
$delivery_date = $_POST["delivery_date"];
$delivery_time = $_POST["delivery_time"];
$wash_fold = $_POST["wash_fold"];
$wash_iron = $_POST["wash_iron"];
$dry_clean = $_POST["dry_clean"];
$price = calculate_price($wash_fold, $wash_iron, $dry_clean);
$status = "Pending";
// Insert the data along with the selected user id
$sql = "INSERT INTO laundry_requests ( user_id, pickup_date, pickup_time, delivery_date, delivery_time, wash_fold, wash_iron, dry_clean, price, status)
VALUES ( '$user_id', '$pickup_date', '$pickup_time', '$delivery_date', '$delivery_time', '$wash_fold', '$wash_iron', '$dry_clean', '$price', '$status')";
if(mysqli_query($conn, $sql)){
echo "<script> alert('Laundry request submitted successfully.'); </script>";
}
else{
echo "<script> alert('Error: Unable to submit laundry request.'); </script>";
}
}
function calculate_price($wash_fold, $wash_iron, $dry_clean){
$wash_fold_price = 10.5; // $10.5 per pound
$wash_iron_price = 20.0; // $20.0 per pound
$dry_clean_price = 30.5; // $30.5 per item
$total_price = $wash_fold * $wash_fold_price + $wash_iron * $wash_iron_price + $dry_clean * $dry_clean_price;
return round($total_price, 2);
}
// Fetch users from the database
$user_query = "SELECT id, name FROM users";
$user_result = mysqli_query($conn, $user_query);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add Request</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom Styles -->
<style>
.content {
margin-left: 250px;
padding: 20px;
}
@media (max-width: 767px) {
.content {
margin-left: 0;
}
}
</style>
</head>
<body>
<!-- Include Sidebar -->
<?php include 'sidebar.php'; ?>
<!-- Mobile Menu -->
<div class="mobile-menu">
<a href="logout.php">Logout</a> |
<a href="laundry_request.php">Add Request</a> |
<a href="view_request.php">View Requests</a>
</div>
<!-- Content Section -->
<div class="content">
<h2 class="mb-4">Laundry Request Form</h2>
<form class="needs-validation" action="" method="post" novalidate>
<div class="row">
<div class="col-md-6">
<div class="mb-3">
<label for="selected_user" class="form-label">Select User:</label>
<select name="selected_user" id="selected_user" class="form-control" required>
<option value="" disabled selected>Select a user</option>
<?php while($user = mysqli_fetch_assoc($user_result)): ?>
<option value="<?php echo $user['id']; ?>"><?php echo $user['name']; ?></option>
<?php endwhile; ?>
</select>
</div>
<div class="mb-3">
<label for="pickup_date" class="form-label">Pickup Date:</label>
<input type="date" name="pickup_date" id="pickup_date" class="form-control" required>
</div>
<div class="mb-3">
<label for="pickup_time" class="form-label">Pickup Time:</label>
<input type="time" name="pickup_time" id="pickup_time" class="form-control" required>
</div>
</div>
<div class="col-md-6">
<div class="mb-3">
<label for="delivery_date" class="form-label">Delivery Date:</label>
<input type="date" name="delivery_date" id="delivery_date" class="form-control" required>
</div>
<div class="mb-3">
<label for="delivery_time" class="form-label">Delivery Time:</label>
<input type="time" name="delivery_time" id="delivery_time" class="form-control" required>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="mb-3">
<label for="wash_fold" class="form-label">Wash & Fold (number of clothes):</label>
<input type="number" name="wash_fold" id="wash_fold" class="form-control" min="0" value="0">
</div>
</div>
<div class="col-md-4">
<div class="mb-3">
<label for="wash_iron" class="form-label">Wash & Iron (number of clothes):</label>
<input type="number" name="wash_iron" id="wash_iron" class="form-control" min="0" value="0">
</div>
</div>
<div class="col-md-4">
<div class="mb-3">
<label for="dry_clean" class="form-label">Dry Clean (number of clothes):</label>
<input type="number" name="dry_clean" id="dry_clean" class="form-control" min="0" value="0">
</div>
</div>
</div>
<button type="submit" name="submit" class="btn btn-primary">Submit</button>
<a href="index.php" class="btn btn-secondary ms-2">Go back</a>
</form>
</div>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.min.js"></script>
</body>
</html>