File "announcements_read_single.php"

Full path: /home2/santhos2/public_html/bharath-coe.firstmatrix.in.net/api/results/announcements_read_single.php
File size: 1.6 KiB (1635 bytes)
MIME-type: text/x-php
Charset: utf-8

Download   Open   Back

<?php
require_once __DIR__ . '/../../config/config.php';
header('Content-Type: application/json');

try {
    $announcement_id = (int)($_GET['id'] ?? 0);
    
    if ($announcement_id <= 0) {
        echo json_encode(['status' => 'error', 'message' => 'Invalid announcement ID']);
        exit;
    }
    
    global $pdo;
    
    // Check if table exists
    $stmt = $pdo->query("SHOW TABLES LIKE 'result_announcements'");
    if ($stmt->rowCount() == 0) {
        echo json_encode(['status' => 'error', 'message' => 'Table not found']);
        exit;
    }
    
    $stmt = $pdo->prepare("SELECT ra.*, c.course_name, et.type_name as exam_type_name
                          FROM result_announcements ra
                          JOIN courses c ON ra.course_id = c.course_id
                          JOIN exam_types et ON ra.exam_type_id = et.exam_type_id
                          WHERE ra.announcement_id = ?");
    $stmt->execute([$announcement_id]);
    $row = $stmt->fetch(PDO::FETCH_ASSOC);
    
    if (!$row) {
        echo json_encode(['status' => 'error', 'message' => 'Announcement not found']);
        exit;
    }
    
    // Format dates for form input
    if ($row['start_at']) {
        $row['start_at'] = date('Y-m-d\TH:i', strtotime($row['start_at']));
    }
    if ($row['end_at']) {
        $row['end_at'] = date('Y-m-d\TH:i', strtotime($row['end_at']));
    }
    
    echo json_encode(['status' => 'success', 'data' => $row]);
} catch (Exception $e) {
    http_response_code(500);
    echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
}
?>

PHP File Manager