<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Admin : View Leads</title>
    <link rel="stylesheet" href="https://cdn.datatables.net/1.11.4/css/jquery.dataTables.min.css">
    <?php include("headerlink.php")?>
</head>

<body class="hold-transition sidebar-mini layout-fixed">
    <div class="wrapper">

        <div class="preloader flex-column justify-content-center align-items-center">
            <img class="animation__shake" src="dist/img/AdminLTELogo.png" alt="AdminLTELogo" height="60" width="60">
        </div>
        <?php include("navbar.php")?>

        <?php include("sidebar.php")?>

        <div class="content-wrapper">

            <div class="content-header">
                <div class="container-fluid">
                    <div class="row mb-2">
                        <div class="col-sm-6">
                            <h1 class="m-0 fw-bold text-uppercase ">Leads</h1>
                        </div>
                        <div class="col-sm-6">
                            <ol class="breadcrumb float-sm-right">
                                <li class="breadcrumb-item"><a href="#">Home</a></li>
                                <li class="breadcrumb-item active">Leads</li>
                                <li class="breadcrumb-item active">View All</li>
                            </ol>
                        </div>
                    </div>
                </div>
            </div>

            <section class="content">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-12">
                            <div class="card shadow">
                                <div class="card-header" style="background: #343a40; ">
                                    <h3 class="card-title text-white text-bold text-uppercase"> View All leads</h3>
                                </div>

                                <div class="card-body">
                                    <div id="example2_wrapper" class="dataTables_wrapper dt-bootstrap4">
                                        <div class="row">
                                            <div class="col-sm-12 col-md-6"></div>
                                            <div class="col-sm-12 col-md-6"></div>
                                        </div>
                                        <div class="row">
                                            <div class="col-sm-12">
                                                <table class="table-responsive text-center">
                                                    <table id="example2"
                                                        class="table table-bordered text-center table-hover dataTable dtr-inline display"
                                                        aria-describedby="example2_info">
                                                        <thead>
                                                            <tr>
                                                                <th>Sr No.</th>
                                                                <th>Date &amp; time</th>
                                                                <th>Name</th>
                                                                <th>Email</th>
                                                                <th>Number</th>
                                                                <th>Service</th>
                                                                <th>Lead Date</th>
                                                                <th>Status</th>
                                                            </tr>
                                                        </thead>
                                                        <tbody>
                                                            <?php
                                                            include('connection.php');
                                                            $sql = "SELECT * FROM add_leads";
                                                            $query = mysqli_query($conn, $sql);
                                                            while ($row = mysqli_fetch_assoc($query)) {
                                                            ?>
                                                            <tr>
                                                                <td><?php echo $row['id']?></td>
                                                                <td><?php echo $row['datetime']?></td>
                                                                <td><?php echo $row['name']?></td>
                                                                <td><?php echo $row['email1']?></td>
                                                                <td><?php echo $row['contact1']?></td>

                                                                <td class="view-details-button fw-bold text-danger text-uppercase"
                                                                    style="text-decoration: none; " data-toggle="modal"
                                                                    data-target="#detailsModal<?php echo $row['id'];?>">
                                                                    <?php echo $row['service']?>
                                                                </td>

                                                                <td><?php echo $row['lead_date']?></td>
                                                                <td class="text-center">
                                                                    <select name="status"
                                                                        class="form-control status-dropdown"
                                                                        data-lead-id="<?php echo $row['id']; ?>">
                                                                        <option value="Followup">Followup</option>
                                                                        <option value="No update">No update</option>
                                                                        <option value="Pricing Issue">Pricing Issue
                                                                        </option>
                                                                        <option value="Not Available">Not Available
                                                                        </option>
                                                                        <option value="Purchased">Purchased</option>
                                                                        <option value="Denied">Denied</option>
                                                                    </select>
                                                                </td>
                                                            </tr>
                                                            <?php }?>

                                                        </tbody>

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

                                    </div>
                                </div>

                            </div>

                        </div>

                    </div>

                </div>

            </section>

        </div>
    </div>

    <?php
      include('connection.php');
      $sql = "SELECT * FROM add_leads";
      $query = mysqli_query($conn, $sql);
      while ($row = mysqli_fetch_assoc($query)) {
     ?>
    <div class="modal fade" id="detailsModal<?php echo $row['id'];?>">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header" style="background: #343a40; ">
                    <h4 class="modal-title fw-bold text-uppercase text-white">Large Modal</h4>
                    <button type="button" class="close text-white" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">

                    <form action="update_leads_code.php" method="POST">
                        <div class="card-body">
                            <input type="hidden" class="form-control" placeholder="Name" id="id" name="id"
                                value="<?php echo $row['id']?>">
                            <div class="row">
                                <div class="col-6">
                                    <div class="form-group">
                                        <label for="exampleInputName">Name</label>
                                        <input type="text" class="form-control" placeholder="Name" name="name"
                                            value="<?php echo $row['name']?>">
                                    </div>
                                </div>
                                <div class="col-6">
                                    <div class="form-group">
                                        <label for="exampleInputPurpose">Compnay Name</label>
                                        <input type="text" class="form-control" placeholder="Compnay Name"
                                            name="company_name" value="<?php echo $row['company_name']?>">
                                    </div>
                                </div>
                            </div>

                            <div class="row">
                                <div class="col-6">
                                    <div class="form-group">
                                        <label for="exampleInputContact1">Contact 1</label>
                                        <!-- <input type="number" class="form-control" placeholder="Contact Number"
                                            name="contact1" value="<?php echo $row['contact1']?>"> -->
                                        <input type="text" class="form-control" value="<?php echo $row['contact1']?>"
                                            id="exampleInputName" placeholder="Contact Number" name="contact1"
                                            oninput="this.value = this.value.replace(/[^0-9]/g, '');">
                                    </div>
                                </div>
                                <div class="col-6">
                                    <div class="form-group">
                                        <label for="exampleInputContact2">Contact 2</label>
                                        <input type="text" class="form-control" value="<?php echo $row['contact2']?>"
                                            id="exampleInputName" placeholder="Contact Number" name="contact2"
                                            oninput="this.value = this.value.replace(/[^0-9]/g, '');">
                                    </div>
                                </div>


                            </div>
                            <div class="row">
                                <div class="col-6">
                                    <div class="form-group">
                                        <label for="exampleInputContact1">Contact Email 1</label>
                                        <input type="email" class="form-control" placeholder="Contact Email"
                                            name="email1" value="<?php echo $row['email1']?>">
                                    </div>
                                </div>
                                <div class="col-6">
                                    <div class="form-group">
                                        <label for="exampleInputContact2">Contact Email 2</label>
                                        <input type="email" class="form-control" placeholder="Contact Email"
                                            name="email2" value="<?php echo $row['email2']?>">
                                    </div>
                                </div>


                            </div>
                            <div class="row">
                                <div class="col-6">
                                    <div class="form-group">
                                        <label for="exampleInputContact1">Company Website 1</label>
                                        <input type="text" class="form-control" placeholder="Company Website"
                                            name="website1" value="<?php echo $row['website1']?>">
                                    </div>
                                </div>
                                <div class="col-6">
                                    <div class="form-group">
                                        <label for="exampleInputContact2">Company Website 2</label>
                                        <input type="text" class="form-control" placeholder="Company Website"
                                            name="website2" value="<?php echo $row['website2']?>">
                                    </div>
                                </div>


                            </div>
                            <div class="row">
                                <div class="col-4">
                                    <div class="form-group">
                                        <label for="exampleInputContact3">Linkedin Page</label>
                                        <div class="input-group mb-3">
                                            <div class="input-group-prepend">
                                                <span class="input-group-text"><i class="fab fa-linkedin"></i></span>
                                            </div>
                                            <!-- <input type="text" class="form-control" placeholder="Linkedin Page"
                                                name="linkedin_username" value="<?php echo $row['linkedin_page']?>"> -->
                                            <input type="text" class="form-control"
                                                value="<?php echo $row['linkedin_page']?>" name="linkedin_username"
                                                placeholder="Linkedin Page">
                                            <input type="hidden" name="linkedin" value="https://www.linkedin.com/in/">
                                        </div>
                                    </div>
                                </div>
                                <div class="col-2">
                                    <div class="form-group">
                                        <label for="exampleInputContact2">Followers</label>
                                        <input type="text" class="form-control" placeholder="Followers"
                                            name="linkedin_followers" value="<?php echo $row['linkedin_followers']?>">
                                    </div>
                                </div>
                                <div class="col-4">
                                    <div class="form-group">
                                        <label for="exampleInputContact3">GMB Page</label>
                                        <div class="input-group mb-3">
                                            <div class="input-group-prepend">
                                                <span class="input-group-text"><i class="fab fa-google"></i></span>
                                            </div>
                                            <!-- <input type="text" class="form-control" name="gmb_page_username"
                                                placeholder="Google My Business Page"
                                                value="<?php echo $row['gmb_page']?>"> -->
                                            <input type="text" name="gmb_page_username"  value="<?php echo $row['gmb_page']?>" class="form-control"
                                                placeholder="GMB Page Username">
                                            <input type="hidden" name="gmb_page" value="https://www.google.com/">
                                        </div>
                                    </div>
                                </div>
                                <div class="col-2">
                                    <div class="form-group">
                                        <label for="exampleInputContact2">Reviews</label>
                                        <input type="text" name="gmb_review" class="form-control" placeholder="Reviews"
                                            value="<?php echo $row['gmb_review']?>">
                                    </div>
                                </div>

                            
                            </div>

                            <label for="exampleInputEmail1">Social Handels</label>
                            <div class="row">
                                <div class="col-8">
                                    <div class="input-group mb-3">
                                        <div class="input-group-prepend">
                                            <span class="input-group-text"><i class="fab fa-facebook"></i></span>
                                        </div>
                                        <!-- <input type="text" name="facebook" value="<?php echo $row['fb_url']?>"
                                            class="form-control" placeholder="Facebook URL"> -->

                                        <input type="text" name="facebook_username" class="form-control"
                                            placeholder="Facebook Username" value="<?php echo $row['fb_url']?>"
                                            required>
                                        <input type="hidden" name="facebook" value="https://www.facebook.com/">
                                    </div>
                                </div>
                                <div class="col-4">
                                    <div class="input-group mb-3">
                                        <div class="input-group-prepend">
                                        </div>
                                        <input type="text" value="<?php echo $row['fb_review']?>" class="form-control"
                                            placeholder="Rating & Reviews" name="fb_review">
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-8">
                                    <div class="input-group mb-3">
                                        <div class="input-group-prepend">
                                            <span class="input-group-text"><i class="fab fa-instagram"></i></span>
                                        </div>
                                        <!-- <input type="text" class="form-control" name="instagram_username"
                                            placeholder="Instagram URL" value="<?php echo $row['insta_url']?>"> -->
                                        <input type="text" name="instagram_username"
                                            value="<?php echo $row['insta_url']?>" class="form-control"
                                            placeholder="Instagram Username">
                                        <input type="hidden" name="instagram" value="https://www.instagram.com/">
                                    </div>
                                </div>
                                <div class="col-4">
                                    <div class="input-group mb-3">
                                        <div class="input-group-prepend">
                                        </div>
                                        <input type="text" class="form-control" placeholder="Rating & Reviews"
                                            name="insta_review" value="<?php echo $row['insta_review']?>">
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-8">
                                    <div class="input-group mb-3">
                                        <div class="input-group-prepend">
                                            <span class="input-group-text"><i class="fab fa-twitter"></i></span>
                                        </div>
                                        <!-- <input type="text" class="form-control" name="twitter_username"
                                            placeholder="Twitter URL" value="<?php echo $row['twitt_url']?>"> -->
                                        <input type="text" name="twitter_username"
                                            value="<?php echo $row['twitt_url']?>" class="form-control"
                                            placeholder="Twitter Username">
                                        <input type="hidden" name="twitter" value="https://twitter.com/">
                                    </div>
                                </div>
                                <div class="col-4">
                                    <div class="input-group mb-3">
                                        <div class="input-group-prepend">
                                        </div>
                                        <input type="text" class="form-control" placeholder="Rating & Reviews"
                                            name="twitt_review" value="<?php echo $row['twitt_review']?>">
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-8">
                                    <div class="input-group mb-3">
                                        <div class="input-group-prepend">
                                            <span class="input-group-text"><i class="fab fa-youtube"></i></span>
                                        </div>
                                        <!-- <input type="text" class="form-control" name="youtube_username"
                                            placeholder="Youtube URL" value="<?php echo $row['youtube_url']?>"> -->

                                        <input type="text" name="youtube_username"
                                            value="<?php echo $row['youtube_url']?>" class="form-control"
                                            placeholder="Youtube Username">
                                        <input type="hidden" name="youtube" value="https://www.youtube.com/">
                                    </div>
                                </div>
                                <div class="col-4">
                                    <div class="input-group mb-3">
                                        <div class="input-group-prepend">
                                        </div>
                                        <input type="text" class="form-control" placeholder="Rating & Reviews"
                                            name="youtube_review" value="<?php echo $row['youtube_review']?>">
                                    </div>
                                </div>
                            </div>

                            <div class="row">
                                <div class="col-8">
                                    <div class="input-group mb-3">
                                        <div class="input-group-prepend">
                                            <span class="input-group-text"><i class="fa fa-whatsapp fw-bold"></i></span>
                                        </div>
                                        <!-- <input type="text" class="form-control" name="youtube_username"
                                            placeholder="Youtube URL" value="<?php echo $row['youtube_url']?>"> -->

                                        <input type="text" name="whatsapp_username"
                                            value="<?php echo $row['whatsapp_url']?>" class="form-control"
                                            placeholder="WhatsApp Username">
                                        <input type="hidden" name="youtube" value="https://wa.me/+">
                                    </div>
                                </div>

                                <div class="col-4">
                                    <div class="input-group mb-3">
                                        <div class="input-group-prepend">
                                        </div>
                                        <input type="text" class="form-control" placeholder="Rating & Reviews"
                                            name="whatsapp_review" value="<?php echo $row['whatsapp_review']?>">
                                    </div>
                                </div>
                            </div>

                            <div class="row">
                                <div class="col-4">
                                    <div class="form-group">
                                        <label for="exampleInputName">Service</label>
                                        <select name="service" class="form-control">
                                            <option value="">Select</option>
                                            <option value="WhatsApp Marketing"
                                                <?php echo ($row['service'] === 'WhatsApp Marketing') ? 'selected' : ''; ?>>
                                                WhatsApp Marketing
                                            </option>
                                            <option value="Bulk SMS"
                                                <?php echo ($row['service'] === 'Bulk SMS') ? 'selected' : ''; ?>>
                                                Bulk SMS
                                            </option>
                                            <option value="Amazon Reviews"
                                                <?php echo ($row['service'] === 'Amazon Reviews') ? 'selected' : ''; ?>>
                                                Amazon Reviews
                                            </option>
                                            <option value="GMB Reviews"
                                                <?php echo ($row['service'] === 'GMB Reviews') ? 'selected' : ''; ?>>
                                                GMB Reviews
                                            </option>
                                            <option value="Justdial Reviews"
                                                <?php echo ($row['service'] === 'Justdial Reviews') ? 'selected' : ''; ?>>
                                                Justdial Reviews
                                            </option>
                                            <option value="Database"
                                                <?php echo ($row['service'] === 'Database') ? 'selected' : ''; ?>>
                                                Database
                                            </option>
                                        </select>
                                    </div>
                                </div>


                                <div class="col-4">
                                    <div class="form-group">
                                        <label for="exampleInputContact2">Source</label>
                                        <select name="source" class="form-control">
                                            <option value="">Select</option>
                                            <option value="Enquiry"
                                                <?php echo ($row['source'] === 'Enquiry') ? 'selected' : ''; ?>>
                                                Enquiry
                                            </option>
                                            <option value="WA Business"
                                                <?php echo ($row['source'] === 'WA Business') ? 'selected' : ''; ?>>
                                                WA Business
                                            </option>
                                            <option value="WA US"
                                                <?php echo ($row['source'] === 'WA US') ? 'selected' : ''; ?>>
                                                WA US
                                            </option>
                                            <option value="IndiaMart"
                                                <?php echo ($row['source'] === 'IndiaMart') ? 'selected' : ''; ?>>
                                                IndiaMart
                                            </option>
                                            <option value="Email"
                                                <?php echo ($row['source'] === 'Email') ? 'selected' : ''; ?>>
                                                Email
                                            </option>
                                            <option value="Call"
                                                <?php echo ($row['source'] === 'Call') ? 'selected' : ''; ?>>
                                                Call
                                            </option>
                                            <option value="Other"
                                                <?php echo ($row['source'] === 'Other') ? 'selected' : ''; ?>>
                                                Other
                                            </option>
                                        </select>
                                    </div>
                                </div>


                                <div class="col-4">
                                    <div class="form-group">
                                        <label for="exampleInputContact3">Lead Date</label>
                                        <input type="date" name="lead_date" class="form-control"
                                            placeholder="Contact Number" value="<?php echo $row['lead_date']?>">
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-12">
                                    <div class="form-group">
                                        <label for="exampleInputContact1">Lead Description</label>
                                        <textarea id="lead_discription" name="lead_discription" rows="5"
                                            class="form-control"
                                            placeholder="Lead Description here...."><?php echo $row['lead_discription']; ?></textarea>
                                    </div>
                                </div>

                            </div>

                        </div>
                        <div class="card-footer">
                            <button type="submit" class="btn text-white fw-bold" style="background: #343a40;">Update
                                Leads</button>
                        </div>
                    </form>


                </div>

            </div>

        </div>

    </div>
    <?php }?>

    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/2.1.2/sweetalert.min.js"></script>
    <script>
    $(document).ready(function() {
        <?php if (isset($_GET['error'])) { ?>
        Swal.fire({
            title: 'Error',
            text: '<?php echo $_GET['error']; ?>',
            icon: 'error',
            confirmButtonText: 'OK',
            confirmButtonClass: 'btn btn-success btn-lg',
        });
        <?php } ?>
        <?php if (isset($_GET['success'])) { ?>
        Swal.fire({
            title: 'Success',
            text: '<?php echo $_GET['success']; ?>',
            icon: 'success',
            confirmButtonText: 'OK',
            confirmButtonClass: 'btn btn-success btn-lg',
        });
        <?php } ?>
    });
    </script>
    <script>
    $(document).ready(function() {
        $(".status-dropdown").change(function() {
            var leadId = $(this).data("lead-id");
            var status = $(this).val();

            // Send AJAX request to update status
            $.ajax({
                url: "update_lead_status.php",
                type: "POST",
                data: {
                    lead_id: leadId,
                    status: status
                },
                success: function(response) {
                    // Handle the response (e.g., show a success message)
                    console.log(response);
                },
                error: function(xhr, status, error) {
                    // Handle errors (e.g., show an error message)
                    console.error(error);
                }
            });
        });
    });
    </script>
    <?php include("footer.php")?>
    <?php include("footerlink.php")?>



    <script src="../../plugins/datatables/jquery.dataTables.min.js"></script>
    <script src="../../plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
    <script src="../../plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>
    <script src="../../plugins/datatables-responsive/js/responsive.bootstrap4.min.js"></script>
    <script src="../../plugins/datatables-buttons/js/dataTables.buttons.min.js"></script>
    <script src="../../plugins/datatables-buttons/js/buttons.bootstrap4.min.js"></script>
    <script src="../../plugins/jszip/jszip.min.js"></script>
    <script src="../../plugins/pdfmake/pdfmake.min.js"></script>
    <script src="../../plugins/pdfmake/vfs_fonts.js"></script>
    <script src="../../plugins/datatables-buttons/js/buttons.html5.min.js"></script>
    <script src="../../plugins/datatables-buttons/js/buttons.print.min.js"></script>
    <script src="../../plugins/datatables-buttons/js/buttons.colVis.min.js"></script>

    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="https://cdn.datatables.net/1.11.4/js/jquery.dataTables.min.js"></script>
    <script>
    var $j = jQuery.noConflict();
    $j(document).ready(function() {
        $j('#example2').DataTable();
    });
    </script>
</body>

</html>