forked from hemang-mishra/DBMSProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsumer_dashboard.php
More file actions
113 lines (105 loc) · 5.13 KB
/
consumer_dashboard.php
File metadata and controls
113 lines (105 loc) · 5.13 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
<?php
// Start the session
session_start();
// Check if the user is logged in
if (!isset($_SESSION['user_id'])) {
// If not logged in, redirect to the sign-in page
header("Location: login.php");
exit();
}
include("db_connection.php");
// Get the search query if it exists
$search_query = isset($_GET['search_query']) ? $_GET['search_query'] : '';
// Fetch crops from the database with average rating and order count
if (!empty($search_query)) {
$sql_crops = "SELECT crop.c_id, crop.c_name, crop.c_qty, crop.img_url, crop.ppu, crop.unit, crop.shelf_life, farmer.name AS farmer_name,
AVG(review.rating) AS avg_rating, COUNT(orders.order_id) AS order_count
FROM crop
JOIN farmer ON crop.f_id = farmer.f_id
LEFT JOIN review ON crop.c_id = review.c_id
LEFT JOIN orders ON crop.c_id = orders.c_id AND orders.status = 'Completed'
WHERE crop.c_name LIKE ? OR farmer.name LIKE ?
GROUP BY crop.c_id, crop.c_name, crop.c_qty, crop.img_url, crop.ppu, crop.unit, crop.shelf_life, farmer.name
ORDER BY avg_rating DESC";
$stmt = $conn->prepare($sql_crops);
$search_term = '%' . $search_query . '%';
$stmt->bind_param('ss', $search_term, $search_term);
$stmt->execute();
$result_crops = $stmt->get_result();
} else {
$sql_crops = "SELECT crop.c_id, crop.c_name, crop.c_qty, crop.img_url, crop.ppu, crop.unit, crop.shelf_life, farmer.name AS farmer_name,
AVG(review.rating) AS avg_rating, COUNT(orders.order_id) AS order_count
FROM crop
JOIN farmer ON crop.f_id = farmer.f_id
LEFT JOIN review ON crop.c_id = review.c_id
LEFT JOIN orders ON crop.c_id = orders.c_id AND orders.status = 'Completed'
GROUP BY crop.c_id, crop.c_name, crop.c_qty, crop.img_url, crop.ppu, crop.unit, crop.shelf_life, farmer.name
ORDER BY avg_rating DESC";
$result_crops = $conn->query($sql_crops);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Consumer Dashboard</title>
<link rel="stylesheet" href="styles.css">
<link rel="stylesheet" href="css/consumer_dashboard.css"> <!-- Link to external CSS in css folder-->
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
</head>
<body>
<!-- Header -->
<?php include("header.php"); ?>
<!-- Hero Section -->
<div class="hero-section">
<h1>Welcome to GreenLeaf</h1>
<p>Discover and purchase fresh crops directly from farmers.</p>
</div>
<!-- Product Grid -->
<div class="product-grid">
<?php while ($crop = $result_crops->fetch_assoc()): ?>
<form method="POST" action="crop_details.php" class="card-form">
<input type="hidden" name="c_id" value="<?php echo htmlspecialchars($crop['c_id']); ?>">
<div class="product-card" onclick="submitForm(this);">
<div class="card-header">
<div class="product-icon">
<img src="<?php echo htmlspecialchars($crop['img_url']); ?>" alt="<?php echo htmlspecialchars($crop['c_name']); ?> Icon" />
</div>
<div class="shelf-life">
<?php echo htmlspecialchars($crop['shelf_life']); ?> days
</div>
</div>
<div class="card-body">
<h2 class="product-title">
<?php if ($crop['order_count'] > 0): ?>
<span class="rating"><?php echo number_format($crop['avg_rating'], 1); ?>★</span> <?php echo htmlspecialchars($crop['c_name']); ?> <span class="review-count">(<?php echo htmlspecialchars($crop['order_count']); ?>)</span>
<?php else: ?>
- ★ <?php echo htmlspecialchars($crop['c_name']); ?> <span class="review-count">(<?php echo htmlspecialchars($crop['order_count']); ?>)</span>
<?php endif; ?>
</h2>
<p class="product-price">₹<?php echo htmlspecialchars($crop['ppu']); ?>/<?php echo htmlspecialchars($crop['unit']); ?></p>
<p class="seller-name">Farmer: <?php echo htmlspecialchars($crop['farmer_name']); ?></p>
</div>
</div>
</form>
<?php endwhile; ?>
</div>
<script>
function submitForm(card) {
console.log("Card clicked:", card); // Debugging statement
const form = card.closest('form');
console.log("Form found:", form); // Debugging statement
if (form) {
form.submit();
} else {
console.error("Form not found for card:", card); // Debugging statement
}
}
</script>
</body>
</html>
<?php
$conn->close();
?>