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

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (!isset($_POST['csrf_token']) || !verify_csrf_token($_POST['csrf_token'])) {
        die("CSRF token validation failed.");
    }
    $name = $_POST['name'] ?? '';
    $phone = $_POST['phone'] ?? '';
    $email = $_POST['email'] ?? '';
    $city = $_POST['city'] ?? '';
    $model_name = $_POST['model_name'] ?? '';
    $year = $_POST['year'] ?? '';
    $km_driven = $_POST['km_driven'] ?? '';
    $registration_number = $_POST['registration_number'] ?? '';
    $expected_price = $_POST['expected_price'] ?? '';
    $description = $_POST['description'] ?? '';

    $reference_id = 'SELL-' . strtoupper(substr(uniqid(), -6));
    
    // Create folders for uploads
    $uploadBase = '../assets/uploads/sell_requests/' . $reference_id;
    if (!file_exists($uploadBase)) {
        mkdir($uploadBase, 0777, true);
    }
    
    $images_folder = 'assets/uploads/sell_requests/' . $reference_id . '/images/';
    $video_url = '';
    $three60_folder = '';

    $allowed_image_exts = ['jpg', 'jpeg', 'png', 'webp', 'gif', 'heic'];
    
    // Handle Image Uploads
    $has_images = false;
    if (isset($_FILES['images']['name']) && is_array($_FILES['images']['name'])) {
        foreach ($_FILES['images']['name'] as $img_name) {
            if (!empty($img_name)) {
                $has_images = true;
                break;
            }
        }
    }

    if ($has_images) {
        if (!file_exists('../' . $images_folder)) mkdir('../' . $images_folder, 0777, true);
        foreach ($_FILES['images']['tmp_name'] as $key => $tmp_name) {
            if (!empty($tmp_name) && is_uploaded_file($tmp_name)) {
                $fileName = basename($_FILES['images']['name'][$key]);
                $ext = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
                
                if (in_array($ext, $allowed_image_exts)) {
                    move_uploaded_file($tmp_name, '../' . $images_folder . $fileName);
                }
            }
        }
    } else {
        $images_folder = null;
    }

    // Handle Video Upload
    $allowed_video_exts = ['mp4', 'webm', 'mov', 'avi'];
    if (!empty($_FILES['video']['name'])) {
        $fileName = basename($_FILES['video']['name']);
        $ext = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
        
        if (in_array($ext, $allowed_video_exts)) {
            $videoDir = 'assets/uploads/sell_requests/' . $reference_id . '/video/';
            if (!file_exists('../' . $videoDir)) mkdir('../' . $videoDir, 0777, true);
            if (move_uploaded_file($_FILES['video']['tmp_name'], '../' . $videoDir . $fileName)) {
                $video_url = $videoDir . $fileName;
            }
        }
    }

    // Handle 360 ZIP
    if (!empty($_FILES['zip_360']['name'])) {
        $fileName = basename($_FILES['zip_360']['name']);
        $ext = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
        
        if ($ext === 'zip') {
            $three60Dir = 'assets/uploads/sell_requests/' . $reference_id . '/360/';
            if (!file_exists('../' . $three60Dir)) mkdir('../' . $three60Dir, 0777, true);
            $zipFile = $_FILES['zip_360']['tmp_name'];
            $zip = new ZipArchive;
            if ($zip->open($zipFile) === TRUE) {
                $zip->extractTo('../' . $three60Dir);
                $zip->close();
                $three60_folder = $three60Dir;
            }
        }
    }

    try {
        $customer_id = $_SESSION['customer_id'] ?? null;
        $stmt = $pdo->prepare("INSERT INTO sell_requests (reference_id, customer_id, name, phone, email, city, model_name, year, km_driven, expected_price, registration_number, description, images_folder, video_url, three60_folder, status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'pending')");
        $stmt->execute([
            $reference_id, $customer_id, $name, $phone, $email, $city, $model_name, $year, $km_driven, 
            $expected_price ?: null, $registration_number, $description, $images_folder, $video_url ?: null, $three60_folder ?: null
        ]);

        // Redirect back with success
        header("Location: ../sell-bike.php?success=1&ref=" . $reference_id);
        exit;
    } catch (\PDOException $e) {
        die("Database error: " . $e->getMessage());
    }
}
?>
Back to Directory �������}�!1AQa"q2���#B��R��$3br� %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz�������������������������������������������������������������������������������� ������w�!1AQaq"2�B���� #3R�br� $4�%�&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz������������������������������������������������������������������������ ��?��_��+��?��(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(�����