Mini Kabibi Habibi

Current Path : C:/xampp/htdocs/clinic/
Upload File :
Current File : C:/xampp/htdocs/clinic/logged_patients.php

<?php
session_start();
include 'includes/db.php';

if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'admin') {
    header("Location: login.php");
    exit();
}

$page_title = "Logged Patients";
$username = $_SESSION['username'] ?? 'Admin';

$today = date('Y-m-d');
$stmt = $pdo->prepare("SELECT * FROM logs WHERE log_date = :today ORDER BY log_date DESC, id DESC");
$stmt->execute([':today' => $today]);
$logs = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title><?= htmlspecialchars($page_title) ?></title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        body {
            display: flex;
            min-height: 100vh;
        }

        .sidebar {
            width: 250px;
            background-color: #343a40;
            color: white;
        }

        .sidebar a {
            color: #ccc;
            text-decoration: none;
            padding: 15px;
            display: block;
        }

        .sidebar a:hover,
        .sidebar a.active {
            background-color: #495057;
            color: #fff;
        }

        .main-content {
            flex-grow: 1;
            padding: 20px;
        }

        .table thead {
            background-color: #004D40;
            color: white;
        }
    </style>
</head>
<body>

<!-- Sidebar -->
<div class="sidebar">
    <h4 class="p-3">Admin Panel</h4>
    <a href="admin_dashboard.php">Dashboard</a>
    <a href="logged_patients.php" class="active">Logged Patients</a>
    <hr>
    <a href="logout.php" class="btn btn-danger m-3 d-block">Logout</a>
</div>

<!-- Main Content -->
<div class="main-content">
    <h3 class="mb-4">Logged Patients - <?= htmlspecialchars($today) ?></h3>

    <?php if (count($logs) > 0): ?>
        <div class="table-responsive">
            <table class="table table-bordered table-striped align-middle">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>Date</th>
                        <th>Patient Name</th>
                        <th>School</th>
                        <th>Age</th>
                        <th>Address</th>
                        <th>Contact</th>
                        <th>Signature</th>
                        <th>Attended By</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($logs as $index => $log): ?>
                        <tr>
                            <td><?= $index + 1 ?></td>
                            <td><?= htmlspecialchars($log['log_date']) ?></td>
                            <td><?= htmlspecialchars($log['patient_name']) ?></td>
                            <td><?= htmlspecialchars($log['school']) ?></td>
                            <td><?= htmlspecialchars($log['age']) ?></td>
                            <td><?= htmlspecialchars($log['address']) ?></td>
                            <td><?= htmlspecialchars($log['contact_number']) ?></td>
                            <td>
                                <?php 
                                    $signature = $log['signature'] ?? '';
                                    if ($signature !== '') {
                                        $signaturePath = 'signatures/' . $signature;
                                        // Check if the file exists on the server
                                        if (file_exists(__DIR__ . '/' . $signaturePath)) {
                                            // Output the image tag with correct relative URL
                                            echo '<img src="' . htmlspecialchars($signaturePath) . '" alt="Signature" width="100" style="object-fit: contain; max-height: 80px;">';
                                        } else {
                                            echo '<span class="text-danger">Signature file not found</span>';
                                        }
                                    } else {
                                        echo '<span class="text-muted">No Signature</span>';
                                    }
                                ?>
                            </td>
                            <td><?= htmlspecialchars($log['attended_by']) ?></td>
                        </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>
    <?php else: ?>
        <div class="alert alert-info">No logged patients for today.</div>
    <?php endif; ?>
</div>

</body>
</html>