<?php
session_start();
include 'include/config.php';

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

?>

<?php  include 'include/head.php'; ?>
                    
    <!-- Start Content-->
    <div class="container-fluid">
                        
                        <!-- start page title -->
                        <div class="row">
                            <div class="col-12">
                                <div class="page-title-box">
                                    <div class="page-title-right">
                                        <ol class="breadcrumb m-0">
                                            <li class="breadcrumb-item"><a href="dashboard.php">Home</a></li>
                                            <li class="breadcrumb-item active">Add New User</li>
                                        </ol>
                                    </div>
                                    <h4 class="page-title">Add Vehicle</h4>
                                </div>
                            </div>
                        </div>
                        <!-- end page title --> 

                        <div class="row">
                        <div class="col-12">
                            <div class="card">
                                <div class="card-body">

                    <?php
                    
                    // if(isset($_POST['submit'])){
                    //     $name = $_POST['name'];
                    //     $image = $_FILES['image']['name'];
                    //     $tmp_name = $_FILES['image']['tmp_name'];
                    //     $image_url = 'https://createapp.co.in/ftc_services/upload/cat_img/' . $image;
                    //       $fourRandomDigit = mt_rand(1000,9999);
                                        
                    //      $sql = "INSERT INTO `service_category`(`cat_name`, `cat_image`, `unique_id`) VALUES ('$name','$image_url','$fourRandomDigit')";
                    //     // print_r($sql);
                    //      $res = mysqli_query($conn,$sql);
                    //     if($res){
                    //       move_uploaded_file($tmp_name, '../upload/cat_img/'.$image);
                    //         echo "<h6> Category Submit </h6>";
                    //     }else{
                    //         echo "<h6> Not Submit Category</h6>";
                    //     }
                                        
                    // }

                    // if(isset($_GET['id'])){
                    //     $id = $_GET['id'];
                    //     $url = 'update-notification.php?id='. $id ;

                    //     $sql1 = "SELECT * FROM notification WHERE id='$id' ";
                    //     $res1 = mysqli_query($conn, $sql1);
                    //     $row = mysqli_fetch_assoc($res1);
                    // }
                    ?>
                   <?php


if (isset($_POST['submit'])) { // ✅ Fixed here
    // Collect basic form data
    $name = $_POST['name'];
    $address = $_POST['address'];
    $city = $_POST['city'] ?? '';
    $pincode = $_POST['pincode'] ?? '';
    $phone = $_POST['phone'] ?? '';
    $password = $_POST['password'] ?? '';
    $email = $_POST['email'] ?? '';
    $state = $_POST['state'] ?? '';
    $lat = $_POST['lat'] ?? '';
    $log = $_POST['log'] ?? '';
    $kyc_status = $_POST['kyc_status'] ?? 'pending';
    $covid_19 = $_POST['covid_19'] ?? '';
    $police_verification = $_POST['police_verification'] ?? '';
    $main_service_name = $_POST['main_service_name'] ?? '';
    $rating = $_POST['rating'] ?? 0;
    $per_hour_sallary = $_POST['per_hour_sallary'] ?? 0;
    $booking_status = $_POST['booking_status'] ?? 'available';
    $about_us = $_POST['about_us'] ?? '';
    $vender_fmc_token = $_POST['vender_fmc_token'] ?? '';
    $wallet = $_POST['wallet'] ?? 0;
    $locality = $_POST['locality'] ?? '';

    // Random unique ID
    $unique_id = mt_rand(1000, 9999);

    // File uploads
    $profile_image = $_FILES['profile_image']['name'];
    $adhar_card = $_FILES['adhar_card']['name'];
    $pan_card = $_FILES['pan_card']['name'];

    $profile_tmp = $_FILES['profile_image']['tmp_name'];
    $adhar_tmp = $_FILES['adhar_card']['tmp_name'];
    $pan_tmp = $_FILES['pan_card']['tmp_name'];

    // Upload folder
    $upload_path = 'upload/';
    move_uploaded_file($profile_tmp, $upload_path . $profile_image);
    move_uploaded_file($adhar_tmp, $upload_path . $adhar_card);
    move_uploaded_file($pan_tmp, $upload_path . $pan_card);

    // Final SQL
    $sql = "INSERT INTO vender (
        name, phone, address, city, pincode, password, unique_id, email, state, lat, log,
        adhar_card, pan_card, kyc_status, covid_19, police_verification,
        main_service_name, rating, per_hour_sallary, booking_status,
        profile_image, about_us, vender_fmc_token, wallet, locality
    ) VALUES (
        '$name', '$phone', '$address', '$city', '$pincode', '$password', '$unique_id', '$email', '$state', '$lat', '$log',
        '$adhar_card', '$pan_card', '$kyc_status', '$covid_19', '$police_verification',
        '$main_service_name', '$rating', '$per_hour_sallary', '$booking_status',
        '$profile_image', '$about_us', '$vender_fmc_token', '$wallet', '$locality'
    )";

    $result = mysqli_query($conn, $sql);

    if ($result) {
        echo "<h4>Vendor data submitted successfully!</h4>";
    } else {
        echo "<h4>Error submitting vendor data: " . mysqli_error($conn) . "</h4>";
    }
}
?>


                <form  method="POST" enctype="multipart/form-data">
    <div class="row">
        <!-- First Name -->
        <div class="col-lg-12 mb-3">
            <label class="form-label">Name</label>
            <input type="text" name="name" class="form-control" required>
        </div>

        <!-- Last Name -->
       
        <!-- Phone -->
        <div class="col-lg-6 mb-3">
            <label class="form-label">Phone</label>
            <input type="text" name="phone" class="form-control" required>
        </div>

        <!-- Email -->
        <div class="col-lg-6 mb-3">
            <label class="form-label">Email</label>
            <input type="email" name="email" class="form-control">
        </div>

        <!-- Password -->
        <div class="col-lg-6 mb-3">
            <label class="form-label">Password</label>
            <input type="text" name="password" class="form-control" required>
        </div>

        <!-- Address -->
        <div class="col-lg-6 mb-3">
            <label class="form-label">Address</label>
            <input type="text" name="address" class="form-control" required>
        </div>

        <!-- City -->
        <div class="col-lg-6 mb-3">
            <label class="form-label">City</label>
            <input type="text" name="city" class="form-control">
        </div>

        <!-- State -->
        <div class="col-lg-6 mb-3">
            <label class="form-label">State</label>
            <input type="text" name="state" class="form-control">
        </div>

        <!-- Pincode -->
        <div class="col-lg-6 mb-3">
            <label class="form-label">Pincode</label>
            <input type="text" name="pincode" class="form-control">
        </div>

        <!-- Latitude -->
        <div class="col-lg-6 mb-3">
            <label class="form-label">Latitude</label>
            <input type="text" name="lat" class="form-control">
        </div>

        <!-- Longitude -->
        <div class="col-lg-6 mb-3">
            <label class="form-label">Longitude</label>
            <input type="text" name="log" class="form-control">
        </div>

        <!-- Aadhar Upload -->
        <div class="col-lg-6 mb-3">
            <label class="form-label">Aadhar Card</label>
            <input type="file" name="adhar_card" class="form-control" required>
        </div>

        <!-- PAN Upload -->
        <div class="col-lg-6 mb-3">
            <label class="form-label">PAN Card</label>
            <input type="file" name="pan_card" class="form-control" required>
        </div>

        <!-- Profile Image -->
        <div class="col-lg-6 mb-3">
            <label class="form-label">Profile Image</label>
            <input type="file" name="profile_image" class="form-control" required>
        </div>

        <!-- KYC Status -->
        <div class="col-lg-6 mb-3">
            <label class="form-label">KYC Status</label>
            <select name="kyc_status" class="form-control">
                <option value="pending">Pending</option>
                <option value="approved">Approved</option>
            </select>
        </div>

        <!-- COVID-19 Status -->
        <div class="col-lg-6 mb-3">
            <label class="form-label">COVID-19 Status</label>
            <input type="text" name="covid_19" class="form-control">
        </div>

        <!-- Police Verification -->
        <div class="col-lg-6 mb-3">
            <label class="form-label">Police Verification</label>
            <input type="text" name="police_verification" class="form-control">
        </div>

        <!-- Main Service Name -->
        <div class="col-lg-6 mb-3">
            <label class="form-label">Main Service Name</label>
            <input type="text" name="main_service_name" class="form-control">
        </div>

        <!-- Rating -->
        <div class="col-lg-6 mb-3">
            <label class="form-label">Rating</label>
            <input type="number" name="rating" class="form-control" step="0.1" min="0" max="5">
        </div>

        <!-- Per Hour Salary -->
        <div class="col-lg-6 mb-3">
            <label class="form-label">Per Hour Salary</label>
            <input type="number" name="per_hour_sallary" class="form-control">
        </div>

        <!-- Booking Status -->
        <div class="col-lg-6 mb-3">
            <label class="form-label">Booking Status</label>
            <select name="booking_status" class="form-control">
                <option value="available">Available</option>
                <option value="booked">Booked</option>
            </select>
        </div>

        <!-- About Us -->
        <div class="col-lg-12 mb-3">
            <label class="form-label">About Us</label>
            <textarea name="about_us" class="form-control" rows="4"></textarea>
        </div>

        <!-- FMC Token -->
        <div class="col-lg-6 mb-3">
            <label class="form-label">Vender FMC Token</label>
            <input type="text" name="vender_fmc_token" class="form-control">
        </div>

        <!-- Wallet -->
        <div class="col-lg-6 mb-3">
            <label class="form-label">Wallet</label>
            <input type="number" name="wallet" class="form-control">
        </div>

        <!-- Locality -->
        <div class="col-lg-6 mb-3">
            <label class="form-label">Locality</label>
            <input type="text" name="locality" class="form-control">
        </div>

        <!-- Guarantor ID -->


        <!-- Submit Button -->
        <div class="col-lg-12 text-end">
            <button type="submit" class="btn btn-primary" name="submit">Submit </button>
        </div>
    </div>
</form>

                                </div>
                                <!-- end card-body -->
                            </div>
                            <!-- end card-->
                        </div>
                            <!-- end col -->
            </div> <!-- end row-->


                    
    </div> <!-- container -->


<?php  
include 'include/footer.php'; 
?>
<!-- editor -->
        <script src='https://cdn.ckeditor.com/4.13.0/standard/ckeditor.js'></script>
        <script src='https://code.jquery.com/jquery-3.4.1.min.js'></script>
        <script id="rendered-js" >
            CKEDITOR.replace('editor1');
            CKEDITOR.on('instanceReady', function (evt)
            {
            var editor = evt.editor;

            editor.on('change', function (e) {
                var contentSpace = editor.ui.space('contents');
                var ckeditorFrameCollection = contentSpace.$.getElementsByTagName('iframe');
                var ckeditorFrame = ckeditorFrameCollection[0];
                var innerDoc = ckeditorFrame.contentDocument;
                var innerDocTextAreaHeight = $(innerDoc.body).height();
                console.log(innerDocTextAreaHeight);
            });
            });
            //# sourceURL=pen.js
            
            function checkmobile() {
    jQuery.ajax({
    url: "check_availability.php",
    data:'checkmobilel='+$("#ac_number").val(),
    type: "POST",
    success:function(data){
        $("#check-mobile").html(data);
    },
    error:function (){}
    });
}
        </script>
        
        