-
Notifications
You must be signed in to change notification settings - Fork 2
/
rating.php
240 lines (211 loc) · 7.89 KB
/
rating.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
<?php
session_start();
// checking if user is logged in or not
if (!isset($_SESSION['customer'])) {
header("Location: login.php");
}
// including database connection
require('env/database.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Rating</title>
<link rel="icon" type="image/x-icon" href="assets/svg-logo/logo-bg.svg">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" type="text/css" media="screen" href="main.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" />
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://kit.fontawesome.com/db79afedbd.js" crossorigin="anonymous"></script>
<link rel="stylesheet" type="text/css" media="screen" href="assets/css/main.css" />
</head>
<body>
<!------------------------------------------------------Loading Screen-------------------------------------------------------- -->
<div id="loading">
<img src="assets/svg-logo/LOADER.svg" alt="Loading..." />
</div>
<script>
var loader = document.getElementById("loading");
window.addEventListener("load", function() {
loader.style.display = "none";
})
</script>
<!-------------------- header ------------------------>
<?php
// including header
include 'header.php';
?>
<!-- Body --------------------------------------------------------------->
<?php
// getting user details from session
if (isset($_SESSION['customer'])) {
$email = $_SESSION['customer'];
// getting user details from database
$sql = "SELECT * FROM user WHERE user_email = '$email'";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
$user_name = $row['user_name'];
$user_id = $row['user_id'];
$first_name = substr($user_name, 0, strpos($user_name, " "));
}
// getting order id from url
$order_id = $_GET['order_id'];
// getting order details from database
$sql = "SELECT * FROM orders WHERE order_id = '$order_id'";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
$order_status = $row['order_status'];
// getting product id from url
$product_id = $_GET['product_id'];
// getting product details from database
$sql = "SELECT * FROM product WHERE product_id = '$product_id'";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
$product_name = $row['product_name'];
$product_image = $row['product_img'];
?>
<?php
// checking if order is delivered or not
if ($order_status == "Delivered") {
// checking if user has already rated the product or not
$sql = "SELECT * FROM review WHERE product_id = '$product_id' AND order_id = '$order_id'";
$result1 = mysqli_query($conn, $sql);
$row_count = mysqli_num_rows($result1);
if ($row_count > 0) {
echo "
<script>alert('Rating Already Submitted');
window.location.href='order_view.php?order_id=$order_id';
</script>
";
}
// if rating is not submited
else {
?>
<div class="container-fluid px-5 my-5">
<div class="row justify-content-center">
<div class="col-xl-6">
<div class="card border-0 rounded-3 shadow-lg overflow-hidden">
<div class="card-body p-0">
<div class="row g-0 d-flex justify-content-center">
<div class="col-sm-10 p-4">
<div class="text-center">
<div class="h3 fw-light">Rate This Product</div>
<p class="mb-4 text-muted">Your Rating is Very importent For us.</p>
</div>
<div class="">
<form method="post">
<div class=" d-flex justify-content-center">
<img src="<?php echo $product_image; ?>" alt="" class="img-fluid thumb_img">
</div>
<div class="d-flex justify-content-center my-3">
<label class='text-muted'>Product:- <?= $product_name ?></label>
</div>
<div class="d-flex justify-content-center">
<div class='rate '>
<input type='radio' id='star5' name='rate' value='5' />
<label for='star5' title='5 Star'>5 stars</label>
<input type='radio' id='star4' name='rate' value='4' />
<label for='star4' title='4 Star'>4 stars</label>
<input type='radio' id='star3' name='rate' value='3' />
<label for='star3' title='3 Star'>3 stars</label>
<input type='radio' id='star2' name='rate' value='2' />
<label for='star2' title='2 Star'>2 stars</label>
<input type='radio' id='star1' name='rate' value='1' />
<label for='star1' title='1 Star'>1 star</label>
</div>
</div>
<input type="hidden" name="product_id" value="<?php echo $product_id; ?>">
<input type="hidden" name="order_id" value="<?php echo $order_id; ?>">
<input type="hidden" name="user_id" value="<?php echo $user_id; ?>">
<br>
<div class='d-flex justify-content-center'>
<button type="submit" name="review" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
}
}
?>
<!-- Footer --------------------------------------------------------------->
<?php
// including footer
include 'footer.php';
?>
<style>
.rate {
float: left;
height: 46px;
padding: 0 10px;
}
.rate:not(:checked)>input {
position: absolute;
top: -9999px;
}
.rate:not(:checked)>label {
float: right;
width: 1em;
overflow: hidden;
white-space: nowrap;
cursor: pointer;
font-size: 30px;
color: #ccc;
}
.rate:not(:checked)>label:before {
content: '★ ';
}
.rate>input:checked~label {
color: #ffc700;
}
.rate:not(:checked)>label:hover,
.rate:not(:checked)>label:hover~label {
color: #deb217;
}
.rate>input:checked+label:hover,
.rate>input:checked+label:hover~label,
.rate>input:checked~label:hover,
.rate>input:checked~label:hover~label,
.rate>label:hover~input:checked~label {
color: #c59b08;
}
</style>
</body>
</html>
<?php
// if review is submitted
if (isset($_POST['review'])) {
// getting data from form
$rate = $_POST['rate'];
$product_id = $_POST['product_id'];
$order_id = $_POST['order_id'];
$user_id = $_POST['user_id'];
// inserting rating into database
$sql = "INSERT INTO `review`(`product_id`, `user_id`,`order_id`, `rating`) VALUES ('$product_id','$user_id','$order_id','$rate')";
$result = mysqli_query($conn, $sql);
if ($result) {
echo "<script>
toastr.options.closeButton = true;
toastr.options.progressBar = true;
toastr['success']('Review Submitted.');
setTimeout(function(){ window.location.href='order_view.php?order_id=$order_id'; }, 5000);
</script>";
} else {
echo "<script>
toastr.options.closeButton = true;
toastr.options.progressBar = true;
toastr['error']('Something went wrong.');
</script>";
}
}
?>