<?php
// Simple test to verify data loading works

session_start();
$_SESSION['admin_logged_in'] = true;

require_once 'db_config.php';

// Test 1: Load products from JSON
$products_file = __DIR__ . '/data/products.json';
if (file_exists($products_file)) {
    $content = file_get_contents($products_file);
    $products = json_decode($content, true);
    echo "✓ Products JSON loaded: " . count($products) . " items\n";
} else {
    echo "✗ Products JSON not found\n";
}

// Test 2: Load categories from JSON  
$categories_file = __DIR__ . '/data/categories.json';
if (file_exists($categories_file)) {
    $content = file_get_contents($categories_file);
    $categories = json_decode($content, true);
    echo "✓ Categories JSON loaded: " . count($categories) . " items\n";
} else {
    echo "✗ Categories JSON not found\n";
}

// Test 3: Load blogs from database
require_once 'db_config.php';
$db = $conn;  // Use the connection from db_config.php

if ($db->connect_error) {
    echo "✗ Database connection failed: " . $db->connect_error . "\n";
} else {
    $result = $db->query("SELECT COUNT(*) as cnt FROM blogs");
    if ($result) {
        $row = $result->fetch_assoc();
        echo "✓ Blogs table loaded: " . $row['cnt'] . " items\n";
    } else {
        echo "✗ Blogs query failed: " . $db->error . "\n";
    }
}

echo "\nAll systems operational!\n";
?>
