<?php
require("header.php")
?>
<style>
    .btn-group>.btn:not(:last-child):not(.dropdown-toggle) {
        background: black;
    }

    .btn-group>.btn-group:not(:first-child)>.btn {
        background: black;
    }

    .page-item.active .page-link {
        background: black;
    }

    .dt-button-collection .dropdown-menu .buttons-columnVisibility {
        background-color: black;
    }
</style>

<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <!-- <h1>Add User</h1> -->
                </div>
                <div class="col-sm-6">

                </div>
            </div>
        </div><!-- /.container-fluid -->
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="container-fluid">
            <div class="row">

                <div class="col-md-12">
                    <!-- general form elements -->
                    <div class="card card-secondary">
                        <div class="card-header" style="background-color: black;">
                            <h3 class="card-title">Our Skype</h3>
                            <ol class="breadcrumb float-sm-right" style="background-color: black;">
                                <li class="breadcrumb-item">Phonebook</li>
                                <li class="breadcrumb-item active">Skype</li>
                            </ol>
                        </div>

                        <!-- /.card-header -->
                        <!-- form start -->
                        <section class="content">
                            <div class="container-fluid">
                                <div class="row">
                                    <!-- left column -->
                                    <div class="col-md-12">
                                        <!-- general form elements -->
                                        <div class="card shadow ">

                                            <!-- /.card-header -->
                                            <!-- form start -->
                                            <form action="add_our_skpe_code.php" method="POST">
                                                <div class="card-body">

                                                    <div class="row">

                                                        <div class="col-4">
                                                            <div class="form-group">
                                                                <label for="exampleInputtitle">Name</label>
                                                                <input type="text" class="form-control" placeholder="Name" name="name">
                                                            </div>
                                                        </div>
                                                        <div class="col-4">
                                                            <div class="form-group">
                                                                <label for="exampleInputtitle">URL</label>
                                                                <input type="text" class="form-control" placeholder="Profile URL" name="url">
                                                            </div>
                                                        </div>
                                                        <div class="col-3">
                                                            <div class="form-group">
                                                                <label for="exampleInputtitle">Number</label>
                                                                <input type="text" class="form-control" placeholder="Number" name="number">
                                                            </div>
                                                        </div>

                                                        <div class="col-1" style="margin-top: 23px;">
                                                            <button type="submit" class="btn btn-danger mt-2" style="background: black;border:none">Submit</button>
                                                        </div>

                                                    </div>

                                                </div>

                                            </form>
                                        </div>
                                        <!-- /.card -->


                                    </div>

                                </div>
                                <!-- /.row -->
                            </div><!-- /.container-fluid -->
                        </section>

                        <section class="content">
                            <div class="container-fluid">
                                <div class="row">
                                    <div class="col-12">
                                        <div class="card shadow">
                                            <div class="card-header" style="background:black; ">
                                                <h3 class="card-title text-white text-bold text-uppercase"> View All
                                                    Our Skype
                                                </h3>
                                            </div>
                                            <!-- /.card-header -->
                                            <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 table-hover dataTable dtr-inline display" aria-describedby="example2_info">
                                                                    <thead>
                                                                        <tr>
                                                                            <th>Date &amp; time</th>
                                                                            <th>Added By</th>
                                                                            <th>Name</th>
                                                                            <th>Url</th>
                                                                            <th>Number</th>
                                                                            <th>Action</th>
                                                                        </tr>
                                                                    </thead>
                                                                    <tbody>
                                                                        <?php
                                                                        include('connection.php');
                                                                        $i = 0;

                                                                        $sql = "SELECT * FROM our_skype ";
                                                                        $res = mysqli_query($conn, $sql);
                                                                        while ($row = mysqli_fetch_assoc($res)) {
                                                                            $i++;

                                                                        ?>
                                                                            <tr>
                                                                                <td><?php echo $row['datetime'] ?></td>
                                                                                <td><?php echo $row['added_by'] ?></td>
                                                                                <td><?php echo $row['name'] ?></td>
                                                                                <td><?php echo $row['url'] ?></td>
                                                                                <td><?php echo $row['number'] ?></td>
                                                                                <td>
                                                                                    <button class="btn btn-primary edit-btn" data-toggle="modal" data-target="#editContactModal" data-id="<?php echo $row['id']; ?>" data-name="<?php echo $row['name']; ?>" data-url="<?php echo $row['url']; ?>" data-number="<?php echo $row['number']; ?>">Edit</button>
                                                                                    <a href="delete_our_skype.php?id=<?php echo $row['id']; ?>" class="btn btn-danger">Delete</a>
                                                                                </td>
                                                                            </tr>
                                                                        <?php } ?>
                                                                        <!-- Add more rows as needed -->
                                                                    </tbody>

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

                                                </div>
                                            </div>
                                            <!-- /.card-body -->
                                        </div>

                                    </div>
                                    <!-- /.col -->
                                </div>

                            </div>

                        </section>
                    </div>
                    <!-- /.card -->




                </div>

            </div>

            <!-- /.col -->
        </div>
        <!-- /.row -->

        <!-- /.container-fluid -->
    </section>
    <!-- /.content -->
</div>
<div class="modal fade" id="editContactModal" tabindex="-1" role="dialog" aria-labelledby="editContactModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header" style="background-color: black;">
                <h5 class="modal-title" id="editContactModalLabel">Edit Skype</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <form action="edit_our_skype.php" method="POST">
                <div class="modal-body">
                    <!-- Edit form fields go here -->
                    <input type="hidden" id="editContactId" name="id">
                    <div class="form-group">
                        <label>Name</label>
                        <input type="text" required class="form-control" placeholder="Name" name="name" id="editContactName">
                    </div>
                    <div class="form-group">
                        <label>URL</label>
                        <input type="text" required class="form-control" placeholder="Url" name="url" id="editContacteUrl">
                    </div>
                    <div class="form-group">
                        <label>Number</label>
                        <input type="text" required class="form-control" placeholder="Number" name="number" id="editContactNumber">
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal" style="background-color: black;">Close</button>
                    <button type="submit" class="btn btn-primary" name="update" style="background-color: black;">Update</button>
                </div>
            </form>
        </div>
    </div>
</div>
<!-- for searching -->
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script>
    $(document).ready(function() {
        $(".edit-btn").click(function() {
            var contactId = $(this).data("id");
            var contactName = $(this).data("name");
            var contacteUrl = $(this).data("url");
            var contactNumber = $(this).data("number");

            // Populate the modal fields with contact information
            $("#editContactId").val(contactId);
            $("#editContactName").val(contactName);
            $("#editContacteUrl").val(contacteUrl);
            $("#editContactNumber").val(contactNumber);
        });
    });
</script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script>
    <?php if (isset($_GET['error'])) { ?>
        Swal.fire({
            icon: 'error',
            title: 'Error',
            text: '<?php echo $_GET['error']; ?>',
        });
    <?php } ?>

    <?php if (isset($_GET['success'])) { ?>
        Swal.fire({
            icon: 'success',
            title: 'Success',
            text: '<?php echo $_GET['success']; ?>',
        });
    <?php } ?>
</script>
<script>
    $().ready(function() {
        $("#gnrt_pass").click(function() {
            var randomstring = Math.random().toString(36).slice(-8);
            $("input[name=password]").val(randomstring);
        })
    })
</script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<!-- Sweet Alert  start-->
<?php if (isset($_REQUEST['msg']) && $_REQUEST['msg'] == 1) { ?>
    <script>
        Swal.fire(
            'Good job!',
            'Data Added Successfully!!',
            'success'
        ).then(() => {
            window.location.href = "our_skype.php";
        });
    </script>
<?php } ?>

<?php if (isset($_REQUEST['msg']) && $_REQUEST['msg'] == 2) { ?>
    <script>
        Swal.fire(
            'Oops...',
            'Something went wrong!!',
            'error'
        ).then(() => {
            window.location.href = "our_skype.php";
        });
    </script>
<?php } ?>
<?php if (isset($_REQUEST['msg']) && $_REQUEST['msg'] == 3) { ?>
    <script>
        Swal.fire(
            'Oops...',
            'Same Data Already Exists!',
            'error'
        ).then(() => {
            window.location.href = "our_skype.php";
        });
    </script>
<?php } ?>
<?php
require("footer.php")
?>