2025-11-07 18:11:58 +01:00
|
|
|
function renderHeader() {
|
2025-11-06 19:52:26 +01:00
|
|
|
const headerDiv = document.getElementById("header");
|
2025-11-03 18:27:23 +01:00
|
|
|
|
2025-11-06 19:52:26 +01:00
|
|
|
if (window.location.pathname.endsWith("/")) {
|
2025-11-03 18:27:23 +01:00
|
|
|
localStorage.removeItem("userRole");
|
|
|
|
|
headerDiv.innerHTML = `
|
|
|
|
|
<header class="header">
|
|
|
|
|
<div class="logo-section">
|
|
|
|
|
<img src="../assets/images/logo/logo.png" alt="Hospital CRM Logo" class="logo-img">
|
|
|
|
|
<span class="logo-title">Hospital CMS</span>
|
|
|
|
|
</div>
|
|
|
|
|
</header>`;
|
|
|
|
|
return;
|
2025-11-06 19:52:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const role = localStorage.getItem("userRole");
|
2025-11-09 17:33:37 +01:00
|
|
|
const token = localStorage.getItem("token");
|
2025-11-06 19:52:26 +01:00
|
|
|
|
|
|
|
|
let headerContent = `<header class="header">
|
|
|
|
|
<div class="logo-section">
|
|
|
|
|
<img src="../assets/images/logo/logo.png" alt="Hospital CRM Logo" class="logo-img">
|
|
|
|
|
<span class="logo-title">Hospital CMS</span>
|
|
|
|
|
</div>
|
|
|
|
|
<nav>`;
|
|
|
|
|
|
|
|
|
|
if ((role === "loggedPatient" || role === "admin" || role === "doctor") && !token) {
|
|
|
|
|
localStorage.removeItem("userRole");
|
|
|
|
|
alert("Session expired or invalid login. Please log in again.");
|
|
|
|
|
window.location.href = "/";
|
|
|
|
|
return;
|
|
|
|
|
} else if (role === "admin") {
|
|
|
|
|
headerContent += `
|
2025-11-09 17:33:37 +01:00
|
|
|
<button id="addDocBtn" class="adminBtn">Add Doctor</button>
|
2025-11-06 19:52:26 +01:00
|
|
|
<a href="#" onclick="logout()">Logout</a>`;
|
|
|
|
|
} else if (role === "doctor") {
|
|
|
|
|
headerContent += `
|
|
|
|
|
<button class="adminBtn" onclick="selectRole('doctor')">Home</button>
|
|
|
|
|
<a href="#" onclick="logout()">Logout</a>`;
|
|
|
|
|
} else if (role === "patient") {
|
|
|
|
|
headerContent += `
|
|
|
|
|
<button id="patientLogin" class="adminBtn">Login</button>
|
|
|
|
|
<button id="patientSignup" class="adminBtn">Sign Up</button>`;
|
|
|
|
|
} else if (role === "loggedPatient") {
|
|
|
|
|
headerContent += `
|
|
|
|
|
<button id="home" class="adminBtn" onclick="window.location.href='/pages/loggedPatientDashboard.html'">Home</button>
|
|
|
|
|
<button id="patientAppointments" class="adminBtn" onclick="window.location.href='/pages/patientAppointments.html'">Appointments</button>
|
|
|
|
|
<a href="#" onclick="logoutPatient()">Logout</a>`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
headerContent += '</nav>';
|
|
|
|
|
headerDiv.innerHTML = headerContent;
|
|
|
|
|
|
|
|
|
|
attachHeaderButtonListeners();
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-07 18:11:58 +01:00
|
|
|
function attachHeaderButtonListeners() {
|
|
|
|
|
const login = document.getElementById("patientLogin");
|
2025-11-06 19:52:26 +01:00
|
|
|
if (login) {
|
|
|
|
|
login.addEventListener('click', () => { openModal('patientLogin'); });
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-07 18:11:58 +01:00
|
|
|
const signup = document.getElementById("patientSignup");
|
2025-11-06 19:52:26 +01:00
|
|
|
if (signup) {
|
|
|
|
|
signup.addEventListener('click', () => { openModal('patientSignup'); });
|
|
|
|
|
}
|
2025-11-10 20:59:17 +01:00
|
|
|
|
|
|
|
|
const addDoctor = document.getElementById("addDocBtn");
|
|
|
|
|
if (addDoctor) {
|
|
|
|
|
addDoctor.addEventListener('click', () => { openModal('addDoctor'); });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-11-06 19:52:26 +01:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 18:11:58 +01:00
|
|
|
function logout() {
|
2025-11-06 19:52:26 +01:00
|
|
|
localStorage.removeItem("userRole");
|
2025-11-09 17:33:37 +01:00
|
|
|
localStorage.removeItem("token");
|
2025-11-06 19:52:26 +01:00
|
|
|
window.location.href = "/";
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-07 18:11:58 +01:00
|
|
|
function logoutPatient() {
|
2025-11-06 19:52:26 +01:00
|
|
|
localStorage.removeItem("userRole");
|
2025-11-09 17:33:37 +01:00
|
|
|
localStorage.removeItem("token");
|
|
|
|
|
setRole('patient')
|
|
|
|
|
window.location.href='/pages/patientDashboard.html';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderHeader();
|