File "get_halls_with_students.php"

Full path: /home2/santhos2/public_html/bharath-coe.firstmatrix.in.net/api/exam_attendance/get_halls_with_students.php
File size: 1.78 KiB (1825 bytes)
MIME-type: text/x-php
Charset: utf-8

Download   Open   Back

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

try {
    $academicYear = $_GET['academic_year'] ?? null;
    $examTypeId = $_GET['exam_type_id'] ?? null;
    $examDate = $_GET['exam_date'] ?? null;
    
    if (!$academicYear || !$examTypeId || !$examDate) {
        echo json_encode([
            'status' => 'error',
            'message' => 'Academic Year, Exam Type, and Date are required'
        ]);
        exit;
    }
    
    // Get halls with student allocations for the selected criteria
    $query = "
        SELECT DISTINCT 
            ha.allocation_id,
            h.hall_id,
            h.hall_name,
            h.block_name,
            ha.num_students,
            et.exam_date,
            et.session,
            et.start_time,
            et.end_time,
            s.subject_code,
            s.subject_name,
            e.exam_name
        FROM hall_allocations ha
        JOIN halls h ON ha.hall_id = h.hall_id
        JOIN exam_timetable et ON ha.timetable_id = et.timetable_id
        JOIN exam_subjects es ON et.exam_subject_id = es.exam_subject_id
        JOIN subjects s ON es.subject_id = s.subject_id
        JOIN exams e ON es.exam_id = e.exam_id
        WHERE e.academic_year = ? 
        AND e.exam_type_id = ? 
        AND et.exam_date = ?
        ORDER BY h.hall_name, et.session, et.start_time
    ";
    
    $stmt = $pdo->prepare($query);
    $stmt->execute([$academicYear, $examTypeId, $examDate]);
    $halls = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    echo json_encode([
        'status' => 'success',
        'data' => $halls
    ]);
    
} catch (Exception $e) {
    echo json_encode([
        'status' => 'error',
        'message' => 'Error: ' . $e->getMessage()
    ]);
}
?>

PHP File Manager