forked from Vimall03/Alimento
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrack_order.php
216 lines (185 loc) · 7.71 KB
/
track_order.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
<?php
session_start();
include 'partials/_dbconnect.php';
$uid = $_SESSION['user_id'];
$feedback = false;
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] != true) {
header("location: user_login.php");
exit;
}
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$r_id = $_POST['r_id'];
$order_id = $_POST['order_id'];
$rating = $_POST['rating'];
$sql = "UPDATE `orders` SET `rating` = '$rating' WHERE `r_id` = '$r_id' AND `order_id` = '$order_id'";
$result = mysqli_query($conn , $sql);
$sql = "SELECT * FROM `orders` WHERE `r_id` = '$r_id' AND `rating` != '0'";
$result = mysqli_query($conn , $sql);
$num = mysqli_num_rows($result);
$sql = "SELECT SUM(rating) AS 'sum_value' FROM `orders` WHERE `r_id` = '$r_id' AND `rating` != '0'";
$result = mysqli_query($conn , $sql);
$row = mysqli_fetch_assoc($result);
$sum = $row['sum_value'];
$new_rating = $sum/$num;
$sql = "UPDATE `restaurant` SET `r_rating` = '$new_rating' WHERE `r_id` = '$r_id'";
$result = mysqli_query($conn , $sql);
}
?>
<!DOCTYPE html>
<html>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="main.css">
<head>
<style>
.star-rating {
font-size: 24px;
}
.star-option {
display: none;
}
.star-label {
cursor: pointer;
}
.star-label:hover,
.star-label:hover~.star-label {
color: #ffc107;
/* Change the color on hover */
}
</style>
<title>Order Information</title>
<style>
table {
border-collapse: collapse;
width: 100%;
}
th,
td {
border: 1px solid black;
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<nav class="nav">
<div class="nav__wrapper grid">
<div class="grid__span2 nav__logo-wrap">
<a href="home.php">
<img class="nav__logo-img" src="images/logo/Logo.png">
</a>
</div>
<div class="grid__span10 nav__links-wrap">
<ul class="nav__links">
<li class="nav__link">
<form action="pin_search.php" method="post">
<input type="text" class="form-control " id="searchBar" name="pincode" placeholder="Search by Pincode" required>
</li>
<li class="nav__link">
<input type="submit" class="btn-dark form-control " value="Search">
</form>
</li>
<li class="nav__link">
<a href="track_order.php">
<img class="nav__link-icon" style="width: 1.8rem" src="images/favicons/tableware_50px.png">
<span class="nav__link-item">Orders</span>
</a>
</li>
<li class="nav__link">
<a href="#contact">
<img class="nav__link-icon" src="images/favicons/phone_32px.png">
<span class="nav__link-item">Contact </span>
</a>
</li>
<li class="nav__link">
<a href="user_logout.php">
<img class="nav__link-icon" style="width: 1.9rem" src="images/favicons/user_male_circle_32px.png">
<span class="nav__link-item">Logout</span>
</a>
</li>
</ul>
</div>
</div>
</nav>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<div class="container">
<h1>Order Information</h1>
<table class="table table-bordered">
<tr>
<th>Order ID</th>
<th>Order</th>
<th>Timing</th>
<th>Name</th>
<th>Amount</th>
<th>Phone</th>
<th>Address</th>
<th>Update Order</th>
<th>Feedback</th>
</tr>
<!-- Replace this section with PHP code to fetch data and loop through rows -->
<?php
// Replace this with your database connection code
// Replace this with your SQL query to retrieve data from the database
$sql = "SELECT * FROM `orders` WHERE `user_id` = '$uid' ";
$result = mysqli_query($conn, $sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>" . $row['order_id'] . "</td>";
echo "<td>" . $row['order'] . "</td>";
echo "<td>" . $row['dt'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['amount'] . "</td>";
echo "<td>" . $row['phone'] . "</td>";
echo "<td>" . $row['address'] . "</td>";
echo "<td>" . $row['order_status'] . "</td>";
$status = $row['order_status'];
$rate = $row['rating'];
if ($status == 'Delivered' && $rate == 0) {
echo "<th>";
echo "<form action='track_order.php' method='post'>";
echo "<input type='hidden' name='order_id' value='" . $row['order_id'] . "'>";
echo "<input type='hidden' name='r_id' value='" . $row['r_id'] . "'>";
echo "<select name='rating'>";
echo "<option value='1' " . ($row['order_status'] === '1' ? 'selected' : '') . ">1 ★ </option>";
echo "<option value='2' " . ($row['order_status'] === '2' ? 'selected' : '') . ">2 ★</option>";
echo "<option value='3' " . ($row['order_status'] === '3' ? 'selected' : '') . ">3 ★</option>";
echo "<option value='4' " . ($row['order_status'] === '4' ? 'selected' : '') . ">4 ★</option>";
echo "<option value='5' " . ($row['order_status'] === '5' ? 'selected' : '') . ">5 ★</option>";
echo "</select>";
echo "<input type='submit' value='rate'>";
echo "</form>";
echo "</th>";
} else if ($status == 'Delivered' && $rate != 0) {
echo '<th> Feedback recieved </th>';
} else if ($status != 'Delivered') {
echo '<th></th>';
}
}
} else {
echo "<tr><td colspan='8'>No Orders yet</td></tr>";
}
?>
<script>
const select = document.getElementById('rating');
select.addEventListener('change', (event) => {
const selectedValue = event.target.value;
alert(`You rated this item ${selectedValue} stars.`);
});
</script>
<!-- End of PHP section -->
</table>
</div>
</body>
</html>