« Back to History
index.php
|
20261118_125741.php
Initial Domain Snapshot
Copy Code
<?php /* ============================================================ File: index.php Purpose: Dashboard / Landing page for logged-in user Auth: STRICT page_acl.php ============================================================ */ require_once __DIR__ . '/modules/auth/page_acl.php'; require_login(); $pdo = $GLOBALS['pdo'] ?? null; $u = auth_user(); $company_id = (int)($u['company_id'] ?? 0); if ($company_id <= 0) { http_response_code(403); exit('Forbidden: No company bound.'); } $ctx = [ 'user' => $u, 'company_id' => $company_id, 'role' => $u['role'] ?? '', 'slug' => 'index', 'pdo' => $pdo, ]; /* ------------------------------------------------- CONTEXT ------------------------------------------------- */ $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; $u = $ctx['user']; /* ------------------------------------------------- HELPERS ------------------------------------------------- */ function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } /* ------------------------------------------------- HEADER ------------------------------------------------- */ require_once __DIR__ . '/partials/header.php'; /* ------------------------------------------------- FETCH COMPANY NAME ------------------------------------------------- */ $company_name = 'Company'; $stmtC = $pdo->prepare(" SELECT name, short_name FROM companies WHERE id = :cid AND is_active = 1 LIMIT 1 "); $stmtC->execute([':cid' => $company_id]); if ($rowC = $stmtC->fetch(PDO::FETCH_ASSOC)) { $company_name = $rowC['name'] ?: $rowC['short_name']; } /* ------------------------------------------------- DISPLAY USER NAME ------------------------------------------------- */ $display_user_name = $u['name'] ?? $u['full_name'] ?? $u['username'] ?? $u['email'] ?? 'User'; $user_role = strtolower( $u['role'] ?? $u['role_name'] ?? $u['user_role'] ?? '' ); $hide_quick_access = in_array($user_role, ['owner', 'admin', 'developer'], true); /* ------------------------------------------------- FETCH PAGES FROM MENU ACL ------------------------------------------------- */ $pages = []; $stmtPages = $pdo->prepare("\n SELECT DISTINCT url\n FROM nav_menu_items\n WHERE is_enabled = 1\n AND (company_id = 0 OR company_id = :cid)\n AND url IS NOT NULL\n AND url <> ''\n AND url <> '#'\n ORDER BY sort_order, id\n"); $stmtPages->execute([':cid' => $company_id]); foreach ($stmtPages->fetchAll(PDO::FETCH_COLUMN) as $url) { $path = (string)parse_url((string)$url, PHP_URL_PATH); $slug = strtolower(basename($path !== '' ? $path : (string)$url, '.php')); if ($slug === '' || isset($pages[$slug])) { continue; } if (!header_user_can_access($slug, $u)) { continue; } $pages[$slug] = $slug; } $pages = array_values($pages); sort($pages); /* ------------------------------------------------- MY TASKS TODAY (read-only, logged-in user) ------------------------------------------------- */ $my_tasks = []; $ut_ok = false; $user_id = (int)($u['id'] ?? 0); if ($user_id > 0) { try { $stT = $pdo->prepare(" SELECT id, title, description, priority_order, status, is_event FROM ut_tasks WHERE company_id = :cid AND user_id = :uid AND task_date = CURDATE() AND status <> 'cancelled' AND NOT (template_id IS NULL AND repeat_rule <> 'none') ORDER BY priority_order, id "); $stT->execute([':cid' => $company_id, ':uid' => $user_id]); $my_tasks = $stT->fetchAll(PDO::FETCH_ASSOC); $ut_ok = true; } catch (Throwable $e) { $my_tasks = []; // task module not installed for this DB yet } } ?> <!-- ===================================================== DASHBOARD RENDER ===================================================== --> <div class="container py-5"> <?php include __DIR__ . '/partials/news_ticker.php'; ?> <div class="row mb-5"> <div class="col-12 text-center"> <h2 class="display-5 fw-bold text-dark"> Welcome to <span class="text-primary"><?= h($company_name) ?></span> </h2> <p class="lead text-muted"> Logged in as: <span class="badge bg-secondary fs-6 fw-normal"><?= h($display_user_name) ?></span> </p> <hr class="w-25 mx-auto opacity-25"> </div> </div> <?php if ($my_tasks || $ut_ok): ?> <div class="row mb-4 justify-content-center"> <div class="col-12 col-lg-8"> <div class="card border-0 shadow-sm"> <div class="card-header bg-white d-flex justify-content-between align-items-center py-2"> <span class="fw-bold"><i class="bi bi-list-check me-2 text-primary"></i>My Tasks Today (<?= count(array_filter($my_tasks, fn($t) => $t['status'] === 'done')) ?>/<?= count($my_tasks) ?> done)</span> <a href="/erp/user_tasks.php" class="btn btn-sm btn-outline-primary">Open Tasks</a> </div> <?php if (!$my_tasks): ?> <div class="card-body text-center text-muted py-4">No tasks today ✅</div> <?php else: ?> <ul class="list-group list-group-flush"> <?php foreach ($my_tasks as $t): $st = $t['status']; $badge = ['done' => 'success', 'in_progress' => 'primary', 'missed' => 'danger', 'transferred' => 'secondary'][$st] ?? 'warning'; $lbl = ['done' => 'Done', 'in_progress' => 'In Progress', 'missed' => 'Missed', 'transferred' => 'Transferred'][$st] ?? 'Pending'; ?> <li class="list-group-item d-flex align-items-start gap-2"> <span class="badge bg-light text-dark border mt-1"><?= (int)$t['priority_order'] ?></span> <div class="flex-grow-1"> <span class="<?= $st === 'done' ? 'text-muted' : 'fw-semibold' ?> <?= $st === 'done' ? 'text-decoration-line-through' : '' ?>"><?= h($t['title']) ?></span> <?php if ((int)$t['is_event'] === 1): ?><span class="badge bg-info-subtle text-info-emphasis ms-1">Event</span><?php endif; ?> <?php if ($t['description'] !== null && $t['description'] !== ''): ?> <div class="small text-muted"><?= h($t['description']) ?></div> <?php endif; ?> </div> <span class="badge bg-<?= $badge ?>-subtle text-<?= $badge ?>-emphasis mt-1"><?= h($lbl) ?></span> </li> <?php endforeach; ?> </ul> <?php endif; ?> </div> </div> </div> <?php endif; ?> <?php if ($hide_quick_access): ?> <?php elseif (empty($pages)): ?> <div class="row justify-content-center"> <div class="col-md-6"> <div class="alert alert-warning shadow-sm border-0 d-flex align-items-center" role="alert"> <i class="bi bi-exclamation-triangle-fill me-3 fs-3"></i> <div> <strong>Access Denied:</strong> Aapko abhi koi page assign nahi kiya gaya hai. Kripya administrator se sampark karein. </div> </div> </div> </div> <?php else: ?> <div class="row mb-3"> <div class="col-12"> <h5 class="text-uppercase fw-bold text-muted small letter-spacing-1 mb-4"> <i class="bi bi-grid-fill me-2"></i> Your Quick Access Pages </h5> </div> </div> <div class="row g-4"> <?php foreach ($pages as $slug): ?> <div class="col-6 col-sm-4 col-md-3 col-lg-2"> <a href="/erp/<?= h($slug) ?>.php" class="card h-100 border-0 shadow-sm text-decoration-none text-center p-3 page-card-hover transition"> <div class="card-body p-2"> <div class="icon-circle mb-3 mx-auto bg-light text-primary fs-3"> <?php $icon = 'bi-file-earmark-text'; // Default if (strpos($slug, 'stock') !== false) $icon = 'bi-box-seam'; if (strpos($slug, 'report') !== false) $icon = 'bi-graph-up-arrow'; if (strpos($slug, 'entry') !== false) $icon = 'bi-plus-circle'; if (strpos($slug, 'send') !== false) $icon = 'bi-send'; ?> <i class="bi <?= $icon ?>"></i> </div> <h6 class="card-title fw-bold text-dark small m-0"> <?= h(ucwords(str_replace(['_','-'], ' ', $slug))) ?> </h6> </div> </a> </div> <?php endforeach; ?> </div> <?php endif; ?> </div> <style> /* Custom Styles for Dashboard Glow Effect */ .letter-spacing-1 { letter-spacing: 1px; } .transition { transition: all 0.3s ease; } .page-card-hover { border: 1px solid rgba(0,0,0,0.05) !important; } .page-card-hover:hover { transform: translateY(-5px); box-shadow: 0 10px 20px rgba(0,0,0,0.1) !important; background-color: #f8f9ff; border-color: #0d6efd !important; } .icon-circle { width: 60px; height: 60px; display: flex; align-items: center; justify-content: center; border-radius: 50%; transition: all 0.3s ease; } .page-card-hover:hover .icon-circle { background-color: #0d6efd !important; color: white !important; } </style> <?php require_once __DIR__ . '/partials/footer.php';