����JFIF��`�`�����Viewing File: /home/u820193700/domains/throtllr.in/public_html/api/get_bike_details.php
<?php
require_once '../includes/db.php';
require_once '../includes/functions.php';

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

$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
if (!$id) {
    echo json_encode(['success' => false, 'message' => 'Invalid ID']);
    exit;
}

$stmt = $pdo->prepare("SELECT * FROM bikes WHERE id = ?");
$stmt->execute([$id]);
$bike = $stmt->fetch(PDO::FETCH_ASSOC);

if (!$bike) {
    echo json_encode(['success' => false, 'message' => 'Bike not found']);
    exit;
}

// 1. Map URL
$resolved_map_url = !empty($bike['map_url']) ? $bike['map_url'] : 'https://www.google.com/maps/place/AVAHAN+MOTORS+PRIVATE+LIMITED/@13.0228511,77.6444219,318m/data=!3m1!1e3!4m14!1m7!3m6!1s0x3bae172fa4140de5:0xcad36f1771fbd60e!2sAVAHAN+MOTORS+PRIVATE+LIMITED!8m2!3d13.0228409!4d77.6461109!16s%2Fg%2F11ks6jzl4c!3m5!1s0x3bae172fa4140de5:0xcad36f1771fbd60e!8m2!3d13.0228409!4d77.6461109!16s%2Fg%2F11ks6jzl4c';

$loc_parts = explode(',', $bike['location'], 2);
$loc_title = trim($loc_parts[0]);
$loc_subtitle = isset($loc_parts[1]) ? trim($loc_parts[1]) : '';

// 2. Gallery Images
$imgStmt = $pdo->prepare("SELECT image_url FROM bike_images WHERE bike_id = ? ORDER BY is_main DESC");
$imgStmt->execute([$id]);
$gallery = $imgStmt->fetchAll(PDO::FETCH_COLUMN);

// 3. Video
$vidStmt = $pdo->prepare("SELECT video_url FROM bike_videos WHERE bike_id = ? LIMIT 1");
$vidStmt->execute([$id]);
$video = $vidStmt->fetchColumn() ?: '';

// 4. 360 View Data
$threeStmt = $pdo->prepare("SELECT folder_path, frame_count FROM bike_360_images WHERE bike_id = ? LIMIT 1");
$threeStmt->execute([$id]);
$three60Data = $threeStmt->fetch(PDO::FETCH_ASSOC);

$images360 = [];
$has360 = false;
if ($three60Data) {
    $has360 = true;
    $folder = '../' . $three60Data['folder_path'];
    $web_folder = $three60Data['folder_path'];
    if (is_dir($folder)) {
        $files = scandir($folder);
        $localFiles = [];
        foreach ($files as $file) {
            $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
            if (in_array($ext, ['jpg', 'jpeg', 'png', 'webp'])) {
                $localFiles[] = $web_folder . $file;
            }
        }
        if ($localFiles) {
            natsort($localFiles);
            $images360 = array_values($localFiles);
        }
    }
}

if (!$has360 && !empty($gallery)) {
    $has360 = true;
    $images360 = $gallery;
}

// 5. Wishlist
$is_wishlisted = false;
if (is_customer_logged_in()) {
    $wStmt = $pdo->prepare("SELECT id FROM wishlist WHERE customer_id = ? AND bike_id = ?");
    $wStmt->execute([$_SESSION['customer_id'], $id]);
    if ($wStmt->fetch()) {
        $is_wishlisted = true;
    }
}

echo json_encode([
    'success' => true,
    'bike' => $bike,
    'resolved_map_url' => $resolved_map_url,
    'loc_title' => $loc_title,
    'loc_subtitle' => $loc_subtitle,
    'gallery' => $gallery,
    'video' => $video,
    'has360' => $has360,
    'images360' => $images360,
    'is_wishlisted' => $is_wishlisted,
    'is_logged_in' => is_customer_logged_in()
]);
?>
Back to Directory �������}�!1AQa"q2���#B��R��$3br� %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz�������������������������������������������������������������������������������� ������w�!1AQaq"2�B���� #3R�br� $4�%�&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz������������������������������������������������������������������������ ��?��_��+��?��(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(�����