35710-vm/dashboard.php
Flatlogic Bot 7a219bcd94 Kotkakey
2025-11-14 10:21:25 +00:00

337 lines
13 KiB
PHP

<?php
session_start();
require_once 'db/config.php';
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit;
}
$userId = $_SESSION['user_id'];
$pdo = db();
// Fetch user data
$stmt = $pdo->prepare("SELECT * FROM users WHERE id = ?");
$stmt->execute([$userId]);
$user = $stmt->fetch();
// Fetch pooled requests
$stmt = $pdo->prepare("SELECT * FROM pooled_requests WHERE user_id = ? ORDER BY created_at DESC");
$stmt->execute([$userId]);
$pooled_requests = $stmt->fetchAll();
// Fetch shortage predictions
$stmt = $pdo->prepare("SELECT * FROM shortage_predictions WHERE user_id = ? ORDER BY days_to_shortage ASC");
$stmt->execute([$userId]);
$predictions = $stmt->fetchAll();
// Prepare data for the chart
$prediction_labels = [];
$prediction_data = [];
foreach ($predictions as $prediction) {
$prediction_labels[] = $prediction['medicine_name'];
$prediction_data[] = $prediction['days_to_shortage'];
}
// Calculate stats
$high_risk_alerts = 0;
foreach ($predictions as $prediction) {
if ($prediction['days_to_shortage'] < 20) {
$high_risk_alerts++;
}
}
$active_pooled_requests = count($pooled_requests);
$medicines_monitored = count($predictions);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pharmacy Dashboard - Kotkakey</title>
<meta name="description" content="Kotkakey Pharmacy Dashboard for managing medicine shortages, pooled requests, and predictions.">
<meta name="robots" content="noindex, nofollow">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
<style>
body {
background-color: #f7f9fc;
font-family: 'Inter', sans-serif;
}
.sidebar {
height: 100vh;
position: fixed;
top: 0;
left: 0;
width: 260px;
background-color: #fff;
border-right: 1px solid #e9ecef;
padding: 1.5rem;
}
.sidebar .nav-link {
color: #5a6474;
font-weight: 500;
padding: 0.75rem 1rem;
border-radius: 0.5rem;
margin-bottom: 0.25rem;
}
.sidebar .nav-link.active, .sidebar .nav-link:hover {
color: #0057FF;
background-color: #f0f6ff;
}
.sidebar .nav-link i {
margin-right: 0.75rem;
font-size: 1.2rem;
}
.main-content {
margin-left: 260px;
padding: 2rem;
padding-top: 80px; /* Space for header */
}
.top-header {
position: fixed;
top: 0;
left: 260px;
right: 0;
height: 64px;
background-color: #fff;
border-bottom: 1px solid #e9ecef;
padding: 0 2rem;
z-index: 1000;
display: flex;
align-items: center;
justify-content: flex-end;
}
.stat-card {
background-color: #fff;
border: 1px solid #e9ecef;
border-radius: 0.75rem;
padding: 1.5rem;
transition: all 0.2s ease;
}
.stat-card:hover {
transform: translateY(-3px);
box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}
.stat-card .icon {
width: 48px;
height: 48px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 1.5rem;
color: #fff;
}
.table-wrapper {
background-color: #fff;
border: 1px solid #e9ecef;
border-radius: 0.75rem;
padding: 1.5rem;
}
.risk-high { color: #e74c3c; }
.risk-medium { color: #f39c12; }
.risk-low { color: #2ecc71; }
</style>
</head>
<body>
<div class="sidebar">
<a class="navbar-brand mb-4" href="index.php">
<img src="assets/pasted-20251114-095035-cf5716ad.png" alt="Kotkakey Logo" height="40">
</a>
<ul class="nav flex-column">
<li class="nav-item">
<a class="nav-link active" href="#">
<i class="bi bi-grid-1x2-fill"></i> Dashboard
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="shortage-alerts.php">
<i class="bi bi-exclamation-triangle-fill"></i> Shortage Alerts
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="pooled-requests.php">
<i class="bi bi-box2-heart-fill"></i> Pooled Requests
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="predictions.php">
<i class="bi bi-graph-up-arrow"></i> Predictions
</a>
</li>
<li class="nav-item mt-auto">
<a class="nav-link" href="#">
<i class="bi bi-gear-fill"></i> Settings
</a>
</li>
</ul>
</div>
<header class="top-header">
<div class="dropdown">
<a href="#" class="d-flex align-items-center link-dark text-decoration-none dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
<i class="bi bi-person-circle fs-3 me-2"></i>
<span class="fw-semibold"><?php echo htmlspecialchars($user['name'] ?? 'User'); ?></span>
</a>
<ul class="dropdown-menu text-small shadow">
<li><a class="dropdown-item" href="profile.php">Profile</a></li>
<li><a class="dropdown-item" href="settings.php">Settings</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="logout.php">Logout</a></li>
</ul>
</div>
</header>
<main class="main-content">
<h1 class="h2 mb-4 fw-bold">Dashboard</h1>
<div class="row mb-4 g-4">
<div class="col-md-4">
<div class="stat-card">
<div class="d-flex align-items-center">
<div class="icon bg-danger me-3">
<i class="bi bi-exclamation-diamond-fill"></i>
</div>
<div>
<h6 class="text-muted mb-1">High-Risk Alerts</h6>
<p class="card-text fs-2 fw-bold mb-0"><?php echo $high_risk_alerts; ?></p>
</div>
</div>
</div>
</div>
<div class="col-md-4">
<div class="stat-card">
<div class="d-flex align-items-center">
<div class="icon bg-warning me-3">
<i class="bi bi-check-circle-fill"></i>
</div>
<div>
<h6 class="text-muted mb-1">Active Pooled Requests</h6>
<p class="card-text fs-2 fw-bold mb-0"><?php echo $active_pooled_requests; ?></p>
</div>
</div>
</div>
</div>
<div class="col-md-4">
<div class="stat-card">
<div class="d-flex align-items-center">
<div class="icon bg-primary me-3">
<i class="bi bi-clipboard2-pulse-fill"></i>
</div>
<div>
<h6 class="text-muted mb-1">Medicines Monitored</h6>
<p class="card-text fs-2 fw-bold mb-0"><?php echo $medicines_monitored; ?></p>
</div>
</div>
</div>
</div>
</div>
<div class="row g-4">
<div class="col-lg-7">
<div class="table-wrapper h-100">
<h4 class="fw-semibold mb-3">
<i class="bi bi-box2-heart-fill me-2 text-primary"></i> My Pooled Requests
</h4>
<table class="table table-hover align-middle">
<thead>
<tr>
<th>Medicine</th>
<th>Status</th>
<th>Participants</th>
<th>Created</th>
<th></th>
</tr>
</thead>
<tbody>
<?php foreach ($pooled_requests as $request): ?>
<tr>
<td><strong><?php echo htmlspecialchars($request['medicine_name']); ?></strong></td>
<td><span class="badge bg-<?php echo strtolower($request['status']) == 'confirmed' ? 'success' : (strtolower($request['status']) == 'pending' ? 'warning' : 'primary'); ?>-subtle text-<?php echo strtolower($request['status']) == 'confirmed' ? 'success' : (strtolower($request['status']) == 'pending' ? 'warning' : 'primary'); ?>-emphasis rounded-pill"><?php echo htmlspecialchars($request['status']); ?></span></td>
<td><?php echo $request['participants']; ?> Pharmacies</td>
<td><?php echo date("Y-m-d", strtotime($request['created_at'])); ?></td>
<td><a href="join-pool.php?id=<?php echo $request['id']; ?>" class="btn btn-sm btn-outline-secondary">View</a></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<div class="col-lg-5">
<div class="table-wrapper h-100">
<h4 class="fw-semibold mb-3">
<i class="bi bi-graph-up-arrow me-2 text-primary"></i> Shortage Predictions
</h4>
<canvas id="predictionsChart"></canvas>
</div>
</div>
</div>
</main>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.2/dist/chart.umd.min.js"></script>
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
<script>
document.addEventListener("DOMContentLoaded", function() {
const ctx = document.getElementById('predictionsChart').getContext('2d');
new Chart(ctx, {
type: 'bar',
data: {
labels: <?php echo json_encode($prediction_labels); ?>,
datasets: [{
label: 'Predicted Days to Shortage',
data: <?php echo json_encode($prediction_data); ?>,
backgroundColor: [
'rgba(231, 76, 60, 0.7)',
'rgba(243, 156, 18, 0.7)',
'rgba(46, 204, 113, 0.7)',
'rgba(243, 156, 18, 0.7)'
],
borderColor: [
'#e74c3c',
'#f39c12',
'#2ecc71',
'#f39c12'
],
borderWidth: 1
}]
},
options: {
indexAxis: 'y',
responsive: true,
plugins: {
legend: {
display: false
},
tooltip: {
callbacks: {
label: function(context) {
return context.dataset.label + ': ' + context.raw + ' days';
}
}
}
},
scales: {
x: {
beginAtZero: true,
title: {
display: true,
text: 'Days Until Predicted Shortage'
}
}
}
}
});
});
</script>
</body>
</html>