forked from hemang-mishra/DBMSProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemp.php
More file actions
71 lines (66 loc) · 2.44 KB
/
temp.php
File metadata and controls
71 lines (66 loc) · 2.44 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
<?php
session_start();
include("db_connection.php");
$isConsumer = false;
if (isset($_SESSION['user_id'])) {
$user_id = $_SESSION['user_id'];
$sql_user = "SELECT isConsumer FROM user WHERE user_id = $user_id";
$result_user = $conn->query($sql_user);
if ($result_user->num_rows > 0) {
$user = $result_user->fetch_assoc();
$isConsumer = $user['isConsumer'];
}
}
?>
<header class="">
<div class="header-container">
<div class="logo" onclick="redirectToDashboard()">
<img src="assets/logo.png" alt="Logo" />
<span>GreenLeaf</span>
</div>
<div class="header-right">
<?php if (isset($_SESSION['user_id'])): ?>
<!-- If user is logged in -->
<div class="user-icon" onclick="toggleDropdown()">
<img src="assets/user_icon.png" alt="User Icon" />
</div>
<div class="dropdown-menu" id="dropdown-menu">
<p class="user-name">Welcome, <?php echo htmlspecialchars($_SESSION['username']); ?></p>
<a href="profile.php" class="dropdown-link">Profile</a>
<a href="logout.php" class="dropdown-link">Logout</a>
</div>
<?php else: ?>
<button class="material-button" onclick="window.location.href='login.php'">
<span class="material-icons">person</span>
<span>Login</span>
</button>
<?php endif; ?>
</div>
</div>
</header>
<script>
function toggleDropdown() {
const dropdownMenu = document.getElementById("dropdown-menu");
dropdownMenu.classList.toggle("show-dropdown");
}
// Close dropdown when clicking outside
document.addEventListener("click", function (event) {
const dropdownMenu = document.getElementById("dropdown-menu");
const userIcon = document.querySelector(".user-icon");
if (dropdownMenu && userIcon && !userIcon.contains(event.target) && !dropdownMenu.contains(event.target)) {
dropdownMenu.classList.remove("show-dropdown");
}
});
function redirectToDashboard() {
<?php if (isset($_SESSION['user_id'])): ?>
<?php if ($isConsumer): ?>
window.location.href = 'consumer_dashboard.php';
<?php else: ?>
window.location.href = 'farmer_dashboard.php';
<?php endif; ?>
<?php else: ?>
window.location.href = 'login.php';
<?php endif; ?>
}
</script>
<link rel="stylesheet" href="styles.css">