<?php
require 'dbconn.php';

$type = $_GET['type'] ?? '';
$id   = (int)($_GET['id'] ?? 0);

if (!$type || !$id) {
    echo 'Invalid request';
    exit;
}

$table = $type === 'news' ? 'news_tb' : 
         ($type === 'event' ? 'events_tb' : 
         ($type === 'circular' ? 'circulars_tb' : ''));

if (!$table) {
    echo 'Invalid type';
    exit;
}

$stmt = $mysqli->prepare("SELECT * FROM $table WHERE id = ?");
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();

if ($row) {
    echo "<h2 style='color: #e02636;'>" . htmlspecialchars(
        $row['news_title']    ?? 
        $row['event_title']   ?? 
        $row['circular_title'] 
    ) . "</h2>";

    echo "<p>" . htmlspecialchars(
        $row['news_date']     ?? 
        $row['event_date']    ?? 
        $row['circular_date']
    ) . "</p>";

    echo "<div>" . (
        $row['long_desc']     ?? 
        $row['event_desc']    ?? 
        $row['circular_desc']
    ) . "</div>";

} else {
    echo "No data found.";
}
