« Back to History
index.php
|
20260721_154032.php
Initial Bulk Import
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); ?> <!-- ===================================================== DASHBOARD RENDER ===================================================== --> <div class="container py-5"> <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 ($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';