<?php
session_start();
require_once __DIR__ . '/config/database.php';
require_once __DIR__ . '/database/schema.php';
require_once __DIR__ . '/models/functions.php';
require_once __DIR__ . '/functions.php';
initDatabase();

header('Cache-Control: no-cache, no-store, must-revalidate');
header('Pragma: no-cache');
header('Expires: 0');

$settings = getAllSettings();
$categories = getArticleCategories();
$currentCategory = isset($_GET['category']) ? (int)$_GET['category'] : null;
$searchQuery = $_GET['q'] ?? $_GET['search'] ?? '';
$perPage = 6;
$currentPage = max(1, (int)($_GET['page'] ?? 1));
$totalArticles = countPublishedArticles($currentCategory, $searchQuery);
$articles = getPublishedArticles($perPage, ($currentPage - 1) * $perPage, $currentCategory, $searchQuery);
include __DIR__ . '/views/header.php';
include __DIR__ . '/views/articles.php';
include __DIR__ . '/views/footer.php';
