78 lines
2.9 KiB
JavaScript
78 lines
2.9 KiB
JavaScript
function renderHeader() {
|
|
const headerDiv = document.getElementById("header");
|
|
|
|
if (window.location.pathname.endsWith("/")) {
|
|
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;
|
|
}
|
|
|
|
const role = localStorage.getItem("userRole");
|
|
const token = localStorage.getItem("TOKEN");
|
|
|
|
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 += `
|
|
<button id="addDocBtn" class="adminBtn" onclick="openModal('addDoctor')">Add Doctor</button>
|
|
<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();
|
|
}
|
|
|
|
function attachHeaderButtonListeners() {
|
|
const login = document.getElementById("patientLogin");
|
|
if (login) {
|
|
login.addEventListener('click', () => { openModal('patientLogin'); });
|
|
}
|
|
|
|
const signup = document.getElementById("patientSignup");
|
|
if (signup) {
|
|
signup.addEventListener('click', () => { openModal('patientSignup'); });
|
|
}
|
|
}
|
|
|
|
function logout() {
|
|
localStorage.removeItem("userRole");
|
|
localStorage.removeItem("TOKEN");
|
|
window.location.href = "/";
|
|
}
|
|
|
|
function logoutPatient() {
|
|
localStorage.removeItem("userRole");
|
|
selectRole('patient');
|
|
window.location.href='/pages/loggedPatientDashboard.html';
|
|
} |