« Back to History
index.php
|
20260920_164915.php
Initial Domain Snapshot
Copy Code
<?php /* ============================================================ File: /erp/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'); } /** * AUTOMATIC DYNAMIC ICON & EMOJI ASSIGNER */ function get_auto_page_meta($slug) { $slug = strtolower($slug); $rules = [ 'stock' => ['icon' => 'bi-box-seam-fill', 'emoji' => '๐ฆ', 'bg' => '#e8f5e9', 'color' => '#2e7d32'], 'yarn' => ['icon' => 'bi-basket3-fill', 'emoji' => '๐งถ', 'bg' => '#fff3e0', 'color' => '#ef6c00'], 'beam' => ['icon' => 'bi-layers-fill', 'emoji' => '๐งต', 'bg' => '#e3f2fd', 'color' => '#1565c0'], 'warper' => ['icon' => 'bi-box-seam', 'emoji' => '๐๏ธ', 'bg' => '#e0f7fa', 'color' => '#00838f'], 'loom' => ['icon' => 'bi-border-inner', 'emoji' => '๐ญ', 'bg' => '#f3e5f5', 'color' => '#7b1fa2'], 'machine' => ['icon' => 'bi-gear-wide-connected','emoji' => 'โ๏ธ', 'bg' => '#e0f2f1', 'color' => '#00695c'], 'salary' => ['icon' => 'bi-cash-stack', 'emoji' => '๐ฐ', 'bg' => '#e8f5e9', 'color' => '#1b5e20'], 'payment' => ['icon' => 'bi-credit-card-2-front','emoji' => '๐ณ', 'bg' => '#e1f5fe', 'color' => '#0288d1'], 'advance' => ['icon' => 'bi-cash-coin', 'emoji' => '๐ต', 'bg' => '#fff8e1', 'color' => '#f57f17'], 'report' => ['icon' => 'bi-graph-up-arrow', 'emoji' => '๐', 'bg' => '#f1f8e9', 'color' => '#558b2f'], 'entry' => ['icon' => 'bi-plus-circle-fill', 'emoji' => '๐', 'bg' => '#e8eaf6', 'color' => '#283593'], 'send' => ['icon' => 'bi-send-fill', 'emoji' => '๐', 'bg' => '#ffe0b2', 'color' => '#e65100'], 'parcel' => ['icon' => 'bi-box2-heart-fill', 'emoji' => '๐ฆ', 'bg' => '#fce4ec', 'color' => '#c2185b'], 'leave' => ['icon' => 'bi-calendar2-check', 'emoji' => '๐๏ธ', 'bg' => '#fff3e0', 'color' => '#f57c00'], 'emp' => ['icon' => 'bi-people-fill', 'emoji' => '๐จโ๐ผ', 'bg' => '#e1f5fe', 'color' => '#0277bd'], 'user' => ['icon' => 'bi-person-badge-fill', 'emoji' => '๐ค', 'bg' => '#f3e5f5', 'color' => '#8e24aa'], 'bill' => ['icon' => 'bi-receipt-cutoff', 'emoji' => '๐งพ', 'bg' => '#e8eaf6', 'color' => '#3f51b5'], 'invoice' => ['icon' => 'bi-file-earmark-spreadsheet','emoji' => '๐', 'bg' => '#f1f8e9', 'color' => '#33691e'], 'kasab' => ['icon' => 'bi-gem', 'emoji' => '๐', 'bg' => '#f3e5f5', 'color' => '#6a1b9a'], 'master' => ['icon' => 'bi-database-fill-gear','emoji' => '๐๏ธ', 'bg' => '#eceff1', 'color' => '#37474f'], 'profile' => ['icon' => 'bi-person-bounding-box','emoji' => '๐', 'bg' => '#e8eaf6', 'color' => '#1a237e'], 'security' => ['icon' => 'bi-shield-lock-fill', 'emoji' => '๐', 'bg' => '#ffebee', 'color' => '#c62828'], ]; foreach ($rules as $key => $meta) { if (strpos($slug, $key) !== false) { return $meta; } } $fallback_icons = ['bi-grid-fill', 'bi-file-earmark-text', 'bi-app-indicator', 'bi-check2-circle', 'bi-sliders']; $fallback_emojis = ['โก', '๐', '๐', '๐น', '๐ฏ', '๐', 'โจ']; $fallback_colors = [ ['bg' => '#e8f5e9', 'color' => '#2e7d32'], ['bg' => '#e3f2fd', 'color' => '#1565c0'], ['bg' => '#fff3e0', 'color' => '#ef6c00'], ['bg' => '#f3e5f5', 'color' => '#7b1fa2'], ['bg' => '#e0f2f1', 'color' => '#00695c'] ]; $hash = crc32($slug); $idx = abs($hash) % count($fallback_colors); return [ 'icon' => $fallback_icons[abs($hash) % count($fallback_icons)], 'emoji' => $fallback_emojis[abs($hash) % count($fallback_emojis)], 'bg' => $fallback_colors[$idx]['bg'], 'color' => $fallback_colors[$idx]['color'] ]; } /* ------------------------------------------------- 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 & PROFILE DATA ------------------------------------------------- */ $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 Profile DP URL from Employee Master $dp_url = $u['dp_url'] ?? null; $user_id = (int)($u['id'] ?? 0); if (!$dp_url && $user_id > 0) { try { $stEmp = $pdo->prepare("SELECT dp_url FROM employees WHERE user_id = ? AND company_id = ? LIMIT 1"); $stEmp->execute([$user_id, $company_id]); if ($empRow = $stEmp->fetch(PDO::FETCH_ASSOC)) { $dp_url = $empRow['dp_url'] ?? null; } } catch (Throwable $e) {} } /* ------------------------------------------------- FETCH PAGES FROM MENU ACL ------------------------------------------------- */ $pages = []; $stmtPages = $pdo->prepare(" SELECT DISTINCT url FROM nav_menu_items WHERE is_enabled = 1 AND (company_id = 0 OR company_id = :cid) AND url IS NOT NULL AND url <> '' AND url <> '#' ORDER BY sort_order, id "); $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); ?> <!-- FORCE LOAD BOOTSTRAP ICONS CSS --> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css"> <!-- ===================================================== DASHBOARD RENDER ===================================================== --> <style> /* CENTER PROFILE DP CARD */ .user-profile-center-card { text-align: center; padding: 10px 0 20px; } .avatar-circle-main { width: 86px; height: 86px; border-radius: 50%; background: linear-gradient(135deg, #04AA6D 0%, #027349 100%); color: #ffffff; margin: 0 auto 12px; display: flex; align-items: center; justify-content: center; font-size: 32px; font-weight: 700; box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12); border: 3px solid #ffffff; overflow: hidden; } .avatar-circle-main img { width: 100%; height: 100%; object-fit: cover; } .user-welcome-heading { font-size: 20px; font-weight: 700; color: #1f2937; margin-bottom: 4px; } .user-welcome-heading span { color: #04AA6D; } .logged-in-chip { display: inline-block; background: #e5e7eb; color: #374151; font-size: 12px; font-weight: 600; padding: 4px 14px; border-radius: 20px; } .letter-spacing-1 { letter-spacing: 1px; } .transition { transition: all 0.25s ease; } /* CARD CONTAINER OVERRIDE FOR VERTICAL FLEX */ .page-card-hover { border: 1px solid #e5e7eb !important; border-radius: 16px !important; background: #ffffff !important; display: flex !important; flex-direction: column !important; align-items: center !important; justify-content: center !important; text-align: center !important; } .page-card-hover:hover, .page-card-hover:active { transform: translateY(-3px); box-shadow: 0 8px 20px rgba(0,0,0,0.08) !important; background-color: #fdfdfd !important; } .page-card-hover .card-body { display: flex !important; flex-direction: column !important; align-items: center !important; justify-content: center !important; width: 100% !important; } /* PERFECT CENTERED ICON BOX */ .icon-box-badge { width: 64px !important; height: 64px !important; display: flex !important; align-items: center !important; justify-content: center !important; border-radius: 18px !important; margin: 0 auto 12px auto !important; flex-shrink: 0 !important; text-align: center !important; font-size: 28px !important; line-height: 1 !important; } .icon-box-badge i { font-size: 28px !important; line-height: 1 !important; display: inline-block !important; } .emoji-center { font-size: 30px !important; line-height: 1 !important; display: inline-block !important; } </style> <div class="container py-3"> <!-- CENTER PROFILE DP & WELCOME --> <div class="user-profile-center-card"> <div class="avatar-circle-main"> <?php if (!empty($dp_url)): ?> <img src="<?= h($dp_url) ?>" alt="DP"> <?php else: ?> <?= h(strtoupper(substr($display_user_name, 0, 1))) ?> <?php endif; ?> </div> <div class="user-welcome-heading"> Welcome to <span><?= h($company_name) ?></span> </div> <div class="logged-in-chip"> Logged in as: <strong><?= h($display_user_name) ?></strong> (<?= h(ucwords($user_role)) ?>) </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-2"> <div class="col-12 text-center"> <h6 class="text-uppercase fw-bold text-muted small letter-spacing-1 mb-3"> <i class="bi bi-grid-fill me-2"></i> Your Quick Access Pages </h6> </div> </div> <div class="row g-3"> <?php foreach ($pages as $slug): ?> <?php $meta = get_auto_page_meta($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 p-3 page-card-hover transition"> <div class="card-body p-1 w-100"> <!-- CENTERED ICON / EMOJI BOX --> <div class="icon-box-badge" style="background-color: <?= $meta['bg'] ?>; color: <?= $meta['color'] ?>;"> <i class="bi <?= $meta['icon'] ?> me-1"></i> <span class="emoji-center"><?= $meta['emoji'] ?></span> </div> <h6 class="card-title fw-bold text-dark small m-0 text-center"> <?= h(ucwords(str_replace(['_','-'], ' ', $slug))) ?> </h6> </div> </a> </div> <?php endforeach; ?> </div> <?php endif; ?> </div> <?php require_once __DIR__ . '/partials/footer.php'; ?>