<?php
session_start();

$host = 'localhost';
$dbname = 'exam_education';
$user = 'root';
$pass = 'root'; // Укажите свой пароль

try {
    $pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8mb4", $user, $pass);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
    die("Ошибка подключения: " . $e->getMessage());
}

function h($str) {
    return htmlspecialchars($str, ENT_QUOTES, 'UTF-8');
}

function isLoggedIn() {
    return isset($_SESSION['user_id']);
}

function getAllNewsCategories($pdo) {
    $stmt = $pdo->query("SELECT DISTINCT category FROM news WHERE is_active = 1 ORDER BY category");
    return $stmt->fetchAll(PDO::FETCH_COLUMN);
}

function getAllGroups($pdo) {
    $stmt = $pdo->query("SELECT DISTINCT group_name FROM schedule ORDER BY group_name");
    return $stmt->fetchAll(PDO::FETCH_COLUMN);
}

function getWeekdayOrder($weekday) {
    $order = [
        'Понедельник' => 1,
        'Вторник' => 2,
        'Среда' => 3,
        'Четверг' => 4,
        'Пятница' => 5,
        'Суббота' => 6
    ];
    return $order[$weekday] ?? 99;
}
?>