34981-vm/dashboard.php
Flatlogic Bot e59c8581a5 1.0.1
2025-10-15 18:48:09 +00:00

227 lines
10 KiB
PHP

<?php
session_start();
require_once 'db/config.php';
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_SESSION['user_role']) && $_SESSION['user_role'] == 'doctor' && isset($_POST['availability'])) {
try {
$db = db();
$doctorId = $_SESSION['user_id'];
$availability = $_POST['availability'];
$stmt = $db->prepare("UPDATE doctors SET availability = ? WHERE id = ?");
$stmt->execute([$availability, $doctorId]);
header("Location: dashboard.php"); // Redirect to avoid form resubmission
exit;
} catch (PDOException $e) {
// For simplicity, we are not displaying the error here. In a real application, you would log this.
}
}
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit;
}
$userName = $_SESSION['user_name'] ?? 'User';
$userRole = $_SESSION['user_role'] ?? 'guest';
// Content for different roles
$dashboardContent = '';
switch ($userRole) {
case 'superadmin':
$dashboardContent = '<p>Here you can manage the entire application, including admins, hospitals, doctors, and patients.</p>';
break;
case 'admin':
$dashboardContent = '<p>Here you can manage hospitals, doctors, and patients.</p>';
break;
case 'hospital':
$dashboardContent = '
<p>Here you can manage your hospital profile, treatments, and doctors.</p>
<div class="list-group">
<a href="hospital-treatments.php" class="list-group-item list-group-item-action">Manage Treatment Categories</a>
<a href="hospital-doctors.php" class="list-group-item list-group-item-action">Manage Doctors</a>
</div>
';
break;
case 'doctor':
$db = db();
$doctorId = $_SESSION['user_id'];
// Fetch doctor's complete profile
$stmt = $db->prepare("SELECT d.full_name, d.email, d.specialty, d.qualifications, d.specialities, d.contact_phone, d.license_number, d.consultation_fee, d.availability, h.hospital_name, h.address, h.city, h.state, h.country FROM doctors d LEFT JOIN hospitals h ON d.hospital_id = h.id WHERE d.id = ?");
$stmt->execute([$doctorId]);
$doctor = $stmt->fetch(PDO::FETCH_ASSOC);
$profileInfo = '<div class="card mb-4"><div class="card-body"><h5 class="card-title">My Profile</h5>';
if ($doctor) {
$profileInfo .= '<p class="card-text"><strong>Name:</strong> '.htmlspecialchars($doctor['full_name']).'</p>';
$profileInfo .= '<p class="card-text"><strong>Email:</strong> '.htmlspecialchars($doctor['email']).'</p>';
$profileInfo .= '<p class="card-text"><strong>Contact Phone:</strong> '.htmlspecialchars($doctor['contact_phone']).'</p>';
$profileInfo .= '<p class="card-text"><strong>Primary Specialty:</strong> '.htmlspecialchars($doctor['specialty']).'</p>';
$profileInfo .= '<p class="card-text"><strong>Additional Specialities:</strong> '.nl2br(htmlspecialchars($doctor['specialities'])).'</p>';
$profileInfo .= '<p class="card-text"><strong>Qualifications:</strong> '.nl2br(htmlspecialchars($doctor['qualifications'])).'</p>';
$profileInfo .= '<p class="card-text"><strong>License Number:</strong> '.htmlspecialchars($doctor['license_number']).'</p>';
$profileInfo .= '<p class="card-text"><strong>Consultation Fee:</strong>
case 'patient':
$dashboardContent = '<p>Here you can manage your profile, view your medical history, and book appointments.</p>';
break;
default:
$dashboardContent = '<p>Welcome to your dashboard.</p>';
break;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard - Medicaltour</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css">
<link rel="stylesheet" href="assets/css/custom.css">
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top">
<div class="container">
<a class="navbar-brand" href="index.php">Medicaltour</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ms-auto">
<li class="nav-item"><a class="nav-link" href="logout.php">Logout</a></li>
</ul>
</div>
</div>
</nav>
<!-- Page Content -->
<main class="container mt-5 pt-5">
<section id="dashboard" class="py-5">
<div class="row">
<div class="col-12">
<h2 class="mb-4">Welcome, <?php echo htmlspecialchars($userName); ?>!</h2>
<p class="text-muted">Your role: <span class="badge bg-primary"><?php echo htmlspecialchars(ucfirst($userRole)); ?></span></p>
<hr>
<div class="dashboard-content">
<?php echo $dashboardContent; ?>
</div>
</div>
</div>
</section>
</main>
<!-- Footer -->
<footer class="py-5 bg-dark text-white mt-auto">
<div class="container text-center">
<p>&copy; 2025 Medicaltour. All Rights Reserved.</p>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="assets/js/main.js"></script>
</body>
</html>.htmlspecialchars($doctor['consultation_fee']).'</p>';
$profileInfo .= '<p class="card-text"><strong>Availability:</strong> '.nl2br(htmlspecialchars($doctor['availability'])).'</p>';
} else {
$profileInfo .= '<p class="card-text">Profile not found.</p>';
}
$profileInfo .= '</div></div>';
// Fetch hospital info
$hospitalInfo = '<div class="card mb-4"><div class="card-body"><h5 class="card-title">My Hospital</h5>';
if ($doctor && $doctor['hospital_name']) {
$hospitalInfo .= '<p class="card-text">'.htmlspecialchars($doctor['hospital_name']).'</p>';
$hospitalInfo .= '<p class="card-text">'.htmlspecialchars($doctor['address']).', '.htmlspecialchars($doctor['city']).', '.htmlspecialchars($doctor['state']).', '.htmlspecialchars($doctor['country']).'</p>';
} else {
$hospitalInfo .= '<p class="card-text">You are not currently affiliated with any hospital.</p>';
}
$hospitalInfo .= '</div></div>';
// Fetch patient history
$stmt = $db->prepare("SELECT p.full_name, a.appointment_date, a.notes FROM patients p JOIN appointments a ON p.id = a.patient_id WHERE a.doctor_id = ? ORDER BY a.appointment_date DESC");
$stmt->execute([$doctorId]);
$appointments = $stmt->fetchAll(PDO::FETCH_ASSOC);
$patientHistory = '<div class="card"><div class="card-body"><h5 class="card-title">Patient History</h5>';
if ($appointments) {
$patientHistory .= '<ul class="list-group list-group-flush">';
foreach ($appointments as $appointment) {
$patientHistory .= '<li class="list-group-item">'.htmlspecialchars($appointment['full_name']).' - '.(new DateTime($appointment['appointment_date']))->format('m/d/Y').'<br><small>'.htmlspecialchars($appointment['notes']).'</small></li>';
}
$patientHistory .= '</ul>';
} else {
$patientHistory .= '<p class="card-text">No patient history found.</p>';
}
$patientHistory .= '</div></div>';
$dashboardContent = $profileInfo . $hospitalInfo . $patientHistory;
break;
case 'patient':
$dashboardContent = '<p>Here you can manage your profile, view your medical history, and book appointments.</p>';
break;
default:
$dashboardContent = '<p>Welcome to your dashboard.</p>';
break;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard - Medicaltour</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css">
<link rel="stylesheet" href="assets/css/custom.css">
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top">
<div class="container">
<a class="navbar-brand" href="index.php">Medicaltour</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ms-auto">
<li class="nav-item"><a class="nav-link" href="logout.php">Logout</a></li>
</ul>
</div>
</div>
</nav>
<!-- Page Content -->
<main class="container mt-5 pt-5">
<section id="dashboard" class="py-5">
<div class="row">
<div class="col-12">
<h2 class="mb-4">Welcome, <?php echo htmlspecialchars($userName); ?>!</h2>
<p class="text-muted">Your role: <span class="badge bg-primary"><?php echo htmlspecialchars(ucfirst($userRole)); ?></span></p>
<hr>
<div class="dashboard-content">
<?php echo $dashboardContent; ?>
</div>
</div>
</div>
</section>
</main>
<!-- Footer -->
<footer class="py-5 bg-dark text-white mt-auto">
<div class="container text-center">
<p>&copy; 2025 Medicaltour. All Rights Reserved.</p>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="assets/js/main.js"></script>
</body>
</html>