| Server IP : 103.243.232.44 / Your IP : 216.73.216.237 Web Server : LiteSpeed System : Linux server17213-10344.hostycare.online 5.14.0-687.38.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Aug 12 17:19:12 EDT 2026 x86_64 User : iamakash ( 1400) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/iamakash/public_html/shaurya.meals28.com/ |
Upload File : |
<?php
require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/includes/auth.php';
requireLogin();
$pdo = getPDO();
$commodities = (int)$pdo->query('SELECT COUNT(*) FROM commodities')->fetchColumn();
$values = (int)$pdo->query('SELECT COUNT(*) FROM monthly_indices')->fetchColumn();
$periods = (int)$pdo->query('SELECT COUNT(DISTINCT period_year*100+period_month) FROM monthly_indices')->fetchColumn();
$latest = $pdo->query(
'SELECT period_year, period_month
FROM monthly_indices
WHERE index_value IS NOT NULL
ORDER BY period_year DESC, period_month DESC LIMIT 1'
)->fetch();
$byLevel = $pdo->query(
'SELECT level, COUNT(*) AS n FROM commodities GROUP BY level ORDER BY level'
)->fetchAll();
$recent = $pdo->query(
'SELECT u.id, u.filename, u.status, u.commodities_seen, u.values_written,
u.latest_period, u.uploaded_at,
(SELECT COUNT(*) FROM monthly_indices mi WHERE mi.upload_id = u.id) AS owned_count
FROM uploads u ORDER BY u.id DESC LIMIT 20'
)->fetchAll();
// Flash message from delete action
$flashMsg = '';
$flashType = 'success';
if (isset($_GET['deleted'])) {
$flashMsg = 'Upload "' . h(rawurldecode($_GET['file'] ?? '')) . '" and its index values were deleted.';
} elseif (isset($_GET['err'])) {
$flashType = 'danger';
$flashMsg = $_GET['err'] === 'notfound' ? 'Upload record not found.' : 'Invalid request.';
}
$pageTitle = 'Dashboard — Shaurya Index Factor';
require __DIR__ . '/includes/header.php';
?>
<?php if ($flashMsg): ?>
<div class="s-alert s-alert-<?= $flashType === 'success' ? 'success' : 'danger' ?>">
<?= $flashMsg ?>
</div>
<?php endif; ?>
<!-- Stat cards -->
<div style="display:grid; grid-template-columns:repeat(auto-fit,minmax(180px,1fr)); gap:1rem; margin-bottom:1.5rem;">
<div class="s-card">
<div style="font-size:0.75rem; text-transform:uppercase; letter-spacing:0.05em; color:var(--ink-faint); margin-bottom:0.4rem;">Commodities</div>
<div style="font-family:'DM Serif Display',serif; font-size:2rem; color:var(--ink); line-height:1.1;"><?= number_format($commodities) ?></div>
</div>
<div class="s-card">
<div style="font-size:0.75rem; text-transform:uppercase; letter-spacing:0.05em; color:var(--ink-faint); margin-bottom:0.4rem;">Index Values Stored</div>
<div style="font-family:'DM Serif Display',serif; font-size:2rem; color:var(--ink); line-height:1.1;"><?= number_format($values) ?></div>
</div>
<div class="s-card">
<div style="font-size:0.75rem; text-transform:uppercase; letter-spacing:0.05em; color:var(--ink-faint); margin-bottom:0.4rem;">Distinct Months</div>
<div style="font-family:'DM Serif Display',serif; font-size:2rem; color:var(--ink); line-height:1.1;"><?= number_format($periods) ?></div>
</div>
<div class="s-card">
<div style="font-size:0.75rem; text-transform:uppercase; letter-spacing:0.05em; color:var(--ink-faint); margin-bottom:0.4rem;">Latest Period</div>
<div style="font-family:'DM Serif Display',serif; font-size:2rem; color:var(--ink); line-height:1.1;">
<?= $latest ? sprintf('%02d-%d', (int)$latest['period_month'], (int)$latest['period_year']) : '—' ?>
</div>
</div>
</div>
<!-- Tables -->
<div style="display:grid; grid-template-columns:1fr 2fr; gap:1.25rem; align-items:start;">
<div class="s-card">
<div style="font-family:'DM Serif Display',serif; font-size:1.1rem; color:var(--ink); margin-bottom:1rem;">Commodities by Level</div>
<?php if (!$byLevel): ?>
<p style="font-size:0.875rem; color:var(--ink-faint);">No commodities yet. <a href="<?= base_url('upload.php') ?>" style="color:var(--sage);">Upload a file</a>.</p>
<?php else: ?>
<table class="s-table">
<thead><tr><th>Level</th><th class="text-end">Count</th></tr></thead>
<tbody>
<?php foreach ($byLevel as $row): ?>
<tr class="level-<?= (int)$row['level'] ?>">
<td>Level <?= (int)$row['level'] ?><?= $row['level'] >= 5 ? ' <span style="color:var(--ink-faint);font-size:0.78rem;">(leaf)</span>' : '' ?></td>
<td class="text-end"><?= number_format((int)$row['n']) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</div>
<div class="s-card" style="overflow-x:auto;">
<div style="font-family:'DM Serif Display',serif; font-size:1.1rem; color:var(--ink); margin-bottom:1rem;">Recent Uploads</div>
<?php if (!$recent): ?>
<p style="font-size:0.875rem; color:var(--ink-faint);">No uploads yet.</p>
<?php else: ?>
<table class="s-table">
<thead><tr><th>#</th><th>File</th><th>Status</th><th class="text-end">Values</th><th>Latest</th><th>When</th><th></th></tr></thead>
<tbody>
<?php foreach ($recent as $u): ?>
<tr>
<td style="color:var(--ink-faint);"><?= (int)$u['id'] ?></td>
<td><?= h($u['filename']) ?></td>
<td>
<?php $bc = match($u['status']) { 'completed' => 'success', 'failed' => 'danger', 'processing' => 'warning', default => 'secondary' }; ?>
<span class="s-badge s-badge-<?= $bc ?>"><?= h($u['status']) ?></span>
</td>
<td class="text-end"><?= number_format((int)$u['values_written']) ?></td>
<td><code><?= h($u['latest_period']) ?></code></td>
<td style="color:var(--ink-faint); white-space:nowrap;"><?= h($u['uploaded_at']) ?></td>
<td>
<button class="s-btn-delete btn-delete-upload"
data-id="<?= (int)$u['id'] ?>"
data-filename="<?= h($u['filename']) ?>"
data-owned="<?= (int)$u['owned_count'] ?>"
title="Delete">🗑</button>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</div>
</div>
<!-- Delete modal -->
<div class="s-modal-overlay" id="deleteModal">
<div class="s-modal">
<div class="s-modal-header">
<h6>Delete Upload</h6>
<button class="s-modal-close" onclick="document.getElementById('deleteModal').classList.remove('open')">×</button>
</div>
<div class="s-modal-body">
<p style="margin-bottom:0.6rem;">File: <strong id="delFilename" style="color:var(--ink);"></strong></p>
<div id="delWarnData" style="color:#c0392b;">This will permanently delete <strong id="delOwned"></strong> index values from the database.</div>
<div id="delWarnSafe" style="color:#1e7e34; display:none;">This upload's data has already been superseded by a newer upload. Only the log entry and file will be removed — no index values will be deleted.</div>
</div>
<div class="s-modal-footer">
<button class="s-btn s-btn-ghost" onclick="document.getElementById('deleteModal').classList.remove('open')">Cancel</button>
<form method="post" action="<?= base_url('delete_upload.php') ?>" style="display:inline;">
<input type="hidden" name="id" id="delId">
<button type="submit" class="s-btn s-btn-danger">Delete</button>
</form>
</div>
</div>
</div>
<script>
document.querySelectorAll('.btn-delete-upload').forEach(btn => {
btn.addEventListener('click', function () {
const owned = parseInt(this.dataset.owned, 10);
document.getElementById('delFilename').textContent = this.dataset.filename;
document.getElementById('delId').value = this.dataset.id;
document.getElementById('delOwned').textContent = owned.toLocaleString();
document.getElementById('delWarnData').style.display = owned > 0 ? '' : 'none';
document.getElementById('delWarnSafe').style.display = owned > 0 ? 'none' : '';
document.getElementById('deleteModal').classList.add('open');
});
});
document.getElementById('deleteModal').addEventListener('click', function(e) {
if (e.target === this) this.classList.remove('open');
});
document.addEventListener('keydown', e => { if (e.key === 'Escape') document.getElementById('deleteModal').classList.remove('open'); });
</script>
<?php require __DIR__ . '/includes/footer.php'; ?>