<?php
include('../connection.php'); // Ensure this path is correct
header("Content-Type: application/json");

$response = []; // Initialize the response variable

if (isset($_POST['phone']) && isset($_POST['password'])) {
    $phone = $_POST['phone'];
    $password = $_POST['password'];

    // Your query
    $query = "SELECT * FROM line_man WHERE phone = '$phone' AND password = '$password'";

    // Execute the query
    $result = mysqli_query($conn, $query);

    if ($result) {
        // Check if any record is found
        if (mysqli_num_rows($result) > 0) {
            // Fetch the result
            $row = mysqli_fetch_assoc($result);
            $response = [
                'status' => 'success',
                'id' => $row['id'],
                'name' => $row['name'],
                'phone' => $row['phone'],
                'role' => $row['role']
            ];
        } else {
            // If no record found
            $response = [
                'status' => 'error',
                'message' => 'No ticket found with the given phone and password.',
            ];
        }
    } else {
        // If query execution fails
        $response = [
            'status' => 'error',
            'message' => 'Query execution failed: ' . mysqli_error($conn),
        ];
    }

} else {
    // If phone or password is not provided
    $response = [
        'status' => 'error',
        'message' => 'Phone or password not provided.',
    ];
}

// Send the response as JSON
echo json_encode($response);
?>
