<?php
include('include/lskfjwfe.php');
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json");

if (!isset($_GET['partner_id']) || empty($_GET['partner_id'])) {
    echo json_encode(["error" => "Missing required partner_id"]);
    exit;
}

$partner_id = intval($_GET['partner_id']);

$sql = "
    SELECT 
        api_locations.api_locations_place_id AS place_id,
        jostj_vikrentcar_places.name AS place_name
    FROM api_locations
    INNER JOIN jostj_vikrentcar_places ON jostj_vikrentcar_places.id = api_locations.api_locations_place_id
    WHERE api_locations.api_locations_partner_id = ?
    ORDER BY jostj_vikrentcar_places.name ASC
";

$stmt = $db2->prepare($sql);
$stmt->bind_param("i", $partner_id);
$stmt->execute();
$result = $stmt->get_result();

$locations = [];
while ($row = $result->fetch_assoc()) {
    $locations[] = $row;
}

$stmt->close();
echo json_encode($locations);
?>
