// Enable error reporting (disable in production) ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); // Start session if not already started if (session_status() === PHP_SESSION_NONE) { session_start(); } // Base paths define('BASE_PATH', __DIR__); define('PAGES_PATH', BASE_PATH . '/pages'); define('ADMIN_PATH', PAGES_PATH . '/admin'); // Load config and utilities require_once BASE_PATH . '/config/db.php'; require_once BASE_PATH . '/includes/functions.php'; // Load site settings $siteSettings = function_exists('getSiteSettings') ? getSiteSettings() : []; // Get requested page from query $page = $_GET['page'] ?? 'home'; // Include header include_once BASE_PATH . '/includes/header.php'; // Routing switch ($page) { // Public pages case 'home': case 'login': case 'register': include PAGES_PATH . "/{$page}.php"; break; // Protected user pages (requires login) case 'dashboard': case 'tasks': case 'wallet': case 'convert': case 'deposit': case 'withdraw': case 'add-wallet': case 'news': case 'referrals': case 'history': case 'profile': case 'kyc': case 'videos': case 'upgrade': case 'deposits': case 'withdrawals': case 'settings': case 'terms': case 'privacy': case 'faq': case 'contact': case 'about': case 'daily_reward': if (!isset($_SESSION['user_id'])) { header("Location: index.php?page=login"); exit; } include PAGES_PATH . "/{$page}.php"; break; // Admin login case 'admin-login': include ADMIN_PATH . '/login.php'; break; // Protected admin pages (requires admin role) case 'admin': case 'admin-dashboard': case 'admin-tasks': case 'admin-news': case 'admin-logs': case 'admin-users': case 'admin-settings': case 'admin-profile': case 'admin-videos': case 'admin-sidebar': case 'admin-email': case 'admin_profile': case 'admin_page': if (!isset($_SESSION['user_id']) || ($_SESSION['user_role'] ?? '') !== 'admin') { header("Location: index.php?page=admin-login"); exit; } // Handle admin sections $section = $_GET['section'] ?? 'dashboard'; if ($section === 'auto-news') { include ADMIN_PATH . '/auto_news.php'; } elseif ($section === 'tasks') { include ADMIN_PATH . '/tasks.php'; } else { // Map admin pages to filenames $adminPage = match ($page) { 'admin' => 'index', 'admin-dashboard' => 'dashboard', 'admin-tasks' => 'tasks', 'admin-news' => 'news', 'admin-logs' => 'logs', 'admin-users' => 'users', 'admin-settings' => 'settings', 'admin-profile' => 'profile', 'admin-videos' => 'videos', 'admin-sidebar' => 'sidebar', 'admin-pages' => 'page', 'admin-email' => 'email', default => 'dashboard', }; include ADMIN_PATH . "/{$adminPage}.php"; } break; // Logout case 'logout': include PAGES_PATH . '/logout.php'; break; // Fallback for unknown pages default: include PAGES_PATH . '/404.php'; break; } // Include footer include_once BASE_PATH . '/includes/footer.php';