/home/ejrndhmu/.trash/page.php.2
<?php
require_once 'config/database.php';
require_once 'includes/functions.php';
startSecureSession();

// Get slug from URL
$slug = $_GET['slug'] ?? '';

if (empty($slug)) {
    header('HTTP/1.0 404 Not Found');
    include '404.php';
    exit;
}

// Get page data
$page = getCustomPageBySlug($slug);

if (!$page) {
    header('HTTP/1.0 404 Not Found');
    include '404.php';
    exit;
}

// Check access permissions
$user_type = null;
if (isLoggedIn()) {
    $user_type = $_SESSION['user_type'] ?? null;
}

if (!canAccessCustomPage($page, $user_type)) {
    // Redirect to login if not logged in
    if (!$user_type) {
        header('Location: login.php?redirect=' . urlencode($_SERVER['REQUEST_URI']));
        exit;
    }
    
    // Show access denied for logged in users without permission
    header('HTTP/1.0 403 Forbidden');
    include '403.php';
    exit;
}

// Get site settings
$siteName = getSetting('site_name', 'Panel Digital');
$siteDescription = getSetting('site_description', 'Platform Member Area Produk Digital');
?>
<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo htmlspecialchars($page['title']); ?> - <?php echo htmlspecialchars($siteName); ?></title>
    
    <?php if (!empty($page['meta_description'])): ?>
    <meta name="description" content="<?php echo htmlspecialchars($page['meta_description']); ?>">
    <?php endif; ?>
    
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        'blue-primary': '#1e40af',
                    }
                }
            }
        }
    </script>
    
    <style>
        .content-area {
            line-height: 1.7;
        }
        .content-area h1 {
            @apply text-3xl font-bold text-gray-900 mb-4;
        }
        .content-area h2 {
            @apply text-2xl font-bold text-gray-900 mb-3 mt-6;
        }
        .content-area h3 {
            @apply text-xl font-bold text-gray-900 mb-2 mt-4;
        }
        .content-area p {
            @apply mb-4 text-gray-700;
        }
        .content-area ul, .content-area ol {
            @apply mb-4 ml-6;
        }
        .content-area li {
            @apply mb-1;
        }
        .content-area a {
            @apply text-blue-primary hover:text-blue-600 underline;
        }
        .content-area img {
            @apply max-w-full h-auto rounded-lg shadow-sm my-4;
        }
        .content-area blockquote {
            @apply border-l-4 border-blue-primary pl-4 italic text-gray-600 my-4;
        }
        .content-area code {
            @apply bg-gray-100 px-2 py-1 rounded text-sm font-mono;
        }
        .content-area pre {
            @apply bg-gray-100 p-4 rounded-lg overflow-x-auto my-4;
        }
        .content-area table {
            @apply w-full border-collapse border border-gray-300 my-4;
        }
        .content-area th, .content-area td {
            @apply border border-gray-300 px-4 py-2;
        }
        .content-area th {
            @apply bg-gray-100 font-semibold;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Navigation -->
    <nav class="bg-white shadow-sm border-b border-gray-200">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="flex justify-between items-center h-16">
                <div class="flex items-center">
                    <a href="/paneldigital/" class="text-xl font-bold text-blue-primary">
                        <?php echo htmlspecialchars($siteName); ?>
                    </a>
                </div>
                
                <div class="flex items-center space-x-4">
                    <?php if (isLoggedIn()): ?>
                        <span class="text-gray-600">Halo, <?php echo htmlspecialchars($_SESSION['full_name'] ?? $_SESSION['username']); ?></span>
                        <?php if ($_SESSION['user_type'] === 'admin'): ?>
                            <a href="admin/dashboard.php" class="text-blue-primary hover:text-blue-600">
                                <i class="fas fa-cog mr-1"></i>Admin Panel
                            </a>
                        <?php elseif ($_SESSION['user_type'] === 'reseller'): ?>
                            <a href="reseller/dashboard.php" class="text-blue-primary hover:text-blue-600">
                                <i class="fas fa-tachometer-alt mr-1"></i>Dashboard
                            </a>
                        <?php else: ?>
                            <a href="user/dashboard.php" class="text-blue-primary hover:text-blue-600">
                                <i class="fas fa-tachometer-alt mr-1"></i>Dashboard
                            </a>
                        <?php endif; ?>
                        <a href="config/logout.php" class="text-red-600 hover:text-red-700">
                            <i class="fas fa-sign-out-alt mr-1"></i>Logout
                        </a>
                    <?php else: ?>
                        <a href="login.php" class="text-blue-primary hover:text-blue-600">
                            <i class="fas fa-sign-in-alt mr-1"></i>Login
                        </a>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </nav>

    <!-- Main Content -->
    <main class="max-w-4xl mx-auto py-8 px-4 sm:px-6 lg:px-8">
        <!-- Page Header -->
        <div class="mb-8">
            <div class="flex items-center text-sm text-gray-500 mb-2">
                <a href="/paneldigital/" class="hover:text-blue-primary">Beranda</a>
                <i class="fas fa-chevron-right mx-2"></i>
                <span><?php echo htmlspecialchars($page['title']); ?></span>
            </div>
            
            <h1 class="text-3xl font-bold text-gray-900 mb-2">
                <?php echo htmlspecialchars($page['title']); ?>
            </h1>
            
            <div class="flex items-center text-sm text-gray-500 space-x-4">
                <span>
                    <i class="fas fa-calendar mr-1"></i>
                    Dibuat: <?php echo formatDate($page['created_at']); ?>
                </span>
                
                <?php if ($page['updated_at'] !== $page['created_at']): ?>
                <span>
                    <i class="fas fa-edit mr-1"></i>
                    Diperbarui: <?php echo formatDate($page['updated_at']); ?>
                </span>
                <?php endif; ?>
                
                <span class="flex items-center">
                    <i class="fas fa-lock mr-1"></i>
                    <?php
                    $accessLabels = [
                        'public' => 'Public',
                        'user' => 'User',
                        'reseller' => 'Reseller'
                    ];
                    echo $accessLabels[$page['access_level']];
                    ?>
                </span>
            </div>
        </div>

        <!-- Page Content -->
        <div class="bg-white rounded-lg shadow-sm border border-gray-200 p-8">
            <div class="content-area">
                <?php echo $page['content']; ?>
            </div>
        </div>
        
        <!-- Back Button -->
        <div class="mt-8 text-center">
            <button onclick="history.back()" class="inline-flex items-center px-4 py-2 bg-gray-200 hover:bg-gray-300 text-gray-700 rounded-lg transition-colors">
                <i class="fas fa-arrow-left mr-2"></i>
                Kembali
            </button>
        </div>
    </main>

    <!-- Footer -->
    <footer class="bg-white border-t border-gray-200 mt-16">
        <div class="max-w-7xl mx-auto py-8 px-4 sm:px-6 lg:px-8">
            <div class="text-center text-gray-600">
                <p>&copy; <?php echo date('Y'); ?> <?php echo htmlspecialchars($siteName); ?>. All rights reserved.</p>
            </div>
        </div>
    </footer>
</body>
</html>