File "get_invigilators.php"

Full path: /home2/santhos2/public_html/bharath-coe.firstmatrix.in.net/api/invigilation_duties/get_invigilators.php
File size: 962 B
MIME-type: text/x-php
Charset: utf-8

Download   Open   Back

<?php
require_once '../../config/config.php';

header('Content-Type: application/json');

function respond($ok, $msg, $extra = []) {
    echo json_encode(($ok ? ['status' => 'success'] : ['status' => 'error']) + ['message' => $msg] + $extra);
    exit;
}

try {
    // Get staff with Invigilator role
    $sql = "
        SELECT DISTINCT s.staff_id, s.first_name, s.last_name, s.staff_code
        FROM staff s
        INNER JOIN staff_roles sr ON s.staff_id = sr.staff_id
        INNER JOIN staff_role_types srt ON sr.role_id = srt.role_id
        WHERE s.status = 'Active' 
        AND srt.role_name = 'Invigilator'
        ORDER BY s.first_name, s.last_name
    ";
    
    $stmt = $pdo->prepare($sql);
    $stmt->execute();
    $data = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    respond(true, 'Invigilators retrieved successfully', ['data' => $data]);
    
} catch (Exception $e) {
    respond(false, $e->getMessage());
}
?>

PHP File Manager