<?php
// Admin dashboard - protected page
session_start();

// Check if user is logged in as admin
if (!isset($_SESSION['is_admin']) || $_SESSION['is_admin'] !== true) {
    header('Location: admin_login.php');
    exit;
}


$username = $_SESSION['username'] ?? 'Admin';

// Data files and upload paths
$dataDir = __DIR__ . '/data';
if (!is_dir($dataDir)) @mkdir($dataDir, 0755, true);
$configFile = $dataDir . '/site_config.json';
$pagesFile = $dataDir . '/pages.json';
$uploadDir = __DIR__ . '/uploads';
if (!is_dir($uploadDir)) @mkdir($uploadDir, 0755, true);

$siteConfig = ['title' => "Esa's Fashion", 'logo' => ''];
if (file_exists($configFile)) {
    $c = @json_decode(file_get_contents($configFile), true);
    if (is_array($c)) $siteConfig = array_merge($siteConfig, $c);
}


// Load pages
$pages = [];
if (file_exists($pagesFile)) {
    $p = @json_decode(file_get_contents($pagesFile), true);
    if (is_array($p)) $pages = $p;
}

$flash = '';

$pages = [];
if(file_exists($pagesFile))
{
    $p = @json_decode(file_get_contyents($pagesFile), true);
    if ( is_array($p)) $pages = $p;
}
