<?php
// Database connection setup
require '../includes/DB/connection.php';
$connect=new Connection();
$con=$connect->connect();

$campus_id = $_GET['campus'];
$branch = $_GET['branch'];
$lang = $_GET['lang'];

$lang_column = '';
switch ($lang) {
    case 'EN':
        $lang_column = 'l.language_en = 1';
        break;
    case 'TA':
        $lang_column = 'l.language_ta = 1';
        break;
    case 'SI':
        $lang_column = 'l.language_si = 1';
        break;
    default:
        die("Invalid language selected");
}

$sql = "SELECT *
        FROM user u
        JOIN campus c ON u.campus_id = c.campus_id
        JOIN branch b ON u.branch_id = b.branch_id
        JOIN language l ON u.user_id = l.user_id
        WHERE 
        u.user_role_id=4 AND
        u.campus_id = '$campus_id'
        AND b.branch_id = '$branch'
        AND $lang_column";

// echo "$sql";

$result = $con->query($sql);
$counselors = [];

if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        $counselors[] = $row;
    }
}

$con->close();

header('Content-Type: application/json');
echo json_encode($counselors);