-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrate_product.php
More file actions
159 lines (145 loc) · 5.4 KB
/
Copy pathrate_product.php
File metadata and controls
159 lines (145 loc) · 5.4 KB
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
<?php
session_start();
require 'db.php';
if (!isset($_SESSION['id']) || $_SESSION['Category'] != 0) { // Only buyers can rate
header("Location: error.php");
exit();
}
$order_id = isset($_GET['order_id']) ? (int)$_GET['order_id'] : 0;
// Get order details
$sql = "SELECT o.*, p.product, p.pid, f.fid as farmer_id
FROM orders o
JOIN fproduct p ON o.product_id = p.pid
JOIN farmer f ON o.farmer_id = f.fid
WHERE o.order_id = $order_id AND o.buyer_id = " . $_SESSION['id'];
$result = mysqli_query($conn, $sql);
$order = mysqli_fetch_assoc($result);
if (!$order) {
header("Location: error.php");
exit();
}
// Check if already rated
$sql = "SELECT * FROM product_ratings WHERE order_id = $order_id";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
header("Location: error.php?msg=already_rated");
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Rate Product - <?php echo $order['product']; ?></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<style>
.rating-container {
max-width: 600px;
margin: 50px auto;
padding: 20px;
border: 1px solid #ddd;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.rating-stars {
font-size: 2em;
color: #ffd700;
cursor: pointer;
}
.rating-stars i {
margin: 0 5px;
}
.rating-stars i:hover,
.rating-stars i.active {
color: #ffd700;
}
textarea {
width: 100%;
padding: 10px;
margin: 10px 0;
border: 1px solid #ddd;
border-radius: 4px;
}
button {
background: #4CAF50;
color: white;
border: none;
padding: 10px 20px;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background: #45a049;
}
</style>
</head>
<body>
<div class="container">
<div class="rating-container">
<h2>Rate Product: <?php echo $order['product']; ?></h2>
<form id="rating-form">
<input type="hidden" name="order_id" value="<?php echo $order_id; ?>">
<input type="hidden" name="product_id" value="<?php echo $order['pid']; ?>">
<input type="hidden" name="farmer_id" value="<?php echo $order['farmer_id']; ?>">
<input type="hidden" name="rating" id="rating-value" value="0">
<div class="rating-stars">
<i class="far fa-star" data-rating="1"></i>
<i class="far fa-star" data-rating="2"></i>
<i class="far fa-star" data-rating="3"></i>
<i class="far fa-star" data-rating="4"></i>
<i class="far fa-star" data-rating="5"></i>
</div>
<textarea name="review" placeholder="Write your review (optional)" rows="4"></textarea>
<button type="submit">Submit Rating</button>
</form>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
// Handle star rating
$('.rating-stars i').hover(
function() {
const rating = $(this).data('rating');
$('.rating-stars i').removeClass('fas').addClass('far');
$('.rating-stars i').slice(0, rating).removeClass('far').addClass('fas');
},
function() {
const currentRating = $('#rating-value').val();
$('.rating-stars i').removeClass('fas').addClass('far');
$('.rating-stars i').slice(0, currentRating).removeClass('far').addClass('fas');
}
);
$('.rating-stars i').click(function() {
const rating = $(this).data('rating');
$('#rating-value').val(rating);
$('.rating-stars i').removeClass('fas').addClass('far');
$('.rating-stars i').slice(0, rating).removeClass('far').addClass('fas');
});
// Handle form submission
$('#rating-form').on('submit', function(e) {
e.preventDefault();
if ($('#rating-value').val() == 0) {
alert('Please select a rating');
return;
}
$.ajax({
url: 'submit_rating.php',
method: 'POST',
data: $(this).serialize(),
success: function(response) {
if (response === 'success') {
alert('Thank you for your rating!');
window.location.href = 'profileView.php';
} else {
alert('Error submitting rating. Please try again.');
}
}
});
});
});
</script>
</body>
</html>