<?php
session_start();
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
header("Access-Control-Allow-Headers: X-Requested-With");

if (isset($_POST['user_id']) && isset($_POST['auth']) && isset($_POST['student_id'])) {
    include 'config.php';

    $user_id = $_POST['user_id'];
    $student_id = $_POST['student_id'];
    $auth = $_POST['auth'];

    $user_id = stripslashes($user_id);
    $user_id = mysqli_escape_string($con, $user_id);

    $student_id = stripslashes($student_id);
    $student_id = mysqli_escape_string($con, $student_id);

    $auth = stripslashes($auth);
    $auth = mysqli_escape_string($con, $auth);
    
    $passport_url = $p_url."/passport/";
    $id_url = $p_url."/id_docs/";
      

    $sql = $con->query("SELECT * FROM students WHERE student_id = '$student_id' AND user_id = '$user_id'") 
        or die("Error: " . mysqli_error($con));

    if ($sql->num_rows > 0) {
        $data = [];
        while ($rows = mysqli_fetch_assoc($sql)) {
            
            $data[] = $rows;
        }

        $suc = "Success";
        $status = true;
    } else {
        $data = [];
        $suc = "No record found";
        $status = false;
    }

    $con->close();


    $output = array('success' => $suc, 'status' => $status, 'passport_url' => $passport_url, 'id_url' => $id_url, 'data' => $data);
    echo json_encode($output); // Output JSON data
} else {
    echo json_encode(array('success' => "Failure", 'status' => false, 'message' => "Missing required fields"));
}
?>
