%PDF- %GIF98; %PNG; .
Cyber Programmer
Logo of a company Server : Apache
System : Linux sh00666.bluehost.com 5.14.0-687.26.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Jul 14 16:32:02 EDT 2026 x86_64
User : ndkhermy ( 1200)
PHP Version : 8.5.12
Disable Function : NONE
Directory :  /home1/ndkhermy/public_html/website_93b53270/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home1/ndkhermy/public_html/website_93b53270/my-car.php
<?php include('header.php');

if (!isset($_SESSION['user_id'])) {
    echo "<script>window.location='login.php'</script>";
}
?>



<!-- Include Select2 CSS and JS -->
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/js/select2.min.js"></script>

<style>
    .car-box {
        position: relative;
        /* Position relative to place the close icon absolutely */
        background-color: #f9f9f9;
        /* Light background color for the boxes */
        border: 1px solid #ddd;
        /* Border for the boxes */
        padding: 15px;
        /* Padding inside the boxes */
        border-radius: 5px;
        /* Rounded corners for the boxes */
        width: 350px;
        /* Fixed width for the boxes, adjust as needed */
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        /* Optional shadow for a subtle 3D effect */
        box-sizing: border-box;
        /* Ensure padding and border are included in the width */
    }

    .car-box input[type="radio"] {
        margin-right: 10px;
        /* Space between the radio button and text */
    }

    /* Style for the close icon */
    .close-icon {
        position: absolute;
        top: -7px;
        right: 6px;
        font-size: 25px;
        color: #333;
        cursor: pointer;
        transition: color 0.3s;
    }

    .close-icon:hover {
        color: red;
        /* Color change on hover */
    }

    .pos_relative {
        position: relative;
    }

    .pos_relative img {
        padding: 0 5px;
    }

    .active_edit {
        display: flex;
        justify-content: space-between;
        /*position: absolute;*/
        top: 5px;
        width: 100%;
        padding: 5px;
    }

    .flexDtl {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        text-align: center;
    }

    .flexDtl div {
        width: 49%;
        margin-bottom: 10px;
    }

    .flexDtl p {
        margin-bottom: 0;
        font-size: 15px;
    }

    p.headTtl {
        font-size: 12px;
        color: #858585;
    }
</style>

<section>
    <div class="container">
        <div class="row">
            <div class="col-md-4">
                <?php include('user-sidebar.php'); ?>
            </div>

            <div class="col-md-8">
                <div class="bg-white p-5 br-20 my-5 box-shadow">
                    <h3 class="text-center text-danger">My car selections</h3>
                    <p class="text-center text-success" id="msg_f"></p>

                    <?php
                    $sql_my = mysqli_query($conn, "SELECT * FROM mycar_tbl WHERE status = 1 AND user_id = '" . $_SESSION['user_id'] . "'");
                    ?>

                    <div class="row">
                        <?php while ($fetch_my = mysqli_fetch_array($sql_my)):

                            $fetch_brand = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM brand_tbl WHERE id='" . $fetch_my['brand_id'] . "'"));
                            $fetch_variant = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM variant_tbl WHERE id='" . $fetch_my['variant_id'] . "'"));
                            $fetch_model_date = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM model_date_tbl WHERE id='" . $fetch_my['model_year_id'] . "'"));
                            // $fetch_vin = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM vin_tbl WHERE id='" . $fetch_my['vin_id'] . "'"));

                            $checked = (
                                isset($_SESSION['filter']) &&
                                $_SESSION['brand_id'] == $fetch_my['brand_id'] &&
                                $_SESSION['model_year_id'] == $fetch_my['model_year_id'] &&
                                $_SESSION['variant_id'] == $fetch_my['variant_id']
                            ) ? "checked" : "";
                        ?>

                            <div class="col-md-6 delete_id<?= $fetch_my['id'] ?>">
                                <div class="card pos_relative">

                                    <div class="active_edit d-flex justify-content-between p-2">
                                        <input type="radio"
                                            class="car_data"
                                            name="my_car"
                                            data-id="<?= $fetch_my['id'] ?>"
                                            <?= $checked ?>>

                                        <div>
                                            <button type="button" class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#editModal<?= $fetch_my['id'] ?>">Edit</button>

                                            <!-- FIXED: Added correct delete id binding -->
                                            <button type="button" class="btn btn-danger btn-sm fetch_my" data-id="<?= $fetch_my['id'] ?>">Close</button>
                                        </div>
                                    </div>

                                    <img src="<?= $base_url ?>images/Upload/variant/<?= $fetch_variant['image1'] ?>" class="card-img-top">

                                    <div class="card-body">
                                        <div class="flexDtl">

                                            <div>
                                                <p class="headTtl">Brand</p>
                                                <p><?= $fetch_brand['name'] ?></p>
                                            </div>

                                            <div>
                                                <p class="headTtl">Variant</p>
                                                <p><?= $fetch_variant['title'] ?></p>
                                            </div>

                                            <div>
                                                <p class="headTtl">VIN Number</p>
                                                <p>
                                                    <?= $fetch_my['vin_number'] ?>
                                                </p>
                                            </div>

                                            <div>
                                                <p class="headTtl">Model Year</p>
                                                <p><?= $fetch_model_date['title'] ?></p>
                                            </div>

                                        </div>
                                    </div>

                                </div>
                            </div>

                            <!-- Edit Modal -->
                            <div class="modal" id="editModal<?= $fetch_my['id'] ?>">
                                <div class="modal-dialog">
                                    <div class="modal-content">

                                        <div class="modal-header">
                                            <h4 class="modal-title">Edit</h4>
                                            <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                                        </div>

                                        <div class="modal-body">

                                            <center><img src="<?= $base_url ?>images/Upload/variant/<?= $fetch_variant['image1'] ?>" class="card-img-top mb-3" style=" width: 330px; "></center>

                                            <form method="POST" name="car_form<?= $fetch_my['id'] ?>">
                                                <input type="hidden" name="row_id<?= $fetch_my['id'] ?>" value="<?= $fetch_my['id'] ?>">
                                                <div class="flexDtl">
                                                    <div>
                                                        <p class="headTtl">Brand</p>
                                                        <select class="form-select" id="brand<?= $fetch_my['id'] ?>" name="brand<?= $fetch_my['id'] ?>">
                                                            <?php
                                                            $brandQuery = mysqli_query($conn, "SELECT * FROM brand_tbl WHERE status=1");
                                                            while ($row = mysqli_fetch_array($brandQuery)) {
                                                                $brand_ids = explode(',', $fetch_my['brand_id']);
                                                                $checked01 = in_array($row['id'], $brand_ids) ? "selected" : "";
                                                            ?>
                                                                <option value="<?= $row['id'] ?>" <?= $checked01 ?>><?= $row['name'] ?></option>
                                                            <?php } ?>
                                                        </select>
                                                    </div>

                                                    <div>
                                                        <p class="headTtl">Variant</p>
                                                        <select class="form-select" id="variant<?= $fetch_my['id'] ?>" name="variant<?= $fetch_my['id'] ?>">
                                                            <?php
                                                            $variantQuery = mysqli_query($conn, "SELECT * FROM variant_tbl WHERE status=1 AND brand_id='" . $fetch_my['brand_id'] . "'");
                                                            while ($row1 = mysqli_fetch_array($variantQuery)) {
                                                                $variant_ids = explode(',', $fetch_my['variant_id']);
                                                                $checked1 = in_array($row1['id'], $variant_ids) ? "selected" : "";
                                                            ?>
                                                                <option value="<?= $row1['id'] ?>" <?= $checked1 ?>><?= $row1['title'] ?></option>
                                                            <?php } ?>
                                                        </select>
                                                    </div>

                                                    <div>
                                                        <p class="headTtl">VIN Number</p>
                                                        <input type="text" class="form-control" name="vin_number<?= $fetch_my['id'] ?>" value="<?= $fetch_my['vin_number'] ?>">
                                                    </div>

                                                    <div>
                                                        <p class="headTtl">Model Year</p>
                                                        <select class="form-select" id="model_year<?= $fetch_my['id'] ?>" name="model_year<?= $fetch_my['id'] ?>">
                                                        <?php
                                                        $model_dateQuery = mysqli_query($conn, "SELECT * FROM model_date_tbl WHERE status=1");
                                                        while ($row2 = mysqli_fetch_array($model_dateQuery)) {
                                                            $model_date_ids = explode(',', $fetch_my['model_year_id']);
                                                            $checked2 = in_array($row2['id'], $model_date_ids) ? "selected" : "";
                                                        ?>
                                                            <option value="<?= $row2['id'] ?>" <?= $checked2 ?>><?= $row2['title'] ?></option>
                                                        <?php } ?>
                                                        </select>
                                                    </div>
                                                </div>
                                                <button type="submit" class="btn btn-primary" name="update_car<?= $fetch_my['id'] ?>">Update</button>
                                            </form>

                                            <?php
                                            if (isset($_POST['update_car' . $fetch_my['id']])) {
                                                $brand = $_POST['brand' . $fetch_my['id']];
                                                $variant = $_POST['variant' . $fetch_my['id']];
                                                $vin_number = $_POST['vin_number' . $fetch_my['id']];
                                                $model_year = $_POST['model_year' . $fetch_my['id']];

                                                $mysqli_up = mysqli_query($conn, "UPDATE `mycar_tbl` SET 
                                                    `brand_id`='$brand',
                                                    `variant_id`='$variant',
                                                    `vin_number`='$vin_number',
                                                    `model_year_id`='$model_year' WHERE id='".$fetch_my['id']."'");
                                                if($mysqli_up){
                                                    echo "<script>window.location='my-car.php'</script>";
                                                }
                                            }

                                            ?>

                                        </div>

                                    </div>
                                </div>
                            </div>

                            <script>
                                $(document).ready(function() {

                                    $("#brand<?= $fetch_my['id'] ?>").on('change', function() {

                                        let brand_id = $(this).val(); // Get selected brand ID

                                        $.ajax({
                                            method: 'POST',
                                            url: 'variant-ajax1.php',
                                            data: {
                                                brand_id: brand_id
                                            },
                                            cache: false,
                                            success: function(response) {
                                                $("#variant<?= $fetch_my['id'] ?>").html(response);
                                            }
                                        });

                                    });

                                });
                            </script>


                        <?php endwhile; ?>
                    </div>

                </div>
            </div>
        </div>
    </div>
</section>


<?php include('footer.php'); ?>

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

<script>
    $(document).ready(function() {

        // Delete car
        $(document).on('click', '.fetch_my', function() {

            var id = $(this).data('id'); // ✔ Correct id of clicked card
            var user = <?= json_encode($_SESSION['user_id']) ?>;

            $.ajax({
                url: 'my_car_close.php',
                type: 'POST',
                data: {
                    id: id,
                    user: user
                },
                dataType: 'json',

                success: function(response) {
                    if (response.status === 'success') {
                        $('#msg_f').text(response.message).show();
                        $('.delete_id' + id).fadeOut();

                        setTimeout(() => $('#msg_f').fadeOut(), 3000);
                    } else {
                        $('#msg_f').text(response.message).show();
                        setTimeout(() => $('#msg_f').fadeOut(), 3000);
                    }
                },

                error: function(xhr, status, error) {
                    console.log('AJAX Error:', error);
                }
            });
        });

    });
</script>

VaKeR 2022