<!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 ">Accounts</h1>
                        </div>
                        <div class="col-sm-6">
                            <ol class="breadcrumb float-sm-right">
                                <li class="breadcrumb-item"><a href="#">HR</a></li>
                                <li class="breadcrumb-item active">Accounts</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; ">
                                    <div class="row">
                                        <div class="col-10">
                                            <h3 class="card-title text-white text-bold text-uppercase pt-1">All Accounts
                                            </h3>
                                        </div>
                                        <div class="col-2 text-end">
                                            <button type="button" class="btn btn-danger btn-sm" data-toggle="modal" data-target="#modal-success">
                                                <i class="fa fa-plus-circle" aria-hidden="true"></i>
                                            </button>
                                        </div>
                                    </div>
                                </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>Plateform</th>
                                                                <th>URl</th>
                                                                <th>Username</th>
                                                                <th>Password</th>
                                                                <th>Type</th>
                                                                <th>Action</th>

                                                            </tr>
                                                        </thead>
                                                        <tbody>
                                                            <?php
                                                            include('connection.php');
                                                            $sql = "SELECT * FROM hr_accounts";
                                                            $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['plateform'] ?></td>
                                                                    <td><?php echo $row['url'] ?></td>
                                                                    <td><?php echo $row['name'] ?></td>
                                                                    <td><?php echo $row['pass'] ?></td>
                                                                    <td><?php echo $row['type'] ?></td>
                                                                    <td>
                                                                        <a href="delete_hr_accounts.php?delete=<?php echo $row['id']; ?>" class="btn btn-danger btn-sm">Delete</a>


                                                                        <a type="button" class="btn btn-success btn-sm" data-toggle="modal" data-target="#detailsModal<?php echo $row['id']; ?>">
                                                                            Edit
                                                                        </a>
                                                                    </td>
                                                                    <div class="modal fade" id="detailsModal<?php echo $row['id']; ?>">
                                                                        <div class="modal-dialog">
                                                                            <div class="modal-content bg-white">
                                                                                <div class="modal-header bg-dark text-white">
                                                                                    <h4 class="modal-title fw-bold">Update
                                                                                        Source</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="hr_accounts_update.php" method="POST">
                                                                                    <input type="hidden" name="id" id="id" value="<?php echo $row['id']; ?>">
                                                                                        <label for="">Plateform</label>
                                                                                        <input type="text" name="plateform" value="<?php echo $row['plateform']; ?>" class="form-control">
                                                                                        <label for="">URl</label>
                                                                                        <input type="text" name="url" value="<?php echo $row['url']; ?>" class="form-control" >
                                                                                        <label for="">Username</label>
                                                                                        <input type="text" name="name"  value="<?php echo $row['name']; ?>"  class="form-control">
                                                                                        <label for="">Password</label>
                                                                                        <input type="text" name="pass"  value="<?php echo $row['pass']; ?>"  class="form-control">
                                                                                        <label for="">Type</label>
                                                                                        <select id="type" class="form-control" name="type">
                                                                                            <option value="<?php echo $row['type']; ?>">Select Type</option>
                                                                                            <option value="Paid" <?php echo ($row['type'] === 'Paid') ? 'selected' : ''; ?>>Paid</option>
                                                                                            <option value="Unpaid" <?php echo ($row['type'] === 'Unpaid') ? 'selected' : ''; ?>>Unpaid</option>
                                                                                        </select>

                                                                                        <hr>
                                                                                        <button class="btn btn-dark text-white" type="submit">Submit</button>
                                                                                    </form>
                                                                                </div>

                                                                            </div>
                                                                            <!-- /.modal-content -->
                                                                        </div>
                                                                        <!-- /.modal-dialog -->
                                                                    </div>

                                                                </tr>
                                                            <?php } ?>

                                                        </tbody>

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

                                    </div>
                                </div>

                            </div>

                        </div>

                    </div>

                </div>

            </section>

        </div>
    </div>

    <div class="modal fade" id="modal-success">
        <div class="modal-dialog">
            <div class="modal-content bg-white">
                <div class="modal-header bg-dark text-white">
                    <h4 class="modal-title fw-bold">Add Accounts</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="hr_accounts_code.php" method="POST">
                        <label for="">Plateform</label>
                        <input type="text" name="plateform" class="form-control">
                        <label for="">URl</label>
                        <input type="text" name="url" class="form-control">
                        <label for="">Username</label>
                        <input type="text" name="name" class="form-control">
                        <label for="">Password</label>
                        <input type="text" name="pass" class="form-control">
                        <label for="">Type</label>
                        <select id="" class="form-control" name="type">
                            <option value="">Select Type</option>
                            <option value="Paid">Paid</option>
                            <option value="Unpaid">Unpaid</option>
                        </select>

                        <hr>
                        <button class="btn btn-dark text-white" type="submit">Submit</button>
                    </form>
                </div>

            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <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>